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>
47 #include <x86/mptable.h>
58 "\n-------------------------------------------------------------------------------\n"
61 "\n===============================================================================\n"
63 /* EBDA is @ 40:0e in real-mode terms */
64 #define EBDA_POINTER 0x040e /* location of EBDA pointer */
66 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
67 #define TOPOFMEM_POINTER 0x0413 /* BIOS: base memory size */
69 #define DEFAULT_TOPOFMEM 0xa0000
71 #define BIOS_BASE 0xf0000
72 #define BIOS_BASE2 0xe0000
73 #define BIOS_SIZE 0x10000
74 #define ONE_KBYTE 1024
76 #define GROPE_AREA1 0x80000
77 #define GROPE_AREA2 0x90000
78 #define GROPE_SIZE 0x10000
82 typedef struct BUSTYPENAME {
87 static const busTypeName busTypeTable[] =
92 { UNKNOWN_BUSTYPE, "---" },
93 { UNKNOWN_BUSTYPE, "---" },
95 { UNKNOWN_BUSTYPE, "---" },
96 { UNKNOWN_BUSTYPE, "---" },
97 { UNKNOWN_BUSTYPE, "---" },
98 { UNKNOWN_BUSTYPE, "---" },
99 { UNKNOWN_BUSTYPE, "---" },
100 { UNKNOWN_BUSTYPE, "---" },
102 { UNKNOWN_BUSTYPE, "---" },
103 { UNKNOWN_BUSTYPE, "---" },
104 { UNKNOWN_BUSTYPE, "---" },
105 { UNKNOWN_BUSTYPE, "---" },
106 { UNKNOWN_BUSTYPE, "---" },
107 { UNKNOWN_BUSTYPE, "---" }
110 static const char *whereStrings[] = {
111 "Extended BIOS Data Area",
112 "BIOS top of memory",
113 "Default top of memory",
120 static void apic_probe( u_int32_t* paddr, int* where );
122 static void MPConfigDefault( int featureByte );
124 static void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp );
125 static void MPConfigTableHeader( u_int32_t pap );
127 static void seekEntry( u_int32_t addr );
128 static void readEntry( void* entry, int size );
129 static void *mapEntry( u_int32_t addr, int size );
131 static void processorEntry( proc_entry_ptr entry );
132 static void busEntry( bus_entry_ptr entry );
133 static void ioApicEntry( io_apic_entry_ptr entry );
134 static void intEntry( int_entry_ptr entry );
136 static void sasEntry( sas_entry_ptr entry );
137 static void bhdEntry( bhd_entry_ptr entry );
138 static void cbasmEntry( cbasm_entry_ptr entry );
140 static void doDmesg( void );
141 static void pnstr( char* s, int c );
144 static int pfd; /* physical /dev/mem fd */
146 static int busses[256];
147 static int apics[256];
161 fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
169 main( int argc, char *argv[] )
178 /* announce ourselves */
181 printf( "MPTable\n" );
183 while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
186 if ( strcmp( optarg, "mesg") == 0 )
192 if ( strcmp( optarg, "elp") == 0 )
196 if ( strcmp( optarg, "rope") == 0 )
200 if ( strcmp( optarg, "erbose") == 0 )
212 /* open physical memory for access to MP structures */
213 if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
214 err( 1, "mem open" );
216 /* probe for MP structures */
217 apic_probe( &paddr, &where );
219 fprintf( stderr, "\n MP FPS NOT found,\n" );
221 fprintf( stderr, " suggest trying -grope option!!!\n\n" );
226 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
227 whereStrings[ where - 1 ], paddr );
231 /* analyze the MP Floating Pointer Structure */
232 MPFloatingPointer( paddr, where, &mpfps );
236 /* check whether an MP config table exists */
237 if ( (defaultConfig = mpfps->config_type) )
238 MPConfigDefault( defaultConfig );
240 MPConfigTableHeader( mpfps->pap );
242 /* do a dmesg output */
253 * set PHYSICAL address of MP floating pointer structure
255 #define NEXT(X) ((X) += 4)
257 apic_probe( u_int32_t* paddr, int* where )
260 * c rewrite of apic_probe() by Jack F. Vogel
266 u_int buffer[ BIOS_SIZE / sizeof( int ) ];
271 /* search Extended Bios Data Area, if present */
273 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
274 seekEntry( (u_int32_t)EBDA_POINTER );
275 readEntry( &segment, 2 );
276 if ( segment ) { /* search EBDA */
277 target = (u_int32_t)segment << 4;
279 printf( "found, searching EBDA @ 0x%08x\n", target );
281 readEntry( buffer, ONE_KBYTE );
283 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
284 if ( buffer[ x ] == MP_SIG ) {
286 *paddr = (x * sizeof( unsigned int )) + target;
293 printf( "NOT found\n" );
296 /* read CMOS for real top of mem */
297 seekEntry( (u_int32_t)TOPOFMEM_POINTER );
298 readEntry( &segment, 2 );
299 --segment; /* less ONE_KBYTE */
300 target = segment * 1024;
302 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
305 readEntry( buffer, ONE_KBYTE );
307 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
308 if ( buffer[ x ] == MP_SIG ) {
310 *paddr = (x * sizeof( unsigned int )) + target;
315 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
316 if ( target != (DEFAULT_TOPOFMEM - 1024)) {
317 target = (DEFAULT_TOPOFMEM - 1024);
319 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
320 target, (target / 1024) );
322 readEntry( buffer, ONE_KBYTE );
324 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
325 if ( buffer[ x ] == MP_SIG ) {
327 *paddr = (x * sizeof( unsigned int )) + target;
333 /* search the BIOS */
335 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
336 seekEntry( BIOS_BASE );
337 readEntry( buffer, BIOS_SIZE );
339 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
340 if ( buffer[ x ] == MP_SIG ) {
342 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
347 /* search the extended BIOS */
349 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
350 seekEntry( BIOS_BASE2 );
351 readEntry( buffer, BIOS_SIZE );
353 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
354 if ( buffer[ x ] == MP_SIG ) {
356 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
362 /* search additional memory */
363 target = GROPE_AREA1;
365 printf( " groping memory @ 0x%08x\n", target );
367 readEntry( buffer, GROPE_SIZE );
369 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
370 if ( buffer[ x ] == MP_SIG ) {
372 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
377 target = GROPE_AREA2;
379 printf( " groping memory @ 0x%08x\n", target );
381 readEntry( buffer, GROPE_SIZE );
383 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
384 if ( buffer[ x ] == MP_SIG ) {
386 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
393 *paddr = (u_int32_t)0;
401 MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp )
405 /* map in mpfps structure*/
406 *mpfpsp = mpfps = mapEntry( paddr, sizeof( *mpfps ) );
408 /* show its contents */
409 printf( "MP Floating Pointer Structure:\n\n" );
411 printf( " location:\t\t\t" );
418 printf( "BIOS base memory\n" );
421 printf( "DEFAULT base memory (639K)\n" );
427 printf( "Extended BIOS\n" );
431 printf( "NOT found!\n" );
434 printf( "BOGUS!\n" );
437 printf( " physical address:\t\t0x%08x\n", paddr );
439 printf( " signature:\t\t\t'" );
440 pnstr( mpfps->signature, 4 );
443 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 );
444 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev );
445 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum );
447 /* bits 0:6 are RESERVED */
448 if ( mpfps->mpfb2 & 0x7f ) {
449 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
453 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & MPFB2_IMCR_PRESENT) ?
454 "PIC" : "Virtual Wire" );
456 /* MP feature bytes 3-5 are expected to be ZERO */
458 printf( " warning, MP feature byte 3 NONZERO!\n" );
460 printf( " warning, MP feature byte 4 NONZERO!\n" );
462 printf( " warning, MP feature byte 5 NONZERO!\n" );
470 MPConfigDefault( int featureByte )
472 printf( " MP default config type: %d\n\n", featureByte );
473 switch ( featureByte ) {
475 printf( " bus: ISA, APIC: 82489DX\n" );
478 printf( " bus: EISA, APIC: 82489DX\n" );
481 printf( " bus: EISA, APIC: 82489DX\n" );
484 printf( " bus: MCA, APIC: 82489DX\n" );
487 printf( " bus: ISA+PCI, APIC: Integrated\n" );
490 printf( " bus: EISA+PCI, APIC: Integrated\n" );
493 printf( " bus: MCA+PCI, APIC: Integrated\n" );
496 printf( " future type\n" );
500 switch ( featureByte ) {
513 printf( " future type\n" );
527 MPConfigTableHeader( u_int32_t pap )
533 int oldtype, entrytype;
537 printf( "MP Configuration Table Header MISSING!\n" );
541 /* map in cth structure */
542 cth = mapEntry( pap, sizeof( *cth ) );
544 printf( "MP Config Table Header:\n\n" );
546 printf( " physical address:\t\t0x%08x\n", pap );
548 printf( " signature:\t\t\t'" );
549 pnstr( cth->signature, 4 );
552 printf( " base table length:\t\t%d\n", cth->base_table_length );
554 printf( " version:\t\t\t1.%1d\n", cth->spec_rev );
555 printf( " checksum:\t\t\t0x%02x\n", cth->checksum );
557 printf( " OEM ID:\t\t\t'" );
558 pnstr( cth->oem_id, 8 );
561 printf( " Product ID:\t\t\t'" );
562 pnstr( cth->product_id, 12 );
565 printf( " OEM table pointer:\t\t0x%08x\n", cth->oem_table_pointer );
566 printf( " OEM table size:\t\t%d\n", cth->oem_table_size );
568 printf( " entry count:\t\t\t%d\n", cth->entry_count );
570 printf( " local APIC address:\t\t0x%08x\n", cth->apic_address );
572 printf( " extended table length:\t%d\n", cth->extended_table_length );
573 printf( " extended table checksum:\t%d\n", cth->extended_table_checksum );
575 totalSize = cth->base_table_length - sizeof( struct MPCTH );
579 printf( "MP Config Base Table Entries:\n\n" );
581 /* initialize tables */
582 for (x = 0; x < (int)nitems(busses); x++)
585 for (x = 0; x < (int)nitems(apics); x++)
594 entry = mapEntry(pap + sizeof(*cth), cth->base_table_length);
595 for (c = cth->entry_count; c; c--) {
597 if (entrytype != oldtype)
599 if (entrytype < oldtype)
600 printf("MPTABLE OUT OF ORDER!\n");
602 case MPCT_ENTRY_PROCESSOR:
603 if (oldtype != MPCT_ENTRY_PROCESSOR)
604 printf( "Processors:\tAPIC ID\tVersion\tState"
605 "\t\tFamily\tModel\tStep\tFlags\n" );
606 processorEntry((proc_entry_ptr)entry);
607 entry += sizeof(struct PROCENTRY);
611 if (oldtype != MPCT_ENTRY_BUS)
612 printf( "Bus:\t\tBus ID\tType\n" );
613 busEntry((bus_entry_ptr)entry);
614 entry += sizeof(struct BUSENTRY);
617 case MPCT_ENTRY_IOAPIC:
618 if (oldtype != MPCT_ENTRY_IOAPIC)
619 printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
620 ioApicEntry((io_apic_entry_ptr)entry);
621 entry += sizeof(struct IOAPICENTRY);
625 if (oldtype != MPCT_ENTRY_INT)
626 printf( "I/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
627 intEntry((int_entry_ptr)entry);
628 entry += sizeof(struct INTENTRY);
631 case MPCT_ENTRY_LOCAL_INT:
632 if (oldtype != MPCT_ENTRY_LOCAL_INT)
633 printf( "Local Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
634 intEntry((int_entry_ptr)entry);
635 entry += sizeof(struct INTENTRY);
639 printf("MPTABLE HOSED! record type = %d\n", entrytype);
646 #if defined( EXTENDED_PROCESSING_READY )
647 /* process any extended data */
648 if ( cth->extended_table_length ) {
649 ext_entry_ptr ext_entry, end;
653 printf( "MP Config Extended Table Entries:\n\n" );
655 ext_entry = mapEntry(pap + cth->base_table_length,
656 cth->extended_table_length);
657 end = (ext_entry_ptr)((char *)ext_entry + cth->extended_table_length);
658 while (ext_entry < end) {
659 switch (ext_entry->type) {
660 case MPCT_EXTENTRY_SAS:
661 sasEntry((sas_entry_ptr)ext_entry);
663 case MPCT_EXTENTRY_BHD:
664 bhdEntry((bhd_entry_ptr)ext_entry);
666 case MPCT_EXTENTRY_CBASM:
667 cbasmEntry((cbasm_entry_ptr)ext_entry);
670 printf( "Extended Table HOSED!\n" );
674 ext_entry = (ext_entry_ptr)((char *)ext_entry + ext_entry->length);
677 #endif /* EXTENDED_PROCESSING_READY */
679 /* process any OEM data */
680 if ( cth->oem_table_pointer && (cth->oem_table_size > 0) ) {
681 #if defined( OEM_PROCESSING_READY )
682 # error your on your own here!
683 /* map in oem table structure */
684 oemdata = mapEntry( cth->oem_table_pointer, cth->oem_table_size);
688 printf( "\nyou need to modify the source to handle OEM data!\n\n" );
689 #endif /* OEM_PROCESSING_READY */
694 #if defined( RAW_DUMP )
699 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
701 dumpbuf = mapEntry( paddr, 1024 );
702 write( ofd, dumpbuf, 1024 );
705 #endif /* RAW_DUMP */
713 seekEntry( u_int32_t addr )
715 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
716 err( 1, "%s seek", _PATH_MEM );
724 readEntry( void* entry, int size )
726 if ( read( pfd, entry, size ) != size )
727 err( 1, "readEntry" );
731 mapEntry( u_int32_t addr, int size )
735 p = mmap( NULL, size, PROT_READ, MAP_SHARED, pfd, addr );
737 err( 1, "mapEntry" );
742 processorEntry( proc_entry_ptr entry )
748 printf( "\t\t%2d", entry->apic_id );
749 printf( "\t 0x%2x", entry->apic_version );
752 (entry->cpu_flags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
753 (entry->cpu_flags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
755 printf( "\t %d\t %d\t %d",
756 (entry->cpu_signature >> 8) & 0x0f,
757 (entry->cpu_signature >> 4) & 0x0f,
758 entry->cpu_signature & 0x0f );
760 printf( "\t 0x%04x\n", entry->feature_flags );
768 lookupBusType( char* name )
772 for ( x = 0; x < MAX_BUSTYPE; ++x )
773 if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
774 return busTypeTable[ x ].type;
776 return UNKNOWN_BUSTYPE;
781 busEntry( bus_entry_ptr entry )
790 printf( "\t\t%2d", entry->bus_id );
791 printf( "\t " ); pnstr( entry->bus_type, 6 ); printf( "\n" );
793 for ( x = 0; x < 6; ++x ) {
794 if ( (c = entry->bus_type[ x ]) == ' ' )
799 busses[ entry->bus_id ] = lookupBusType( name );
804 ioApicEntry( io_apic_entry_ptr entry )
810 printf( "\t\t%2d", entry->apic_id );
811 printf( "\t 0x%02x", entry->apic_version );
813 (entry->apic_flags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
814 printf( "\t\t 0x%x\n", entry->apic_address );
816 apics[ entry->apic_id ] = entry->apic_id;
820 static const char *intTypes[] = {
821 "INT", "NMI", "SMI", "ExtINT"
824 static const char *polarityMode[] = {
825 "conforms", "active-hi", "reserved", "active-lo"
827 static const char *triggerMode[] = {
828 "conforms", "edge", "reserved", "level"
832 intEntry( int_entry_ptr entry )
836 if ( entry->type == MPCT_ENTRY_INT )
839 printf( "\t\t%s", intTypes[ entry->int_type ] );
841 printf( "\t%9s", polarityMode[ entry->int_flags & INTENTRY_FLAGS_POLARITY ] );
842 printf( "%12s", triggerMode[ (entry->int_flags & INTENTRY_FLAGS_TRIGGER) >> 2 ] );
844 printf( "\t %5d", entry->src_bus_id );
845 if ( busses[ entry->src_bus_id ] == PCI )
847 (entry->src_bus_irq >> 2) & 0x1f,
848 (entry->src_bus_irq & 0x03) + 'A' );
850 printf( "\t %3d", entry->src_bus_irq );
851 printf( "\t %6d", entry->dst_apic_id );
852 printf( "\t %3d\n", entry->dst_apic_int );
857 sasEntry( sas_entry_ptr entry )
860 printf( "--\nSystem Address Space\n");
861 printf( " bus ID: %d", entry->bus_id );
862 printf( " address type: " );
863 switch ( entry->address_type ) {
864 case SASENTRY_TYPE_IO:
865 printf( "I/O address\n" );
867 case SASENTRY_TYPE_MEMORY:
868 printf( "memory address\n" );
870 case SASENTRY_TYPE_PREFETCH:
871 printf( "prefetch address\n" );
874 printf( "UNKNOWN type\n" );
878 printf( " address base: 0x%jx\n", (uintmax_t)entry->address_base );
879 printf( " address range: 0x%jx\n", (uintmax_t)entry->address_length );
884 bhdEntry( bhd_entry_ptr entry )
887 printf( "--\nBus Hierarchy\n" );
888 printf( " bus ID: %d", entry->bus_id );
889 printf( " bus info: 0x%02x", entry->bus_info );
890 printf( " parent bus ID: %d\n", entry->parent_bus );
895 cbasmEntry( cbasm_entry_ptr entry )
898 printf( "--\nCompatibility Bus Address\n" );
899 printf( " bus ID: %d", entry->bus_id );
900 printf( " address modifier: %s\n",
901 (entry->address_mod & CBASMENTRY_ADDRESS_MOD_SUBTRACT) ?
902 "subtract" : "add" );
903 printf( " predefined range: 0x%08x\n", entry->predefined_range );
915 printf( "dmesg output:\n\n" );
925 pnstr( char* s, int c )
927 char string[ MAXPNSTR + 1 ];
931 strncpy( string, s, c );
933 printf( "%s", string );