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