From owner-freebsd-smp Thu Sep 12 17:45:22 1996 Return-Path: owner-smp Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id RAA16373 for smp-outgoing; Thu, 12 Sep 1996 17:45:22 -0700 (PDT) Received: from clem.systemsix.com (clem.systemsix.com [198.99.86.131]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id RAA16366 for ; Thu, 12 Sep 1996 17:45:15 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by clem.systemsix.com (8.6.12/8.6.12) with SMTP id SAA20723; Thu, 12 Sep 1996 18:45:11 -0600 Message-Id: <199609130045.SAA20723@clem.systemsix.com> X-Authentication-Warning: clem.systemsix.com: Host localhost didn't use HELO protocol X-Mailer: exmh version 1.6.5 12/11/95 From: Steve Passe To: freebsd-smp@freebsd.org cc: peter@spinner.dialix.com Subject: mptable.c Mime-Version: 1.0 Content-Type: text/plain Date: Thu, 12 Sep 1996 18:45:11 -0600 Sender: owner-smp@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Hi, here's the tool to parse out your MP table from your motherboard. It uses /dev/kmem so it must be built and run as root. Keywords: MP Spec, Configuration Table ----------------------------------- cut --------------------------------------- /* * mptable.c */ #define MP_SIG 0x5f504d5f /* _MP_ */ #define EXTENDED_PROCESSING_READY #define OEM_PROCESSING_READY_NOT /** cheat for now, hardcode address */ #define CHEATING_NOT #if 0 /* XXPRESS */ #define CHEAT_ADDRESS 0x000f7ba0 #else /* GA586DX */ #define CHEAT_ADDRESS 0x000f0c80 #endif #include #include #include #include #include #if 0 #include #include #include what else? and is it worth it? #else #define KERNBASE ((vm_offset_t)0xf0000000) #endif #define BIOS_BASE 0xf0000 #define BIOS_SIZE 0x10000 #define ONE_KBYTE 1024 #define PROCENTRY_FLAG_EN 0x01 #define PROCENTRY_FLAG_BP 0x02 #define IOAPICENTRY_FLAG_EN 0x01 #define MAXPNSTR 132 char* whereStrings[] = { "Extended BIOS Data Area", "@ top of memory", "BIOS" }; typedef struct TABLE_ENTRY { u_char type; u_char length; char name[ 32 ]; } tableEntry; tableEntry basetableEntryTypes[] = { { 0, 20, "Processor" }, { 1, 8, "Bus" }, { 2, 8, "I/O APIC" }, { 3, 8, "I/O INT" }, { 4, 8, "Local INT" } }; tableEntry extendedtableEntryTypes[] = { { 128, 20, "System Address Space" }, { 129, 8, "Bus Heirarchy" }, { 130, 8, "Compatibility Bus Address" } }; /* MP Floating Pointer Structure */ typedef struct MPFPS { char signature[ 4 ]; void* pap; u_char length; u_char spec_rev; u_char checksum; u_char mpfb1; u_char mpfb2; u_char mpfb3; u_char mpfb4; u_char mpfb5; } mpfps_t; /* MP Configuration Table Header */ typedef struct MPCTH { char signature[ 4 ]; u_short base_table_length; u_char spec_rev; u_char checksum; u_char oem_id[ 8 ]; u_char product_id[ 12 ]; void* oem_table_pointer; u_short oem_table_size; u_short entry_count; void* apic_address; u_short extended_table_length; u_char extended_table_checksum; u_char reserved; } mpcth_t; typedef struct PROCENTRY { u_char type; u_char apicID; u_char apicVersion; u_char cpuFlags; u_long cpuSignature; u_long featureFlags; u_long reserved1; u_long reserved2; } ProcEntry; typedef struct BUSENTRY { u_char type; u_char busID; char busType[ 6 ]; } BusEntry; typedef struct IOAPICENTRY { u_char type; u_char apicID; u_char apicVersion; u_char apicFlags; void* apicAddress; } IOApicEntry; typedef struct INTENTRY { u_char type; u_char intType; u_short intFlags; u_char srcBusID; u_char srcBusIRQ; u_char dstApicID; u_char dstApicINT; } IntEntry; /* * extended entry type structures */ typedef struct SASENTRY { u_char type; u_char length; u_char busID; u_char addressType; u_int64_t addressBase; u_int64_t addressLength; } SasEntry; typedef struct BHDENTRY { u_char type; u_char length; u_char busID; u_char busInfo; u_char busParent; u_char reserved[ 3 ]; } BhdEntry; typedef struct CBASMENTRY { u_char type; u_char length; u_char busID; u_char addressMod; u_int predefinedRange; } CbasmEntry; static void apic_probe( vm_offset_t* paddr, int* where ); static void MPConfigDefault( int featureByte ); static int MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps ); static void MPConfigTableHeader( void* pap ); static int readType( void ); static void seekEntry( vm_offset_t addr ); static void readEntry( void* entry, int size ); static void processorEntry( void ); static void busEntry( void ); static void ioApicEntry( void ); static void intEntry( void ); static void sasEntry( void ); static void bhdEntry( void ); static void cbasmEntry( void ); static void pnstr( char* s, int c ); /* global data */ int kfd; /* * */ int main( int argc, char *argv[] ) { vm_offset_t paddr; int where; mpfps_t mpfps; int defaultConfig; /* open kernel memory for access to MP structures */ if ( (kfd = open( "/dev/kmem", O_RDONLY )) < 0 ) { perror( "kmem open" ); exit( 1 ); } /* probe for MP structures */ apic_probe( &paddr, &where ); if ( where <= 0 ) { fprintf( stderr, "\n MP Table NOT found!!!\n\n" ); return 1; } printf( "\n-------------------------------------" ); printf( "-------------------------------------\n" ); printf( "\nFound MP Table in %s, physical addr: 0x%08x\n", whereStrings[ where - 1 ], paddr ); printf( "\n-------------------------------------" ); printf( "-------------------------------------\n" ); /* analyze the MP Floating Pointer Structure */ MPFloatingPointer( paddr, where, &mpfps ); printf( "\n-------------------------------------" ); printf( "-------------------------------------\n" ); /* check whether an MP config table exists */ if ( defaultConfig = mpfps.mpfb1 ) { MPConfigDefault( defaultConfig ); } else { MPConfigTableHeader( mpfps.pap ); } printf( "\n-------------------------------------" ); printf( "-------------------------------------\n" ); return 0; } /* * set PHYSICAL address of MP floating pointer structure */ static void apic_probe( vm_offset_t* paddr, int* where ) { #if defined( CHEATING ) /** cheat for now, hardcode address */ *paddr = (vm_offset_t)CHEAT_ADDRESS; /** cheat again, where we found it */ *where = 3; #else /** CHEATING */ /* * c rewrite of apic_probe() by Jack F. Vogel */ int x; unsigned short segment; vm_offset_t target; unsigned int buffer[ 16384 ]; if ( 1 ) { /* why can't I access kmem below 0xf0010000? */ fprintf( stderr, "\nWarning: EBDA support is BROKEN!!!\n" ); } else { /* EBDA is @ 40:0e in real-mode terms */ seekEntry( (vm_offset_t)0x040e + KERNBASE ); readEntry( &segment, 2 ); if ( segment ) /* search EBDA */ { target = (vm_offset_t)segment << 4; seekEntry( target + KERNBASE ); readEntry( buffer, ONE_KBYTE ); for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); ++x ) { if ( buffer[ x ] == MP_SIG ) { *where = 1; *paddr = (x * sizeof( unsigned int )) + target; return; } } } } # if 0 /** we should read CMOS for real top of mem, for now: */ # else /* base of the last 1K of 640K */ target = 0x9fc00; # endif seekEntry( target + KERNBASE); readEntry( buffer, ONE_KBYTE ); for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); ++x ) { if ( buffer[ x ] == MP_SIG ) { *where = 2; *paddr = (x * sizeof( unsigned int )) + target; return; } } /* search the BIOS */ seekEntry( BIOS_BASE + KERNBASE ); readEntry( buffer, BIOS_SIZE ); for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); ++x ) { if ( buffer[ x ] == MP_SIG ) { *where = 3; *paddr = (x * sizeof( unsigned int )) + BIOS_BASE; return; } } *where = 0; *paddr = (vm_offset_t)0; #endif /** CHEATING */ } /* * */ static int MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps ) { vm_offset_t vaddr; /* convert physical address to a virtual address */ vaddr = paddr + (vm_offset_t)KERNBASE; /* read in mpfps structure*/ seekEntry( vaddr ); readEntry( mpfps, sizeof( mpfps_t ) ); /* show its contents */ printf( "MP Floating Pointer Structure:\n\n" ); printf( " location:\t\t\t", where ); switch ( where ) { case 0: printf( "NOT found!\n" ); exit( 1 ); case 1: printf( "EBDA\n" ); break; case 2: printf( "base memory\n" ); break; case 3: printf( "BIOS\n" ); break; default: printf( "BOGUS!\n" ); exit( 1 ); } printf( " physical address:\t\t0x%08x\n", paddr ); printf( " signature:\t\t\t'" ); pnstr( mpfps->signature, 4 ); printf( "'\n" ); printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 ); printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev ); printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum ); /* bits 0:6 are RESERVED */ if ( mpfps->mpfb2 & 0x7f ) { printf( " warning, MP feature byte 2: 0x%02x\n" ); } /* bit 7 is IMCRP */ printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & 0x80) ? "PIC" : "Virtual Wire" ); /* MP feature bytes 3-5 are expected to be ZERO */ if ( mpfps->mpfb3 ) printf( " warning, MP feature byte 3 NONZERO!\n" ); if ( mpfps->mpfb4 ) printf( " warning, MP feature byte 4 NONZERO!\n" ); if ( mpfps->mpfb5 ) printf( " warning, MP feature byte 5 NONZERO!\n" ); } /* * */ static void MPConfigDefault( int featureByte ) { printf( " MP default config type: %d\n\n", featureByte ); switch ( featureByte ) { case 1: printf( " bus: ISA, APIC: 82489DX\n" ); break; case 2: printf( " bus: EISA, APIC: 82489DX\n" ); break; case 3: printf( " bus: EISA, APIC: 82489DX\n" ); break; case 4: printf( " bus: MCA, APIC: 82489DX\n" ); break; case 5: printf( " bus: ISA+PCI, APIC: Integrated\n" ); break; case 6: printf( " bus: EISA+PCI, APIC: Integrated\n" ); break; case 7: printf( " bus: MCA+PCI, APIC: Integrated\n" ); break; default: printf( " future type\n" ); break; } } /* * */ static void MPConfigTableHeader( void* pap ) { vm_offset_t vaddr; mpcth_t cth; int totalSize; int count; int type; vm_offset_t voemtp; void* oemdata; if ( pap == 0 ) { printf( "MP Configuration Table Header MISSING!\n" ); exit( 1 ); } /* convert physical address to virtual address */ vaddr = (vm_offset_t)pap + (vm_offset_t)KERNBASE; /* read in cth structure */ seekEntry( vaddr ); readEntry( &cth, sizeof( cth ) ); printf( "MP Config Table Header:\n\n" ); printf( " physical address:\t\t0x%08x\n", pap ); printf( " signature:\t\t\t'" ); pnstr( cth.signature, 4 ); printf( "'\n" ); printf( " base table length:\t\t%d\n", cth.base_table_length ); printf( " version:\t\t\t1.%1d\n", cth.spec_rev ); printf( " checksum:\t\t\t0x%02x\n", cth.checksum ); printf( " OEM ID:\t\t\t'" ); pnstr( cth.oem_id, 8 ); printf( "'\n" ); printf( " Product ID:\t\t\t'" ); pnstr( cth.product_id, 12 ); printf( "'\n" ); printf( " OEM table pointer:\t\t0x%08x\n", cth.oem_table_pointer ); printf( " OEM table size:\t\t%d\n", cth.oem_table_size ); printf( " entry count:\t\t\t%d\n", cth.entry_count ); printf( " local APIC address:\t\t0x%08x\n", cth.apic_address ); printf( " extended table length:\t%d\n", cth.extended_table_length ); printf( " extended table checksum:\t%d\n", cth.extended_table_checksum ); totalSize = cth.base_table_length - sizeof( struct MPCTH ); count = cth.entry_count; printf( "\n-------------------------------------" ); printf( "-------------------------------------\n" ); printf( "MP Config Base Table Entries:\n\n" ); while ( count-- ) { switch ( type = readType() ) { case 0: processorEntry(); break; case 1: busEntry(); break; case 2: ioApicEntry(); break; case 3: intEntry(); break; case 4: intEntry(); break; default: printf( "Base Table HOSED!\n" ); exit( 1 ); } totalSize -= basetableEntryTypes[ type ].length; } #if defined( EXTENDED_PROCESSING_READY ) /* process any extended data */ if ( totalSize = cth.extended_table_length ) { printf( "\n-------------------------------------" ); printf( "-------------------------------------\n" ); printf( "MP Config Extended Table Entries:\n\n" ); while ( totalSize > 0 ) { switch ( type = readType() ) { case 128: sasEntry(); break; case 129: bhdEntry(); break; case 130: cbasmEntry(); break; default: printf( "Extended Table HOSED!\n" ); exit( 1 ); } totalSize -= extendedtableEntryTypes[ type-128 ].length; } } #endif /* EXTENDED_PROCESSING_READY */ /* process any OEM data */ if ( cth.oem_table_pointer && (cth.oem_table_size > 0) ) { #if defined( OEM_PROCESSING_READY ) # error your on your own here! /* convert OEM table pointer to virtual address */ voemtp = (vm_offset_t)cth.oem_table_pointer + (vm_offset_t)KERNBASE; /* read in oem table structure */ if ( (oemdata = (void*)malloc( cth.oem_table_size )) == NULL ) { perror( "oem malloc" ); exit( 1 ); } seekEntry( voemtp ); readEntry( oemdata, cth.oem_table_size ); /** process it */ free( oemdata ); #else printf( "\nyou need to modify the source to handle OEM data!\n\n" ); #endif /* OEM_PROCESSING_READY */ } } /* * */ static int readType( void ) { u_char type; if ( read( kfd, &type, sizeof( u_char ) ) != sizeof( u_char ) ) { perror( "type read" ); exit( 1 ); } if ( lseek( kfd, -1, SEEK_CUR ) < 0 ) { perror( "type seek" ); exit( 1 ); } return (int)type; } /* * */ static void seekEntry( vm_offset_t addr ) { if ( lseek( kfd, (off_t)addr, SEEK_SET ) < 0 ) { fprintf( stderr, "\nvaddr: 0x%08x\n", addr ); perror( "kmem seek" ); exit( 1 ); } } /* * */ static void readEntry( void* entry, int size ) { if ( read( kfd, entry, size ) != size ) { perror( "readEntry" ); exit( 1 ); } } static void processorEntry( void ) { ProcEntry entry; /* read it into local memory */ readEntry( &entry, sizeof( entry ) ); printf( "--\n%s\n", basetableEntryTypes[ entry.type ].name ); printf( " apic ID: %d", entry.apicID ); printf( ", version: %d\n", entry.apicVersion ); printf( " CPU %s usable, CPU %s the bootstrap processor\n", (entry.cpuFlags & PROCENTRY_FLAG_EN) ? "is" : "is NOT", (entry.cpuFlags & PROCENTRY_FLAG_BP) ? "is" : "is NOT" ); printf( " family: %d, model: %d, stepping: %d\n", (entry.cpuSignature >> 8) & 0x0f, (entry.cpuSignature >> 4) & 0x0f, entry.cpuSignature & 0x0f ); printf( " feature flags: 0x%08x\n", entry.featureFlags ); } static void busEntry( void ) { BusEntry entry; /* read it into local memory */ readEntry( &entry, sizeof( entry ) ); printf( "--\n%s\n", basetableEntryTypes[ entry.type ].name ); printf( " bus ID: %d", entry.busID ); printf( ", bus type: " ); pnstr( entry.busType, 6 ); printf( "\n" ); } static void ioApicEntry( void ) { IOApicEntry entry; /* read it into local memory */ readEntry( &entry, sizeof( entry ) ); printf( "--\n%s\n", basetableEntryTypes[ entry.type ].name ); printf( " apic ID: %d", entry.apicID ); printf( ", version: %d\n", entry.apicVersion ); printf( " APIC %s usable\n", (entry.apicFlags & IOAPICENTRY_FLAG_EN) ? "is" : "is NOT" ); printf( " apic address: 0x%x\n", entry.apicAddress ); } static void intEntry( void ) { IntEntry entry; /* read it into local memory */ readEntry( &entry, sizeof( entry ) ); printf( "--\n%s\n", basetableEntryTypes[ entry.type ].name ); printf( " INT type: %d", (int)entry.intType ); printf( ", flags: 0x%04x\n", (int)entry.intFlags ); printf( " source bus ID: %d", (int)entry.srcBusID ); printf( ", IRQ: %d\n", (int)entry.srcBusIRQ ); printf( " destination APIC ID: %d", (int)entry.dstApicID ); printf( ", INT: %d\n", (int)entry.dstApicINT ); } static void sasEntry( void ) { SasEntry entry; /* read it into local memory */ readEntry( &entry, sizeof( entry ) ); printf( "--\n%s\n", extendedtableEntryTypes[ entry.type ].name ); printf( " bus ID: %d", entry.busID ); printf( " address type: " ); switch ( entry.addressType ) { case 0: printf( "I/O address\n" ); break; case 1: printf( "memory address\n" ); break; case 2: printf( "prefetch address\n" ); break; default: printf( "UNKNOWN type\n" ); break; } printf( " address base: 0x%qx\n", entry.addressBase ); printf( " address range: 0x%qx\n", entry.addressLength ); } static void bhdEntry( void ) { BhdEntry entry; /* read it into local memory */ readEntry( &entry, sizeof( entry ) ); printf( "--\n%s\n", extendedtableEntryTypes[ entry.type ].name ); printf( " bus ID: %d", entry.busID ); printf( " bus info: 0x%02x", entry.busInfo ); printf( " parent bus ID: %d", entry.busParent ); } static void cbasmEntry( void ) { CbasmEntry entry; /* read it into local memory */ readEntry( &entry, sizeof( entry ) ); printf( "--\n%s\n", extendedtableEntryTypes[ entry.type ].name ); printf( " bus ID: %d", entry.busID ); printf( " address modifier: %s\n", (entry.addressMod & 0x01) ? "subtract" : "add" ); printf( " predefined range: 0x%08x", entry.predefinedRange ); } /* * */ static void pnstr( char* s, int c ) { char string[ MAXPNSTR + 1 ]; if ( c > MAXPNSTR ) c = MAXPNSTR; strncpy( string, s, c ); string[ c ] = '\0'; printf( "%s", string ); } ----------------------------------- cut --------------------------------------- -- Steve Passe | powered by smp@csn.net | FreeBSD