diff options
Diffstat (limited to 'drivers/pcmcia/ds.c')
-rw-r--r-- | drivers/pcmcia/ds.c | 1255 |
1 files changed, 420 insertions, 835 deletions
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 569e55feecfd..cabddd49f6ff 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c | |||
@@ -10,44 +10,29 @@ | |||
10 | * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. | 10 | * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. |
11 | * | 11 | * |
12 | * (C) 1999 David A. Hinds | 12 | * (C) 1999 David A. Hinds |
13 | * (C) 2003 - 2004 Dominik Brodowski | 13 | * (C) 2003 - 2005 Dominik Brodowski |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <linux/config.h> | 16 | #include <linux/config.h> |
17 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
18 | #include <linux/moduleparam.h> | ||
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/kernel.h> | ||
21 | #include <linux/major.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/errno.h> | 20 | #include <linux/errno.h> |
24 | #include <linux/slab.h> | ||
25 | #include <linux/mm.h> | ||
26 | #include <linux/fcntl.h> | ||
27 | #include <linux/sched.h> | ||
28 | #include <linux/smp_lock.h> | ||
29 | #include <linux/timer.h> | ||
30 | #include <linux/ioctl.h> | ||
31 | #include <linux/proc_fs.h> | ||
32 | #include <linux/poll.h> | ||
33 | #include <linux/pci.h> | ||
34 | #include <linux/list.h> | 21 | #include <linux/list.h> |
35 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
36 | #include <linux/kref.h> | ||
37 | #include <linux/workqueue.h> | 23 | #include <linux/workqueue.h> |
38 | 24 | #include <linux/crc32.h> | |
39 | #include <asm/atomic.h> | 25 | #include <linux/firmware.h> |
40 | 26 | ||
41 | #define IN_CARD_SERVICES | 27 | #define IN_CARD_SERVICES |
42 | #include <pcmcia/version.h> | ||
43 | #include <pcmcia/cs_types.h> | 28 | #include <pcmcia/cs_types.h> |
44 | #include <pcmcia/cs.h> | 29 | #include <pcmcia/cs.h> |
45 | #include <pcmcia/bulkmem.h> | ||
46 | #include <pcmcia/cistpl.h> | 30 | #include <pcmcia/cistpl.h> |
47 | #include <pcmcia/ds.h> | 31 | #include <pcmcia/ds.h> |
48 | #include <pcmcia/ss.h> | 32 | #include <pcmcia/ss.h> |
49 | 33 | ||
50 | #include "cs_internal.h" | 34 | #include "cs_internal.h" |
35 | #include "ds_internal.h" | ||
51 | 36 | ||
52 | /*====================================================================*/ | 37 | /*====================================================================*/ |
53 | 38 | ||
@@ -70,49 +55,9 @@ module_param_named(pc_debug, ds_pc_debug, int, 0644); | |||
70 | #define ds_dbg(lvl, fmt, arg...) do { } while (0) | 55 | #define ds_dbg(lvl, fmt, arg...) do { } while (0) |
71 | #endif | 56 | #endif |
72 | 57 | ||
73 | /*====================================================================*/ | 58 | spinlock_t pcmcia_dev_list_lock; |
74 | 59 | ||
75 | /* Device user information */ | 60 | static int unbind_request(struct pcmcia_socket *s); |
76 | #define MAX_EVENTS 32 | ||
77 | #define USER_MAGIC 0x7ea4 | ||
78 | #define CHECK_USER(u) \ | ||
79 | (((u) == NULL) || ((u)->user_magic != USER_MAGIC)) | ||
80 | typedef struct user_info_t { | ||
81 | u_int user_magic; | ||
82 | int event_head, event_tail; | ||
83 | event_t event[MAX_EVENTS]; | ||
84 | struct user_info_t *next; | ||
85 | struct pcmcia_bus_socket *socket; | ||
86 | } user_info_t; | ||
87 | |||
88 | /* Socket state information */ | ||
89 | struct pcmcia_bus_socket { | ||
90 | struct kref refcount; | ||
91 | struct pcmcia_callback callback; | ||
92 | int state; | ||
93 | user_info_t *user; | ||
94 | wait_queue_head_t queue; | ||
95 | struct pcmcia_socket *parent; | ||
96 | |||
97 | /* the PCMCIA devices connected to this socket (normally one, more | ||
98 | * for multifunction devices: */ | ||
99 | struct list_head devices_list; | ||
100 | u8 device_count; /* the number of devices, used | ||
101 | * only internally and subject | ||
102 | * to incorrectness and change */ | ||
103 | }; | ||
104 | static spinlock_t pcmcia_dev_list_lock; | ||
105 | |||
106 | #define DS_SOCKET_PRESENT 0x01 | ||
107 | #define DS_SOCKET_BUSY 0x02 | ||
108 | #define DS_SOCKET_REMOVAL_PENDING 0x10 | ||
109 | #define DS_SOCKET_DEAD 0x80 | ||
110 | |||
111 | /*====================================================================*/ | ||
112 | |||
113 | static int major_dev = -1; | ||
114 | |||
115 | static int unbind_request(struct pcmcia_bus_socket *s); | ||
116 | 61 | ||
117 | /*====================================================================*/ | 62 | /*====================================================================*/ |
118 | 63 | ||
@@ -213,7 +158,7 @@ static const lookup_t service_table[] = { | |||
213 | }; | 158 | }; |
214 | 159 | ||
215 | 160 | ||
216 | int pcmcia_report_error(client_handle_t handle, error_info_t *err) | 161 | static int pcmcia_report_error(client_handle_t handle, error_info_t *err) |
217 | { | 162 | { |
218 | int i; | 163 | int i; |
219 | char *serv; | 164 | char *serv; |
@@ -243,7 +188,6 @@ int pcmcia_report_error(client_handle_t handle, error_info_t *err) | |||
243 | 188 | ||
244 | return CS_SUCCESS; | 189 | return CS_SUCCESS; |
245 | } /* report_error */ | 190 | } /* report_error */ |
246 | EXPORT_SYMBOL(pcmcia_report_error); | ||
247 | 191 | ||
248 | /* end of code which was in cs.c before */ | 192 | /* end of code which was in cs.c before */ |
249 | 193 | ||
@@ -256,29 +200,101 @@ void cs_error(client_handle_t handle, int func, int ret) | |||
256 | } | 200 | } |
257 | EXPORT_SYMBOL(cs_error); | 201 | EXPORT_SYMBOL(cs_error); |
258 | 202 | ||
259 | /*======================================================================*/ | ||
260 | |||
261 | static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info); | ||
262 | static struct pcmcia_bus_socket * get_socket_info_by_nr(unsigned int nr); | ||
263 | 203 | ||
264 | static void pcmcia_release_bus_socket(struct kref *refcount) | 204 | static void pcmcia_check_driver(struct pcmcia_driver *p_drv) |
265 | { | 205 | { |
266 | struct pcmcia_bus_socket *s = container_of(refcount, struct pcmcia_bus_socket, refcount); | 206 | struct pcmcia_device_id *did = p_drv->id_table; |
267 | pcmcia_put_socket(s->parent); | 207 | unsigned int i; |
268 | kfree(s); | 208 | u32 hash; |
209 | |||
210 | while (did && did->match_flags) { | ||
211 | for (i=0; i<4; i++) { | ||
212 | if (!did->prod_id[i]) | ||
213 | continue; | ||
214 | |||
215 | hash = crc32(0, did->prod_id[i], strlen(did->prod_id[i])); | ||
216 | if (hash == did->prod_id_hash[i]) | ||
217 | continue; | ||
218 | |||
219 | printk(KERN_DEBUG "pcmcia: %s: invalid hash for " | ||
220 | "product string \"%s\": is 0x%x, should " | ||
221 | "be 0x%x\n", p_drv->drv.name, did->prod_id[i], | ||
222 | did->prod_id_hash[i], hash); | ||
223 | printk(KERN_DEBUG "pcmcia: see " | ||
224 | "Documentation/pcmcia/devicetable.txt for " | ||
225 | "details\n"); | ||
226 | } | ||
227 | did++; | ||
228 | } | ||
229 | |||
230 | return; | ||
269 | } | 231 | } |
270 | 232 | ||
271 | static void pcmcia_put_bus_socket(struct pcmcia_bus_socket *s) | 233 | |
234 | #ifdef CONFIG_PCMCIA_LOAD_CIS | ||
235 | |||
236 | /** | ||
237 | * pcmcia_load_firmware - load CIS from userspace if device-provided is broken | ||
238 | * @dev - the pcmcia device which needs a CIS override | ||
239 | * @filename - requested filename in /lib/firmware/cis/ | ||
240 | * | ||
241 | * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if | ||
242 | * the one provided by the card is broken. The firmware files reside in | ||
243 | * /lib/firmware/cis/ in userspace. | ||
244 | */ | ||
245 | static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) | ||
272 | { | 246 | { |
273 | kref_put(&s->refcount, pcmcia_release_bus_socket); | 247 | struct pcmcia_socket *s = dev->socket; |
248 | const struct firmware *fw; | ||
249 | char path[20]; | ||
250 | int ret=-ENOMEM; | ||
251 | cisdump_t *cis; | ||
252 | |||
253 | if (!filename) | ||
254 | return -EINVAL; | ||
255 | |||
256 | ds_dbg(1, "trying to load firmware %s\n", filename); | ||
257 | |||
258 | if (strlen(filename) > 14) | ||
259 | return -EINVAL; | ||
260 | |||
261 | snprintf(path, 20, "%s", filename); | ||
262 | |||
263 | if (request_firmware(&fw, path, &dev->dev) == 0) { | ||
264 | if (fw->size >= CISTPL_MAX_CIS_SIZE) | ||
265 | goto release; | ||
266 | |||
267 | cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL); | ||
268 | if (!cis) | ||
269 | goto release; | ||
270 | |||
271 | memset(cis, 0, sizeof(cisdump_t)); | ||
272 | |||
273 | cis->Length = fw->size + 1; | ||
274 | memcpy(cis->Data, fw->data, fw->size); | ||
275 | |||
276 | if (!pcmcia_replace_cis(s, cis)) | ||
277 | ret = 0; | ||
278 | } | ||
279 | release: | ||
280 | release_firmware(fw); | ||
281 | |||
282 | return (ret); | ||
274 | } | 283 | } |
275 | 284 | ||
276 | static struct pcmcia_bus_socket *pcmcia_get_bus_socket(struct pcmcia_bus_socket *s) | 285 | #else /* !CONFIG_PCMCIA_LOAD_CIS */ |
286 | |||
287 | static inline int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) | ||
277 | { | 288 | { |
278 | kref_get(&s->refcount); | 289 | return -ENODEV; |
279 | return (s); | ||
280 | } | 290 | } |
281 | 291 | ||
292 | #endif | ||
293 | |||
294 | |||
295 | /*======================================================================*/ | ||
296 | |||
297 | |||
282 | /** | 298 | /** |
283 | * pcmcia_register_driver - register a PCMCIA driver with the bus core | 299 | * pcmcia_register_driver - register a PCMCIA driver with the bus core |
284 | * | 300 | * |
@@ -292,6 +308,8 @@ int pcmcia_register_driver(struct pcmcia_driver *driver) | |||
292 | if (!driver) | 308 | if (!driver) |
293 | return -EINVAL; | 309 | return -EINVAL; |
294 | 310 | ||
311 | pcmcia_check_driver(driver); | ||
312 | |||
295 | /* initialize common fields */ | 313 | /* initialize common fields */ |
296 | driver->drv.bus = &pcmcia_bus_type; | 314 | driver->drv.bus = &pcmcia_bus_type; |
297 | driver->drv.owner = driver->owner; | 315 | driver->drv.owner = driver->owner; |
@@ -311,42 +329,10 @@ void pcmcia_unregister_driver(struct pcmcia_driver *driver) | |||
311 | } | 329 | } |
312 | EXPORT_SYMBOL(pcmcia_unregister_driver); | 330 | EXPORT_SYMBOL(pcmcia_unregister_driver); |
313 | 331 | ||
314 | #ifdef CONFIG_PROC_FS | ||
315 | static struct proc_dir_entry *proc_pccard = NULL; | ||
316 | |||
317 | static int proc_read_drivers_callback(struct device_driver *driver, void *d) | ||
318 | { | ||
319 | char **p = d; | ||
320 | struct pcmcia_driver *p_drv = container_of(driver, | ||
321 | struct pcmcia_driver, drv); | ||
322 | |||
323 | *p += sprintf(*p, "%-24.24s 1 %d\n", p_drv->drv.name, | ||
324 | #ifdef CONFIG_MODULE_UNLOAD | ||
325 | (p_drv->owner) ? module_refcount(p_drv->owner) : 1 | ||
326 | #else | ||
327 | 1 | ||
328 | #endif | ||
329 | ); | ||
330 | d = (void *) p; | ||
331 | |||
332 | return 0; | ||
333 | } | ||
334 | |||
335 | static int proc_read_drivers(char *buf, char **start, off_t pos, | ||
336 | int count, int *eof, void *data) | ||
337 | { | ||
338 | char *p = buf; | ||
339 | |||
340 | bus_for_each_drv(&pcmcia_bus_type, NULL, | ||
341 | (void *) &p, proc_read_drivers_callback); | ||
342 | |||
343 | return (p - buf); | ||
344 | } | ||
345 | #endif | ||
346 | 332 | ||
347 | /* pcmcia_device handling */ | 333 | /* pcmcia_device handling */ |
348 | 334 | ||
349 | static struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev) | 335 | struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev) |
350 | { | 336 | { |
351 | struct device *tmp_dev; | 337 | struct device *tmp_dev; |
352 | tmp_dev = get_device(&p_dev->dev); | 338 | tmp_dev = get_device(&p_dev->dev); |
@@ -355,7 +341,7 @@ static struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev) | |||
355 | return to_pcmcia_dev(tmp_dev); | 341 | return to_pcmcia_dev(tmp_dev); |
356 | } | 342 | } |
357 | 343 | ||
358 | static void pcmcia_put_dev(struct pcmcia_device *p_dev) | 344 | void pcmcia_put_dev(struct pcmcia_device *p_dev) |
359 | { | 345 | { |
360 | if (p_dev) | 346 | if (p_dev) |
361 | put_device(&p_dev->dev); | 347 | put_device(&p_dev->dev); |
@@ -365,7 +351,7 @@ static void pcmcia_release_dev(struct device *dev) | |||
365 | { | 351 | { |
366 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); | 352 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); |
367 | ds_dbg(1, "releasing dev %p\n", p_dev); | 353 | ds_dbg(1, "releasing dev %p\n", p_dev); |
368 | pcmcia_put_bus_socket(p_dev->socket->pcmcia); | 354 | pcmcia_put_socket(p_dev->socket); |
369 | kfree(p_dev); | 355 | kfree(p_dev); |
370 | } | 356 | } |
371 | 357 | ||
@@ -500,34 +486,38 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) | |||
500 | */ | 486 | */ |
501 | static DECLARE_MUTEX(device_add_lock); | 487 | static DECLARE_MUTEX(device_add_lock); |
502 | 488 | ||
503 | static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, unsigned int function) | 489 | struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) |
504 | { | 490 | { |
505 | struct pcmcia_device *p_dev; | 491 | struct pcmcia_device *p_dev; |
506 | unsigned long flags; | 492 | unsigned long flags; |
507 | 493 | ||
508 | s = pcmcia_get_bus_socket(s); | 494 | s = pcmcia_get_socket(s); |
509 | if (!s) | 495 | if (!s) |
510 | return NULL; | 496 | return NULL; |
511 | 497 | ||
512 | down(&device_add_lock); | 498 | down(&device_add_lock); |
513 | 499 | ||
500 | /* max of 2 devices per card */ | ||
501 | if (s->device_count == 2) | ||
502 | goto err_put; | ||
503 | |||
514 | p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL); | 504 | p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL); |
515 | if (!p_dev) | 505 | if (!p_dev) |
516 | goto err_put; | 506 | goto err_put; |
517 | memset(p_dev, 0, sizeof(struct pcmcia_device)); | 507 | memset(p_dev, 0, sizeof(struct pcmcia_device)); |
518 | 508 | ||
519 | p_dev->socket = s->parent; | 509 | p_dev->socket = s; |
520 | p_dev->device_no = (s->device_count++); | 510 | p_dev->device_no = (s->device_count++); |
521 | p_dev->func = function; | 511 | p_dev->func = function; |
522 | 512 | ||
523 | p_dev->dev.bus = &pcmcia_bus_type; | 513 | p_dev->dev.bus = &pcmcia_bus_type; |
524 | p_dev->dev.parent = s->parent->dev.dev; | 514 | p_dev->dev.parent = s->dev.dev; |
525 | p_dev->dev.release = pcmcia_release_dev; | 515 | p_dev->dev.release = pcmcia_release_dev; |
526 | sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no); | 516 | sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no); |
527 | 517 | ||
528 | /* compat */ | 518 | /* compat */ |
529 | p_dev->client.client_magic = CLIENT_MAGIC; | 519 | p_dev->client.client_magic = CLIENT_MAGIC; |
530 | p_dev->client.Socket = s->parent; | 520 | p_dev->client.Socket = s; |
531 | p_dev->client.Function = function; | 521 | p_dev->client.Function = function; |
532 | p_dev->client.state = CLIENT_UNBOUND; | 522 | p_dev->client.state = CLIENT_UNBOUND; |
533 | 523 | ||
@@ -536,6 +526,8 @@ static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, uns | |||
536 | list_add_tail(&p_dev->socket_device_list, &s->devices_list); | 526 | list_add_tail(&p_dev->socket_device_list, &s->devices_list); |
537 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 527 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
538 | 528 | ||
529 | pcmcia_device_query(p_dev); | ||
530 | |||
539 | if (device_register(&p_dev->dev)) { | 531 | if (device_register(&p_dev->dev)) { |
540 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 532 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); |
541 | list_del(&p_dev->socket_device_list); | 533 | list_del(&p_dev->socket_device_list); |
@@ -553,7 +545,7 @@ static struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, uns | |||
553 | s->device_count--; | 545 | s->device_count--; |
554 | err_put: | 546 | err_put: |
555 | up(&device_add_lock); | 547 | up(&device_add_lock); |
556 | pcmcia_put_bus_socket(s); | 548 | pcmcia_put_socket(s); |
557 | 549 | ||
558 | return NULL; | 550 | return NULL; |
559 | } | 551 | } |
@@ -584,23 +576,252 @@ static int pcmcia_card_add(struct pcmcia_socket *s) | |||
584 | /* this doesn't handle multifunction devices on one pcmcia function | 576 | /* this doesn't handle multifunction devices on one pcmcia function |
585 | * yet. */ | 577 | * yet. */ |
586 | for (i=0; i < no_funcs; i++) | 578 | for (i=0; i < no_funcs; i++) |
587 | pcmcia_device_add(s->pcmcia, i); | 579 | pcmcia_device_add(s, i); |
588 | 580 | ||
589 | return (ret); | 581 | return (ret); |
590 | } | 582 | } |
591 | 583 | ||
592 | 584 | ||
585 | static void pcmcia_delayed_add_pseudo_device(void *data) | ||
586 | { | ||
587 | struct pcmcia_socket *s = data; | ||
588 | pcmcia_device_add(s, 0); | ||
589 | s->pcmcia_state.device_add_pending = 0; | ||
590 | } | ||
591 | |||
592 | static inline void pcmcia_add_pseudo_device(struct pcmcia_socket *s) | ||
593 | { | ||
594 | if (!s->pcmcia_state.device_add_pending) { | ||
595 | schedule_work(&s->device_add); | ||
596 | s->pcmcia_state.device_add_pending = 1; | ||
597 | } | ||
598 | return; | ||
599 | } | ||
600 | |||
601 | static int pcmcia_requery(struct device *dev, void * _data) | ||
602 | { | ||
603 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); | ||
604 | if (!p_dev->dev.driver) | ||
605 | pcmcia_device_query(p_dev); | ||
606 | |||
607 | return 0; | ||
608 | } | ||
609 | |||
610 | static void pcmcia_bus_rescan(struct pcmcia_socket *skt) | ||
611 | { | ||
612 | int no_devices=0; | ||
613 | unsigned long flags; | ||
614 | |||
615 | /* must be called with skt_sem held */ | ||
616 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | ||
617 | if (list_empty(&skt->devices_list)) | ||
618 | no_devices=1; | ||
619 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
620 | |||
621 | /* if no devices were added for this socket yet because of | ||
622 | * missing resource information or other trouble, we need to | ||
623 | * do this now. */ | ||
624 | if (no_devices) { | ||
625 | int ret = pcmcia_card_add(skt); | ||
626 | if (ret) | ||
627 | return; | ||
628 | } | ||
629 | |||
630 | /* some device information might have changed because of a CIS | ||
631 | * update or because we can finally read it correctly... so | ||
632 | * determine it again, overwriting old values if necessary. */ | ||
633 | bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery); | ||
634 | |||
635 | /* we re-scan all devices, not just the ones connected to this | ||
636 | * socket. This does not matter, though. */ | ||
637 | bus_rescan_devices(&pcmcia_bus_type); | ||
638 | } | ||
639 | |||
640 | static inline int pcmcia_devmatch(struct pcmcia_device *dev, | ||
641 | struct pcmcia_device_id *did) | ||
642 | { | ||
643 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID) { | ||
644 | if ((!dev->has_manf_id) || (dev->manf_id != did->manf_id)) | ||
645 | return 0; | ||
646 | } | ||
647 | |||
648 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID) { | ||
649 | if ((!dev->has_card_id) || (dev->card_id != did->card_id)) | ||
650 | return 0; | ||
651 | } | ||
652 | |||
653 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION) { | ||
654 | if (dev->func != did->function) | ||
655 | return 0; | ||
656 | } | ||
657 | |||
658 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1) { | ||
659 | if (!dev->prod_id[0]) | ||
660 | return 0; | ||
661 | if (strcmp(did->prod_id[0], dev->prod_id[0])) | ||
662 | return 0; | ||
663 | } | ||
664 | |||
665 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2) { | ||
666 | if (!dev->prod_id[1]) | ||
667 | return 0; | ||
668 | if (strcmp(did->prod_id[1], dev->prod_id[1])) | ||
669 | return 0; | ||
670 | } | ||
671 | |||
672 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3) { | ||
673 | if (!dev->prod_id[2]) | ||
674 | return 0; | ||
675 | if (strcmp(did->prod_id[2], dev->prod_id[2])) | ||
676 | return 0; | ||
677 | } | ||
678 | |||
679 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4) { | ||
680 | if (!dev->prod_id[3]) | ||
681 | return 0; | ||
682 | if (strcmp(did->prod_id[3], dev->prod_id[3])) | ||
683 | return 0; | ||
684 | } | ||
685 | |||
686 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { | ||
687 | /* handle pseudo multifunction devices: | ||
688 | * there are at most two pseudo multifunction devices. | ||
689 | * if we're matching against the first, schedule a | ||
690 | * call which will then check whether there are two | ||
691 | * pseudo devices, and if not, add the second one. | ||
692 | */ | ||
693 | if (dev->device_no == 0) | ||
694 | pcmcia_add_pseudo_device(dev->socket); | ||
695 | |||
696 | if (dev->device_no != did->device_no) | ||
697 | return 0; | ||
698 | } | ||
699 | |||
700 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { | ||
701 | if ((!dev->has_func_id) || (dev->func_id != did->func_id)) | ||
702 | return 0; | ||
703 | |||
704 | /* if this is a pseudo-multi-function device, | ||
705 | * we need explicit matches */ | ||
706 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) | ||
707 | return 0; | ||
708 | if (dev->device_no) | ||
709 | return 0; | ||
710 | |||
711 | /* also, FUNC_ID matching needs to be activated by userspace | ||
712 | * after it has re-checked that there is no possible module | ||
713 | * with a prod_id/manf_id/card_id match. | ||
714 | */ | ||
715 | if (!dev->allow_func_id_match) | ||
716 | return 0; | ||
717 | } | ||
718 | |||
719 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { | ||
720 | if (!dev->socket->fake_cis) | ||
721 | pcmcia_load_firmware(dev, did->cisfile); | ||
722 | |||
723 | if (!dev->socket->fake_cis) | ||
724 | return 0; | ||
725 | } | ||
726 | |||
727 | if (did->match_flags & PCMCIA_DEV_ID_MATCH_ANONYMOUS) { | ||
728 | int i; | ||
729 | for (i=0; i<4; i++) | ||
730 | if (dev->prod_id[i]) | ||
731 | return 0; | ||
732 | if (dev->has_manf_id || dev->has_card_id || dev->has_func_id) | ||
733 | return 0; | ||
734 | } | ||
735 | |||
736 | dev->dev.driver_data = (void *) did; | ||
737 | |||
738 | return 1; | ||
739 | } | ||
740 | |||
741 | |||
593 | static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) { | 742 | static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) { |
594 | struct pcmcia_device * p_dev = to_pcmcia_dev(dev); | 743 | struct pcmcia_device * p_dev = to_pcmcia_dev(dev); |
595 | struct pcmcia_driver * p_drv = to_pcmcia_drv(drv); | 744 | struct pcmcia_driver * p_drv = to_pcmcia_drv(drv); |
745 | struct pcmcia_device_id *did = p_drv->id_table; | ||
596 | 746 | ||
597 | /* matching by cardmgr */ | 747 | /* matching by cardmgr */ |
598 | if (p_dev->cardmgr == p_drv) | 748 | if (p_dev->cardmgr == p_drv) |
599 | return 1; | 749 | return 1; |
600 | 750 | ||
751 | while (did && did->match_flags) { | ||
752 | if (pcmcia_devmatch(p_dev, did)) | ||
753 | return 1; | ||
754 | did++; | ||
755 | } | ||
756 | |||
601 | return 0; | 757 | return 0; |
602 | } | 758 | } |
603 | 759 | ||
760 | #ifdef CONFIG_HOTPLUG | ||
761 | |||
762 | static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp, | ||
763 | char *buffer, int buffer_size) | ||
764 | { | ||
765 | struct pcmcia_device *p_dev; | ||
766 | int i, length = 0; | ||
767 | u32 hash[4] = { 0, 0, 0, 0}; | ||
768 | |||
769 | if (!dev) | ||
770 | return -ENODEV; | ||
771 | |||
772 | p_dev = to_pcmcia_dev(dev); | ||
773 | |||
774 | /* calculate hashes */ | ||
775 | for (i=0; i<4; i++) { | ||
776 | if (!p_dev->prod_id[i]) | ||
777 | continue; | ||
778 | hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i])); | ||
779 | } | ||
780 | |||
781 | i = 0; | ||
782 | |||
783 | if (add_hotplug_env_var(envp, num_envp, &i, | ||
784 | buffer, buffer_size, &length, | ||
785 | "SOCKET_NO=%u", | ||
786 | p_dev->socket->sock)) | ||
787 | return -ENOMEM; | ||
788 | |||
789 | if (add_hotplug_env_var(envp, num_envp, &i, | ||
790 | buffer, buffer_size, &length, | ||
791 | "DEVICE_NO=%02X", | ||
792 | p_dev->device_no)) | ||
793 | return -ENOMEM; | ||
794 | |||
795 | if (add_hotplug_env_var(envp, num_envp, &i, | ||
796 | buffer, buffer_size, &length, | ||
797 | "MODALIAS=pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X" | ||
798 | "pa%08Xpb%08Xpc%08Xpd%08X", | ||
799 | p_dev->has_manf_id ? p_dev->manf_id : 0, | ||
800 | p_dev->has_card_id ? p_dev->card_id : 0, | ||
801 | p_dev->has_func_id ? p_dev->func_id : 0, | ||
802 | p_dev->func, | ||
803 | p_dev->device_no, | ||
804 | hash[0], | ||
805 | hash[1], | ||
806 | hash[2], | ||
807 | hash[3])) | ||
808 | return -ENOMEM; | ||
809 | |||
810 | envp[i] = NULL; | ||
811 | |||
812 | return 0; | ||
813 | } | ||
814 | |||
815 | #else | ||
816 | |||
817 | static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp, | ||
818 | char *buffer, int buffer_size) | ||
819 | { | ||
820 | return -ENODEV; | ||
821 | } | ||
822 | |||
823 | #endif | ||
824 | |||
604 | /************************ per-device sysfs output ***************************/ | 825 | /************************ per-device sysfs output ***************************/ |
605 | 826 | ||
606 | #define pcmcia_device_attr(field, test, format) \ | 827 | #define pcmcia_device_attr(field, test, format) \ |
@@ -626,6 +847,43 @@ pcmcia_device_stringattr(prod_id2, prod_id[1]); | |||
626 | pcmcia_device_stringattr(prod_id3, prod_id[2]); | 847 | pcmcia_device_stringattr(prod_id3, prod_id[2]); |
627 | pcmcia_device_stringattr(prod_id4, prod_id[3]); | 848 | pcmcia_device_stringattr(prod_id4, prod_id[3]); |
628 | 849 | ||
850 | static ssize_t modalias_show(struct device *dev, char *buf) | ||
851 | { | ||
852 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); | ||
853 | int i; | ||
854 | u32 hash[4] = { 0, 0, 0, 0}; | ||
855 | |||
856 | /* calculate hashes */ | ||
857 | for (i=0; i<4; i++) { | ||
858 | if (!p_dev->prod_id[i]) | ||
859 | continue; | ||
860 | hash[i] = crc32(0,p_dev->prod_id[i],strlen(p_dev->prod_id[i])); | ||
861 | } | ||
862 | return sprintf(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X" | ||
863 | "pa%08Xpb%08Xpc%08Xpd%08X\n", | ||
864 | p_dev->has_manf_id ? p_dev->manf_id : 0, | ||
865 | p_dev->has_card_id ? p_dev->card_id : 0, | ||
866 | p_dev->has_func_id ? p_dev->func_id : 0, | ||
867 | p_dev->func, p_dev->device_no, | ||
868 | hash[0], hash[1], hash[2], hash[3]); | ||
869 | } | ||
870 | |||
871 | static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, | ||
872 | struct device_attribute *attr, const char *buf, size_t count) | ||
873 | { | ||
874 | struct pcmcia_device *p_dev = to_pcmcia_dev(dev); | ||
875 | if (!count) | ||
876 | return -EINVAL; | ||
877 | |||
878 | down(&p_dev->socket->skt_sem); | ||
879 | p_dev->allow_func_id_match = 1; | ||
880 | up(&p_dev->socket->skt_sem); | ||
881 | |||
882 | bus_rescan_devices(&pcmcia_bus_type); | ||
883 | |||
884 | return count; | ||
885 | } | ||
886 | |||
629 | static struct device_attribute pcmcia_dev_attrs[] = { | 887 | static struct device_attribute pcmcia_dev_attrs[] = { |
630 | __ATTR(function, 0444, func_show, NULL), | 888 | __ATTR(function, 0444, func_show, NULL), |
631 | __ATTR_RO(func_id), | 889 | __ATTR_RO(func_id), |
@@ -635,46 +893,14 @@ static struct device_attribute pcmcia_dev_attrs[] = { | |||
635 | __ATTR_RO(prod_id2), | 893 | __ATTR_RO(prod_id2), |
636 | __ATTR_RO(prod_id3), | 894 | __ATTR_RO(prod_id3), |
637 | __ATTR_RO(prod_id4), | 895 | __ATTR_RO(prod_id4), |
896 | __ATTR_RO(modalias), | ||
897 | __ATTR(allow_func_id_match, 0200, NULL, pcmcia_store_allow_func_id_match), | ||
638 | __ATTR_NULL, | 898 | __ATTR_NULL, |
639 | }; | 899 | }; |
640 | 900 | ||
641 | 901 | ||
642 | /*====================================================================== | 902 | /*====================================================================== |
643 | 903 | ||
644 | These manage a ring buffer of events pending for one user process | ||
645 | |||
646 | ======================================================================*/ | ||
647 | |||
648 | static int queue_empty(user_info_t *user) | ||
649 | { | ||
650 | return (user->event_head == user->event_tail); | ||
651 | } | ||
652 | |||
653 | static event_t get_queued_event(user_info_t *user) | ||
654 | { | ||
655 | user->event_tail = (user->event_tail+1) % MAX_EVENTS; | ||
656 | return user->event[user->event_tail]; | ||
657 | } | ||
658 | |||
659 | static void queue_event(user_info_t *user, event_t event) | ||
660 | { | ||
661 | user->event_head = (user->event_head+1) % MAX_EVENTS; | ||
662 | if (user->event_head == user->event_tail) | ||
663 | user->event_tail = (user->event_tail+1) % MAX_EVENTS; | ||
664 | user->event[user->event_head] = event; | ||
665 | } | ||
666 | |||
667 | static void handle_event(struct pcmcia_bus_socket *s, event_t event) | ||
668 | { | ||
669 | user_info_t *user; | ||
670 | for (user = s->user; user; user = user->next) | ||
671 | queue_event(user, event); | ||
672 | wake_up_interruptible(&s->queue); | ||
673 | } | ||
674 | |||
675 | |||
676 | /*====================================================================== | ||
677 | |||
678 | The card status event handler. | 904 | The card status event handler. |
679 | 905 | ||
680 | ======================================================================*/ | 906 | ======================================================================*/ |
@@ -706,21 +932,13 @@ static int send_event_callback(struct device *dev, void * _data) | |||
706 | 932 | ||
707 | static int send_event(struct pcmcia_socket *s, event_t event, int priority) | 933 | static int send_event(struct pcmcia_socket *s, event_t event, int priority) |
708 | { | 934 | { |
709 | int ret = 0; | ||
710 | struct send_event_data private; | 935 | struct send_event_data private; |
711 | struct pcmcia_bus_socket *skt = pcmcia_get_bus_socket(s->pcmcia); | ||
712 | |||
713 | if (!skt) | ||
714 | return 0; | ||
715 | 936 | ||
716 | private.skt = s; | 937 | private.skt = s; |
717 | private.event = event; | 938 | private.event = event; |
718 | private.priority = priority; | 939 | private.priority = priority; |
719 | 940 | ||
720 | ret = bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback); | 941 | return bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback); |
721 | |||
722 | pcmcia_put_bus_socket(skt); | ||
723 | return ret; | ||
724 | } /* send_event */ | 942 | } /* send_event */ |
725 | 943 | ||
726 | 944 | ||
@@ -731,25 +949,25 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) | |||
731 | 949 | ||
732 | static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) | 950 | static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) |
733 | { | 951 | { |
734 | struct pcmcia_bus_socket *s = skt->pcmcia; | 952 | struct pcmcia_socket *s = pcmcia_get_socket(skt); |
735 | int ret = 0; | 953 | int ret = 0; |
736 | 954 | ||
737 | ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n", | 955 | ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n", |
738 | event, priority, s); | 956 | event, priority, skt); |
739 | 957 | ||
740 | switch (event) { | 958 | switch (event) { |
741 | 959 | ||
742 | case CS_EVENT_CARD_REMOVAL: | 960 | case CS_EVENT_CARD_REMOVAL: |
743 | s->state &= ~DS_SOCKET_PRESENT; | 961 | s->pcmcia_state.present = 0; |
744 | send_event(skt, event, priority); | 962 | send_event(skt, event, priority); |
745 | unbind_request(s); | 963 | unbind_request(skt); |
746 | handle_event(s, event); | 964 | handle_event(skt, event); |
747 | break; | 965 | break; |
748 | 966 | ||
749 | case CS_EVENT_CARD_INSERTION: | 967 | case CS_EVENT_CARD_INSERTION: |
750 | s->state |= DS_SOCKET_PRESENT; | 968 | s->pcmcia_state.present = 1; |
751 | pcmcia_card_add(skt); | 969 | pcmcia_card_add(skt); |
752 | handle_event(s, event); | 970 | handle_event(skt, event); |
753 | break; | 971 | break; |
754 | 972 | ||
755 | case CS_EVENT_EJECTION_REQUEST: | 973 | case CS_EVENT_EJECTION_REQUEST: |
@@ -757,137 +975,22 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) | |||
757 | break; | 975 | break; |
758 | 976 | ||
759 | default: | 977 | default: |
760 | handle_event(s, event); | 978 | handle_event(skt, event); |
761 | send_event(skt, event, priority); | 979 | send_event(skt, event, priority); |
762 | break; | 980 | break; |
763 | } | 981 | } |
764 | 982 | ||
983 | pcmcia_put_socket(s); | ||
984 | |||
765 | return 0; | 985 | return 0; |
766 | } /* ds_event */ | 986 | } /* ds_event */ |
767 | 987 | ||
768 | 988 | ||
769 | /*====================================================================== | ||
770 | |||
771 | bind_request() and bind_device() are merged by now. Register_client() | ||
772 | is called right at the end of bind_request(), during the driver's | ||
773 | ->attach() call. Individual descriptions: | ||
774 | |||
775 | bind_request() connects a socket to a particular client driver. | ||
776 | It looks up the specified device ID in the list of registered | ||
777 | drivers, binds it to the socket, and tries to create an instance | ||
778 | of the device. unbind_request() deletes a driver instance. | ||
779 | |||
780 | Bind_device() associates a device driver with a particular socket. | ||
781 | It is normally called by Driver Services after it has identified | ||
782 | a newly inserted card. An instance of that driver will then be | ||
783 | eligible to register as a client of this socket. | ||
784 | |||
785 | Register_client() uses the dev_info_t handle to match the | ||
786 | caller with a socket. The driver must have already been bound | ||
787 | to a socket with bind_device() -- in fact, bind_device() | ||
788 | allocates the client structure that will be used. | ||
789 | |||
790 | ======================================================================*/ | ||
791 | |||
792 | static int bind_request(struct pcmcia_bus_socket *s, bind_info_t *bind_info) | ||
793 | { | ||
794 | struct pcmcia_driver *p_drv; | ||
795 | struct pcmcia_device *p_dev; | ||
796 | int ret = 0; | ||
797 | unsigned long flags; | ||
798 | |||
799 | s = pcmcia_get_bus_socket(s); | ||
800 | if (!s) | ||
801 | return -EINVAL; | ||
802 | |||
803 | ds_dbg(2, "bind_request(%d, '%s')\n", s->parent->sock, | ||
804 | (char *)bind_info->dev_info); | ||
805 | |||
806 | p_drv = get_pcmcia_driver(&bind_info->dev_info); | ||
807 | if (!p_drv) { | ||
808 | ret = -EINVAL; | ||
809 | goto err_put; | ||
810 | } | ||
811 | |||
812 | if (!try_module_get(p_drv->owner)) { | ||
813 | ret = -EINVAL; | ||
814 | goto err_put_driver; | ||
815 | } | ||
816 | |||
817 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | ||
818 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { | ||
819 | if (p_dev->func == bind_info->function) { | ||
820 | if ((p_dev->dev.driver == &p_drv->drv)) { | ||
821 | if (p_dev->cardmgr) { | ||
822 | /* if there's already a device | ||
823 | * registered, and it was registered | ||
824 | * by userspace before, we need to | ||
825 | * return the "instance". */ | ||
826 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
827 | bind_info->instance = p_dev->instance; | ||
828 | ret = -EBUSY; | ||
829 | goto err_put_module; | ||
830 | } else { | ||
831 | /* the correct driver managed to bind | ||
832 | * itself magically to the correct | ||
833 | * device. */ | ||
834 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
835 | p_dev->cardmgr = p_drv; | ||
836 | ret = 0; | ||
837 | goto err_put_module; | ||
838 | } | ||
839 | } else if (!p_dev->dev.driver) { | ||
840 | /* there's already a device available where | ||
841 | * no device has been bound to yet. So we don't | ||
842 | * need to register a device! */ | ||
843 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
844 | goto rescan; | ||
845 | } | ||
846 | } | ||
847 | } | ||
848 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
849 | |||
850 | p_dev = pcmcia_device_add(s, bind_info->function); | ||
851 | if (!p_dev) { | ||
852 | ret = -EIO; | ||
853 | goto err_put_module; | ||
854 | } | ||
855 | |||
856 | rescan: | ||
857 | p_dev->cardmgr = p_drv; | ||
858 | |||
859 | pcmcia_device_query(p_dev); | ||
860 | |||
861 | /* | ||
862 | * Prevent this racing with a card insertion. | ||
863 | */ | ||
864 | down(&s->parent->skt_sem); | ||
865 | bus_rescan_devices(&pcmcia_bus_type); | ||
866 | up(&s->parent->skt_sem); | ||
867 | |||
868 | /* check whether the driver indeed matched. I don't care if this | ||
869 | * is racy or not, because it can only happen on cardmgr access | ||
870 | * paths... | ||
871 | */ | ||
872 | if (!(p_dev->dev.driver == &p_drv->drv)) | ||
873 | p_dev->cardmgr = NULL; | ||
874 | |||
875 | err_put_module: | ||
876 | module_put(p_drv->owner); | ||
877 | err_put_driver: | ||
878 | put_driver(&p_drv->drv); | ||
879 | err_put: | ||
880 | pcmcia_put_bus_socket(s); | ||
881 | |||
882 | return (ret); | ||
883 | } /* bind_request */ | ||
884 | |||
885 | 989 | ||
886 | int pcmcia_register_client(client_handle_t *handle, client_reg_t *req) | 990 | int pcmcia_register_client(client_handle_t *handle, client_reg_t *req) |
887 | { | 991 | { |
888 | client_t *client = NULL; | 992 | client_t *client = NULL; |
889 | struct pcmcia_socket *s; | 993 | struct pcmcia_socket *s = NULL; |
890 | struct pcmcia_bus_socket *skt = NULL; | ||
891 | struct pcmcia_device *p_dev = NULL; | 994 | struct pcmcia_device *p_dev = NULL; |
892 | 995 | ||
893 | /* Look for unbound client with matching dev_info */ | 996 | /* Look for unbound client with matching dev_info */ |
@@ -898,14 +1001,11 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req) | |||
898 | if (s->state & SOCKET_CARDBUS) | 1001 | if (s->state & SOCKET_CARDBUS) |
899 | continue; | 1002 | continue; |
900 | 1003 | ||
901 | skt = s->pcmcia; | 1004 | s = pcmcia_get_socket(s); |
902 | if (!skt) | 1005 | if (!s) |
903 | continue; | ||
904 | skt = pcmcia_get_bus_socket(skt); | ||
905 | if (!skt) | ||
906 | continue; | 1006 | continue; |
907 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | 1007 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); |
908 | list_for_each_entry(p_dev, &skt->devices_list, socket_device_list) { | 1008 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { |
909 | struct pcmcia_driver *p_drv; | 1009 | struct pcmcia_driver *p_drv; |
910 | p_dev = pcmcia_get_dev(p_dev); | 1010 | p_dev = pcmcia_get_dev(p_dev); |
911 | if (!p_dev) | 1011 | if (!p_dev) |
@@ -924,14 +1024,14 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req) | |||
924 | pcmcia_put_dev(p_dev); | 1024 | pcmcia_put_dev(p_dev); |
925 | } | 1025 | } |
926 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | 1026 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); |
927 | pcmcia_put_bus_socket(skt); | 1027 | pcmcia_put_socket(s); |
928 | } | 1028 | } |
929 | found: | 1029 | found: |
930 | up_read(&pcmcia_socket_list_rwsem); | 1030 | up_read(&pcmcia_socket_list_rwsem); |
931 | if (!p_dev || !client) | 1031 | if (!p_dev || !client) |
932 | return -ENODEV; | 1032 | return -ENODEV; |
933 | 1033 | ||
934 | pcmcia_put_bus_socket(skt); /* safe, as we already hold a reference from bind_device */ | 1034 | pcmcia_put_socket(s); /* safe, as we already hold a reference from bind_device */ |
935 | 1035 | ||
936 | *handle = client; | 1036 | *handle = client; |
937 | client->state &= ~CLIENT_UNBOUND; | 1037 | client->state &= ~CLIENT_UNBOUND; |
@@ -978,106 +1078,15 @@ int pcmcia_register_client(client_handle_t *handle, client_reg_t *req) | |||
978 | EXPORT_SYMBOL(pcmcia_register_client); | 1078 | EXPORT_SYMBOL(pcmcia_register_client); |
979 | 1079 | ||
980 | 1080 | ||
981 | /*====================================================================*/ | ||
982 | |||
983 | extern struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s); | ||
984 | |||
985 | static int get_device_info(struct pcmcia_bus_socket *s, bind_info_t *bind_info, int first) | ||
986 | { | ||
987 | dev_node_t *node; | ||
988 | struct pcmcia_device *p_dev; | ||
989 | unsigned long flags; | ||
990 | int ret = 0; | ||
991 | |||
992 | #ifdef CONFIG_CARDBUS | ||
993 | /* | ||
994 | * Some unbelievably ugly code to associate the PCI cardbus | ||
995 | * device and its driver with the PCMCIA "bind" information. | ||
996 | */ | ||
997 | { | ||
998 | struct pci_bus *bus; | ||
999 | |||
1000 | bus = pcmcia_lookup_bus(s->parent); | ||
1001 | if (bus) { | ||
1002 | struct list_head *list; | ||
1003 | struct pci_dev *dev = NULL; | ||
1004 | |||
1005 | list = bus->devices.next; | ||
1006 | while (list != &bus->devices) { | ||
1007 | struct pci_dev *pdev = pci_dev_b(list); | ||
1008 | list = list->next; | ||
1009 | |||
1010 | if (first) { | ||
1011 | dev = pdev; | ||
1012 | break; | ||
1013 | } | ||
1014 | |||
1015 | /* Try to handle "next" here some way? */ | ||
1016 | } | ||
1017 | if (dev && dev->driver) { | ||
1018 | strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN); | ||
1019 | bind_info->major = 0; | ||
1020 | bind_info->minor = 0; | ||
1021 | bind_info->next = NULL; | ||
1022 | return 0; | ||
1023 | } | ||
1024 | } | ||
1025 | } | ||
1026 | #endif | ||
1027 | |||
1028 | spin_lock_irqsave(&pcmcia_dev_list_lock, flags); | ||
1029 | list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { | ||
1030 | if (p_dev->func == bind_info->function) { | ||
1031 | p_dev = pcmcia_get_dev(p_dev); | ||
1032 | if (!p_dev) | ||
1033 | continue; | ||
1034 | goto found; | ||
1035 | } | ||
1036 | } | ||
1037 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
1038 | return -ENODEV; | ||
1039 | |||
1040 | found: | ||
1041 | spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); | ||
1042 | |||
1043 | if ((!p_dev->instance) || | ||
1044 | (p_dev->instance->state & DEV_CONFIG_PENDING)) { | ||
1045 | ret = -EAGAIN; | ||
1046 | goto err_put; | ||
1047 | } | ||
1048 | |||
1049 | if (first) | ||
1050 | node = p_dev->instance->dev; | ||
1051 | else | ||
1052 | for (node = p_dev->instance->dev; node; node = node->next) | ||
1053 | if (node == bind_info->next) | ||
1054 | break; | ||
1055 | if (!node) { | ||
1056 | ret = -ENODEV; | ||
1057 | goto err_put; | ||
1058 | } | ||
1059 | |||
1060 | strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN); | ||
1061 | bind_info->major = node->major; | ||
1062 | bind_info->minor = node->minor; | ||
1063 | bind_info->next = node->next; | ||
1064 | |||
1065 | err_put: | ||
1066 | pcmcia_put_dev(p_dev); | ||
1067 | return (ret); | ||
1068 | } /* get_device_info */ | ||
1069 | |||
1070 | /*====================================================================*/ | ||
1071 | |||
1072 | /* unbind _all_ devices attached to a given pcmcia_bus_socket. The | 1081 | /* unbind _all_ devices attached to a given pcmcia_bus_socket. The |
1073 | * drivers have been called with EVENT_CARD_REMOVAL before. | 1082 | * drivers have been called with EVENT_CARD_REMOVAL before. |
1074 | */ | 1083 | */ |
1075 | static int unbind_request(struct pcmcia_bus_socket *s) | 1084 | static int unbind_request(struct pcmcia_socket *s) |
1076 | { | 1085 | { |
1077 | struct pcmcia_device *p_dev; | 1086 | struct pcmcia_device *p_dev; |
1078 | unsigned long flags; | 1087 | unsigned long flags; |
1079 | 1088 | ||
1080 | ds_dbg(2, "unbind_request(%d)\n", s->parent->sock); | 1089 | ds_dbg(2, "unbind_request(%d)\n", s->sock); |
1081 | 1090 | ||
1082 | s->device_count = 0; | 1091 | s->device_count = 0; |
1083 | 1092 | ||
@@ -1133,433 +1142,58 @@ int pcmcia_deregister_client(client_handle_t handle) | |||
1133 | } /* deregister_client */ | 1142 | } /* deregister_client */ |
1134 | EXPORT_SYMBOL(pcmcia_deregister_client); | 1143 | EXPORT_SYMBOL(pcmcia_deregister_client); |
1135 | 1144 | ||
1136 | 1145 | static struct pcmcia_callback pcmcia_bus_callback = { | |
1137 | /*====================================================================== | 1146 | .owner = THIS_MODULE, |
1138 | 1147 | .event = ds_event, | |
1139 | The user-mode PC Card device interface | 1148 | .requery = pcmcia_bus_rescan, |
1140 | |||
1141 | ======================================================================*/ | ||
1142 | |||
1143 | static int ds_open(struct inode *inode, struct file *file) | ||
1144 | { | ||
1145 | socket_t i = iminor(inode); | ||
1146 | struct pcmcia_bus_socket *s; | ||
1147 | user_info_t *user; | ||
1148 | |||
1149 | ds_dbg(0, "ds_open(socket %d)\n", i); | ||
1150 | |||
1151 | s = get_socket_info_by_nr(i); | ||
1152 | if (!s) | ||
1153 | return -ENODEV; | ||
1154 | s = pcmcia_get_bus_socket(s); | ||
1155 | if (!s) | ||
1156 | return -ENODEV; | ||
1157 | |||
1158 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) { | ||
1159 | if (s->state & DS_SOCKET_BUSY) { | ||
1160 | pcmcia_put_bus_socket(s); | ||
1161 | return -EBUSY; | ||
1162 | } | ||
1163 | else | ||
1164 | s->state |= DS_SOCKET_BUSY; | ||
1165 | } | ||
1166 | |||
1167 | user = kmalloc(sizeof(user_info_t), GFP_KERNEL); | ||
1168 | if (!user) { | ||
1169 | pcmcia_put_bus_socket(s); | ||
1170 | return -ENOMEM; | ||
1171 | } | ||
1172 | user->event_tail = user->event_head = 0; | ||
1173 | user->next = s->user; | ||
1174 | user->user_magic = USER_MAGIC; | ||
1175 | user->socket = s; | ||
1176 | s->user = user; | ||
1177 | file->private_data = user; | ||
1178 | |||
1179 | if (s->state & DS_SOCKET_PRESENT) | ||
1180 | queue_event(user, CS_EVENT_CARD_INSERTION); | ||
1181 | return 0; | ||
1182 | } /* ds_open */ | ||
1183 | |||
1184 | /*====================================================================*/ | ||
1185 | |||
1186 | static int ds_release(struct inode *inode, struct file *file) | ||
1187 | { | ||
1188 | struct pcmcia_bus_socket *s; | ||
1189 | user_info_t *user, **link; | ||
1190 | |||
1191 | ds_dbg(0, "ds_release(socket %d)\n", iminor(inode)); | ||
1192 | |||
1193 | user = file->private_data; | ||
1194 | if (CHECK_USER(user)) | ||
1195 | goto out; | ||
1196 | |||
1197 | s = user->socket; | ||
1198 | |||
1199 | /* Unlink user data structure */ | ||
1200 | if ((file->f_flags & O_ACCMODE) != O_RDONLY) { | ||
1201 | s->state &= ~DS_SOCKET_BUSY; | ||
1202 | } | ||
1203 | file->private_data = NULL; | ||
1204 | for (link = &s->user; *link; link = &(*link)->next) | ||
1205 | if (*link == user) break; | ||
1206 | if (link == NULL) | ||
1207 | goto out; | ||
1208 | *link = user->next; | ||
1209 | user->user_magic = 0; | ||
1210 | kfree(user); | ||
1211 | pcmcia_put_bus_socket(s); | ||
1212 | out: | ||
1213 | return 0; | ||
1214 | } /* ds_release */ | ||
1215 | |||
1216 | /*====================================================================*/ | ||
1217 | |||
1218 | static ssize_t ds_read(struct file *file, char __user *buf, | ||
1219 | size_t count, loff_t *ppos) | ||
1220 | { | ||
1221 | struct pcmcia_bus_socket *s; | ||
1222 | user_info_t *user; | ||
1223 | int ret; | ||
1224 | |||
1225 | ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_dentry->d_inode)); | ||
1226 | |||
1227 | if (count < 4) | ||
1228 | return -EINVAL; | ||
1229 | |||
1230 | user = file->private_data; | ||
1231 | if (CHECK_USER(user)) | ||
1232 | return -EIO; | ||
1233 | |||
1234 | s = user->socket; | ||
1235 | if (s->state & DS_SOCKET_DEAD) | ||
1236 | return -EIO; | ||
1237 | |||
1238 | ret = wait_event_interruptible(s->queue, !queue_empty(user)); | ||
1239 | if (ret == 0) | ||
1240 | ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4; | ||
1241 | |||
1242 | return ret; | ||
1243 | } /* ds_read */ | ||
1244 | |||
1245 | /*====================================================================*/ | ||
1246 | |||
1247 | static ssize_t ds_write(struct file *file, const char __user *buf, | ||
1248 | size_t count, loff_t *ppos) | ||
1249 | { | ||
1250 | ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_dentry->d_inode)); | ||
1251 | |||
1252 | if (count != 4) | ||
1253 | return -EINVAL; | ||
1254 | if ((file->f_flags & O_ACCMODE) == O_RDONLY) | ||
1255 | return -EBADF; | ||
1256 | |||
1257 | return -EIO; | ||
1258 | } /* ds_write */ | ||
1259 | |||
1260 | /*====================================================================*/ | ||
1261 | |||
1262 | /* No kernel lock - fine */ | ||
1263 | static u_int ds_poll(struct file *file, poll_table *wait) | ||
1264 | { | ||
1265 | struct pcmcia_bus_socket *s; | ||
1266 | user_info_t *user; | ||
1267 | |||
1268 | ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_dentry->d_inode)); | ||
1269 | |||
1270 | user = file->private_data; | ||
1271 | if (CHECK_USER(user)) | ||
1272 | return POLLERR; | ||
1273 | s = user->socket; | ||
1274 | /* | ||
1275 | * We don't check for a dead socket here since that | ||
1276 | * will send cardmgr into an endless spin. | ||
1277 | */ | ||
1278 | poll_wait(file, &s->queue, wait); | ||
1279 | if (!queue_empty(user)) | ||
1280 | return POLLIN | POLLRDNORM; | ||
1281 | return 0; | ||
1282 | } /* ds_poll */ | ||
1283 | |||
1284 | /*====================================================================*/ | ||
1285 | |||
1286 | extern int pcmcia_adjust_resource_info(adjust_t *adj); | ||
1287 | |||
1288 | static int ds_ioctl(struct inode * inode, struct file * file, | ||
1289 | u_int cmd, u_long arg) | ||
1290 | { | ||
1291 | struct pcmcia_bus_socket *s; | ||
1292 | void __user *uarg = (char __user *)arg; | ||
1293 | u_int size; | ||
1294 | int ret, err; | ||
1295 | ds_ioctl_arg_t *buf; | ||
1296 | user_info_t *user; | ||
1297 | |||
1298 | ds_dbg(2, "ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg); | ||
1299 | |||
1300 | user = file->private_data; | ||
1301 | if (CHECK_USER(user)) | ||
1302 | return -EIO; | ||
1303 | |||
1304 | s = user->socket; | ||
1305 | if (s->state & DS_SOCKET_DEAD) | ||
1306 | return -EIO; | ||
1307 | |||
1308 | size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT; | ||
1309 | if (size > sizeof(ds_ioctl_arg_t)) return -EINVAL; | ||
1310 | |||
1311 | /* Permission check */ | ||
1312 | if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN)) | ||
1313 | return -EPERM; | ||
1314 | |||
1315 | if (cmd & IOC_IN) { | ||
1316 | if (!access_ok(VERIFY_READ, uarg, size)) { | ||
1317 | ds_dbg(3, "ds_ioctl(): verify_read = %d\n", -EFAULT); | ||
1318 | return -EFAULT; | ||
1319 | } | ||
1320 | } | ||
1321 | if (cmd & IOC_OUT) { | ||
1322 | if (!access_ok(VERIFY_WRITE, uarg, size)) { | ||
1323 | ds_dbg(3, "ds_ioctl(): verify_write = %d\n", -EFAULT); | ||
1324 | return -EFAULT; | ||
1325 | } | ||
1326 | } | ||
1327 | buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL); | ||
1328 | if (!buf) | ||
1329 | return -ENOMEM; | ||
1330 | |||
1331 | err = ret = 0; | ||
1332 | |||
1333 | if (cmd & IOC_IN) __copy_from_user((char *)buf, uarg, size); | ||
1334 | |||
1335 | switch (cmd) { | ||
1336 | case DS_ADJUST_RESOURCE_INFO: | ||
1337 | ret = pcmcia_adjust_resource_info(&buf->adjust); | ||
1338 | break; | ||
1339 | case DS_GET_CARD_SERVICES_INFO: | ||
1340 | ret = pcmcia_get_card_services_info(&buf->servinfo); | ||
1341 | break; | ||
1342 | case DS_GET_CONFIGURATION_INFO: | ||
1343 | if (buf->config.Function && | ||
1344 | (buf->config.Function >= s->parent->functions)) | ||
1345 | ret = CS_BAD_ARGS; | ||
1346 | else | ||
1347 | ret = pccard_get_configuration_info(s->parent, | ||
1348 | buf->config.Function, &buf->config); | ||
1349 | break; | ||
1350 | case DS_GET_FIRST_TUPLE: | ||
1351 | down(&s->parent->skt_sem); | ||
1352 | pcmcia_validate_mem(s->parent); | ||
1353 | up(&s->parent->skt_sem); | ||
1354 | ret = pccard_get_first_tuple(s->parent, BIND_FN_ALL, &buf->tuple); | ||
1355 | break; | ||
1356 | case DS_GET_NEXT_TUPLE: | ||
1357 | ret = pccard_get_next_tuple(s->parent, BIND_FN_ALL, &buf->tuple); | ||
1358 | break; | ||
1359 | case DS_GET_TUPLE_DATA: | ||
1360 | buf->tuple.TupleData = buf->tuple_parse.data; | ||
1361 | buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data); | ||
1362 | ret = pccard_get_tuple_data(s->parent, &buf->tuple); | ||
1363 | break; | ||
1364 | case DS_PARSE_TUPLE: | ||
1365 | buf->tuple.TupleData = buf->tuple_parse.data; | ||
1366 | ret = pccard_parse_tuple(&buf->tuple, &buf->tuple_parse.parse); | ||
1367 | break; | ||
1368 | case DS_RESET_CARD: | ||
1369 | ret = pccard_reset_card(s->parent); | ||
1370 | break; | ||
1371 | case DS_GET_STATUS: | ||
1372 | if (buf->status.Function && | ||
1373 | (buf->status.Function >= s->parent->functions)) | ||
1374 | ret = CS_BAD_ARGS; | ||
1375 | else | ||
1376 | ret = pccard_get_status(s->parent, buf->status.Function, &buf->status); | ||
1377 | break; | ||
1378 | case DS_VALIDATE_CIS: | ||
1379 | down(&s->parent->skt_sem); | ||
1380 | pcmcia_validate_mem(s->parent); | ||
1381 | up(&s->parent->skt_sem); | ||
1382 | ret = pccard_validate_cis(s->parent, BIND_FN_ALL, &buf->cisinfo); | ||
1383 | break; | ||
1384 | case DS_SUSPEND_CARD: | ||
1385 | ret = pcmcia_suspend_card(s->parent); | ||
1386 | break; | ||
1387 | case DS_RESUME_CARD: | ||
1388 | ret = pcmcia_resume_card(s->parent); | ||
1389 | break; | ||
1390 | case DS_EJECT_CARD: | ||
1391 | err = pcmcia_eject_card(s->parent); | ||
1392 | break; | ||
1393 | case DS_INSERT_CARD: | ||
1394 | err = pcmcia_insert_card(s->parent); | ||
1395 | break; | ||
1396 | case DS_ACCESS_CONFIGURATION_REGISTER: | ||
1397 | if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) { | ||
1398 | err = -EPERM; | ||
1399 | goto free_out; | ||
1400 | } | ||
1401 | if (buf->conf_reg.Function && | ||
1402 | (buf->conf_reg.Function >= s->parent->functions)) | ||
1403 | ret = CS_BAD_ARGS; | ||
1404 | else | ||
1405 | ret = pccard_access_configuration_register(s->parent, | ||
1406 | buf->conf_reg.Function, &buf->conf_reg); | ||
1407 | break; | ||
1408 | case DS_GET_FIRST_REGION: | ||
1409 | case DS_GET_NEXT_REGION: | ||
1410 | case DS_BIND_MTD: | ||
1411 | if (!capable(CAP_SYS_ADMIN)) { | ||
1412 | err = -EPERM; | ||
1413 | goto free_out; | ||
1414 | } else { | ||
1415 | static int printed = 0; | ||
1416 | if (!printed) { | ||
1417 | printk(KERN_WARNING "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n"); | ||
1418 | printk(KERN_WARNING "MTD handling any more.\n"); | ||
1419 | printed++; | ||
1420 | } | ||
1421 | } | ||
1422 | err = -EINVAL; | ||
1423 | goto free_out; | ||
1424 | break; | ||
1425 | case DS_GET_FIRST_WINDOW: | ||
1426 | ret = pcmcia_get_window(s->parent, &buf->win_info.handle, 0, | ||
1427 | &buf->win_info.window); | ||
1428 | break; | ||
1429 | case DS_GET_NEXT_WINDOW: | ||
1430 | ret = pcmcia_get_window(s->parent, &buf->win_info.handle, | ||
1431 | buf->win_info.handle->index + 1, &buf->win_info.window); | ||
1432 | break; | ||
1433 | case DS_GET_MEM_PAGE: | ||
1434 | ret = pcmcia_get_mem_page(buf->win_info.handle, | ||
1435 | &buf->win_info.map); | ||
1436 | break; | ||
1437 | case DS_REPLACE_CIS: | ||
1438 | ret = pcmcia_replace_cis(s->parent, &buf->cisdump); | ||
1439 | break; | ||
1440 | case DS_BIND_REQUEST: | ||
1441 | if (!capable(CAP_SYS_ADMIN)) { | ||
1442 | err = -EPERM; | ||
1443 | goto free_out; | ||
1444 | } | ||
1445 | err = bind_request(s, &buf->bind_info); | ||
1446 | break; | ||
1447 | case DS_GET_DEVICE_INFO: | ||
1448 | err = get_device_info(s, &buf->bind_info, 1); | ||
1449 | break; | ||
1450 | case DS_GET_NEXT_DEVICE: | ||
1451 | err = get_device_info(s, &buf->bind_info, 0); | ||
1452 | break; | ||
1453 | case DS_UNBIND_REQUEST: | ||
1454 | err = 0; | ||
1455 | break; | ||
1456 | default: | ||
1457 | err = -EINVAL; | ||
1458 | } | ||
1459 | |||
1460 | if ((err == 0) && (ret != CS_SUCCESS)) { | ||
1461 | ds_dbg(2, "ds_ioctl: ret = %d\n", ret); | ||
1462 | switch (ret) { | ||
1463 | case CS_BAD_SOCKET: case CS_NO_CARD: | ||
1464 | err = -ENODEV; break; | ||
1465 | case CS_BAD_ARGS: case CS_BAD_ATTRIBUTE: case CS_BAD_IRQ: | ||
1466 | case CS_BAD_TUPLE: | ||
1467 | err = -EINVAL; break; | ||
1468 | case CS_IN_USE: | ||
1469 | err = -EBUSY; break; | ||
1470 | case CS_OUT_OF_RESOURCE: | ||
1471 | err = -ENOSPC; break; | ||
1472 | case CS_NO_MORE_ITEMS: | ||
1473 | err = -ENODATA; break; | ||
1474 | case CS_UNSUPPORTED_FUNCTION: | ||
1475 | err = -ENOSYS; break; | ||
1476 | default: | ||
1477 | err = -EIO; break; | ||
1478 | } | ||
1479 | } | ||
1480 | |||
1481 | if (cmd & IOC_OUT) { | ||
1482 | if (__copy_to_user(uarg, (char *)buf, size)) | ||
1483 | err = -EFAULT; | ||
1484 | } | ||
1485 | |||
1486 | free_out: | ||
1487 | kfree(buf); | ||
1488 | return err; | ||
1489 | } /* ds_ioctl */ | ||
1490 | |||
1491 | /*====================================================================*/ | ||
1492 | |||
1493 | static struct file_operations ds_fops = { | ||
1494 | .owner = THIS_MODULE, | ||
1495 | .open = ds_open, | ||
1496 | .release = ds_release, | ||
1497 | .ioctl = ds_ioctl, | ||
1498 | .read = ds_read, | ||
1499 | .write = ds_write, | ||
1500 | .poll = ds_poll, | ||
1501 | }; | 1149 | }; |
1502 | 1150 | ||
1503 | static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev) | 1151 | static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev) |
1504 | { | 1152 | { |
1505 | struct pcmcia_socket *socket = class_get_devdata(class_dev); | 1153 | struct pcmcia_socket *socket = class_get_devdata(class_dev); |
1506 | struct pcmcia_bus_socket *s; | ||
1507 | int ret; | 1154 | int ret; |
1508 | 1155 | ||
1509 | s = kmalloc(sizeof(struct pcmcia_bus_socket), GFP_KERNEL); | 1156 | socket = pcmcia_get_socket(socket); |
1510 | if(!s) | 1157 | if (!socket) { |
1511 | return -ENOMEM; | ||
1512 | memset(s, 0, sizeof(struct pcmcia_bus_socket)); | ||
1513 | |||
1514 | /* get reference to parent socket */ | ||
1515 | s->parent = pcmcia_get_socket(socket); | ||
1516 | if (!s->parent) { | ||
1517 | printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket); | 1158 | printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket); |
1518 | kfree (s); | ||
1519 | return -ENODEV; | 1159 | return -ENODEV; |
1520 | } | 1160 | } |
1521 | 1161 | ||
1522 | kref_init(&s->refcount); | ||
1523 | |||
1524 | /* | 1162 | /* |
1525 | * Ugly. But we want to wait for the socket threads to have started up. | 1163 | * Ugly. But we want to wait for the socket threads to have started up. |
1526 | * We really should let the drivers themselves drive some of this.. | 1164 | * We really should let the drivers themselves drive some of this.. |
1527 | */ | 1165 | */ |
1528 | msleep(250); | 1166 | msleep(250); |
1529 | 1167 | ||
1530 | init_waitqueue_head(&s->queue); | 1168 | #ifdef CONFIG_PCMCIA_IOCTL |
1531 | INIT_LIST_HEAD(&s->devices_list); | 1169 | init_waitqueue_head(&socket->queue); |
1532 | 1170 | #endif | |
1533 | /* Set up hotline to Card Services */ | 1171 | INIT_LIST_HEAD(&socket->devices_list); |
1534 | s->callback.owner = THIS_MODULE; | 1172 | INIT_WORK(&socket->device_add, pcmcia_delayed_add_pseudo_device, socket); |
1535 | s->callback.event = &ds_event; | 1173 | memset(&socket->pcmcia_state, 0, sizeof(u8)); |
1536 | s->callback.resources_done = &pcmcia_card_add; | 1174 | socket->device_count = 0; |
1537 | socket->pcmcia = s; | ||
1538 | 1175 | ||
1539 | ret = pccard_register_pcmcia(socket, &s->callback); | 1176 | ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback); |
1540 | if (ret) { | 1177 | if (ret) { |
1541 | printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket); | 1178 | printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket); |
1542 | pcmcia_put_bus_socket(s); | 1179 | pcmcia_put_socket(socket); |
1543 | socket->pcmcia = NULL; | ||
1544 | return (ret); | 1180 | return (ret); |
1545 | } | 1181 | } |
1546 | 1182 | ||
1547 | return 0; | 1183 | return 0; |
1548 | } | 1184 | } |
1549 | 1185 | ||
1550 | |||
1551 | static void pcmcia_bus_remove_socket(struct class_device *class_dev) | 1186 | static void pcmcia_bus_remove_socket(struct class_device *class_dev) |
1552 | { | 1187 | { |
1553 | struct pcmcia_socket *socket = class_get_devdata(class_dev); | 1188 | struct pcmcia_socket *socket = class_get_devdata(class_dev); |
1554 | 1189 | ||
1555 | if (!socket || !socket->pcmcia) | 1190 | if (!socket) |
1556 | return; | 1191 | return; |
1557 | 1192 | ||
1193 | socket->pcmcia_state.dead = 1; | ||
1558 | pccard_register_pcmcia(socket, NULL); | 1194 | pccard_register_pcmcia(socket, NULL); |
1559 | 1195 | ||
1560 | socket->pcmcia->state |= DS_SOCKET_DEAD; | 1196 | pcmcia_put_socket(socket); |
1561 | pcmcia_put_bus_socket(socket->pcmcia); | ||
1562 | socket->pcmcia = NULL; | ||
1563 | 1197 | ||
1564 | return; | 1198 | return; |
1565 | } | 1199 | } |
@@ -1575,34 +1209,20 @@ static struct class_interface pcmcia_bus_interface = { | |||
1575 | 1209 | ||
1576 | struct bus_type pcmcia_bus_type = { | 1210 | struct bus_type pcmcia_bus_type = { |
1577 | .name = "pcmcia", | 1211 | .name = "pcmcia", |
1212 | .hotplug = pcmcia_bus_hotplug, | ||
1578 | .match = pcmcia_bus_match, | 1213 | .match = pcmcia_bus_match, |
1579 | .dev_attrs = pcmcia_dev_attrs, | 1214 | .dev_attrs = pcmcia_dev_attrs, |
1580 | }; | 1215 | }; |
1581 | EXPORT_SYMBOL(pcmcia_bus_type); | ||
1582 | 1216 | ||
1583 | 1217 | ||
1584 | static int __init init_pcmcia_bus(void) | 1218 | static int __init init_pcmcia_bus(void) |
1585 | { | 1219 | { |
1586 | int i; | ||
1587 | |||
1588 | spin_lock_init(&pcmcia_dev_list_lock); | 1220 | spin_lock_init(&pcmcia_dev_list_lock); |
1589 | 1221 | ||
1590 | bus_register(&pcmcia_bus_type); | 1222 | bus_register(&pcmcia_bus_type); |
1591 | class_interface_register(&pcmcia_bus_interface); | 1223 | class_interface_register(&pcmcia_bus_interface); |
1592 | 1224 | ||
1593 | /* Set up character device for user mode clients */ | 1225 | pcmcia_setup_ioctl(); |
1594 | i = register_chrdev(0, "pcmcia", &ds_fops); | ||
1595 | if (i < 0) | ||
1596 | printk(KERN_NOTICE "unable to find a free device # for " | ||
1597 | "Driver Services (error=%d)\n", i); | ||
1598 | else | ||
1599 | major_dev = i; | ||
1600 | |||
1601 | #ifdef CONFIG_PROC_FS | ||
1602 | proc_pccard = proc_mkdir("pccard", proc_bus); | ||
1603 | if (proc_pccard) | ||
1604 | create_proc_read_entry("drivers",0,proc_pccard,proc_read_drivers,NULL); | ||
1605 | #endif | ||
1606 | 1226 | ||
1607 | return 0; | 1227 | return 0; |
1608 | } | 1228 | } |
@@ -1612,48 +1232,13 @@ fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that | |||
1612 | 1232 | ||
1613 | static void __exit exit_pcmcia_bus(void) | 1233 | static void __exit exit_pcmcia_bus(void) |
1614 | { | 1234 | { |
1615 | class_interface_unregister(&pcmcia_bus_interface); | 1235 | pcmcia_cleanup_ioctl(); |
1616 | 1236 | ||
1617 | #ifdef CONFIG_PROC_FS | 1237 | class_interface_unregister(&pcmcia_bus_interface); |
1618 | if (proc_pccard) { | ||
1619 | remove_proc_entry("drivers", proc_pccard); | ||
1620 | remove_proc_entry("pccard", proc_bus); | ||
1621 | } | ||
1622 | #endif | ||
1623 | if (major_dev != -1) | ||
1624 | unregister_chrdev(major_dev, "pcmcia"); | ||
1625 | 1238 | ||
1626 | bus_unregister(&pcmcia_bus_type); | 1239 | bus_unregister(&pcmcia_bus_type); |
1627 | } | 1240 | } |
1628 | module_exit(exit_pcmcia_bus); | 1241 | module_exit(exit_pcmcia_bus); |
1629 | 1242 | ||
1630 | 1243 | ||
1631 | |||
1632 | /* helpers for backwards-compatible functions */ | ||
1633 | |||
1634 | static struct pcmcia_bus_socket * get_socket_info_by_nr(unsigned int nr) | ||
1635 | { | ||
1636 | struct pcmcia_socket * s = pcmcia_get_socket_by_nr(nr); | ||
1637 | if (s && s->pcmcia) | ||
1638 | return s->pcmcia; | ||
1639 | else | ||
1640 | return NULL; | ||
1641 | } | ||
1642 | |||
1643 | /* backwards-compatible accessing of driver --- by name! */ | ||
1644 | |||
1645 | static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info) | ||
1646 | { | ||
1647 | struct device_driver *drv; | ||
1648 | struct pcmcia_driver *p_drv; | ||
1649 | |||
1650 | drv = driver_find((char *) dev_info, &pcmcia_bus_type); | ||
1651 | if (!drv) | ||
1652 | return NULL; | ||
1653 | |||
1654 | p_drv = container_of(drv, struct pcmcia_driver, drv); | ||
1655 | |||
1656 | return (p_drv); | ||
1657 | } | ||
1658 | |||
1659 | MODULE_ALIAS("ds"); | 1244 | MODULE_ALIAS("ds"); |