xref: /titanic_52/usr/src/uts/common/sys/ddi_impldefs.h (revision abe68f2c9805b74afc71e9aca07688c688d7269c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5144dfaa9Scth  * Common Development and Distribution License (the "License").
6144dfaa9Scth  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2294c894bbSVikram Hegde  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23cd21e7c5SGarrett D'Amore  * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
24*abe68f2cSRobert Mustacchi  * Copyright 2016 Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_DDI_IMPLDEFS_H
287c478bd9Sstevel@tonic-gate #define	_SYS_DDI_IMPLDEFS_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
337c478bd9Sstevel@tonic-gate #include <sys/ddipropdefs.h>
347c478bd9Sstevel@tonic-gate #include <sys/devops.h>
357c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
367c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
377c478bd9Sstevel@tonic-gate #include <vm/page.h>
387c478bd9Sstevel@tonic-gate #include <sys/dacf_impl.h>
397c478bd9Sstevel@tonic-gate #include <sys/ndifm.h>
407c478bd9Sstevel@tonic-gate #include <sys/epm.h>
417c478bd9Sstevel@tonic-gate #include <sys/ddidmareq.h>
427c478bd9Sstevel@tonic-gate #include <sys/ddi_intr.h>
4326947304SEvan Yan #include <sys/ddi_hp.h>
4426947304SEvan Yan #include <sys/ddi_hp_impl.h>
457c478bd9Sstevel@tonic-gate #include <sys/ddi_isa.h>
464c06356bSdh142964 #include <sys/id_space.h>
474c06356bSdh142964 #include <sys/modhash.h>
484c06356bSdh142964 #include <sys/bitset.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
517c478bd9Sstevel@tonic-gate extern "C" {
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * The device id implementation has been switched to be based on properties.
567c478bd9Sstevel@tonic-gate  * For compatibility with di_devid libdevinfo interface the following
577c478bd9Sstevel@tonic-gate  * must be defined:
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate #define	DEVID_COMPATIBILITY	((ddi_devid_t)-1)
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Definitions for node class.
637c478bd9Sstevel@tonic-gate  * DDI_NC_PROM: a node with a nodeid that may be used in a promif call.
647c478bd9Sstevel@tonic-gate  * DDI_NC_PSEUDO: a software created node with a software assigned nodeid.
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate typedef enum {
677c478bd9Sstevel@tonic-gate 	DDI_NC_PROM = 0,
687c478bd9Sstevel@tonic-gate 	DDI_NC_PSEUDO
697c478bd9Sstevel@tonic-gate } ddi_node_class_t;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
725febcb4aSScott Carter, SD IOSW  * Definitions for generic callback mechanism.
735febcb4aSScott Carter, SD IOSW  */
745febcb4aSScott Carter, SD IOSW typedef enum {
7526947304SEvan Yan 	DDI_CB_INTR_ADD,		/* More available interrupts */
7626947304SEvan Yan 	DDI_CB_INTR_REMOVE		/* Fewer available interrupts */
775febcb4aSScott Carter, SD IOSW } ddi_cb_action_t;
785febcb4aSScott Carter, SD IOSW 
795febcb4aSScott Carter, SD IOSW typedef enum {
8026947304SEvan Yan 	DDI_CB_FLAG_INTR = 0x1		/* Driver is IRM aware */
815febcb4aSScott Carter, SD IOSW } ddi_cb_flags_t;
825febcb4aSScott Carter, SD IOSW 
835febcb4aSScott Carter, SD IOSW #define	DDI_CB_FLAG_VALID(f)	((f) & DDI_CB_FLAG_INTR)
845febcb4aSScott Carter, SD IOSW 
855febcb4aSScott Carter, SD IOSW typedef int	(*ddi_cb_func_t)(dev_info_t *dip, ddi_cb_action_t action,
865febcb4aSScott Carter, SD IOSW 		    void *cbarg, void *arg1, void *arg2);
875febcb4aSScott Carter, SD IOSW 
885febcb4aSScott Carter, SD IOSW typedef struct ddi_cb {
895febcb4aSScott Carter, SD IOSW 	uint64_t	cb_flags;
905febcb4aSScott Carter, SD IOSW 	dev_info_t	*cb_dip;
915febcb4aSScott Carter, SD IOSW 	ddi_cb_func_t	cb_func;
925febcb4aSScott Carter, SD IOSW 	void		*cb_arg1;
935febcb4aSScott Carter, SD IOSW 	void		*cb_arg2;
945febcb4aSScott Carter, SD IOSW } ddi_cb_t;
955febcb4aSScott Carter, SD IOSW 
965febcb4aSScott Carter, SD IOSW /*
977c478bd9Sstevel@tonic-gate  * dev_info:	The main device information structure this is intended to be
987c478bd9Sstevel@tonic-gate  *		opaque to drivers and drivers should use ddi functions to
997c478bd9Sstevel@tonic-gate  *		access *all* driver accessible fields.
1007c478bd9Sstevel@tonic-gate  *
1017c478bd9Sstevel@tonic-gate  * devi_parent_data includes property lists (interrupts, registers, etc.)
1027c478bd9Sstevel@tonic-gate  * devi_driver_data includes whatever the driver wants to place there.
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate struct devinfo_audit;
1057c478bd9Sstevel@tonic-gate 
106eae2e508Skrishnae typedef struct devi_port {
107eae2e508Skrishnae 	union {
108eae2e508Skrishnae 		struct {
109eae2e508Skrishnae 			uint32_t type;
110eae2e508Skrishnae 			uint32_t pad;
111eae2e508Skrishnae 		} port;
112eae2e508Skrishnae 		uint64_t type64;
113eae2e508Skrishnae 	} info;
114eae2e508Skrishnae 	void	*priv_p;
115eae2e508Skrishnae } devi_port_t;
116eae2e508Skrishnae 
117eae2e508Skrishnae typedef struct devi_bus_priv {
118eae2e508Skrishnae 	devi_port_t port_up;
119eae2e508Skrishnae 	devi_port_t port_down;
120eae2e508Skrishnae } devi_bus_priv_t;
121eae2e508Skrishnae 
12250200e77SFrank Van Der Linden #if defined(__x86)
12320906b23SVikram Hegde struct iommulib_unit;
12420906b23SVikram Hegde typedef struct iommulib_unit *iommulib_handle_t;
12550200e77SFrank Van Der Linden struct iommulib_nex;
12650200e77SFrank Van Der Linden typedef struct iommulib_nex *iommulib_nexhandle_t;
12750200e77SFrank Van Der Linden #endif
12850200e77SFrank Van Der Linden 
129255a2d50SMatthew Jacob typedef uint8_t	ndi_flavor_t;
13026947304SEvan Yan struct ddi_hp_cn_handle;
13120906b23SVikram Hegde 
13294c894bbSVikram Hegde struct in_node;
13394c894bbSVikram Hegde 
1347c478bd9Sstevel@tonic-gate struct dev_info  {
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	struct dev_info *devi_parent;	/* my parent node in tree	*/
1377c478bd9Sstevel@tonic-gate 	struct dev_info *devi_child;	/* my child list head		*/
1387c478bd9Sstevel@tonic-gate 	struct dev_info *devi_sibling;	/* next element on my level	*/
1397c478bd9Sstevel@tonic-gate 
140f4da9be0Scth 	char	*devi_binding_name;	/* name used to bind driver:	*/
141f4da9be0Scth 					/* shared storage, points to	*/
142f4da9be0Scth 					/* devi_node_name, devi_compat_names */
143f4da9be0Scth 					/* or devi_rebinding_name	*/
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	char	*devi_addr;		/* address part of name		*/
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	int	devi_nodeid;		/* device nodeid		*/
1487c478bd9Sstevel@tonic-gate 	int	devi_instance;		/* device instance number	*/
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	struct dev_ops *devi_ops;	/* driver operations		*/
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	void	*devi_parent_data;	/* parent private data		*/
1537c478bd9Sstevel@tonic-gate 	void	*devi_driver_data;	/* driver private data		*/
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	ddi_prop_t *devi_drv_prop_ptr;	/* head of driver prop list */
1567c478bd9Sstevel@tonic-gate 	ddi_prop_t *devi_sys_prop_ptr;	/* head of system prop list */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	struct ddi_minor_data *devi_minor;	/* head of minor list */
1597c478bd9Sstevel@tonic-gate 	struct dev_info *devi_next;	/* Next instance of this device */
1607c478bd9Sstevel@tonic-gate 	kmutex_t devi_lock;		/* Protects per-devinfo data */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	/* logical parents for busop primitives */
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_map_fault;	/* bus_map_fault parent	 */
165cd21e7c5SGarrett D'Amore 	void		*devi_obsolete;		/* obsolete placeholder */
1667c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_dma_allochdl; /* bus_dma_newhdl parent */
1677c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_dma_freehdl;  /* bus_dma_freehdl parent */
1687c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_dma_bindhdl;  /* bus_dma_bindhdl parent */
1697c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_dma_unbindhdl; /* bus_dma_unbindhdl parent */
1707c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_dma_flush;    /* bus_dma_flush parent	 */
1717c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_dma_win;	/* bus_dma_win parent	 */
1727c478bd9Sstevel@tonic-gate 	struct dev_info *devi_bus_dma_ctl;	/* bus_dma_ctl parent	 */
1737c478bd9Sstevel@tonic-gate 	struct dev_info	*devi_bus_ctl;		/* bus_ctl parent	 */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	ddi_prop_t *devi_hw_prop_ptr;		/* head of hw prop list */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	char	*devi_node_name;		/* The 'name' of the node */
1787c478bd9Sstevel@tonic-gate 	char	*devi_compat_names;		/* A list of driver names */
1797c478bd9Sstevel@tonic-gate 	size_t	devi_compat_length;		/* Size of compat_names */
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	int (*devi_bus_dma_bindfunc)(dev_info_t *, dev_info_t *,
1827c478bd9Sstevel@tonic-gate 	    ddi_dma_handle_t, struct ddi_dma_req *, ddi_dma_cookie_t *,
1837c478bd9Sstevel@tonic-gate 	    uint_t *);
1847c478bd9Sstevel@tonic-gate 	int (*devi_bus_dma_unbindfunc)(dev_info_t *, dev_info_t *,
1857c478bd9Sstevel@tonic-gate 	    ddi_dma_handle_t);
1867c478bd9Sstevel@tonic-gate 
187602ca9eaScth 	char		*devi_devid_str;	/* registered device id */
188602ca9eaScth 
1897c478bd9Sstevel@tonic-gate 	/*
1907c478bd9Sstevel@tonic-gate 	 * power management entries
1917c478bd9Sstevel@tonic-gate 	 * components exist even if the device is not currently power managed
1927c478bd9Sstevel@tonic-gate 	 */
1937c478bd9Sstevel@tonic-gate 	struct pm_info *devi_pm_info;		/* 0 => dev not power managed */
1947c478bd9Sstevel@tonic-gate 	uint_t		devi_pm_flags;		/* pm flags */
1957c478bd9Sstevel@tonic-gate 	int		devi_pm_num_components;	/* number of components */
1967c478bd9Sstevel@tonic-gate 	size_t		devi_pm_comp_size;	/* size of devi_components */
1977c478bd9Sstevel@tonic-gate 	struct pm_component *devi_pm_components; /* array of pm components */
1987c478bd9Sstevel@tonic-gate 	struct dev_info *devi_pm_ppm;		/* ppm attached to this one */
1997c478bd9Sstevel@tonic-gate 	void		*devi_pm_ppm_private;	/* for use by ppm driver */
2007c478bd9Sstevel@tonic-gate 	int		devi_pm_dev_thresh;	/* "device" threshold */
201f13856c4Scth 	uint_t		devi_pm_kidsupcnt;	/* # of kids powered up */
2027c478bd9Sstevel@tonic-gate 	struct pm_scan	*devi_pm_scan;		/* pm scan info */
2037c478bd9Sstevel@tonic-gate 	uint_t		devi_pm_noinvolpm;	/* # of descendents no-invol */
2047c478bd9Sstevel@tonic-gate 	uint_t		devi_pm_volpmd;		/* # of voluntarily pm'ed */
2057c478bd9Sstevel@tonic-gate 	kmutex_t	devi_pm_lock;		/* pm lock for state */
2067c478bd9Sstevel@tonic-gate 	kmutex_t	devi_pm_busy_lock;	/* for component busy count */
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	uint_t		devi_state;		/* device/bus state flags */
2097c478bd9Sstevel@tonic-gate 						/* see below for definitions */
2107c478bd9Sstevel@tonic-gate 	kcondvar_t	devi_cv;		/* cv */
2117c478bd9Sstevel@tonic-gate 	int		devi_ref;		/* reference count */
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	dacf_rsrvlist_t *devi_dacf_tasks;	/* dacf reservation queue */
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	ddi_node_class_t devi_node_class;	/* Node class */
2167c478bd9Sstevel@tonic-gate 	int		devi_node_attributes;	/* Node attributes: See below */
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	char		*devi_device_class;
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	/*
2217c478bd9Sstevel@tonic-gate 	 * New mpxio kernel hooks entries
2227c478bd9Sstevel@tonic-gate 	 */
2237c478bd9Sstevel@tonic-gate 	int		devi_mdi_component;	/* mpxio component type */
2247c478bd9Sstevel@tonic-gate 	void		*devi_mdi_client;	/* mpxio client information */
2257c478bd9Sstevel@tonic-gate 	void		*devi_mdi_xhci;		/* vhci/phci info */
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	ddi_prop_list_t	*devi_global_prop_list;	/* driver global properties */
2287c478bd9Sstevel@tonic-gate 	major_t		devi_major;		/* driver major number */
2297c478bd9Sstevel@tonic-gate 	ddi_node_state_t devi_node_state;	/* state of node */
2307c478bd9Sstevel@tonic-gate 	uint_t		devi_flags;		/* configuration flags */
2317c478bd9Sstevel@tonic-gate 	int		devi_circular;		/* for recursive operations */
2327c478bd9Sstevel@tonic-gate 	void		*devi_busy_thread;	/* thread operating on node */
2337c478bd9Sstevel@tonic-gate 	void		*devi_taskq;		/* hotplug taskq */
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	/* device driver statistical and audit info */
2367c478bd9Sstevel@tonic-gate 	struct devinfo_audit *devi_audit;		/* last state change */
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	/*
2397c478bd9Sstevel@tonic-gate 	 * FMA support for resource caches and error handlers
2407c478bd9Sstevel@tonic-gate 	 */
2417c478bd9Sstevel@tonic-gate 	struct i_ddi_fmhdl	*devi_fmhdl;
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	uint_t		devi_cpr_flags;
2447c478bd9Sstevel@tonic-gate 
24526947304SEvan Yan 	/* Owned by DDI interrupt framework */
2467c478bd9Sstevel@tonic-gate 	devinfo_intr_t	*devi_intr_p;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	void		*devi_nex_pm;		/* nexus PM private */
249fe9fe9fbScth 
250fe9fe9fbScth 	char		*devi_addr_buf;		/* buffer for devi_addr */
251f4da9be0Scth 
252f4da9be0Scth 	char		*devi_rebinding_name;	/* binding_name of rebind */
253602ca9eaScth 
25425e8c5aaSvikram 	/* For device contracts that have this dip's minor node as resource */
25525e8c5aaSvikram 	kmutex_t	devi_ct_lock;		/* contract lock */
25625e8c5aaSvikram 	kcondvar_t	devi_ct_cv;		/* contract cv */
25725e8c5aaSvikram 	int		devi_ct_count;		/* # of outstanding responses */
25825e8c5aaSvikram 	int		devi_ct_neg;		/* neg. occurred on dip */
25925e8c5aaSvikram 	list_t		devi_ct;
260eae2e508Skrishnae 
261eae2e508Skrishnae 	/* owned by bus framework */
262eae2e508Skrishnae 	devi_bus_priv_t	devi_bus;		/* bus private data */
263b9ccdc5aScth 
264b9ccdc5aScth 	/* Declarations of the pure dynamic properties to snapshot */
265b9ccdc5aScth 	struct i_ddi_prop_dyn	*devi_prop_dyn_driver;	/* prop_op */
266b9ccdc5aScth 	struct i_ddi_prop_dyn	*devi_prop_dyn_parent;	/* bus_prop_op */
26786c1f4dcSVikram Hegde 
26850200e77SFrank Van Der Linden #if defined(__x86)
2693a634bfcSVikram Hegde 	/* For x86 (Intel and AMD) IOMMU support */
2703a634bfcSVikram Hegde 	void		*devi_iommu;
27120906b23SVikram Hegde 	iommulib_handle_t	devi_iommulib_handle;
27250200e77SFrank Van Der Linden 	iommulib_nexhandle_t	devi_iommulib_nex_handle;
27350200e77SFrank Van Der Linden #endif
2745febcb4aSScott Carter, SD IOSW 
2755febcb4aSScott Carter, SD IOSW 	/* Generic callback mechanism */
2765febcb4aSScott Carter, SD IOSW 	ddi_cb_t	*devi_cb_p;
277255a2d50SMatthew Jacob 
278255a2d50SMatthew Jacob 	/* ndi 'flavors' */
279255a2d50SMatthew Jacob 	ndi_flavor_t	devi_flavor;		/* flavor assigned by parent */
280255a2d50SMatthew Jacob 	ndi_flavor_t	devi_flavorv_n;		/* number of child-flavors */
281255a2d50SMatthew Jacob 	void		**devi_flavorv;		/* child-flavor specific data */
28226947304SEvan Yan 
28326947304SEvan Yan 	/* Owned by hotplug framework */
28426947304SEvan Yan 	struct ddi_hp_cn_handle *devi_hp_hdlp;   /* hotplug handle list */
28594c894bbSVikram Hegde 
28694c894bbSVikram Hegde 	struct in_node  *devi_in_node; /* pointer to devinfo node's in_node_t */
287779f1d69SMichael Bergknoff 
288779f1d69SMichael Bergknoff 	/* detach event data */
289779f1d69SMichael Bergknoff 	char	*devi_ev_path;
290779f1d69SMichael Bergknoff 	int	devi_ev_instance;
2917c478bd9Sstevel@tonic-gate };
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #define	DEVI(dev_info_type)	((struct dev_info *)(dev_info_type))
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * NB: The 'name' field, for compatibility with old code (both existing
2977c478bd9Sstevel@tonic-gate  * device drivers and userland code), is now defined as the name used
2987c478bd9Sstevel@tonic-gate  * to bind the node to a device driver, and not the device node name.
2997c478bd9Sstevel@tonic-gate  * If the device node name does not define a binding to a device driver,
3007c478bd9Sstevel@tonic-gate  * and the framework uses a different algorithm to create the binding to
3017c478bd9Sstevel@tonic-gate  * the driver, the node name and binding name will be different.
3027c478bd9Sstevel@tonic-gate  *
3037c478bd9Sstevel@tonic-gate  * Note that this implies that the node name plus instance number does
3047c478bd9Sstevel@tonic-gate  * NOT create a unique driver id; only the binding name plus instance
3057c478bd9Sstevel@tonic-gate  * number creates a unique driver id.
3067c478bd9Sstevel@tonic-gate  *
3077c478bd9Sstevel@tonic-gate  * New code should not use 'devi_name'; use 'devi_binding_name' or
3087c478bd9Sstevel@tonic-gate  * 'devi_node_name' and/or the routines that access those fields.
3097c478bd9Sstevel@tonic-gate  */
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate #define	devi_name devi_binding_name
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate  * DDI_CF1, DDI_CF2 and DDI_DRV_UNLOADED are obsolete. They are kept
3157c478bd9Sstevel@tonic-gate  * around to allow legacy drivers to to compile.
3167c478bd9Sstevel@tonic-gate  */
3177c478bd9Sstevel@tonic-gate #define	DDI_CF1(devi)		(DEVI(devi)->devi_addr != NULL)
3187c478bd9Sstevel@tonic-gate #define	DDI_CF2(devi)		(DEVI(devi)->devi_ops != NULL)
3197c478bd9Sstevel@tonic-gate #define	DDI_DRV_UNLOADED(devi)	(DEVI(devi)->devi_ops == &mod_nodev_ops)
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate /*
32216747f41Scth  * The device state flags (devi_state) contains information regarding
3237c478bd9Sstevel@tonic-gate  * the state of the device (Online/Offline/Down).  For bus nexus
3247c478bd9Sstevel@tonic-gate  * devices, the device state also contains state information regarding
3257c478bd9Sstevel@tonic-gate  * the state of the bus represented by this nexus node.
3267c478bd9Sstevel@tonic-gate  *
3277c478bd9Sstevel@tonic-gate  * Device state information is stored in bits [0-7], bus state in bits
3287c478bd9Sstevel@tonic-gate  * [8-15].
3297c478bd9Sstevel@tonic-gate  *
330b9ccdc5aScth  * NOTE: all devi_state updates should be protected by devi_lock.
3317c478bd9Sstevel@tonic-gate  */
3327c478bd9Sstevel@tonic-gate #define	DEVI_DEVICE_OFFLINE	0x00000001
3337c478bd9Sstevel@tonic-gate #define	DEVI_DEVICE_DOWN	0x00000002
3347c478bd9Sstevel@tonic-gate #define	DEVI_DEVICE_DEGRADED	0x00000004
3357c478bd9Sstevel@tonic-gate #define	DEVI_DEVICE_REMOVED	0x00000008 /* hardware removed */
33616747f41Scth 
3377c478bd9Sstevel@tonic-gate #define	DEVI_BUS_QUIESCED	0x00000100
3387c478bd9Sstevel@tonic-gate #define	DEVI_BUS_DOWN		0x00000200
3397c478bd9Sstevel@tonic-gate #define	DEVI_NDI_CONFIG		0x00000400 /* perform config when attaching */
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate #define	DEVI_S_ATTACHING	0x00010000
3427c478bd9Sstevel@tonic-gate #define	DEVI_S_DETACHING	0x00020000
3437c478bd9Sstevel@tonic-gate #define	DEVI_S_ONLINING		0x00040000
3447c478bd9Sstevel@tonic-gate #define	DEVI_S_OFFLINING	0x00080000
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate #define	DEVI_S_INVOKING_DACF	0x00100000 /* busy invoking a dacf task */
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate #define	DEVI_S_UNBOUND		0x00200000
3497c478bd9Sstevel@tonic-gate #define	DEVI_S_REPORT		0x08000000 /* report status change */
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate #define	DEVI_S_EVADD		0x10000000 /* state of devfs event */
3527c478bd9Sstevel@tonic-gate #define	DEVI_S_EVREMOVE		0x20000000 /* state of devfs event */
3537c478bd9Sstevel@tonic-gate #define	DEVI_S_NEED_RESET	0x40000000 /* devo_reset should be called */
3547c478bd9Sstevel@tonic-gate 
35516747f41Scth /*
35616747f41Scth  * Device state macros.
35716747f41Scth  * o All SET/CLR/DONE users must protect context with devi_lock.
35816747f41Scth  * o DEVI_SET_DEVICE_ONLINE users must do his own DEVI_SET_REPORT.
35916747f41Scth  * o DEVI_SET_DEVICE_{DOWN|DEGRADED|UP} should only be used when !OFFLINE.
36016747f41Scth  * o DEVI_SET_DEVICE_UP clears DOWN and DEGRADED.
36116747f41Scth  */
3627c478bd9Sstevel@tonic-gate #define	DEVI_IS_DEVICE_OFFLINE(dip)					\
36316747f41Scth 	((DEVI(dip)->devi_state & DEVI_DEVICE_OFFLINE) == DEVI_DEVICE_OFFLINE)
3647c478bd9Sstevel@tonic-gate 
36516747f41Scth #define	DEVI_SET_DEVICE_ONLINE(dip)	{				\
36616747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
36725e8c5aaSvikram 	if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) {		\
36825e8c5aaSvikram 		mutex_exit(&DEVI(dip)->devi_lock);			\
36925e8c5aaSvikram 		e_ddi_undegrade_finalize(dip);				\
37025e8c5aaSvikram 		mutex_enter(&DEVI(dip)->devi_lock);			\
37125e8c5aaSvikram 	}								\
37216747f41Scth 	/* setting ONLINE clears DOWN, DEGRADED, OFFLINE */		\
37316747f41Scth 	DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DOWN |			\
37416747f41Scth 	    DEVI_DEVICE_DEGRADED | DEVI_DEVICE_OFFLINE);		\
37516747f41Scth 	}
3767c478bd9Sstevel@tonic-gate 
37716747f41Scth #define	DEVI_SET_DEVICE_OFFLINE(dip)	{				\
37816747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
37916747f41Scth 	DEVI(dip)->devi_state |= (DEVI_DEVICE_OFFLINE | DEVI_S_REPORT);	\
38016747f41Scth 	}
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate #define	DEVI_IS_DEVICE_DOWN(dip)					\
38316747f41Scth 	((DEVI(dip)->devi_state & DEVI_DEVICE_DOWN) == DEVI_DEVICE_DOWN)
3847c478bd9Sstevel@tonic-gate 
38516747f41Scth #define	DEVI_SET_DEVICE_DOWN(dip)	{				\
38616747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
38716747f41Scth 	ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip));				\
38816747f41Scth 	DEVI(dip)->devi_state |= (DEVI_DEVICE_DOWN | DEVI_S_REPORT);	\
38916747f41Scth 	}
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate #define	DEVI_IS_DEVICE_DEGRADED(dip)					\
39216747f41Scth 	((DEVI(dip)->devi_state &					\
39316747f41Scth 	    (DEVI_DEVICE_DEGRADED|DEVI_DEVICE_DOWN)) == DEVI_DEVICE_DEGRADED)
3947c478bd9Sstevel@tonic-gate 
39516747f41Scth #define	DEVI_SET_DEVICE_DEGRADED(dip)	{				\
39616747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
39716747f41Scth 	ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip));				\
39825e8c5aaSvikram 	mutex_exit(&DEVI(dip)->devi_lock);				\
39925e8c5aaSvikram 	e_ddi_degrade_finalize(dip);					\
40025e8c5aaSvikram 	mutex_enter(&DEVI(dip)->devi_lock);				\
40116747f41Scth 	DEVI(dip)->devi_state |= (DEVI_DEVICE_DEGRADED | DEVI_S_REPORT); \
40216747f41Scth 	}
4037c478bd9Sstevel@tonic-gate 
40416747f41Scth #define	DEVI_SET_DEVICE_UP(dip)		{				\
40516747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
40616747f41Scth 	ASSERT(!DEVI_IS_DEVICE_OFFLINE(dip));				\
40725e8c5aaSvikram 	if (DEVI(dip)->devi_state & DEVI_DEVICE_DEGRADED) {		\
40825e8c5aaSvikram 		mutex_exit(&DEVI(dip)->devi_lock);			\
40925e8c5aaSvikram 		e_ddi_undegrade_finalize(dip);				\
41025e8c5aaSvikram 		mutex_enter(&DEVI(dip)->devi_lock);			\
41125e8c5aaSvikram 	}								\
41216747f41Scth 	DEVI(dip)->devi_state &= ~(DEVI_DEVICE_DEGRADED | DEVI_DEVICE_DOWN); \
41316747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
41416747f41Scth 	}
4157c478bd9Sstevel@tonic-gate 
41616747f41Scth /* Device removal and insertion */
4177c478bd9Sstevel@tonic-gate #define	DEVI_IS_DEVICE_REMOVED(dip)					\
41816747f41Scth 	((DEVI(dip)->devi_state & DEVI_DEVICE_REMOVED) == DEVI_DEVICE_REMOVED)
4197c478bd9Sstevel@tonic-gate 
42016747f41Scth #define	DEVI_SET_DEVICE_REMOVED(dip)	{				\
42116747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
4224c06356bSdh142964 	DEVI(dip)->devi_state |= DEVI_DEVICE_REMOVED | DEVI_S_REPORT;	\
42316747f41Scth 	}
4247c478bd9Sstevel@tonic-gate 
42516747f41Scth #define	DEVI_SET_DEVICE_REINSERTED(dip)	{				\
42616747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
42716747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_DEVICE_REMOVED;			\
4284c06356bSdh142964 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
42916747f41Scth 	}
4307c478bd9Sstevel@tonic-gate 
43116747f41Scth /* Bus state change macros */
4327c478bd9Sstevel@tonic-gate #define	DEVI_IS_BUS_QUIESCED(dip)					\
43316747f41Scth 	((DEVI(dip)->devi_state & DEVI_BUS_QUIESCED) == DEVI_BUS_QUIESCED)
4347c478bd9Sstevel@tonic-gate 
43516747f41Scth #define	DEVI_SET_BUS_ACTIVE(dip)	{				\
43616747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
43716747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_BUS_QUIESCED;			\
43816747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
43916747f41Scth 	}
4407c478bd9Sstevel@tonic-gate 
44116747f41Scth #define	DEVI_SET_BUS_QUIESCE(dip)	{				\
44216747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
44316747f41Scth 	DEVI(dip)->devi_state |= (DEVI_BUS_QUIESCED | DEVI_S_REPORT);	\
44416747f41Scth 	}
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate #define	DEVI_IS_BUS_DOWN(dip)						\
44716747f41Scth 	((DEVI(dip)->devi_state & DEVI_BUS_DOWN) == DEVI_BUS_DOWN)
4487c478bd9Sstevel@tonic-gate 
44916747f41Scth #define	DEVI_SET_BUS_UP(dip)		{				\
45016747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
45116747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_BUS_DOWN;			\
45216747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
45316747f41Scth 	}
4547c478bd9Sstevel@tonic-gate 
45516747f41Scth #define	DEVI_SET_BUS_DOWN(dip)		{				\
45616747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
45716747f41Scth 	DEVI(dip)->devi_state |= (DEVI_BUS_DOWN | DEVI_S_REPORT);	\
45816747f41Scth 	}
4597c478bd9Sstevel@tonic-gate 
46016747f41Scth /* Status change report needed */
4617c478bd9Sstevel@tonic-gate #define	DEVI_NEED_REPORT(dip)						\
46216747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_REPORT) == DEVI_S_REPORT)
4637c478bd9Sstevel@tonic-gate 
46416747f41Scth #define	DEVI_SET_REPORT(dip)		{				\
46516747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
46616747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_REPORT;				\
46716747f41Scth 	}
4687c478bd9Sstevel@tonic-gate 
46916747f41Scth #define	DEVI_REPORT_DONE(dip)		{				\
47016747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
47116747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_REPORT;			\
47216747f41Scth 	}
47316747f41Scth 
47416747f41Scth /* Do an NDI_CONFIG for its children */
4757c478bd9Sstevel@tonic-gate #define	DEVI_NEED_NDI_CONFIG(dip)					\
47616747f41Scth 	((DEVI(dip)->devi_state & DEVI_NDI_CONFIG) == DEVI_NDI_CONFIG)
4777c478bd9Sstevel@tonic-gate 
47816747f41Scth #define	DEVI_SET_NDI_CONFIG(dip)	{				\
47916747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
48016747f41Scth 	DEVI(dip)->devi_state |= DEVI_NDI_CONFIG;			\
48116747f41Scth 	}
4827c478bd9Sstevel@tonic-gate 
48316747f41Scth #define	DEVI_CLR_NDI_CONFIG(dip)	{				\
48416747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
48516747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_NDI_CONFIG;			\
48616747f41Scth 	}
4877c478bd9Sstevel@tonic-gate 
48816747f41Scth /* Attaching or detaching state */
4897c478bd9Sstevel@tonic-gate #define	DEVI_IS_ATTACHING(dip)						\
49016747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_ATTACHING) == DEVI_S_ATTACHING)
4917c478bd9Sstevel@tonic-gate 
49216747f41Scth #define	DEVI_SET_ATTACHING(dip)		{				\
49316747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
49416747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_ATTACHING;			\
49516747f41Scth 	}
4967c478bd9Sstevel@tonic-gate 
49716747f41Scth #define	DEVI_CLR_ATTACHING(dip)		{				\
49816747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
49916747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_ATTACHING;			\
50016747f41Scth 	}
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate #define	DEVI_IS_DETACHING(dip)						\
50316747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_DETACHING) == DEVI_S_DETACHING)
5047c478bd9Sstevel@tonic-gate 
50516747f41Scth #define	DEVI_SET_DETACHING(dip)		{				\
50616747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
50716747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_DETACHING;			\
50816747f41Scth 	}
5097c478bd9Sstevel@tonic-gate 
51016747f41Scth #define	DEVI_CLR_DETACHING(dip)		{				\
51116747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
51216747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_DETACHING;			\
51316747f41Scth 	}
5147c478bd9Sstevel@tonic-gate 
51516747f41Scth /* Onlining or offlining state */
5167c478bd9Sstevel@tonic-gate #define	DEVI_IS_ONLINING(dip)						\
51716747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_ONLINING) == DEVI_S_ONLINING)
5187c478bd9Sstevel@tonic-gate 
51916747f41Scth #define	DEVI_SET_ONLINING(dip)		{				\
52016747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
52116747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_ONLINING;			\
52216747f41Scth 	}
5237c478bd9Sstevel@tonic-gate 
52416747f41Scth #define	DEVI_CLR_ONLINING(dip)		{				\
52516747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
52616747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_ONLINING;			\
52716747f41Scth 	}
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate #define	DEVI_IS_OFFLINING(dip)						\
53016747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_OFFLINING) == DEVI_S_OFFLINING)
53116747f41Scth 
53216747f41Scth #define	DEVI_SET_OFFLINING(dip)		{				\
53316747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
53416747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_OFFLINING;			\
53516747f41Scth 	}
53616747f41Scth 
53716747f41Scth #define	DEVI_CLR_OFFLINING(dip)		{				\
53816747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
53916747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_OFFLINING;			\
54016747f41Scth 	}
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate #define	DEVI_IS_IN_RECONFIG(dip)					\
54316747f41Scth 	(DEVI(dip)->devi_state & (DEVI_S_OFFLINING | DEVI_S_ONLINING))
5447c478bd9Sstevel@tonic-gate 
54516747f41Scth /* Busy invoking a dacf task against this node */
5467c478bd9Sstevel@tonic-gate #define	DEVI_IS_INVOKING_DACF(dip)					\
54716747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_INVOKING_DACF) == DEVI_S_INVOKING_DACF)
5487c478bd9Sstevel@tonic-gate 
54916747f41Scth #define	DEVI_SET_INVOKING_DACF(dip)	{				\
55016747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
55116747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_INVOKING_DACF;			\
55216747f41Scth 	}
5537c478bd9Sstevel@tonic-gate 
55416747f41Scth #define	DEVI_CLR_INVOKING_DACF(dip)	{				\
55516747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
55616747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_INVOKING_DACF;			\
55716747f41Scth 	}
5587c478bd9Sstevel@tonic-gate 
55916747f41Scth /* Events for add/remove */
5607c478bd9Sstevel@tonic-gate #define	DEVI_EVADD(dip)							\
56116747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_EVADD) == DEVI_S_EVADD)
56216747f41Scth 
56316747f41Scth #define	DEVI_SET_EVADD(dip)		{				\
56416747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
56516747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_EVREMOVE;			\
56616747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_EVADD;				\
56716747f41Scth 	}
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate #define	DEVI_EVREMOVE(dip)						\
57016747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_EVREMOVE) == DEVI_S_EVREMOVE)
5717c478bd9Sstevel@tonic-gate 
57216747f41Scth #define	DEVI_SET_EVREMOVE(dip)		{				\
57316747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
57416747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_EVADD;				\
57516747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_EVREMOVE;			\
57616747f41Scth 	}
57716747f41Scth 
57816747f41Scth #define	DEVI_SET_EVUNINIT(dip)		{				\
57916747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
58016747f41Scth 	DEVI(dip)->devi_state &= ~(DEVI_S_EVADD | DEVI_S_EVREMOVE);	\
58116747f41Scth 	}
58216747f41Scth 
58316747f41Scth /* Need to call the devo_reset entry point for this device at shutdown */
5847c478bd9Sstevel@tonic-gate #define	DEVI_NEED_RESET(dip)						\
58516747f41Scth 	((DEVI(dip)->devi_state & DEVI_S_NEED_RESET) == DEVI_S_NEED_RESET)
5867c478bd9Sstevel@tonic-gate 
58716747f41Scth #define	DEVI_SET_NEED_RESET(dip)	{				\
58816747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
58916747f41Scth 	DEVI(dip)->devi_state |= DEVI_S_NEED_RESET;			\
59016747f41Scth 	}
5917c478bd9Sstevel@tonic-gate 
59216747f41Scth #define	DEVI_CLR_NEED_RESET(dip)	{				\
59316747f41Scth 	ASSERT(mutex_owned(&DEVI(dip)->devi_lock));			\
59416747f41Scth 	DEVI(dip)->devi_state &= ~DEVI_S_NEED_RESET;			\
59516747f41Scth 	}
5967c478bd9Sstevel@tonic-gate 
59716747f41Scth /*
59816747f41Scth  * devi_flags bits
59916747f41Scth  *
600b9ccdc5aScth  * NOTE: all devi_state updates should be protected by devi_lock.
60116747f41Scth  */
60216747f41Scth #define	DEVI_BUSY		0x00000001 /* busy configuring children */
60316747f41Scth #define	DEVI_MADE_CHILDREN	0x00000002 /* children made from specs */
60416747f41Scth #define	DEVI_ATTACHED_CHILDREN	0x00000004 /* attached all existing children */
60516747f41Scth #define	DEVI_BRANCH_HELD	0x00000008 /* branch rooted at this dip held */
60616747f41Scth #define	DEVI_NO_BIND		0x00000010 /* prevent driver binding */
6078451e9c3SGavin Maltby #define	DEVI_CACHED_DEVID	0x00000020 /* devid cached in devid cache */
6085e3986cbScth #define	DEVI_PHCI_SIGNALS_VHCI	0x00000040 /* pHCI ndi_devi_exit signals vHCI */
609f4da9be0Scth #define	DEVI_REBIND		0x00000080 /* post initchild driver rebind */
61025e8c5aaSvikram #define	DEVI_RETIRED		0x00000100 /* device is retired */
61125e8c5aaSvikram #define	DEVI_RETIRING		0x00000200 /* being evaluated for retire */
61225e8c5aaSvikram #define	DEVI_R_CONSTRAINT	0x00000400 /* constraints have been applied  */
61325e8c5aaSvikram #define	DEVI_R_BLOCKED		0x00000800 /* constraints block retire  */
61425e8c5aaSvikram #define	DEVI_CT_NOP		0x00001000 /* NOP contract event occurred */
6153a634bfcSVikram Hegde #define	DEVI_PCI_DEVICE		0x00002000 /* dip is PCI */
61616747f41Scth 
61716747f41Scth #define	DEVI_BUSY_CHANGING(dip)	(DEVI(dip)->devi_flags & DEVI_BUSY)
61816747f41Scth #define	DEVI_BUSY_OWNED(dip)	(DEVI_BUSY_CHANGING(dip) &&	\
61916747f41Scth 	((DEVI(dip))->devi_busy_thread == curthread))
62016747f41Scth 
6213a634bfcSVikram Hegde #define	DEVI_IS_PCI(dip)	(DEVI(dip)->devi_flags & DEVI_PCI_DEVICE)
6223a634bfcSVikram Hegde #define	DEVI_SET_PCI(dip)	(DEVI(dip)->devi_flags |= (DEVI_PCI_DEVICE))
6233a634bfcSVikram Hegde 
6247c478bd9Sstevel@tonic-gate char	*i_ddi_devi_class(dev_info_t *);
6257c478bd9Sstevel@tonic-gate int	i_ddi_set_devi_class(dev_info_t *, char *, int);
6267c478bd9Sstevel@tonic-gate 
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate  * This structure represents one piece of bus space occupied by a given
6297c478bd9Sstevel@tonic-gate  * device. It is used in an array for devices with multiple address windows.
6307c478bd9Sstevel@tonic-gate  */
6317c478bd9Sstevel@tonic-gate struct regspec {
6327c478bd9Sstevel@tonic-gate 	uint_t regspec_bustype;		/* cookie for bus type it's on */
6337c478bd9Sstevel@tonic-gate 	uint_t regspec_addr;		/* address of reg relative to bus */
6347c478bd9Sstevel@tonic-gate 	uint_t regspec_size;		/* size of this register set */
6357c478bd9Sstevel@tonic-gate };
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate /*
638*abe68f2cSRobert Mustacchi  * This is a version of the above structure that works for 64-bit mappings and
639*abe68f2cSRobert Mustacchi  * doesn't rely on overloading of fields as is done on SPARC. Eventually the
640*abe68f2cSRobert Mustacchi  * struct regspec should be replaced with this.
641*abe68f2cSRobert Mustacchi  */
642*abe68f2cSRobert Mustacchi struct regspec64 {
643*abe68f2cSRobert Mustacchi 	uint64_t regspec_bustype;	/* cookie for bus type it's on */
644*abe68f2cSRobert Mustacchi 	uint64_t regspec_addr;		/* address of reg relative to bus */
645*abe68f2cSRobert Mustacchi 	uint64_t regspec_size;		/* size of this register set */
646*abe68f2cSRobert Mustacchi };
647*abe68f2cSRobert Mustacchi 
648*abe68f2cSRobert Mustacchi /*
6497c478bd9Sstevel@tonic-gate  * This structure represents one piece of nexus bus space.
6507c478bd9Sstevel@tonic-gate  * It is used in an array for nexi with multiple bus spaces
6517c478bd9Sstevel@tonic-gate  * to define the childs offsets in the parents bus space.
6527c478bd9Sstevel@tonic-gate  */
6537c478bd9Sstevel@tonic-gate struct rangespec {
6547c478bd9Sstevel@tonic-gate 	uint_t rng_cbustype;		/* Child's address, hi order */
6557c478bd9Sstevel@tonic-gate 	uint_t rng_coffset;		/* Child's address, lo order */
6567c478bd9Sstevel@tonic-gate 	uint_t rng_bustype;		/* Parent's address, hi order */
6577c478bd9Sstevel@tonic-gate 	uint_t rng_offset;		/* Parent's address, lo order */
6587c478bd9Sstevel@tonic-gate 	uint_t rng_size;		/* size of space for this entry */
6597c478bd9Sstevel@tonic-gate };
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate #ifdef _KERNEL
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate typedef enum {
6647c478bd9Sstevel@tonic-gate 	DDI_PRE = 0,
6657c478bd9Sstevel@tonic-gate 	DDI_POST = 1
6667c478bd9Sstevel@tonic-gate } ddi_pre_post_t;
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate /*
6697c478bd9Sstevel@tonic-gate  * This structure represents notification of a child attach event
6707c478bd9Sstevel@tonic-gate  * These could both be the same if attach/detach commands were in the
6717c478bd9Sstevel@tonic-gate  * same name space.
6727c478bd9Sstevel@tonic-gate  * Note that the target dip is passed as an arg already.
6737c478bd9Sstevel@tonic-gate  */
6747c478bd9Sstevel@tonic-gate struct attachspec {
6757c478bd9Sstevel@tonic-gate 	ddi_attach_cmd_t cmd;	/* type of event */
6767c478bd9Sstevel@tonic-gate 	ddi_pre_post_t	when;	/* one of DDI_PRE or DDI_POST */
6777c478bd9Sstevel@tonic-gate 	dev_info_t	*pdip;	/* parent of attaching node */
6787c478bd9Sstevel@tonic-gate 	int		result;	/* result of attach op (post command only) */
6797c478bd9Sstevel@tonic-gate };
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate /*
6827c478bd9Sstevel@tonic-gate  * This structure represents notification of a child detach event
6837c478bd9Sstevel@tonic-gate  * Note that the target dip is passed as an arg already.
6847c478bd9Sstevel@tonic-gate  */
6857c478bd9Sstevel@tonic-gate struct detachspec {
6867c478bd9Sstevel@tonic-gate 	ddi_detach_cmd_t cmd;	/* type of event */
6877c478bd9Sstevel@tonic-gate 	ddi_pre_post_t	when;	/* one of DDI_PRE or DDI_POST */
6887c478bd9Sstevel@tonic-gate 	dev_info_t	*pdip;	/* parent of detaching node */
6897c478bd9Sstevel@tonic-gate 	int		result;	/* result of detach op (post command only) */
6907c478bd9Sstevel@tonic-gate };
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate typedef enum {
6957c478bd9Sstevel@tonic-gate 	DDM_MINOR = 0,
6967c478bd9Sstevel@tonic-gate 	DDM_ALIAS,
6977c478bd9Sstevel@tonic-gate 	DDM_DEFAULT,
6987c478bd9Sstevel@tonic-gate 	DDM_INTERNAL_PATH
6997c478bd9Sstevel@tonic-gate } ddi_minor_type;
7007c478bd9Sstevel@tonic-gate 
7017c478bd9Sstevel@tonic-gate /* implementation flags for driver specified device access control */
7027c478bd9Sstevel@tonic-gate #define	DM_NO_FSPERM	0x1
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate struct devplcy;
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate struct ddi_minor {
7077c478bd9Sstevel@tonic-gate 	char		*name;		/* name of node */
7087c478bd9Sstevel@tonic-gate 	dev_t		dev;		/* device number */
7097c478bd9Sstevel@tonic-gate 	int		spec_type;	/* block or char */
7107c478bd9Sstevel@tonic-gate 	int		flags;		/* access flags */
7117c478bd9Sstevel@tonic-gate 	char		*node_type;	/* block, byte, serial, network */
7127c478bd9Sstevel@tonic-gate 	struct devplcy	*node_priv;	/* privilege for this minor */
7137c478bd9Sstevel@tonic-gate 	mode_t		priv_mode;	/* default apparent privilege mode */
7147c478bd9Sstevel@tonic-gate };
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate /*
7177c478bd9Sstevel@tonic-gate  * devi_node_attributes contains node attributes private to the
7187c478bd9Sstevel@tonic-gate  * ddi implementation. As a consumer, do not use these bit definitions
7197c478bd9Sstevel@tonic-gate  * directly, use the ndi functions that check for the existence of the
7207c478bd9Sstevel@tonic-gate  * specific node attributes.
7217c478bd9Sstevel@tonic-gate  *
7227c478bd9Sstevel@tonic-gate  * DDI_PERSISTENT indicates a 'persistent' node; one that is not
7237c478bd9Sstevel@tonic-gate  * automatically freed by the framework if the driver is unloaded
7247c478bd9Sstevel@tonic-gate  * or the driver fails to attach to this node.
7257c478bd9Sstevel@tonic-gate  *
7267c478bd9Sstevel@tonic-gate  * DDI_AUTO_ASSIGNED_NODEID indicates that the nodeid was auto-assigned
7277c478bd9Sstevel@tonic-gate  * by the framework and should be auto-freed if the node is removed.
7287c478bd9Sstevel@tonic-gate  *
7297c478bd9Sstevel@tonic-gate  * DDI_VHCI_NODE indicates that the node type is VHCI. This flag
7307c478bd9Sstevel@tonic-gate  * must be set by ndi_devi_config_vhci() routine only.
731027021c7SChris Horne  *
732027021c7SChris Horne  * DDI_HIDDEN_NODE indicates that the node should not show up in snapshots
733027021c7SChris Horne  * or in /devices.
7344c06356bSdh142964  *
7354c06356bSdh142964  * DDI_HOTPLUG_NODE indicates that the node created by nexus hotplug.
7367c478bd9Sstevel@tonic-gate  */
7377c478bd9Sstevel@tonic-gate #define	DDI_PERSISTENT			0x01
7387c478bd9Sstevel@tonic-gate #define	DDI_AUTO_ASSIGNED_NODEID	0x02
7397c478bd9Sstevel@tonic-gate #define	DDI_VHCI_NODE			0x04
740027021c7SChris Horne #define	DDI_HIDDEN_NODE			0x08
7414c06356bSdh142964 #define	DDI_HOTPLUG_NODE		0x10
7427c478bd9Sstevel@tonic-gate 
74316747f41Scth #define	DEVI_VHCI_NODE(dip)						\
74416747f41Scth 	(DEVI(dip)->devi_node_attributes & DDI_VHCI_NODE)
74516747f41Scth 
7467c478bd9Sstevel@tonic-gate /*
7477c478bd9Sstevel@tonic-gate  * The ddi_minor_data structure gets filled in by ddi_create_minor_node.
7487c478bd9Sstevel@tonic-gate  * It then gets attached to the devinfo node as a property.
7497c478bd9Sstevel@tonic-gate  */
7507c478bd9Sstevel@tonic-gate struct ddi_minor_data {
7517c478bd9Sstevel@tonic-gate 	struct ddi_minor_data *next;	/* next one in the chain */
7527c478bd9Sstevel@tonic-gate 	dev_info_t	*dip;		/* pointer to devinfo node */
7537c478bd9Sstevel@tonic-gate 	ddi_minor_type	type;		/* Following data type */
7547c478bd9Sstevel@tonic-gate 	struct ddi_minor d_minor;	/* Actual minor node data */
7557c478bd9Sstevel@tonic-gate };
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate #define	ddm_name	d_minor.name
7587c478bd9Sstevel@tonic-gate #define	ddm_dev		d_minor.dev
7597c478bd9Sstevel@tonic-gate #define	ddm_flags	d_minor.flags
7607c478bd9Sstevel@tonic-gate #define	ddm_spec_type	d_minor.spec_type
7617c478bd9Sstevel@tonic-gate #define	ddm_node_type	d_minor.node_type
7627c478bd9Sstevel@tonic-gate #define	ddm_node_priv	d_minor.node_priv
7637c478bd9Sstevel@tonic-gate #define	ddm_priv_mode	d_minor.priv_mode
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate /*
7667c478bd9Sstevel@tonic-gate  * parent private data structure contains register, interrupt, property
7677c478bd9Sstevel@tonic-gate  * and range information.
7687c478bd9Sstevel@tonic-gate  */
7697c478bd9Sstevel@tonic-gate struct ddi_parent_private_data {
7707c478bd9Sstevel@tonic-gate 	int par_nreg;			/* number of regs */
7717c478bd9Sstevel@tonic-gate 	struct regspec *par_reg;	/* array of regs */
7727c478bd9Sstevel@tonic-gate 	int par_nintr;			/* number of interrupts */
7737c478bd9Sstevel@tonic-gate 	struct intrspec *par_intr;	/* array of possible interrupts */
7747c478bd9Sstevel@tonic-gate 	int par_nrng;			/* number of ranges */
7757c478bd9Sstevel@tonic-gate 	struct rangespec *par_rng;	/* array of ranges */
7767c478bd9Sstevel@tonic-gate };
7777c478bd9Sstevel@tonic-gate #define	DEVI_PD(d)	\
7787c478bd9Sstevel@tonic-gate 	((struct ddi_parent_private_data *)DEVI((d))->devi_parent_data)
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate #define	sparc_pd_getnreg(dev)		(DEVI_PD(dev)->par_nreg)
7817c478bd9Sstevel@tonic-gate #define	sparc_pd_getnintr(dev)		(DEVI_PD(dev)->par_nintr)
7827c478bd9Sstevel@tonic-gate #define	sparc_pd_getnrng(dev)		(DEVI_PD(dev)->par_nrng)
7837c478bd9Sstevel@tonic-gate #define	sparc_pd_getreg(dev, n)		(&DEVI_PD(dev)->par_reg[(n)])
7847c478bd9Sstevel@tonic-gate #define	sparc_pd_getintr(dev, n)	(&DEVI_PD(dev)->par_intr[(n)])
7857c478bd9Sstevel@tonic-gate #define	sparc_pd_getrng(dev, n)		(&DEVI_PD(dev)->par_rng[(n)])
7867c478bd9Sstevel@tonic-gate 
7874c06356bSdh142964 #ifdef _KERNEL
7887c478bd9Sstevel@tonic-gate /*
7894c06356bSdh142964  * This data structure is private to the indexed soft state allocator.
7907c478bd9Sstevel@tonic-gate  */
7914c06356bSdh142964 typedef struct i_ddi_soft_state {
7927c478bd9Sstevel@tonic-gate 	void		**array;	/* the array of pointers */
7937c478bd9Sstevel@tonic-gate 	kmutex_t	lock;		/* serialize access to this struct */
7947c478bd9Sstevel@tonic-gate 	size_t		size;		/* how many bytes per state struct */
7957c478bd9Sstevel@tonic-gate 	size_t		n_items;	/* how many structs herein */
7967c478bd9Sstevel@tonic-gate 	struct i_ddi_soft_state *next;	/* 'dirty' elements */
7974c06356bSdh142964 } i_ddi_soft_state;
7984c06356bSdh142964 
7994c06356bSdh142964 /*
8004c06356bSdh142964  * This data structure is private to the stringhashed soft state allocator.
8014c06356bSdh142964  */
8024c06356bSdh142964 typedef struct i_ddi_soft_state_bystr {
8034c06356bSdh142964 	size_t		ss_size;	/* how many bytes per state struct */
8044c06356bSdh142964 	mod_hash_t	*ss_mod_hash;	/* hash implementation */
8054c06356bSdh142964 } i_ddi_soft_state_bystr;
8064c06356bSdh142964 
8074c06356bSdh142964 /*
8084c06356bSdh142964  * This data structure is private to the ddi_strid_* implementation
8094c06356bSdh142964  */
8104c06356bSdh142964 typedef struct i_ddi_strid {
8111b115575SJohn Danielson 	size_t		strid_chunksz;
8121b115575SJohn Danielson 	size_t		strid_spacesz;
8134c06356bSdh142964 	id_space_t	*strid_space;
8144c06356bSdh142964 	mod_hash_t	*strid_byid;
8154c06356bSdh142964 	mod_hash_t	*strid_bystr;
8164c06356bSdh142964 } i_ddi_strid;
8174c06356bSdh142964 #endif /* _KERNEL */
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate /*
8207c478bd9Sstevel@tonic-gate  * Solaris DDI DMA implementation structure and function definitions.
8217c478bd9Sstevel@tonic-gate  *
8227c478bd9Sstevel@tonic-gate  * Note: no callers of DDI functions must depend upon data structures
8237c478bd9Sstevel@tonic-gate  * declared below. They are not guaranteed to remain constant.
8247c478bd9Sstevel@tonic-gate  */
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate /*
8277c478bd9Sstevel@tonic-gate  * Implementation DMA mapping structure.
8287c478bd9Sstevel@tonic-gate  *
8297c478bd9Sstevel@tonic-gate  * The publicly visible ddi_dma_req structure is filled
8307c478bd9Sstevel@tonic-gate  * in by a caller that wishes to map a memory object
8317c478bd9Sstevel@tonic-gate  * for DMA. Internal to this implementation of the public
8327c478bd9Sstevel@tonic-gate  * DDI DMA functions this request structure is put together
8337c478bd9Sstevel@tonic-gate  * with bus nexus specific functions that have additional
8347c478bd9Sstevel@tonic-gate  * information and constraints as to how to go about doing
8357c478bd9Sstevel@tonic-gate  * the requested mapping function
8367c478bd9Sstevel@tonic-gate  *
8377c478bd9Sstevel@tonic-gate  * In this implementation, some of the information from the
8387c478bd9Sstevel@tonic-gate  * original requester is retained throughout the lifetime
8397c478bd9Sstevel@tonic-gate  * of the I/O mapping being active.
8407c478bd9Sstevel@tonic-gate  */
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate /*
8437c478bd9Sstevel@tonic-gate  * This is the implementation specific description
8447c478bd9Sstevel@tonic-gate  * of how we've mapped an object for DMA.
8457c478bd9Sstevel@tonic-gate  */
8467c478bd9Sstevel@tonic-gate #if defined(__sparc)
8477c478bd9Sstevel@tonic-gate typedef struct ddi_dma_impl {
8487c478bd9Sstevel@tonic-gate 	/*
8497c478bd9Sstevel@tonic-gate 	 * DMA mapping information
8507c478bd9Sstevel@tonic-gate 	 */
8517c478bd9Sstevel@tonic-gate 	ulong_t	dmai_mapping;	/* mapping cookie */
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate 	/*
8547c478bd9Sstevel@tonic-gate 	 * Size of the current mapping, in bytes.
8557c478bd9Sstevel@tonic-gate 	 *
8567c478bd9Sstevel@tonic-gate 	 * Note that this is distinct from the size of the object being mapped
8577c478bd9Sstevel@tonic-gate 	 * for DVMA. We might have only a portion of the object mapped at any
8587c478bd9Sstevel@tonic-gate 	 * given point in time.
8597c478bd9Sstevel@tonic-gate 	 */
8607c478bd9Sstevel@tonic-gate 	uint_t	dmai_size;
8617c478bd9Sstevel@tonic-gate 
8627c478bd9Sstevel@tonic-gate 	/*
8637c478bd9Sstevel@tonic-gate 	 * Offset, in bytes, into object that is currently mapped.
8647c478bd9Sstevel@tonic-gate 	 */
8657c478bd9Sstevel@tonic-gate 	off_t	dmai_offset;
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 	/*
8687c478bd9Sstevel@tonic-gate 	 * Information gathered from the original DMA mapping
8697c478bd9Sstevel@tonic-gate 	 * request and saved for the lifetime of the mapping.
8707c478bd9Sstevel@tonic-gate 	 */
8717c478bd9Sstevel@tonic-gate 	uint_t		dmai_minxfer;
8727c478bd9Sstevel@tonic-gate 	uint_t		dmai_burstsizes;
8737c478bd9Sstevel@tonic-gate 	uint_t		dmai_ndvmapages;
8747c478bd9Sstevel@tonic-gate 	uint_t		dmai_pool;	/* cached DVMA space */
8757c478bd9Sstevel@tonic-gate 	uint_t		dmai_rflags;	/* requester's flags + ours */
8767c478bd9Sstevel@tonic-gate 	uint_t		dmai_inuse;	/* active handle? */
8777c478bd9Sstevel@tonic-gate 	uint_t		dmai_nwin;
8787c478bd9Sstevel@tonic-gate 	uint_t		dmai_winsize;
8797c478bd9Sstevel@tonic-gate 	caddr_t		dmai_nexus_private;
8807c478bd9Sstevel@tonic-gate 	void		*dmai_iopte;
8817c478bd9Sstevel@tonic-gate 	uint_t		*dmai_sbi;
8827c478bd9Sstevel@tonic-gate 	void		*dmai_minfo;	/* random mapping information */
8837c478bd9Sstevel@tonic-gate 	dev_info_t	*dmai_rdip;	/* original requester's dev_info_t */
8847c478bd9Sstevel@tonic-gate 	ddi_dma_obj_t	dmai_object;	/* requester's object */
8857c478bd9Sstevel@tonic-gate 	ddi_dma_attr_t	dmai_attr;	/* DMA attributes */
8867c478bd9Sstevel@tonic-gate 	ddi_dma_cookie_t *dmai_cookie;	/* pointer to first DMA cookie */
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	int		(*dmai_fault_check)(struct ddi_dma_impl *handle);
8897c478bd9Sstevel@tonic-gate 	void		(*dmai_fault_notify)(struct ddi_dma_impl *handle);
8907c478bd9Sstevel@tonic-gate 	int		dmai_fault;
8917c478bd9Sstevel@tonic-gate 	ndi_err_t	dmai_error;
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate } ddi_dma_impl_t;
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate #elif defined(__x86)
8967c478bd9Sstevel@tonic-gate 
89712f080e7Smrj /*
89812f080e7Smrj  * ddi_dma_impl portion that genunix (sunddi.c) depends on. x86 rootnex
89912f080e7Smrj  * implementation specific state is in dmai_private.
90012f080e7Smrj  */
9017c478bd9Sstevel@tonic-gate typedef struct ddi_dma_impl {
90212f080e7Smrj 	ddi_dma_cookie_t *dmai_cookie; /* array of DMA cookies */
90312f080e7Smrj 	void		*dmai_private;
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 	/*
9067c478bd9Sstevel@tonic-gate 	 * Information gathered from the original dma mapping
9077c478bd9Sstevel@tonic-gate 	 * request and saved for the lifetime of the mapping.
9087c478bd9Sstevel@tonic-gate 	 */
9097c478bd9Sstevel@tonic-gate 	uint_t		dmai_minxfer;
9107c478bd9Sstevel@tonic-gate 	uint_t		dmai_burstsizes;
9117c478bd9Sstevel@tonic-gate 	uint_t		dmai_rflags;	/* requester's flags + ours */
9127c478bd9Sstevel@tonic-gate 	int		dmai_nwin;
9137c478bd9Sstevel@tonic-gate 	dev_info_t	*dmai_rdip;	/* original requester's dev_info_t */
9147c478bd9Sstevel@tonic-gate 
9157c478bd9Sstevel@tonic-gate 	ddi_dma_attr_t	dmai_attr;	/* DMA attributes */
9167c478bd9Sstevel@tonic-gate 
9177c478bd9Sstevel@tonic-gate 	int		(*dmai_fault_check)(struct ddi_dma_impl *handle);
9187c478bd9Sstevel@tonic-gate 	void		(*dmai_fault_notify)(struct ddi_dma_impl *handle);
9197c478bd9Sstevel@tonic-gate 	int		dmai_fault;
9207c478bd9Sstevel@tonic-gate 	ndi_err_t	dmai_error;
9217c478bd9Sstevel@tonic-gate } ddi_dma_impl_t;
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate #else
9247c478bd9Sstevel@tonic-gate #error "struct ddi_dma_impl not defined for this architecture"
9257c478bd9Sstevel@tonic-gate #endif  /* defined(__sparc) */
9267c478bd9Sstevel@tonic-gate 
9277c478bd9Sstevel@tonic-gate /*
9287c478bd9Sstevel@tonic-gate  * For now DMA segments share state with the DMA handle
9297c478bd9Sstevel@tonic-gate  */
9307c478bd9Sstevel@tonic-gate typedef ddi_dma_impl_t ddi_dma_seg_impl_t;
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate /*
9337c478bd9Sstevel@tonic-gate  * These flags use reserved bits from the dma request flags.
9347c478bd9Sstevel@tonic-gate  *
9357c478bd9Sstevel@tonic-gate  * A note about the DMP_NOSYNC flags: the root nexus will
9367c478bd9Sstevel@tonic-gate  * set these as it sees best. If an intermediate nexus
9377c478bd9Sstevel@tonic-gate  * actually needs these operations, then during the unwind
9387c478bd9Sstevel@tonic-gate  * from the call to ddi_dma_bind, the nexus driver *must*
9397c478bd9Sstevel@tonic-gate  * clear the appropriate flag(s). This is because, as an
9407c478bd9Sstevel@tonic-gate  * optimization, ddi_dma_sync(9F) looks at these flags before
9417c478bd9Sstevel@tonic-gate  * deciding to spend the time going back up the tree.
9427c478bd9Sstevel@tonic-gate  */
9437c478bd9Sstevel@tonic-gate 
9447c478bd9Sstevel@tonic-gate #define	_DMCM1	DDI_DMA_RDWR|DDI_DMA_REDZONE|DDI_DMA_PARTIAL
9457c478bd9Sstevel@tonic-gate #define	_DMCM2	DDI_DMA_CONSISTENT|DMP_VMEREQ
9467c478bd9Sstevel@tonic-gate #define	DMP_DDIFLAGS	(_DMCM1|_DMCM2)
9477c478bd9Sstevel@tonic-gate #define	DMP_SHADOW	0x20
9487c478bd9Sstevel@tonic-gate #define	DMP_LKIOPB	0x40
9497c478bd9Sstevel@tonic-gate #define	DMP_LKSYSV	0x80
9507c478bd9Sstevel@tonic-gate #define	DMP_IOCACHE	0x100
9517c478bd9Sstevel@tonic-gate #define	DMP_USEHAT	0x200
9527c478bd9Sstevel@tonic-gate #define	DMP_PHYSADDR	0x400
9537c478bd9Sstevel@tonic-gate #define	DMP_INVALID	0x800
9547c478bd9Sstevel@tonic-gate #define	DMP_NOLIMIT	0x1000
9557c478bd9Sstevel@tonic-gate #define	DMP_VMEREQ	0x10000000
9567c478bd9Sstevel@tonic-gate #define	DMP_BYPASSNEXUS	0x20000000
9577c478bd9Sstevel@tonic-gate #define	DMP_NODEVSYNC	0x40000000
9587c478bd9Sstevel@tonic-gate #define	DMP_NOCPUSYNC	0x80000000
9597c478bd9Sstevel@tonic-gate #define	DMP_NOSYNC	(DMP_NODEVSYNC|DMP_NOCPUSYNC)
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate /*
9627c478bd9Sstevel@tonic-gate  * In order to complete a device to device mapping that
9637c478bd9Sstevel@tonic-gate  * has percolated as high as an IU nexus (gone that high
9647c478bd9Sstevel@tonic-gate  * because the DMA request is a VADDR type), we define
9657c478bd9Sstevel@tonic-gate  * structure to use with the DDI_CTLOPS_DMAPMAPC request
9667c478bd9Sstevel@tonic-gate  * that re-traverses the request tree to finish the
9677c478bd9Sstevel@tonic-gate  * DMA 'mapping' for a device.
9687c478bd9Sstevel@tonic-gate  */
9697c478bd9Sstevel@tonic-gate struct dma_phys_mapc {
9707c478bd9Sstevel@tonic-gate 	struct ddi_dma_req *dma_req;	/* original request */
9717c478bd9Sstevel@tonic-gate 	ddi_dma_impl_t *mp;		/* current handle, or none */
9727c478bd9Sstevel@tonic-gate 	int nptes;			/* number of ptes */
9737c478bd9Sstevel@tonic-gate 	void *ptes;			/* ptes already read */
9747c478bd9Sstevel@tonic-gate };
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate #define	MAXCALLBACK		20
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate /*
9797c478bd9Sstevel@tonic-gate  * Callback definitions
9807c478bd9Sstevel@tonic-gate  */
9817c478bd9Sstevel@tonic-gate struct ddi_callback {
9827c478bd9Sstevel@tonic-gate 	struct ddi_callback	*c_nfree;
9837c478bd9Sstevel@tonic-gate 	struct ddi_callback	*c_nlist;
9847c478bd9Sstevel@tonic-gate 	int			(*c_call)();
9857c478bd9Sstevel@tonic-gate 	int			c_count;
9867c478bd9Sstevel@tonic-gate 	caddr_t			c_arg;
9877c478bd9Sstevel@tonic-gate 	size_t			c_size;
9887c478bd9Sstevel@tonic-gate };
9897c478bd9Sstevel@tonic-gate 
990b9ccdc5aScth /*
991b9ccdc5aScth  * Pure dynamic property declaration. A pure dynamic property is a property
992b9ccdc5aScth  * for which a driver's prop_op(9E) implementation will return a value on
993b9ccdc5aScth  * demand, but the property name does not exist on a property list (global,
994b9ccdc5aScth  * driver, system, or hardware) - the person asking for the value must know
995b9ccdc5aScth  * the name and type information.
996b9ccdc5aScth  *
997b9ccdc5aScth  * For a pure dynamic property to show up in a di_init() devinfo shapshot, the
998b9ccdc5aScth  * devinfo driver must know name and type. The i_ddi_prop_dyn_t mechanism
999b9ccdc5aScth  * allows a driver to define an array of the name/type information of its
1000b9ccdc5aScth  * dynamic properties. When a driver declares its dynamic properties in a
1001b9ccdc5aScth  * i_ddi_prop_dyn_t array, and registers that array using
1002b9ccdc5aScth  * i_ddi_prop_dyn_driver_set() the devinfo driver has sufficient information
1003b9ccdc5aScth  * to represent the properties in a snapshot - calling the driver's
1004b9ccdc5aScth  * prop_op(9E) to obtain values.
1005b9ccdc5aScth  *
1006b9ccdc5aScth  * The last element of a i_ddi_prop_dyn_t is detected via a NULL dp_name value.
1007b9ccdc5aScth  *
1008b9ccdc5aScth  * A pure dynamic property name associated with a minor_node/dev_t should be
1009b9ccdc5aScth  * defined with a dp_spec_type of S_IFCHR or S_IFBLK, as appropriate.  The
1010b9ccdc5aScth  * driver's prop_op(9E) entry point will be called for all
1011b9ccdc5aScth  * ddi_create_minor_node(9F) nodes of the specified spec_type. For a driver
1012b9ccdc5aScth  * where not all minor_node/dev_t combinations support the same named
1013b9ccdc5aScth  * properties, it is the responsibility of the prop_op(9E) implementation to
1014b9ccdc5aScth  * sort out what combinations are appropriate.
1015b9ccdc5aScth  *
1016b9ccdc5aScth  * A pure dynamic property of a devinfo node should be defined with a
1017b9ccdc5aScth  * dp_spec_type of 0.
1018b9ccdc5aScth  *
1019b9ccdc5aScth  * NB: Public DDI property interfaces no longer support pure dynamic
1020b9ccdc5aScth  * properties, but they are still still used.  A prime example is the cmlb
1021b9ccdc5aScth  * implementation of size(9P) properties. Using pure dynamic properties
1022b9ccdc5aScth  * reduces the space required to maintain per-partition information. Since
1023b9ccdc5aScth  * there are no public interfaces to create pure dynamic properties,
1024b9ccdc5aScth  * the i_ddi_prop_dyn_t mechanism should remain private.
1025b9ccdc5aScth  */
1026b9ccdc5aScth typedef struct i_ddi_prop_dyn {
1027b9ccdc5aScth 	char	*dp_name;		/* name of dynamic property */
1028b9ccdc5aScth 	int	dp_type;		/* DDI_PROP_TYPE_ of property */
1029b9ccdc5aScth 	int	dp_spec_type;		/* 0, S_IFCHR, S_IFBLK */
1030b9ccdc5aScth } i_ddi_prop_dyn_t;
1031b9ccdc5aScth void			i_ddi_prop_dyn_driver_set(dev_info_t *,
1032b9ccdc5aScth 			    i_ddi_prop_dyn_t *);
1033b9ccdc5aScth i_ddi_prop_dyn_t	*i_ddi_prop_dyn_driver_get(dev_info_t *);
1034b9ccdc5aScth void			i_ddi_prop_dyn_parent_set(dev_info_t *,
1035b9ccdc5aScth 			    i_ddi_prop_dyn_t *);
1036b9ccdc5aScth i_ddi_prop_dyn_t	*i_ddi_prop_dyn_parent_get(dev_info_t *);
1037b9ccdc5aScth void			i_ddi_prop_dyn_cache_invalidate(dev_info_t *,
1038b9ccdc5aScth 			    i_ddi_prop_dyn_t *);
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate /*
10417c478bd9Sstevel@tonic-gate  * Device id - Internal definition.
10427c478bd9Sstevel@tonic-gate  */
10437c478bd9Sstevel@tonic-gate #define	DEVID_MAGIC_MSB		0x69
10447c478bd9Sstevel@tonic-gate #define	DEVID_MAGIC_LSB		0x64
10457c478bd9Sstevel@tonic-gate #define	DEVID_REV_MSB		0x00
10467c478bd9Sstevel@tonic-gate #define	DEVID_REV_LSB		0x01
10477c478bd9Sstevel@tonic-gate #define	DEVID_HINT_SIZE		4
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate typedef struct impl_devid {
10507c478bd9Sstevel@tonic-gate 	uchar_t	did_magic_hi;			/* device id magic # (msb) */
10517c478bd9Sstevel@tonic-gate 	uchar_t	did_magic_lo;			/* device id magic # (lsb) */
10527c478bd9Sstevel@tonic-gate 	uchar_t	did_rev_hi;			/* device id revision # (msb) */
10537c478bd9Sstevel@tonic-gate 	uchar_t	did_rev_lo;			/* device id revision # (lsb) */
10547c478bd9Sstevel@tonic-gate 	uchar_t	did_type_hi;			/* device id type (msb) */
10557c478bd9Sstevel@tonic-gate 	uchar_t	did_type_lo;			/* device id type (lsb) */
10567c478bd9Sstevel@tonic-gate 	uchar_t	did_len_hi;			/* length of devid data (msb) */
10577c478bd9Sstevel@tonic-gate 	uchar_t	did_len_lo;			/* length of devid data (lsb) */
10587c478bd9Sstevel@tonic-gate 	char	did_driver[DEVID_HINT_SIZE];	/* driver name - HINT */
10597c478bd9Sstevel@tonic-gate 	char	did_id[1];			/* start of device id data */
10607c478bd9Sstevel@tonic-gate } impl_devid_t;
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate #define	DEVID_GETTYPE(devid)		((ushort_t) \
10637c478bd9Sstevel@tonic-gate 					    (((devid)->did_type_hi << NBBY) + \
10647c478bd9Sstevel@tonic-gate 					    (devid)->did_type_lo))
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate #define	DEVID_FORMTYPE(devid, type)	(devid)->did_type_hi = hibyte((type)); \
10677c478bd9Sstevel@tonic-gate 					(devid)->did_type_lo = lobyte((type));
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate #define	DEVID_GETLEN(devid)		((ushort_t) \
10707c478bd9Sstevel@tonic-gate 					    (((devid)->did_len_hi << NBBY) + \
10717c478bd9Sstevel@tonic-gate 					    (devid)->did_len_lo))
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate #define	DEVID_FORMLEN(devid, len)	(devid)->did_len_hi = hibyte((len)); \
10747c478bd9Sstevel@tonic-gate 					(devid)->did_len_lo = lobyte((len));
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate /*
10777c478bd9Sstevel@tonic-gate  * Per PSARC/1995/352, a binary devid contains fields for <magic number>,
10787c478bd9Sstevel@tonic-gate  * <revision>, <driver_hint>, <type>, <id_length>, and the <id> itself.
10797c478bd9Sstevel@tonic-gate  * This proposal would encode the binary devid into a string consisting
10807c478bd9Sstevel@tonic-gate  * of "<magic><revision>,<driver_hint>@<type><id>" as indicated below
10817c478bd9Sstevel@tonic-gate  * (<id_length> is rederived from the length of the string
10827c478bd9Sstevel@tonic-gate  * representation of the <id>):
10837c478bd9Sstevel@tonic-gate  *
10847c478bd9Sstevel@tonic-gate  *	<magic>		->"id"
10857c478bd9Sstevel@tonic-gate  *
10867c478bd9Sstevel@tonic-gate  *	<rev>		->"%d"	// "0" -> type of DEVID_NONE  "id0"
10877c478bd9Sstevel@tonic-gate  *				// NOTE: PSARC/1995/352 <revision> is "1".
10887c478bd9Sstevel@tonic-gate  *				// NOTE: support limited to 10 revisions
10897c478bd9Sstevel@tonic-gate  *				//	in current implementation
10907c478bd9Sstevel@tonic-gate  *
10917c478bd9Sstevel@tonic-gate  *	<driver_hint>	->"%s"	// "sd"/"ssd"
10927c478bd9Sstevel@tonic-gate  *				// NOTE: driver names limited to 4
10937c478bd9Sstevel@tonic-gate  *				//	characters for <revision> "1"
10947c478bd9Sstevel@tonic-gate  *
10957c478bd9Sstevel@tonic-gate  *	<type>		->'w' |	// DEVID_SCSI3_WWN	<hex_id>
10967c478bd9Sstevel@tonic-gate  *			'W' |	// DEVID_SCSI3_WWN	<ascii_id>
10977c478bd9Sstevel@tonic-gate  *			't' |	// DEVID_SCSI3_VPD_T10	<hex_id>
10987c478bd9Sstevel@tonic-gate  *			'T' |	// DEVID_SCSI3_VPD_T10	<ascii_id>
10997c478bd9Sstevel@tonic-gate  *			'x' |	// DEVID_SCSI3_VPD_EUI	<hex_id>
11007c478bd9Sstevel@tonic-gate  *			'X' |	// DEVID_SCSI3_VPD_EUI	<ascii_id>
11017c478bd9Sstevel@tonic-gate  *			'n' |	// DEVID_SCSI3_VPD_NAA	<hex_id>
11027c478bd9Sstevel@tonic-gate  *			'N' |	// DEVID_SCSI3_VPD_NAA	<ascii_id>
11037c478bd9Sstevel@tonic-gate  *			's' |	// DEVID_SCSI_SERIAL	<hex_id>
11047c478bd9Sstevel@tonic-gate  *			'S' |	// DEVID_SCSI_SERIAL	<ascii_id>
11057c478bd9Sstevel@tonic-gate  *			'f' |	// DEVID_FAB		<hex_id>
11067c478bd9Sstevel@tonic-gate  *			'F' |	// DEVID_FAB		<ascii_id>
11077c478bd9Sstevel@tonic-gate  *			'e' |	// DEVID_ENCAP		<hex_id>
11087c478bd9Sstevel@tonic-gate  *			'E' |	// DEVID_ENCAP		<ascii_id>
11097c478bd9Sstevel@tonic-gate  *			'a' |	// DEVID_ATA_SERIAL	<hex_id>
11107c478bd9Sstevel@tonic-gate  *			'A' |	// DEVID_ATA_SERIAL	<ascii_id>
11117c478bd9Sstevel@tonic-gate  *			'u' |	// unknown		<hex_id>
11127c478bd9Sstevel@tonic-gate  *			'U'	// unknown		<ascii_id>
11137c478bd9Sstevel@tonic-gate  *				// NOTE:lower case -> <hex_id>
11147c478bd9Sstevel@tonic-gate  *				//	upper case -> <ascii_id>
11157c478bd9Sstevel@tonic-gate  *				// NOTE:this covers all types currently
11167c478bd9Sstevel@tonic-gate  *				//	defined for <revision> 1.
11177c478bd9Sstevel@tonic-gate  *				// NOTE:a <type> can be added
11187c478bd9Sstevel@tonic-gate  *				//	without changing the <revision>.
11197c478bd9Sstevel@tonic-gate  *
11207c478bd9Sstevel@tonic-gate  *	<id>		-> <ascii_id> |	// <type> is upper case
11217c478bd9Sstevel@tonic-gate  *			<hex_id>	// <type> is lower case
11227c478bd9Sstevel@tonic-gate  *
11237c478bd9Sstevel@tonic-gate  *	<ascii_id>	// only if all bytes of binary <id> field
11247c478bd9Sstevel@tonic-gate  *			// are in the set:
11257c478bd9Sstevel@tonic-gate  *			//	[A-Z][a-z][0-9]+-.= and space and 0x00
11267c478bd9Sstevel@tonic-gate  *			// the encoded form is:
11277c478bd9Sstevel@tonic-gate  *			//	[A-Z][a-z][0-9]+-.= and _ and ~
11287c478bd9Sstevel@tonic-gate  *			//	NOTE: ' ' <=> '_', 0x00 <=> '~'
11297c478bd9Sstevel@tonic-gate  *			// these sets are chosen to avoid shell
11307c478bd9Sstevel@tonic-gate  *			// and conflicts with DDI node names.
11317c478bd9Sstevel@tonic-gate  *
11327c478bd9Sstevel@tonic-gate  *	<hex_id>	// if not <ascii_id>; each byte of binary
11337c478bd9Sstevel@tonic-gate  *			// <id> maps a to 2 digit ascii hex
11347c478bd9Sstevel@tonic-gate  *			// representation in the string.
11357c478bd9Sstevel@tonic-gate  *
11367c478bd9Sstevel@tonic-gate  * This encoding provides a meaningful correlation between the /devices
11377c478bd9Sstevel@tonic-gate  * path and the devid string where possible.
11387c478bd9Sstevel@tonic-gate  *
11397c478bd9Sstevel@tonic-gate  *   Fibre:
11407c478bd9Sstevel@tonic-gate  *	sbus@6,0/SUNW,socal@d,10000/sf@1,0/ssd@w21000020370bb488,0:c,raw
11417c478bd9Sstevel@tonic-gate  *	id1,ssd@w20000020370bb488:c,raw
11427c478bd9Sstevel@tonic-gate  *
11437c478bd9Sstevel@tonic-gate  *   Copper:
11447c478bd9Sstevel@tonic-gate  *	sbus@7,0/SUNW,fas@3,8800000/sd@a,0:c
11457c478bd9Sstevel@tonic-gate  *	id1,sd@SIBM_____1XY210__________:c
11467c478bd9Sstevel@tonic-gate  */
11477c478bd9Sstevel@tonic-gate /* determine if a byte of an id meets ASCII representation requirements */
11487c478bd9Sstevel@tonic-gate #define	DEVID_IDBYTE_ISASCII(b)		(				\
11497c478bd9Sstevel@tonic-gate 	(((b) >= 'a') && ((b) <= 'z')) ||				\
11507c478bd9Sstevel@tonic-gate 	(((b) >= 'A') && ((b) <= 'Z')) ||				\
11517c478bd9Sstevel@tonic-gate 	(((b) >= '0') && ((b) <= '9')) ||				\
11527c478bd9Sstevel@tonic-gate 	(b == '+') || (b == '-') || (b == '.') || (b == '=') ||		\
11537c478bd9Sstevel@tonic-gate 	(b == ' ') || (b == 0x00))
11547c478bd9Sstevel@tonic-gate 
11557c478bd9Sstevel@tonic-gate /* set type to lower case to indicate that the did_id field is ascii */
11567c478bd9Sstevel@tonic-gate #define	DEVID_TYPE_SETASCII(c)	(c - 0x20)	/* 'a' -> 'A' */
11577c478bd9Sstevel@tonic-gate 
11587c478bd9Sstevel@tonic-gate /* determine from type if did_id field is binary or ascii */
11597c478bd9Sstevel@tonic-gate #define	DEVID_TYPE_ISASCII(c)	(((c) >= 'A') && ((c) <= 'Z'))
11607c478bd9Sstevel@tonic-gate 
11617c478bd9Sstevel@tonic-gate /* convert type field from binary to ascii */
11627c478bd9Sstevel@tonic-gate #define	DEVID_TYPE_BINTOASCII(b)	(				\
11637c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_WWN)	? 'w' :				\
11647c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_T10)	? 't' :				\
11657c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_EUI)	? 'x' :				\
11667c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_NAA)	? 'n' :				\
11677c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI_SERIAL)	? 's' :				\
11687c478bd9Sstevel@tonic-gate 	((b) == DEVID_FAB)		? 'f' :				\
11697c478bd9Sstevel@tonic-gate 	((b) == DEVID_ENCAP)		? 'e' :				\
11707c478bd9Sstevel@tonic-gate 	((b) == DEVID_ATA_SERIAL)	? 'a' :				\
11717c478bd9Sstevel@tonic-gate 	'u')						/* unknown */
11727c478bd9Sstevel@tonic-gate 
11737c478bd9Sstevel@tonic-gate /* convert type field from ascii to binary */
11747c478bd9Sstevel@tonic-gate #define	DEVID_TYPE_ASCIITOBIN(c)	(				\
11757c478bd9Sstevel@tonic-gate 	(((c) == 'w') || ((c) == 'W'))	? DEVID_SCSI3_WWN :		\
11767c478bd9Sstevel@tonic-gate 	(((c) == 't') || ((c) == 'T'))	? DEVID_SCSI3_VPD_T10 :		\
11777c478bd9Sstevel@tonic-gate 	(((c) == 'x') || ((c) == 'X'))	? DEVID_SCSI3_VPD_EUI :		\
11787c478bd9Sstevel@tonic-gate 	(((c) == 'n') || ((c) == 'N'))	? DEVID_SCSI3_VPD_NAA :		\
11797c478bd9Sstevel@tonic-gate 	(((c) == 's') || ((c) == 'S'))	? DEVID_SCSI_SERIAL :		\
11807c478bd9Sstevel@tonic-gate 	(((c) == 'f') || ((c) == 'F'))	? DEVID_FAB :			\
11817c478bd9Sstevel@tonic-gate 	(((c) == 'e') || ((c) == 'E'))	? DEVID_ENCAP :			\
11827c478bd9Sstevel@tonic-gate 	(((c) == 'a') || ((c) == 'A'))	? DEVID_ATA_SERIAL :		\
11837c478bd9Sstevel@tonic-gate 	DEVID_MAXTYPE +1)				/* unknown */
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate /* determine if the type should be forced to hex encoding (non-ascii) */
11867c478bd9Sstevel@tonic-gate #define	DEVID_TYPE_BIN_FORCEHEX(b) (	\
11877c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_WWN) ||	\
11887c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_EUI) ||	\
11897c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_NAA) ||	\
11907c478bd9Sstevel@tonic-gate 	((b) == DEVID_FAB))
11917c478bd9Sstevel@tonic-gate 
11927c478bd9Sstevel@tonic-gate /* determine if the type is from a scsi3 vpd */
11937c478bd9Sstevel@tonic-gate #define	IS_DEVID_SCSI3_VPD_TYPE(b) (	\
11947c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_T10) ||	\
11957c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_EUI) ||	\
11967c478bd9Sstevel@tonic-gate 	((b) == DEVID_SCSI3_VPD_NAA))
11977c478bd9Sstevel@tonic-gate 
11987c478bd9Sstevel@tonic-gate /* convert rev field from binary to ascii (only supports 10 revs) */
11997c478bd9Sstevel@tonic-gate #define	DEVID_REV_BINTOASCII(b) (b + '0')
12007c478bd9Sstevel@tonic-gate 
12017c478bd9Sstevel@tonic-gate /* convert rev field from ascii to binary (only supports 10 revs) */
12027c478bd9Sstevel@tonic-gate #define	DEVID_REV_ASCIITOBIN(c) (c - '0')
12037c478bd9Sstevel@tonic-gate 
12047c478bd9Sstevel@tonic-gate /* name of devid property */
12057c478bd9Sstevel@tonic-gate #define	DEVID_PROP_NAME	"devid"
12067c478bd9Sstevel@tonic-gate 
12077c478bd9Sstevel@tonic-gate /*
12087c478bd9Sstevel@tonic-gate  * prop_name used by pci_{save,restore}_config_regs()
12097c478bd9Sstevel@tonic-gate  */
12107c478bd9Sstevel@tonic-gate #define	SAVED_CONFIG_REGS "pci-config-regs"
12117c478bd9Sstevel@tonic-gate #define	SAVED_CONFIG_REGS_MASK "pcie-config-regs-mask"
12127c478bd9Sstevel@tonic-gate #define	SAVED_CONFIG_REGS_CAPINFO "pci-cap-info"
12137c478bd9Sstevel@tonic-gate 
12147c478bd9Sstevel@tonic-gate typedef struct pci_config_header_state {
12157c478bd9Sstevel@tonic-gate 	uint16_t	chs_command;
12167c478bd9Sstevel@tonic-gate 	uint8_t		chs_cache_line_size;
12177c478bd9Sstevel@tonic-gate 	uint8_t		chs_latency_timer;
12187c478bd9Sstevel@tonic-gate 	uint8_t		chs_header_type;
12197c478bd9Sstevel@tonic-gate 	uint8_t		chs_sec_latency_timer;
12207c478bd9Sstevel@tonic-gate 	uint8_t		chs_bridge_control;
12217c478bd9Sstevel@tonic-gate 	uint32_t	chs_base0;
12227c478bd9Sstevel@tonic-gate 	uint32_t	chs_base1;
12237c478bd9Sstevel@tonic-gate 	uint32_t	chs_base2;
12247c478bd9Sstevel@tonic-gate 	uint32_t	chs_base3;
12257c478bd9Sstevel@tonic-gate 	uint32_t	chs_base4;
12267c478bd9Sstevel@tonic-gate 	uint32_t	chs_base5;
12277c478bd9Sstevel@tonic-gate } pci_config_header_state_t;
12287c478bd9Sstevel@tonic-gate 
12297c478bd9Sstevel@tonic-gate #ifdef _KERNEL
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate typedef struct pci_cap_save_desc {
12327c478bd9Sstevel@tonic-gate 	uint16_t	cap_offset;
12337c478bd9Sstevel@tonic-gate 	uint16_t	cap_id;
12347c478bd9Sstevel@tonic-gate 	uint32_t	cap_nregs;
12357c478bd9Sstevel@tonic-gate } pci_cap_save_desc_t;
12367c478bd9Sstevel@tonic-gate 
12377c478bd9Sstevel@tonic-gate typedef struct pci_cap_entry {
12387c478bd9Sstevel@tonic-gate 	uint16_t		cap_id;
1239cb7ea99dSJimmy Vetayases 	uint16_t		cap_reg;
1240cb7ea99dSJimmy Vetayases 	uint16_t		cap_mask;
12417c478bd9Sstevel@tonic-gate 	uint32_t		cap_ndwords;
12427c478bd9Sstevel@tonic-gate 	uint32_t (*cap_save_func)(ddi_acc_handle_t confhdl, uint16_t cap_ptr,
12437c478bd9Sstevel@tonic-gate 	    uint32_t *regbuf, uint32_t ndwords);
12447c478bd9Sstevel@tonic-gate } pci_cap_entry_t;
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
12477c478bd9Sstevel@tonic-gate 
12487c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
12497c478bd9Sstevel@tonic-gate }
12507c478bd9Sstevel@tonic-gate #endif
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate #endif	/* _SYS_DDI_IMPLDEFS_H */
1253