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>
41 #include <dev/acpica5/acpivar.h>
43 /* Hooks for the ACPI CA debugging infrastructure */
44 #define _COMPONENT ACPI_BUS
45 ACPI_MODULE_NAME("RESOURCE")
47 struct lookup_irq_request {
48 ACPI_RESOURCE *acpi_res;
56 acpi_lookup_irq_handler(ACPI_RESOURCE *res, void *context)
58 struct lookup_irq_request *req;
62 case ACPI_RESOURCE_TYPE_IRQ:
63 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
64 if (res->Type == ACPI_RESOURCE_TYPE_IRQ) {
65 irqnum = res->Data.Irq.InterruptCount;
66 irq = res->Data.Irq.Interrupts[0];
68 irqnum = res->Data.ExtendedIrq.InterruptCount;
69 irq = res->Data.ExtendedIrq.Interrupts[0];
73 req = (struct lookup_irq_request *)context;
74 if (req->counter != req->rid) {
79 KASSERT(irq == rman_get_start(req->res),
80 ("IRQ resources do not match"));
81 bcopy(res, req->acpi_res, sizeof(ACPI_RESOURCE));
82 return (AE_CTRL_TERMINATE);
88 acpi_lookup_irq_resource(device_t dev, int rid, struct resource *res,
89 ACPI_RESOURCE *acpi_res)
91 struct lookup_irq_request req;
94 req.acpi_res = acpi_res;
99 status = AcpiWalkResources(acpi_get_handle(dev), "_CRS",
100 acpi_lookup_irq_handler, &req);
101 if (ACPI_SUCCESS(status) && req.found == 0)
102 status = AE_NOT_FOUND;
107 acpi_config_intr(device_t dev, ACPI_RESOURCE *res)
112 case ACPI_RESOURCE_TYPE_IRQ:
113 KASSERT(res->Data.Irq.InterruptCount == 1,
114 ("%s: multiple interrupts", __func__));
115 irq = res->Data.Irq.Interrupts[0];
116 trig = res->Data.Irq.Triggering;
117 pol = res->Data.Irq.Polarity;
119 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
120 KASSERT(res->Data.ExtendedIrq.InterruptCount == 1,
121 ("%s: multiple interrupts", __func__));
122 irq = res->Data.ExtendedIrq.Interrupts[0];
123 trig = res->Data.ExtendedIrq.Triggering;
124 pol = res->Data.ExtendedIrq.Polarity;
127 panic("%s: bad resource type %u", __func__, res->Type);
130 if (irq == AcpiGbl_FADT.SciInterrupt) {
132 kprintf("acpi_config_intr: Skip SCI config\n");
136 BUS_CONFIG_INTR(dev, dev, irq, (trig == ACPI_EDGE_SENSITIVE) ?
137 INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ?
138 INTR_POLARITY_HIGH : INTR_POLARITY_LOW);
142 * Fetch a device's resources and associate them with the device.
144 * Note that it might be nice to also locate ACPI-specific resource items, such
147 * We really need to split the resource-fetching code out from the
148 * resource-parsing code, since we may want to use the parsing
149 * code for _PRS someday.
152 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
153 struct acpi_parse_resource_set *set, void *arg)
161 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
164 * Special-case some devices that abuse _PRS/_CRS to mean
165 * something other than "I consume this resource".
167 * XXX do we really need this? It's only relevant once
168 * we start always-allocating these resources, and even
169 * then, the only special-cased device is likely to be
170 * the PCI interrupt link.
173 /* Fetch the device's current resources. */
174 buf.Length = ACPI_ALLOCATE_BUFFER;
175 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
176 if (status != AE_NOT_FOUND && status != AE_TYPE)
177 kprintf("can't fetch resources for %s - %s\n",
178 acpi_name(handle), AcpiFormatException(status));
179 return_ACPI_STATUS (status);
181 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
182 acpi_name(handle), (long)buf.Length));
183 set->set_init(dev, arg, &context);
185 /* Iterate through the resources */
187 last = (char *)buf.Pointer + buf.Length;
188 while (curr < last) {
189 res = (ACPI_RESOURCE *)curr;
192 /* Handle the individual resource types */
194 case ACPI_RESOURCE_TYPE_END_TAG:
195 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
198 case ACPI_RESOURCE_TYPE_FIXED_IO:
199 if (res->Data.FixedIo.AddressLength <= 0)
201 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
202 res->Data.FixedIo.Address,
203 res->Data.FixedIo.AddressLength));
204 set->set_ioport(dev, context,
205 res->Data.FixedIo.Address,
206 res->Data.FixedIo.AddressLength);
208 case ACPI_RESOURCE_TYPE_IO:
209 if (res->Data.Io.AddressLength <= 0)
211 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
212 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
213 res->Data.Io.Minimum,
214 res->Data.Io.AddressLength));
215 set->set_ioport(dev, context,
216 res->Data.Io.Minimum,
217 res->Data.Io.AddressLength);
219 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
220 res->Data.Io.Minimum,
221 res->Data.Io.Maximum,
222 res->Data.Io.AddressLength));
223 set->set_iorange(dev, context,
224 res->Data.Io.Minimum,
225 res->Data.Io.Maximum,
226 res->Data.Io.AddressLength,
227 res->Data.Io.Alignment);
230 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
231 if (res->Data.FixedMemory32.AddressLength <= 0)
233 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
234 res->Data.FixedMemory32.Address,
235 res->Data.FixedMemory32.AddressLength));
236 set->set_memory(dev, context,
237 res->Data.FixedMemory32.Address,
238 res->Data.FixedMemory32.AddressLength);
240 case ACPI_RESOURCE_TYPE_MEMORY32:
241 if (res->Data.Memory32.AddressLength <= 0)
243 if (res->Data.Memory32.Minimum ==
244 res->Data.Memory32.Maximum) {
246 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
247 res->Data.Memory32.Minimum,
248 res->Data.Memory32.AddressLength));
249 set->set_memory(dev, context,
250 res->Data.Memory32.Minimum,
251 res->Data.Memory32.AddressLength);
253 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
254 res->Data.Memory32.Minimum,
255 res->Data.Memory32.Maximum,
256 res->Data.Memory32.AddressLength));
257 set->set_memoryrange(dev, context,
258 res->Data.Memory32.Minimum,
259 res->Data.Memory32.Maximum,
260 res->Data.Memory32.AddressLength,
261 res->Data.Memory32.Alignment);
264 case ACPI_RESOURCE_TYPE_MEMORY24:
265 if (res->Data.Memory24.AddressLength <= 0)
267 if (res->Data.Memory24.Minimum ==
268 res->Data.Memory24.Maximum) {
270 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
271 res->Data.Memory24.Minimum,
272 res->Data.Memory24.AddressLength));
273 set->set_memory(dev, context, res->Data.Memory24.Minimum,
274 res->Data.Memory24.AddressLength);
276 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
277 res->Data.Memory24.Minimum,
278 res->Data.Memory24.Maximum,
279 res->Data.Memory24.AddressLength));
280 set->set_memoryrange(dev, context,
281 res->Data.Memory24.Minimum,
282 res->Data.Memory24.Maximum,
283 res->Data.Memory24.AddressLength,
284 res->Data.Memory24.Alignment);
287 case ACPI_RESOURCE_TYPE_IRQ:
290 * "This structure is repeated for each separate interrupt
293 set->set_irq(dev, context, res->Data.Irq.Interrupts,
294 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
295 res->Data.Irq.Polarity);
297 case ACPI_RESOURCE_TYPE_DMA:
300 * "This structure is repeated for each separate dma channel
303 set->set_drq(dev, context, res->Data.Dma.Channels,
304 res->Data.Dma.ChannelCount);
306 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
307 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
308 set->set_start_dependent(dev, context,
309 res->Data.StartDpf.CompatibilityPriority);
311 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
312 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
313 set->set_end_dependent(dev, context);
315 case ACPI_RESOURCE_TYPE_ADDRESS32:
316 if (res->Data.Address32.AddressLength <= 0)
318 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
319 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
320 "ignored Address32 %s producer\n",
321 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
325 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
326 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
327 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
328 "ignored Address32 for non-memory, non-I/O\n"));
332 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
333 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
335 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
336 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
337 "Address32/Memory 0x%x/%d\n",
338 res->Data.Address32.Minimum,
339 res->Data.Address32.AddressLength));
340 set->set_memory(dev, context,
341 res->Data.Address32.Minimum,
342 res->Data.Address32.AddressLength);
344 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
345 "Address32/IO 0x%x/%d\n",
346 res->Data.Address32.Minimum,
347 res->Data.Address32.AddressLength));
348 set->set_ioport(dev, context,
349 res->Data.Address32.Minimum,
350 res->Data.Address32.AddressLength);
353 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
354 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
355 "Address32/Memory 0x%x-0x%x/%d\n",
356 res->Data.Address32.Minimum,
357 res->Data.Address32.Maximum,
358 res->Data.Address32.AddressLength));
359 set->set_memoryrange(dev, context,
360 res->Data.Address32.Minimum,
361 res->Data.Address32.Maximum,
362 res->Data.Address32.AddressLength,
363 res->Data.Address32.Granularity);
365 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
366 "Address32/IO 0x%x-0x%x/%d\n",
367 res->Data.Address32.Minimum,
368 res->Data.Address32.Maximum,
369 res->Data.Address32.AddressLength));
370 set->set_iorange(dev, context,
371 res->Data.Address32.Minimum,
372 res->Data.Address32.Maximum,
373 res->Data.Address32.AddressLength,
374 res->Data.Address32.Granularity);
378 case ACPI_RESOURCE_TYPE_ADDRESS16:
379 if (res->Data.Address16.AddressLength <= 0)
381 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
382 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
383 "ignored Address16 %s producer\n",
384 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
388 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
389 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
390 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
391 "ignored Address16 for non-memory, non-I/O\n"));
395 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
396 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
398 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
399 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
400 "Address16/Memory 0x%x/%d\n",
401 res->Data.Address16.Minimum,
402 res->Data.Address16.AddressLength));
403 set->set_memory(dev, context,
404 res->Data.Address16.Minimum,
405 res->Data.Address16.AddressLength);
407 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
408 "Address16/IO 0x%x/%d\n",
409 res->Data.Address16.Minimum,
410 res->Data.Address16.AddressLength));
411 set->set_ioport(dev, context,
412 res->Data.Address16.Minimum,
413 res->Data.Address16.AddressLength);
416 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
417 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
418 "Address16/Memory 0x%x-0x%x/%d\n",
419 res->Data.Address16.Minimum,
420 res->Data.Address16.Maximum,
421 res->Data.Address16.AddressLength));
422 set->set_memoryrange(dev, context,
423 res->Data.Address16.Minimum,
424 res->Data.Address16.Maximum,
425 res->Data.Address16.AddressLength,
426 res->Data.Address16.Granularity);
428 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
429 "Address16/IO 0x%x-0x%x/%d\n",
430 res->Data.Address16.Minimum,
431 res->Data.Address16.Maximum,
432 res->Data.Address16.AddressLength));
433 set->set_iorange(dev, context,
434 res->Data.Address16.Minimum,
435 res->Data.Address16.Maximum,
436 res->Data.Address16.AddressLength,
437 res->Data.Address16.Granularity);
441 case ACPI_RESOURCE_TYPE_ADDRESS64:
442 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
443 "unimplemented Address64 resource\n"));
445 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
446 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
447 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
448 "ignored ExtIRQ producer\n"));
451 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
452 res->Data.ExtendedIrq.InterruptCount,
453 res->Data.ExtendedIrq.Triggering,
454 res->Data.ExtendedIrq.Polarity);
456 case ACPI_RESOURCE_TYPE_VENDOR:
457 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
458 "unimplemented VendorSpecific resource\n"));
465 AcpiOsFree(buf.Pointer);
466 set->set_done(dev, context);
467 return_ACPI_STATUS (AE_OK);
471 * Resource-set vectors used to attach _CRS-derived resources
474 static void acpi_res_set_init(device_t dev, void *arg, void **context);
475 static void acpi_res_set_done(device_t dev, void *context);
476 static void acpi_res_set_ioport(device_t dev, void *context,
477 u_int32_t base, u_int32_t length);
478 static void acpi_res_set_iorange(device_t dev, void *context,
479 u_int32_t low, u_int32_t high,
480 u_int32_t length, u_int32_t align);
481 static void acpi_res_set_memory(device_t dev, void *context,
482 u_int32_t base, u_int32_t length);
483 static void acpi_res_set_memoryrange(device_t dev, void *context,
484 u_int32_t low, u_int32_t high,
485 u_int32_t length, u_int32_t align);
486 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
487 int count, int trig, int pol);
488 static void acpi_res_set_ext_irq(device_t dev, void *context,
489 u_int32_t *irq, int count, int trig, int pol);
490 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
492 static void acpi_res_set_start_dependent(device_t dev, void *context,
494 static void acpi_res_set_end_dependent(device_t dev, void *context);
496 struct acpi_parse_resource_set acpi_res_parse_set = {
500 acpi_res_set_iorange,
502 acpi_res_set_memoryrange,
504 acpi_res_set_ext_irq,
506 acpi_res_set_start_dependent,
507 acpi_res_set_end_dependent
510 struct acpi_res_context {
519 acpi_res_set_init(device_t dev, void *arg, void **context)
521 struct acpi_res_context *cp;
523 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
524 bzero(cp, sizeof(*cp));
531 acpi_res_set_done(device_t dev, void *context)
533 struct acpi_res_context *cp = (struct acpi_res_context *)context;
541 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
544 struct acpi_res_context *cp = (struct acpi_res_context *)context;
548 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length);
552 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
553 u_int32_t high, u_int32_t length, u_int32_t align)
555 struct acpi_res_context *cp = (struct acpi_res_context *)context;
559 device_printf(dev, "I/O range not supported\n");
563 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
566 struct acpi_res_context *cp = (struct acpi_res_context *)context;
571 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length);
575 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
576 u_int32_t high, u_int32_t length, u_int32_t align)
578 struct acpi_res_context *cp = (struct acpi_res_context *)context;
582 device_printf(dev, "memory range not supported\n");
586 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
589 struct acpi_res_context *cp = (struct acpi_res_context *)context;
591 if (cp == NULL || irq == NULL)
594 /* This implements no resource relocation. */
598 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
602 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
605 struct acpi_res_context *cp = (struct acpi_res_context *)context;
607 if (cp == NULL || irq == NULL)
610 /* This implements no resource relocation. */
614 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
618 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
620 struct acpi_res_context *cp = (struct acpi_res_context *)context;
622 if (cp == NULL || drq == NULL)
625 /* This implements no resource relocation. */
629 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1);
633 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
635 struct acpi_res_context *cp = (struct acpi_res_context *)context;
639 device_printf(dev, "dependent functions not supported\n");
643 acpi_res_set_end_dependent(device_t dev, void *context)
645 struct acpi_res_context *cp = (struct acpi_res_context *)context;
649 device_printf(dev, "dependent functions not supported\n");
653 * Resource-owning placeholders for IO and memory pseudo-devices.
655 * This code allocates system resources that will be used by ACPI
656 * child devices. The acpi parent manages these resources through a
660 static int acpi_sysres_rid = 100;
662 static int acpi_sysres_probe(device_t dev);
663 static int acpi_sysres_attach(device_t dev);
665 static device_method_t acpi_sysres_methods[] = {
666 /* Device interface */
667 DEVMETHOD(device_probe, acpi_sysres_probe),
668 DEVMETHOD(device_attach, acpi_sysres_attach),
673 static driver_t acpi_sysres_driver = {
679 static devclass_t acpi_sysres_devclass;
680 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
682 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
685 acpi_sysres_probe(device_t dev)
687 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
689 if (acpi_disabled("sysresource") ||
690 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
693 device_set_desc(dev, "System Resource");
695 return (BUS_PROBE_DEFAULT);
699 acpi_sysres_attach(device_t dev)
702 struct resource_list_entry *bus_rle, *dev_rle;
703 struct resource_list *bus_rl, *dev_rl;
705 u_long start, end, count;
707 * Loop through all current resources to see if the new one overlaps
708 * any existing ones. If so, grow the old one up and/or down
709 * accordingly. Discard any that are wholly contained in the old. If
710 * the resource is unique, add it to the parent. It will later go into
713 bus = device_get_parent(dev);
714 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
715 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
717 kprintf("busrl is not null!\n");
718 SLIST_FOREACH(dev_rle, dev_rl, link) {
719 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
722 start = dev_rle->start;
724 count = dev_rle->count;
725 type = dev_rle->type;
728 SLIST_FOREACH(bus_rle, bus_rl, link) {
729 if (bus_rle->type != type)
732 /* New resource wholly contained in old, discard. */
733 if (start >= bus_rle->start && end <= bus_rle->end)
736 /* New tail overlaps old head, grow existing resource downward. */
737 if (start < bus_rle->start && end >= bus_rle->start) {
738 bus_rle->count += bus_rle->start - start;
739 bus_rle->start = start;
743 /* New head overlaps old tail, grow existing resource upward. */
744 if (start <= bus_rle->end && end > bus_rle->end) {
745 bus_rle->count += end - bus_rle->end;
750 /* If we adjusted the old resource, we're finished. */
754 } else bus_rle = NULL;
755 /* If we didn't merge with anything, add this resource. */
756 if (bus_rle == NULL) {
757 bus_set_resource(bus, type, acpi_sysres_rid++, start, count);
761 /* After merging/moving resources to the parent, free the list. */
762 resource_list_free(dev_rl);