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