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[] =
36 * this will cause the raw mp table to be dumped to /tmp/mpdump
41 #define MP_SIG 0x5f504d5f /* _MP_ */
42 #define EXTENDED_PROCESSING_READY
43 #define OEM_PROCESSING_READY_NOT
45 #include <sys/param.h>
55 "\n-------------------------------------------------------------------------------\n"
58 "\n===============================================================================\n"
60 /* EBDA is @ 40:0e in real-mode terms */
61 #define EBDA_POINTER 0x040e /* location of EBDA pointer */
63 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
64 #define TOPOFMEM_POINTER 0x0413 /* BIOS: base memory size */
66 #define DEFAULT_TOPOFMEM 0xa0000
68 #define BIOS_BASE 0xf0000
69 #define BIOS_BASE2 0xe0000
70 #define BIOS_SIZE 0x10000
71 #define ONE_KBYTE 1024
73 #define GROPE_AREA1 0x80000
74 #define GROPE_AREA2 0x90000
75 #define GROPE_SIZE 0x10000
77 #define PROCENTRY_FLAG_EN 0x01
78 #define PROCENTRY_FLAG_BP 0x02
79 #define IOAPICENTRY_FLAG_EN 0x01
91 UNKNOWN_BUSTYPE = 0xff
94 typedef struct BUSTYPENAME {
99 static const busTypeName busTypeTable[] =
102 { CBUSII, "CBUSII" },
104 { UNKNOWN_BUSTYPE, "---" },
105 { UNKNOWN_BUSTYPE, "---" },
107 { UNKNOWN_BUSTYPE, "---" },
108 { UNKNOWN_BUSTYPE, "---" },
109 { UNKNOWN_BUSTYPE, "---" },
110 { UNKNOWN_BUSTYPE, "---" },
111 { UNKNOWN_BUSTYPE, "---" },
112 { UNKNOWN_BUSTYPE, "---" },
114 { UNKNOWN_BUSTYPE, "---" },
115 { UNKNOWN_BUSTYPE, "---" },
116 { UNKNOWN_BUSTYPE, "---" },
117 { UNKNOWN_BUSTYPE, "---" },
118 { UNKNOWN_BUSTYPE, "---" },
119 { UNKNOWN_BUSTYPE, "---" }
122 static const char *whereStrings[] = {
123 "Extended BIOS Data Area",
124 "BIOS top of memory",
125 "Default top of memory",
132 typedef struct TABLE_ENTRY {
138 static const tableEntry extendedtableEntryTypes[] =
140 { 128, 20, "System Address Space" },
141 { 129, 8, "Bus Hierarchy" },
142 { 130, 8, "Compatibility Bus Address" }
145 /* MP Floating Pointer Structure */
146 typedef struct MPFPS {
159 /* MP Configuration Table Header */
160 typedef struct MPCTH {
162 u_short base_table_length;
166 u_char product_id[ 12 ];
167 u_int32_t oem_table_pointer;
168 u_short oem_table_size;
170 u_int32_t apic_address;
171 u_short extended_table_length;
172 u_char extended_table_checksum;
177 typedef struct PROCENTRY {
182 u_int32_t cpuSignature;
183 u_int32_t featureFlags;
188 typedef struct BUSENTRY {
194 typedef struct IOAPICENTRY {
199 u_int32_t apicAddress;
202 typedef struct INTENTRY {
214 * extended entry type structures
217 typedef struct SASENTRY {
222 u_int64_t addressBase;
223 u_int64_t addressLength;
224 } __attribute__((__packed__)) SasEntry;
227 typedef struct BHDENTRY {
233 u_char reserved[ 3 ];
237 typedef struct CBASMENTRY {
242 u_int predefinedRange;
247 static void apic_probe( u_int32_t* paddr, int* where );
249 static void MPConfigDefault( int featureByte );
251 static void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfps );
252 static void MPConfigTableHeader( u_int32_t pap );
254 static int readType( void );
255 static void seekEntry( u_int32_t addr );
256 static void readEntry( void* entry, int size );
258 static void processorEntry( void );
259 static void busEntry( void );
260 static void ioApicEntry( void );
261 static void intEntry( void );
263 static void sasEntry( void );
264 static void bhdEntry( void );
265 static void cbasmEntry( void );
267 static void doDmesg( void );
268 static void pnstr( char* s, int c );
271 static int pfd; /* physical /dev/mem fd */
273 static int busses[256];
274 static int apics[256];
288 fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
296 main( int argc, char *argv[] )
305 /* announce ourselves */
308 printf( "MPTable\n" );
310 while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
313 if ( strcmp( optarg, "mesg") == 0 )
319 if ( strcmp( optarg, "elp") == 0 )
323 if ( strcmp( optarg, "rope") == 0 )
327 if ( strcmp( optarg, "erbose") == 0 )
339 /* open physical memory for access to MP structures */
340 if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
341 err( 1, "mem open" );
343 /* probe for MP structures */
344 apic_probe( &paddr, &where );
346 fprintf( stderr, "\n MP FPS NOT found,\n" );
347 fprintf( stderr, " suggest trying -grope option!!!\n\n" );
352 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
353 whereStrings[ where - 1 ], paddr );
357 /* analyze the MP Floating Pointer Structure */
358 MPFloatingPointer( paddr, where, &mpfps );
362 /* check whether an MP config table exists */
363 if ( (defaultConfig = mpfps.mpfb1) )
364 MPConfigDefault( defaultConfig );
366 MPConfigTableHeader( mpfps.pap );
368 /* do a dmesg output */
379 * set PHYSICAL address of MP floating pointer structure
381 #define NEXT(X) ((X) += 4)
383 apic_probe( u_int32_t* paddr, int* where )
386 * c rewrite of apic_probe() by Jack F. Vogel
392 u_int buffer[ BIOS_SIZE / sizeof( int ) ];
397 /* search Extended Bios Data Area, if present */
399 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
400 seekEntry( (u_int32_t)EBDA_POINTER );
401 readEntry( &segment, 2 );
402 if ( segment ) { /* search EBDA */
403 target = (u_int32_t)segment << 4;
405 printf( "found, searching EBDA @ 0x%08x\n", target );
407 readEntry( buffer, ONE_KBYTE );
409 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
410 if ( buffer[ x ] == MP_SIG ) {
412 *paddr = (x * sizeof( unsigned int )) + target;
419 printf( "NOT found\n" );
422 /* read CMOS for real top of mem */
423 seekEntry( (u_int32_t)TOPOFMEM_POINTER );
424 readEntry( &segment, 2 );
425 --segment; /* less ONE_KBYTE */
426 target = segment * 1024;
428 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
431 readEntry( buffer, ONE_KBYTE );
433 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
434 if ( buffer[ x ] == MP_SIG ) {
436 *paddr = (x * sizeof( unsigned int )) + target;
441 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
442 if ( target != (DEFAULT_TOPOFMEM - 1024)) {
443 target = (DEFAULT_TOPOFMEM - 1024);
445 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
446 target, (target / 1024) );
448 readEntry( buffer, ONE_KBYTE );
450 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
451 if ( buffer[ x ] == MP_SIG ) {
453 *paddr = (x * sizeof( unsigned int )) + target;
459 /* search the BIOS */
461 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
462 seekEntry( BIOS_BASE );
463 readEntry( buffer, BIOS_SIZE );
465 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
466 if ( buffer[ x ] == MP_SIG ) {
468 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
473 /* search the extended BIOS */
475 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
476 seekEntry( BIOS_BASE2 );
477 readEntry( buffer, BIOS_SIZE );
479 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
480 if ( buffer[ x ] == MP_SIG ) {
482 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
488 /* search additional memory */
489 target = GROPE_AREA1;
491 printf( " groping memory @ 0x%08x\n", target );
493 readEntry( buffer, GROPE_SIZE );
495 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
496 if ( buffer[ x ] == MP_SIG ) {
498 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
503 target = GROPE_AREA2;
505 printf( " groping memory @ 0x%08x\n", target );
507 readEntry( buffer, GROPE_SIZE );
509 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
510 if ( buffer[ x ] == MP_SIG ) {
512 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
519 *paddr = (u_int32_t)0;
527 MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfps )
530 /* read in mpfps structure*/
532 readEntry( mpfps, sizeof( mpfps_t ) );
534 /* show its contents */
535 printf( "MP Floating Pointer Structure:\n\n" );
537 printf( " location:\t\t\t" );
544 printf( "BIOS base memory\n" );
547 printf( "DEFAULT base memory (639K)\n" );
553 printf( "Extended BIOS\n" );
557 printf( "NOT found!\n" );
560 printf( "BOGUS!\n" );
563 printf( " physical address:\t\t0x%08x\n", paddr );
565 printf( " signature:\t\t\t'" );
566 pnstr( mpfps->signature, 4 );
569 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 );
570 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev );
571 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum );
573 /* bits 0:6 are RESERVED */
574 if ( mpfps->mpfb2 & 0x7f ) {
575 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
579 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & 0x80) ?
580 "PIC" : "Virtual Wire" );
582 /* MP feature bytes 3-5 are expected to be ZERO */
584 printf( " warning, MP feature byte 3 NONZERO!\n" );
586 printf( " warning, MP feature byte 4 NONZERO!\n" );
588 printf( " warning, MP feature byte 5 NONZERO!\n" );
596 MPConfigDefault( int featureByte )
598 printf( " MP default config type: %d\n\n", featureByte );
599 switch ( featureByte ) {
601 printf( " bus: ISA, APIC: 82489DX\n" );
604 printf( " bus: EISA, APIC: 82489DX\n" );
607 printf( " bus: EISA, APIC: 82489DX\n" );
610 printf( " bus: MCA, APIC: 82489DX\n" );
613 printf( " bus: ISA+PCI, APIC: Integrated\n" );
616 printf( " bus: EISA+PCI, APIC: Integrated\n" );
619 printf( " bus: MCA+PCI, APIC: Integrated\n" );
622 printf( " future type\n" );
626 switch ( featureByte ) {
639 printf( " future type\n" );
653 MPConfigTableHeader( u_int32_t pap )
661 int oldtype, entrytype;
664 printf( "MP Configuration Table Header MISSING!\n" );
668 /* convert physical address to virtual address */
671 /* read in cth structure */
673 readEntry( &cth, sizeof( cth ) );
675 printf( "MP Config Table Header:\n\n" );
677 printf( " physical address:\t\t0x%08x\n", pap );
679 printf( " signature:\t\t\t'" );
680 pnstr( cth.signature, 4 );
683 printf( " base table length:\t\t%d\n", cth.base_table_length );
685 printf( " version:\t\t\t1.%1d\n", cth.spec_rev );
686 printf( " checksum:\t\t\t0x%02x\n", cth.checksum );
688 printf( " OEM ID:\t\t\t'" );
689 pnstr( cth.oem_id, 8 );
692 printf( " Product ID:\t\t\t'" );
693 pnstr( cth.product_id, 12 );
696 printf( " OEM table pointer:\t\t0x%08x\n", cth.oem_table_pointer );
697 printf( " OEM table size:\t\t%d\n", cth.oem_table_size );
699 printf( " entry count:\t\t\t%d\n", cth.entry_count );
701 printf( " local APIC address:\t\t0x%08x\n", cth.apic_address );
703 printf( " extended table length:\t%d\n", cth.extended_table_length );
704 printf( " extended table checksum:\t%d\n", cth.extended_table_checksum );
706 totalSize = cth.base_table_length - sizeof( struct MPCTH );
707 count = cth.entry_count;
711 printf( "MP Config Base Table Entries:\n\n" );
713 /* initialize tables */
714 for (x = 0; x < (int)nitems(busses); x++)
717 for (x = 0; x < (int)nitems(apics); x++)
726 for (c = count; c; c--) {
727 entrytype = readType();
728 if (entrytype != oldtype)
730 if (entrytype < oldtype)
731 printf("MPTABLE OUT OF ORDER!\n");
735 printf( "Processors:\tAPIC ID\tVersion\tState"
736 "\t\tFamily\tModel\tStep\tFlags\n" );
743 printf( "Bus:\t\tBus ID\tType\n" );
750 printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
757 printf( "I/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
764 printf( "Local Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
770 printf("MPTABLE HOSED! record type = %d\n", entrytype);
776 #if defined( EXTENDED_PROCESSING_READY )
777 /* process any extended data */
778 if ( (totalSize = cth.extended_table_length) ) {
781 printf( "MP Config Extended Table Entries:\n\n" );
783 while ( totalSize > 0 ) {
784 switch ( type = readType() ) {
795 printf( "Extended Table HOSED!\n" );
799 totalSize -= extendedtableEntryTypes[ type-128 ].length;
802 #endif /* EXTENDED_PROCESSING_READY */
804 /* process any OEM data */
805 if ( cth.oem_table_pointer && (cth.oem_table_size > 0) ) {
806 #if defined( OEM_PROCESSING_READY )
807 # error your on your own here!
808 /* convert OEM table pointer to virtual address */
809 poemtp = (u_int32_t)cth.oem_table_pointer;
811 /* read in oem table structure */
812 if ( (oemdata = (void*)malloc( cth.oem_table_size )) == NULL )
813 err( 1, "oem malloc" );
816 readEntry( oemdata, cth.oem_table_size );
822 printf( "\nyou need to modify the source to handle OEM data!\n\n" );
823 #endif /* OEM_PROCESSING_READY */
828 #if defined( RAW_DUMP )
831 u_char dumpbuf[ 4096 ];
833 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
835 readEntry( dumpbuf, 1024 );
836 write( ofd, dumpbuf, 1024 );
839 #endif /* RAW_DUMP */
851 if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) )
852 err( 1, "type read; pfd: %d", pfd );
854 if ( lseek( pfd, -1, SEEK_CUR ) < 0 )
855 err( 1, "type seek" );
865 seekEntry( u_int32_t addr )
867 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
868 err( 1, "%s seek", _PATH_MEM );
876 readEntry( void* entry, int size )
878 if ( read( pfd, entry, size ) != size )
879 err( 1, "readEntry" );
884 processorEntry( void )
888 /* read it into local memory */
889 readEntry( &entry, sizeof( entry ) );
894 printf( "\t\t%2d", entry.apicID );
895 printf( "\t 0x%2x", entry.apicVersion );
898 (entry.cpuFlags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
899 (entry.cpuFlags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
901 printf( "\t %d\t %d\t %d",
902 (entry.cpuSignature >> 8) & 0x0f,
903 (entry.cpuSignature >> 4) & 0x0f,
904 entry.cpuSignature & 0x0f );
906 printf( "\t 0x%04x\n", entry.featureFlags );
914 lookupBusType( char* name )
918 for ( x = 0; x < MAX_BUSTYPE; ++x )
919 if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
920 return busTypeTable[ x ].type;
922 return UNKNOWN_BUSTYPE;
934 /* read it into local memory */
935 readEntry( &entry, sizeof( entry ) );
940 printf( "\t\t%2d", entry.busID );
941 printf( "\t " ); pnstr( entry.busType, 6 ); printf( "\n" );
943 for ( x = 0; x < 6; ++x ) {
944 if ( (c = entry.busType[ x ]) == ' ' )
949 busses[ entry.busID ] = lookupBusType( name );
958 /* read it into local memory */
959 readEntry( &entry, sizeof( entry ) );
964 printf( "\t\t%2d", entry.apicID );
965 printf( "\t 0x%02x", entry.apicVersion );
967 (entry.apicFlags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
968 printf( "\t\t 0x%x\n", entry.apicAddress );
970 apics[ entry.apicID ] = entry.apicID;
974 static const char *intTypes[] = {
975 "INT", "NMI", "SMI", "ExtINT"
978 static const char *polarityMode[] = {
979 "conforms", "active-hi", "reserved", "active-lo"
981 static const char *triggerMode[] = {
982 "conforms", "edge", "reserved", "level"
990 /* read it into local memory */
991 readEntry( &entry, sizeof( entry ) );
994 if ( (int)entry.type == 3 )
997 printf( "\t\t%s", intTypes[ (int)entry.intType ] );
999 printf( "\t%9s", polarityMode[ (int)entry.intFlags & 0x03 ] );
1000 printf( "%12s", triggerMode[ ((int)entry.intFlags >> 2) & 0x03 ] );
1002 printf( "\t %5d", (int)entry.srcBusID );
1003 if ( busses[ (int)entry.srcBusID ] == PCI )
1005 ((int)entry.srcBusIRQ >> 2) & 0x1f,
1006 ((int)entry.srcBusIRQ & 0x03) + 'A' );
1008 printf( "\t %3d", (int)entry.srcBusIRQ );
1009 printf( "\t %6d", (int)entry.dstApicID );
1010 printf( "\t %3d\n", (int)entry.dstApicINT );
1019 /* read it into local memory */
1020 readEntry( &entry, sizeof( entry ) );
1022 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1023 printf( " bus ID: %d", entry.busID );
1024 printf( " address type: " );
1025 switch ( entry.addressType ) {
1027 printf( "I/O address\n" );
1030 printf( "memory address\n" );
1033 printf( "prefetch address\n" );
1036 printf( "UNKNOWN type\n" );
1040 printf( " address base: 0x%llx\n", (long long)entry.addressBase );
1041 printf( " address range: 0x%llx\n", (long long)entry.addressLength );
1050 /* read it into local memory */
1051 readEntry( &entry, sizeof( entry ) );
1053 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1054 printf( " bus ID: %d", entry.busID );
1055 printf( " bus info: 0x%02x", entry.busInfo );
1056 printf( " parent bus ID: %d\n", entry.busParent );
1065 /* read it into local memory */
1066 readEntry( &entry, sizeof( entry ) );
1068 printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
1069 printf( " bus ID: %d", entry.busID );
1070 printf( " address modifier: %s\n", (entry.addressMod & 0x01) ?
1071 "subtract" : "add" );
1072 printf( " predefined range: 0x%08x\n", entry.predefinedRange );
1084 printf( "dmesg output:\n\n" );
1094 pnstr( char* s, int c )
1096 char string[ MAXPNSTR + 1 ];
1100 strncpy( string, s, c );
1102 printf( "%s", string );