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