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)
116 case ACPI_RESOURCE_TYPE_IRQ:
117 KASSERT(res->Data.Irq.InterruptCount == 1,
118 ("%s: multiple interrupts", __func__));
119 irq = res->Data.Irq.Interrupts[0];
120 trig = res->Data.Irq.Triggering;
121 pol = res->Data.Irq.Polarity;
123 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
124 KASSERT(res->Data.ExtendedIrq.InterruptCount == 1,
125 ("%s: multiple interrupts", __func__));
126 irq = res->Data.ExtendedIrq.Interrupts[0];
127 trig = res->Data.ExtendedIrq.Triggering;
128 pol = res->Data.ExtendedIrq.Polarity;
131 panic("%s: bad resource type %u", __func__, res->Type);
134 if (irq == AcpiGbl_FADT.SciInterrupt) {
136 kprintf("acpi_config_intr: Skip SCI config\n");
140 BUS_CONFIG_INTR(dev, dev, irq, (trig == ACPI_EDGE_SENSITIVE) ?
141 INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ?
142 INTR_POLARITY_HIGH : INTR_POLARITY_LOW);
146 * Fetch a device's resources and associate them with the device.
148 * Note that it might be nice to also locate ACPI-specific resource items, such
151 * We really need to split the resource-fetching code out from the
152 * resource-parsing code, since we may want to use the parsing
153 * code for _PRS someday.
156 acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
157 struct acpi_parse_resource_set *set, void *arg)
165 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
168 * Special-case some devices that abuse _PRS/_CRS to mean
169 * something other than "I consume this resource".
171 * XXX do we really need this? It's only relevant once
172 * we start always-allocating these resources, and even
173 * then, the only special-cased device is likely to be
174 * the PCI interrupt link.
177 /* Fetch the device's current resources. */
178 buf.Length = ACPI_ALLOCATE_BUFFER;
179 if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
180 if (status != AE_NOT_FOUND && status != AE_TYPE)
181 kprintf("can't fetch resources for %s - %s\n",
182 acpi_name(handle), AcpiFormatException(status));
183 return_ACPI_STATUS (status);
185 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
186 acpi_name(handle), (long)buf.Length));
187 set->set_init(dev, arg, &context);
189 /* Iterate through the resources */
191 last = (char *)buf.Pointer + buf.Length;
192 while (curr < last) {
193 res = (ACPI_RESOURCE *)curr;
196 /* Handle the individual resource types */
198 case ACPI_RESOURCE_TYPE_END_TAG:
199 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
202 case ACPI_RESOURCE_TYPE_FIXED_IO:
203 if (res->Data.FixedIo.AddressLength <= 0)
205 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
206 res->Data.FixedIo.Address,
207 res->Data.FixedIo.AddressLength));
208 set->set_ioport(dev, context,
209 res->Data.FixedIo.Address,
210 res->Data.FixedIo.AddressLength);
212 case ACPI_RESOURCE_TYPE_IO:
213 if (res->Data.Io.AddressLength <= 0)
215 if (res->Data.Io.Minimum == res->Data.Io.Maximum) {
216 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
217 res->Data.Io.Minimum,
218 res->Data.Io.AddressLength));
219 set->set_ioport(dev, context,
220 res->Data.Io.Minimum,
221 res->Data.Io.AddressLength);
223 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
224 res->Data.Io.Minimum,
225 res->Data.Io.Maximum,
226 res->Data.Io.AddressLength));
227 set->set_iorange(dev, context,
228 res->Data.Io.Minimum,
229 res->Data.Io.Maximum,
230 res->Data.Io.AddressLength,
231 res->Data.Io.Alignment);
234 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
235 if (res->Data.FixedMemory32.AddressLength <= 0)
237 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
238 res->Data.FixedMemory32.Address,
239 res->Data.FixedMemory32.AddressLength));
240 set->set_memory(dev, context,
241 res->Data.FixedMemory32.Address,
242 res->Data.FixedMemory32.AddressLength);
244 case ACPI_RESOURCE_TYPE_MEMORY32:
245 if (res->Data.Memory32.AddressLength <= 0)
247 if (res->Data.Memory32.Minimum ==
248 res->Data.Memory32.Maximum) {
250 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
251 res->Data.Memory32.Minimum,
252 res->Data.Memory32.AddressLength));
253 set->set_memory(dev, context,
254 res->Data.Memory32.Minimum,
255 res->Data.Memory32.AddressLength);
257 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
258 res->Data.Memory32.Minimum,
259 res->Data.Memory32.Maximum,
260 res->Data.Memory32.AddressLength));
261 set->set_memoryrange(dev, context,
262 res->Data.Memory32.Minimum,
263 res->Data.Memory32.Maximum,
264 res->Data.Memory32.AddressLength,
265 res->Data.Memory32.Alignment);
268 case ACPI_RESOURCE_TYPE_MEMORY24:
269 if (res->Data.Memory24.AddressLength <= 0)
271 if (res->Data.Memory24.Minimum ==
272 res->Data.Memory24.Maximum) {
274 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
275 res->Data.Memory24.Minimum,
276 res->Data.Memory24.AddressLength));
277 set->set_memory(dev, context, res->Data.Memory24.Minimum,
278 res->Data.Memory24.AddressLength);
280 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
281 res->Data.Memory24.Minimum,
282 res->Data.Memory24.Maximum,
283 res->Data.Memory24.AddressLength));
284 set->set_memoryrange(dev, context,
285 res->Data.Memory24.Minimum,
286 res->Data.Memory24.Maximum,
287 res->Data.Memory24.AddressLength,
288 res->Data.Memory24.Alignment);
291 case ACPI_RESOURCE_TYPE_IRQ:
294 * "This structure is repeated for each separate interrupt
297 set->set_irq(dev, context, res->Data.Irq.Interrupts,
298 res->Data.Irq.InterruptCount, res->Data.Irq.Triggering,
299 res->Data.Irq.Polarity);
301 case ACPI_RESOURCE_TYPE_DMA:
304 * "This structure is repeated for each separate dma channel
307 set->set_drq(dev, context, res->Data.Dma.Channels,
308 res->Data.Dma.ChannelCount);
310 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
311 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependent functions\n"));
312 set->set_start_dependent(dev, context,
313 res->Data.StartDpf.CompatibilityPriority);
315 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
316 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependent functions\n"));
317 set->set_end_dependent(dev, context);
319 case ACPI_RESOURCE_TYPE_ADDRESS32:
320 if (res->Data.Address32.AddressLength <= 0)
322 if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
323 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
324 "ignored Address32 %s producer\n",
325 res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
329 if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
330 res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
331 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
332 "ignored Address32 for non-memory, non-I/O\n"));
336 if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
337 res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
339 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
340 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
341 "Address32/Memory 0x%x/%d\n",
342 res->Data.Address32.Minimum,
343 res->Data.Address32.AddressLength));
344 set->set_memory(dev, context,
345 res->Data.Address32.Minimum,
346 res->Data.Address32.AddressLength);
348 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
349 "Address32/IO 0x%x/%d\n",
350 res->Data.Address32.Minimum,
351 res->Data.Address32.AddressLength));
352 set->set_ioport(dev, context,
353 res->Data.Address32.Minimum,
354 res->Data.Address32.AddressLength);
357 if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
358 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
359 "Address32/Memory 0x%x-0x%x/%d\n",
360 res->Data.Address32.Minimum,
361 res->Data.Address32.Maximum,
362 res->Data.Address32.AddressLength));
363 set->set_memoryrange(dev, context,
364 res->Data.Address32.Minimum,
365 res->Data.Address32.Maximum,
366 res->Data.Address32.AddressLength,
367 res->Data.Address32.Granularity);
369 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
370 "Address32/IO 0x%x-0x%x/%d\n",
371 res->Data.Address32.Minimum,
372 res->Data.Address32.Maximum,
373 res->Data.Address32.AddressLength));
374 set->set_iorange(dev, context,
375 res->Data.Address32.Minimum,
376 res->Data.Address32.Maximum,
377 res->Data.Address32.AddressLength,
378 res->Data.Address32.Granularity);
382 case ACPI_RESOURCE_TYPE_ADDRESS16:
383 if (res->Data.Address16.AddressLength <= 0)
385 if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
386 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
387 "ignored Address16 %s producer\n",
388 res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
392 if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
393 res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
394 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
395 "ignored Address16 for non-memory, non-I/O\n"));
399 if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
400 res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
402 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
403 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
404 "Address16/Memory 0x%x/%d\n",
405 res->Data.Address16.Minimum,
406 res->Data.Address16.AddressLength));
407 set->set_memory(dev, context,
408 res->Data.Address16.Minimum,
409 res->Data.Address16.AddressLength);
411 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
412 "Address16/IO 0x%x/%d\n",
413 res->Data.Address16.Minimum,
414 res->Data.Address16.AddressLength));
415 set->set_ioport(dev, context,
416 res->Data.Address16.Minimum,
417 res->Data.Address16.AddressLength);
420 if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
421 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
422 "Address16/Memory 0x%x-0x%x/%d\n",
423 res->Data.Address16.Minimum,
424 res->Data.Address16.Maximum,
425 res->Data.Address16.AddressLength));
426 set->set_memoryrange(dev, context,
427 res->Data.Address16.Minimum,
428 res->Data.Address16.Maximum,
429 res->Data.Address16.AddressLength,
430 res->Data.Address16.Granularity);
432 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
433 "Address16/IO 0x%x-0x%x/%d\n",
434 res->Data.Address16.Minimum,
435 res->Data.Address16.Maximum,
436 res->Data.Address16.AddressLength));
437 set->set_iorange(dev, context,
438 res->Data.Address16.Minimum,
439 res->Data.Address16.Maximum,
440 res->Data.Address16.AddressLength,
441 res->Data.Address16.Granularity);
445 case ACPI_RESOURCE_TYPE_ADDRESS64:
446 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
447 "unimplemented Address64 resource\n"));
449 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
450 if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
451 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
452 "ignored ExtIRQ producer\n"));
455 set->set_ext_irq(dev, context, res->Data.ExtendedIrq.Interrupts,
456 res->Data.ExtendedIrq.InterruptCount,
457 res->Data.ExtendedIrq.Triggering,
458 res->Data.ExtendedIrq.Polarity);
460 case ACPI_RESOURCE_TYPE_VENDOR:
461 ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
462 "unimplemented VendorSpecific resource\n"));
469 AcpiOsFree(buf.Pointer);
470 set->set_done(dev, context);
471 return_ACPI_STATUS (AE_OK);
475 * Resource-set vectors used to attach _CRS-derived resources
478 static void acpi_res_set_init(device_t dev, void *arg, void **context);
479 static void acpi_res_set_done(device_t dev, void *context);
480 static void acpi_res_set_ioport(device_t dev, void *context,
481 u_int32_t base, u_int32_t length);
482 static void acpi_res_set_iorange(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_memory(device_t dev, void *context,
486 u_int32_t base, u_int32_t length);
487 static void acpi_res_set_memoryrange(device_t dev, void *context,
488 u_int32_t low, u_int32_t high,
489 u_int32_t length, u_int32_t align);
490 static void acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq,
491 int count, int trig, int pol);
492 static void acpi_res_set_ext_irq(device_t dev, void *context,
493 u_int32_t *irq, int count, int trig, int pol);
494 static void acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq,
496 static void acpi_res_set_start_dependent(device_t dev, void *context,
498 static void acpi_res_set_end_dependent(device_t dev, void *context);
500 struct acpi_parse_resource_set acpi_res_parse_set = {
504 acpi_res_set_iorange,
506 acpi_res_set_memoryrange,
508 acpi_res_set_ext_irq,
510 acpi_res_set_start_dependent,
511 acpi_res_set_end_dependent
514 struct acpi_res_context {
523 acpi_res_set_init(device_t dev, void *arg, void **context)
525 struct acpi_res_context *cp;
527 if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
528 bzero(cp, sizeof(*cp));
535 acpi_res_set_done(device_t dev, void *context)
537 struct acpi_res_context *cp = (struct acpi_res_context *)context;
545 acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
548 struct acpi_res_context *cp = (struct acpi_res_context *)context;
552 bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length, -1);
556 acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
557 u_int32_t high, u_int32_t length, u_int32_t align)
559 struct acpi_res_context *cp = (struct acpi_res_context *)context;
563 device_printf(dev, "I/O range not supported\n");
567 acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
570 struct acpi_res_context *cp = (struct acpi_res_context *)context;
575 bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length, -1);
579 acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
580 u_int32_t high, u_int32_t length, u_int32_t align)
582 struct acpi_res_context *cp = (struct acpi_res_context *)context;
586 device_printf(dev, "memory range not supported\n");
590 acpi_res_set_irq(device_t dev, void *context, u_int8_t *irq, int count,
593 struct acpi_res_context *cp = (struct acpi_res_context *)context;
595 if (cp == NULL || irq == NULL)
598 /* This implements no resource relocation. */
602 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
603 machintr_legacy_intr_cpuid(*irq));
607 acpi_res_set_ext_irq(device_t dev, void *context, u_int32_t *irq, int count,
610 struct acpi_res_context *cp = (struct acpi_res_context *)context;
612 if (cp == NULL || irq == NULL)
615 /* This implements no resource relocation. */
619 bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1,
620 machintr_legacy_intr_cpuid(*irq));
624 acpi_res_set_drq(device_t dev, void *context, u_int8_t *drq, int count)
626 struct acpi_res_context *cp = (struct acpi_res_context *)context;
628 if (cp == NULL || drq == NULL)
631 /* This implements no resource relocation. */
635 bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1, -1);
639 acpi_res_set_start_dependent(device_t dev, void *context, int preference)
641 struct acpi_res_context *cp = (struct acpi_res_context *)context;
645 device_printf(dev, "dependent functions not supported\n");
649 acpi_res_set_end_dependent(device_t dev, void *context)
651 struct acpi_res_context *cp = (struct acpi_res_context *)context;
655 device_printf(dev, "dependent functions not supported\n");
659 * Resource-owning placeholders for IO and memory pseudo-devices.
661 * This code allocates system resources that will be used by ACPI
662 * child devices. The acpi parent manages these resources through a
666 static int acpi_sysres_rid = 100;
668 static int acpi_sysres_probe(device_t dev);
669 static int acpi_sysres_attach(device_t dev);
671 static device_method_t acpi_sysres_methods[] = {
672 /* Device interface */
673 DEVMETHOD(device_probe, acpi_sysres_probe),
674 DEVMETHOD(device_attach, acpi_sysres_attach),
679 static driver_t acpi_sysres_driver = {
685 static devclass_t acpi_sysres_devclass;
686 DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
688 MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
691 acpi_sysres_probe(device_t dev)
693 static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
695 if (acpi_disabled("sysresource") ||
696 ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
699 device_set_desc(dev, "System Resource");
701 return (BUS_PROBE_DEFAULT);
705 acpi_sysres_attach(device_t dev)
708 struct resource_list_entry *bus_rle, *dev_rle;
709 struct resource_list *bus_rl, *dev_rl;
711 u_long start, end, count;
713 * Loop through all current resources to see if the new one overlaps
714 * any existing ones. If so, grow the old one up and/or down
715 * accordingly. Discard any that are wholly contained in the old. If
716 * the resource is unique, add it to the parent. It will later go into
719 bus = device_get_parent(dev);
720 dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
721 bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
723 kprintf("busrl is not null!\n");
724 SLIST_FOREACH(dev_rle, dev_rl, link) {
725 if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
728 start = dev_rle->start;
730 count = dev_rle->count;
731 type = dev_rle->type;
734 SLIST_FOREACH(bus_rle, bus_rl, link) {
735 if (bus_rle->type != type)
738 /* New resource wholly contained in old, discard. */
739 if (start >= bus_rle->start && end <= bus_rle->end)
742 /* New tail overlaps old head, grow existing resource downward. */
743 if (start < bus_rle->start && end >= bus_rle->start) {
744 bus_rle->count += bus_rle->start - start;
745 bus_rle->start = start;
749 /* New head overlaps old tail, grow existing resource upward. */
750 if (start <= bus_rle->end && end > bus_rle->end) {
751 bus_rle->count += end - bus_rle->end;
756 /* If we adjusted the old resource, we're finished. */
760 } else bus_rle = NULL;
761 /* If we didn't merge with anything, add this resource. */
762 if (bus_rle == NULL) {
763 bus_set_resource(bus, type, acpi_sysres_rid++, start, count, -1);
767 /* After merging/moving resources to the parent, free the list. */
768 resource_list_free(dev_rl);