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