2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1996, by Steve Passe
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. The name of the developer may NOT be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 static const char rcsid[] =
38 * this will cause the raw mp table to be dumped to /tmp/mpdump
43 #define MP_SIG 0x5f504d5f /* _MP_ */
44 #define EXTENDED_PROCESSING_READY
45 #define OEM_PROCESSING_READY_NOT
47 #include <sys/param.h>
49 #include <x86/mptable.h>
60 "\n-------------------------------------------------------------------------------\n"
63 "\n===============================================================================\n"
65 /* EBDA is @ 40:0e in real-mode terms */
66 #define EBDA_POINTER 0x040e /* location of EBDA pointer */
68 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
69 #define TOPOFMEM_POINTER 0x0413 /* BIOS: base memory size */
71 #define DEFAULT_TOPOFMEM 0xa0000
73 #define BIOS_BASE 0xf0000
74 #define BIOS_BASE2 0xe0000
75 #define BIOS_SIZE 0x10000
76 #define ONE_KBYTE 1024
78 #define GROPE_AREA1 0x80000
79 #define GROPE_AREA2 0x90000
80 #define GROPE_SIZE 0x10000
84 typedef struct BUSTYPENAME {
89 static const busTypeName busTypeTable[] =
94 { UNKNOWN_BUSTYPE, "---" },
95 { UNKNOWN_BUSTYPE, "---" },
97 { UNKNOWN_BUSTYPE, "---" },
98 { UNKNOWN_BUSTYPE, "---" },
99 { UNKNOWN_BUSTYPE, "---" },
100 { UNKNOWN_BUSTYPE, "---" },
101 { UNKNOWN_BUSTYPE, "---" },
102 { UNKNOWN_BUSTYPE, "---" },
104 { UNKNOWN_BUSTYPE, "---" },
105 { UNKNOWN_BUSTYPE, "---" },
106 { UNKNOWN_BUSTYPE, "---" },
107 { UNKNOWN_BUSTYPE, "---" },
108 { UNKNOWN_BUSTYPE, "---" },
109 { UNKNOWN_BUSTYPE, "---" }
112 static const char *whereStrings[] = {
113 "Extended BIOS Data Area",
114 "BIOS top of memory",
115 "Default top of memory",
122 static void apic_probe( u_int32_t* paddr, int* where );
124 static void MPConfigDefault( int featureByte );
126 static void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp );
127 static void MPConfigTableHeader( u_int32_t pap );
129 static void seekEntry( u_int32_t addr );
130 static void readEntry( void* entry, int size );
131 static void *mapEntry( u_int32_t addr, int size );
133 static void processorEntry( proc_entry_ptr entry );
134 static void busEntry( bus_entry_ptr entry );
135 static void ioApicEntry( io_apic_entry_ptr entry );
136 static void intEntry( int_entry_ptr entry );
138 static void sasEntry( sas_entry_ptr entry );
139 static void bhdEntry( bhd_entry_ptr entry );
140 static void cbasmEntry( cbasm_entry_ptr entry );
142 static void doDmesg( void );
143 static void pnstr( char* s, int c );
146 static int pfd; /* physical /dev/mem fd */
148 static int busses[256];
149 static int apics[256];
163 fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
171 main( int argc, char *argv[] )
180 /* announce ourselves */
183 printf( "MPTable\n" );
185 while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
188 if ( strcmp( optarg, "mesg") == 0 )
194 if ( strcmp( optarg, "elp") == 0 )
198 if ( strcmp( optarg, "rope") == 0 )
202 if ( strcmp( optarg, "erbose") == 0 )
214 /* open physical memory for access to MP structures */
215 if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
216 err( 1, "mem open" );
218 /* probe for MP structures */
219 apic_probe( &paddr, &where );
221 fprintf( stderr, "\n MP FPS NOT found,\n" );
223 fprintf( stderr, " suggest trying -grope option!!!\n\n" );
228 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
229 whereStrings[ where - 1 ], paddr );
233 /* analyze the MP Floating Pointer Structure */
234 MPFloatingPointer( paddr, where, &mpfps );
238 /* check whether an MP config table exists */
239 if ( (defaultConfig = mpfps->config_type) )
240 MPConfigDefault( defaultConfig );
242 MPConfigTableHeader( mpfps->pap );
244 /* do a dmesg output */
255 * set PHYSICAL address of MP floating pointer structure
257 #define NEXT(X) ((X) += 4)
259 apic_probe( u_int32_t* paddr, int* where )
262 * c rewrite of apic_probe() by Jack F. Vogel
268 u_int buffer[ BIOS_SIZE / sizeof( int ) ];
273 /* search Extended Bios Data Area, if present */
275 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
276 seekEntry( (u_int32_t)EBDA_POINTER );
277 readEntry( &segment, 2 );
278 if ( segment ) { /* search EBDA */
279 target = (u_int32_t)segment << 4;
281 printf( "found, searching EBDA @ 0x%08x\n", target );
283 readEntry( buffer, ONE_KBYTE );
285 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
286 if ( buffer[ x ] == MP_SIG ) {
288 *paddr = (x * sizeof( unsigned int )) + target;
295 printf( "NOT found\n" );
298 /* read CMOS for real top of mem */
299 seekEntry( (u_int32_t)TOPOFMEM_POINTER );
300 readEntry( &segment, 2 );
301 --segment; /* less ONE_KBYTE */
302 target = segment * 1024;
304 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
307 readEntry( buffer, ONE_KBYTE );
309 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
310 if ( buffer[ x ] == MP_SIG ) {
312 *paddr = (x * sizeof( unsigned int )) + target;
317 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
318 if ( target != (DEFAULT_TOPOFMEM - 1024)) {
319 target = (DEFAULT_TOPOFMEM - 1024);
321 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
322 target, (target / 1024) );
324 readEntry( buffer, ONE_KBYTE );
326 for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
327 if ( buffer[ x ] == MP_SIG ) {
329 *paddr = (x * sizeof( unsigned int )) + target;
335 /* search the BIOS */
337 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
338 seekEntry( BIOS_BASE );
339 readEntry( buffer, BIOS_SIZE );
341 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
342 if ( buffer[ x ] == MP_SIG ) {
344 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
349 /* search the extended BIOS */
351 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
352 seekEntry( BIOS_BASE2 );
353 readEntry( buffer, BIOS_SIZE );
355 for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
356 if ( buffer[ x ] == MP_SIG ) {
358 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
364 /* search additional memory */
365 target = GROPE_AREA1;
367 printf( " groping memory @ 0x%08x\n", target );
369 readEntry( buffer, GROPE_SIZE );
371 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
372 if ( buffer[ x ] == MP_SIG ) {
374 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
379 target = GROPE_AREA2;
381 printf( " groping memory @ 0x%08x\n", target );
383 readEntry( buffer, GROPE_SIZE );
385 for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
386 if ( buffer[ x ] == MP_SIG ) {
388 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
395 *paddr = (u_int32_t)0;
403 MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp )
407 /* map in mpfps structure*/
408 *mpfpsp = mpfps = mapEntry( paddr, sizeof( *mpfps ) );
410 /* show its contents */
411 printf( "MP Floating Pointer Structure:\n\n" );
413 printf( " location:\t\t\t" );
420 printf( "BIOS base memory\n" );
423 printf( "DEFAULT base memory (639K)\n" );
429 printf( "Extended BIOS\n" );
433 printf( "NOT found!\n" );
436 printf( "BOGUS!\n" );
439 printf( " physical address:\t\t0x%08x\n", paddr );
441 printf( " signature:\t\t\t'" );
442 pnstr( mpfps->signature, 4 );
445 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 );
446 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev );
447 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum );
449 /* bits 0:6 are RESERVED */
450 if ( mpfps->mpfb2 & 0x7f ) {
451 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
455 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & MPFB2_IMCR_PRESENT) ?
456 "PIC" : "Virtual Wire" );
458 /* MP feature bytes 3-5 are expected to be ZERO */
460 printf( " warning, MP feature byte 3 NONZERO!\n" );
462 printf( " warning, MP feature byte 4 NONZERO!\n" );
464 printf( " warning, MP feature byte 5 NONZERO!\n" );
472 MPConfigDefault( int featureByte )
474 printf( " MP default config type: %d\n\n", featureByte );
475 switch ( featureByte ) {
477 printf( " bus: ISA, APIC: 82489DX\n" );
480 printf( " bus: EISA, APIC: 82489DX\n" );
483 printf( " bus: EISA, APIC: 82489DX\n" );
486 printf( " bus: MCA, APIC: 82489DX\n" );
489 printf( " bus: ISA+PCI, APIC: Integrated\n" );
492 printf( " bus: EISA+PCI, APIC: Integrated\n" );
495 printf( " bus: MCA+PCI, APIC: Integrated\n" );
498 printf( " future type\n" );
502 switch ( featureByte ) {
515 printf( " future type\n" );
529 MPConfigTableHeader( u_int32_t pap )
535 int oldtype, entrytype;
539 printf( "MP Configuration Table Header MISSING!\n" );
543 /* map in cth structure */
544 cth = mapEntry( pap, sizeof( *cth ) );
546 printf( "MP Config Table Header:\n\n" );
548 printf( " physical address:\t\t0x%08x\n", pap );
550 printf( " signature:\t\t\t'" );
551 pnstr( cth->signature, 4 );
554 printf( " base table length:\t\t%d\n", cth->base_table_length );
556 printf( " version:\t\t\t1.%1d\n", cth->spec_rev );
557 printf( " checksum:\t\t\t0x%02x\n", cth->checksum );
559 printf( " OEM ID:\t\t\t'" );
560 pnstr( cth->oem_id, 8 );
563 printf( " Product ID:\t\t\t'" );
564 pnstr( cth->product_id, 12 );
567 printf( " OEM table pointer:\t\t0x%08x\n", cth->oem_table_pointer );
568 printf( " OEM table size:\t\t%d\n", cth->oem_table_size );
570 printf( " entry count:\t\t\t%d\n", cth->entry_count );
572 printf( " local APIC address:\t\t0x%08x\n", cth->apic_address );
574 printf( " extended table length:\t%d\n", cth->extended_table_length );
575 printf( " extended table checksum:\t%d\n", cth->extended_table_checksum );
577 totalSize = cth->base_table_length - sizeof( struct MPCTH );
581 printf( "MP Config Base Table Entries:\n\n" );
583 /* initialize tables */
584 for (x = 0; x < (int)nitems(busses); x++)
587 for (x = 0; x < (int)nitems(apics); x++)
596 entry = mapEntry(pap + sizeof(*cth), cth->base_table_length);
597 for (c = cth->entry_count; c; c--) {
599 if (entrytype != oldtype)
601 if (entrytype < oldtype)
602 printf("MPTABLE OUT OF ORDER!\n");
604 case MPCT_ENTRY_PROCESSOR:
605 if (oldtype != MPCT_ENTRY_PROCESSOR)
606 printf( "Processors:\tAPIC ID\tVersion\tState"
607 "\t\tFamily\tModel\tStep\tFlags\n" );
608 processorEntry((proc_entry_ptr)entry);
609 entry += sizeof(struct PROCENTRY);
613 if (oldtype != MPCT_ENTRY_BUS)
614 printf( "Bus:\t\tBus ID\tType\n" );
615 busEntry((bus_entry_ptr)entry);
616 entry += sizeof(struct BUSENTRY);
619 case MPCT_ENTRY_IOAPIC:
620 if (oldtype != MPCT_ENTRY_IOAPIC)
621 printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
622 ioApicEntry((io_apic_entry_ptr)entry);
623 entry += sizeof(struct IOAPICENTRY);
627 if (oldtype != MPCT_ENTRY_INT)
628 printf( "I/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
629 intEntry((int_entry_ptr)entry);
630 entry += sizeof(struct INTENTRY);
633 case MPCT_ENTRY_LOCAL_INT:
634 if (oldtype != MPCT_ENTRY_LOCAL_INT)
635 printf( "Local Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
636 intEntry((int_entry_ptr)entry);
637 entry += sizeof(struct INTENTRY);
641 printf("MPTABLE HOSED! record type = %d\n", entrytype);
648 #if defined( EXTENDED_PROCESSING_READY )
649 /* process any extended data */
650 if ( cth->extended_table_length ) {
651 ext_entry_ptr ext_entry, end;
655 printf( "MP Config Extended Table Entries:\n\n" );
657 ext_entry = mapEntry(pap + cth->base_table_length,
658 cth->extended_table_length);
659 end = (ext_entry_ptr)((char *)ext_entry + cth->extended_table_length);
660 while (ext_entry < end) {
661 switch (ext_entry->type) {
662 case MPCT_EXTENTRY_SAS:
663 sasEntry((sas_entry_ptr)ext_entry);
665 case MPCT_EXTENTRY_BHD:
666 bhdEntry((bhd_entry_ptr)ext_entry);
668 case MPCT_EXTENTRY_CBASM:
669 cbasmEntry((cbasm_entry_ptr)ext_entry);
672 printf( "Extended Table HOSED!\n" );
676 ext_entry = (ext_entry_ptr)((char *)ext_entry + ext_entry->length);
679 #endif /* EXTENDED_PROCESSING_READY */
681 /* process any OEM data */
682 if ( cth->oem_table_pointer && (cth->oem_table_size > 0) ) {
683 #if defined( OEM_PROCESSING_READY )
684 # error your on your own here!
685 /* map in oem table structure */
686 oemdata = mapEntry( cth->oem_table_pointer, cth->oem_table_size);
690 printf( "\nyou need to modify the source to handle OEM data!\n\n" );
691 #endif /* OEM_PROCESSING_READY */
696 #if defined( RAW_DUMP )
701 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
703 dumpbuf = mapEntry( paddr, 1024 );
704 write( ofd, dumpbuf, 1024 );
707 #endif /* RAW_DUMP */
715 seekEntry( u_int32_t addr )
717 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
718 err( 1, "%s seek", _PATH_MEM );
726 readEntry( void* entry, int size )
728 if ( read( pfd, entry, size ) != size )
729 err( 1, "readEntry" );
733 mapEntry( u_int32_t addr, int size )
737 p = mmap( NULL, size, PROT_READ, MAP_SHARED, pfd, addr );
739 err( 1, "mapEntry" );
744 processorEntry( proc_entry_ptr entry )
750 printf( "\t\t%2d", entry->apic_id );
751 printf( "\t 0x%2x", entry->apic_version );
754 (entry->cpu_flags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
755 (entry->cpu_flags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
757 printf( "\t %d\t %d\t %d",
758 (entry->cpu_signature >> 8) & 0x0f,
759 (entry->cpu_signature >> 4) & 0x0f,
760 entry->cpu_signature & 0x0f );
762 printf( "\t 0x%04x\n", entry->feature_flags );
770 lookupBusType( char* name )
774 for ( x = 0; x < MAX_BUSTYPE; ++x )
775 if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
776 return busTypeTable[ x ].type;
778 return UNKNOWN_BUSTYPE;
783 busEntry( bus_entry_ptr entry )
792 printf( "\t\t%2d", entry->bus_id );
793 printf( "\t " ); pnstr( entry->bus_type, 6 ); printf( "\n" );
795 for ( x = 0; x < 6; ++x ) {
796 if ( (c = entry->bus_type[ x ]) == ' ' )
801 busses[ entry->bus_id ] = lookupBusType( name );
806 ioApicEntry( io_apic_entry_ptr entry )
812 printf( "\t\t%2d", entry->apic_id );
813 printf( "\t 0x%02x", entry->apic_version );
815 (entry->apic_flags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
816 printf( "\t\t 0x%x\n", entry->apic_address );
818 apics[ entry->apic_id ] = entry->apic_id;
822 static const char *intTypes[] = {
823 "INT", "NMI", "SMI", "ExtINT"
826 static const char *polarityMode[] = {
827 "conforms", "active-hi", "reserved", "active-lo"
829 static const char *triggerMode[] = {
830 "conforms", "edge", "reserved", "level"
834 intEntry( int_entry_ptr entry )
838 if ( entry->type == MPCT_ENTRY_INT )
841 printf( "\t\t%s", intTypes[ entry->int_type ] );
843 printf( "\t%9s", polarityMode[ entry->int_flags & INTENTRY_FLAGS_POLARITY ] );
844 printf( "%12s", triggerMode[ (entry->int_flags & INTENTRY_FLAGS_TRIGGER) >> 2 ] );
846 printf( "\t %5d", entry->src_bus_id );
847 if ( busses[ entry->src_bus_id ] == PCI )
849 (entry->src_bus_irq >> 2) & 0x1f,
850 (entry->src_bus_irq & 0x03) + 'A' );
852 printf( "\t %3d", entry->src_bus_irq );
853 printf( "\t %6d", entry->dst_apic_id );
854 printf( "\t %3d\n", entry->dst_apic_int );
859 sasEntry( sas_entry_ptr entry )
862 printf( "--\nSystem Address Space\n");
863 printf( " bus ID: %d", entry->bus_id );
864 printf( " address type: " );
865 switch ( entry->address_type ) {
866 case SASENTRY_TYPE_IO:
867 printf( "I/O address\n" );
869 case SASENTRY_TYPE_MEMORY:
870 printf( "memory address\n" );
872 case SASENTRY_TYPE_PREFETCH:
873 printf( "prefetch address\n" );
876 printf( "UNKNOWN type\n" );
880 printf( " address base: 0x%jx\n", (uintmax_t)entry->address_base );
881 printf( " address range: 0x%jx\n", (uintmax_t)entry->address_length );
886 bhdEntry( bhd_entry_ptr entry )
889 printf( "--\nBus Hierarchy\n" );
890 printf( " bus ID: %d", entry->bus_id );
891 printf( " bus info: 0x%02x", entry->bus_info );
892 printf( " parent bus ID: %d\n", entry->parent_bus );
897 cbasmEntry( cbasm_entry_ptr entry )
900 printf( "--\nCompatibility Bus Address\n" );
901 printf( " bus ID: %d", entry->bus_id );
902 printf( " address modifier: %s\n",
903 (entry->address_mod & CBASMENTRY_ADDRESS_MOD_SUBTRACT) ?
904 "subtract" : "add" );
905 printf( " predefined range: 0x%08x\n", entry->predefined_range );
917 printf( "dmesg output:\n\n" );
927 pnstr( char* s, int c )
929 char string[ MAXPNSTR + 1 ];
933 strncpy( string, s, c );
935 printf( "%s", string );