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