]> err.no Git - linux-2.6/commitdiff
PNP: make generic pnp_add_io_resource()
authorBjorn Helgaas <bjorn.helgaas@hp.com>
Mon, 28 Apr 2008 22:34:36 +0000 (16:34 -0600)
committerLen Brown <len.brown@intel.com>
Tue, 29 Apr 2008 07:22:29 +0000 (03:22 -0400)
Add a pnp_add_io_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>
drivers/pnp/base.h
drivers/pnp/interface.c
drivers/pnp/isapnp/core.c
drivers/pnp/pnpacpi/rsparser.c
drivers/pnp/pnpbios/rsparser.c
drivers/pnp/resource.c

index b6719b384347c43068e5b39c72d22dddaff2c336..bfb08abc311b57ebdcd50c44680a5e3cbeff6ae3 100644 (file)
@@ -45,3 +45,6 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
                                          int flags);
 struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
                                          int flags);
+struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
+                                        resource_size_t start,
+                                        resource_size_t end, int flags);
index 00c8a970a97e909e94c740cec8b4cb0b1666ab46..77d8bf01b485520b3672e7a3b615e4c7337e5bd0 100644 (file)
@@ -324,7 +324,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
        struct resource *res;
        char *buf = (void *)ubuf;
        int retval = 0;
-       resource_size_t start;
+       resource_size_t start, end;
 
        if (dev->status & PNP_ATTACHED) {
                retval = -EBUSY;
@@ -382,24 +382,20 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                                buf += 2;
                                while (isspace(*buf))
                                        ++buf;
-                               pnp_res = pnp_get_pnp_resource(dev,
-                                               IORESOURCE_IO, nport);
-                               if (!pnp_res)
-                                       break;
-                               pnp_res->index = nport;
-                               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_IO;
-                               nport++;
+                                       end = start;
+                               pnp_res = pnp_add_io_resource(dev, start, end,
+                                                             0);
+                               if (pnp_res)
+                                       pnp_res->index = nport++;
                                continue;
                        }
                        if (!strnicmp(buf, "mem", 3)) {
index 2e5e58c777dd542a7918da00b3289a2e7e7677c4..bdd8508090da7e5bf82bcd95124d20efa52ab126 100644 (file)
@@ -941,11 +941,9 @@ static int isapnp_read_resources(struct pnp_dev *dev)
                        ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1));
                        if (!ret)
                                continue;
-                       pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, tmp);
-                       pnp_res->index = tmp;
-                       res = &pnp_res->res;
-                       res->start = ret;
-                       res->flags = IORESOURCE_IO;
+                       pnp_res = pnp_add_io_resource(dev, ret, ret, 0);
+                       if (pnp_res)
+                               pnp_res->index = tmp;
                }
                for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
                        ret =
index fc7cf73b7a7edec49e27b6fd8ad6ff2ae1711829..d3ca8e035c190f0dae18d656d4ccfbac529aecfe 100644 (file)
@@ -158,33 +158,18 @@ static int dma_flags(int type, int bus_master, int transfer)
        return flags;
 }
 
-static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev,
-                                              u64 io, u64 len, int io_decode)
+static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
+                                              u64 len, int io_decode)
 {
-       struct resource *res;
-       int i;
-       static unsigned char warned;
+       int flags = 0;
+       u64 end = start + len - 1;
 
-       for (i = 0; i < PNP_MAX_PORT; i++) {
-               res = pnp_get_resource(dev, IORESOURCE_IO, i);
-               if (!pnp_resource_valid(res))
-                       break;
-       }
-       if (i < PNP_MAX_PORT) {
-               res->flags = IORESOURCE_IO;     // Also clears _UNSET flag
-               if (io_decode == ACPI_DECODE_16)
-                       res->flags |= PNP_PORT_FLAG_16BITADDR;
-               if (len <= 0 || (io + len - 1) >= 0x10003) {
-                       res->flags |= IORESOURCE_DISABLED;
-                       return;
-               }
-               res->start = io;
-               res->end = io + len - 1;
-       } else if (!warned) {
-               printk(KERN_WARNING "pnpacpi: exceeded the max number of IO "
-                               "resources: %d \n", PNP_MAX_PORT);
-               warned = 1;
-       }
+       if (io_decode == ACPI_DECODE_16)
+               flags |= PNP_PORT_FLAG_16BITADDR;
+       if (len == 0 || end >= 0x10003)
+               flags |= IORESOURCE_DISABLED;
+
+       pnp_add_io_resource(dev, start, end, flags);
 }
 
 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
index 7f8d657285992c7f132c1a1903104fea213ae590..8c83bc16a9be7b6ff0aa5faf11e84a4138ef30d3 100644 (file)
@@ -55,26 +55,15 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
  */
 
 static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
-                                              int io, 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_PORT; i++) {
-               res = pnp_get_resource(dev, IORESOURCE_IO, i);
-               if (!pnp_resource_valid(res))
-                       break;
-       }
+       if (len <= 0 || end >= 0x10003)
+               flags |= IORESOURCE_DISABLED;
 
-       if (i < PNP_MAX_PORT) {
-               res->flags = IORESOURCE_IO;     // Also clears _UNSET flag
-               if (len <= 0 || (io + len - 1) >= 0x10003) {
-                       res->flags |= IORESOURCE_DISABLED;
-                       return;
-               }
-               res->start = (unsigned long)io;
-               res->end = (unsigned long)(io + len - 1);
-       }
+       pnp_add_io_resource(dev, start, end, flags);
 }
 
 static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
index 2a8612e31ab75933e5b3347b5b3a0275fbd22234..64387b70026aadcc446d9344e16461362e880e0b 100644 (file)
@@ -628,6 +628,35 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
        return pnp_res;
 }
 
+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_res;
+       struct resource *res;
+       static unsigned char warned;
+
+       pnp_res = pnp_new_resource(dev, IORESOURCE_IO);
+       if (!pnp_res) {
+               if (!warned) {
+                       dev_err(&dev->dev, "can't add resource for IO "
+                               "%#llx-%#llx\n",(unsigned long long) start,
+                               (unsigned long long) end);
+                       warned = 1;
+               }
+               return NULL;
+       }
+
+       res = &pnp_res->res;
+       res->flags = IORESOURCE_IO | flags;
+       res->start = start;
+       res->end = end;
+
+       dev_dbg(&dev->dev, "  add io  %#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)
 {