aboutsummaryrefslogtreecommitdiff
path: root/drivers/pnp/resource.c
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2008-06-27 16:56:57 -0600
committerAndi Kleen <andi@basil.nowhere.org>2008-07-16 23:27:05 +0200
commitaee3ad815dd291a7193ab01da0f1a30c84d00061 (patch)
treeb0549b2a98ddfe6734e1e5f7cedd3958eec18503 /drivers/pnp/resource.c
parent20bfdbba7212d19613b93dcea93f26cb65af91fe (diff)
PNP: replace pnp_resource_table with dynamically allocated resources
PNP used to have a fixed-size pnp_resource_table for tracking the resources used by a device. This table often overflowed, so we've had to increase the table size, which wastes memory because most devices have very few resources. This patch replaces the table with a linked list of resources where the entries are allocated on demand. This removes messages like these: pnpacpi: exceeded the max number of IO resources 00:01: too many I/O port resources References: http://bugzilla.kernel.org/show_bug.cgi?id=9535 http://bugzilla.kernel.org/show_bug.cgi?id=9740 http://lkml.org/lkml/2007/11/30/110 This patch also changes the way PNP uses the IORESOURCE_UNSET, IORESOURCE_AUTO, and IORESOURCE_DISABLED flags. Prior to this patch, the pnp_resource_table entries used the flags like this: IORESOURCE_UNSET This table entry is unused and available for use. When this flag is set, we shouldn't look at anything else in the resource structure. This flag is set when a resource table entry is initialized. IORESOURCE_AUTO This resource was assigned automatically by pnp_assign_{io,mem,etc}(). This flag is set when a resource table entry is initialized and cleared whenever we discover a resource setting by reading an ISAPNP config register, parsing a PNPBIOS resource data stream, parsing an ACPI _CRS list, or interpreting a sysfs "set" command. Resources marked IORESOURCE_AUTO are reinitialized and marked as IORESOURCE_UNSET by pnp_clean_resource_table() in these cases: - before we attempt to assign resources automatically, - if we fail to assign resources automatically, - after disabling a device IORESOURCE_DISABLED Set by pnp_assign_{io,mem,etc}() when automatic assignment fails. Also set by PNPBIOS and PNPACPI for: - invalid IRQs or GSI registration failures - invalid DMA channels - I/O ports above 0x10000 - mem ranges with negative length After this patch, there is no pnp_resource_table, and the resource list entries use the flags like this: IORESOURCE_UNSET This flag is no longer used in PNP. Instead of keeping IORESOURCE_UNSET entries in the resource list, we remove entries from the list and free them. IORESOURCE_AUTO No change in meaning: it still means the resource was assigned automatically by pnp_assign_{port,mem,etc}(), but these functions now set the bit explicitly. We still "clean" a device's resource list in the same places, but rather than reinitializing IORESOURCE_AUTO entries, we just remove them from the list. Note that IORESOURCE_AUTO entries are always at the end of the list, so removing them doesn't reorder other list entries. This is because non-IORESOURCE_AUTO entries are added by the ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the sysfs "set" command. In each of these cases, we completely free the resource list first. IORESOURCE_DISABLED In addition to the cases where we used to set this flag, ISAPNP now adds an IORESOURCE_DISABLED resource when it reads a configuration register with a "disabled" value. Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Len Brown <len.brown@intel.com> Signed-off-by: Andi Kleen <ak@linux.intel.com>
Diffstat (limited to 'drivers/pnp/resource.c')
-rw-r--r--drivers/pnp/resource.c86
1 files changed, 18 insertions, 68 deletions
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index cce341f743d4..0797a77bd042 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -237,7 +237,7 @@ void pnp_free_option(struct pnp_option *option)
!((*(enda) < *(startb)) || (*(endb) < *(starta)))
#define cannot_compare(flags) \
-((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
+((flags) & IORESOURCE_DISABLED)
int pnp_check_port(struct pnp_dev *dev, struct resource *res)
{
@@ -505,81 +505,31 @@ int pnp_resource_type(struct resource *res)
IORESOURCE_IRQ | IORESOURCE_DMA);
}
-struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,
- unsigned int type, unsigned int num)
-{
- struct pnp_resource_table *res = dev->res;
-
- switch (type) {
- case IORESOURCE_IO:
- if (num >= PNP_MAX_PORT)
- return NULL;
- return &res->port[num];
- case IORESOURCE_MEM:
- if (num >= PNP_MAX_MEM)
- return NULL;
- return &res->mem[num];
- case IORESOURCE_IRQ:
- if (num >= PNP_MAX_IRQ)
- return NULL;
- return &res->irq[num];
- case IORESOURCE_DMA:
- if (num >= PNP_MAX_DMA)
- return NULL;
- return &res->dma[num];
- }
- return NULL;
-}
-
struct resource *pnp_get_resource(struct pnp_dev *dev,
unsigned int type, unsigned int num)
{
struct pnp_resource *pnp_res;
+ struct resource *res;
- pnp_res = pnp_get_pnp_resource(dev, type, num);
- if (pnp_res)
- return &pnp_res->res;
-
+ list_for_each_entry(pnp_res, &dev->resources, list) {
+ res = &pnp_res->res;
+ if (pnp_resource_type(res) == type && num-- == 0)
+ return res;
+ }
return NULL;
}
EXPORT_SYMBOL(pnp_get_resource);
-static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type)
+static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev)
{
struct pnp_resource *pnp_res;
- int i;
- switch (type) {
- case IORESOURCE_IO:
- for (i = 0; i < PNP_MAX_PORT; i++) {
- pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, i);
- if (pnp_res && !pnp_resource_valid(&pnp_res->res))
- return pnp_res;
- }
- break;
- case IORESOURCE_MEM:
- for (i = 0; i < PNP_MAX_MEM; i++) {
- pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, i);
- if (pnp_res && !pnp_resource_valid(&pnp_res->res))
- return pnp_res;
- }
- break;
- case IORESOURCE_IRQ:
- for (i = 0; i < PNP_MAX_IRQ; i++) {
- pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, i);
- if (pnp_res && !pnp_resource_valid(&pnp_res->res))
- return pnp_res;
- }
- break;
- case IORESOURCE_DMA:
- for (i = 0; i < PNP_MAX_DMA; i++) {
- pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, i);
- if (pnp_res && !pnp_resource_valid(&pnp_res->res))
- return pnp_res;
- }
- break;
- }
- return NULL;
+ pnp_res = kzalloc(sizeof(struct pnp_resource), GFP_KERNEL);
+ if (!pnp_res)
+ return NULL;
+
+ list_add_tail(&pnp_res->list, &dev->resources);
+ return pnp_res;
}
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
@@ -589,7 +539,7 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
struct resource *res;
static unsigned char warned;
- pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ);
+ pnp_res = pnp_new_resource(dev);
if (!pnp_res) {
if (!warned) {
dev_err(&dev->dev, "can't add resource for IRQ %d\n",
@@ -615,7 +565,7 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
struct resource *res;
static unsigned char warned;
- pnp_res = pnp_new_resource(dev, IORESOURCE_DMA);
+ pnp_res = pnp_new_resource(dev);
if (!pnp_res) {
if (!warned) {
dev_err(&dev->dev, "can't add resource for DMA %d\n",
@@ -642,7 +592,7 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
struct resource *res;
static unsigned char warned;
- pnp_res = pnp_new_resource(dev, IORESOURCE_IO);
+ pnp_res = pnp_new_resource(dev);
if (!pnp_res) {
if (!warned) {
dev_err(&dev->dev, "can't add resource for IO "
@@ -671,7 +621,7 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
struct resource *res;
static unsigned char warned;
- pnp_res = pnp_new_resource(dev, IORESOURCE_MEM);
+ pnp_res = pnp_new_resource(dev);
if (!pnp_res) {
if (!warned) {
dev_err(&dev->dev, "can't add resource for MEM "