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