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