xref: /freebsd/sys/dev/acpica/acpiio.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1 /*-
2  * Copyright (c) 1999 Takanori Watanabe <takawata@jp.freebsd.org>
3  * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef _ACPIIO_H_
29 #define _ACPIIO_H_
30 
31 /*
32  * Core ACPI subsystem ioctls
33  */
34 #define ACPIIO_SETSLPSTATE	_IOW('P', 3, int) /* DEPRECATED */
35 
36 /* Request S1-5 sleep state. User is notified and then sleep proceeds. */
37 #define ACPIIO_REQSLPSTATE	_IOW('P', 4, int)
38 
39 /* Allow suspend to continue (0) or abort it (errno). */
40 #define ACPIIO_ACKSLPSTATE	_IOW('P', 5, int)
41 
42 struct acpi_battinfo {
43     int	 cap;				/* percent */
44     int	 min;				/* remaining time (in minutes) */
45     int	 state;				/* battery state */
46     int	 rate;				/* emptying rate */
47 };
48 
49 /*
50  * Battery Information object.  Note that this object is deprecated in
51  * ACPI 4.0
52  */
53 #define ACPI_CMBAT_MAXSTRLEN 32
54 struct acpi_bif {
55     uint32_t units;			/* Power Unit (mW or mA). */
56 #define ACPI_BIF_UNITS_MW	0	/* Capacity in mWh, rate in mW. */
57 #define ACPI_BIF_UNITS_MA	1	/* Capacity in mAh, rate in mA. */
58     uint32_t dcap;			/* Design Capacity */
59     uint32_t lfcap;			/* Last Full capacity */
60     uint32_t btech;			/* Battery Technology */
61     uint32_t dvol;			/* Design voltage (mV) */
62     uint32_t wcap;			/* WARN capacity */
63     uint32_t lcap;			/* Low capacity */
64     uint32_t gra1;			/* Granularity 1 (Warn to Low) */
65     uint32_t gra2;			/* Granularity 2 (Full to Warn) */
66     char model[ACPI_CMBAT_MAXSTRLEN];	/* model identifier */
67     char serial[ACPI_CMBAT_MAXSTRLEN];	/* Serial number */
68     char type[ACPI_CMBAT_MAXSTRLEN];	/* Type */
69     char oeminfo[ACPI_CMBAT_MAXSTRLEN];	/* OEM information */
70 };
71 
72 /*
73  * Members in acpi_bix are reordered so that the first part is compatible
74  * with acpi_bif.
75  */
76 struct acpi_bix {
77 /* _BIF-compatible */
78     uint32_t units;			/* Power Unit (mW or mA). */
79 #define ACPI_BIX_UNITS_MW	0	/* Capacity in mWh, rate in mW. */
80 #define ACPI_BIX_UNITS_MA	1	/* Capacity in mAh, rate in mA. */
81     uint32_t dcap;			/* Design Capacity */
82     uint32_t lfcap;			/* Last Full capacity */
83     uint32_t btech;			/* Battery Technology */
84     uint32_t dvol;			/* Design voltage (mV) */
85     uint32_t wcap;			/* WARN capacity */
86     uint32_t lcap;			/* Low capacity */
87     uint32_t gra1;			/* Granularity 1 (Warn to Low) */
88     uint32_t gra2;			/* Granularity 2 (Full to Warn) */
89     char model[ACPI_CMBAT_MAXSTRLEN];	/* model identifier */
90     char serial[ACPI_CMBAT_MAXSTRLEN];	/* Serial number */
91     char type[ACPI_CMBAT_MAXSTRLEN];	/* Type */
92     char oeminfo[ACPI_CMBAT_MAXSTRLEN];	/* OEM information */
93     /* ACPI 4.0 or later */
94     uint16_t rev;			/* Revision */
95 #define	ACPI_BIX_REV_0		0	/* ACPI 4.0 _BIX */
96 #define	ACPI_BIX_REV_1		1	/* ACPI 6.0 _BIX */
97 #define	ACPI_BIX_REV_BIF	0xffff	/* _BIF */
98 #define	ACPI_BIX_REV_MIN_CHECK(x, min)	\
99 	(((min) == ACPI_BIX_REV_BIF) ? ((x) == ACPI_BIX_REV_BIF) : \
100 	    (((x) == ACPI_BIX_REV_BIF) ? 0 : ((x) >= (min))))
101     uint32_t cycles;			/* Cycle Count */
102     uint32_t accuracy;			/* Measurement Accuracy */
103     uint32_t stmax;			/* Max Sampling Time */
104     uint32_t stmin;			/* Min Sampling Time */
105     uint32_t aimax;			/* Max Average Interval */
106     uint32_t aimin;			/* Min Average Interval */
107     /* ACPI 6.0 or later */
108     uint32_t scap;			/* Battery Swapping Capability */
109 #define	ACPI_BIX_SCAP_NO	0x00000000
110 #define	ACPI_BIX_SCAP_COLD	0x00000001
111 #define	ACPI_BIX_SCAP_HOT	0x00000010
112     uint8_t bix_reserved[58];		/* padding */
113 };
114 
115 #if 0
116 /* acpi_bix in the original order just for reference */
117 struct acpi_bix {
118     uint16_t rev;			/* Revision */
119     uint32_t units;			/* Power Unit (mW or mA). */
120     uint32_t dcap;			/* Design Capacity */
121     uint32_t lfcap;			/* Last Full capacity */
122     uint32_t btech;			/* Battery Technology */
123     uint32_t dvol;			/* Design voltage (mV) */
124     uint32_t wcap;			/* Design Capacity of Warning */
125     uint32_t lcap;			/* Design Capacity of Low */
126     uint32_t cycles;			/* Cycle Count */
127     uint32_t accuracy;			/* Measurement Accuracy */
128     uint32_t stmax;			/* Max Sampling Time */
129     uint32_t stmin;			/* Min Sampling Time */
130     uint32_t aimax;			/* Max Average Interval */
131     uint32_t aimin;			/* Min Average Interval */
132     uint32_t gra1;			/* Granularity 1 (Warn to Low) */
133     uint32_t gra2;			/* Granularity 2 (Full to Warn) */
134     char model[ACPI_CMBAT_MAXSTRLEN];	/* model identifier */
135     char serial[ACPI_CMBAT_MAXSTRLEN];	/* Serial number */
136     char type[ACPI_CMBAT_MAXSTRLEN];	/* Type */
137     char oeminfo[ACPI_CMBAT_MAXSTRLEN];	/* OEM information */
138     uint32_t scap;			/* Battery Swapping Capability */
139 };
140 #endif
141 
142 struct acpi_bst {
143     uint32_t state;			/* Battery State */
144     uint32_t rate;			/* Present Rate */
145     uint32_t cap;			/* Remaining Capacity */
146     uint32_t volt;			/* Present Voltage */
147 };
148 
149 /*
150  * Note that the following definitions represent status bits for internal
151  * driver state.  The first three of them (charging, discharging and critical)
152  * conveninetly conform to ACPI specification of status returned by _BST
153  * method.  Other definitions (not present, etc) are synthetic.
154  * Also note that according to the specification the charging and discharging
155  * status bits must not be set at the same time.
156  */
157 #define ACPI_BATT_STAT_DISCHARG		0x0001
158 #define ACPI_BATT_STAT_CHARGING		0x0002
159 #define ACPI_BATT_STAT_CRITICAL		0x0004
160 #define ACPI_BATT_STAT_INVALID					\
161     (ACPI_BATT_STAT_DISCHARG | ACPI_BATT_STAT_CHARGING)
162 #define ACPI_BATT_STAT_BST_MASK					\
163     (ACPI_BATT_STAT_INVALID | ACPI_BATT_STAT_CRITICAL)
164 #define ACPI_BATT_STAT_NOT_PRESENT	ACPI_BATT_STAT_BST_MASK
165 
166 /* For backward compatibility */
167 union acpi_battery_ioctl_arg_v1 {
168     int			 unit;	/* Device unit or ACPI_BATTERY_ALL_UNITS. */
169 
170     struct acpi_battinfo battinfo;
171 
172     struct acpi_bif	 bif;
173     struct acpi_bst	 bst;
174 };
175 union acpi_battery_ioctl_arg {
176     int			 unit;	/* Device unit or ACPI_BATTERY_ALL_UNITS. */
177 
178     struct acpi_battinfo battinfo;
179 
180     struct acpi_bix	 bix;
181     struct acpi_bif	 bif;
182     struct acpi_bst	 bst;
183 };
184 
185 #define ACPI_BATTERY_ALL_UNITS 	(-1)
186 #define ACPI_BATT_UNKNOWN 	0xffffffff /* _BST or _BI[FX] value unknown. */
187 
188 /* Common battery ioctls */
189 #define ACPIIO_BATT_GET_UNITS	  _IOR('B', 0x01, int)
190 #define ACPIIO_BATT_GET_BATTINFO _IOWR('B', 0x03, union acpi_battery_ioctl_arg)
191 #define ACPIIO_BATT_GET_BATTINFO_V1 _IOWR('B', 0x03, union acpi_battery_ioctl_arg_v1)
192 #define ACPIIO_BATT_GET_BIF	 _IOWR('B', 0x10, union acpi_battery_ioctl_arg_v1)
193 #define ACPIIO_BATT_GET_BIX	 _IOWR('B', 0x10, union acpi_battery_ioctl_arg)
194 #define ACPIIO_BATT_GET_BST	 _IOWR('B', 0x11, union acpi_battery_ioctl_arg)
195 #define ACPIIO_BATT_GET_BST_V1	 _IOWR('B', 0x11, union acpi_battery_ioctl_arg_v1)
196 
197 /* Control Method battery ioctls (deprecated) */
198 #define ACPIIO_CMBAT_GET_BIF	 ACPIIO_BATT_GET_BIF
199 #define ACPIIO_CMBAT_GET_BST	 ACPIIO_BATT_GET_BST
200 
201 /* Get AC adapter status. */
202 #define ACPIIO_ACAD_GET_STATUS	  _IOR('A', 1, int)
203 
204 #ifdef _KERNEL
205 typedef int	(*acpi_ioctl_fn)(u_long cmd, caddr_t addr, void *arg);
206 extern int	acpi_register_ioctl(u_long cmd, acpi_ioctl_fn fn, void *arg);
207 extern void	acpi_deregister_ioctl(u_long cmd, acpi_ioctl_fn fn);
208 #endif
209 
210 #endif /* !_ACPIIO_H_ */
211