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 #define DDI_PERSISTENT 0x01 693 #define DDI_AUTO_ASSIGNED_NODEID 0x02 694 #define DDI_VHCI_NODE 0x04 695 696 #define DEVI_VHCI_NODE(dip) \ 697 (DEVI(dip)->devi_node_attributes & DDI_VHCI_NODE) 698 699 /* 700 * The ddi_minor_data structure gets filled in by ddi_create_minor_node. 701 * It then gets attached to the devinfo node as a property. 702 */ 703 struct ddi_minor_data { 704 struct ddi_minor_data *next; /* next one in the chain */ 705 dev_info_t *dip; /* pointer to devinfo node */ 706 ddi_minor_type type; /* Following data type */ 707 struct ddi_minor d_minor; /* Actual minor node data */ 708 }; 709 710 #define ddm_name d_minor.name 711 #define ddm_dev d_minor.dev 712 #define ddm_flags d_minor.flags 713 #define ddm_spec_type d_minor.spec_type 714 #define ddm_node_type d_minor.node_type 715 #define ddm_node_priv d_minor.node_priv 716 #define ddm_priv_mode d_minor.priv_mode 717 718 /* 719 * parent private data structure contains register, interrupt, property 720 * and range information. 721 */ 722 struct ddi_parent_private_data { 723 int par_nreg; /* number of regs */ 724 struct regspec *par_reg; /* array of regs */ 725 int par_nintr; /* number of interrupts */ 726 struct intrspec *par_intr; /* array of possible interrupts */ 727 int par_nrng; /* number of ranges */ 728 struct rangespec *par_rng; /* array of ranges */ 729 }; 730 #define DEVI_PD(d) \ 731 ((struct ddi_parent_private_data *)DEVI((d))->devi_parent_data) 732 733 #define sparc_pd_getnreg(dev) (DEVI_PD(dev)->par_nreg) 734 #define sparc_pd_getnintr(dev) (DEVI_PD(dev)->par_nintr) 735 #define sparc_pd_getnrng(dev) (DEVI_PD(dev)->par_nrng) 736 #define sparc_pd_getreg(dev, n) (&DEVI_PD(dev)->par_reg[(n)]) 737 #define sparc_pd_getintr(dev, n) (&DEVI_PD(dev)->par_intr[(n)]) 738 #define sparc_pd_getrng(dev, n) (&DEVI_PD(dev)->par_rng[(n)]) 739 740 /* 741 * This data structure is entirely private to the soft state allocator. 742 */ 743 struct i_ddi_soft_state { 744 void **array; /* the array of pointers */ 745 kmutex_t lock; /* serialize access to this struct */ 746 size_t size; /* how many bytes per state struct */ 747 size_t n_items; /* how many structs herein */ 748 struct i_ddi_soft_state *next; /* 'dirty' elements */ 749 }; 750 751 /* 752 * Solaris DDI DMA implementation structure and function definitions. 753 * 754 * Note: no callers of DDI functions must depend upon data structures 755 * declared below. They are not guaranteed to remain constant. 756 */ 757 758 /* 759 * Implementation DMA mapping structure. 760 * 761 * The publicly visible ddi_dma_req structure is filled 762 * in by a caller that wishes to map a memory object 763 * for DMA. Internal to this implementation of the public 764 * DDI DMA functions this request structure is put together 765 * with bus nexus specific functions that have additional 766 * information and constraints as to how to go about doing 767 * the requested mapping function 768 * 769 * In this implementation, some of the information from the 770 * original requester is retained throughout the lifetime 771 * of the I/O mapping being active. 772 */ 773 774 /* 775 * This is the implementation specific description 776 * of how we've mapped an object for DMA. 777 */ 778 #if defined(__sparc) 779 typedef struct ddi_dma_impl { 780 /* 781 * DMA mapping information 782 */ 783 ulong_t dmai_mapping; /* mapping cookie */ 784 785 /* 786 * Size of the current mapping, in bytes. 787 * 788 * Note that this is distinct from the size of the object being mapped 789 * for DVMA. We might have only a portion of the object mapped at any 790 * given point in time. 791 */ 792 uint_t dmai_size; 793 794 /* 795 * Offset, in bytes, into object that is currently mapped. 796 */ 797 off_t dmai_offset; 798 799 /* 800 * Information gathered from the original DMA mapping 801 * request and saved for the lifetime of the mapping. 802 */ 803 uint_t dmai_minxfer; 804 uint_t dmai_burstsizes; 805 uint_t dmai_ndvmapages; 806 uint_t dmai_pool; /* cached DVMA space */ 807 uint_t dmai_rflags; /* requester's flags + ours */ 808 uint_t dmai_inuse; /* active handle? */ 809 uint_t dmai_nwin; 810 uint_t dmai_winsize; 811 caddr_t dmai_nexus_private; 812 void *dmai_iopte; 813 uint_t *dmai_sbi; 814 void *dmai_minfo; /* random mapping information */ 815 dev_info_t *dmai_rdip; /* original requester's dev_info_t */ 816 ddi_dma_obj_t dmai_object; /* requester's object */ 817 ddi_dma_attr_t dmai_attr; /* DMA attributes */ 818 ddi_dma_cookie_t *dmai_cookie; /* pointer to first DMA cookie */ 819 820 int (*dmai_fault_check)(struct ddi_dma_impl *handle); 821 void (*dmai_fault_notify)(struct ddi_dma_impl *handle); 822 int dmai_fault; 823 ndi_err_t dmai_error; 824 825 } ddi_dma_impl_t; 826 827 #elif defined(__x86) 828 829 /* 830 * ddi_dma_impl portion that genunix (sunddi.c) depends on. x86 rootnex 831 * implementation specific state is in dmai_private. 832 */ 833 typedef struct ddi_dma_impl { 834 ddi_dma_cookie_t *dmai_cookie; /* array of DMA cookies */ 835 void *dmai_private; 836 837 /* 838 * Information gathered from the original dma mapping 839 * request and saved for the lifetime of the mapping. 840 */ 841 uint_t dmai_minxfer; 842 uint_t dmai_burstsizes; 843 uint_t dmai_rflags; /* requester's flags + ours */ 844 int dmai_nwin; 845 dev_info_t *dmai_rdip; /* original requester's dev_info_t */ 846 847 ddi_dma_attr_t dmai_attr; /* DMA attributes */ 848 849 int (*dmai_fault_check)(struct ddi_dma_impl *handle); 850 void (*dmai_fault_notify)(struct ddi_dma_impl *handle); 851 int dmai_fault; 852 ndi_err_t dmai_error; 853 } ddi_dma_impl_t; 854 855 #else 856 #error "struct ddi_dma_impl not defined for this architecture" 857 #endif /* defined(__sparc) */ 858 859 /* 860 * For now DMA segments share state with the DMA handle 861 */ 862 typedef ddi_dma_impl_t ddi_dma_seg_impl_t; 863 864 /* 865 * These flags use reserved bits from the dma request flags. 866 * 867 * A note about the DMP_NOSYNC flags: the root nexus will 868 * set these as it sees best. If an intermediate nexus 869 * actually needs these operations, then during the unwind 870 * from the call to ddi_dma_bind, the nexus driver *must* 871 * clear the appropriate flag(s). This is because, as an 872 * optimization, ddi_dma_sync(9F) looks at these flags before 873 * deciding to spend the time going back up the tree. 874 */ 875 876 #define _DMCM1 DDI_DMA_RDWR|DDI_DMA_REDZONE|DDI_DMA_PARTIAL 877 #define _DMCM2 DDI_DMA_CONSISTENT|DMP_VMEREQ 878 #define DMP_DDIFLAGS (_DMCM1|_DMCM2) 879 #define DMP_SHADOW 0x20 880 #define DMP_LKIOPB 0x40 881 #define DMP_LKSYSV 0x80 882 #define DMP_IOCACHE 0x100 883 #define DMP_USEHAT 0x200 884 #define DMP_PHYSADDR 0x400 885 #define DMP_INVALID 0x800 886 #define DMP_NOLIMIT 0x1000 887 #define DMP_VMEREQ 0x10000000 888 #define DMP_BYPASSNEXUS 0x20000000 889 #define DMP_NODEVSYNC 0x40000000 890 #define DMP_NOCPUSYNC 0x80000000 891 #define DMP_NOSYNC (DMP_NODEVSYNC|DMP_NOCPUSYNC) 892 893 /* 894 * In order to complete a device to device mapping that 895 * has percolated as high as an IU nexus (gone that high 896 * because the DMA request is a VADDR type), we define 897 * structure to use with the DDI_CTLOPS_DMAPMAPC request 898 * that re-traverses the request tree to finish the 899 * DMA 'mapping' for a device. 900 */ 901 struct dma_phys_mapc { 902 struct ddi_dma_req *dma_req; /* original request */ 903 ddi_dma_impl_t *mp; /* current handle, or none */ 904 int nptes; /* number of ptes */ 905 void *ptes; /* ptes already read */ 906 }; 907 908 #define MAXCALLBACK 20 909 910 /* 911 * Callback definitions 912 */ 913 struct ddi_callback { 914 struct ddi_callback *c_nfree; 915 struct ddi_callback *c_nlist; 916 int (*c_call)(); 917 int c_count; 918 caddr_t c_arg; 919 size_t c_size; 920 }; 921 922 /* 923 * Pure dynamic property declaration. A pure dynamic property is a property 924 * for which a driver's prop_op(9E) implementation will return a value on 925 * demand, but the property name does not exist on a property list (global, 926 * driver, system, or hardware) - the person asking for the value must know 927 * the name and type information. 928 * 929 * For a pure dynamic property to show up in a di_init() devinfo shapshot, the 930 * devinfo driver must know name and type. The i_ddi_prop_dyn_t mechanism 931 * allows a driver to define an array of the name/type information of its 932 * dynamic properties. When a driver declares its dynamic properties in a 933 * i_ddi_prop_dyn_t array, and registers that array using 934 * i_ddi_prop_dyn_driver_set() the devinfo driver has sufficient information 935 * to represent the properties in a snapshot - calling the driver's 936 * prop_op(9E) to obtain values. 937 * 938 * The last element of a i_ddi_prop_dyn_t is detected via a NULL dp_name value. 939 * 940 * A pure dynamic property name associated with a minor_node/dev_t should be 941 * defined with a dp_spec_type of S_IFCHR or S_IFBLK, as appropriate. The 942 * driver's prop_op(9E) entry point will be called for all 943 * ddi_create_minor_node(9F) nodes of the specified spec_type. For a driver 944 * where not all minor_node/dev_t combinations support the same named 945 * properties, it is the responsibility of the prop_op(9E) implementation to 946 * sort out what combinations are appropriate. 947 * 948 * A pure dynamic property of a devinfo node should be defined with a 949 * dp_spec_type of 0. 950 * 951 * NB: Public DDI property interfaces no longer support pure dynamic 952 * properties, but they are still still used. A prime example is the cmlb 953 * implementation of size(9P) properties. Using pure dynamic properties 954 * reduces the space required to maintain per-partition information. Since 955 * there are no public interfaces to create pure dynamic properties, 956 * the i_ddi_prop_dyn_t mechanism should remain private. 957 */ 958 typedef struct i_ddi_prop_dyn { 959 char *dp_name; /* name of dynamic property */ 960 int dp_type; /* DDI_PROP_TYPE_ of property */ 961 int dp_spec_type; /* 0, S_IFCHR, S_IFBLK */ 962 } i_ddi_prop_dyn_t; 963 void i_ddi_prop_dyn_driver_set(dev_info_t *, 964 i_ddi_prop_dyn_t *); 965 i_ddi_prop_dyn_t *i_ddi_prop_dyn_driver_get(dev_info_t *); 966 void i_ddi_prop_dyn_parent_set(dev_info_t *, 967 i_ddi_prop_dyn_t *); 968 i_ddi_prop_dyn_t *i_ddi_prop_dyn_parent_get(dev_info_t *); 969 void i_ddi_prop_dyn_cache_invalidate(dev_info_t *, 970 i_ddi_prop_dyn_t *); 971 972 /* 973 * Device id - Internal definition. 974 */ 975 #define DEVID_MAGIC_MSB 0x69 976 #define DEVID_MAGIC_LSB 0x64 977 #define DEVID_REV_MSB 0x00 978 #define DEVID_REV_LSB 0x01 979 #define DEVID_HINT_SIZE 4 980 981 typedef struct impl_devid { 982 uchar_t did_magic_hi; /* device id magic # (msb) */ 983 uchar_t did_magic_lo; /* device id magic # (lsb) */ 984 uchar_t did_rev_hi; /* device id revision # (msb) */ 985 uchar_t did_rev_lo; /* device id revision # (lsb) */ 986 uchar_t did_type_hi; /* device id type (msb) */ 987 uchar_t did_type_lo; /* device id type (lsb) */ 988 uchar_t did_len_hi; /* length of devid data (msb) */ 989 uchar_t did_len_lo; /* length of devid data (lsb) */ 990 char did_driver[DEVID_HINT_SIZE]; /* driver name - HINT */ 991 char did_id[1]; /* start of device id data */ 992 } impl_devid_t; 993 994 #define DEVID_GETTYPE(devid) ((ushort_t) \ 995 (((devid)->did_type_hi << NBBY) + \ 996 (devid)->did_type_lo)) 997 998 #define DEVID_FORMTYPE(devid, type) (devid)->did_type_hi = hibyte((type)); \ 999 (devid)->did_type_lo = lobyte((type)); 1000 1001 #define DEVID_GETLEN(devid) ((ushort_t) \ 1002 (((devid)->did_len_hi << NBBY) + \ 1003 (devid)->did_len_lo)) 1004 1005 #define DEVID_FORMLEN(devid, len) (devid)->did_len_hi = hibyte((len)); \ 1006 (devid)->did_len_lo = lobyte((len)); 1007 1008 /* 1009 * Per PSARC/1995/352, a binary devid contains fields for <magic number>, 1010 * <revision>, <driver_hint>, <type>, <id_length>, and the <id> itself. 1011 * This proposal would encode the binary devid into a string consisting 1012 * of "<magic><revision>,<driver_hint>@<type><id>" as indicated below 1013 * (<id_length> is rederived from the length of the string 1014 * representation of the <id>): 1015 * 1016 * <magic> ->"id" 1017 * 1018 * <rev> ->"%d" // "0" -> type of DEVID_NONE "id0" 1019 * // NOTE: PSARC/1995/352 <revision> is "1". 1020 * // NOTE: support limited to 10 revisions 1021 * // in current implementation 1022 * 1023 * <driver_hint> ->"%s" // "sd"/"ssd" 1024 * // NOTE: driver names limited to 4 1025 * // characters for <revision> "1" 1026 * 1027 * <type> ->'w' | // DEVID_SCSI3_WWN <hex_id> 1028 * 'W' | // DEVID_SCSI3_WWN <ascii_id> 1029 * 't' | // DEVID_SCSI3_VPD_T10 <hex_id> 1030 * 'T' | // DEVID_SCSI3_VPD_T10 <ascii_id> 1031 * 'x' | // DEVID_SCSI3_VPD_EUI <hex_id> 1032 * 'X' | // DEVID_SCSI3_VPD_EUI <ascii_id> 1033 * 'n' | // DEVID_SCSI3_VPD_NAA <hex_id> 1034 * 'N' | // DEVID_SCSI3_VPD_NAA <ascii_id> 1035 * 's' | // DEVID_SCSI_SERIAL <hex_id> 1036 * 'S' | // DEVID_SCSI_SERIAL <ascii_id> 1037 * 'f' | // DEVID_FAB <hex_id> 1038 * 'F' | // DEVID_FAB <ascii_id> 1039 * 'e' | // DEVID_ENCAP <hex_id> 1040 * 'E' | // DEVID_ENCAP <ascii_id> 1041 * 'a' | // DEVID_ATA_SERIAL <hex_id> 1042 * 'A' | // DEVID_ATA_SERIAL <ascii_id> 1043 * 'u' | // unknown <hex_id> 1044 * 'U' // unknown <ascii_id> 1045 * // NOTE: lower case -> <hex_id> 1046 * // upper case -> <ascii_id> 1047 * // NOTE: this covers all types currently 1048 * // defined for <revision> 1. 1049 * // NOTE: a <type> can be added 1050 * // without changing the <revision>. 1051 * 1052 * <id> -> <ascii_id> | // <type> is upper case 1053 * <hex_id> // <type> is lower case 1054 * 1055 * <ascii_id> // only if all bytes of binary <id> field 1056 * // are in the set: 1057 * // [A-Z][a-z][0-9]+-.= and space and 0x00 1058 * // the encoded form is: 1059 * // [A-Z][a-z][0-9]+-.= and _ and ~ 1060 * // NOTE: ' ' <=> '_', 0x00 <=> '~' 1061 * // these sets are chosen to avoid shell 1062 * // and conflicts with DDI node names. 1063 * 1064 * <hex_id> // if not <ascii_id>; each byte of binary 1065 * // <id> maps a to 2 digit ascii hex 1066 * // representation in the string. 1067 * 1068 * This encoding provides a meaningful correlation between the /devices 1069 * path and the devid string where possible. 1070 * 1071 * Fibre: 1072 * sbus@6,0/SUNW,socal@d,10000/sf@1,0/ssd@w21000020370bb488,0:c,raw 1073 * id1,ssd@w20000020370bb488:c,raw 1074 * 1075 * Copper: 1076 * sbus@7,0/SUNW,fas@3,8800000/sd@a,0:c 1077 * id1,sd@SIBM_____1XY210__________:c 1078 */ 1079 /* determine if a byte of an id meets ASCII representation requirements */ 1080 #define DEVID_IDBYTE_ISASCII(b) ( \ 1081 (((b) >= 'a') && ((b) <= 'z')) || \ 1082 (((b) >= 'A') && ((b) <= 'Z')) || \ 1083 (((b) >= '0') && ((b) <= '9')) || \ 1084 (b == '+') || (b == '-') || (b == '.') || (b == '=') || \ 1085 (b == ' ') || (b == 0x00)) 1086 1087 /* set type to lower case to indicate that the did_id field is ascii */ 1088 #define DEVID_TYPE_SETASCII(c) (c - 0x20) /* 'a' -> 'A' */ 1089 1090 /* determine from type if did_id field is binary or ascii */ 1091 #define DEVID_TYPE_ISASCII(c) (((c) >= 'A') && ((c) <= 'Z')) 1092 1093 /* convert type field from binary to ascii */ 1094 #define DEVID_TYPE_BINTOASCII(b) ( \ 1095 ((b) == DEVID_SCSI3_WWN) ? 'w' : \ 1096 ((b) == DEVID_SCSI3_VPD_T10) ? 't' : \ 1097 ((b) == DEVID_SCSI3_VPD_EUI) ? 'x' : \ 1098 ((b) == DEVID_SCSI3_VPD_NAA) ? 'n' : \ 1099 ((b) == DEVID_SCSI_SERIAL) ? 's' : \ 1100 ((b) == DEVID_FAB) ? 'f' : \ 1101 ((b) == DEVID_ENCAP) ? 'e' : \ 1102 ((b) == DEVID_ATA_SERIAL) ? 'a' : \ 1103 'u') /* unknown */ 1104 1105 /* convert type field from ascii to binary */ 1106 #define DEVID_TYPE_ASCIITOBIN(c) ( \ 1107 (((c) == 'w') || ((c) == 'W')) ? DEVID_SCSI3_WWN : \ 1108 (((c) == 't') || ((c) == 'T')) ? DEVID_SCSI3_VPD_T10 : \ 1109 (((c) == 'x') || ((c) == 'X')) ? DEVID_SCSI3_VPD_EUI : \ 1110 (((c) == 'n') || ((c) == 'N')) ? DEVID_SCSI3_VPD_NAA : \ 1111 (((c) == 's') || ((c) == 'S')) ? DEVID_SCSI_SERIAL : \ 1112 (((c) == 'f') || ((c) == 'F')) ? DEVID_FAB : \ 1113 (((c) == 'e') || ((c) == 'E')) ? DEVID_ENCAP : \ 1114 (((c) == 'a') || ((c) == 'A')) ? DEVID_ATA_SERIAL : \ 1115 DEVID_MAXTYPE +1) /* unknown */ 1116 1117 /* determine if the type should be forced to hex encoding (non-ascii) */ 1118 #define DEVID_TYPE_BIN_FORCEHEX(b) ( \ 1119 ((b) == DEVID_SCSI3_WWN) || \ 1120 ((b) == DEVID_SCSI3_VPD_EUI) || \ 1121 ((b) == DEVID_SCSI3_VPD_NAA) || \ 1122 ((b) == DEVID_FAB)) 1123 1124 /* determine if the type is from a scsi3 vpd */ 1125 #define IS_DEVID_SCSI3_VPD_TYPE(b) ( \ 1126 ((b) == DEVID_SCSI3_VPD_T10) || \ 1127 ((b) == DEVID_SCSI3_VPD_EUI) || \ 1128 ((b) == DEVID_SCSI3_VPD_NAA)) 1129 1130 /* convert rev field from binary to ascii (only supports 10 revs) */ 1131 #define DEVID_REV_BINTOASCII(b) (b + '0') 1132 1133 /* convert rev field from ascii to binary (only supports 10 revs) */ 1134 #define DEVID_REV_ASCIITOBIN(c) (c - '0') 1135 1136 /* name of devid property */ 1137 #define DEVID_PROP_NAME "devid" 1138 1139 /* 1140 * prop_name used by pci_{save,restore}_config_regs() 1141 */ 1142 #define SAVED_CONFIG_REGS "pci-config-regs" 1143 #define SAVED_CONFIG_REGS_MASK "pcie-config-regs-mask" 1144 #define SAVED_CONFIG_REGS_CAPINFO "pci-cap-info" 1145 1146 typedef struct pci_config_header_state { 1147 uint16_t chs_command; 1148 uint8_t chs_cache_line_size; 1149 uint8_t chs_latency_timer; 1150 uint8_t chs_header_type; 1151 uint8_t chs_sec_latency_timer; 1152 uint8_t chs_bridge_control; 1153 uint32_t chs_base0; 1154 uint32_t chs_base1; 1155 uint32_t chs_base2; 1156 uint32_t chs_base3; 1157 uint32_t chs_base4; 1158 uint32_t chs_base5; 1159 } pci_config_header_state_t; 1160 1161 #ifdef _KERNEL 1162 1163 typedef struct pci_cap_save_desc { 1164 uint16_t cap_offset; 1165 uint16_t cap_id; 1166 uint32_t cap_nregs; 1167 } pci_cap_save_desc_t; 1168 1169 typedef struct pci_cap_entry { 1170 uint16_t cap_id; 1171 uint32_t cap_ndwords; 1172 uint32_t (*cap_save_func)(ddi_acc_handle_t confhdl, uint16_t cap_ptr, 1173 uint32_t *regbuf, uint32_t ndwords); 1174 } pci_cap_entry_t; 1175 1176 #endif /* _KERNEL */ 1177 1178 #ifdef __cplusplus 1179 } 1180 #endif 1181 1182 #endif /* _SYS_DDI_IMPLDEFS_H */ 1183