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