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