Skip to content

Commit c502380

Browse files
author
Dominik Brodowski
committed
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>
1 parent 635416e commit c502380

4 files changed

Lines changed: 102 additions & 102 deletions

File tree

‎drivers/pcmcia/pcmcia_ioctl.c‎

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,94 @@ static int proc_read_drivers(char *buf, char **start, off_t pos,
138138
}
139139
#endif
140140

141+
142+
#ifdef CONFIG_PCMCIA_PROBE
143+
144+
static 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+
168+
static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
169+
return CS_SUCCESS;
170+
}
171+
172+
#endif
173+
174+
static 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+
141229
/*======================================================================
142230
143231
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)
546634

547635
/*====================================================================*/
548636

549-
extern int pcmcia_adjust_resource_info(adjust_t *adj);
550-
551637
static int ds_ioctl(struct inode * inode, struct file * file,
552638
u_int cmd, u_long arg)
553639
{

‎drivers/pcmcia/rsrc_mgr.c‎

Lines changed: 4 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -21,86 +21,6 @@
2121
#include "cs_internal.h"
2222

2323

24-
#ifdef CONFIG_PCMCIA_IOCTL
25-
26-
#ifdef CONFIG_PCMCIA_PROBE
27-
28-
static 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-
52-
static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
53-
return CS_SUCCESS;
54-
}
55-
56-
#endif
57-
58-
59-
int 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-
}
100-
EXPORT_SYMBOL(pcmcia_adjust_resource_info);
101-
102-
#endif
103-
10424
int pcmcia_validate_mem(struct pcmcia_socket *s)
10525
{
10626
if (s->resource_ops->validate_mem)
@@ -164,7 +84,8 @@ struct pccard_resource_ops pccard_static_ops = {
16484
.adjust_io_region = NULL,
16585
.find_io = NULL,
16686
.find_mem = NULL,
167-
.adjust_resource = NULL,
87+
.add_io = NULL,
88+
.add_mem = NULL,
16889
.init = static_init,
16990
.exit = NULL,
17091
};
@@ -264,7 +185,8 @@ struct pccard_resource_ops pccard_iodyn_ops = {
264185
.adjust_io_region = iodyn_adjust_io_region,
265186
.find_io = iodyn_find_io_region,
266187
.find_mem = NULL,
267-
.adjust_resource = NULL,
188+
.add_io = NULL,
189+
.add_mem = NULL,
268190
.init = static_init,
269191
.exit = NULL,
270192
};

‎drivers/pcmcia/rsrc_nonstatic.c‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -766,21 +766,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
766766
}
767767

768768

769-
static 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-
784769
#ifdef CONFIG_PCI
785770
static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
786771
{
@@ -889,7 +874,8 @@ struct pccard_resource_ops pccard_nonstatic_ops = {
889874
.adjust_io_region = nonstatic_adjust_io_region,
890875
.find_io = nonstatic_find_io_region,
891876
.find_mem = nonstatic_find_mem_region,
892-
.adjust_resource = nonstatic_adjust_resource_info,
877+
.add_io = adjust_io,
878+
.add_mem = adjust_memory,
893879
.init = nonstatic_init,
894880
.exit = nonstatic_release_resource_db,
895881
};

‎include/pcmcia/ss.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,14 @@ struct pccard_resource_ops {
136136
struct resource* (*find_mem) (unsigned long base, unsigned long num,
137137
unsigned long align, int low,
138138
struct pcmcia_socket *s);
139-
int (*adjust_resource) (struct pcmcia_socket *s,
140-
adjust_t *adj);
139+
int (*add_io) (struct pcmcia_socket *s,
140+
unsigned int action,
141+
unsigned long r_start,
142+
unsigned long r_end);
143+
int (*add_mem) (struct pcmcia_socket *s,
144+
unsigned int action,
145+
unsigned long r_start,
146+
unsigned long r_end);
141147
int (*init) (struct pcmcia_socket *s);
142148
void (*exit) (struct pcmcia_socket *s);
143149
};

0 commit comments

Comments
 (0)