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