4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "ndievents.h"
30 #include <sys/sunndi.h>
31 #include <sys/ndi_impldefs.h>
32 #include <sys/dditypes.h>
33 #include <sys/ddi_impldefs.h>
34 #include <sys/sunddi.h>
35 #include <sys/param.h>
39 dip_to_pathname(struct dev_info
*device
, char *path
, int buflen
) {
44 char nodename
[MAXNAMELEN
];
45 struct dev_info devi_parent
;
48 mdb_warn("Unable to access devinfo.");
52 if (device
->devi_parent
== NULL
) {
53 if (mdb_readstr(nodename
, sizeof (nodename
),
54 (uintptr_t)device
->devi_node_name
) == -1) {
58 if (sizeof (nodename
) > (buflen
- strlen(path
))) {
62 strncpy(path
, nodename
, sizeof (nodename
));
66 if (mdb_vread(&devi_parent
, sizeof (struct dev_info
),
67 (uintptr_t)device
->devi_parent
) == -1) {
68 mdb_warn("Unable to access devi_parent at %p",
69 (uintptr_t)device
->devi_parent
);
73 if (dip_to_pathname(&devi_parent
, path
, buflen
) == -1) {
77 if (mdb_readstr(nodename
, sizeof (nodename
),
78 (uintptr_t)device
->devi_node_name
) == -1) {
82 if (device
->devi_node_state
< DS_INITIALIZED
) {
83 strncpy(addr_str
, '\0', sizeof ('\0'));
85 addr
= device
->devi_addr
;
86 if (mdb_readstr(addr_str
, sizeof (addr_str
),
87 (uintptr_t)addr
) == -1) {
92 bp
= path
+ strlen(path
);
94 if (addr_str
[0] == '\0') {
95 (void) mdb_snprintf(bp
, buflen
- strlen(path
), "/%s", nodename
);
97 (void) mdb_snprintf(bp
, buflen
- strlen(path
), "/%s@%s",
106 ndi_callback_print(struct ndi_event_cookie
*cookie
, uint_t flags
)
109 struct ndi_event_callbacks
*callback_list
;
110 struct ndi_event_callbacks cb
;
111 char device_path
[MAXPATHLEN
];
112 struct dev_info devi
;
118 callback_list
= cookie
->callback_list
;
120 while (callback_list
!= NULL
) {
121 if (mdb_vread(&cb
, sizeof (struct ndi_event_callbacks
),
122 (uintptr_t)callback_list
) == -1) {
123 mdb_warn("Could not read callback structure at"
124 " %p", callback_list
);
128 if (mdb_vread(&devi
, sizeof (struct dev_info
),
129 (uintptr_t)cb
.ndi_evtcb_dip
) == -1) {
130 mdb_warn("Could not read devinfo structure at"
131 " %p", cb
.ndi_evtcb_dip
);
135 if (dip_to_pathname(&devi
, device_path
, sizeof (device_path
))
140 mdb_printf("\t\tCallback Registered By: %s\n", device_path
);
141 mdb_printf("\t\t Callback Address:\t%-?p\n"
142 "\t\t Callback Function:\t%-p\n"
143 "\t\t Callback Args:\t%-?p\n"
144 "\t\t Callback Cookie:\t%-?p\n",
145 callback_list
, cb
.ndi_evtcb_callback
, cb
.ndi_evtcb_arg
,
146 cb
.ndi_evtcb_cookie
);
148 callback_list
= cb
.ndi_evtcb_next
;
156 ndi_event_print(struct ndi_event_hdl
*hdl
, uint_t flags
)
159 struct ndi_event_definition def
;
160 struct ndi_event_cookie cookie
;
161 struct ndi_event_cookie
*cookie_list
;
162 char ndi_event_name
[256];
167 cookie_list
= hdl
->ndi_evthdl_cookie_list
;
168 if (cookie_list
== NULL
) {
169 mdb_printf("\tNo cookies defined for this handle.\n");
173 while (cookie_list
!= NULL
) {
174 if (mdb_vread(&cookie
, sizeof (struct ndi_event_cookie
),
175 (uintptr_t)cookie_list
) == -1) {
176 mdb_warn("Unable to access cookie list");
180 if (mdb_vread(&def
, sizeof (struct ndi_event_definition
),
181 (uintptr_t)cookie
.definition
) == -1) {
182 mdb_warn("Unable to access definition at %p",
187 if (mdb_readstr(ndi_event_name
, sizeof (ndi_event_name
),
188 (uintptr_t)def
.ndi_event_name
) == -1) {
189 mdb_warn("Unable to read cookie name.");
193 mdb_printf("\tCookie(%s %p) :Plevel(%d)\n\tddip(%p)"
195 ndi_event_name
, cookie_list
, def
.ndi_event_plevel
,
196 cookie
.ddip
, def
.ndi_event_attributes
);
198 ndi_callback_print(&cookie
, flags
);
199 cookie_list
= cookie
.next_cookie
;
207 ndi_event_hdl(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
210 struct dev_info devi
;
211 struct ndi_event_hdl handle
;
212 char path
[MAXPATHLEN
];
215 if (!(flags
& DCMD_ADDRSPEC
)) {
219 if (mdb_vread(&handle
, sizeof (struct ndi_event_hdl
), addr
) == -1) {
220 mdb_warn("failed to read ndi_event_hdl at %p", addr
);
224 if (mdb_vread(&devi
, sizeof (struct dev_info
),
225 (uintptr_t)handle
.ndi_evthdl_dip
)
227 mdb_warn("failed to read devinfo node at %p",
228 handle
.ndi_evthdl_dip
);
232 if (dip_to_pathname(&devi
, path
, sizeof (path
)) == -1) {
239 mdb_printf("%<b>Handle%</b> (%p) :%<b> Path%</b> (%s) : %<b>"
240 "dip %</b>(%p) \n", addr
, path
, handle
.ndi_evthdl_dip
);
242 mdb_printf("mutexes: handle(%p) callback(%p)\n",
243 handle
.ndi_evthdl_mutex
, handle
.ndi_evthdl_cb_mutex
);
245 ndi_event_print(&handle
, flags
);
247 if (handle
.ndi_next_hdl
== NULL
) {
250 addr
= (uintptr_t)handle
.ndi_next_hdl
;
251 if (mdb_vread(&handle
, sizeof (struct ndi_event_hdl
),
252 (uintptr_t)addr
) == -1) {
253 mdb_warn("failed to read ndi_event_hdl at %p",