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