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