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