]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/pnp/interface.c
PNP: define PNP-specific IORESOURCE_IO_* flags alongside IRQ, DMA, MEM
[linux-2.6.git] / drivers / pnp / interface.c
index 00c8a970a97e909e94c740cec8b4cb0b1666ab46..c172b6de6b71af59c924872fc70d5b38f3310e0a 100644 (file)
@@ -57,7 +57,7 @@ static void pnp_print_port(pnp_info_buffer_t * buffer, char *space,
                   "%sport 0x%x-0x%x, align 0x%x, size 0x%x, %i-bit address decoding\n",
                   space, port->min, port->max,
                   port->align ? (port->align - 1) : 0, port->size,
-                  port->flags & PNP_PORT_FLAG_16BITADDR ? 16 : 10);
+                  port->flags & IORESOURCE_IO_16BIT_ADDR ? 16 : 10);
 }
 
 static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space,
@@ -216,12 +216,12 @@ static ssize_t pnp_show_options(struct device *dmdev,
                                struct device_attribute *attr, char *buf)
 {
        struct pnp_dev *dev = to_pnp_dev(dmdev);
+       pnp_info_buffer_t *buffer;
        struct pnp_option *independent = dev->independent;
        struct pnp_option *dependent = dev->dependent;
        int ret, dep = 1;
 
-       pnp_info_buffer_t *buffer = (pnp_info_buffer_t *)
-           pnp_alloc(sizeof(pnp_info_buffer_t));
+       buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
        if (!buffer)
                return -ENOMEM;
 
@@ -248,83 +248,62 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
                                          char *buf)
 {
        struct pnp_dev *dev = to_pnp_dev(dmdev);
-       struct resource *res;
-       int i, ret;
        pnp_info_buffer_t *buffer;
+       struct pnp_resource *pnp_res;
+       struct resource *res;
+       int ret;
 
        if (!dev)
                return -EINVAL;
 
-       buffer = (pnp_info_buffer_t *) pnp_alloc(sizeof(pnp_info_buffer_t));
+       buffer = pnp_alloc(sizeof(pnp_info_buffer_t));
        if (!buffer)
                return -ENOMEM;
+
        buffer->len = PAGE_SIZE;
        buffer->buffer = buf;
        buffer->curr = buffer->buffer;
 
-       pnp_printf(buffer, "state = ");
-       if (dev->active)
-               pnp_printf(buffer, "active\n");
-       else
-               pnp_printf(buffer, "disabled\n");
-
-       for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
-               if (pnp_resource_valid(res)) {
-                       pnp_printf(buffer, "io");
-                       if (res->flags & IORESOURCE_DISABLED)
-                               pnp_printf(buffer, " disabled\n");
-                       else
-                               pnp_printf(buffer, " 0x%llx-0x%llx\n",
-                                          (unsigned long long) res->start,
-                                          (unsigned long long) res->end);
-               }
-       }
-       for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
-               if (pnp_resource_valid(res)) {
-                       pnp_printf(buffer, "mem");
-                       if (res->flags & IORESOURCE_DISABLED)
-                               pnp_printf(buffer, " disabled\n");
-                       else
-                               pnp_printf(buffer, " 0x%llx-0x%llx\n",
-                                          (unsigned long long) res->start,
-                                          (unsigned long long) res->end);
-               }
-       }
-       for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
-               if (pnp_resource_valid(res)) {
-                       pnp_printf(buffer, "irq");
-                       if (res->flags & IORESOURCE_DISABLED)
-                               pnp_printf(buffer, " disabled\n");
-                       else
-                               pnp_printf(buffer, " %lld\n",
-                                          (unsigned long long) res->start);
+       pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled");
+
+       list_for_each_entry(pnp_res, &dev->resources, list) {
+               res = &pnp_res->res;
+
+               pnp_printf(buffer, pnp_resource_type_name(res));
+
+               if (res->flags & IORESOURCE_DISABLED) {
+                       pnp_printf(buffer, " disabled\n");
+                       continue;
                }
-       }
-       for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
-               if (pnp_resource_valid(res)) {
-                       pnp_printf(buffer, "dma");
-                       if (res->flags & IORESOURCE_DISABLED)
-                               pnp_printf(buffer, " disabled\n");
-                       else
-                               pnp_printf(buffer, " %lld\n",
-                                          (unsigned long long) res->start);
+
+               switch (pnp_resource_type(res)) {
+               case IORESOURCE_IO:
+               case IORESOURCE_MEM:
+                       pnp_printf(buffer, " %#llx-%#llx\n",
+                                  (unsigned long long) res->start,
+                                  (unsigned long long) res->end);
+                       break;
+               case IORESOURCE_IRQ:
+               case IORESOURCE_DMA:
+                       pnp_printf(buffer, " %lld\n",
+                                  (unsigned long long) res->start);
+                       break;
                }
        }
+
        ret = (buffer->curr - buf);
        kfree(buffer);
        return ret;
 }
 
-static ssize_t
-pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
-                         const char *ubuf, size_t count)
+static ssize_t pnp_set_current_resources(struct device *dmdev,
+                                        struct device_attribute *attr,
+                                        const char *ubuf, size_t count)
 {
        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;
+       resource_size_t start, end;
 
        if (dev->status & PNP_ATTACHED) {
                retval = -EBUSY;
@@ -369,7 +348,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                goto done;
        }
        if (!strnicmp(buf, "set", 3)) {
-               int nport = 0, nmem = 0, nirq = 0, ndma = 0;
                if (dev->active)
                        goto done;
                buf += 3;
@@ -382,48 +360,34 @@ 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_add_io_resource(dev, start, end, 0);
                                continue;
                        }
                        if (!strnicmp(buf, "mem", 3)) {
                                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_add_mem_resource(dev, start, end, 0);
                                continue;
                        }
                        if (!strnicmp(buf, "irq", 3)) {
@@ -431,9 +395,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                                while (isspace(*buf))
                                        ++buf;
                                start = simple_strtoul(buf, &buf, 0);
-                               pnp_res = pnp_add_irq_resource(dev, start, 0);
-                               if (pnp_res)
-                                       nirq++;
+                               pnp_add_irq_resource(dev, start, 0);
                                continue;
                        }
                        if (!strnicmp(buf, "dma", 3)) {
@@ -441,9 +403,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
                                while (isspace(*buf))
                                        ++buf;
                                start = simple_strtoul(buf, &buf, 0);
-                               pnp_res = pnp_add_dma_resource(dev, start, 0);
-                               if (pnp_res)
-                                       pnp_res->index = ndma++;
+                               pnp_add_dma_resource(dev, start, 0);
                                continue;
                        }
                        break;