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