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