xref: /titanic_41/usr/src/uts/common/sys/ddi_impldefs.h (revision 03494a9880d80f834bec10a1e8f0a2f8f7c97bf4)
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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_DDI_IMPLDEFS_H
27 #define	_SYS_DDI_IMPLDEFS_H
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/t_lock.h>
32 #include <sys/ddipropdefs.h>
33 #include <sys/devops.h>
34 #include <sys/autoconf.h>
35 #include <sys/mutex.h>
36 #include <vm/page.h>
37 #include <sys/dacf_impl.h>
38 #include <sys/ndifm.h>
39 #include <sys/epm.h>
40 #include <sys/ddidmareq.h>
41 #include <sys/ddi_intr.h>
42 #include <sys/ddi_isa.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 /*
49  * The device id implementation has been switched to be based on properties.
50  * For compatibility with di_devid libdevinfo interface the following
51  * must be defined:
52  */
53 #define	DEVID_COMPATIBILITY	((ddi_devid_t)-1)
54 
55 /*
56  * Definitions for node class.
57  * DDI_NC_PROM: a node with a nodeid that may be used in a promif call.
58  * DDI_NC_PSEUDO: a software created node with a software assigned nodeid.
59  */
60 typedef enum {
61 	DDI_NC_PROM = 0,
62 	DDI_NC_PSEUDO
63 } ddi_node_class_t;
64 
65 /*
66  * Definitions for generic callback mechanism.
67  */
68 typedef enum {
69 	DDI_CB_INTR_ADD,
70 	DDI_CB_INTR_REMOVE
71 } ddi_cb_action_t;
72 
73 typedef enum {
74 	DDI_CB_FLAG_INTR = 0x1
75 } ddi_cb_flags_t;
76 
77 #define	DDI_CB_FLAG_VALID(f)	((f) & DDI_CB_FLAG_INTR)
78 
79 typedef int	(*ddi_cb_func_t)(dev_info_t *dip, ddi_cb_action_t action,
80 		    void *cbarg, void *arg1, void *arg2);
81 
82 typedef struct ddi_cb {
83 	uint64_t	cb_flags;
84 	dev_info_t	*cb_dip;
85 	ddi_cb_func_t	cb_func;
86 	void		*cb_arg1;
87 	void		*cb_arg2;
88 } ddi_cb_t;
89 
90 /*
91  * dev_info:	The main device information structure this is intended to be
92  *		opaque to drivers and drivers should use ddi functions to
93  *		access *all* driver accessible fields.
94  *
95  * devi_parent_data includes property lists (interrupts, registers, etc.)
96  * devi_driver_data includes whatever the driver wants to place there.
97  */
98 struct devinfo_audit;
99 
100 typedef struct devi_port {
101 	union {
102 		struct {
103 			uint32_t type;
104 			uint32_t pad;
105 		} port;
106 		uint64_t type64;
107 	} info;
108 	void	 *priv_p;
109 } devi_port_t;
110 
111 typedef struct devi_bus_priv {
112 	devi_port_t port_up;
113 	devi_port_t port_down;
114 } devi_bus_priv_t;
115 
116 struct iommulib_unit;
117 typedef struct iommulib_unit *iommulib_handle_t;
118 
119 struct dev_info  {
120 
121 	struct dev_info *devi_parent;	/* my parent node in tree	*/
122 	struct dev_info *devi_child;	/* my child list head		*/
123 	struct dev_info *devi_sibling;	/* next element on my level	*/
124 
125 	char	*devi_binding_name;	/* name used to bind driver:	*/
126 					/* shared storage, points to	*/
127 					/* devi_node_name, devi_compat_names */
128 					/* or devi_rebinding_name	*/
129 
130 	char	*devi_addr;		/* address part of name		*/
131 
132 	int	devi_nodeid;		/* device nodeid		*/
133 	int	devi_instance;		/* device instance number	*/
134 
135 	struct dev_ops *devi_ops;	/* driver operations		*/
136 
137 	void	*devi_parent_data;	/* parent private data		*/
138 	void	*devi_driver_data;	/* driver private data		*/
139 
140 	ddi_prop_t *devi_drv_prop_ptr;	/* head of driver prop list */
141 	ddi_prop_t *devi_sys_prop_ptr;	/* head of system prop list */
142 
143 	struct ddi_minor_data *devi_minor;	/* head of minor list */
144 	struct dev_info *devi_next;	/* Next instance of this device */
145 	kmutex_t devi_lock;		/* Protects per-devinfo data */
146 
147 	/* logical parents for busop primitives	 */
148 
149 	struct dev_info *devi_bus_map_fault;	/* bus_map_fault parent	 */
150 	struct dev_info *devi_bus_dma_map;	/* bus_dma_map parent	 */
151 	struct dev_info *devi_bus_dma_allochdl; /* bus_dma_newhdl parent */
152 	struct dev_info *devi_bus_dma_freehdl;  /* bus_dma_freehdl parent */
153 	struct dev_info *devi_bus_dma_bindhdl;  /* bus_dma_bindhdl parent */
154 	struct dev_info *devi_bus_dma_unbindhdl; /* bus_dma_unbindhdl parent */
155 	struct dev_info *devi_bus_dma_flush;    /* bus_dma_flush parent	 */
156 	struct dev_info *devi_bus_dma_win;	/* bus_dma_win parent	 */
157 	struct dev_info *devi_bus_dma_ctl;	/* bus_dma_ctl parent	 */
158 	struct dev_info	*devi_bus_ctl;		/* bus_ctl parent	 */
159 
160 	ddi_prop_t *devi_hw_prop_ptr;		/* head of hw prop list */
161 
162 	char	*devi_node_name;		/* The 'name' of the node */
163 	char	*devi_compat_names;		/* A list of driver names */
164 	size_t	devi_compat_length;		/* Size of compat_names */
165 
166 	int (*devi_bus_dma_bindfunc)(dev_info_t *, dev_info_t *,
167 	    ddi_dma_handle_t, struct ddi_dma_req *, ddi_dma_cookie_t *,
168 	    uint_t *);
169 	int (*devi_bus_dma_unbindfunc)(dev_info_t *, dev_info_t *,
170 	    ddi_dma_handle_t);
171 
172 	char		*devi_devid_str;	/* registered device id */
173 
174 	/*
175 	 * power management entries
176 	 * components exist even if the device is not currently power managed
177 	 */
178 	struct pm_info *devi_pm_info;		/* 0 => dev not power managed */
179 	uint_t		devi_pm_flags;		/* pm flags */
180 	int		devi_pm_num_components;	/* number of components */
181 	size_t		devi_pm_comp_size;	/* size of devi_components */
182 	struct pm_component *devi_pm_components; /* array of pm components */
183 	struct dev_info *devi_pm_ppm;		/* ppm attached to this one */
184 	void		*devi_pm_ppm_private;	/* for use by ppm driver */
185 	int		devi_pm_dev_thresh;	/* "device" threshold */
186 	uint_t		devi_pm_kidsupcnt;	/* # of kids powered up */
187 	struct pm_scan	*devi_pm_scan;		/* pm scan info */
188 	uint_t		devi_pm_noinvolpm;	/* # of descendents no-invol */
189 	uint_t		devi_pm_volpmd;		/* # of voluntarily pm'ed */
190 	kmutex_t	devi_pm_lock;		/* pm lock for state */
191 	kmutex_t	devi_pm_busy_lock;	/* for component busy count */
192 
193 	uint_t		devi_state;		/* device/bus state flags */
194 						/* see below for definitions */
195 	kcondvar_t	devi_cv;		/* cv */
196 	int		devi_ref;		/* reference count */
197 
198 	dacf_rsrvlist_t *devi_dacf_tasks;	/* dacf reservation queue */
199 
200 	ddi_node_class_t devi_node_class;	/* Node class */
201 	int		devi_node_attributes;	/* Node attributes: See below */
202 
203 	char		*devi_device_class;
204 
205 	/*
206 	 * New mpxio kernel hooks entries
207 	 */
208 	int		devi_mdi_component;	/* mpxio component type */
209 	void		*devi_mdi_client;	/* mpxio client information */
210 	void		*devi_mdi_xhci;		/* vhci/phci info */
211 
212 	ddi_prop_list_t	*devi_global_prop_list;	/* driver global properties */
213 	major_t		devi_major;		/* driver major number */
214 	ddi_node_state_t devi_node_state;	/* state of node */
215 	uint_t		devi_flags;		/* configuration flags */
216 	int		devi_circular;		/* for recursive operations */
217 	void		*devi_busy_thread;	/* thread operating on node */
218 	void		*devi_taskq;		/* hotplug taskq */
219 
220 	/* device driver statistical and audit info */
221 	struct devinfo_audit *devi_audit;		/* last state change */
222 
223 	/*
224 	 * FMA support for resource caches and error handlers
225 	 */
226 	struct i_ddi_fmhdl	*devi_fmhdl;
227 
228 	uint_t		devi_cpr_flags;
229 
230 	/* For interrupt support */
231 	devinfo_intr_t		*devi_intr_p;
232 
233 	void		*devi_nex_pm;		/* nexus PM private */
234 
235 	char		*devi_addr_buf;		/* buffer for devi_addr */
236 
237 	char		*devi_rebinding_name;	/* binding_name of rebind */
238 
239 	/* For device contracts that have this dip's minor node as resource */
240 	kmutex_t	devi_ct_lock;		/* contract lock */
241 	kcondvar_t	devi_ct_cv;		/* contract cv */
242 	int		devi_ct_count;		/* # of outstanding responses */
243 	int		devi_ct_neg;		/* neg. occurred on dip */
244 	list_t		devi_ct;
245 
246 	/* owned by bus framework */
247 	devi_bus_priv_t	devi_bus;		/* bus private data */
248 
249 	/* Declarations of the pure dynamic properties to snapshot */
250 	struct i_ddi_prop_dyn	*devi_prop_dyn_driver;	/* prop_op */
251 	struct i_ddi_prop_dyn	*devi_prop_dyn_parent;	/* bus_prop_op */
252 
253 	/* For intel iommu support */
254 	void		*devi_iommu_private;
255 
256 	/* IOMMU handle */
257 	iommulib_handle_t	devi_iommulib_handle;
258 
259 	/* Generic callback mechanism */
260 	ddi_cb_t	*devi_cb_p;
261 };
262 
263 #define	DEVI(dev_info_type)	((struct dev_info *)(dev_info_type))
264 
265 /*
266  * NB: The 'name' field, for compatibility with old code (both existing
267  * device drivers and userland code), is now defined as the name used
268  * to bind the node to a device driver, and not the device node name.
269  * If the device node name does not define a binding to a device driver,
270  * and the framework uses a different algorithm to create the binding to
271  * the driver, the node name and binding name will be different.
272  *
273  * Note that this implies that the node name plus instance number does
274  * NOT create a unique driver id; only the binding name plus instance
275  * number creates a unique driver id.
276  *
277  * New code should not use 'devi_name'; use 'devi_binding_name' or
278  * 'devi_node_name' and/or the routines that access those fields.
279  */
280 
281 #define	devi_name devi_binding_name
282 
283 /*
284  * DDI_CF1, DDI_CF2 and DDI_DRV_UNLOADED are obsolete. They are kept
285  * around to allow legacy drivers to to compile.
286  */
287 #define	DDI_CF1(devi)		(DEVI(devi)->devi_addr != NULL)
288 #define	DDI_CF2(devi)		(DEVI(devi)->devi_ops != NULL)
289 #define	DDI_DRV_UNLOADED(devi)	(DEVI(devi)->devi_ops == &mod_nodev_ops)
290 
291 /*
292  * The device state flags (devi_state) contains information regarding
293  * the state of the device (Online/Offline/Down).  For bus nexus
294  * devices, the device state also contains state information regarding
295  * the state of the bus represented by this nexus node.
296  *
297  * Device state information is stored in bits [0-7], bus state in bits
298  * [8-15].
299  *
300  * NOTE: all devi_state updates should be protected by devi_lock.
301  */
302 #define	DEVI_DEVICE_OFFLINE	0x00000001
303 #define	DEVI_DEVICE_DOWN	0x00000002
304 #define	DEVI_DEVICE_DEGRADED	0x00000004
305 #define	DEVI_DEVICE_REMOVED	0x00000008 /* hardware removed */
306 
307 #define	DEVI_BUS_QUIESCED	0x00000100
308 #define	DEVI_BUS_DOWN		0x00000200
309 #define	DEVI_NDI_CONFIG		0x00000400 /* perform config when attaching */
310 
311 #define	DEVI_S_ATTACHING	0x00010000
312 #define	DEVI_S_DETACHING	0x00020000
313 #define	DEVI_S_ONLINING		0x00040000
314 #define	DEVI_S_OFFLINING	0x00080000
315 
316 #define	DEVI_S_INVOKING_DACF	0x00100000 /* busy invoking a dacf task */
317 
318 #define	DEVI_S_UNBOUND		0x00200000
319 #define	DEVI_S_REPORT		0x08000000 /* report status change */
320 
321 #define	DEVI_S_EVADD		0x10000000 /* state of devfs event */
322 #define	DEVI_S_EVREMOVE		0x20000000 /* state of devfs event */
323 #define	DEVI_S_NEED_RESET	0x40000000 /* devo_reset should be called */
324 
325 /*
326  * Device state macros.
327  * o All SET/CLR/DONE users must protect context with devi_lock.
328  * o DEVI_SET_DEVICE_ONLINE users must do his own DEVI_SET_REPORT.
329  * o DEVI_SET_DEVICE_{DOWN|DEGRADED|UP} should only be used when !OFFLINE.
330  * o DEVI_SET_DEVICE_UP clears DOWN and DEGRADED.
331  */
332 #define	DEVI_IS_DEVICE_OFFLINE(dip)					\
333 	((DEVI(dip)->devi_state & DEVI_DEVICE_OFFLINE) == DEVI_DEVICE_OFFLINE)
334 
335 #define	DEVI_SET_DEVICE_ONLINE(dip)	{				\
336 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
337 	if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) {		\
338 		mutex_exit(&DEVI(dip)->devi_lock);			\
339 		e_ddi_undegrade_finalize(dip);				\
340 		mutex_enter(&DEVI(dip)->devi_lock);			\
341 	}								\
342 	/* setting ONLINE clears DOWN, DEGRADED, OFFLINE */		\
343 	DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DOWN |			\
344 	    DEVI_DEVICE_DEGRADED | DEVI_DEVICE_OFFLINE);		\
345 	}
346 
347 #define	DEVI_SET_DEVICE_OFFLINE(dip)	{				\
348 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
349 	DEVI(dip)->devi_state |= (DEVI_DEVICE_OFFLINE | DEVI_S_REPORT);	\
350 	}
351 
352 #define	DEVI_IS_DEVICE_DOWN(dip)					\
353 	((DEVI(dip)->devi_state & DEVI_DEVICE_DOWN) == DEVI_DEVICE_DOWN)
354 
355 #define	DEVI_SET_DEVICE_DOWN(dip)	{				\
356 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
357 	ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip));				\
358 	DEVI(dip)->devi_state |= (DEVI_DEVICE_DOWN | DEVI_S_REPORT);	\
359 	}
360 
361 #define	DEVI_IS_DEVICE_DEGRADED(dip)					\
362 	((DEVI(dip)->devi_state &					\
363 	    (DEVI_DEVICE_DEGRADED|DEVI_DEVICE_DOWN)) == DEVI_DEVICE_DEGRADED)
364 
365 #define	DEVI_SET_DEVICE_DEGRADED(dip)	{				\
366 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
367 	ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip));				\
368 	mutex_exit(&DEVI(dip)->devi_lock);				\
369 	e_ddi_degrade_finalize(dip);					\
370 	mutex_enter(&DEVI(dip)->devi_lock);				\
371 	DEVI(dip)->devi_state |= (DEVI_DEVICE_DEGRADED | DEVI_S_REPORT); \
372 	}
373 
374 #define	DEVI_SET_DEVICE_UP(dip)		{				\
375 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
376 	ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip));				\
377 	if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) {		\
378 		mutex_exit(&DEVI(dip)->devi_lock);			\
379 		e_ddi_undegrade_finalize(dip);				\
380 		mutex_enter(&DEVI(dip)->devi_lock);			\
381 	}								\
382 	DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DEGRADED | DEVI_DEVICE_DOWN); \
383 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
384 	}
385 
386 /* Device removal and insertion */
387 #define	DEVI_IS_DEVICE_REMOVED(dip)					\
388 	((DEVI(dip)->devi_state & DEVI_DEVICE_REMOVED) == DEVI_DEVICE_REMOVED)
389 
390 #define	DEVI_SET_DEVICE_REMOVED(dip)	{				\
391 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
392 	DEVI(dip)->devi_state |= DEVI_DEVICE_REMOVED;			\
393 	}
394 
395 #define	DEVI_SET_DEVICE_REINSERTED(dip)	{				\
396 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
397 	DEVI(dip)->devi_state &= ~DEVI_DEVICE_REMOVED;			\
398 	}
399 
400 /* Bus state change macros */
401 #define	DEVI_IS_BUS_QUIESCED(dip)					\
402 	((DEVI(dip)->devi_state & DEVI_BUS_QUIESCED) == DEVI_BUS_QUIESCED)
403 
404 #define	DEVI_SET_BUS_ACTIVE(dip)	{				\
405 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
406 	DEVI(dip)->devi_state &= ~DEVI_BUS_QUIESCED;			\
407 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
408 	}
409 
410 #define	DEVI_SET_BUS_QUIESCE(dip)	{				\
411 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
412 	DEVI(dip)->devi_state |= (DEVI_BUS_QUIESCED | DEVI_S_REPORT);	\
413 	}
414 
415 #define	DEVI_IS_BUS_DOWN(dip)						\
416 	((DEVI(dip)->devi_state & DEVI_BUS_DOWN) == DEVI_BUS_DOWN)
417 
418 #define	DEVI_SET_BUS_UP(dip)		{				\
419 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
420 	DEVI(dip)->devi_state &= ~DEVI_BUS_DOWN;			\
421 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
422 	}
423 
424 #define	DEVI_SET_BUS_DOWN(dip)		{				\
425 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
426 	DEVI(dip)->devi_state |= (DEVI_BUS_DOWN | DEVI_S_REPORT);	\
427 	}
428 
429 /* Status change report needed */
430 #define	DEVI_NEED_REPORT(dip)						\
431 	((DEVI(dip)->devi_state & DEVI_S_REPORT) == DEVI_S_REPORT)
432 
433 #define	DEVI_SET_REPORT(dip)		{				\
434 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
435 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
436 	}
437 
438 #define	DEVI_REPORT_DONE(dip)		{				\
439 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
440 	DEVI(dip)->devi_state &= ~DEVI_S_REPORT;			\
441 	}
442 
443 /* Do an NDI_CONFIG for its children */
444 #define	DEVI_NEED_NDI_CONFIG(dip)					\
445 	((DEVI(dip)->devi_state & DEVI_NDI_CONFIG) == DEVI_NDI_CONFIG)
446 
447 #define	DEVI_SET_NDI_CONFIG(dip)	{				\
448 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
449 	DEVI(dip)->devi_state |= DEVI_NDI_CONFIG;			\
450 	}
451 
452 #define	DEVI_CLR_NDI_CONFIG(dip)	{				\
453 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
454 	DEVI(dip)->devi_state &= ~DEVI_NDI_CONFIG;			\
455 	}
456 
457 /* Attaching or detaching state */
458 #define	DEVI_IS_ATTACHING(dip)						\
459 	((DEVI(dip)->devi_state & DEVI_S_ATTACHING) == DEVI_S_ATTACHING)
460 
461 #define	DEVI_SET_ATTACHING(dip)		{				\
462 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
463 	DEVI(dip)->devi_state |= DEVI_S_ATTACHING;			\
464 	}
465 
466 #define	DEVI_CLR_ATTACHING(dip)		{				\
467 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
468 	DEVI(dip)->devi_state &= ~DEVI_S_ATTACHING;			\
469 	}
470 
471 #define	DEVI_IS_DETACHING(dip)						\
472 	((DEVI(dip)->devi_state & DEVI_S_DETACHING) == DEVI_S_DETACHING)
473 
474 #define	DEVI_SET_DETACHING(dip)		{				\
475 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
476 	DEVI(dip)->devi_state |= DEVI_S_DETACHING;			\
477 	}
478 
479 #define	DEVI_CLR_DETACHING(dip)		{				\
480 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
481 	DEVI(dip)->devi_state &= ~DEVI_S_DETACHING;			\
482 	}
483 
484 /* Onlining or offlining state */
485 #define	DEVI_IS_ONLINING(dip)						\
486 	((DEVI(dip)->devi_state & DEVI_S_ONLINING) == DEVI_S_ONLINING)
487 
488 #define	DEVI_SET_ONLINING(dip)		{				\
489 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
490 	DEVI(dip)->devi_state |= DEVI_S_ONLINING;			\
491 	}
492 
493 #define	DEVI_CLR_ONLINING(dip)		{				\
494 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
495 	DEVI(dip)->devi_state &= ~DEVI_S_ONLINING;			\
496 	}
497 
498 #define	DEVI_IS_OFFLINING(dip)						\
499 	((DEVI(dip)->devi_state & DEVI_S_OFFLINING) == DEVI_S_OFFLINING)
500 
501 #define	DEVI_SET_OFFLINING(dip)		{				\
502 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
503 	DEVI(dip)->devi_state |= DEVI_S_OFFLINING;			\
504 	}
505 
506 #define	DEVI_CLR_OFFLINING(dip)		{				\
507 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
508 	DEVI(dip)->devi_state &= ~DEVI_S_OFFLINING;			\
509 	}
510 
511 #define	DEVI_IS_IN_RECONFIG(dip)					\
512 	(DEVI(dip)->devi_state & (DEVI_S_OFFLINING | DEVI_S_ONLINING))
513 
514 /* Busy invoking a dacf task against this node */
515 #define	DEVI_IS_INVOKING_DACF(dip)					\
516 	((DEVI(dip)->devi_state & DEVI_S_INVOKING_DACF) == DEVI_S_INVOKING_DACF)
517 
518 #define	DEVI_SET_INVOKING_DACF(dip)	{				\
519 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
520 	DEVI(dip)->devi_state |= DEVI_S_INVOKING_DACF;			\
521 	}
522 
523 #define	DEVI_CLR_INVOKING_DACF(dip)	{				\
524 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
525 	DEVI(dip)->devi_state &= ~DEVI_S_INVOKING_DACF;			\
526 	}
527 
528 /* Events for add/remove */
529 #define	DEVI_EVADD(dip)							\
530 	((DEVI(dip)->devi_state & DEVI_S_EVADD) == DEVI_S_EVADD)
531 
532 #define	DEVI_SET_EVADD(dip)		{				\
533 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
534 	DEVI(dip)->devi_state &= ~DEVI_S_EVREMOVE;			\
535 	DEVI(dip)->devi_state |= DEVI_S_EVADD;				\
536 	}
537 
538 #define	DEVI_EVREMOVE(dip)						\
539 	((DEVI(dip)->devi_state & DEVI_S_EVREMOVE) == DEVI_S_EVREMOVE)
540 
541 #define	DEVI_SET_EVREMOVE(dip)		{				\
542 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
543 	DEVI(dip)->devi_state &= ~DEVI_S_EVADD;				\
544 	DEVI(dip)->devi_state |= DEVI_S_EVREMOVE;			\
545 	}
546 
547 #define	DEVI_SET_EVUNINIT(dip)		{				\
548 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
549 	DEVI(dip)->devi_state &= ~(DEVI_S_EVADD | DEVI_S_EVREMOVE);	\
550 	}
551 
552 /* Need to call the devo_reset entry point for this device at shutdown */
553 #define	DEVI_NEED_RESET(dip)						\
554 	((DEVI(dip)->devi_state & DEVI_S_NEED_RESET) == DEVI_S_NEED_RESET)
555 
556 #define	DEVI_SET_NEED_RESET(dip)	{				\
557 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
558 	DEVI(dip)->devi_state |= DEVI_S_NEED_RESET;			\
559 	}
560 
561 #define	DEVI_CLR_NEED_RESET(dip)	{				\
562 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
563 	DEVI(dip)->devi_state &= ~DEVI_S_NEED_RESET;			\
564 	}
565 
566 /*
567  * devi_flags bits
568  *
569  * NOTE: all devi_state updates should be protected by devi_lock.
570  */
571 #define	DEVI_BUSY		0x00000001 /* busy configuring children */
572 #define	DEVI_MADE_CHILDREN	0x00000002 /* children made from specs */
573 #define	DEVI_ATTACHED_CHILDREN	0x00000004 /* attached all existing children */
574 #define	DEVI_BRANCH_HELD	0x00000008 /* branch rooted at this dip held */
575 #define	DEVI_NO_BIND		0x00000010 /* prevent driver binding */
576 #define	DEVI_REGISTERED_DEVID	0x00000020 /* device registered a devid */
577 #define	DEVI_PHCI_SIGNALS_VHCI	0x00000040 /* pHCI ndi_devi_exit signals vHCI */
578 #define	DEVI_REBIND		0x00000080 /* post initchild driver rebind */
579 #define	DEVI_RETIRED		0x00000100 /* device is retired */
580 #define	DEVI_RETIRING		0x00000200 /* being evaluated for retire */
581 #define	DEVI_R_CONSTRAINT	0x00000400 /* constraints have been applied  */
582 #define	DEVI_R_BLOCKED		0x00000800 /* constraints block retire  */
583 #define	DEVI_CT_NOP		0x00001000 /*  NOP contract event occurred */
584 
585 #define	DEVI_BUSY_CHANGING(dip)	(DEVI(dip)->devi_flags & DEVI_BUSY)
586 #define	DEVI_BUSY_OWNED(dip)	(DEVI_BUSY_CHANGING(dip) &&	\
587 	((DEVI(dip))->devi_busy_thread == curthread))
588 
589 char	*i_ddi_devi_class(dev_info_t *);
590 int	i_ddi_set_devi_class(dev_info_t *, char *, int);
591 
592 /*
593  * This structure represents one piece of bus space occupied by a given
594  * device. It is used in an array for devices with multiple address windows.
595  */
596 struct regspec {
597 	uint_t regspec_bustype;		/* cookie for bus type it's on */
598 	uint_t regspec_addr;		/* address of reg relative to bus */
599 	uint_t regspec_size;		/* size of this register set */
600 };
601 
602 /*
603  * This structure represents one piece of nexus bus space.
604  * It is used in an array for nexi with multiple bus spaces
605  * to define the childs offsets in the parents bus space.
606  */
607 struct rangespec {
608 	uint_t rng_cbustype;		/* Child's address, hi order */
609 	uint_t rng_coffset;		/* Child's address, lo order */
610 	uint_t rng_bustype;		/* Parent's address, hi order */
611 	uint_t rng_offset;		/* Parent's address, lo order */
612 	uint_t rng_size;		/* size of space for this entry */
613 };
614 
615 #ifdef _KERNEL
616 
617 typedef enum {
618 	DDI_PRE = 0,
619 	DDI_POST = 1
620 } ddi_pre_post_t;
621 
622 /*
623  * This structure represents notification of a child attach event
624  * These could both be the same if attach/detach commands were in the
625  * same name space.
626  * Note that the target dip is passed as an arg already.
627  */
628 struct attachspec {
629 	ddi_attach_cmd_t cmd;	/* type of event */
630 	ddi_pre_post_t	when;	/* one of DDI_PRE or DDI_POST */
631 	dev_info_t	*pdip;	/* parent of attaching node */
632 	int		result;	/* result of attach op (post command only) */
633 };
634 
635 /*
636  * This structure represents notification of a child detach event
637  * Note that the target dip is passed as an arg already.
638  */
639 struct detachspec {
640 	ddi_detach_cmd_t cmd;	/* type of event */
641 	ddi_pre_post_t	when;	/* one of DDI_PRE or DDI_POST */
642 	dev_info_t	*pdip;	/* parent of detaching node */
643 	int		result;	/* result of detach op (post command only) */
644 };
645 
646 #endif /* _KERNEL */
647 
648 typedef enum {
649 	DDM_MINOR = 0,
650 	DDM_ALIAS,
651 	DDM_DEFAULT,
652 	DDM_INTERNAL_PATH
653 } ddi_minor_type;
654 
655 /* implementation flags for driver specified device access control */
656 #define	DM_NO_FSPERM	0x1
657 
658 struct devplcy;
659 
660 struct ddi_minor {
661 	char		*name;		/* name of node */
662 	dev_t		dev;		/* device number */
663 	int		spec_type;	/* block or char */
664 	int		flags;		/* access flags */
665 	char		*node_type;	/* block, byte, serial, network */
666 	struct devplcy	*node_priv;	/* privilege for this minor */
667 	mode_t		priv_mode;	/* default apparent privilege mode */
668 };
669 
670 /*
671  * devi_node_attributes contains node attributes private to the
672  * ddi implementation. As a consumer, do not use these bit definitions
673  * directly, use the ndi functions that check for the existence of the
674  * specific node attributes.
675  *
676  * DDI_PERSISTENT indicates a 'persistent' node; one that is not
677  * automatically freed by the framework if the driver is unloaded
678  * or the driver fails to attach to this node.
679  *
680  * DDI_AUTO_ASSIGNED_NODEID indicates that the nodeid was auto-assigned
681  * by the framework and should be auto-freed if the node is removed.
682  *
683  * DDI_VHCI_NODE indicates that the node type is VHCI. This flag
684  * must be set by ndi_devi_config_vhci() routine only.
685  */
686 #define	DDI_PERSISTENT			0x01
687 #define	DDI_AUTO_ASSIGNED_NODEID	0x02
688 #define	DDI_VHCI_NODE			0x04
689 
690 #define	DEVI_VHCI_NODE(dip)						\
691 	(DEVI(dip)->devi_node_attributes & DDI_VHCI_NODE)
692 
693 /*
694  * The ddi_minor_data structure gets filled in by ddi_create_minor_node.
695  * It then gets attached to the devinfo node as a property.
696  */
697 struct ddi_minor_data {
698 	struct ddi_minor_data *next;	/* next one in the chain */
699 	dev_info_t	*dip;		/* pointer to devinfo node */
700 	ddi_minor_type	type;		/* Following data type */
701 	struct ddi_minor d_minor;	/* Actual minor node data */
702 };
703 
704 #define	ddm_name	d_minor.name
705 #define	ddm_dev		d_minor.dev
706 #define	ddm_flags	d_minor.flags
707 #define	ddm_spec_type	d_minor.spec_type
708 #define	ddm_node_type	d_minor.node_type
709 #define	ddm_node_priv	d_minor.node_priv
710 #define	ddm_priv_mode	d_minor.priv_mode
711 
712 /*
713  * parent private data structure contains register, interrupt, property
714  * and range information.
715  */
716 struct ddi_parent_private_data {
717 	int par_nreg;			/* number of regs */
718 	struct regspec *par_reg;	/* array of regs */
719 	int par_nintr;			/* number of interrupts */
720 	struct intrspec *par_intr;	/* array of possible interrupts */
721 	int par_nrng;			/* number of ranges */
722 	struct rangespec *par_rng;	/* array of ranges */
723 };
724 #define	DEVI_PD(d)	\
725 	((struct ddi_parent_private_data *)DEVI((d))->devi_parent_data)
726 
727 #define	sparc_pd_getnreg(dev)		(DEVI_PD(dev)->par_nreg)
728 #define	sparc_pd_getnintr(dev)		(DEVI_PD(dev)->par_nintr)
729 #define	sparc_pd_getnrng(dev)		(DEVI_PD(dev)->par_nrng)
730 #define	sparc_pd_getreg(dev, n)		(&DEVI_PD(dev)->par_reg[(n)])
731 #define	sparc_pd_getintr(dev, n)	(&DEVI_PD(dev)->par_intr[(n)])
732 #define	sparc_pd_getrng(dev, n)		(&DEVI_PD(dev)->par_rng[(n)])
733 
734 /*
735  * This data structure is entirely private to the soft state allocator.
736  */
737 struct i_ddi_soft_state {
738 	void		**array;	/* the array of pointers */
739 	kmutex_t	lock;	/* serialize access to this struct */
740 	size_t		size;	/* how many bytes per state struct */
741 	size_t		n_items;	/* how many structs herein */
742 	struct i_ddi_soft_state *next;	/* 'dirty' elements */
743 };
744 
745 /*
746  * Solaris DDI DMA implementation structure and function definitions.
747  *
748  * Note: no callers of DDI functions must depend upon data structures
749  * declared below. They are not guaranteed to remain constant.
750  */
751 
752 /*
753  * Implementation DMA mapping structure.
754  *
755  * The publicly visible ddi_dma_req structure is filled
756  * in by a caller that wishes to map a memory object
757  * for DMA. Internal to this implementation of the public
758  * DDI DMA functions this request structure is put together
759  * with bus nexus specific functions that have additional
760  * information and constraints as to how to go about doing
761  * the requested mapping function
762  *
763  * In this implementation, some of the information from the
764  * original requester is retained throughout the lifetime
765  * of the I/O mapping being active.
766  */
767 
768 /*
769  * This is the implementation specific description
770  * of how we've mapped an object for DMA.
771  */
772 #if defined(__sparc)
773 typedef struct ddi_dma_impl {
774 	/*
775 	 * DMA mapping information
776 	 */
777 	ulong_t	dmai_mapping;	/* mapping cookie */
778 
779 	/*
780 	 * Size of the current mapping, in bytes.
781 	 *
782 	 * Note that this is distinct from the size of the object being mapped
783 	 * for DVMA. We might have only a portion of the object mapped at any
784 	 * given point in time.
785 	 */
786 	uint_t	dmai_size;
787 
788 	/*
789 	 * Offset, in bytes, into object that is currently mapped.
790 	 */
791 	off_t	dmai_offset;
792 
793 	/*
794 	 * Information gathered from the original DMA mapping
795 	 * request and saved for the lifetime of the mapping.
796 	 */
797 	uint_t		dmai_minxfer;
798 	uint_t		dmai_burstsizes;
799 	uint_t		dmai_ndvmapages;
800 	uint_t		dmai_pool;	/* cached DVMA space */
801 	uint_t		dmai_rflags;	/* requester's flags + ours */
802 	uint_t		dmai_inuse;	/* active handle? */
803 	uint_t		dmai_nwin;
804 	uint_t		dmai_winsize;
805 	caddr_t		dmai_nexus_private;
806 	void		*dmai_iopte;
807 	uint_t		*dmai_sbi;
808 	void		*dmai_minfo;	/* random mapping information */
809 	dev_info_t	*dmai_rdip;	/* original requester's dev_info_t */
810 	ddi_dma_obj_t	dmai_object;	/* requester's object */
811 	ddi_dma_attr_t	dmai_attr;	/* DMA attributes */
812 	ddi_dma_cookie_t *dmai_cookie;	/* pointer to first DMA cookie */
813 
814 	int		(*dmai_fault_check)(struct ddi_dma_impl *handle);
815 	void		(*dmai_fault_notify)(struct ddi_dma_impl *handle);
816 	int		dmai_fault;
817 	ndi_err_t	dmai_error;
818 
819 } ddi_dma_impl_t;
820 
821 #elif defined(__x86)
822 
823 /*
824  * ddi_dma_impl portion that genunix (sunddi.c) depends on. x86 rootnex
825  * implementation specific state is in dmai_private.
826  */
827 typedef struct ddi_dma_impl {
828 	ddi_dma_cookie_t *dmai_cookie; /* array of DMA cookies */
829 	void		*dmai_private;
830 
831 	/*
832 	 * Information gathered from the original dma mapping
833 	 * request and saved for the lifetime of the mapping.
834 	 */
835 	uint_t		dmai_minxfer;
836 	uint_t		dmai_burstsizes;
837 	uint_t		dmai_rflags;	/* requester's flags + ours */
838 	int		dmai_nwin;
839 	dev_info_t	*dmai_rdip;	/* original requester's dev_info_t */
840 
841 	ddi_dma_attr_t	dmai_attr;	/* DMA attributes */
842 
843 	int		(*dmai_fault_check)(struct ddi_dma_impl *handle);
844 	void		(*dmai_fault_notify)(struct ddi_dma_impl *handle);
845 	int		dmai_fault;
846 	ndi_err_t	dmai_error;
847 } ddi_dma_impl_t;
848 
849 #else
850 #error "struct ddi_dma_impl not defined for this architecture"
851 #endif  /* defined(__sparc) */
852 
853 /*
854  * For now DMA segments share state with the DMA handle
855  */
856 typedef ddi_dma_impl_t ddi_dma_seg_impl_t;
857 
858 /*
859  * These flags use reserved bits from the dma request flags.
860  *
861  * A note about the DMP_NOSYNC flags: the root nexus will
862  * set these as it sees best. If an intermediate nexus
863  * actually needs these operations, then during the unwind
864  * from the call to ddi_dma_bind, the nexus driver *must*
865  * clear the appropriate flag(s). This is because, as an
866  * optimization, ddi_dma_sync(9F) looks at these flags before
867  * deciding to spend the time going back up the tree.
868  */
869 
870 #define	_DMCM1	DDI_DMA_RDWR|DDI_DMA_REDZONE|DDI_DMA_PARTIAL
871 #define	_DMCM2	DDI_DMA_CONSISTENT|DMP_VMEREQ
872 #define	DMP_DDIFLAGS	(_DMCM1|_DMCM2)
873 #define	DMP_SHADOW	0x20
874 #define	DMP_LKIOPB	0x40
875 #define	DMP_LKSYSV	0x80
876 #define	DMP_IOCACHE	0x100
877 #define	DMP_USEHAT	0x200
878 #define	DMP_PHYSADDR	0x400
879 #define	DMP_INVALID	0x800
880 #define	DMP_NOLIMIT	0x1000
881 #define	DMP_VMEREQ	0x10000000
882 #define	DMP_BYPASSNEXUS	0x20000000
883 #define	DMP_NODEVSYNC	0x40000000
884 #define	DMP_NOCPUSYNC	0x80000000
885 #define	DMP_NOSYNC	(DMP_NODEVSYNC|DMP_NOCPUSYNC)
886 
887 /*
888  * In order to complete a device to device mapping that
889  * has percolated as high as an IU nexus (gone that high
890  * because the DMA request is a VADDR type), we define
891  * structure to use with the DDI_CTLOPS_DMAPMAPC request
892  * that re-traverses the request tree to finish the
893  * DMA 'mapping' for a device.
894  */
895 struct dma_phys_mapc {
896 	struct ddi_dma_req *dma_req;	/* original request */
897 	ddi_dma_impl_t *mp;		/* current handle, or none */
898 	int nptes;			/* number of ptes */
899 	void *ptes;			/* ptes already read */
900 };
901 
902 #define	MAXCALLBACK		20
903 
904 /*
905  * Callback definitions
906  */
907 struct ddi_callback {
908 	struct ddi_callback	*c_nfree;
909 	struct ddi_callback	*c_nlist;
910 	int			(*c_call)();
911 	int			c_count;
912 	caddr_t			c_arg;
913 	size_t			c_size;
914 };
915 
916 /*
917  * Pure dynamic property declaration. A pure dynamic property is a property
918  * for which a driver's prop_op(9E) implementation will return a value on
919  * demand, but the property name does not exist on a property list (global,
920  * driver, system, or hardware) - the person asking for the value must know
921  * the name and type information.
922  *
923  * For a pure dynamic property to show up in a di_init() devinfo shapshot, the
924  * devinfo driver must know name and type. The i_ddi_prop_dyn_t mechanism
925  * allows a driver to define an array of the name/type information of its
926  * dynamic properties. When a driver declares its dynamic properties in a
927  * i_ddi_prop_dyn_t array, and registers that array using
928  * i_ddi_prop_dyn_driver_set() the devinfo driver has sufficient information
929  * to represent the properties in a snapshot - calling the driver's
930  * prop_op(9E) to obtain values.
931  *
932  * The last element of a i_ddi_prop_dyn_t is detected via a NULL dp_name value.
933  *
934  * A pure dynamic property name associated with a minor_node/dev_t should be
935  * defined with a dp_spec_type of S_IFCHR or S_IFBLK, as appropriate.  The
936  * driver's prop_op(9E) entry point will be called for all
937  * ddi_create_minor_node(9F) nodes of the specified spec_type. For a driver
938  * where not all minor_node/dev_t combinations support the same named
939  * properties, it is the responsibility of the prop_op(9E) implementation to
940  * sort out what combinations are appropriate.
941  *
942  * A pure dynamic property of a devinfo node should be defined with a
943  * dp_spec_type of 0.
944  *
945  * NB: Public DDI property interfaces no longer support pure dynamic
946  * properties, but they are still still used.  A prime example is the cmlb
947  * implementation of size(9P) properties. Using pure dynamic properties
948  * reduces the space required to maintain per-partition information. Since
949  * there are no public interfaces to create pure dynamic properties,
950  * the i_ddi_prop_dyn_t mechanism should remain private.
951  */
952 typedef struct i_ddi_prop_dyn {
953 	char	*dp_name;		/* name of dynamic property */
954 	int	dp_type;		/* DDI_PROP_TYPE_ of property */
955 	int	dp_spec_type;		/* 0, S_IFCHR, S_IFBLK */
956 } i_ddi_prop_dyn_t;
957 void			i_ddi_prop_dyn_driver_set(dev_info_t *,
958 			    i_ddi_prop_dyn_t *);
959 i_ddi_prop_dyn_t	*i_ddi_prop_dyn_driver_get(dev_info_t *);
960 void			i_ddi_prop_dyn_parent_set(dev_info_t *,
961 			    i_ddi_prop_dyn_t *);
962 i_ddi_prop_dyn_t	*i_ddi_prop_dyn_parent_get(dev_info_t *);
963 void			i_ddi_prop_dyn_cache_invalidate(dev_info_t *,
964 			    i_ddi_prop_dyn_t *);
965 
966 /*
967  * Device id - Internal definition.
968  */
969 #define	DEVID_MAGIC_MSB		0x69
970 #define	DEVID_MAGIC_LSB		0x64
971 #define	DEVID_REV_MSB		0x00
972 #define	DEVID_REV_LSB		0x01
973 #define	DEVID_HINT_SIZE		4
974 
975 typedef struct impl_devid {
976 	uchar_t	did_magic_hi;			/* device id magic # (msb) */
977 	uchar_t	did_magic_lo;			/* device id magic # (lsb) */
978 	uchar_t	did_rev_hi;			/* device id revision # (msb) */
979 	uchar_t	did_rev_lo;			/* device id revision # (lsb) */
980 	uchar_t	did_type_hi;			/* device id type (msb) */
981 	uchar_t	did_type_lo;			/* device id type (lsb) */
982 	uchar_t	did_len_hi;			/* length of devid data (msb) */
983 	uchar_t	did_len_lo;			/* length of devid data (lsb) */
984 	char	did_driver[DEVID_HINT_SIZE];	/* driver name - HINT */
985 	char	did_id[1];			/* start of device id data */
986 } impl_devid_t;
987 
988 #define	DEVID_GETTYPE(devid)		((ushort_t) \
989 					    (((devid)->did_type_hi << NBBY) + \
990 					    (devid)->did_type_lo))
991 
992 #define	DEVID_FORMTYPE(devid, type)	(devid)->did_type_hi = hibyte((type)); \
993 					(devid)->did_type_lo = lobyte((type));
994 
995 #define	DEVID_GETLEN(devid)		((ushort_t) \
996 					    (((devid)->did_len_hi << NBBY) + \
997 					    (devid)->did_len_lo))
998 
999 #define	DEVID_FORMLEN(devid, len)	(devid)->did_len_hi = hibyte((len)); \
1000 					(devid)->did_len_lo = lobyte((len));
1001 
1002 /*
1003  * Per PSARC/1995/352, a binary devid contains fields for <magic number>,
1004  * <revision>, <driver_hint>, <type>, <id_length>, and the <id> itself.
1005  * This proposal would encode the binary devid into a string consisting
1006  * of "<magic><revision>,<driver_hint>@<type><id>" as indicated below
1007  * (<id_length> is rederived from the length of the string
1008  * representation of the <id>):
1009  *
1010  *	<magic>		->"id"
1011  *
1012  *	<rev>		->"%d"	// "0" -> type of DEVID_NONE  "id0"
1013  *				// NOTE: PSARC/1995/352 <revision> is "1".
1014  *				// NOTE: support limited to 10 revisions
1015  *				//	in current implementation
1016  *
1017  *	<driver_hint>	->"%s"	// "sd"/"ssd"
1018  *				// NOTE: driver names limited to 4
1019  *				//	characters for <revision> "1"
1020  *
1021  *	<type>		->'w' |	// DEVID_SCSI3_WWN	<hex_id>
1022  *			'W' |	// DEVID_SCSI3_WWN	<ascii_id>
1023  *			't' |	// DEVID_SCSI3_VPD_T10	<hex_id>
1024  *			'T' |	// DEVID_SCSI3_VPD_T10	<ascii_id>
1025  *			'x' |	// DEVID_SCSI3_VPD_EUI	<hex_id>
1026  *			'X' |	// DEVID_SCSI3_VPD_EUI	<ascii_id>
1027  *			'n' |	// DEVID_SCSI3_VPD_NAA	<hex_id>
1028  *			'N' |	// DEVID_SCSI3_VPD_NAA	<ascii_id>
1029  *			's' |	// DEVID_SCSI_SERIAL	<hex_id>
1030  *			'S' |	// DEVID_SCSI_SERIAL	<ascii_id>
1031  *			'f' |	// DEVID_FAB		<hex_id>
1032  *			'F' |	// DEVID_FAB		<ascii_id>
1033  *			'e' |	// DEVID_ENCAP		<hex_id>
1034  *			'E' |	// DEVID_ENCAP		<ascii_id>
1035  *			'a' |	// DEVID_ATA_SERIAL	<hex_id>
1036  *			'A' |	// DEVID_ATA_SERIAL	<ascii_id>
1037  *			'u' |	// unknown		<hex_id>
1038  *			'U'	// unknown		<ascii_id>
1039  *              		// NOTE: lower case -> <hex_id>
1040  *				//       upper case -> <ascii_id>
1041  *				// NOTE: this covers all types currently
1042  *				//	defined for <revision> 1.
1043  *				// NOTE: a <type> can be added
1044  *				//	without changing the <revision>.
1045  *
1046  *	<id>		-> <ascii_id> |	// <type> is upper case
1047  *			<hex_id>	// <type> is lower case
1048  *
1049  *	<ascii_id>	// only if all bytes of binary <id> field
1050  *			// are in the set:
1051  *			//	[A-Z][a-z][0-9]+-.= and space and 0x00
1052  *			// the encoded form is:
1053  *			//	[A-Z][a-z][0-9]+-.= and _     and ~
1054  *			//          NOTE: ' ' <=> '_', 0x00 <=> '~'
1055  *			// these sets are chosen to avoid shell
1056  *			// and conflicts with DDI node names.
1057  *
1058  *	<hex_id>	// if not <ascii_id>; each byte of binary
1059  *			// <id> maps a to 2 digit ascii hex
1060  *			// representation in the string.
1061  *
1062  * This encoding provides a meaningful correlation between the /devices
1063  * path and the devid string where possible.
1064  *
1065  *   Fibre:
1066  *	sbus@6,0/SUNW,socal@d,10000/sf@1,0/ssd@w21000020370bb488,0:c,raw
1067  *      id1,ssd@w20000020370bb488:c,raw
1068  *
1069  *   Copper:
1070  *	sbus@7,0/SUNW,fas@3,8800000/sd@a,0:c
1071  *      id1,sd@SIBM_____1XY210__________:c
1072  */
1073 /* determine if a byte of an id meets ASCII representation requirements */
1074 #define	DEVID_IDBYTE_ISASCII(b)		(				\
1075 	(((b) >= 'a') && ((b) <= 'z')) ||				\
1076 	(((b) >= 'A') && ((b) <= 'Z')) ||				\
1077 	(((b) >= '0') && ((b) <= '9')) ||				\
1078 	(b == '+') || (b == '-') || (b == '.') || (b == '=') ||		\
1079 	(b == ' ') || (b == 0x00))
1080 
1081 /* set type to lower case to indicate that the did_id field is ascii */
1082 #define	DEVID_TYPE_SETASCII(c)	(c - 0x20)	/* 'a' -> 'A' */
1083 
1084 /* determine from type if did_id field is binary or ascii */
1085 #define	DEVID_TYPE_ISASCII(c)	(((c) >= 'A') && ((c) <= 'Z'))
1086 
1087 /* convert type field from binary to ascii */
1088 #define	DEVID_TYPE_BINTOASCII(b)	(				\
1089 	((b) == DEVID_SCSI3_WWN)	? 'w' :				\
1090 	((b) == DEVID_SCSI3_VPD_T10)	? 't' :				\
1091 	((b) == DEVID_SCSI3_VPD_EUI)	? 'x' :				\
1092 	((b) == DEVID_SCSI3_VPD_NAA)	? 'n' :				\
1093 	((b) == DEVID_SCSI_SERIAL)	? 's' :				\
1094 	((b) == DEVID_FAB)		? 'f' :				\
1095 	((b) == DEVID_ENCAP)		? 'e' :				\
1096 	((b) == DEVID_ATA_SERIAL)	? 'a' :				\
1097 	'u')						/* unknown */
1098 
1099 /* convert type field from ascii to binary */
1100 #define	DEVID_TYPE_ASCIITOBIN(c)	(				\
1101 	(((c) == 'w') || ((c) == 'W'))	? DEVID_SCSI3_WWN :		\
1102 	(((c) == 't') || ((c) == 'T'))	? DEVID_SCSI3_VPD_T10 :		\
1103 	(((c) == 'x') || ((c) == 'X'))	? DEVID_SCSI3_VPD_EUI :		\
1104 	(((c) == 'n') || ((c) == 'N'))	? DEVID_SCSI3_VPD_NAA :		\
1105 	(((c) == 's') || ((c) == 'S'))	? DEVID_SCSI_SERIAL :		\
1106 	(((c) == 'f') || ((c) == 'F'))	? DEVID_FAB :			\
1107 	(((c) == 'e') || ((c) == 'E'))	? DEVID_ENCAP :			\
1108 	(((c) == 'a') || ((c) == 'A'))	? DEVID_ATA_SERIAL :		\
1109 	DEVID_MAXTYPE +1)				/* unknown */
1110 
1111 /* determine if the type should be forced to hex encoding (non-ascii) */
1112 #define	DEVID_TYPE_BIN_FORCEHEX(b) (	\
1113 	((b) == DEVID_SCSI3_WWN) ||	\
1114 	((b) == DEVID_SCSI3_VPD_EUI) ||	\
1115 	((b) == DEVID_SCSI3_VPD_NAA) ||	\
1116 	((b) == DEVID_FAB))
1117 
1118 /* determine if the type is from a scsi3 vpd */
1119 #define	IS_DEVID_SCSI3_VPD_TYPE(b) (	\
1120 	((b) == DEVID_SCSI3_VPD_T10) ||	\
1121 	((b) == DEVID_SCSI3_VPD_EUI) ||	\
1122 	((b) == DEVID_SCSI3_VPD_NAA))
1123 
1124 /* convert rev field from binary to ascii (only supports 10 revs) */
1125 #define	DEVID_REV_BINTOASCII(b) (b + '0')
1126 
1127 /* convert rev field from ascii to binary (only supports 10 revs) */
1128 #define	DEVID_REV_ASCIITOBIN(c) (c - '0')
1129 
1130 /* name of devid property */
1131 #define	DEVID_PROP_NAME	"devid"
1132 
1133 /*
1134  * prop_name used by pci_{save,restore}_config_regs()
1135  */
1136 #define	SAVED_CONFIG_REGS "pci-config-regs"
1137 #define	SAVED_CONFIG_REGS_MASK "pcie-config-regs-mask"
1138 #define	SAVED_CONFIG_REGS_CAPINFO "pci-cap-info"
1139 
1140 typedef struct pci_config_header_state {
1141 	uint16_t	chs_command;
1142 	uint8_t		chs_cache_line_size;
1143 	uint8_t		chs_latency_timer;
1144 	uint8_t		chs_header_type;
1145 	uint8_t		chs_sec_latency_timer;
1146 	uint8_t		chs_bridge_control;
1147 	uint32_t	chs_base0;
1148 	uint32_t	chs_base1;
1149 	uint32_t	chs_base2;
1150 	uint32_t	chs_base3;
1151 	uint32_t	chs_base4;
1152 	uint32_t	chs_base5;
1153 } pci_config_header_state_t;
1154 
1155 #ifdef _KERNEL
1156 
1157 typedef struct pci_cap_save_desc {
1158 	uint16_t	cap_offset;
1159 	uint16_t	cap_id;
1160 	uint32_t	cap_nregs;
1161 } pci_cap_save_desc_t;
1162 
1163 typedef struct pci_cap_entry {
1164 	uint16_t		cap_id;
1165 	uint32_t		cap_ndwords;
1166 	uint32_t (*cap_save_func)(ddi_acc_handle_t confhdl, uint16_t cap_ptr,
1167 	    uint32_t *regbuf, uint32_t ndwords);
1168 } pci_cap_entry_t;
1169 
1170 #endif /* _KERNEL */
1171 
1172 #ifdef	__cplusplus
1173 }
1174 #endif
1175 
1176 #endif	/* _SYS_DDI_IMPLDEFS_H */
1177