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