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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/kernel.h>
35 #include <sys/malloc.h>
36 #include <sys/module.h>
38 #include <machine/bus.h>
39 #include <machine/resource.h>
42 #include <contrib/dev/acpica/include/acpi.h>
43 #include <contrib/dev/acpica/include/accommon.h>
45 #include <dev/acpica/acpivar.h>
47 /* Hooks for the ACPI CA debugging infrastructure */
48 #define _COMPONENT ACPI_BUS
49 ACPI_MODULE_NAME("RESOURCE")
51 struct lookup_irq_request {
52 ACPI_RESOURCE *acpi_res;
60 acpi_lookup_irq_handler(ACPI_RESOURCE *res, void *context)
62 struct lookup_irq_request *req;
67 case ACPI_RESOURCE_TYPE_IRQ:
68 irqnum = res->Data.Irq.InterruptCount;
69 irq = res->Data.Irq.Interrupts[0];
70 len = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
72 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
73 irqnum = res->Data.ExtendedIrq.InterruptCount;
74 irq = res->Data.ExtendedIrq.Interrupts[0];
75 len = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
82 req = (struct lookup_irq_request *)context;
83 if (req->counter != req->rid) {
88 KASSERT(irq == rman_get_start(req->res),
89 ("IRQ resources do not match"));
90 bcopy(res, req->acpi_res, len);
91 return (AE_CTRL_TERMINATE);
95 acpi_lookup_irq_resource(device_t dev, int rid, struct resource *res,
96 ACPI_RESOURCE *acpi_res)
98 struct lookup_irq_request req;
101 req.acpi_res = acpi_res;
106 status = AcpiWalkResources(acpi_get_handle(dev), "_CRS",
107 acpi_lookup_irq_handler, &req);
108 if (ACPI_SUCCESS(status) && req.found == 0)
109 status = AE_NOT_FOUND;
114 acpi_config_intr(device_t dev, ACPI_RESOURCE *res)
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);
137 BUS_CONFIG_INTR(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 printf("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);
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);
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);
603 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
606 struct acpi_res_context *cp = (struct acpi_res_context *)context;
608 if (cp == NULL || irq == NULL)
611 /* This implements no resource relocation. */
615 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
619 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
621 struct acpi_res_context *cp = (struct acpi_res_context *)context;
623 if (cp == NULL || drq == NULL)
626 /* This implements no resource relocation. */
630 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1);
634 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
636 struct acpi_res_context *cp = (struct acpi_res_context *)context;
640 device_printf(dev, "dependent functions not supported\n");
644 acpi_res_set_end_dependent(device_t dev, void *context)
646 struct acpi_res_context *cp = (struct acpi_res_context *)context;
650 device_printf(dev, "dependent functions not supported\n");
654 * Resource-owning placeholders for IO and memory pseudo-devices.
656 * This code allocates system resources that will be used by ACPI
657 * child devices. The acpi parent manages these resources through a
661 static int acpi_sysres_rid = 100;
663 static int acpi_sysres_probe(device_t dev);
664 static int acpi_sysres_attach(device_t dev);
666 static device_method_t acpi_sysres_methods[] = {
667 /* Device interface */
668 DEVMETHOD(device_probe, acpi_sysres_probe),
669 DEVMETHOD(device_attach, acpi_sysres_attach),
674 static driver_t acpi_sysres_driver = {
680 static devclass_t acpi_sysres_devclass;
681 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
683 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
686 acpi_sysres_probe(device_t dev)
688 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
690 if (acpi_disabled("sysresource") ||
691 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
694 device_set_desc(dev, "System Resource");
696 return (BUS_PROBE_DEFAULT);
700 acpi_sysres_attach(device_t dev)
703 struct resource_list_entry *bus_rle, *dev_rle;
704 struct resource_list *bus_rl, *dev_rl;
706 u_long start, end, count;
709 * Loop through all current resources to see if the new one overlaps
710 * any existing ones. If so, grow the old one up and/or down
711 * accordingly. Discard any that are wholly contained in the old. If
712 * the resource is unique, add it to the parent. It will later go into
715 bus = device_get_parent(dev);
716 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
717 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
718 STAILQ_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 STAILQ_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. */
755 /* If we didn't merge with anything, add this resource. */
757 bus_set_resource(bus, type, acpi_sysres_rid++, start, count);
760 /* After merging/moving resources to the parent, free the list. */
761 resource_list_free(dev_rl);