xref: /freebsd/usr.sbin/mptable/mptable.c (revision 11500481c82c9fa6e7d3b9a707bd9ca1ed637c2d)
11de7b4b8SPedro F. Giffuni /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
42b33a0f9SSteve Passe  * Copyright (c) 1996, by Steve Passe
52b33a0f9SSteve Passe  * All rights reserved.
62b33a0f9SSteve Passe  *
72b33a0f9SSteve Passe  * Redistribution and use in source and binary forms, with or without
82b33a0f9SSteve Passe  * modification, are permitted provided that the following conditions
92b33a0f9SSteve Passe  * are met:
102b33a0f9SSteve Passe  * 1. Redistributions of source code must retain the above copyright
112b33a0f9SSteve Passe  *    notice, this list of conditions and the following disclaimer.
122b33a0f9SSteve Passe  * 2. The name of the developer may NOT be used to endorse or promote products
132b33a0f9SSteve Passe  *    derived from this software without specific prior written permission.
142b33a0f9SSteve Passe  *
152b33a0f9SSteve Passe  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
162b33a0f9SSteve Passe  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
172b33a0f9SSteve Passe  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
182b33a0f9SSteve Passe  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
192b33a0f9SSteve Passe  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
202b33a0f9SSteve Passe  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
212b33a0f9SSteve Passe  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
222b33a0f9SSteve Passe  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
232b33a0f9SSteve Passe  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
242b33a0f9SSteve Passe  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
252b33a0f9SSteve Passe  * SUCH DAMAGE.
262b33a0f9SSteve Passe  */
272b33a0f9SSteve Passe 
282b33a0f9SSteve Passe /*
292b33a0f9SSteve Passe  * mptable.c
302b33a0f9SSteve Passe  */
312b33a0f9SSteve Passe 
322b33a0f9SSteve Passe /*
332b33a0f9SSteve Passe  * this will cause the raw mp table to be dumped to /tmp/mpdump
342b33a0f9SSteve Passe  *
352b33a0f9SSteve Passe #define RAW_DUMP
362b33a0f9SSteve Passe  */
372b33a0f9SSteve Passe 
382b33a0f9SSteve Passe #define MP_SIG			0x5f504d5f	/* _MP_ */
392b33a0f9SSteve Passe #define EXTENDED_PROCESSING_READY
402b33a0f9SSteve Passe #define OEM_PROCESSING_READY_NOT
412b33a0f9SSteve Passe 
42d72323d1SNeel Natu #include <sys/param.h>
43a61a3b33SJohn Baldwin #include <sys/mman.h>
44a61a3b33SJohn Baldwin #include <x86/mptable.h>
45ec175cedSPhilippe Charnier #include <err.h>
462b33a0f9SSteve Passe #include <fcntl.h>
471a37aa56SDavid E. O'Brien #include <paths.h>
48a61a3b33SJohn Baldwin #include <stdint.h>
49ec175cedSPhilippe Charnier #include <stdio.h>
50ec175cedSPhilippe Charnier #include <stdlib.h>
51ec175cedSPhilippe Charnier #include <string.h>
522b33a0f9SSteve Passe #include <unistd.h>
532b33a0f9SSteve Passe 
542b33a0f9SSteve Passe #define SEP_LINE \
552b33a0f9SSteve Passe "\n-------------------------------------------------------------------------------\n"
562b33a0f9SSteve Passe 
572b33a0f9SSteve Passe #define SEP_LINE2 \
582b33a0f9SSteve Passe "\n===============================================================================\n"
592b33a0f9SSteve Passe 
602b33a0f9SSteve Passe /* EBDA is @ 40:0e in real-mode terms */
612b33a0f9SSteve Passe #define EBDA_POINTER		0x040e		/* location of EBDA pointer */
622b33a0f9SSteve Passe 
632b33a0f9SSteve Passe /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
642b33a0f9SSteve Passe #define TOPOFMEM_POINTER	0x0413		/* BIOS: base memory size */
652b33a0f9SSteve Passe 
662b33a0f9SSteve Passe #define DEFAULT_TOPOFMEM	0xa0000
672b33a0f9SSteve Passe 
682b33a0f9SSteve Passe #define BIOS_BASE		0xf0000
692b33a0f9SSteve Passe #define BIOS_BASE2		0xe0000
702b33a0f9SSteve Passe #define BIOS_SIZE		0x10000
712b33a0f9SSteve Passe #define ONE_KBYTE		1024
722b33a0f9SSteve Passe 
732b33a0f9SSteve Passe #define GROPE_AREA1		0x80000
742b33a0f9SSteve Passe #define GROPE_AREA2		0x90000
752b33a0f9SSteve Passe #define GROPE_SIZE		0x10000
762b33a0f9SSteve Passe 
772b33a0f9SSteve Passe #define MAXPNSTR		132
782b33a0f9SSteve Passe 
792b33a0f9SSteve Passe typedef struct BUSTYPENAME {
802b33a0f9SSteve Passe     u_char	type;
812b33a0f9SSteve Passe     char	name[ 7 ];
822b33a0f9SSteve Passe } busTypeName;
832b33a0f9SSteve Passe 
8460bd06daSEd Schouten static const busTypeName busTypeTable[] =
852b33a0f9SSteve Passe {
862b33a0f9SSteve Passe     { CBUS,		"CBUS"   },
872b33a0f9SSteve Passe     { CBUSII,		"CBUSII" },
882b33a0f9SSteve Passe     { EISA,		"EISA"   },
892b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
902b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
912b33a0f9SSteve Passe     { ISA,		"ISA"    },
922b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
932b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
942b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
952b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
962b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
972b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
982b33a0f9SSteve Passe     { PCI,		"PCI"    },
992b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
1002b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
1012b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
1022b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
1032b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    },
1042b33a0f9SSteve Passe     { UNKNOWN_BUSTYPE,	"---"    }
1052b33a0f9SSteve Passe };
1062b33a0f9SSteve Passe 
10760bd06daSEd Schouten static const char *whereStrings[] = {
1082b33a0f9SSteve Passe     "Extended BIOS Data Area",
1092b33a0f9SSteve Passe     "BIOS top of memory",
1102b33a0f9SSteve Passe     "Default top of memory",
1112b33a0f9SSteve Passe     "BIOS",
1122b33a0f9SSteve Passe     "Extended BIOS",
1132b33a0f9SSteve Passe     "GROPE AREA #1",
1142b33a0f9SSteve Passe     "GROPE AREA #2"
1152b33a0f9SSteve Passe };
1162b33a0f9SSteve Passe 
1178c489d72SPeter Wemm static void apic_probe( u_int32_t* paddr, int* where );
1182b33a0f9SSteve Passe 
1192b33a0f9SSteve Passe static void MPConfigDefault( int featureByte );
1202b33a0f9SSteve Passe 
121a61a3b33SJohn Baldwin static void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp );
1228c489d72SPeter Wemm static void MPConfigTableHeader( u_int32_t pap );
1232b33a0f9SSteve Passe 
1248c489d72SPeter Wemm static void seekEntry( u_int32_t addr );
1252b33a0f9SSteve Passe static void readEntry( void* entry, int size );
126a61a3b33SJohn Baldwin static void *mapEntry( u_int32_t addr, int size );
1272b33a0f9SSteve Passe 
128a61a3b33SJohn Baldwin static void processorEntry( proc_entry_ptr entry );
129a61a3b33SJohn Baldwin static void busEntry( bus_entry_ptr entry );
130a61a3b33SJohn Baldwin static void ioApicEntry( io_apic_entry_ptr entry );
131a61a3b33SJohn Baldwin static void intEntry( int_entry_ptr entry );
1322b33a0f9SSteve Passe 
133a61a3b33SJohn Baldwin static void sasEntry( sas_entry_ptr entry );
134a61a3b33SJohn Baldwin static void bhdEntry( bhd_entry_ptr entry );
135a61a3b33SJohn Baldwin static void cbasmEntry( cbasm_entry_ptr entry );
1362b33a0f9SSteve Passe 
1372b33a0f9SSteve Passe static void doDmesg( void );
1382b33a0f9SSteve Passe static void pnstr( char* s, int c );
1392b33a0f9SSteve Passe 
1402b33a0f9SSteve Passe /* global data */
14160bd06daSEd Schouten static int	pfd;		/* physical /dev/mem fd */
1422b33a0f9SSteve Passe 
1435b87feb6SNeel Natu static int	busses[256];
1445b87feb6SNeel Natu static int	apics[256];
1452b33a0f9SSteve Passe 
14660bd06daSEd Schouten static int	ncpu;
14760bd06daSEd Schouten static int	nbus;
14860bd06daSEd Schouten static int	napic;
14960bd06daSEd Schouten static int	nintr;
1502b33a0f9SSteve Passe 
15160bd06daSEd Schouten static int	dmesg;
15260bd06daSEd Schouten static int	grope;
15360bd06daSEd Schouten static int	verbose;
1542b33a0f9SSteve Passe 
1552b33a0f9SSteve Passe static void
usage(void)1562b33a0f9SSteve Passe usage( void )
1572b33a0f9SSteve Passe {
158ec175cedSPhilippe Charnier     fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
1592b33a0f9SSteve Passe     exit( 0 );
1602b33a0f9SSteve Passe }
1612b33a0f9SSteve Passe 
1622b33a0f9SSteve Passe /*
1632b33a0f9SSteve Passe  *
1642b33a0f9SSteve Passe  */
1652b33a0f9SSteve Passe int
main(int argc,char * argv[])1662b33a0f9SSteve Passe main( int argc, char *argv[] )
1672b33a0f9SSteve Passe {
1688c489d72SPeter Wemm     u_int32_t	paddr;
1692b33a0f9SSteve Passe     int		where;
1702b33a0f9SSteve Passe     mpfps_t	mpfps;
1712b33a0f9SSteve Passe     int		defaultConfig;
1722b33a0f9SSteve Passe 
1732b33a0f9SSteve Passe     int		ch;
1742b33a0f9SSteve Passe 
1752b33a0f9SSteve Passe     /* announce ourselves */
1762b33a0f9SSteve Passe     puts( SEP_LINE2 );
1772b33a0f9SSteve Passe 
1780446a99eSDavid E. O'Brien     printf( "MPTable\n" );
1792b33a0f9SSteve Passe 
180b790f1b6SWarner Losh     while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
1812b33a0f9SSteve Passe 	switch(ch) {
1822b33a0f9SSteve Passe 	case 'd':
1832b33a0f9SSteve Passe 	    if ( strcmp( optarg, "mesg") == 0 )
1842b33a0f9SSteve Passe 	        dmesg = 1;
1852b33a0f9SSteve Passe 	    else
1862b33a0f9SSteve Passe 		usage();
1872b33a0f9SSteve Passe 	    break;
188*11500481SPete Zaitcev 	case 'h':
189*11500481SPete Zaitcev 	    usage();
1902b33a0f9SSteve Passe 	case 'g':
1919d35fde7SSteve Passe 	    if ( strcmp( optarg, "rope") == 0 )
1922b33a0f9SSteve Passe 	        grope = 1;
193*11500481SPete Zaitcev 	    else
194*11500481SPete Zaitcev 		usage();
1952b33a0f9SSteve Passe 	    break;
1962b33a0f9SSteve Passe 	case 'v':
1972b33a0f9SSteve Passe 	    if ( strcmp( optarg, "erbose") == 0 )
1982b33a0f9SSteve Passe 	        verbose = 1;
199*11500481SPete Zaitcev 	    else
200*11500481SPete Zaitcev 		usage();
2012b33a0f9SSteve Passe 	    break;
2022b33a0f9SSteve Passe 	default:
2032b33a0f9SSteve Passe 	    usage();
2042b33a0f9SSteve Passe 	}
2052b33a0f9SSteve Passe 	argc -= optind;
2062b33a0f9SSteve Passe 	argv += optind;
2072b33a0f9SSteve Passe 	optreset = 1;
2082b33a0f9SSteve Passe 	optind = 0;
2092b33a0f9SSteve Passe     }
2102b33a0f9SSteve Passe 
2112b33a0f9SSteve Passe     /* open physical memory for access to MP structures */
2121a37aa56SDavid E. O'Brien     if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
213ec175cedSPhilippe Charnier         err( 1, "mem open" );
2142b33a0f9SSteve Passe 
2152b33a0f9SSteve Passe     /* probe for MP structures */
2162b33a0f9SSteve Passe     apic_probe( &paddr, &where );
2172b33a0f9SSteve Passe     if ( where <= 0 ) {
2182b33a0f9SSteve Passe         fprintf( stderr, "\n MP FPS NOT found,\n" );
219d9a4f21fSBaptiste Daroussin         if (!grope)
2202b33a0f9SSteve Passe             fprintf( stderr, " suggest trying -grope option!!!\n\n" );
2212b33a0f9SSteve Passe         return 1;
2222b33a0f9SSteve Passe     }
2232b33a0f9SSteve Passe 
2242b33a0f9SSteve Passe     if ( verbose )
2252b33a0f9SSteve Passe         printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
2262b33a0f9SSteve Passe 	      whereStrings[ where - 1 ], paddr );
2272b33a0f9SSteve Passe 
2282b33a0f9SSteve Passe     puts( SEP_LINE );
2292b33a0f9SSteve Passe 
2302b33a0f9SSteve Passe     /* analyze the MP Floating Pointer Structure */
2312b33a0f9SSteve Passe     MPFloatingPointer( paddr, where, &mpfps );
2322b33a0f9SSteve Passe 
2332b33a0f9SSteve Passe     puts( SEP_LINE );
2342b33a0f9SSteve Passe 
2352b33a0f9SSteve Passe     /* check whether an MP config table exists */
236a61a3b33SJohn Baldwin     if ( (defaultConfig = mpfps->config_type) )
2372b33a0f9SSteve Passe         MPConfigDefault( defaultConfig );
2382b33a0f9SSteve Passe     else
239a61a3b33SJohn Baldwin 	MPConfigTableHeader( mpfps->pap );
2402b33a0f9SSteve Passe 
2412b33a0f9SSteve Passe     /* do a dmesg output */
2422b33a0f9SSteve Passe     if ( dmesg )
2432b33a0f9SSteve Passe         doDmesg();
2442b33a0f9SSteve Passe 
2452b33a0f9SSteve Passe     puts( SEP_LINE2 );
2462b33a0f9SSteve Passe 
2472b33a0f9SSteve Passe     return 0;
2482b33a0f9SSteve Passe }
2492b33a0f9SSteve Passe 
2502b33a0f9SSteve Passe 
2512b33a0f9SSteve Passe /*
2522b33a0f9SSteve Passe  * set PHYSICAL address of MP floating pointer structure
2532b33a0f9SSteve Passe  */
2542b33a0f9SSteve Passe #define NEXT(X)		((X) += 4)
2552b33a0f9SSteve Passe static void
apic_probe(u_int32_t * paddr,int * where)2568c489d72SPeter Wemm apic_probe( u_int32_t* paddr, int* where )
2572b33a0f9SSteve Passe {
2582b33a0f9SSteve Passe     /*
2592b33a0f9SSteve Passe      * c rewrite of apic_probe() by Jack F. Vogel
2602b33a0f9SSteve Passe      */
2612b33a0f9SSteve Passe 
2622b33a0f9SSteve Passe     int		x;
2632b33a0f9SSteve Passe     u_short	segment;
2648c489d72SPeter Wemm     u_int32_t	target;
2652b33a0f9SSteve Passe     u_int	buffer[ BIOS_SIZE / sizeof( int ) ];
2662b33a0f9SSteve Passe 
2672b33a0f9SSteve Passe     if ( verbose )
2682b33a0f9SSteve Passe         printf( "\n" );
2692b33a0f9SSteve Passe 
2702b33a0f9SSteve Passe     /* search Extended Bios Data Area, if present */
2712b33a0f9SSteve Passe     if ( verbose )
2722b33a0f9SSteve Passe         printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
2738c489d72SPeter Wemm     seekEntry( (u_int32_t)EBDA_POINTER );
2742b33a0f9SSteve Passe     readEntry( &segment, 2 );
2752b33a0f9SSteve Passe     if ( segment ) {		    /* search EBDA */
2768c489d72SPeter Wemm         target = (u_int32_t)segment << 4;
2772b33a0f9SSteve Passe 	if ( verbose )
2782b33a0f9SSteve Passe 	    printf( "found, searching EBDA @ 0x%08x\n", target );
2792b33a0f9SSteve Passe         seekEntry( target );
2802b33a0f9SSteve Passe         readEntry( buffer, ONE_KBYTE );
2812b33a0f9SSteve Passe 
2828c489d72SPeter Wemm         for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
2832b33a0f9SSteve Passe             if ( buffer[ x ] == MP_SIG ) {
2842b33a0f9SSteve Passe                 *where = 1;
2852b33a0f9SSteve Passe                 *paddr = (x * sizeof( unsigned int )) + target;
2862b33a0f9SSteve Passe                 return;
2872b33a0f9SSteve Passe             }
2882b33a0f9SSteve Passe         }
2892b33a0f9SSteve Passe     }
2902b33a0f9SSteve Passe     else {
2912b33a0f9SSteve Passe 	if ( verbose )
2922b33a0f9SSteve Passe 	    printf( "NOT found\n" );
2932b33a0f9SSteve Passe     }
2942b33a0f9SSteve Passe 
2952b33a0f9SSteve Passe     /* read CMOS for real top of mem */
2968c489d72SPeter Wemm     seekEntry( (u_int32_t)TOPOFMEM_POINTER );
2972b33a0f9SSteve Passe     readEntry( &segment, 2 );
2982b33a0f9SSteve Passe     --segment;						/* less ONE_KBYTE */
2992b33a0f9SSteve Passe     target = segment * 1024;
3002b33a0f9SSteve Passe     if ( verbose )
3012b33a0f9SSteve Passe         printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
3022b33a0f9SSteve Passe 	        target, segment );
3032b33a0f9SSteve Passe     seekEntry( target );
3042b33a0f9SSteve Passe     readEntry( buffer, ONE_KBYTE );
3052b33a0f9SSteve Passe 
3068c489d72SPeter Wemm     for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
3072b33a0f9SSteve Passe         if ( buffer[ x ] == MP_SIG ) {
3082b33a0f9SSteve Passe             *where = 2;
3092b33a0f9SSteve Passe             *paddr = (x * sizeof( unsigned int )) + target;
3102b33a0f9SSteve Passe             return;
3112b33a0f9SSteve Passe         }
3122b33a0f9SSteve Passe     }
3132b33a0f9SSteve Passe 
3142b33a0f9SSteve Passe     /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
3152b33a0f9SSteve Passe     if ( target != (DEFAULT_TOPOFMEM - 1024)) {
3162b33a0f9SSteve Passe 	target = (DEFAULT_TOPOFMEM - 1024);
3172b33a0f9SSteve Passe 	if ( verbose )
3182b33a0f9SSteve Passe 	    printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
3192b33a0f9SSteve Passe 		    target, (target / 1024) );
3202b33a0f9SSteve Passe 	seekEntry( target );
3212b33a0f9SSteve Passe 	readEntry( buffer, ONE_KBYTE );
3222b33a0f9SSteve Passe 
3238c489d72SPeter Wemm 	for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
3242b33a0f9SSteve Passe 	    if ( buffer[ x ] == MP_SIG ) {
3252b33a0f9SSteve Passe 		*where = 3;
3262b33a0f9SSteve Passe 		*paddr = (x * sizeof( unsigned int )) + target;
3272b33a0f9SSteve Passe 		return;
3282b33a0f9SSteve Passe 	    }
3292b33a0f9SSteve Passe 	}
3302b33a0f9SSteve Passe     }
3312b33a0f9SSteve Passe 
3322b33a0f9SSteve Passe     /* search the BIOS */
3332b33a0f9SSteve Passe     if ( verbose )
3342b33a0f9SSteve Passe         printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
3352b33a0f9SSteve Passe     seekEntry( BIOS_BASE );
3362b33a0f9SSteve Passe     readEntry( buffer, BIOS_SIZE );
3372b33a0f9SSteve Passe 
3388c489d72SPeter Wemm     for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
3392b33a0f9SSteve Passe         if ( buffer[ x ] == MP_SIG ) {
3402b33a0f9SSteve Passe             *where = 4;
3412b33a0f9SSteve Passe             *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
3422b33a0f9SSteve Passe             return;
3432b33a0f9SSteve Passe         }
3442b33a0f9SSteve Passe     }
3452b33a0f9SSteve Passe 
3462b33a0f9SSteve Passe     /* search the extended BIOS */
3472b33a0f9SSteve Passe     if ( verbose )
3482b33a0f9SSteve Passe         printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
3492b33a0f9SSteve Passe     seekEntry( BIOS_BASE2 );
3502b33a0f9SSteve Passe     readEntry( buffer, BIOS_SIZE );
3512b33a0f9SSteve Passe 
3528c489d72SPeter Wemm     for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
3532b33a0f9SSteve Passe         if ( buffer[ x ] == MP_SIG ) {
3542b33a0f9SSteve Passe             *where = 5;
3552b33a0f9SSteve Passe             *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
3562b33a0f9SSteve Passe             return;
3572b33a0f9SSteve Passe         }
3582b33a0f9SSteve Passe     }
3592b33a0f9SSteve Passe 
3602b33a0f9SSteve Passe     if ( grope ) {
3612b33a0f9SSteve Passe 	/* search additional memory */
3622b33a0f9SSteve Passe 	target = GROPE_AREA1;
3632b33a0f9SSteve Passe 	if ( verbose )
3642b33a0f9SSteve Passe 	    printf( " groping memory @ 0x%08x\n", target );
3652b33a0f9SSteve Passe 	seekEntry( target );
3662b33a0f9SSteve Passe 	readEntry( buffer, GROPE_SIZE );
3672b33a0f9SSteve Passe 
3688c489d72SPeter Wemm 	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
3692b33a0f9SSteve Passe 	    if ( buffer[ x ] == MP_SIG ) {
3702b33a0f9SSteve Passe 		*where = 6;
3712b33a0f9SSteve Passe 		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
3722b33a0f9SSteve Passe 		return;
3732b33a0f9SSteve Passe 	    }
3742b33a0f9SSteve Passe 	}
3752b33a0f9SSteve Passe 
3762b33a0f9SSteve Passe 	target = GROPE_AREA2;
3772b33a0f9SSteve Passe 	if ( verbose )
3782b33a0f9SSteve Passe 	    printf( " groping memory @ 0x%08x\n", target );
3792b33a0f9SSteve Passe 	seekEntry( target );
3802b33a0f9SSteve Passe 	readEntry( buffer, GROPE_SIZE );
3812b33a0f9SSteve Passe 
3828c489d72SPeter Wemm 	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
3832b33a0f9SSteve Passe 	    if ( buffer[ x ] == MP_SIG ) {
3842b33a0f9SSteve Passe 		*where = 7;
3852b33a0f9SSteve Passe 		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
3862b33a0f9SSteve Passe 		return;
3872b33a0f9SSteve Passe 	    }
3882b33a0f9SSteve Passe 	}
3892b33a0f9SSteve Passe     }
3902b33a0f9SSteve Passe 
3912b33a0f9SSteve Passe     *where = 0;
3928c489d72SPeter Wemm     *paddr = (u_int32_t)0;
3932b33a0f9SSteve Passe }
3942b33a0f9SSteve Passe 
3952b33a0f9SSteve Passe 
3962b33a0f9SSteve Passe /*
3972b33a0f9SSteve Passe  *
3982b33a0f9SSteve Passe  */
399ec175cedSPhilippe Charnier static void
MPFloatingPointer(u_int32_t paddr,int where,mpfps_t * mpfpsp)400a61a3b33SJohn Baldwin MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp )
4012b33a0f9SSteve Passe {
402a61a3b33SJohn Baldwin     mpfps_t mpfps;
4032b33a0f9SSteve Passe 
404a61a3b33SJohn Baldwin     /* map in mpfps structure*/
4052efbc4a6SJohn Baldwin     *mpfpsp = mpfps = mapEntry( paddr, sizeof( *mpfps ) );
4062b33a0f9SSteve Passe 
4072b33a0f9SSteve Passe     /* show its contents */
4082b33a0f9SSteve Passe     printf( "MP Floating Pointer Structure:\n\n" );
4092b33a0f9SSteve Passe 
410ec175cedSPhilippe Charnier     printf( "  location:\t\t\t" );
4112b33a0f9SSteve Passe     switch ( where )
4122b33a0f9SSteve Passe     {
4132b33a0f9SSteve Passe     case 1:
4142b33a0f9SSteve Passe 	printf( "EBDA\n" );
4152b33a0f9SSteve Passe 	break;
4162b33a0f9SSteve Passe     case 2:
4172b33a0f9SSteve Passe 	printf( "BIOS base memory\n" );
4182b33a0f9SSteve Passe 	break;
4192b33a0f9SSteve Passe     case 3:
4202b33a0f9SSteve Passe 	printf( "DEFAULT base memory (639K)\n" );
4212b33a0f9SSteve Passe 	break;
4222b33a0f9SSteve Passe     case 4:
4232b33a0f9SSteve Passe 	printf( "BIOS\n" );
4242b33a0f9SSteve Passe 	break;
4252b33a0f9SSteve Passe     case 5:
4262b33a0f9SSteve Passe 	printf( "Extended BIOS\n" );
4272b33a0f9SSteve Passe 	break;
4282b33a0f9SSteve Passe 
4292b33a0f9SSteve Passe     case 0:
4302b33a0f9SSteve Passe 	printf( "NOT found!\n" );
4312b33a0f9SSteve Passe 	exit( 1 );
4322b33a0f9SSteve Passe     default:
4332b33a0f9SSteve Passe 	printf( "BOGUS!\n" );
4342b33a0f9SSteve Passe 	exit( 1 );
4352b33a0f9SSteve Passe     }
4362b33a0f9SSteve Passe     printf( "  physical address:\t\t0x%08x\n", paddr );
4372b33a0f9SSteve Passe 
4382b33a0f9SSteve Passe     printf( "  signature:\t\t\t'" );
4392b33a0f9SSteve Passe     pnstr( mpfps->signature, 4 );
4402b33a0f9SSteve Passe     printf( "'\n" );
4412b33a0f9SSteve Passe 
4422b33a0f9SSteve Passe     printf( "  length:\t\t\t%d bytes\n", mpfps->length * 16 );
4432b33a0f9SSteve Passe     printf( "  version:\t\t\t1.%1d\n", mpfps->spec_rev );
4442b33a0f9SSteve Passe     printf( "  checksum:\t\t\t0x%02x\n", mpfps->checksum );
4452b33a0f9SSteve Passe 
4462b33a0f9SSteve Passe     /* bits 0:6 are RESERVED */
4472b33a0f9SSteve Passe     if ( mpfps->mpfb2 & 0x7f ) {
448ec175cedSPhilippe Charnier         printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
4492b33a0f9SSteve Passe     }
4502b33a0f9SSteve Passe 
4512b33a0f9SSteve Passe     /* bit 7 is IMCRP */
452a61a3b33SJohn Baldwin     printf( "  mode:\t\t\t\t%s\n", (mpfps->mpfb2 & MPFB2_IMCR_PRESENT) ?
4532b33a0f9SSteve Passe             "PIC" : "Virtual Wire" );
4542b33a0f9SSteve Passe 
4552b33a0f9SSteve Passe     /* MP feature bytes 3-5 are expected to be ZERO */
4562b33a0f9SSteve Passe     if ( mpfps->mpfb3 )
4572b33a0f9SSteve Passe         printf( " warning, MP feature byte 3 NONZERO!\n" );
4582b33a0f9SSteve Passe     if ( mpfps->mpfb4 )
4592b33a0f9SSteve Passe         printf( " warning, MP feature byte 4 NONZERO!\n" );
4602b33a0f9SSteve Passe     if ( mpfps->mpfb5 )
4612b33a0f9SSteve Passe         printf( " warning, MP feature byte 5 NONZERO!\n" );
4622b33a0f9SSteve Passe }
4632b33a0f9SSteve Passe 
4642b33a0f9SSteve Passe 
4652b33a0f9SSteve Passe /*
4662b33a0f9SSteve Passe  *
4672b33a0f9SSteve Passe  */
4682b33a0f9SSteve Passe static void
MPConfigDefault(int featureByte)4692b33a0f9SSteve Passe MPConfigDefault( int featureByte )
4702b33a0f9SSteve Passe {
4712b33a0f9SSteve Passe     printf( "  MP default config type: %d\n\n", featureByte );
4722b33a0f9SSteve Passe     switch ( featureByte ) {
4732b33a0f9SSteve Passe     case 1:
4742b33a0f9SSteve Passe 	printf( "   bus: ISA, APIC: 82489DX\n" );
4752b33a0f9SSteve Passe 	break;
4762b33a0f9SSteve Passe     case 2:
4772b33a0f9SSteve Passe 	printf( "   bus: EISA, APIC: 82489DX\n" );
4782b33a0f9SSteve Passe 	break;
4792b33a0f9SSteve Passe     case 3:
4802b33a0f9SSteve Passe 	printf( "   bus: EISA, APIC: 82489DX\n" );
4812b33a0f9SSteve Passe 	break;
4822b33a0f9SSteve Passe     case 4:
4832b33a0f9SSteve Passe 	printf( "   bus: MCA, APIC: 82489DX\n" );
4842b33a0f9SSteve Passe 	break;
4852b33a0f9SSteve Passe     case 5:
4862b33a0f9SSteve Passe 	printf( "   bus: ISA+PCI, APIC: Integrated\n" );
4872b33a0f9SSteve Passe 	break;
4882b33a0f9SSteve Passe     case 6:
4892b33a0f9SSteve Passe 	printf( "   bus: EISA+PCI, APIC: Integrated\n" );
4902b33a0f9SSteve Passe 	break;
4912b33a0f9SSteve Passe     case 7:
4922b33a0f9SSteve Passe 	printf( "   bus: MCA+PCI, APIC: Integrated\n" );
4932b33a0f9SSteve Passe 	break;
4942b33a0f9SSteve Passe     default:
4952b33a0f9SSteve Passe 	printf( "   future type\n" );
4962b33a0f9SSteve Passe 	break;
4972b33a0f9SSteve Passe     }
4982b33a0f9SSteve Passe 
4992b33a0f9SSteve Passe     switch ( featureByte ) {
5002b33a0f9SSteve Passe     case 1:
5012b33a0f9SSteve Passe     case 2:
5022b33a0f9SSteve Passe     case 3:
5032b33a0f9SSteve Passe     case 4:
5042b33a0f9SSteve Passe 	nbus = 1;
5052b33a0f9SSteve Passe 	break;
5062b33a0f9SSteve Passe     case 5:
5072b33a0f9SSteve Passe     case 6:
5082b33a0f9SSteve Passe     case 7:
5092b33a0f9SSteve Passe 	nbus = 2;
5102b33a0f9SSteve Passe 	break;
5112b33a0f9SSteve Passe     default:
5122b33a0f9SSteve Passe 	printf( "   future type\n" );
5132b33a0f9SSteve Passe 	break;
5142b33a0f9SSteve Passe     }
5152b33a0f9SSteve Passe 
5162b33a0f9SSteve Passe     ncpu = 2;
5172b33a0f9SSteve Passe     napic = 1;
5182b33a0f9SSteve Passe     nintr = 16;
5192b33a0f9SSteve Passe }
5202b33a0f9SSteve Passe 
5212b33a0f9SSteve Passe 
5222b33a0f9SSteve Passe /*
5232b33a0f9SSteve Passe  *
5242b33a0f9SSteve Passe  */
5252b33a0f9SSteve Passe static void
MPConfigTableHeader(u_int32_t pap)5268c489d72SPeter Wemm MPConfigTableHeader( u_int32_t pap )
5272b33a0f9SSteve Passe {
5282b33a0f9SSteve Passe     mpcth_t	cth;
529ec175cedSPhilippe Charnier     int		x;
530a61a3b33SJohn Baldwin     int		c;
5314a3e427fSPeter Wemm     int		oldtype, entrytype;
532a61a3b33SJohn Baldwin     u_int8_t	*entry;
5332b33a0f9SSteve Passe 
5342b33a0f9SSteve Passe     if ( pap == 0 ) {
5352b33a0f9SSteve Passe 	printf( "MP Configuration Table Header MISSING!\n" );
5362b33a0f9SSteve Passe         exit( 1 );
5372b33a0f9SSteve Passe     }
5382b33a0f9SSteve Passe 
539a61a3b33SJohn Baldwin     /* map in cth structure */
540a61a3b33SJohn Baldwin     cth = mapEntry( pap, sizeof( *cth ) );
5412b33a0f9SSteve Passe 
5422b33a0f9SSteve Passe     printf( "MP Config Table Header:\n\n" );
5432b33a0f9SSteve Passe 
5442b33a0f9SSteve Passe     printf( "  physical address:\t\t0x%08x\n", pap );
5452b33a0f9SSteve Passe 
5462b33a0f9SSteve Passe     printf( "  signature:\t\t\t'" );
547a61a3b33SJohn Baldwin     pnstr( cth->signature, 4 );
5482b33a0f9SSteve Passe     printf( "'\n" );
5492b33a0f9SSteve Passe 
550a61a3b33SJohn Baldwin     printf( "  base table length:\t\t%d\n", cth->base_table_length );
5512b33a0f9SSteve Passe 
552a61a3b33SJohn Baldwin     printf( "  version:\t\t\t1.%1d\n", cth->spec_rev );
553a61a3b33SJohn Baldwin     printf( "  checksum:\t\t\t0x%02x\n", cth->checksum );
5542b33a0f9SSteve Passe 
5552b33a0f9SSteve Passe     printf( "  OEM ID:\t\t\t'" );
556a61a3b33SJohn Baldwin     pnstr( cth->oem_id, 8 );
5572b33a0f9SSteve Passe     printf( "'\n" );
5582b33a0f9SSteve Passe 
5592b33a0f9SSteve Passe     printf( "  Product ID:\t\t\t'" );
560a61a3b33SJohn Baldwin     pnstr( cth->product_id, 12 );
5612b33a0f9SSteve Passe     printf( "'\n" );
5622b33a0f9SSteve Passe 
563a61a3b33SJohn Baldwin     printf( "  OEM table pointer:\t\t0x%08x\n", cth->oem_table_pointer );
564a61a3b33SJohn Baldwin     printf( "  OEM table size:\t\t%d\n", cth->oem_table_size );
5652b33a0f9SSteve Passe 
566a61a3b33SJohn Baldwin     printf( "  entry count:\t\t\t%d\n", cth->entry_count );
5672b33a0f9SSteve Passe 
568a61a3b33SJohn Baldwin     printf( "  local APIC address:\t\t0x%08x\n", cth->apic_address );
5692b33a0f9SSteve Passe 
570a61a3b33SJohn Baldwin     printf( "  extended table length:\t%d\n", cth->extended_table_length );
571a61a3b33SJohn Baldwin     printf( "  extended table checksum:\t%d\n", cth->extended_table_checksum );
5722b33a0f9SSteve Passe 
5732b33a0f9SSteve Passe     puts( SEP_LINE );
5742b33a0f9SSteve Passe 
5752b33a0f9SSteve Passe     printf( "MP Config Base Table Entries:\n\n" );
5762b33a0f9SSteve Passe 
577d72323d1SNeel Natu     /* initialize tables */
578d72323d1SNeel Natu     for (x = 0; x < (int)nitems(busses); x++)
579d72323d1SNeel Natu 	busses[x] = 0xff;
580d72323d1SNeel Natu 
581d72323d1SNeel Natu     for (x = 0; x < (int)nitems(apics); x++)
582d72323d1SNeel Natu 	apics[x] = 0xff;
5832b33a0f9SSteve Passe 
5842b33a0f9SSteve Passe     ncpu = 0;
5852b33a0f9SSteve Passe     nbus = 0;
5862b33a0f9SSteve Passe     napic = 0;
5872b33a0f9SSteve Passe     nintr = 0;
5882b33a0f9SSteve Passe 
5894a3e427fSPeter Wemm     oldtype = -1;
590a61a3b33SJohn Baldwin     entry = mapEntry(pap + sizeof(*cth), cth->base_table_length);
591a61a3b33SJohn Baldwin     for (c = cth->entry_count; c; c--) {
592a61a3b33SJohn Baldwin 	entrytype = *entry;
5934a3e427fSPeter Wemm 	if (entrytype != oldtype)
5944a3e427fSPeter Wemm 	    printf("--\n");
5954a3e427fSPeter Wemm 	if (entrytype < oldtype)
5964a3e427fSPeter Wemm 	    printf("MPTABLE OUT OF ORDER!\n");
5974a3e427fSPeter Wemm 	switch (entrytype) {
598a61a3b33SJohn Baldwin 	case MPCT_ENTRY_PROCESSOR:
599a61a3b33SJohn Baldwin 	    if (oldtype != MPCT_ENTRY_PROCESSOR)
6004a3e427fSPeter Wemm 		printf( "Processors:\tAPIC ID\tVersion\tState"
6012b33a0f9SSteve Passe 			"\t\tFamily\tModel\tStep\tFlags\n" );
602a61a3b33SJohn Baldwin 	    processorEntry((proc_entry_ptr)entry);
603a61a3b33SJohn Baldwin 	    entry += sizeof(struct PROCENTRY);
6044a3e427fSPeter Wemm 	    break;
6052b33a0f9SSteve Passe 
606a61a3b33SJohn Baldwin 	case MPCT_ENTRY_BUS:
607a61a3b33SJohn Baldwin 	    if (oldtype != MPCT_ENTRY_BUS)
6084a3e427fSPeter Wemm 		printf( "Bus:\t\tBus ID\tType\n" );
609a61a3b33SJohn Baldwin 	    busEntry((bus_entry_ptr)entry);
610a61a3b33SJohn Baldwin 	    entry += sizeof(struct BUSENTRY);
6114a3e427fSPeter Wemm 	    break;
6122b33a0f9SSteve Passe 
613a61a3b33SJohn Baldwin 	case MPCT_ENTRY_IOAPIC:
614a61a3b33SJohn Baldwin 	    if (oldtype != MPCT_ENTRY_IOAPIC)
6154a3e427fSPeter Wemm 		printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
616a61a3b33SJohn Baldwin 	    ioApicEntry((io_apic_entry_ptr)entry);
617a61a3b33SJohn Baldwin 	    entry += sizeof(struct IOAPICENTRY);
6184a3e427fSPeter Wemm 	    break;
6192b33a0f9SSteve Passe 
620a61a3b33SJohn Baldwin 	case MPCT_ENTRY_INT:
621a61a3b33SJohn Baldwin 	    if (oldtype != MPCT_ENTRY_INT)
6224a3e427fSPeter Wemm 		printf( "I/O Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
623a61a3b33SJohn Baldwin 	    intEntry((int_entry_ptr)entry);
624a61a3b33SJohn Baldwin 	    entry += sizeof(struct INTENTRY);
6254a3e427fSPeter Wemm 	    break;
6262b33a0f9SSteve Passe 
627a61a3b33SJohn Baldwin 	case MPCT_ENTRY_LOCAL_INT:
628a61a3b33SJohn Baldwin 	    if (oldtype != MPCT_ENTRY_LOCAL_INT)
6294a3e427fSPeter Wemm 		printf( "Local Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
630a61a3b33SJohn Baldwin 	    intEntry((int_entry_ptr)entry);
631a61a3b33SJohn Baldwin 	    entry += sizeof(struct INTENTRY);
6324a3e427fSPeter Wemm 	    break;
6334a3e427fSPeter Wemm 
6344a3e427fSPeter Wemm 	default:
6354a3e427fSPeter Wemm 	    printf("MPTABLE HOSED! record type = %d\n", entrytype);
6364a3e427fSPeter Wemm 	    exit(1);
6374a3e427fSPeter Wemm 	}
638a61a3b33SJohn Baldwin 	oldtype = entrytype;
6392b33a0f9SSteve Passe     }
6402b33a0f9SSteve Passe 
6412b33a0f9SSteve Passe 
6422b33a0f9SSteve Passe #if defined( EXTENDED_PROCESSING_READY )
6432b33a0f9SSteve Passe     /* process any extended data */
644a61a3b33SJohn Baldwin     if ( cth->extended_table_length ) {
645a61a3b33SJohn Baldwin 	ext_entry_ptr ext_entry, end;
646a61a3b33SJohn Baldwin 
6472b33a0f9SSteve Passe 	puts( SEP_LINE );
6482b33a0f9SSteve Passe 
6492b33a0f9SSteve Passe         printf( "MP Config Extended Table Entries:\n\n" );
6502b33a0f9SSteve Passe 
651a61a3b33SJohn Baldwin 	ext_entry = mapEntry(pap + cth->base_table_length,
652a61a3b33SJohn Baldwin 	    cth->extended_table_length);
653a61a3b33SJohn Baldwin 	end = (ext_entry_ptr)((char *)ext_entry + cth->extended_table_length);
654a61a3b33SJohn Baldwin 	while (ext_entry < end) {
655a61a3b33SJohn Baldwin 	    switch (ext_entry->type) {
656a61a3b33SJohn Baldwin             case MPCT_EXTENTRY_SAS:
657a61a3b33SJohn Baldwin 		sasEntry((sas_entry_ptr)ext_entry);
6582b33a0f9SSteve Passe 		break;
659a61a3b33SJohn Baldwin             case MPCT_EXTENTRY_BHD:
660a61a3b33SJohn Baldwin 		bhdEntry((bhd_entry_ptr)ext_entry);
6612b33a0f9SSteve Passe 		break;
662a61a3b33SJohn Baldwin             case MPCT_EXTENTRY_CBASM:
663a61a3b33SJohn Baldwin 		cbasmEntry((cbasm_entry_ptr)ext_entry);
6642b33a0f9SSteve Passe 		break;
6652b33a0f9SSteve Passe             default:
6662b33a0f9SSteve Passe                 printf( "Extended Table HOSED!\n" );
6672b33a0f9SSteve Passe                 exit( 1 );
6682b33a0f9SSteve Passe             }
6692b33a0f9SSteve Passe 
670a61a3b33SJohn Baldwin 	    ext_entry = (ext_entry_ptr)((char *)ext_entry + ext_entry->length);
6712b33a0f9SSteve Passe         }
6722b33a0f9SSteve Passe     }
6732b33a0f9SSteve Passe #endif  /* EXTENDED_PROCESSING_READY */
6742b33a0f9SSteve Passe 
6752b33a0f9SSteve Passe     /* process any OEM data */
676a61a3b33SJohn Baldwin     if ( cth->oem_table_pointer && (cth->oem_table_size > 0) ) {
6772b33a0f9SSteve Passe #if defined( OEM_PROCESSING_READY )
6782b33a0f9SSteve Passe # error your on your own here!
679a61a3b33SJohn Baldwin         /* map in oem table structure */
680a61a3b33SJohn Baldwin 	oemdata = mapEntry( cth->oem_table_pointer, cth->oem_table_size);
6812b33a0f9SSteve Passe 
6822b33a0f9SSteve Passe         /** process it */
6832b33a0f9SSteve Passe #else
6842b33a0f9SSteve Passe         printf( "\nyou need to modify the source to handle OEM data!\n\n" );
6852b33a0f9SSteve Passe #endif  /* OEM_PROCESSING_READY */
6862b33a0f9SSteve Passe     }
6872b33a0f9SSteve Passe 
6882b33a0f9SSteve Passe     fflush( stdout );
6892b33a0f9SSteve Passe 
6902b33a0f9SSteve Passe #if defined( RAW_DUMP )
6912b33a0f9SSteve Passe {
6922b33a0f9SSteve Passe     int		ofd;
693a61a3b33SJohn Baldwin     void	*dumpbuf;
6942b33a0f9SSteve Passe 
69524bc5224SPawel Jakub Dawidek     ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
696a61a3b33SJohn Baldwin 
697a61a3b33SJohn Baldwin     dumpbuf = mapEntry( paddr, 1024 );
6982b33a0f9SSteve Passe     write( ofd, dumpbuf, 1024 );
6992b33a0f9SSteve Passe     close( ofd );
7002b33a0f9SSteve Passe }
7012b33a0f9SSteve Passe #endif /* RAW_DUMP */
7022b33a0f9SSteve Passe }
7032b33a0f9SSteve Passe 
7042b33a0f9SSteve Passe 
7052b33a0f9SSteve Passe /*
7062b33a0f9SSteve Passe  *
7072b33a0f9SSteve Passe  */
7082b33a0f9SSteve Passe static void
seekEntry(u_int32_t addr)7098c489d72SPeter Wemm seekEntry( u_int32_t addr )
7102b33a0f9SSteve Passe {
711ec175cedSPhilippe Charnier     if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
7121a37aa56SDavid E. O'Brien         err( 1, "%s seek", _PATH_MEM );
7132b33a0f9SSteve Passe }
7142b33a0f9SSteve Passe 
7152b33a0f9SSteve Passe 
7162b33a0f9SSteve Passe /*
7172b33a0f9SSteve Passe  *
7182b33a0f9SSteve Passe  */
7192b33a0f9SSteve Passe static void
readEntry(void * entry,int size)7202b33a0f9SSteve Passe readEntry( void* entry, int size )
7212b33a0f9SSteve Passe {
722ec175cedSPhilippe Charnier     if ( read( pfd, entry, size ) != size )
723ec175cedSPhilippe Charnier         err( 1, "readEntry" );
7242b33a0f9SSteve Passe }
7252b33a0f9SSteve Passe 
726a61a3b33SJohn Baldwin static void *
mapEntry(u_int32_t addr,int size)727a61a3b33SJohn Baldwin mapEntry( u_int32_t addr, int size )
728a61a3b33SJohn Baldwin {
729a61a3b33SJohn Baldwin     void	*p;
730a61a3b33SJohn Baldwin 
731a61a3b33SJohn Baldwin     p = mmap( NULL, size, PROT_READ, MAP_SHARED, pfd, addr );
732a61a3b33SJohn Baldwin     if (p == MAP_FAILED)
733a61a3b33SJohn Baldwin 	err( 1, "mapEntry" );
734a61a3b33SJohn Baldwin     return (p);
735a61a3b33SJohn Baldwin }
7362b33a0f9SSteve Passe 
7372b33a0f9SSteve Passe static void
processorEntry(proc_entry_ptr entry)738a61a3b33SJohn Baldwin processorEntry( proc_entry_ptr entry )
7392b33a0f9SSteve Passe {
7402b33a0f9SSteve Passe 
7412b33a0f9SSteve Passe     /* count it */
7422b33a0f9SSteve Passe     ++ncpu;
7432b33a0f9SSteve Passe 
744a61a3b33SJohn Baldwin     printf( "\t\t%2d", entry->apic_id );
745a61a3b33SJohn Baldwin     printf( "\t 0x%2x", entry->apic_version );
7462b33a0f9SSteve Passe 
7472b33a0f9SSteve Passe     printf( "\t %s, %s",
748a61a3b33SJohn Baldwin             (entry->cpu_flags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
749a61a3b33SJohn Baldwin             (entry->cpu_flags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
7502b33a0f9SSteve Passe 
7512b33a0f9SSteve Passe     printf( "\t %d\t %d\t %d",
752a61a3b33SJohn Baldwin             (entry->cpu_signature >> 8) & 0x0f,
753a61a3b33SJohn Baldwin             (entry->cpu_signature >> 4) & 0x0f,
754a61a3b33SJohn Baldwin             entry->cpu_signature & 0x0f );
7552b33a0f9SSteve Passe 
756a61a3b33SJohn Baldwin     printf( "\t 0x%04x\n", entry->feature_flags );
7572b33a0f9SSteve Passe }
7582b33a0f9SSteve Passe 
7592b33a0f9SSteve Passe 
7602b33a0f9SSteve Passe /*
7612b33a0f9SSteve Passe  *
7622b33a0f9SSteve Passe  */
7632b33a0f9SSteve Passe static int
lookupBusType(char * name)7642b33a0f9SSteve Passe lookupBusType( char* name )
7652b33a0f9SSteve Passe {
7662b33a0f9SSteve Passe     int x;
7672b33a0f9SSteve Passe 
7682b33a0f9SSteve Passe     for ( x = 0; x < MAX_BUSTYPE; ++x )
7692b33a0f9SSteve Passe 	if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
7702b33a0f9SSteve Passe 	    return busTypeTable[ x ].type;
7712b33a0f9SSteve Passe 
7722b33a0f9SSteve Passe     return UNKNOWN_BUSTYPE;
7732b33a0f9SSteve Passe }
7742b33a0f9SSteve Passe 
7752b33a0f9SSteve Passe 
7762b33a0f9SSteve Passe static void
busEntry(bus_entry_ptr entry)777a61a3b33SJohn Baldwin busEntry( bus_entry_ptr entry )
7782b33a0f9SSteve Passe {
7792b33a0f9SSteve Passe     int		x;
7802b33a0f9SSteve Passe     char	name[ 8 ];
7812b33a0f9SSteve Passe     char	c;
7822b33a0f9SSteve Passe 
7832b33a0f9SSteve Passe     /* count it */
7842b33a0f9SSteve Passe     ++nbus;
7852b33a0f9SSteve Passe 
786a61a3b33SJohn Baldwin     printf( "\t\t%2d", entry->bus_id );
787a61a3b33SJohn Baldwin     printf( "\t " ); pnstr( entry->bus_type, 6 ); printf( "\n" );
7882b33a0f9SSteve Passe 
7892b33a0f9SSteve Passe     for ( x = 0; x < 6; ++x ) {
790a61a3b33SJohn Baldwin 	if ( (c = entry->bus_type[ x ]) == ' ' )
7912b33a0f9SSteve Passe 	    break;
7922b33a0f9SSteve Passe 	name[ x ] = c;
7932b33a0f9SSteve Passe     }
7942b33a0f9SSteve Passe     name[ x ] = '\0';
795a61a3b33SJohn Baldwin     busses[ entry->bus_id ] = lookupBusType( name );
7962b33a0f9SSteve Passe }
7972b33a0f9SSteve Passe 
7982b33a0f9SSteve Passe 
7992b33a0f9SSteve Passe static void
ioApicEntry(io_apic_entry_ptr entry)800a61a3b33SJohn Baldwin ioApicEntry( io_apic_entry_ptr entry )
8012b33a0f9SSteve Passe {
8022b33a0f9SSteve Passe 
8032b33a0f9SSteve Passe     /* count it */
8042b33a0f9SSteve Passe     ++napic;
8052b33a0f9SSteve Passe 
806a61a3b33SJohn Baldwin     printf( "\t\t%2d", entry->apic_id );
807a61a3b33SJohn Baldwin     printf( "\t 0x%02x", entry->apic_version );
8082b33a0f9SSteve Passe     printf( "\t %s",
809a61a3b33SJohn Baldwin             (entry->apic_flags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
810a61a3b33SJohn Baldwin     printf( "\t\t 0x%x\n", entry->apic_address );
8112b33a0f9SSteve Passe 
812a61a3b33SJohn Baldwin     apics[ entry->apic_id ] = entry->apic_id;
8132b33a0f9SSteve Passe }
8142b33a0f9SSteve Passe 
8152b33a0f9SSteve Passe 
81660bd06daSEd Schouten static const char *intTypes[] = {
8172b33a0f9SSteve Passe     "INT", "NMI", "SMI", "ExtINT"
8182b33a0f9SSteve Passe };
8192b33a0f9SSteve Passe 
82060bd06daSEd Schouten static const char *polarityMode[] = {
8212b33a0f9SSteve Passe     "conforms", "active-hi", "reserved", "active-lo"
8222b33a0f9SSteve Passe };
82360bd06daSEd Schouten static const char *triggerMode[] = {
8242b33a0f9SSteve Passe     "conforms", "edge", "reserved", "level"
8252b33a0f9SSteve Passe };
8262b33a0f9SSteve Passe 
8272b33a0f9SSteve Passe static void
intEntry(int_entry_ptr entry)828a61a3b33SJohn Baldwin intEntry( int_entry_ptr entry )
8292b33a0f9SSteve Passe {
8302b33a0f9SSteve Passe 
8312b33a0f9SSteve Passe     /* count it */
832a61a3b33SJohn Baldwin     if ( entry->type == MPCT_ENTRY_INT )
8332b33a0f9SSteve Passe 	++nintr;
8342b33a0f9SSteve Passe 
835a61a3b33SJohn Baldwin     printf( "\t\t%s", intTypes[ entry->int_type ] );
8362b33a0f9SSteve Passe 
837a61a3b33SJohn Baldwin     printf( "\t%9s", polarityMode[ entry->int_flags & INTENTRY_FLAGS_POLARITY ] );
838a61a3b33SJohn Baldwin     printf( "%12s", triggerMode[ (entry->int_flags & INTENTRY_FLAGS_TRIGGER) >> 2 ] );
8392b33a0f9SSteve Passe 
840a61a3b33SJohn Baldwin     printf( "\t %5d", entry->src_bus_id );
841a61a3b33SJohn Baldwin     if ( busses[ entry->src_bus_id ] == PCI )
8422b33a0f9SSteve Passe 	printf( "\t%2d:%c",
843a61a3b33SJohn Baldwin 	        (entry->src_bus_irq >> 2) & 0x1f,
844a61a3b33SJohn Baldwin 	        (entry->src_bus_irq & 0x03) + 'A' );
8452b33a0f9SSteve Passe     else
846a61a3b33SJohn Baldwin 	printf( "\t %3d", entry->src_bus_irq );
847a61a3b33SJohn Baldwin     printf( "\t %6d", entry->dst_apic_id );
848a61a3b33SJohn Baldwin     printf( "\t %3d\n", entry->dst_apic_int );
8492b33a0f9SSteve Passe }
8502b33a0f9SSteve Passe 
8512b33a0f9SSteve Passe 
8522b33a0f9SSteve Passe static void
sasEntry(sas_entry_ptr entry)853a61a3b33SJohn Baldwin sasEntry( sas_entry_ptr entry )
8542b33a0f9SSteve Passe {
8552b33a0f9SSteve Passe 
856a61a3b33SJohn Baldwin     printf( "--\nSystem Address Space\n");
857a61a3b33SJohn Baldwin     printf( " bus ID: %d", entry->bus_id );
8582b33a0f9SSteve Passe     printf( " address type: " );
859a61a3b33SJohn Baldwin     switch ( entry->address_type ) {
860a61a3b33SJohn Baldwin     case SASENTRY_TYPE_IO:
8612b33a0f9SSteve Passe 	printf( "I/O address\n" );
8622b33a0f9SSteve Passe 	break;
863a61a3b33SJohn Baldwin     case SASENTRY_TYPE_MEMORY:
8642b33a0f9SSteve Passe 	printf( "memory address\n" );
8652b33a0f9SSteve Passe 	break;
866a61a3b33SJohn Baldwin     case SASENTRY_TYPE_PREFETCH:
8672b33a0f9SSteve Passe 	printf( "prefetch address\n" );
8682b33a0f9SSteve Passe 	break;
8692b33a0f9SSteve Passe     default:
8702b33a0f9SSteve Passe 	printf( "UNKNOWN type\n" );
8712b33a0f9SSteve Passe 	break;
8722b33a0f9SSteve Passe     }
8732b33a0f9SSteve Passe 
874a61a3b33SJohn Baldwin     printf( " address base: 0x%jx\n", (uintmax_t)entry->address_base );
875a61a3b33SJohn Baldwin     printf( " address range: 0x%jx\n", (uintmax_t)entry->address_length );
8762b33a0f9SSteve Passe }
8772b33a0f9SSteve Passe 
8782b33a0f9SSteve Passe 
8792b33a0f9SSteve Passe static void
bhdEntry(bhd_entry_ptr entry)880a61a3b33SJohn Baldwin bhdEntry( bhd_entry_ptr entry )
8812b33a0f9SSteve Passe {
8822b33a0f9SSteve Passe 
883a61a3b33SJohn Baldwin     printf( "--\nBus Hierarchy\n" );
884a61a3b33SJohn Baldwin     printf( " bus ID: %d", entry->bus_id );
885a61a3b33SJohn Baldwin     printf( " bus info: 0x%02x", entry->bus_info );
886a61a3b33SJohn Baldwin     printf( " parent bus ID: %d\n", entry->parent_bus );
8872b33a0f9SSteve Passe }
8882b33a0f9SSteve Passe 
8892b33a0f9SSteve Passe 
8902b33a0f9SSteve Passe static void
cbasmEntry(cbasm_entry_ptr entry)891a61a3b33SJohn Baldwin cbasmEntry( cbasm_entry_ptr entry )
8922b33a0f9SSteve Passe {
8932b33a0f9SSteve Passe 
894a61a3b33SJohn Baldwin     printf( "--\nCompatibility Bus Address\n" );
895a61a3b33SJohn Baldwin     printf( " bus ID: %d", entry->bus_id );
896a61a3b33SJohn Baldwin     printf( " address modifier: %s\n",
897a61a3b33SJohn Baldwin 	(entry->address_mod & CBASMENTRY_ADDRESS_MOD_SUBTRACT) ?
8982b33a0f9SSteve Passe 	"subtract" : "add" );
899a61a3b33SJohn Baldwin     printf( " predefined range: 0x%08x\n", entry->predefined_range );
9002b33a0f9SSteve Passe }
9012b33a0f9SSteve Passe 
9022b33a0f9SSteve Passe 
9032b33a0f9SSteve Passe /*
9042b33a0f9SSteve Passe  * do a dmesg output
9052b33a0f9SSteve Passe  */
9062b33a0f9SSteve Passe static void
doDmesg(void)9072b33a0f9SSteve Passe doDmesg( void )
9082b33a0f9SSteve Passe {
9092b33a0f9SSteve Passe     puts( SEP_LINE );
9102b33a0f9SSteve Passe 
9112b33a0f9SSteve Passe     printf( "dmesg output:\n\n" );
9122b33a0f9SSteve Passe     fflush( stdout );
9132b33a0f9SSteve Passe     system( "dmesg" );
9142b33a0f9SSteve Passe }
9152b33a0f9SSteve Passe 
9162b33a0f9SSteve Passe 
9172b33a0f9SSteve Passe /*
9182b33a0f9SSteve Passe  *
9192b33a0f9SSteve Passe  */
9202b33a0f9SSteve Passe static void
pnstr(char * s,int c)9212b33a0f9SSteve Passe pnstr( char* s, int c )
9222b33a0f9SSteve Passe {
9232b33a0f9SSteve Passe     char string[ MAXPNSTR + 1 ];
9242b33a0f9SSteve Passe 
9252b33a0f9SSteve Passe     if ( c > MAXPNSTR )
9262b33a0f9SSteve Passe         c = MAXPNSTR;
9272b33a0f9SSteve Passe     strncpy( string, s, c );
9282b33a0f9SSteve Passe     string[ c ] = '\0';
9292b33a0f9SSteve Passe     printf( "%s", string );
9302b33a0f9SSteve Passe }
931