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 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_SUNDDI_H 28 #define _SYS_SUNDDI_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * Sun Specific DDI definitions 34 */ 35 36 #include <sys/isa_defs.h> 37 #include <sys/dditypes.h> 38 #include <sys/ddipropdefs.h> 39 #include <sys/devops.h> 40 #include <sys/time.h> 41 #include <sys/cmn_err.h> 42 #include <sys/ddidevmap.h> 43 #include <sys/ddi_impldefs.h> 44 #include <sys/ddi_implfuncs.h> 45 #include <sys/ddi_isa.h> 46 #include <sys/model.h> 47 #include <sys/devctl.h> 48 #if defined(__i386) || defined(__amd64) 49 #include <sys/dma_engine.h> 50 #endif 51 #include <sys/sunpm.h> 52 #include <sys/nvpair.h> 53 #include <sys/sysevent.h> 54 #include <sys/thread.h> 55 #include <sys/stream.h> 56 #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL) 57 #include <asm/sunddi.h> 58 #endif 59 #ifdef _KERNEL 60 #include <sys/ddi_obsolete.h> 61 #endif 62 63 #ifdef __cplusplus 64 extern "C" { 65 #endif 66 67 /* 68 * Generic Sun DDI definitions. 69 */ 70 71 #define DDI_SUCCESS (0) /* successful return */ 72 #define DDI_FAILURE (-1) /* unsuccessful return */ 73 #define DDI_NOT_WELL_FORMED (-2) /* A dev_info node is not valid */ 74 #define DDI_EAGAIN (-3) /* not enough interrupt resources */ 75 #define DDI_EINVAL (-4) /* invalid request or arguments */ 76 #define DDI_ENOTSUP (-5) /* operation is not supported */ 77 #define DDI_EPENDING (-6) /* operation or an event is pending */ 78 79 /* 80 * General-purpose DDI error return value definitions 81 */ 82 #define DDI_ENOMEM 1 /* memory not available */ 83 #define DDI_EBUSY 2 /* busy */ 84 #define DDI_ETRANSPORT 3 /* transport down */ 85 #define DDI_ECONTEXT 4 /* context error */ 86 87 88 /* 89 * General DDI sleep/nosleep allocation flags 90 */ 91 #define DDI_SLEEP 0 92 #define DDI_NOSLEEP 1 93 94 /* 95 * The following special nodeid values are reserved for use when creating 96 * nodes ONLY. They specify the attributes of the DDI_NC_PSEUDO class node 97 * being created: 98 * 99 * o DEVI_PSEUDO_NODEID specifics a node without persistence. 100 * o DEVI_SID_NODEID specifies a node with persistence. 101 * 102 * A node with the 'persistent' attribute will not be automatically removed by 103 * the framework in the current implementation - driver.conf nodes are without 104 * persistence. 105 * 106 * The actual nodeid value may be assigned by the framework and may be 107 * different than these special values. Drivers may not make assumptions 108 * about the nodeid value that is actually assigned to the node. 109 */ 110 111 #define DEVI_PSEUDO_NODEID ((int)-1) 112 #define DEVI_SID_NODEID ((int)-2) 113 114 #define DEVI_PSEUDO_NEXNAME "pseudo" 115 #define DEVI_ISA_NEXNAME "isa" 116 #define DEVI_EISA_NEXNAME "eisa" 117 118 /* 119 * ddi_create_minor_node flags 120 */ 121 #define CLONE_DEV 1 /* device is a clone device */ 122 #define PRIVONLY_DEV 0x10 /* policy-based permissions only */ 123 124 /* 125 * Historical values used for the flag field in ddi_create_minor_node. 126 * Future use of flag bits should avoid these fields to keep binary 127 * compatibility 128 * #define GLOBAL_DEV 0x2 129 * #define NODEBOUND_DEV 0x4 130 * #define NODESPECIFIC_DEV 0x6 131 * #define ENUMERATED_DEV 0x8 132 */ 133 134 /* 135 * Device type defines which are used by the 'node_type' element of the 136 * ddi_minor_data structure 137 */ 138 #define DDI_NT_SERIAL "ddi_serial" /* Serial port */ 139 #define DDI_NT_SERIAL_MB "ddi_serial:mb" /* the 'built-in' serial */ 140 /* ports (the old ttya, b */ 141 /* (,c ,d)) */ 142 #define DDI_NT_SERIAL_DO "ddi_serial:dialout" /* dialout ports */ 143 #define DDI_NT_SERIAL_MB_DO "ddi_serial:dialout,mb" /* dialout for onboard */ 144 /* ports */ 145 #define DDI_NT_SERIAL_LOMCON "ddi_serial:lomcon" /* LOMlite2 console port */ 146 147 /* 148 * *_CHAN disk type devices have channel numbers or target numbers. 149 * (i.e. ipi and scsi devices) 150 */ 151 #define DDI_NT_BLOCK "ddi_block" /* hard disks */ 152 /* 153 * The next define is for block type devices that can possible exist on 154 * a sub-bus like the scsi bus or the ipi channel. The 'disks' program 155 * will pick up on this and create logical names like c0t0d0s0 instead of 156 * c0d0s0 157 */ 158 #define DDI_NT_BLOCK_CHAN "ddi_block:channel" 159 #define DDI_NT_BLOCK_WWN "ddi_block:wwn" 160 #define DDI_NT_CD "ddi_block:cdrom" /* rom drives (cd-rom) */ 161 #define DDI_NT_CD_CHAN "ddi_block:cdrom:channel" /* rom drives (scsi type) */ 162 #define DDI_NT_FD "ddi_block:diskette" /* floppy disks */ 163 164 #define DDI_NT_ENCLOSURE "ddi_enclosure" 165 #define DDI_NT_SCSI_ENCLOSURE "ddi_enclosure:scsi" 166 167 168 #define DDI_NT_TAPE "ddi_byte:tape" /* tape drives */ 169 170 #define DDI_NT_NET "ddi_network" /* DLPI network devices */ 171 172 #define DDI_NT_NET_WIFI "ddi_network:wifi" /* wifi devices */ 173 174 #define DDI_NT_DISPLAY "ddi_display" /* display devices */ 175 176 #define DDI_PSEUDO "ddi_pseudo" /* general pseudo devices */ 177 178 #define DDI_NT_AUDIO "ddi_audio" /* audio device */ 179 180 #define DDI_NT_MOUSE "ddi_mouse" /* mouse device */ 181 182 #define DDI_NT_KEYBOARD "ddi_keyboard" /* keyboard device */ 183 184 #define DDI_NT_PARALLEL "ddi_parallel" /* parallel port */ 185 186 #define DDI_NT_PRINTER "ddi_printer" /* printer device */ 187 188 #define DDI_NT_UGEN "ddi_generic:usb" /* USB generic drv */ 189 190 #define DDI_NT_NEXUS "ddi_ctl:devctl" /* nexus drivers */ 191 192 #define DDI_NT_SCSI_NEXUS "ddi_ctl:devctl:scsi" /* nexus drivers */ 193 194 #define DDI_NT_SATA_NEXUS "ddi_ctl:devctl:sata" /* nexus drivers */ 195 196 #define DDI_NT_ATTACHMENT_POINT "ddi_ctl:attachment_point" /* attachment pt */ 197 198 #define DDI_NT_SCSI_ATTACHMENT_POINT "ddi_ctl:attachment_point:scsi" 199 /* scsi attachment pt */ 200 201 #define DDI_NT_SATA_ATTACHMENT_POINT "ddi_ctl:attachment_point:sata" 202 /* sata attachment pt */ 203 204 #define DDI_NT_PCI_ATTACHMENT_POINT "ddi_ctl:attachment_point:pci" 205 /* PCI attachment pt */ 206 #define DDI_NT_SBD_ATTACHMENT_POINT "ddi_ctl:attachment_point:sbd" 207 /* generic bd attachment pt */ 208 #define DDI_NT_FC_ATTACHMENT_POINT "ddi_ctl:attachment_point:fc" 209 /* FC attachment pt */ 210 #define DDI_NT_USB_ATTACHMENT_POINT "ddi_ctl:attachment_point:usb" 211 /* USB devices */ 212 #define DDI_NT_BLOCK_FABRIC "ddi_block:fabric" 213 /* Fabric Devices */ 214 #define DDI_NT_IB_ATTACHMENT_POINT "ddi_ctl:attachment_point:ib" 215 /* IB devices */ 216 #define DDI_NT_SMARTCARD_READER "ddi_smartcard_reader" /* Smartcard reader */ 217 218 #define DDI_NT_AV_ASYNC "ddi_av:async" /* asynchronous AV device */ 219 #define DDI_NT_AV_ISOCH "ddi_av:isoch" /* isochronous AV device */ 220 221 /* Device types used for agpgart driver related devices */ 222 #define DDI_NT_AGP_PSEUDO "ddi_agp:pseudo" /* agpgart pseudo device */ 223 #define DDI_NT_AGP_MASTER "ddi_agp:master" /* agp master device */ 224 #define DDI_NT_AGP_TARGET "ddi_agp:target" /* agp target device */ 225 #define DDI_NT_AGP_CPUGART "ddi_agp:cpugart" /* amd64 on-cpu gart device */ 226 227 #define DDI_NT_REGACC "ddi_tool_reg" /* tool register access */ 228 #define DDI_NT_INTRCTL "ddi_tool_intr" /* tool intr access */ 229 230 /* 231 * DDI event definitions 232 */ 233 #define EC_DEVFS "EC_devfs" /* Event class devfs */ 234 #define EC_DDI "EC_ddi" /* Event class ddi */ 235 236 /* Class devfs subclasses */ 237 #define ESC_DEVFS_MINOR_CREATE "ESC_devfs_minor_create" 238 #define ESC_DEVFS_MINOR_REMOVE "ESC_devfs_minor_remove" 239 #define ESC_DEVFS_DEVI_ADD "ESC_devfs_devi_add" 240 #define ESC_DEVFS_DEVI_REMOVE "ESC_devfs_devi_remove" 241 #define ESC_DEVFS_INSTANCE_MOD "ESC_devfs_instance_mod" 242 #define ESC_DEVFS_BRANCH_ADD "ESC_devfs_branch_add" 243 #define ESC_DEVFS_BRANCH_REMOVE "ESC_devfs_branch_remove" 244 245 /* Class ddi subclasses */ 246 #define ESC_DDI_INITIATOR_REGISTER "ESC_ddi_initiator_register" 247 #define ESC_DDI_INITIATOR_UNREGISTER "ESC_ddi_initiator_unregister" 248 249 /* DDI/NDI event publisher */ 250 #define EP_DDI SUNW_KERN_PUB"ddi" 251 252 /* 253 * devfs event class attributes 254 * 255 * The following attributes are private to EC_DEVFS event data. 256 */ 257 #define DEVFS_DRIVER_NAME "di.driver" 258 #define DEVFS_INSTANCE "di.instance" 259 #define DEVFS_PATHNAME "di.path" 260 #define DEVFS_DEVI_CLASS "di.devi_class" 261 #define DEVFS_BRANCH_EVENT "di.branch_event" 262 #define DEVFS_MINOR_NAME "mi.name" 263 #define DEVFS_MINOR_NODETYPE "mi.nodetype" 264 #define DEVFS_MINOR_ISCLONE "mi.isclone" 265 #define DEVFS_MINOR_MAJNUM "mi.majorno" 266 #define DEVFS_MINOR_MINORNUM "mi.minorno" 267 268 /* 269 * ddi event class payload 270 * 271 * The following attributes are private to EC_DDI event data. 272 */ 273 #define DDI_DRIVER_NAME "ddi.driver" 274 #define DDI_DRIVER_MAJOR "ddi.major" 275 #define DDI_INSTANCE "ddi.instance" 276 #define DDI_PATHNAME "ddi.path" 277 #define DDI_CLASS "ddi.class" 278 279 /* 280 * Fault-related definitions 281 * 282 * The specific numeric values have been chosen to be ordered, but 283 * not consecutive, to allow for future interpolation if required. 284 */ 285 typedef enum { 286 DDI_SERVICE_LOST = -32, 287 DDI_SERVICE_DEGRADED = -16, 288 DDI_SERVICE_UNAFFECTED = 0, 289 DDI_SERVICE_RESTORED = 16 290 } ddi_fault_impact_t; 291 292 typedef enum { 293 DDI_DATAPATH_FAULT = -32, 294 DDI_DEVICE_FAULT = -16, 295 DDI_EXTERNAL_FAULT = 0 296 } ddi_fault_location_t; 297 298 typedef enum { 299 DDI_DEVSTATE_OFFLINE = -32, 300 DDI_DEVSTATE_DOWN = -16, 301 DDI_DEVSTATE_QUIESCED = 0, 302 DDI_DEVSTATE_DEGRADED = 16, 303 DDI_DEVSTATE_UP = 32 304 } ddi_devstate_t; 305 306 #ifdef _KERNEL 307 308 /* 309 * Common property definitions 310 */ 311 #define DDI_FORCEATTACH "ddi-forceattach" 312 #define DDI_NO_AUTODETACH "ddi-no-autodetach" 313 314 /* 315 * Values that the function supplied to the dev_info 316 * tree traversal functions defined below must return. 317 */ 318 319 /* 320 * Continue search, if appropriate. 321 */ 322 #define DDI_WALK_CONTINUE 0 323 324 /* 325 * Terminate current depth of traversal. That is, terminate 326 * the current traversal of children nodes, but continue 327 * traversing sibling nodes and their children (if any). 328 */ 329 330 #define DDI_WALK_PRUNECHILD -1 331 332 /* 333 * Terminate current width of traversal. That is, terminate 334 * the current traversal of sibling nodes, but continue with 335 * traversing children nodes and their siblings (if appropriate). 336 */ 337 338 #define DDI_WALK_PRUNESIB -2 339 340 /* 341 * Terminate the entire search. 342 */ 343 344 #define DDI_WALK_TERMINATE -3 345 346 /* 347 * Terminate the entire search because an error occurred in function 348 */ 349 #define DDI_WALK_ERROR -4 350 351 /* 352 * Drivers that are prepared to support full driver layering 353 * should create and export a null-valued property of the following 354 * name. 355 * 356 * Such drivers should be prepared to be called with FKLYR in 357 * the 'flag' argument of their open(9E), close(9E) routines, and 358 * with FKIOCTL in the 'mode' argument of their ioctl(9E) routines. 359 * 360 * See ioctl(9E) and ddi_copyin(9F) for details. 361 */ 362 #define DDI_KERNEL_IOCTL "ddi-kernel-ioctl" 363 364 /* 365 * Model definitions for ddi_mmap_get_model(9F) and ddi_model_convert_from(9F). 366 */ 367 #define DDI_MODEL_MASK DATAMODEL_MASK /* Note: 0x0FF00000 */ 368 #define DDI_MODEL_ILP32 DATAMODEL_ILP32 369 #define DDI_MODEL_LP64 DATAMODEL_LP64 370 #define DDI_MODEL_NATIVE DATAMODEL_NATIVE 371 #define DDI_MODEL_NONE DATAMODEL_NONE 372 373 /* 374 * Functions and data references which really should be in <sys/ddi.h> 375 */ 376 377 extern int maxphys; 378 extern void minphys(struct buf *); 379 extern int physio(int (*)(struct buf *), struct buf *, dev_t, 380 int, void (*)(struct buf *), struct uio *); 381 extern void disksort(struct diskhd *, struct buf *); 382 383 extern long strtol(const char *, char **, int); 384 extern unsigned long strtoul(const char *, char **, int); 385 extern size_t strlen(const char *) __PURE; 386 extern char *strcpy(char *, const char *); 387 extern char *strncpy(char *, const char *, size_t); 388 /* Need to be consistent with <string.h> C++ definition for strchr() */ 389 #if __cplusplus >= 199711L 390 extern const char *strchr(const char *, int); 391 #ifndef _STRCHR_INLINE 392 #define _STRCHR_INLINE 393 extern "C++" { 394 inline char *strchr(char *__s, int __c) { 395 return (char *)strchr((const char *)__s, __c); 396 } 397 } 398 #endif /* _STRCHR_INLINE */ 399 #else 400 extern char *strchr(const char *, int); 401 #endif /* __cplusplus >= 199711L */ 402 #define DDI_STRSAME(s1, s2) ((*(s1) == *(s2)) && (strcmp((s1), (s2)) == 0)) 403 extern int strcmp(const char *, const char *) __PURE; 404 extern int strncmp(const char *, const char *, size_t) __PURE; 405 extern char *strncat(char *, const char *, size_t); 406 extern size_t strlcat(char *, const char *, size_t); 407 extern size_t strlcpy(char *, const char *, size_t); 408 extern size_t strspn(const char *, const char *); 409 extern int bcmp(const void *, const void *, size_t) __PURE; 410 extern int stoi(char **); 411 extern void numtos(ulong_t, char *); 412 extern void bcopy(const void *, void *, size_t); 413 extern void bzero(void *, size_t); 414 415 extern void *memcpy(void *, const void *, size_t); 416 extern void *memset(void *, int, size_t); 417 extern void *memmove(void *, const void *, size_t); 418 extern int memcmp(const void *, const void *, size_t) __PURE; 419 /* Need to be consistent with <string.h> C++ definition for memchr() */ 420 #if __cplusplus >= 199711L 421 extern const void *memchr(const void *, int, size_t); 422 #ifndef _MEMCHR_INLINE 423 #define _MEMCHR_INLINE 424 extern "C++" { 425 inline void *memchr(void * __s, int __c, size_t __n) { 426 return (void *)memchr((const void *)__s, __c, __n); 427 } 428 } 429 #endif /* _MEMCHR_INLINE */ 430 #else 431 extern void *memchr(const void *, int, size_t); 432 #endif /* __cplusplus >= 199711L */ 433 434 extern int ddi_strtol(const char *, char **, int, long *); 435 extern int ddi_strtoul(const char *, char **, int, unsigned long *); 436 437 /* 438 * ddi_map_regs 439 * 440 * Map in the register set given by rnumber. 441 * The register number determine which register 442 * set will be mapped if more than one exists. 443 * The parent driver gets the information 444 * from parent private data and sets up the 445 * appropriate mappings and returns the kernel 446 * virtual address of the register set in *kaddrp. 447 * The offset specifies an offset into the register 448 * space to start from and len indicates the size 449 * of the area to map. If len and offset are 0 then 450 * the entire space is mapped. It returns DDI_SUCCESS on 451 * success or DDI_FAILURE otherwise. 452 * 453 */ 454 int 455 ddi_map_regs(dev_info_t *dip, uint_t rnumber, caddr_t *kaddrp, 456 off_t offset, off_t len); 457 458 /* 459 * ddi_unmap_regs 460 * 461 * Undo mappings set up by ddi_map_regs. 462 * The register number determines which register 463 * set will be unmapped if more than one exists. 464 * This is provided for drivers preparing 465 * to detach themselves from the system to 466 * allow them to release allocated mappings. 467 * 468 * The kaddrp and len specify the area to be 469 * unmapped. *kaddrp was returned from ddi_map_regs 470 * and len should match what ddi_map_regs was called 471 * with. 472 */ 473 474 void 475 ddi_unmap_regs(dev_info_t *dip, uint_t rnumber, caddr_t *kaddrp, 476 off_t offset, off_t len); 477 478 int 479 ddi_map(dev_info_t *dp, ddi_map_req_t *mp, off_t offset, off_t len, 480 caddr_t *addrp); 481 482 int 483 ddi_apply_range(dev_info_t *dip, dev_info_t *rdip, struct regspec *rp); 484 485 /* 486 * ddi_rnumber_to_regspec: Not for use by leaf drivers. 487 */ 488 struct regspec * 489 ddi_rnumber_to_regspec(dev_info_t *dip, int rnumber); 490 491 int 492 ddi_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, off_t offset, 493 off_t len, caddr_t *vaddrp); 494 495 int 496 nullbusmap(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, off_t offset, 497 off_t len, caddr_t *vaddrp); 498 499 int ddi_peek8(dev_info_t *dip, int8_t *addr, int8_t *val_p); 500 int ddi_peek16(dev_info_t *dip, int16_t *addr, int16_t *val_p); 501 int ddi_peek32(dev_info_t *dip, int32_t *addr, int32_t *val_p); 502 int ddi_peek64(dev_info_t *dip, int64_t *addr, int64_t *val_p); 503 504 int ddi_poke8(dev_info_t *dip, int8_t *addr, int8_t val); 505 int ddi_poke16(dev_info_t *dip, int16_t *addr, int16_t val); 506 int ddi_poke32(dev_info_t *dip, int32_t *addr, int32_t val); 507 int ddi_poke64(dev_info_t *dip, int64_t *addr, int64_t val); 508 509 /* 510 * Peek and poke to and from a uio structure in xfersize pieces, 511 * using the parent nexi. 512 */ 513 int ddi_peekpokeio(dev_info_t *devi, struct uio *uio, enum uio_rw rw, 514 caddr_t addr, size_t len, uint_t xfersize); 515 516 /* 517 * Pagesize conversions using the parent nexi 518 */ 519 unsigned long ddi_btop(dev_info_t *dip, unsigned long bytes); 520 unsigned long ddi_btopr(dev_info_t *dip, unsigned long bytes); 521 unsigned long ddi_ptob(dev_info_t *dip, unsigned long pages); 522 523 /* 524 * There are no more "block" interrupt functions, per se. 525 * All thread of control should be done with MP/MT lockings. 526 * 527 * However, there are certain times in which a driver needs 528 * absolutely a critical guaranteed non-preemptable time 529 * in which to execute a few instructions. 530 * 531 * The following pair of functions attempt to guarantee this, 532 * but they are dangerous to use. That is, use them with 533 * extreme care. They do not guarantee to stop other processors 534 * from executing, but they do guarantee that the caller 535 * of ddi_enter_critical will continue to run until the 536 * caller calls ddi_exit_critical. No intervening DDI functions 537 * may be called between an entry and an exit from a critical 538 * region. 539 * 540 * ddi_enter_critical returns an integer identifier which must 541 * be passed to ddi_exit_critical. 542 * 543 * Be very sparing in the use of these functions since it is 544 * likely that absolutely nothing else can occur in the system 545 * whilst in the critical region. 546 */ 547 548 unsigned int 549 ddi_enter_critical(void); 550 551 void 552 ddi_exit_critical(unsigned int); 553 554 /* 555 * devmap functions 556 */ 557 int 558 devmap_setup(dev_t dev, offset_t off, ddi_as_handle_t as, caddr_t *addrp, 559 size_t len, uint_t prot, uint_t maxprot, uint_t flags, 560 struct cred *cred); 561 562 int 563 ddi_devmap_segmap(dev_t dev, off_t off, ddi_as_handle_t as, caddr_t *addrp, 564 off_t len, uint_t prot, uint_t maxprot, uint_t flags, 565 struct cred *cred); 566 567 int 568 devmap_load(devmap_cookie_t dhp, offset_t offset, size_t len, uint_t type, 569 uint_t rw); 570 571 int 572 devmap_unload(devmap_cookie_t dhp, offset_t offset, size_t len); 573 574 int 575 devmap_devmem_setup(devmap_cookie_t dhp, dev_info_t *dip, 576 struct devmap_callback_ctl *callback_ops, 577 uint_t rnumber, offset_t roff, size_t len, uint_t maxprot, 578 uint_t flags, ddi_device_acc_attr_t *accattrp); 579 580 int 581 devmap_umem_setup(devmap_cookie_t dhp, dev_info_t *dip, 582 struct devmap_callback_ctl *callback_ops, 583 ddi_umem_cookie_t cookie, offset_t off, size_t len, uint_t maxprot, 584 uint_t flags, ddi_device_acc_attr_t *accattrp); 585 586 int 587 devmap_devmem_remap(devmap_cookie_t dhp, dev_info_t *dip, 588 uint_t rnumber, offset_t roff, size_t len, uint_t maxprot, 589 uint_t flags, ddi_device_acc_attr_t *accattrp); 590 591 int 592 devmap_umem_remap(devmap_cookie_t dhp, dev_info_t *dip, 593 ddi_umem_cookie_t cookie, offset_t off, size_t len, uint_t maxprot, 594 uint_t flags, ddi_device_acc_attr_t *accattrp); 595 596 void 597 devmap_set_ctx_timeout(devmap_cookie_t dhp, clock_t ticks); 598 599 int 600 devmap_default_access(devmap_cookie_t dhp, void *pvtp, offset_t off, 601 size_t len, uint_t type, uint_t rw); 602 603 int 604 devmap_do_ctxmgt(devmap_cookie_t dhp, void *pvtp, offset_t off, size_t len, 605 uint_t type, uint_t rw, int (*ctxmgt)(devmap_cookie_t, void *, offset_t, 606 size_t, uint_t, uint_t)); 607 608 609 void *ddi_umem_alloc(size_t size, int flag, ddi_umem_cookie_t *cookiep); 610 611 void ddi_umem_free(ddi_umem_cookie_t cookie); 612 613 /* 614 * Functions to lock user memory and do repeated I/O or do devmap_umem_setup 615 */ 616 int 617 ddi_umem_lock(caddr_t addr, size_t size, int flags, ddi_umem_cookie_t *cookie); 618 619 void 620 ddi_umem_unlock(ddi_umem_cookie_t cookie); 621 622 struct buf * 623 ddi_umem_iosetup(ddi_umem_cookie_t cookie, off_t off, size_t len, int direction, 624 dev_t dev, daddr_t blkno, int (*iodone)(struct buf *), int sleepflag); 625 626 /* 627 * Mapping functions 628 */ 629 int 630 ddi_segmap(dev_t dev, off_t offset, struct as *asp, caddr_t *addrp, off_t len, 631 uint_t prot, uint_t maxprot, uint_t flags, cred_t *credp); 632 633 int 634 ddi_segmap_setup(dev_t dev, off_t offset, struct as *as, caddr_t *addrp, 635 off_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cred, 636 ddi_device_acc_attr_t *accattrp, uint_t rnumber); 637 638 int 639 ddi_map_fault(dev_info_t *dip, struct hat *hat, struct seg *seg, caddr_t addr, 640 struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock); 641 642 int 643 ddi_device_mapping_check(dev_t dev, ddi_device_acc_attr_t *accattrp, 644 uint_t rnumber, uint_t *hat_flags); 645 646 /* 647 * Property functions: See also, ddipropdefs.h. 648 * In general, the underlying driver MUST be held 649 * to call it's property functions. 650 */ 651 652 /* 653 * Used to create, modify, and lookup integer properties 654 */ 655 int ddi_prop_get_int(dev_t match_dev, dev_info_t *dip, uint_t flags, 656 char *name, int defvalue); 657 int64_t ddi_prop_get_int64(dev_t match_dev, dev_info_t *dip, uint_t flags, 658 char *name, int64_t defvalue); 659 int ddi_prop_lookup_int_array(dev_t match_dev, dev_info_t *dip, uint_t flags, 660 char *name, int **data, uint_t *nelements); 661 int ddi_prop_lookup_int64_array(dev_t match_dev, dev_info_t *dip, uint_t flags, 662 char *name, int64_t **data, uint_t *nelements); 663 int ddi_prop_update_int(dev_t match_dev, dev_info_t *dip, 664 char *name, int data); 665 int ddi_prop_update_int64(dev_t match_dev, dev_info_t *dip, 666 char *name, int64_t data); 667 int ddi_prop_update_int_array(dev_t match_dev, dev_info_t *dip, 668 char *name, int *data, uint_t nelements); 669 int ddi_prop_update_int64_array(dev_t match_dev, dev_info_t *dip, 670 char *name, int64_t *data, uint_t nelements); 671 /* 672 * Used to create, modify, and lookup string properties 673 */ 674 int ddi_prop_lookup_string(dev_t match_dev, dev_info_t *dip, uint_t flags, 675 char *name, char **data); 676 int ddi_prop_lookup_string_array(dev_t match_dev, dev_info_t *dip, uint_t flags, 677 char *name, char ***data, uint_t *nelements); 678 int ddi_prop_update_string(dev_t match_dev, dev_info_t *dip, 679 char *name, char *data); 680 int ddi_prop_update_string_array(dev_t match_dev, dev_info_t *dip, 681 char *name, char **data, uint_t nelements); 682 683 /* 684 * Used to create, modify, and lookup byte properties 685 */ 686 int ddi_prop_lookup_byte_array(dev_t match_dev, dev_info_t *dip, uint_t flags, 687 char *name, uchar_t **data, uint_t *nelements); 688 int ddi_prop_update_byte_array(dev_t match_dev, dev_info_t *dip, 689 char *name, uchar_t *data, uint_t nelements); 690 691 /* 692 * Used to verify the existence of a property or to see if a boolean 693 * property exists. 694 */ 695 int ddi_prop_exists(dev_t match_dev, dev_info_t *dip, uint_t flags, char *name); 696 697 /* 698 * Used to free the data returned by the above property routines. 699 */ 700 void ddi_prop_free(void *data); 701 702 /* 703 * nopropop: For internal use in `dummy' cb_prop_op functions only 704 */ 705 706 int 707 nopropop(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int mod_flags, 708 char *name, caddr_t valuep, int *lengthp); 709 710 /* 711 * ddi_prop_op: The basic property operator for drivers. 712 * 713 * In ddi_prop_op, the type of valuep is interpreted based on prop_op: 714 * 715 * prop_op valuep 716 * ------ ------ 717 * 718 * PROP_LEN <unused> 719 * 720 * PROP_LEN_AND_VAL_BUF Pointer to callers buffer 721 * 722 * PROP_LEN_AND_VAL_ALLOC Address of callers pointer (will be set to 723 * address of allocated buffer, if successful) 724 */ 725 726 int 727 ddi_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int mod_flags, 728 char *name, caddr_t valuep, int *lengthp); 729 730 /* ddi_prop_op_size: for drivers that implement size in bytes */ 731 int 732 ddi_prop_op_size(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 733 int mod_flags, char *name, caddr_t valuep, int *lengthp, 734 uint64_t size64); 735 736 /* ddi_prop_op_nblocks: for drivers that implement size in DEV_BSIZE blocks */ 737 int 738 ddi_prop_op_nblocks(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 739 int mod_flags, char *name, caddr_t valuep, int *lengthp, 740 uint64_t nblocks64); 741 742 /* 743 * Variable length props... 744 */ 745 746 /* 747 * ddi_getlongprop: Get variable length property len+val into a buffer 748 * allocated by property provider via kmem_alloc. Requester 749 * is responsible for freeing returned property via kmem_free. 750 * 751 * Arguments: 752 * 753 * dev: Input: dev_t of property. 754 * dip: Input: dev_info_t pointer of child. 755 * flags: Input: Possible flag modifiers are: 756 * DDI_PROP_DONTPASS: Don't pass to parent if prop not found. 757 * DDI_PROP_CANSLEEP: Memory allocation may sleep. 758 * name: Input: name of property. 759 * valuep: Output: Addr of callers buffer pointer. 760 * lengthp:Output: *lengthp will contain prop length on exit. 761 * 762 * Possible Returns: 763 * 764 * DDI_PROP_SUCCESS: Prop found and returned. 765 * DDI_PROP_NOT_FOUND: Prop not found 766 * DDI_PROP_UNDEFINED: Prop explicitly undefined. 767 * DDI_PROP_NO_MEMORY: Prop found, but unable to alloc mem. 768 */ 769 770 int 771 ddi_getlongprop(dev_t dev, dev_info_t *dip, int flags, 772 char *name, caddr_t valuep, int *lengthp); 773 774 /* 775 * 776 * ddi_getlongprop_buf: Get long prop into pre-allocated callers 777 * buffer. (no memory allocation by provider). 778 * 779 * dev: Input: dev_t of property. 780 * dip: Input: dev_info_t pointer of child. 781 * flags: Input: DDI_PROP_DONTPASS or NULL 782 * name: Input: name of property 783 * valuep: Input: ptr to callers buffer. 784 * lengthp:I/O: ptr to length of callers buffer on entry, 785 * actual length of property on exit. 786 * 787 * Possible returns: 788 * 789 * DDI_PROP_SUCCESS Prop found and returned 790 * DDI_PROP_NOT_FOUND Prop not found 791 * DDI_PROP_UNDEFINED Prop explicitly undefined. 792 * DDI_PROP_BUF_TOO_SMALL Prop found, callers buf too small, 793 * no value returned, but actual prop 794 * length returned in *lengthp 795 * 796 */ 797 798 int 799 ddi_getlongprop_buf(dev_t dev, dev_info_t *dip, int flags, 800 char *name, caddr_t valuep, int *lengthp); 801 802 /* 803 * Integer/boolean sized props. 804 * 805 * Call is value only... returns found boolean or int sized prop value or 806 * defvalue if prop not found or is wrong length or is explicitly undefined. 807 * Only flag is DDI_PROP_DONTPASS... 808 * 809 * By convention, this interface returns boolean (0) sized properties 810 * as value (int)1. 811 */ 812 813 int 814 ddi_getprop(dev_t dev, dev_info_t *dip, int flags, char *name, int defvalue); 815 816 /* 817 * Get prop length interface: flags are 0 or DDI_PROP_DONTPASS 818 * if returns DDI_PROP_SUCCESS, length returned in *lengthp. 819 */ 820 821 int 822 ddi_getproplen(dev_t dev, dev_info_t *dip, int flags, char *name, int *lengthp); 823 824 825 /* 826 * Interface to create/modify a managed property on child's behalf... 827 * Only flag is DDI_PROP_CANSLEEP to allow memory allocation to sleep 828 * if no memory available for internal prop structure. Long property 829 * (non integer sized) value references are not copied. 830 * 831 * Define property with DDI_DEV_T_NONE dev_t for properties not associated 832 * with any particular dev_t. Use the same dev_t when modifying or undefining 833 * a property. 834 * 835 * No guarantee on order of property search, so don't mix the same 836 * property name with wildcard and non-wildcard dev_t's. 837 */ 838 839 /* 840 * ddi_prop_create: Define a managed property: 841 */ 842 843 int 844 ddi_prop_create(dev_t dev, dev_info_t *dip, int flag, 845 char *name, caddr_t value, int length); 846 847 /* 848 * ddi_prop_modify: Modify a managed property value 849 */ 850 851 int 852 ddi_prop_modify(dev_t dev, dev_info_t *dip, int flag, 853 char *name, caddr_t value, int length); 854 855 /* 856 * ddi_prop_remove: Undefine a managed property: 857 */ 858 859 int 860 ddi_prop_remove(dev_t dev, dev_info_t *dip, char *name); 861 862 /* 863 * ddi_prop_remove_all: Used before unloading a driver to remove 864 * all properties. (undefines all dev_t's props.) 865 * Also removes `undefined' prop defs. 866 */ 867 868 void 869 ddi_prop_remove_all(dev_info_t *dip); 870 871 872 /* 873 * ddi_prop_undefine: Explicitly undefine a property. Property 874 * searches which match this property return 875 * the error code DDI_PROP_UNDEFINED. 876 * 877 * Use ddi_prop_remove to negate effect of 878 * ddi_prop_undefine 879 */ 880 881 int 882 ddi_prop_undefine(dev_t dev, dev_info_t *dip, int flag, char *name); 883 884 885 /* 886 * The default ddi_bus_prop_op wrapper... 887 */ 888 889 int 890 ddi_bus_prop_op(dev_t dev, dev_info_t *dip, dev_info_t *ch_dip, 891 ddi_prop_op_t prop_op, int mod_flags, 892 char *name, caddr_t valuep, int *lengthp); 893 894 895 /* 896 * Routines to traverse the tree of dev_info nodes. 897 * The general idea of these functions is to provide 898 * various tree traversal utilities. For each node 899 * that the tree traversal function finds, a caller 900 * supplied function is called with arguments of 901 * the current node and a caller supplied argument. 902 * The caller supplied function should return one 903 * of the integer values defined below which will 904 * indicate to the tree traversal function whether 905 * the traversal should be continued, and if so, how, 906 * or whether the traversal should terminate. 907 */ 908 909 /* 910 * This general-purpose routine traverses the tree of dev_info nodes, 911 * starting from the given node, and calls the given function for each 912 * node that it finds with the current node and the pointer arg (which 913 * can point to a structure of information that the function 914 * needs) as arguments. 915 * 916 * It does the walk a layer at a time, not depth-first. 917 * 918 * The given function must return one of the values defined above. 919 * 920 */ 921 922 void 923 ddi_walk_devs(dev_info_t *, int (*)(dev_info_t *, void *), void *); 924 925 /* 926 * Routines to get at elements of the dev_info structure 927 */ 928 929 /* 930 * ddi_node_name gets the device's 'name' from the device node. 931 * 932 * ddi_binding_name gets the string the OS used to bind the node to a driver, 933 * in certain cases, the binding name may be different from the node name, 934 * if the node name does not name a specific device driver. 935 * 936 * ddi_get_name is a synonym for ddi_binding_name(). 937 */ 938 char * 939 ddi_get_name(dev_info_t *dip); 940 941 char * 942 ddi_binding_name(dev_info_t *dip); 943 944 const char * 945 ddi_driver_name(dev_info_t *dip); 946 947 major_t 948 ddi_driver_major(dev_info_t *dip); 949 950 major_t 951 ddi_compatible_driver_major(dev_info_t *dip, char **formp); 952 953 char * 954 ddi_node_name(dev_info_t *dip); 955 956 int 957 ddi_get_nodeid(dev_info_t *dip); 958 959 int 960 ddi_get_instance(dev_info_t *dip); 961 962 struct dev_ops * 963 ddi_get_driver(dev_info_t *dip); 964 965 void 966 ddi_set_driver(dev_info_t *dip, struct dev_ops *devo); 967 968 void 969 ddi_set_driver_private(dev_info_t *dip, void *data); 970 971 void * 972 ddi_get_driver_private(dev_info_t *dip); 973 974 /* 975 * ddi_dev_is_needed tells system that a device is about to use a 976 * component. Returns when component is ready. 977 */ 978 int 979 ddi_dev_is_needed(dev_info_t *dip, int cmpt, int level); 980 981 /* 982 * check if DDI_SUSPEND may result in power being removed from a device. 983 */ 984 int 985 ddi_removing_power(dev_info_t *dip); 986 987 /* 988 * (Obsolete) power entry point 989 */ 990 int 991 ddi_power(dev_info_t *dip, int cmpt, int level); 992 993 /* 994 * ddi_get_parent requires that the branch of the tree with the 995 * node be held (ddi_hold_installed_driver) or that the devinfo tree 996 * lock be held 997 */ 998 dev_info_t * 999 ddi_get_parent(dev_info_t *dip); 1000 1001 /* 1002 * ddi_get_child and ddi_get_next_sibling require that the devinfo 1003 * tree lock be held 1004 */ 1005 dev_info_t * 1006 ddi_get_child(dev_info_t *dip); 1007 1008 dev_info_t * 1009 ddi_get_next_sibling(dev_info_t *dip); 1010 1011 dev_info_t * 1012 ddi_get_next(dev_info_t *dip); 1013 1014 void 1015 ddi_set_next(dev_info_t *dip, dev_info_t *nextdip); 1016 1017 /* 1018 * dev_info manipulation functions 1019 */ 1020 1021 /* 1022 * Add and remove child devices. These are part of the system framework. 1023 * 1024 * ddi_add_child creates a dev_info structure with the passed name, 1025 * nodeid and instance arguments and makes it a child of pdip. Devices 1026 * that are known directly by the hardware have real nodeids; devices 1027 * that are software constructs use the defined DEVI_PSEUDO_NODEID 1028 * for the node id. 1029 * 1030 * ddi_remove_node removes the node from the tree. This fails if this 1031 * child has children. Parent and driver private data should already 1032 * be released (freed) prior to calling this function. If flag is 1033 * non-zero, the child is removed from it's linked list of instances. 1034 */ 1035 dev_info_t * 1036 ddi_add_child(dev_info_t *pdip, char *name, uint_t nodeid, uint_t instance); 1037 1038 int 1039 ddi_remove_child(dev_info_t *dip, int flag); 1040 1041 /* 1042 * Given the major number for a driver, make sure that dev_info nodes 1043 * are created form the driver's hwconf file, the driver for the named 1044 * device is loaded and attached, as well as any drivers for parent devices. 1045 * Return a pointer to the driver's dev_ops struct with the dev_ops held. 1046 * Note - Callers must release the dev_ops with ddi_rele_driver. 1047 * 1048 * When a driver is held, the branch of the devinfo tree from any of the 1049 * drivers devinfos to the root node are automatically held. This only 1050 * applies to tree traversals up (and back down) the tree following the 1051 * parent pointers. 1052 * 1053 * Use of this interface is discouraged, it may be removed in a future release. 1054 */ 1055 struct dev_ops * 1056 ddi_hold_installed_driver(major_t major); 1057 1058 void 1059 ddi_rele_driver(major_t major); 1060 1061 /* 1062 * Attach and hold the specified instance of a driver. The flags argument 1063 * should be zero. 1064 */ 1065 dev_info_t * 1066 ddi_hold_devi_by_instance(major_t major, int instance, int flags); 1067 1068 void 1069 ddi_release_devi(dev_info_t *); 1070 1071 /* 1072 * Associate a streams queue with a devinfo node 1073 */ 1074 void 1075 ddi_assoc_queue_with_devi(queue_t *, dev_info_t *); 1076 1077 /* 1078 * Given the identifier string passed, make sure that dev_info nodes 1079 * are created form the driver's hwconf file, the driver for the named 1080 * device is loaded and attached, as well as any drivers for parent devices. 1081 * 1082 * Note that the driver is not held and is subject to being removed the instant 1083 * this call completes. You probably really want ddi_hold_installed_driver. 1084 */ 1085 int 1086 ddi_install_driver(char *idstring); 1087 1088 /* 1089 * Routines that return specific nodes 1090 */ 1091 1092 dev_info_t * 1093 ddi_root_node(void); 1094 1095 /* 1096 * Given a name and an instance number, find and return the 1097 * dev_info from the current state of the device tree. 1098 * 1099 * If instance number is -1, return the first named instance. 1100 * 1101 * If attached is 1, exclude all nodes that are < DS_ATTACHED 1102 * 1103 * Requires that the devinfo tree be locked. 1104 * If attached is 1, the driver must be held. 1105 */ 1106 dev_info_t * 1107 ddi_find_devinfo(char *name, int instance, int attached); 1108 1109 /* 1110 * Synchronization of I/O with respect to various 1111 * caches and system write buffers. 1112 * 1113 * Done at varying points during an I/O transfer (including at the 1114 * removal of an I/O mapping). 1115 * 1116 * Due to the support of systems with write buffers which may 1117 * not be able to be turned off, this function *must* used at 1118 * any point in which data consistency might be required. 1119 * 1120 * Generally this means that if a memory object has multiple mappings 1121 * (both for I/O, as described by the handle, and the IU, via, e.g. 1122 * a call to ddi_dma_kvaddrp), and one mapping may have been 1123 * used to modify the memory object, this function must be called 1124 * to ensure that the modification of the memory object is 1125 * complete, as well as possibly to inform other mappings of 1126 * the object that any cached references to the object are 1127 * now stale (and flush or invalidate these stale cache references 1128 * as necessary). 1129 * 1130 * The function ddi_dma_sync() provides the general interface with 1131 * respect to this capability. Generally, ddi_dma_free() (below) may 1132 * be used in preference to ddi_dma_sync() as ddi_dma_free() calls 1133 * ddi_dma_sync(). 1134 * 1135 * Returns 0 if all caches that exist and are specified by cache_flags 1136 * are successfully operated on, else -1. 1137 * 1138 * The argument offset specifies an offset into the mapping of the mapped 1139 * object in which to perform the synchronization. It will be silently 1140 * truncated to the granularity of underlying cache line sizes as 1141 * appropriate. 1142 * 1143 * The argument len specifies a length starting from offset in which to 1144 * perform the synchronization. A value of (uint_t) -1 means that the length 1145 * proceeds from offset to the end of the mapping. The length argument 1146 * will silently rounded up to the granularity of underlying cache line 1147 * sizes as appropriate. 1148 * 1149 * The argument flags specifies what to synchronize (the device's view of 1150 * the object or the cpu's view of the object). 1151 * 1152 * Inquiring minds want to know when ddi_dma_sync should be used: 1153 * 1154 * + When an object is mapped for dma, assume that an 1155 * implicit ddi_dma_sync() is done for you. 1156 * 1157 * + When an object is unmapped (ddi_dma_free()), assume 1158 * that an implicit ddi_dma_sync() is done for you. 1159 * 1160 * + At any time between the two times above that the 1161 * memory object may have been modified by either 1162 * the DMA device or a processor and you wish that 1163 * the change be noticed by the master that didn't 1164 * do the modifying. 1165 * 1166 * Clearly, only the third case above requires the use of ddi_dma_sync. 1167 * 1168 * Inquiring minds also want to know which flag to use: 1169 * 1170 * + If you *modify* with a cpu the object, you use 1171 * ddi_dma_sync(...DDI_DMA_SYNC_FORDEV) (you are making sure 1172 * that the DMA device sees the changes you made). 1173 * 1174 * + If you are checking, with the processor, an area 1175 * of the object that the DMA device *may* have modified, 1176 * you use ddi_dma_sync(....DDI_DMA_SYNC_FORCPU) (you are 1177 * making sure that the processor(s) will see the changes 1178 * that the DMA device may have made). 1179 */ 1180 1181 int 1182 ddi_dma_sync(ddi_dma_handle_t handle, off_t offset, size_t len, uint_t flags); 1183 1184 /* 1185 * Return the allowable DMA burst size for the object mapped by handle. 1186 * The burst sizes will returned in an integer that encodes power 1187 * of two burst sizes that are allowed in bit encoded format. For 1188 * example, a transfer that could allow 1, 2, 4, 8 and 32 byte bursts 1189 * would be encoded as 0x2f. A transfer that could be allowed as solely 1190 * a halfword (2 byte) transfers would be returned as 0x2. 1191 */ 1192 1193 int 1194 ddi_dma_burstsizes(ddi_dma_handle_t handle); 1195 1196 /* 1197 * Merge DMA attributes 1198 */ 1199 1200 void 1201 ddi_dma_attr_merge(ddi_dma_attr_t *attr, ddi_dma_attr_t *mod); 1202 1203 /* 1204 * Allocate a DMA handle 1205 */ 1206 1207 int 1208 ddi_dma_alloc_handle(dev_info_t *dip, ddi_dma_attr_t *attr, 1209 int (*waitfp)(caddr_t), caddr_t arg, 1210 ddi_dma_handle_t *handlep); 1211 1212 /* 1213 * Free DMA handle 1214 */ 1215 1216 void 1217 ddi_dma_free_handle(ddi_dma_handle_t *handlep); 1218 1219 /* 1220 * Allocate memory for DMA transfers 1221 */ 1222 1223 int 1224 ddi_dma_mem_alloc(ddi_dma_handle_t handle, size_t length, 1225 ddi_device_acc_attr_t *accattrp, uint_t xfermodes, 1226 int (*waitfp)(caddr_t), caddr_t arg, caddr_t *kaddrp, 1227 size_t *real_length, ddi_acc_handle_t *handlep); 1228 1229 /* 1230 * Free DMA memory 1231 */ 1232 1233 void 1234 ddi_dma_mem_free(ddi_acc_handle_t *hp); 1235 1236 /* 1237 * bind address to a DMA handle 1238 */ 1239 1240 int 1241 ddi_dma_addr_bind_handle(ddi_dma_handle_t handle, struct as *as, 1242 caddr_t addr, size_t len, uint_t flags, 1243 int (*waitfp)(caddr_t), caddr_t arg, 1244 ddi_dma_cookie_t *cookiep, uint_t *ccountp); 1245 1246 /* 1247 * bind buffer to DMA handle 1248 */ 1249 1250 int 1251 ddi_dma_buf_bind_handle(ddi_dma_handle_t handle, struct buf *bp, 1252 uint_t flags, int (*waitfp)(caddr_t), caddr_t arg, 1253 ddi_dma_cookie_t *cookiep, uint_t *ccountp); 1254 1255 /* 1256 * unbind mapping object to handle 1257 */ 1258 1259 int 1260 ddi_dma_unbind_handle(ddi_dma_handle_t handle); 1261 1262 /* 1263 * get next DMA cookie 1264 */ 1265 1266 void 1267 ddi_dma_nextcookie(ddi_dma_handle_t handle, ddi_dma_cookie_t *cookiep); 1268 1269 /* 1270 * get number of DMA windows 1271 */ 1272 1273 int 1274 ddi_dma_numwin(ddi_dma_handle_t handle, uint_t *nwinp); 1275 1276 /* 1277 * get specific DMA window 1278 */ 1279 1280 int 1281 ddi_dma_getwin(ddi_dma_handle_t handle, uint_t win, off_t *offp, 1282 size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); 1283 1284 /* 1285 * activate 64 bit SBus support 1286 */ 1287 1288 int 1289 ddi_dma_set_sbus64(ddi_dma_handle_t handle, ulong_t burstsizes); 1290 1291 /* 1292 * Miscellaneous functions 1293 */ 1294 1295 /* 1296 * ddi_report_dev: Report a successful attach. 1297 */ 1298 1299 void 1300 ddi_report_dev(dev_info_t *dev); 1301 1302 /* 1303 * ddi_dev_regsize 1304 * 1305 * If the device has h/w register(s), report 1306 * the size, in bytes, of the specified one into *resultp. 1307 * 1308 * Returns DDI_FAILURE if there are not registers, 1309 * or the specified register doesn't exist. 1310 */ 1311 1312 int 1313 ddi_dev_regsize(dev_info_t *dev, uint_t rnumber, off_t *resultp); 1314 1315 /* 1316 * ddi_dev_nregs 1317 * 1318 * If the device has h/w register(s), report 1319 * how many of them that there are into resultp. 1320 * Return DDI_FAILURE if the device has no registers. 1321 */ 1322 1323 int 1324 ddi_dev_nregs(dev_info_t *dev, int *resultp); 1325 1326 /* 1327 * ddi_dev_is_sid 1328 * 1329 * If the device is self-identifying, i.e., 1330 * has already been probed by a smart PROM 1331 * (and thus registers are known to be valid) 1332 * return DDI_SUCCESS, else DDI_FAILURE. 1333 */ 1334 1335 1336 int 1337 ddi_dev_is_sid(dev_info_t *dev); 1338 1339 /* 1340 * ddi_slaveonly 1341 * 1342 * If the device is on a bus that precludes 1343 * the device from being either a dma master or 1344 * a dma slave, return DDI_SUCCESS. 1345 */ 1346 1347 int 1348 ddi_slaveonly(dev_info_t *); 1349 1350 1351 /* 1352 * ddi_dev_affinity 1353 * 1354 * Report, via DDI_SUCCESS, whether there exists 1355 * an 'affinity' between two dev_info_t's. An 1356 * affinity is defined to be either a parent-child, 1357 * or a sibling relationship such that the siblings 1358 * or in the same part of the bus they happen to be 1359 * on. 1360 */ 1361 1362 int 1363 ddi_dev_affinity(dev_info_t *deva, dev_info_t *devb); 1364 1365 1366 /* 1367 * ddi_set_callback 1368 * 1369 * Set a function/arg pair into the callback list identified 1370 * by listid. *listid must always initially start out as zero. 1371 */ 1372 1373 void 1374 ddi_set_callback(int (*funcp)(caddr_t), caddr_t arg, uintptr_t *listid); 1375 1376 /* 1377 * ddi_run_callback 1378 * 1379 * Run the callback list identified by listid. 1380 */ 1381 1382 void 1383 ddi_run_callback(uintptr_t *listid); 1384 1385 /* 1386 * More miscellaneous 1387 */ 1388 1389 int 1390 nochpoll(dev_t dev, short events, int anyyet, short *reventsp, 1391 struct pollhead **phpp); 1392 1393 dev_info_t * 1394 nodevinfo(dev_t dev, int otyp); 1395 1396 int 1397 ddi_no_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result); 1398 1399 int 1400 ddi_getinfo_1to1(dev_info_t *dip, ddi_info_cmd_t infocmd, 1401 void *arg, void **result); 1402 1403 int 1404 ddifail(dev_info_t *devi, ddi_attach_cmd_t cmd); 1405 1406 int 1407 ddi_no_dma_map(dev_info_t *dip, dev_info_t *rdip, 1408 struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep); 1409 1410 int 1411 ddi_no_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr, 1412 int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep); 1413 1414 int 1415 ddi_no_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, 1416 ddi_dma_handle_t handle); 1417 1418 int 1419 ddi_no_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip, 1420 ddi_dma_handle_t handle, struct ddi_dma_req *dmareq, 1421 ddi_dma_cookie_t *cp, uint_t *ccountp); 1422 1423 int 1424 ddi_no_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, 1425 ddi_dma_handle_t handle); 1426 1427 int 1428 ddi_no_dma_flush(dev_info_t *dip, dev_info_t *rdip, 1429 ddi_dma_handle_t handle, off_t off, size_t len, 1430 uint_t cache_flags); 1431 1432 int 1433 ddi_no_dma_win(dev_info_t *dip, dev_info_t *rdip, 1434 ddi_dma_handle_t handle, uint_t win, off_t *offp, 1435 size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); 1436 1437 int 1438 ddi_no_dma_mctl(register dev_info_t *dip, dev_info_t *rdip, 1439 ddi_dma_handle_t handle, enum ddi_dma_ctlops request, 1440 off_t *offp, size_t *lenp, caddr_t *objp, uint_t flags); 1441 1442 void 1443 ddivoid(); 1444 1445 cred_t * 1446 ddi_get_cred(void); 1447 1448 clock_t 1449 ddi_get_lbolt(void); 1450 1451 time_t 1452 ddi_get_time(void); 1453 1454 pid_t 1455 ddi_get_pid(void); 1456 1457 kt_did_t 1458 ddi_get_kt_did(void); 1459 1460 boolean_t 1461 ddi_can_receive_sig(void); 1462 1463 void 1464 swab(void *src, void *dst, size_t nbytes); 1465 1466 int 1467 ddi_create_minor_node(dev_info_t *dip, char *name, int spec_type, 1468 minor_t minor_num, char *node_type, int flag); 1469 1470 int 1471 ddi_create_priv_minor_node(dev_info_t *dip, char *name, int spec_type, 1472 minor_t minor_num, char *node_type, int flag, 1473 const char *rdpriv, const char *wrpriv, mode_t priv_mode); 1474 1475 void 1476 ddi_remove_minor_node(dev_info_t *dip, char *name); 1477 1478 int 1479 ddi_in_panic(void); 1480 1481 int 1482 ddi_streams_driver(dev_info_t *dip); 1483 1484 /* 1485 * DDI wrappers for ffs and fls 1486 */ 1487 int 1488 ddi_ffs(long mask); 1489 1490 int 1491 ddi_fls(long mask); 1492 1493 /* 1494 * The next five routines comprise generic storage management utilities 1495 * for driver soft state structures. 1496 */ 1497 1498 /* 1499 * Allocate a set of pointers to 'n_items' objects of size 'size' 1500 * bytes. Each pointer is initialized to nil. 'n_items' is a hint i.e. 1501 * zero is allowed. 1502 */ 1503 int 1504 ddi_soft_state_init(void **state_p, size_t size, size_t n_items); 1505 1506 /* 1507 * Allocate a state structure of size 'size' to be associated 1508 * with item 'item'. 1509 */ 1510 int 1511 ddi_soft_state_zalloc(void *state, int item); 1512 1513 /* 1514 * Fetch a pointer to the allocated soft state structure 1515 * corresponding to 'item.' 1516 */ 1517 void * 1518 ddi_get_soft_state(void *state, int item); 1519 1520 /* 1521 * Free the state structure corresponding to 'item.' 1522 */ 1523 void 1524 ddi_soft_state_free(void *state, int item); 1525 1526 /* 1527 * Free the handle, and any associated soft state structures. 1528 */ 1529 void 1530 ddi_soft_state_fini(void **state_p); 1531 1532 /* 1533 * Set the addr field of the name in dip to name 1534 */ 1535 void 1536 ddi_set_name_addr(dev_info_t *dip, char *name); 1537 1538 /* 1539 * Get the address part of the name. 1540 */ 1541 char * 1542 ddi_get_name_addr(dev_info_t *dip); 1543 1544 void 1545 ddi_set_parent_data(dev_info_t *dip, void *pd); 1546 1547 void * 1548 ddi_get_parent_data(dev_info_t *dip); 1549 1550 int 1551 ddi_initchild(dev_info_t *parent, dev_info_t *proto); 1552 1553 int 1554 ddi_uninitchild(dev_info_t *dip); 1555 1556 major_t 1557 ddi_name_to_major(char *name); 1558 1559 char * 1560 ddi_major_to_name(major_t major); 1561 1562 char * 1563 ddi_deviname(dev_info_t *dip, char *name); 1564 1565 char * 1566 ddi_pathname(dev_info_t *dip, char *path); 1567 1568 int 1569 ddi_dev_pathname(dev_t devt, int spec_type, char *name); 1570 1571 dev_t 1572 ddi_pathname_to_dev_t(char *pathname); 1573 1574 /* 1575 * High resolution system timer functions. 1576 * 1577 * These functions are already in the kernel (see sys/time.h). 1578 * The ddi supports the notion of a hrtime_t type and the 1579 * functions gethrtime, hrtadd, hrtsub and hrtcmp. 1580 */ 1581 1582 1583 /* 1584 * Nexus wrapper functions 1585 * 1586 * These functions are for entries in a bus nexus driver's bus_ops 1587 * structure for when the driver doesn't have such a function and 1588 * doesn't wish to prohibit such a function from existing. They 1589 * may also be called to start passing a request up the dev_info 1590 * tree. 1591 */ 1592 1593 /* 1594 * bus_ctl wrapper 1595 */ 1596 1597 int 1598 ddi_ctlops(dev_info_t *d, dev_info_t *r, ddi_ctl_enum_t o, void *a, void *v); 1599 1600 /* 1601 * bus_dma_map wrapper 1602 */ 1603 1604 int 1605 ddi_dma_map(dev_info_t *dip, dev_info_t *rdip, 1606 struct ddi_dma_req *dmareqp, ddi_dma_handle_t *handlep); 1607 1608 int 1609 ddi_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr, 1610 int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep); 1611 1612 int 1613 ddi_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, 1614 ddi_dma_handle_t handle); 1615 1616 int 1617 ddi_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip, 1618 ddi_dma_handle_t handle, struct ddi_dma_req *dmareq, 1619 ddi_dma_cookie_t *cp, uint_t *ccountp); 1620 1621 int 1622 ddi_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, 1623 ddi_dma_handle_t handle); 1624 1625 int 1626 ddi_dma_flush(dev_info_t *dip, dev_info_t *rdip, 1627 ddi_dma_handle_t handle, off_t off, size_t len, 1628 uint_t cache_flags); 1629 1630 int 1631 ddi_dma_win(dev_info_t *dip, dev_info_t *rdip, 1632 ddi_dma_handle_t handle, uint_t win, off_t *offp, 1633 size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp); 1634 1635 /* 1636 * bus_dma_ctl wrapper 1637 */ 1638 1639 int 1640 ddi_dma_mctl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, 1641 enum ddi_dma_ctlops request, off_t *offp, size_t *lenp, 1642 caddr_t *objp, uint_t flags); 1643 1644 /* 1645 * dvma support for networking drivers 1646 */ 1647 1648 unsigned long 1649 dvma_pagesize(dev_info_t *dip); 1650 1651 int 1652 dvma_reserve(dev_info_t *dip, ddi_dma_lim_t *limp, uint_t pages, 1653 ddi_dma_handle_t *handlep); 1654 1655 void 1656 dvma_release(ddi_dma_handle_t h); 1657 1658 void 1659 dvma_kaddr_load(ddi_dma_handle_t h, caddr_t a, uint_t len, uint_t index, 1660 ddi_dma_cookie_t *cp); 1661 1662 void 1663 dvma_unload(ddi_dma_handle_t h, uint_t objindex, uint_t type); 1664 1665 void 1666 dvma_sync(ddi_dma_handle_t h, uint_t objindex, uint_t type); 1667 1668 /* 1669 * Layered driver support 1670 */ 1671 1672 extern int ddi_copyin(const void *, void *, size_t, int); 1673 extern int ddi_copyout(const void *, void *, size_t, int); 1674 1675 /* 1676 * Send signals to processes 1677 */ 1678 extern void *proc_ref(void); 1679 extern void proc_unref(void *pref); 1680 extern int proc_signal(void *pref, int sig); 1681 1682 /* I/O port access routines */ 1683 extern uint8_t inb(int port); 1684 extern uint16_t inw(int port); 1685 extern uint32_t inl(int port); 1686 extern void outb(int port, uint8_t value); 1687 extern void outw(int port, uint16_t value); 1688 extern void outl(int port, uint32_t value); 1689 1690 /* 1691 * Console bell routines 1692 */ 1693 extern void ddi_ring_console_bell(clock_t duration); 1694 extern void ddi_set_console_bell(void (*bellfunc)(clock_t duration)); 1695 1696 /* 1697 * Fault-related functions 1698 */ 1699 extern int ddi_check_acc_handle(ddi_acc_handle_t); 1700 extern int ddi_check_dma_handle(ddi_dma_handle_t); 1701 extern void ddi_dev_report_fault(dev_info_t *, ddi_fault_impact_t, 1702 ddi_fault_location_t, const char *); 1703 extern ddi_devstate_t ddi_get_devstate(dev_info_t *); 1704 1705 /* 1706 * Miscellaneous redefines 1707 */ 1708 #define uiophysio physio 1709 1710 /* 1711 * utilities - "reg" mapping and all common portable data access functions 1712 */ 1713 1714 /* 1715 * error code from ddi_regs_map_setup 1716 */ 1717 1718 #define DDI_REGS_ACC_CONFLICT (-10) 1719 1720 /* 1721 * Device address advance flags 1722 */ 1723 1724 #define DDI_DEV_NO_AUTOINCR 0x0000 1725 #define DDI_DEV_AUTOINCR 0x0001 1726 1727 int 1728 ddi_regs_map_setup(dev_info_t *dip, uint_t rnumber, caddr_t *addrp, 1729 offset_t offset, offset_t len, ddi_device_acc_attr_t *accattrp, 1730 ddi_acc_handle_t *handle); 1731 1732 void 1733 ddi_regs_map_free(ddi_acc_handle_t *handle); 1734 1735 /* 1736 * these are the prototypes for the common portable data access functions 1737 */ 1738 1739 uint8_t 1740 ddi_get8(ddi_acc_handle_t handle, uint8_t *addr); 1741 1742 uint16_t 1743 ddi_get16(ddi_acc_handle_t handle, uint16_t *addr); 1744 1745 uint32_t 1746 ddi_get32(ddi_acc_handle_t handle, uint32_t *addr); 1747 1748 uint64_t 1749 ddi_get64(ddi_acc_handle_t handle, uint64_t *addr); 1750 1751 void 1752 ddi_rep_get8(ddi_acc_handle_t handle, uint8_t *host_addr, uint8_t *dev_addr, 1753 size_t repcount, uint_t flags); 1754 1755 void 1756 ddi_rep_get16(ddi_acc_handle_t handle, uint16_t *host_addr, uint16_t *dev_addr, 1757 size_t repcount, uint_t flags); 1758 1759 void 1760 ddi_rep_get32(ddi_acc_handle_t handle, uint32_t *host_addr, uint32_t *dev_addr, 1761 size_t repcount, uint_t flags); 1762 1763 void 1764 ddi_rep_get64(ddi_acc_handle_t handle, uint64_t *host_addr, uint64_t *dev_addr, 1765 size_t repcount, uint_t flags); 1766 1767 void 1768 ddi_put8(ddi_acc_handle_t handle, uint8_t *addr, uint8_t value); 1769 1770 void 1771 ddi_put16(ddi_acc_handle_t handle, uint16_t *addr, uint16_t value); 1772 1773 void 1774 ddi_put32(ddi_acc_handle_t handle, uint32_t *addr, uint32_t value); 1775 1776 void 1777 ddi_put64(ddi_acc_handle_t handle, uint64_t *addr, uint64_t value); 1778 1779 void 1780 ddi_rep_put8(ddi_acc_handle_t handle, uint8_t *host_addr, uint8_t *dev_addr, 1781 size_t repcount, uint_t flags); 1782 void 1783 ddi_rep_put16(ddi_acc_handle_t handle, uint16_t *host_addr, uint16_t *dev_addr, 1784 size_t repcount, uint_t flags); 1785 void 1786 ddi_rep_put32(ddi_acc_handle_t handle, uint32_t *host_addr, uint32_t *dev_addr, 1787 size_t repcount, uint_t flags); 1788 1789 void 1790 ddi_rep_put64(ddi_acc_handle_t handle, uint64_t *host_addr, uint64_t *dev_addr, 1791 size_t repcount, uint_t flags); 1792 1793 /* 1794 * these are special device handling functions 1795 */ 1796 int 1797 ddi_device_zero(ddi_acc_handle_t handle, caddr_t dev_addr, 1798 size_t bytecount, ssize_t dev_advcnt, uint_t dev_datasz); 1799 1800 int 1801 ddi_device_copy( 1802 ddi_acc_handle_t src_handle, caddr_t src_addr, ssize_t src_advcnt, 1803 ddi_acc_handle_t dest_handle, caddr_t dest_addr, ssize_t dest_advcnt, 1804 size_t bytecount, uint_t dev_datasz); 1805 1806 /* 1807 * these are software byte swapping functions 1808 */ 1809 uint16_t 1810 ddi_swap16(uint16_t value); 1811 1812 uint32_t 1813 ddi_swap32(uint32_t value); 1814 1815 uint64_t 1816 ddi_swap64(uint64_t value); 1817 1818 /* 1819 * these are the prototypes for PCI local bus functions 1820 */ 1821 /* 1822 * PCI power management capabilities reporting in addition to those 1823 * provided by the PCI Power Management Specification. 1824 */ 1825 #define PCI_PM_IDLESPEED 0x1 /* clock for idle dev - cap */ 1826 #define PCI_PM_IDLESPEED_ANY (void *)-1 /* any clock for idle dev */ 1827 #define PCI_PM_IDLESPEED_NONE (void *)-2 /* regular clock for idle dev */ 1828 1829 int 1830 pci_config_setup(dev_info_t *dip, ddi_acc_handle_t *handle); 1831 1832 void 1833 pci_config_teardown(ddi_acc_handle_t *handle); 1834 1835 uint8_t 1836 pci_config_get8(ddi_acc_handle_t handle, off_t offset); 1837 1838 uint16_t 1839 pci_config_get16(ddi_acc_handle_t handle, off_t offset); 1840 1841 uint32_t 1842 pci_config_get32(ddi_acc_handle_t handle, off_t offset); 1843 1844 uint64_t 1845 pci_config_get64(ddi_acc_handle_t handle, off_t offset); 1846 1847 void 1848 pci_config_put8(ddi_acc_handle_t handle, off_t offset, uint8_t value); 1849 1850 void 1851 pci_config_put16(ddi_acc_handle_t handle, off_t offset, uint16_t value); 1852 1853 void 1854 pci_config_put32(ddi_acc_handle_t handle, off_t offset, uint32_t value); 1855 1856 void 1857 pci_config_put64(ddi_acc_handle_t handle, off_t offset, uint64_t value); 1858 1859 int 1860 pci_report_pmcap(dev_info_t *dip, int cap, void *arg); 1861 1862 int 1863 pci_restore_config_regs(dev_info_t *dip); 1864 1865 int 1866 pci_save_config_regs(dev_info_t *dip); 1867 1868 void 1869 pci_ereport_setup(dev_info_t *dip); 1870 1871 void 1872 pci_ereport_teardown(dev_info_t *dip); 1873 1874 void 1875 pci_ereport_post(dev_info_t *dip, ddi_fm_error_t *derr, uint16_t *status); 1876 1877 #if defined(__i386) || defined(__amd64) 1878 int 1879 pci_peekpoke_check(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *, 1880 int (*handler)(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, 1881 void *), kmutex_t *, kmutex_t *); 1882 #endif 1883 1884 void 1885 pci_target_enqueue(uint64_t, char *, char *, uint64_t); 1886 1887 void 1888 pci_targetq_init(void); 1889 1890 /* 1891 * the prototype for the C Language Type Model inquiry. 1892 */ 1893 model_t ddi_mmap_get_model(void); 1894 model_t ddi_model_convert_from(model_t); 1895 1896 /* 1897 * these are the prototypes for device id functions. 1898 */ 1899 int 1900 ddi_devid_valid(ddi_devid_t devid); 1901 1902 int 1903 ddi_devid_register(dev_info_t *dip, ddi_devid_t devid); 1904 1905 void 1906 ddi_devid_unregister(dev_info_t *dip); 1907 1908 int 1909 ddi_devid_init(dev_info_t *dip, ushort_t devid_type, ushort_t nbytes, 1910 void *id, ddi_devid_t *ret_devid); 1911 1912 size_t 1913 ddi_devid_sizeof(ddi_devid_t devid); 1914 1915 void 1916 ddi_devid_free(ddi_devid_t devid); 1917 1918 int 1919 ddi_devid_compare(ddi_devid_t id1, ddi_devid_t id2); 1920 1921 int 1922 ddi_devid_scsi_encode(int version, char *driver_name, 1923 uchar_t *inq, size_t inq_len, uchar_t *inq80, size_t inq80_len, 1924 uchar_t *inq83, size_t inq83_len, ddi_devid_t *ret_devid); 1925 1926 char 1927 *ddi_devid_to_guid(ddi_devid_t devid); 1928 1929 void 1930 ddi_devid_free_guid(char *guid); 1931 1932 int 1933 ddi_lyr_get_devid(dev_t dev, ddi_devid_t *ret_devid); 1934 1935 int 1936 ddi_lyr_get_minor_name(dev_t dev, int spec_type, char **minor_name); 1937 1938 int 1939 ddi_lyr_devid_to_devlist(ddi_devid_t devid, char *minor_name, int *retndevs, 1940 dev_t **retdevs); 1941 1942 void 1943 ddi_lyr_free_devlist(dev_t *devlist, int ndevs); 1944 1945 char * 1946 ddi_devid_str_encode(ddi_devid_t devid, char *minor_name); 1947 1948 int 1949 ddi_devid_str_decode(char *devidstr, ddi_devid_t *devidp, char **minor_namep); 1950 1951 void 1952 ddi_devid_str_free(char *devidstr); 1953 1954 int 1955 ddi_devid_str_compare(char *id1_str, char *id2_str); 1956 1957 /* 1958 * Event to post to when a devinfo node is removed. 1959 */ 1960 #define DDI_DEVI_REMOVE_EVENT "DDI:DEVI_REMOVE" 1961 #define DDI_DEVI_INSERT_EVENT "DDI:DEVI_INSERT" 1962 #define DDI_DEVI_BUS_RESET_EVENT "DDI:DEVI_BUS_RESET" 1963 #define DDI_DEVI_DEVICE_RESET_EVENT "DDI:DEVI_DEVICE_RESET" 1964 1965 /* 1966 * Invoke bus nexus driver's implementation of the 1967 * (*bus_remove_eventcall)() interface to remove a registered 1968 * callback handler for "event". 1969 */ 1970 int 1971 ddi_remove_event_handler(ddi_callback_id_t id); 1972 1973 /* 1974 * Invoke bus nexus driver's implementation of the 1975 * (*bus_add_eventcall)() interface to register a callback handler 1976 * for "event". 1977 */ 1978 int 1979 ddi_add_event_handler(dev_info_t *dip, ddi_eventcookie_t event, 1980 void (*handler)(dev_info_t *, ddi_eventcookie_t, void *, void *), 1981 void *arg, ddi_callback_id_t *id); 1982 1983 /* 1984 * Return a handle for event "name" by calling up the device tree 1985 * hierarchy via (*bus_get_eventcookie)() interface until claimed 1986 * by a bus nexus or top of dev_info tree is reached. 1987 */ 1988 int 1989 ddi_get_eventcookie(dev_info_t *dip, char *name, 1990 ddi_eventcookie_t *event_cookiep); 1991 1992 /* 1993 * log a system event 1994 */ 1995 int 1996 ddi_log_sysevent(dev_info_t *dip, char *vendor, char *class_name, 1997 char *subclass_name, nvlist_t *attr_list, sysevent_id_t *eidp, 1998 int sleep_flag); 1999 2000 /* 2001 * ddi_log_sysevent() vendors 2002 */ 2003 #define DDI_VENDOR_SUNW "SUNW" 2004 2005 /* 2006 * Opaque task queue handle. 2007 */ 2008 typedef struct ddi_taskq ddi_taskq_t; 2009 2010 /* 2011 * Use default system priority. 2012 */ 2013 #define TASKQ_DEFAULTPRI -1 2014 2015 /* 2016 * Create a task queue 2017 */ 2018 ddi_taskq_t *ddi_taskq_create(dev_info_t *dip, const char *name, 2019 int nthreads, pri_t pri, uint_t cflags); 2020 2021 /* 2022 * destroy a task queue 2023 */ 2024 void ddi_taskq_destroy(ddi_taskq_t *tq); 2025 2026 /* 2027 * Dispatch a task to a task queue 2028 */ 2029 int ddi_taskq_dispatch(ddi_taskq_t *tq, void (* func)(void *), 2030 void *arg, uint_t dflags); 2031 2032 /* 2033 * Wait for all previously scheduled tasks to complete. 2034 */ 2035 void ddi_taskq_wait(ddi_taskq_t *tq); 2036 2037 /* 2038 * Suspend all task execution. 2039 */ 2040 void ddi_taskq_suspend(ddi_taskq_t *tq); 2041 2042 /* 2043 * Resume task execution. 2044 */ 2045 void ddi_taskq_resume(ddi_taskq_t *tq); 2046 2047 /* 2048 * Is task queue suspended? 2049 */ 2050 boolean_t ddi_taskq_suspended(ddi_taskq_t *tq); 2051 2052 /* 2053 * Parse an interface name of the form <alphanumeric>##<numeric> where 2054 * <numeric> is maximal. 2055 */ 2056 int ddi_parse(const char *, char *, uint_t *); 2057 2058 #endif /* _KERNEL */ 2059 2060 #ifdef __cplusplus 2061 } 2062 #endif 2063 2064 #endif /* _SYS_SUNDDI_H */ 2065