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