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" );
220 fprintf( stderr, " suggest trying -grope option!!!\n\n" );
225 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
226 whereStrings[ where - 1 ], paddr );
230 /* analyze the MP Floating Pointer Structure */
231 MPFloatingPointer( paddr, where, &mpfps );
235 /* check whether an MP config table exists */
236 if ( (defaultConfig = mpfps->config_type) )
237 MPConfigDefault( defaultConfig );
239 MPConfigTableHeader( mpfps->pap );
241 /* do a dmesg output */
252 * set PHYSICAL address of MP floating pointer structure
254 #define NEXT(X) ((X) += 4)
256 apic_probe( u_int32_t* paddr, int* where )
259 * c rewrite of apic_probe() by Jack F. Vogel
265 u_int buffer[ BIOS_SIZE / sizeof( int ) ];
270 /* search Extended Bios Data Area, if present */
272 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
273 seekEntry( (u_int32_t)EBDA_POINTER );
274 readEntry( &segment, 2 );
275 if ( segment ) { /* search EBDA */
276 target = (u_int32_t)segment << 4;
278 printf( "found, searching EBDA @ 0x%08x\n", target );
280 readEntry( buffer, ONE_KBYTE );
282 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
283 if ( buffer[ x ] == MP_SIG ) {
285 *paddr = (x * sizeof( unsigned int )) + target;
292 printf( "NOT found\n" );
295 /* read CMOS for real top of mem */
296 seekEntry( (u_int32_t)TOPOFMEM_POINTER );
297 readEntry( &segment, 2 );
298 --segment; /* less ONE_KBYTE */
299 target = segment * 1024;
301 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
304 readEntry( buffer, ONE_KBYTE );
306 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
307 if ( buffer[ x ] == MP_SIG ) {
309 *paddr = (x * sizeof( unsigned int )) + target;
314 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
315 if ( target != (DEFAULT_TOPOFMEM - 1024)) {
316 target = (DEFAULT_TOPOFMEM - 1024);
318 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
319 target, (target / 1024) );
321 readEntry( buffer, ONE_KBYTE );
323 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
324 if ( buffer[ x ] == MP_SIG ) {
326 *paddr = (x * sizeof( unsigned int )) + target;
332 /* search the BIOS */
334 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
335 seekEntry( BIOS_BASE );
336 readEntry( buffer, BIOS_SIZE );
338 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
339 if ( buffer[ x ] == MP_SIG ) {
341 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
346 /* search the extended BIOS */
348 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
349 seekEntry( BIOS_BASE2 );
350 readEntry( buffer, BIOS_SIZE );
352 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
353 if ( buffer[ x ] == MP_SIG ) {
355 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
361 /* search additional memory */
362 target = GROPE_AREA1;
364 printf( " groping memory @ 0x%08x\n", target );
366 readEntry( buffer, GROPE_SIZE );
368 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
369 if ( buffer[ x ] == MP_SIG ) {
371 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
376 target = GROPE_AREA2;
378 printf( " groping memory @ 0x%08x\n", target );
380 readEntry( buffer, GROPE_SIZE );
382 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
383 if ( buffer[ x ] == MP_SIG ) {
385 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
392 *paddr = (u_int32_t)0;
400 MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp )
404 /* map in mpfps structure*/
405 *mpfpsp = mpfps = mapEntry( paddr, sizeof( *mpfps ) );
407 /* show its contents */
408 printf( "MP Floating Pointer Structure:\n\n" );
410 printf( " location:\t\t\t" );
417 printf( "BIOS base memory\n" );
420 printf( "DEFAULT base memory (639K)\n" );
426 printf( "Extended BIOS\n" );
430 printf( "NOT found!\n" );
433 printf( "BOGUS!\n" );
436 printf( " physical address:\t\t0x%08x\n", paddr );
438 printf( " signature:\t\t\t'" );
439 pnstr( mpfps->signature, 4 );
442 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 );
443 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev );
444 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum );
446 /* bits 0:6 are RESERVED */
447 if ( mpfps->mpfb2 & 0x7f ) {
448 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
452 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & MPFB2_IMCR_PRESENT) ?
453 "PIC" : "Virtual Wire" );
455 /* MP feature bytes 3-5 are expected to be ZERO */
457 printf( " warning, MP feature byte 3 NONZERO!\n" );
459 printf( " warning, MP feature byte 4 NONZERO!\n" );
461 printf( " warning, MP feature byte 5 NONZERO!\n" );
469 MPConfigDefault( int featureByte )
471 printf( " MP default config type: %d\n\n", featureByte );
472 switch ( featureByte ) {
474 printf( " bus: ISA, APIC: 82489DX\n" );
477 printf( " bus: EISA, APIC: 82489DX\n" );
480 printf( " bus: EISA, APIC: 82489DX\n" );
483 printf( " bus: MCA, APIC: 82489DX\n" );
486 printf( " bus: ISA+PCI, APIC: Integrated\n" );
489 printf( " bus: EISA+PCI, APIC: Integrated\n" );
492 printf( " bus: MCA+PCI, APIC: Integrated\n" );
495 printf( " future type\n" );
499 switch ( featureByte ) {
512 printf( " future type\n" );
526 MPConfigTableHeader( u_int32_t pap )
532 int oldtype, entrytype;
536 printf( "MP Configuration Table Header MISSING!\n" );
540 /* map in cth structure */
541 cth = mapEntry( pap, sizeof( *cth ) );
543 printf( "MP Config Table Header:\n\n" );
545 printf( " physical address:\t\t0x%08x\n", pap );
547 printf( " signature:\t\t\t'" );
548 pnstr( cth->signature, 4 );
551 printf( " base table length:\t\t%d\n", cth->base_table_length );
553 printf( " version:\t\t\t1.%1d\n", cth->spec_rev );
554 printf( " checksum:\t\t\t0x%02x\n", cth->checksum );
556 printf( " OEM ID:\t\t\t'" );
557 pnstr( cth->oem_id, 8 );
560 printf( " Product ID:\t\t\t'" );
561 pnstr( cth->product_id, 12 );
564 printf( " OEM table pointer:\t\t0x%08x\n", cth->oem_table_pointer );
565 printf( " OEM table size:\t\t%d\n", cth->oem_table_size );
567 printf( " entry count:\t\t\t%d\n", cth->entry_count );
569 printf( " local APIC address:\t\t0x%08x\n", cth->apic_address );
571 printf( " extended table length:\t%d\n", cth->extended_table_length );
572 printf( " extended table checksum:\t%d\n", cth->extended_table_checksum );
574 totalSize = cth->base_table_length - sizeof( struct MPCTH );
578 printf( "MP Config Base Table Entries:\n\n" );
580 /* initialize tables */
581 for (x = 0; x < (int)nitems(busses); x++)
584 for (x = 0; x < (int)nitems(apics); x++)
593 entry = mapEntry(pap + sizeof(*cth), cth->base_table_length);
594 for (c = cth->entry_count; c; c--) {
596 if (entrytype != oldtype)
598 if (entrytype < oldtype)
599 printf("MPTABLE OUT OF ORDER!\n");
601 case MPCT_ENTRY_PROCESSOR:
602 if (oldtype != MPCT_ENTRY_PROCESSOR)
603 printf( "Processors:\tAPIC ID\tVersion\tState"
604 "\t\tFamily\tModel\tStep\tFlags\n" );
605 processorEntry((proc_entry_ptr)entry);
606 entry += sizeof(struct PROCENTRY);
610 if (oldtype != MPCT_ENTRY_BUS)
611 printf( "Bus:\t\tBus ID\tType\n" );
612 busEntry((bus_entry_ptr)entry);
613 entry += sizeof(struct BUSENTRY);
616 case MPCT_ENTRY_IOAPIC:
617 if (oldtype != MPCT_ENTRY_IOAPIC)
618 printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
619 ioApicEntry((io_apic_entry_ptr)entry);
620 entry += sizeof(struct IOAPICENTRY);
624 if (oldtype != MPCT_ENTRY_INT)
625 printf( "I/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
626 intEntry((int_entry_ptr)entry);
627 entry += sizeof(struct INTENTRY);
630 case MPCT_ENTRY_LOCAL_INT:
631 if (oldtype != MPCT_ENTRY_LOCAL_INT)
632 printf( "Local Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
633 intEntry((int_entry_ptr)entry);
634 entry += sizeof(struct INTENTRY);
638 printf("MPTABLE HOSED! record type = %d\n", entrytype);
645 #if defined( EXTENDED_PROCESSING_READY )
646 /* process any extended data */
647 if ( cth->extended_table_length ) {
648 ext_entry_ptr ext_entry, end;
652 printf( "MP Config Extended Table Entries:\n\n" );
654 ext_entry = mapEntry(pap + cth->base_table_length,
655 cth->extended_table_length);
656 end = (ext_entry_ptr)((char *)ext_entry + cth->extended_table_length);
657 while (ext_entry < end) {
658 switch (ext_entry->type) {
659 case MPCT_EXTENTRY_SAS:
660 sasEntry((sas_entry_ptr)ext_entry);
662 case MPCT_EXTENTRY_BHD:
663 bhdEntry((bhd_entry_ptr)ext_entry);
665 case MPCT_EXTENTRY_CBASM:
666 cbasmEntry((cbasm_entry_ptr)ext_entry);
669 printf( "Extended Table HOSED!\n" );
673 ext_entry = (ext_entry_ptr)((char *)ext_entry + ext_entry->length);
676 #endif /* EXTENDED_PROCESSING_READY */
678 /* process any OEM data */
679 if ( cth->oem_table_pointer && (cth->oem_table_size > 0) ) {
680 #if defined( OEM_PROCESSING_READY )
681 # error your on your own here!
682 /* map in oem table structure */
683 oemdata = mapEntry( cth->oem_table_pointer, cth->oem_table_size);
687 printf( "\nyou need to modify the source to handle OEM data!\n\n" );
688 #endif /* OEM_PROCESSING_READY */
693 #if defined( RAW_DUMP )
698 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
700 dumpbuf = mapEntry( paddr, 1024 );
701 write( ofd, dumpbuf, 1024 );
704 #endif /* RAW_DUMP */
712 seekEntry( u_int32_t addr )
714 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
715 err( 1, "%s seek", _PATH_MEM );
723 readEntry( void* entry, int size )
725 if ( read( pfd, entry, size ) != size )
726 err( 1, "readEntry" );
730 mapEntry( u_int32_t addr, int size )
734 p = mmap( NULL, size, PROT_READ, MAP_SHARED, pfd, addr );
736 err( 1, "mapEntry" );
741 processorEntry( proc_entry_ptr entry )
747 printf( "\t\t%2d", entry->apic_id );
748 printf( "\t 0x%2x", entry->apic_version );
751 (entry->cpu_flags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
752 (entry->cpu_flags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
754 printf( "\t %d\t %d\t %d",
755 (entry->cpu_signature >> 8) & 0x0f,
756 (entry->cpu_signature >> 4) & 0x0f,
757 entry->cpu_signature & 0x0f );
759 printf( "\t 0x%04x\n", entry->feature_flags );
767 lookupBusType( char* name )
771 for ( x = 0; x < MAX_BUSTYPE; ++x )
772 if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
773 return busTypeTable[ x ].type;
775 return UNKNOWN_BUSTYPE;
780 busEntry( bus_entry_ptr entry )
789 printf( "\t\t%2d", entry->bus_id );
790 printf( "\t " ); pnstr( entry->bus_type, 6 ); printf( "\n" );
792 for ( x = 0; x < 6; ++x ) {
793 if ( (c = entry->bus_type[ x ]) == ' ' )
798 busses[ entry->bus_id ] = lookupBusType( name );
803 ioApicEntry( io_apic_entry_ptr entry )
809 printf( "\t\t%2d", entry->apic_id );
810 printf( "\t 0x%02x", entry->apic_version );
812 (entry->apic_flags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
813 printf( "\t\t 0x%x\n", entry->apic_address );
815 apics[ entry->apic_id ] = entry->apic_id;
819 static const char *intTypes[] = {
820 "INT", "NMI", "SMI", "ExtINT"
823 static const char *polarityMode[] = {
824 "conforms", "active-hi", "reserved", "active-lo"
826 static const char *triggerMode[] = {
827 "conforms", "edge", "reserved", "level"
831 intEntry( int_entry_ptr entry )
835 if ( entry->type == MPCT_ENTRY_INT )
838 printf( "\t\t%s", intTypes[ entry->int_type ] );
840 printf( "\t%9s", polarityMode[ entry->int_flags & INTENTRY_FLAGS_POLARITY ] );
841 printf( "%12s", triggerMode[ (entry->int_flags & INTENTRY_FLAGS_TRIGGER) >> 2 ] );
843 printf( "\t %5d", entry->src_bus_id );
844 if ( busses[ entry->src_bus_id ] == PCI )
846 (entry->src_bus_irq >> 2) & 0x1f,
847 (entry->src_bus_irq & 0x03) + 'A' );
849 printf( "\t %3d", entry->src_bus_irq );
850 printf( "\t %6d", entry->dst_apic_id );
851 printf( "\t %3d\n", entry->dst_apic_int );
856 sasEntry( sas_entry_ptr entry )
859 printf( "--\nSystem Address Space\n");
860 printf( " bus ID: %d", entry->bus_id );
861 printf( " address type: " );
862 switch ( entry->address_type ) {
863 case SASENTRY_TYPE_IO:
864 printf( "I/O address\n" );
866 case SASENTRY_TYPE_MEMORY:
867 printf( "memory address\n" );
869 case SASENTRY_TYPE_PREFETCH:
870 printf( "prefetch address\n" );
873 printf( "UNKNOWN type\n" );
877 printf( " address base: 0x%jx\n", (uintmax_t)entry->address_base );
878 printf( " address range: 0x%jx\n", (uintmax_t)entry->address_length );
883 bhdEntry( bhd_entry_ptr entry )
886 printf( "--\nBus Hierarchy\n" );
887 printf( " bus ID: %d", entry->bus_id );
888 printf( " bus info: 0x%02x", entry->bus_info );
889 printf( " parent bus ID: %d\n", entry->parent_bus );
894 cbasmEntry( cbasm_entry_ptr entry )
897 printf( "--\nCompatibility Bus Address\n" );
898 printf( " bus ID: %d", entry->bus_id );
899 printf( " address modifier: %s\n",
900 (entry->address_mod & CBASMENTRY_ADDRESS_MOD_SUBTRACT) ?
901 "subtract" : "add" );
902 printf( " predefined range: 0x%08x\n", entry->predefined_range );
914 printf( "dmesg output:\n\n" );
924 pnstr( char* s, int c )
926 char string[ MAXPNSTR + 1 ];
930 strncpy( string, s, c );
932 printf( "%s", string );