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>
37 #include <sys/machintr.h>
42 #include <dev/acpica5/acpivar.h>
44 /* Hooks for the ACPI CA debugging infrastructure */
45 #define _COMPONENT ACPI_BUS
46 ACPI_MODULE_NAME("RESOURCE")
48 struct lookup_irq_request {
49 ACPI_RESOURCE *acpi_res;
57 acpi_lookup_irq_handler(ACPI_RESOURCE *res, void *context)
59 struct lookup_irq_request *req;
64 case ACPI_RESOURCE_TYPE_IRQ:
65 irqnum = res->Data.Irq.InterruptCount;
66 irq = res->Data.Irq.Interrupts[0];
67 len = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
69 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
70 irqnum = res->Data.ExtendedIrq.InterruptCount;
71 irq = res->Data.ExtendedIrq.Interrupts[0];
72 len = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
79 req = (struct lookup_irq_request *)context;
80 if (req->counter != req->rid) {
85 KASSERT(irq == rman_get_start(req->res),
86 ("IRQ resources do not match"));
87 bcopy(res, req->acpi_res, len);
88 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)
115 enum intr_trigger trigger;
116 enum intr_polarity polarity;
119 case ACPI_RESOURCE_TYPE_IRQ:
120 KASSERT(res->Data.Irq.InterruptCount == 1,
121 ("%s: multiple interrupts", __func__));
122 irq = res->Data.Irq.Interrupts[0];
123 trig = res->Data.Irq.Triggering;
124 pol = res->Data.Irq.Polarity;
126 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
127 KASSERT(res->Data.ExtendedIrq.InterruptCount == 1,
128 ("%s: multiple interrupts", __func__));
129 irq = res->Data.ExtendedIrq.Interrupts[0];
130 trig = res->Data.ExtendedIrq.Triggering;
131 pol = res->Data.ExtendedIrq.Polarity;
134 panic("%s: bad resource type %u", __func__, res->Type);
137 if (trig == ACPI_EDGE_SENSITIVE)
138 trigger = INTR_TRIGGER_EDGE;
140 trigger = INTR_TRIGGER_LEVEL;
142 if (pol == ACPI_ACTIVE_HIGH)
143 polarity = INTR_POLARITY_HIGH;
145 polarity = INTR_POLARITY_LOW;
147 if (machintr_legacy_intr_find(irq, trigger, polarity) < 0) {
149 kprintf("acpi_config_intr: Skip irq %d config\n", irq);
151 BUS_CONFIG_INTR(dev, dev, irq, trigger, polarity);
156 * Fetch a device's resources and associate them with the device.
158 * Note that it might be nice to also locate ACPI-specific resource items, such
161 * We really need to split the resource-fetching code out from the
162 * resource-parsing code, since we may want to use the parsing
163 * code for _PRS someday.
166 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
167 struct acpi_parse_resource_set *set, void *arg)
175 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
178 * Special-case some devices that abuse _PRS/_CRS to mean
179 * something other than "I consume this resource".
181 * XXX do we really need this? It's only relevant once
182 * we start always-allocating these resources, and even
183 * then, the only special-cased device is likely to be
184 * the PCI interrupt link.
187 /* Fetch the device's current resources. */
188 buf.Length = ACPI_ALLOCATE_BUFFER;
189 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
190 if (status != AE_NOT_FOUND && status != AE_TYPE)
191 kprintf("can't fetch resources for %s - %s\n",
192 acpi_name(handle), AcpiFormatException(status));
193 return_ACPI_STATUS (status);
195 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
196 acpi_name(handle), (long)buf.Length));
197 set->set_init(dev, arg, &context);
199 /* Iterate through the resources */
201 last = (char *)buf.Pointer + buf.Length;
202 while (curr < last) {
203 res = (ACPI_RESOURCE *)curr;
206 /* Handle the individual resource types */
208 case ACPI_RESOURCE_TYPE_END_TAG:
209 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
212 case ACPI_RESOURCE_TYPE_FIXED_IO:
213 if (res->Data.FixedIo.AddressLength <= 0)
215 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
216 res->Data.FixedIo.Address,
217 res->Data.FixedIo.AddressLength));
218 set->set_ioport(dev, context,
219 res->Data.FixedIo.Address,
220 res->Data.FixedIo.AddressLength);
222 case ACPI_RESOURCE_TYPE_IO:
223 if (res->Data.Io.AddressLength <= 0)
225 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
226 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
227 res->Data.Io.Minimum,
228 res->Data.Io.AddressLength));
229 set->set_ioport(dev, context,
230 res->Data.Io.Minimum,
231 res->Data.Io.AddressLength);
233 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
234 res->Data.Io.Minimum,
235 res->Data.Io.Maximum,
236 res->Data.Io.AddressLength));
237 set->set_iorange(dev, context,
238 res->Data.Io.Minimum,
239 res->Data.Io.Maximum,
240 res->Data.Io.AddressLength,
241 res->Data.Io.Alignment);
244 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
245 if (res->Data.FixedMemory32.AddressLength <= 0)
247 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
248 res->Data.FixedMemory32.Address,
249 res->Data.FixedMemory32.AddressLength));
250 set->set_memory(dev, context,
251 res->Data.FixedMemory32.Address,
252 res->Data.FixedMemory32.AddressLength);
254 case ACPI_RESOURCE_TYPE_MEMORY32:
255 if (res->Data.Memory32.AddressLength <= 0)
257 if (res->Data.Memory32.Minimum ==
258 res->Data.Memory32.Maximum) {
260 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
261 res->Data.Memory32.Minimum,
262 res->Data.Memory32.AddressLength));
263 set->set_memory(dev, context,
264 res->Data.Memory32.Minimum,
265 res->Data.Memory32.AddressLength);
267 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
268 res->Data.Memory32.Minimum,
269 res->Data.Memory32.Maximum,
270 res->Data.Memory32.AddressLength));
271 set->set_memoryrange(dev, context,
272 res->Data.Memory32.Minimum,
273 res->Data.Memory32.Maximum,
274 res->Data.Memory32.AddressLength,
275 res->Data.Memory32.Alignment);
278 case ACPI_RESOURCE_TYPE_MEMORY24:
279 if (res->Data.Memory24.AddressLength <= 0)
281 if (res->Data.Memory24.Minimum ==
282 res->Data.Memory24.Maximum) {
284 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
285 res->Data.Memory24.Minimum,
286 res->Data.Memory24.AddressLength));
287 set->set_memory(dev, context, res->Data.Memory24.Minimum,
288 res->Data.Memory24.AddressLength);
290 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
291 res->Data.Memory24.Minimum,
292 res->Data.Memory24.Maximum,
293 res->Data.Memory24.AddressLength));
294 set->set_memoryrange(dev, context,
295 res->Data.Memory24.Minimum,
296 res->Data.Memory24.Maximum,
297 res->Data.Memory24.AddressLength,
298 res->Data.Memory24.Alignment);
301 case ACPI_RESOURCE_TYPE_IRQ:
304 * "This structure is repeated for each separate interrupt
307 set->set_irq(dev, context, res->Data.Irq.Interrupts,
308 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
309 res->Data.Irq.Polarity);
311 case ACPI_RESOURCE_TYPE_DMA:
314 * "This structure is repeated for each separate dma channel
317 set->set_drq(dev, context, res->Data.Dma.Channels,
318 res->Data.Dma.ChannelCount);
320 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
321 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
322 set->set_start_dependent(dev, context,
323 res->Data.StartDpf.CompatibilityPriority);
325 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
326 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
327 set->set_end_dependent(dev, context);
329 case ACPI_RESOURCE_TYPE_ADDRESS32:
330 if (res->Data.Address32.AddressLength <= 0)
332 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
333 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
334 "ignored Address32 %s producer\n",
335 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
339 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
340 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
341 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
342 "ignored Address32 for non-memory, non-I/O\n"));
346 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
347 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
349 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
350 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
351 "Address32/Memory 0x%x/%d\n",
352 res->Data.Address32.Minimum,
353 res->Data.Address32.AddressLength));
354 set->set_memory(dev, context,
355 res->Data.Address32.Minimum,
356 res->Data.Address32.AddressLength);
358 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
359 "Address32/IO 0x%x/%d\n",
360 res->Data.Address32.Minimum,
361 res->Data.Address32.AddressLength));
362 set->set_ioport(dev, context,
363 res->Data.Address32.Minimum,
364 res->Data.Address32.AddressLength);
367 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
368 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
369 "Address32/Memory 0x%x-0x%x/%d\n",
370 res->Data.Address32.Minimum,
371 res->Data.Address32.Maximum,
372 res->Data.Address32.AddressLength));
373 set->set_memoryrange(dev, context,
374 res->Data.Address32.Minimum,
375 res->Data.Address32.Maximum,
376 res->Data.Address32.AddressLength,
377 res->Data.Address32.Granularity);
379 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
380 "Address32/IO 0x%x-0x%x/%d\n",
381 res->Data.Address32.Minimum,
382 res->Data.Address32.Maximum,
383 res->Data.Address32.AddressLength));
384 set->set_iorange(dev, context,
385 res->Data.Address32.Minimum,
386 res->Data.Address32.Maximum,
387 res->Data.Address32.AddressLength,
388 res->Data.Address32.Granularity);
392 case ACPI_RESOURCE_TYPE_ADDRESS16:
393 if (res->Data.Address16.AddressLength <= 0)
395 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
396 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
397 "ignored Address16 %s producer\n",
398 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
402 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
403 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
404 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
405 "ignored Address16 for non-memory, non-I/O\n"));
409 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
410 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
412 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
413 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
414 "Address16/Memory 0x%x/%d\n",
415 res->Data.Address16.Minimum,
416 res->Data.Address16.AddressLength));
417 set->set_memory(dev, context,
418 res->Data.Address16.Minimum,
419 res->Data.Address16.AddressLength);
421 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
422 "Address16/IO 0x%x/%d\n",
423 res->Data.Address16.Minimum,
424 res->Data.Address16.AddressLength));
425 set->set_ioport(dev, context,
426 res->Data.Address16.Minimum,
427 res->Data.Address16.AddressLength);
430 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
431 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
432 "Address16/Memory 0x%x-0x%x/%d\n",
433 res->Data.Address16.Minimum,
434 res->Data.Address16.Maximum,
435 res->Data.Address16.AddressLength));
436 set->set_memoryrange(dev, context,
437 res->Data.Address16.Minimum,
438 res->Data.Address16.Maximum,
439 res->Data.Address16.AddressLength,
440 res->Data.Address16.Granularity);
442 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
443 "Address16/IO 0x%x-0x%x/%d\n",
444 res->Data.Address16.Minimum,
445 res->Data.Address16.Maximum,
446 res->Data.Address16.AddressLength));
447 set->set_iorange(dev, context,
448 res->Data.Address16.Minimum,
449 res->Data.Address16.Maximum,
450 res->Data.Address16.AddressLength,
451 res->Data.Address16.Granularity);
455 case ACPI_RESOURCE_TYPE_ADDRESS64:
456 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
457 "unimplemented Address64 resource\n"));
459 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
460 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
461 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
462 "ignored ExtIRQ producer\n"));
465 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
466 res->Data.ExtendedIrq.InterruptCount,
467 res->Data.ExtendedIrq.Triggering,
468 res->Data.ExtendedIrq.Polarity);
470 case ACPI_RESOURCE_TYPE_VENDOR:
471 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
472 "unimplemented VendorSpecific resource\n"));
479 AcpiOsFree(buf.Pointer);
480 set->set_done(dev, context);
481 return_ACPI_STATUS (AE_OK);
485 * Resource-set vectors used to attach _CRS-derived resources
488 static void acpi_res_set_init(device_t dev, void *arg, void **context);
489 static void acpi_res_set_done(device_t dev, void *context);
490 static void acpi_res_set_ioport(device_t dev, void *context,
491 u_int32_t base, u_int32_t length);
492 static void acpi_res_set_iorange(device_t dev, void *context,
493 u_int32_t low, u_int32_t high,
494 u_int32_t length, u_int32_t align);
495 static void acpi_res_set_memory(device_t dev, void *context,
496 u_int32_t base, u_int32_t length);
497 static void acpi_res_set_memoryrange(device_t dev, void *context,
498 u_int32_t low, u_int32_t high,
499 u_int32_t length, u_int32_t align);
500 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
501 int count, int trig, int pol);
502 static void acpi_res_set_ext_irq(device_t dev, void *context,
503 u_int32_t *irq, int count, int trig, int pol);
504 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
506 static void acpi_res_set_start_dependent(device_t dev, void *context,
508 static void acpi_res_set_end_dependent(device_t dev, void *context);
510 struct acpi_parse_resource_set acpi_res_parse_set = {
514 acpi_res_set_iorange,
516 acpi_res_set_memoryrange,
518 acpi_res_set_ext_irq,
520 acpi_res_set_start_dependent,
521 acpi_res_set_end_dependent
524 struct acpi_res_context {
533 acpi_res_set_init(device_t dev, void *arg, void **context)
535 struct acpi_res_context *cp;
537 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
538 bzero(cp, sizeof(*cp));
545 acpi_res_set_done(device_t dev, void *context)
547 struct acpi_res_context *cp = (struct acpi_res_context *)context;
555 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
558 struct acpi_res_context *cp = (struct acpi_res_context *)context;
562 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length, -1);
566 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
567 u_int32_t high, u_int32_t length, u_int32_t align)
569 struct acpi_res_context *cp = (struct acpi_res_context *)context;
573 device_printf(dev, "I/O range not supported\n");
577 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
580 struct acpi_res_context *cp = (struct acpi_res_context *)context;
585 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length, -1);
589 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
590 u_int32_t high, u_int32_t length, u_int32_t align)
592 struct acpi_res_context *cp = (struct acpi_res_context *)context;
596 device_printf(dev, "memory range not supported\n");
600 acpi_res_set_irq(device_t dev, void *context, u_int8_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,
613 machintr_legacy_intr_cpuid(*irq));
617 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
620 struct acpi_res_context *cp = (struct acpi_res_context *)context;
622 if (cp == NULL || irq == NULL)
625 /* This implements no resource relocation. */
629 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
630 machintr_legacy_intr_cpuid(*irq));
634 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
636 struct acpi_res_context *cp = (struct acpi_res_context *)context;
638 if (cp == NULL || drq == NULL)
641 /* This implements no resource relocation. */
645 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1, -1);
649 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
651 struct acpi_res_context *cp = (struct acpi_res_context *)context;
655 device_printf(dev, "dependent functions not supported\n");
659 acpi_res_set_end_dependent(device_t dev, void *context)
661 struct acpi_res_context *cp = (struct acpi_res_context *)context;
665 device_printf(dev, "dependent functions not supported\n");
669 * Resource-owning placeholders for IO and memory pseudo-devices.
671 * This code allocates system resources that will be used by ACPI
672 * child devices. The acpi parent manages these resources through a
676 static int acpi_sysres_rid = 100;
678 static int acpi_sysres_probe(device_t dev);
679 static int acpi_sysres_attach(device_t dev);
681 static device_method_t acpi_sysres_methods[] = {
682 /* Device interface */
683 DEVMETHOD(device_probe, acpi_sysres_probe),
684 DEVMETHOD(device_attach, acpi_sysres_attach),
689 static driver_t acpi_sysres_driver = {
695 static devclass_t acpi_sysres_devclass;
696 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
698 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
701 acpi_sysres_probe(device_t dev)
703 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
705 if (acpi_disabled("sysresource") ||
706 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
709 device_set_desc(dev, "System Resource");
711 return (BUS_PROBE_DEFAULT);
715 acpi_sysres_attach(device_t dev)
718 struct resource_list_entry *bus_rle, *dev_rle;
719 struct resource_list *bus_rl, *dev_rl;
721 u_long start, end, count;
723 * Loop through all current resources to see if the new one overlaps
724 * any existing ones. If so, grow the old one up and/or down
725 * accordingly. Discard any that are wholly contained in the old. If
726 * the resource is unique, add it to the parent. It will later go into
729 bus = device_get_parent(dev);
730 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
731 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
733 kprintf("busrl is not null!\n");
734 SLIST_FOREACH(dev_rle, dev_rl, link) {
735 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
738 start = dev_rle->start;
740 count = dev_rle->count;
741 type = dev_rle->type;
744 SLIST_FOREACH(bus_rle, bus_rl, link) {
745 if (bus_rle->type != type)
748 /* New resource wholly contained in old, discard. */
749 if (start >= bus_rle->start && end <= bus_rle->end)
752 /* New tail overlaps old head, grow existing resource downward. */
753 if (start < bus_rle->start && end >= bus_rle->start) {
754 bus_rle->count += bus_rle->start - start;
755 bus_rle->start = start;
759 /* New head overlaps old tail, grow existing resource upward. */
760 if (start <= bus_rle->end && end > bus_rle->end) {
761 bus_rle->count += end - bus_rle->end;
766 /* If we adjusted the old resource, we're finished. */
770 } else bus_rle = NULL;
771 /* If we didn't merge with anything, add this resource. */
772 if (bus_rle == NULL) {
773 bus_set_resource(bus, type, acpi_sysres_rid++, start, count, -1);
777 /* After merging/moving resources to the parent, free the list. */
778 resource_list_free(dev_rl);