acpivar.h revision 1.4 1 /* $NetBSD: acpivar.h,v 1.4 2002/03/24 03:32:14 sommerfeld 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
111 void *sc_sdhook; /* shutdown hook */
112
113 /*
114 * Sleep state to transition to when a given
115 * switch is activated.
116 */
117 int sc_switch_sleep[ACPI_NSWITCHES];
118
119 int sc_sleepstate; /* current sleep state */
120
121 /*
122 * Scopes we manage.
123 */
124 TAILQ_HEAD(, acpi_scope) sc_scopes;
125 };
126
127 /*
128 * acpi_attach_args:
129 *
130 * Used to attach a device instance to the acpi "bus".
131 */
132 struct acpi_attach_args {
133 struct acpi_devnode *aa_node; /* ACPI device node */
134 bus_space_tag_t aa_iot; /* PCI I/O space tag */
135 bus_space_tag_t aa_memt; /* PCI MEM space tag */
136 pci_chipset_tag_t aa_pc; /* PCI chipset tag */
137 int aa_pciflags; /* PCI bus flags */
138 };
139
140 /*
141 * ACPI resources:
142 *
143 * acpi_io I/O ports
144 * acpi_iorange I/O port range
145 * acpi_mem memory region
146 * acpi_memrange memory range
147 * acpi_irq Interrupt Request
148 * acpi_drq DMA request
149 */
150
151 struct acpi_io {
152 SIMPLEQ_ENTRY(acpi_io) ar_list;
153 int ar_index;
154 uint32_t ar_base;
155 uint32_t ar_length;
156 };
157
158 struct acpi_iorange {
159 SIMPLEQ_ENTRY(acpi_iorange) ar_list;
160 int ar_index;
161 uint32_t ar_low;
162 uint32_t ar_high;
163 uint32_t ar_length;
164 uint32_t ar_align;
165 };
166
167 struct acpi_mem {
168 SIMPLEQ_ENTRY(acpi_mem) ar_list;
169 int ar_index;
170 uint32_t ar_base;
171 uint32_t ar_length;
172 };
173
174 struct acpi_memrange {
175 SIMPLEQ_ENTRY(acpi_memrange) ar_list;
176 int ar_index;
177 uint32_t ar_low;
178 uint32_t ar_high;
179 uint32_t ar_length;
180 uint32_t ar_align;
181 };
182
183 struct acpi_irq {
184 SIMPLEQ_ENTRY(acpi_irq) ar_list;
185 int ar_index;
186 uint32_t ar_irq;
187 };
188
189 struct acpi_drq {
190 SIMPLEQ_ENTRY(acpi_drq) ar_list;
191 int ar_index;
192 uint32_t ar_drq;
193 };
194
195 struct acpi_resources {
196 SIMPLEQ_HEAD(, acpi_io) ar_io;
197 int ar_nio;
198
199 SIMPLEQ_HEAD(, acpi_iorange) ar_iorange;
200 int ar_niorange;
201
202 SIMPLEQ_HEAD(, acpi_mem) ar_mem;
203 int ar_nmem;
204
205 SIMPLEQ_HEAD(, acpi_memrange) ar_memrange;
206 int ar_nmemrange;
207
208 SIMPLEQ_HEAD(, acpi_irq) ar_irq;
209 int ar_nirq;
210
211 SIMPLEQ_HEAD(, acpi_drq) ar_drq;
212 int ar_ndrq;
213 };
214
215 /*
216 * acpi_resource_parse_ops:
217 *
218 * The client of ACPI resources specifies these operations
219 * when the resources are parsed.
220 */
221 struct acpi_resource_parse_ops {
222 void (*init)(struct device *, void *, void **);
223 void (*fini)(struct device *, void *);
224
225 void (*ioport)(struct device *, void *, uint32_t, uint32_t);
226 void (*iorange)(struct device *, void *, uint32_t, uint32_t,
227 uint32_t, uint32_t);
228
229 void (*memory)(struct device *, void *, uint32_t, uint32_t);
230 void (*memrange)(struct device *, void *, uint32_t, uint32_t,
231 uint32_t, uint32_t);
232
233 void (*irq)(struct device *, void *, uint32_t);
234 void (*drq)(struct device *, void *, uint32_t);
235
236 void (*start_dep)(struct device *, void *, int);
237 void (*end_dep)(struct device *, void *);
238 };
239
240 extern struct acpi_softc *acpi_softc;
241 extern int acpi_active;
242
243 extern const struct acpi_resource_parse_ops acpi_resource_parse_ops_default;
244
245 int acpi_probe(void);
246
247 ACPI_STATUS acpi_eval_integer(ACPI_HANDLE, char *, int *);
248 ACPI_STATUS acpi_eval_string(ACPI_HANDLE, char *, char **);
249 ACPI_STATUS acpi_eval_struct(ACPI_HANDLE, char *, ACPI_BUFFER *);
250
251 ACPI_STATUS acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
252 ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
253
254 ACPI_STATUS acpi_resource_parse(struct device *, struct acpi_devnode *,
255 void *, const struct acpi_resource_parse_ops *);
256 void acpi_resource_print(struct device *, struct acpi_resources *);
257
258 struct acpi_io *acpi_res_io(struct acpi_resources *, int);
259 struct acpi_iorange *acpi_res_iorange(struct acpi_resources *, int);
260 struct acpi_mem *acpi_res_mem(struct acpi_resources *, int);
261 struct acpi_memrange *acpi_res_memrange(struct acpi_resources *, int);
262 struct acpi_irq *acpi_res_irq(struct acpi_resources *, int);
263 struct acpi_drq *acpi_res_drq(struct acpi_resources *, int);
264