xref: /netbsd-src/sys/dev/acpi/acpivar.h (revision bf1e9b32e27832f0c493206710fb8b58a980838a)
1 /*	$NetBSD: acpivar.h,v 1.23 2005/06/01 16:44:38 drochner Exp $	*/
2 
3 /*
4  * Copyright 2001 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed for the NetBSD Project by
20  *	Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 /*
39  * This file defines the ACPI interface provided to the rest of the
40  * kernel, as well as the autoconfiguration structures for ACPI
41  * support.
42  */
43 
44 #include <machine/bus.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/isa/isavar.h>
47 
48 #include <dev/acpi/acpica.h>
49 
50 #include <dev/sysmon/sysmonvar.h>
51 
52 /*
53  * acpibus_attach_args:
54  *
55  *	This structure is used to attach the ACPI "bus".
56  */
57 struct acpibus_attach_args {
58 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
59 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
60 	pci_chipset_tag_t aa_pc;	/* PCI chipset */
61 	int aa_pciflags;		/* PCI bus flags */
62 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
63 };
64 
65 /*
66  * Types of switches that ACPI understands.
67  */
68 #define	ACPI_SWITCH_POWERBUTTON		0
69 #define	ACPI_SWITCH_SLEEPBUTTON		1
70 #define	ACPI_SWITCH_LID			2
71 #define	ACPI_NSWITCHES			3
72 
73 /*
74  * acpi_devnode:
75  *
76  *	An ACPI device node.
77  */
78 struct acpi_devnode {
79 	TAILQ_ENTRY(acpi_devnode) ad_list;
80 	ACPI_HANDLE	ad_handle;	/* our ACPI handle */
81 	u_int32_t	ad_level;	/* ACPI level */
82 	u_int32_t	ad_type;	/* ACPI object type */
83 	ACPI_DEVICE_INFO *ad_devinfo;	/* our ACPI device info */
84 	struct acpi_scope *ad_scope;	/* backpointer to scope */
85 	struct device	*ad_device;	/* pointer to configured device */
86 };
87 
88 /*
89  * acpi_scope:
90  *
91  *	Description of an ACPI scope.
92  */
93 struct acpi_scope {
94 	TAILQ_ENTRY(acpi_scope) as_list;
95 	const char *as_name;		/* scope name */
96 	/*
97 	 * Device nodes we manage.
98 	 */
99 	TAILQ_HEAD(, acpi_devnode) as_devnodes;
100 };
101 
102 /*
103  * acpi_softc:
104  *
105  *	Software state of the ACPI subsystem.
106  */
107 struct acpi_softc {
108 	struct device sc_dev;		/* base device info */
109 	bus_space_tag_t sc_iot;		/* PCI I/O space tag */
110 	bus_space_tag_t sc_memt;	/* PCI MEM space tag */
111 	pci_chipset_tag_t sc_pc;	/* PCI chipset tag */
112 	int sc_pciflags;		/* PCI bus flags */
113 	int sc_pci_bus;			/* internal PCI fixup */
114 	isa_chipset_tag_t sc_ic;	/* ISA chipset tag */
115 
116 	void *sc_sdhook;		/* shutdown hook */
117 
118 	/*
119 	 * Power switch handlers for fixed-feature buttons.
120 	 */
121 	struct sysmon_pswitch sc_smpsw_power;
122 	struct sysmon_pswitch sc_smpsw_sleep;
123 
124 	/*
125 	 * Sleep state to transition to when a given
126 	 * switch is activated.
127 	 */
128 	int sc_switch_sleep[ACPI_NSWITCHES];
129 
130 	int sc_sleepstate;		/* current sleep state */
131 
132 	int sc_quirks;
133 
134 	/*
135 	 * Scopes we manage.
136 	 */
137 	TAILQ_HEAD(, acpi_scope) sc_scopes;
138 };
139 
140 /*
141  * acpi_attach_args:
142  *
143  *	Used to attach a device instance to the acpi "bus".
144  */
145 struct acpi_attach_args {
146 	struct acpi_devnode *aa_node;	/* ACPI device node */
147 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
148 	bus_space_tag_t aa_memt;	/* PCI MEM space tag */
149 	pci_chipset_tag_t aa_pc;	/* PCI chipset tag */
150 	int aa_pciflags;		/* PCI bus flags */
151 	isa_chipset_tag_t aa_ic;	/* ISA chipset */
152 };
153 
154 /*
155  * ACPI resources:
156  *
157  *	acpi_io		I/O ports
158  *	acpi_iorange	I/O port range
159  *	acpi_mem	memory region
160  *	acpi_memrange	memory range
161  *	acpi_irq	Interrupt Request
162  *	acpi_drq	DMA request
163  */
164 
165 struct acpi_io {
166 	SIMPLEQ_ENTRY(acpi_io) ar_list;
167 	int		ar_index;
168 	uint32_t	ar_base;
169 	uint32_t	ar_length;
170 };
171 
172 struct acpi_iorange {
173 	SIMPLEQ_ENTRY(acpi_iorange) ar_list;
174 	int		ar_index;
175 	uint32_t	ar_low;
176 	uint32_t	ar_high;
177 	uint32_t	ar_length;
178 	uint32_t	ar_align;
179 };
180 
181 struct acpi_mem {
182 	SIMPLEQ_ENTRY(acpi_mem) ar_list;
183 	int		ar_index;
184 	uint32_t	ar_base;
185 	uint32_t	ar_length;
186 };
187 
188 struct acpi_memrange {
189 	SIMPLEQ_ENTRY(acpi_memrange) ar_list;
190 	int		ar_index;
191 	uint32_t	ar_low;
192 	uint32_t	ar_high;
193 	uint32_t	ar_length;
194 	uint32_t	ar_align;
195 };
196 
197 struct acpi_irq {
198 	SIMPLEQ_ENTRY(acpi_irq) ar_list;
199 	int		ar_index;
200 	uint32_t	ar_irq;
201 	uint32_t	ar_type;
202 };
203 
204 struct acpi_drq {
205 	SIMPLEQ_ENTRY(acpi_drq) ar_list;
206 	int		ar_index;
207 	uint32_t	ar_drq;
208 };
209 
210 struct acpi_resources {
211 	SIMPLEQ_HEAD(, acpi_io) ar_io;
212 	int ar_nio;
213 
214 	SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
215 	int ar_niorange;
216 
217 	SIMPLEQ_HEAD(, acpi_mem) ar_mem;
218 	int ar_nmem;
219 
220 	SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
221 	int ar_nmemrange;
222 
223 	SIMPLEQ_HEAD(, acpi_irq) ar_irq;
224 	int ar_nirq;
225 
226 	SIMPLEQ_HEAD(, acpi_drq) ar_drq;
227 	int ar_ndrq;
228 };
229 
230 /*
231  * acpi_resource_parse_ops:
232  *
233  *	The client of ACPI resources specifies these operations
234  *	when the resources are parsed.
235  */
236 struct acpi_resource_parse_ops {
237 	void	(*init)(struct device *, void *, void **);
238 	void	(*fini)(struct device *, void *);
239 
240 	void	(*ioport)(struct device *, void *, uint32_t, uint32_t);
241 	void	(*iorange)(struct device *, void *, uint32_t, uint32_t,
242 		    uint32_t, uint32_t);
243 
244 	void	(*memory)(struct device *, void *, uint32_t, uint32_t);
245 	void	(*memrange)(struct device *, void *, uint32_t, uint32_t,
246 		    uint32_t, uint32_t);
247 
248 	void	(*irq)(struct device *, void *, uint32_t, uint32_t);
249 	void	(*drq)(struct device *, void *, uint32_t);
250 
251 	void	(*start_dep)(struct device *, void *, int);
252 	void	(*end_dep)(struct device *, void *);
253 };
254 
255 extern struct acpi_softc *acpi_softc;
256 extern int acpi_active;
257 
258 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
259 
260 int		acpi_probe(void);
261 int		acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *);
262 void		acpi_set_wake_gpe(ACPI_HANDLE);
263 
264 ACPI_STATUS	acpi_eval_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
265 ACPI_STATUS	acpi_eval_string(ACPI_HANDLE, const char *, char **);
266 ACPI_STATUS	acpi_eval_struct(ACPI_HANDLE, const char *, ACPI_BUFFER *);
267 
268 ACPI_STATUS	acpi_foreach_package_object(ACPI_OBJECT *,
269 		    ACPI_STATUS (*)(ACPI_OBJECT *, void *), void *);
270 ACPI_STATUS	acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
271 		    ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
272 const char*	acpi_name(ACPI_HANDLE);
273 
274 ACPI_STATUS	acpi_resource_parse(struct device *, ACPI_HANDLE, const char *,
275 		    void *, const struct acpi_resource_parse_ops *);
276 void		acpi_resource_print(struct device *, struct acpi_resources *);
277 void		acpi_resource_cleanup(struct acpi_resources *);
278 
279 ACPI_STATUS	acpi_pwr_switch_consumer(ACPI_HANDLE, int);
280 
281 #if defined(_KERNEL_OPT)
282 #include "acpiec.h"
283 
284 #if NACPIEC > 0
285 void		acpiec_early_attach(struct device *);
286 #endif
287 #else
288 #define	NACPIEC	0
289 #endif
290 
291 struct acpi_io		*acpi_res_io(struct acpi_resources *, int);
292 struct acpi_iorange	*acpi_res_iorange(struct acpi_resources *, int);
293 struct acpi_mem		*acpi_res_mem(struct acpi_resources *, int);
294 struct acpi_memrange	*acpi_res_memrange(struct acpi_resources *, int);
295 struct acpi_irq		*acpi_res_irq(struct acpi_resources *, int);
296 struct acpi_drq		*acpi_res_drq(struct acpi_resources *, int);
297 
298 /*
299  * power state transition
300  */
301 ACPI_STATUS	acpi_enter_sleep_state(struct acpi_softc *, int);
302 
303 /*
304  * quirk handling
305  */
306 struct acpi_quirk {
307 	const char *aq_oemid;	/* compared against the X/RSDT OemId */
308 	int aq_oemrev;		/* compared against the X/RSDT OemRev */
309 	int aq_quirks;		/* the actual quirks */
310 };
311 
312 #define ACPI_QUIRK_BADPCI	0x00000001	/* bad PCI hierarchy */
313 #define ACPI_QUIRK_BADIRQ	0x00000002	/* bad IRQ information */
314 
315 int acpi_find_quirks(void);
316