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 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 void* oem_table_pointer;
181 u_short oem_table_size;
184 u_short extended_table_length;
185 u_char extended_table_checksum;
190 typedef struct PROCENTRY {
201 typedef struct BUSENTRY {
207 typedef struct IOAPICENTRY {
215 typedef struct INTENTRY {
227 * extended entry type structures
230 typedef struct SASENTRY {
235 u_int64_t addressBase;
236 u_int64_t addressLength;
240 typedef struct BHDENTRY {
246 u_char reserved[ 3 ];
250 typedef struct CBASMENTRY {
255 u_int predefinedRange;
260 static void apic_probe( vm_offset_t* paddr, int* where );
262 static void MPConfigDefault( int featureByte );
264 static void MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps );
265 static void MPConfigTableHeader( void* pap );
267 static int readType( void );
268 static void seekEntry( vm_offset_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[] )
319 /* announce ourselves */
322 printf( "MPTable, version %d.%d.%d\n", VMAJOR, VMINOR, VDELTA );
324 while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
327 if ( strcmp( optarg, "mesg") == 0 )
333 if ( strcmp( optarg, "elp") == 0 )
337 if ( strcmp( optarg, "rope") == 0 )
341 if ( strcmp( optarg, "erbose") == 0 )
353 /* open physical memory for access to MP structures */
354 if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
355 err( 1, "mem open" );
357 /* probe for MP structures */
358 apic_probe( &paddr, &where );
360 fprintf( stderr, "\n MP FPS NOT found,\n" );
361 fprintf( stderr, " suggest trying -grope option!!!\n\n" );
366 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
367 whereStrings[ where - 1 ], paddr );
371 /* analyze the MP Floating Pointer Structure */
372 MPFloatingPointer( paddr, where, &mpfps );
376 /* check whether an MP config table exists */
377 if ( (defaultConfig = mpfps.mpfb1) )
378 MPConfigDefault( defaultConfig );
380 MPConfigTableHeader( mpfps.pap );
382 /* do a dmesg output */
393 * set PHYSICAL address of MP floating pointer structure
395 #define NEXT(X) ((X) += 4)
397 apic_probe( vm_offset_t* paddr, int* where )
400 * c rewrite of apic_probe() by Jack F. Vogel
406 u_int buffer[ BIOS_SIZE / sizeof( int ) ];
411 /* search Extended Bios Data Area, if present */
413 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
414 seekEntry( (vm_offset_t)EBDA_POINTER );
415 readEntry( &segment, 2 );
416 if ( segment ) { /* search EBDA */
417 target = (vm_offset_t)segment << 4;
419 printf( "found, searching EBDA @ 0x%08x\n", target );
421 readEntry( buffer, ONE_KBYTE );
423 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) {
424 if ( buffer[ x ] == MP_SIG ) {
426 *paddr = (x * sizeof( unsigned int )) + target;
433 printf( "NOT found\n" );
436 /* read CMOS for real top of mem */
437 seekEntry( (vm_offset_t)TOPOFMEM_POINTER );
438 readEntry( &segment, 2 );
439 --segment; /* less ONE_KBYTE */
440 target = segment * 1024;
442 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
445 readEntry( buffer, ONE_KBYTE );
447 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) {
448 if ( buffer[ x ] == MP_SIG ) {
450 *paddr = (x * sizeof( unsigned int )) + target;
455 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
456 if ( target != (DEFAULT_TOPOFMEM - 1024)) {
457 target = (DEFAULT_TOPOFMEM - 1024);
459 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
460 target, (target / 1024) );
462 readEntry( buffer, ONE_KBYTE );
464 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) {
465 if ( buffer[ x ] == MP_SIG ) {
467 *paddr = (x * sizeof( unsigned int )) + target;
473 /* search the BIOS */
475 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
476 seekEntry( BIOS_BASE );
477 readEntry( buffer, BIOS_SIZE );
479 for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) {
480 if ( buffer[ x ] == MP_SIG ) {
482 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
487 /* search the extended BIOS */
489 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
490 seekEntry( BIOS_BASE2 );
491 readEntry( buffer, BIOS_SIZE );
493 for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) {
494 if ( buffer[ x ] == MP_SIG ) {
496 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
502 /* search additional memory */
503 target = GROPE_AREA1;
505 printf( " groping memory @ 0x%08x\n", target );
507 readEntry( buffer, GROPE_SIZE );
509 for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) {
510 if ( buffer[ x ] == MP_SIG ) {
512 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
517 target = GROPE_AREA2;
519 printf( " groping memory @ 0x%08x\n", target );
521 readEntry( buffer, GROPE_SIZE );
523 for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) {
524 if ( buffer[ x ] == MP_SIG ) {
526 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
533 *paddr = (vm_offset_t)0;
541 MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps )
544 /* read in mpfps structure*/
546 readEntry( mpfps, sizeof( mpfps_t ) );
548 /* show its contents */
549 printf( "MP Floating Pointer Structure:\n\n" );
551 printf( " location:\t\t\t" );
558 printf( "BIOS base memory\n" );
561 printf( "DEFAULT base memory (639K)\n" );
567 printf( "Extended BIOS\n" );
571 printf( "NOT found!\n" );
574 printf( "BOGUS!\n" );
577 printf( " physical address:\t\t0x%08x\n", paddr );
579 printf( " signature:\t\t\t'" );
580 pnstr( mpfps->signature, 4 );
583 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 );
584 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev );
585 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum );
587 /* bits 0:6 are RESERVED */
588 if ( mpfps->mpfb2 & 0x7f ) {
589 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
593 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & 0x80) ?
594 "PIC" : "Virtual Wire" );
596 /* MP feature bytes 3-5 are expected to be ZERO */
598 printf( " warning, MP feature byte 3 NONZERO!\n" );
600 printf( " warning, MP feature byte 4 NONZERO!\n" );
602 printf( " warning, MP feature byte 5 NONZERO!\n" );
610 MPConfigDefault( int featureByte )
612 printf( " MP default config type: %d\n\n", featureByte );
613 switch ( featureByte ) {
615 printf( " bus: ISA, APIC: 82489DX\n" );
618 printf( " bus: EISA, APIC: 82489DX\n" );
621 printf( " bus: EISA, APIC: 82489DX\n" );
624 printf( " bus: MCA, APIC: 82489DX\n" );
627 printf( " bus: ISA+PCI, APIC: Integrated\n" );
630 printf( " bus: EISA+PCI, APIC: Integrated\n" );
633 printf( " bus: MCA+PCI, APIC: Integrated\n" );
636 printf( " future type\n" );
640 switch ( featureByte ) {
653 printf( " future type\n" );
667 MPConfigTableHeader( void* pap )
675 int oldtype, entrytype;
678 printf( "MP Configuration Table Header MISSING!\n" );
682 /* convert physical address to virtual address */
683 paddr = (vm_offset_t)pap;
685 /* read in cth structure */
687 readEntry( &cth, sizeof( cth ) );
689 printf( "MP Config Table Header:\n\n" );
691 printf( " physical address:\t\t0x%08x\n", pap );
693 printf( " signature:\t\t\t'" );
694 pnstr( cth.signature, 4 );
697 printf( " base table length:\t\t%d\n", cth.base_table_length );
699 printf( " version:\t\t\t1.%1d\n", cth.spec_rev );
700 printf( " checksum:\t\t\t0x%02x\n", cth.checksum );
702 printf( " OEM ID:\t\t\t'" );
703 pnstr( cth.oem_id, 8 );
706 printf( " Product ID:\t\t\t'" );
707 pnstr( cth.product_id, 12 );
710 printf( " OEM table pointer:\t\t0x%08x\n", cth.oem_table_pointer );
711 printf( " OEM table size:\t\t%d\n", cth.oem_table_size );
713 printf( " entry count:\t\t\t%d\n", cth.entry_count );
715 printf( " local APIC address:\t\t0x%08x\n", cth.apic_address );
717 printf( " extended table length:\t%d\n", cth.extended_table_length );
718 printf( " extended table checksum:\t%d\n", cth.extended_table_checksum );
720 totalSize = cth.base_table_length - sizeof( struct MPCTH );
721 count = cth.entry_count;
725 printf( "MP Config Base Table Entries:\n\n" );
727 /* initialze tables */
728 for ( x = 0; x < 16; ++x ) {
729 busses[ x ] = apics[ x ] = 0xff;
738 for (c = count; c; c--) {
739 entrytype = readType();
740 if (entrytype != oldtype)
742 if (entrytype < oldtype)
743 printf("MPTABLE OUT OF ORDER!\n");
747 printf( "Processors:\tAPIC ID\tVersion\tState"
748 "\t\tFamily\tModel\tStep\tFlags\n" );
755 printf( "Bus:\t\tBus ID\tType\n" );
762 printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
769 printf( "I/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
776 printf( "Local Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
782 printf("MPTABLE HOSED! record type = %d\n", entrytype);
788 #if defined( EXTENDED_PROCESSING_READY )
789 /* process any extended data */
790 if ( (totalSize = cth.extended_table_length) ) {
793 printf( "MP Config Extended Table Entries:\n\n" );
795 while ( totalSize > 0 ) {
796 switch ( type = readType() ) {
807 printf( "Extended Table HOSED!\n" );
811 totalSize -= extendedtableEntryTypes[ type-128 ].length;
814 #endif /* EXTENDED_PROCESSING_READY */
816 /* process any OEM data */
817 if ( cth.oem_table_pointer && (cth.oem_table_size > 0) ) {
818 #if defined( OEM_PROCESSING_READY )
819 # error your on your own here!
820 /* convert OEM table pointer to virtual address */
821 poemtp = (vm_offset_t)cth.oem_table_pointer;
823 /* read in oem table structure */
824 if ( (oemdata = (void*)malloc( cth.oem_table_size )) == NULL )
825 err( 1, "oem malloc" );
828 readEntry( oemdata, cth.oem_table_size );
834 printf( "\nyou need to modify the source to handle OEM data!\n\n" );
835 #endif /* OEM_PROCESSING_READY */
840 #if defined( RAW_DUMP )
843 u_char dumpbuf[ 4096 ];
845 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR );
847 readEntry( dumpbuf, 1024 );
848 write( ofd, dumpbuf, 1024 );
851 #endif /* RAW_DUMP */
863 if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) )
864 err( 1, "type read; pfd: %d", pfd );
866 if ( lseek( pfd, -1, SEEK_CUR ) < 0 )
867 err( 1, "type seek" );
877 seekEntry( vm_offset_t addr )
879 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
880 err( 1, "%s seek", _PATH_MEM );
888 readEntry( void* entry, int size )
890 if ( read( pfd, entry, size ) != size )
891 err( 1, "readEntry" );
896 processorEntry( void )
900 /* read it into local memory */
901 readEntry( &entry, sizeof( entry ) );
906 printf( "\t\t%2d", entry.apicID );
907 printf( "\t 0x%2x", entry.apicVersion );
910 (entry.cpuFlags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
911 (entry.cpuFlags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
913 printf( "\t %d\t %d\t %d",
914 (entry.cpuSignature >> 8) & 0x0f,
915 (entry.cpuSignature >> 4) & 0x0f,
916 entry.cpuSignature & 0x0f );
918 printf( "\t 0x%04x\n", entry.featureFlags );
926 lookupBusType( char* name )
930 for ( x = 0; x < MAX_BUSTYPE; ++x )
931 if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
932 return busTypeTable[ x ].type;
934 return UNKNOWN_BUSTYPE;
946 /* read it into local memory */
947 readEntry( &entry, sizeof( entry ) );
952 printf( "\t\t%2d", entry.busID );
953 printf( "\t " ); pnstr( entry.busType, 6 ); printf( "\n" );
955 for ( x = 0; x < 6; ++x ) {
956 if ( (c = entry.busType[ x ]) == ' ' )
961 busses[ entry.busID ] = lookupBusType( name );
970 /* read it into local memory */
971 readEntry( &entry, sizeof( entry ) );
976 printf( "\t\t%2d", entry.apicID );
977 printf( "\t 0x%02x", entry.apicVersion );
979 (entry.apicFlags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
980 printf( "\t\t 0x%x\n", entry.apicAddress );
982 apics[ entry.apicID ] = entry.apicID;
987 "INT", "NMI", "SMI", "ExtINT"
990 char* polarityMode[] = {
991 "conforms", "active-hi", "reserved", "active-lo"
993 char* triggerMode[] = {
994 "conforms", "edge", "reserved", "level"
1002 /* read it into local memory */
1003 readEntry( &entry, sizeof( entry ) );
1006 if ( (int)entry.type == 3 )
1009 printf( "\t\t%s", intTypes[ (int)entry.intType ] );
1011 printf( "\t%9s", polarityMode[ (int)entry.intFlags & 0x03 ] );
1012 printf( "%12s", triggerMode[ ((int)entry.intFlags >> 2) & 0x03 ] );
1014 printf( "\t %5d", (int)entry.srcBusID );
1015 if ( busses[ (int)entry.srcBusID ] == PCI )
1017 ((int)entry.srcBusIRQ >> 2) & 0x1f,
1018 ((int)entry.srcBusIRQ & 0x03) + 'A' );
1020 printf( "\t %3d", (int)entry.srcBusIRQ );
1021 printf( "\t %6d", (int)entry.dstApicID );
1022 printf( "\t %3d\n", (int)entry.dstApicINT );
1031 /* read it into local memory */
1032 readEntry( &entry, sizeof( entry ) );
1034 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1035 printf( " bus ID: %d", entry.busID );
1036 printf( " address type: " );
1037 switch ( entry.addressType ) {
1039 printf( "I/O address\n" );
1042 printf( "memory address\n" );
1045 printf( "prefetch address\n" );
1048 printf( "UNKNOWN type\n" );
1052 printf( " address base: 0x%qx\n", entry.addressBase );
1053 printf( " address range: 0x%qx\n", entry.addressLength );
1062 /* read it into local memory */
1063 readEntry( &entry, sizeof( entry ) );
1065 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1066 printf( " bus ID: %d", entry.busID );
1067 printf( " bus info: 0x%02x", entry.busInfo );
1068 printf( " parent bus ID: %d\n", entry.busParent );
1077 /* read it into local memory */
1078 readEntry( &entry, sizeof( entry ) );
1080 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1081 printf( " bus ID: %d", entry.busID );
1082 printf( " address modifier: %s\n", (entry.addressMod & 0x01) ?
1083 "subtract" : "add" );
1084 printf( " predefined range: 0x%08x\n", entry.predefinedRange );
1096 printf( "dmesg output:\n\n" );
1106 pnstr( char* s, int c )
1108 char string[ MAXPNSTR + 1 ];
1112 strncpy( string, s, c );
1114 printf( "%s", string );