2000-10-28 06:59:48 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Michael Smith
|
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/bus.h>
|
2004-06-13 22:52:30 +00:00
|
|
|
#include <sys/malloc.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
2001-08-30 00:49:34 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
2001-08-30 00:49:34 +00:00
|
|
|
#include <sys/rman.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2005-09-11 18:39:03 +00:00
|
|
|
#include <contrib/dev/acpica/acpi.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Hooks for the ACPI CA debugging infrastructure */
|
2001-06-29 20:32:29 +00:00
|
|
|
#define _COMPONENT ACPI_BUS
|
2002-02-23 05:28:22 +00:00
|
|
|
ACPI_MODULE_NAME("RESOURCE")
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2004-06-23 17:21:02 +00:00
|
|
|
struct lookup_irq_request {
|
|
|
|
ACPI_RESOURCE *acpi_res;
|
|
|
|
struct resource *res;
|
|
|
|
int counter;
|
|
|
|
int rid;
|
|
|
|
int found;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_lookup_irq_handler(ACPI_RESOURCE *res, void *context)
|
|
|
|
{
|
|
|
|
struct lookup_irq_request *req;
|
|
|
|
u_int irqnum, irq;
|
|
|
|
|
|
|
|
switch (res->Id) {
|
|
|
|
case ACPI_RSTYPE_IRQ:
|
|
|
|
case ACPI_RSTYPE_EXT_IRQ:
|
|
|
|
if (res->Id == ACPI_RSTYPE_IRQ) {
|
|
|
|
irqnum = res->Data.Irq.NumberOfInterrupts;
|
|
|
|
irq = res->Data.Irq.Interrupts[0];
|
|
|
|
} else {
|
|
|
|
irqnum = res->Data.ExtendedIrq.NumberOfInterrupts;
|
|
|
|
irq = res->Data.ExtendedIrq.Interrupts[0];
|
|
|
|
}
|
|
|
|
if (irqnum != 1)
|
|
|
|
break;
|
|
|
|
req = (struct lookup_irq_request *)context;
|
|
|
|
if (req->counter != req->rid) {
|
|
|
|
req->counter++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
req->found = 1;
|
|
|
|
KASSERT(irq == rman_get_start(req->res),
|
|
|
|
("IRQ resources do not match"));
|
|
|
|
bcopy(res, req->acpi_res, sizeof(ACPI_RESOURCE));
|
|
|
|
return (AE_CTRL_TERMINATE);
|
|
|
|
}
|
|
|
|
return (AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_lookup_irq_resource(device_t dev, int rid, struct resource *res,
|
|
|
|
ACPI_RESOURCE *acpi_res)
|
|
|
|
{
|
|
|
|
struct lookup_irq_request req;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
|
|
|
req.acpi_res = acpi_res;
|
|
|
|
req.res = res;
|
|
|
|
req.counter = 0;
|
|
|
|
req.rid = rid;
|
|
|
|
req.found = 0;
|
|
|
|
status = AcpiWalkResources(acpi_get_handle(dev), "_CRS",
|
|
|
|
acpi_lookup_irq_handler, &req);
|
|
|
|
if (ACPI_SUCCESS(status) && req.found == 0)
|
|
|
|
status = AE_NOT_FOUND;
|
|
|
|
return (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
acpi_config_intr(device_t dev, ACPI_RESOURCE *res)
|
|
|
|
{
|
|
|
|
u_int irq;
|
|
|
|
int pol, trig;
|
|
|
|
|
|
|
|
switch (res->Id) {
|
|
|
|
case ACPI_RSTYPE_IRQ:
|
|
|
|
KASSERT(res->Data.Irq.NumberOfInterrupts == 1,
|
|
|
|
("%s: multiple interrupts", __func__));
|
|
|
|
irq = res->Data.Irq.Interrupts[0];
|
|
|
|
trig = res->Data.Irq.EdgeLevel;
|
|
|
|
pol = res->Data.Irq.ActiveHighLow;
|
|
|
|
break;
|
|
|
|
case ACPI_RSTYPE_EXT_IRQ:
|
|
|
|
KASSERT(res->Data.ExtendedIrq.NumberOfInterrupts == 1,
|
|
|
|
("%s: multiple interrupts", __func__));
|
|
|
|
irq = res->Data.ExtendedIrq.Interrupts[0];
|
|
|
|
trig = res->Data.ExtendedIrq.EdgeLevel;
|
|
|
|
pol = res->Data.ExtendedIrq.ActiveHighLow;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("%s: bad resource type %u", __func__, res->Id);
|
|
|
|
}
|
|
|
|
BUS_CONFIG_INTR(dev, irq, (trig == ACPI_EDGE_SENSITIVE) ?
|
|
|
|
INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ?
|
2004-12-27 05:36:47 +00:00
|
|
|
INTR_POLARITY_HIGH : INTR_POLARITY_LOW);
|
2004-06-23 17:21:02 +00:00
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Fetch a device's resources and associate them with the device.
|
|
|
|
*
|
|
|
|
* Note that it might be nice to also locate ACPI-specific resource items, such
|
|
|
|
* as GPE bits.
|
2001-08-30 00:49:34 +00:00
|
|
|
*
|
|
|
|
* We really need to split the resource-fetching code out from the
|
|
|
|
* resource-parsing code, since we may want to use the parsing
|
|
|
|
* code for _PRS someday.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_parse_resources(device_t dev, ACPI_HANDLE handle,
|
2004-03-31 17:23:46 +00:00
|
|
|
struct acpi_parse_resource_set *set, void *arg)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
ACPI_BUFFER buf;
|
2001-05-29 20:13:42 +00:00
|
|
|
ACPI_RESOURCE *res;
|
2000-10-28 06:59:48 +00:00
|
|
|
char *curr, *last;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
void *context;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
2001-08-30 00:49:34 +00:00
|
|
|
* Special-case some devices that abuse _PRS/_CRS to mean
|
|
|
|
* something other than "I consume this resource".
|
|
|
|
*
|
|
|
|
* XXX do we really need this? It's only relevant once
|
|
|
|
* we start always-allocating these resources, and even
|
|
|
|
* then, the only special-cased device is likely to be
|
|
|
|
* the PCI interrupt link.
|
|
|
|
*/
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Fetch the device's current resources. */
|
2002-02-23 05:28:22 +00:00
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) {
|
2001-08-30 00:49:34 +00:00
|
|
|
if (status != AE_NOT_FOUND)
|
|
|
|
printf("can't fetch resources for %s - %s\n",
|
|
|
|
acpi_name(handle), AcpiFormatException(status));
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (status);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2002-10-04 00:35:22 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_name(handle), (long)buf.Length));
|
2004-03-31 17:23:46 +00:00
|
|
|
set->set_init(dev, arg, &context);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Iterate through the resources */
|
2000-10-28 06:59:48 +00:00
|
|
|
curr = buf.Pointer;
|
|
|
|
last = (char *)buf.Pointer + buf.Length;
|
|
|
|
while (curr < last) {
|
2001-05-29 20:13:42 +00:00
|
|
|
res = (ACPI_RESOURCE *)curr;
|
2000-10-28 06:59:48 +00:00
|
|
|
curr += res->Length;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Handle the individual resource types */
|
2000-10-28 06:59:48 +00:00
|
|
|
switch(res->Id) {
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_END_TAG:
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
curr = last;
|
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_FIXED_IO:
|
2001-08-30 00:49:34 +00:00
|
|
|
if (res->Data.FixedIo.RangeLength <= 0)
|
|
|
|
break;
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
res->Data.FixedIo.BaseAddress,
|
|
|
|
res->Data.FixedIo.RangeLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_ioport(dev, context,
|
|
|
|
res->Data.FixedIo.BaseAddress,
|
|
|
|
res->Data.FixedIo.RangeLength);
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_IO:
|
2001-08-30 00:49:34 +00:00
|
|
|
if (res->Data.Io.RangeLength <= 0)
|
|
|
|
break;
|
2000-10-28 06:59:48 +00:00
|
|
|
if (res->Data.Io.MinBaseAddress == res->Data.Io.MaxBaseAddress) {
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
res->Data.Io.MinBaseAddress,
|
|
|
|
res->Data.Io.RangeLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_ioport(dev, context,
|
|
|
|
res->Data.Io.MinBaseAddress,
|
|
|
|
res->Data.Io.RangeLength);
|
2000-10-28 06:59:48 +00:00
|
|
|
} else {
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
res->Data.Io.MinBaseAddress,
|
|
|
|
res->Data.Io.MaxBaseAddress,
|
|
|
|
res->Data.Io.RangeLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_iorange(dev, context,
|
|
|
|
res->Data.Io.MinBaseAddress,
|
|
|
|
res->Data.Io.MaxBaseAddress,
|
2003-08-28 16:06:30 +00:00
|
|
|
res->Data.Io.RangeLength,
|
|
|
|
res->Data.Io.Alignment);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_FIXED_MEM32:
|
2001-08-30 00:49:34 +00:00
|
|
|
if (res->Data.FixedMemory32.RangeLength <= 0)
|
|
|
|
break;
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n",
|
|
|
|
res->Data.FixedMemory32.RangeBaseAddress,
|
2001-08-26 22:50:15 +00:00
|
|
|
res->Data.FixedMemory32.RangeLength));
|
2003-08-28 16:06:30 +00:00
|
|
|
set->set_memory(dev, context,
|
|
|
|
res->Data.FixedMemory32.RangeBaseAddress,
|
2000-10-28 06:59:48 +00:00
|
|
|
res->Data.FixedMemory32.RangeLength);
|
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_MEM32:
|
2001-08-30 00:49:34 +00:00
|
|
|
if (res->Data.Memory32.RangeLength <= 0)
|
|
|
|
break;
|
2003-08-28 16:06:30 +00:00
|
|
|
if (res->Data.Memory32.MinBaseAddress ==
|
|
|
|
res->Data.Memory32.MaxBaseAddress) {
|
|
|
|
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n",
|
|
|
|
res->Data.Memory32.MinBaseAddress,
|
2001-08-26 22:50:15 +00:00
|
|
|
res->Data.Memory32.RangeLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memory(dev, context,
|
|
|
|
res->Data.Memory32.MinBaseAddress,
|
|
|
|
res->Data.Memory32.RangeLength);
|
2000-10-28 06:59:48 +00:00
|
|
|
} else {
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
res->Data.Memory32.MinBaseAddress,
|
|
|
|
res->Data.Memory32.MaxBaseAddress,
|
|
|
|
res->Data.Memory32.RangeLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memoryrange(dev, context,
|
|
|
|
res->Data.Memory32.MinBaseAddress,
|
|
|
|
res->Data.Memory32.MaxBaseAddress,
|
|
|
|
res->Data.Memory32.RangeLength,
|
|
|
|
res->Data.Memory32.Alignment);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_MEM24:
|
2001-08-30 00:49:34 +00:00
|
|
|
if (res->Data.Memory24.RangeLength <= 0)
|
|
|
|
break;
|
2003-08-28 16:06:30 +00:00
|
|
|
if (res->Data.Memory24.MinBaseAddress ==
|
|
|
|
res->Data.Memory24.MaxBaseAddress) {
|
|
|
|
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
res->Data.Memory24.MinBaseAddress,
|
|
|
|
res->Data.Memory24.RangeLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memory(dev, context, res->Data.Memory24.MinBaseAddress,
|
|
|
|
res->Data.Memory24.RangeLength);
|
2000-10-28 06:59:48 +00:00
|
|
|
} else {
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n",
|
2003-08-28 16:06:30 +00:00
|
|
|
res->Data.Memory24.MinBaseAddress,
|
|
|
|
res->Data.Memory24.MaxBaseAddress,
|
|
|
|
res->Data.Memory24.RangeLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memoryrange(dev, context,
|
|
|
|
res->Data.Memory24.MinBaseAddress,
|
|
|
|
res->Data.Memory24.MaxBaseAddress,
|
|
|
|
res->Data.Memory24.RangeLength,
|
|
|
|
res->Data.Memory24.Alignment);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_IRQ:
|
2002-01-31 09:18:27 +00:00
|
|
|
/*
|
|
|
|
* from 1.0b 6.4.2
|
|
|
|
* "This structure is repeated for each separate interrupt
|
|
|
|
* required"
|
|
|
|
*/
|
|
|
|
set->set_irq(dev, context, res->Data.Irq.Interrupts,
|
2003-09-10 22:06:41 +00:00
|
|
|
res->Data.Irq.NumberOfInterrupts, res->Data.Irq.EdgeLevel,
|
|
|
|
res->Data.Irq.ActiveHighLow);
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_DMA:
|
2002-01-31 09:18:27 +00:00
|
|
|
/*
|
|
|
|
* from 1.0b 6.4.3
|
|
|
|
* "This structure is repeated for each separate dma channel
|
|
|
|
* required"
|
|
|
|
*/
|
|
|
|
set->set_drq(dev, context, res->Data.Dma.Channels,
|
|
|
|
res->Data.Dma.NumberOfChannels);
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_START_DPF:
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependant functions\n"));
|
|
|
|
set->set_start_dependant(dev, context,
|
|
|
|
res->Data.StartDpf.CompatibilityPriority);
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_END_DPF:
|
2001-08-30 00:49:34 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependant functions\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
set->set_end_dependant(dev, context);
|
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_ADDRESS32:
|
2001-08-30 00:49:34 +00:00
|
|
|
if (res->Data.Address32.AddressLength <= 0)
|
|
|
|
break;
|
2002-02-23 05:28:22 +00:00
|
|
|
if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"ignored Address32 %s producer\n",
|
|
|
|
res->Data.Address32.ResourceType == ACPI_IO_RANGE ?
|
|
|
|
"IO" : "Memory"));
|
2001-08-30 00:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-12-23 03:48:59 +00:00
|
|
|
if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE &&
|
|
|
|
res->Data.Address32.ResourceType != ACPI_IO_RANGE) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
2003-08-28 16:06:30 +00:00
|
|
|
"ignored Address32 for non-memory, non-I/O\n"));
|
2001-08-30 00:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&
|
|
|
|
res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
|
|
|
|
|
2002-02-23 05:28:22 +00:00
|
|
|
if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address32/Memory 0x%x/%d\n",
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memory(dev, context,
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.AddressLength);
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address32/IO 0x%x/%d\n",
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_ioport(dev, context,
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.AddressLength);
|
|
|
|
}
|
|
|
|
} else {
|
2002-02-23 05:28:22 +00:00
|
|
|
if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address32/Memory 0x%x-0x%x/%d\n",
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.MaxAddressRange,
|
|
|
|
res->Data.Address32.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memoryrange(dev, context,
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.MaxAddressRange,
|
|
|
|
res->Data.Address32.AddressLength,
|
|
|
|
res->Data.Address32.Granularity);
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address32/IO 0x%x-0x%x/%d\n",
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.MaxAddressRange,
|
|
|
|
res->Data.Address32.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_iorange(dev, context,
|
|
|
|
res->Data.Address32.MinAddressRange,
|
|
|
|
res->Data.Address32.MaxAddressRange,
|
|
|
|
res->Data.Address32.AddressLength,
|
|
|
|
res->Data.Address32.Granularity);
|
|
|
|
}
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_ADDRESS16:
|
2001-08-30 00:49:34 +00:00
|
|
|
if (res->Data.Address16.AddressLength <= 0)
|
|
|
|
break;
|
2002-02-23 05:28:22 +00:00
|
|
|
if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"ignored Address16 %s producer\n",
|
|
|
|
res->Data.Address16.ResourceType == ACPI_IO_RANGE ?
|
|
|
|
"IO" : "Memory"));
|
2001-08-30 00:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-12-23 03:48:59 +00:00
|
|
|
if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE &&
|
|
|
|
res->Data.Address16.ResourceType != ACPI_IO_RANGE) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"ignored Address16 for non-memory, non-I/O\n"));
|
2001-08-30 00:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED &&
|
|
|
|
res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) {
|
|
|
|
|
2002-02-23 05:28:22 +00:00
|
|
|
if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address16/Memory 0x%x/%d\n",
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memory(dev, context,
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.AddressLength);
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address16/IO 0x%x/%d\n",
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_ioport(dev, context,
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.AddressLength);
|
|
|
|
}
|
|
|
|
} else {
|
2002-02-23 05:28:22 +00:00
|
|
|
if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address16/Memory 0x%x-0x%x/%d\n",
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.MaxAddressRange,
|
|
|
|
res->Data.Address16.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_memoryrange(dev, context,
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.MaxAddressRange,
|
|
|
|
res->Data.Address16.AddressLength,
|
|
|
|
res->Data.Address16.Granularity);
|
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"Address16/IO 0x%x-0x%x/%d\n",
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.MaxAddressRange,
|
|
|
|
res->Data.Address16.AddressLength));
|
2001-08-30 00:49:34 +00:00
|
|
|
set->set_iorange(dev, context,
|
|
|
|
res->Data.Address16.MinAddressRange,
|
|
|
|
res->Data.Address16.MaxAddressRange,
|
|
|
|
res->Data.Address16.AddressLength,
|
|
|
|
res->Data.Address16.Granularity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ACPI_RSTYPE_ADDRESS64:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"unimplemented Address64 resource\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_EXT_IRQ:
|
2005-01-18 20:21:36 +00:00
|
|
|
if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"ignored ExtIRQ producer\n"));
|
|
|
|
break;
|
|
|
|
}
|
2002-01-31 09:18:27 +00:00
|
|
|
set->set_irq(dev, context,res->Data.ExtendedIrq.Interrupts,
|
2003-09-10 22:06:41 +00:00
|
|
|
res->Data.ExtendedIrq.NumberOfInterrupts,
|
|
|
|
res->Data.ExtendedIrq.EdgeLevel,
|
|
|
|
res->Data.ExtendedIrq.ActiveHighLow);
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
2001-05-29 20:13:42 +00:00
|
|
|
case ACPI_RSTYPE_VENDOR:
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
|
|
|
|
"unimplemented VendorSpecific resource\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
set->set_done(dev, context);
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2001-08-30 00:49:34 +00:00
|
|
|
/*
|
|
|
|
* Resource-set vectors used to attach _CRS-derived resources
|
|
|
|
* to an ACPI device.
|
|
|
|
*/
|
2004-03-31 17:23:46 +00:00
|
|
|
static void acpi_res_set_init(device_t dev, void *arg, void **context);
|
2000-10-28 06:59:48 +00:00
|
|
|
static void acpi_res_set_done(device_t dev, void *context);
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_res_set_ioport(device_t dev, void *context,
|
|
|
|
u_int32_t base, u_int32_t length);
|
|
|
|
static void acpi_res_set_iorange(device_t dev, void *context,
|
|
|
|
u_int32_t low, u_int32_t high,
|
2000-10-28 06:59:48 +00:00
|
|
|
u_int32_t length, u_int32_t align);
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_res_set_memory(device_t dev, void *context,
|
|
|
|
u_int32_t base, u_int32_t length);
|
|
|
|
static void acpi_res_set_memoryrange(device_t dev, void *context,
|
|
|
|
u_int32_t low, u_int32_t high,
|
2000-10-28 06:59:48 +00:00
|
|
|
u_int32_t length, u_int32_t align);
|
2002-01-31 09:18:27 +00:00
|
|
|
static void acpi_res_set_irq(device_t dev, void *context, u_int32_t *irq,
|
2003-09-10 22:06:41 +00:00
|
|
|
int count, int trig, int pol);
|
2002-01-31 09:18:27 +00:00
|
|
|
static void acpi_res_set_drq(device_t dev, void *context, u_int32_t *drq,
|
|
|
|
int count);
|
2003-08-28 16:06:30 +00:00
|
|
|
static void acpi_res_set_start_dependant(device_t dev, void *context,
|
|
|
|
int preference);
|
2000-10-28 06:59:48 +00:00
|
|
|
static void acpi_res_set_end_dependant(device_t dev, void *context);
|
|
|
|
|
|
|
|
struct acpi_parse_resource_set acpi_res_parse_set = {
|
|
|
|
acpi_res_set_init,
|
|
|
|
acpi_res_set_done,
|
|
|
|
acpi_res_set_ioport,
|
|
|
|
acpi_res_set_iorange,
|
|
|
|
acpi_res_set_memory,
|
|
|
|
acpi_res_set_memoryrange,
|
|
|
|
acpi_res_set_irq,
|
|
|
|
acpi_res_set_drq,
|
|
|
|
acpi_res_set_start_dependant,
|
|
|
|
acpi_res_set_end_dependant
|
|
|
|
};
|
|
|
|
|
|
|
|
struct acpi_res_context {
|
|
|
|
int ar_nio;
|
|
|
|
int ar_nmem;
|
|
|
|
int ar_nirq;
|
2001-08-30 00:49:34 +00:00
|
|
|
int ar_ndrq;
|
2004-03-31 17:23:46 +00:00
|
|
|
void *ar_parent;
|
2000-10-28 06:59:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2004-03-31 17:23:46 +00:00
|
|
|
acpi_res_set_init(device_t dev, void *arg, void **context)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
struct acpi_res_context *cp;
|
|
|
|
|
|
|
|
if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) {
|
|
|
|
bzero(cp, sizeof(*cp));
|
2004-03-31 17:23:46 +00:00
|
|
|
cp->ar_parent = arg;
|
2000-10-28 06:59:48 +00:00
|
|
|
*context = cp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_res_set_done(device_t dev, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
|
|
|
if (cp == NULL)
|
|
|
|
return;
|
|
|
|
AcpiOsFree(cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_res_set_ioport(device_t dev, void *context, u_int32_t base,
|
|
|
|
u_int32_t length)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
|
|
|
if (cp == NULL)
|
|
|
|
return;
|
2004-08-23 16:28:42 +00:00
|
|
|
bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_res_set_iorange(device_t dev, void *context, u_int32_t low,
|
|
|
|
u_int32_t high, u_int32_t length, u_int32_t align)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
|
|
|
if (cp == NULL)
|
|
|
|
return;
|
|
|
|
device_printf(dev, "I/O range not supported\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_res_set_memory(device_t dev, void *context, u_int32_t base,
|
|
|
|
u_int32_t length)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
|
|
|
if (cp == NULL)
|
|
|
|
return;
|
2002-01-31 09:18:27 +00:00
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low,
|
|
|
|
u_int32_t high, u_int32_t length, u_int32_t align)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
|
|
|
if (cp == NULL)
|
|
|
|
return;
|
|
|
|
device_printf(dev, "memory range not supported\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-09-10 22:06:41 +00:00
|
|
|
acpi_res_set_irq(device_t dev, void *context, u_int32_t *irq, int count,
|
|
|
|
int trig, int pol)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
2003-09-10 22:06:41 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (cp == NULL || irq == NULL)
|
2002-01-31 09:18:27 +00:00
|
|
|
return;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* This implements no resource relocation. */
|
|
|
|
if (count != 1)
|
2002-01-31 09:18:27 +00:00
|
|
|
return;
|
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-01-31 09:18:27 +00:00
|
|
|
acpi_res_set_drq(device_t dev, void *context, u_int32_t *drq, int count)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (cp == NULL || drq == NULL)
|
2002-01-31 09:18:27 +00:00
|
|
|
return;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* This implements no resource relocation. */
|
|
|
|
if (count != 1)
|
2002-01-31 09:18:27 +00:00
|
|
|
return;
|
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_res_set_start_dependant(device_t dev, void *context, int preference)
|
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
|
|
|
if (cp == NULL)
|
|
|
|
return;
|
2001-08-30 00:49:34 +00:00
|
|
|
device_printf(dev, "dependant functions not supported\n");
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_res_set_end_dependant(device_t dev, void *context)
|
|
|
|
{
|
|
|
|
struct acpi_res_context *cp = (struct acpi_res_context *)context;
|
|
|
|
|
|
|
|
if (cp == NULL)
|
|
|
|
return;
|
2003-08-28 16:06:30 +00:00
|
|
|
device_printf(dev, "dependant functions not supported\n");
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-08-30 00:49:34 +00:00
|
|
|
|
|
|
|
/*
|
2004-06-13 22:52:30 +00:00
|
|
|
* Resource-owning placeholders for IO and memory pseudo-devices.
|
2001-08-30 00:49:34 +00:00
|
|
|
*
|
2004-08-23 16:28:42 +00:00
|
|
|
* This code allocates system resources that will be used by ACPI
|
|
|
|
* child devices. The acpi parent manages these resources through a
|
|
|
|
* private rman.
|
2001-08-30 00:49:34 +00:00
|
|
|
*/
|
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
static int acpi_sysres_rid = 100;
|
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
static int acpi_sysres_probe(device_t dev);
|
|
|
|
static int acpi_sysres_attach(device_t dev);
|
2001-08-30 00:49:34 +00:00
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
static device_method_t acpi_sysres_methods[] = {
|
2001-08-30 00:49:34 +00:00
|
|
|
/* Device interface */
|
2004-06-13 22:52:30 +00:00
|
|
|
DEVMETHOD(device_probe, acpi_sysres_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_sysres_attach),
|
2001-08-30 00:49:34 +00:00
|
|
|
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
static driver_t acpi_sysres_driver = {
|
2001-08-30 00:49:34 +00:00
|
|
|
"acpi_sysresource",
|
2004-06-13 22:52:30 +00:00
|
|
|
acpi_sysres_methods,
|
2001-08-30 00:49:34 +00:00
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
static devclass_t acpi_sysres_devclass;
|
|
|
|
DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass,
|
|
|
|
0, 0);
|
2004-04-09 18:14:32 +00:00
|
|
|
MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1);
|
2001-08-30 00:49:34 +00:00
|
|
|
|
|
|
|
static int
|
2004-06-13 22:52:30 +00:00
|
|
|
acpi_sysres_probe(device_t dev)
|
2001-08-30 00:49:34 +00:00
|
|
|
{
|
2004-06-29 19:02:27 +00:00
|
|
|
static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL };
|
2004-06-13 22:52:30 +00:00
|
|
|
|
|
|
|
if (acpi_disabled("sysresource") ||
|
2004-06-29 19:02:27 +00:00
|
|
|
ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
device_set_desc(dev, "System Resource");
|
2001-08-30 00:49:34 +00:00
|
|
|
device_quiet(dev);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (-100);
|
2001-08-30 00:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-13 22:52:30 +00:00
|
|
|
acpi_sysres_attach(device_t dev)
|
2001-08-30 00:49:34 +00:00
|
|
|
{
|
2004-08-23 16:28:42 +00:00
|
|
|
device_t bus;
|
|
|
|
struct resource_list_entry *bus_rle, *dev_rle;
|
|
|
|
struct resource_list *bus_rl, *dev_rl;
|
|
|
|
int done, type;
|
|
|
|
u_long start, end, count;
|
2001-08-30 00:49:34 +00:00
|
|
|
|
|
|
|
/*
|
2004-08-23 16:28:42 +00:00
|
|
|
* Loop through all current resources to see if the new one overlaps
|
|
|
|
* any existing ones. If so, grow the old one up and/or down
|
|
|
|
* accordingly. Discard any that are wholly contained in the old. If
|
|
|
|
* the resource is unique, add it to the parent. It will later go into
|
|
|
|
* the rman pool.
|
2001-08-30 00:49:34 +00:00
|
|
|
*/
|
2004-08-23 16:28:42 +00:00
|
|
|
bus = device_get_parent(dev);
|
|
|
|
dev_rl = BUS_GET_RESOURCE_LIST(bus, dev);
|
|
|
|
bus_rl = BUS_GET_RESOURCE_LIST(device_get_parent(bus), bus);
|
2005-03-18 11:57:44 +00:00
|
|
|
STAILQ_FOREACH(dev_rle, dev_rl, link) {
|
2004-08-23 16:28:42 +00:00
|
|
|
if (dev_rle->type != SYS_RES_IOPORT && dev_rle->type != SYS_RES_MEMORY)
|
2004-06-13 22:52:30 +00:00
|
|
|
continue;
|
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
start = dev_rle->start;
|
|
|
|
end = dev_rle->end;
|
|
|
|
count = dev_rle->count;
|
|
|
|
type = dev_rle->type;
|
|
|
|
done = FALSE;
|
2004-06-13 22:52:30 +00:00
|
|
|
|
2005-03-18 11:57:44 +00:00
|
|
|
STAILQ_FOREACH(bus_rle, bus_rl, link) {
|
2004-08-23 16:28:42 +00:00
|
|
|
if (bus_rle->type != type)
|
|
|
|
continue;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
/* New resource wholly contained in old, discard. */
|
|
|
|
if (start >= bus_rle->start && end <= bus_rle->end)
|
|
|
|
break;
|
2004-06-13 22:52:30 +00:00
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
/* New tail overlaps old head, grow existing resource downward. */
|
|
|
|
if (start < bus_rle->start && end >= bus_rle->start) {
|
|
|
|
bus_rle->count += bus_rle->start - start;
|
|
|
|
bus_rle->start = start;
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* New head overlaps old tail, grow existing resource upward. */
|
|
|
|
if (start <= bus_rle->end && end > bus_rle->end) {
|
|
|
|
bus_rle->count += end - bus_rle->end;
|
|
|
|
bus_rle->end = end;
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we adjusted the old resource, we're finished. */
|
|
|
|
if (done)
|
2004-06-13 22:52:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-23 16:28:42 +00:00
|
|
|
|
|
|
|
/* If we didn't merge with anything, add this resource. */
|
|
|
|
if (bus_rle == NULL)
|
|
|
|
bus_set_resource(bus, type, acpi_sysres_rid++, start, count);
|
2004-06-13 22:52:30 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 16:28:42 +00:00
|
|
|
/* After merging/moving resources to the parent, free the list. */
|
|
|
|
resource_list_free(dev_rl);
|
|
|
|
|
|
|
|
return (0);
|
2004-06-13 22:52:30 +00:00
|
|
|
}
|