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