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