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