2 * Copyright (c) 1996, by Steve Passe
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. The name of the developer may NOT be used to endorse or promote products
11 * derived from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * $FreeBSD: src/usr.sbin/mptable/mptable.c,v 1.12.2.3 2000/12/11 01:03:34 obrien Exp $
26 * $DragonFly: src/usr.sbin/mptable/mptable.c,v 1.3 2005/04/05 09:04:49 joerg Exp $
38 * this will cause the raw mp table to be dumped to /tmp/mpdump
43 #define MP_SIG 0x5f504d5f /* _MP_ */
44 #define EXTENDED_PROCESSING_READY
45 #define OEM_PROCESSING_READY_NOT
47 #include <sys/types.h>
57 "\n-------------------------------------------------------------------------------\n"
60 "\n===============================================================================\n"
62 /* EBDA is @ 40:0e in real-mode terms */
63 #define EBDA_POINTER 0x040e /* location of EBDA pointer */
65 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
66 #define TOPOFMEM_POINTER 0x0413 /* BIOS: base memory size */
68 #define DEFAULT_TOPOFMEM 0xa0000
70 #define BIOS_BASE 0xf0000
71 #define BIOS_BASE2 0xe0000
72 #define BIOS_SIZE 0x10000
73 #define ONE_KBYTE 1024
75 #define GROPE_AREA1 0x80000
76 #define GROPE_AREA2 0x90000
77 #define GROPE_SIZE 0x10000
79 #define PROCENTRY_FLAG_EN 0x01
80 #define PROCENTRY_FLAG_BP 0x02
81 #define IOAPICENTRY_FLAG_EN 0x01
93 UNKNOWN_BUSTYPE = 0xff
96 typedef struct BUSTYPENAME {
101 static busTypeName busTypeTable[] =
104 { CBUSII, "CBUSII" },
106 { UNKNOWN_BUSTYPE, "---" },
107 { UNKNOWN_BUSTYPE, "---" },
109 { UNKNOWN_BUSTYPE, "---" },
110 { UNKNOWN_BUSTYPE, "---" },
111 { UNKNOWN_BUSTYPE, "---" },
112 { UNKNOWN_BUSTYPE, "---" },
113 { UNKNOWN_BUSTYPE, "---" },
114 { UNKNOWN_BUSTYPE, "---" },
116 { UNKNOWN_BUSTYPE, "---" },
117 { UNKNOWN_BUSTYPE, "---" },
118 { UNKNOWN_BUSTYPE, "---" },
119 { UNKNOWN_BUSTYPE, "---" },
120 { UNKNOWN_BUSTYPE, "---" },
121 { UNKNOWN_BUSTYPE, "---" }
124 char* whereStrings[] = {
125 "Extended BIOS Data Area",
126 "BIOS top of memory",
127 "Default top of memory",
134 typedef struct TABLE_ENTRY {
140 tableEntry basetableEntryTypes[] =
142 { 0, 20, "Processor" },
144 { 2, 8, "I/O APIC" },
146 { 4, 8, "Local INT" }
149 tableEntry extendedtableEntryTypes[] =
151 { 128, 20, "System Address Space" },
152 { 129, 8, "Bus Heirarchy" },
153 { 130, 8, "Compatibility Bus Address" }
156 /* MP Floating Pointer Structure */
157 typedef struct MPFPS {
170 /* MP Configuration Table Header */
171 typedef struct MPCTH {
173 u_short base_table_length;
177 u_char product_id[ 12 ];
178 void* oem_table_pointer;
179 u_short oem_table_size;
182 u_short extended_table_length;
183 u_char extended_table_checksum;
188 typedef struct PROCENTRY {
199 typedef struct BUSENTRY {
205 typedef struct IOAPICENTRY {
213 typedef struct INTENTRY {
225 * extended entry type structures
228 typedef struct SASENTRY {
233 u_int64_t addressBase;
234 u_int64_t addressLength;
238 typedef struct BHDENTRY {
244 u_char reserved[ 3 ];
248 typedef struct CBASMENTRY {
253 u_int predefinedRange;
258 static void apic_probe( vm_offset_t* paddr, int* where );
260 static void MPConfigDefault( int featureByte );
262 static void MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps );
263 static void MPConfigTableHeader( void* pap );
265 static int readType( void );
266 static void seekEntry( vm_offset_t addr );
267 static void readEntry( void* entry, int size );
269 static void processorEntry( void );
270 static void busEntry( void );
271 static void ioApicEntry( void );
272 static void intEntry( void );
274 static void sasEntry( void );
275 static void bhdEntry( void );
276 static void cbasmEntry( void );
278 static void doDmesg( void );
279 static void pnstr( char* s, int c );
282 int pfd; /* physical /dev/mem fd */
299 fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
307 main( int argc, char *argv[] )
317 /* announce ourselves */
320 printf( "MPTable, version %d.%d.%d\n", VMAJOR, VMINOR, VDELTA );
322 while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
325 if ( strcmp( optarg, "mesg") == 0 )
331 if ( strcmp( optarg, "elp") == 0 )
335 if ( strcmp( optarg, "rope") == 0 )
339 if ( strcmp( optarg, "erbose") == 0 )
350 /* open physical memory for access to MP structures */
351 if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
352 err( 1, "mem open" );
354 /* probe for MP structures */
355 apic_probe( &paddr, &where );
357 fprintf( stderr, "\n MP FPS NOT found,\n" );
358 fprintf( stderr, " suggest trying -grope option!!!\n\n" );
363 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
364 whereStrings[ where - 1 ], paddr );
368 /* analyze the MP Floating Pointer Structure */
369 MPFloatingPointer( paddr, where, &mpfps );
373 /* check whether an MP config table exists */
374 if ( (defaultConfig = mpfps.mpfb1) )
375 MPConfigDefault( defaultConfig );
377 MPConfigTableHeader( mpfps.pap );
379 /* do a dmesg output */
390 * set PHYSICAL address of MP floating pointer structure
392 #define NEXT(X) ((X) += 4)
394 apic_probe( vm_offset_t* paddr, int* where )
397 * c rewrite of apic_probe() by Jack F. Vogel
403 u_int buffer[ BIOS_SIZE / sizeof( int ) ];
408 /* search Extended Bios Data Area, if present */
410 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
411 seekEntry( (vm_offset_t)EBDA_POINTER );
412 readEntry( &segment, 2 );
413 if ( segment ) { /* search EBDA */
414 target = (vm_offset_t)segment << 4;
416 printf( "found, searching EBDA @ 0x%08x\n", target );
418 readEntry( buffer, ONE_KBYTE );
420 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) {
421 if ( buffer[ x ] == MP_SIG ) {
423 *paddr = (x * sizeof( unsigned int )) + target;
430 printf( "NOT found\n" );
433 /* read CMOS for real top of mem */
434 seekEntry( (vm_offset_t)TOPOFMEM_POINTER );
435 readEntry( &segment, 2 );
436 --segment; /* less ONE_KBYTE */
437 target = segment * 1024;
439 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
442 readEntry( buffer, ONE_KBYTE );
444 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) {
445 if ( buffer[ x ] == MP_SIG ) {
447 *paddr = (x * sizeof( unsigned int )) + target;
452 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
453 if ( target != (DEFAULT_TOPOFMEM - 1024)) {
454 target = (DEFAULT_TOPOFMEM - 1024);
456 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
457 target, (target / 1024) );
459 readEntry( buffer, ONE_KBYTE );
461 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) {
462 if ( buffer[ x ] == MP_SIG ) {
464 *paddr = (x * sizeof( unsigned int )) + target;
470 /* search the BIOS */
472 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
473 seekEntry( BIOS_BASE );
474 readEntry( buffer, BIOS_SIZE );
476 for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) {
477 if ( buffer[ x ] == MP_SIG ) {
479 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
484 /* search the extended BIOS */
486 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
487 seekEntry( BIOS_BASE2 );
488 readEntry( buffer, BIOS_SIZE );
490 for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) {
491 if ( buffer[ x ] == MP_SIG ) {
493 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
499 /* search additional memory */
500 target = GROPE_AREA1;
502 printf( " groping memory @ 0x%08x\n", target );
504 readEntry( buffer, GROPE_SIZE );
506 for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) {
507 if ( buffer[ x ] == MP_SIG ) {
509 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
514 target = GROPE_AREA2;
516 printf( " groping memory @ 0x%08x\n", target );
518 readEntry( buffer, GROPE_SIZE );
520 for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) {
521 if ( buffer[ x ] == MP_SIG ) {
523 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
530 *paddr = (vm_offset_t)0;
538 MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps )
541 /* read in mpfps structure*/
543 readEntry( mpfps, sizeof( mpfps_t ) );
545 /* show its contents */
546 printf( "MP Floating Pointer Structure:\n\n" );
548 printf( " location:\t\t\t" );
555 printf( "BIOS base memory\n" );
558 printf( "DEFAULT base memory (639K)\n" );
564 printf( "Extended BIOS\n" );
568 printf( "NOT found!\n" );
571 printf( "BOGUS!\n" );
574 printf( " physical address:\t\t0x%08x\n", paddr );
576 printf( " signature:\t\t\t'" );
577 pnstr( mpfps->signature, 4 );
580 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 );
581 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev );
582 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum );
584 /* bits 0:6 are RESERVED */
585 if ( mpfps->mpfb2 & 0x7f ) {
586 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
590 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & 0x80) ?
591 "PIC" : "Virtual Wire" );
593 /* MP feature bytes 3-5 are expected to be ZERO */
595 printf( " warning, MP feature byte 3 NONZERO!\n" );
597 printf( " warning, MP feature byte 4 NONZERO!\n" );
599 printf( " warning, MP feature byte 5 NONZERO!\n" );
607 MPConfigDefault( int featureByte )
609 printf( " MP default config type: %d\n\n", featureByte );
610 switch ( featureByte ) {
612 printf( " bus: ISA, APIC: 82489DX\n" );
615 printf( " bus: EISA, APIC: 82489DX\n" );
618 printf( " bus: EISA, APIC: 82489DX\n" );
621 printf( " bus: MCA, APIC: 82489DX\n" );
624 printf( " bus: ISA+PCI, APIC: Integrated\n" );
627 printf( " bus: EISA+PCI, APIC: Integrated\n" );
630 printf( " bus: MCA+PCI, APIC: Integrated\n" );
633 printf( " future type\n" );
637 switch ( featureByte ) {
650 printf( " future type\n" );
664 MPConfigTableHeader( void* pap )
674 printf( "MP Configuration Table Header MISSING!\n" );
678 /* convert physical address to virtual address */
679 paddr = (vm_offset_t)pap;
681 /* read in cth structure */
683 readEntry( &cth, sizeof( cth ) );
685 printf( "MP Config Table Header:\n\n" );
687 printf( " physical address:\t\t0x%08x\n", pap );
689 printf( " signature:\t\t\t'" );
690 pnstr( cth.signature, 4 );
693 printf( " base table length:\t\t%d\n", cth.base_table_length );
695 printf( " version:\t\t\t1.%1d\n", cth.spec_rev );
696 printf( " checksum:\t\t\t0x%02x\n", cth.checksum );
698 printf( " OEM ID:\t\t\t'" );
699 pnstr( cth.oem_id, 8 );
702 printf( " Product ID:\t\t\t'" );
703 pnstr( cth.product_id, 12 );
706 printf( " OEM table pointer:\t\t0x%08x\n", cth.oem_table_pointer );
707 printf( " OEM table size:\t\t%d\n", cth.oem_table_size );
709 printf( " entry count:\t\t\t%d\n", cth.entry_count );
711 printf( " local APIC address:\t\t0x%08x\n", cth.apic_address );
713 printf( " extended table length:\t%d\n", cth.extended_table_length );
714 printf( " extended table checksum:\t%d\n", cth.extended_table_checksum );
716 totalSize = cth.base_table_length - sizeof( struct MPCTH );
717 count = cth.entry_count;
721 printf( "MP Config Base Table Entries:\n\n" );
723 /* initialze tables */
724 for ( x = 0; x < 16; ++x ) {
725 busses[ x ] = apics[ x ] = 0xff;
733 /* process all the CPUs */
734 printf( "--\nProcessors:\tAPIC ID\tVersion\tState"
735 "\t\tFamily\tModel\tStep\tFlags\n" );
736 for ( t = totalSize, c = count; c; c-- ) {
737 if ( readType() == 0 )
739 totalSize -= basetableEntryTypes[ 0 ].length;
742 /* process all the busses */
743 printf( "--\nBus:\t\tBus ID\tType\n" );
744 for ( t = totalSize, c = count; c; c-- ) {
745 if ( readType() == 1 )
747 totalSize -= basetableEntryTypes[ 1 ].length;
750 /* process all the apics */
751 printf( "--\nI/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
752 for ( t = totalSize, c = count; c; c-- ) {
753 if ( readType() == 2 )
755 totalSize -= basetableEntryTypes[ 2 ].length;
758 /* process all the I/O Ints */
759 printf( "--\nI/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
760 for ( t = totalSize, c = count; c; c-- ) {
761 if ( readType() == 3 )
763 totalSize -= basetableEntryTypes[ 3 ].length;
766 /* process all the Local Ints */
767 printf( "--\nLocal Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
768 for ( t = totalSize, c = count; c; c-- ) {
769 if ( readType() == 4 )
771 totalSize -= basetableEntryTypes[ 4 ].length;
775 #if defined( EXTENDED_PROCESSING_READY )
776 /* process any extended data */
777 if ( (totalSize = cth.extended_table_length) ) {
780 printf( "MP Config Extended Table Entries:\n\n" );
782 while ( totalSize > 0 ) {
783 switch ( type = readType() ) {
794 printf( "Extended Table HOSED!\n" );
798 totalSize -= extendedtableEntryTypes[ type-128 ].length;
801 #endif /* EXTENDED_PROCESSING_READY */
803 /* process any OEM data */
804 if ( cth.oem_table_pointer && (cth.oem_table_size > 0) ) {
805 #if defined( OEM_PROCESSING_READY )
806 # error your on your own here!
807 /* convert OEM table pointer to virtual address */
808 poemtp = (vm_offset_t)cth.oem_table_pointer;
810 /* read in oem table structure */
811 if ( (oemdata = (void*)malloc( cth.oem_table_size )) == NULL )
812 err( 1, "oem malloc" );
815 readEntry( oemdata, cth.oem_table_size );
821 printf( "\nyou need to modify the source to handle OEM data!\n\n" );
822 #endif /* OEM_PROCESSING_READY */
827 #if defined( RAW_DUMP )
830 u_char dumpbuf[ 4096 ];
832 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR );
834 readEntry( dumpbuf, 1024 );
835 write( ofd, dumpbuf, 1024 );
838 #endif /* RAW_DUMP */
850 if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) )
851 err( 1, "type read; pfd: %d", pfd );
853 if ( lseek( pfd, -1, SEEK_CUR ) < 0 )
854 err( 1, "type seek" );
864 seekEntry( vm_offset_t addr )
866 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
867 err( 1, "%s seek", _PATH_MEM );
875 readEntry( void* entry, int size )
877 if ( read( pfd, entry, size ) != size )
878 err( 1, "readEntry" );
883 processorEntry( void )
887 /* read it into local memory */
888 readEntry( &entry, sizeof( entry ) );
893 printf( "\t\t%2d", entry.apicID );
894 printf( "\t 0x%2x", entry.apicVersion );
897 (entry.cpuFlags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
898 (entry.cpuFlags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
900 printf( "\t %d\t %d\t %d",
901 (entry.cpuSignature >> 8) & 0x0f,
902 (entry.cpuSignature >> 4) & 0x0f,
903 entry.cpuSignature & 0x0f );
905 printf( "\t 0x%04x\n", entry.featureFlags );
913 lookupBusType( char* name )
917 for ( x = 0; x < MAX_BUSTYPE; ++x )
918 if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
919 return busTypeTable[ x ].type;
921 return UNKNOWN_BUSTYPE;
933 /* read it into local memory */
934 readEntry( &entry, sizeof( entry ) );
939 printf( "\t\t%2d", entry.busID );
940 printf( "\t " ); pnstr( entry.busType, 6 ); printf( "\n" );
942 for ( x = 0; x < 6; ++x ) {
943 if ( (c = entry.busType[ x ]) == ' ' )
948 busses[ entry.busID ] = lookupBusType( name );
957 /* read it into local memory */
958 readEntry( &entry, sizeof( entry ) );
963 printf( "\t\t%2d", entry.apicID );
964 printf( "\t 0x%02x", entry.apicVersion );
966 (entry.apicFlags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
967 printf( "\t\t 0x%x\n", entry.apicAddress );
969 apics[ entry.apicID ] = entry.apicID;
974 "INT", "NMI", "SMI", "ExtINT"
977 char* polarityMode[] = {
978 "conforms", "active-hi", "reserved", "active-lo"
980 char* triggerMode[] = {
981 "conforms", "edge", "reserved", "level"
989 /* read it into local memory */
990 readEntry( &entry, sizeof( entry ) );
993 if ( (int)entry.type == 3 )
996 printf( "\t\t%s", intTypes[ (int)entry.intType ] );
998 printf( "\t%9s", polarityMode[ (int)entry.intFlags & 0x03 ] );
999 printf( "%12s", triggerMode[ ((int)entry.intFlags >> 2) & 0x03 ] );
1001 printf( "\t %5d", (int)entry.srcBusID );
1002 if ( busses[ (int)entry.srcBusID ] == PCI )
1004 ((int)entry.srcBusIRQ >> 2) & 0x1f,
1005 ((int)entry.srcBusIRQ & 0x03) + 'A' );
1007 printf( "\t %3d", (int)entry.srcBusIRQ );
1008 printf( "\t %6d", (int)entry.dstApicID );
1009 printf( "\t %3d\n", (int)entry.dstApicINT );
1018 /* read it into local memory */
1019 readEntry( &entry, sizeof( entry ) );
1021 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1022 printf( " bus ID: %d", entry.busID );
1023 printf( " address type: " );
1024 switch ( entry.addressType ) {
1026 printf( "I/O address\n" );
1029 printf( "memory address\n" );
1032 printf( "prefetch address\n" );
1035 printf( "UNKNOWN type\n" );
1039 printf( " address base: 0x%qx\n", entry.addressBase );
1040 printf( " address range: 0x%qx\n", entry.addressLength );
1049 /* read it into local memory */
1050 readEntry( &entry, sizeof( entry ) );
1052 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1053 printf( " bus ID: %d", entry.busID );
1054 printf( " bus info: 0x%02x", entry.busInfo );
1055 printf( " parent bus ID: %d\n", entry.busParent );
1064 /* read it into local memory */
1065 readEntry( &entry, sizeof( entry ) );
1067 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1068 printf( " bus ID: %d", entry.busID );
1069 printf( " address modifier: %s\n", (entry.addressMod & 0x01) ?
1070 "subtract" : "add" );
1071 printf( " predefined range: 0x%08x\n", entry.predefinedRange );
1083 printf( "dmesg output:\n\n" );
1093 pnstr( char* s, int c )
1095 char string[ MAXPNSTR + 1 ];
1099 strncpy( string, s, c );
1101 printf( "%s", string );