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;
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;
147 if (machintr_legacy_intr_find(irq, trigger, polarity) < 0)
148 kprintf("acpi_config_intr: Skip irq %d config\n", irq);
150 BUS_CONFIG_INTR(dev, dev, irq, trigger, polarity);
154 * Fetch a device's resources and associate them with the device.
156 * Note that it might be nice to also locate ACPI-specific resource items, such
159 * We really need to split the resource-fetching code out from the
160 * resource-parsing code, since we may want to use the parsing
161 * code for _PRS someday.
164 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
165 struct acpi_parse_resource_set *set, void *arg)
173 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
176 * Special-case some devices that abuse _PRS/_CRS to mean
177 * something other than "I consume this resource".
179 * XXX do we really need this? It's only relevant once
180 * we start always-allocating these resources, and even
181 * then, the only special-cased device is likely to be
182 * the PCI interrupt link.
185 /* Fetch the device's current resources. */
186 buf.Length = ACPI_ALLOCATE_BUFFER;
187 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
188 if (status != AE_NOT_FOUND && status != AE_TYPE)
189 kprintf("can't fetch resources for %s - %s\n",
190 acpi_name(handle), AcpiFormatException(status));
191 return_ACPI_STATUS (status);
193 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
194 acpi_name(handle), (long)buf.Length));
195 set->set_init(dev, arg, &context);
197 /* Iterate through the resources */
199 last = (char *)buf.Pointer + buf.Length;
200 while (curr < last) {
201 res = (ACPI_RESOURCE *)curr;
204 /* Handle the individual resource types */
206 case ACPI_RESOURCE_TYPE_END_TAG:
207 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
210 case ACPI_RESOURCE_TYPE_FIXED_IO:
211 if (res->Data.FixedIo.AddressLength <= 0)
213 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
214 res->Data.FixedIo.Address,
215 res->Data.FixedIo.AddressLength));
216 set->set_ioport(dev, context,
217 res->Data.FixedIo.Address,
218 res->Data.FixedIo.AddressLength);
220 case ACPI_RESOURCE_TYPE_IO:
221 if (res->Data.Io.AddressLength <= 0)
223 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
224 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
225 res->Data.Io.Minimum,
226 res->Data.Io.AddressLength));
227 set->set_ioport(dev, context,
228 res->Data.Io.Minimum,
229 res->Data.Io.AddressLength);
231 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
232 res->Data.Io.Minimum,
233 res->Data.Io.Maximum,
234 res->Data.Io.AddressLength));
235 set->set_iorange(dev, context,
236 res->Data.Io.Minimum,
237 res->Data.Io.Maximum,
238 res->Data.Io.AddressLength,
239 res->Data.Io.Alignment);
242 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
243 if (res->Data.FixedMemory32.AddressLength <= 0)
245 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
246 res->Data.FixedMemory32.Address,
247 res->Data.FixedMemory32.AddressLength));
248 set->set_memory(dev, context,
249 res->Data.FixedMemory32.Address,
250 res->Data.FixedMemory32.AddressLength);
252 case ACPI_RESOURCE_TYPE_MEMORY32:
253 if (res->Data.Memory32.AddressLength <= 0)
255 if (res->Data.Memory32.Minimum ==
256 res->Data.Memory32.Maximum) {
258 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
259 res->Data.Memory32.Minimum,
260 res->Data.Memory32.AddressLength));
261 set->set_memory(dev, context,
262 res->Data.Memory32.Minimum,
263 res->Data.Memory32.AddressLength);
265 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
266 res->Data.Memory32.Minimum,
267 res->Data.Memory32.Maximum,
268 res->Data.Memory32.AddressLength));
269 set->set_memoryrange(dev, context,
270 res->Data.Memory32.Minimum,
271 res->Data.Memory32.Maximum,
272 res->Data.Memory32.AddressLength,
273 res->Data.Memory32.Alignment);
276 case ACPI_RESOURCE_TYPE_MEMORY24:
277 if (res->Data.Memory24.AddressLength <= 0)
279 if (res->Data.Memory24.Minimum ==
280 res->Data.Memory24.Maximum) {
282 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
283 res->Data.Memory24.Minimum,
284 res->Data.Memory24.AddressLength));
285 set->set_memory(dev, context, res->Data.Memory24.Minimum,
286 res->Data.Memory24.AddressLength);
288 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
289 res->Data.Memory24.Minimum,
290 res->Data.Memory24.Maximum,
291 res->Data.Memory24.AddressLength));
292 set->set_memoryrange(dev, context,
293 res->Data.Memory24.Minimum,
294 res->Data.Memory24.Maximum,
295 res->Data.Memory24.AddressLength,
296 res->Data.Memory24.Alignment);
299 case ACPI_RESOURCE_TYPE_IRQ:
302 * "This structure is repeated for each separate interrupt
305 set->set_irq(dev, context, res->Data.Irq.Interrupts,
306 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
307 res->Data.Irq.Polarity);
309 case ACPI_RESOURCE_TYPE_DMA:
312 * "This structure is repeated for each separate dma channel
315 set->set_drq(dev, context, res->Data.Dma.Channels,
316 res->Data.Dma.ChannelCount);
318 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
319 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
320 set->set_start_dependent(dev, context,
321 res->Data.StartDpf.CompatibilityPriority);
323 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
324 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
325 set->set_end_dependent(dev, context);
327 case ACPI_RESOURCE_TYPE_ADDRESS32:
328 if (res->Data.Address32.AddressLength <= 0)
330 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
331 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
332 "ignored Address32 %s producer\n",
333 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
337 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
338 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
339 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
340 "ignored Address32 for non-memory, non-I/O\n"));
344 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
345 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
347 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
348 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
349 "Address32/Memory 0x%x/%d\n",
350 res->Data.Address32.Minimum,
351 res->Data.Address32.AddressLength));
352 set->set_memory(dev, context,
353 res->Data.Address32.Minimum,
354 res->Data.Address32.AddressLength);
356 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
357 "Address32/IO 0x%x/%d\n",
358 res->Data.Address32.Minimum,
359 res->Data.Address32.AddressLength));
360 set->set_ioport(dev, context,
361 res->Data.Address32.Minimum,
362 res->Data.Address32.AddressLength);
365 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
366 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
367 "Address32/Memory 0x%x-0x%x/%d\n",
368 res->Data.Address32.Minimum,
369 res->Data.Address32.Maximum,
370 res->Data.Address32.AddressLength));
371 set->set_memoryrange(dev, context,
372 res->Data.Address32.Minimum,
373 res->Data.Address32.Maximum,
374 res->Data.Address32.AddressLength,
375 res->Data.Address32.Granularity);
377 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
378 "Address32/IO 0x%x-0x%x/%d\n",
379 res->Data.Address32.Minimum,
380 res->Data.Address32.Maximum,
381 res->Data.Address32.AddressLength));
382 set->set_iorange(dev, context,
383 res->Data.Address32.Minimum,
384 res->Data.Address32.Maximum,
385 res->Data.Address32.AddressLength,
386 res->Data.Address32.Granularity);
390 case ACPI_RESOURCE_TYPE_ADDRESS16:
391 if (res->Data.Address16.AddressLength <= 0)
393 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
394 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
395 "ignored Address16 %s producer\n",
396 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
400 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
401 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
402 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
403 "ignored Address16 for non-memory, non-I/O\n"));
407 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
408 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
410 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
411 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
412 "Address16/Memory 0x%x/%d\n",
413 res->Data.Address16.Minimum,
414 res->Data.Address16.AddressLength));
415 set->set_memory(dev, context,
416 res->Data.Address16.Minimum,
417 res->Data.Address16.AddressLength);
419 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
420 "Address16/IO 0x%x/%d\n",
421 res->Data.Address16.Minimum,
422 res->Data.Address16.AddressLength));
423 set->set_ioport(dev, context,
424 res->Data.Address16.Minimum,
425 res->Data.Address16.AddressLength);
428 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
429 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
430 "Address16/Memory 0x%x-0x%x/%d\n",
431 res->Data.Address16.Minimum,
432 res->Data.Address16.Maximum,
433 res->Data.Address16.AddressLength));
434 set->set_memoryrange(dev, context,
435 res->Data.Address16.Minimum,
436 res->Data.Address16.Maximum,
437 res->Data.Address16.AddressLength,
438 res->Data.Address16.Granularity);
440 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
441 "Address16/IO 0x%x-0x%x/%d\n",
442 res->Data.Address16.Minimum,
443 res->Data.Address16.Maximum,
444 res->Data.Address16.AddressLength));
445 set->set_iorange(dev, context,
446 res->Data.Address16.Minimum,
447 res->Data.Address16.Maximum,
448 res->Data.Address16.AddressLength,
449 res->Data.Address16.Granularity);
453 case ACPI_RESOURCE_TYPE_ADDRESS64:
454 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
455 "unimplemented Address64 resource\n"));
457 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
458 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
459 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
460 "ignored ExtIRQ producer\n"));
463 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
464 res->Data.ExtendedIrq.InterruptCount,
465 res->Data.ExtendedIrq.Triggering,
466 res->Data.ExtendedIrq.Polarity);
468 case ACPI_RESOURCE_TYPE_VENDOR:
469 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
470 "unimplemented VendorSpecific resource\n"));
477 AcpiOsFree(buf.Pointer);
478 set->set_done(dev, context);
479 return_ACPI_STATUS (AE_OK);
483 * Resource-set vectors used to attach _CRS-derived resources
486 static void acpi_res_set_init(device_t dev, void *arg, void **context);
487 static void acpi_res_set_done(device_t dev, void *context);
488 static void acpi_res_set_ioport(device_t dev, void *context,
489 u_int32_t base, u_int32_t length);
490 static void acpi_res_set_iorange(device_t dev, void *context,
491 u_int32_t low, u_int32_t high,
492 u_int32_t length, u_int32_t align);
493 static void acpi_res_set_memory(device_t dev, void *context,
494 u_int32_t base, u_int32_t length);
495 static void acpi_res_set_memoryrange(device_t dev, void *context,
496 u_int32_t low, u_int32_t high,
497 u_int32_t length, u_int32_t align);
498 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
499 int count, int trig, int pol);
500 static void acpi_res_set_ext_irq(device_t dev, void *context,
501 u_int32_t *irq, int count, int trig, int pol);
502 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
504 static void acpi_res_set_start_dependent(device_t dev, void *context,
506 static void acpi_res_set_end_dependent(device_t dev, void *context);
508 struct acpi_parse_resource_set acpi_res_parse_set = {
512 acpi_res_set_iorange,
514 acpi_res_set_memoryrange,
516 acpi_res_set_ext_irq,
518 acpi_res_set_start_dependent,
519 acpi_res_set_end_dependent
522 struct acpi_res_context {
531 acpi_res_set_init(device_t dev, void *arg, void **context)
533 struct acpi_res_context *cp;
535 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
536 bzero(cp, sizeof(*cp));
543 acpi_res_set_done(device_t dev, void *context)
545 struct acpi_res_context *cp = (struct acpi_res_context *)context;
553 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
556 struct acpi_res_context *cp = (struct acpi_res_context *)context;
560 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length, -1);
564 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
565 u_int32_t high, u_int32_t length, u_int32_t align)
567 struct acpi_res_context *cp = (struct acpi_res_context *)context;
571 device_printf(dev, "I/O range not supported\n");
575 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
578 struct acpi_res_context *cp = (struct acpi_res_context *)context;
583 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length, -1);
587 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
588 u_int32_t high, u_int32_t length, u_int32_t align)
590 struct acpi_res_context *cp = (struct acpi_res_context *)context;
594 device_printf(dev, "memory range not supported\n");
598 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
601 struct acpi_res_context *cp = (struct acpi_res_context *)context;
603 if (cp == NULL || irq == NULL)
606 /* This implements no resource relocation. */
610 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
611 machintr_legacy_intr_cpuid(*irq));
615 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
618 struct acpi_res_context *cp = (struct acpi_res_context *)context;
620 if (cp == NULL || irq == NULL)
623 /* This implements no resource relocation. */
627 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
628 machintr_legacy_intr_cpuid(*irq));
632 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
634 struct acpi_res_context *cp = (struct acpi_res_context *)context;
636 if (cp == NULL || drq == NULL)
639 /* This implements no resource relocation. */
643 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1, -1);
647 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
649 struct acpi_res_context *cp = (struct acpi_res_context *)context;
653 device_printf(dev, "dependent functions not supported\n");
657 acpi_res_set_end_dependent(device_t dev, void *context)
659 struct acpi_res_context *cp = (struct acpi_res_context *)context;
663 device_printf(dev, "dependent functions not supported\n");
667 * Resource-owning placeholders for IO and memory pseudo-devices.
669 * This code allocates system resources that will be used by ACPI
670 * child devices. The acpi parent manages these resources through a
674 static int acpi_sysres_rid = 100;
676 static int acpi_sysres_probe(device_t dev);
677 static int acpi_sysres_attach(device_t dev);
679 static device_method_t acpi_sysres_methods[] = {
680 /* Device interface */
681 DEVMETHOD(device_probe, acpi_sysres_probe),
682 DEVMETHOD(device_attach, acpi_sysres_attach),
687 static driver_t acpi_sysres_driver = {
693 static devclass_t acpi_sysres_devclass;
694 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
696 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
699 acpi_sysres_probe(device_t dev)
701 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
703 if (acpi_disabled("sysresource") ||
704 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
707 device_set_desc(dev, "System Resource");
709 return (BUS_PROBE_DEFAULT);
713 acpi_sysres_attach(device_t dev)
716 struct resource_list_entry *bus_rle, *dev_rle;
717 struct resource_list *bus_rl, *dev_rl;
719 u_long start, end, count;
721 * Loop through all current resources to see if the new one overlaps
722 * any existing ones. If so, grow the old one up and/or down
723 * accordingly. Discard any that are wholly contained in the old. If
724 * the resource is unique, add it to the parent. It will later go into
727 bus = device_get_parent(dev);
728 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
729 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
731 kprintf("busrl is not null!\n");
732 SLIST_FOREACH(dev_rle, dev_rl, link) {
733 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
736 start = dev_rle->start;
738 count = dev_rle->count;
739 type = dev_rle->type;
742 SLIST_FOREACH(bus_rle, bus_rl, link) {
743 if (bus_rle->type != type)
746 /* New resource wholly contained in old, discard. */
747 if (start >= bus_rle->start && end <= bus_rle->end)
750 /* New tail overlaps old head, grow existing resource downward. */
751 if (start < bus_rle->start && end >= bus_rle->start) {
752 bus_rle->count += bus_rle->start - start;
753 bus_rle->start = start;
757 /* New head overlaps old tail, grow existing resource upward. */
758 if (start <= bus_rle->end && end > bus_rle->end) {
759 bus_rle->count += end - bus_rle->end;
764 /* If we adjusted the old resource, we're finished. */
768 } else bus_rle = NULL;
769 /* If we didn't merge with anything, add this resource. */
770 if (bus_rle == NULL) {
771 bus_set_resource(bus, type, acpi_sysres_rid++, start, count, -1);
775 /* After merging/moving resources to the parent, free the list. */
776 resource_list_free(dev_rl);