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