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