acpivar.h revision 1.7 1 /* $NetBSD: acpivar.h,v 1.7 2002/12/28 06:14:07 jmcneill 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 /*
51 * acpibus_attach_args:
52 *
53 * This structure is used to attach the ACPI "bus".
54 */
55 struct acpibus_attach_args {
56 const char *aa_busname; /* XXX should be common */
57 bus_space_tag_t aa_iot; /* PCI I/O space tag */
58 bus_space_tag_t aa_memt; /* PCI MEM space tag */
59 pci_chipset_tag_t aa_pc; /* PCI chipset */
60 int aa_pciflags; /* PCI bus flags */
61 isa_chipset_tag_t aa_ic; /* ISA chipset */
62 };
63
64 /*
65 * Types of switches that ACPI understands.
66 */
67 #define ACPI_SWITCH_POWERBUTTON 0
68 #define ACPI_SWITCH_SLEEPBUTTON 1
69 #define ACPI_SWITCH_LID 2
70 #define ACPI_NSWITCHES 3
71
72 /*
73 * acpi_devnode:
74 *
75 * An ACPI device node.
76 */
77 struct acpi_devnode {
78 TAILQ_ENTRY(acpi_devnode) ad_list;
79 ACPI_HANDLE ad_handle; /* our ACPI handle */
80 u_int32_t ad_level; /* ACPI level */
81 u_int32_t ad_type; /* ACPI object type */
82 ACPI_DEVICE_INFO ad_devinfo; /* our ACPI device info */
83 struct acpi_scope *ad_scope; /* backpointer to scope */
84 struct device *ad_device; /* pointer to configured device */
85 };
86
87 /*
88 * acpi_scope:
89 *
90 * Description of an ACPI scope.
91 */
92 struct acpi_scope {
93 TAILQ_ENTRY(acpi_scope) as_list;
94 const char *as_name; /* scope name */
95 /*
96 * Device nodes we manage.
97 */
98 TAILQ_HEAD(, acpi_devnode) as_devnodes;
99 };
100
101 /*
102 * acpi_softc:
103 *
104 * Software state of the ACPI subsystem.
105 */
106 struct acpi_softc {
107 struct device sc_dev; /* base device info */
108 bus_space_tag_t sc_iot; /* PCI I/O space tag */
109 bus_space_tag_t sc_memt; /* PCI MEM space tag */
110 pci_chipset_tag_t sc_pc; /* PCI chipset tag */
111 int sc_pciflags; /* PCI bus flags */
112 int sc_pci_bus; /* internal PCI fixup */
113 isa_chipset_tag_t sc_ic; /* ISA chipset tag */
114
115 void *sc_sdhook; /* shutdown hook */
116
117 /*
118 * Sleep state to transition to when a given
119 * switch is activated.
120 */
121 int sc_switch_sleep[ACPI_NSWITCHES];
122
123 int sc_sleepstate; /* current sleep state */
124
125 /*
126 * Scopes we manage.
127 */
128 TAILQ_HEAD(, acpi_scope) sc_scopes;
129 };
130
131 /*
132 * acpi_attach_args:
133 *
134 * Used to attach a device instance to the acpi "bus".
135 */
136 struct acpi_attach_args {
137 struct acpi_devnode *aa_node; /* ACPI device node */
138 bus_space_tag_t aa_iot; /* PCI I/O space tag */
139 bus_space_tag_t aa_memt; /* PCI MEM space tag */
140 pci_chipset_tag_t aa_pc; /* PCI chipset tag */
141 int aa_pciflags; /* PCI bus flags */
142 isa_chipset_tag_t aa_ic; /* ISA chipset */
143 };
144
145 /*
146 * ACPI resources:
147 *
148 * acpi_io I/O ports
149 * acpi_iorange I/O port range
150 * acpi_mem memory region
151 * acpi_memrange memory range
152 * acpi_irq Interrupt Request
153 * acpi_drq DMA request
154 */
155
156 struct acpi_io {
157 SIMPLEQ_ENTRY(acpi_io) ar_list;
158 int ar_index;
159 uint32_t ar_base;
160 uint32_t ar_length;
161 };
162
163 struct acpi_iorange {
164 SIMPLEQ_ENTRY(acpi_iorange) ar_list;
165 int ar_index;
166 uint32_t ar_low;
167 uint32_t ar_high;
168 uint32_t ar_length;
169 uint32_t ar_align;
170 };
171
172 struct acpi_mem {
173 SIMPLEQ_ENTRY(acpi_mem) ar_list;
174 int ar_index;
175 uint32_t ar_base;
176 uint32_t ar_length;
177 };
178
179 struct acpi_memrange {
180 SIMPLEQ_ENTRY(acpi_memrange) ar_list;
181 int ar_index;
182 uint32_t ar_low;
183 uint32_t ar_high;
184 uint32_t ar_length;
185 uint32_t ar_align;
186 };
187
188 struct acpi_irq {
189 SIMPLEQ_ENTRY(acpi_irq) ar_list;
190 int ar_index;
191 uint32_t ar_irq;
192 };
193
194 struct acpi_drq {
195 SIMPLEQ_ENTRY(acpi_drq) ar_list;
196 int ar_index;
197 uint32_t ar_drq;
198 };
199
200 struct acpi_resources {
201 SIMPLEQ_HEAD(, acpi_io) ar_io;
202 int ar_nio;
203
204 SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
205 int ar_niorange;
206
207 SIMPLEQ_HEAD(, acpi_mem) ar_mem;
208 int ar_nmem;
209
210 SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
211 int ar_nmemrange;
212
213 SIMPLEQ_HEAD(, acpi_irq) ar_irq;
214 int ar_nirq;
215
216 SIMPLEQ_HEAD(, acpi_drq) ar_drq;
217 int ar_ndrq;
218 };
219
220 /*
221 * acpi_resource_parse_ops:
222 *
223 * The client of ACPI resources specifies these operations
224 * when the resources are parsed.
225 */
226 struct acpi_resource_parse_ops {
227 void (*init)(struct device *, void *, void **);
228 void (*fini)(struct device *, void *);
229
230 void (*ioport)(struct device *, void *, uint32_t, uint32_t);
231 void (*iorange)(struct device *, void *, uint32_t, uint32_t,
232 uint32_t, uint32_t);
233
234 void (*memory)(struct device *, void *, uint32_t, uint32_t);
235 void (*memrange)(struct device *, void *, uint32_t, uint32_t,
236 uint32_t, uint32_t);
237
238 void (*irq)(struct device *, void *, uint32_t);
239 void (*drq)(struct device *, void *, uint32_t);
240
241 void (*start_dep)(struct device *, void *, int);
242 void (*end_dep)(struct device *, void *);
243 };
244
245 extern struct acpi_softc *acpi_softc;
246 extern int acpi_active;
247
248 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
249
250 int acpi_probe(void);
251
252 ACPI_STATUS acpi_eval_integer(ACPI_HANDLE, char *, int *);
253 ACPI_STATUS acpi_eval_string(ACPI_HANDLE, char *, char **);
254 ACPI_STATUS acpi_eval_struct(ACPI_HANDLE, char *, ACPI_BUFFER *);
255
256 ACPI_STATUS acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
257 ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
258
259 ACPI_STATUS acpi_resource_parse(struct device *, struct acpi_devnode *,
260 void *, const struct acpi_resource_parse_ops *);
261 void acpi_resource_print(struct device *, struct acpi_resources *);
262
263 struct acpi_io *acpi_res_io(struct acpi_resources *, int);
264 struct acpi_iorange *acpi_res_iorange(struct acpi_resources *, int);
265 struct acpi_mem *acpi_res_mem(struct acpi_resources *, int);
266 struct acpi_memrange *acpi_res_memrange(struct acpi_resources *, int);
267 struct acpi_irq *acpi_res_irq(struct acpi_resources *, int);
268 struct acpi_drq *acpi_res_drq(struct acpi_resources *, int);
269
270 /*
271 * power state transition
272 */
273 extern ACPI_STATUS acpi_enter_sleep_state(struct acpi_softc *, int state);
274