xref: /onnv-gate/usr/src/cmd/mdb/sun4v/modules/vdsk/vdsk.c (revision 1991:f29baf5bf770)
1*1991Sheppo /*
2*1991Sheppo  * CDDL HEADER START
3*1991Sheppo  *
4*1991Sheppo  * The contents of this file are subject to the terms of the
5*1991Sheppo  * Common Development and Distribution License (the "License").
6*1991Sheppo  * You may not use this file except in compliance with the License.
7*1991Sheppo  *
8*1991Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*1991Sheppo  * or http://www.opensolaris.org/os/licensing.
10*1991Sheppo  * See the License for the specific language governing permissions
11*1991Sheppo  * and limitations under the License.
12*1991Sheppo  *
13*1991Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
14*1991Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*1991Sheppo  * If applicable, add the following below this CDDL HEADER, with the
16*1991Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
17*1991Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
18*1991Sheppo  *
19*1991Sheppo  * CDDL HEADER END
20*1991Sheppo  */
21*1991Sheppo 
22*1991Sheppo /*
23*1991Sheppo  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*1991Sheppo  * Use is subject to license terms.
25*1991Sheppo  */
26*1991Sheppo 
27*1991Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*1991Sheppo 
29*1991Sheppo /*
30*1991Sheppo  * This module provides debugging tools for the LDoms vDisk drivers
31*1991Sheppo  * (vds and vdc).
32*1991Sheppo  */
33*1991Sheppo 
34*1991Sheppo #include <sys/mdb_modapi.h>
35*1991Sheppo 
36*1991Sheppo #include <sys/vdsk_common.h>
37*1991Sheppo 
38*1991Sheppo /*
39*1991Sheppo  */
40*1991Sheppo int
vd_dring_entry_walk_init(mdb_walk_state_t * wsp)41*1991Sheppo vd_dring_entry_walk_init(mdb_walk_state_t *wsp)
42*1991Sheppo {
43*1991Sheppo 	/* Must have a start addr.  */
44*1991Sheppo 	if (wsp->walk_addr == NULL) {
45*1991Sheppo 		mdb_warn("Descriptor Ring base address required\n");
46*1991Sheppo 
47*1991Sheppo 		return (WALK_ERR);
48*1991Sheppo 	}
49*1991Sheppo 
50*1991Sheppo 	return (WALK_NEXT);
51*1991Sheppo }
52*1991Sheppo 
53*1991Sheppo 
54*1991Sheppo /*
55*1991Sheppo  * Generic entry walker step routine.
56*1991Sheppo  */
57*1991Sheppo int
vd_dring_entry_walk_step(mdb_walk_state_t * wsp)58*1991Sheppo vd_dring_entry_walk_step(mdb_walk_state_t *wsp)
59*1991Sheppo {
60*1991Sheppo 	static int		entry_count = 0;
61*1991Sheppo 	int			status;
62*1991Sheppo 	vd_dring_entry_t	dring_entry;
63*1991Sheppo 
64*1991Sheppo 	if (mdb_vread(&dring_entry, VD_DRING_ENTRY_SZ,
65*1991Sheppo 	    (uintptr_t)wsp->walk_addr) == -1) {
66*1991Sheppo 		mdb_warn("failed to read vd_dring_entry_t at %p",
67*1991Sheppo 		    wsp->walk_addr);
68*1991Sheppo 
69*1991Sheppo 		return (WALK_ERR);
70*1991Sheppo 	}
71*1991Sheppo 
72*1991Sheppo 	status = wsp->walk_callback(wsp->walk_addr, &dring_entry,
73*1991Sheppo 	    wsp->walk_cbdata);
74*1991Sheppo 	wsp->walk_addr = (uintptr_t)(wsp->walk_addr + VD_DRING_ENTRY_SZ);
75*1991Sheppo 
76*1991Sheppo 	/* Check if we're at the last element */
77*1991Sheppo 	if (++entry_count >= VD_DRING_LEN) {
78*1991Sheppo 		/* reset counter for next call to this walker */
79*1991Sheppo 		entry_count = 0;
80*1991Sheppo 
81*1991Sheppo 		return (WALK_DONE);
82*1991Sheppo 	}
83*1991Sheppo 
84*1991Sheppo 	return (status);
85*1991Sheppo }
86*1991Sheppo 
87*1991Sheppo /*
88*1991Sheppo  * MDB module linkage information:
89*1991Sheppo  */
90*1991Sheppo 
91*1991Sheppo static const mdb_walker_t walkers[] = {
92*1991Sheppo 	{ "vd_dring_entry", "walk vDisk public Descriptor Ring entries",
93*1991Sheppo 	    vd_dring_entry_walk_init, vd_dring_entry_walk_step, NULL, NULL },
94*1991Sheppo 	{ NULL }
95*1991Sheppo };
96*1991Sheppo 
97*1991Sheppo static const mdb_modinfo_t modinfo = {
98*1991Sheppo 	MDB_API_VERSION, NULL, walkers
99*1991Sheppo };
100*1991Sheppo 
101*1991Sheppo const mdb_modinfo_t *
_mdb_init(void)102*1991Sheppo _mdb_init(void)
103*1991Sheppo {
104*1991Sheppo 	return (&modinfo);
105*1991Sheppo }
106