Print this page
XXXX don't fail device detach when it's physically removed
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/ddi_impldefs.h
+++ new/usr/src/uts/common/sys/ddi_impldefs.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 +
21 22 /*
22 23 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
24 + */
25 +
26 +/*
23 27 * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved.
24 28 * Copyright 2016 Joyent, Inc.
25 29 * Copyright (c) 2016 by Delphix. All rights reserved.
30 + * Copyright 2018 Nexenta Systems, Inc.
26 31 */
27 32
28 33 #ifndef _SYS_DDI_IMPLDEFS_H
29 34 #define _SYS_DDI_IMPLDEFS_H
30 35
31 36 #include <sys/types.h>
32 37 #include <sys/param.h>
33 38 #include <sys/t_lock.h>
34 39 #include <sys/ddipropdefs.h>
35 40 #include <sys/devops.h>
36 41 #include <sys/autoconf.h>
37 42 #include <sys/mutex.h>
38 43 #include <vm/page.h>
39 44 #include <sys/dacf_impl.h>
40 45 #include <sys/ndifm.h>
41 46 #include <sys/epm.h>
42 47 #include <sys/ddidmareq.h>
43 48 #include <sys/ddi_intr.h>
44 49 #include <sys/ddi_hp.h>
45 50 #include <sys/ddi_hp_impl.h>
46 51 #include <sys/ddi_isa.h>
47 52 #include <sys/id_space.h>
48 53 #include <sys/modhash.h>
49 54 #include <sys/bitset.h>
50 55
51 56 #ifdef __cplusplus
52 57 extern "C" {
53 58 #endif
54 59
55 60 /*
56 61 * The device id implementation has been switched to be based on properties.
57 62 * For compatibility with di_devid libdevinfo interface the following
58 63 * must be defined:
59 64 */
60 65 #define DEVID_COMPATIBILITY ((ddi_devid_t)-1)
61 66
62 67 /*
63 68 * Definitions for node class.
64 69 * DDI_NC_PROM: a node with a nodeid that may be used in a promif call.
65 70 * DDI_NC_PSEUDO: a software created node with a software assigned nodeid.
66 71 */
67 72 typedef enum {
68 73 DDI_NC_PROM = 0,
69 74 DDI_NC_PSEUDO
70 75 } ddi_node_class_t;
71 76
72 77 /*
73 78 * Definitions for generic callback mechanism.
74 79 */
75 80 typedef enum {
76 81 DDI_CB_INTR_ADD, /* More available interrupts */
77 82 DDI_CB_INTR_REMOVE /* Fewer available interrupts */
78 83 } ddi_cb_action_t;
79 84
80 85 typedef enum {
81 86 DDI_CB_FLAG_INTR = 0x1 /* Driver is IRM aware */
82 87 } ddi_cb_flags_t;
83 88
84 89 #define DDI_CB_FLAG_VALID(f) ((f) & DDI_CB_FLAG_INTR)
85 90
86 91 typedef int (*ddi_cb_func_t)(dev_info_t *dip, ddi_cb_action_t action,
87 92 void *cbarg, void *arg1, void *arg2);
88 93
89 94 typedef struct ddi_cb {
90 95 uint64_t cb_flags;
91 96 dev_info_t *cb_dip;
92 97 ddi_cb_func_t cb_func;
93 98 void *cb_arg1;
94 99 void *cb_arg2;
95 100 } ddi_cb_t;
96 101
97 102 /*
98 103 * dev_info: The main device information structure this is intended to be
99 104 * opaque to drivers and drivers should use ddi functions to
100 105 * access *all* driver accessible fields.
101 106 *
102 107 * devi_parent_data includes property lists (interrupts, registers, etc.)
103 108 * devi_driver_data includes whatever the driver wants to place there.
104 109 */
105 110 struct devinfo_audit;
106 111
107 112 typedef struct devi_port {
108 113 union {
109 114 struct {
110 115 uint32_t type;
111 116 uint32_t pad;
112 117 } port;
113 118 uint64_t type64;
114 119 } info;
115 120 void *priv_p;
116 121 } devi_port_t;
117 122
118 123 typedef struct devi_bus_priv {
119 124 devi_port_t port_up;
120 125 devi_port_t port_down;
121 126 } devi_bus_priv_t;
122 127
123 128 #if defined(__x86)
124 129 struct iommulib_unit;
125 130 typedef struct iommulib_unit *iommulib_handle_t;
126 131 struct iommulib_nex;
127 132 typedef struct iommulib_nex *iommulib_nexhandle_t;
128 133 #endif
129 134
130 135 typedef uint8_t ndi_flavor_t;
131 136 struct ddi_hp_cn_handle;
132 137
133 138 struct in_node;
134 139
135 140 struct dev_info {
136 141
137 142 struct dev_info *devi_parent; /* my parent node in tree */
138 143 struct dev_info *devi_child; /* my child list head */
139 144 struct dev_info *devi_sibling; /* next element on my level */
140 145
141 146 char *devi_binding_name; /* name used to bind driver: */
142 147 /* shared storage, points to */
143 148 /* devi_node_name, devi_compat_names */
144 149 /* or devi_rebinding_name */
145 150
146 151 char *devi_addr; /* address part of name */
147 152
148 153 int devi_nodeid; /* device nodeid */
149 154 int devi_instance; /* device instance number */
150 155
151 156 struct dev_ops *devi_ops; /* driver operations */
152 157
153 158 void *devi_parent_data; /* parent private data */
154 159 void *devi_driver_data; /* driver private data */
155 160
156 161 ddi_prop_t *devi_drv_prop_ptr; /* head of driver prop list */
157 162 ddi_prop_t *devi_sys_prop_ptr; /* head of system prop list */
158 163
159 164 struct ddi_minor_data *devi_minor; /* head of minor list */
160 165 struct dev_info *devi_next; /* Next instance of this device */
161 166 kmutex_t devi_lock; /* Protects per-devinfo data */
162 167
163 168 /* logical parents for busop primitives */
164 169
165 170 struct dev_info *devi_bus_map_fault; /* bus_map_fault parent */
166 171 void *devi_obsolete; /* obsolete placeholder */
167 172 struct dev_info *devi_bus_dma_allochdl; /* bus_dma_newhdl parent */
168 173 struct dev_info *devi_bus_dma_freehdl; /* bus_dma_freehdl parent */
169 174 struct dev_info *devi_bus_dma_bindhdl; /* bus_dma_bindhdl parent */
170 175 struct dev_info *devi_bus_dma_unbindhdl; /* bus_dma_unbindhdl parent */
171 176 struct dev_info *devi_bus_dma_flush; /* bus_dma_flush parent */
172 177 struct dev_info *devi_bus_dma_win; /* bus_dma_win parent */
173 178 struct dev_info *devi_bus_dma_ctl; /* bus_dma_ctl parent */
174 179 struct dev_info *devi_bus_ctl; /* bus_ctl parent */
175 180
176 181 ddi_prop_t *devi_hw_prop_ptr; /* head of hw prop list */
177 182
178 183 char *devi_node_name; /* The 'name' of the node */
179 184 char *devi_compat_names; /* A list of driver names */
180 185 size_t devi_compat_length; /* Size of compat_names */
181 186
182 187 int (*devi_bus_dma_bindfunc)(dev_info_t *, dev_info_t *,
183 188 ddi_dma_handle_t, struct ddi_dma_req *, ddi_dma_cookie_t *,
184 189 uint_t *);
185 190 int (*devi_bus_dma_unbindfunc)(dev_info_t *, dev_info_t *,
186 191 ddi_dma_handle_t);
187 192
188 193 char *devi_devid_str; /* registered device id */
189 194
190 195 /*
191 196 * power management entries
192 197 * components exist even if the device is not currently power managed
193 198 */
194 199 struct pm_info *devi_pm_info; /* 0 => dev not power managed */
195 200 uint_t devi_pm_flags; /* pm flags */
196 201 int devi_pm_num_components; /* number of components */
197 202 size_t devi_pm_comp_size; /* size of devi_components */
198 203 struct pm_component *devi_pm_components; /* array of pm components */
199 204 struct dev_info *devi_pm_ppm; /* ppm attached to this one */
200 205 void *devi_pm_ppm_private; /* for use by ppm driver */
201 206 int devi_pm_dev_thresh; /* "device" threshold */
202 207 uint_t devi_pm_kidsupcnt; /* # of kids powered up */
↓ open down ↓ |
167 lines elided |
↑ open up ↑ |
203 208 struct pm_scan *devi_pm_scan; /* pm scan info */
204 209 uint_t devi_pm_noinvolpm; /* # of descendents no-invol */
205 210 uint_t devi_pm_volpmd; /* # of voluntarily pm'ed */
206 211 kmutex_t devi_pm_lock; /* pm lock for state */
207 212 kmutex_t devi_pm_busy_lock; /* for component busy count */
208 213
209 214 uint_t devi_state; /* device/bus state flags */
210 215 /* see below for definitions */
211 216 kcondvar_t devi_cv; /* cv */
212 217 int devi_ref; /* reference count */
218 + int devi_gone; /* devi gone, force clean */
213 219
214 220 dacf_rsrvlist_t *devi_dacf_tasks; /* dacf reservation queue */
215 221
216 222 ddi_node_class_t devi_node_class; /* Node class */
217 223 int devi_node_attributes; /* Node attributes: See below */
218 224
219 225 char *devi_device_class;
220 226
221 227 /*
222 228 * New mpxio kernel hooks entries
223 229 */
224 230 int devi_mdi_component; /* mpxio component type */
225 231 void *devi_mdi_client; /* mpxio client information */
226 232 void *devi_mdi_xhci; /* vhci/phci info */
227 233
228 234 ddi_prop_list_t *devi_global_prop_list; /* driver global properties */
229 235 major_t devi_major; /* driver major number */
230 236 ddi_node_state_t devi_node_state; /* state of node */
231 237 uint_t devi_flags; /* configuration flags */
232 238 int devi_circular; /* for recursive operations */
233 239 void *devi_busy_thread; /* thread operating on node */
234 240 void *devi_taskq; /* hotplug taskq */
235 241
236 242 /* device driver statistical and audit info */
237 243 struct devinfo_audit *devi_audit; /* last state change */
238 244
239 245 /*
240 246 * FMA support for resource caches and error handlers
241 247 */
242 248 struct i_ddi_fmhdl *devi_fmhdl;
243 249
244 250 uint_t devi_cpr_flags;
245 251
246 252 /* Owned by DDI interrupt framework */
247 253 devinfo_intr_t *devi_intr_p;
248 254
249 255 void *devi_nex_pm; /* nexus PM private */
250 256
251 257 char *devi_addr_buf; /* buffer for devi_addr */
252 258
253 259 char *devi_rebinding_name; /* binding_name of rebind */
254 260
255 261 /* For device contracts that have this dip's minor node as resource */
256 262 kmutex_t devi_ct_lock; /* contract lock */
257 263 kcondvar_t devi_ct_cv; /* contract cv */
258 264 int devi_ct_count; /* # of outstanding responses */
259 265 int devi_ct_neg; /* neg. occurred on dip */
260 266 list_t devi_ct;
261 267
262 268 /* owned by bus framework */
263 269 devi_bus_priv_t devi_bus; /* bus private data */
264 270
265 271 /* Declarations of the pure dynamic properties to snapshot */
266 272 struct i_ddi_prop_dyn *devi_prop_dyn_driver; /* prop_op */
267 273 struct i_ddi_prop_dyn *devi_prop_dyn_parent; /* bus_prop_op */
268 274
269 275 #if defined(__x86)
270 276 /* For x86 (Intel and AMD) IOMMU support */
271 277 void *devi_iommu;
272 278 iommulib_handle_t devi_iommulib_handle;
273 279 iommulib_nexhandle_t devi_iommulib_nex_handle;
274 280 #endif
275 281
276 282 /* Generic callback mechanism */
277 283 ddi_cb_t *devi_cb_p;
278 284
279 285 /* ndi 'flavors' */
280 286 ndi_flavor_t devi_flavor; /* flavor assigned by parent */
281 287 ndi_flavor_t devi_flavorv_n; /* number of child-flavors */
282 288 void **devi_flavorv; /* child-flavor specific data */
283 289
284 290 /* Owned by hotplug framework */
285 291 struct ddi_hp_cn_handle *devi_hp_hdlp; /* hotplug handle list */
286 292
287 293 struct in_node *devi_in_node; /* pointer to devinfo node's in_node_t */
288 294
289 295 /* detach event data */
290 296 char *devi_ev_path;
291 297 int devi_ev_instance;
292 298 };
293 299
294 300 #define DEVI(dev_info_type) ((struct dev_info *)(dev_info_type))
295 301
296 302 /*
297 303 * NB: The 'name' field, for compatibility with old code (both existing
298 304 * device drivers and userland code), is now defined as the name used
299 305 * to bind the node to a device driver, and not the device node name.
300 306 * If the device node name does not define a binding to a device driver,
301 307 * and the framework uses a different algorithm to create the binding to
302 308 * the driver, the node name and binding name will be different.
303 309 *
304 310 * Note that this implies that the node name plus instance number does
305 311 * NOT create a unique driver id; only the binding name plus instance
306 312 * number creates a unique driver id.
307 313 *
308 314 * New code should not use 'devi_name'; use 'devi_binding_name' or
309 315 * 'devi_node_name' and/or the routines that access those fields.
310 316 */
311 317
312 318 #define devi_name devi_binding_name
313 319
314 320 /*
315 321 * DDI_CF1, DDI_CF2 and DDI_DRV_UNLOADED are obsolete. They are kept
316 322 * around to allow legacy drivers to to compile.
317 323 */
318 324 #define DDI_CF1(devi) (DEVI(devi)->devi_addr != NULL)
319 325 #define DDI_CF2(devi) (DEVI(devi)->devi_ops != NULL)
320 326 #define DDI_DRV_UNLOADED(devi) (DEVI(devi)->devi_ops == &mod_nodev_ops)
321 327
322 328 /*
323 329 * The device state flags (devi_state) contains information regarding
324 330 * the state of the device (Online/Offline/Down). For bus nexus
325 331 * devices, the device state also contains state information regarding
326 332 * the state of the bus represented by this nexus node.
327 333 *
328 334 * Device state information is stored in bits [0-7], bus state in bits
329 335 * [8-15].
330 336 *
331 337 * NOTE: all devi_state updates should be protected by devi_lock.
332 338 */
333 339 #define DEVI_DEVICE_OFFLINE 0x00000001
334 340 #define DEVI_DEVICE_DOWN 0x00000002
335 341 #define DEVI_DEVICE_DEGRADED 0x00000004
336 342 #define DEVI_DEVICE_REMOVED 0x00000008 /* hardware removed */
337 343
338 344 #define DEVI_BUS_QUIESCED 0x00000100
339 345 #define DEVI_BUS_DOWN 0x00000200
340 346 #define DEVI_NDI_CONFIG 0x00000400 /* perform config when attaching */
341 347
342 348 #define DEVI_S_ATTACHING 0x00010000
343 349 #define DEVI_S_DETACHING 0x00020000
344 350 #define DEVI_S_ONLINING 0x00040000
345 351 #define DEVI_S_OFFLINING 0x00080000
346 352
347 353 #define DEVI_S_INVOKING_DACF 0x00100000 /* busy invoking a dacf task */
348 354
349 355 #define DEVI_S_UNBOUND 0x00200000
350 356 #define DEVI_S_REPORT 0x08000000 /* report status change */
351 357
352 358 #define DEVI_S_EVADD 0x10000000 /* state of devfs event */
353 359 #define DEVI_S_EVREMOVE 0x20000000 /* state of devfs event */
354 360 #define DEVI_S_NEED_RESET 0x40000000 /* devo_reset should be called */
355 361
356 362 /*
357 363 * Device state macros.
358 364 * o All SET/CLR/DONE users must protect context with devi_lock.
359 365 * o DEVI_SET_DEVICE_ONLINE users must do their own DEVI_SET_REPORT.
360 366 * o DEVI_SET_DEVICE_{DOWN|DEGRADED|UP} should only be used when !OFFLINE.
361 367 * o DEVI_SET_DEVICE_UP clears DOWN and DEGRADED.
362 368 */
363 369 #define DEVI_IS_DEVICE_OFFLINE(dip) \
364 370 ((DEVI(dip)->devi_state & DEVI_DEVICE_OFFLINE) == DEVI_DEVICE_OFFLINE)
365 371
366 372 #define DEVI_SET_DEVICE_ONLINE(dip) { \
367 373 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
368 374 if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) { \
369 375 mutex_exit(&DEVI(dip)->devi_lock); \
370 376 e_ddi_undegrade_finalize(dip); \
371 377 mutex_enter(&DEVI(dip)->devi_lock); \
372 378 } \
373 379 /* setting ONLINE clears DOWN, DEGRADED, OFFLINE */ \
374 380 DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DOWN | \
375 381 DEVI_DEVICE_DEGRADED | DEVI_DEVICE_OFFLINE); \
376 382 }
377 383
378 384 #define DEVI_SET_DEVICE_OFFLINE(dip) { \
379 385 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
380 386 DEVI(dip)->devi_state |= (DEVI_DEVICE_OFFLINE | DEVI_S_REPORT); \
381 387 }
382 388
383 389 #define DEVI_IS_DEVICE_DOWN(dip) \
384 390 ((DEVI(dip)->devi_state & DEVI_DEVICE_DOWN) == DEVI_DEVICE_DOWN)
385 391
386 392 #define DEVI_SET_DEVICE_DOWN(dip) { \
387 393 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
388 394 ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip)); \
389 395 DEVI(dip)->devi_state |= (DEVI_DEVICE_DOWN | DEVI_S_REPORT); \
390 396 }
391 397
392 398 #define DEVI_IS_DEVICE_DEGRADED(dip) \
393 399 ((DEVI(dip)->devi_state & \
394 400 (DEVI_DEVICE_DEGRADED|DEVI_DEVICE_DOWN)) == DEVI_DEVICE_DEGRADED)
395 401
396 402 #define DEVI_SET_DEVICE_DEGRADED(dip) { \
397 403 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
398 404 ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip)); \
399 405 mutex_exit(&DEVI(dip)->devi_lock); \
400 406 e_ddi_degrade_finalize(dip); \
401 407 mutex_enter(&DEVI(dip)->devi_lock); \
402 408 DEVI(dip)->devi_state |= (DEVI_DEVICE_DEGRADED | DEVI_S_REPORT); \
403 409 }
404 410
405 411 #define DEVI_SET_DEVICE_UP(dip) { \
406 412 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
407 413 ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip)); \
408 414 if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) { \
409 415 mutex_exit(&DEVI(dip)->devi_lock); \
410 416 e_ddi_undegrade_finalize(dip); \
411 417 mutex_enter(&DEVI(dip)->devi_lock); \
412 418 } \
413 419 DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DEGRADED | DEVI_DEVICE_DOWN); \
414 420 DEVI(dip)->devi_state |= DEVI_S_REPORT; \
415 421 }
416 422
417 423 /* Device removal and insertion */
418 424 #define DEVI_IS_DEVICE_REMOVED(dip) \
419 425 ((DEVI(dip)->devi_state & DEVI_DEVICE_REMOVED) == DEVI_DEVICE_REMOVED)
420 426
421 427 #define DEVI_SET_DEVICE_REMOVED(dip) { \
422 428 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
423 429 DEVI(dip)->devi_state |= DEVI_DEVICE_REMOVED | DEVI_S_REPORT; \
424 430 }
425 431
426 432 #define DEVI_SET_DEVICE_REINSERTED(dip) { \
427 433 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
428 434 DEVI(dip)->devi_state &= ~DEVI_DEVICE_REMOVED; \
429 435 DEVI(dip)->devi_state |= DEVI_S_REPORT; \
430 436 }
431 437
432 438 /* Bus state change macros */
433 439 #define DEVI_IS_BUS_QUIESCED(dip) \
434 440 ((DEVI(dip)->devi_state & DEVI_BUS_QUIESCED) == DEVI_BUS_QUIESCED)
435 441
436 442 #define DEVI_SET_BUS_ACTIVE(dip) { \
437 443 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
438 444 DEVI(dip)->devi_state &= ~DEVI_BUS_QUIESCED; \
439 445 DEVI(dip)->devi_state |= DEVI_S_REPORT; \
440 446 }
441 447
442 448 #define DEVI_SET_BUS_QUIESCE(dip) { \
443 449 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
444 450 DEVI(dip)->devi_state |= (DEVI_BUS_QUIESCED | DEVI_S_REPORT); \
445 451 }
446 452
447 453 #define DEVI_IS_BUS_DOWN(dip) \
448 454 ((DEVI(dip)->devi_state & DEVI_BUS_DOWN) == DEVI_BUS_DOWN)
449 455
450 456 #define DEVI_SET_BUS_UP(dip) { \
451 457 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
452 458 DEVI(dip)->devi_state &= ~DEVI_BUS_DOWN; \
453 459 DEVI(dip)->devi_state |= DEVI_S_REPORT; \
454 460 }
455 461
456 462 #define DEVI_SET_BUS_DOWN(dip) { \
457 463 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
458 464 DEVI(dip)->devi_state |= (DEVI_BUS_DOWN | DEVI_S_REPORT); \
459 465 }
460 466
461 467 /* Status change report needed */
462 468 #define DEVI_NEED_REPORT(dip) \
463 469 ((DEVI(dip)->devi_state & DEVI_S_REPORT) == DEVI_S_REPORT)
464 470
465 471 #define DEVI_SET_REPORT(dip) { \
466 472 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
467 473 DEVI(dip)->devi_state |= DEVI_S_REPORT; \
468 474 }
469 475
470 476 #define DEVI_REPORT_DONE(dip) { \
471 477 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
472 478 DEVI(dip)->devi_state &= ~DEVI_S_REPORT; \
473 479 }
474 480
475 481 /* Do an NDI_CONFIG for its children */
476 482 #define DEVI_NEED_NDI_CONFIG(dip) \
477 483 ((DEVI(dip)->devi_state & DEVI_NDI_CONFIG) == DEVI_NDI_CONFIG)
478 484
479 485 #define DEVI_SET_NDI_CONFIG(dip) { \
480 486 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
481 487 DEVI(dip)->devi_state |= DEVI_NDI_CONFIG; \
482 488 }
483 489
484 490 #define DEVI_CLR_NDI_CONFIG(dip) { \
485 491 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
486 492 DEVI(dip)->devi_state &= ~DEVI_NDI_CONFIG; \
487 493 }
488 494
489 495 /* Attaching or detaching state */
490 496 #define DEVI_IS_ATTACHING(dip) \
491 497 ((DEVI(dip)->devi_state & DEVI_S_ATTACHING) == DEVI_S_ATTACHING)
492 498
493 499 #define DEVI_SET_ATTACHING(dip) { \
494 500 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
495 501 DEVI(dip)->devi_state |= DEVI_S_ATTACHING; \
496 502 }
497 503
498 504 #define DEVI_CLR_ATTACHING(dip) { \
499 505 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
500 506 DEVI(dip)->devi_state &= ~DEVI_S_ATTACHING; \
501 507 }
502 508
503 509 #define DEVI_IS_DETACHING(dip) \
504 510 ((DEVI(dip)->devi_state & DEVI_S_DETACHING) == DEVI_S_DETACHING)
505 511
506 512 #define DEVI_SET_DETACHING(dip) { \
507 513 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
508 514 DEVI(dip)->devi_state |= DEVI_S_DETACHING; \
509 515 }
510 516
511 517 #define DEVI_CLR_DETACHING(dip) { \
512 518 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
513 519 DEVI(dip)->devi_state &= ~DEVI_S_DETACHING; \
514 520 }
515 521
516 522 /* Onlining or offlining state */
517 523 #define DEVI_IS_ONLINING(dip) \
518 524 ((DEVI(dip)->devi_state & DEVI_S_ONLINING) == DEVI_S_ONLINING)
519 525
520 526 #define DEVI_SET_ONLINING(dip) { \
521 527 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
522 528 DEVI(dip)->devi_state |= DEVI_S_ONLINING; \
523 529 }
524 530
525 531 #define DEVI_CLR_ONLINING(dip) { \
526 532 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
527 533 DEVI(dip)->devi_state &= ~DEVI_S_ONLINING; \
528 534 }
529 535
530 536 #define DEVI_IS_OFFLINING(dip) \
531 537 ((DEVI(dip)->devi_state & DEVI_S_OFFLINING) == DEVI_S_OFFLINING)
532 538
533 539 #define DEVI_SET_OFFLINING(dip) { \
534 540 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
535 541 DEVI(dip)->devi_state |= DEVI_S_OFFLINING; \
536 542 }
537 543
538 544 #define DEVI_CLR_OFFLINING(dip) { \
539 545 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
540 546 DEVI(dip)->devi_state &= ~DEVI_S_OFFLINING; \
541 547 }
542 548
543 549 #define DEVI_IS_IN_RECONFIG(dip) \
544 550 (DEVI(dip)->devi_state & (DEVI_S_OFFLINING | DEVI_S_ONLINING))
545 551
546 552 /* Busy invoking a dacf task against this node */
547 553 #define DEVI_IS_INVOKING_DACF(dip) \
548 554 ((DEVI(dip)->devi_state & DEVI_S_INVOKING_DACF) == DEVI_S_INVOKING_DACF)
549 555
550 556 #define DEVI_SET_INVOKING_DACF(dip) { \
551 557 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
552 558 DEVI(dip)->devi_state |= DEVI_S_INVOKING_DACF; \
553 559 }
554 560
555 561 #define DEVI_CLR_INVOKING_DACF(dip) { \
556 562 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
557 563 DEVI(dip)->devi_state &= ~DEVI_S_INVOKING_DACF; \
558 564 }
559 565
560 566 /* Events for add/remove */
561 567 #define DEVI_EVADD(dip) \
562 568 ((DEVI(dip)->devi_state & DEVI_S_EVADD) == DEVI_S_EVADD)
563 569
564 570 #define DEVI_SET_EVADD(dip) { \
565 571 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
566 572 DEVI(dip)->devi_state &= ~DEVI_S_EVREMOVE; \
567 573 DEVI(dip)->devi_state |= DEVI_S_EVADD; \
568 574 }
569 575
570 576 #define DEVI_EVREMOVE(dip) \
571 577 ((DEVI(dip)->devi_state & DEVI_S_EVREMOVE) == DEVI_S_EVREMOVE)
572 578
573 579 #define DEVI_SET_EVREMOVE(dip) { \
574 580 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
575 581 DEVI(dip)->devi_state &= ~DEVI_S_EVADD; \
576 582 DEVI(dip)->devi_state |= DEVI_S_EVREMOVE; \
577 583 }
578 584
579 585 #define DEVI_SET_EVUNINIT(dip) { \
580 586 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
581 587 DEVI(dip)->devi_state &= ~(DEVI_S_EVADD | DEVI_S_EVREMOVE); \
582 588 }
583 589
584 590 /* Need to call the devo_reset entry point for this device at shutdown */
585 591 #define DEVI_NEED_RESET(dip) \
586 592 ((DEVI(dip)->devi_state & DEVI_S_NEED_RESET) == DEVI_S_NEED_RESET)
587 593
588 594 #define DEVI_SET_NEED_RESET(dip) { \
589 595 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
590 596 DEVI(dip)->devi_state |= DEVI_S_NEED_RESET; \
591 597 }
592 598
593 599 #define DEVI_CLR_NEED_RESET(dip) { \
594 600 ASSERT(mutex_owned(&DEVI(dip)->devi_lock)); \
595 601 DEVI(dip)->devi_state &= ~DEVI_S_NEED_RESET; \
596 602 }
597 603
598 604 /*
599 605 * devi_flags bits
600 606 *
601 607 * NOTE: all devi_state updates should be protected by devi_lock.
602 608 */
603 609 #define DEVI_BUSY 0x00000001 /* busy configuring children */
604 610 #define DEVI_MADE_CHILDREN 0x00000002 /* children made from specs */
605 611 #define DEVI_ATTACHED_CHILDREN 0x00000004 /* attached all existing children */
606 612 #define DEVI_BRANCH_HELD 0x00000008 /* branch rooted at this dip held */
607 613 #define DEVI_NO_BIND 0x00000010 /* prevent driver binding */
608 614 #define DEVI_CACHED_DEVID 0x00000020 /* devid cached in devid cache */
609 615 #define DEVI_PHCI_SIGNALS_VHCI 0x00000040 /* pHCI ndi_devi_exit signals vHCI */
610 616 #define DEVI_REBIND 0x00000080 /* post initchild driver rebind */
611 617 #define DEVI_RETIRED 0x00000100 /* device is retired */
612 618 #define DEVI_RETIRING 0x00000200 /* being evaluated for retire */
613 619 #define DEVI_R_CONSTRAINT 0x00000400 /* constraints have been applied */
614 620 #define DEVI_R_BLOCKED 0x00000800 /* constraints block retire */
615 621 #define DEVI_CT_NOP 0x00001000 /* NOP contract event occurred */
616 622 #define DEVI_PCI_DEVICE 0x00002000 /* dip is PCI */
617 623
618 624 #define DEVI_BUSY_CHANGING(dip) (DEVI(dip)->devi_flags & DEVI_BUSY)
619 625 #define DEVI_BUSY_OWNED(dip) (DEVI_BUSY_CHANGING(dip) && \
620 626 ((DEVI(dip))->devi_busy_thread == curthread))
621 627
622 628 #define DEVI_IS_PCI(dip) (DEVI(dip)->devi_flags & DEVI_PCI_DEVICE)
623 629 #define DEVI_SET_PCI(dip) (DEVI(dip)->devi_flags |= (DEVI_PCI_DEVICE))
624 630
625 631 char *i_ddi_devi_class(dev_info_t *);
626 632 int i_ddi_set_devi_class(dev_info_t *, char *, int);
627 633
628 634 /*
629 635 * This structure represents one piece of bus space occupied by a given
630 636 * device. It is used in an array for devices with multiple address windows.
631 637 */
632 638 struct regspec {
633 639 uint_t regspec_bustype; /* cookie for bus type it's on */
634 640 uint_t regspec_addr; /* address of reg relative to bus */
635 641 uint_t regspec_size; /* size of this register set */
636 642 };
637 643
638 644 /*
639 645 * This is a version of the above structure that works for 64-bit mappings and
640 646 * doesn't rely on overloading of fields as is done on SPARC. Eventually the
641 647 * struct regspec should be replaced with this.
642 648 */
643 649 struct regspec64 {
644 650 uint64_t regspec_bustype; /* cookie for bus type it's on */
645 651 uint64_t regspec_addr; /* address of reg relative to bus */
646 652 uint64_t regspec_size; /* size of this register set */
647 653 };
648 654
649 655 /*
650 656 * This structure represents one piece of nexus bus space.
651 657 * It is used in an array for nexi with multiple bus spaces
652 658 * to define the childs offsets in the parents bus space.
653 659 */
654 660 struct rangespec {
655 661 uint_t rng_cbustype; /* Child's address, hi order */
656 662 uint_t rng_coffset; /* Child's address, lo order */
657 663 uint_t rng_bustype; /* Parent's address, hi order */
658 664 uint_t rng_offset; /* Parent's address, lo order */
659 665 uint_t rng_size; /* size of space for this entry */
660 666 };
661 667
662 668 #ifdef _KERNEL
663 669
664 670 typedef enum {
665 671 DDI_PRE = 0,
666 672 DDI_POST = 1
667 673 } ddi_pre_post_t;
668 674
669 675 /*
670 676 * This structure represents notification of a child attach event
671 677 * These could both be the same if attach/detach commands were in the
672 678 * same name space.
673 679 * Note that the target dip is passed as an arg already.
674 680 */
675 681 struct attachspec {
676 682 ddi_attach_cmd_t cmd; /* type of event */
677 683 ddi_pre_post_t when; /* one of DDI_PRE or DDI_POST */
678 684 dev_info_t *pdip; /* parent of attaching node */
679 685 int result; /* result of attach op (post command only) */
680 686 };
681 687
682 688 /*
683 689 * This structure represents notification of a child detach event
684 690 * Note that the target dip is passed as an arg already.
685 691 */
686 692 struct detachspec {
687 693 ddi_detach_cmd_t cmd; /* type of event */
688 694 ddi_pre_post_t when; /* one of DDI_PRE or DDI_POST */
689 695 dev_info_t *pdip; /* parent of detaching node */
690 696 int result; /* result of detach op (post command only) */
691 697 };
692 698
693 699 #endif /* _KERNEL */
694 700
695 701 typedef enum {
696 702 DDM_MINOR = 0,
697 703 DDM_ALIAS,
698 704 DDM_DEFAULT,
699 705 DDM_INTERNAL_PATH
700 706 } ddi_minor_type;
701 707
702 708 /* implementation flags for driver specified device access control */
703 709 #define DM_NO_FSPERM 0x1
704 710
705 711 struct devplcy;
706 712
707 713 struct ddi_minor {
708 714 char *name; /* name of node */
709 715 dev_t dev; /* device number */
710 716 int spec_type; /* block or char */
711 717 int flags; /* access flags */
712 718 char *node_type; /* block, byte, serial, network */
713 719 struct devplcy *node_priv; /* privilege for this minor */
714 720 mode_t priv_mode; /* default apparent privilege mode */
715 721 };
716 722
717 723 /*
718 724 * devi_node_attributes contains node attributes private to the
719 725 * ddi implementation. As a consumer, do not use these bit definitions
720 726 * directly, use the ndi functions that check for the existence of the
721 727 * specific node attributes.
722 728 *
723 729 * DDI_PERSISTENT indicates a 'persistent' node; one that is not
724 730 * automatically freed by the framework if the driver is unloaded
725 731 * or the driver fails to attach to this node.
726 732 *
727 733 * DDI_AUTO_ASSIGNED_NODEID indicates that the nodeid was auto-assigned
728 734 * by the framework and should be auto-freed if the node is removed.
729 735 *
730 736 * DDI_VHCI_NODE indicates that the node type is VHCI. This flag
731 737 * must be set by ndi_devi_config_vhci() routine only.
732 738 *
733 739 * DDI_HIDDEN_NODE indicates that the node should not show up in snapshots
734 740 * or in /devices.
735 741 *
736 742 * DDI_HOTPLUG_NODE indicates that the node created by nexus hotplug.
737 743 */
738 744 #define DDI_PERSISTENT 0x01
739 745 #define DDI_AUTO_ASSIGNED_NODEID 0x02
740 746 #define DDI_VHCI_NODE 0x04
741 747 #define DDI_HIDDEN_NODE 0x08
742 748 #define DDI_HOTPLUG_NODE 0x10
743 749
744 750 #define DEVI_VHCI_NODE(dip) \
745 751 (DEVI(dip)->devi_node_attributes & DDI_VHCI_NODE)
746 752
747 753 /*
748 754 * The ddi_minor_data structure gets filled in by ddi_create_minor_node.
749 755 * It then gets attached to the devinfo node as a property.
750 756 */
751 757 struct ddi_minor_data {
752 758 struct ddi_minor_data *next; /* next one in the chain */
753 759 dev_info_t *dip; /* pointer to devinfo node */
754 760 ddi_minor_type type; /* Following data type */
755 761 struct ddi_minor d_minor; /* Actual minor node data */
756 762 };
757 763
758 764 #define ddm_name d_minor.name
759 765 #define ddm_dev d_minor.dev
760 766 #define ddm_flags d_minor.flags
761 767 #define ddm_spec_type d_minor.spec_type
762 768 #define ddm_node_type d_minor.node_type
763 769 #define ddm_node_priv d_minor.node_priv
764 770 #define ddm_priv_mode d_minor.priv_mode
765 771
766 772 /*
767 773 * parent private data structure contains register, interrupt, property
768 774 * and range information.
769 775 */
770 776 struct ddi_parent_private_data {
771 777 int par_nreg; /* number of regs */
772 778 struct regspec *par_reg; /* array of regs */
773 779 int par_nintr; /* number of interrupts */
774 780 struct intrspec *par_intr; /* array of possible interrupts */
775 781 int par_nrng; /* number of ranges */
776 782 struct rangespec *par_rng; /* array of ranges */
777 783 };
778 784 #define DEVI_PD(d) \
779 785 ((struct ddi_parent_private_data *)DEVI((d))->devi_parent_data)
780 786
781 787 #define sparc_pd_getnreg(dev) (DEVI_PD(dev)->par_nreg)
782 788 #define sparc_pd_getnintr(dev) (DEVI_PD(dev)->par_nintr)
783 789 #define sparc_pd_getnrng(dev) (DEVI_PD(dev)->par_nrng)
784 790 #define sparc_pd_getreg(dev, n) (&DEVI_PD(dev)->par_reg[(n)])
785 791 #define sparc_pd_getintr(dev, n) (&DEVI_PD(dev)->par_intr[(n)])
786 792 #define sparc_pd_getrng(dev, n) (&DEVI_PD(dev)->par_rng[(n)])
787 793
788 794 #ifdef _KERNEL
789 795 /*
790 796 * This data structure is private to the indexed soft state allocator.
791 797 */
792 798 typedef struct i_ddi_soft_state {
793 799 void **array; /* the array of pointers */
794 800 kmutex_t lock; /* serialize access to this struct */
795 801 size_t size; /* how many bytes per state struct */
796 802 size_t n_items; /* how many structs herein */
797 803 struct i_ddi_soft_state *next; /* 'dirty' elements */
798 804 } i_ddi_soft_state;
799 805
800 806 /*
801 807 * This data structure is private to the stringhashed soft state allocator.
802 808 */
803 809 typedef struct i_ddi_soft_state_bystr {
804 810 size_t ss_size; /* how many bytes per state struct */
805 811 mod_hash_t *ss_mod_hash; /* hash implementation */
806 812 } i_ddi_soft_state_bystr;
807 813
808 814 /*
809 815 * This data structure is private to the ddi_strid_* implementation
810 816 */
811 817 typedef struct i_ddi_strid {
812 818 size_t strid_chunksz;
813 819 size_t strid_spacesz;
814 820 id_space_t *strid_space;
815 821 mod_hash_t *strid_byid;
816 822 mod_hash_t *strid_bystr;
817 823 } i_ddi_strid;
818 824 #endif /* _KERNEL */
819 825
820 826 /*
821 827 * Solaris DDI DMA implementation structure and function definitions.
822 828 *
823 829 * Note: no callers of DDI functions must depend upon data structures
824 830 * declared below. They are not guaranteed to remain constant.
825 831 */
826 832
827 833 /*
828 834 * Implementation DMA mapping structure.
829 835 *
830 836 * The publicly visible ddi_dma_req structure is filled
831 837 * in by a caller that wishes to map a memory object
832 838 * for DMA. Internal to this implementation of the public
833 839 * DDI DMA functions this request structure is put together
834 840 * with bus nexus specific functions that have additional
835 841 * information and constraints as to how to go about doing
836 842 * the requested mapping function
837 843 *
838 844 * In this implementation, some of the information from the
839 845 * original requester is retained throughout the lifetime
840 846 * of the I/O mapping being active.
841 847 */
842 848
843 849 /*
844 850 * This is the implementation specific description
845 851 * of how we've mapped an object for DMA.
846 852 */
847 853 #if defined(__sparc)
848 854 typedef struct ddi_dma_impl {
849 855 /*
850 856 * DMA mapping information
851 857 */
852 858 ulong_t dmai_mapping; /* mapping cookie */
853 859
854 860 /*
855 861 * Size of the current mapping, in bytes.
856 862 *
857 863 * Note that this is distinct from the size of the object being mapped
858 864 * for DVMA. We might have only a portion of the object mapped at any
859 865 * given point in time.
860 866 */
861 867 uint_t dmai_size;
862 868
863 869 /*
864 870 * Offset, in bytes, into object that is currently mapped.
865 871 */
866 872 off_t dmai_offset;
867 873
868 874 /*
869 875 * Information gathered from the original DMA mapping
870 876 * request and saved for the lifetime of the mapping.
871 877 */
872 878 uint_t dmai_minxfer;
873 879 uint_t dmai_burstsizes;
874 880 uint_t dmai_ndvmapages;
875 881 uint_t dmai_pool; /* cached DVMA space */
876 882 uint_t dmai_rflags; /* requester's flags + ours */
877 883 uint_t dmai_inuse; /* active handle? */
878 884 uint_t dmai_nwin;
879 885 uint_t dmai_winsize;
880 886 caddr_t dmai_nexus_private;
881 887 void *dmai_iopte;
882 888 uint_t *dmai_sbi;
883 889 void *dmai_minfo; /* random mapping information */
884 890 dev_info_t *dmai_rdip; /* original requester's dev_info_t */
885 891 ddi_dma_obj_t dmai_object; /* requester's object */
886 892 ddi_dma_attr_t dmai_attr; /* DMA attributes */
887 893 ddi_dma_cookie_t *dmai_cookie; /* pointer to first DMA cookie */
888 894
889 895 int (*dmai_fault_check)(struct ddi_dma_impl *handle);
890 896 void (*dmai_fault_notify)(struct ddi_dma_impl *handle);
891 897 int dmai_fault;
892 898 ndi_err_t dmai_error;
893 899
894 900 } ddi_dma_impl_t;
895 901
896 902 #elif defined(__x86)
897 903
898 904 /*
899 905 * ddi_dma_impl portion that genunix (sunddi.c) depends on. x86 rootnex
900 906 * implementation specific state is in dmai_private.
901 907 */
902 908 typedef struct ddi_dma_impl {
903 909 ddi_dma_cookie_t *dmai_cookie; /* array of DMA cookies */
904 910 void *dmai_private;
905 911
906 912 /*
907 913 * Information gathered from the original dma mapping
908 914 * request and saved for the lifetime of the mapping.
909 915 */
910 916 uint_t dmai_minxfer;
911 917 uint_t dmai_burstsizes;
912 918 uint_t dmai_rflags; /* requester's flags + ours */
913 919 int dmai_nwin;
914 920 dev_info_t *dmai_rdip; /* original requester's dev_info_t */
915 921
916 922 ddi_dma_attr_t dmai_attr; /* DMA attributes */
917 923
918 924 int (*dmai_fault_check)(struct ddi_dma_impl *handle);
919 925 void (*dmai_fault_notify)(struct ddi_dma_impl *handle);
920 926 int dmai_fault;
921 927 ndi_err_t dmai_error;
922 928 } ddi_dma_impl_t;
923 929
924 930 #else
925 931 #error "struct ddi_dma_impl not defined for this architecture"
926 932 #endif /* defined(__sparc) */
927 933
928 934 /*
929 935 * For now DMA segments share state with the DMA handle
930 936 */
931 937 typedef ddi_dma_impl_t ddi_dma_seg_impl_t;
932 938
933 939 /*
934 940 * These flags use reserved bits from the dma request flags.
935 941 *
936 942 * A note about the DMP_NOSYNC flags: the root nexus will
937 943 * set these as it sees best. If an intermediate nexus
938 944 * actually needs these operations, then during the unwind
939 945 * from the call to ddi_dma_bind, the nexus driver *must*
940 946 * clear the appropriate flag(s). This is because, as an
941 947 * optimization, ddi_dma_sync(9F) looks at these flags before
942 948 * deciding to spend the time going back up the tree.
943 949 */
944 950
945 951 #define _DMCM1 DDI_DMA_RDWR|DDI_DMA_REDZONE|DDI_DMA_PARTIAL
946 952 #define _DMCM2 DDI_DMA_CONSISTENT|DMP_VMEREQ
947 953 #define DMP_DDIFLAGS (_DMCM1|_DMCM2)
948 954 #define DMP_SHADOW 0x20
949 955 #define DMP_LKIOPB 0x40
950 956 #define DMP_LKSYSV 0x80
951 957 #define DMP_IOCACHE 0x100
952 958 #define DMP_USEHAT 0x200
953 959 #define DMP_PHYSADDR 0x400
954 960 #define DMP_INVALID 0x800
955 961 #define DMP_NOLIMIT 0x1000
956 962 #define DMP_VMEREQ 0x10000000
957 963 #define DMP_BYPASSNEXUS 0x20000000
958 964 #define DMP_NODEVSYNC 0x40000000
959 965 #define DMP_NOCPUSYNC 0x80000000
960 966 #define DMP_NOSYNC (DMP_NODEVSYNC|DMP_NOCPUSYNC)
961 967
962 968 /*
963 969 * In order to complete a device to device mapping that
964 970 * has percolated as high as an IU nexus (gone that high
965 971 * because the DMA request is a VADDR type), we define
966 972 * structure to use with the DDI_CTLOPS_DMAPMAPC request
967 973 * that re-traverses the request tree to finish the
968 974 * DMA 'mapping' for a device.
969 975 */
970 976 struct dma_phys_mapc {
971 977 struct ddi_dma_req *dma_req; /* original request */
972 978 ddi_dma_impl_t *mp; /* current handle, or none */
973 979 int nptes; /* number of ptes */
974 980 void *ptes; /* ptes already read */
975 981 };
976 982
977 983 #define MAXCALLBACK 20
978 984
979 985 /*
980 986 * Callback definitions
981 987 */
982 988 struct ddi_callback {
983 989 struct ddi_callback *c_nfree;
984 990 struct ddi_callback *c_nlist;
985 991 int (*c_call)();
986 992 int c_count;
987 993 caddr_t c_arg;
988 994 size_t c_size;
989 995 };
990 996
991 997 /*
992 998 * Pure dynamic property declaration. A pure dynamic property is a property
993 999 * for which a driver's prop_op(9E) implementation will return a value on
994 1000 * demand, but the property name does not exist on a property list (global,
995 1001 * driver, system, or hardware) - the person asking for the value must know
996 1002 * the name and type information.
997 1003 *
998 1004 * For a pure dynamic property to show up in a di_init() devinfo shapshot, the
999 1005 * devinfo driver must know name and type. The i_ddi_prop_dyn_t mechanism
1000 1006 * allows a driver to define an array of the name/type information of its
1001 1007 * dynamic properties. When a driver declares its dynamic properties in a
1002 1008 * i_ddi_prop_dyn_t array, and registers that array using
1003 1009 * i_ddi_prop_dyn_driver_set() the devinfo driver has sufficient information
1004 1010 * to represent the properties in a snapshot - calling the driver's
1005 1011 * prop_op(9E) to obtain values.
1006 1012 *
1007 1013 * The last element of a i_ddi_prop_dyn_t is detected via a NULL dp_name value.
1008 1014 *
1009 1015 * A pure dynamic property name associated with a minor_node/dev_t should be
1010 1016 * defined with a dp_spec_type of S_IFCHR or S_IFBLK, as appropriate. The
1011 1017 * driver's prop_op(9E) entry point will be called for all
1012 1018 * ddi_create_minor_node(9F) nodes of the specified spec_type. For a driver
1013 1019 * where not all minor_node/dev_t combinations support the same named
1014 1020 * properties, it is the responsibility of the prop_op(9E) implementation to
1015 1021 * sort out what combinations are appropriate.
1016 1022 *
1017 1023 * A pure dynamic property of a devinfo node should be defined with a
1018 1024 * dp_spec_type of 0.
1019 1025 *
1020 1026 * NB: Public DDI property interfaces no longer support pure dynamic
1021 1027 * properties, but they are still still used. A prime example is the cmlb
1022 1028 * implementation of size(9P) properties. Using pure dynamic properties
1023 1029 * reduces the space required to maintain per-partition information. Since
1024 1030 * there are no public interfaces to create pure dynamic properties,
1025 1031 * the i_ddi_prop_dyn_t mechanism should remain private.
1026 1032 */
1027 1033 typedef struct i_ddi_prop_dyn {
1028 1034 char *dp_name; /* name of dynamic property */
1029 1035 int dp_type; /* DDI_PROP_TYPE_ of property */
1030 1036 int dp_spec_type; /* 0, S_IFCHR, S_IFBLK */
1031 1037 } i_ddi_prop_dyn_t;
1032 1038 void i_ddi_prop_dyn_driver_set(dev_info_t *,
1033 1039 i_ddi_prop_dyn_t *);
1034 1040 i_ddi_prop_dyn_t *i_ddi_prop_dyn_driver_get(dev_info_t *);
1035 1041 void i_ddi_prop_dyn_parent_set(dev_info_t *,
1036 1042 i_ddi_prop_dyn_t *);
1037 1043 i_ddi_prop_dyn_t *i_ddi_prop_dyn_parent_get(dev_info_t *);
1038 1044 void i_ddi_prop_dyn_cache_invalidate(dev_info_t *,
1039 1045 i_ddi_prop_dyn_t *);
1040 1046
1041 1047 /*
1042 1048 * Device id - Internal definition.
1043 1049 */
1044 1050 #define DEVID_MAGIC_MSB 0x69
1045 1051 #define DEVID_MAGIC_LSB 0x64
1046 1052 #define DEVID_REV_MSB 0x00
1047 1053 #define DEVID_REV_LSB 0x01
1048 1054 #define DEVID_HINT_SIZE 4
1049 1055
1050 1056 typedef struct impl_devid {
1051 1057 uchar_t did_magic_hi; /* device id magic # (msb) */
1052 1058 uchar_t did_magic_lo; /* device id magic # (lsb) */
1053 1059 uchar_t did_rev_hi; /* device id revision # (msb) */
1054 1060 uchar_t did_rev_lo; /* device id revision # (lsb) */
1055 1061 uchar_t did_type_hi; /* device id type (msb) */
1056 1062 uchar_t did_type_lo; /* device id type (lsb) */
1057 1063 uchar_t did_len_hi; /* length of devid data (msb) */
1058 1064 uchar_t did_len_lo; /* length of devid data (lsb) */
1059 1065 char did_driver[DEVID_HINT_SIZE]; /* driver name - HINT */
1060 1066 char did_id[1]; /* start of device id data */
1061 1067 } impl_devid_t;
1062 1068
1063 1069 #define DEVID_GETTYPE(devid) ((ushort_t) \
1064 1070 (((devid)->did_type_hi << NBBY) + \
1065 1071 (devid)->did_type_lo))
1066 1072
1067 1073 #define DEVID_FORMTYPE(devid, type) (devid)->did_type_hi = hibyte((type)); \
1068 1074 (devid)->did_type_lo = lobyte((type));
1069 1075
1070 1076 #define DEVID_GETLEN(devid) ((ushort_t) \
1071 1077 (((devid)->did_len_hi << NBBY) + \
1072 1078 (devid)->did_len_lo))
1073 1079
1074 1080 #define DEVID_FORMLEN(devid, len) (devid)->did_len_hi = hibyte((len)); \
1075 1081 (devid)->did_len_lo = lobyte((len));
1076 1082
1077 1083 /*
1078 1084 * Per PSARC/1995/352, a binary devid contains fields for <magic number>,
1079 1085 * <revision>, <driver_hint>, <type>, <id_length>, and the <id> itself.
1080 1086 * This proposal would encode the binary devid into a string consisting
1081 1087 * of "<magic><revision>,<driver_hint>@<type><id>" as indicated below
1082 1088 * (<id_length> is rederived from the length of the string
1083 1089 * representation of the <id>):
1084 1090 *
1085 1091 * <magic> ->"id"
1086 1092 *
1087 1093 * <rev> ->"%d" // "0" -> type of DEVID_NONE "id0"
1088 1094 * // NOTE: PSARC/1995/352 <revision> is "1".
1089 1095 * // NOTE: support limited to 10 revisions
1090 1096 * // in current implementation
1091 1097 *
1092 1098 * <driver_hint> ->"%s" // "sd"/"ssd"
1093 1099 * // NOTE: driver names limited to 4
1094 1100 * // characters for <revision> "1"
1095 1101 *
1096 1102 * <type> ->'w' | // DEVID_SCSI3_WWN <hex_id>
1097 1103 * 'W' | // DEVID_SCSI3_WWN <ascii_id>
1098 1104 * 't' | // DEVID_SCSI3_VPD_T10 <hex_id>
1099 1105 * 'T' | // DEVID_SCSI3_VPD_T10 <ascii_id>
1100 1106 * 'x' | // DEVID_SCSI3_VPD_EUI <hex_id>
1101 1107 * 'X' | // DEVID_SCSI3_VPD_EUI <ascii_id>
1102 1108 * 'n' | // DEVID_SCSI3_VPD_NAA <hex_id>
1103 1109 * 'N' | // DEVID_SCSI3_VPD_NAA <ascii_id>
1104 1110 * 's' | // DEVID_SCSI_SERIAL <hex_id>
1105 1111 * 'S' | // DEVID_SCSI_SERIAL <ascii_id>
1106 1112 * 'f' | // DEVID_FAB <hex_id>
1107 1113 * 'F' | // DEVID_FAB <ascii_id>
1108 1114 * 'e' | // DEVID_ENCAP <hex_id>
1109 1115 * 'E' | // DEVID_ENCAP <ascii_id>
1110 1116 * 'a' | // DEVID_ATA_SERIAL <hex_id>
1111 1117 * 'A' | // DEVID_ATA_SERIAL <ascii_id>
1112 1118 * 'u' | // unknown <hex_id>
1113 1119 * 'U' // unknown <ascii_id>
1114 1120 * // NOTE:lower case -> <hex_id>
1115 1121 * // upper case -> <ascii_id>
1116 1122 * // NOTE:this covers all types currently
1117 1123 * // defined for <revision> 1.
1118 1124 * // NOTE:a <type> can be added
1119 1125 * // without changing the <revision>.
1120 1126 *
1121 1127 * <id> -> <ascii_id> | // <type> is upper case
1122 1128 * <hex_id> // <type> is lower case
1123 1129 *
1124 1130 * <ascii_id> // only if all bytes of binary <id> field
1125 1131 * // are in the set:
1126 1132 * // [A-Z][a-z][0-9]+-.= and space and 0x00
1127 1133 * // the encoded form is:
1128 1134 * // [A-Z][a-z][0-9]+-.= and _ and ~
1129 1135 * // NOTE: ' ' <=> '_', 0x00 <=> '~'
1130 1136 * // these sets are chosen to avoid shell
1131 1137 * // and conflicts with DDI node names.
1132 1138 *
1133 1139 * <hex_id> // if not <ascii_id>; each byte of binary
1134 1140 * // <id> maps a to 2 digit ascii hex
1135 1141 * // representation in the string.
1136 1142 *
1137 1143 * This encoding provides a meaningful correlation between the /devices
1138 1144 * path and the devid string where possible.
1139 1145 *
1140 1146 * Fibre:
1141 1147 * sbus@6,0/SUNW,socal@d,10000/sf@1,0/ssd@w21000020370bb488,0:c,raw
1142 1148 * id1,ssd@w20000020370bb488:c,raw
1143 1149 *
1144 1150 * Copper:
1145 1151 * sbus@7,0/SUNW,fas@3,8800000/sd@a,0:c
1146 1152 * id1,sd@SIBM_____1XY210__________:c
1147 1153 */
1148 1154 /* determine if a byte of an id meets ASCII representation requirements */
1149 1155 #define DEVID_IDBYTE_ISASCII(b) ( \
1150 1156 (((b) >= 'a') && ((b) <= 'z')) || \
1151 1157 (((b) >= 'A') && ((b) <= 'Z')) || \
1152 1158 (((b) >= '0') && ((b) <= '9')) || \
1153 1159 (b == '+') || (b == '-') || (b == '.') || (b == '=') || \
1154 1160 (b == ' ') || (b == 0x00))
1155 1161
1156 1162 /* set type to lower case to indicate that the did_id field is ascii */
1157 1163 #define DEVID_TYPE_SETASCII(c) (c - 0x20) /* 'a' -> 'A' */
1158 1164
1159 1165 /* determine from type if did_id field is binary or ascii */
1160 1166 #define DEVID_TYPE_ISASCII(c) (((c) >= 'A') && ((c) <= 'Z'))
1161 1167
1162 1168 /* convert type field from binary to ascii */
1163 1169 #define DEVID_TYPE_BINTOASCII(b) ( \
1164 1170 ((b) == DEVID_SCSI3_WWN) ? 'w' : \
1165 1171 ((b) == DEVID_SCSI3_VPD_T10) ? 't' : \
1166 1172 ((b) == DEVID_SCSI3_VPD_EUI) ? 'x' : \
1167 1173 ((b) == DEVID_SCSI3_VPD_NAA) ? 'n' : \
1168 1174 ((b) == DEVID_SCSI_SERIAL) ? 's' : \
1169 1175 ((b) == DEVID_FAB) ? 'f' : \
1170 1176 ((b) == DEVID_ENCAP) ? 'e' : \
1171 1177 ((b) == DEVID_ATA_SERIAL) ? 'a' : \
1172 1178 'u') /* unknown */
1173 1179
1174 1180 /* convert type field from ascii to binary */
1175 1181 #define DEVID_TYPE_ASCIITOBIN(c) ( \
1176 1182 (((c) == 'w') || ((c) == 'W')) ? DEVID_SCSI3_WWN : \
1177 1183 (((c) == 't') || ((c) == 'T')) ? DEVID_SCSI3_VPD_T10 : \
1178 1184 (((c) == 'x') || ((c) == 'X')) ? DEVID_SCSI3_VPD_EUI : \
1179 1185 (((c) == 'n') || ((c) == 'N')) ? DEVID_SCSI3_VPD_NAA : \
1180 1186 (((c) == 's') || ((c) == 'S')) ? DEVID_SCSI_SERIAL : \
1181 1187 (((c) == 'f') || ((c) == 'F')) ? DEVID_FAB : \
1182 1188 (((c) == 'e') || ((c) == 'E')) ? DEVID_ENCAP : \
1183 1189 (((c) == 'a') || ((c) == 'A')) ? DEVID_ATA_SERIAL : \
1184 1190 DEVID_MAXTYPE +1) /* unknown */
1185 1191
1186 1192 /* determine if the type should be forced to hex encoding (non-ascii) */
1187 1193 #define DEVID_TYPE_BIN_FORCEHEX(b) ( \
1188 1194 ((b) == DEVID_SCSI3_WWN) || \
1189 1195 ((b) == DEVID_SCSI3_VPD_EUI) || \
1190 1196 ((b) == DEVID_SCSI3_VPD_NAA) || \
1191 1197 ((b) == DEVID_FAB))
1192 1198
1193 1199 /* determine if the type is from a scsi3 vpd */
1194 1200 #define IS_DEVID_SCSI3_VPD_TYPE(b) ( \
1195 1201 ((b) == DEVID_SCSI3_VPD_T10) || \
1196 1202 ((b) == DEVID_SCSI3_VPD_EUI) || \
1197 1203 ((b) == DEVID_SCSI3_VPD_NAA))
1198 1204
1199 1205 /* convert rev field from binary to ascii (only supports 10 revs) */
1200 1206 #define DEVID_REV_BINTOASCII(b) (b + '0')
1201 1207
1202 1208 /* convert rev field from ascii to binary (only supports 10 revs) */
1203 1209 #define DEVID_REV_ASCIITOBIN(c) (c - '0')
1204 1210
1205 1211 /* name of devid property */
1206 1212 #define DEVID_PROP_NAME "devid"
1207 1213
1208 1214 /*
1209 1215 * prop_name used by pci_{save,restore}_config_regs()
1210 1216 */
1211 1217 #define SAVED_CONFIG_REGS "pci-config-regs"
1212 1218 #define SAVED_CONFIG_REGS_MASK "pcie-config-regs-mask"
1213 1219 #define SAVED_CONFIG_REGS_CAPINFO "pci-cap-info"
1214 1220
1215 1221 typedef struct pci_config_header_state {
1216 1222 uint16_t chs_command;
1217 1223 uint8_t chs_cache_line_size;
1218 1224 uint8_t chs_latency_timer;
1219 1225 uint8_t chs_header_type;
1220 1226 uint8_t chs_sec_latency_timer;
1221 1227 uint8_t chs_bridge_control;
1222 1228 uint32_t chs_base0;
1223 1229 uint32_t chs_base1;
1224 1230 uint32_t chs_base2;
1225 1231 uint32_t chs_base3;
1226 1232 uint32_t chs_base4;
1227 1233 uint32_t chs_base5;
1228 1234 } pci_config_header_state_t;
1229 1235
1230 1236 #ifdef _KERNEL
1231 1237
1232 1238 typedef struct pci_cap_save_desc {
1233 1239 uint16_t cap_offset;
1234 1240 uint16_t cap_id;
1235 1241 uint32_t cap_nregs;
1236 1242 } pci_cap_save_desc_t;
1237 1243
1238 1244 typedef struct pci_cap_entry {
1239 1245 uint16_t cap_id;
1240 1246 uint16_t cap_reg;
1241 1247 uint16_t cap_mask;
1242 1248 uint32_t cap_ndwords;
1243 1249 uint32_t (*cap_save_func)(ddi_acc_handle_t confhdl, uint16_t cap_ptr,
1244 1250 uint32_t *regbuf, uint32_t ndwords);
1245 1251 } pci_cap_entry_t;
1246 1252
1247 1253 #endif /* _KERNEL */
1248 1254
1249 1255 #ifdef __cplusplus
1250 1256 }
1251 1257 #endif
1252 1258
1253 1259 #endif /* _SYS_DDI_IMPLDEFS_H */
↓ open down ↓ |
1031 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX