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