Add pcmcia_device(s). drivers/pcmcia/ds.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/pcmcia/ds.h | 17 +++++++++++++ 2 files changed, 85 insertions(+) diff -ruN linux-original/drivers/pcmcia/ds.c linux/drivers/pcmcia/ds.c --- linux-original/drivers/pcmcia/ds.c 2004-11-13 13:40:34.000000000 +0100 +++ linux/drivers/pcmcia/ds.c 2004-11-13 13:42:46.605168640 +0100 @@ -101,7 +101,12 @@ wait_queue_head_t queue, request; socket_bind_t *bind; struct pcmcia_socket *parent; + + /* the PCMCIA devices connected to this socket (normally one, more + * for multifunction devices: */ + struct list_head devices_list; }; +static spinlock_t pcmcia_dev_list_lock; #define DS_SOCKET_PRESENT 0x01 #define DS_SOCKET_BUSY 0x02 @@ -330,6 +335,15 @@ } #endif +/* pcmcia_device handling */ + +static void pcmcia_release_dev(struct device *dev) +{ + struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + kfree(p_dev); +} + + /*====================================================================== These manage a ring buffer of events pending for one user process @@ -493,8 +507,10 @@ static int bind_request(struct pcmcia_bus_socket *s, bind_info_t *bind_info) { struct pcmcia_driver *driver; + struct pcmcia_device *p_dev; socket_bind_t *b; client_t *client; + unsigned long flags; if (!s) return -EINVAL; @@ -545,6 +561,37 @@ b->next = s->bind; s->bind = b; + /* Currently, the userspace pcmcia cardmgr detects pcmcia devices. + * Here this information is translated into a kernel + * struct pcmcia_device. + */ + + p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL); + if (!p_dev) { + /* FIXME: client isn't freed here */ + goto no_p_dev; + } + memset(p_dev, 0, sizeof(struct pcmcia_device)); + + p_dev->socket = s->parent; + p_dev->func = bind_info->function; + + p_dev->dev.bus = &pcmcia_bus_type; + p_dev->dev.parent = s->parent->dev.dev; + p_dev->dev.release = pcmcia_release_dev; + sprintf (p_dev->dev.bus_id, "pcmcia%d.%d", p_dev->socket->sock, p_dev->func); + p_dev->dev.driver = &driver->drv; + if (device_register(&p_dev->dev)) { + /* FIXME: client isn't freed here */ + kfree(p_dev); + goto no_p_dev; + } + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + list_add_tail(&p_dev->socket_device_list, &s->devices_list); + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + + no_p_dev: + driver->use_count++; if (driver->attach) { b->instance = driver->attach(); @@ -634,6 +681,8 @@ static int unbind_request(struct pcmcia_bus_socket *s, bind_info_t *bind_info) { socket_bind_t **b, *c; + struct pcmcia_device *p_dev; + unsigned long flags; ds_dbg(2, "unbind_request(%d, '%s')\n", s->parent->sock, (char *)bind_info->dev_info); @@ -654,6 +703,22 @@ module_put(c->driver->owner); *b = c->next; kfree(c); + + /* unregister the pcmcia_device */ + spin_lock_irqsave(&pcmcia_dev_list_lock, flags); + list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { + if (p_dev->func == bind_info->function) + goto found; + } + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + return 0; + + found: + list_del(&p_dev->socket_device_list); + spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); + + device_unregister(&p_dev->dev); + return 0; } /* unbind_request */ @@ -1036,6 +1101,7 @@ init_waitqueue_head(&s->queue); init_waitqueue_head(&s->request); + INIT_LIST_HEAD(&s->devices_list); /* initialize data */ s->parent = socket; @@ -1092,6 +1158,8 @@ { int i; + spin_lock_init(&pcmcia_dev_list_lock); + bus_register(&pcmcia_bus_type); class_interface_register(&pcmcia_bus_interface); diff -ruN linux-original/include/pcmcia/ds.h linux/include/pcmcia/ds.h --- linux-original/include/pcmcia/ds.h 2004-11-13 13:40:34.000000000 +0100 +++ linux/include/pcmcia/ds.h 2004-11-13 13:42:12.988279184 +0100 @@ -127,6 +127,8 @@ ((l) && ((l->state & ~DEV_BUSY) == (DEV_CONFIG|DEV_PRESENT))) +struct pcmcia_socket; + extern struct bus_type pcmcia_bus_type; struct pcmcia_driver { @@ -141,6 +143,21 @@ int pcmcia_register_driver(struct pcmcia_driver *driver); void pcmcia_unregister_driver(struct pcmcia_driver *driver); +struct pcmcia_device { + /* the socket and the function no [for multifunction devices] + uniquely define a pcmcia_device */ + struct pcmcia_socket *socket; + u8 func; + + struct list_head socket_device_list; + + struct device dev; +}; + +#define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev) +#define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv) + + /* error reporting */ void cs_error(client_handle_t handle, int func, int ret);