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