aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pcmcia/rsrc_mgr.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/pcmcia/rsrc_mgr.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/pcmcia/rsrc_mgr.c')
-rw-r--r--drivers/pcmcia/rsrc_mgr.c163
1 files changed, 163 insertions, 0 deletions
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
new file mode 100644
index 000000000000..b6843f8d300d
--- /dev/null
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -0,0 +1,163 @@
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 unsigned long flags;
63
64 down_read(&pcmcia_socket_list_rwsem);
65 list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
66
67 if (adj->Resource == RES_IRQ)
68 ret = adjust_irq(s, adj);
69
70 else if (s->resource_ops->adjust_resource) {
71
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_done) &&
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);
82
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);
92 }
93 }
94 }
95 up_read(&pcmcia_socket_list_rwsem);
96
97 return (ret);
98}
99EXPORT_SYMBOL(pcmcia_adjust_resource_info);
100
101void pcmcia_validate_mem(struct pcmcia_socket *s)
102{
103 if (s->resource_ops->validate_mem)
104 s->resource_ops->validate_mem(s);
105}
106EXPORT_SYMBOL(pcmcia_validate_mem);
107
108int adjust_io_region(struct resource *res, unsigned long r_start,
109 unsigned long r_end, struct pcmcia_socket *s)
110{
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;
114}
115
116struct resource *find_io_region(unsigned long base, int num,
117 unsigned long align, struct pcmcia_socket *s)
118{
119 if (s->resource_ops->find_io)
120 return s->resource_ops->find_io(base, num, align, s);
121 return NULL;
122}
123
124struct resource *find_mem_region(u_long base, u_long num, u_long align,
125 int low, struct pcmcia_socket *s)
126{
127 if (s->resource_ops->find_mem)
128 return s->resource_ops->find_mem(base, num, align, low, s);
129 return NULL;
130}
131
132void release_resource_db(struct pcmcia_socket *s)
133{
134 if (s->resource_ops->exit)
135 s->resource_ops->exit(s);
136}
137
138
139static int static_init(struct pcmcia_socket *s)
140{
141 unsigned long flags;
142
143 /* the good thing about SS_CAP_STATIC_MAP sockets is
144 * that they don't need a resource database */
145
146 spin_lock_irqsave(&s->lock, flags);
147 s->resource_setup_done = 1;
148 spin_unlock_irqrestore(&s->lock, flags);
149
150 return 0;
151}
152
153
154struct pccard_resource_ops pccard_static_ops = {
155 .validate_mem = NULL,
156 .adjust_io_region = NULL,
157 .find_io = NULL,
158 .find_mem = NULL,
159 .adjust_resource = NULL,
160 .init = static_init,
161 .exit = NULL,
162};
163EXPORT_SYMBOL(pccard_static_ops);