xref: /freebsd/usr.sbin/mptable/mptable.c (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1996, by Steve Passe
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  */
27 
28 /*
29  * mptable.c
30  */
31 
32 /*
33  * this will cause the raw mp table to be dumped to /tmp/mpdump
34  *
35 #define RAW_DUMP
36  */
37 
38 #define MP_SIG			0x5f504d5f	/* _MP_ */
39 #define EXTENDED_PROCESSING_READY
40 #define OEM_PROCESSING_READY_NOT
41 
42 #include <sys/param.h>
43 #include <sys/mman.h>
44 #include <x86/mptable.h>
45 #include <err.h>
46 #include <fcntl.h>
47 #include <paths.h>
48 #include <stdint.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <unistd.h>
53 
54 #define SEP_LINE \
55 "\n-------------------------------------------------------------------------------\n"
56 
57 #define SEP_LINE2 \
58 "\n===============================================================================\n"
59 
60 /* EBDA is @ 40:0e in real-mode terms */
61 #define EBDA_POINTER		0x040e		/* location of EBDA pointer */
62 
63 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
64 #define TOPOFMEM_POINTER	0x0413		/* BIOS: base memory size */
65 
66 #define DEFAULT_TOPOFMEM	0xa0000
67 
68 #define BIOS_BASE		0xf0000
69 #define BIOS_BASE2		0xe0000
70 #define BIOS_SIZE		0x10000
71 #define ONE_KBYTE		1024
72 
73 #define GROPE_AREA1		0x80000
74 #define GROPE_AREA2		0x90000
75 #define GROPE_SIZE		0x10000
76 
77 #define MAXPNSTR		132
78 
79 typedef struct BUSTYPENAME {
80     u_char	type;
81     char	name[ 7 ];
82 } busTypeName;
83 
84 static const busTypeName busTypeTable[] =
85 {
86     { CBUS,		"CBUS"   },
87     { CBUSII,		"CBUSII" },
88     { EISA,		"EISA"   },
89     { UNKNOWN_BUSTYPE,	"---"    },
90     { UNKNOWN_BUSTYPE,	"---"    },
91     { ISA,		"ISA"    },
92     { UNKNOWN_BUSTYPE,	"---"    },
93     { UNKNOWN_BUSTYPE,	"---"    },
94     { UNKNOWN_BUSTYPE,	"---"    },
95     { UNKNOWN_BUSTYPE,	"---"    },
96     { UNKNOWN_BUSTYPE,	"---"    },
97     { UNKNOWN_BUSTYPE,	"---"    },
98     { PCI,		"PCI"    },
99     { UNKNOWN_BUSTYPE,	"---"    },
100     { UNKNOWN_BUSTYPE,	"---"    },
101     { UNKNOWN_BUSTYPE,	"---"    },
102     { UNKNOWN_BUSTYPE,	"---"    },
103     { UNKNOWN_BUSTYPE,	"---"    },
104     { UNKNOWN_BUSTYPE,	"---"    }
105 };
106 
107 static const char *whereStrings[] = {
108     "Extended BIOS Data Area",
109     "BIOS top of memory",
110     "Default top of memory",
111     "BIOS",
112     "Extended BIOS",
113     "GROPE AREA #1",
114     "GROPE AREA #2"
115 };
116 
117 static void apic_probe( u_int32_t* paddr, int* where );
118 
119 static void MPConfigDefault( int featureByte );
120 
121 static void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp );
122 static void MPConfigTableHeader( u_int32_t pap );
123 
124 static void seekEntry( u_int32_t addr );
125 static void readEntry( void* entry, int size );
126 static void *mapEntry( u_int32_t addr, int size );
127 
128 static void processorEntry( proc_entry_ptr entry );
129 static void busEntry( bus_entry_ptr entry );
130 static void ioApicEntry( io_apic_entry_ptr entry );
131 static void intEntry( int_entry_ptr entry );
132 
133 static void sasEntry( sas_entry_ptr entry );
134 static void bhdEntry( bhd_entry_ptr entry );
135 static void cbasmEntry( cbasm_entry_ptr entry );
136 
137 static void doDmesg( void );
138 static void pnstr( char* s, int c );
139 
140 /* global data */
141 static int	pfd;		/* physical /dev/mem fd */
142 
143 static int	busses[256];
144 static int	apics[256];
145 
146 static int	ncpu;
147 static int	nbus;
148 static int	napic;
149 static int	nintr;
150 
151 static int	dmesg;
152 static int	grope;
153 static int	verbose;
154 
155 static void
156 usage( void )
157 {
158     fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
159     exit( 0 );
160 }
161 
162 /*
163  *
164  */
165 int
166 main( int argc, char *argv[] )
167 {
168     u_int32_t	paddr;
169     int		where;
170     mpfps_t	mpfps;
171     int		defaultConfig;
172 
173     int		ch;
174 
175     /* announce ourselves */
176     puts( SEP_LINE2 );
177 
178     printf( "MPTable\n" );
179 
180     while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
181 	switch(ch) {
182 	case 'd':
183 	    if ( strcmp( optarg, "mesg") == 0 )
184 	        dmesg = 1;
185 	    else
186 		usage();
187 	    break;
188 	case 'h':
189 	    usage();
190 	case 'g':
191 	    if ( strcmp( optarg, "rope") == 0 )
192 	        grope = 1;
193 	    else
194 		usage();
195 	    break;
196 	case 'v':
197 	    if ( strcmp( optarg, "erbose") == 0 )
198 	        verbose = 1;
199 	    else
200 		usage();
201 	    break;
202 	default:
203 	    usage();
204 	}
205 	argc -= optind;
206 	argv += optind;
207 	optreset = 1;
208 	optind = 0;
209     }
210 
211     /* open physical memory for access to MP structures */
212     if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
213         err( 1, "mem open" );
214 
215     /* probe for MP structures */
216     apic_probe( &paddr, &where );
217     if ( where <= 0 ) {
218         fprintf( stderr, "\n MP FPS NOT found,\n" );
219         if (!grope)
220             fprintf( stderr, " suggest trying -grope option!!!\n\n" );
221         return 1;
222     }
223 
224     if ( verbose )
225         printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
226 	      whereStrings[ where - 1 ], paddr );
227 
228     puts( SEP_LINE );
229 
230     /* analyze the MP Floating Pointer Structure */
231     MPFloatingPointer( paddr, where, &mpfps );
232 
233     puts( SEP_LINE );
234 
235     /* check whether an MP config table exists */
236     if ( (defaultConfig = mpfps->config_type) )
237         MPConfigDefault( defaultConfig );
238     else
239 	MPConfigTableHeader( mpfps->pap );
240 
241     /* do a dmesg output */
242     if ( dmesg )
243         doDmesg();
244 
245     puts( SEP_LINE2 );
246 
247     return 0;
248 }
249 
250 
251 /*
252  * set PHYSICAL address of MP floating pointer structure
253  */
254 #define NEXT(X)		((X) += 4)
255 static void
256 apic_probe( u_int32_t* paddr, int* where )
257 {
258     /*
259      * c rewrite of apic_probe() by Jack F. Vogel
260      */
261 
262     int		x;
263     u_short	segment;
264     u_int32_t	target;
265     u_int	buffer[ BIOS_SIZE / sizeof( int ) ];
266 
267     if ( verbose )
268         printf( "\n" );
269 
270     /* search Extended Bios Data Area, if present */
271     if ( verbose )
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;
277 	if ( verbose )
278 	    printf( "found, searching EBDA @ 0x%08x\n", target );
279         seekEntry( target );
280         readEntry( buffer, ONE_KBYTE );
281 
282         for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
283             if ( buffer[ x ] == MP_SIG ) {
284                 *where = 1;
285                 *paddr = (x * sizeof( unsigned int )) + target;
286                 return;
287             }
288         }
289     }
290     else {
291 	if ( verbose )
292 	    printf( "NOT found\n" );
293     }
294 
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;
300     if ( verbose )
301         printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
302 	        target, segment );
303     seekEntry( target );
304     readEntry( buffer, ONE_KBYTE );
305 
306     for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
307         if ( buffer[ x ] == MP_SIG ) {
308             *where = 2;
309             *paddr = (x * sizeof( unsigned int )) + target;
310             return;
311         }
312     }
313 
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);
317 	if ( verbose )
318 	    printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
319 		    target, (target / 1024) );
320 	seekEntry( target );
321 	readEntry( buffer, ONE_KBYTE );
322 
323 	for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
324 	    if ( buffer[ x ] == MP_SIG ) {
325 		*where = 3;
326 		*paddr = (x * sizeof( unsigned int )) + target;
327 		return;
328 	    }
329 	}
330     }
331 
332     /* search the BIOS */
333     if ( verbose )
334         printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
335     seekEntry( BIOS_BASE );
336     readEntry( buffer, BIOS_SIZE );
337 
338     for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
339         if ( buffer[ x ] == MP_SIG ) {
340             *where = 4;
341             *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
342             return;
343         }
344     }
345 
346     /* search the extended BIOS */
347     if ( verbose )
348         printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
349     seekEntry( BIOS_BASE2 );
350     readEntry( buffer, BIOS_SIZE );
351 
352     for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
353         if ( buffer[ x ] == MP_SIG ) {
354             *where = 5;
355             *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
356             return;
357         }
358     }
359 
360     if ( grope ) {
361 	/* search additional memory */
362 	target = GROPE_AREA1;
363 	if ( verbose )
364 	    printf( " groping memory @ 0x%08x\n", target );
365 	seekEntry( target );
366 	readEntry( buffer, GROPE_SIZE );
367 
368 	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
369 	    if ( buffer[ x ] == MP_SIG ) {
370 		*where = 6;
371 		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
372 		return;
373 	    }
374 	}
375 
376 	target = GROPE_AREA2;
377 	if ( verbose )
378 	    printf( " groping memory @ 0x%08x\n", target );
379 	seekEntry( target );
380 	readEntry( buffer, GROPE_SIZE );
381 
382 	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
383 	    if ( buffer[ x ] == MP_SIG ) {
384 		*where = 7;
385 		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
386 		return;
387 	    }
388 	}
389     }
390 
391     *where = 0;
392     *paddr = (u_int32_t)0;
393 }
394 
395 
396 /*
397  *
398  */
399 static void
400 MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp )
401 {
402     mpfps_t mpfps;
403 
404     /* map in mpfps structure*/
405     *mpfpsp = mpfps = mapEntry( paddr, sizeof( *mpfps ) );
406 
407     /* show its contents */
408     printf( "MP Floating Pointer Structure:\n\n" );
409 
410     printf( "  location:\t\t\t" );
411     switch ( where )
412     {
413     case 1:
414 	printf( "EBDA\n" );
415 	break;
416     case 2:
417 	printf( "BIOS base memory\n" );
418 	break;
419     case 3:
420 	printf( "DEFAULT base memory (639K)\n" );
421 	break;
422     case 4:
423 	printf( "BIOS\n" );
424 	break;
425     case 5:
426 	printf( "Extended BIOS\n" );
427 	break;
428 
429     case 0:
430 	printf( "NOT found!\n" );
431 	exit( 1 );
432     default:
433 	printf( "BOGUS!\n" );
434 	exit( 1 );
435     }
436     printf( "  physical address:\t\t0x%08x\n", paddr );
437 
438     printf( "  signature:\t\t\t'" );
439     pnstr( mpfps->signature, 4 );
440     printf( "'\n" );
441 
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 );
445 
446     /* bits 0:6 are RESERVED */
447     if ( mpfps->mpfb2 & 0x7f ) {
448         printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
449     }
450 
451     /* bit 7 is IMCRP */
452     printf( "  mode:\t\t\t\t%s\n", (mpfps->mpfb2 & MPFB2_IMCR_PRESENT) ?
453             "PIC" : "Virtual Wire" );
454 
455     /* MP feature bytes 3-5 are expected to be ZERO */
456     if ( mpfps->mpfb3 )
457         printf( " warning, MP feature byte 3 NONZERO!\n" );
458     if ( mpfps->mpfb4 )
459         printf( " warning, MP feature byte 4 NONZERO!\n" );
460     if ( mpfps->mpfb5 )
461         printf( " warning, MP feature byte 5 NONZERO!\n" );
462 }
463 
464 
465 /*
466  *
467  */
468 static void
469 MPConfigDefault( int featureByte )
470 {
471     printf( "  MP default config type: %d\n\n", featureByte );
472     switch ( featureByte ) {
473     case 1:
474 	printf( "   bus: ISA, APIC: 82489DX\n" );
475 	break;
476     case 2:
477 	printf( "   bus: EISA, APIC: 82489DX\n" );
478 	break;
479     case 3:
480 	printf( "   bus: EISA, APIC: 82489DX\n" );
481 	break;
482     case 4:
483 	printf( "   bus: MCA, APIC: 82489DX\n" );
484 	break;
485     case 5:
486 	printf( "   bus: ISA+PCI, APIC: Integrated\n" );
487 	break;
488     case 6:
489 	printf( "   bus: EISA+PCI, APIC: Integrated\n" );
490 	break;
491     case 7:
492 	printf( "   bus: MCA+PCI, APIC: Integrated\n" );
493 	break;
494     default:
495 	printf( "   future type\n" );
496 	break;
497     }
498 
499     switch ( featureByte ) {
500     case 1:
501     case 2:
502     case 3:
503     case 4:
504 	nbus = 1;
505 	break;
506     case 5:
507     case 6:
508     case 7:
509 	nbus = 2;
510 	break;
511     default:
512 	printf( "   future type\n" );
513 	break;
514     }
515 
516     ncpu = 2;
517     napic = 1;
518     nintr = 16;
519 }
520 
521 
522 /*
523  *
524  */
525 static void
526 MPConfigTableHeader( u_int32_t pap )
527 {
528     mpcth_t	cth;
529     int		x;
530     int		c;
531     int		oldtype, entrytype;
532     u_int8_t	*entry;
533 
534     if ( pap == 0 ) {
535 	printf( "MP Configuration Table Header MISSING!\n" );
536         exit( 1 );
537     }
538 
539     /* map in cth structure */
540     cth = mapEntry( pap, sizeof( *cth ) );
541 
542     printf( "MP Config Table Header:\n\n" );
543 
544     printf( "  physical address:\t\t0x%08x\n", pap );
545 
546     printf( "  signature:\t\t\t'" );
547     pnstr( cth->signature, 4 );
548     printf( "'\n" );
549 
550     printf( "  base table length:\t\t%d\n", cth->base_table_length );
551 
552     printf( "  version:\t\t\t1.%1d\n", cth->spec_rev );
553     printf( "  checksum:\t\t\t0x%02x\n", cth->checksum );
554 
555     printf( "  OEM ID:\t\t\t'" );
556     pnstr( cth->oem_id, 8 );
557     printf( "'\n" );
558 
559     printf( "  Product ID:\t\t\t'" );
560     pnstr( cth->product_id, 12 );
561     printf( "'\n" );
562 
563     printf( "  OEM table pointer:\t\t0x%08x\n", cth->oem_table_pointer );
564     printf( "  OEM table size:\t\t%d\n", cth->oem_table_size );
565 
566     printf( "  entry count:\t\t\t%d\n", cth->entry_count );
567 
568     printf( "  local APIC address:\t\t0x%08x\n", cth->apic_address );
569 
570     printf( "  extended table length:\t%d\n", cth->extended_table_length );
571     printf( "  extended table checksum:\t%d\n", cth->extended_table_checksum );
572 
573     puts( SEP_LINE );
574 
575     printf( "MP Config Base Table Entries:\n\n" );
576 
577     /* initialize tables */
578     for (x = 0; x < (int)nitems(busses); x++)
579 	busses[x] = 0xff;
580 
581     for (x = 0; x < (int)nitems(apics); x++)
582 	apics[x] = 0xff;
583 
584     ncpu = 0;
585     nbus = 0;
586     napic = 0;
587     nintr = 0;
588 
589     oldtype = -1;
590     entry = mapEntry(pap + sizeof(*cth), cth->base_table_length);
591     for (c = cth->entry_count; c; c--) {
592 	entrytype = *entry;
593 	if (entrytype != oldtype)
594 	    printf("--\n");
595 	if (entrytype < oldtype)
596 	    printf("MPTABLE OUT OF ORDER!\n");
597 	switch (entrytype) {
598 	case MPCT_ENTRY_PROCESSOR:
599 	    if (oldtype != MPCT_ENTRY_PROCESSOR)
600 		printf( "Processors:\tAPIC ID\tVersion\tState"
601 			"\t\tFamily\tModel\tStep\tFlags\n" );
602 	    processorEntry((proc_entry_ptr)entry);
603 	    entry += sizeof(struct PROCENTRY);
604 	    break;
605 
606 	case MPCT_ENTRY_BUS:
607 	    if (oldtype != MPCT_ENTRY_BUS)
608 		printf( "Bus:\t\tBus ID\tType\n" );
609 	    busEntry((bus_entry_ptr)entry);
610 	    entry += sizeof(struct BUSENTRY);
611 	    break;
612 
613 	case MPCT_ENTRY_IOAPIC:
614 	    if (oldtype != MPCT_ENTRY_IOAPIC)
615 		printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
616 	    ioApicEntry((io_apic_entry_ptr)entry);
617 	    entry += sizeof(struct IOAPICENTRY);
618 	    break;
619 
620 	case MPCT_ENTRY_INT:
621 	    if (oldtype != MPCT_ENTRY_INT)
622 		printf( "I/O Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
623 	    intEntry((int_entry_ptr)entry);
624 	    entry += sizeof(struct INTENTRY);
625 	    break;
626 
627 	case MPCT_ENTRY_LOCAL_INT:
628 	    if (oldtype != MPCT_ENTRY_LOCAL_INT)
629 		printf( "Local Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
630 	    intEntry((int_entry_ptr)entry);
631 	    entry += sizeof(struct INTENTRY);
632 	    break;
633 
634 	default:
635 	    printf("MPTABLE HOSED! record type = %d\n", entrytype);
636 	    exit(1);
637 	}
638 	oldtype = entrytype;
639     }
640 
641 
642 #if defined( EXTENDED_PROCESSING_READY )
643     /* process any extended data */
644     if ( cth->extended_table_length ) {
645 	ext_entry_ptr ext_entry, end;
646 
647 	puts( SEP_LINE );
648 
649         printf( "MP Config Extended Table Entries:\n\n" );
650 
651 	ext_entry = mapEntry(pap + cth->base_table_length,
652 	    cth->extended_table_length);
653 	end = (ext_entry_ptr)((char *)ext_entry + cth->extended_table_length);
654 	while (ext_entry < end) {
655 	    switch (ext_entry->type) {
656             case MPCT_EXTENTRY_SAS:
657 		sasEntry((sas_entry_ptr)ext_entry);
658 		break;
659             case MPCT_EXTENTRY_BHD:
660 		bhdEntry((bhd_entry_ptr)ext_entry);
661 		break;
662             case MPCT_EXTENTRY_CBASM:
663 		cbasmEntry((cbasm_entry_ptr)ext_entry);
664 		break;
665             default:
666                 printf( "Extended Table HOSED!\n" );
667                 exit( 1 );
668             }
669 
670 	    ext_entry = (ext_entry_ptr)((char *)ext_entry + ext_entry->length);
671         }
672     }
673 #endif  /* EXTENDED_PROCESSING_READY */
674 
675     /* process any OEM data */
676     if ( cth->oem_table_pointer && (cth->oem_table_size > 0) ) {
677 #if defined( OEM_PROCESSING_READY )
678 # error your on your own here!
679         /* map in oem table structure */
680 	oemdata = mapEntry( cth->oem_table_pointer, cth->oem_table_size);
681 
682         /** process it */
683 #else
684         printf( "\nyou need to modify the source to handle OEM data!\n\n" );
685 #endif  /* OEM_PROCESSING_READY */
686     }
687 
688     fflush( stdout );
689 
690 #if defined( RAW_DUMP )
691 {
692     int		ofd;
693     void	*dumpbuf;
694 
695     ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
696 
697     dumpbuf = mapEntry( paddr, 1024 );
698     write( ofd, dumpbuf, 1024 );
699     close( ofd );
700 }
701 #endif /* RAW_DUMP */
702 }
703 
704 
705 /*
706  *
707  */
708 static void
709 seekEntry( u_int32_t addr )
710 {
711     if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
712         err( 1, "%s seek", _PATH_MEM );
713 }
714 
715 
716 /*
717  *
718  */
719 static void
720 readEntry( void* entry, int size )
721 {
722     if ( read( pfd, entry, size ) != size )
723         err( 1, "readEntry" );
724 }
725 
726 static void *
727 mapEntry( u_int32_t addr, int size )
728 {
729     void	*p;
730 
731     p = mmap( NULL, size, PROT_READ, MAP_SHARED, pfd, addr );
732     if (p == MAP_FAILED)
733 	err( 1, "mapEntry" );
734     return (p);
735 }
736 
737 static void
738 processorEntry( proc_entry_ptr entry )
739 {
740 
741     /* count it */
742     ++ncpu;
743 
744     printf( "\t\t%2d", entry->apic_id );
745     printf( "\t 0x%2x", entry->apic_version );
746 
747     printf( "\t %s, %s",
748             (entry->cpu_flags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
749             (entry->cpu_flags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
750 
751     printf( "\t %d\t %d\t %d",
752             (entry->cpu_signature >> 8) & 0x0f,
753             (entry->cpu_signature >> 4) & 0x0f,
754             entry->cpu_signature & 0x0f );
755 
756     printf( "\t 0x%04x\n", entry->feature_flags );
757 }
758 
759 
760 /*
761  *
762  */
763 static int
764 lookupBusType( char* name )
765 {
766     int x;
767 
768     for ( x = 0; x < MAX_BUSTYPE; ++x )
769 	if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
770 	    return busTypeTable[ x ].type;
771 
772     return UNKNOWN_BUSTYPE;
773 }
774 
775 
776 static void
777 busEntry( bus_entry_ptr entry )
778 {
779     int		x;
780     char	name[ 8 ];
781     char	c;
782 
783     /* count it */
784     ++nbus;
785 
786     printf( "\t\t%2d", entry->bus_id );
787     printf( "\t " ); pnstr( entry->bus_type, 6 ); printf( "\n" );
788 
789     for ( x = 0; x < 6; ++x ) {
790 	if ( (c = entry->bus_type[ x ]) == ' ' )
791 	    break;
792 	name[ x ] = c;
793     }
794     name[ x ] = '\0';
795     busses[ entry->bus_id ] = lookupBusType( name );
796 }
797 
798 
799 static void
800 ioApicEntry( io_apic_entry_ptr entry )
801 {
802 
803     /* count it */
804     ++napic;
805 
806     printf( "\t\t%2d", entry->apic_id );
807     printf( "\t 0x%02x", entry->apic_version );
808     printf( "\t %s",
809             (entry->apic_flags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
810     printf( "\t\t 0x%x\n", entry->apic_address );
811 
812     apics[ entry->apic_id ] = entry->apic_id;
813 }
814 
815 
816 static const char *intTypes[] = {
817     "INT", "NMI", "SMI", "ExtINT"
818 };
819 
820 static const char *polarityMode[] = {
821     "conforms", "active-hi", "reserved", "active-lo"
822 };
823 static const char *triggerMode[] = {
824     "conforms", "edge", "reserved", "level"
825 };
826 
827 static void
828 intEntry( int_entry_ptr entry )
829 {
830 
831     /* count it */
832     if ( entry->type == MPCT_ENTRY_INT )
833 	++nintr;
834 
835     printf( "\t\t%s", intTypes[ entry->int_type ] );
836 
837     printf( "\t%9s", polarityMode[ entry->int_flags & INTENTRY_FLAGS_POLARITY ] );
838     printf( "%12s", triggerMode[ (entry->int_flags & INTENTRY_FLAGS_TRIGGER) >> 2 ] );
839 
840     printf( "\t %5d", entry->src_bus_id );
841     if ( busses[ entry->src_bus_id ] == PCI )
842 	printf( "\t%2d:%c",
843 	        (entry->src_bus_irq >> 2) & 0x1f,
844 	        (entry->src_bus_irq & 0x03) + 'A' );
845     else
846 	printf( "\t %3d", entry->src_bus_irq );
847     printf( "\t %6d", entry->dst_apic_id );
848     printf( "\t %3d\n", entry->dst_apic_int );
849 }
850 
851 
852 static void
853 sasEntry( sas_entry_ptr entry )
854 {
855 
856     printf( "--\nSystem Address Space\n");
857     printf( " bus ID: %d", entry->bus_id );
858     printf( " address type: " );
859     switch ( entry->address_type ) {
860     case SASENTRY_TYPE_IO:
861 	printf( "I/O address\n" );
862 	break;
863     case SASENTRY_TYPE_MEMORY:
864 	printf( "memory address\n" );
865 	break;
866     case SASENTRY_TYPE_PREFETCH:
867 	printf( "prefetch address\n" );
868 	break;
869     default:
870 	printf( "UNKNOWN type\n" );
871 	break;
872     }
873 
874     printf( " address base: 0x%jx\n", (uintmax_t)entry->address_base );
875     printf( " address range: 0x%jx\n", (uintmax_t)entry->address_length );
876 }
877 
878 
879 static void
880 bhdEntry( bhd_entry_ptr entry )
881 {
882 
883     printf( "--\nBus Hierarchy\n" );
884     printf( " bus ID: %d", entry->bus_id );
885     printf( " bus info: 0x%02x", entry->bus_info );
886     printf( " parent bus ID: %d\n", entry->parent_bus );
887 }
888 
889 
890 static void
891 cbasmEntry( cbasm_entry_ptr entry )
892 {
893 
894     printf( "--\nCompatibility Bus Address\n" );
895     printf( " bus ID: %d", entry->bus_id );
896     printf( " address modifier: %s\n",
897 	(entry->address_mod & CBASMENTRY_ADDRESS_MOD_SUBTRACT) ?
898 	"subtract" : "add" );
899     printf( " predefined range: 0x%08x\n", entry->predefined_range );
900 }
901 
902 
903 /*
904  * do a dmesg output
905  */
906 static void
907 doDmesg( void )
908 {
909     puts( SEP_LINE );
910 
911     printf( "dmesg output:\n\n" );
912     fflush( stdout );
913     system( "dmesg" );
914 }
915 
916 
917 /*
918  *
919  */
920 static void
921 pnstr( char* s, int c )
922 {
923     char string[ MAXPNSTR + 1 ];
924 
925     if ( c > MAXPNSTR )
926         c = MAXPNSTR;
927     strncpy( string, s, c );
928     string[ c ] = '\0';
929     printf( "%s", string );
930 }
931