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