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 2004 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_DEVCTL_H
28*0Sstevel@tonic-gate #define	_SYS_DEVCTL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * Device control interfaces
34*0Sstevel@tonic-gate  */
35*0Sstevel@tonic-gate #include <sys/types.h>
36*0Sstevel@tonic-gate #include <sys/nvpair.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #ifdef	__cplusplus
39*0Sstevel@tonic-gate extern "C" {
40*0Sstevel@tonic-gate #endif
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate /*
43*0Sstevel@tonic-gate  * structure used to pass IOCTL data between the libdevice interfaces
44*0Sstevel@tonic-gate  * and nexus driver devctl IOCTL interface.
45*0Sstevel@tonic-gate  *
46*0Sstevel@tonic-gate  * Applications and nexus drivers may not access the contents of this
47*0Sstevel@tonic-gate  * structure directly.  Instead, drivers must use the ndi_dc_XXX(9n)
48*0Sstevel@tonic-gate  * interfaces, while applications must use the interfaces provided by
49*0Sstevel@tonic-gate  * libdevice.so.1.
50*0Sstevel@tonic-gate  */
51*0Sstevel@tonic-gate struct devctl_iocdata {
52*0Sstevel@tonic-gate 	uint_t	cmd;			/* ioctl cmd */
53*0Sstevel@tonic-gate 	uint_t	flags;			/* command-specific flags */
54*0Sstevel@tonic-gate 	void	*cpyout_buf;		/* copyout vector */
55*0Sstevel@tonic-gate 	nvlist_t *nvl_user;		/* application defined attributes */
56*0Sstevel@tonic-gate 	size_t  nvl_usersz;
57*0Sstevel@tonic-gate 	char	*c_nodename;		/* child device nodename */
58*0Sstevel@tonic-gate 	char	*c_unitaddr;		/* child device unit address */
59*0Sstevel@tonic-gate };
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate #if defined(_SYSCALL32)
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate  * Structure to pass/return data from 32-bit program's.
64*0Sstevel@tonic-gate  */
65*0Sstevel@tonic-gate struct devctl_iocdata32 {
66*0Sstevel@tonic-gate 	uint32_t  cmd;
67*0Sstevel@tonic-gate 	uint32_t  flags;
68*0Sstevel@tonic-gate 	caddr32_t cpyout_buf;
69*0Sstevel@tonic-gate 	caddr32_t nvl_user;
70*0Sstevel@tonic-gate 	uint32_t  nvl_usersz;
71*0Sstevel@tonic-gate 	caddr32_t c_nodename;
72*0Sstevel@tonic-gate 	caddr32_t c_unitaddr;
73*0Sstevel@tonic-gate };
74*0Sstevel@tonic-gate #endif
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate /*
77*0Sstevel@tonic-gate  * State of receptacle for an Attachment Point.
78*0Sstevel@tonic-gate  */
79*0Sstevel@tonic-gate typedef enum {
80*0Sstevel@tonic-gate 	AP_RSTATE_EMPTY,
81*0Sstevel@tonic-gate 	AP_RSTATE_DISCONNECTED,
82*0Sstevel@tonic-gate 	AP_RSTATE_CONNECTED
83*0Sstevel@tonic-gate } ap_rstate_t;
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate /*
86*0Sstevel@tonic-gate  * State of occupant for an Attachment Point.
87*0Sstevel@tonic-gate  */
88*0Sstevel@tonic-gate typedef enum {
89*0Sstevel@tonic-gate 	AP_OSTATE_UNCONFIGURED,
90*0Sstevel@tonic-gate 	AP_OSTATE_CONFIGURED
91*0Sstevel@tonic-gate } ap_ostate_t;
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate /*
94*0Sstevel@tonic-gate  * condition of an Attachment Point.
95*0Sstevel@tonic-gate  */
96*0Sstevel@tonic-gate typedef enum {
97*0Sstevel@tonic-gate 	AP_COND_UNKNOWN,
98*0Sstevel@tonic-gate 	AP_COND_OK,
99*0Sstevel@tonic-gate 	AP_COND_FAILING,
100*0Sstevel@tonic-gate 	AP_COND_FAILED,
101*0Sstevel@tonic-gate 	AP_COND_UNUSABLE
102*0Sstevel@tonic-gate } ap_condition_t;
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate /*
105*0Sstevel@tonic-gate  * structure used to return the state of Attachment Point (AP) thru
106*0Sstevel@tonic-gate  * devctl_ap_getstate() interface.
107*0Sstevel@tonic-gate  */
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate typedef struct devctl_ap_state {
110*0Sstevel@tonic-gate 	ap_rstate_t	ap_rstate; 	/* receptacle state */
111*0Sstevel@tonic-gate 	ap_ostate_t	ap_ostate;	/* occupant state */
112*0Sstevel@tonic-gate 	ap_condition_t	ap_condition;	/* condition of AP */
113*0Sstevel@tonic-gate 	time_t		ap_last_change;
114*0Sstevel@tonic-gate 	uint32_t	ap_error_code;	/* error code */
115*0Sstevel@tonic-gate 	uint8_t		ap_in_transition;
116*0Sstevel@tonic-gate } devctl_ap_state_t;
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate #if defined(_SYSCALL32)
119*0Sstevel@tonic-gate /*
120*0Sstevel@tonic-gate  * Structure to pass/return data from 32-bit program's.
121*0Sstevel@tonic-gate  */
122*0Sstevel@tonic-gate typedef struct devctl_ap_state32 {
123*0Sstevel@tonic-gate 	ap_rstate_t	ap_rstate; 	/* receptacle state */
124*0Sstevel@tonic-gate 	ap_ostate_t	ap_ostate;	/* occupant state */
125*0Sstevel@tonic-gate 	ap_condition_t	ap_condition;	/* condition of AP */
126*0Sstevel@tonic-gate 	time32_t	ap_last_change;
127*0Sstevel@tonic-gate 	uint32_t	ap_error_code;	/* error code */
128*0Sstevel@tonic-gate 	uint8_t		ap_in_transition;
129*0Sstevel@tonic-gate } devctl_ap_state32_t;
130*0Sstevel@tonic-gate #endif
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate #define	DEVCTL_IOC		(0xDC << 16)
133*0Sstevel@tonic-gate #define	DEVCTL_IOC_MAX		(DEVCTL_IOC | 0xFFFF)
134*0Sstevel@tonic-gate #define	DEVCTL_BUS_QUIESCE	(DEVCTL_IOC | 1)
135*0Sstevel@tonic-gate #define	DEVCTL_BUS_UNQUIESCE	(DEVCTL_IOC | 2)
136*0Sstevel@tonic-gate #define	DEVCTL_BUS_RESETALL	(DEVCTL_IOC | 3)
137*0Sstevel@tonic-gate #define	DEVCTL_BUS_RESET	(DEVCTL_IOC | 4)
138*0Sstevel@tonic-gate #define	DEVCTL_BUS_GETSTATE	(DEVCTL_IOC | 5)
139*0Sstevel@tonic-gate #define	DEVCTL_DEVICE_ONLINE	(DEVCTL_IOC | 6)
140*0Sstevel@tonic-gate #define	DEVCTL_DEVICE_OFFLINE	(DEVCTL_IOC | 7)
141*0Sstevel@tonic-gate #define	DEVCTL_DEVICE_GETSTATE	(DEVCTL_IOC | 9)
142*0Sstevel@tonic-gate #define	DEVCTL_DEVICE_RESET	(DEVCTL_IOC | 10)
143*0Sstevel@tonic-gate #define	DEVCTL_BUS_CONFIGURE	(DEVCTL_IOC | 11)
144*0Sstevel@tonic-gate #define	DEVCTL_BUS_UNCONFIGURE	(DEVCTL_IOC | 12)
145*0Sstevel@tonic-gate #define	DEVCTL_DEVICE_REMOVE	(DEVCTL_IOC | 13)
146*0Sstevel@tonic-gate #define	DEVCTL_AP_CONNECT	(DEVCTL_IOC | 14)
147*0Sstevel@tonic-gate #define	DEVCTL_AP_DISCONNECT	(DEVCTL_IOC | 15)
148*0Sstevel@tonic-gate #define	DEVCTL_AP_INSERT	(DEVCTL_IOC | 16)
149*0Sstevel@tonic-gate #define	DEVCTL_AP_REMOVE	(DEVCTL_IOC | 17)
150*0Sstevel@tonic-gate #define	DEVCTL_AP_CONFIGURE	(DEVCTL_IOC | 18)
151*0Sstevel@tonic-gate #define	DEVCTL_AP_UNCONFIGURE	(DEVCTL_IOC | 19)
152*0Sstevel@tonic-gate #define	DEVCTL_AP_GETSTATE	(DEVCTL_IOC | 20)
153*0Sstevel@tonic-gate #define	DEVCTL_AP_CONTROL	(DEVCTL_IOC | 21)
154*0Sstevel@tonic-gate #define	DEVCTL_BUS_DEV_CREATE	(DEVCTL_IOC | 22)
155*0Sstevel@tonic-gate #define	DEVCTL_PM_BUSY_COMP	(DEVCTL_IOC | 23)
156*0Sstevel@tonic-gate #define	DEVCTL_PM_IDLE_COMP	(DEVCTL_IOC | 24)
157*0Sstevel@tonic-gate #define	DEVCTL_PM_RAISE_PWR	(DEVCTL_IOC | 25)
158*0Sstevel@tonic-gate #define	DEVCTL_PM_LOWER_PWR	(DEVCTL_IOC | 26)
159*0Sstevel@tonic-gate #define	DEVCTL_PM_CHANGE_PWR_LOW	(DEVCTL_IOC | 27)
160*0Sstevel@tonic-gate #define	DEVCTL_PM_CHANGE_PWR_HIGH	(DEVCTL_IOC | 28)
161*0Sstevel@tonic-gate #define	DEVCTL_PM_POWER		(DEVCTL_IOC | 29)
162*0Sstevel@tonic-gate #define	DEVCTL_PM_PROM_PRINTF	(DEVCTL_IOC | 30)
163*0Sstevel@tonic-gate #define	DEVCTL_PM_FAIL_SUSPEND	(DEVCTL_IOC | 31)
164*0Sstevel@tonic-gate #define	DEVCTL_PM_PWR_HAS_CHANGED_ON_RESUME	(DEVCTL_IOC | 32)
165*0Sstevel@tonic-gate #define	DEVCTL_PM_PUP_WITH_PWR_HAS_CHANGED	(DEVCTL_IOC | 34)
166*0Sstevel@tonic-gate #define	DEVCTL_PM_BUSY_COMP_TEST	(DEVCTL_IOC | 35)
167*0Sstevel@tonic-gate #define	DEVCTL_PM_BUS_STRICT_TEST	(DEVCTL_IOC | 36)
168*0Sstevel@tonic-gate #define	DEVCTL_PM_NO_LOWER_POWER	(DEVCTL_IOC | 37)
169*0Sstevel@tonic-gate #define	DEVCTL_PM_BUS_NO_INVOL		(DEVCTL_IOC | 38)
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate /*
172*0Sstevel@tonic-gate  * is (c) in the range of possible devctl IOCTL commands?
173*0Sstevel@tonic-gate  */
174*0Sstevel@tonic-gate #define	IS_DEVCTL(c) (((c) >= DEVCTL_IOC) && ((c) <= DEVCTL_IOC_MAX))
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate /*
177*0Sstevel@tonic-gate  * Device and Bus State definitions
178*0Sstevel@tonic-gate  *
179*0Sstevel@tonic-gate  * Device state is returned as a set of bit-flags that indicate the current
180*0Sstevel@tonic-gate  * operational state of a device node.
181*0Sstevel@tonic-gate  *
182*0Sstevel@tonic-gate  * Device nodes for leaf devices only contain state information for the
183*0Sstevel@tonic-gate  * device itself.  Nexus device nodes contain both Bus and Device state
184*0Sstevel@tonic-gate  * information.
185*0Sstevel@tonic-gate  *
186*0Sstevel@tonic-gate  * 	DEVICE_ONLINE  - Device is available for use by the system.  Mutually
187*0Sstevel@tonic-gate  *                       exclusive with DEVICE_OFFLINE.
188*0Sstevel@tonic-gate  *
189*0Sstevel@tonic-gate  *	DEVICE_OFFLINE - Device is unavailable for use by the system.
190*0Sstevel@tonic-gate  *			 Mutually exclusive with DEVICE_ONLINE and DEVICE_BUSY.
191*0Sstevel@tonic-gate  *
192*0Sstevel@tonic-gate  *	DEVICE_DOWN    - Device has been placed in the "DOWN" state by
193*0Sstevel@tonic-gate  *			 its controlling driver.
194*0Sstevel@tonic-gate  *
195*0Sstevel@tonic-gate  *	DEVICE_BUSY    - Device has open instances or nexus has INITALIZED
196*0Sstevel@tonic-gate  *                       children (nexi).  A device in this state is by
197*0Sstevel@tonic-gate  *			 definition Online.
198*0Sstevel@tonic-gate  *
199*0Sstevel@tonic-gate  * Bus state is returned as a set of bit-flags which indicates the
200*0Sstevel@tonic-gate  * operational state of a bus associated with the nexus dev_info node.
201*0Sstevel@tonic-gate  *
202*0Sstevel@tonic-gate  * 	BUS_ACTIVE     - The bus associated with the device node is Active.
203*0Sstevel@tonic-gate  *                       I/O requests from child devices attached to the
204*0Sstevel@tonic-gate  *			 are initiated (or queued for initiation) as they
205*0Sstevel@tonic-gate  *			 are received.
206*0Sstevel@tonic-gate  *
207*0Sstevel@tonic-gate  *	BUS_QUIESCED   - The bus associated with the device node has been
208*0Sstevel@tonic-gate  *			 Quieced. I/O requests from child devices attached
209*0Sstevel@tonic-gate  *			 to the bus are held pending until the bus nexus is
210*0Sstevel@tonic-gate  *			 Unquiesced.
211*0Sstevel@tonic-gate  *
212*0Sstevel@tonic-gate  *	BUS_SHUTDOWN   - The bus associated with the device node has been
213*0Sstevel@tonic-gate  *			 shutdown by the nexus driver.  I/O requests from
214*0Sstevel@tonic-gate  *			 child devices are returned with an error indicating
215*0Sstevel@tonic-gate  *			 the requested operation failed.
216*0Sstevel@tonic-gate  */
217*0Sstevel@tonic-gate #define	DEVICE_ONLINE	0x1
218*0Sstevel@tonic-gate #define	DEVICE_BUSY	0x2
219*0Sstevel@tonic-gate #define	DEVICE_OFFLINE  0x4
220*0Sstevel@tonic-gate #define	DEVICE_DOWN	0x8
221*0Sstevel@tonic-gate 
222*0Sstevel@tonic-gate #define	BUS_ACTIVE	0x10
223*0Sstevel@tonic-gate #define	BUS_QUIESCED	0x20
224*0Sstevel@tonic-gate #define	BUS_SHUTDOWN	0x40
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate #define	DC_DEVI_NODENAME	"ndi_dc.devi_nodename"
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate #define	DEVCTL_CONSTRUCT	0x1
229*0Sstevel@tonic-gate #define	DEVCTL_OFFLINE		0x2
230*0Sstevel@tonic-gate 
231*0Sstevel@tonic-gate #ifdef	__cplusplus
232*0Sstevel@tonic-gate }
233*0Sstevel@tonic-gate #endif
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate #endif	/* _SYS_DEVCTL_H */
236