pcmcia: CodingStyle fixes
[linux-2.6.git] / drivers / pcmcia / rsrc_mgr.c
index 0668384..452c83b 100644 (file)
  * (C) 1999            David A. Hinds
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
 #include "cs_internal.h"
 
-
-#ifdef CONFIG_PCMCIA_PROBE
-
-static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
+static int static_init(struct pcmcia_socket *s)
 {
-       int irq;
-       u32 mask;
-
-       irq = adj->resource.irq.IRQ;
-       if ((irq < 0) || (irq > 15))
-               return CS_BAD_IRQ;
-
-       if (adj->Action != REMOVE_MANAGED_RESOURCE)
-               return 0;
-
-       mask = 1 << irq;
-
-       if (!(s->irq_mask & mask))
-               return 0;
+       /* the good thing about SS_CAP_STATIC_MAP sockets is
+        * that they don't need a resource database */
 
-       s->irq_mask &= ~mask;
+       s->resource_setup_done = 1;
 
        return 0;
 }
 
-#else
 
-static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
-       return CS_SUCCESS;
-}
+struct pccard_resource_ops pccard_static_ops = {
+       .validate_mem = NULL,
+       .adjust_io_region = NULL,
+       .find_io = NULL,
+       .find_mem = NULL,
+       .add_io = NULL,
+       .add_mem = NULL,
+       .init = static_init,
+       .exit = NULL,
+};
+EXPORT_SYMBOL(pccard_static_ops);
 
-#endif
 
+#ifdef CONFIG_PCCARD_IODYN
 
-int pcmcia_adjust_resource_info(adjust_t *adj)
+static struct resource *
+make_resource(unsigned long b, unsigned long n, int flags, char *name)
 {
-       struct pcmcia_socket *s;
-       int ret = CS_UNSUPPORTED_FUNCTION;
-       unsigned long flags;
-
-       down_read(&pcmcia_socket_list_rwsem);
-       list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
-
-               if (adj->Resource == RES_IRQ)
-                       ret = adjust_irq(s, adj);
-
-               else if (s->resource_ops->adjust_resource) {
-
-                       /* you can't use the old interface if the new
-                        * one was used before */
-                       spin_lock_irqsave(&s->lock, flags);
-                       if ((s->resource_setup_new) &&
-                           !(s->resource_setup_old)) {
-                               spin_unlock_irqrestore(&s->lock, flags);
-                               continue;
-                       } else if (!(s->resource_setup_old))
-                               s->resource_setup_old = 1;
-                       spin_unlock_irqrestore(&s->lock, flags);
-
-                       ret = s->resource_ops->adjust_resource(s, adj);
-                       if (!ret) {
-                               /* as there's no way we know this is the
-                                * last call to adjust_resource_info, we
-                                * always need to assume this is the latest
-                                * one... */
-                               spin_lock_irqsave(&s->lock, flags);
-                               s->resource_setup_done = 1;
-                               spin_unlock_irqrestore(&s->lock, flags);
-                       }
-               }
-       }
-       up_read(&pcmcia_socket_list_rwsem);
+       struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
 
-       return (ret);
+       if (res) {
+               res->name = name;
+               res->start = b;
+               res->end = b + n - 1;
+               res->flags = flags;
+       }
+       return res;
 }
-EXPORT_SYMBOL(pcmcia_adjust_resource_info);
 
-void pcmcia_validate_mem(struct pcmcia_socket *s)
-{
-       if (s->resource_ops->validate_mem)
-               s->resource_ops->validate_mem(s);
-}
-EXPORT_SYMBOL(pcmcia_validate_mem);
+struct pcmcia_align_data {
+       unsigned long   mask;
+       unsigned long   offset;
+};
 
-int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
-                    unsigned long r_end, struct pcmcia_socket *s)
+static resource_size_t pcmcia_align(void *align_data,
+                               const struct resource *res,
+                               resource_size_t size, resource_size_t align)
 {
-       if (s->resource_ops->adjust_io_region)
-               return s->resource_ops->adjust_io_region(res, r_start, r_end, s);
-       return -ENOMEM;
-}
-EXPORT_SYMBOL(pcmcia_adjust_io_region);
+       struct pcmcia_align_data *data = align_data;
+       resource_size_t start;
 
-struct resource *pcmcia_find_io_region(unsigned long base, int num,
-                  unsigned long align, struct pcmcia_socket *s)
-{
-       if (s->resource_ops->find_io)
-               return s->resource_ops->find_io(base, num, align, s);
-       return NULL;
-}
-EXPORT_SYMBOL(pcmcia_find_io_region);
+       start = (res->start & ~data->mask) + data->offset;
+       if (start < res->start)
+               start += data->mask + 1;
 
-struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
-                                int low, struct pcmcia_socket *s)
-{
-       if (s->resource_ops->find_mem)
-               return s->resource_ops->find_mem(base, num, align, low, s);
-       return NULL;
-}
-EXPORT_SYMBOL(pcmcia_find_mem_region);
+#ifdef CONFIG_X86
+       if (res->flags & IORESOURCE_IO) {
+               if (start & 0x300)
+                       start = (start + 0x3ff) & ~0x3ff;
+       }
+#endif
 
-void release_resource_db(struct pcmcia_socket *s)
-{
-       if (s->resource_ops->exit)
-               s->resource_ops->exit(s);
+#ifdef CONFIG_M68K
+       if (res->flags & IORESOURCE_IO) {
+               if ((res->start + size - 1) >= 1024)
+                       start = res->end;
+       }
+#endif
+
+       return start;
 }
 
 
-static int static_init(struct pcmcia_socket *s)
+static int iodyn_adjust_io_region(struct resource *res, unsigned long r_start,
+                                     unsigned long r_end, struct pcmcia_socket *s)
 {
-       unsigned long flags;
+       return adjust_resource(res, r_start, r_end - r_start + 1);
+}
 
-       /* the good thing about SS_CAP_STATIC_MAP sockets is
-        * that they don't need a resource database */
 
-       spin_lock_irqsave(&s->lock, flags);
-       s->resource_setup_done = 1;
-       spin_unlock_irqrestore(&s->lock, flags);
+static struct resource *iodyn_find_io_region(unsigned long base, int num,
+               unsigned long align, struct pcmcia_socket *s)
+{
+       struct resource *res = make_resource(0, num, IORESOURCE_IO,
+                                            dev_name(&s->dev));
+       struct pcmcia_align_data data;
+       unsigned long min = base;
+       int ret;
+
+       if (align == 0)
+               align = 0x10000;
+
+       data.mask = align - 1;
+       data.offset = base & data.mask;
+
+#ifdef CONFIG_PCI
+       if (s->cb_dev) {
+               ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
+                                            min, 0, pcmcia_align, &data);
+       } else
+#endif
+               ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
+                                       1, pcmcia_align, &data);
 
-       return 0;
+       if (ret != 0) {
+               kfree(res);
+               res = NULL;
+       }
+       return res;
 }
 
-
-struct pccard_resource_ops pccard_static_ops = {
+struct pccard_resource_ops pccard_iodyn_ops = {
        .validate_mem = NULL,
-       .adjust_io_region = NULL,
-       .find_io = NULL,
+       .adjust_io_region = iodyn_adjust_io_region,
+       .find_io = iodyn_find_io_region,
        .find_mem = NULL,
-       .adjust_resource = NULL,
+       .add_io = NULL,
+       .add_mem = NULL,
        .init = static_init,
        .exit = NULL,
 };
-EXPORT_SYMBOL(pccard_static_ops);
+EXPORT_SYMBOL(pccard_iodyn_ops);
+
+#endif /* CONFIG_PCCARD_IODYN */