]> err.no Git - linux-2.6/blobdiff - drivers/pnp/manager.c
Merge git://git.infradead.org/mtd-2.6
[linux-2.6] / drivers / pnp / manager.c
index 17c95188bd11b9805486c7bb9ca6f308029cc7df..c28caf272c1167f13c761da916af4a0983d878da 100644 (file)
@@ -1,9 +1,8 @@
 /*
  * manager.c - Resource Management, Conflict Resolution, Activation and Disabling of Devices
  *
- * based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz>
+ * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz>
  * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
- *
  */
 
 #include <linux/errno.h>
 #include <linux/pnp.h>
 #include <linux/slab.h>
 #include <linux/bitmap.h>
+#include <linux/mutex.h>
 #include "base.h"
 
-DECLARE_MUTEX(pnp_res_mutex);
+DEFINE_MUTEX(pnp_res_mutex);
 
 static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
 {
        resource_size_t *start, *end;
        unsigned long *flags;
 
-       if (!dev || !rule)
-               return -EINVAL;
-
        if (idx >= PNP_MAX_PORT) {
-               pnp_err
-                   ("More than 4 ports is incompatible with pnp specifications.");
+               dev_err(&dev->dev, "too many I/O port resources\n");
                /* pretend we were successful so at least the manager won't try again */
                return 1;
        }
@@ -67,12 +63,8 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
        resource_size_t *start, *end;
        unsigned long *flags;
 
-       if (!dev || !rule)
-               return -EINVAL;
-
        if (idx >= PNP_MAX_MEM) {
-               pnp_err
-                   ("More than 8 mems is incompatible with pnp specifications.");
+               dev_err(&dev->dev, "too many memory resources\n");
                /* pretend we were successful so at least the manager won't try again */
                return 1;
        }
@@ -128,12 +120,8 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
                5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
        };
 
-       if (!dev || !rule)
-               return -EINVAL;
-
        if (idx >= PNP_MAX_IRQ) {
-               pnp_err
-                   ("More than 2 irqs is incompatible with pnp specifications.");
+               dev_err(&dev->dev, "too many IRQ resources\n");
                /* pretend we were successful so at least the manager won't try again */
                return 1;
        }
@@ -171,7 +159,7 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
        return 0;
 }
 
-static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
+static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
 {
        resource_size_t *start, *end;
        unsigned long *flags;
@@ -182,19 +170,14 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
                1, 3, 5, 6, 7, 0, 2, 4
        };
 
-       if (!dev || !rule)
-               return -EINVAL;
-
        if (idx >= PNP_MAX_DMA) {
-               pnp_err
-                   ("More than 2 dmas is incompatible with pnp specifications.");
-               /* pretend we were successful so at least the manager won't try again */
-               return 1;
+               dev_err(&dev->dev, "too many DMA resources\n");
+               return;
        }
 
        /* check if this resource has been manually set, if so skip */
        if (!(dev->res.dma_resource[idx].flags & IORESOURCE_AUTO))
-               return 1;
+               return;
 
        start = &dev->res.dma_resource[idx].start;
        end = &dev->res.dma_resource[idx].end;
@@ -204,29 +187,27 @@ static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
        *flags |= rule->flags | IORESOURCE_DMA;
        *flags &= ~IORESOURCE_UNSET;
 
-       if (!rule->map) {
-               *flags |= IORESOURCE_DISABLED;
-               return 1;       /* skip disabled resource requests */
-       }
-
        for (i = 0; i < 8; i++) {
                if (rule->map & (1 << xtab[i])) {
                        *start = *end = xtab[i];
                        if (pnp_check_dma(dev, idx))
-                               return 1;
+                               return;
                }
        }
-       return 0;
+#ifdef MAX_DMA_CHANNELS
+       *start = *end = MAX_DMA_CHANNELS;
+#endif
+       *flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
 }
 
 /**
  * pnp_init_resources - Resets a resource table to default values.
  * @table: pointer to the desired resource table
- *
  */
 void pnp_init_resource_table(struct pnp_resource_table *table)
 {
        int idx;
+
        for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
                table->irq_resource[idx].name = NULL;
                table->irq_resource[idx].start = -1;
@@ -260,11 +241,11 @@ void pnp_init_resource_table(struct pnp_resource_table *table)
 /**
  * pnp_clean_resources - clears resources that were not manually set
  * @res: the resources to clean
- *
  */
 static void pnp_clean_resource_table(struct pnp_resource_table *res)
 {
        int idx;
+
        for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
                if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO))
                        continue;
@@ -317,7 +298,7 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
        if (!pnp_can_configure(dev))
                return -ENODEV;
 
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        pnp_clean_resource_table(&dev->res);    /* start with a fresh slate */
        if (dev->independent) {
                port = dev->independent->port;
@@ -343,8 +324,7 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
                        irq = irq->next;
                }
                while (dma) {
-                       if (!pnp_assign_dma(dev, dma, ndma))
-                               goto fail;
+                       pnp_assign_dma(dev, dma, ndma);
                        ndma++;
                        dma = dma->next;
                }
@@ -380,20 +360,19 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
                        irq = irq->next;
                }
                while (dma) {
-                       if (!pnp_assign_dma(dev, dma, ndma))
-                               goto fail;
+                       pnp_assign_dma(dev, dma, ndma);
                        ndma++;
                        dma = dma->next;
                }
        } else if (dev->dependent)
                goto fail;
 
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        return 1;
 
-      fail:
+fail:
        pnp_clean_resource_table(&dev->res);
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        return 0;
 }
 
@@ -410,8 +389,7 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
 {
        int i;
        struct pnp_resource_table *bak;
-       if (!dev || !res)
-               return -EINVAL;
+
        if (!pnp_can_configure(dev))
                return -ENODEV;
        bak = pnp_alloc(sizeof(struct pnp_resource_table));
@@ -419,7 +397,7 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
                return -ENOMEM;
        *bak = dev->res;
 
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        dev->res = *res;
        if (!(mode & PNP_CONFIG_FORCE)) {
                for (i = 0; i < PNP_MAX_PORT; i++) {
@@ -439,14 +417,14 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
                                goto fail;
                }
        }
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
 
        kfree(bak);
        return 0;
 
-      fail:
+fail:
        dev->res = *bak;
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
        kfree(bak);
        return -EINVAL;
 }
@@ -454,19 +432,14 @@ int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
 /**
  * pnp_auto_config_dev - automatically assigns resources to a device
  * @dev: pointer to the desired device
- *
  */
 int pnp_auto_config_dev(struct pnp_dev *dev)
 {
        struct pnp_option *dep;
        int i = 1;
 
-       if (!dev)
-               return -EINVAL;
-
        if (!pnp_can_configure(dev)) {
-               pnp_dbg("Device %s does not support resource configuration.",
-                       dev->dev.bus_id);
+               dev_dbg(&dev->dev, "configuration not supported\n");
                return -ENODEV;
        }
 
@@ -483,7 +456,7 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
                } while (dep);
        }
 
-       pnp_err("Unable to assign resources to device %s.", dev->dev.bus_id);
+       dev_err(&dev->dev, "unable to assign resources\n");
        return -EBUSY;
 }
 
@@ -491,24 +464,21 @@ int pnp_auto_config_dev(struct pnp_dev *dev)
  * pnp_start_dev - low-level start of the PnP device
  * @dev: pointer to the desired device
  *
- * assumes that resources have alread been allocated
+ * assumes that resources have already been allocated
  */
-
 int pnp_start_dev(struct pnp_dev *dev)
 {
        if (!pnp_can_write(dev)) {
-               pnp_dbg("Device %s does not support activation.",
-                       dev->dev.bus_id);
+               dev_dbg(&dev->dev, "activation not supported\n");
                return -EINVAL;
        }
 
        if (dev->protocol->set(dev, &dev->res) < 0) {
-               pnp_err("Failed to activate device %s.", dev->dev.bus_id);
+               dev_err(&dev->dev, "activation failed\n");
                return -EIO;
        }
 
-       pnp_info("Device %s activated.", dev->dev.bus_id);
-
+       dev_info(&dev->dev, "activated\n");
        return 0;
 }
 
@@ -518,21 +488,18 @@ int pnp_start_dev(struct pnp_dev *dev)
  *
  * does not free resources
  */
-
 int pnp_stop_dev(struct pnp_dev *dev)
 {
        if (!pnp_can_disable(dev)) {
-               pnp_dbg("Device %s does not support disabling.",
-                       dev->dev.bus_id);
+               dev_dbg(&dev->dev, "disabling not supported\n");
                return -EINVAL;
        }
        if (dev->protocol->disable(dev) < 0) {
-               pnp_err("Failed to disable device %s.", dev->dev.bus_id);
+               dev_err(&dev->dev, "disable failed\n");
                return -EIO;
        }
 
-       pnp_info("Device %s disabled.", dev->dev.bus_id);
-
+       dev_info(&dev->dev, "disabled\n");
        return 0;
 }
 
@@ -546,11 +513,8 @@ int pnp_activate_dev(struct pnp_dev *dev)
 {
        int error;
 
-       if (!dev)
-               return -EINVAL;
-       if (dev->active) {
-               return 0;       /* the device is already active */
-       }
+       if (dev->active)
+               return 0;
 
        /* ensure resources are allocated */
        if (pnp_auto_config_dev(dev))
@@ -561,8 +525,7 @@ int pnp_activate_dev(struct pnp_dev *dev)
                return error;
 
        dev->active = 1;
-
-       return 1;
+       return 0;
 }
 
 /**
@@ -575,11 +538,8 @@ int pnp_disable_dev(struct pnp_dev *dev)
 {
        int error;
 
-       if (!dev)
-               return -EINVAL;
-       if (!dev->active) {
-               return 0;       /* the device is already disabled */
-       }
+       if (!dev->active)
+               return 0;
 
        error = pnp_stop_dev(dev);
        if (error)
@@ -588,11 +548,11 @@ int pnp_disable_dev(struct pnp_dev *dev)
        dev->active = 0;
 
        /* release the resources so that other devices can use them */
-       down(&pnp_res_mutex);
+       mutex_lock(&pnp_res_mutex);
        pnp_clean_resource_table(&dev->res);
-       up(&pnp_res_mutex);
+       mutex_unlock(&pnp_res_mutex);
 
-       return 1;
+       return 0;
 }
 
 /**
@@ -600,22 +560,16 @@ int pnp_disable_dev(struct pnp_dev *dev)
  * @resource: pointer to resource to be changed
  * @start: start of region
  * @size: size of region
- *
  */
 void pnp_resource_change(struct resource *resource, resource_size_t start,
                         resource_size_t size)
 {
-       if (resource == NULL)
-               return;
        resource->flags &= ~(IORESOURCE_AUTO | IORESOURCE_UNSET);
        resource->start = start;
        resource->end = start + size - 1;
 }
 
 EXPORT_SYMBOL(pnp_manual_config_dev);
-#if 0
-EXPORT_SYMBOL(pnp_auto_config_dev);
-#endif
 EXPORT_SYMBOL(pnp_start_dev);
 EXPORT_SYMBOL(pnp_stop_dev);
 EXPORT_SYMBOL(pnp_activate_dev);