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