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;
66 case ACPI_RESOURCE_TYPE_IRQ:
67 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
68 if (res->Type == ACPI_RESOURCE_TYPE_IRQ) {
69 irqnum = res->Data.Irq.InterruptCount;
70 irq = res->Data.Irq.Interrupts[0];
72 irqnum = res->Data.ExtendedIrq.InterruptCount;
73 irq = res->Data.ExtendedIrq.Interrupts[0];
77 req = (struct lookup_irq_request *)context;
78 if (req->counter != req->rid) {
83 KASSERT(irq == rman_get_start(req->res),
84 ("IRQ resources do not match"));
85 bcopy(res, req->acpi_res, sizeof(ACPI_RESOURCE));
86 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)
117 case ACPI_RESOURCE_TYPE_IRQ:
118 KASSERT(res->Data.Irq.InterruptCount == 1,
119 ("%s: multiple interrupts", __func__));
120 irq = res->Data.Irq.Interrupts[0];
121 trig = res->Data.Irq.Triggering;
122 pol = res->Data.Irq.Polarity;
124 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
125 KASSERT(res->Data.ExtendedIrq.InterruptCount == 1,
126 ("%s: multiple interrupts", __func__));
127 irq = res->Data.ExtendedIrq.Interrupts[0];
128 trig = res->Data.ExtendedIrq.Triggering;
129 pol = res->Data.ExtendedIrq.Polarity;
132 panic("%s: bad resource type %u", __func__, res->Type);
134 BUS_CONFIG_INTR(dev, irq, (trig == ACPI_EDGE_SENSITIVE) ?
135 INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ?
136 INTR_POLARITY_HIGH : INTR_POLARITY_LOW);
140 * Fetch a device's resources and associate them with the device.
142 * Note that it might be nice to also locate ACPI-specific resource items, such
145 * We really need to split the resource-fetching code out from the
146 * resource-parsing code, since we may want to use the parsing
147 * code for _PRS someday.
150 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
151 struct acpi_parse_resource_set *set, void *arg)
159 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
162 * Special-case some devices that abuse _PRS/_CRS to mean
163 * something other than "I consume this resource".
165 * XXX do we really need this? It's only relevant once
166 * we start always-allocating these resources, and even
167 * then, the only special-cased device is likely to be
168 * the PCI interrupt link.
171 /* Fetch the device's current resources. */
172 buf.Length = ACPI_ALLOCATE_BUFFER;
173 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
174 if (status != AE_NOT_FOUND && status != AE_TYPE)
175 printf("can't fetch resources for %s - %s\n",
176 acpi_name(handle), AcpiFormatException(status));
177 return_ACPI_STATUS (status);
179 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
180 acpi_name(handle), (long)buf.Length));
181 set->set_init(dev, arg, &context);
183 /* Iterate through the resources */
185 last = (char *)buf.Pointer + buf.Length;
186 while (curr < last) {
187 res = (ACPI_RESOURCE *)curr;
190 /* Handle the individual resource types */
192 case ACPI_RESOURCE_TYPE_END_TAG:
193 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
196 case ACPI_RESOURCE_TYPE_FIXED_IO:
197 if (res->Data.FixedIo.AddressLength <= 0)
199 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
200 res->Data.FixedIo.Address,
201 res->Data.FixedIo.AddressLength));
202 set->set_ioport(dev, context,
203 res->Data.FixedIo.Address,
204 res->Data.FixedIo.AddressLength);
206 case ACPI_RESOURCE_TYPE_IO:
207 if (res->Data.Io.AddressLength <= 0)
209 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
210 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
211 res->Data.Io.Minimum,
212 res->Data.Io.AddressLength));
213 set->set_ioport(dev, context,
214 res->Data.Io.Minimum,
215 res->Data.Io.AddressLength);
217 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
218 res->Data.Io.Minimum,
219 res->Data.Io.Maximum,
220 res->Data.Io.AddressLength));
221 set->set_iorange(dev, context,
222 res->Data.Io.Minimum,
223 res->Data.Io.Maximum,
224 res->Data.Io.AddressLength,
225 res->Data.Io.Alignment);
228 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
229 if (res->Data.FixedMemory32.AddressLength <= 0)
231 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
232 res->Data.FixedMemory32.Address,
233 res->Data.FixedMemory32.AddressLength));
234 set->set_memory(dev, context,
235 res->Data.FixedMemory32.Address,
236 res->Data.FixedMemory32.AddressLength);
238 case ACPI_RESOURCE_TYPE_MEMORY32:
239 if (res->Data.Memory32.AddressLength <= 0)
241 if (res->Data.Memory32.Minimum ==
242 res->Data.Memory32.Maximum) {
244 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
245 res->Data.Memory32.Minimum,
246 res->Data.Memory32.AddressLength));
247 set->set_memory(dev, context,
248 res->Data.Memory32.Minimum,
249 res->Data.Memory32.AddressLength);
251 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
252 res->Data.Memory32.Minimum,
253 res->Data.Memory32.Maximum,
254 res->Data.Memory32.AddressLength));
255 set->set_memoryrange(dev, context,
256 res->Data.Memory32.Minimum,
257 res->Data.Memory32.Maximum,
258 res->Data.Memory32.AddressLength,
259 res->Data.Memory32.Alignment);
262 case ACPI_RESOURCE_TYPE_MEMORY24:
263 if (res->Data.Memory24.AddressLength <= 0)
265 if (res->Data.Memory24.Minimum ==
266 res->Data.Memory24.Maximum) {
268 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
269 res->Data.Memory24.Minimum,
270 res->Data.Memory24.AddressLength));
271 set->set_memory(dev, context, res->Data.Memory24.Minimum,
272 res->Data.Memory24.AddressLength);
274 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
275 res->Data.Memory24.Minimum,
276 res->Data.Memory24.Maximum,
277 res->Data.Memory24.AddressLength));
278 set->set_memoryrange(dev, context,
279 res->Data.Memory24.Minimum,
280 res->Data.Memory24.Maximum,
281 res->Data.Memory24.AddressLength,
282 res->Data.Memory24.Alignment);
285 case ACPI_RESOURCE_TYPE_IRQ:
288 * "This structure is repeated for each separate interrupt
291 set->set_irq(dev, context, res->Data.Irq.Interrupts,
292 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
293 res->Data.Irq.Polarity);
295 case ACPI_RESOURCE_TYPE_DMA:
298 * "This structure is repeated for each separate dma channel
301 set->set_drq(dev, context, res->Data.Dma.Channels,
302 res->Data.Dma.ChannelCount);
304 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
305 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
306 set->set_start_dependent(dev, context,
307 res->Data.StartDpf.CompatibilityPriority);
309 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
310 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
311 set->set_end_dependent(dev, context);
313 case ACPI_RESOURCE_TYPE_ADDRESS32:
314 if (res->Data.Address32.AddressLength <= 0)
316 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
317 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
318 "ignored Address32 %s producer\n",
319 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
323 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
324 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
325 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
326 "ignored Address32 for non-memory, non-I/O\n"));
330 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
331 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
333 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
334 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
335 "Address32/Memory 0x%x/%d\n",
336 res->Data.Address32.Minimum,
337 res->Data.Address32.AddressLength));
338 set->set_memory(dev, context,
339 res->Data.Address32.Minimum,
340 res->Data.Address32.AddressLength);
342 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
343 "Address32/IO 0x%x/%d\n",
344 res->Data.Address32.Minimum,
345 res->Data.Address32.AddressLength));
346 set->set_ioport(dev, context,
347 res->Data.Address32.Minimum,
348 res->Data.Address32.AddressLength);
351 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
352 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
353 "Address32/Memory 0x%x-0x%x/%d\n",
354 res->Data.Address32.Minimum,
355 res->Data.Address32.Maximum,
356 res->Data.Address32.AddressLength));
357 set->set_memoryrange(dev, context,
358 res->Data.Address32.Minimum,
359 res->Data.Address32.Maximum,
360 res->Data.Address32.AddressLength,
361 res->Data.Address32.Granularity);
363 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
364 "Address32/IO 0x%x-0x%x/%d\n",
365 res->Data.Address32.Minimum,
366 res->Data.Address32.Maximum,
367 res->Data.Address32.AddressLength));
368 set->set_iorange(dev, context,
369 res->Data.Address32.Minimum,
370 res->Data.Address32.Maximum,
371 res->Data.Address32.AddressLength,
372 res->Data.Address32.Granularity);
376 case ACPI_RESOURCE_TYPE_ADDRESS16:
377 if (res->Data.Address16.AddressLength <= 0)
379 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
380 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
381 "ignored Address16 %s producer\n",
382 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
386 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
387 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
388 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
389 "ignored Address16 for non-memory, non-I/O\n"));
393 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
394 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
396 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
397 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
398 "Address16/Memory 0x%x/%d\n",
399 res->Data.Address16.Minimum,
400 res->Data.Address16.AddressLength));
401 set->set_memory(dev, context,
402 res->Data.Address16.Minimum,
403 res->Data.Address16.AddressLength);
405 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
406 "Address16/IO 0x%x/%d\n",
407 res->Data.Address16.Minimum,
408 res->Data.Address16.AddressLength));
409 set->set_ioport(dev, context,
410 res->Data.Address16.Minimum,
411 res->Data.Address16.AddressLength);
414 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
415 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
416 "Address16/Memory 0x%x-0x%x/%d\n",
417 res->Data.Address16.Minimum,
418 res->Data.Address16.Maximum,
419 res->Data.Address16.AddressLength));
420 set->set_memoryrange(dev, context,
421 res->Data.Address16.Minimum,
422 res->Data.Address16.Maximum,
423 res->Data.Address16.AddressLength,
424 res->Data.Address16.Granularity);
426 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
427 "Address16/IO 0x%x-0x%x/%d\n",
428 res->Data.Address16.Minimum,
429 res->Data.Address16.Maximum,
430 res->Data.Address16.AddressLength));
431 set->set_iorange(dev, context,
432 res->Data.Address16.Minimum,
433 res->Data.Address16.Maximum,
434 res->Data.Address16.AddressLength,
435 res->Data.Address16.Granularity);
439 case ACPI_RESOURCE_TYPE_ADDRESS64:
440 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
441 "unimplemented Address64 resource\n"));
443 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
444 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
445 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
446 "ignored ExtIRQ producer\n"));
449 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
450 res->Data.ExtendedIrq.InterruptCount,
451 res->Data.ExtendedIrq.Triggering,
452 res->Data.ExtendedIrq.Polarity);
454 case ACPI_RESOURCE_TYPE_VENDOR:
455 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
456 "unimplemented VendorSpecific resource\n"));
463 AcpiOsFree(buf.Pointer);
464 set->set_done(dev, context);
465 return_ACPI_STATUS (AE_OK);
469 * Resource-set vectors used to attach _CRS-derived resources
472 static void acpi_res_set_init(device_t dev, void *arg, void **context);
473 static void acpi_res_set_done(device_t dev, void *context);
474 static void acpi_res_set_ioport(device_t dev, void *context,
475 u_int32_t base, u_int32_t length);
476 static void acpi_res_set_iorange(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_memory(device_t dev, void *context,
480 u_int32_t base, u_int32_t length);
481 static void acpi_res_set_memoryrange(device_t dev, void *context,
482 u_int32_t low, u_int32_t high,
483 u_int32_t length, u_int32_t align);
484 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
485 int count, int trig, int pol);
486 static void acpi_res_set_ext_irq(device_t dev, void *context,
487 u_int32_t *irq, int count, int trig, int pol);
488 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
490 static void acpi_res_set_start_dependent(device_t dev, void *context,
492 static void acpi_res_set_end_dependent(device_t dev, void *context);
494 struct acpi_parse_resource_set acpi_res_parse_set = {
498 acpi_res_set_iorange,
500 acpi_res_set_memoryrange,
502 acpi_res_set_ext_irq,
504 acpi_res_set_start_dependent,
505 acpi_res_set_end_dependent
508 struct acpi_res_context {
517 acpi_res_set_init(device_t dev, void *arg, void **context)
519 struct acpi_res_context *cp;
521 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
522 bzero(cp, sizeof(*cp));
529 acpi_res_set_done(device_t dev, void *context)
531 struct acpi_res_context *cp = (struct acpi_res_context *)context;
539 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
542 struct acpi_res_context *cp = (struct acpi_res_context *)context;
546 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length);
550 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
551 u_int32_t high, u_int32_t length, u_int32_t align)
553 struct acpi_res_context *cp = (struct acpi_res_context *)context;
557 device_printf(dev, "I/O range not supported\n");
561 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
564 struct acpi_res_context *cp = (struct acpi_res_context *)context;
569 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length);
573 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
574 u_int32_t high, u_int32_t length, u_int32_t align)
576 struct acpi_res_context *cp = (struct acpi_res_context *)context;
580 device_printf(dev, "memory range not supported\n");
584 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
587 struct acpi_res_context *cp = (struct acpi_res_context *)context;
589 if (cp == NULL || irq == NULL)
592 /* This implements no resource relocation. */
596 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
600 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
603 struct acpi_res_context *cp = (struct acpi_res_context *)context;
605 if (cp == NULL || irq == NULL)
608 /* This implements no resource relocation. */
612 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
616 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
618 struct acpi_res_context *cp = (struct acpi_res_context *)context;
620 if (cp == NULL || drq == NULL)
623 /* This implements no resource relocation. */
627 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1);
631 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
633 struct acpi_res_context *cp = (struct acpi_res_context *)context;
637 device_printf(dev, "dependent functions not supported\n");
641 acpi_res_set_end_dependent(device_t dev, void *context)
643 struct acpi_res_context *cp = (struct acpi_res_context *)context;
647 device_printf(dev, "dependent functions not supported\n");
651 * Resource-owning placeholders for IO and memory pseudo-devices.
653 * This code allocates system resources that will be used by ACPI
654 * child devices. The acpi parent manages these resources through a
658 static int acpi_sysres_rid = 100;
660 static int acpi_sysres_probe(device_t dev);
661 static int acpi_sysres_attach(device_t dev);
663 static device_method_t acpi_sysres_methods[] = {
664 /* Device interface */
665 DEVMETHOD(device_probe, acpi_sysres_probe),
666 DEVMETHOD(device_attach, acpi_sysres_attach),
671 static driver_t acpi_sysres_driver = {
677 static devclass_t acpi_sysres_devclass;
678 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
680 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
683 acpi_sysres_probe(device_t dev)
685 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
687 if (acpi_disabled("sysresource") ||
688 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
691 device_set_desc(dev, "System Resource");
693 return (BUS_PROBE_DEFAULT);
697 acpi_sysres_attach(device_t dev)
700 struct resource_list_entry *bus_rle, *dev_rle;
701 struct resource_list *bus_rl, *dev_rl;
703 u_long start, end, count;
706 * Loop through all current resources to see if the new one overlaps
707 * any existing ones. If so, grow the old one up and/or down
708 * accordingly. Discard any that are wholly contained in the old. If
709 * the resource is unique, add it to the parent. It will later go into
712 bus = device_get_parent(dev);
713 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
714 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
715 STAILQ_FOREACH(dev_rle, dev_rl, link) {
716 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
719 start = dev_rle->start;
721 count = dev_rle->count;
722 type = dev_rle->type;
725 STAILQ_FOREACH(bus_rle, bus_rl, link) {
726 if (bus_rle->type != type)
729 /* New resource wholly contained in old, discard. */
730 if (start >= bus_rle->start && end <= bus_rle->end)
733 /* New tail overlaps old head, grow existing resource downward. */
734 if (start < bus_rle->start && end >= bus_rle->start) {
735 bus_rle->count += bus_rle->start - start;
736 bus_rle->start = start;
740 /* New head overlaps old tail, grow existing resource upward. */
741 if (start <= bus_rle->end && end > bus_rle->end) {
742 bus_rle->count += end - bus_rle->end;
747 /* If we adjusted the old resource, we're finished. */
752 /* If we didn't merge with anything, add this resource. */
754 bus_set_resource(bus, type, acpi_sysres_rid++, start, count);
757 /* After merging/moving resources to the parent, free the list. */
758 resource_list_free(dev_rl);