1 /* 2 * Copyright (c) 1996, by Steve Passe 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 12 * 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 23 * SUCH DAMAGE. 24 * 25 * $FreeBSD: src/usr.sbin/mptable/mptable.c,v 1.12.2.3 2000/12/11 01:03:34 obrien Exp $ 26 * $DragonFly: src/usr.sbin/mptable/mptable.c,v 1.2 2003/06/17 04:29:57 dillon Exp $ 27 */ 28 29 /* 30 * mptable.c 31 */ 32 33 #define VMAJOR 2 34 #define VMINOR 0 35 #define VDELTA 15 36 37 /* 38 * this will cause the raw mp table to be dumped to /tmp/mpdump 39 * 40 #define RAW_DUMP 41 */ 42 43 #define MP_SIG 0x5f504d5f /* _MP_ */ 44 #define EXTENDED_PROCESSING_READY 45 #define OEM_PROCESSING_READY_NOT 46 47 #include <sys/types.h> 48 #include <err.h> 49 #include <fcntl.h> 50 #include <paths.h> 51 #include <stdio.h> 52 #include <stdlib.h> 53 #include <string.h> 54 #include <unistd.h> 55 56 #define SEP_LINE \ 57 "\n-------------------------------------------------------------------------------\n" 58 59 #define SEP_LINE2 \ 60 "\n===============================================================================\n" 61 62 /* EBDA is @ 40:0e in real-mode terms */ 63 #define EBDA_POINTER 0x040e /* location of EBDA pointer */ 64 65 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */ 66 #define TOPOFMEM_POINTER 0x0413 /* BIOS: base memory size */ 67 68 #define DEFAULT_TOPOFMEM 0xa0000 69 70 #define BIOS_BASE 0xf0000 71 #define BIOS_BASE2 0xe0000 72 #define BIOS_SIZE 0x10000 73 #define ONE_KBYTE 1024 74 75 #define GROPE_AREA1 0x80000 76 #define GROPE_AREA2 0x90000 77 #define GROPE_SIZE 0x10000 78 79 #define PROCENTRY_FLAG_EN 0x01 80 #define PROCENTRY_FLAG_BP 0x02 81 #define IOAPICENTRY_FLAG_EN 0x01 82 83 #define MAXPNSTR 132 84 85 enum busTypes { 86 CBUS = 1, 87 CBUSII = 2, 88 EISA = 3, 89 ISA = 6, 90 PCI = 13, 91 XPRESS = 18, 92 MAX_BUSTYPE = 18, 93 UNKNOWN_BUSTYPE = 0xff 94 }; 95 96 typedef struct BUSTYPENAME { 97 u_char type; 98 char name[ 7 ]; 99 } busTypeName; 100 101 static busTypeName busTypeTable[] = 102 { 103 { CBUS, "CBUS" }, 104 { CBUSII, "CBUSII" }, 105 { EISA, "EISA" }, 106 { UNKNOWN_BUSTYPE, "---" }, 107 { UNKNOWN_BUSTYPE, "---" }, 108 { ISA, "ISA" }, 109 { UNKNOWN_BUSTYPE, "---" }, 110 { UNKNOWN_BUSTYPE, "---" }, 111 { UNKNOWN_BUSTYPE, "---" }, 112 { UNKNOWN_BUSTYPE, "---" }, 113 { UNKNOWN_BUSTYPE, "---" }, 114 { UNKNOWN_BUSTYPE, "---" }, 115 { PCI, "PCI" }, 116 { UNKNOWN_BUSTYPE, "---" }, 117 { UNKNOWN_BUSTYPE, "---" }, 118 { UNKNOWN_BUSTYPE, "---" }, 119 { UNKNOWN_BUSTYPE, "---" }, 120 { UNKNOWN_BUSTYPE, "---" }, 121 { UNKNOWN_BUSTYPE, "---" } 122 }; 123 124 char* whereStrings[] = { 125 "Extended BIOS Data Area", 126 "BIOS top of memory", 127 "Default top of memory", 128 "BIOS", 129 "Extended BIOS", 130 "GROPE AREA #1", 131 "GROPE AREA #2" 132 }; 133 134 typedef struct TABLE_ENTRY { 135 u_char type; 136 u_char length; 137 char name[ 32 ]; 138 } tableEntry; 139 140 tableEntry basetableEntryTypes[] = 141 { 142 { 0, 20, "Processor" }, 143 { 1, 8, "Bus" }, 144 { 2, 8, "I/O APIC" }, 145 { 3, 8, "I/O INT" }, 146 { 4, 8, "Local INT" } 147 }; 148 149 tableEntry extendedtableEntryTypes[] = 150 { 151 { 128, 20, "System Address Space" }, 152 { 129, 8, "Bus Heirarchy" }, 153 { 130, 8, "Compatibility Bus Address" } 154 }; 155 156 /* MP Floating Pointer Structure */ 157 typedef struct MPFPS { 158 char signature[ 4 ]; 159 void* pap; 160 u_char length; 161 u_char spec_rev; 162 u_char checksum; 163 u_char mpfb1; 164 u_char mpfb2; 165 u_char mpfb3; 166 u_char mpfb4; 167 u_char mpfb5; 168 } mpfps_t; 169 170 /* MP Configuration Table Header */ 171 typedef struct MPCTH { 172 char signature[ 4 ]; 173 u_short base_table_length; 174 u_char spec_rev; 175 u_char checksum; 176 u_char oem_id[ 8 ]; 177 u_char product_id[ 12 ]; 178 void* oem_table_pointer; 179 u_short oem_table_size; 180 u_short entry_count; 181 void* apic_address; 182 u_short extended_table_length; 183 u_char extended_table_checksum; 184 u_char reserved; 185 } mpcth_t; 186 187 188 typedef struct PROCENTRY { 189 u_char type; 190 u_char apicID; 191 u_char apicVersion; 192 u_char cpuFlags; 193 u_long cpuSignature; 194 u_long featureFlags; 195 u_long reserved1; 196 u_long reserved2; 197 } ProcEntry; 198 199 typedef struct BUSENTRY { 200 u_char type; 201 u_char busID; 202 char busType[ 6 ]; 203 } BusEntry; 204 205 typedef struct IOAPICENTRY { 206 u_char type; 207 u_char apicID; 208 u_char apicVersion; 209 u_char apicFlags; 210 void* apicAddress; 211 } IOApicEntry; 212 213 typedef struct INTENTRY { 214 u_char type; 215 u_char intType; 216 u_short intFlags; 217 u_char srcBusID; 218 u_char srcBusIRQ; 219 u_char dstApicID; 220 u_char dstApicINT; 221 } IntEntry; 222 223 224 /* 225 * extended entry type structures 226 */ 227 228 typedef struct SASENTRY { 229 u_char type; 230 u_char length; 231 u_char busID; 232 u_char addressType; 233 u_int64_t addressBase; 234 u_int64_t addressLength; 235 } SasEntry; 236 237 238 typedef struct BHDENTRY { 239 u_char type; 240 u_char length; 241 u_char busID; 242 u_char busInfo; 243 u_char busParent; 244 u_char reserved[ 3 ]; 245 } BhdEntry; 246 247 248 typedef struct CBASMENTRY { 249 u_char type; 250 u_char length; 251 u_char busID; 252 u_char addressMod; 253 u_int predefinedRange; 254 } CbasmEntry; 255 256 257 258 static void apic_probe( vm_offset_t* paddr, int* where ); 259 260 static void MPConfigDefault( int featureByte ); 261 262 static void MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps ); 263 static void MPConfigTableHeader( void* pap ); 264 265 static int readType( void ); 266 static void seekEntry( vm_offset_t addr ); 267 static void readEntry( void* entry, int size ); 268 269 static void processorEntry( void ); 270 static void busEntry( void ); 271 static void ioApicEntry( void ); 272 static void intEntry( void ); 273 274 static void sasEntry( void ); 275 static void bhdEntry( void ); 276 static void cbasmEntry( void ); 277 278 static void doDmesg( void ); 279 static void pnstr( char* s, int c ); 280 281 /* global data */ 282 int pfd; /* physical /dev/mem fd */ 283 284 int busses[ 16 ]; 285 int apics[ 16 ]; 286 287 int ncpu; 288 int nbus; 289 int napic; 290 int nintr; 291 292 int dmesg; 293 int grope; 294 int verbose; 295 296 static void 297 usage( void ) 298 { 299 fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" ); 300 exit( 0 ); 301 } 302 303 /* 304 * 305 */ 306 int 307 main( int argc, char *argv[] ) 308 { 309 vm_offset_t paddr; 310 int where; 311 mpfps_t mpfps; 312 int defaultConfig; 313 314 extern int optreset; 315 int ch; 316 317 /* announce ourselves */ 318 puts( SEP_LINE2 ); 319 320 printf( "MPTable, version %d.%d.%d\n", VMAJOR, VMINOR, VDELTA ); 321 322 while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) { 323 switch(ch) { 324 case 'd': 325 if ( strcmp( optarg, "mesg") == 0 ) 326 dmesg = 1; 327 else 328 dmesg = 0; 329 break; 330 case 'h': 331 if ( strcmp( optarg, "elp") == 0 ) 332 usage(); 333 break; 334 case 'g': 335 if ( strcmp( optarg, "rope") == 0 ) 336 grope = 1; 337 break; 338 case 'v': 339 if ( strcmp( optarg, "erbose") == 0 ) 340 verbose = 1; 341 break; 342 default: 343 usage(); 344 } 345 argc -= optind; 346 argv += optind; 347 optreset = 1; 348 optind = 0; 349 } 350 351 /* open physical memory for access to MP structures */ 352 if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 ) 353 err( 1, "mem open" ); 354 355 /* probe for MP structures */ 356 apic_probe( &paddr, &where ); 357 if ( where <= 0 ) { 358 fprintf( stderr, "\n MP FPS NOT found,\n" ); 359 fprintf( stderr, " suggest trying -grope option!!!\n\n" ); 360 return 1; 361 } 362 363 if ( verbose ) 364 printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n", 365 whereStrings[ where - 1 ], paddr ); 366 367 puts( SEP_LINE ); 368 369 /* analyze the MP Floating Pointer Structure */ 370 MPFloatingPointer( paddr, where, &mpfps ); 371 372 puts( SEP_LINE ); 373 374 /* check whether an MP config table exists */ 375 if ( (defaultConfig = mpfps.mpfb1) ) 376 MPConfigDefault( defaultConfig ); 377 else 378 MPConfigTableHeader( mpfps.pap ); 379 380 /* do a dmesg output */ 381 if ( dmesg ) 382 doDmesg(); 383 384 puts( SEP_LINE2 ); 385 386 return 0; 387 } 388 389 390 /* 391 * set PHYSICAL address of MP floating pointer structure 392 */ 393 #define NEXT(X) ((X) += 4) 394 static void 395 apic_probe( vm_offset_t* paddr, int* where ) 396 { 397 /* 398 * c rewrite of apic_probe() by Jack F. Vogel 399 */ 400 401 int x; 402 u_short segment; 403 vm_offset_t target; 404 u_int buffer[ BIOS_SIZE / sizeof( int ) ]; 405 406 if ( verbose ) 407 printf( "\n" ); 408 409 /* search Extended Bios Data Area, if present */ 410 if ( verbose ) 411 printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER ); 412 seekEntry( (vm_offset_t)EBDA_POINTER ); 413 readEntry( &segment, 2 ); 414 if ( segment ) { /* search EBDA */ 415 target = (vm_offset_t)segment << 4; 416 if ( verbose ) 417 printf( "found, searching EBDA @ 0x%08x\n", target ); 418 seekEntry( target ); 419 readEntry( buffer, ONE_KBYTE ); 420 421 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) { 422 if ( buffer[ x ] == MP_SIG ) { 423 *where = 1; 424 *paddr = (x * sizeof( unsigned int )) + target; 425 return; 426 } 427 } 428 } 429 else { 430 if ( verbose ) 431 printf( "NOT found\n" ); 432 } 433 434 /* read CMOS for real top of mem */ 435 seekEntry( (vm_offset_t)TOPOFMEM_POINTER ); 436 readEntry( &segment, 2 ); 437 --segment; /* less ONE_KBYTE */ 438 target = segment * 1024; 439 if ( verbose ) 440 printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n", 441 target, segment ); 442 seekEntry( target ); 443 readEntry( buffer, ONE_KBYTE ); 444 445 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) { 446 if ( buffer[ x ] == MP_SIG ) { 447 *where = 2; 448 *paddr = (x * sizeof( unsigned int )) + target; 449 return; 450 } 451 } 452 453 /* we don't necessarily believe CMOS, check base of the last 1K of 640K */ 454 if ( target != (DEFAULT_TOPOFMEM - 1024)) { 455 target = (DEFAULT_TOPOFMEM - 1024); 456 if ( verbose ) 457 printf( " searching default 'top of mem' @ 0x%08x (%dK)\n", 458 target, (target / 1024) ); 459 seekEntry( target ); 460 readEntry( buffer, ONE_KBYTE ); 461 462 for ( x = 0; x < ONE_KBYTE / sizeof ( unsigned int ); NEXT(x) ) { 463 if ( buffer[ x ] == MP_SIG ) { 464 *where = 3; 465 *paddr = (x * sizeof( unsigned int )) + target; 466 return; 467 } 468 } 469 } 470 471 /* search the BIOS */ 472 if ( verbose ) 473 printf( " searching BIOS @ 0x%08x\n", BIOS_BASE ); 474 seekEntry( BIOS_BASE ); 475 readEntry( buffer, BIOS_SIZE ); 476 477 for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) { 478 if ( buffer[ x ] == MP_SIG ) { 479 *where = 4; 480 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE; 481 return; 482 } 483 } 484 485 /* search the extended BIOS */ 486 if ( verbose ) 487 printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 ); 488 seekEntry( BIOS_BASE2 ); 489 readEntry( buffer, BIOS_SIZE ); 490 491 for ( x = 0; x < BIOS_SIZE / sizeof( unsigned int ); NEXT(x) ) { 492 if ( buffer[ x ] == MP_SIG ) { 493 *where = 5; 494 *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2; 495 return; 496 } 497 } 498 499 if ( grope ) { 500 /* search additional memory */ 501 target = GROPE_AREA1; 502 if ( verbose ) 503 printf( " groping memory @ 0x%08x\n", target ); 504 seekEntry( target ); 505 readEntry( buffer, GROPE_SIZE ); 506 507 for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) { 508 if ( buffer[ x ] == MP_SIG ) { 509 *where = 6; 510 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA1; 511 return; 512 } 513 } 514 515 target = GROPE_AREA2; 516 if ( verbose ) 517 printf( " groping memory @ 0x%08x\n", target ); 518 seekEntry( target ); 519 readEntry( buffer, GROPE_SIZE ); 520 521 for ( x = 0; x < GROPE_SIZE / sizeof( unsigned int ); NEXT(x) ) { 522 if ( buffer[ x ] == MP_SIG ) { 523 *where = 7; 524 *paddr = (x * sizeof( unsigned int )) + GROPE_AREA2; 525 return; 526 } 527 } 528 } 529 530 *where = 0; 531 *paddr = (vm_offset_t)0; 532 } 533 534 535 /* 536 * 537 */ 538 static void 539 MPFloatingPointer( vm_offset_t paddr, int where, mpfps_t* mpfps ) 540 { 541 542 /* read in mpfps structure*/ 543 seekEntry( paddr ); 544 readEntry( mpfps, sizeof( mpfps_t ) ); 545 546 /* show its contents */ 547 printf( "MP Floating Pointer Structure:\n\n" ); 548 549 printf( " location:\t\t\t" ); 550 switch ( where ) 551 { 552 case 1: 553 printf( "EBDA\n" ); 554 break; 555 case 2: 556 printf( "BIOS base memory\n" ); 557 break; 558 case 3: 559 printf( "DEFAULT base memory (639K)\n" ); 560 break; 561 case 4: 562 printf( "BIOS\n" ); 563 break; 564 case 5: 565 printf( "Extended BIOS\n" ); 566 break; 567 568 case 0: 569 printf( "NOT found!\n" ); 570 exit( 1 ); 571 default: 572 printf( "BOGUS!\n" ); 573 exit( 1 ); 574 } 575 printf( " physical address:\t\t0x%08x\n", paddr ); 576 577 printf( " signature:\t\t\t'" ); 578 pnstr( mpfps->signature, 4 ); 579 printf( "'\n" ); 580 581 printf( " length:\t\t\t%d bytes\n", mpfps->length * 16 ); 582 printf( " version:\t\t\t1.%1d\n", mpfps->spec_rev ); 583 printf( " checksum:\t\t\t0x%02x\n", mpfps->checksum ); 584 585 /* bits 0:6 are RESERVED */ 586 if ( mpfps->mpfb2 & 0x7f ) { 587 printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 ); 588 } 589 590 /* bit 7 is IMCRP */ 591 printf( " mode:\t\t\t\t%s\n", (mpfps->mpfb2 & 0x80) ? 592 "PIC" : "Virtual Wire" ); 593 594 /* MP feature bytes 3-5 are expected to be ZERO */ 595 if ( mpfps->mpfb3 ) 596 printf( " warning, MP feature byte 3 NONZERO!\n" ); 597 if ( mpfps->mpfb4 ) 598 printf( " warning, MP feature byte 4 NONZERO!\n" ); 599 if ( mpfps->mpfb5 ) 600 printf( " warning, MP feature byte 5 NONZERO!\n" ); 601 } 602 603 604 /* 605 * 606 */ 607 static void 608 MPConfigDefault( int featureByte ) 609 { 610 printf( " MP default config type: %d\n\n", featureByte ); 611 switch ( featureByte ) { 612 case 1: 613 printf( " bus: ISA, APIC: 82489DX\n" ); 614 break; 615 case 2: 616 printf( " bus: EISA, APIC: 82489DX\n" ); 617 break; 618 case 3: 619 printf( " bus: EISA, APIC: 82489DX\n" ); 620 break; 621 case 4: 622 printf( " bus: MCA, APIC: 82489DX\n" ); 623 break; 624 case 5: 625 printf( " bus: ISA+PCI, APIC: Integrated\n" ); 626 break; 627 case 6: 628 printf( " bus: EISA+PCI, APIC: Integrated\n" ); 629 break; 630 case 7: 631 printf( " bus: MCA+PCI, APIC: Integrated\n" ); 632 break; 633 default: 634 printf( " future type\n" ); 635 break; 636 } 637 638 switch ( featureByte ) { 639 case 1: 640 case 2: 641 case 3: 642 case 4: 643 nbus = 1; 644 break; 645 case 5: 646 case 6: 647 case 7: 648 nbus = 2; 649 break; 650 default: 651 printf( " future type\n" ); 652 break; 653 } 654 655 ncpu = 2; 656 napic = 1; 657 nintr = 16; 658 } 659 660 661 /* 662 * 663 */ 664 static void 665 MPConfigTableHeader( void* pap ) 666 { 667 vm_offset_t paddr; 668 mpcth_t cth; 669 int x; 670 int totalSize, t; 671 int count, c; 672 int type; 673 674 if ( pap == 0 ) { 675 printf( "MP Configuration Table Header MISSING!\n" ); 676 exit( 1 ); 677 } 678 679 /* convert physical address to virtual address */ 680 paddr = (vm_offset_t)pap; 681 682 /* read in cth structure */ 683 seekEntry( paddr ); 684 readEntry( &cth, sizeof( cth ) ); 685 686 printf( "MP Config Table Header:\n\n" ); 687 688 printf( " physical address:\t\t0x%08x\n", pap ); 689 690 printf( " signature:\t\t\t'" ); 691 pnstr( cth.signature, 4 ); 692 printf( "'\n" ); 693 694 printf( " base table length:\t\t%d\n", cth.base_table_length ); 695 696 printf( " version:\t\t\t1.%1d\n", cth.spec_rev ); 697 printf( " checksum:\t\t\t0x%02x\n", cth.checksum ); 698 699 printf( " OEM ID:\t\t\t'" ); 700 pnstr( cth.oem_id, 8 ); 701 printf( "'\n" ); 702 703 printf( " Product ID:\t\t\t'" ); 704 pnstr( cth.product_id, 12 ); 705 printf( "'\n" ); 706 707 printf( " OEM table pointer:\t\t0x%08x\n", cth.oem_table_pointer ); 708 printf( " OEM table size:\t\t%d\n", cth.oem_table_size ); 709 710 printf( " entry count:\t\t\t%d\n", cth.entry_count ); 711 712 printf( " local APIC address:\t\t0x%08x\n", cth.apic_address ); 713 714 printf( " extended table length:\t%d\n", cth.extended_table_length ); 715 printf( " extended table checksum:\t%d\n", cth.extended_table_checksum ); 716 717 totalSize = cth.base_table_length - sizeof( struct MPCTH ); 718 count = cth.entry_count; 719 720 puts( SEP_LINE ); 721 722 printf( "MP Config Base Table Entries:\n\n" ); 723 724 /* initialze tables */ 725 for ( x = 0; x < 16; ++x ) { 726 busses[ x ] = apics[ x ] = 0xff; 727 } 728 729 ncpu = 0; 730 nbus = 0; 731 napic = 0; 732 nintr = 0; 733 734 /* process all the CPUs */ 735 printf( "--\nProcessors:\tAPIC ID\tVersion\tState" 736 "\t\tFamily\tModel\tStep\tFlags\n" ); 737 for ( t = totalSize, c = count; c; c-- ) { 738 if ( readType() == 0 ) 739 processorEntry(); 740 totalSize -= basetableEntryTypes[ 0 ].length; 741 } 742 743 /* process all the busses */ 744 printf( "--\nBus:\t\tBus ID\tType\n" ); 745 for ( t = totalSize, c = count; c; c-- ) { 746 if ( readType() == 1 ) 747 busEntry(); 748 totalSize -= basetableEntryTypes[ 1 ].length; 749 } 750 751 /* process all the apics */ 752 printf( "--\nI/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" ); 753 for ( t = totalSize, c = count; c; c-- ) { 754 if ( readType() == 2 ) 755 ioApicEntry(); 756 totalSize -= basetableEntryTypes[ 2 ].length; 757 } 758 759 /* process all the I/O Ints */ 760 printf( "--\nI/O Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" ); 761 for ( t = totalSize, c = count; c; c-- ) { 762 if ( readType() == 3 ) 763 intEntry(); 764 totalSize -= basetableEntryTypes[ 3 ].length; 765 } 766 767 /* process all the Local Ints */ 768 printf( "--\nLocal Ints:\tType\tPolarity Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" ); 769 for ( t = totalSize, c = count; c; c-- ) { 770 if ( readType() == 4 ) 771 intEntry(); 772 totalSize -= basetableEntryTypes[ 4 ].length; 773 } 774 775 776 #if defined( EXTENDED_PROCESSING_READY ) 777 /* process any extended data */ 778 if ( (totalSize = cth.extended_table_length) ) { 779 puts( SEP_LINE ); 780 781 printf( "MP Config Extended Table Entries:\n\n" ); 782 783 while ( totalSize > 0 ) { 784 switch ( type = readType() ) { 785 case 128: 786 sasEntry(); 787 break; 788 case 129: 789 bhdEntry(); 790 break; 791 case 130: 792 cbasmEntry(); 793 break; 794 default: 795 printf( "Extended Table HOSED!\n" ); 796 exit( 1 ); 797 } 798 799 totalSize -= extendedtableEntryTypes[ type-128 ].length; 800 } 801 } 802 #endif /* EXTENDED_PROCESSING_READY */ 803 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 = (vm_offset_t)cth.oem_table_pointer; 810 811 /* read in oem table structure */ 812 if ( (oemdata = (void*)malloc( cth.oem_table_size )) == NULL ) 813 err( 1, "oem malloc" ); 814 815 seekEntry( poemtp ); 816 readEntry( oemdata, cth.oem_table_size ); 817 818 /** process it */ 819 820 free( oemdata ); 821 #else 822 printf( "\nyou need to modify the source to handle OEM data!\n\n" ); 823 #endif /* OEM_PROCESSING_READY */ 824 } 825 826 fflush( stdout ); 827 828 #if defined( RAW_DUMP ) 829 { 830 int ofd; 831 u_char dumpbuf[ 4096 ]; 832 833 ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR ); 834 seekEntry( paddr ); 835 readEntry( dumpbuf, 1024 ); 836 write( ofd, dumpbuf, 1024 ); 837 close( ofd ); 838 } 839 #endif /* RAW_DUMP */ 840 } 841 842 843 /* 844 * 845 */ 846 static int 847 readType( void ) 848 { 849 u_char type; 850 851 if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) ) 852 err( 1, "type read; pfd: %d", pfd ); 853 854 if ( lseek( pfd, -1, SEEK_CUR ) < 0 ) 855 err( 1, "type seek" ); 856 857 return (int)type; 858 } 859 860 861 /* 862 * 863 */ 864 static void 865 seekEntry( vm_offset_t addr ) 866 { 867 if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 ) 868 err( 1, "%s seek", _PATH_MEM ); 869 } 870 871 872 /* 873 * 874 */ 875 static void 876 readEntry( void* entry, int size ) 877 { 878 if ( read( pfd, entry, size ) != size ) 879 err( 1, "readEntry" ); 880 } 881 882 883 static void 884 processorEntry( void ) 885 { 886 ProcEntry entry; 887 888 /* read it into local memory */ 889 readEntry( &entry, sizeof( entry ) ); 890 891 /* count it */ 892 ++ncpu; 893 894 printf( "\t\t%2d", entry.apicID ); 895 printf( "\t 0x%2x", entry.apicVersion ); 896 897 printf( "\t %s, %s", 898 (entry.cpuFlags & PROCENTRY_FLAG_BP) ? "BSP" : "AP", 899 (entry.cpuFlags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" ); 900 901 printf( "\t %d\t %d\t %d", 902 (entry.cpuSignature >> 8) & 0x0f, 903 (entry.cpuSignature >> 4) & 0x0f, 904 entry.cpuSignature & 0x0f ); 905 906 printf( "\t 0x%04x\n", entry.featureFlags ); 907 } 908 909 910 /* 911 * 912 */ 913 static int 914 lookupBusType( char* name ) 915 { 916 int x; 917 918 for ( x = 0; x < MAX_BUSTYPE; ++x ) 919 if ( strcmp( busTypeTable[ x ].name, name ) == 0 ) 920 return busTypeTable[ x ].type; 921 922 return UNKNOWN_BUSTYPE; 923 } 924 925 926 static void 927 busEntry( void ) 928 { 929 int x; 930 char name[ 8 ]; 931 char c; 932 BusEntry entry; 933 934 /* read it into local memory */ 935 readEntry( &entry, sizeof( entry ) ); 936 937 /* count it */ 938 ++nbus; 939 940 printf( "\t\t%2d", entry.busID ); 941 printf( "\t " ); pnstr( entry.busType, 6 ); printf( "\n" ); 942 943 for ( x = 0; x < 6; ++x ) { 944 if ( (c = entry.busType[ x ]) == ' ' ) 945 break; 946 name[ x ] = c; 947 } 948 name[ x ] = '\0'; 949 busses[ entry.busID ] = lookupBusType( name ); 950 } 951 952 953 static void 954 ioApicEntry( void ) 955 { 956 IOApicEntry entry; 957 958 /* read it into local memory */ 959 readEntry( &entry, sizeof( entry ) ); 960 961 /* count it */ 962 ++napic; 963 964 printf( "\t\t%2d", entry.apicID ); 965 printf( "\t 0x%02x", entry.apicVersion ); 966 printf( "\t %s", 967 (entry.apicFlags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" ); 968 printf( "\t\t 0x%x\n", entry.apicAddress ); 969 970 apics[ entry.apicID ] = entry.apicID; 971 } 972 973 974 char* intTypes[] = { 975 "INT", "NMI", "SMI", "ExtINT" 976 }; 977 978 char* polarityMode[] = { 979 "conforms", "active-hi", "reserved", "active-lo" 980 }; 981 char* triggerMode[] = { 982 "conforms", "edge", "reserved", "level" 983 }; 984 985 static void 986 intEntry( void ) 987 { 988 IntEntry entry; 989 990 /* read it into local memory */ 991 readEntry( &entry, sizeof( entry ) ); 992 993 /* count it */ 994 if ( (int)entry.type == 3 ) 995 ++nintr; 996 997 printf( "\t\t%s", intTypes[ (int)entry.intType ] ); 998 999 printf( "\t%9s", polarityMode[ (int)entry.intFlags & 0x03 ] ); 1000 printf( "%12s", triggerMode[ ((int)entry.intFlags >> 2) & 0x03 ] ); 1001 1002 printf( "\t %5d", (int)entry.srcBusID ); 1003 if ( busses[ (int)entry.srcBusID ] == PCI ) 1004 printf( "\t%2d:%c", 1005 ((int)entry.srcBusIRQ >> 2) & 0x1f, 1006 ((int)entry.srcBusIRQ & 0x03) + 'A' ); 1007 else 1008 printf( "\t %3d", (int)entry.srcBusIRQ ); 1009 printf( "\t %6d", (int)entry.dstApicID ); 1010 printf( "\t %3d\n", (int)entry.dstApicINT ); 1011 } 1012 1013 1014 static void 1015 sasEntry( void ) 1016 { 1017 SasEntry entry; 1018 1019 /* read it into local memory */ 1020 readEntry( &entry, sizeof( entry ) ); 1021 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 ) { 1026 case 0: 1027 printf( "I/O address\n" ); 1028 break; 1029 case 1: 1030 printf( "memory address\n" ); 1031 break; 1032 case 2: 1033 printf( "prefetch address\n" ); 1034 break; 1035 default: 1036 printf( "UNKNOWN type\n" ); 1037 break; 1038 } 1039 1040 printf( " address base: 0x%qx\n", entry.addressBase ); 1041 printf( " address range: 0x%qx\n", entry.addressLength ); 1042 } 1043 1044 1045 static void 1046 bhdEntry( void ) 1047 { 1048 BhdEntry entry; 1049 1050 /* read it into local memory */ 1051 readEntry( &entry, sizeof( entry ) ); 1052 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 ); 1057 } 1058 1059 1060 static void 1061 cbasmEntry( void ) 1062 { 1063 CbasmEntry entry; 1064 1065 /* read it into local memory */ 1066 readEntry( &entry, sizeof( entry ) ); 1067 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 ); 1073 } 1074 1075 1076 /* 1077 * do a dmesg output 1078 */ 1079 static void 1080 doDmesg( void ) 1081 { 1082 puts( SEP_LINE ); 1083 1084 printf( "dmesg output:\n\n" ); 1085 fflush( stdout ); 1086 system( "dmesg" ); 1087 } 1088 1089 1090 /* 1091 * 1092 */ 1093 static void 1094 pnstr( char* s, int c ) 1095 { 1096 char string[ MAXPNSTR + 1 ]; 1097 1098 if ( c > MAXPNSTR ) 1099 c = MAXPNSTR; 1100 strncpy( string, s, c ); 1101 string[ c ] = '\0'; 1102 printf( "%s", string ); 1103 } 1104