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
31 static const char rcsid[] =
40 * this will cause the raw mp table to be dumped to /tmp/mpdump
45 #define MP_SIG 0x5f504d5f /* _MP_ */
46 #define EXTENDED_PROCESSING_READY
47 #define OEM_PROCESSING_READY_NOT
49 #include <sys/types.h>
59 "\n-------------------------------------------------------------------------------\n"
62 "\n===============================================================================\n"
64 /* EBDA is @ 40:0e in real-mode terms */
65 #define EBDA_POINTER 0x040e /* location of EBDA pointer */
67 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
68 #define TOPOFMEM_POINTER 0x0413 /* BIOS: base memory size */
70 #define DEFAULT_TOPOFMEM 0xa0000
72 #define BIOS_BASE 0xf0000
73 #define BIOS_BASE2 0xe0000
74 #define BIOS_SIZE 0x10000
75 #define ONE_KBYTE 1024
77 #define GROPE_AREA1 0x80000
78 #define GROPE_AREA2 0x90000
79 #define GROPE_SIZE 0x10000
81 #define PROCENTRY_FLAG_EN 0x01
82 #define PROCENTRY_FLAG_BP 0x02
83 #define IOAPICENTRY_FLAG_EN 0x01
95 UNKNOWN_BUSTYPE = 0xff
98 typedef struct BUSTYPENAME {
103 static busTypeName busTypeTable[] =
106 { CBUSII, "CBUSII" },
108 { UNKNOWN_BUSTYPE, "---" },
109 { UNKNOWN_BUSTYPE, "---" },
111 { UNKNOWN_BUSTYPE, "---" },
112 { UNKNOWN_BUSTYPE, "---" },
113 { UNKNOWN_BUSTYPE, "---" },
114 { UNKNOWN_BUSTYPE, "---" },
115 { UNKNOWN_BUSTYPE, "---" },
116 { UNKNOWN_BUSTYPE, "---" },
118 { UNKNOWN_BUSTYPE, "---" },
119 { UNKNOWN_BUSTYPE, "---" },
120 { UNKNOWN_BUSTYPE, "---" },
121 { UNKNOWN_BUSTYPE, "---" },
122 { UNKNOWN_BUSTYPE, "---" },
123 { UNKNOWN_BUSTYPE, "---" }
126 const char* whereStrings[] = {
127 "Extended BIOS Data Area",
128 "BIOS top of memory",
129 "Default top of memory",
136 typedef struct TABLE_ENTRY {
142 tableEntry basetableEntryTypes[] =
144 { 0, 20, "Processor" },
146 { 2, 8, "I/O APIC" },
148 { 4, 8, "Local INT" }
151 tableEntry extendedtableEntryTypes[] =
153 { 128, 20, "System Address Space" },
154 { 129, 8, "Bus Heirarchy" },
155 { 130, 8, "Compatibility Bus Address" }
158 /* MP Floating Pointer Structure */
159 typedef struct MPFPS {
172 /* MP Configuration Table Header */
173 typedef struct MPCTH {
175 u_short base_table_length;
179 u_char product_id[ 12 ];
180 u_int32_t oem_table_pointer;
181 u_short oem_table_size;
183 u_int32_t apic_address;
184 u_short extended_table_length;
185 u_char extended_table_checksum;
190 typedef struct PROCENTRY {
195 u_int32_t cpuSignature;
196 u_int32_t featureFlags;
201 typedef struct BUSENTRY {
207 typedef struct IOAPICENTRY {
212 u_int32_t apicAddress;
215 typedef struct INTENTRY {
227 * extended entry type structures
230 typedef struct SASENTRY {
235 u_int64_t addressBase;
236 u_int64_t addressLength;
237 } __attribute__((__packed__)) SasEntry;
240 typedef struct BHDENTRY {
246 u_char reserved[ 3 ];
250 typedef struct CBASMENTRY {
255 u_int predefinedRange;
260 static void apic_probe( u_int32_t* paddr, int* where );
262 static void MPConfigDefault( int featureByte );
264 static void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfps );
265 static void MPConfigTableHeader( u_int32_t pap );
267 static int readType( void );
268 static void seekEntry( u_int32_t addr );
269 static void readEntry( void* entry, int size );
271 static void processorEntry( void );
272 static void busEntry( void );
273 static void ioApicEntry( void );
274 static void intEntry( void );
276 static void sasEntry( void );
277 static void bhdEntry( void );
278 static void cbasmEntry( void );
280 static void doDmesg( void );
281 static void pnstr( char* s, int c );
284 int pfd; /* physical /dev/mem fd */
301 fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
309 main( int argc, char *argv[] )
318 /* announce ourselves */
321 printf( "MPTable, version %d.%d.%d\n", VMAJOR, VMINOR, VDELTA );
323 while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
326 if ( strcmp( optarg, "mesg") == 0 )
332 if ( strcmp( optarg, "elp") == 0 )
336 if ( strcmp( optarg, "rope") == 0 )
340 if ( strcmp( optarg, "erbose") == 0 )
352 /* open physical memory for access to MP structures */
353 if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
354 err( 1, "mem open" );
356 /* probe for MP structures */
357 apic_probe( &paddr, &where );
359 fprintf( stderr, "\n MP FPS NOT found,\n" );
360 fprintf( stderr, " suggest trying -grope option!!!\n\n" );
365 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
366 whereStrings[ where - 1 ], paddr );
370 /* analyze the MP Floating Pointer Structure */
371 MPFloatingPointer( paddr, where, &mpfps );
375 /* check whether an MP config table exists */
376 if ( (defaultConfig = mpfps.mpfb1) )
377 MPConfigDefault( defaultConfig );
379 MPConfigTableHeader( mpfps.pap );
381 /* do a dmesg output */
392 * set PHYSICAL address of MP floating pointer structure
394 #define NEXT(X) ((X) += 4)
396 apic_probe( u_int32_t* paddr, int* where )
399 * c rewrite of apic_probe() by Jack F. Vogel
405 u_int buffer[ BIOS_SIZE / sizeof( int ) ];
410 /* search Extended Bios Data Area, if present */
412 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
413 seekEntry( (u_int32_t)EBDA_POINTER );
414 readEntry( &segment, 2 );
415 if ( segment ) { /* search EBDA */
416 target = (u_int32_t)segment << 4;
418 printf( "found, searching EBDA @ 0x%08x\n", target );
420 readEntry( buffer, ONE_KBYTE );
422 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
423 if ( buffer[ x ] == MP_SIG ) {
425 *paddr = (x * sizeof( unsigned int )) + target;
432 printf( "NOT found\n" );
435 /* read CMOS for real top of mem */
436 seekEntry( (u_int32_t)TOPOFMEM_POINTER );
437 readEntry( &segment, 2 );
438 --segment; /* less ONE_KBYTE */
439 target = segment * 1024;
441 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
444 readEntry( buffer, ONE_KBYTE );
446 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
447 if ( buffer[ x ] == MP_SIG ) {
449 *paddr = (x * sizeof( unsigned int )) + target;
454 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
455 if ( target != (DEFAULT_TOPOFMEM - 1024)) {
456 target = (DEFAULT_TOPOFMEM - 1024);
458 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
459 target, (target / 1024) );
461 readEntry( buffer, ONE_KBYTE );
463 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
464 if ( buffer[ x ] == MP_SIG ) {
466 *paddr = (x * sizeof( unsigned int )) + target;
472 /* search the BIOS */
474 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
475 seekEntry( BIOS_BASE );
476 readEntry( buffer, BIOS_SIZE );
478 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
479 if ( buffer[ x ] == MP_SIG ) {
481 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
486 /* search the extended BIOS */
488 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
489 seekEntry( BIOS_BASE2 );
490 readEntry( buffer, BIOS_SIZE );
492 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
493 if ( buffer[ x ] == MP_SIG ) {
495 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
501 /* search additional memory */
502 target = GROPE_AREA1;
504 printf( " groping memory @ 0x%08x\n", target );
506 readEntry( buffer, GROPE_SIZE );
508 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
509 if ( buffer[ x ] == MP_SIG ) {
511 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
516 target = GROPE_AREA2;
518 printf( " groping memory @ 0x%08x\n", target );
520 readEntry( buffer, GROPE_SIZE );
522 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
523 if ( buffer[ x ] == MP_SIG ) {
525 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
532 *paddr = (u_int32_t)0;
540 MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfps )
543 /* read in mpfps structure*/
545 readEntry( mpfps, sizeof( mpfps_t ) );
547 /* show its contents */
548 printf( "MP Floating Pointer Structure:\n\n" );
550 printf( " location:\t\t\t" );
557 printf( "BIOS base memory\n" );
560 printf( "DEFAULT base memory (639K)\n" );
566 printf( "Extended BIOS\n" );
570 printf( "NOT found!\n" );
573 printf( "BOGUS!\n" );
576 printf( " physical address:\t\t0x%08x\n", paddr );
578 printf( " signature:\t\t\t'" );
579 pnstr( mpfps->signature, 4 );
582 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 );
583 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev );
584 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum );
586 /* bits 0:6 are RESERVED */
587 if ( mpfps->mpfb2 & 0x7f ) {
588 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
592 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & 0x80) ?
593 "PIC" : "Virtual Wire" );
595 /* MP feature bytes 3-5 are expected to be ZERO */
597 printf( " warning, MP feature byte 3 NONZERO!\n" );
599 printf( " warning, MP feature byte 4 NONZERO!\n" );
601 printf( " warning, MP feature byte 5 NONZERO!\n" );
609 MPConfigDefault( int featureByte )
611 printf( " MP default config type: %d\n\n", featureByte );
612 switch ( featureByte ) {
614 printf( " bus: ISA, APIC: 82489DX\n" );
617 printf( " bus: EISA, APIC: 82489DX\n" );
620 printf( " bus: EISA, APIC: 82489DX\n" );
623 printf( " bus: MCA, APIC: 82489DX\n" );
626 printf( " bus: ISA+PCI, APIC: Integrated\n" );
629 printf( " bus: EISA+PCI, APIC: Integrated\n" );
632 printf( " bus: MCA+PCI, APIC: Integrated\n" );
635 printf( " future type\n" );
639 switch ( featureByte ) {
652 printf( " future type\n" );
666 MPConfigTableHeader( u_int32_t pap )
674 int oldtype, entrytype;
677 printf( "MP Configuration Table Header MISSING!\n" );
681 /* convert physical address to virtual address */
684 /* read in cth structure */
686 readEntry( &cth, sizeof( cth ) );
688 printf( "MP Config Table Header:\n\n" );
690 printf( " physical address:\t\t0x%08x\n", pap );
692 printf( " signature:\t\t\t'" );
693 pnstr( cth.signature, 4 );
696 printf( " base table length:\t\t%d\n", cth.base_table_length );
698 printf( " version:\t\t\t1.%1d\n", cth.spec_rev );
699 printf( " checksum:\t\t\t0x%02x\n", cth.checksum );
701 printf( " OEM ID:\t\t\t'" );
702 pnstr( cth.oem_id, 8 );
705 printf( " Product ID:\t\t\t'" );
706 pnstr( cth.product_id, 12 );
709 printf( " OEM table pointer:\t\t0x%08x\n", cth.oem_table_pointer );
710 printf( " OEM table size:\t\t%d\n", cth.oem_table_size );
712 printf( " entry count:\t\t\t%d\n", cth.entry_count );
714 printf( " local APIC address:\t\t0x%08x\n", cth.apic_address );
716 printf( " extended table length:\t%d\n", cth.extended_table_length );
717 printf( " extended table checksum:\t%d\n", cth.extended_table_checksum );
719 totalSize = cth.base_table_length - sizeof( struct MPCTH );
720 count = cth.entry_count;
724 printf( "MP Config Base Table Entries:\n\n" );
726 /* initialze tables */
727 for ( x = 0; x < 16; ++x ) {
728 busses[ x ] = apics[ x ] = 0xff;
737 for (c = count; c; c--) {
738 entrytype = readType();
739 if (entrytype != oldtype)
741 if (entrytype < oldtype)
742 printf("MPTABLE OUT OF ORDER!\n");
746 printf( "Processors:\tAPIC ID\tVersion\tState"
747 "\t\tFamily\tModel\tStep\tFlags\n" );
754 printf( "Bus:\t\tBus ID\tType\n" );
761 printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
768 printf( "I/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
775 printf( "Local Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
781 printf("MPTABLE HOSED! record type = %d\n", entrytype);
787 #if defined( EXTENDED_PROCESSING_READY )
788 /* process any extended data */
789 if ( (totalSize = cth.extended_table_length) ) {
792 printf( "MP Config Extended Table Entries:\n\n" );
794 while ( totalSize > 0 ) {
795 switch ( type = readType() ) {
806 printf( "Extended Table HOSED!\n" );
810 totalSize -= extendedtableEntryTypes[ type-128 ].length;
813 #endif /* EXTENDED_PROCESSING_READY */
815 /* process any OEM data */
816 if ( cth.oem_table_pointer && (cth.oem_table_size > 0) ) {
817 #if defined( OEM_PROCESSING_READY )
818 # error your on your own here!
819 /* convert OEM table pointer to virtual address */
820 poemtp = (u_int32_t)cth.oem_table_pointer;
822 /* read in oem table structure */
823 if ( (oemdata = (void*)malloc( cth.oem_table_size )) == NULL )
824 err( 1, "oem malloc" );
827 readEntry( oemdata, cth.oem_table_size );
833 printf( "\nyou need to modify the source to handle OEM data!\n\n" );
834 #endif /* OEM_PROCESSING_READY */
839 #if defined( RAW_DUMP )
842 u_char dumpbuf[ 4096 ];
844 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR );
846 readEntry( dumpbuf, 1024 );
847 write( ofd, dumpbuf, 1024 );
850 #endif /* RAW_DUMP */
862 if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) )
863 err( 1, "type read; pfd: %d", pfd );
865 if ( lseek( pfd, -1, SEEK_CUR ) < 0 )
866 err( 1, "type seek" );
876 seekEntry( u_int32_t addr )
878 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
879 err( 1, "%s seek", _PATH_MEM );
887 readEntry( void* entry, int size )
889 if ( read( pfd, entry, size ) != size )
890 err( 1, "readEntry" );
895 processorEntry( void )
899 /* read it into local memory */
900 readEntry( &entry, sizeof( entry ) );
905 printf( "\t\t%2d", entry.apicID );
906 printf( "\t 0x%2x", entry.apicVersion );
909 (entry.cpuFlags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
910 (entry.cpuFlags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
912 printf( "\t %d\t %d\t %d",
913 (entry.cpuSignature >> 8) & 0x0f,
914 (entry.cpuSignature >> 4) & 0x0f,
915 entry.cpuSignature & 0x0f );
917 printf( "\t 0x%04x\n", entry.featureFlags );
925 lookupBusType( char* name )
929 for ( x = 0; x < MAX_BUSTYPE; ++x )
930 if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
931 return busTypeTable[ x ].type;
933 return UNKNOWN_BUSTYPE;
945 /* read it into local memory */
946 readEntry( &entry, sizeof( entry ) );
951 printf( "\t\t%2d", entry.busID );
952 printf( "\t " ); pnstr( entry.busType, 6 ); printf( "\n" );
954 for ( x = 0; x < 6; ++x ) {
955 if ( (c = entry.busType[ x ]) == ' ' )
960 busses[ entry.busID ] = lookupBusType( name );
969 /* read it into local memory */
970 readEntry( &entry, sizeof( entry ) );
975 printf( "\t\t%2d", entry.apicID );
976 printf( "\t 0x%02x", entry.apicVersion );
978 (entry.apicFlags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
979 printf( "\t\t 0x%x\n", entry.apicAddress );
981 apics[ entry.apicID ] = entry.apicID;
985 const char* intTypes[] = {
986 "INT", "NMI", "SMI", "ExtINT"
989 const char* polarityMode[] = {
990 "conforms", "active-hi", "reserved", "active-lo"
992 const char* triggerMode[] = {
993 "conforms", "edge", "reserved", "level"
1001 /* read it into local memory */
1002 readEntry( &entry, sizeof( entry ) );
1005 if ( (int)entry.type == 3 )
1008 printf( "\t\t%s", intTypes[ (int)entry.intType ] );
1010 printf( "\t%9s", polarityMode[ (int)entry.intFlags & 0x03 ] );
1011 printf( "%12s", triggerMode[ ((int)entry.intFlags >> 2) & 0x03 ] );
1013 printf( "\t %5d", (int)entry.srcBusID );
1014 if ( busses[ (int)entry.srcBusID ] == PCI )
1016 ((int)entry.srcBusIRQ >> 2) & 0x1f,
1017 ((int)entry.srcBusIRQ & 0x03) + 'A' );
1019 printf( "\t %3d", (int)entry.srcBusIRQ );
1020 printf( "\t %6d", (int)entry.dstApicID );
1021 printf( "\t %3d\n", (int)entry.dstApicINT );
1030 /* read it into local memory */
1031 readEntry( &entry, sizeof( entry ) );
1033 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1034 printf( " bus ID: %d", entry.busID );
1035 printf( " address type: " );
1036 switch ( entry.addressType ) {
1038 printf( "I/O address\n" );
1041 printf( "memory address\n" );
1044 printf( "prefetch address\n" );
1047 printf( "UNKNOWN type\n" );
1051 printf( " address base: 0x%llx\n", (long long)entry.addressBase );
1052 printf( " address range: 0x%llx\n", (long long)entry.addressLength );
1061 /* read it into local memory */
1062 readEntry( &entry, sizeof( entry ) );
1064 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1065 printf( " bus ID: %d", entry.busID );
1066 printf( " bus info: 0x%02x", entry.busInfo );
1067 printf( " parent bus ID: %d\n", entry.busParent );
1076 /* read it into local memory */
1077 readEntry( &entry, sizeof( entry ) );
1079 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1080 printf( " bus ID: %d", entry.busID );
1081 printf( " address modifier: %s\n", (entry.addressMod & 0x01) ?
1082 "subtract" : "add" );
1083 printf( " predefined range: 0x%08x\n", entry.predefinedRange );
1095 printf( "dmesg output:\n\n" );
1105 pnstr( char* s, int c )
1107 char string[ MAXPNSTR + 1 ];
1111 strncpy( string, s, c );
1113 printf( "%s", string );