diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2008-04-28 16:34:37 -0600 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2008-04-29 03:22:29 -0400 |
commit | d6180f36617953990bf90d4c1ff85b77e9995cd1 (patch) | |
tree | a9fa336f7cb1f99a62c859926c6cbcfb53f5b81e /drivers/pnp | |
parent | cc8c2e308194f0997c718c7c735550ff06754d20 (diff) | |
download | linux-3.10-d6180f36617953990bf90d4c1ff85b77e9995cd1.tar.gz linux-3.10-d6180f36617953990bf90d4c1ff85b77e9995cd1.tar.bz2 linux-3.10-d6180f36617953990bf90d4c1ff85b77e9995cd1.zip |
PNP: make generic pnp_add_mem_resource()
Add a pnp_add_mem_resource() that can be used by all the PNP
backends. This consolidates a little more pnp_resource_table
knowledge into one place.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/pnp')
-rw-r--r-- | drivers/pnp/base.h | 3 | ||||
-rw-r--r-- | drivers/pnp/interface.c | 19 | ||||
-rw-r--r-- | drivers/pnp/isapnp/core.c | 10 | ||||
-rw-r--r-- | drivers/pnp/pnpacpi/rsparser.c | 34 | ||||
-rw-r--r-- | drivers/pnp/pnpbios/rsparser.c | 23 | ||||
-rw-r--r-- | drivers/pnp/resource.c | 29 |
6 files changed, 57 insertions, 61 deletions
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index bfb08abc311..9b7bb62c98b 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h @@ -48,3 +48,6 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, resource_size_t start, resource_size_t end, int flags); +struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, + resource_size_t start, + resource_size_t end, int flags); diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c index 77d8bf01b48..5d9301de177 100644 --- a/drivers/pnp/interface.c +++ b/drivers/pnp/interface.c @@ -321,7 +321,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, { struct pnp_dev *dev = to_pnp_dev(dmdev); struct pnp_resource *pnp_res; - struct resource *res; char *buf = (void *)ubuf; int retval = 0; resource_size_t start, end; @@ -402,24 +401,20 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, buf += 3; while (isspace(*buf)) ++buf; - pnp_res = pnp_get_pnp_resource(dev, - IORESOURCE_MEM, nmem); - if (!pnp_res) - break; - pnp_res->index = nmem; - res = &pnp_res->res; - res->start = simple_strtoul(buf, &buf, 0); + start = simple_strtoul(buf, &buf, 0); while (isspace(*buf)) ++buf; if (*buf == '-') { buf += 1; while (isspace(*buf)) ++buf; - res->end = simple_strtoul(buf, &buf, 0); + end = simple_strtoul(buf, &buf, 0); } else - res->end = res->start; - res->flags = IORESOURCE_MEM; - nmem++; + end = start; + pnp_res = pnp_add_mem_resource(dev, start, end, + 0); + if (pnp_res) + pnp_res->index = nmem++; continue; } if (!strnicmp(buf, "irq", 3)) { diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c index bdd8508090d..f08399497e4 100644 --- a/drivers/pnp/isapnp/core.c +++ b/drivers/pnp/isapnp/core.c @@ -932,7 +932,6 @@ EXPORT_SYMBOL(isapnp_write_byte); static int isapnp_read_resources(struct pnp_dev *dev) { struct pnp_resource *pnp_res; - struct resource *res; int tmp, ret; dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE); @@ -950,12 +949,9 @@ static int isapnp_read_resources(struct pnp_dev *dev) isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8; if (!ret) continue; - pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, - tmp); - pnp_res->index = tmp; - res = &pnp_res->res; - res->start = ret; - res->flags = IORESOURCE_MEM; + pnp_res = pnp_add_mem_resource(dev, ret, ret, 0); + if (pnp_res) + pnp_res->index = tmp; } for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { ret = diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index d3ca8e035c1..a512908bf4e 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c @@ -173,34 +173,18 @@ static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start, } static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, - u64 mem, u64 len, + u64 start, u64 len, int write_protect) { - struct resource *res; - int i; - static unsigned char warned; + int flags = 0; + u64 end = start + len - 1; - for (i = 0; i < PNP_MAX_MEM; i++) { - res = pnp_get_resource(dev, IORESOURCE_MEM, i); - if (!pnp_resource_valid(res)) - break; - } - if (i < PNP_MAX_MEM) { - res->flags = IORESOURCE_MEM; // Also clears _UNSET flag - if (len <= 0) { - res->flags |= IORESOURCE_DISABLED; - return; - } - if (write_protect == ACPI_READ_WRITE_MEMORY) - res->flags |= IORESOURCE_MEM_WRITEABLE; - - res->start = mem; - res->end = mem + len - 1; - } else if (!warned) { - printk(KERN_WARNING "pnpacpi: exceeded the max number of mem " - "resources: %d\n", PNP_MAX_MEM); - warned = 1; - } + if (len == 0) + flags |= IORESOURCE_DISABLED; + if (write_protect == ACPI_READ_WRITE_MEMORY) + flags |= IORESOURCE_MEM_WRITEABLE; + + pnp_add_mem_resource(dev, start, end, flags); } static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev, diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c index 8c83bc16a9b..ed63ecd9bf4 100644 --- a/drivers/pnp/pnpbios/rsparser.c +++ b/drivers/pnp/pnpbios/rsparser.c @@ -67,26 +67,15 @@ static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev, } static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev, - int mem, int len) + int start, int len) { - struct resource *res; - int i; + int flags = 0; + int end = start + len - 1; - for (i = 0; i < PNP_MAX_MEM; i++) { - res = pnp_get_resource(dev, IORESOURCE_MEM, i); - if (!pnp_resource_valid(res)) - break; - } + if (len <= 0) + flags |= IORESOURCE_DISABLED; - if (i < PNP_MAX_MEM) { - res->flags = IORESOURCE_MEM; // Also clears _UNSET flag - if (len <= 0) { - res->flags |= IORESOURCE_DISABLED; - return; - } - res->start = (unsigned long)mem; - res->end = (unsigned long)(mem + len - 1); - } + pnp_add_mem_resource(dev, start, end, flags); } static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev, diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 64387b70026..2041620d568 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -657,6 +657,35 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, return pnp_res; } +struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, + resource_size_t start, + resource_size_t end, int flags) +{ + struct pnp_resource *pnp_res; + struct resource *res; + static unsigned char warned; + + pnp_res = pnp_new_resource(dev, IORESOURCE_MEM); + if (!pnp_res) { + if (!warned) { + dev_err(&dev->dev, "can't add resource for MEM " + "%#llx-%#llx\n",(unsigned long long) start, + (unsigned long long) end); + warned = 1; + } + return NULL; + } + + res = &pnp_res->res; + res->flags = IORESOURCE_MEM | flags; + res->start = start; + res->end = end; + + dev_dbg(&dev->dev, " add mem %#llx-%#llx flags %#x\n", + (unsigned long long) start, (unsigned long long) end, flags); + return pnp_res; +} + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { |