xref: /onnv-gate/usr/src/uts/common/sys/pshot.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_SYS_PSHOT_H
28*0Sstevel@tonic-gate #define	_SYS_PSHOT_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef	__cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <sys/sunndi.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /*
39*0Sstevel@tonic-gate  * user accessable features
40*0Sstevel@tonic-gate  */
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /* determines max pshot_minor allocation per softstate */
43*0Sstevel@tonic-gate #define	PSHOT_MAX_MINOR_PERINST		2
44*0Sstevel@tonic-gate #define	PSHOT_MAX_MINOR_NAMELEN		16
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate #define	PSHOT_NODENAME_DEVCTL		"devctl"
47*0Sstevel@tonic-gate #define	PSHOT_NODENAME_TESTCTL		"testctl"
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate #define	PSHOT_PROP_DEVNAME	"dev-name"
50*0Sstevel@tonic-gate #define	PSHOT_PROP_DEVNT	"dev-nt"
51*0Sstevel@tonic-gate #define	PSHOT_PROP_DEVCOMPAT	"dev-compat"
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate #ifdef	_KERNEL
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate #define	PARENT_IS_PSHOT(self)	\
58*0Sstevel@tonic-gate 	(ddi_driver_major(self) == ddi_driver_major(ddi_get_parent(self)))
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate static int pshot_debug = 0;
62*0Sstevel@tonic-gate static int pshot_event_test_enable = 0;
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate #ifdef DEBUG
65*0Sstevel@tonic-gate #define	pshot_debug pshot_debug_on
66*0Sstevel@tonic-gate #define	pshot_event_test_enable pshot_event_test_on
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate static int pshot_debug_on = 0;
69*0Sstevel@tonic-gate static int pshot_event_test_on = 0;
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate #endif
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate #define	PSHOT_MAX_CBCACHE	6
74*0Sstevel@tonic-gate #define	PSHOT_MAX_TSTCACHE	8
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate /*
77*0Sstevel@tonic-gate  * soft state and minor node management
78*0Sstevel@tonic-gate  * (includes user features above)
79*0Sstevel@tonic-gate  */
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate /*
82*0Sstevel@tonic-gate  * a "node number" is currently implemented as an index into a pshot_minor_t
83*0Sstevel@tonic-gate  * array, therefore the max must be less than PSHOT_MAX_MINOR_PERINST and
84*0Sstevel@tonic-gate  * ideally, the minor array should be fully populated, with a node number
85*0Sstevel@tonic-gate  * defined for each index
86*0Sstevel@tonic-gate  */
87*0Sstevel@tonic-gate #define	PSHOT_NODENUM_DEVCTL		0
88*0Sstevel@tonic-gate #define	PSHOT_NODENUM_TESTCTL		1
89*0Sstevel@tonic-gate #define	PSHOT_MAX_NODENUM		PSHOT_NODENUM_TESTCTL
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate typedef struct pshot_minor pshot_minor_t;
92*0Sstevel@tonic-gate typedef struct pshot pshot_t;
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate struct pshot_minor {
95*0Sstevel@tonic-gate 	pshot_t		*pshot;
96*0Sstevel@tonic-gate 	minor_t		minor;
97*0Sstevel@tonic-gate 	char		name[PSHOT_MAX_MINOR_NAMELEN];
98*0Sstevel@tonic-gate };
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate struct pshot {
101*0Sstevel@tonic-gate 	kmutex_t	lock;
102*0Sstevel@tonic-gate 	uint_t		state;
103*0Sstevel@tonic-gate 	dev_info_t	*dip;
104*0Sstevel@tonic-gate 	int		instance;
105*0Sstevel@tonic-gate 	ndi_event_hdl_t	ndi_event_hdl;
106*0Sstevel@tonic-gate 	ndi_event_set_t	ndi_events;
107*0Sstevel@tonic-gate 	ddi_iblock_cookie_t	iblock_cookie;
108*0Sstevel@tonic-gate 	ddi_callback_id_t 	callback_cache[PSHOT_MAX_CBCACHE];
109*0Sstevel@tonic-gate 	ddi_callback_id_t	test_callback_cache[PSHOT_MAX_TSTCACHE];
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate 	pshot_minor_t	nodes[PSHOT_MAX_MINOR_PERINST];
112*0Sstevel@tonic-gate 	int	level;		/* pm power level */
113*0Sstevel@tonic-gate 	int	busy;		/* pm busy state */
114*0Sstevel@tonic-gate 	int	busy_ioctl;	/* track busy and idle ioctl calls */
115*0Sstevel@tonic-gate };
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate static size_t pshot_numbits(size_t);
119*0Sstevel@tonic-gate static minor_t pshot_minor_encode(int, minor_t);
120*0Sstevel@tonic-gate static int pshot_minor_decode_inst(minor_t);
121*0Sstevel@tonic-gate static minor_t pshot_minor_decode_nodenum(minor_t);
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate #define	PSHOT_NODENUM_BITS()	pshot_numbits(PSHOT_MAX_MINOR_PERINST)
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate /*
126*0Sstevel@tonic-gate  * children device configuration
127*0Sstevel@tonic-gate  */
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate typedef struct pshot_device {
130*0Sstevel@tonic-gate 	char *name;
131*0Sstevel@tonic-gate 	char *nodetype;
132*0Sstevel@tonic-gate 	char *compat;
133*0Sstevel@tonic-gate } pshot_device_t;
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate #define	PSHOT_DEV_ANYNT		0x1
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate static char *pshot_str2nt(char *);
138*0Sstevel@tonic-gate static pshot_device_t *pshot_devices_from_props(dev_info_t *, size_t *, int);
139*0Sstevel@tonic-gate static void pshot_devices_free(pshot_device_t *, size_t);
140*0Sstevel@tonic-gate static int pshot_devices_setup(dev_info_t *);
141*0Sstevel@tonic-gate static int pshot_devices_grow(pshot_device_t **, size_t,
142*0Sstevel@tonic-gate     const pshot_device_t *, size_t);
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate /*
146*0Sstevel@tonic-gate  * softstate state bits
147*0Sstevel@tonic-gate  */
148*0Sstevel@tonic-gate #define	IS_OPEN				0x0001
149*0Sstevel@tonic-gate #define	IS_OPEN_EXCL			0x0002
150*0Sstevel@tonic-gate #define	DEV_RESET_PENDING		0x0004
151*0Sstevel@tonic-gate #define	BUS_RESET_PENDING		0x0008
152*0Sstevel@tonic-gate #define	POWER_FLAG			0x0010
153*0Sstevel@tonic-gate #define	FAIL_SUSPEND_FLAG		0x0020
154*0Sstevel@tonic-gate #define	STRICT_PARENT			0x0040
155*0Sstevel@tonic-gate #define	NO_INVOL_FLAG			0x0080
156*0Sstevel@tonic-gate #define	PM_SUPPORTED			0x0100
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate /*
159*0Sstevel@tonic-gate  * Leaf ops (supports hotplug controls to the device)
160*0Sstevel@tonic-gate  */
161*0Sstevel@tonic-gate static int pshot_open(dev_t *, int, int, cred_t *);
162*0Sstevel@tonic-gate static int pshot_close(dev_t, int, int, cred_t *);
163*0Sstevel@tonic-gate static int pshot_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
164*0Sstevel@tonic-gate static int pshot_probe(dev_info_t *);
165*0Sstevel@tonic-gate static int pshot_attach(dev_info_t *, ddi_attach_cmd_t);
166*0Sstevel@tonic-gate static int pshot_detach(dev_info_t *, ddi_detach_cmd_t);
167*0Sstevel@tonic-gate static int pshot_info(dev_info_t *, ddi_info_cmd_t,  void *, void **);
168*0Sstevel@tonic-gate static int pshot_power(dev_info_t *dip, int cmpt, int level);
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate static int pshot_devctl(pshot_t *, minor_t, int, intptr_t, int, cred_t *,
171*0Sstevel@tonic-gate     int *);
172*0Sstevel@tonic-gate static int pshot_testctl(pshot_t *, minor_t, int, intptr_t, int, cred_t *,
173*0Sstevel@tonic-gate     int *);
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate /*
176*0Sstevel@tonic-gate  * Event handling prototype support.
177*0Sstevel@tonic-gate  */
178*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_DEV_OFFLINE	"pshot_dev_offline"
179*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_DEV_RESET	"pshot_dev_reset"
180*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_BUS_RESET	"pshot_bus_reset"
181*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_BUS_QUIESCE	"pshot_bus_quiesce"
182*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_BUS_UNQUIESCE	"pshot_bus_unquiesce"
183*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_BUS_TEST_POST	"pshot_bus_test_post"
184*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_DEBUG_SET	"pshot_debug_set"
185*0Sstevel@tonic-gate #define	PSHOT_EVENT_NAME_SUB_RESET	"pshot_sub_reset"
186*0Sstevel@tonic-gate 						/* for hash sanity check */
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate #define	PSHOT_EVENT_TAG_OFFLINE		0
189*0Sstevel@tonic-gate #define	PSHOT_EVENT_TAG_DEV_RESET	1
190*0Sstevel@tonic-gate #define	PSHOT_EVENT_TAG_BUS_RESET	2
191*0Sstevel@tonic-gate #define	PSHOT_EVENT_TAG_BUS_QUIESCE	3
192*0Sstevel@tonic-gate #define	PSHOT_EVENT_TAG_BUS_UNQUIESCE	4
193*0Sstevel@tonic-gate #define	PSHOT_EVENT_TAG_TEST_POST	5
194*0Sstevel@tonic-gate 
195*0Sstevel@tonic-gate typedef struct pshot_event_callback {
196*0Sstevel@tonic-gate 	dev_info_t			*dip;
197*0Sstevel@tonic-gate 	int				(*callback)();
198*0Sstevel@tonic-gate 	void				*arg;
199*0Sstevel@tonic-gate 	struct pshot_event_callback	*next;
200*0Sstevel@tonic-gate } ps_callback_t;
201*0Sstevel@tonic-gate 
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate static void pshot_event_cb(dev_info_t *dip, ddi_eventcookie_t cookie,
204*0Sstevel@tonic-gate 	void *arg, void *bus_impldata);
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate static int pshot_event(pshot_t *pshot, int event_tag, dev_info_t *child,
207*0Sstevel@tonic-gate 	void *bus_impldata);
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate #ifdef DEBUG
210*0Sstevel@tonic-gate static void pshot_event_cb_test(dev_info_t *dip, ddi_eventcookie_t cookie,
211*0Sstevel@tonic-gate     void *arg, void *bus_impldata);
212*0Sstevel@tonic-gate static void pshot_event_test(void *arg);
213*0Sstevel@tonic-gate static void pshot_event_test_post_one(void *arg);
214*0Sstevel@tonic-gate #endif
215*0Sstevel@tonic-gate 
216*0Sstevel@tonic-gate /* event busops */
217*0Sstevel@tonic-gate static int pshot_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
218*0Sstevel@tonic-gate     char *name, ddi_eventcookie_t *event_cookiep);
219*0Sstevel@tonic-gate static int pshot_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
220*0Sstevel@tonic-gate     ddi_eventcookie_t eventid, void (*callback)(), void *arg,
221*0Sstevel@tonic-gate     ddi_callback_id_t *cb_id);
222*0Sstevel@tonic-gate static int pshot_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id);
223*0Sstevel@tonic-gate static int pshot_post_event(dev_info_t *dip, dev_info_t *rdip,
224*0Sstevel@tonic-gate     ddi_eventcookie_t eventid, void *impl_data);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate /* function prototypes */
227*0Sstevel@tonic-gate static int pshot_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_ctl_enum_t ctlop,
228*0Sstevel@tonic-gate     void *arg, void *result);
229*0Sstevel@tonic-gate static int pshot_initchild(dev_info_t *, dev_info_t *);
230*0Sstevel@tonic-gate static int pshot_uninitchild(dev_info_t *, dev_info_t *);
231*0Sstevel@tonic-gate static int pshot_bus_config(dev_info_t *, uint_t,
232*0Sstevel@tonic-gate 	ddi_bus_config_op_t, void *, dev_info_t **);
233*0Sstevel@tonic-gate static int pshot_bus_unconfig(dev_info_t *, uint_t,
234*0Sstevel@tonic-gate     ddi_bus_config_op_t, void *);
235*0Sstevel@tonic-gate static int pshot_bus_config_setup_nexus(dev_info_t *, char *cname, char *caddr);
236*0Sstevel@tonic-gate static int pshot_bus_config_setup_leaf(dev_info_t *, char *cname, char *caddr);
237*0Sstevel@tonic-gate static int pshot_bus_config_test_specials(dev_info_t *parent,
238*0Sstevel@tonic-gate 	char *devname, char *cname, char *caddr);
239*0Sstevel@tonic-gate static int pshot_bus_introp(dev_info_t *, dev_info_t *, ddi_intr_op_t,
240*0Sstevel@tonic-gate 	ddi_intr_handle_impl_t *, void *);
241*0Sstevel@tonic-gate 
242*0Sstevel@tonic-gate static void pshot_setup_autoattach(dev_info_t *);
243*0Sstevel@tonic-gate static int pshot_bus_power(dev_info_t *dip, void *impl_arg,
244*0Sstevel@tonic-gate 	    pm_bus_power_op_t op, void *arg, void *result);
245*0Sstevel@tonic-gate static void pshot_nexus_properties(dev_info_t *, dev_info_t *, char *, char *);
246*0Sstevel@tonic-gate static void pshot_leaf_properties(dev_info_t *, dev_info_t *, char *, char *);
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate #endif /* _KERNEL */
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate 
252*0Sstevel@tonic-gate #ifdef	__cplusplus
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate #endif
255*0Sstevel@tonic-gate 
256*0Sstevel@tonic-gate #endif /* _SYS_PSHOT_H */
257