Add missing "local_irq_enable()" to C2/C3 exit logic
[linux-2.6/linux-loongson.git] / drivers / pcmcia / rsrc_mgr.c
blob0668384ebc8bf8a4bbc0b43b522e5c7a221259c8
1 /*
2 * rsrc_mgr.c -- Resource management routines and/or wrappers
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.
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.
12 * (C) 1999 David A. Hinds
15 #include <linux/config.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
19 #include <pcmcia/cs_types.h>
20 #include <pcmcia/ss.h>
21 #include <pcmcia/cs.h>
22 #include "cs_internal.h"
25 #ifdef CONFIG_PCMCIA_PROBE
27 static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
29 int irq;
30 u32 mask;
32 irq = adj->resource.irq.IRQ;
33 if ((irq < 0) || (irq > 15))
34 return CS_BAD_IRQ;
36 if (adj->Action != REMOVE_MANAGED_RESOURCE)
37 return 0;
39 mask = 1 << irq;
41 if (!(s->irq_mask & mask))
42 return 0;
44 s->irq_mask &= ~mask;
46 return 0;
49 #else
51 static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
52 return CS_SUCCESS;
55 #endif
58 int pcmcia_adjust_resource_info(adjust_t *adj)
60 struct pcmcia_socket *s;
61 int ret = CS_UNSUPPORTED_FUNCTION;
62 unsigned long flags;
64 down_read(&pcmcia_socket_list_rwsem);
65 list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
67 if (adj->Resource == RES_IRQ)
68 ret = adjust_irq(s, adj);
70 else if (s->resource_ops->adjust_resource) {
72 /* you can't use the old interface if the new
73 * one was used before */
74 spin_lock_irqsave(&s->lock, flags);
75 if ((s->resource_setup_new) &&
76 !(s->resource_setup_old)) {
77 spin_unlock_irqrestore(&s->lock, flags);
78 continue;
79 } else if (!(s->resource_setup_old))
80 s->resource_setup_old = 1;
81 spin_unlock_irqrestore(&s->lock, flags);
83 ret = s->resource_ops->adjust_resource(s, adj);
84 if (!ret) {
85 /* as there's no way we know this is the
86 * last call to adjust_resource_info, we
87 * always need to assume this is the latest
88 * one... */
89 spin_lock_irqsave(&s->lock, flags);
90 s->resource_setup_done = 1;
91 spin_unlock_irqrestore(&s->lock, flags);
95 up_read(&pcmcia_socket_list_rwsem);
97 return (ret);
99 EXPORT_SYMBOL(pcmcia_adjust_resource_info);
101 void pcmcia_validate_mem(struct pcmcia_socket *s)
103 if (s->resource_ops->validate_mem)
104 s->resource_ops->validate_mem(s);
106 EXPORT_SYMBOL(pcmcia_validate_mem);
108 int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
109 unsigned long r_end, struct pcmcia_socket *s)
111 if (s->resource_ops->adjust_io_region)
112 return s->resource_ops->adjust_io_region(res, r_start, r_end, s);
113 return -ENOMEM;
115 EXPORT_SYMBOL(pcmcia_adjust_io_region);
117 struct resource *pcmcia_find_io_region(unsigned long base, int num,
118 unsigned long align, struct pcmcia_socket *s)
120 if (s->resource_ops->find_io)
121 return s->resource_ops->find_io(base, num, align, s);
122 return NULL;
124 EXPORT_SYMBOL(pcmcia_find_io_region);
126 struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
127 int low, struct pcmcia_socket *s)
129 if (s->resource_ops->find_mem)
130 return s->resource_ops->find_mem(base, num, align, low, s);
131 return NULL;
133 EXPORT_SYMBOL(pcmcia_find_mem_region);
135 void release_resource_db(struct pcmcia_socket *s)
137 if (s->resource_ops->exit)
138 s->resource_ops->exit(s);
142 static int static_init(struct pcmcia_socket *s)
144 unsigned long flags;
146 /* the good thing about SS_CAP_STATIC_MAP sockets is
147 * that they don't need a resource database */
149 spin_lock_irqsave(&s->lock, flags);
150 s->resource_setup_done = 1;
151 spin_unlock_irqrestore(&s->lock, flags);
153 return 0;
157 struct pccard_resource_ops pccard_static_ops = {
158 .validate_mem = NULL,
159 .adjust_io_region = NULL,
160 .find_io = NULL,
161 .find_mem = NULL,
162 .adjust_resource = NULL,
163 .init = static_init,
164 .exit = NULL,
166 EXPORT_SYMBOL(pccard_static_ops);