Skip to content

Commit b19a727

Browse files
author
Dominik Brodowski
committed
pcmcia: clarify alloc_io_space, move it to resource handlers
Clean up the alloc_io_space() function by moving most of it to the actual resource_ops. This allows for a bit less re-directions. Future cleanups will follow, and will make up for the code duplication currently present between rsrc_iodyn and rsrc_nonstatic (which are hardly ever built at the same time anyway, therefore no increase in built size). Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent 49b1153 commit b19a727

6 files changed

Lines changed: 204 additions & 101 deletions

File tree

‎drivers/pcmcia/cs_internal.h‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ struct cis_cache_entry {
5252

5353
struct pccard_resource_ops {
5454
int (*validate_mem) (struct pcmcia_socket *s);
55-
int (*adjust_io_region) (struct resource *res,
56-
unsigned long r_start,
57-
unsigned long r_end,
58-
struct pcmcia_socket *s);
59-
struct resource* (*find_io) (unsigned long base, int num,
60-
unsigned long align,
61-
struct pcmcia_socket *s);
55+
int (*find_io) (struct pcmcia_socket *s,
56+
unsigned int attr,
57+
unsigned int *base,
58+
unsigned int num,
59+
unsigned int align);
6260
struct resource* (*find_mem) (unsigned long base, unsigned long num,
6361
unsigned long align, int low,
6462
struct pcmcia_socket *s);

‎drivers/pcmcia/pcmcia_resource.c‎

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,6 @@ static int io_speed;
4040
module_param(io_speed, int, 0444);
4141

4242

43-
static int pcmcia_adjust_io_region(struct resource *res, unsigned long start,
44-
unsigned long end, struct pcmcia_socket *s)
45-
{
46-
if (s->resource_ops->adjust_io_region)
47-
return s->resource_ops->adjust_io_region(res, start, end, s);
48-
return -ENOMEM;
49-
}
50-
51-
static struct resource *pcmcia_find_io_region(unsigned long base, int num,
52-
unsigned long align,
53-
struct pcmcia_socket *s)
54-
{
55-
if (s->resource_ops->find_io)
56-
return s->resource_ops->find_io(base, num, align, s);
57-
return NULL;
58-
}
59-
6043
int pcmcia_validate_mem(struct pcmcia_socket *s)
6144
{
6245
if (s->resource_ops->validate_mem)
@@ -82,8 +65,7 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
8265
static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
8366
unsigned int *base, unsigned int num, u_int lines)
8467
{
85-
int i;
86-
unsigned int try, align;
68+
unsigned int align;
8769

8870
align = (*base) ? (lines ? 1<<lines : 0) : 1;
8971
if (align && (align < num)) {
@@ -100,50 +82,8 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
10082
*base, align);
10183
align = 0;
10284
}
103-
if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
104-
*base = s->io_offset | (*base & 0x0fff);
105-
return 0;
106-
}
107-
/* Check for an already-allocated window that must conflict with
108-
* what was asked for. It is a hack because it does not catch all
109-
* potential conflicts, just the most obvious ones.
110-
*/
111-
for (i = 0; i < MAX_IO_WIN; i++)
112-
if ((s->io[i].res) && *base &&
113-
((s->io[i].res->start & (align-1)) == *base))
114-
return 1;
115-
for (i = 0; i < MAX_IO_WIN; i++) {
116-
if (!s->io[i].res) {
117-
s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
118-
if (s->io[i].res) {
119-
*base = s->io[i].res->start;
120-
s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
121-
s->io[i].InUse = num;
122-
break;
123-
} else
124-
return 1;
125-
} else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
126-
continue;
127-
/* Try to extend top of window */
128-
try = s->io[i].res->end + 1;
129-
if ((*base == 0) || (*base == try))
130-
if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
131-
s->io[i].res->end + num, s) == 0) {
132-
*base = try;
133-
s->io[i].InUse += num;
134-
break;
135-
}
136-
/* Try to extend bottom of window */
137-
try = s->io[i].res->start - num;
138-
if ((*base == 0) || (*base == try))
139-
if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
140-
s->io[i].res->end, s) == 0) {
141-
*base = try;
142-
s->io[i].InUse += num;
143-
break;
144-
}
145-
}
146-
return (i == MAX_IO_WIN);
85+
86+
return s->resource_ops->find_io(s, attr, base, num, align);
14787
} /* alloc_io_space */
14888

14989

@@ -683,7 +623,8 @@ EXPORT_SYMBOL(pcmcia_request_irq);
683623
* free_irq themselves, too), or the pcmcia_request_irq() function.
684624
*/
685625
int __must_check
686-
pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, irq_handler_t handler)
626+
__pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
627+
irq_handler_t handler)
687628
{
688629
int ret;
689630

@@ -705,7 +646,7 @@ pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, irq_handler_t handler)
705646

706647
return ret;
707648
} /* pcmcia_request_exclusive_irq */
708-
EXPORT_SYMBOL(pcmcia_request_exclusive_irq);
649+
EXPORT_SYMBOL(__pcmcia_request_exclusive_irq);
709650

710651

711652
#ifdef CONFIG_PCMCIA_PROBE

‎drivers/pcmcia/rsrc_iodyn.c‎

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,16 @@ static resource_size_t pcmcia_align(void *align_data,
5656
}
5757

5858

59-
static int iodyn_adjust_io_region(struct resource *res, unsigned long r_start,
60-
unsigned long r_end, struct pcmcia_socket *s)
61-
{
62-
return adjust_resource(res, r_start, r_end - r_start + 1);
63-
}
64-
65-
66-
static struct resource *iodyn_find_io_region(unsigned long base, int num,
67-
unsigned long align, struct pcmcia_socket *s)
59+
static struct resource *__iodyn_find_io_region(struct pcmcia_socket *s,
60+
unsigned long base, int num,
61+
unsigned long align)
6862
{
6963
struct resource *res = pcmcia_make_resource(0, num, IORESOURCE_IO,
7064
dev_name(&s->dev));
7165
struct pcmcia_align_data data;
7266
unsigned long min = base;
7367
int ret;
7468

75-
if (align == 0)
76-
align = 0x10000;
77-
7869
data.mask = align - 1;
7970
data.offset = base & data.mask;
8071

@@ -94,10 +85,83 @@ static struct resource *iodyn_find_io_region(unsigned long base, int num,
9485
return res;
9586
}
9687

88+
static int iodyn_find_io(struct pcmcia_socket *s, unsigned int attr,
89+
unsigned int *base, unsigned int num,
90+
unsigned int align)
91+
{
92+
int i, ret = 0;
93+
94+
/* Check for an already-allocated window that must conflict with
95+
* what was asked for. It is a hack because it does not catch all
96+
* potential conflicts, just the most obvious ones.
97+
*/
98+
for (i = 0; i < MAX_IO_WIN; i++) {
99+
if (!s->io[i].res)
100+
continue;
101+
102+
if (!*base)
103+
continue;
104+
105+
if ((s->io[i].res->start & (align-1)) == *base)
106+
return -EBUSY;
107+
}
108+
109+
for (i = 0; i < MAX_IO_WIN; i++) {
110+
struct resource *res = s->io[i].res;
111+
unsigned int try;
112+
113+
if (res && (res->flags & IORESOURCE_BITS) !=
114+
(attr & IORESOURCE_BITS))
115+
continue;
116+
117+
if (!res) {
118+
if (align == 0)
119+
align = 0x10000;
120+
121+
res = s->io[i].res = __iodyn_find_io_region(s, *base,
122+
num, align);
123+
if (!res)
124+
return -EINVAL;
125+
126+
*base = res->start;
127+
s->io[i].res->flags =
128+
((res->flags & ~IORESOURCE_BITS) |
129+
(attr & IORESOURCE_BITS));
130+
s->io[i].InUse = num;
131+
return 0;
132+
}
133+
134+
/* Try to extend top of window */
135+
try = res->end + 1;
136+
if ((*base == 0) || (*base == try)) {
137+
if (adjust_resource(s->io[i].res, res->start,
138+
res->end - res->start + num + 1))
139+
continue;
140+
*base = try;
141+
s->io[i].InUse += num;
142+
return 0;
143+
}
144+
145+
/* Try to extend bottom of window */
146+
try = res->start - num;
147+
if ((*base == 0) || (*base == try)) {
148+
if (adjust_resource(s->io[i].res,
149+
res->start - num,
150+
res->end - res->start + num + 1))
151+
continue;
152+
*base = try;
153+
s->io[i].InUse += num;
154+
return 0;
155+
}
156+
}
157+
158+
return -EINVAL;
159+
}
160+
161+
97162
struct pccard_resource_ops pccard_iodyn_ops = {
98163
.validate_mem = NULL,
99-
.adjust_io_region = iodyn_adjust_io_region,
100-
.find_io = iodyn_find_io_region,
164+
.find_io = iodyn_find_io,
101165
.find_mem = NULL,
102166
.add_io = NULL,
103167
.add_mem = NULL,

‎drivers/pcmcia/rsrc_mgr.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,21 @@ struct resource *pcmcia_make_resource(unsigned long start, unsigned long end,
4646
return res;
4747
}
4848

49+
static int static_find_io(struct pcmcia_socket *s, unsigned int attr,
50+
unsigned int *base, unsigned int num,
51+
unsigned int align)
52+
{
53+
if (!s->io_offset)
54+
return -EINVAL;
55+
*base = s->io_offset | (*base & 0x0fff);
56+
57+
return 0;
58+
}
59+
4960

5061
struct pccard_resource_ops pccard_static_ops = {
5162
.validate_mem = NULL,
52-
.adjust_io_region = NULL,
53-
.find_io = NULL,
63+
.find_io = static_find_io,
5464
.find_mem = NULL,
5565
.add_io = NULL,
5666
.add_mem = NULL,

0 commit comments

Comments
 (0)