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