acpi_resource.c revision 1.37 1 1.37 msaitoh /* $NetBSD: acpi_resource.c,v 1.37 2015/07/27 04:50:50 msaitoh Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright 2001 Wasabi Systems, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1 thorpej *
9 1.1 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1 thorpej * modification, are permitted provided that the following conditions
11 1.1 thorpej * are met:
12 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1 thorpej * documentation and/or other materials provided with the distribution.
17 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1 thorpej * must display the following acknowledgement:
19 1.1 thorpej * This product includes software developed for the NetBSD Project by
20 1.1 thorpej * Wasabi Systems, Inc.
21 1.1 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 thorpej * or promote products derived from this software without specific prior
23 1.1 thorpej * written permission.
24 1.1 thorpej *
25 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.1 thorpej */
37 1.1 thorpej
38 1.1 thorpej /*-
39 1.1 thorpej * Copyright (c) 2000 Michael Smith
40 1.1 thorpej * Copyright (c) 2000 BSDi
41 1.1 thorpej * All rights reserved.
42 1.1 thorpej *
43 1.1 thorpej * Redistribution and use in source and binary forms, with or without
44 1.1 thorpej * modification, are permitted provided that the following conditions
45 1.1 thorpej * are met:
46 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
47 1.1 thorpej * notice, this list of conditions and the following disclaimer.
48 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
50 1.1 thorpej * documentation and/or other materials provided with the distribution.
51 1.10 kochi *
52 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.10 kochi * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.10 kochi * SUCH DAMAGE.
63 1.1 thorpej */
64 1.1 thorpej
65 1.1 thorpej /*
66 1.1 thorpej * ACPI resource parsing.
67 1.1 thorpej */
68 1.2 lukem
69 1.2 lukem #include <sys/cdefs.h>
70 1.37 msaitoh __KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.37 2015/07/27 04:50:50 msaitoh Exp $");
71 1.1 thorpej
72 1.1 thorpej #include <sys/param.h>
73 1.32 jruoho #include <sys/device.h>
74 1.1 thorpej #include <sys/systm.h>
75 1.1 thorpej
76 1.1 thorpej #include <dev/acpi/acpireg.h>
77 1.1 thorpej #include <dev/acpi/acpivar.h>
78 1.1 thorpej
79 1.4 thorpej #define _COMPONENT ACPI_RESOURCE_COMPONENT
80 1.4 thorpej ACPI_MODULE_NAME("RESOURCE")
81 1.1 thorpej
82 1.13 kochi static ACPI_STATUS acpi_resource_parse_callback(ACPI_RESOURCE *, void *);
83 1.13 kochi
84 1.12 kochi struct resource_parse_callback_arg {
85 1.12 kochi const struct acpi_resource_parse_ops *ops;
86 1.28 cegger device_t dev;
87 1.12 kochi void *context;
88 1.12 kochi };
89 1.12 kochi
90 1.12 kochi static ACPI_STATUS
91 1.12 kochi acpi_resource_parse_callback(ACPI_RESOURCE *res, void *context)
92 1.1 thorpej {
93 1.12 kochi struct resource_parse_callback_arg *arg = context;
94 1.12 kochi const struct acpi_resource_parse_ops *ops;
95 1.1 thorpej int i;
96 1.1 thorpej
97 1.24 perry ACPI_FUNCTION_TRACE(__func__);
98 1.15 kochi
99 1.12 kochi ops = arg->ops;
100 1.1 thorpej
101 1.19 kochi switch (res->Type) {
102 1.37 msaitoh case ACPI_RESOURCE_TYPE_END_TAG:
103 1.37 msaitoh ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
104 1.37 msaitoh break;
105 1.19 kochi case ACPI_RESOURCE_TYPE_FIXED_IO:
106 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
107 1.31 jruoho "FixedIo 0x%x/%u\n",
108 1.19 kochi res->Data.FixedIo.Address,
109 1.19 kochi res->Data.FixedIo.AddressLength));
110 1.13 kochi if (ops->ioport)
111 1.13 kochi (*ops->ioport)(arg->dev, arg->context,
112 1.19 kochi res->Data.FixedIo.Address,
113 1.19 kochi res->Data.FixedIo.AddressLength);
114 1.12 kochi break;
115 1.1 thorpej
116 1.19 kochi case ACPI_RESOURCE_TYPE_IO:
117 1.19 kochi if (res->Data.Io.Minimum ==
118 1.22 njoly res->Data.Io.Maximum) {
119 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
120 1.31 jruoho "Io 0x%x/%u\n",
121 1.19 kochi res->Data.Io.Minimum,
122 1.19 kochi res->Data.Io.AddressLength));
123 1.13 kochi if (ops->ioport)
124 1.13 kochi (*ops->ioport)(arg->dev, arg->context,
125 1.19 kochi res->Data.Io.Minimum,
126 1.19 kochi res->Data.Io.AddressLength);
127 1.12 kochi } else {
128 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
129 1.31 jruoho "Io 0x%x-0x%x/%u\n",
130 1.19 kochi res->Data.Io.Minimum,
131 1.19 kochi res->Data.Io.Maximum,
132 1.19 kochi res->Data.Io.AddressLength));
133 1.22 njoly if (ops->iorange)
134 1.13 kochi (*ops->iorange)(arg->dev, arg->context,
135 1.19 kochi res->Data.Io.Minimum,
136 1.19 kochi res->Data.Io.Maximum,
137 1.19 kochi res->Data.Io.AddressLength,
138 1.13 kochi res->Data.Io.Alignment);
139 1.12 kochi }
140 1.12 kochi break;
141 1.1 thorpej
142 1.19 kochi case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
143 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
144 1.31 jruoho "FixedMemory32 0x%x/%u\n",
145 1.19 kochi res->Data.FixedMemory32.Address,
146 1.19 kochi res->Data.FixedMemory32.AddressLength));
147 1.13 kochi if (ops->memory)
148 1.13 kochi (*ops->memory)(arg->dev, arg->context,
149 1.19 kochi res->Data.FixedMemory32.Address,
150 1.19 kochi res->Data.FixedMemory32.AddressLength);
151 1.12 kochi break;
152 1.12 kochi
153 1.19 kochi case ACPI_RESOURCE_TYPE_MEMORY32:
154 1.19 kochi if (res->Data.Memory32.Minimum ==
155 1.19 kochi res->Data.Memory32.Maximum) {
156 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
157 1.31 jruoho "Memory32 0x%x/%u\n",
158 1.19 kochi res->Data.Memory32.Minimum,
159 1.19 kochi res->Data.Memory32.AddressLength));
160 1.13 kochi if (ops->memory)
161 1.13 kochi (*ops->memory)(arg->dev, arg->context,
162 1.19 kochi res->Data.Memory32.Minimum,
163 1.19 kochi res->Data.Memory32.AddressLength);
164 1.12 kochi } else {
165 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
166 1.31 jruoho "Memory32 0x%x-0x%x/%u\n",
167 1.19 kochi res->Data.Memory32.Minimum,
168 1.19 kochi res->Data.Memory32.Maximum,
169 1.19 kochi res->Data.Memory32.AddressLength));
170 1.13 kochi if (ops->memrange)
171 1.13 kochi (*ops->memrange)(arg->dev, arg->context,
172 1.19 kochi res->Data.Memory32.Minimum,
173 1.19 kochi res->Data.Memory32.Maximum,
174 1.19 kochi res->Data.Memory32.AddressLength,
175 1.13 kochi res->Data.Memory32.Alignment);
176 1.12 kochi }
177 1.12 kochi break;
178 1.1 thorpej
179 1.19 kochi case ACPI_RESOURCE_TYPE_MEMORY24:
180 1.19 kochi if (res->Data.Memory24.Minimum ==
181 1.19 kochi res->Data.Memory24.Maximum) {
182 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
183 1.31 jruoho "Memory24 0x%x/%u\n",
184 1.19 kochi res->Data.Memory24.Minimum,
185 1.19 kochi res->Data.Memory24.AddressLength));
186 1.13 kochi if (ops->memory)
187 1.13 kochi (*ops->memory)(arg->dev, arg->context,
188 1.19 kochi res->Data.Memory24.Minimum,
189 1.19 kochi res->Data.Memory24.AddressLength);
190 1.12 kochi } else {
191 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
192 1.31 jruoho "Memory24 0x%x-0x%x/%u\n",
193 1.19 kochi res->Data.Memory24.Minimum,
194 1.19 kochi res->Data.Memory24.Maximum,
195 1.19 kochi res->Data.Memory24.AddressLength));
196 1.13 kochi if (ops->memrange)
197 1.13 kochi (*ops->memrange)(arg->dev, arg->context,
198 1.19 kochi res->Data.Memory24.Minimum,
199 1.19 kochi res->Data.Memory24.Maximum,
200 1.19 kochi res->Data.Memory24.AddressLength,
201 1.13 kochi res->Data.Memory24.Alignment);
202 1.12 kochi }
203 1.12 kochi break;
204 1.1 thorpej
205 1.19 kochi case ACPI_RESOURCE_TYPE_IRQ:
206 1.19 kochi for (i = 0; i < res->Data.Irq.InterruptCount; i++) {
207 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
208 1.31 jruoho "IRQ %u\n",
209 1.12 kochi res->Data.Irq.Interrupts[i]));
210 1.13 kochi if (ops->irq)
211 1.13 kochi (*ops->irq)(arg->dev, arg->context,
212 1.13 kochi res->Data.Irq.Interrupts[i],
213 1.19 kochi res->Data.Irq.Triggering);
214 1.12 kochi }
215 1.12 kochi break;
216 1.1 thorpej
217 1.19 kochi case ACPI_RESOURCE_TYPE_DMA:
218 1.19 kochi for (i = 0; i < res->Data.Dma.ChannelCount; i++) {
219 1.1 thorpej ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
220 1.31 jruoho "DRQ %u\n",
221 1.12 kochi res->Data.Dma.Channels[i]));
222 1.13 kochi if (ops->drq)
223 1.13 kochi (*ops->drq)(arg->dev, arg->context,
224 1.13 kochi res->Data.Dma.Channels[i]);
225 1.1 thorpej }
226 1.12 kochi break;
227 1.12 kochi
228 1.19 kochi case ACPI_RESOURCE_TYPE_START_DEPENDENT:
229 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
230 1.35 wiz "Start dependent functions: %u\n",
231 1.12 kochi res->Data.StartDpf.CompatibilityPriority));
232 1.13 kochi if (ops->start_dep)
233 1.13 kochi (*ops->start_dep)(arg->dev, arg->context,
234 1.13 kochi res->Data.StartDpf.CompatibilityPriority);
235 1.12 kochi break;
236 1.12 kochi
237 1.19 kochi case ACPI_RESOURCE_TYPE_END_DEPENDENT:
238 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
239 1.35 wiz "End dependent functions\n"));
240 1.13 kochi if (ops->end_dep)
241 1.13 kochi (*ops->end_dep)(arg->dev, arg->context);
242 1.22 njoly break;
243 1.12 kochi
244 1.19 kochi case ACPI_RESOURCE_TYPE_ADDRESS32:
245 1.22 njoly /* XXX Only fixed size supported for now */
246 1.36 christos if (res->Data.Address32.Address.AddressLength == 0 ||
247 1.22 njoly res->Data.Address32.ProducerConsumer != ACPI_CONSUMER)
248 1.22 njoly break;
249 1.22 njoly #define ADRRESS32_FIXED2(r) \
250 1.22 njoly ((r)->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED && \
251 1.22 njoly (r)->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED)
252 1.22 njoly switch (res->Data.Address32.ResourceType) {
253 1.22 njoly case ACPI_MEMORY_RANGE:
254 1.22 njoly if (ADRRESS32_FIXED2(res)) {
255 1.22 njoly if (ops->memory)
256 1.22 njoly (*ops->memory)(arg->dev, arg->context,
257 1.36 christos res->Data.Address32.Address.Minimum,
258 1.36 christos res->Data.Address32.Address.AddressLength);
259 1.22 njoly } else {
260 1.22 njoly if (ops->memrange)
261 1.22 njoly (*ops->memrange)(arg->dev, arg->context,
262 1.36 christos res->Data.Address32.Address.Minimum,
263 1.36 christos res->Data.Address32.Address.Maximum,
264 1.36 christos res->Data.Address32.Address.AddressLength,
265 1.36 christos res->Data.Address32.Address.Granularity);
266 1.22 njoly }
267 1.22 njoly break;
268 1.22 njoly case ACPI_IO_RANGE:
269 1.22 njoly if (ADRRESS32_FIXED2(res)) {
270 1.22 njoly if (ops->ioport)
271 1.22 njoly (*ops->ioport)(arg->dev, arg->context,
272 1.36 christos res->Data.Address32.Address.Minimum,
273 1.36 christos res->Data.Address32.Address.AddressLength);
274 1.22 njoly } else {
275 1.22 njoly if (ops->iorange)
276 1.22 njoly (*ops->iorange)(arg->dev, arg->context,
277 1.36 christos res->Data.Address32.Address.Minimum,
278 1.36 christos res->Data.Address32.Address.Maximum,
279 1.36 christos res->Data.Address32.Address.AddressLength,
280 1.36 christos res->Data.Address32.Address.Granularity);
281 1.22 njoly }
282 1.22 njoly break;
283 1.22 njoly case ACPI_BUS_NUMBER_RANGE:
284 1.22 njoly ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
285 1.22 njoly "Address32/BusNumber unimplemented\n"));
286 1.22 njoly break;
287 1.22 njoly }
288 1.22 njoly #undef ADRRESS32_FIXED2
289 1.12 kochi break;
290 1.12 kochi
291 1.19 kochi case ACPI_RESOURCE_TYPE_ADDRESS16:
292 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
293 1.12 kochi "Address16 unimplemented\n"));
294 1.12 kochi break;
295 1.12 kochi
296 1.37 msaitoh case ACPI_RESOURCE_TYPE_ADDRESS64:
297 1.37 msaitoh ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
298 1.37 msaitoh "Address64 unimplemented\n"));
299 1.37 msaitoh break;
300 1.19 kochi case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
301 1.19 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
302 1.19 kochi "Extended address64 unimplemented\n"));
303 1.19 kochi break;
304 1.19 kochi
305 1.19 kochi case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
306 1.29 kiyohara if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
307 1.29 kiyohara ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
308 1.29 kiyohara "ignored ExtIRQ producer\n"));
309 1.29 kiyohara break;
310 1.29 kiyohara }
311 1.29 kiyohara for (i = 0; i < res->Data.ExtendedIrq.InterruptCount; i++) {
312 1.29 kiyohara ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
313 1.31 jruoho "ExtIRQ %u\n",
314 1.29 kiyohara res->Data.ExtendedIrq.Interrupts[i]));
315 1.29 kiyohara if (ops->irq)
316 1.29 kiyohara (*ops->irq)(arg->dev, arg->context,
317 1.29 kiyohara res->Data.ExtendedIrq.Interrupts[i],
318 1.29 kiyohara res->Data.ExtendedIrq.Triggering);
319 1.29 kiyohara }
320 1.19 kochi break;
321 1.19 kochi
322 1.19 kochi case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
323 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
324 1.22 njoly "GenericRegister unimplemented\n"));
325 1.12 kochi break;
326 1.12 kochi
327 1.19 kochi case ACPI_RESOURCE_TYPE_VENDOR:
328 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
329 1.12 kochi "VendorSpecific unimplemented\n"));
330 1.12 kochi break;
331 1.12 kochi
332 1.12 kochi default:
333 1.12 kochi ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
334 1.31 jruoho "Unknown resource type: %u\n", res->Type));
335 1.12 kochi break;
336 1.12 kochi }
337 1.12 kochi
338 1.15 kochi return_ACPI_STATUS(AE_OK);
339 1.12 kochi }
340 1.12 kochi
341 1.12 kochi
342 1.12 kochi /*
343 1.12 kochi * acpi_resource_parse:
344 1.12 kochi *
345 1.12 kochi * Parse a device node's resources and fill them in for the
346 1.12 kochi * client.
347 1.12 kochi *
348 1.12 kochi * This API supports _CRS (current resources) and
349 1.12 kochi * _PRS (possible resources).
350 1.12 kochi *
351 1.12 kochi * Note that it might be nice to also locate ACPI-specific resource
352 1.12 kochi * items, such as GPE bits.
353 1.12 kochi */
354 1.12 kochi ACPI_STATUS
355 1.28 cegger acpi_resource_parse(device_t dev, ACPI_HANDLE handle, const char *path,
356 1.12 kochi void *arg, const struct acpi_resource_parse_ops *ops)
357 1.12 kochi {
358 1.12 kochi struct resource_parse_callback_arg cbarg;
359 1.12 kochi ACPI_STATUS rv;
360 1.12 kochi
361 1.24 perry ACPI_FUNCTION_TRACE(__func__);
362 1.12 kochi
363 1.13 kochi if (ops->init)
364 1.13 kochi (*ops->init)(dev, arg, &cbarg.context);
365 1.13 kochi else
366 1.13 kochi cbarg.context = arg;
367 1.12 kochi cbarg.ops = ops;
368 1.12 kochi cbarg.dev = dev;
369 1.12 kochi
370 1.17 christos rv = AcpiWalkResources(handle, path, acpi_resource_parse_callback,
371 1.12 kochi &cbarg);
372 1.12 kochi if (ACPI_FAILURE(rv)) {
373 1.23 jmcneill aprint_error_dev(dev, "ACPI: unable to get %s resources: %s\n",
374 1.23 jmcneill path, AcpiFormatException(rv));
375 1.12 kochi return_ACPI_STATUS(rv);
376 1.1 thorpej }
377 1.1 thorpej
378 1.13 kochi if (ops->fini)
379 1.13 kochi (*ops->fini)(dev, cbarg.context);
380 1.1 thorpej
381 1.1 thorpej return_ACPI_STATUS(AE_OK);
382 1.1 thorpej }
383 1.1 thorpej
384 1.1 thorpej /*
385 1.1 thorpej * acpi_resource_print:
386 1.1 thorpej *
387 1.1 thorpej * Print the resources assigned to a device.
388 1.1 thorpej */
389 1.1 thorpej void
390 1.28 cegger acpi_resource_print(device_t dev, struct acpi_resources *res)
391 1.1 thorpej {
392 1.1 thorpej const char *sep;
393 1.1 thorpej
394 1.1 thorpej if (SIMPLEQ_EMPTY(&res->ar_io) &&
395 1.1 thorpej SIMPLEQ_EMPTY(&res->ar_iorange) &&
396 1.1 thorpej SIMPLEQ_EMPTY(&res->ar_mem) &&
397 1.1 thorpej SIMPLEQ_EMPTY(&res->ar_memrange) &&
398 1.1 thorpej SIMPLEQ_EMPTY(&res->ar_irq) &&
399 1.1 thorpej SIMPLEQ_EMPTY(&res->ar_drq))
400 1.1 thorpej return;
401 1.1 thorpej
402 1.27 jmcneill aprint_normal(":");
403 1.1 thorpej
404 1.1 thorpej if (SIMPLEQ_EMPTY(&res->ar_io) == 0) {
405 1.1 thorpej struct acpi_io *ar;
406 1.1 thorpej
407 1.1 thorpej sep = "";
408 1.23 jmcneill aprint_normal(" io ");
409 1.3 lukem SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
410 1.23 jmcneill aprint_normal("%s0x%x", sep, ar->ar_base);
411 1.1 thorpej if (ar->ar_length > 1)
412 1.23 jmcneill aprint_normal("-0x%x", ar->ar_base +
413 1.1 thorpej ar->ar_length - 1);
414 1.1 thorpej sep = ",";
415 1.1 thorpej }
416 1.1 thorpej }
417 1.1 thorpej
418 1.1 thorpej /* XXX iorange */
419 1.1 thorpej
420 1.1 thorpej if (SIMPLEQ_EMPTY(&res->ar_mem) == 0) {
421 1.1 thorpej struct acpi_mem *ar;
422 1.1 thorpej
423 1.1 thorpej sep = "";
424 1.23 jmcneill aprint_normal(" mem ");
425 1.3 lukem SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
426 1.23 jmcneill aprint_normal("%s0x%x", sep, ar->ar_base);
427 1.1 thorpej if (ar->ar_length > 1)
428 1.23 jmcneill aprint_normal("-0x%x", ar->ar_base +
429 1.1 thorpej ar->ar_length - 1);
430 1.1 thorpej sep = ",";
431 1.1 thorpej }
432 1.1 thorpej }
433 1.1 thorpej
434 1.1 thorpej /* XXX memrange */
435 1.1 thorpej
436 1.1 thorpej if (SIMPLEQ_EMPTY(&res->ar_irq) == 0) {
437 1.1 thorpej struct acpi_irq *ar;
438 1.1 thorpej
439 1.1 thorpej sep = "";
440 1.23 jmcneill aprint_normal(" irq ");
441 1.3 lukem SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
442 1.23 jmcneill aprint_normal("%s%d", sep, ar->ar_irq);
443 1.1 thorpej sep = ",";
444 1.1 thorpej }
445 1.1 thorpej }
446 1.1 thorpej
447 1.1 thorpej if (SIMPLEQ_EMPTY(&res->ar_drq) == 0) {
448 1.1 thorpej struct acpi_drq *ar;
449 1.1 thorpej
450 1.1 thorpej sep = "";
451 1.23 jmcneill aprint_normal(" drq ");
452 1.3 lukem SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
453 1.23 jmcneill aprint_normal("%s%d", sep, ar->ar_drq);
454 1.1 thorpej sep = ",";
455 1.1 thorpej }
456 1.1 thorpej }
457 1.1 thorpej
458 1.23 jmcneill aprint_normal("\n");
459 1.27 jmcneill aprint_naive("\n");
460 1.1 thorpej }
461 1.1 thorpej
462 1.14 kochi /*
463 1.14 kochi * acpi_resource_cleanup:
464 1.14 kochi *
465 1.14 kochi * Free all allocated buffers
466 1.14 kochi */
467 1.14 kochi void
468 1.14 kochi acpi_resource_cleanup(struct acpi_resources *res)
469 1.14 kochi {
470 1.14 kochi while (!SIMPLEQ_EMPTY(&res->ar_io)) {
471 1.14 kochi struct acpi_io *ar;
472 1.14 kochi ar = SIMPLEQ_FIRST(&res->ar_io);
473 1.14 kochi SIMPLEQ_REMOVE_HEAD(&res->ar_io, ar_list);
474 1.30 mlelstv ACPI_FREE(ar);
475 1.14 kochi }
476 1.14 kochi
477 1.14 kochi while (!SIMPLEQ_EMPTY(&res->ar_iorange)) {
478 1.14 kochi struct acpi_iorange *ar;
479 1.14 kochi ar = SIMPLEQ_FIRST(&res->ar_iorange);
480 1.14 kochi SIMPLEQ_REMOVE_HEAD(&res->ar_iorange, ar_list);
481 1.30 mlelstv ACPI_FREE(ar);
482 1.14 kochi }
483 1.14 kochi
484 1.14 kochi while (!SIMPLEQ_EMPTY(&res->ar_mem)) {
485 1.14 kochi struct acpi_mem *ar;
486 1.14 kochi ar = SIMPLEQ_FIRST(&res->ar_mem);
487 1.14 kochi SIMPLEQ_REMOVE_HEAD(&res->ar_mem, ar_list);
488 1.30 mlelstv ACPI_FREE(ar);
489 1.14 kochi }
490 1.14 kochi
491 1.14 kochi while (!SIMPLEQ_EMPTY(&res->ar_memrange)) {
492 1.14 kochi struct acpi_memrange *ar;
493 1.14 kochi ar = SIMPLEQ_FIRST(&res->ar_memrange);
494 1.14 kochi SIMPLEQ_REMOVE_HEAD(&res->ar_memrange, ar_list);
495 1.30 mlelstv ACPI_FREE(ar);
496 1.14 kochi }
497 1.14 kochi
498 1.14 kochi while (!SIMPLEQ_EMPTY(&res->ar_irq)) {
499 1.14 kochi struct acpi_irq *ar;
500 1.14 kochi ar = SIMPLEQ_FIRST(&res->ar_irq);
501 1.14 kochi SIMPLEQ_REMOVE_HEAD(&res->ar_irq, ar_list);
502 1.30 mlelstv ACPI_FREE(ar);
503 1.14 kochi }
504 1.14 kochi
505 1.14 kochi while (!SIMPLEQ_EMPTY(&res->ar_drq)) {
506 1.14 kochi struct acpi_drq *ar;
507 1.14 kochi ar = SIMPLEQ_FIRST(&res->ar_drq);
508 1.14 kochi SIMPLEQ_REMOVE_HEAD(&res->ar_drq, ar_list);
509 1.30 mlelstv ACPI_FREE(ar);
510 1.14 kochi }
511 1.14 kochi
512 1.16 perry res->ar_nio = res->ar_niorange = res->ar_nmem =
513 1.14 kochi res->ar_nmemrange = res->ar_nirq = res->ar_ndrq = 0;
514 1.14 kochi }
515 1.14 kochi
516 1.1 thorpej struct acpi_io *
517 1.1 thorpej acpi_res_io(struct acpi_resources *res, int idx)
518 1.1 thorpej {
519 1.1 thorpej struct acpi_io *ar;
520 1.1 thorpej
521 1.1 thorpej SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
522 1.1 thorpej if (ar->ar_index == idx)
523 1.11 kochi return ar;
524 1.1 thorpej }
525 1.11 kochi return NULL;
526 1.1 thorpej }
527 1.1 thorpej
528 1.1 thorpej struct acpi_iorange *
529 1.1 thorpej acpi_res_iorange(struct acpi_resources *res, int idx)
530 1.1 thorpej {
531 1.1 thorpej struct acpi_iorange *ar;
532 1.1 thorpej
533 1.1 thorpej SIMPLEQ_FOREACH(ar, &res->ar_iorange, ar_list) {
534 1.1 thorpej if (ar->ar_index == idx)
535 1.11 kochi return ar;
536 1.1 thorpej }
537 1.11 kochi return NULL;
538 1.1 thorpej }
539 1.1 thorpej
540 1.1 thorpej struct acpi_mem *
541 1.1 thorpej acpi_res_mem(struct acpi_resources *res, int idx)
542 1.1 thorpej {
543 1.1 thorpej struct acpi_mem *ar;
544 1.1 thorpej
545 1.1 thorpej SIMPLEQ_FOREACH(ar, &res->ar_mem, ar_list) {
546 1.1 thorpej if (ar->ar_index == idx)
547 1.11 kochi return ar;
548 1.1 thorpej }
549 1.11 kochi return NULL;
550 1.1 thorpej }
551 1.1 thorpej
552 1.1 thorpej struct acpi_memrange *
553 1.1 thorpej acpi_res_memrange(struct acpi_resources *res, int idx)
554 1.1 thorpej {
555 1.1 thorpej struct acpi_memrange *ar;
556 1.1 thorpej
557 1.1 thorpej SIMPLEQ_FOREACH(ar, &res->ar_memrange, ar_list) {
558 1.1 thorpej if (ar->ar_index == idx)
559 1.11 kochi return ar;
560 1.1 thorpej }
561 1.11 kochi return NULL;
562 1.1 thorpej }
563 1.1 thorpej
564 1.1 thorpej struct acpi_irq *
565 1.1 thorpej acpi_res_irq(struct acpi_resources *res, int idx)
566 1.1 thorpej {
567 1.1 thorpej struct acpi_irq *ar;
568 1.1 thorpej
569 1.1 thorpej SIMPLEQ_FOREACH(ar, &res->ar_irq, ar_list) {
570 1.1 thorpej if (ar->ar_index == idx)
571 1.11 kochi return ar;
572 1.1 thorpej }
573 1.11 kochi return NULL;
574 1.1 thorpej }
575 1.1 thorpej
576 1.1 thorpej struct acpi_drq *
577 1.1 thorpej acpi_res_drq(struct acpi_resources *res, int idx)
578 1.1 thorpej {
579 1.1 thorpej struct acpi_drq *ar;
580 1.1 thorpej
581 1.1 thorpej SIMPLEQ_FOREACH(ar, &res->ar_drq, ar_list) {
582 1.1 thorpej if (ar->ar_index == idx)
583 1.11 kochi return ar;
584 1.1 thorpej }
585 1.11 kochi return NULL;
586 1.1 thorpej }
587 1.1 thorpej
588 1.1 thorpej /*****************************************************************************
589 1.1 thorpej * Default ACPI resource parse operations.
590 1.1 thorpej *****************************************************************************/
591 1.1 thorpej
592 1.28 cegger static void acpi_res_parse_init(device_t, void *, void **);
593 1.28 cegger static void acpi_res_parse_fini(device_t, void *);
594 1.1 thorpej
595 1.28 cegger static void acpi_res_parse_ioport(device_t, void *, uint32_t,
596 1.1 thorpej uint32_t);
597 1.28 cegger static void acpi_res_parse_iorange(device_t, void *, uint32_t,
598 1.1 thorpej uint32_t, uint32_t, uint32_t);
599 1.1 thorpej
600 1.28 cegger static void acpi_res_parse_memory(device_t, void *, uint32_t,
601 1.1 thorpej uint32_t);
602 1.28 cegger static void acpi_res_parse_memrange(device_t, void *, uint32_t,
603 1.1 thorpej uint32_t, uint32_t, uint32_t);
604 1.1 thorpej
605 1.28 cegger static void acpi_res_parse_irq(device_t, void *, uint32_t, uint32_t);
606 1.28 cegger static void acpi_res_parse_drq(device_t, void *, uint32_t);
607 1.1 thorpej
608 1.28 cegger static void acpi_res_parse_start_dep(device_t, void *, int);
609 1.28 cegger static void acpi_res_parse_end_dep(device_t, void *);
610 1.1 thorpej
611 1.1 thorpej const struct acpi_resource_parse_ops acpi_resource_parse_ops_default = {
612 1.13 kochi .init = acpi_res_parse_init,
613 1.13 kochi .fini = acpi_res_parse_fini,
614 1.1 thorpej
615 1.13 kochi .ioport = acpi_res_parse_ioport,
616 1.13 kochi .iorange = acpi_res_parse_iorange,
617 1.1 thorpej
618 1.13 kochi .memory = acpi_res_parse_memory,
619 1.13 kochi .memrange = acpi_res_parse_memrange,
620 1.1 thorpej
621 1.13 kochi .irq = acpi_res_parse_irq,
622 1.13 kochi .drq = acpi_res_parse_drq,
623 1.1 thorpej
624 1.13 kochi .start_dep = acpi_res_parse_start_dep,
625 1.13 kochi .end_dep = acpi_res_parse_end_dep,
626 1.1 thorpej };
627 1.1 thorpej
628 1.34 jruoho const struct acpi_resource_parse_ops acpi_resource_parse_ops_quiet = {
629 1.34 jruoho .init = acpi_res_parse_init,
630 1.34 jruoho .fini = NULL,
631 1.34 jruoho
632 1.34 jruoho .ioport = acpi_res_parse_ioport,
633 1.34 jruoho .iorange = acpi_res_parse_iorange,
634 1.34 jruoho
635 1.34 jruoho .memory = acpi_res_parse_memory,
636 1.34 jruoho .memrange = acpi_res_parse_memrange,
637 1.34 jruoho
638 1.34 jruoho .irq = acpi_res_parse_irq,
639 1.34 jruoho .drq = acpi_res_parse_drq,
640 1.34 jruoho
641 1.34 jruoho .start_dep = acpi_res_parse_start_dep,
642 1.34 jruoho .end_dep = acpi_res_parse_end_dep,
643 1.34 jruoho };
644 1.34 jruoho
645 1.1 thorpej static void
646 1.28 cegger acpi_res_parse_init(device_t dev, void *arg, void **contextp)
647 1.1 thorpej {
648 1.1 thorpej struct acpi_resources *res = arg;
649 1.1 thorpej
650 1.1 thorpej SIMPLEQ_INIT(&res->ar_io);
651 1.1 thorpej res->ar_nio = 0;
652 1.1 thorpej
653 1.1 thorpej SIMPLEQ_INIT(&res->ar_iorange);
654 1.1 thorpej res->ar_niorange = 0;
655 1.1 thorpej
656 1.1 thorpej SIMPLEQ_INIT(&res->ar_mem);
657 1.1 thorpej res->ar_nmem = 0;
658 1.1 thorpej
659 1.1 thorpej SIMPLEQ_INIT(&res->ar_memrange);
660 1.1 thorpej res->ar_nmemrange = 0;
661 1.1 thorpej
662 1.1 thorpej SIMPLEQ_INIT(&res->ar_irq);
663 1.1 thorpej res->ar_nirq = 0;
664 1.1 thorpej
665 1.1 thorpej SIMPLEQ_INIT(&res->ar_drq);
666 1.1 thorpej res->ar_ndrq = 0;
667 1.1 thorpej
668 1.1 thorpej *contextp = res;
669 1.1 thorpej }
670 1.1 thorpej
671 1.1 thorpej static void
672 1.28 cegger acpi_res_parse_fini(device_t dev, void *context)
673 1.1 thorpej {
674 1.1 thorpej struct acpi_resources *res = context;
675 1.1 thorpej
676 1.1 thorpej /* Print the resources we're using. */
677 1.1 thorpej acpi_resource_print(dev, res);
678 1.1 thorpej }
679 1.1 thorpej
680 1.1 thorpej static void
681 1.28 cegger acpi_res_parse_ioport(device_t dev, void *context, uint32_t base,
682 1.1 thorpej uint32_t length)
683 1.1 thorpej {
684 1.1 thorpej struct acpi_resources *res = context;
685 1.1 thorpej struct acpi_io *ar;
686 1.7 jdolecek
687 1.7 jdolecek /*
688 1.7 jdolecek * Check if there is another I/O port directly below/under
689 1.7 jdolecek * this one.
690 1.7 jdolecek */
691 1.7 jdolecek SIMPLEQ_FOREACH(ar, &res->ar_io, ar_list) {
692 1.7 jdolecek if (ar->ar_base == base + length ) {
693 1.7 jdolecek /*
694 1.7 jdolecek * Entry just below existing entry - adjust
695 1.7 jdolecek * the entry and return.
696 1.7 jdolecek */
697 1.7 jdolecek ar->ar_base = base;
698 1.7 jdolecek ar->ar_length += length;
699 1.7 jdolecek return;
700 1.7 jdolecek } else if (ar->ar_base + ar->ar_length == base) {
701 1.7 jdolecek /*
702 1.7 jdolecek * Entry just above existing entry - adjust
703 1.7 jdolecek * the entry and return.
704 1.7 jdolecek */
705 1.7 jdolecek ar->ar_length += length;
706 1.7 jdolecek return;
707 1.7 jdolecek }
708 1.7 jdolecek }
709 1.1 thorpej
710 1.30 mlelstv ar = ACPI_ALLOCATE(sizeof(*ar));
711 1.1 thorpej if (ar == NULL) {
712 1.23 jmcneill aprint_error_dev(dev, "ACPI: unable to allocate I/O resource %d\n",
713 1.23 jmcneill res->ar_nio);
714 1.1 thorpej res->ar_nio++;
715 1.1 thorpej return;
716 1.1 thorpej }
717 1.1 thorpej
718 1.1 thorpej ar->ar_index = res->ar_nio++;
719 1.1 thorpej ar->ar_base = base;
720 1.1 thorpej ar->ar_length = length;
721 1.1 thorpej
722 1.1 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_io, ar, ar_list);
723 1.1 thorpej }
724 1.1 thorpej
725 1.1 thorpej static void
726 1.28 cegger acpi_res_parse_iorange(device_t dev, void *context, uint32_t low,
727 1.1 thorpej uint32_t high, uint32_t length, uint32_t align)
728 1.1 thorpej {
729 1.1 thorpej struct acpi_resources *res = context;
730 1.1 thorpej struct acpi_iorange *ar;
731 1.1 thorpej
732 1.30 mlelstv ar = ACPI_ALLOCATE(sizeof(*ar));
733 1.1 thorpej if (ar == NULL) {
734 1.23 jmcneill aprint_error_dev(dev, "ACPI: unable to allocate I/O range resource %d\n",
735 1.23 jmcneill res->ar_niorange);
736 1.1 thorpej res->ar_niorange++;
737 1.1 thorpej return;
738 1.1 thorpej }
739 1.1 thorpej
740 1.1 thorpej ar->ar_index = res->ar_niorange++;
741 1.1 thorpej ar->ar_low = low;
742 1.1 thorpej ar->ar_high = high;
743 1.1 thorpej ar->ar_length = length;
744 1.1 thorpej ar->ar_align = align;
745 1.1 thorpej
746 1.1 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_iorange, ar, ar_list);
747 1.1 thorpej }
748 1.1 thorpej
749 1.1 thorpej static void
750 1.28 cegger acpi_res_parse_memory(device_t dev, void *context, uint32_t base,
751 1.1 thorpej uint32_t length)
752 1.1 thorpej {
753 1.1 thorpej struct acpi_resources *res = context;
754 1.1 thorpej struct acpi_mem *ar;
755 1.1 thorpej
756 1.30 mlelstv ar = ACPI_ALLOCATE(sizeof(*ar));
757 1.1 thorpej if (ar == NULL) {
758 1.23 jmcneill aprint_error_dev(dev, "ACPI: unable to allocate Memory resource %d\n",
759 1.23 jmcneill res->ar_nmem);
760 1.1 thorpej res->ar_nmem++;
761 1.1 thorpej return;
762 1.1 thorpej }
763 1.1 thorpej
764 1.1 thorpej ar->ar_index = res->ar_nmem++;
765 1.1 thorpej ar->ar_base = base;
766 1.1 thorpej ar->ar_length = length;
767 1.1 thorpej
768 1.1 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_mem, ar, ar_list);
769 1.1 thorpej }
770 1.1 thorpej
771 1.1 thorpej static void
772 1.28 cegger acpi_res_parse_memrange(device_t dev, void *context, uint32_t low,
773 1.1 thorpej uint32_t high, uint32_t length, uint32_t align)
774 1.1 thorpej {
775 1.1 thorpej struct acpi_resources *res = context;
776 1.1 thorpej struct acpi_memrange *ar;
777 1.1 thorpej
778 1.30 mlelstv ar = ACPI_ALLOCATE(sizeof(*ar));
779 1.1 thorpej if (ar == NULL) {
780 1.23 jmcneill aprint_error_dev(dev, "ACPI: unable to allocate Memory range resource %d\n",
781 1.23 jmcneill res->ar_nmemrange);
782 1.1 thorpej res->ar_nmemrange++;
783 1.1 thorpej return;
784 1.1 thorpej }
785 1.1 thorpej
786 1.1 thorpej ar->ar_index = res->ar_nmemrange++;
787 1.1 thorpej ar->ar_low = low;
788 1.1 thorpej ar->ar_high = high;
789 1.1 thorpej ar->ar_length = length;
790 1.1 thorpej ar->ar_align = align;
791 1.1 thorpej
792 1.1 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_memrange, ar, ar_list);
793 1.1 thorpej }
794 1.1 thorpej
795 1.1 thorpej static void
796 1.28 cegger acpi_res_parse_irq(device_t dev, void *context, uint32_t irq, uint32_t type)
797 1.1 thorpej {
798 1.1 thorpej struct acpi_resources *res = context;
799 1.1 thorpej struct acpi_irq *ar;
800 1.1 thorpej
801 1.30 mlelstv ar = ACPI_ALLOCATE(sizeof(*ar));
802 1.1 thorpej if (ar == NULL) {
803 1.23 jmcneill aprint_error_dev(dev, "ACPI: unable to allocate IRQ resource %d\n",
804 1.23 jmcneill res->ar_nirq);
805 1.1 thorpej res->ar_nirq++;
806 1.1 thorpej return;
807 1.1 thorpej }
808 1.1 thorpej
809 1.1 thorpej ar->ar_index = res->ar_nirq++;
810 1.1 thorpej ar->ar_irq = irq;
811 1.5 matt ar->ar_type = type;
812 1.1 thorpej
813 1.1 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_irq, ar, ar_list);
814 1.1 thorpej }
815 1.1 thorpej
816 1.1 thorpej static void
817 1.28 cegger acpi_res_parse_drq(device_t dev, void *context, uint32_t drq)
818 1.1 thorpej {
819 1.1 thorpej struct acpi_resources *res = context;
820 1.1 thorpej struct acpi_drq *ar;
821 1.1 thorpej
822 1.30 mlelstv ar = ACPI_ALLOCATE(sizeof(*ar));
823 1.1 thorpej if (ar == NULL) {
824 1.23 jmcneill aprint_error_dev(dev, "ACPI: unable to allocate DRQ resource %d\n",
825 1.23 jmcneill res->ar_ndrq);
826 1.1 thorpej res->ar_ndrq++;
827 1.1 thorpej return;
828 1.1 thorpej }
829 1.1 thorpej
830 1.1 thorpej ar->ar_index = res->ar_ndrq++;
831 1.1 thorpej ar->ar_drq = drq;
832 1.1 thorpej
833 1.1 thorpej SIMPLEQ_INSERT_TAIL(&res->ar_drq, ar, ar_list);
834 1.1 thorpej }
835 1.1 thorpej
836 1.1 thorpej static void
837 1.28 cegger acpi_res_parse_start_dep(device_t dev, void *context,
838 1.21 christos int preference)
839 1.1 thorpej {
840 1.10 kochi
841 1.35 wiz aprint_error_dev(dev, "ACPI: dependent functions not supported\n");
842 1.1 thorpej }
843 1.1 thorpej
844 1.1 thorpej static void
845 1.28 cegger acpi_res_parse_end_dep(device_t dev, void *context)
846 1.1 thorpej {
847 1.1 thorpej
848 1.1 thorpej /* Nothing to do. */
849 1.1 thorpej }
850