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/acpica/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;
65 case ACPI_RESOURCE_TYPE_IRQ:
66 irqnum = res->Data.Irq.InterruptCount;
67 irq = res->Data.Irq.Interrupts[0];
68 len = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
70 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
71 irqnum = res->Data.ExtendedIrq.InterruptCount;
72 irq = res->Data.ExtendedIrq.Interrupts[0];
73 len = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
80 req = (struct lookup_irq_request *)context;
81 if (req->counter != req->rid) {
86 KASSERT(irq == rman_get_start(req->res),
87 ("IRQ resources do not match"));
88 bcopy(res, req->acpi_res, len);
89 return (AE_CTRL_TERMINATE);
93 acpi_lookup_irq_resource(device_t dev, int rid, struct resource *res,
94 ACPI_RESOURCE *acpi_res)
96 struct lookup_irq_request req;
99 req.acpi_res = acpi_res;
104 status = AcpiWalkResources(acpi_get_handle(dev), "_CRS",
105 acpi_lookup_irq_handler, &req);
106 if (ACPI_SUCCESS(status) && req.found == 0)
107 status = AE_NOT_FOUND;
112 acpi_config_intr(device_t dev, ACPI_RESOURCE *res)
116 enum intr_trigger trigger;
117 enum intr_polarity polarity;
120 case ACPI_RESOURCE_TYPE_IRQ:
121 KASSERT(res->Data.Irq.InterruptCount == 1,
122 ("%s: multiple interrupts", __func__));
123 irq = res->Data.Irq.Interrupts[0];
124 trig = res->Data.Irq.Triggering;
125 pol = res->Data.Irq.Polarity;
127 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
128 KASSERT(res->Data.ExtendedIrq.InterruptCount == 1,
129 ("%s: multiple interrupts", __func__));
130 irq = res->Data.ExtendedIrq.Interrupts[0];
131 trig = res->Data.ExtendedIrq.Triggering;
132 pol = res->Data.ExtendedIrq.Polarity;
135 panic("%s: bad resource type %u", __func__, res->Type);
138 if (trig == ACPI_EDGE_SENSITIVE)
139 trigger = INTR_TRIGGER_EDGE;
141 trigger = INTR_TRIGGER_LEVEL;
143 if (pol == ACPI_ACTIVE_HIGH)
144 polarity = INTR_POLARITY_HIGH;
146 polarity = INTR_POLARITY_LOW;
148 if (machintr_legacy_intr_find(irq, trigger, polarity) < 0)
149 kprintf("acpi_config_intr: Skip irq %d config\n", irq);
151 BUS_CONFIG_INTR(dev, dev, irq, trigger, polarity);
155 * Fetch a device's resources and associate them with the device.
157 * Note that it might be nice to also locate ACPI-specific resource items, such
160 * We really need to split the resource-fetching code out from the
161 * resource-parsing code, since we may want to use the parsing
162 * code for _PRS someday.
165 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
166 struct acpi_parse_resource_set *set, void *arg)
174 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
177 * Special-case some devices that abuse _PRS/_CRS to mean
178 * something other than "I consume this resource".
180 * XXX do we really need this? It's only relevant once
181 * we start always-allocating these resources, and even
182 * then, the only special-cased device is likely to be
183 * the PCI interrupt link.
186 /* Fetch the device's current resources. */
187 buf.Length = ACPI_ALLOCATE_BUFFER;
188 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
189 if (status != AE_NOT_FOUND && status != AE_TYPE)
190 kprintf("can't fetch resources for %s - %s\n",
191 acpi_name(handle), AcpiFormatException(status));
192 return_ACPI_STATUS (status);
194 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
195 acpi_name(handle), (long)buf.Length));
196 set->set_init(dev, arg, &context);
198 /* Iterate through the resources */
200 last = (char *)buf.Pointer + buf.Length;
201 while (curr < last) {
202 res = (ACPI_RESOURCE *)curr;
205 /* Handle the individual resource types */
207 case ACPI_RESOURCE_TYPE_END_TAG:
208 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
211 case ACPI_RESOURCE_TYPE_FIXED_IO:
212 if (res->Data.FixedIo.AddressLength <= 0)
214 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
215 res->Data.FixedIo.Address,
216 res->Data.FixedIo.AddressLength));
217 set->set_ioport(dev, context,
218 res->Data.FixedIo.Address,
219 res->Data.FixedIo.AddressLength);
221 case ACPI_RESOURCE_TYPE_IO:
222 if (res->Data.Io.AddressLength <= 0)
224 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
225 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
226 res->Data.Io.Minimum,
227 res->Data.Io.AddressLength));
228 set->set_ioport(dev, context,
229 res->Data.Io.Minimum,
230 res->Data.Io.AddressLength);
232 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
233 res->Data.Io.Minimum,
234 res->Data.Io.Maximum,
235 res->Data.Io.AddressLength));
236 set->set_iorange(dev, context,
237 res->Data.Io.Minimum,
238 res->Data.Io.Maximum,
239 res->Data.Io.AddressLength,
240 res->Data.Io.Alignment);
243 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
244 if (res->Data.FixedMemory32.AddressLength <= 0)
246 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
247 res->Data.FixedMemory32.Address,
248 res->Data.FixedMemory32.AddressLength));
249 set->set_memory(dev, context,
250 res->Data.FixedMemory32.Address,
251 res->Data.FixedMemory32.AddressLength);
253 case ACPI_RESOURCE_TYPE_MEMORY32:
254 if (res->Data.Memory32.AddressLength <= 0)
256 if (res->Data.Memory32.Minimum ==
257 res->Data.Memory32.Maximum) {
259 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
260 res->Data.Memory32.Minimum,
261 res->Data.Memory32.AddressLength));
262 set->set_memory(dev, context,
263 res->Data.Memory32.Minimum,
264 res->Data.Memory32.AddressLength);
266 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
267 res->Data.Memory32.Minimum,
268 res->Data.Memory32.Maximum,
269 res->Data.Memory32.AddressLength));
270 set->set_memoryrange(dev, context,
271 res->Data.Memory32.Minimum,
272 res->Data.Memory32.Maximum,
273 res->Data.Memory32.AddressLength,
274 res->Data.Memory32.Alignment);
277 case ACPI_RESOURCE_TYPE_MEMORY24:
278 if (res->Data.Memory24.AddressLength <= 0)
280 if (res->Data.Memory24.Minimum ==
281 res->Data.Memory24.Maximum) {
283 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
284 res->Data.Memory24.Minimum,
285 res->Data.Memory24.AddressLength));
286 set->set_memory(dev, context, res->Data.Memory24.Minimum,
287 res->Data.Memory24.AddressLength);
289 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
290 res->Data.Memory24.Minimum,
291 res->Data.Memory24.Maximum,
292 res->Data.Memory24.AddressLength));
293 set->set_memoryrange(dev, context,
294 res->Data.Memory24.Minimum,
295 res->Data.Memory24.Maximum,
296 res->Data.Memory24.AddressLength,
297 res->Data.Memory24.Alignment);
300 case ACPI_RESOURCE_TYPE_IRQ:
303 * "This structure is repeated for each separate interrupt
306 set->set_irq(dev, context, res->Data.Irq.Interrupts,
307 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
308 res->Data.Irq.Polarity);
310 case ACPI_RESOURCE_TYPE_DMA:
313 * "This structure is repeated for each separate dma channel
316 set->set_drq(dev, context, res->Data.Dma.Channels,
317 res->Data.Dma.ChannelCount);
319 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
320 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
321 set->set_start_dependent(dev, context,
322 res->Data.StartDpf.CompatibilityPriority);
324 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
325 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
326 set->set_end_dependent(dev, context);
328 case ACPI_RESOURCE_TYPE_ADDRESS32:
329 if (res->Data.Address32.AddressLength <= 0)
331 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
332 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
333 "ignored Address32 %s producer\n",
334 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
338 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
339 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
340 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
341 "ignored Address32 for non-memory, non-I/O\n"));
345 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
346 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
348 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
349 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
350 "Address32/Memory 0x%x/%d\n",
351 res->Data.Address32.Minimum,
352 res->Data.Address32.AddressLength));
353 set->set_memory(dev, context,
354 res->Data.Address32.Minimum,
355 res->Data.Address32.AddressLength);
357 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
358 "Address32/IO 0x%x/%d\n",
359 res->Data.Address32.Minimum,
360 res->Data.Address32.AddressLength));
361 set->set_ioport(dev, context,
362 res->Data.Address32.Minimum,
363 res->Data.Address32.AddressLength);
366 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
367 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
368 "Address32/Memory 0x%x-0x%x/%d\n",
369 res->Data.Address32.Minimum,
370 res->Data.Address32.Maximum,
371 res->Data.Address32.AddressLength));
372 set->set_memoryrange(dev, context,
373 res->Data.Address32.Minimum,
374 res->Data.Address32.Maximum,
375 res->Data.Address32.AddressLength,
376 res->Data.Address32.Granularity);
378 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
379 "Address32/IO 0x%x-0x%x/%d\n",
380 res->Data.Address32.Minimum,
381 res->Data.Address32.Maximum,
382 res->Data.Address32.AddressLength));
383 set->set_iorange(dev, context,
384 res->Data.Address32.Minimum,
385 res->Data.Address32.Maximum,
386 res->Data.Address32.AddressLength,
387 res->Data.Address32.Granularity);
391 case ACPI_RESOURCE_TYPE_ADDRESS16:
392 if (res->Data.Address16.AddressLength <= 0)
394 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
395 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
396 "ignored Address16 %s producer\n",
397 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
401 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
402 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
403 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
404 "ignored Address16 for non-memory, non-I/O\n"));
408 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
409 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
411 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
412 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
413 "Address16/Memory 0x%x/%d\n",
414 res->Data.Address16.Minimum,
415 res->Data.Address16.AddressLength));
416 set->set_memory(dev, context,
417 res->Data.Address16.Minimum,
418 res->Data.Address16.AddressLength);
420 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
421 "Address16/IO 0x%x/%d\n",
422 res->Data.Address16.Minimum,
423 res->Data.Address16.AddressLength));
424 set->set_ioport(dev, context,
425 res->Data.Address16.Minimum,
426 res->Data.Address16.AddressLength);
429 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
430 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
431 "Address16/Memory 0x%x-0x%x/%d\n",
432 res->Data.Address16.Minimum,
433 res->Data.Address16.Maximum,
434 res->Data.Address16.AddressLength));
435 set->set_memoryrange(dev, context,
436 res->Data.Address16.Minimum,
437 res->Data.Address16.Maximum,
438 res->Data.Address16.AddressLength,
439 res->Data.Address16.Granularity);
441 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
442 "Address16/IO 0x%x-0x%x/%d\n",
443 res->Data.Address16.Minimum,
444 res->Data.Address16.Maximum,
445 res->Data.Address16.AddressLength));
446 set->set_iorange(dev, context,
447 res->Data.Address16.Minimum,
448 res->Data.Address16.Maximum,
449 res->Data.Address16.AddressLength,
450 res->Data.Address16.Granularity);
454 case ACPI_RESOURCE_TYPE_ADDRESS64:
455 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
456 "unimplemented Address64 resource\n"));
458 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
459 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
460 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
461 "ignored ExtIRQ producer\n"));
464 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
465 res->Data.ExtendedIrq.InterruptCount,
466 res->Data.ExtendedIrq.Triggering,
467 res->Data.ExtendedIrq.Polarity);
469 case ACPI_RESOURCE_TYPE_VENDOR:
470 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
471 "unimplemented VendorSpecific resource\n"));
478 AcpiOsFree(buf.Pointer);
479 set->set_done(dev, context);
480 return_ACPI_STATUS (AE_OK);
484 * Resource-set vectors used to attach _CRS-derived resources
487 static void acpi_res_set_init(device_t dev, void *arg, void **context);
488 static void acpi_res_set_done(device_t dev, void *context);
489 static void acpi_res_set_ioport(device_t dev, void *context,
490 u_int32_t base, u_int32_t length);
491 static void acpi_res_set_iorange(device_t dev, void *context,
492 u_int32_t low, u_int32_t high,
493 u_int32_t length, u_int32_t align);
494 static void acpi_res_set_memory(device_t dev, void *context,
495 u_int32_t base, u_int32_t length);
496 static void acpi_res_set_memoryrange(device_t dev, void *context,
497 u_int32_t low, u_int32_t high,
498 u_int32_t length, u_int32_t align);
499 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
500 int count, int trig, int pol);
501 static void acpi_res_set_ext_irq(device_t dev, void *context,
502 u_int32_t *irq, int count, int trig, int pol);
503 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
505 static void acpi_res_set_start_dependent(device_t dev, void *context,
507 static void acpi_res_set_end_dependent(device_t dev, void *context);
509 struct acpi_parse_resource_set acpi_res_parse_set = {
513 acpi_res_set_iorange,
515 acpi_res_set_memoryrange,
517 acpi_res_set_ext_irq,
519 acpi_res_set_start_dependent,
520 acpi_res_set_end_dependent
523 struct acpi_res_context {
532 acpi_res_set_init(device_t dev, void *arg, void **context)
534 struct acpi_res_context *cp;
536 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
537 bzero(cp, sizeof(*cp));
544 acpi_res_set_done(device_t dev, void *context)
546 struct acpi_res_context *cp = (struct acpi_res_context *)context;
554 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
557 struct acpi_res_context *cp = (struct acpi_res_context *)context;
561 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length, -1);
565 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
566 u_int32_t high, u_int32_t length, u_int32_t align)
568 struct acpi_res_context *cp = (struct acpi_res_context *)context;
572 device_printf(dev, "I/O range not supported\n");
576 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
579 struct acpi_res_context *cp = (struct acpi_res_context *)context;
584 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length, -1);
588 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
589 u_int32_t high, u_int32_t length, u_int32_t align)
591 struct acpi_res_context *cp = (struct acpi_res_context *)context;
595 device_printf(dev, "memory range not supported\n");
599 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
602 struct acpi_res_context *cp = (struct acpi_res_context *)context;
604 if (cp == NULL || irq == NULL)
607 /* This implements no resource relocation. */
611 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
612 machintr_legacy_intr_cpuid(*irq));
616 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
619 struct acpi_res_context *cp = (struct acpi_res_context *)context;
621 if (cp == NULL || irq == NULL)
624 /* This implements no resource relocation. */
628 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
629 machintr_legacy_intr_cpuid(*irq));
633 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
635 struct acpi_res_context *cp = (struct acpi_res_context *)context;
637 if (cp == NULL || drq == NULL)
640 /* This implements no resource relocation. */
644 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1, -1);
648 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
650 struct acpi_res_context *cp = (struct acpi_res_context *)context;
654 device_printf(dev, "dependent functions not supported\n");
658 acpi_res_set_end_dependent(device_t dev, void *context)
660 struct acpi_res_context *cp = (struct acpi_res_context *)context;
664 device_printf(dev, "dependent functions not supported\n");
668 * Resource-owning placeholders for IO and memory pseudo-devices.
670 * This code allocates system resources that will be used by ACPI
671 * child devices. The acpi parent manages these resources through a
675 static int acpi_sysres_rid = 100;
677 static int acpi_sysres_probe(device_t dev);
678 static int acpi_sysres_attach(device_t dev);
680 static device_method_t acpi_sysres_methods[] = {
681 /* Device interface */
682 DEVMETHOD(device_probe, acpi_sysres_probe),
683 DEVMETHOD(device_attach, acpi_sysres_attach),
688 static driver_t acpi_sysres_driver = {
694 static devclass_t acpi_sysres_devclass;
695 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
697 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
700 acpi_sysres_probe(device_t dev)
702 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
704 if (acpi_disabled("sysresource") ||
705 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
708 device_set_desc(dev, "System Resource");
710 return (BUS_PROBE_DEFAULT);
714 acpi_sysres_attach(device_t dev)
717 struct resource_list_entry *bus_rle, *dev_rle;
718 struct resource_list *bus_rl, *dev_rl;
720 u_long start, end, count;
722 * Loop through all current resources to see if the new one overlaps
723 * any existing ones. If so, grow the old one up and/or down
724 * accordingly. Discard any that are wholly contained in the old. If
725 * the resource is unique, add it to the parent. It will later go into
728 bus = device_get_parent(dev);
729 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
730 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
732 kprintf("busrl is not null!\n");
733 SLIST_FOREACH(dev_rle, dev_rl, link) {
734 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
737 start = dev_rle->start;
739 count = dev_rle->count;
740 type = dev_rle->type;
743 SLIST_FOREACH(bus_rle, bus_rl, link) {
744 if (bus_rle->type != type)
747 /* New resource wholly contained in old, discard. */
748 if (start >= bus_rle->start && end <= bus_rle->end)
751 /* New tail overlaps old head, grow existing resource downward. */
752 if (start < bus_rle->start && end >= bus_rle->start) {
753 bus_rle->count += bus_rle->start - start;
754 bus_rle->start = start;
758 /* New head overlaps old tail, grow existing resource upward. */
759 if (start <= bus_rle->end && end > bus_rle->end) {
760 bus_rle->count += end - bus_rle->end;
765 /* If we adjusted the old resource, we're finished. */
769 } else bus_rle = NULL;
770 /* If we didn't merge with anything, add this resource. */
771 if (bus_rle == NULL) {
772 bus_set_resource(bus, type, acpi_sysres_rid++, start, count, -1);
776 /* After merging/moving resources to the parent, free the list. */
777 resource_list_free(dev_rl);