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