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