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) {
131 kprintf("acpi_config_intr: Skip SCI config\n");
135 BUS_CONFIG_INTR(dev, dev, irq, (trig == ACPI_EDGE_SENSITIVE) ?
136 INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ?
137 INTR_POLARITY_HIGH : INTR_POLARITY_LOW);
141 * Fetch a device's resources and associate them with the device.
143 * Note that it might be nice to also locate ACPI-specific resource items, such
146 * We really need to split the resource-fetching code out from the
147 * resource-parsing code, since we may want to use the parsing
148 * code for _PRS someday.
151 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
152 struct acpi_parse_resource_set *set, void *arg)
160 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
163 * Special-case some devices that abuse _PRS/_CRS to mean
164 * something other than "I consume this resource".
166 * XXX do we really need this? It's only relevant once
167 * we start always-allocating these resources, and even
168 * then, the only special-cased device is likely to be
169 * the PCI interrupt link.
172 /* Fetch the device's current resources. */
173 buf.Length = ACPI_ALLOCATE_BUFFER;
174 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
175 if (status != AE_NOT_FOUND && status != AE_TYPE)
176 kprintf("can't fetch resources for %s - %s\n",
177 acpi_name(handle), AcpiFormatException(status));
178 return_ACPI_STATUS (status);
180 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
181 acpi_name(handle), (long)buf.Length));
182 set->set_init(dev, arg, &context);
184 /* Iterate through the resources */
186 last = (char *)buf.Pointer + buf.Length;
187 while (curr < last) {
188 res = (ACPI_RESOURCE *)curr;
191 /* Handle the individual resource types */
193 case ACPI_RESOURCE_TYPE_END_TAG:
194 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
197 case ACPI_RESOURCE_TYPE_FIXED_IO:
198 if (res->Data.FixedIo.AddressLength <= 0)
200 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
201 res->Data.FixedIo.Address,
202 res->Data.FixedIo.AddressLength));
203 set->set_ioport(dev, context,
204 res->Data.FixedIo.Address,
205 res->Data.FixedIo.AddressLength);
207 case ACPI_RESOURCE_TYPE_IO:
208 if (res->Data.Io.AddressLength <= 0)
210 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
211 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
212 res->Data.Io.Minimum,
213 res->Data.Io.AddressLength));
214 set->set_ioport(dev, context,
215 res->Data.Io.Minimum,
216 res->Data.Io.AddressLength);
218 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
219 res->Data.Io.Minimum,
220 res->Data.Io.Maximum,
221 res->Data.Io.AddressLength));
222 set->set_iorange(dev, context,
223 res->Data.Io.Minimum,
224 res->Data.Io.Maximum,
225 res->Data.Io.AddressLength,
226 res->Data.Io.Alignment);
229 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
230 if (res->Data.FixedMemory32.AddressLength <= 0)
232 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
233 res->Data.FixedMemory32.Address,
234 res->Data.FixedMemory32.AddressLength));
235 set->set_memory(dev, context,
236 res->Data.FixedMemory32.Address,
237 res->Data.FixedMemory32.AddressLength);
239 case ACPI_RESOURCE_TYPE_MEMORY32:
240 if (res->Data.Memory32.AddressLength <= 0)
242 if (res->Data.Memory32.Minimum ==
243 res->Data.Memory32.Maximum) {
245 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
246 res->Data.Memory32.Minimum,
247 res->Data.Memory32.AddressLength));
248 set->set_memory(dev, context,
249 res->Data.Memory32.Minimum,
250 res->Data.Memory32.AddressLength);
252 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
253 res->Data.Memory32.Minimum,
254 res->Data.Memory32.Maximum,
255 res->Data.Memory32.AddressLength));
256 set->set_memoryrange(dev, context,
257 res->Data.Memory32.Minimum,
258 res->Data.Memory32.Maximum,
259 res->Data.Memory32.AddressLength,
260 res->Data.Memory32.Alignment);
263 case ACPI_RESOURCE_TYPE_MEMORY24:
264 if (res->Data.Memory24.AddressLength <= 0)
266 if (res->Data.Memory24.Minimum ==
267 res->Data.Memory24.Maximum) {
269 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
270 res->Data.Memory24.Minimum,
271 res->Data.Memory24.AddressLength));
272 set->set_memory(dev, context, res->Data.Memory24.Minimum,
273 res->Data.Memory24.AddressLength);
275 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
276 res->Data.Memory24.Minimum,
277 res->Data.Memory24.Maximum,
278 res->Data.Memory24.AddressLength));
279 set->set_memoryrange(dev, context,
280 res->Data.Memory24.Minimum,
281 res->Data.Memory24.Maximum,
282 res->Data.Memory24.AddressLength,
283 res->Data.Memory24.Alignment);
286 case ACPI_RESOURCE_TYPE_IRQ:
289 * "This structure is repeated for each separate interrupt
292 set->set_irq(dev, context, res->Data.Irq.Interrupts,
293 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
294 res->Data.Irq.Polarity);
296 case ACPI_RESOURCE_TYPE_DMA:
299 * "This structure is repeated for each separate dma channel
302 set->set_drq(dev, context, res->Data.Dma.Channels,
303 res->Data.Dma.ChannelCount);
305 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
306 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
307 set->set_start_dependent(dev, context,
308 res->Data.StartDpf.CompatibilityPriority);
310 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
311 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
312 set->set_end_dependent(dev, context);
314 case ACPI_RESOURCE_TYPE_ADDRESS32:
315 if (res->Data.Address32.AddressLength <= 0)
317 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
318 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
319 "ignored Address32 %s producer\n",
320 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
324 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
325 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
326 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
327 "ignored Address32 for non-memory, non-I/O\n"));
331 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
332 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
334 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
335 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
336 "Address32/Memory 0x%x/%d\n",
337 res->Data.Address32.Minimum,
338 res->Data.Address32.AddressLength));
339 set->set_memory(dev, context,
340 res->Data.Address32.Minimum,
341 res->Data.Address32.AddressLength);
343 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
344 "Address32/IO 0x%x/%d\n",
345 res->Data.Address32.Minimum,
346 res->Data.Address32.AddressLength));
347 set->set_ioport(dev, context,
348 res->Data.Address32.Minimum,
349 res->Data.Address32.AddressLength);
352 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
353 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
354 "Address32/Memory 0x%x-0x%x/%d\n",
355 res->Data.Address32.Minimum,
356 res->Data.Address32.Maximum,
357 res->Data.Address32.AddressLength));
358 set->set_memoryrange(dev, context,
359 res->Data.Address32.Minimum,
360 res->Data.Address32.Maximum,
361 res->Data.Address32.AddressLength,
362 res->Data.Address32.Granularity);
364 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
365 "Address32/IO 0x%x-0x%x/%d\n",
366 res->Data.Address32.Minimum,
367 res->Data.Address32.Maximum,
368 res->Data.Address32.AddressLength));
369 set->set_iorange(dev, context,
370 res->Data.Address32.Minimum,
371 res->Data.Address32.Maximum,
372 res->Data.Address32.AddressLength,
373 res->Data.Address32.Granularity);
377 case ACPI_RESOURCE_TYPE_ADDRESS16:
378 if (res->Data.Address16.AddressLength <= 0)
380 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
381 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
382 "ignored Address16 %s producer\n",
383 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
387 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
388 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
389 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
390 "ignored Address16 for non-memory, non-I/O\n"));
394 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
395 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
397 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
398 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
399 "Address16/Memory 0x%x/%d\n",
400 res->Data.Address16.Minimum,
401 res->Data.Address16.AddressLength));
402 set->set_memory(dev, context,
403 res->Data.Address16.Minimum,
404 res->Data.Address16.AddressLength);
406 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
407 "Address16/IO 0x%x/%d\n",
408 res->Data.Address16.Minimum,
409 res->Data.Address16.AddressLength));
410 set->set_ioport(dev, context,
411 res->Data.Address16.Minimum,
412 res->Data.Address16.AddressLength);
415 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
416 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
417 "Address16/Memory 0x%x-0x%x/%d\n",
418 res->Data.Address16.Minimum,
419 res->Data.Address16.Maximum,
420 res->Data.Address16.AddressLength));
421 set->set_memoryrange(dev, context,
422 res->Data.Address16.Minimum,
423 res->Data.Address16.Maximum,
424 res->Data.Address16.AddressLength,
425 res->Data.Address16.Granularity);
427 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
428 "Address16/IO 0x%x-0x%x/%d\n",
429 res->Data.Address16.Minimum,
430 res->Data.Address16.Maximum,
431 res->Data.Address16.AddressLength));
432 set->set_iorange(dev, context,
433 res->Data.Address16.Minimum,
434 res->Data.Address16.Maximum,
435 res->Data.Address16.AddressLength,
436 res->Data.Address16.Granularity);
440 case ACPI_RESOURCE_TYPE_ADDRESS64:
441 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
442 "unimplemented Address64 resource\n"));
444 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
445 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
446 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
447 "ignored ExtIRQ producer\n"));
450 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
451 res->Data.ExtendedIrq.InterruptCount,
452 res->Data.ExtendedIrq.Triggering,
453 res->Data.ExtendedIrq.Polarity);
455 case ACPI_RESOURCE_TYPE_VENDOR:
456 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
457 "unimplemented VendorSpecific resource\n"));
464 AcpiOsFree(buf.Pointer);
465 set->set_done(dev, context);
466 return_ACPI_STATUS (AE_OK);
470 * Resource-set vectors used to attach _CRS-derived resources
473 static void acpi_res_set_init(device_t dev, void *arg, void **context);
474 static void acpi_res_set_done(device_t dev, void *context);
475 static void acpi_res_set_ioport(device_t dev, void *context,
476 u_int32_t base, u_int32_t length);
477 static void acpi_res_set_iorange(device_t dev, void *context,
478 u_int32_t low, u_int32_t high,
479 u_int32_t length, u_int32_t align);
480 static void acpi_res_set_memory(device_t dev, void *context,
481 u_int32_t base, u_int32_t length);
482 static void acpi_res_set_memoryrange(device_t dev, void *context,
483 u_int32_t low, u_int32_t high,
484 u_int32_t length, u_int32_t align);
485 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
486 int count, int trig, int pol);
487 static void acpi_res_set_ext_irq(device_t dev, void *context,
488 u_int32_t *irq, int count, int trig, int pol);
489 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
491 static void acpi_res_set_start_dependent(device_t dev, void *context,
493 static void acpi_res_set_end_dependent(device_t dev, void *context);
495 struct acpi_parse_resource_set acpi_res_parse_set = {
499 acpi_res_set_iorange,
501 acpi_res_set_memoryrange,
503 acpi_res_set_ext_irq,
505 acpi_res_set_start_dependent,
506 acpi_res_set_end_dependent
509 struct acpi_res_context {
518 acpi_res_set_init(device_t dev, void *arg, void **context)
520 struct acpi_res_context *cp;
522 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
523 bzero(cp, sizeof(*cp));
530 acpi_res_set_done(device_t dev, void *context)
532 struct acpi_res_context *cp = (struct acpi_res_context *)context;
540 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
543 struct acpi_res_context *cp = (struct acpi_res_context *)context;
547 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length);
551 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
552 u_int32_t high, u_int32_t length, u_int32_t align)
554 struct acpi_res_context *cp = (struct acpi_res_context *)context;
558 device_printf(dev, "I/O range not supported\n");
562 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
565 struct acpi_res_context *cp = (struct acpi_res_context *)context;
570 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length);
574 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
575 u_int32_t high, u_int32_t length, u_int32_t align)
577 struct acpi_res_context *cp = (struct acpi_res_context *)context;
581 device_printf(dev, "memory range not supported\n");
585 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
588 struct acpi_res_context *cp = (struct acpi_res_context *)context;
590 if (cp == NULL || irq == NULL)
593 /* This implements no resource relocation. */
597 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
601 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
604 struct acpi_res_context *cp = (struct acpi_res_context *)context;
606 if (cp == NULL || irq == NULL)
609 /* This implements no resource relocation. */
613 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
617 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
619 struct acpi_res_context *cp = (struct acpi_res_context *)context;
621 if (cp == NULL || drq == NULL)
624 /* This implements no resource relocation. */
628 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1);
632 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
634 struct acpi_res_context *cp = (struct acpi_res_context *)context;
638 device_printf(dev, "dependent functions not supported\n");
642 acpi_res_set_end_dependent(device_t dev, void *context)
644 struct acpi_res_context *cp = (struct acpi_res_context *)context;
648 device_printf(dev, "dependent functions not supported\n");
652 * Resource-owning placeholders for IO and memory pseudo-devices.
654 * This code allocates system resources that will be used by ACPI
655 * child devices. The acpi parent manages these resources through a
659 static int acpi_sysres_rid = 100;
661 static int acpi_sysres_probe(device_t dev);
662 static int acpi_sysres_attach(device_t dev);
664 static device_method_t acpi_sysres_methods[] = {
665 /* Device interface */
666 DEVMETHOD(device_probe, acpi_sysres_probe),
667 DEVMETHOD(device_attach, acpi_sysres_attach),
672 static driver_t acpi_sysres_driver = {
678 static devclass_t acpi_sysres_devclass;
679 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
681 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
684 acpi_sysres_probe(device_t dev)
686 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
688 if (acpi_disabled("sysresource") ||
689 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
692 device_set_desc(dev, "System Resource");
694 return (BUS_PROBE_DEFAULT);
698 acpi_sysres_attach(device_t dev)
701 struct resource_list_entry *bus_rle, *dev_rle;
702 struct resource_list *bus_rl, *dev_rl;
704 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);
716 kprintf("busrl is not null!\n");
717 SLIST_FOREACH(dev_rle, dev_rl, link) {
718 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
721 start = dev_rle->start;
723 count = dev_rle->count;
724 type = dev_rle->type;
727 SLIST_FOREACH(bus_rle, bus_rl, link) {
728 if (bus_rle->type != type)
731 /* New resource wholly contained in old, discard. */
732 if (start >= bus_rle->start && end <= bus_rle->end)
735 /* New tail overlaps old head, grow existing resource downward. */
736 if (start < bus_rle->start && end >= bus_rle->start) {
737 bus_rle->count += bus_rle->start - start;
738 bus_rle->start = start;
742 /* New head overlaps old tail, grow existing resource upward. */
743 if (start <= bus_rle->end && end > bus_rle->end) {
744 bus_rle->count += end - bus_rle->end;
749 /* If we adjusted the old resource, we're finished. */
753 } else bus_rle = NULL;
754 /* If we didn't merge with anything, add this resource. */
755 if (bus_rle == NULL) {
756 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);