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