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/seq_file.h>
31 #include <linux/smp_lock.h>
32 #include <linux/workqueue.h>
34 #include <pcmcia/cs_types.h>
35 #include <pcmcia/cs.h>
36 #include <pcmcia/cistpl.h>
37 #include <pcmcia/cisreg.h>
38 #include <pcmcia/ds.h>
39 #include <pcmcia/ss.h>
41 #include "cs_internal.h"
43 static int major_dev = -1;
46 /* Device user information */
48 #define USER_MAGIC 0x7ea4
49 #define CHECK_USER(u) \
50 (((u) == NULL) || ((u)->user_magic != USER_MAGIC))
52 typedef struct user_info_t {
54 int event_head, event_tail;
55 event_t event[MAX_EVENTS];
56 struct user_info_t *next;
57 struct pcmcia_socket *socket;
61 static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s,
62 unsigned int function)
64 struct pcmcia_device *p_dev = NULL;
67 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
68 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
69 if (p_dev->func == function) {
70 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
71 return pcmcia_get_dev(p_dev);
74 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
78 /* backwards-compatible accessing of driver --- by name! */
80 static struct pcmcia_driver *get_pcmcia_driver(dev_info_t *dev_info)
82 struct device_driver *drv;
83 struct pcmcia_driver *p_drv;
85 drv = driver_find((char *) dev_info, &pcmcia_bus_type);
89 p_drv = container_of(drv, struct pcmcia_driver, drv);
96 static struct proc_dir_entry *proc_pccard = NULL;
98 static int proc_read_drivers_callback(struct device_driver *driver, void *_m)
100 struct seq_file *m = _m;
101 struct pcmcia_driver *p_drv = container_of(driver,
102 struct pcmcia_driver, drv);
104 seq_printf(m, "%-24.24s 1 %d\n", p_drv->drv.name,
105 #ifdef CONFIG_MODULE_UNLOAD
106 (p_drv->owner) ? module_refcount(p_drv->owner) : 1
114 static int pccard_drivers_proc_show(struct seq_file *m, void *v)
116 return bus_for_each_drv(&pcmcia_bus_type, NULL,
117 m, proc_read_drivers_callback);
120 static int pccard_drivers_proc_open(struct inode *inode, struct file *file)
122 return single_open(file, pccard_drivers_proc_show, NULL);
125 static const struct file_operations pccard_drivers_proc_fops = {
126 .owner = THIS_MODULE,
127 .open = pccard_drivers_proc_open,
130 .release = single_release,
135 #ifdef CONFIG_PCMCIA_PROBE
137 static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
142 irq = adj->resource.irq.IRQ;
143 if ((irq < 0) || (irq > 15))
146 if (adj->Action != REMOVE_MANAGED_RESOURCE)
151 if (!(s->irq_mask & mask))
154 s->irq_mask &= ~mask;
161 static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
167 static int pcmcia_adjust_resource_info(adjust_t *adj)
169 struct pcmcia_socket *s;
173 down_read(&pcmcia_socket_list_rwsem);
174 list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
176 if (adj->Resource == RES_IRQ)
177 ret = adjust_irq(s, adj);
179 else if (s->resource_ops->add_io) {
180 unsigned long begin, end;
182 /* you can't use the old interface if the new
183 * one was used before */
184 spin_lock_irqsave(&s->lock, flags);
185 if ((s->resource_setup_new) &&
186 !(s->resource_setup_old)) {
187 spin_unlock_irqrestore(&s->lock, flags);
189 } else if (!(s->resource_setup_old))
190 s->resource_setup_old = 1;
191 spin_unlock_irqrestore(&s->lock, flags);
193 switch (adj->Resource) {
194 case RES_MEMORY_RANGE:
195 begin = adj->resource.memory.Base;
196 end = adj->resource.memory.Base + adj->resource.memory.Size - 1;
197 if (s->resource_ops->add_mem)
198 ret =s->resource_ops->add_mem(s, adj->Action, begin, end);
200 begin = adj->resource.io.BasePort;
201 end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1;
202 if (s->resource_ops->add_io)
203 ret = s->resource_ops->add_io(s, adj->Action, begin, end);
206 /* as there's no way we know this is the
207 * last call to adjust_resource_info, we
208 * always need to assume this is the latest
210 spin_lock_irqsave(&s->lock, flags);
211 s->resource_setup_done = 1;
212 spin_unlock_irqrestore(&s->lock, flags);
216 up_read(&pcmcia_socket_list_rwsem);
221 /** pccard_get_status
223 * Get the current socket state bits. We don't support the latched
224 * SocketState yet: I haven't seen any point for it.
227 static int pccard_get_status(struct pcmcia_socket *s,
228 struct pcmcia_device *p_dev,
234 s->ops->get_status(s, &val);
235 status->CardState = status->SocketState = 0;
236 status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0;
237 status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0;
238 status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0;
239 status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0;
240 if (s->state & SOCKET_SUSPEND)
241 status->CardState |= CS_EVENT_PM_SUSPEND;
242 if (!(s->state & SOCKET_PRESENT))
245 c = (p_dev) ? p_dev->function_config : NULL;
247 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
248 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
250 if (c->CardValues & PRESENT_PIN_REPLACE) {
251 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, ®);
253 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
255 (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0;
257 (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0;
259 (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0;
261 /* No PRR? Then assume we're always ready */
262 status->CardState |= CS_EVENT_READY_CHANGE;
264 if (c->CardValues & PRESENT_EXT_STATUS) {
265 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, ®);
267 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
272 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
274 (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0;
276 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
278 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
280 } /* pccard_get_status */
282 static int pccard_get_configuration_info(struct pcmcia_socket *s,
283 struct pcmcia_device *p_dev,
284 config_info_t *config)
288 if (!(s->state & SOCKET_PRESENT))
292 #ifdef CONFIG_CARDBUS
293 if (s->state & SOCKET_CARDBUS) {
294 memset(config, 0, sizeof(config_info_t));
295 config->Vcc = s->socket.Vcc;
296 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
297 config->Option = s->cb_dev->subordinate->number;
298 if (s->state & SOCKET_CARDBUS_CONFIG) {
299 config->Attributes = CONF_VALID_CLIENT;
300 config->IntType = INT_CARDBUS;
301 config->AssignedIRQ = s->irq.AssignedIRQ;
302 if (config->AssignedIRQ)
303 config->Attributes |= CONF_ENABLE_IRQ;
305 config->BasePort1 = s->io[0].res->start;
306 config->NumPorts1 = s->io[0].res->end -
307 config->BasePort1 + 1;
315 c = p_dev->function_config;
316 config->Function = p_dev->func;
319 config->Function = 0;
322 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
323 config->Attributes = 0;
324 config->Vcc = s->socket.Vcc;
325 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
329 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
330 config->Vcc = s->socket.Vcc;
331 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
332 config->IntType = c->IntType;
333 config->ConfigBase = c->ConfigBase;
334 config->Status = c->Status;
335 config->Pin = c->Pin;
336 config->Copy = c->Copy;
337 config->Option = c->Option;
338 config->ExtStatus = c->ExtStatus;
339 config->Present = config->CardValues = c->CardValues;
340 config->IRQAttributes = c->irq.Attributes;
341 config->AssignedIRQ = s->irq.AssignedIRQ;
342 config->BasePort1 = c->io.BasePort1;
343 config->NumPorts1 = c->io.NumPorts1;
344 config->Attributes1 = c->io.Attributes1;
345 config->BasePort2 = c->io.BasePort2;
346 config->NumPorts2 = c->io.NumPorts2;
347 config->Attributes2 = c->io.Attributes2;
348 config->IOAddrLines = c->io.IOAddrLines;
351 } /* pccard_get_configuration_info */
354 /*======================================================================
356 These manage a ring buffer of events pending for one user process
358 ======================================================================*/
361 static int queue_empty(user_info_t *user)
363 return (user->event_head == user->event_tail);
366 static event_t get_queued_event(user_info_t *user)
368 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
369 return user->event[user->event_tail];
372 static void queue_event(user_info_t *user, event_t event)
374 user->event_head = (user->event_head+1) % MAX_EVENTS;
375 if (user->event_head == user->event_tail)
376 user->event_tail = (user->event_tail+1) % MAX_EVENTS;
377 user->event[user->event_head] = event;
380 void handle_event(struct pcmcia_socket *s, event_t event)
383 for (user = s->user; user; user = user->next)
384 queue_event(user, event);
385 wake_up_interruptible(&s->queue);
389 /*======================================================================
391 bind_request() and bind_device() are merged by now. Register_client()
392 is called right at the end of bind_request(), during the driver's
393 ->attach() call. Individual descriptions:
395 bind_request() connects a socket to a particular client driver.
396 It looks up the specified device ID in the list of registered
397 drivers, binds it to the socket, and tries to create an instance
398 of the device. unbind_request() deletes a driver instance.
400 Bind_device() associates a device driver with a particular socket.
401 It is normally called by Driver Services after it has identified
402 a newly inserted card. An instance of that driver will then be
403 eligible to register as a client of this socket.
405 Register_client() uses the dev_info_t handle to match the
406 caller with a socket. The driver must have already been bound
407 to a socket with bind_device() -- in fact, bind_device()
408 allocates the client structure that will be used.
410 ======================================================================*/
412 static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
414 struct pcmcia_driver *p_drv;
415 struct pcmcia_device *p_dev;
419 s = pcmcia_get_socket(s);
423 pr_debug("bind_request(%d, '%s')\n", s->sock,
424 (char *)bind_info->dev_info);
426 p_drv = get_pcmcia_driver(&bind_info->dev_info);
432 if (!try_module_get(p_drv->owner)) {
437 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
438 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
439 if (p_dev->func == bind_info->function) {
440 if ((p_dev->dev.driver == &p_drv->drv)) {
441 if (p_dev->cardmgr) {
442 /* if there's already a device
443 * registered, and it was registered
444 * by userspace before, we need to
445 * return the "instance". */
446 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
447 bind_info->instance = p_dev;
451 /* the correct driver managed to bind
452 * itself magically to the correct
454 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
455 p_dev->cardmgr = p_drv;
459 } else if (!p_dev->dev.driver) {
460 /* there's already a device available where
461 * no device has been bound to yet. So we don't
462 * need to register a device! */
463 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
468 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
470 p_dev = pcmcia_device_add(s, bind_info->function);
477 p_dev->cardmgr = p_drv;
479 /* if a driver is already running, we can abort */
480 if (p_dev->dev.driver)
484 * Prevent this racing with a card insertion.
486 mutex_lock(&s->skt_mutex);
487 ret = bus_rescan_devices(&pcmcia_bus_type);
488 mutex_unlock(&s->skt_mutex);
492 /* check whether the driver indeed matched. I don't care if this
493 * is racy or not, because it can only happen on cardmgr access
496 if (!(p_dev->dev.driver == &p_drv->drv))
497 p_dev->cardmgr = NULL;
500 module_put(p_drv->owner);
502 put_driver(&p_drv->drv);
504 pcmcia_put_socket(s);
509 #ifdef CONFIG_CARDBUS
511 static struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
513 if (!s || !(s->state & SOCKET_CARDBUS))
516 return s->cb_dev->subordinate;
520 static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int first)
523 struct pcmcia_device *p_dev;
524 struct pcmcia_driver *p_drv;
528 #ifdef CONFIG_CARDBUS
530 * Some unbelievably ugly code to associate the PCI cardbus
531 * device and its driver with the PCMCIA "bind" information.
536 bus = pcmcia_lookup_bus(s);
538 struct list_head *list;
539 struct pci_dev *dev = NULL;
541 list = bus->devices.next;
542 while (list != &bus->devices) {
543 struct pci_dev *pdev = pci_dev_b(list);
551 /* Try to handle "next" here some way? */
553 if (dev && dev->driver) {
554 strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN);
555 bind_info->major = 0;
556 bind_info->minor = 0;
557 bind_info->next = NULL;
564 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
565 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
566 if (p_dev->func == bind_info->function) {
567 p_dev = pcmcia_get_dev(p_dev);
573 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
577 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
579 p_drv = to_pcmcia_drv(p_dev->dev.driver);
580 if (p_drv && !p_dev->_locked) {
586 node = p_dev->dev_node;
588 for (node = p_dev->dev_node; node; node = node->next)
589 if (node == bind_info->next)
596 strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN);
597 bind_info->major = node->major;
598 bind_info->minor = node->minor;
599 bind_info->next = node->next;
602 pcmcia_put_dev(p_dev);
604 } /* get_device_info */
607 static int ds_open(struct inode *inode, struct file *file)
609 socket_t i = iminor(inode);
610 struct pcmcia_socket *s;
612 static int warning_printed = 0;
615 pr_debug("ds_open(socket %d)\n", i);
618 s = pcmcia_get_socket_by_nr(i);
623 s = pcmcia_get_socket(s);
629 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
630 if (s->pcmcia_state.busy) {
631 pcmcia_put_socket(s);
636 s->pcmcia_state.busy = 1;
639 user = kmalloc(sizeof(user_info_t), GFP_KERNEL);
641 pcmcia_put_socket(s);
645 user->event_tail = user->event_head = 0;
646 user->next = s->user;
647 user->user_magic = USER_MAGIC;
650 file->private_data = user;
652 if (!warning_printed) {
653 printk(KERN_INFO "pcmcia: Detected deprecated PCMCIA ioctl "
654 "usage from process: %s.\n", current->comm);
655 printk(KERN_INFO "pcmcia: This interface will soon be removed from "
656 "the kernel; please expect breakage unless you upgrade "
658 printk(KERN_INFO "pcmcia: see http://www.kernel.org/pub/linux/"
659 "utils/kernel/pcmcia/pcmcia.html for details.\n");
663 if (s->pcmcia_state.present)
664 queue_event(user, CS_EVENT_CARD_INSERTION);
670 /*====================================================================*/
672 static int ds_release(struct inode *inode, struct file *file)
674 struct pcmcia_socket *s;
675 user_info_t *user, **link;
677 pr_debug("ds_release(socket %d)\n", iminor(inode));
679 user = file->private_data;
680 if (CHECK_USER(user))
685 /* Unlink user data structure */
686 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
687 s->pcmcia_state.busy = 0;
689 file->private_data = NULL;
690 for (link = &s->user; *link; link = &(*link)->next)
691 if (*link == user) break;
695 user->user_magic = 0;
697 pcmcia_put_socket(s);
702 /*====================================================================*/
704 static ssize_t ds_read(struct file *file, char __user *buf,
705 size_t count, loff_t *ppos)
707 struct pcmcia_socket *s;
711 pr_debug("ds_read(socket %d)\n", iminor(file->f_path.dentry->d_inode));
716 user = file->private_data;
717 if (CHECK_USER(user))
721 if (s->pcmcia_state.dead)
724 ret = wait_event_interruptible(s->queue, !queue_empty(user));
726 ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4;
731 /*====================================================================*/
733 static ssize_t ds_write(struct file *file, const char __user *buf,
734 size_t count, loff_t *ppos)
736 pr_debug("ds_write(socket %d)\n", iminor(file->f_path.dentry->d_inode));
740 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
746 /*====================================================================*/
748 /* No kernel lock - fine */
749 static u_int ds_poll(struct file *file, poll_table *wait)
751 struct pcmcia_socket *s;
754 pr_debug("ds_poll(socket %d)\n", iminor(file->f_path.dentry->d_inode));
756 user = file->private_data;
757 if (CHECK_USER(user))
761 * We don't check for a dead socket here since that
762 * will send cardmgr into an endless spin.
764 poll_wait(file, &s->queue, wait);
765 if (!queue_empty(user))
766 return POLLIN | POLLRDNORM;
770 /*====================================================================*/
772 static int ds_ioctl(struct inode * inode, struct file * file,
773 u_int cmd, u_long arg)
775 struct pcmcia_socket *s;
776 void __user *uarg = (char __user *)arg;
782 pr_debug("ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg);
784 user = file->private_data;
785 if (CHECK_USER(user))
789 if (s->pcmcia_state.dead)
792 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
793 if (size > sizeof(ds_ioctl_arg_t)) return -EINVAL;
795 /* Permission check */
796 if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN))
800 if (!access_ok(VERIFY_READ, uarg, size)) {
801 pr_debug("ds_ioctl(): verify_read = %d\n", -EFAULT);
806 if (!access_ok(VERIFY_WRITE, uarg, size)) {
807 pr_debug("ds_ioctl(): verify_write = %d\n", -EFAULT);
811 buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
818 if (__copy_from_user((char *)buf, uarg, size)) {
825 case DS_ADJUST_RESOURCE_INFO:
826 ret = pcmcia_adjust_resource_info(&buf->adjust);
828 case DS_GET_CONFIGURATION_INFO:
829 if (buf->config.Function &&
830 (buf->config.Function >= s->functions))
833 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function);
834 ret = pccard_get_configuration_info(s, p_dev, &buf->config);
835 pcmcia_put_dev(p_dev);
838 case DS_GET_FIRST_TUPLE:
839 mutex_lock(&s->skt_mutex);
840 pcmcia_validate_mem(s);
841 mutex_unlock(&s->skt_mutex);
842 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple);
844 case DS_GET_NEXT_TUPLE:
845 ret = pccard_get_next_tuple(s, BIND_FN_ALL, &buf->tuple);
847 case DS_GET_TUPLE_DATA:
848 buf->tuple.TupleData = buf->tuple_parse.data;
849 buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data);
850 ret = pccard_get_tuple_data(s, &buf->tuple);
853 buf->tuple.TupleData = buf->tuple_parse.data;
854 ret = pcmcia_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
857 ret = pcmcia_reset_card(s);
860 if (buf->status.Function &&
861 (buf->status.Function >= s->functions))
864 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function);
865 ret = pccard_get_status(s, p_dev, &buf->status);
866 pcmcia_put_dev(p_dev);
869 case DS_VALIDATE_CIS:
870 mutex_lock(&s->skt_mutex);
871 pcmcia_validate_mem(s);
872 mutex_unlock(&s->skt_mutex);
873 ret = pccard_validate_cis(s, &buf->cisinfo.Chains);
875 case DS_SUSPEND_CARD:
876 ret = pcmcia_suspend_card(s);
879 ret = pcmcia_resume_card(s);
882 err = pcmcia_eject_card(s);
885 err = pcmcia_insert_card(s);
887 case DS_ACCESS_CONFIGURATION_REGISTER:
888 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) {
895 if (!(buf->conf_reg.Function &&
896 (buf->conf_reg.Function >= s->functions))) {
897 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->conf_reg.Function);
899 ret = pcmcia_access_configuration_register(p_dev, &buf->conf_reg);
900 pcmcia_put_dev(p_dev);
904 case DS_GET_FIRST_REGION:
905 case DS_GET_NEXT_REGION:
907 if (!capable(CAP_SYS_ADMIN)) {
911 printk_once(KERN_WARNING
912 "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n");
913 printk_once(KERN_WARNING "MTD handling any more.\n");
918 case DS_GET_FIRST_WINDOW:
919 ret = pcmcia_get_window(s, &buf->win_info.handle, 1,
920 &buf->win_info.window);
922 case DS_GET_NEXT_WINDOW:
923 ret = pcmcia_get_window(s, &buf->win_info.handle,
924 buf->win_info.handle + 1, &buf->win_info.window);
926 case DS_GET_MEM_PAGE:
927 ret = pcmcia_get_mem_page(s, buf->win_info.handle,
931 ret = pcmcia_replace_cis(s, buf->cisdump.Data, buf->cisdump.Length);
933 case DS_BIND_REQUEST:
934 if (!capable(CAP_SYS_ADMIN)) {
938 err = bind_request(s, &buf->bind_info);
940 case DS_GET_DEVICE_INFO:
941 err = get_device_info(s, &buf->bind_info, 1);
943 case DS_GET_NEXT_DEVICE:
944 err = get_device_info(s, &buf->bind_info, 0);
946 case DS_UNBIND_REQUEST:
953 if ((err == 0) && (ret != 0)) {
954 pr_debug("ds_ioctl: ret = %d\n", ret);
963 err = -ENOSPC; break;
965 err = -ENODATA; break;
972 if (__copy_to_user(uarg, (char *)buf, size))
981 /*====================================================================*/
983 static const struct file_operations ds_fops = {
984 .owner = THIS_MODULE,
986 .release = ds_release,
993 void __init pcmcia_setup_ioctl(void) {
996 /* Set up character device for user mode clients */
997 i = register_chrdev(0, "pcmcia", &ds_fops);
999 printk(KERN_NOTICE "unable to find a free device # for "
1000 "Driver Services (error=%d)\n", i);
1004 #ifdef CONFIG_PROC_FS
1005 proc_pccard = proc_mkdir("bus/pccard", NULL);
1007 proc_create("drivers", 0, proc_pccard, &pccard_drivers_proc_fops);
1012 void __exit pcmcia_cleanup_ioctl(void) {
1013 #ifdef CONFIG_PROC_FS
1015 remove_proc_entry("drivers", proc_pccard);
1016 remove_proc_entry("bus/pccard", NULL);
1019 if (major_dev != -1)
1020 unregister_chrdev(major_dev, "pcmcia");