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;
63 case ACPI_RESOURCE_TYPE_IRQ:
64 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
65 if (res->Type == ACPI_RESOURCE_TYPE_IRQ) {
66 irqnum = res->Data.Irq.InterruptCount;
67 irq = res->Data.Irq.Interrupts[0];
69 irqnum = res->Data.ExtendedIrq.InterruptCount;
70 irq = res->Data.ExtendedIrq.Interrupts[0];
74 req = (struct lookup_irq_request *)context;
75 if (req->counter != req->rid) {
80 KASSERT(irq == rman_get_start(req->res),
81 ("IRQ resources do not match"));
82 bcopy(res, req->acpi_res, sizeof(ACPI_RESOURCE));
83 return (AE_CTRL_TERMINATE);
89 acpi_lookup_irq_resource(device_t dev, int rid, struct resource *res,
90 ACPI_RESOURCE *acpi_res)
92 struct lookup_irq_request req;
95 req.acpi_res = acpi_res;
100 status = AcpiWalkResources(acpi_get_handle(dev), "_CRS",
101 acpi_lookup_irq_handler, &req);
102 if (ACPI_SUCCESS(status) && req.found == 0)
103 status = AE_NOT_FOUND;
108 acpi_config_intr(device_t dev, ACPI_RESOURCE *res)
113 case ACPI_RESOURCE_TYPE_IRQ:
114 KASSERT(res->Data.Irq.InterruptCount == 1,
115 ("%s: multiple interrupts", __func__));
116 irq = res->Data.Irq.Interrupts[0];
117 trig = res->Data.Irq.Triggering;
118 pol = res->Data.Irq.Polarity;
120 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
121 KASSERT(res->Data.ExtendedIrq.InterruptCount == 1,
122 ("%s: multiple interrupts", __func__));
123 irq = res->Data.ExtendedIrq.Interrupts[0];
124 trig = res->Data.ExtendedIrq.Triggering;
125 pol = res->Data.ExtendedIrq.Polarity;
128 panic("%s: bad resource type %u", __func__, res->Type);
131 if (irq == AcpiGbl_FADT.SciInterrupt) {
133 kprintf("acpi_config_intr: Skip SCI config\n");
137 BUS_CONFIG_INTR(dev, dev, irq, (trig == ACPI_EDGE_SENSITIVE) ?
138 INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ?
139 INTR_POLARITY_HIGH : INTR_POLARITY_LOW);
143 * Fetch a device's resources and associate them with the device.
145 * Note that it might be nice to also locate ACPI-specific resource items, such
148 * We really need to split the resource-fetching code out from the
149 * resource-parsing code, since we may want to use the parsing
150 * code for _PRS someday.
153 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
154 struct acpi_parse_resource_set *set, void *arg)
162 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
165 * Special-case some devices that abuse _PRS/_CRS to mean
166 * something other than "I consume this resource".
168 * XXX do we really need this? It's only relevant once
169 * we start always-allocating these resources, and even
170 * then, the only special-cased device is likely to be
171 * the PCI interrupt link.
174 /* Fetch the device's current resources. */
175 buf.Length = ACPI_ALLOCATE_BUFFER;
176 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
177 if (status != AE_NOT_FOUND && status != AE_TYPE)
178 kprintf("can't fetch resources for %s - %s\n",
179 acpi_name(handle), AcpiFormatException(status));
180 return_ACPI_STATUS (status);
182 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
183 acpi_name(handle), (long)buf.Length));
184 set->set_init(dev, arg, &context);
186 /* Iterate through the resources */
188 last = (char *)buf.Pointer + buf.Length;
189 while (curr < last) {
190 res = (ACPI_RESOURCE *)curr;
193 /* Handle the individual resource types */
195 case ACPI_RESOURCE_TYPE_END_TAG:
196 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
199 case ACPI_RESOURCE_TYPE_FIXED_IO:
200 if (res->Data.FixedIo.AddressLength <= 0)
202 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
203 res->Data.FixedIo.Address,
204 res->Data.FixedIo.AddressLength));
205 set->set_ioport(dev, context,
206 res->Data.FixedIo.Address,
207 res->Data.FixedIo.AddressLength);
209 case ACPI_RESOURCE_TYPE_IO:
210 if (res->Data.Io.AddressLength <= 0)
212 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
213 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
214 res->Data.Io.Minimum,
215 res->Data.Io.AddressLength));
216 set->set_ioport(dev, context,
217 res->Data.Io.Minimum,
218 res->Data.Io.AddressLength);
220 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
221 res->Data.Io.Minimum,
222 res->Data.Io.Maximum,
223 res->Data.Io.AddressLength));
224 set->set_iorange(dev, context,
225 res->Data.Io.Minimum,
226 res->Data.Io.Maximum,
227 res->Data.Io.AddressLength,
228 res->Data.Io.Alignment);
231 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
232 if (res->Data.FixedMemory32.AddressLength <= 0)
234 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
235 res->Data.FixedMemory32.Address,
236 res->Data.FixedMemory32.AddressLength));
237 set->set_memory(dev, context,
238 res->Data.FixedMemory32.Address,
239 res->Data.FixedMemory32.AddressLength);
241 case ACPI_RESOURCE_TYPE_MEMORY32:
242 if (res->Data.Memory32.AddressLength <= 0)
244 if (res->Data.Memory32.Minimum ==
245 res->Data.Memory32.Maximum) {
247 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
248 res->Data.Memory32.Minimum,
249 res->Data.Memory32.AddressLength));
250 set->set_memory(dev, context,
251 res->Data.Memory32.Minimum,
252 res->Data.Memory32.AddressLength);
254 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
255 res->Data.Memory32.Minimum,
256 res->Data.Memory32.Maximum,
257 res->Data.Memory32.AddressLength));
258 set->set_memoryrange(dev, context,
259 res->Data.Memory32.Minimum,
260 res->Data.Memory32.Maximum,
261 res->Data.Memory32.AddressLength,
262 res->Data.Memory32.Alignment);
265 case ACPI_RESOURCE_TYPE_MEMORY24:
266 if (res->Data.Memory24.AddressLength <= 0)
268 if (res->Data.Memory24.Minimum ==
269 res->Data.Memory24.Maximum) {
271 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
272 res->Data.Memory24.Minimum,
273 res->Data.Memory24.AddressLength));
274 set->set_memory(dev, context, res->Data.Memory24.Minimum,
275 res->Data.Memory24.AddressLength);
277 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
278 res->Data.Memory24.Minimum,
279 res->Data.Memory24.Maximum,
280 res->Data.Memory24.AddressLength));
281 set->set_memoryrange(dev, context,
282 res->Data.Memory24.Minimum,
283 res->Data.Memory24.Maximum,
284 res->Data.Memory24.AddressLength,
285 res->Data.Memory24.Alignment);
288 case ACPI_RESOURCE_TYPE_IRQ:
291 * "This structure is repeated for each separate interrupt
294 set->set_irq(dev, context, res->Data.Irq.Interrupts,
295 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
296 res->Data.Irq.Polarity);
298 case ACPI_RESOURCE_TYPE_DMA:
301 * "This structure is repeated for each separate dma channel
304 set->set_drq(dev, context, res->Data.Dma.Channels,
305 res->Data.Dma.ChannelCount);
307 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
308 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
309 set->set_start_dependent(dev, context,
310 res->Data.StartDpf.CompatibilityPriority);
312 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
313 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
314 set->set_end_dependent(dev, context);
316 case ACPI_RESOURCE_TYPE_ADDRESS32:
317 if (res->Data.Address32.AddressLength <= 0)
319 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
320 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
321 "ignored Address32 %s producer\n",
322 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
326 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
327 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
328 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
329 "ignored Address32 for non-memory, non-I/O\n"));
333 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
334 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
336 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
337 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
338 "Address32/Memory 0x%x/%d\n",
339 res->Data.Address32.Minimum,
340 res->Data.Address32.AddressLength));
341 set->set_memory(dev, context,
342 res->Data.Address32.Minimum,
343 res->Data.Address32.AddressLength);
345 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
346 "Address32/IO 0x%x/%d\n",
347 res->Data.Address32.Minimum,
348 res->Data.Address32.AddressLength));
349 set->set_ioport(dev, context,
350 res->Data.Address32.Minimum,
351 res->Data.Address32.AddressLength);
354 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
355 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
356 "Address32/Memory 0x%x-0x%x/%d\n",
357 res->Data.Address32.Minimum,
358 res->Data.Address32.Maximum,
359 res->Data.Address32.AddressLength));
360 set->set_memoryrange(dev, context,
361 res->Data.Address32.Minimum,
362 res->Data.Address32.Maximum,
363 res->Data.Address32.AddressLength,
364 res->Data.Address32.Granularity);
366 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
367 "Address32/IO 0x%x-0x%x/%d\n",
368 res->Data.Address32.Minimum,
369 res->Data.Address32.Maximum,
370 res->Data.Address32.AddressLength));
371 set->set_iorange(dev, context,
372 res->Data.Address32.Minimum,
373 res->Data.Address32.Maximum,
374 res->Data.Address32.AddressLength,
375 res->Data.Address32.Granularity);
379 case ACPI_RESOURCE_TYPE_ADDRESS16:
380 if (res->Data.Address16.AddressLength <= 0)
382 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
383 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
384 "ignored Address16 %s producer\n",
385 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
389 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
390 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
391 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
392 "ignored Address16 for non-memory, non-I/O\n"));
396 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
397 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
399 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
400 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
401 "Address16/Memory 0x%x/%d\n",
402 res->Data.Address16.Minimum,
403 res->Data.Address16.AddressLength));
404 set->set_memory(dev, context,
405 res->Data.Address16.Minimum,
406 res->Data.Address16.AddressLength);
408 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
409 "Address16/IO 0x%x/%d\n",
410 res->Data.Address16.Minimum,
411 res->Data.Address16.AddressLength));
412 set->set_ioport(dev, context,
413 res->Data.Address16.Minimum,
414 res->Data.Address16.AddressLength);
417 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
418 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
419 "Address16/Memory 0x%x-0x%x/%d\n",
420 res->Data.Address16.Minimum,
421 res->Data.Address16.Maximum,
422 res->Data.Address16.AddressLength));
423 set->set_memoryrange(dev, context,
424 res->Data.Address16.Minimum,
425 res->Data.Address16.Maximum,
426 res->Data.Address16.AddressLength,
427 res->Data.Address16.Granularity);
429 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
430 "Address16/IO 0x%x-0x%x/%d\n",
431 res->Data.Address16.Minimum,
432 res->Data.Address16.Maximum,
433 res->Data.Address16.AddressLength));
434 set->set_iorange(dev, context,
435 res->Data.Address16.Minimum,
436 res->Data.Address16.Maximum,
437 res->Data.Address16.AddressLength,
438 res->Data.Address16.Granularity);
442 case ACPI_RESOURCE_TYPE_ADDRESS64:
443 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
444 "unimplemented Address64 resource\n"));
446 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
447 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
448 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
449 "ignored ExtIRQ producer\n"));
452 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
453 res->Data.ExtendedIrq.InterruptCount,
454 res->Data.ExtendedIrq.Triggering,
455 res->Data.ExtendedIrq.Polarity);
457 case ACPI_RESOURCE_TYPE_VENDOR:
458 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
459 "unimplemented VendorSpecific resource\n"));
466 AcpiOsFree(buf.Pointer);
467 set->set_done(dev, context);
468 return_ACPI_STATUS (AE_OK);
472 * Resource-set vectors used to attach _CRS-derived resources
475 static void acpi_res_set_init(device_t dev, void *arg, void **context);
476 static void acpi_res_set_done(device_t dev, void *context);
477 static void acpi_res_set_ioport(device_t dev, void *context,
478 u_int32_t base, u_int32_t length);
479 static void acpi_res_set_iorange(device_t dev, void *context,
480 u_int32_t low, u_int32_t high,
481 u_int32_t length, u_int32_t align);
482 static void acpi_res_set_memory(device_t dev, void *context,
483 u_int32_t base, u_int32_t length);
484 static void acpi_res_set_memoryrange(device_t dev, void *context,
485 u_int32_t low, u_int32_t high,
486 u_int32_t length, u_int32_t align);
487 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
488 int count, int trig, int pol);
489 static void acpi_res_set_ext_irq(device_t dev, void *context,
490 u_int32_t *irq, int count, int trig, int pol);
491 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
493 static void acpi_res_set_start_dependent(device_t dev, void *context,
495 static void acpi_res_set_end_dependent(device_t dev, void *context);
497 struct acpi_parse_resource_set acpi_res_parse_set = {
501 acpi_res_set_iorange,
503 acpi_res_set_memoryrange,
505 acpi_res_set_ext_irq,
507 acpi_res_set_start_dependent,
508 acpi_res_set_end_dependent
511 struct acpi_res_context {
520 acpi_res_set_init(device_t dev, void *arg, void **context)
522 struct acpi_res_context *cp;
524 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
525 bzero(cp, sizeof(*cp));
532 acpi_res_set_done(device_t dev, void *context)
534 struct acpi_res_context *cp = (struct acpi_res_context *)context;
542 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
545 struct acpi_res_context *cp = (struct acpi_res_context *)context;
549 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length, -1);
553 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
554 u_int32_t high, u_int32_t length, u_int32_t align)
556 struct acpi_res_context *cp = (struct acpi_res_context *)context;
560 device_printf(dev, "I/O range not supported\n");
564 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
567 struct acpi_res_context *cp = (struct acpi_res_context *)context;
572 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length, -1);
576 acpi_res_set_memoryrange(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, "memory range not supported\n");
587 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
590 struct acpi_res_context *cp = (struct acpi_res_context *)context;
592 if (cp == NULL || irq == NULL)
595 /* This implements no resource relocation. */
599 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
600 machintr_intr_cpuid(*irq));
604 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
607 struct acpi_res_context *cp = (struct acpi_res_context *)context;
609 if (cp == NULL || irq == NULL)
612 /* This implements no resource relocation. */
616 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
617 machintr_intr_cpuid(*irq));
621 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
623 struct acpi_res_context *cp = (struct acpi_res_context *)context;
625 if (cp == NULL || drq == NULL)
628 /* This implements no resource relocation. */
632 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1, -1);
636 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
638 struct acpi_res_context *cp = (struct acpi_res_context *)context;
642 device_printf(dev, "dependent functions not supported\n");
646 acpi_res_set_end_dependent(device_t dev, void *context)
648 struct acpi_res_context *cp = (struct acpi_res_context *)context;
652 device_printf(dev, "dependent functions not supported\n");
656 * Resource-owning placeholders for IO and memory pseudo-devices.
658 * This code allocates system resources that will be used by ACPI
659 * child devices. The acpi parent manages these resources through a
663 static int acpi_sysres_rid = 100;
665 static int acpi_sysres_probe(device_t dev);
666 static int acpi_sysres_attach(device_t dev);
668 static device_method_t acpi_sysres_methods[] = {
669 /* Device interface */
670 DEVMETHOD(device_probe, acpi_sysres_probe),
671 DEVMETHOD(device_attach, acpi_sysres_attach),
676 static driver_t acpi_sysres_driver = {
682 static devclass_t acpi_sysres_devclass;
683 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
685 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
688 acpi_sysres_probe(device_t dev)
690 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
692 if (acpi_disabled("sysresource") ||
693 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
696 device_set_desc(dev, "System Resource");
698 return (BUS_PROBE_DEFAULT);
702 acpi_sysres_attach(device_t dev)
705 struct resource_list_entry *bus_rle, *dev_rle;
706 struct resource_list *bus_rl, *dev_rl;
708 u_long start, end, count;
710 * Loop through all current resources to see if the new one overlaps
711 * any existing ones. If so, grow the old one up and/or down
712 * accordingly. Discard any that are wholly contained in the old. If
713 * the resource is unique, add it to the parent. It will later go into
716 bus = device_get_parent(dev);
717 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
718 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
720 kprintf("busrl is not null!\n");
721 SLIST_FOREACH(dev_rle, dev_rl, link) {
722 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
725 start = dev_rle->start;
727 count = dev_rle->count;
728 type = dev_rle->type;
731 SLIST_FOREACH(bus_rle, bus_rl, link) {
732 if (bus_rle->type != type)
735 /* New resource wholly contained in old, discard. */
736 if (start >= bus_rle->start && end <= bus_rle->end)
739 /* New tail overlaps old head, grow existing resource downward. */
740 if (start < bus_rle->start && end >= bus_rle->start) {
741 bus_rle->count += bus_rle->start - start;
742 bus_rle->start = start;
746 /* New head overlaps old tail, grow existing resource upward. */
747 if (start <= bus_rle->end && end > bus_rle->end) {
748 bus_rle->count += end - bus_rle->end;
753 /* If we adjusted the old resource, we're finished. */
757 } else bus_rle = NULL;
758 /* If we didn't merge with anything, add this resource. */
759 if (bus_rle == NULL) {
760 bus_set_resource(bus, type, acpi_sysres_rid++, start, count, -1);
764 /* After merging/moving resources to the parent, free the list. */
765 resource_list_free(dev_rl);