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