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