xref: /titanic_51/usr/src/cmd/mdb/sun4v/modules/vdsk/vdsk.c (revision fe598cdcd847f8359013532d5c691bb6190378c0)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * This module provides debugging tools for the LDoms vDisk drivers
31  * (vds and vdc).
32  */
33 
34 #include <sys/mdb_modapi.h>
35 
36 #include <sys/vdsk_common.h>
37 
38 /*
39  */
40 int
41 vd_dring_entry_walk_init(mdb_walk_state_t *wsp)
42 {
43 	/* Must have a start addr.  */
44 	if (wsp->walk_addr == NULL) {
45 		mdb_warn("Descriptor Ring base address required\n");
46 
47 		return (WALK_ERR);
48 	}
49 
50 	return (WALK_NEXT);
51 }
52 
53 
54 /*
55  * Generic entry walker step routine.
56  */
57 int
58 vd_dring_entry_walk_step(mdb_walk_state_t *wsp)
59 {
60 	static int		entry_count = 0;
61 	int			status;
62 	vd_dring_entry_t	dring_entry;
63 
64 	if (mdb_vread(&dring_entry, VD_DRING_ENTRY_SZ,
65 	    (uintptr_t)wsp->walk_addr) == -1) {
66 		mdb_warn("failed to read vd_dring_entry_t at %p",
67 		    wsp->walk_addr);
68 
69 		return (WALK_ERR);
70 	}
71 
72 	status = wsp->walk_callback(wsp->walk_addr, &dring_entry,
73 	    wsp->walk_cbdata);
74 	wsp->walk_addr = (uintptr_t)(wsp->walk_addr + VD_DRING_ENTRY_SZ);
75 
76 	/* Check if we're at the last element */
77 	if (++entry_count >= VD_DRING_LEN) {
78 		/* reset counter for next call to this walker */
79 		entry_count = 0;
80 
81 		return (WALK_DONE);
82 	}
83 
84 	return (status);
85 }
86 
87 /*
88  * MDB module linkage information:
89  */
90 
91 static const mdb_walker_t walkers[] = {
92 	{ "vd_dring_entry", "walk vDisk public Descriptor Ring entries",
93 	    vd_dring_entry_walk_init, vd_dring_entry_walk_step, NULL, NULL },
94 	{ NULL }
95 };
96 
97 static const mdb_modinfo_t modinfo = {
98 	MDB_API_VERSION, NULL, walkers
99 };
100 
101 const mdb_modinfo_t *
102 _mdb_init(void)
103 {
104 	return (&modinfo);
105 }
106