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