1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2018, Joyent, Inc.
*/
#include "ndievents.h"
#include <sys/sunndi.h>
#include <sys/ndi_impldefs.h>
#include <sys/dditypes.h>
#include <sys/ddi_impldefs.h>
#include <sys/sunddi.h>
#include <sys/param.h>
int
dip_to_pathname(struct dev_info *device, char *path, int buflen)
{
char *bp;
char *addr;
char addr_str[32];
char nodename[MAXNAMELEN];
struct dev_info devi_parent;
if (!device) {
mdb_warn("Unable to access devinfo.");
return (-1);
}
if (device->devi_parent == NULL) {
if (mdb_readstr(nodename, sizeof (nodename),
(uintptr_t)device->devi_node_name) == -1) {
return (-1);
}
if (sizeof (nodename) > (buflen - strlen(path))) {
return (-1);
}
strncpy(path, nodename, sizeof (nodename));
return (0);
}
if (mdb_vread(&devi_parent, sizeof (struct dev_info),
(uintptr_t)device->devi_parent) == -1) {
mdb_warn("Unable to access devi_parent at %p",
(uintptr_t)device->devi_parent);
return (-1);
}
if (dip_to_pathname(&devi_parent, path, buflen) == -1) {
return (-1);
}
if (mdb_readstr(nodename, sizeof (nodename),
(uintptr_t)device->devi_node_name) == -1) {
return (-1);
}
if (device->devi_node_state < DS_INITIALIZED) {
addr_str[0] = '\0';
} else {
addr = device->devi_addr;
if (mdb_readstr(addr_str, sizeof (addr_str),
(uintptr_t)addr) == -1) {
return (-1);
}
}
bp = path + strlen(path);
if (addr_str[0] == '\0') {
(void) mdb_snprintf(bp, buflen - strlen(path), "/%s", nodename);
} else {
(void) mdb_snprintf(bp, buflen - strlen(path), "/%s@%s",
nodename, addr_str);
}
return (0);
}
/*ARGSUSED*/
int
ndi_callback_print(struct ndi_event_cookie *cookie, uint_t flags)
{
struct ndi_event_callbacks *callback_list;
struct ndi_event_callbacks cb;
char device_path[MAXPATHLEN];
struct dev_info devi;
if (!cookie) {
return (DCMD_ERR);
}
callback_list = cookie->callback_list;
while (callback_list != NULL) {
if (mdb_vread(&cb, sizeof (struct ndi_event_callbacks),
(uintptr_t)callback_list) == -1) {
mdb_warn("Could not read callback structure at"
" %p", callback_list);
return (DCMD_ERR);
}
if (mdb_vread(&devi, sizeof (struct dev_info),
(uintptr_t)cb.ndi_evtcb_dip) == -1) {
mdb_warn("Could not read devinfo structure at"
" %p", cb.ndi_evtcb_dip);
return (DCMD_ERR);
}
if (dip_to_pathname(&devi, device_path, sizeof (device_path))
== -1) {
return (DCMD_ERR);
}
mdb_printf("\t\tCallback Registered By: %s\n", device_path);
mdb_printf("\t\t Callback Address:\t%-?p\n"
"\t\t Callback Function:\t%-p\n"
"\t\t Callback Args:\t%-?p\n"
"\t\t Callback Cookie:\t%-?p\n",
callback_list, cb.ndi_evtcb_callback, cb.ndi_evtcb_arg,
cb.ndi_evtcb_cookie);
callback_list = cb.ndi_evtcb_next;
}
return (DCMD_OK);
}
int
ndi_event_print(struct ndi_event_hdl *hdl, uint_t flags)
{
struct ndi_event_definition def;
struct ndi_event_cookie cookie;
struct ndi_event_cookie *cookie_list;
char ndi_event_name[256];
if (!hdl)
return (DCMD_ERR);
cookie_list = hdl->ndi_evthdl_cookie_list;
if (cookie_list == NULL) {
mdb_printf("\tNo cookies defined for this handle.\n");
return (DCMD_OK);
}
while (cookie_list != NULL) {
if (mdb_vread(&cookie, sizeof (struct ndi_event_cookie),
(uintptr_t)cookie_list) == -1) {
mdb_warn("Unable to access cookie list");
return (DCMD_ERR);
}
if (mdb_vread(&def, sizeof (struct ndi_event_definition),
(uintptr_t)cookie.definition) == -1) {
mdb_warn("Unable to access definition at %p",
cookie.definition);
return (DCMD_ERR);
}
if (mdb_readstr(ndi_event_name, sizeof (ndi_event_name),
(uintptr_t)def.ndi_event_name) == -1) {
mdb_warn("Unable to read cookie name.");
return (DCMD_ERR);
}
mdb_printf("\tCookie(%s %p) :Plevel(%d)\n\tddip(%p)"
" : Attr(%d)\n",
ndi_event_name, cookie_list, def.ndi_event_plevel,
cookie.ddip, def.ndi_event_attributes);
ndi_callback_print(&cookie, flags);
cookie_list = cookie.next_cookie;
}
return (0);
}
/*ARGSUSED*/
int
ndi_event_hdl(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
struct dev_info devi;
struct ndi_event_hdl handle;
char path[MAXPATHLEN];
int done;
if (!(flags & DCMD_ADDRSPEC)) {
return (DCMD_USAGE);
}
if (mdb_vread(&handle, sizeof (struct ndi_event_hdl), addr) == -1) {
mdb_warn("failed to read ndi_event_hdl at %p", addr);
return (DCMD_ERR);
}
if (mdb_vread(&devi, sizeof (struct dev_info),
(uintptr_t)handle.ndi_evthdl_dip) == -1) {
mdb_warn("failed to read devinfo node at %p",
handle.ndi_evthdl_dip);
return (DCMD_ERR);
}
if (dip_to_pathname(&devi, path, sizeof (path)) == -1) {
return (DCMD_ERR);
}
done = 0;
while (!done) {
mdb_printf("%<b>Handle%</b> (%p) :%<b> Path%</b> (%s) : %<b>"
"dip %</b>(%p) \n", addr, path, handle.ndi_evthdl_dip);
mdb_printf("mutexes: handle(%p) callback(%p)\n",
handle.ndi_evthdl_mutex, handle.ndi_evthdl_cb_mutex);
ndi_event_print(&handle, flags);
if (handle.ndi_next_hdl == NULL) {
done = 1;
} else {
addr = (uintptr_t)handle.ndi_next_hdl;
if (mdb_vread(&handle, sizeof (struct ndi_event_hdl),
(uintptr_t)addr) == -1) {
mdb_warn("failed to read ndi_event_hdl at %p",
addr);
break;
}
}
}
return (0);
}
|