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