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