2 * pcmcia_ioctl.c -- ioctl interface for cardmgr and cardctl
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2004 Dominik Brodowski
17 * This file will go away soon.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/major.h>
25 #include <linux/errno.h>
26 #include <linux/ioctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/poll.h>
29 #include <linux/pci.h>
30 #include <linux/smp_lock.h>
31 #include <linux/workqueue.h>
33 #include <pcmcia/cs_types.h>
34 #include <pcmcia/cs.h>
35 #include <pcmcia/cistpl.h>
36 #include <pcmcia/cisreg.h>
37 #include <pcmcia/ds.h>
38 #include <pcmcia/ss.h>
40 #include "cs_internal.h"
42 static int major_dev = -1;
45 /* Device user information */
47 #define USER_MAGIC 0x7ea4
48 #define CHECK_USER(u) \
49 (((u) == NULL) || ((u)->user_magic != USER_MAGIC))
51 typedef struct user_info_t {
53 int event_head, event_tail;
54 event_t event[MAX_EVENTS];
55 struct user_info_t *next;
56 struct pcmcia_socket *socket;
60 #ifdef CONFIG_PCMCIA_DEBUG
61 extern int ds_pc_debug;
63 #define ds_dbg(lvl, fmt, arg...) do { \
64 if (ds_pc_debug >= lvl) \
65 printk(KERN_DEBUG "ds: " fmt , ## arg); \
68 #define ds_dbg(lvl, fmt, arg...) do { } while (0)
71 static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s,
72 unsigned int function)
74 struct pcmcia_device *p_dev = NULL;
77 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
78 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
79 if (p_dev->func == function) {
80 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
81 return pcmcia_get_dev(p_dev);
84 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
88 /* backwards-compatible accessing of driver --- by name! */
90 static struct pcmcia_driver *get_pcmcia_driver(dev_info_t *dev_info)
92 struct device_driver *drv;
93 struct pcmcia_driver *p_drv;
95 drv = driver_find((char *) dev_info, &pcmcia_bus_type);
99 p_drv = container_of(drv, struct pcmcia_driver, drv);
105 #ifdef CONFIG_PROC_FS
106 static struct proc_dir_entry *proc_pccard = NULL;
108 static int proc_read_drivers_callback(struct device_driver *driver, void *d)
111 struct pcmcia_driver *p_drv = container_of(driver,
112 struct pcmcia_driver, drv);
114 *p += sprintf(*p, "%-24.24s 1 %d\n", p_drv->drv.name,
115 #ifdef CONFIG_MODULE_UNLOAD
116 (p_drv->owner) ? module_refcount(p_drv->owner) : 1
126 static int proc_read_drivers(char *buf, char **start, off_t pos,
127 int count, int *eof, void *data)
132 rc = bus_for_each_drv(&pcmcia_bus_type, NULL,
133 (void *) &p, proc_read_drivers_callback);
142 #ifdef CONFIG_PCMCIA_PROBE
144 static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
149 irq = adj->resource.irq.IRQ;
150 if ((irq < 0) || (irq > 15))
153 if (adj->Action != REMOVE_MANAGED_RESOURCE)
158 if (!(s->irq_mask & mask))
161 s->irq_mask &= ~mask;
168 static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
174 static int pcmcia_adjust_resource_info(adjust_t *adj)
176 struct pcmcia_socket *s;
180 down_read(&pcmcia_socket_list_rwsem);
181 list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
183 if (adj->Resource == RES_IRQ)
184 ret = adjust_irq(s, adj);
186 else if (s->resource_ops->add_io) {
187 unsigned long begin, end;
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);
196 } else if (!(s->resource_setup_old))
197 s->resource_setup_old = 1;
198 spin_unlock_irqrestore(&s->lock, flags);
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);
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);
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
217 spin_lock_irqsave(&s->lock, flags);
218 s->resource_setup_done = 1;
219 spin_unlock_irqrestore(&s->lock, flags);
223 up_read(&pcmcia_socket_list_rwsem);
228 /** pccard_get_status
230 * Get the current socket state bits. We don't support the latched
231 * SocketState yet: I haven't seen any point for it.
234 static int pccard_get_status(struct pcmcia_socket *s,
235 struct pcmcia_device *p_dev,
241 s->ops->get_status(s, &val);
242 status->CardState = status->SocketState = 0;
243 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
244 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
245 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
246 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
247 if (s->state & SOCKET_SUSPEND)
248 status->CardState |= CS_EVENT_PM_SUSPEND;
249 if (!(s->state & SOCKET_PRESENT))
252 c = (p_dev) ? p_dev->function_config : NULL;
254 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
255 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
257 if (c->CardValues & PRESENT_PIN_REPLACE) {
258 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, ®);
260 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
262 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
264 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
266 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
268 /* No PRR? Then assume we're always ready */
269 status->CardState |= CS_EVENT_READY_CHANGE;
271 if (c->CardValues & PRESENT_EXT_STATUS) {
272 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, ®);
274 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
279 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
281 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
283 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
285 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
287 } /* pccard_get_status */
289 int pccard_get_configuration_info(struct pcmcia_socket *s,
290 struct pcmcia_device *p_dev,
291 config_info_t *config)
295 if (!(s->state & SOCKET_PRESENT))
299 #ifdef CONFIG_CARDBUS
300 if (s->state & SOCKET_CARDBUS) {
301 memset(config, 0, sizeof(config_info_t));
302 config->Vcc = s->socket.Vcc;
303 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
304 config->Option = s->cb_dev->subordinate->number;
305 if (s->state & SOCKET_CARDBUS_CONFIG) {
306 config->Attributes = CONF_VALID_CLIENT;
307 config->IntType = INT_CARDBUS;
308 config->AssignedIRQ = s->irq.AssignedIRQ;
309 if (config->AssignedIRQ)
310 config->Attributes |= CONF_ENABLE_IRQ;
312 config->BasePort1 = s->io[0].res->start;
313 config->NumPorts1 = s->io[0].res->end -
314 config->BasePort1 + 1;
322 c = p_dev->function_config;
323 config->Function = p_dev->func;
326 config->Function = 0;
329 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
330 config->Attributes = 0;
331 config->Vcc = s->socket.Vcc;
332 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
336 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
337 config->Vcc = s->socket.Vcc;
338 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
339 config->IntType = c->IntType;
340 config->ConfigBase = c->ConfigBase;
341 config->Status = c->Status;
342 config->Pin = c->Pin;
343 config->Copy = c->Copy;
344 config->Option = c->Option;
345 config->ExtStatus = c->ExtStatus;
346 config->Present = config->CardValues = c->CardValues;
347 config->IRQAttributes = c->irq.Attributes;
348 config->AssignedIRQ = s->irq.AssignedIRQ;
349 config->BasePort1 = c->io.BasePort1;
350 config->NumPorts1 = c->io.NumPorts1;
351 config->Attributes1 = c->io.Attributes1;
352 config->BasePort2 = c->io.BasePort2;
353 config->NumPorts2 = c->io.NumPorts2;
354 config->Attributes2 = c->io.Attributes2;
355 config->IOAddrLines = c->io.IOAddrLines;
358 } /* pccard_get_configuration_info */
361 /*======================================================================
363 These manage a ring buffer of events pending for one user process
365 ======================================================================*/
368 static int queue_empty(user_info_t *user)
370 return (user->event_head == user->event_tail);
373 static event_t get_queued_event(user_info_t *user)
375 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
376 return user->event[user->event_tail];
379 static void queue_event(user_info_t *user, event_t event)
381 user->event_head = (user->event_head+1) % MAX_EVENTS;
382 if (user->event_head == user->event_tail)
383 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
384 user->event[user->event_head] = event;
387 void handle_event(struct pcmcia_socket *s, event_t event)
390 for (user = s->user; user; user = user->next)
391 queue_event(user, event);
392 wake_up_interruptible(&s->queue);
396 /*======================================================================
398 bind_request() and bind_device() are merged by now. Register_client()
399 is called right at the end of bind_request(), during the driver's
400 ->attach() call. Individual descriptions:
402 bind_request() connects a socket to a particular client driver.
403 It looks up the specified device ID in the list of registered
404 drivers, binds it to the socket, and tries to create an instance
405 of the device. unbind_request() deletes a driver instance.
407 Bind_device() associates a device driver with a particular socket.
408 It is normally called by Driver Services after it has identified
409 a newly inserted card. An instance of that driver will then be
410 eligible to register as a client of this socket.
412 Register_client() uses the dev_info_t handle to match the
413 caller with a socket. The driver must have already been bound
414 to a socket with bind_device() -- in fact, bind_device()
415 allocates the client structure that will be used.
417 ======================================================================*/
419 static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
421 struct pcmcia_driver *p_drv;
422 struct pcmcia_device *p_dev;
426 s = pcmcia_get_socket(s);
430 ds_dbg(2, "bind_request(%d, '%s')\n", s->sock,
431 (char *)bind_info->dev_info);
433 p_drv = get_pcmcia_driver(&bind_info->dev_info);
439 if (!try_module_get(p_drv->owner)) {
444 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
445 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
446 if (p_dev->func == bind_info->function) {
447 if ((p_dev->dev.driver == &p_drv->drv)) {
448 if (p_dev->cardmgr) {
449 /* if there's already a device
450 * registered, and it was registered
451 * by userspace before, we need to
452 * return the "instance". */
453 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
454 bind_info->instance = p_dev;
458 /* the correct driver managed to bind
459 * itself magically to the correct
461 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
462 p_dev->cardmgr = p_drv;
466 } else if (!p_dev->dev.driver) {
467 /* there's already a device available where
468 * no device has been bound to yet. So we don't
469 * need to register a device! */
470 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
475 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
477 p_dev = pcmcia_device_add(s, bind_info->function);
484 p_dev->cardmgr = p_drv;
486 /* if a driver is already running, we can abort */
487 if (p_dev->dev.driver)
491 * Prevent this racing with a card insertion.
493 mutex_lock(&s->skt_mutex);
494 ret = bus_rescan_devices(&pcmcia_bus_type);
495 mutex_unlock(&s->skt_mutex);
499 /* check whether the driver indeed matched. I don't care if this
500 * is racy or not, because it can only happen on cardmgr access
503 if (!(p_dev->dev.driver == &p_drv->drv))
504 p_dev->cardmgr = NULL;
507 module_put(p_drv->owner);
509 put_driver(&p_drv->drv);
511 pcmcia_put_socket(s);
516 #ifdef CONFIG_CARDBUS
518 static struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
520 if (!s || !(s->state & SOCKET_CARDBUS))
523 return s->cb_dev->subordinate;
527 static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int first)
530 struct pcmcia_device *p_dev;
531 struct pcmcia_driver *p_drv;
535 #ifdef CONFIG_CARDBUS
537 * Some unbelievably ugly code to associate the PCI cardbus
538 * device and its driver with the PCMCIA "bind" information.
543 bus = pcmcia_lookup_bus(s);
545 struct list_head *list;
546 struct pci_dev *dev = NULL;
548 list = bus->devices.next;
549 while (list != &bus->devices) {
550 struct pci_dev *pdev = pci_dev_b(list);
558 /* Try to handle "next" here some way? */
560 if (dev && dev->driver) {
561 strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN);
562 bind_info->major = 0;
563 bind_info->minor = 0;
564 bind_info->next = NULL;
571 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
572 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
573 if (p_dev->func == bind_info->function) {
574 p_dev = pcmcia_get_dev(p_dev);
580 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
584 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
586 p_drv = to_pcmcia_drv(p_dev->dev.driver);
587 if (p_drv && !p_dev->_locked) {
593 node = p_dev->dev_node;
595 for (node = p_dev->dev_node; node; node = node->next)
596 if (node == bind_info->next)
603 strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN);
604 bind_info->major = node->major;
605 bind_info->minor = node->minor;
606 bind_info->next = node->next;
609 pcmcia_put_dev(p_dev);
611 } /* get_device_info */
614 static int ds_open(struct inode *inode, struct file *file)
616 socket_t i = iminor(inode);
617 struct pcmcia_socket *s;
619 static int warning_printed = 0;
622 ds_dbg(0, "ds_open(socket %d)\n", i);
625 s = pcmcia_get_socket_by_nr(i);
630 s = pcmcia_get_socket(s);
636 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
637 if (s->pcmcia_state.busy) {
638 pcmcia_put_socket(s);
643 s->pcmcia_state.busy = 1;
646 user = kmalloc(sizeof(user_info_t), GFP_KERNEL);
648 pcmcia_put_socket(s);
652 user->event_tail = user->event_head = 0;
653 user->next = s->user;
654 user->user_magic = USER_MAGIC;
657 file->private_data = user;
659 if (!warning_printed) {
660 printk(KERN_INFO "pcmcia: Detected deprecated PCMCIA ioctl "
661 "usage from process: %s.\n", current->comm);
662 printk(KERN_INFO "pcmcia: This interface will soon be removed from "
663 "the kernel; please expect breakage unless you upgrade "
665 printk(KERN_INFO "pcmcia: see http://www.kernel.org/pub/linux/"
666 "utils/kernel/pcmcia/pcmcia.html for details.\n");
670 if (s->pcmcia_state.present)
671 queue_event(user, CS_EVENT_CARD_INSERTION);
677 /*====================================================================*/
679 static int ds_release(struct inode *inode, struct file *file)
681 struct pcmcia_socket *s;
682 user_info_t *user, **link;
684 ds_dbg(0, "ds_release(socket %d)\n", iminor(inode));
686 user = file->private_data;
687 if (CHECK_USER(user))
692 /* Unlink user data structure */
693 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
694 s->pcmcia_state.busy = 0;
696 file->private_data = NULL;
697 for (link = &s->user; *link; link = &(*link)->next)
698 if (*link == user) break;
702 user->user_magic = 0;
704 pcmcia_put_socket(s);
709 /*====================================================================*/
711 static ssize_t ds_read(struct file *file, char __user *buf,
712 size_t count, loff_t *ppos)
714 struct pcmcia_socket *s;
718 ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_path.dentry->d_inode));
723 user = file->private_data;
724 if (CHECK_USER(user))
728 if (s->pcmcia_state.dead)
731 ret = wait_event_interruptible(s->queue, !queue_empty(user));
733 ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4;
738 /*====================================================================*/
740 static ssize_t ds_write(struct file *file, const char __user *buf,
741 size_t count, loff_t *ppos)
743 ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_path.dentry->d_inode));
747 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
753 /*====================================================================*/
755 /* No kernel lock - fine */
756 static u_int ds_poll(struct file *file, poll_table *wait)
758 struct pcmcia_socket *s;
761 ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_path.dentry->d_inode));
763 user = file->private_data;
764 if (CHECK_USER(user))
768 * We don't check for a dead socket here since that
769 * will send cardmgr into an endless spin.
771 poll_wait(file, &s->queue, wait);
772 if (!queue_empty(user))
773 return POLLIN | POLLRDNORM;
777 /*====================================================================*/
779 static int ds_ioctl(struct inode * inode, struct file * file,
780 u_int cmd, u_long arg)
782 struct pcmcia_socket *s;
783 void __user *uarg = (char __user *)arg;
789 ds_dbg(2, "ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg);
791 user = file->private_data;
792 if (CHECK_USER(user))
796 if (s->pcmcia_state.dead)
799 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
800 if (size > sizeof(ds_ioctl_arg_t)) return -EINVAL;
802 /* Permission check */
803 if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN))
807 if (!access_ok(VERIFY_READ, uarg, size)) {
808 ds_dbg(3, "ds_ioctl(): verify_read = %d\n", -EFAULT);
813 if (!access_ok(VERIFY_WRITE, uarg, size)) {
814 ds_dbg(3, "ds_ioctl(): verify_write = %d\n", -EFAULT);
818 buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
825 if (__copy_from_user((char *)buf, uarg, size)) {
832 case DS_ADJUST_RESOURCE_INFO:
833 ret = pcmcia_adjust_resource_info(&buf->adjust);
835 case DS_GET_CONFIGURATION_INFO:
836 if (buf->config.Function &&
837 (buf->config.Function >= s->functions))
840 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function);
841 ret = pccard_get_configuration_info(s, p_dev, &buf->config);
842 pcmcia_put_dev(p_dev);
845 case DS_GET_FIRST_TUPLE:
846 mutex_lock(&s->skt_mutex);
847 pcmcia_validate_mem(s);
848 mutex_unlock(&s->skt_mutex);
849 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple);
851 case DS_GET_NEXT_TUPLE:
852 ret = pccard_get_next_tuple(s, BIND_FN_ALL, &buf->tuple);
854 case DS_GET_TUPLE_DATA:
855 buf->tuple.TupleData = buf->tuple_parse.data;
856 buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data);
857 ret = pccard_get_tuple_data(s, &buf->tuple);
860 buf->tuple.TupleData = buf->tuple_parse.data;
861 ret = pcmcia_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
864 ret = pcmcia_reset_card(s);
867 if (buf->status.Function &&
868 (buf->status.Function >= s->functions))
871 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function);
872 ret = pccard_get_status(s, p_dev, &buf->status);
873 pcmcia_put_dev(p_dev);
876 case DS_VALIDATE_CIS:
877 mutex_lock(&s->skt_mutex);
878 pcmcia_validate_mem(s);
879 mutex_unlock(&s->skt_mutex);
880 ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo.Chains);
882 case DS_SUSPEND_CARD:
883 ret = pcmcia_suspend_card(s);
886 ret = pcmcia_resume_card(s);
889 err = pcmcia_eject_card(s);
892 err = pcmcia_insert_card(s);
894 case DS_ACCESS_CONFIGURATION_REGISTER:
895 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) {
902 if (!(buf->conf_reg.Function &&
903 (buf->conf_reg.Function >= s->functions))) {
904 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->conf_reg.Function);
906 ret = pcmcia_access_configuration_register(p_dev, &buf->conf_reg);
907 pcmcia_put_dev(p_dev);
911 case DS_GET_FIRST_REGION:
912 case DS_GET_NEXT_REGION:
914 if (!capable(CAP_SYS_ADMIN)) {
918 printk_once(KERN_WARNING
919 "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n");
920 printk_once(KERN_WARNING "MTD handling any more.\n");
925 case DS_GET_FIRST_WINDOW:
926 ret = pcmcia_get_window(s, &buf->win_info.handle, 0,
927 &buf->win_info.window);
929 case DS_GET_NEXT_WINDOW:
930 ret = pcmcia_get_window(s, &buf->win_info.handle,
931 buf->win_info.handle->index + 1, &buf->win_info.window);
933 case DS_GET_MEM_PAGE:
934 ret = pcmcia_get_mem_page(buf->win_info.handle,
938 ret = pcmcia_replace_cis(s, buf->cisdump.Data, buf->cisdump.Length);
940 case DS_BIND_REQUEST:
941 if (!capable(CAP_SYS_ADMIN)) {
945 err = bind_request(s, &buf->bind_info);
947 case DS_GET_DEVICE_INFO:
948 err = get_device_info(s, &buf->bind_info, 1);
950 case DS_GET_NEXT_DEVICE:
951 err = get_device_info(s, &buf->bind_info, 0);
953 case DS_UNBIND_REQUEST:
960 if ((err == 0) && (ret != 0)) {
961 ds_dbg(2, "ds_ioctl: ret = %d\n", ret);
970 err = -ENOSPC; break;
972 err = -ENODATA; break;
979 if (__copy_to_user(uarg, (char *)buf, size))
988 /*====================================================================*/
990 static const struct file_operations ds_fops = {
991 .owner = THIS_MODULE,
993 .release = ds_release,
1000 void __init pcmcia_setup_ioctl(void) {
1003 /* Set up character device for user mode clients */
1004 i = register_chrdev(0, "pcmcia", &ds_fops);
1006 printk(KERN_NOTICE "unable to find a free device # for "
1007 "Driver Services (error=%d)\n", i);
1011 #ifdef CONFIG_PROC_FS
1012 proc_pccard = proc_mkdir("bus/pccard", NULL);
1014 create_proc_read_entry("drivers",0,proc_pccard,proc_read_drivers,NULL);
1019 void __exit pcmcia_cleanup_ioctl(void) {
1020 #ifdef CONFIG_PROC_FS
1022 remove_proc_entry("drivers", proc_pccard);
1023 remove_proc_entry("bus/pccard", NULL);
1026 if (major_dev != -1)
1027 unregister_chrdev(major_dev, "pcmcia");