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);
129 BUS_CONFIG_INTR(dev, dev, irq, (trig == ACPI_EDGE_SENSITIVE) ?
130 INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ?
131 INTR_POLARITY_HIGH : INTR_POLARITY_LOW);
135 * Fetch a device's resources and associate them with the device.
137 * Note that it might be nice to also locate ACPI-specific resource items, such
140 * We really need to split the resource-fetching code out from the
141 * resource-parsing code, since we may want to use the parsing
142 * code for _PRS someday.
145 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
146 struct acpi_parse_resource_set *set, void *arg)
154 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
157 * Special-case some devices that abuse _PRS/_CRS to mean
158 * something other than "I consume this resource".
160 * XXX do we really need this? It's only relevant once
161 * we start always-allocating these resources, and even
162 * then, the only special-cased device is likely to be
163 * the PCI interrupt link.
166 /* Fetch the device's current resources. */
167 buf.Length = ACPI_ALLOCATE_BUFFER;
168 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
169 if (status != AE_NOT_FOUND && status != AE_TYPE)
170 kprintf("can't fetch resources for %s - %s\n",
171 acpi_name(handle), AcpiFormatException(status));
172 return_ACPI_STATUS (status);
174 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
175 acpi_name(handle), (long)buf.Length));
176 set->set_init(dev, arg, &context);
178 /* Iterate through the resources */
180 last = (char *)buf.Pointer + buf.Length;
181 while (curr < last) {
182 res = (ACPI_RESOURCE *)curr;
185 /* Handle the individual resource types */
187 case ACPI_RESOURCE_TYPE_END_TAG:
188 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
191 case ACPI_RESOURCE_TYPE_FIXED_IO:
192 if (res->Data.FixedIo.AddressLength <= 0)
194 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
195 res->Data.FixedIo.Address,
196 res->Data.FixedIo.AddressLength));
197 set->set_ioport(dev, context,
198 res->Data.FixedIo.Address,
199 res->Data.FixedIo.AddressLength);
201 case ACPI_RESOURCE_TYPE_IO:
202 if (res->Data.Io.AddressLength <= 0)
204 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
205 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
206 res->Data.Io.Minimum,
207 res->Data.Io.AddressLength));
208 set->set_ioport(dev, context,
209 res->Data.Io.Minimum,
210 res->Data.Io.AddressLength);
212 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
213 res->Data.Io.Minimum,
214 res->Data.Io.Maximum,
215 res->Data.Io.AddressLength));
216 set->set_iorange(dev, context,
217 res->Data.Io.Minimum,
218 res->Data.Io.Maximum,
219 res->Data.Io.AddressLength,
220 res->Data.Io.Alignment);
223 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
224 if (res->Data.FixedMemory32.AddressLength <= 0)
226 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
227 res->Data.FixedMemory32.Address,
228 res->Data.FixedMemory32.AddressLength));
229 set->set_memory(dev, context,
230 res->Data.FixedMemory32.Address,
231 res->Data.FixedMemory32.AddressLength);
233 case ACPI_RESOURCE_TYPE_MEMORY32:
234 if (res->Data.Memory32.AddressLength <= 0)
236 if (res->Data.Memory32.Minimum ==
237 res->Data.Memory32.Maximum) {
239 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
240 res->Data.Memory32.Minimum,
241 res->Data.Memory32.AddressLength));
242 set->set_memory(dev, context,
243 res->Data.Memory32.Minimum,
244 res->Data.Memory32.AddressLength);
246 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
247 res->Data.Memory32.Minimum,
248 res->Data.Memory32.Maximum,
249 res->Data.Memory32.AddressLength));
250 set->set_memoryrange(dev, context,
251 res->Data.Memory32.Minimum,
252 res->Data.Memory32.Maximum,
253 res->Data.Memory32.AddressLength,
254 res->Data.Memory32.Alignment);
257 case ACPI_RESOURCE_TYPE_MEMORY24:
258 if (res->Data.Memory24.AddressLength <= 0)
260 if (res->Data.Memory24.Minimum ==
261 res->Data.Memory24.Maximum) {
263 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
264 res->Data.Memory24.Minimum,
265 res->Data.Memory24.AddressLength));
266 set->set_memory(dev, context, res->Data.Memory24.Minimum,
267 res->Data.Memory24.AddressLength);
269 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
270 res->Data.Memory24.Minimum,
271 res->Data.Memory24.Maximum,
272 res->Data.Memory24.AddressLength));
273 set->set_memoryrange(dev, context,
274 res->Data.Memory24.Minimum,
275 res->Data.Memory24.Maximum,
276 res->Data.Memory24.AddressLength,
277 res->Data.Memory24.Alignment);
280 case ACPI_RESOURCE_TYPE_IRQ:
283 * "This structure is repeated for each separate interrupt
286 set->set_irq(dev, context, res->Data.Irq.Interrupts,
287 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
288 res->Data.Irq.Polarity);
290 case ACPI_RESOURCE_TYPE_DMA:
293 * "This structure is repeated for each separate dma channel
296 set->set_drq(dev, context, res->Data.Dma.Channels,
297 res->Data.Dma.ChannelCount);
299 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
300 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
301 set->set_start_dependent(dev, context,
302 res->Data.StartDpf.CompatibilityPriority);
304 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
305 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
306 set->set_end_dependent(dev, context);
308 case ACPI_RESOURCE_TYPE_ADDRESS32:
309 if (res->Data.Address32.AddressLength <= 0)
311 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
312 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
313 "ignored Address32 %s producer\n",
314 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
318 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
319 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
320 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
321 "ignored Address32 for non-memory, non-I/O\n"));
325 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
326 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
328 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
329 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
330 "Address32/Memory 0x%x/%d\n",
331 res->Data.Address32.Minimum,
332 res->Data.Address32.AddressLength));
333 set->set_memory(dev, context,
334 res->Data.Address32.Minimum,
335 res->Data.Address32.AddressLength);
337 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
338 "Address32/IO 0x%x/%d\n",
339 res->Data.Address32.Minimum,
340 res->Data.Address32.AddressLength));
341 set->set_ioport(dev, context,
342 res->Data.Address32.Minimum,
343 res->Data.Address32.AddressLength);
346 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
347 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
348 "Address32/Memory 0x%x-0x%x/%d\n",
349 res->Data.Address32.Minimum,
350 res->Data.Address32.Maximum,
351 res->Data.Address32.AddressLength));
352 set->set_memoryrange(dev, context,
353 res->Data.Address32.Minimum,
354 res->Data.Address32.Maximum,
355 res->Data.Address32.AddressLength,
356 res->Data.Address32.Granularity);
358 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
359 "Address32/IO 0x%x-0x%x/%d\n",
360 res->Data.Address32.Minimum,
361 res->Data.Address32.Maximum,
362 res->Data.Address32.AddressLength));
363 set->set_iorange(dev, context,
364 res->Data.Address32.Minimum,
365 res->Data.Address32.Maximum,
366 res->Data.Address32.AddressLength,
367 res->Data.Address32.Granularity);
371 case ACPI_RESOURCE_TYPE_ADDRESS16:
372 if (res->Data.Address16.AddressLength <= 0)
374 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
375 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
376 "ignored Address16 %s producer\n",
377 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
381 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
382 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
383 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
384 "ignored Address16 for non-memory, non-I/O\n"));
388 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
389 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
391 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
392 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
393 "Address16/Memory 0x%x/%d\n",
394 res->Data.Address16.Minimum,
395 res->Data.Address16.AddressLength));
396 set->set_memory(dev, context,
397 res->Data.Address16.Minimum,
398 res->Data.Address16.AddressLength);
400 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
401 "Address16/IO 0x%x/%d\n",
402 res->Data.Address16.Minimum,
403 res->Data.Address16.AddressLength));
404 set->set_ioport(dev, context,
405 res->Data.Address16.Minimum,
406 res->Data.Address16.AddressLength);
409 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
410 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
411 "Address16/Memory 0x%x-0x%x/%d\n",
412 res->Data.Address16.Minimum,
413 res->Data.Address16.Maximum,
414 res->Data.Address16.AddressLength));
415 set->set_memoryrange(dev, context,
416 res->Data.Address16.Minimum,
417 res->Data.Address16.Maximum,
418 res->Data.Address16.AddressLength,
419 res->Data.Address16.Granularity);
421 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
422 "Address16/IO 0x%x-0x%x/%d\n",
423 res->Data.Address16.Minimum,
424 res->Data.Address16.Maximum,
425 res->Data.Address16.AddressLength));
426 set->set_iorange(dev, context,
427 res->Data.Address16.Minimum,
428 res->Data.Address16.Maximum,
429 res->Data.Address16.AddressLength,
430 res->Data.Address16.Granularity);
434 case ACPI_RESOURCE_TYPE_ADDRESS64:
435 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
436 "unimplemented Address64 resource\n"));
438 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
439 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
440 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
441 "ignored ExtIRQ producer\n"));
444 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
445 res->Data.ExtendedIrq.InterruptCount,
446 res->Data.ExtendedIrq.Triggering,
447 res->Data.ExtendedIrq.Polarity);
449 case ACPI_RESOURCE_TYPE_VENDOR:
450 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
451 "unimplemented VendorSpecific resource\n"));
458 AcpiOsFree(buf.Pointer);
459 set->set_done(dev, context);
460 return_ACPI_STATUS (AE_OK);
464 * Resource-set vectors used to attach _CRS-derived resources
467 static void acpi_res_set_init(device_t dev, void *arg, void **context);
468 static void acpi_res_set_done(device_t dev, void *context);
469 static void acpi_res_set_ioport(device_t dev, void *context,
470 u_int32_t base, u_int32_t length);
471 static void acpi_res_set_iorange(device_t dev, void *context,
472 u_int32_t low, u_int32_t high,
473 u_int32_t length, u_int32_t align);
474 static void acpi_res_set_memory(device_t dev, void *context,
475 u_int32_t base, u_int32_t length);
476 static void acpi_res_set_memoryrange(device_t dev, void *context,
477 u_int32_t low, u_int32_t high,
478 u_int32_t length, u_int32_t align);
479 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
480 int count, int trig, int pol);
481 static void acpi_res_set_ext_irq(device_t dev, void *context,
482 u_int32_t *irq, int count, int trig, int pol);
483 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
485 static void acpi_res_set_start_dependent(device_t dev, void *context,
487 static void acpi_res_set_end_dependent(device_t dev, void *context);
489 struct acpi_parse_resource_set acpi_res_parse_set = {
493 acpi_res_set_iorange,
495 acpi_res_set_memoryrange,
497 acpi_res_set_ext_irq,
499 acpi_res_set_start_dependent,
500 acpi_res_set_end_dependent
503 struct acpi_res_context {
512 acpi_res_set_init(device_t dev, void *arg, void **context)
514 struct acpi_res_context *cp;
516 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
517 bzero(cp, sizeof(*cp));
524 acpi_res_set_done(device_t dev, void *context)
526 struct acpi_res_context *cp = (struct acpi_res_context *)context;
534 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
537 struct acpi_res_context *cp = (struct acpi_res_context *)context;
541 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length);
545 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
546 u_int32_t high, u_int32_t length, u_int32_t align)
548 struct acpi_res_context *cp = (struct acpi_res_context *)context;
552 device_printf(dev, "I/O range not supported\n");
556 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
559 struct acpi_res_context *cp = (struct acpi_res_context *)context;
564 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length);
568 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
569 u_int32_t high, u_int32_t length, u_int32_t align)
571 struct acpi_res_context *cp = (struct acpi_res_context *)context;
575 device_printf(dev, "memory range not supported\n");
579 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
582 struct acpi_res_context *cp = (struct acpi_res_context *)context;
584 if (cp == NULL || irq == NULL)
587 /* This implements no resource relocation. */
591 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
595 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
598 struct acpi_res_context *cp = (struct acpi_res_context *)context;
600 if (cp == NULL || irq == NULL)
603 /* This implements no resource relocation. */
607 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
611 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
613 struct acpi_res_context *cp = (struct acpi_res_context *)context;
615 if (cp == NULL || drq == NULL)
618 /* This implements no resource relocation. */
622 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1);
626 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
628 struct acpi_res_context *cp = (struct acpi_res_context *)context;
632 device_printf(dev, "dependent functions not supported\n");
636 acpi_res_set_end_dependent(device_t dev, void *context)
638 struct acpi_res_context *cp = (struct acpi_res_context *)context;
642 device_printf(dev, "dependent functions not supported\n");
646 * Resource-owning placeholders for IO and memory pseudo-devices.
648 * This code allocates system resources that will be used by ACPI
649 * child devices. The acpi parent manages these resources through a
653 static int acpi_sysres_rid = 100;
655 static int acpi_sysres_probe(device_t dev);
656 static int acpi_sysres_attach(device_t dev);
658 static device_method_t acpi_sysres_methods[] = {
659 /* Device interface */
660 DEVMETHOD(device_probe, acpi_sysres_probe),
661 DEVMETHOD(device_attach, acpi_sysres_attach),
666 static driver_t acpi_sysres_driver = {
672 static devclass_t acpi_sysres_devclass;
673 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
675 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
678 acpi_sysres_probe(device_t dev)
680 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
682 if (acpi_disabled("sysresource") ||
683 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
686 device_set_desc(dev, "System Resource");
688 return (BUS_PROBE_DEFAULT);
692 acpi_sysres_attach(device_t dev)
696 struct resource_list_entry *bus_rle, *dev_rle;
697 struct resource_list *bus_rl, *dev_rl;
699 u_long start, end, count;
701 * Loop through all current resources to see if the new one overlaps
702 * any existing ones. If so, grow the old one up and/or down
703 * accordingly. Discard any that are wholly contained in the old. If
704 * the resource is unique, add it to the parent. It will later go into
707 bus = device_get_parent(dev);
708 gparent = device_get_parent(bus);
709 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
710 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
712 kprintf("busrl is not null!\n");
713 SLIST_FOREACH(dev_rle, dev_rl, link) {
714 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
717 start = dev_rle->start;
719 count = dev_rle->count;
720 type = dev_rle->type;
723 SLIST_FOREACH(bus_rle, bus_rl, link) {
724 if (bus_rle->type != type)
727 /* New resource wholly contained in old, discard. */
728 if (start >= bus_rle->start && end <= bus_rle->end)
731 /* New tail overlaps old head, grow existing resource downward. */
732 if (start < bus_rle->start && end >= bus_rle->start) {
733 bus_rle->count += bus_rle->start - start;
734 bus_rle->start = start;
738 /* New head overlaps old tail, grow existing resource upward. */
739 if (start <= bus_rle->end && end > bus_rle->end) {
740 bus_rle->count += end - bus_rle->end;
745 /* If we adjusted the old resource, we're finished. */
749 } else bus_rle = NULL;
750 /* If we didn't merge with anything, add this resource. */
751 if (bus_rle == NULL) {
752 bus_set_resource(bus, type, acpi_sysres_rid++, start, count);
756 /* After merging/moving resources to the parent, free the list. */
757 resource_list_free(dev_rl);