xref: /openbsd-src/sys/dev/acpi/acpivar.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: acpivar.h,v 1.83 2016/07/28 21:57:56 kettenis Exp $	*/
2 /*
3  * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef _DEV_ACPI_ACPIVAR_H_
19 #define _DEV_ACPI_ACPIVAR_H_
20 
21 #define ACPI_TRAMPOLINE		(19 * NBPG)
22 #define ACPI_TRAMP_DATA		(20 * NBPG)
23 
24 #ifndef _ACPI_WAKECODE
25 
26 #include <sys/timeout.h>
27 #include <sys/rwlock.h>
28 #include <machine/biosvar.h>
29 
30 #include "acpipwrres.h"
31 
32 /* #define ACPI_DEBUG */
33 #ifdef ACPI_DEBUG
34 extern int acpi_debug;
35 #define dprintf(x...)	  do { if (acpi_debug) printf(x); } while (0)
36 #define dnprintf(n,x...)  do { if (acpi_debug > (n)) printf(x); } while (0)
37 #else
38 #define dprintf(x...)
39 #define dnprintf(n,x...)
40 #endif
41 
42 extern int acpi_hasprocfvs;
43 
44 struct klist;
45 struct acpiec_softc;
46 struct acpipwrres_softc;
47 
48 struct acpivideo_softc {
49 	struct device sc_dev;
50 
51 	struct acpi_softc *sc_acpi;
52 	struct aml_node	*sc_devnode;
53 };
54 
55 struct acpi_attach_args {
56 	char		*aaa_name;
57 	bus_space_tag_t	 aaa_iot;
58 	bus_space_tag_t	 aaa_memt;
59 	void		*aaa_table;
60 	struct aml_node *aaa_node;
61 	const char	*aaa_dev;
62 };
63 
64 struct acpi_mem_map {
65 	vaddr_t		 baseva;
66 	u_int8_t	*va;
67 	size_t		 vsize;
68 	paddr_t		 pa;
69 };
70 
71 struct acpi_q {
72 	SIMPLEQ_ENTRY(acpi_q)	 q_next;
73 	int			 q_id;
74 	void			*q_table;
75 	u_int8_t		 q_data[0];
76 };
77 
78 struct acpi_taskq {
79 	SIMPLEQ_ENTRY(acpi_taskq)	next;
80 	void 				(*handler)(void *, int);
81 	void				*arg0;
82 	int				arg1;
83 };
84 
85 struct acpi_wakeq {
86 	SIMPLEQ_ENTRY(acpi_wakeq)	 q_next;
87 	struct aml_node			*q_node;
88 	struct aml_value		*q_wakepkg;
89 	int				 q_gpe;
90 	int				 q_state;
91 };
92 
93 #if NACPIPWRRES > 0
94 struct acpi_pwrres {
95 	SIMPLEQ_ENTRY(acpi_pwrres)	 p_next;
96 	struct aml_node			*p_node;	/* device's node */
97 	int				 p_state;	/* current state */
98 
99 	int				 p_res_state;
100 	struct acpipwrres_softc		*p_res_sc;
101 };
102 
103 typedef SIMPLEQ_HEAD(, acpi_pwrres) acpi_pwrreshead_t;
104 #endif /* NACPIPWRRES > 0 */
105 
106 typedef SIMPLEQ_HEAD(, acpi_q) acpi_qhead_t;
107 typedef SIMPLEQ_HEAD(, acpi_wakeq) acpi_wakeqhead_t;
108 
109 #define ACPIREG_PM1A_STS	0x00
110 #define ACPIREG_PM1A_EN		0x01
111 #define ACPIREG_PM1A_CNT	0x02
112 #define ACPIREG_PM1B_STS	0x03
113 #define ACPIREG_PM1B_EN		0x04
114 #define ACPIREG_PM1B_CNT	0x05
115 #define ACPIREG_PM2_CNT		0x06
116 #define ACPIREG_PM_TMR		0x07
117 #define ACPIREG_GPE0_STS	0x08
118 #define ACPIREG_GPE0_EN		0x09
119 #define ACPIREG_GPE1_STS	0x0A
120 #define ACPIREG_GPE1_EN		0x0B
121 #define ACPIREG_SMICMD		0x0C
122 #define ACPIREG_MAXREG		0x0D
123 
124 /* Special registers */
125 #define ACPIREG_PM1_STS		0x0E
126 #define ACPIREG_PM1_EN		0x0F
127 #define ACPIREG_PM1_CNT		0x10
128 #define ACPIREG_GPE_STS		0x11
129 #define ACPIREG_GPE_EN		0x12
130 
131 /* System status (_SST) codes */
132 #define ACPI_SST_INDICATOR_OFF	0
133 #define ACPI_SST_WORKING	1
134 #define ACPI_SST_WAKING		2
135 #define ACPI_SST_SLEEPING	3
136 #define ACPI_SST_SLEEP_CONTEXT	4
137 
138 struct acpi_parsestate {
139 	u_int8_t		*start;
140 	u_int8_t		*end;
141 	u_int8_t		*pos;
142 };
143 
144 struct acpi_reg_map {
145 	bus_space_handle_t	ioh;
146 	int			addr;
147 	int			size;
148 	int			access;
149 	const char		*name;
150 };
151 
152 struct acpi_thread {
153 	struct acpi_softc   *sc;
154 	volatile int	    running;
155 };
156 
157 struct acpi_mutex {
158 	struct rwlock		amt_lock;
159 #define ACPI_MTX_MAXNAME	5
160 	char			amt_name[ACPI_MTX_MAXNAME + 3]; /* only 4 used */
161 	int			amt_ref_count;
162 	int			amt_timeout;
163 	int			amt_synclevel;
164 };
165 
166 struct gpe_block {
167 	int  (*handler)(struct acpi_softc *, int, void *);
168 	void *arg;
169 	int   active;
170 	int   edge;
171 };
172 
173 struct acpi_devlist {
174 	struct aml_node			*dev_node;
175 	TAILQ_ENTRY(acpi_devlist)	dev_link;
176 };
177 
178 TAILQ_HEAD(acpi_devlist_head, acpi_devlist);
179 
180 struct acpi_ac {
181 	struct acpiac_softc	*aac_softc;
182 	SLIST_ENTRY(acpi_ac)	aac_link;
183 };
184 
185 SLIST_HEAD(acpi_ac_head, acpi_ac);
186 
187 struct acpi_bat {
188 	struct acpibat_softc	*aba_softc;
189 	SLIST_ENTRY(acpi_bat)	aba_link;
190 };
191 
192 SLIST_HEAD(acpi_bat_head, acpi_bat);
193 
194 struct acpi_softc {
195 	struct device		sc_dev;
196 
197 	bus_space_tag_t		sc_iot;
198 	bus_space_tag_t		sc_memt;
199 #if 0
200 	bus_space_tag_t		sc_pcit;
201 	bus_space_tag_t		sc_smbust;
202 #endif
203 
204 	/*
205 	 * First-level ACPI tables
206 	 */
207 	struct acpi_fadt	*sc_fadt;
208 	acpi_qhead_t		 sc_tables;
209 	acpi_wakeqhead_t	 sc_wakedevs;
210 #if NACPIPWRRES > 0
211 	acpi_pwrreshead_t	 sc_pwrresdevs;
212 #endif /* NACPIPWRRES > 0 */
213 	int			 sc_hw_reduced;
214 
215 	/*
216 	 * Second-level information from FADT
217 	 */
218 	struct acpi_facs	*sc_facs;	/* Shared with firmware! */
219 
220 	struct klist		*sc_note;
221 	struct acpi_reg_map	sc_pmregs[ACPIREG_MAXREG];
222 	bus_space_handle_t	sc_ioh_pm1a_evt;
223 
224 	void			*sc_interrupt;
225 
226 	struct rwlock		sc_lck;
227 
228 	struct {
229 		int slp_typa;
230 		int slp_typb;
231 	}			sc_sleeptype[6];
232 	int			sc_maxgpe;
233 	int			sc_lastgpe;
234 
235 	struct gpe_block	*gpe_table;
236 
237 	int			sc_threadwaiting;
238 	u_int32_t		sc_gpe_sts;
239 	u_int32_t		sc_gpe_en;
240 	struct acpi_thread	*sc_thread;
241 
242 	struct aml_node		*sc_tts;
243 	struct aml_node		*sc_pts;
244 	struct aml_node		*sc_bfs;
245 	struct aml_node		*sc_gts;
246 	struct aml_node		*sc_sst;
247 	struct aml_node		*sc_wak;
248 	int			sc_state;
249 	struct acpiec_softc	*sc_ec;		/* XXX assume single EC */
250 
251 	struct acpi_ac_head	sc_ac;
252 	struct acpi_bat_head	sc_bat;
253 
254 	struct timeout		sc_dev_timeout;
255 
256 	int			sc_revision;
257 
258 	int			sc_pse;		/* passive cooling enabled */
259 
260 	int			sc_flags;
261 };
262 
263 extern struct acpi_softc *acpi_softc;
264 
265 #define	SCFLAG_OREAD	0x0000001
266 #define	SCFLAG_OWRITE	0x0000002
267 #define	SCFLAG_OPEN	(SCFLAG_OREAD|SCFLAG_OWRITE)
268 
269 #define GPE_NONE  0x00
270 #define GPE_LEVEL 0x01
271 #define GPE_EDGE  0x02
272 
273 struct acpi_table {
274 	int	offset;
275 	size_t	size;
276 	void	*table;
277 };
278 
279 struct acpi_dev_rank {
280 	struct device	*dev;
281 	int		rank;
282 	TAILQ_ENTRY(acpi_dev_rank) link;
283 };
284 
285 #define	ACPI_IOC_GETFACS	_IOR('A', 0, struct acpi_facs)
286 #define	ACPI_IOC_GETTABLE	_IOWR('A', 1, struct acpi_table)
287 #define ACPI_IOC_SETSLEEPSTATE	_IOW('A', 2, int)
288 
289 #if defined(_KERNEL)
290 struct   acpi_gas;
291 int	 acpi_map_address(struct acpi_softc *, struct acpi_gas *, bus_addr_t, bus_size_t,
292 			  bus_space_handle_t *, bus_space_tag_t *);
293 
294 int	 acpi_map(paddr_t, size_t, struct acpi_mem_map *);
295 void	 acpi_unmap(struct acpi_mem_map *);
296 int	 acpi_probe(struct device *, struct cfdata *, struct bios_attach_args *);
297 u_int	 acpi_checksum(const void *, size_t);
298 void	 acpi_attach_machdep(struct acpi_softc *);
299 int	 acpi_interrupt(void *);
300 void	 acpi_powerdown(void);
301 void	 acpi_reset(void);
302 int	 acpi_sleep_state(struct acpi_softc *, int);
303 void	 acpi_sleep_clocks(struct acpi_softc *, int);
304 int	 acpi_sleep_cpu(struct acpi_softc *, int);
305 void	 acpi_sleep_mp(void);
306 void	 acpi_sleep_pm(struct acpi_softc *, int);
307 void	 acpi_resume_pm(struct acpi_softc *, int);
308 void	 acpi_resume_clocks(struct acpi_softc *);
309 void	 acpi_resume_cpu(struct acpi_softc *);
310 void	 acpi_resume_mp(void);
311 void	 acpi_sleep_walk(struct acpi_softc *, int);
312 
313 
314 #define ACPI_IOREAD 0
315 #define ACPI_IOWRITE 1
316 
317 void acpi_wakeup(void *);
318 
319 int acpi_gasio(struct acpi_softc *, int, int, uint64_t, int, int, void *);
320 
321 int	acpi_set_gpehandler(struct acpi_softc *, int,
322 	    int (*)(struct acpi_softc *, int, void *), void *, int);
323 void	acpi_enable_gpe(struct acpi_softc *, u_int32_t);
324 
325 int	acpiec_intr(struct acpiec_softc *);
326 void	acpiec_read(struct acpiec_softc *, u_int8_t, int, u_int8_t *);
327 void	acpiec_write(struct acpiec_softc *, u_int8_t, int, u_int8_t *);
328 void	acpiec_handle_events(struct acpiec_softc *);
329 
330 #if NACPIPWRRES > 0
331 int	acpipwrres_ref_incr(struct acpipwrres_softc *, struct aml_node *);
332 int	acpipwrres_ref_decr(struct acpipwrres_softc *, struct aml_node *);
333 #endif /* NACPIPWRRES > 0 */
334 
335 int	acpi_read_pmreg(struct acpi_softc *, int, int);
336 void	acpi_write_pmreg(struct acpi_softc *, int, int, int);
337 
338 void	acpi_poll(void *);
339 void	acpi_sleep(int, char *);
340 
341 int	acpi_matchhids(struct acpi_attach_args *, const char *[], const char *);
342 int	acpi_parsehid(struct aml_node *, void *, char *, char *, size_t);
343 
344 int	acpi_record_event(struct acpi_softc *, u_int);
345 
346 void	acpi_addtask(struct acpi_softc *, void (*)(void *, int), void *, int);
347 int	acpi_dotask(struct acpi_softc *);
348 
349 void	acpi_powerdown_task(void *, int);
350 void	acpi_sleep_task(void *, int);
351 
352 /* Section 5.2.10.1: global lock acquire/release functions */
353 #define	GL_BIT_PENDING	0x01
354 #define	GL_BIT_OWNED	0x02
355 int	acpi_acquire_glk(uint32_t *);
356 int	acpi_release_glk(uint32_t *);
357 
358 void	acpi_pciroots_attach(struct device *, void *, cfprint_t);
359 
360 void	*acpi_intr_establish(int, int, int, int (*)(void *), void *,
361 	    const char *);
362 
363 #endif
364 
365 #endif /* !_ACPI_WAKECODE */
366 #endif	/* !_DEV_ACPI_ACPIVAR_H_ */
367