acpi_resource.c revision 1.2.2.3 1 1.2.2.3 jdolecek /* $NetBSD: acpi_resource.c,v 1.2.2.3 2002/06/23 17:45:02 jdolecek Exp $ */
2 1.2.2.2 thorpej
3 1.2.2.2 thorpej /*
4 1.2.2.2 thorpej * Copyright 2001 Wasabi Systems, Inc.
5 1.2.2.2 thorpej * All rights reserved.
6 1.2.2.2 thorpej *
7 1.2.2.2 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.2.2.2 thorpej *
9 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
10 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
11 1.2.2.2 thorpej * are met:
12 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
14 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
17 1.2.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.2.2.2 thorpej * must display the following acknowledgement:
19 1.2.2.2 thorpej * This product includes software developed for the NetBSD Project by
20 1.2.2.2 thorpej * Wasabi Systems, Inc.
21 1.2.2.2 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.2.2.2 thorpej * or promote products derived from this software without specific prior
23 1.2.2.2 thorpej * written permission.
24 1.2.2.2 thorpej *
25 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.2.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.2.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.2.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.2.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.2.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.2.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.2.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.2.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.2.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.2.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.2.2.2 thorpej */
37 1.2.2.2 thorpej
38 1.2.2.2 thorpej /*-
39 1.2.2.2 thorpej * Copyright (c) 2000 Michael Smith
40 1.2.2.2 thorpej * Copyright (c) 2000 BSDi
41 1.2.2.2 thorpej * All rights reserved.
42 1.2.2.2 thorpej *
43 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
44 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
45 1.2.2.2 thorpej * are met:
46 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
47 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
48 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
49 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
50 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
51 1.2.2.2 thorpej *
52 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53 1.2.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.2.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.2.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56 1.2.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.2.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.2.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.2.2.2 thorpej * SUCH DAMAGE.
63 1.2.2.2 thorpej */
64 1.2.2.2 thorpej
65 1.2.2.2 thorpej /*
66 1.2.2.2 thorpej * ACPI resource parsing.
67 1.2.2.2 thorpej */
68 1.2.2.2 thorpej
69 1.2.2.2 thorpej #include <sys/cdefs.h>
70 1.2.2.3 jdolecek __KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.2.2.3 2002/06/23 17:45:02 jdolecek Exp $");
71 1.2.2.2 thorpej
72 1.2.2.2 thorpej #include <sys/param.h>
73 1.2.2.2 thorpej #include <sys/systm.h>
74 1.2.2.2 thorpej #include <sys/device.h>
75 1.2.2.2 thorpej #include <sys/malloc.h>
76 1.2.2.2 thorpej
77 1.2.2.2 thorpej #include <dev/acpi/acpica.h>
78 1.2.2.2 thorpej #include <dev/acpi/acpireg.h>
79 1.2.2.2 thorpej #include <dev/acpi/acpivar.h>
80 1.2.2.2 thorpej
81 1.2.2.3 jdolecek #define _COMPONENT ACPI_RESOURCE_COMPONENT
82 1.2.2.3 jdolecek ACPI_MODULE_NAME("RESOURCE")
83 1.2.2.2 thorpej
84 1.2.2.2 thorpej /*
85 1.2.2.2 thorpej * acpi_resource_parse:
86 1.2.2.2 thorpej *
87 1.2.2.2 thorpej * Parse a device node's resources and fill them in for the
88 1.2.2.2 thorpej * client.
89 1.2.2.2 thorpej *
90 1.2.2.2 thorpej * Note that it might be nice to also locate ACPI-specific resource
91 1.2.2.2 thorpej * items, such as GPE bits.
92 1.2.2.2 thorpej */
93 1.2.2.2 thorpej ACPI_STATUS
94 1.2.2.2 thorpej acpi_resource_parse(struct device *dev, struct acpi_devnode *ad,
95 1.2.2.2 thorpej void *arg, const struct acpi_resource_parse_ops *ops)
96 1.2.2.2 thorpej {
97 1.2.2.2 thorpej ACPI_BUFFER buf;
98 1.2.2.2 thorpej ACPI_RESOURCE *res;
99 1.2.2.2 thorpej char *cur, *last;
100 1.2.2.2 thorpej ACPI_STATUS status;
101 1.2.2.2 thorpej void *context;
102 1.2.2.2 thorpej int i;
103 1.2.2.2 thorpej
104 1.2.2.3 jdolecek ACPI_FUNCTION_TRACE(__FUNCTION__);
105 1.2.2.2 thorpej
106 1.2.2.2 thorpej /*
107 1.2.2.2 thorpej * XXX Note, this means we only get devices that are currently
108 1.2.2.2 thorpej * decoding their address space. This might not be what we
109 1.2.2.2 thorpej * want, in the long term.
110 1.2.2.2 thorpej */
111 1.2.2.2 thorpej
112 1.2.2.2 thorpej status = acpi_get(ad->ad_handle, &buf, AcpiGetCurrentResources);
113 1.2.2.2 thorpej if (status != AE_OK) {
114 1.2.2.2 thorpej printf("%s: ACPI: unable to get Current Resources: %d\n",
115 1.2.2.2 thorpej dev->dv_xname, status);
116 1.2.2.2 thorpej return_ACPI_STATUS(status);
117 1.2.2.2 thorpej }
118 1.2.2.2 thorpej
119 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "got %d bytes of _CRS\n",
120 1.2.2.2 thorpej buf.Length));
121 1.2.2.2 thorpej
122 1.2.2.2 thorpej (*ops->init)(dev, arg, &context);
123 1.2.2.2 thorpej
124 1.2.2.2 thorpej cur = buf.Pointer;
125 1.2.2.2 thorpej last = cur + buf.Length;
126 1.2.2.2 thorpej while (cur < last) {
127 1.2.2.2 thorpej res = (ACPI_RESOURCE *) cur;
128 1.2.2.2 thorpej cur += res->Length;
129 1.2.2.2 thorpej
130 1.2.2.2 thorpej switch (res->Id) {
131 1.2.2.2 thorpej case ACPI_RSTYPE_END_TAG:
132 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
133 1.2.2.2 thorpej cur = last;
134 1.2.2.2 thorpej break;
135 1.2.2.2 thorpej
136 1.2.2.2 thorpej case ACPI_RSTYPE_FIXED_IO:
137 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
138 1.2.2.2 thorpej "FixedIo 0x%x/%d\n",
139 1.2.2.2 thorpej res->Data.FixedIo.BaseAddress,
140 1.2.2.2 thorpej res->Data.FixedIo.RangeLength));
141 1.2.2.2 thorpej (*ops->ioport)(dev, context,
142 1.2.2.2 thorpej res->Data.FixedIo.BaseAddress,
143 1.2.2.2 thorpej res->Data.FixedIo.RangeLength);
144 1.2.2.2 thorpej break;
145 1.2.2.2 thorpej
146 1.2.2.2 thorpej case ACPI_RSTYPE_IO:
147 1.2.2.2 thorpej if (res->Data.Io.MinBaseAddress ==
148 1.2.2.2 thorpej res->Data.Io.MaxBaseAddress) {
149 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
150 1.2.2.2 thorpej "Io 0x%x/%d\n",
151 1.2.2.2 thorpej res->Data.Io.MinBaseAddress,
152 1.2.2.2 thorpej res->Data.Io.RangeLength));
153 1.2.2.2 thorpej (*ops->ioport)(dev, context,
154 1.2.2.2 thorpej res->Data.Io.MinBaseAddress,
155 1.2.2.2 thorpej res->Data.Io.RangeLength);
156 1.2.2.2 thorpej } else {
157 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
158 1.2.2.2 thorpej "Io 0x%x-0x%x/%d\n",
159 1.2.2.2 thorpej res->Data.Io.MinBaseAddress,
160 1.2.2.2 thorpej res->Data.Io.MaxBaseAddress,
161 1.2.2.2 thorpej res->Data.Io.RangeLength));
162 1.2.2.2 thorpej (*ops->iorange)(dev, context,
163 1.2.2.2 thorpej res->Data.Io.MinBaseAddress,
164 1.2.2.2 thorpej res->Data.Io.MaxBaseAddress,
165 1.2.2.2 thorpej res->Data.Io.RangeLength,
166 1.2.2.2 thorpej res->Data.Io.Alignment);
167 1.2.2.2 thorpej }
168 1.2.2.2 thorpej break;
169 1.2.2.2 thorpej
170 1.2.2.2 thorpej case ACPI_RSTYPE_FIXED_MEM32:
171 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
172 1.2.2.2 thorpej "FixedMemory32 0x%x/%d\n",
173 1.2.2.2 thorpej res->Data.FixedMemory32.RangeBaseAddress,
174 1.2.2.2 thorpej res->Data.FixedMemory32.RangeLength));
175 1.2.2.2 thorpej (*ops->memory)(dev, context,
176 1.2.2.2 thorpej res->Data.FixedMemory32.RangeBaseAddress,
177 1.2.2.2 thorpej res->Data.FixedMemory32.RangeLength);
178 1.2.2.2 thorpej break;
179 1.2.2.2 thorpej
180 1.2.2.2 thorpej case ACPI_RSTYPE_MEM32:
181 1.2.2.2 thorpej if (res->Data.Memory32.MinBaseAddress ==
182 1.2.2.2 thorpej res->Data.Memory32.MaxBaseAddress) {
183 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
184 1.2.2.2 thorpej "Memory32 0x%x/%d\n",
185 1.2.2.2 thorpej res->Data.Memory32.MinBaseAddress,
186 1.2.2.2 thorpej res->Data.Memory32.RangeLength));
187 1.2.2.2 thorpej (*ops->memory)(dev, context,
188 1.2.2.2 thorpej res->Data.Memory32.MinBaseAddress,
189 1.2.2.2 thorpej res->Data.Memory32.RangeLength);
190 1.2.2.2 thorpej } else {
191 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
192 1.2.2.2 thorpej "Memory32 0x%x-0x%x/%d\n",
193 1.2.2.2 thorpej res->Data.Memory32.MinBaseAddress,
194 1.2.2.2 thorpej res->Data.Memory32.MaxBaseAddress,
195 1.2.2.2 thorpej res->Data.Memory32.RangeLength));
196 1.2.2.2 thorpej (*ops->memrange)(dev, context,
197 1.2.2.2 thorpej res->Data.Memory32.MinBaseAddress,
198 1.2.2.2 thorpej res->Data.Memory32.MaxBaseAddress,
199 1.2.2.2 thorpej res->Data.Memory32.RangeLength,
200 1.2.2.2 thorpej res->Data.Memory32.Alignment);
201 1.2.2.2 thorpej }
202 1.2.2.2 thorpej break;
203 1.2.2.2 thorpej
204 1.2.2.2 thorpej case ACPI_RSTYPE_MEM24:
205 1.2.2.2 thorpej if (res->Data.Memory24.MinBaseAddress ==
206 1.2.2.2 thorpej res->Data.Memory24.MaxBaseAddress) {
207 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
208 1.2.2.2 thorpej "Memory24 0x%x/%d\n",
209 1.2.2.2 thorpej res->Data.Memory24.MinBaseAddress,
210 1.2.2.2 thorpej res->Data.Memory24.RangeLength));
211 1.2.2.2 thorpej (*ops->memory)(dev, context,
212 1.2.2.2 thorpej res->Data.Memory24.MinBaseAddress,
213 1.2.2.2 thorpej res->Data.Memory24.RangeLength);
214 1.2.2.2 thorpej } else {
215 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
216 1.2.2.2 thorpej "Memory24 0x%x-0x%x/%d\n",
217 1.2.2.2 thorpej res->Data.Memory24.MinBaseAddress,
218 1.2.2.2 thorpej res->Data.Memory24.MaxBaseAddress,
219 1.2.2.2 thorpej res->Data.Memory24.RangeLength));
220 1.2.2.2 thorpej (*ops->memrange)(dev, context,
221 1.2.2.2 thorpej res->Data.Memory24.MinBaseAddress,
222 1.2.2.2 thorpej res->Data.Memory24.MaxBaseAddress,
223 1.2.2.2 thorpej res->Data.Memory24.RangeLength,
224 1.2.2.2 thorpej res->Data.Memory24.Alignment);
225 1.2.2.2 thorpej }
226 1.2.2.2 thorpej break;
227 1.2.2.2 thorpej
228 1.2.2.2 thorpej case ACPI_RSTYPE_IRQ:
229 1.2.2.2 thorpej for (i = 0; i < res->Data.Irq.NumberOfInterrupts; i++) {
230 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
231 1.2.2.2 thorpej "IRQ %d\n", res->Data.Irq.Interrupts[i]));
232 1.2.2.2 thorpej (*ops->irq)(dev, context,
233 1.2.2.2 thorpej res->Data.Irq.Interrupts[i]);
234 1.2.2.2 thorpej }
235 1.2.2.2 thorpej break;
236 1.2.2.2 thorpej
237 1.2.2.2 thorpej case ACPI_RSTYPE_DMA:
238 1.2.2.2 thorpej for (i = 0; i < res->Data.Dma.NumberOfChannels; i++) {
239 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
240 1.2.2.2 thorpej "DRQ %d\n", res->Data.Dma.Channels[i]));
241 1.2.2.2 thorpej (*ops->drq)(dev, context,
242 1.2.2.2 thorpej res->Data.Dma.Channels[i]);
243 1.2.2.2 thorpej }
244 1.2.2.2 thorpej break;
245 1.2.2.2 thorpej
246 1.2.2.2 thorpej case ACPI_RSTYPE_START_DPF:
247 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
248 1.2.2.2 thorpej "Start dependant functions: %d\n",
249 1.2.2.2 thorpej res->Data.StartDpf.CompatibilityPriority));
250 1.2.2.2 thorpej (*ops->start_dep)(dev, context,
251 1.2.2.2 thorpej res->Data.StartDpf.CompatibilityPriority);
252 1.2.2.2 thorpej break;
253 1.2.2.2 thorpej
254 1.2.2.2 thorpej case ACPI_RSTYPE_END_DPF:
255 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
256 1.2.2.2 thorpej "End dependant functions\n"));
257 1.2.2.2 thorpej (*ops->end_dep)(dev, context);
258 1.2.2.2 thorpej
259 1.2.2.2 thorpej case ACPI_RSTYPE_ADDRESS32:
260 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
261 1.2.2.2 thorpej "Address32 unimplemented\n"));
262 1.2.2.2 thorpej break;
263 1.2.2.2 thorpej
264 1.2.2.2 thorpej case ACPI_RSTYPE_ADDRESS16:
265 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
266 1.2.2.2 thorpej "Address16 unimplemented\n"));
267 1.2.2.2 thorpej break;
268 1.2.2.2 thorpej
269 1.2.2.2 thorpej case ACPI_RSTYPE_EXT_IRQ:
270 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
271 1.2.2.2 thorpej "ExtendedIrq unimplemented\n"));
272 1.2.2.2 thorpej break;
273 1.2.2.2 thorpej
274 1.2.2.2 thorpej case ACPI_RSTYPE_VENDOR:
275 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
276 1.2.2.2 thorpej "VendorSpecific unimplemented\n"));
277 1.2.2.2 thorpej break;
278 1.2.2.2 thorpej
279 1.2.2.2 thorpej default:
280 1.2.2.2 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
281 1.2.2.2 thorpej "Unknown resource type: %d\n", res->Id));
282 1.2.2.2 thorpej break;
283 1.2.2.2 thorpej }
284 1.2.2.2 thorpej }
285 1.2.2.2 thorpej
286 1.2.2.2 thorpej AcpiOsFree(buf.Pointer);
287 1.2.2.2 thorpej (*ops->fini)(dev, context);
288 1.2.2.2 thorpej
289 1.2.2.2 thorpej return_ACPI_STATUS(AE_OK);
290 1.2.2.2 thorpej }
291 1.2.2.2 thorpej
292 1.2.2.2 thorpej /*
293 1.2.2.2 thorpej * acpi_resource_print:
294 1.2.2.2 thorpej *
295 1.2.2.2 thorpej * Print the resources assigned to a device.
296 1.2.2.2 thorpej */
297 1.2.2.2 thorpej void
298 1.2.2.2 thorpej acpi_resource_print(struct device *dev, struct acpi_resources *res)
299 1.2.2.2 thorpej {
300 1.2.2.2 thorpej const char *sep;
301 1.2.2.2 thorpej
302 1.2.2.2 thorpej if (SIMPLEQ_EMPTY(&res->ar_io) &&
303 1.2.2.2 thorpej SIMPLEQ_EMPTY(&res->ar_iorange) &&
304 1.2.2.2 thorpej SIMPLEQ_EMPTY(&res->ar_mem) &&
305 1.2.2.2 thorpej SIMPLEQ_EMPTY(&res->ar_memrange) &&
306 1.2.2.2 thorpej SIMPLEQ_EMPTY(&res->ar_irq) &&
307 1.2.2.2 thorpej SIMPLEQ_EMPTY(&res->ar_drq))
308 1.2.2.2 thorpej return;
309 1.2.2.2 thorpej
310 1.2.2.2 thorpej printf("%s:", dev->dv_xname);
311 1.2.2.2 thorpej
312 1.2.2.2 thorpej if (SIMPLEQ_EMPTY(&res->ar_io) == 0) {
313 1.2.2.2 thorpej struct acpi_io *ar;
314 1.2.2.2 thorpej
315 1.2.2.2 thorpej sep = "";
316 1.2.2.2 thorpej printf(" io ");
317 1.2.2.3 jdolecek SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
318 1.2.2.2 thorpej printf("%s0x%x", sep, ar->ar_base);
319 1.2.2.2 thorpej if (ar->ar_length > 1)
320 1.2.2.2 thorpej printf("-0x%x", ar->ar_base +
321 1.2.2.2 thorpej ar->ar_length - 1);
322 1.2.2.2 thorpej sep = ",";
323 1.2.2.2 thorpej }
324 1.2.2.2 thorpej }
325 1.2.2.2 thorpej
326 1.2.2.2 thorpej /* XXX iorange */
327 1.2.2.2 thorpej
328 1.2.2.2 thorpej if (SIMPLEQ_EMPTY(&res->ar_mem) == 0) {
329 1.2.2.2 thorpej struct acpi_mem *ar;
330 1.2.2.2 thorpej
331 1.2.2.2 thorpej sep = "";
332 1.2.2.2 thorpej printf(" mem ");
333 1.2.2.3 jdolecek SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
334 1.2.2.2 thorpej printf("%s0x%x", sep, ar->ar_base);
335 1.2.2.2 thorpej if (ar->ar_length > 1)
336 1.2.2.2 thorpej printf("-0x%x", ar->ar_base +
337 1.2.2.2 thorpej ar->ar_length - 1);
338 1.2.2.2 thorpej sep = ",";
339 1.2.2.2 thorpej }
340 1.2.2.2 thorpej }
341 1.2.2.2 thorpej
342 1.2.2.2 thorpej /* XXX memrange */
343 1.2.2.2 thorpej
344 1.2.2.2 thorpej if (SIMPLEQ_EMPTY(&res->ar_irq) == 0) {
345 1.2.2.2 thorpej struct acpi_irq *ar;
346 1.2.2.2 thorpej
347 1.2.2.2 thorpej sep = "";
348 1.2.2.2 thorpej printf(" irq ");
349 1.2.2.3 jdolecek SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
350 1.2.2.2 thorpej printf("%s%d", sep, ar->ar_irq);
351 1.2.2.2 thorpej sep = ",";
352 1.2.2.2 thorpej }
353 1.2.2.2 thorpej }
354 1.2.2.2 thorpej
355 1.2.2.2 thorpej if (SIMPLEQ_EMPTY(&res->ar_drq) == 0) {
356 1.2.2.2 thorpej struct acpi_drq *ar;
357 1.2.2.2 thorpej
358 1.2.2.2 thorpej sep = "";
359 1.2.2.2 thorpej printf(" drq ");
360 1.2.2.3 jdolecek SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
361 1.2.2.2 thorpej printf("%s%d", sep, ar->ar_drq);
362 1.2.2.2 thorpej sep = ",";
363 1.2.2.2 thorpej }
364 1.2.2.2 thorpej }
365 1.2.2.2 thorpej
366 1.2.2.2 thorpej printf("\n");
367 1.2.2.2 thorpej }
368 1.2.2.2 thorpej
369 1.2.2.2 thorpej struct acpi_io *
370 1.2.2.2 thorpej acpi_res_io(struct acpi_resources *res, int idx)
371 1.2.2.2 thorpej {
372 1.2.2.2 thorpej struct acpi_io *ar;
373 1.2.2.2 thorpej
374 1.2.2.2 thorpej SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
375 1.2.2.2 thorpej if (ar->ar_index == idx)
376 1.2.2.2 thorpej return (ar);
377 1.2.2.2 thorpej }
378 1.2.2.2 thorpej return (NULL);
379 1.2.2.2 thorpej }
380 1.2.2.2 thorpej
381 1.2.2.2 thorpej struct acpi_iorange *
382 1.2.2.2 thorpej acpi_res_iorange(struct acpi_resources *res, int idx)
383 1.2.2.2 thorpej {
384 1.2.2.2 thorpej struct acpi_iorange *ar;
385 1.2.2.2 thorpej
386 1.2.2.2 thorpej SIMPLEQ_FOREACH(ar, &res->ar_iorange, ar_list) {
387 1.2.2.2 thorpej if (ar->ar_index == idx)
388 1.2.2.2 thorpej return (ar);
389 1.2.2.2 thorpej }
390 1.2.2.2 thorpej return (NULL);
391 1.2.2.2 thorpej }
392 1.2.2.2 thorpej
393 1.2.2.2 thorpej struct acpi_mem *
394 1.2.2.2 thorpej acpi_res_mem(struct acpi_resources *res, int idx)
395 1.2.2.2 thorpej {
396 1.2.2.2 thorpej struct acpi_mem *ar;
397 1.2.2.2 thorpej
398 1.2.2.2 thorpej SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
399 1.2.2.2 thorpej if (ar->ar_index == idx)
400 1.2.2.2 thorpej return (ar);
401 1.2.2.2 thorpej }
402 1.2.2.2 thorpej return (NULL);
403 1.2.2.2 thorpej }
404 1.2.2.2 thorpej
405 1.2.2.2 thorpej struct acpi_memrange *
406 1.2.2.2 thorpej acpi_res_memrange(struct acpi_resources *res, int idx)
407 1.2.2.2 thorpej {
408 1.2.2.2 thorpej struct acpi_memrange *ar;
409 1.2.2.2 thorpej
410 1.2.2.2 thorpej SIMPLEQ_FOREACH(ar, &res->ar_memrange, ar_list) {
411 1.2.2.2 thorpej if (ar->ar_index == idx)
412 1.2.2.2 thorpej return (ar);
413 1.2.2.2 thorpej }
414 1.2.2.2 thorpej return (NULL);
415 1.2.2.2 thorpej }
416 1.2.2.2 thorpej
417 1.2.2.2 thorpej struct acpi_irq *
418 1.2.2.2 thorpej acpi_res_irq(struct acpi_resources *res, int idx)
419 1.2.2.2 thorpej {
420 1.2.2.2 thorpej struct acpi_irq *ar;
421 1.2.2.2 thorpej
422 1.2.2.2 thorpej SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
423 1.2.2.2 thorpej if (ar->ar_index == idx)
424 1.2.2.2 thorpej return (ar);
425 1.2.2.2 thorpej }
426 1.2.2.2 thorpej return (NULL);
427 1.2.2.2 thorpej }
428 1.2.2.2 thorpej
429 1.2.2.2 thorpej struct acpi_drq *
430 1.2.2.2 thorpej acpi_res_drq(struct acpi_resources *res, int idx)
431 1.2.2.2 thorpej {
432 1.2.2.2 thorpej struct acpi_drq *ar;
433 1.2.2.2 thorpej
434 1.2.2.2 thorpej SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
435 1.2.2.2 thorpej if (ar->ar_index == idx)
436 1.2.2.2 thorpej return (ar);
437 1.2.2.2 thorpej }
438 1.2.2.2 thorpej return (NULL);
439 1.2.2.2 thorpej }
440 1.2.2.2 thorpej
441 1.2.2.2 thorpej /*****************************************************************************
442 1.2.2.2 thorpej * Default ACPI resource parse operations.
443 1.2.2.2 thorpej *****************************************************************************/
444 1.2.2.2 thorpej
445 1.2.2.2 thorpej static void acpi_res_parse_init(struct device *, void *, void **);
446 1.2.2.2 thorpej static void acpi_res_parse_fini(struct device *, void *);
447 1.2.2.2 thorpej
448 1.2.2.2 thorpej static void acpi_res_parse_ioport(struct device *, void *, uint32_t,
449 1.2.2.2 thorpej uint32_t);
450 1.2.2.2 thorpej static void acpi_res_parse_iorange(struct device *, void *, uint32_t,
451 1.2.2.2 thorpej uint32_t, uint32_t, uint32_t);
452 1.2.2.2 thorpej
453 1.2.2.2 thorpej static void acpi_res_parse_memory(struct device *, void *, uint32_t,
454 1.2.2.2 thorpej uint32_t);
455 1.2.2.2 thorpej static void acpi_res_parse_memrange(struct device *, void *, uint32_t,
456 1.2.2.2 thorpej uint32_t, uint32_t, uint32_t);
457 1.2.2.2 thorpej
458 1.2.2.2 thorpej static void acpi_res_parse_irq(struct device *, void *, uint32_t);
459 1.2.2.2 thorpej static void acpi_res_parse_drq(struct device *, void *, uint32_t);
460 1.2.2.2 thorpej
461 1.2.2.2 thorpej static void acpi_res_parse_start_dep(struct device *, void *, int);
462 1.2.2.2 thorpej static void acpi_res_parse_end_dep(struct device *, void *);
463 1.2.2.2 thorpej
464 1.2.2.2 thorpej const struct acpi_resource_parse_ops acpi_resource_parse_ops_default = {
465 1.2.2.2 thorpej acpi_res_parse_init,
466 1.2.2.2 thorpej acpi_res_parse_fini,
467 1.2.2.2 thorpej
468 1.2.2.2 thorpej acpi_res_parse_ioport,
469 1.2.2.2 thorpej acpi_res_parse_iorange,
470 1.2.2.2 thorpej
471 1.2.2.2 thorpej acpi_res_parse_memory,
472 1.2.2.2 thorpej acpi_res_parse_memrange,
473 1.2.2.2 thorpej
474 1.2.2.2 thorpej acpi_res_parse_irq,
475 1.2.2.2 thorpej acpi_res_parse_drq,
476 1.2.2.2 thorpej
477 1.2.2.2 thorpej acpi_res_parse_start_dep,
478 1.2.2.2 thorpej acpi_res_parse_end_dep,
479 1.2.2.2 thorpej };
480 1.2.2.2 thorpej
481 1.2.2.2 thorpej static void
482 1.2.2.2 thorpej acpi_res_parse_init(struct device *dev, void *arg, void **contextp)
483 1.2.2.2 thorpej {
484 1.2.2.2 thorpej struct acpi_resources *res = arg;
485 1.2.2.2 thorpej
486 1.2.2.2 thorpej SIMPLEQ_INIT(&res->ar_io);
487 1.2.2.2 thorpej res->ar_nio = 0;
488 1.2.2.2 thorpej
489 1.2.2.2 thorpej SIMPLEQ_INIT(&res->ar_iorange);
490 1.2.2.2 thorpej res->ar_niorange = 0;
491 1.2.2.2 thorpej
492 1.2.2.2 thorpej SIMPLEQ_INIT(&res->ar_mem);
493 1.2.2.2 thorpej res->ar_nmem = 0;
494 1.2.2.2 thorpej
495 1.2.2.2 thorpej SIMPLEQ_INIT(&res->ar_memrange);
496 1.2.2.2 thorpej res->ar_nmemrange = 0;
497 1.2.2.2 thorpej
498 1.2.2.2 thorpej SIMPLEQ_INIT(&res->ar_irq);
499 1.2.2.2 thorpej res->ar_nirq = 0;
500 1.2.2.2 thorpej
501 1.2.2.2 thorpej SIMPLEQ_INIT(&res->ar_drq);
502 1.2.2.2 thorpej res->ar_ndrq = 0;
503 1.2.2.2 thorpej
504 1.2.2.2 thorpej *contextp = res;
505 1.2.2.2 thorpej }
506 1.2.2.2 thorpej
507 1.2.2.2 thorpej static void
508 1.2.2.2 thorpej acpi_res_parse_fini(struct device *dev, void *context)
509 1.2.2.2 thorpej {
510 1.2.2.2 thorpej struct acpi_resources *res = context;
511 1.2.2.2 thorpej
512 1.2.2.2 thorpej /* Print the resources we're using. */
513 1.2.2.2 thorpej acpi_resource_print(dev, res);
514 1.2.2.2 thorpej }
515 1.2.2.2 thorpej
516 1.2.2.2 thorpej static void
517 1.2.2.2 thorpej acpi_res_parse_ioport(struct device *dev, void *context, uint32_t base,
518 1.2.2.2 thorpej uint32_t length)
519 1.2.2.2 thorpej {
520 1.2.2.2 thorpej struct acpi_resources *res = context;
521 1.2.2.2 thorpej struct acpi_io *ar;
522 1.2.2.2 thorpej
523 1.2.2.2 thorpej ar = AcpiOsAllocate(sizeof(*ar));
524 1.2.2.2 thorpej if (ar == NULL) {
525 1.2.2.2 thorpej printf("%s: ACPI: unable to allocate I/O resource %d\n",
526 1.2.2.2 thorpej dev->dv_xname, res->ar_nio);
527 1.2.2.2 thorpej res->ar_nio++;
528 1.2.2.2 thorpej return;
529 1.2.2.2 thorpej }
530 1.2.2.2 thorpej
531 1.2.2.2 thorpej ar->ar_index = res->ar_nio++;
532 1.2.2.2 thorpej ar->ar_base = base;
533 1.2.2.2 thorpej ar->ar_length = length;
534 1.2.2.2 thorpej
535 1.2.2.2 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_io, ar, ar_list);
536 1.2.2.2 thorpej }
537 1.2.2.2 thorpej
538 1.2.2.2 thorpej static void
539 1.2.2.2 thorpej acpi_res_parse_iorange(struct device *dev, void *context, uint32_t low,
540 1.2.2.2 thorpej uint32_t high, uint32_t length, uint32_t align)
541 1.2.2.2 thorpej {
542 1.2.2.2 thorpej struct acpi_resources *res = context;
543 1.2.2.2 thorpej struct acpi_iorange *ar;
544 1.2.2.2 thorpej
545 1.2.2.2 thorpej ar = AcpiOsAllocate(sizeof(*ar));
546 1.2.2.2 thorpej if (ar == NULL) {
547 1.2.2.2 thorpej printf("%s: ACPI: unable to allocate I/O range resource %d\n",
548 1.2.2.2 thorpej dev->dv_xname, res->ar_niorange);
549 1.2.2.2 thorpej res->ar_niorange++;
550 1.2.2.2 thorpej return;
551 1.2.2.2 thorpej }
552 1.2.2.2 thorpej
553 1.2.2.2 thorpej ar->ar_index = res->ar_niorange++;
554 1.2.2.2 thorpej ar->ar_low = low;
555 1.2.2.2 thorpej ar->ar_high = high;
556 1.2.2.2 thorpej ar->ar_length = length;
557 1.2.2.2 thorpej ar->ar_align = align;
558 1.2.2.2 thorpej
559 1.2.2.2 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_iorange, ar, ar_list);
560 1.2.2.2 thorpej }
561 1.2.2.2 thorpej
562 1.2.2.2 thorpej static void
563 1.2.2.2 thorpej acpi_res_parse_memory(struct device *dev, void *context, uint32_t base,
564 1.2.2.2 thorpej uint32_t length)
565 1.2.2.2 thorpej {
566 1.2.2.2 thorpej struct acpi_resources *res = context;
567 1.2.2.2 thorpej struct acpi_mem *ar;
568 1.2.2.2 thorpej
569 1.2.2.2 thorpej ar = AcpiOsAllocate(sizeof(*ar));
570 1.2.2.2 thorpej if (ar == NULL) {
571 1.2.2.2 thorpej printf("%s: ACPI: unable to allocate Memory resource %d\n",
572 1.2.2.2 thorpej dev->dv_xname, res->ar_nmem);
573 1.2.2.2 thorpej res->ar_nmem++;
574 1.2.2.2 thorpej return;
575 1.2.2.2 thorpej }
576 1.2.2.2 thorpej
577 1.2.2.2 thorpej ar->ar_index = res->ar_nmem++;
578 1.2.2.2 thorpej ar->ar_base = base;
579 1.2.2.2 thorpej ar->ar_length = length;
580 1.2.2.2 thorpej
581 1.2.2.2 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
582 1.2.2.2 thorpej }
583 1.2.2.2 thorpej
584 1.2.2.2 thorpej static void
585 1.2.2.2 thorpej acpi_res_parse_memrange(struct device *dev, void *context, uint32_t low,
586 1.2.2.2 thorpej uint32_t high, uint32_t length, uint32_t align)
587 1.2.2.2 thorpej {
588 1.2.2.2 thorpej struct acpi_resources *res = context;
589 1.2.2.2 thorpej struct acpi_memrange *ar;
590 1.2.2.2 thorpej
591 1.2.2.2 thorpej ar = AcpiOsAllocate(sizeof(*ar));
592 1.2.2.2 thorpej if (ar == NULL) {
593 1.2.2.2 thorpej printf("%s: ACPI: unable to allocate Memory range resource "
594 1.2.2.2 thorpej "%d\n", dev->dv_xname, res->ar_nmemrange);
595 1.2.2.2 thorpej res->ar_nmemrange++;
596 1.2.2.2 thorpej return;
597 1.2.2.2 thorpej }
598 1.2.2.2 thorpej
599 1.2.2.2 thorpej ar->ar_index = res->ar_nmemrange++;
600 1.2.2.2 thorpej ar->ar_low = low;
601 1.2.2.2 thorpej ar->ar_high = high;
602 1.2.2.2 thorpej ar->ar_length = length;
603 1.2.2.2 thorpej ar->ar_align = align;
604 1.2.2.2 thorpej
605 1.2.2.2 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_memrange, ar, ar_list);
606 1.2.2.2 thorpej }
607 1.2.2.2 thorpej
608 1.2.2.2 thorpej static void
609 1.2.2.2 thorpej acpi_res_parse_irq(struct device *dev, void *context, uint32_t irq)
610 1.2.2.2 thorpej {
611 1.2.2.2 thorpej struct acpi_resources *res = context;
612 1.2.2.2 thorpej struct acpi_irq *ar;
613 1.2.2.2 thorpej
614 1.2.2.2 thorpej ar = AcpiOsAllocate(sizeof(*ar));
615 1.2.2.2 thorpej if (ar == NULL) {
616 1.2.2.2 thorpej printf("%s: ACPI: unable to allocate IRQ resource %d\n",
617 1.2.2.2 thorpej dev->dv_xname, res->ar_nirq);
618 1.2.2.2 thorpej res->ar_nirq++;
619 1.2.2.2 thorpej return;
620 1.2.2.2 thorpej }
621 1.2.2.2 thorpej
622 1.2.2.2 thorpej ar->ar_index = res->ar_nirq++;
623 1.2.2.2 thorpej ar->ar_irq = irq;
624 1.2.2.2 thorpej
625 1.2.2.2 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_irq, ar, ar_list);
626 1.2.2.2 thorpej }
627 1.2.2.2 thorpej
628 1.2.2.2 thorpej static void
629 1.2.2.2 thorpej acpi_res_parse_drq(struct device *dev, void *context, uint32_t drq)
630 1.2.2.2 thorpej {
631 1.2.2.2 thorpej struct acpi_resources *res = context;
632 1.2.2.2 thorpej struct acpi_drq *ar;
633 1.2.2.2 thorpej
634 1.2.2.2 thorpej ar = AcpiOsAllocate(sizeof(*ar));
635 1.2.2.2 thorpej if (ar == NULL) {
636 1.2.2.2 thorpej printf("%s: ACPI: unable to allocate DRQ resource %d\n",
637 1.2.2.2 thorpej dev->dv_xname, res->ar_ndrq);
638 1.2.2.2 thorpej res->ar_ndrq++;
639 1.2.2.2 thorpej return;
640 1.2.2.2 thorpej }
641 1.2.2.2 thorpej
642 1.2.2.2 thorpej ar->ar_index = res->ar_ndrq++;
643 1.2.2.2 thorpej ar->ar_drq = drq;
644 1.2.2.2 thorpej
645 1.2.2.2 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_drq, ar, ar_list);
646 1.2.2.2 thorpej }
647 1.2.2.2 thorpej
648 1.2.2.2 thorpej static void
649 1.2.2.2 thorpej acpi_res_parse_start_dep(struct device *dev, void *context, int preference)
650 1.2.2.2 thorpej {
651 1.2.2.2 thorpej
652 1.2.2.2 thorpej printf("%s: ACPI: dependant functions not supported\n",
653 1.2.2.2 thorpej dev->dv_xname);
654 1.2.2.2 thorpej }
655 1.2.2.2 thorpej
656 1.2.2.2 thorpej static void
657 1.2.2.2 thorpej acpi_res_parse_end_dep(struct device *dev, void *context)
658 1.2.2.2 thorpej {
659 1.2.2.2 thorpej
660 1.2.2.2 thorpej /* Nothing to do. */
661 1.2.2.2 thorpej }
662