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