aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pcmcia
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2008-06-19 13:02:52 -0400
committerDominik Brodowski <linux@dominikbrodowski.net>2008-06-24 09:33:42 -0400
commitc502380170ee93fd1f4028cc1f32efc87fde7376 (patch)
tree3743249953d40aa0f08cc9ae4f7774c8907b3326 /drivers/pcmcia
parent635416ef393e8cec5a89fc6c1de710ee9596a51e (diff)
pcmcia: carve out ioctl adjust function to pcmcia_ioctl
Let pcmcia_ioctl interact with rsrc_nonstatic using functions which rsrc_nonstatic.c has to use anyway. Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Diffstat (limited to 'drivers/pcmcia')
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c90
-rw-r--r--drivers/pcmcia/rsrc_mgr.c86
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c18
3 files changed, 94 insertions, 100 deletions
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index 5f186abca108..758ece8dc362 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -138,6 +138,94 @@ static int proc_read_drivers(char *buf, char **start, off_t pos,
138} 138}
139#endif 139#endif
140 140
141
142#ifdef CONFIG_PCMCIA_PROBE
143
144static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
145{
146 int irq;
147 u32 mask;
148
149 irq = adj->resource.irq.IRQ;
150 if ((irq < 0) || (irq > 15))
151 return CS_BAD_IRQ;
152
153 if (adj->Action != REMOVE_MANAGED_RESOURCE)
154 return 0;
155
156 mask = 1 << irq;
157
158 if (!(s->irq_mask & mask))
159 return 0;
160
161 s->irq_mask &= ~mask;
162
163 return 0;
164}
165
166#else
167
168static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
169 return CS_SUCCESS;
170}
171
172#endif
173
174static int pcmcia_adjust_resource_info(adjust_t *adj)
175{
176 struct pcmcia_socket *s;
177 int ret = CS_UNSUPPORTED_FUNCTION;
178 unsigned long flags;
179
180 down_read(&pcmcia_socket_list_rwsem);
181 list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
182
183 if (adj->Resource == RES_IRQ)
184 ret = adjust_irq(s, adj);
185
186 else if (s->resource_ops->add_io) {
187 unsigned long begin, end;
188
189 /* you can't use the old interface if the new
190 * one was used before */
191 spin_lock_irqsave(&s->lock, flags);
192 if ((s->resource_setup_new) &&
193 !(s->resource_setup_old)) {
194 spin_unlock_irqrestore(&s->lock, flags);
195 continue;
196 } else if (!(s->resource_setup_old))
197 s->resource_setup_old = 1;
198 spin_unlock_irqrestore(&s->lock, flags);
199
200 switch (adj->Resource) {
201 case RES_MEMORY_RANGE:
202 begin = adj->resource.memory.Base;
203 end = adj->resource.memory.Base + adj->resource.memory.Size - 1;
204 if (s->resource_ops->add_mem)
205 ret =s->resource_ops->add_mem(s, adj->Action, begin, end);
206 case RES_IO_RANGE:
207 begin = adj->resource.io.BasePort;
208 end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1;
209 if (s->resource_ops->add_io)
210 ret = s->resource_ops->add_io(s, adj->Action, begin, end);
211 }
212 if (!ret) {
213 /* as there's no way we know this is the
214 * last call to adjust_resource_info, we
215 * always need to assume this is the latest
216 * one... */
217 spin_lock_irqsave(&s->lock, flags);
218 s->resource_setup_done = 1;
219 spin_unlock_irqrestore(&s->lock, flags);
220 }
221 }
222 }
223 up_read(&pcmcia_socket_list_rwsem);
224
225 return (ret);
226}
227
228
141/*====================================================================== 229/*======================================================================
142 230
143 These manage a ring buffer of events pending for one user process 231 These manage a ring buffer of events pending for one user process
@@ -546,8 +634,6 @@ static u_int ds_poll(struct file *file, poll_table *wait)
546 634
547/*====================================================================*/ 635/*====================================================================*/
548 636
549extern int pcmcia_adjust_resource_info(adjust_t *adj);
550
551static int ds_ioctl(struct inode * inode, struct file * file, 637static int ds_ioctl(struct inode * inode, struct file * file,
552 u_int cmd, u_long arg) 638 u_int cmd, u_long arg)
553{ 639{
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index ce2226273aaa..c0e2afc79e3e 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -21,86 +21,6 @@
21#include "cs_internal.h" 21#include "cs_internal.h"
22 22
23 23
24#ifdef CONFIG_PCMCIA_IOCTL
25
26#ifdef CONFIG_PCMCIA_PROBE
27
28static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
29{
30 int irq;
31 u32 mask;
32
33 irq = adj->resource.irq.IRQ;
34 if ((irq < 0) || (irq > 15))
35 return CS_BAD_IRQ;
36
37 if (adj->Action != REMOVE_MANAGED_RESOURCE)
38 return 0;
39
40 mask = 1 << irq;
41
42 if (!(s->irq_mask & mask))
43 return 0;
44
45 s->irq_mask &= ~mask;
46
47 return 0;
48}
49
50#else
51
52static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
53 return CS_SUCCESS;
54}
55
56#endif
57
58
59int pcmcia_adjust_resource_info(adjust_t *adj)
60{
61 struct pcmcia_socket *s;
62 int ret = CS_UNSUPPORTED_FUNCTION;
63 unsigned long flags;
64
65 down_read(&pcmcia_socket_list_rwsem);
66 list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
67
68 if (adj->Resource == RES_IRQ)
69 ret = adjust_irq(s, adj);
70
71 else if (s->resource_ops->adjust_resource) {
72
73 /* you can't use the old interface if the new
74 * one was used before */
75 spin_lock_irqsave(&s->lock, flags);
76 if ((s->resource_setup_new) &&
77 !(s->resource_setup_old)) {
78 spin_unlock_irqrestore(&s->lock, flags);
79 continue;
80 } else if (!(s->resource_setup_old))
81 s->resource_setup_old = 1;
82 spin_unlock_irqrestore(&s->lock, flags);
83
84 ret = s->resource_ops->adjust_resource(s, adj);
85 if (!ret) {
86 /* as there's no way we know this is the
87 * last call to adjust_resource_info, we
88 * always need to assume this is the latest
89 * one... */
90 spin_lock_irqsave(&s->lock, flags);
91 s->resource_setup_done = 1;
92 spin_unlock_irqrestore(&s->lock, flags);
93 }
94 }
95 }
96 up_read(&pcmcia_socket_list_rwsem);
97
98 return (ret);
99}
100EXPORT_SYMBOL(pcmcia_adjust_resource_info);
101
102#endif
103
104int pcmcia_validate_mem(struct pcmcia_socket *s) 24int pcmcia_validate_mem(struct pcmcia_socket *s)
105{ 25{
106 if (s->resource_ops->validate_mem) 26 if (s->resource_ops->validate_mem)
@@ -164,7 +84,8 @@ struct pccard_resource_ops pccard_static_ops = {
164 .adjust_io_region = NULL, 84 .adjust_io_region = NULL,
165 .find_io = NULL, 85 .find_io = NULL,
166 .find_mem = NULL, 86 .find_mem = NULL,
167 .adjust_resource = NULL, 87 .add_io = NULL,
88 .add_mem = NULL,
168 .init = static_init, 89 .init = static_init,
169 .exit = NULL, 90 .exit = NULL,
170}; 91};
@@ -264,7 +185,8 @@ struct pccard_resource_ops pccard_iodyn_ops = {
264 .adjust_io_region = iodyn_adjust_io_region, 185 .adjust_io_region = iodyn_adjust_io_region,
265 .find_io = iodyn_find_io_region, 186 .find_io = iodyn_find_io_region,
266 .find_mem = NULL, 187 .find_mem = NULL,
267 .adjust_resource = NULL, 188 .add_io = NULL,
189 .add_mem = NULL,
268 .init = static_init, 190 .init = static_init,
269 .exit = NULL, 191 .exit = NULL,
270}; 192};
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 4123155e2f7a..162693480ed0 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -766,21 +766,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
766} 766}
767 767
768 768
769static int nonstatic_adjust_resource_info(struct pcmcia_socket *s, adjust_t *adj)
770{
771 unsigned long end;
772
773 switch (adj->Resource) {
774 case RES_MEMORY_RANGE:
775 end = adj->resource.memory.Base + adj->resource.memory.Size - 1;
776 return adjust_memory(s, adj->Action, adj->resource.memory.Base, end);
777 case RES_IO_RANGE:
778 end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1;
779 return adjust_io(s, adj->Action, adj->resource.io.BasePort, end);
780 }
781 return CS_UNSUPPORTED_FUNCTION;
782}
783
784#ifdef CONFIG_PCI 769#ifdef CONFIG_PCI
785static int nonstatic_autoadd_resources(struct pcmcia_socket *s) 770static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
786{ 771{
@@ -889,7 +874,8 @@ struct pccard_resource_ops pccard_nonstatic_ops = {
889 .adjust_io_region = nonstatic_adjust_io_region, 874 .adjust_io_region = nonstatic_adjust_io_region,
890 .find_io = nonstatic_find_io_region, 875 .find_io = nonstatic_find_io_region,
891 .find_mem = nonstatic_find_mem_region, 876 .find_mem = nonstatic_find_mem_region,
892 .adjust_resource = nonstatic_adjust_resource_info, 877 .add_io = adjust_io,
878 .add_mem = adjust_memory,
893 .init = nonstatic_init, 879 .init = nonstatic_init,
894 .exit = nonstatic_release_resource_db, 880 .exit = nonstatic_release_resource_db,
895}; 881};