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