linux-bk/drivers/pcmcia/rsrc_mgr.c
<<
>>
Prefs
   1/*
   2 * rsrc_mgr.c -- Resource management routines and/or wrappers
   3 *
   4 * This program is free software; you can redistribute it and/or modify
   5 * it under the terms of the GNU General Public License version 2 as
   6 * published by the Free Software Foundation.
   7 *
   8 * The initial developer of the original code is David A. Hinds
   9 * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
  10 * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
  11 *
  12 * (C) 1999             David A. Hinds
  13 */
  14
  15#include <linux/config.h>
  16#include <linux/module.h>
  17#include <linux/kernel.h>
  18
  19#include <pcmcia/cs_types.h>
  20#include <pcmcia/ss.h>
  21#include <pcmcia/cs.h>
  22#include "cs_internal.h"
  23
  24
  25#ifdef CONFIG_PCMCIA_PROBE
  26
  27static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
  28{
  29        int irq;
  30        u32 mask;
  31
  32        irq = adj->resource.irq.IRQ;
  33        if ((irq < 0) || (irq > 15))
  34                return CS_BAD_IRQ;
  35
  36        if (adj->Action != REMOVE_MANAGED_RESOURCE)
  37                return 0;
  38
  39        mask = 1 << irq;
  40
  41        if (!(s->irq_mask & mask))
  42                return 0;
  43
  44        s->irq_mask &= ~mask;
  45
  46        return 0;
  47}
  48
  49#else
  50
  51static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
  52        return CS_SUCCESS;
  53}
  54
  55#endif
  56
  57
  58int pcmcia_adjust_resource_info(adjust_t *adj)
  59{
  60        struct pcmcia_socket *s;
  61        int ret = CS_UNSUPPORTED_FUNCTION;
  62
  63        down_read(&pcmcia_socket_list_rwsem);
  64        list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
  65
  66                if (adj->Resource == RES_IRQ)
  67                        ret = adjust_irq(s, adj);
  68
  69                else if (s->resource_ops->adjust_resource)
  70                        ret = s->resource_ops->adjust_resource(s, adj);
  71        }
  72        up_read(&pcmcia_socket_list_rwsem);
  73
  74        return (ret);
  75}
  76EXPORT_SYMBOL(pcmcia_adjust_resource_info);
  77
  78void pcmcia_validate_mem(struct pcmcia_socket *s)
  79{
  80        if (s->resource_ops->validate_mem)
  81                s->resource_ops->validate_mem(s);
  82}
  83EXPORT_SYMBOL(pcmcia_validate_mem);
  84
  85int adjust_io_region(struct resource *res, unsigned long r_start,
  86                     unsigned long r_end, struct pcmcia_socket *s)
  87{
  88        if (s->resource_ops->adjust_io_region)
  89                return s->resource_ops->adjust_io_region(res, r_start, r_end, s);
  90        return -ENOMEM;
  91}
  92
  93struct resource *find_io_region(unsigned long base, int num,
  94                   unsigned long align, struct pcmcia_socket *s)
  95{
  96        if (s->resource_ops->find_io)
  97                return s->resource_ops->find_io(base, num, align, s);
  98        return NULL;
  99}
 100
 101struct resource *find_mem_region(u_long base, u_long num, u_long align,
 102                                 int low, struct pcmcia_socket *s)
 103{
 104        if (s->resource_ops->find_mem)
 105                return s->resource_ops->find_mem(base, num, align, low, s);
 106        return NULL;
 107}
 108
 109void release_resource_db(struct pcmcia_socket *s)
 110{
 111        if (s->resource_ops->exit)
 112                s->resource_ops->exit(s);
 113}
 114
 115
 116struct pccard_resource_ops pccard_static_ops = {
 117        .validate_mem = NULL,
 118        .adjust_io_region = NULL,
 119        .find_io = NULL,
 120        .find_mem = NULL,
 121        .adjust_resource = NULL,
 122        .exit = NULL,
 123};
 124EXPORT_SYMBOL(pccard_static_ops);
 125
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.