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