1*3434Sesaxe /*
2*3434Sesaxe  * CDDL HEADER START
3*3434Sesaxe  *
4*3434Sesaxe  * The contents of this file are subject to the terms of the
5*3434Sesaxe  * Common Development and Distribution License (the "License").
6*3434Sesaxe  * You may not use this file except in compliance with the License.
7*3434Sesaxe  *
8*3434Sesaxe  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3434Sesaxe  * or http://www.opensolaris.org/os/licensing.
10*3434Sesaxe  * See the License for the specific language governing permissions
11*3434Sesaxe  * and limitations under the License.
12*3434Sesaxe  *
13*3434Sesaxe  * When distributing Covered Code, include this CDDL HEADER in each
14*3434Sesaxe  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3434Sesaxe  * If applicable, add the following below this CDDL HEADER, with the
16*3434Sesaxe  * fields enclosed by brackets "[]" replaced with your own identifying
17*3434Sesaxe  * information: Portions Copyright [yyyy] [name of copyright owner]
18*3434Sesaxe  *
19*3434Sesaxe  * CDDL HEADER END
20*3434Sesaxe  */
21*3434Sesaxe 
22*3434Sesaxe /*
23*3434Sesaxe  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*3434Sesaxe  * Use is subject to license terms.
25*3434Sesaxe  */
26*3434Sesaxe 
27*3434Sesaxe #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*3434Sesaxe 
29*3434Sesaxe /*
30*3434Sesaxe  * Display processor group information
31*3434Sesaxe  */
32*3434Sesaxe 
33*3434Sesaxe #include "pg.h"
34*3434Sesaxe 
35*3434Sesaxe #include <mdb/mdb_modapi.h>
36*3434Sesaxe #include <sys/pghw.h>
37*3434Sesaxe 
38*3434Sesaxe /*
39*3434Sesaxe  * PG hardware types indexed by hardware ID
40*3434Sesaxe  */
41*3434Sesaxe char *pg_hw_names[] = {
42*3434Sesaxe 	"hw",
43*3434Sesaxe 	"ipipe",
44*3434Sesaxe 	"cache",
45*3434Sesaxe 	"fpu",
46*3434Sesaxe 	"mpipe/chip",
47*3434Sesaxe 	"memory",
48*3434Sesaxe };
49*3434Sesaxe 
50*3434Sesaxe #define	A_CNT(arr)	(sizeof (arr) / sizeof (arr[0]))
51*3434Sesaxe 
52*3434Sesaxe #define	NHW	 A_CNT(pg_hw_names)
53*3434Sesaxe 
54*3434Sesaxe /*
55*3434Sesaxe  * Convert HW id to symbolic name
56*3434Sesaxe  */
57*3434Sesaxe static char *
58*3434Sesaxe pg_hw_name(int hw)
59*3434Sesaxe {
60*3434Sesaxe 	return ((hw < 0 || hw > NHW) ? "UNKNOWN" : pg_hw_names[hw]);
61*3434Sesaxe }
62*3434Sesaxe 
63*3434Sesaxe /*
64*3434Sesaxe  * Display processor group.
65*3434Sesaxe  */
66*3434Sesaxe /* ARGSUSED */
67*3434Sesaxe int
68*3434Sesaxe pg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
69*3434Sesaxe {
70*3434Sesaxe 	pg_t		pg;
71*3434Sesaxe 	pghw_t		pghw;
72*3434Sesaxe 	pg_class_t	pg_class;
73*3434Sesaxe 	int		opt_q = 0; /* display only address. */
74*3434Sesaxe 
75*3434Sesaxe 	/* Should provide an address */
76*3434Sesaxe 	if (! (flags & DCMD_ADDRSPEC))
77*3434Sesaxe 		return (DCMD_USAGE);
78*3434Sesaxe 
79*3434Sesaxe 	if (mdb_getopts(argc, argv,
80*3434Sesaxe 	    'q', MDB_OPT_SETBITS, TRUE, &opt_q,
81*3434Sesaxe 		NULL) != argc)
82*3434Sesaxe 		return (DCMD_USAGE);
83*3434Sesaxe 
84*3434Sesaxe 	if (flags & DCMD_PIPE_OUT)
85*3434Sesaxe 		opt_q = B_TRUE;
86*3434Sesaxe 
87*3434Sesaxe 	if (DCMD_HDRSPEC(flags) && !opt_q) {
88*3434Sesaxe 		mdb_printf("%6s %?s %6s %7s %9s %5s\n",
89*3434Sesaxe 		    "PGID",
90*3434Sesaxe 		    "ADDR",
91*3434Sesaxe 		    "PHYSID",
92*3434Sesaxe 		    "CLASS",
93*3434Sesaxe 		    "HARDWARE",
94*3434Sesaxe 		    "#CPUs");
95*3434Sesaxe 	}
96*3434Sesaxe 
97*3434Sesaxe 	/*
98*3434Sesaxe 	 * Read pg at specified address
99*3434Sesaxe 	 */
100*3434Sesaxe 	if (mdb_vread(&pg, sizeof (struct pg), addr) == -1) {
101*3434Sesaxe 		mdb_warn("unable to read 'pg' at %p", addr);
102*3434Sesaxe 		return (DCMD_ERR);
103*3434Sesaxe 	}
104*3434Sesaxe 
105*3434Sesaxe 	/*
106*3434Sesaxe 	 * In quiet mode just print pg address
107*3434Sesaxe 	 */
108*3434Sesaxe 	if (opt_q) {
109*3434Sesaxe 		mdb_printf("%0?p\n", addr);
110*3434Sesaxe 		return (DCMD_OK);
111*3434Sesaxe 	}
112*3434Sesaxe 
113*3434Sesaxe 	if (mdb_vread(&pg_class, sizeof (struct pg_class),
114*3434Sesaxe 		(uintptr_t)pg.pg_class) == -1) {
115*3434Sesaxe 		mdb_warn("unable to read 'pg_class' at %p", pg.pg_class);
116*3434Sesaxe 		return (DCMD_ERR);
117*3434Sesaxe 	}
118*3434Sesaxe 
119*3434Sesaxe 	if (pg.pg_relation == PGR_PHYSICAL) {
120*3434Sesaxe 		if (mdb_vread(&pghw, sizeof (struct pghw), addr) == -1) {
121*3434Sesaxe 			mdb_warn("unable to read 'pghw' at %p", addr);
122*3434Sesaxe 			return (DCMD_ERR);
123*3434Sesaxe 		}
124*3434Sesaxe 		/*
125*3434Sesaxe 		 * Display the physical PG info.
126*3434Sesaxe 		 */
127*3434Sesaxe 		mdb_printf("%6d %?p %6d %7s %9s %5d\n",
128*3434Sesaxe 		    pg.pg_id, addr, pghw.pghw_instance,
129*3434Sesaxe 		    pg_class.pgc_name, pg_hw_name(pghw.pghw_hw),
130*3434Sesaxe 		    pg.pg_cpus.grp_size);
131*3434Sesaxe 	} else {
132*3434Sesaxe 		/*
133*3434Sesaxe 		 * Display the basic PG info.
134*3434Sesaxe 		 */
135*3434Sesaxe 		mdb_printf("%6d %?p %7s %5d\n",
136*3434Sesaxe 		    pg.pg_id, addr, pg_class.pgc_name,
137*3434Sesaxe 		    pg.pg_cpus.grp_size);
138*3434Sesaxe 	}
139*3434Sesaxe 
140*3434Sesaxe 	return (DCMD_OK);
141*3434Sesaxe }
142