Skip to content

Commit 2ce4905

Browse files
author
Dominik Brodowski
committed
pcmcia: use struct resource for PCMCIA devices
Introduce a new field into struct pcmcia_device named "resource" and of type struct resource *, which contains the IO port ranges allocated for this device. Memory window ranges and registration with the resource trees will follow at a later date. Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent 3dace8c commit 2ce4905

5 files changed

Lines changed: 95 additions & 73 deletions

File tree

‎drivers/pcmcia/cs_internal.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ typedef struct config_t {
3535
unsigned int ConfigBase;
3636
unsigned char Status, Pin, Copy, Option, ExtStatus;
3737
unsigned int CardValues;
38-
io_req_t io;
38+
39+
struct resource io[MAX_IO_WIN]; /* io ports */
40+
3941
struct {
4042
u_int Attributes;
4143
} irq;

‎drivers/pcmcia/ds.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,6 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
531531
list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list)
532532
if (p_dev->func == tmp_dev->func) {
533533
p_dev->function_config = tmp_dev->function_config;
534-
p_dev->io = tmp_dev->io;
535534
p_dev->irq = tmp_dev->irq;
536535
kref_get(&p_dev->function_config->ref);
537536
}
@@ -544,15 +543,23 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
544543
"IRQ setup failed -- device might not work\n");
545544

546545
if (!p_dev->function_config) {
546+
config_t *c;
547547
dev_dbg(&p_dev->dev, "creating config_t\n");
548-
p_dev->function_config = kzalloc(sizeof(struct config_t),
549-
GFP_KERNEL);
550-
if (!p_dev->function_config) {
548+
c = kzalloc(sizeof(struct config_t), GFP_KERNEL);
549+
if (!c) {
551550
mutex_unlock(&s->ops_mutex);
552551
goto err_unreg;
553552
}
554-
kref_init(&p_dev->function_config->ref);
553+
p_dev->function_config = c;
554+
kref_init(&c->ref);
555+
for (i = 0; i < MAX_IO_WIN; i++) {
556+
c->io[i].name = dev_name(&p_dev->dev);
557+
c->io[i].flags = IORESOURCE_IO;
558+
}
555559
}
560+
for (i = 0; i < MAX_IO_WIN; i++)
561+
p_dev->resource[i] = &p_dev->function_config->io[i];
562+
556563
mutex_unlock(&s->ops_mutex);
557564

558565
dev_printk(KERN_NOTICE, &p_dev->dev,

‎drivers/pcmcia/pcmcia_resource.c‎

Lines changed: 78 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -60,43 +60,60 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
6060
*
6161
* Special stuff for managing IO windows, because they are scarce
6262
*/
63-
64-
static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
65-
unsigned int *base, unsigned int num, u_int lines)
63+
static int alloc_io_space(struct pcmcia_socket *s, struct resource *res,
64+
unsigned int lines)
6665
{
6766
unsigned int align;
67+
unsigned int base = res->start;
68+
unsigned int num = res->end;
69+
int ret;
70+
71+
res->flags |= IORESOURCE_IO;
6872

69-
align = (*base) ? (lines ? 1<<lines : 0) : 1;
73+
dev_dbg(&s->dev, "alloc_io_space request for %pR\n", res);
74+
75+
align = base ? (lines ? 1<<lines : 0) : 1;
7076
if (align && (align < num)) {
71-
if (*base) {
72-
dev_dbg(&s->dev, "odd IO request: num %#x align %#x\n",
73-
num, align);
77+
if (base) {
78+
dev_dbg(&s->dev, "odd IO request\n");
7479
align = 0;
7580
} else
7681
while (align && (align < num))
7782
align <<= 1;
7883
}
79-
if (*base & ~(align-1)) {
80-
dev_dbg(&s->dev, "odd IO request: base %#x align %#x\n",
81-
*base, align);
84+
if (base & ~(align-1)) {
85+
dev_dbg(&s->dev, "odd IO request\n");
8286
align = 0;
8387
}
8488

85-
return s->resource_ops->find_io(s, attr, base, num, align);
89+
ret = s->resource_ops->find_io(s, res->flags, &base, num, align);
90+
if (ret) {
91+
dev_dbg(&s->dev, "alloc_io_space request returned %d", ret);
92+
return -EINVAL;
93+
}
94+
95+
res->start = base;
96+
res->end = res->start + num - 1;
97+
dev_dbg(&s->dev, "alloc_io_space request returned %pR, %d\n", res, ret);
98+
return 0;
8699
} /* alloc_io_space */
87100

88101

89-
static void release_io_space(struct pcmcia_socket *s, unsigned int base,
90-
unsigned int num)
102+
static void release_io_space(struct pcmcia_socket *s, struct resource *res)
91103
{
104+
resource_size_t num = resource_size(res);
92105
int i;
93106

107+
dev_dbg(&s->dev, "release_io_space for %pR\n", res);
108+
94109
for (i = 0; i < MAX_IO_WIN; i++) {
95110
if (!s->io[i].res)
96111
continue;
97-
if ((s->io[i].res->start <= base) &&
98-
(s->io[i].res->end >= base+num-1)) {
112+
if ((s->io[i].res->start <= res->start) &&
113+
(s->io[i].res->end >= res->end)) {
99114
s->io[i].InUse -= num;
115+
res->start = res->end = 0;
116+
res->flags = IORESOURCE_IO;
100117
/* Free the window if no one else is using it */
101118
if (s->io[i].InUse == 0) {
102119
release_resource(s->io[i].res);
@@ -329,31 +346,25 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
329346
* don't bother checking the port ranges against the current socket
330347
* values.
331348
*/
332-
static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
349+
static int pcmcia_release_io(struct pcmcia_device *p_dev)
333350
{
334351
struct pcmcia_socket *s = p_dev->socket;
335352
int ret = -EINVAL;
336353
config_t *c;
337354

338355
mutex_lock(&s->ops_mutex);
339-
c = p_dev->function_config;
340-
341356
if (!p_dev->_io)
342357
goto out;
343358

344-
p_dev->_io = 0;
359+
c = p_dev->function_config;
345360

346-
if ((c->io.BasePort1 != req->BasePort1) ||
347-
(c->io.NumPorts1 != req->NumPorts1) ||
348-
(c->io.BasePort2 != req->BasePort2) ||
349-
(c->io.NumPorts2 != req->NumPorts2))
350-
goto out;
361+
release_io_space(s, &c->io[0]);
351362

352-
c->state &= ~CONFIG_IO_REQ;
363+
if (c->io[1].end)
364+
release_io_space(s, &c->io[1]);
353365

354-
release_io_space(s, req->BasePort1, req->NumPorts1);
355-
if (req->NumPorts2)
356-
release_io_space(s, req->BasePort2, req->NumPorts2);
366+
p_dev->_io = 0;
367+
c->state &= ~CONFIG_IO_REQ;
357368

358369
out:
359370
mutex_unlock(&s->ops_mutex);
@@ -486,13 +497,13 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
486497
pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
487498
}
488499
if (req->Present & PRESENT_IOBASE_0) {
489-
u_char b = c->io.BasePort1 & 0xff;
500+
u8 b = c->io[0].start & 0xff;
490501
pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
491-
b = (c->io.BasePort1 >> 8) & 0xff;
502+
b = (c->io[0].start >> 8) & 0xff;
492503
pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
493504
}
494505
if (req->Present & PRESENT_IOSIZE) {
495-
u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1;
506+
u8 b = resource_size(&c->io[0]) + resource_size(&c->io[1]) - 1;
496507
pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
497508
}
498509

@@ -526,28 +537,42 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
526537
EXPORT_SYMBOL(pcmcia_request_configuration);
527538

528539

529-
/** pcmcia_request_io
540+
/**
541+
* pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices
542+
*
543+
* pcmcia_request_io() attepts to reserve the IO port ranges specified in
544+
* struct pcmcia_device *p_dev->resource[0] and *p_dev->resource[1]. The
545+
* "start" value is the requested start of the IO port resource; "end"
546+
* relfects the number of ports requested.
530547
*
531-
* Request_io() reserves ranges of port addresses for a socket.
532-
* I have not implemented range sharing or alias addressing.
548+
* If io_req_t is passed, those values are converted automatically.
533549
*/
534550
int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
535551
{
536552
struct pcmcia_socket *s = p_dev->socket;
537553
config_t *c;
538554
int ret = -EINVAL;
555+
unsigned int lines = req->IOAddrLines;
539556

540557
mutex_lock(&s->ops_mutex);
541558

542559
if (!(s->state & SOCKET_PRESENT)) {
543-
dev_dbg(&s->dev, "No card present\n");
560+
dev_dbg(&s->dev, "pcmcia_request_io: No card present\n");
544561
goto out;
545562
}
546563

547-
if (!req)
548-
goto out;
549-
550564
c = p_dev->function_config;
565+
if (req) {
566+
c->io[0].start = req->BasePort1;
567+
c->io[0].end = req->NumPorts1;
568+
c->io[0].flags |= req->Attributes1;
569+
c->io[1].start = req->BasePort2;
570+
c->io[1].end = req->NumPorts2;
571+
c->io[1].flags |= req->Attributes2;
572+
}
573+
574+
dev_dbg(&s->dev, "pcmcia_request_io: %pR , %pR", &c->io[0], &c->io[1]);
575+
551576
if (c->state & CONFIG_LOCKED) {
552577
dev_dbg(&s->dev, "Configuration is locked\n");
553578
goto out;
@@ -556,40 +581,30 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
556581
dev_dbg(&s->dev, "IO already configured\n");
557582
goto out;
558583
}
559-
if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) {
560-
dev_dbg(&s->dev, "bad attribute setting for IO region 1\n");
561-
goto out;
562-
}
563-
if ((req->NumPorts2 > 0) &&
564-
(req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) {
565-
dev_dbg(&s->dev, "bad attribute setting for IO region 2\n");
566-
goto out;
567-
}
568584

569-
dev_dbg(&s->dev, "trying to allocate resource 1\n");
570-
ret = alloc_io_space(s, req->Attributes1, &req->BasePort1,
571-
req->NumPorts1, req->IOAddrLines);
572-
if (ret) {
573-
dev_dbg(&s->dev, "allocation of resource 1 failed\n");
585+
ret = alloc_io_space(s, &c->io[0], lines);
586+
if (ret)
574587
goto out;
575-
}
576588

577-
if (req->NumPorts2) {
578-
dev_dbg(&s->dev, "trying to allocate resource 2\n");
579-
ret = alloc_io_space(s, req->Attributes2, &req->BasePort2,
580-
req->NumPorts2, req->IOAddrLines);
589+
if (c->io[1].end) {
590+
ret = alloc_io_space(s, &c->io[1], lines);
581591
if (ret) {
582-
dev_dbg(&s->dev, "allocation of resource 2 failed\n");
583-
release_io_space(s, req->BasePort1, req->NumPorts1);
592+
release_io_space(s, &c->io[0]);
584593
goto out;
585594
}
586-
}
595+
} else
596+
c->io[1].start = 0;
587597

588-
c->io = *req;
589598
c->state |= CONFIG_IO_REQ;
590599
p_dev->_io = 1;
591-
dev_dbg(&s->dev, "allocating resources succeeded: %d\n", ret);
592600

601+
if (!ret) {
602+
req->BasePort1 = c->io[0].start;
603+
req->BasePort2 = c->io[1].start;
604+
}
605+
606+
dev_dbg(&s->dev, "pcmcia_request_io succeeded: %pR , %pR",
607+
&c->io[0], &c->io[1]);
593608
out:
594609
mutex_unlock(&s->ops_mutex);
595610

@@ -869,7 +884,7 @@ EXPORT_SYMBOL(pcmcia_request_window);
869884
void pcmcia_disable_device(struct pcmcia_device *p_dev)
870885
{
871886
pcmcia_release_configuration(p_dev);
872-
pcmcia_release_io(p_dev, &p_dev->io);
887+
pcmcia_release_io(p_dev);
873888
if (p_dev->_irq) {
874889
free_irq(p_dev->irq, p_dev->priv);
875890
p_dev->_irq = 0;

‎include/pcmcia/cs.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ typedef struct io_req_t {
6868
} io_req_t;
6969

7070
/* Attributes for RequestIO and ReleaseIO */
71-
#define IO_SHARED 0x01
72-
#define IO_FIRST_SHARED 0x02
73-
#define IO_FORCE_ALIAS_ACCESS 0x04
7471
#define IO_DATA_PATH_WIDTH 0x18
7572
#define IO_DATA_PATH_WIDTH_8 0x00
7673
#define IO_DATA_PATH_WIDTH_16 0x08

‎include/pcmcia/ds.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ struct pcmcia_device {
8080
struct list_head socket_device_list;
8181

8282
/* deprecated, will be cleaned up soon */
83-
u_int open;
8483
io_req_t io;
8584
config_req_t conf;
8685
window_handle_t win;
8786

8887
/* device setup */
8988
unsigned int irq;
89+
struct resource *resource[MAX_IO_WIN];
9090

9191
/* Is the device suspended? */
9292
u16 suspended:1;
@@ -120,6 +120,7 @@ struct pcmcia_device {
120120

121121
/* data private to drivers */
122122
void *priv;
123+
unsigned int open;
123124
};
124125

125126
#define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)

0 commit comments

Comments
 (0)