Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763408AbYCZRPt (ORCPT ); Wed, 26 Mar 2008 13:15:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758164AbYCZRJN (ORCPT ); Wed, 26 Mar 2008 13:09:13 -0400 Received: from g1t0029.austin.hp.com ([15.216.28.36]:26115 "EHLO g1t0029.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760892AbYCZRJA (ORCPT ); Wed, 26 Mar 2008 13:09:00 -0400 Message-Id: <20080326171227.941656065@ldl.fc.hp.com> References: <20080326171058.099442579@ldl.fc.hp.com> User-Agent: quilt/0.46-1 Date: Wed, 26 Mar 2008 11:11:21 -0600 From: Bjorn Helgaas To: Len Brown Cc: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Adam Belay Cc: Li Shaohua Cc: Matthieu Castet Cc: Thomas Renninger Cc: Rene Herman Cc: Jaroslav Kysela Cc: Andrew Morton Subject: [patch 23/37] PNP: make generic pnp_add_mem_resource() Content-Disposition: inline; filename=pnp-common-add-mem-resource Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9096 Lines: 275 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 --- drivers/pnp/base.h | 1 drivers/pnp/interface.c | 17 ++++--------- drivers/pnp/isapnp/core.c | 4 --- drivers/pnp/pnpacpi/rsparser.c | 50 +++++++++-------------------------------- drivers/pnp/pnpbios/rsparser.c | 26 ++------------------- drivers/pnp/resource.c | 24 +++++++++++++++++++ 6 files changed, 46 insertions(+), 76 deletions(-) Index: work7/drivers/pnp/base.h =================================================================== --- work7.orig/drivers/pnp/base.h 2008-03-25 14:48:57.000000000 -0600 +++ work7/drivers/pnp/base.h 2008-03-25 14:48:59.000000000 -0600 @@ -18,3 +18,4 @@ int pnp_add_irq_resource(struct pnp_dev *dev, int irq, int flags); int pnp_add_dma_resource(struct pnp_dev *dev, int dma, int flags); int pnp_add_io_resource(struct pnp_dev *dev, resource_size_t start, resource_size_t len, int flags); +int pnp_add_mem_resource(struct pnp_dev *dev, resource_size_t start, resource_size_t len, int flags); Index: work7/drivers/pnp/resource.c =================================================================== --- work7.orig/drivers/pnp/resource.c 2008-03-25 14:48:57.000000000 -0600 +++ work7/drivers/pnp/resource.c 2008-03-25 14:48:59.000000000 -0600 @@ -536,6 +536,30 @@ return 0; } +int pnp_add_mem_resource(struct pnp_dev *dev, resource_size_t start, resource_size_t len, int flags) +{ + struct pnp_resource_table *res = &dev->res; + int i = 0; + static unsigned char warned; + + while (set(res->mem_resource[i].flags) && i < PNP_MAX_MEM) + i++; + if (i >= PNP_MAX_MEM && !warned) { + dev_err(&dev->dev, "too many MEMs (max %d)\n", PNP_MAX_MEM); + warned = 1; + return -ENOSPC; + } + + res->mem_resource[i].flags = IORESOURCE_MEM | flags; + if (len <= 0) { + res->mem_resource[i].flags |= IORESOURCE_DISABLED; + return -EINVAL; + } + res->mem_resource[i].start = start; + res->mem_resource[i].end = start + len - 1; + return 0; +} + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { Index: work7/drivers/pnp/isapnp/core.c =================================================================== --- work7.orig/drivers/pnp/isapnp/core.c 2008-03-25 14:48:57.000000000 -0600 +++ work7/drivers/pnp/isapnp/core.c 2008-03-25 14:48:59.000000000 -0600 @@ -936,7 +936,6 @@ static int isapnp_read_resources(struct pnp_dev *dev) { - struct pnp_resource_table *res = &dev->res; int tmp, ret; dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE); @@ -952,8 +951,7 @@ isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8; if (!ret) continue; - res->mem_resource[tmp].start = ret; - res->mem_resource[tmp].flags = IORESOURCE_MEM; + pnp_add_mem_resource(dev, ret, 1, 0); } for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { ret = Index: work7/drivers/pnp/pnpacpi/rsparser.c =================================================================== --- work7.orig/drivers/pnp/pnpacpi/rsparser.c 2008-03-25 14:48:57.000000000 -0600 +++ work7/drivers/pnp/pnpacpi/rsparser.c 2008-03-25 14:48:59.000000000 -0600 @@ -153,35 +153,6 @@ return flags; } -static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, - u64 mem, u64 len, - int write_protect) -{ - struct pnp_resource_table *res = &dev->res; - int i = 0; - static unsigned char warned; - - while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) && - (i < PNP_MAX_MEM)) - i++; - if (i < PNP_MAX_MEM) { - res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag - if (len <= 0) { - res->mem_resource[i].flags |= IORESOURCE_DISABLED; - return; - } - if (write_protect == ACPI_READ_WRITE_MEMORY) - res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE; - - res->mem_resource[i].start = mem; - res->mem_resource[i].end = mem + len - 1; - } else if (!warned) { - printk(KERN_ERR "pnpacpi: exceeded the max number of mem " - "resources: %d\n", PNP_MAX_MEM); - warned = 1; - } -} - static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev, struct acpi_resource *res) { @@ -199,9 +170,9 @@ return; if (p->resource_type == ACPI_MEMORY_RANGE) - pnpacpi_parse_allocated_memresource(dev, - p->minimum, p->address_length, - p->info.mem.write_protect); + pnp_add_mem_resource(dev, p->minimum, p->address_length, + p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY ? + IORESOURCE_MEM_WRITEABLE : 0); else if (p->resource_type == ACPI_IO_RANGE) pnp_add_io_resource(dev, p->minimum, p->address_length, p->granularity == 0xfff ? 0 : PNP_PORT_FLAG_16BITADDR); @@ -272,24 +243,27 @@ case ACPI_RESOURCE_TYPE_MEMORY24: memory24 = &res->data.memory24; - pnpacpi_parse_allocated_memresource(dev, + pnp_add_mem_resource(dev, memory24->minimum, memory24->address_length, - memory24->write_protect); + memory24->write_protect == ACPI_READ_WRITE_MEMORY ? + IORESOURCE_MEM_WRITEABLE : 0); break; case ACPI_RESOURCE_TYPE_MEMORY32: memory32 = &res->data.memory32; - pnpacpi_parse_allocated_memresource(dev, + pnp_add_mem_resource(dev, memory32->minimum, memory32->address_length, - memory32->write_protect); + memory32->write_protect == ACPI_READ_WRITE_MEMORY ? + IORESOURCE_MEM_WRITEABLE : 0); break; case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: fixed_memory32 = &res->data.fixed_memory32; - pnpacpi_parse_allocated_memresource(dev, + pnp_add_mem_resource(dev, fixed_memory32->address, fixed_memory32->address_length, - fixed_memory32->write_protect); + fixed_memory32->write_protect == ACPI_READ_WRITE_MEMORY ? + IORESOURCE_MEM_WRITEABLE : 0); break; case ACPI_RESOURCE_TYPE_ADDRESS16: case ACPI_RESOURCE_TYPE_ADDRESS32: Index: work7/drivers/pnp/pnpbios/rsparser.c =================================================================== --- work7.orig/drivers/pnp/pnpbios/rsparser.c 2008-03-25 14:48:57.000000000 -0600 +++ work7/drivers/pnp/pnpbios/rsparser.c 2008-03-25 14:48:59.000000000 -0600 @@ -54,26 +54,6 @@ * Allocated Resources */ -static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev, - int mem, int len) -{ - struct pnp_resource_table *res = &dev->res; - int i = 0; - - while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) - && i < PNP_MAX_MEM) - i++; - if (i < PNP_MAX_MEM) { - res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag - if (len <= 0) { - res->mem_resource[i].flags |= IORESOURCE_DISABLED; - return; - } - res->mem_resource[i].start = (unsigned long)mem; - res->mem_resource[i].end = (unsigned long)(mem + len - 1); - } -} - static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev, unsigned char *p, unsigned char *end) @@ -104,7 +84,7 @@ goto len_err; io = *(short *)&p[4]; size = *(short *)&p[10]; - pnpbios_parse_allocated_memresource(dev, io, size); + pnp_add_mem_resource(dev, io, size, 0); break; case LARGE_TAG_ANSISTR: @@ -120,7 +100,7 @@ goto len_err; io = *(int *)&p[4]; size = *(int *)&p[16]; - pnpbios_parse_allocated_memresource(dev, io, size); + pnp_add_mem_resource(dev, io, size, 0); break; case LARGE_TAG_FIXEDMEM32: @@ -128,7 +108,7 @@ goto len_err; io = *(int *)&p[4]; size = *(int *)&p[8]; - pnpbios_parse_allocated_memresource(dev, io, size); + pnp_add_mem_resource(dev, io, size, 0); break; case SMALL_TAG_IRQ: Index: work7/drivers/pnp/interface.c =================================================================== --- work7.orig/drivers/pnp/interface.c 2008-03-25 14:48:57.000000000 -0600 +++ work7/drivers/pnp/interface.c 2008-03-25 14:48:59.000000000 -0600 @@ -370,7 +370,6 @@ goto done; } if (!strnicmp(buf, "set", 3)) { - int nmem = 0; if (dev->active) goto done; buf += 3; @@ -401,24 +400,18 @@ buf += 3; while (isspace(*buf)) ++buf; - dev->res.mem_resource[nmem].start = - simple_strtoul(buf, &buf, 0); + start = simple_strtoul(buf, &buf, 0); while (isspace(*buf)) ++buf; if (*buf == '-') { buf += 1; while (isspace(*buf)) ++buf; - dev->res.mem_resource[nmem].end = - simple_strtoul(buf, &buf, 0); + end = simple_strtoul(buf, &buf, 0); } else - dev->res.mem_resource[nmem].end = - dev->res.mem_resource[nmem].start; - dev->res.mem_resource[nmem].flags = - IORESOURCE_MEM; - nmem++; - if (nmem >= PNP_MAX_MEM) - break; + end = start; + length = end - start + 1; + pnp_add_mem_resource(dev, start, length, 0); continue; } if (!strnicmp(buf, "irq", 3)) { -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/