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