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