2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/acpica/acpi_resource.c,v 1.40.8.1 2009/04/15 03:14:26 kensmith Exp $
31 #include <sys/param.h>
32 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/module.h>
36 #include <sys/resource.h>
37 #include <sys/machintr.h>
42 #include <dev/acpica5/acpivar.h>
44 /* Hooks for the ACPI CA debugging infrastructure */
45 #define _COMPONENT ACPI_BUS
46 ACPI_MODULE_NAME("RESOURCE")
48 struct lookup_irq_request {
49 ACPI_RESOURCE *acpi_res;
57 acpi_lookup_irq_handler(ACPI_RESOURCE *res, void *context)
59 struct lookup_irq_request *req;
64 case ACPI_RESOURCE_TYPE_IRQ:
65 irqnum = res->Data.Irq.InterruptCount;
66 irq = res->Data.Irq.Interrupts[0];
67 len = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
69 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
70 irqnum = res->Data.ExtendedIrq.InterruptCount;
71 irq = res->Data.ExtendedIrq.Interrupts[0];
72 len = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
79 req = (struct lookup_irq_request *)context;
80 if (req->counter != req->rid) {
85 KASSERT(irq == rman_get_start(req->res),
86 ("IRQ resources do not match"));
87 bcopy(res, req->acpi_res, len);
88 return (AE_CTRL_TERMINATE);
92 acpi_lookup_irq_resource(device_t dev, int rid, struct resource *res,
93 ACPI_RESOURCE *acpi_res)
95 struct lookup_irq_request req;
98 req.acpi_res = acpi_res;
103 status = AcpiWalkResources(acpi_get_handle(dev), "_CRS",
104 acpi_lookup_irq_handler, &req);
105 if (ACPI_SUCCESS(status) && req.found == 0)
106 status = AE_NOT_FOUND;
111 acpi_config_intr(device_t dev, ACPI_RESOURCE *res)
115 enum intr_trigger trigger;
116 enum intr_polarity polarity;
119 case ACPI_RESOURCE_TYPE_IRQ:
120 KASSERT(res->Data.Irq.InterruptCount == 1,
121 ("%s: multiple interrupts", __func__));
122 irq = res->Data.Irq.Interrupts[0];
123 trig = res->Data.Irq.Triggering;
124 pol = res->Data.Irq.Polarity;
126 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
127 KASSERT(res->Data.ExtendedIrq.InterruptCount == 1,
128 ("%s: multiple interrupts", __func__));
129 irq = res->Data.ExtendedIrq.Interrupts[0];
130 trig = res->Data.ExtendedIrq.Triggering;
131 pol = res->Data.ExtendedIrq.Polarity;
134 panic("%s: bad resource type %u", __func__, res->Type);
137 if (trig == ACPI_EDGE_SENSITIVE)
138 trigger = INTR_TRIGGER_EDGE;
140 trigger = INTR_TRIGGER_LEVEL;
142 if (pol == ACPI_ACTIVE_HIGH)
143 polarity = INTR_POLARITY_HIGH;
145 polarity = INTR_POLARITY_LOW;
149 * This causes interrupt storm on certain systems, on which
150 * certain IRQs are configured into different mode but the
151 * configured IRQs are actually never used.
153 if (machintr_legacy_intr_find(irq, trigger, polarity) < 0)
155 if (irq == acpi_sci_irqno())
159 kprintf("acpi_config_intr: Skip irq %d config\n", irq);
161 BUS_CONFIG_INTR(dev, dev, irq, trigger, polarity);
166 * Fetch a device's resources and associate them with the device.
168 * Note that it might be nice to also locate ACPI-specific resource items, such
171 * We really need to split the resource-fetching code out from the
172 * resource-parsing code, since we may want to use the parsing
173 * code for _PRS someday.
176 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
177 struct acpi_parse_resource_set *set, void *arg)
185 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
188 * Special-case some devices that abuse _PRS/_CRS to mean
189 * something other than "I consume this resource".
191 * XXX do we really need this? It's only relevant once
192 * we start always-allocating these resources, and even
193 * then, the only special-cased device is likely to be
194 * the PCI interrupt link.
197 /* Fetch the device's current resources. */
198 buf.Length = ACPI_ALLOCATE_BUFFER;
199 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
200 if (status != AE_NOT_FOUND && status != AE_TYPE)
201 kprintf("can't fetch resources for %s - %s\n",
202 acpi_name(handle), AcpiFormatException(status));
203 return_ACPI_STATUS (status);
205 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
206 acpi_name(handle), (long)buf.Length));
207 set->set_init(dev, arg, &context);
209 /* Iterate through the resources */
211 last = (char *)buf.Pointer + buf.Length;
212 while (curr < last) {
213 res = (ACPI_RESOURCE *)curr;
216 /* Handle the individual resource types */
218 case ACPI_RESOURCE_TYPE_END_TAG:
219 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
222 case ACPI_RESOURCE_TYPE_FIXED_IO:
223 if (res->Data.FixedIo.AddressLength <= 0)
225 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
226 res->Data.FixedIo.Address,
227 res->Data.FixedIo.AddressLength));
228 set->set_ioport(dev, context,
229 res->Data.FixedIo.Address,
230 res->Data.FixedIo.AddressLength);
232 case ACPI_RESOURCE_TYPE_IO:
233 if (res->Data.Io.AddressLength <= 0)
235 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
236 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
237 res->Data.Io.Minimum,
238 res->Data.Io.AddressLength));
239 set->set_ioport(dev, context,
240 res->Data.Io.Minimum,
241 res->Data.Io.AddressLength);
243 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
244 res->Data.Io.Minimum,
245 res->Data.Io.Maximum,
246 res->Data.Io.AddressLength));
247 set->set_iorange(dev, context,
248 res->Data.Io.Minimum,
249 res->Data.Io.Maximum,
250 res->Data.Io.AddressLength,
251 res->Data.Io.Alignment);
254 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
255 if (res->Data.FixedMemory32.AddressLength <= 0)
257 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
258 res->Data.FixedMemory32.Address,
259 res->Data.FixedMemory32.AddressLength));
260 set->set_memory(dev, context,
261 res->Data.FixedMemory32.Address,
262 res->Data.FixedMemory32.AddressLength);
264 case ACPI_RESOURCE_TYPE_MEMORY32:
265 if (res->Data.Memory32.AddressLength <= 0)
267 if (res->Data.Memory32.Minimum ==
268 res->Data.Memory32.Maximum) {
270 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
271 res->Data.Memory32.Minimum,
272 res->Data.Memory32.AddressLength));
273 set->set_memory(dev, context,
274 res->Data.Memory32.Minimum,
275 res->Data.Memory32.AddressLength);
277 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
278 res->Data.Memory32.Minimum,
279 res->Data.Memory32.Maximum,
280 res->Data.Memory32.AddressLength));
281 set->set_memoryrange(dev, context,
282 res->Data.Memory32.Minimum,
283 res->Data.Memory32.Maximum,
284 res->Data.Memory32.AddressLength,
285 res->Data.Memory32.Alignment);
288 case ACPI_RESOURCE_TYPE_MEMORY24:
289 if (res->Data.Memory24.AddressLength <= 0)
291 if (res->Data.Memory24.Minimum ==
292 res->Data.Memory24.Maximum) {
294 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
295 res->Data.Memory24.Minimum,
296 res->Data.Memory24.AddressLength));
297 set->set_memory(dev, context, res->Data.Memory24.Minimum,
298 res->Data.Memory24.AddressLength);
300 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
301 res->Data.Memory24.Minimum,
302 res->Data.Memory24.Maximum,
303 res->Data.Memory24.AddressLength));
304 set->set_memoryrange(dev, context,
305 res->Data.Memory24.Minimum,
306 res->Data.Memory24.Maximum,
307 res->Data.Memory24.AddressLength,
308 res->Data.Memory24.Alignment);
311 case ACPI_RESOURCE_TYPE_IRQ:
314 * "This structure is repeated for each separate interrupt
317 set->set_irq(dev, context, res->Data.Irq.Interrupts,
318 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
319 res->Data.Irq.Polarity);
321 case ACPI_RESOURCE_TYPE_DMA:
324 * "This structure is repeated for each separate dma channel
327 set->set_drq(dev, context, res->Data.Dma.Channels,
328 res->Data.Dma.ChannelCount);
330 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
331 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
332 set->set_start_dependent(dev, context,
333 res->Data.StartDpf.CompatibilityPriority);
335 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
336 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
337 set->set_end_dependent(dev, context);
339 case ACPI_RESOURCE_TYPE_ADDRESS32:
340 if (res->Data.Address32.AddressLength <= 0)
342 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
343 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
344 "ignored Address32 %s producer\n",
345 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
349 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
350 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
351 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
352 "ignored Address32 for non-memory, non-I/O\n"));
356 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
357 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
359 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
360 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
361 "Address32/Memory 0x%x/%d\n",
362 res->Data.Address32.Minimum,
363 res->Data.Address32.AddressLength));
364 set->set_memory(dev, context,
365 res->Data.Address32.Minimum,
366 res->Data.Address32.AddressLength);
368 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
369 "Address32/IO 0x%x/%d\n",
370 res->Data.Address32.Minimum,
371 res->Data.Address32.AddressLength));
372 set->set_ioport(dev, context,
373 res->Data.Address32.Minimum,
374 res->Data.Address32.AddressLength);
377 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
378 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
379 "Address32/Memory 0x%x-0x%x/%d\n",
380 res->Data.Address32.Minimum,
381 res->Data.Address32.Maximum,
382 res->Data.Address32.AddressLength));
383 set->set_memoryrange(dev, context,
384 res->Data.Address32.Minimum,
385 res->Data.Address32.Maximum,
386 res->Data.Address32.AddressLength,
387 res->Data.Address32.Granularity);
389 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
390 "Address32/IO 0x%x-0x%x/%d\n",
391 res->Data.Address32.Minimum,
392 res->Data.Address32.Maximum,
393 res->Data.Address32.AddressLength));
394 set->set_iorange(dev, context,
395 res->Data.Address32.Minimum,
396 res->Data.Address32.Maximum,
397 res->Data.Address32.AddressLength,
398 res->Data.Address32.Granularity);
402 case ACPI_RESOURCE_TYPE_ADDRESS16:
403 if (res->Data.Address16.AddressLength <= 0)
405 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
406 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
407 "ignored Address16 %s producer\n",
408 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
412 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
413 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
414 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
415 "ignored Address16 for non-memory, non-I/O\n"));
419 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
420 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
422 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
423 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
424 "Address16/Memory 0x%x/%d\n",
425 res->Data.Address16.Minimum,
426 res->Data.Address16.AddressLength));
427 set->set_memory(dev, context,
428 res->Data.Address16.Minimum,
429 res->Data.Address16.AddressLength);
431 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
432 "Address16/IO 0x%x/%d\n",
433 res->Data.Address16.Minimum,
434 res->Data.Address16.AddressLength));
435 set->set_ioport(dev, context,
436 res->Data.Address16.Minimum,
437 res->Data.Address16.AddressLength);
440 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
441 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
442 "Address16/Memory 0x%x-0x%x/%d\n",
443 res->Data.Address16.Minimum,
444 res->Data.Address16.Maximum,
445 res->Data.Address16.AddressLength));
446 set->set_memoryrange(dev, context,
447 res->Data.Address16.Minimum,
448 res->Data.Address16.Maximum,
449 res->Data.Address16.AddressLength,
450 res->Data.Address16.Granularity);
452 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
453 "Address16/IO 0x%x-0x%x/%d\n",
454 res->Data.Address16.Minimum,
455 res->Data.Address16.Maximum,
456 res->Data.Address16.AddressLength));
457 set->set_iorange(dev, context,
458 res->Data.Address16.Minimum,
459 res->Data.Address16.Maximum,
460 res->Data.Address16.AddressLength,
461 res->Data.Address16.Granularity);
465 case ACPI_RESOURCE_TYPE_ADDRESS64:
466 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
467 "unimplemented Address64 resource\n"));
469 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
470 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
471 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
472 "ignored ExtIRQ producer\n"));
475 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
476 res->Data.ExtendedIrq.InterruptCount,
477 res->Data.ExtendedIrq.Triggering,
478 res->Data.ExtendedIrq.Polarity);
480 case ACPI_RESOURCE_TYPE_VENDOR:
481 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
482 "unimplemented VendorSpecific resource\n"));
489 AcpiOsFree(buf.Pointer);
490 set->set_done(dev, context);
491 return_ACPI_STATUS (AE_OK);
495 * Resource-set vectors used to attach _CRS-derived resources
498 static void acpi_res_set_init(device_t dev, void *arg, void **context);
499 static void acpi_res_set_done(device_t dev, void *context);
500 static void acpi_res_set_ioport(device_t dev, void *context,
501 u_int32_t base, u_int32_t length);
502 static void acpi_res_set_iorange(device_t dev, void *context,
503 u_int32_t low, u_int32_t high,
504 u_int32_t length, u_int32_t align);
505 static void acpi_res_set_memory(device_t dev, void *context,
506 u_int32_t base, u_int32_t length);
507 static void acpi_res_set_memoryrange(device_t dev, void *context,
508 u_int32_t low, u_int32_t high,
509 u_int32_t length, u_int32_t align);
510 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
511 int count, int trig, int pol);
512 static void acpi_res_set_ext_irq(device_t dev, void *context,
513 u_int32_t *irq, int count, int trig, int pol);
514 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
516 static void acpi_res_set_start_dependent(device_t dev, void *context,
518 static void acpi_res_set_end_dependent(device_t dev, void *context);
520 struct acpi_parse_resource_set acpi_res_parse_set = {
524 acpi_res_set_iorange,
526 acpi_res_set_memoryrange,
528 acpi_res_set_ext_irq,
530 acpi_res_set_start_dependent,
531 acpi_res_set_end_dependent
534 struct acpi_res_context {
543 acpi_res_set_init(device_t dev, void *arg, void **context)
545 struct acpi_res_context *cp;
547 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
548 bzero(cp, sizeof(*cp));
555 acpi_res_set_done(device_t dev, void *context)
557 struct acpi_res_context *cp = (struct acpi_res_context *)context;
565 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
568 struct acpi_res_context *cp = (struct acpi_res_context *)context;
572 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length, -1);
576 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
577 u_int32_t high, u_int32_t length, u_int32_t align)
579 struct acpi_res_context *cp = (struct acpi_res_context *)context;
583 device_printf(dev, "I/O range not supported\n");
587 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
590 struct acpi_res_context *cp = (struct acpi_res_context *)context;
595 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length, -1);
599 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
600 u_int32_t high, u_int32_t length, u_int32_t align)
602 struct acpi_res_context *cp = (struct acpi_res_context *)context;
606 device_printf(dev, "memory range not supported\n");
610 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
613 struct acpi_res_context *cp = (struct acpi_res_context *)context;
615 if (cp == NULL || irq == NULL)
618 /* This implements no resource relocation. */
622 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
623 machintr_legacy_intr_cpuid(*irq));
627 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
630 struct acpi_res_context *cp = (struct acpi_res_context *)context;
632 if (cp == NULL || irq == NULL)
635 /* This implements no resource relocation. */
639 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
640 machintr_legacy_intr_cpuid(*irq));
644 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
646 struct acpi_res_context *cp = (struct acpi_res_context *)context;
648 if (cp == NULL || drq == NULL)
651 /* This implements no resource relocation. */
655 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1, -1);
659 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
661 struct acpi_res_context *cp = (struct acpi_res_context *)context;
665 device_printf(dev, "dependent functions not supported\n");
669 acpi_res_set_end_dependent(device_t dev, void *context)
671 struct acpi_res_context *cp = (struct acpi_res_context *)context;
675 device_printf(dev, "dependent functions not supported\n");
679 * Resource-owning placeholders for IO and memory pseudo-devices.
681 * This code allocates system resources that will be used by ACPI
682 * child devices. The acpi parent manages these resources through a
686 static int acpi_sysres_rid = 100;
688 static int acpi_sysres_probe(device_t dev);
689 static int acpi_sysres_attach(device_t dev);
691 static device_method_t acpi_sysres_methods[] = {
692 /* Device interface */
693 DEVMETHOD(device_probe, acpi_sysres_probe),
694 DEVMETHOD(device_attach, acpi_sysres_attach),
699 static driver_t acpi_sysres_driver = {
705 static devclass_t acpi_sysres_devclass;
706 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
708 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
711 acpi_sysres_probe(device_t dev)
713 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
715 if (acpi_disabled("sysresource") ||
716 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
719 device_set_desc(dev, "System Resource");
721 return (BUS_PROBE_DEFAULT);
725 acpi_sysres_attach(device_t dev)
728 struct resource_list_entry *bus_rle, *dev_rle;
729 struct resource_list *bus_rl, *dev_rl;
731 u_long start, end, count;
733 * Loop through all current resources to see if the new one overlaps
734 * any existing ones. If so, grow the old one up and/or down
735 * accordingly. Discard any that are wholly contained in the old. If
736 * the resource is unique, add it to the parent. It will later go into
739 bus = device_get_parent(dev);
740 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
741 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
743 kprintf("busrl is not null!\n");
744 SLIST_FOREACH(dev_rle, dev_rl, link) {
745 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
748 start = dev_rle->start;
750 count = dev_rle->count;
751 type = dev_rle->type;
754 SLIST_FOREACH(bus_rle, bus_rl, link) {
755 if (bus_rle->type != type)
758 /* New resource wholly contained in old, discard. */
759 if (start >= bus_rle->start && end <= bus_rle->end)
762 /* New tail overlaps old head, grow existing resource downward. */
763 if (start < bus_rle->start && end >= bus_rle->start) {
764 bus_rle->count += bus_rle->start - start;
765 bus_rle->start = start;
769 /* New head overlaps old tail, grow existing resource upward. */
770 if (start <= bus_rle->end && end > bus_rle->end) {
771 bus_rle->count += end - bus_rle->end;
776 /* If we adjusted the old resource, we're finished. */
780 } else bus_rle = NULL;
781 /* If we didn't merge with anything, add this resource. */
782 if (bus_rle == NULL) {
783 bus_set_resource(bus, type, acpi_sysres_rid++, start, count, -1);
787 /* After merging/moving resources to the parent, free the list. */
788 resource_list_free(dev_rl);