From 5716d415f8c5a17d44f6e1d5a1e4998f7306a93b Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 11 Jul 2010 09:51:14 +0200 Subject: pcmcia: remove obsolete ioctl Signed-off-by: Dominik Brodowski --- drivers/pcmcia/Makefile | 1 - drivers/pcmcia/cs_internal.h | 40 +- drivers/pcmcia/ds.c | 26 +- drivers/pcmcia/pcmcia_ioctl.c | 1077 --------------------------------------- drivers/pcmcia/rsrc_iodyn.c | 2 - drivers/pcmcia/rsrc_mgr.c | 2 - drivers/pcmcia/rsrc_nonstatic.c | 2 - 7 files changed, 6 insertions(+), 1144 deletions(-) delete mode 100644 drivers/pcmcia/pcmcia_ioctl.c (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile index d006e8be..7a2b160 100644 --- a/drivers/pcmcia/Makefile +++ b/drivers/pcmcia/Makefile @@ -7,7 +7,6 @@ pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o obj-$(CONFIG_PCCARD) += pcmcia_core.o pcmcia-y += ds.o pcmcia_resource.o cistpl.o pcmcia_cis.o -pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o obj-$(CONFIG_PCMCIA) += pcmcia.o pcmcia_rsrc-y += rsrc_mgr.o diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 4126a75..a6cc63d 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -60,14 +60,6 @@ struct pccard_resource_ops { struct resource* (*find_mem) (unsigned long base, unsigned long num, unsigned long align, int low, struct pcmcia_socket *s); - int (*add_io) (struct pcmcia_socket *s, - unsigned int action, - unsigned long r_start, - unsigned long r_end); - int (*add_mem) (struct pcmcia_socket *s, - unsigned int action, - unsigned long r_start, - unsigned long r_end); int (*init) (struct pcmcia_socket *s); void (*exit) (struct pcmcia_socket *s); }; @@ -146,6 +138,8 @@ void pcmcia_put_socket(struct pcmcia_socket *skt); /* ds.c */ extern struct bus_type pcmcia_bus_type; +struct pcmcia_device; + /* pcmcia_resource.c */ extern int pcmcia_release_configuration(struct pcmcia_device *p_dev); extern int pcmcia_validate_mem(struct pcmcia_socket *s); @@ -188,34 +182,4 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); - -#ifdef CONFIG_PCMCIA_IOCTL -/* ds.c */ -extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); -extern void pcmcia_put_dev(struct pcmcia_device *p_dev); - -struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, - unsigned int function); - -/* pcmcia_ioctl.c */ -extern void __init pcmcia_setup_ioctl(void); -extern void __exit pcmcia_cleanup_ioctl(void); -extern void handle_event(struct pcmcia_socket *s, event_t event); -extern int handle_request(struct pcmcia_socket *s, event_t event); - -#else /* CONFIG_PCMCIA_IOCTL */ - -static inline void __init pcmcia_setup_ioctl(void) { return; } -static inline void __exit pcmcia_cleanup_ioctl(void) { return; } -static inline void handle_event(struct pcmcia_socket *s, event_t event) -{ - return; -} -static inline int handle_request(struct pcmcia_socket *s, event_t event) -{ - return 0; -} - -#endif /* CONFIG_PCMCIA_IOCTL */ - #endif /* _LINUX_CS_INTERNAL_H */ diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index eac9614..d2ec458 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -213,7 +213,7 @@ EXPORT_SYMBOL(pcmcia_unregister_driver); /* pcmcia_device handling */ -struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev) +static struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev) { struct device *tmp_dev; tmp_dev = get_device(&p_dev->dev); @@ -222,7 +222,7 @@ struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev) return to_pcmcia_dev(tmp_dev); } -void pcmcia_put_dev(struct pcmcia_device *p_dev) +static void pcmcia_put_dev(struct pcmcia_device *p_dev) { if (p_dev) put_device(&p_dev->dev); @@ -477,7 +477,8 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev) } -struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) +static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, + unsigned int function) { struct pcmcia_device *p_dev, *tmp_dev; int i; @@ -885,14 +886,6 @@ static int pcmcia_bus_match(struct device *dev, struct device_driver *drv) } mutex_unlock(&p_drv->dynids.lock); -#ifdef CONFIG_PCMCIA_IOCTL - /* matching by cardmgr */ - if (p_dev->cardmgr == p_drv) { - dev_dbg(dev, "cardmgr matched to %s\n", drv->name); - return 1; - } -#endif - while (did && did->match_flags) { dev_dbg(dev, "trying to match to %s\n", drv->name); if (pcmcia_devmatch(p_dev, did)) { @@ -1245,7 +1238,6 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) case CS_EVENT_CARD_REMOVAL: atomic_set(&skt->present, 0); pcmcia_card_remove(skt, NULL); - handle_event(skt, event); mutex_lock(&s->ops_mutex); destroy_cis_cache(s); pcmcia_cleanup_irq(s); @@ -1259,7 +1251,6 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) destroy_cis_cache(s); /* to be on the safe side... */ mutex_unlock(&s->ops_mutex); pcmcia_card_add(skt); - handle_event(skt, event); break; case CS_EVENT_EJECTION_REQUEST: @@ -1280,14 +1271,12 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) ds_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); } - handle_event(skt, event); break; case CS_EVENT_PM_SUSPEND: case CS_EVENT_RESET_PHYSICAL: case CS_EVENT_CARD_RESET: default: - handle_event(skt, event); break; } @@ -1350,9 +1339,6 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev, return ret; } -#ifdef CONFIG_PCMCIA_IOCTL - init_waitqueue_head(&socket->queue); -#endif INIT_LIST_HEAD(&socket->devices_list); memset(&socket->pcmcia_state, 0, sizeof(u8)); socket->device_count = 0; @@ -1429,8 +1415,6 @@ static int __init init_pcmcia_bus(void) return ret; } - pcmcia_setup_ioctl(); - return 0; } fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that @@ -1439,8 +1423,6 @@ fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that static void __exit exit_pcmcia_bus(void) { - pcmcia_cleanup_ioctl(); - class_interface_unregister(&pcmcia_bus_interface); bus_unregister(&pcmcia_bus_type); diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c deleted file mode 100644 index d007a2a..0000000 --- a/drivers/pcmcia/pcmcia_ioctl.c +++ /dev/null @@ -1,1077 +0,0 @@ -/* - * pcmcia_ioctl.c -- ioctl interface for cardmgr and cardctl - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * The initial developer of the original code is David A. Hinds - * . Portions created by David A. Hinds - * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - * - * (C) 1999 David A. Hinds - * (C) 2003 - 2004 Dominik Brodowski - */ - -/* - * This file will go away soon. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "cs_internal.h" - -static int major_dev = -1; - - -/* Device user information */ -#define MAX_EVENTS 32 -#define USER_MAGIC 0x7ea4 -#define CHECK_USER(u) \ - (((u) == NULL) || ((u)->user_magic != USER_MAGIC)) - -typedef struct user_info_t { - u_int user_magic; - int event_head, event_tail; - event_t event[MAX_EVENTS]; - struct user_info_t *next; - struct pcmcia_socket *socket; -} user_info_t; - - -static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s, - unsigned int function) -{ - struct pcmcia_device *p_dev = NULL; - - mutex_lock(&s->ops_mutex); - list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { - if (p_dev->func == function) { - mutex_unlock(&s->ops_mutex); - return pcmcia_get_dev(p_dev); - } - } - mutex_unlock(&s->ops_mutex); - return NULL; -} - -/* backwards-compatible accessing of driver --- by name! */ - -static struct pcmcia_driver *get_pcmcia_driver(dev_info_t *dev_info) -{ - struct device_driver *drv; - struct pcmcia_driver *p_drv; - - drv = driver_find((char *) dev_info, &pcmcia_bus_type); - if (!drv) - return NULL; - - p_drv = container_of(drv, struct pcmcia_driver, drv); - - return p_drv; -} - - -#ifdef CONFIG_PROC_FS -static struct proc_dir_entry *proc_pccard; - -static int proc_read_drivers_callback(struct device_driver *driver, void *_m) -{ - struct seq_file *m = _m; - struct pcmcia_driver *p_drv = container_of(driver, - struct pcmcia_driver, drv); - - seq_printf(m, "%-24.24s 1 %d\n", p_drv->drv.name, -#ifdef CONFIG_MODULE_UNLOAD - (p_drv->owner) ? module_refcount(p_drv->owner) : 1 -#else - 1 -#endif - ); - return 0; -} - -static int pccard_drivers_proc_show(struct seq_file *m, void *v) -{ - return bus_for_each_drv(&pcmcia_bus_type, NULL, - m, proc_read_drivers_callback); -} - -static int pccard_drivers_proc_open(struct inode *inode, struct file *file) -{ - return single_open(file, pccard_drivers_proc_show, NULL); -} - -static const struct file_operations pccard_drivers_proc_fops = { - .owner = THIS_MODULE, - .open = pccard_drivers_proc_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; -#endif - - -#ifdef CONFIG_PCMCIA_PROBE - -static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) -{ - int irq; - u32 mask; - - irq = adj->resource.irq.IRQ; - if ((irq < 0) || (irq > 15)) - return -EINVAL; - - if (adj->Action != REMOVE_MANAGED_RESOURCE) - return 0; - - mask = 1 << irq; - - if (!(s->irq_mask & mask)) - return 0; - - s->irq_mask &= ~mask; - - return 0; -} - -#else - -static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) -{ - return 0; -} - -#endif - -static int pcmcia_adjust_resource_info(adjust_t *adj) -{ - struct pcmcia_socket *s; - int ret = -ENOSYS; - - down_read(&pcmcia_socket_list_rwsem); - list_for_each_entry(s, &pcmcia_socket_list, socket_list) { - - if (adj->Resource == RES_IRQ) - ret = adjust_irq(s, adj); - - else if (s->resource_ops->add_io) { - unsigned long begin, end; - - /* you can't use the old interface if the new - * one was used before */ - mutex_lock(&s->ops_mutex); - if ((s->resource_setup_new) && - !(s->resource_setup_old)) { - mutex_unlock(&s->ops_mutex); - continue; - } else if (!(s->resource_setup_old)) - s->resource_setup_old = 1; - - switch (adj->Resource) { - case RES_MEMORY_RANGE: - begin = adj->resource.memory.Base; - end = adj->resource.memory.Base + adj->resource.memory.Size - 1; - if (s->resource_ops->add_mem) - ret = s->resource_ops->add_mem(s, adj->Action, begin, end); - case RES_IO_RANGE: - begin = adj->resource.io.BasePort; - end = adj->resource.io.BasePort + adj->resource.io.NumPorts - 1; - if (s->resource_ops->add_io) - ret = s->resource_ops->add_io(s, adj->Action, begin, end); - } - if (!ret) { - /* as there's no way we know this is the - * last call to adjust_resource_info, we - * always need to assume this is the latest - * one... */ - s->resource_setup_done = 1; - } - mutex_unlock(&s->ops_mutex); - } - } - up_read(&pcmcia_socket_list_rwsem); - - return ret; -} - - -/** pcmcia_get_window - */ -static int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *wh_out, - window_handle_t wh, win_req_t *req) -{ - pccard_mem_map *win; - window_handle_t w; - - wh--; - if (!s || !(s->state & SOCKET_PRESENT)) - return -ENODEV; - if (wh >= MAX_WIN) - return -EINVAL; - for (w = wh; w < MAX_WIN; w++) - if (s->state & SOCKET_WIN_REQ(w)) - break; - if (w == MAX_WIN) - return -EINVAL; - win = &s->win[w]; - req->Base = win->res->start; - req->Size = win->res->end - win->res->start + 1; - req->AccessSpeed = win->speed; - req->Attributes = 0; - if (win->flags & MAP_ATTRIB) - req->Attributes |= WIN_MEMORY_TYPE_AM; - if (win->flags & MAP_ACTIVE) - req->Attributes |= WIN_ENABLE; - if (win->flags & MAP_16BIT) - req->Attributes |= WIN_DATA_WIDTH_16; - if (win->flags & MAP_USE_WAIT) - req->Attributes |= WIN_USE_WAIT; - - *wh_out = w + 1; - return 0; -} /* pcmcia_get_window */ - - -/** pcmcia_get_mem_page - * - * Change the card address of an already open memory window. - */ -static int pcmcia_get_mem_page(struct pcmcia_socket *skt, window_handle_t wh, - memreq_t *req) -{ - wh--; - if (wh >= MAX_WIN) - return -EINVAL; - - req->Page = 0; - req->CardOffset = skt->win[wh].card_start; - return 0; -} /* pcmcia_get_mem_page */ - - -/** pccard_get_status - * - * Get the current socket state bits. We don't support the latched - * SocketState yet: I haven't seen any point for it. - */ - -static int pccard_get_status(struct pcmcia_socket *s, - struct pcmcia_device *p_dev, - cs_status_t *status) -{ - config_t *c; - int val; - - s->ops->get_status(s, &val); - status->CardState = status->SocketState = 0; - status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0; - status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0; - status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0; - status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0; - if (s->state & SOCKET_SUSPEND) - status->CardState |= CS_EVENT_PM_SUSPEND; - if (!(s->state & SOCKET_PRESENT)) - return -ENODEV; - - c = (p_dev) ? p_dev->function_config : NULL; - - if ((c != NULL) && (c->state & CONFIG_LOCKED) && - (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) { - u_char reg; - if (c->CardValues & PRESENT_PIN_REPLACE) { - mutex_lock(&s->ops_mutex); - pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, ®); - mutex_unlock(&s->ops_mutex); - status->CardState |= - (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0; - status->CardState |= - (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0; - status->CardState |= - (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0; - status->CardState |= - (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0; - } else { - /* No PRR? Then assume we're always ready */ - status->CardState |= CS_EVENT_READY_CHANGE; - } - if (c->CardValues & PRESENT_EXT_STATUS) { - mutex_lock(&s->ops_mutex); - pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, ®); - mutex_unlock(&s->ops_mutex); - status->CardState |= - (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0; - } - return 0; - } - status->CardState |= - (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0; - status->CardState |= - (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0; - status->CardState |= - (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0; - status->CardState |= - (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0; - return 0; -} /* pccard_get_status */ - -static int pccard_get_configuration_info(struct pcmcia_socket *s, - struct pcmcia_device *p_dev, - config_info_t *config) -{ - config_t *c; - - if (!(s->state & SOCKET_PRESENT)) - return -ENODEV; - - -#ifdef CONFIG_CARDBUS - if (s->state & SOCKET_CARDBUS) { - memset(config, 0, sizeof(config_info_t)); - config->Vcc = s->socket.Vcc; - config->Vpp1 = config->Vpp2 = s->socket.Vpp; - config->Option = s->cb_dev->subordinate->number; - if (s->state & SOCKET_CARDBUS_CONFIG) { - config->Attributes = CONF_VALID_CLIENT; - config->IntType = INT_CARDBUS; - config->AssignedIRQ = s->pcmcia_irq; - if (config->AssignedIRQ) - config->Attributes |= CONF_ENABLE_IRQ; - if (s->io[0].res) { - config->BasePort1 = s->io[0].res->start; - config->NumPorts1 = s->io[0].res->end - - config->BasePort1 + 1; - } - } - return 0; - } -#endif - - if (p_dev) { - c = p_dev->function_config; - config->Function = p_dev->func; - } else { - c = NULL; - config->Function = 0; - } - - if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { - config->Attributes = 0; - config->Vcc = s->socket.Vcc; - config->Vpp1 = config->Vpp2 = s->socket.Vpp; - return 0; - } - - config->Attributes = c->Attributes | CONF_VALID_CLIENT; - config->Vcc = s->socket.Vcc; - config->Vpp1 = config->Vpp2 = s->socket.Vpp; - config->IntType = c->IntType; - config->ConfigBase = c->ConfigBase; - config->Status = c->Status; - config->Pin = c->Pin; - config->Copy = c->Copy; - config->Option = c->Option; - config->ExtStatus = c->ExtStatus; - config->Present = config->CardValues = c->CardValues; - config->IRQAttributes = c->irq.Attributes; - config->AssignedIRQ = s->pcmcia_irq; - config->BasePort1 = c->io.BasePort1; - config->NumPorts1 = c->io.NumPorts1; - config->Attributes1 = c->io.Attributes1; - config->BasePort2 = c->io.BasePort2; - config->NumPorts2 = c->io.NumPorts2; - config->Attributes2 = c->io.Attributes2; - config->IOAddrLines = c->io.IOAddrLines; - - return 0; -} /* pccard_get_configuration_info */ - - -/*====================================================================== - - These manage a ring buffer of events pending for one user process - -======================================================================*/ - - -static int queue_empty(user_info_t *user) -{ - return (user->event_head == user->event_tail); -} - -static event_t get_queued_event(user_info_t *user) -{ - user->event_tail = (user->event_tail+1) % MAX_EVENTS; - return user->event[user->event_tail]; -} - -static void queue_event(user_info_t *user, event_t event) -{ - user->event_head = (user->event_head+1) % MAX_EVENTS; - if (user->event_head == user->event_tail) - user->event_tail = (user->event_tail+1) % MAX_EVENTS; - user->event[user->event_head] = event; -} - -void handle_event(struct pcmcia_socket *s, event_t event) -{ - user_info_t *user; - for (user = s->user; user; user = user->next) - queue_event(user, event); - wake_up_interruptible(&s->queue); -} - - -/*====================================================================== - - bind_request() and bind_device() are merged by now. Register_client() - is called right at the end of bind_request(), during the driver's - ->attach() call. Individual descriptions: - - bind_request() connects a socket to a particular client driver. - It looks up the specified device ID in the list of registered - drivers, binds it to the socket, and tries to create an instance - of the device. unbind_request() deletes a driver instance. - - Bind_device() associates a device driver with a particular socket. - It is normally called by Driver Services after it has identified - a newly inserted card. An instance of that driver will then be - eligible to register as a client of this socket. - - Register_client() uses the dev_info_t handle to match the - caller with a socket. The driver must have already been bound - to a socket with bind_device() -- in fact, bind_device() - allocates the client structure that will be used. - -======================================================================*/ - -static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info) -{ - struct pcmcia_driver *p_drv; - struct pcmcia_device *p_dev; - int ret = 0; - - s = pcmcia_get_socket(s); - if (!s) - return -EINVAL; - - pr_debug("bind_request(%d, '%s')\n", s->sock, - (char *)bind_info->dev_info); - - p_drv = get_pcmcia_driver(&bind_info->dev_info); - if (!p_drv) { - ret = -EINVAL; - goto err_put; - } - - if (!try_module_get(p_drv->owner)) { - ret = -EINVAL; - goto err_put_driver; - } - - mutex_lock(&s->ops_mutex); - list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { - if (p_dev->func == bind_info->function) { - if ((p_dev->dev.driver == &p_drv->drv)) { - if (p_dev->cardmgr) { - /* if there's already a device - * registered, and it was registered - * by userspace before, we need to - * return the "instance". */ - mutex_unlock(&s->ops_mutex); - bind_info->instance = p_dev; - ret = -EBUSY; - goto err_put_module; - } else { - /* the correct driver managed to bind - * itself magically to the correct - * device. */ - mutex_unlock(&s->ops_mutex); - p_dev->cardmgr = p_drv; - ret = 0; - goto err_put_module; - } - } else if (!p_dev->dev.driver) { - /* there's already a device available where - * no device has been bound to yet. So we don't - * need to register a device! */ - mutex_unlock(&s->ops_mutex); - goto rescan; - } - } - } - mutex_unlock(&s->ops_mutex); - - p_dev = pcmcia_device_add(s, bind_info->function); - if (!p_dev) { - ret = -EIO; - goto err_put_module; - } - -rescan: - p_dev->cardmgr = p_drv; - - /* if a driver is already running, we can abort */ - if (p_dev->dev.driver) - goto err_put_module; - - /* - * Prevent this racing with a card insertion. - */ - mutex_lock(&s->skt_mutex); - ret = bus_rescan_devices(&pcmcia_bus_type); - mutex_unlock(&s->skt_mutex); - if (ret) - goto err_put_module; - - /* check whether the driver indeed matched. I don't care if this - * is racy or not, because it can only happen on cardmgr access - * paths... - */ - if (!(p_dev->dev.driver == &p_drv->drv)) - p_dev->cardmgr = NULL; - - err_put_module: - module_put(p_drv->owner); - err_put_driver: - put_driver(&p_drv->drv); - err_put: - pcmcia_put_socket(s); - - return ret; -} /* bind_request */ - -#ifdef CONFIG_CARDBUS - -static struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s) -{ - if (!s || !(s->state & SOCKET_CARDBUS)) - return NULL; - - return s->cb_dev->subordinate; -} -#endif - -static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int first) -{ - struct pcmcia_device *p_dev; - struct pcmcia_driver *p_drv; - int ret = 0; - -#ifdef CONFIG_CARDBUS - /* - * Some unbelievably ugly code to associate the PCI cardbus - * device and its driver with the PCMCIA "bind" information. - */ - { - struct pci_bus *bus; - - bus = pcmcia_lookup_bus(s); - if (bus) { - struct list_head *list; - struct pci_dev *dev = NULL; - - list = bus->devices.next; - while (list != &bus->devices) { - struct pci_dev *pdev = pci_dev_b(list); - list = list->next; - - if (first) { - dev = pdev; - break; - } - - /* Try to handle "next" here some way? */ - } - if (dev && dev->driver) { - strlcpy(bind_info->name, dev->driver->name, DEV_NAME_LEN); - bind_info->major = 0; - bind_info->minor = 0; - bind_info->next = NULL; - return 0; - } - } - } -#endif - - mutex_lock(&s->ops_mutex); - list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { - if (p_dev->func == bind_info->function) { - p_dev = pcmcia_get_dev(p_dev); - if (!p_dev) - continue; - goto found; - } - } - mutex_unlock(&s->ops_mutex); - return -ENODEV; - - found: - mutex_unlock(&s->ops_mutex); - - p_drv = to_pcmcia_drv(p_dev->dev.driver); - if (p_drv && !p_dev->_locked) { - ret = -EAGAIN; - goto err_put; - } - - if (!first) { - ret = -ENODEV; - goto err_put; - } - - strlcpy(bind_info->name, dev_name(&p_dev->dev), DEV_NAME_LEN); - bind_info->next = NULL; - - err_put: - pcmcia_put_dev(p_dev); - return ret; -} /* get_device_info */ - - -static int ds_open(struct inode *inode, struct file *file) -{ - socket_t i = iminor(inode); - struct pcmcia_socket *s; - user_info_t *user; - static int warning_printed; - int ret = 0; - - pr_debug("ds_open(socket %d)\n", i); - - lock_kernel(); - s = pcmcia_get_socket_by_nr(i); - if (!s) { - ret = -ENODEV; - goto out; - } - s = pcmcia_get_socket(s); - if (!s) { - ret = -ENODEV; - goto out; - } - - if ((file->f_flags & O_ACCMODE) != O_RDONLY) { - if (s->pcmcia_state.busy) { - pcmcia_put_socket(s); - ret = -EBUSY; - goto out; - } - else - s->pcmcia_state.busy = 1; - } - - user = kmalloc(sizeof(user_info_t), GFP_KERNEL); - if (!user) { - pcmcia_put_socket(s); - ret = -ENOMEM; - goto out; - } - user->event_tail = user->event_head = 0; - user->next = s->user; - user->user_magic = USER_MAGIC; - user->socket = s; - s->user = user; - file->private_data = user; - - if (!warning_printed) { - printk(KERN_INFO "pcmcia: Detected deprecated PCMCIA ioctl " - "usage from process: %s.\n", current->comm); - printk(KERN_INFO "pcmcia: This interface will soon be removed from " - "the kernel; please expect breakage unless you upgrade " - "to new tools.\n"); - printk(KERN_INFO "pcmcia: see http://www.kernel.org/pub/linux/" - "utils/kernel/pcmcia/pcmcia.html for details.\n"); - warning_printed = 1; - } - - if (atomic_read(&s->present)) - queue_event(user, CS_EVENT_CARD_INSERTION); -out: - unlock_kernel(); - return ret; -} /* ds_open */ - -/*====================================================================*/ - -static int ds_release(struct inode *inode, struct file *file) -{ - struct pcmcia_socket *s; - user_info_t *user, **link; - - pr_debug("ds_release(socket %d)\n", iminor(inode)); - - user = file->private_data; - if (CHECK_USER(user)) - goto out; - - s = user->socket; - - /* Unlink user data structure */ - if ((file->f_flags & O_ACCMODE) != O_RDONLY) - s->pcmcia_state.busy = 0; - - file->private_data = NULL; - for (link = &s->user; *link; link = &(*link)->next) - if (*link == user) - break; - if (link == NULL) - goto out; - *link = user->next; - user->user_magic = 0; - kfree(user); - pcmcia_put_socket(s); -out: - return 0; -} /* ds_release */ - -/*====================================================================*/ - -static ssize_t ds_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - struct pcmcia_socket *s; - user_info_t *user; - int ret; - - pr_debug("ds_read(socket %d)\n", iminor(file->f_path.dentry->d_inode)); - - if (count < 4) - return -EINVAL; - - user = file->private_data; - if (CHECK_USER(user)) - return -EIO; - - s = user->socket; - ret = wait_event_interruptible(s->queue, !queue_empty(user)); - if (ret == 0) - ret = put_user(get_queued_event(user), (int __user *)buf) ? -EFAULT : 4; - - return ret; -} /* ds_read */ - -/*====================================================================*/ - -static ssize_t ds_write(struct file *file, const char __user *buf, - size_t count, loff_t *ppos) -{ - pr_debug("ds_write(socket %d)\n", iminor(file->f_path.dentry->d_inode)); - - if (count != 4) - return -EINVAL; - if ((file->f_flags & O_ACCMODE) == O_RDONLY) - return -EBADF; - - return -EIO; -} /* ds_write */ - -/*====================================================================*/ - -/* No kernel lock - fine */ -static u_int ds_poll(struct file *file, poll_table *wait) -{ - struct pcmcia_socket *s; - user_info_t *user; - - pr_debug("ds_poll(socket %d)\n", iminor(file->f_path.dentry->d_inode)); - - user = file->private_data; - if (CHECK_USER(user)) - return POLLERR; - s = user->socket; - /* - * We don't check for a dead socket here since that - * will send cardmgr into an endless spin. - */ - poll_wait(file, &s->queue, wait); - if (!queue_empty(user)) - return POLLIN | POLLRDNORM; - return 0; -} /* ds_poll */ - -/*====================================================================*/ - -static int ds_ioctl(struct file *file, u_int cmd, u_long arg) -{ - struct pcmcia_socket *s; - void __user *uarg = (char __user *)arg; - u_int size; - int ret, err; - ds_ioctl_arg_t *buf; - user_info_t *user; - - pr_debug("ds_ioctl(socket %d, %#x, %#lx)\n", iminor(inode), cmd, arg); - - user = file->private_data; - if (CHECK_USER(user)) - return -EIO; - - s = user->socket; - - size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT; - if (size > sizeof(ds_ioctl_arg_t)) - return -EINVAL; - - /* Permission check */ - if (!(cmd & IOC_OUT) && !capable(CAP_SYS_ADMIN)) - return -EPERM; - - if (cmd & IOC_IN) { - if (!access_ok(VERIFY_READ, uarg, size)) { - pr_debug("ds_ioctl(): verify_read = %d\n", -EFAULT); - return -EFAULT; - } - } - if (cmd & IOC_OUT) { - if (!access_ok(VERIFY_WRITE, uarg, size)) { - pr_debug("ds_ioctl(): verify_write = %d\n", -EFAULT); - return -EFAULT; - } - } - buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL); - if (!buf) - return -ENOMEM; - - err = ret = 0; - - if (cmd & IOC_IN) { - if (__copy_from_user((char *)buf, uarg, size)) { - err = -EFAULT; - goto free_out; - } - } - - switch (cmd) { - case DS_ADJUST_RESOURCE_INFO: - ret = pcmcia_adjust_resource_info(&buf->adjust); - break; - case DS_GET_CONFIGURATION_INFO: - if (buf->config.Function && - (buf->config.Function >= s->functions)) - ret = -EINVAL; - else { - struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function); - ret = pccard_get_configuration_info(s, p_dev, &buf->config); - pcmcia_put_dev(p_dev); - } - break; - case DS_GET_FIRST_TUPLE: - mutex_lock(&s->skt_mutex); - pcmcia_validate_mem(s); - mutex_unlock(&s->skt_mutex); - ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple); - break; - case DS_GET_NEXT_TUPLE: - ret = pccard_get_next_tuple(s, BIND_FN_ALL, &buf->tuple); - break; - case DS_GET_TUPLE_DATA: - buf->tuple.TupleData = buf->tuple_parse.data; - buf->tuple.TupleDataMax = sizeof(buf->tuple_parse.data); - ret = pccard_get_tuple_data(s, &buf->tuple); - break; - case DS_PARSE_TUPLE: - buf->tuple.TupleData = buf->tuple_parse.data; - ret = pcmcia_parse_tuple(&buf->tuple, &buf->tuple_parse.parse); - break; - case DS_RESET_CARD: - ret = pcmcia_reset_card(s); - break; - case DS_GET_STATUS: - if (buf->status.Function && - (buf->status.Function >= s->functions)) - ret = -EINVAL; - else { - struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function); - ret = pccard_get_status(s, p_dev, &buf->status); - pcmcia_put_dev(p_dev); - } - break; - case DS_VALIDATE_CIS: - mutex_lock(&s->skt_mutex); - pcmcia_validate_mem(s); - mutex_unlock(&s->skt_mutex); - ret = pccard_validate_cis(s, &buf->cisinfo.Chains); - break; - case DS_SUSPEND_CARD: - pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND); - break; - case DS_RESUME_CARD: - pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME); - break; - case DS_EJECT_CARD: - pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT); - break; - case DS_INSERT_CARD: - pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT); - break; - case DS_ACCESS_CONFIGURATION_REGISTER: - if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) { - err = -EPERM; - goto free_out; - } - - ret = -EINVAL; - - if (!(buf->conf_reg.Function && - (buf->conf_reg.Function >= s->functions))) { - struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->conf_reg.Function); - if (p_dev) { - ret = pcmcia_access_configuration_register(p_dev, &buf->conf_reg); - pcmcia_put_dev(p_dev); - } - } - break; - case DS_GET_FIRST_REGION: - case DS_GET_NEXT_REGION: - case DS_BIND_MTD: - if (!capable(CAP_SYS_ADMIN)) { - err = -EPERM; - goto free_out; - } else { - printk_once(KERN_WARNING - "2.6. kernels use pcmciamtd instead of memory_cs.c and do not require special\n"); - printk_once(KERN_WARNING "MTD handling any more.\n"); - } - err = -EINVAL; - goto free_out; - break; - case DS_GET_FIRST_WINDOW: - ret = pcmcia_get_window(s, &buf->win_info.handle, 1, - &buf->win_info.window); - break; - case DS_GET_NEXT_WINDOW: - ret = pcmcia_get_window(s, &buf->win_info.handle, - buf->win_info.handle + 1, &buf->win_info.window); - break; - case DS_GET_MEM_PAGE: - ret = pcmcia_get_mem_page(s, buf->win_info.handle, - &buf->win_info.map); - break; - case DS_REPLACE_CIS: - ret = pcmcia_replace_cis(s, buf->cisdump.Data, buf->cisdump.Length); - break; - case DS_BIND_REQUEST: - if (!capable(CAP_SYS_ADMIN)) { - err = -EPERM; - goto free_out; - } - err = bind_request(s, &buf->bind_info); - break; - case DS_GET_DEVICE_INFO: - err = get_device_info(s, &buf->bind_info, 1); - break; - case DS_GET_NEXT_DEVICE: - err = get_device_info(s, &buf->bind_info, 0); - break; - case DS_UNBIND_REQUEST: - err = 0; - break; - default: - err = -EINVAL; - } - - if ((err == 0) && (ret != 0)) { - pr_debug("ds_ioctl: ret = %d\n", ret); - switch (ret) { - case -ENODEV: - case -EINVAL: - case -EBUSY: - case -ENOSYS: - err = ret; - break; - case -ENOMEM: - err = -ENOSPC; break; - case -ENOSPC: - err = -ENODATA; break; - default: - err = -EIO; break; - } - } - - if (cmd & IOC_OUT) { - if (__copy_to_user(uarg, (char *)buf, size)) - err = -EFAULT; - } - -free_out: - kfree(buf); - return err; -} /* ds_ioctl */ - -static long ds_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - int ret; - - lock_kernel(); - ret = ds_ioctl(file, cmd, arg); - unlock_kernel(); - - return ret; -} - - -/*====================================================================*/ - -static const struct file_operations ds_fops = { - .owner = THIS_MODULE, - .open = ds_open, - .release = ds_release, - .unlocked_ioctl = ds_unlocked_ioctl, - .read = ds_read, - .write = ds_write, - .poll = ds_poll, -}; - -void __init pcmcia_setup_ioctl(void) -{ - int i; - - /* Set up character device for user mode clients */ - i = register_chrdev(0, "pcmcia", &ds_fops); - if (i < 0) - printk(KERN_NOTICE "unable to find a free device # for " - "Driver Services (error=%d)\n", i); - else - major_dev = i; - -#ifdef CONFIG_PROC_FS - proc_pccard = proc_mkdir("bus/pccard", NULL); - if (proc_pccard) - proc_create("drivers", 0, proc_pccard, &pccard_drivers_proc_fops); -#endif -} - - -void __exit pcmcia_cleanup_ioctl(void) -{ -#ifdef CONFIG_PROC_FS - if (proc_pccard) { - remove_proc_entry("drivers", proc_pccard); - remove_proc_entry("bus/pccard", NULL); - } -#endif - if (major_dev != -1) - unregister_chrdev(major_dev, "pcmcia"); -} diff --git a/drivers/pcmcia/rsrc_iodyn.c b/drivers/pcmcia/rsrc_iodyn.c index d0bf350..6ed7bf1 100644 --- a/drivers/pcmcia/rsrc_iodyn.c +++ b/drivers/pcmcia/rsrc_iodyn.c @@ -164,8 +164,6 @@ struct pccard_resource_ops pccard_iodyn_ops = { .validate_mem = NULL, .find_io = iodyn_find_io, .find_mem = NULL, - .add_io = NULL, - .add_mem = NULL, .init = static_init, .exit = NULL, }; diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index 142efac..b12ecf7 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c @@ -62,8 +62,6 @@ struct pccard_resource_ops pccard_static_ops = { .validate_mem = NULL, .find_io = static_find_io, .find_mem = NULL, - .add_io = NULL, - .add_mem = NULL, .init = static_init, .exit = NULL, }; diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index dcd1a4a..d217dc1 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -1055,8 +1055,6 @@ struct pccard_resource_ops pccard_nonstatic_ops = { .validate_mem = pcmcia_nonstatic_validate_mem, .find_io = nonstatic_find_io, .find_mem = nonstatic_find_mem_region, - .add_io = adjust_io, - .add_mem = adjust_memory, .init = nonstatic_init, .exit = nonstatic_release_resource_db, }; -- cgit v1.1 From 216d7cdd3b060518a2d4faf584eb15ef5af862b6 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 11 Jul 2010 10:04:59 +0200 Subject: pcmcia: simplify event callback The event callback for handling 16bit PCMCIA cards only needs to be informed about a few events. Furthermore, send_event may already only be called with skt->skt_mutex held, which also protects against the module being removed behind the callback's back. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs.c | 44 ++++++++++---------------------------------- drivers/pcmcia/ds.c | 6 ------ 2 files changed, 10 insertions(+), 40 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 976d807..5ea19672 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -264,8 +264,6 @@ EXPORT_SYMBOL(pcmcia_get_socket_by_nr); static int send_event(struct pcmcia_socket *s, event_t event, int priority) { - int ret; - if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL)) return 0; @@ -274,14 +272,8 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority) if (!s->callback) return 0; - if (!try_module_get(s->callback->owner)) - return 0; - ret = s->callback->event(s, event, priority); - - module_put(s->callback->owner); - - return ret; + return s->callback->event(s, event, priority); } static int socket_reset(struct pcmcia_socket *skt) @@ -494,7 +486,6 @@ static int socket_suspend(struct pcmcia_socket *skt) mutex_lock(&skt->ops_mutex); skt->suspended_state = skt->state; - send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); skt->socket = dead_socket; skt->ops->set_socket(skt, &skt->socket); if (skt->ops->suspend) @@ -654,16 +645,8 @@ static int pccardd(void *__skt) spin_unlock_irqrestore(&skt->thread_lock, flags); mutex_lock(&skt->skt_mutex); - if (events) { - if (events & SS_DETECT) - socket_detect_change(skt); - if (events & SS_BATDEAD) - send_event(skt, CS_EVENT_BATTERY_DEAD, CS_EVENT_PRI_LOW); - if (events & SS_BATWARN) - send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); - if (events & SS_READY) - send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); - } + if (events & SS_DETECT) + socket_detect_change(skt); if (sysfs_events) { if (sysfs_events & PCMCIA_UEVENT_EJECT) @@ -823,20 +806,13 @@ int pcmcia_reset_card(struct pcmcia_socket *skt) break; } - ret = send_event(skt, CS_EVENT_RESET_REQUEST, CS_EVENT_PRI_LOW); - if (ret == 0) { - send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); - if (skt->callback) - skt->callback->suspend(skt); - mutex_lock(&skt->ops_mutex); - ret = socket_reset(skt); - mutex_unlock(&skt->ops_mutex); - if (ret == 0) { - send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); - if (skt->callback) - skt->callback->resume(skt); - } - } + if (skt->callback) + skt->callback->suspend(skt); + mutex_lock(&skt->ops_mutex); + ret = socket_reset(skt); + mutex_unlock(&skt->ops_mutex); + if ((ret == 0) && (skt->callback)) + skt->callback->resume(skt); ret = 0; } while (0); diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index d2ec458..bd58650 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1253,9 +1253,6 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) pcmcia_card_add(skt); break; - case CS_EVENT_EJECTION_REQUEST: - break; - case CS_EVENT_PM_RESUME: if (verify_cis_cache(skt) != 0) { dev_dbg(&skt->dev, "cis mismatch - different card\n"); @@ -1273,9 +1270,6 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) } break; - case CS_EVENT_PM_SUSPEND: - case CS_EVENT_RESET_PHYSICAL: - case CS_EVENT_CARD_RESET: default: break; } -- cgit v1.1 From 7b24e7988263d3cae25ff35cfeae8a5657d93051 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 11 Jul 2010 10:26:53 +0200 Subject: pcmcia: split up central event handler Split up the central event handler for 16bit cards into three individual functions. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs.c | 36 +++------------ drivers/pcmcia/cs_internal.h | 7 +-- drivers/pcmcia/ds.c | 103 ++++++++++++++++++------------------------- 3 files changed, 54 insertions(+), 92 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 5ea19672..efa30b8 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -252,30 +252,6 @@ struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr) } EXPORT_SYMBOL(pcmcia_get_socket_by_nr); -/* - * The central event handler. Send_event() sends an event to the - * 16-bit subsystem, which then calls the relevant device drivers. - * Parse_events() interprets the event bits from - * a card status change report. Do_shutdown() handles the high - * priority stuff associated with a card removal. - */ - -/* NOTE: send_event needs to be called with skt->sem held. */ - -static int send_event(struct pcmcia_socket *s, event_t event, int priority) -{ - if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL)) - return 0; - - dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", - event, priority, s->callback); - - if (!s->callback) - return 0; - - return s->callback->event(s, event, priority); -} - static int socket_reset(struct pcmcia_socket *skt) { int status, i; @@ -318,7 +294,8 @@ static void socket_shutdown(struct pcmcia_socket *s) dev_dbg(&s->dev, "shutdown\n"); - send_event(s, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); + if (s->callback) + s->callback->remove(s); mutex_lock(&s->ops_mutex); s->state &= SOCKET_INUSE | SOCKET_PRESENT; @@ -469,7 +446,8 @@ static int socket_insert(struct pcmcia_socket *skt) dev_dbg(&skt->dev, "insert done\n"); mutex_unlock(&skt->ops_mutex); - send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); + if (!(skt->state & SOCKET_CARDBUS) && (skt->callback)) + skt->callback->add(skt); } else { mutex_unlock(&skt->ops_mutex); socket_shutdown(skt); @@ -546,8 +524,8 @@ static int socket_late_resume(struct pcmcia_socket *skt) return 0; } #endif - - send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW); + if (!(skt->state & SOCKET_CARDBUS) && (skt->callback)) + skt->callback->early_resume(skt); return 0; } @@ -766,7 +744,7 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) s->callback = c; if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) - send_event(s, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); + s->callback->add(s); } else s->callback = NULL; err: diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index a6cc63d..45e7fd1 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -10,7 +10,7 @@ * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * (C) 1999 David A. Hinds - * (C) 2003 - 2008 Dominik Brodowski + * (C) 2003 - 2010 Dominik Brodowski * * * This file contains definitions _only_ needed by the PCMCIA core modules. @@ -106,11 +106,12 @@ void cb_free(struct pcmcia_socket *s); struct pcmcia_callback{ struct module *owner; - int (*event) (struct pcmcia_socket *s, - event_t event, int priority); + int (*add) (struct pcmcia_socket *s); + int (*remove) (struct pcmcia_socket *s); void (*requery) (struct pcmcia_socket *s); int (*validate) (struct pcmcia_socket *s, unsigned int *i); int (*suspend) (struct pcmcia_socket *s); + int (*early_resume) (struct pcmcia_socket *s); int (*resume) (struct pcmcia_socket *s); }; diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index bd58650..78b5b65 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -10,7 +10,7 @@ * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. * * (C) 1999 David A. Hinds - * (C) 2003 - 2006 Dominik Brodowski + * (C) 2003 - 2010 Dominik Brodowski */ #include @@ -1208,76 +1208,57 @@ static int pcmcia_bus_suspend(struct pcmcia_socket *skt) return 0; } +static int pcmcia_bus_remove(struct pcmcia_socket *skt) +{ + atomic_set(&skt->present, 0); + pcmcia_card_remove(skt, NULL); -/*====================================================================== + mutex_lock(&skt->ops_mutex); + destroy_cis_cache(skt); + pcmcia_cleanup_irq(skt); + mutex_unlock(&skt->ops_mutex); - The card status event handler. + return 0; +} -======================================================================*/ +static int pcmcia_bus_add(struct pcmcia_socket *skt) +{ + atomic_set(&skt->present, 1); -/* Normally, the event is passed to individual drivers after - * informing userspace. Only for CS_EVENT_CARD_REMOVAL this - * is inversed to maintain historic compatibility. - */ + mutex_lock(&skt->ops_mutex); + skt->pcmcia_state.has_pfc = 0; + destroy_cis_cache(skt); /* to be on the safe side... */ + mutex_unlock(&skt->ops_mutex); -static int ds_event(struct pcmcia_socket *skt, event_t event, int priority) -{ - struct pcmcia_socket *s = pcmcia_get_socket(skt); + pcmcia_card_add(skt); - if (!s) { - dev_printk(KERN_ERR, &skt->dev, - "PCMCIA obtaining reference to socket " \ - "failed, event 0x%x lost!\n", event); - return -ENODEV; - } + return 0; +} - dev_dbg(&skt->dev, "ds_event(0x%06x, %d, 0x%p)\n", - event, priority, skt); +static int pcmcia_bus_early_resume(struct pcmcia_socket *skt) +{ + if (!verify_cis_cache(skt)) { + pcmcia_put_socket(skt); + return 0; + } - switch (event) { - case CS_EVENT_CARD_REMOVAL: - atomic_set(&skt->present, 0); - pcmcia_card_remove(skt, NULL); - mutex_lock(&s->ops_mutex); - destroy_cis_cache(s); - pcmcia_cleanup_irq(s); - mutex_unlock(&s->ops_mutex); - break; + dev_dbg(&skt->dev, "cis mismatch - different card\n"); - case CS_EVENT_CARD_INSERTION: - atomic_set(&skt->present, 1); - mutex_lock(&s->ops_mutex); - s->pcmcia_state.has_pfc = 0; - destroy_cis_cache(s); /* to be on the safe side... */ - mutex_unlock(&s->ops_mutex); - pcmcia_card_add(skt); - break; - - case CS_EVENT_PM_RESUME: - if (verify_cis_cache(skt) != 0) { - dev_dbg(&skt->dev, "cis mismatch - different card\n"); - /* first, remove the card */ - ds_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); - mutex_lock(&s->ops_mutex); - destroy_cis_cache(skt); - kfree(skt->fake_cis); - skt->fake_cis = NULL; - s->functions = 0; - mutex_unlock(&s->ops_mutex); - /* now, add the new card */ - ds_event(skt, CS_EVENT_CARD_INSERTION, - CS_EVENT_PRI_LOW); - } - break; + /* first, remove the card */ + pcmcia_bus_remove(skt); - default: - break; - } + mutex_lock(&skt->ops_mutex); + destroy_cis_cache(skt); + kfree(skt->fake_cis); + skt->fake_cis = NULL; + skt->functions = 0; + mutex_unlock(&skt->ops_mutex); - pcmcia_put_socket(s); + /* now, add the new card */ + pcmcia_bus_add(skt); + return 0; +} - return 0; -} /* ds_event */ /* * NOTE: This is racy. There's no guarantee the card will still be @@ -1306,10 +1287,12 @@ EXPORT_SYMBOL(pcmcia_dev_present); static struct pcmcia_callback pcmcia_bus_callback = { .owner = THIS_MODULE, - .event = ds_event, + .add = pcmcia_bus_add, + .remove = pcmcia_bus_remove, .requery = pcmcia_requery, .validate = pccard_validate_cis, .suspend = pcmcia_bus_suspend, + .early_resume = pcmcia_bus_early_resume, .resume = pcmcia_bus_resume, }; -- cgit v1.1 From ce3f9d71bd9c4268698109ad425625a2a8f51e22 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 21 Jul 2010 14:43:05 +0200 Subject: pcmcia: remove unused flag, simplify headers As we only provide one way to set up resources now, we can remove the resource-setup-related bitfield (except resource_setup_done). In addition, pcmcia_state only consisted of one entry, so remove this bitfield as well. Suggested-by: Komuro Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 14 +++++++------- drivers/pcmcia/rsrc_nonstatic.c | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 78b5b65..0861771 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -294,7 +294,7 @@ static int pcmcia_device_probe(struct device *dev) } mutex_lock(&s->ops_mutex); - if ((s->pcmcia_state.has_pfc) && + if ((s->pcmcia_pfc) && (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY); mutex_unlock(&s->ops_mutex); @@ -359,7 +359,7 @@ static int pcmcia_device_remove(struct device *dev) * pseudo multi-function card, we need to unbind * all devices */ - if ((p_dev->socket->pcmcia_state.has_pfc) && + if ((p_dev->socket->pcmcia_pfc) && (p_dev->socket->device_count > 0) && (p_dev->device_no == 0)) pcmcia_card_remove(p_dev->socket, p_dev); @@ -681,7 +681,7 @@ static void pcmcia_requery(struct pcmcia_socket *s) * call pcmcia_device_add() -- which will fail if both * devices are already registered. */ mutex_lock(&s->ops_mutex); - has_pfc = s->pcmcia_state.has_pfc; + has_pfc = s->pcmcia_pfc; mutex_unlock(&s->ops_mutex); if (has_pfc) pcmcia_device_add(s, 0); @@ -813,7 +813,7 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { dev_dbg(&dev->dev, "this is a pseudo-multi-function device\n"); mutex_lock(&dev->socket->ops_mutex); - dev->socket->pcmcia_state.has_pfc = 1; + dev->socket->pcmcia_pfc = 1; mutex_unlock(&dev->socket->ops_mutex); if (dev->device_no != did->device_no) return 0; @@ -827,7 +827,7 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev, /* if this is a pseudo-multi-function device, * we need explicit matches */ - if (dev->socket->pcmcia_state.has_pfc) + if (dev->socket->pcmcia_pfc) return 0; if (dev->device_no) return 0; @@ -1226,7 +1226,7 @@ static int pcmcia_bus_add(struct pcmcia_socket *skt) atomic_set(&skt->present, 1); mutex_lock(&skt->ops_mutex); - skt->pcmcia_state.has_pfc = 0; + skt->pcmcia_pfc = 0; destroy_cis_cache(skt); /* to be on the safe side... */ mutex_unlock(&skt->ops_mutex); @@ -1317,7 +1317,7 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev, } INIT_LIST_HEAD(&socket->devices_list); - memset(&socket->pcmcia_state, 0, sizeof(u8)); + socket->pcmcia_pfc = 0; socket->device_count = 0; atomic_set(&socket->present, 0); diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index d217dc1..13245a2 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -1113,8 +1113,6 @@ static ssize_t store_io_db(struct device *dev, mutex_lock(&s->ops_mutex); ret = adjust_io(s, add, start_addr, end_addr); - if (!ret) - s->resource_setup_new = 1; mutex_unlock(&s->ops_mutex); return ret ? ret : count; @@ -1181,8 +1179,6 @@ static ssize_t store_mem_db(struct device *dev, mutex_lock(&s->ops_mutex); ret = adjust_memory(s, add, start_addr, end_addr); - if (!ret) - s->resource_setup_new = 1; mutex_unlock(&s->ops_mutex); return ret ? ret : count; -- cgit v1.1 From ac8b422838046ffc26be4874a3cbae0d313f4209 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Wed, 21 Jul 2010 22:38:13 +0200 Subject: pcmcia: remove cs_types.h Remove cs_types.h which is no longer needed: Most definitions aren't used at all, a few can be made away with, and two remaining definitions (typedefs, unfortunatley) may be moved to more specific places. CC: linux-ide@vger.kernel.org CC: linux-usb@vger.kernel.org CC: laforge@gnumonks.org CC: linux-mtd@lists.infradead.org CC: alsa-devel@alsa-project.org CC: linux-serial@vger.kernel.org Acked-by: Marcel Holtmann (for drivers/bluetooth/) Acked-by: David S. Miller Signed-off-by: Dominik Brodowski --- drivers/pcmcia/au1000_generic.h | 1 - drivers/pcmcia/au1000_pb1x00.c | 2 -- drivers/pcmcia/cistpl.c | 1 - drivers/pcmcia/cs.c | 1 - drivers/pcmcia/db1xxx_ss.c | 1 - drivers/pcmcia/ds.c | 1 - drivers/pcmcia/i82092.c | 1 - drivers/pcmcia/i82365.c | 1 - drivers/pcmcia/m32r_cfc.c | 1 - drivers/pcmcia/m32r_pcc.c | 1 - drivers/pcmcia/m8xx_pcmcia.c | 1 - drivers/pcmcia/pcmcia_cis.c | 1 - drivers/pcmcia/pcmcia_resource.c | 1 - drivers/pcmcia/pd6729.c | 1 - drivers/pcmcia/pxa2xx_base.c | 1 - drivers/pcmcia/rsrc_iodyn.c | 1 - drivers/pcmcia/rsrc_mgr.c | 1 - drivers/pcmcia/rsrc_nonstatic.c | 1 - drivers/pcmcia/sa1100_generic.c | 1 - drivers/pcmcia/soc_common.h | 1 - drivers/pcmcia/socket_sysfs.c | 1 - drivers/pcmcia/tcic.c | 1 - drivers/pcmcia/xxs1500_ss.c | 1 - drivers/pcmcia/yenta_socket.c | 1 - 24 files changed, 25 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/au1000_generic.h b/drivers/pcmcia/au1000_generic.h index a324d32..67530ce 100644 --- a/drivers/pcmcia/au1000_generic.h +++ b/drivers/pcmcia/au1000_generic.h @@ -23,7 +23,6 @@ /* include the world */ -#include #include #include #include diff --git a/drivers/pcmcia/au1000_pb1x00.c b/drivers/pcmcia/au1000_pb1x00.c index 5a979cb..807f2d7 100644 --- a/drivers/pcmcia/au1000_pb1x00.c +++ b/drivers/pcmcia/au1000_pb1x00.c @@ -31,11 +31,9 @@ #include #include -#include #include #include #include -#include #include #include diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 8844bc3e..ba4a5ac 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -27,7 +27,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index efa30b8..2ec8ac9 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -32,7 +32,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/db1xxx_ss.c b/drivers/pcmcia/db1xxx_ss.c index 0f4cc3f..27575e63 100644 --- a/drivers/pcmcia/db1xxx_ss.c +++ b/drivers/pcmcia/db1xxx_ss.c @@ -29,7 +29,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 0861771..bacfc55 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/i82092.c b/drivers/pcmcia/i82092.c index 3003bb3..05d0879 100644 --- a/drivers/pcmcia/i82092.c +++ b/drivers/pcmcia/i82092.c @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c index 9e2a156..61746bd 100644 --- a/drivers/pcmcia/i82365.c +++ b/drivers/pcmcia/i82365.c @@ -50,7 +50,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c index 7e16ed8..24de499 100644 --- a/drivers/pcmcia/m32r_cfc.c +++ b/drivers/pcmcia/m32r_cfc.c @@ -26,7 +26,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c index 6c5c3f9..8e47238 100644 --- a/drivers/pcmcia/m32r_pcc.c +++ b/drivers/pcmcia/m32r_pcc.c @@ -27,7 +27,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c index 25e5e30..f2f90a7 100644 --- a/drivers/pcmcia/m8xx_pcmcia.c +++ b/drivers/pcmcia/m8xx_pcmcia.c @@ -59,7 +59,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/pcmcia_cis.c b/drivers/pcmcia/pcmcia_cis.c index 4a65eaf..0ac54da 100644 --- a/drivers/pcmcia/pcmcia_cis.c +++ b/drivers/pcmcia/pcmcia_cis.c @@ -19,7 +19,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index a4cd9ad..2394de4 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -25,7 +25,6 @@ #include -#include #include #include #include diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c index b61a136..b8a869a 100644 --- a/drivers/pcmcia/pd6729.c +++ b/drivers/pcmcia/pd6729.c @@ -17,7 +17,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/pxa2xx_base.c b/drivers/pcmcia/pxa2xx_base.c index df4532e..66c0225 100644 --- a/drivers/pcmcia/pxa2xx_base.c +++ b/drivers/pcmcia/pxa2xx_base.c @@ -32,7 +32,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/rsrc_iodyn.c b/drivers/pcmcia/rsrc_iodyn.c index 6ed7bf1..3b1dce2 100644 --- a/drivers/pcmcia/rsrc_iodyn.c +++ b/drivers/pcmcia/rsrc_iodyn.c @@ -16,7 +16,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index b12ecf7..b433a79 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c @@ -16,7 +16,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 13245a2..0cca08f 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -28,7 +28,6 @@ #include -#include #include #include #include diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c index edbd8c4..e098514 100644 --- a/drivers/pcmcia/sa1100_generic.c +++ b/drivers/pcmcia/sa1100_generic.c @@ -35,7 +35,6 @@ #include #include -#include #include #include diff --git a/drivers/pcmcia/soc_common.h b/drivers/pcmcia/soc_common.h index e40824c..3fba3a6 100644 --- a/drivers/pcmcia/soc_common.h +++ b/drivers/pcmcia/soc_common.h @@ -11,7 +11,6 @@ /* include the world */ #include -#include #include #include #include diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index 80e36bc..cb0d3ac 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c index 56004a1..be0d841 100644 --- a/drivers/pcmcia/tcic.c +++ b/drivers/pcmcia/tcic.c @@ -49,7 +49,6 @@ #include #include -#include #include #include #include "tcic.h" diff --git a/drivers/pcmcia/xxs1500_ss.c b/drivers/pcmcia/xxs1500_ss.c index 201ccfa..fa88c36 100644 --- a/drivers/pcmcia/xxs1500_ss.c +++ b/drivers/pcmcia/xxs1500_ss.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index f1d4137..414d9a6 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -19,7 +19,6 @@ #include #include -#include #include #include -- cgit v1.1 From 1d5cc192d431bce2ebe9fde64054ce903200e179 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 24 Jul 2010 12:23:21 +0200 Subject: pcmcia: use pcmica_{read,write}_config_byte Use pcmcia_read_config_byte and pcmcia_write_config_byte instead of pcmcia_access_configuration_register. CC: netdev@vger.kernel.org CC: linux-wireless@vger.kernel.org CC: linux-serial@vger.kernel.org CC: Michael Buesch Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cistpl.c | 7 ++-- drivers/pcmcia/cs_internal.h | 4 +-- drivers/pcmcia/pcmcia_resource.c | 70 ++++++++++++++++++++++++---------------- 3 files changed, 48 insertions(+), 33 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index ba4a5ac..1733fab 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -209,7 +209,7 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, * Probably only useful for writing one-byte registers. Must be called * with ops_mutex held. */ -void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, +int pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, u_int len, void *ptr) { void __iomem *sys, *end; @@ -231,7 +231,7 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, ((cis_width) ? MAP_16BIT : 0)); if (!sys) { dev_dbg(&s->dev, "could not map memory\n"); - return; /* FIXME: Error */ + return -EINVAL; } writeb(flags, sys+CISREG_ICTRL0); @@ -256,7 +256,7 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, sys = set_cis_map(s, card_offset, flags); if (!sys) { dev_dbg(&s->dev, "could not map memory\n"); - return; /* FIXME: error */ + return -EINVAL; } end = sys + s->map_size; @@ -270,6 +270,7 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, addr = 0; } } + return 0; } diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 45e7fd1..cebd40d 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -158,8 +158,8 @@ extern struct bin_attribute pccard_cis_attr; int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, u_int len, void *ptr); -void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, - u_int addr, u_int len, void *ptr); +int pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, + u_int addr, u_int len, void *ptr); void release_cis_mem(struct pcmcia_socket *s); void destroy_cis_cache(struct pcmcia_socket *s); int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index 2394de4..563750e 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -108,25 +108,25 @@ static void release_io_space(struct pcmcia_socket *s, unsigned int base, } /* release_io_space */ -/** pccard_access_configuration_register +/** + * pcmcia_access_config() - read or write card configuration registers * - * Access_configuration_register() reads and writes configuration - * registers in attribute memory. Memory window 0 is reserved for - * this and the tuple reading services. + * pcmcia_access_config() reads and writes configuration registers in + * attribute memory. Memory window 0 is reserved for this and the tuple + * reading services. Drivers must use pcmcia_read_config_byte() or + * pcmcia_write_config_byte(). */ - -int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, - conf_reg_t *reg) +static int pcmcia_access_config(struct pcmcia_device *p_dev, + off_t where, u8 *val, + int (*accessf) (struct pcmcia_socket *s, + int attr, unsigned int addr, + unsigned int len, void *ptr)) { struct pcmcia_socket *s; config_t *c; int addr; - u_char val; int ret = 0; - if (!p_dev || !p_dev->function_config) - return -EINVAL; - s = p_dev->socket; mutex_lock(&s->ops_mutex); @@ -138,26 +138,40 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, return -EACCES; } - addr = (c->ConfigBase + reg->Offset) >> 1; + addr = (c->ConfigBase + where) >> 1; + + ret = accessf(s, 1, addr, 1, val); - switch (reg->Action) { - case CS_READ: - ret = pcmcia_read_cis_mem(s, 1, addr, 1, &val); - reg->Value = val; - break; - case CS_WRITE: - val = reg->Value; - pcmcia_write_cis_mem(s, 1, addr, 1, &val); - break; - default: - dev_dbg(&s->dev, "Invalid conf register request\n"); - ret = -EINVAL; - break; - } mutex_unlock(&s->ops_mutex); + return ret; -} /* pcmcia_access_configuration_register */ -EXPORT_SYMBOL(pcmcia_access_configuration_register); +} /* pcmcia_access_config */ + + +/** + * pcmcia_read_config_byte() - read a byte from a card configuration register + * + * pcmcia_read_config_byte() reads a byte from a configuration register in + * attribute memory. + */ +int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val) +{ + return pcmcia_access_config(p_dev, where, val, pcmcia_read_cis_mem); +} +EXPORT_SYMBOL(pcmcia_read_config_byte); + + +/** + * pcmcia_write_config_byte() - write a byte to a card configuration register + * + * pcmcia_write_config_byte() writes a byte to a configuration register in + * attribute memory. + */ +int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val) +{ + return pcmcia_access_config(p_dev, where, &val, pcmcia_write_cis_mem); +} +EXPORT_SYMBOL(pcmcia_write_config_byte); int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, -- cgit v1.1 From 3dace8cf15ae1dd7c9384758b3a29556b441a90a Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 24 Jul 2010 12:33:29 +0200 Subject: pcmcia: clean up cs.h Remove some obsolete definitions from cs.h Signed-off-by: Dominik Brodowski --- drivers/pcmcia/rsrc_nonstatic.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 0cca08f..c17a17d 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -63,6 +63,9 @@ struct socket_data { #define MEM_PROBE_LOW (1 << 0) #define MEM_PROBE_HIGH (1 << 1) +/* Action field */ +#define REMOVE_MANAGED_RESOURCE 1 +#define ADD_MANAGED_RESOURCE 2 /*====================================================================== -- cgit v1.1 From 2ce4905e4da9f512b38f56a53ece9da2072dd164 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 24 Jul 2010 13:14:44 +0200 Subject: pcmcia: use struct resource for PCMCIA devices Introduce a new field into struct pcmcia_device named "resource" and of type struct resource *, which contains the IO port ranges allocated for this device. Memory window ranges and registration with the resource trees will follow at a later date. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs_internal.h | 4 +- drivers/pcmcia/ds.c | 17 +++-- drivers/pcmcia/pcmcia_resource.c | 141 ++++++++++++++++++++++----------------- 3 files changed, 93 insertions(+), 69 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index cebd40d..a85558f 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -35,7 +35,9 @@ typedef struct config_t { unsigned int ConfigBase; unsigned char Status, Pin, Copy, Option, ExtStatus; unsigned int CardValues; - io_req_t io; + + struct resource io[MAX_IO_WIN]; /* io ports */ + struct { u_int Attributes; } irq; diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index bacfc55..7ddd19a 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -531,7 +531,6 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list) if (p_dev->func == tmp_dev->func) { p_dev->function_config = tmp_dev->function_config; - p_dev->io = tmp_dev->io; p_dev->irq = tmp_dev->irq; kref_get(&p_dev->function_config->ref); } @@ -544,15 +543,23 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, "IRQ setup failed -- device might not work\n"); if (!p_dev->function_config) { + config_t *c; dev_dbg(&p_dev->dev, "creating config_t\n"); - p_dev->function_config = kzalloc(sizeof(struct config_t), - GFP_KERNEL); - if (!p_dev->function_config) { + c = kzalloc(sizeof(struct config_t), GFP_KERNEL); + if (!c) { mutex_unlock(&s->ops_mutex); goto err_unreg; } - kref_init(&p_dev->function_config->ref); + p_dev->function_config = c; + kref_init(&c->ref); + for (i = 0; i < MAX_IO_WIN; i++) { + c->io[i].name = dev_name(&p_dev->dev); + c->io[i].flags = IORESOURCE_IO; + } } + for (i = 0; i < MAX_IO_WIN; i++) + p_dev->resource[i] = &p_dev->function_config->io[i]; + mutex_unlock(&s->ops_mutex); dev_printk(KERN_NOTICE, &p_dev->dev, diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index 563750e..fcd48da 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -60,43 +60,60 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, * * Special stuff for managing IO windows, because they are scarce */ - -static int alloc_io_space(struct pcmcia_socket *s, u_int attr, - unsigned int *base, unsigned int num, u_int lines) +static int alloc_io_space(struct pcmcia_socket *s, struct resource *res, + unsigned int lines) { unsigned int align; + unsigned int base = res->start; + unsigned int num = res->end; + int ret; + + res->flags |= IORESOURCE_IO; - align = (*base) ? (lines ? 1<dev, "alloc_io_space request for %pR\n", res); + + align = base ? (lines ? 1<dev, "odd IO request: num %#x align %#x\n", - num, align); + if (base) { + dev_dbg(&s->dev, "odd IO request\n"); align = 0; } else while (align && (align < num)) align <<= 1; } - if (*base & ~(align-1)) { - dev_dbg(&s->dev, "odd IO request: base %#x align %#x\n", - *base, align); + if (base & ~(align-1)) { + dev_dbg(&s->dev, "odd IO request\n"); align = 0; } - return s->resource_ops->find_io(s, attr, base, num, align); + ret = s->resource_ops->find_io(s, res->flags, &base, num, align); + if (ret) { + dev_dbg(&s->dev, "alloc_io_space request returned %d", ret); + return -EINVAL; + } + + res->start = base; + res->end = res->start + num - 1; + dev_dbg(&s->dev, "alloc_io_space request returned %pR, %d\n", res, ret); + return 0; } /* alloc_io_space */ -static void release_io_space(struct pcmcia_socket *s, unsigned int base, - unsigned int num) +static void release_io_space(struct pcmcia_socket *s, struct resource *res) { + resource_size_t num = resource_size(res); int i; + dev_dbg(&s->dev, "release_io_space for %pR\n", res); + for (i = 0; i < MAX_IO_WIN; i++) { if (!s->io[i].res) continue; - if ((s->io[i].res->start <= base) && - (s->io[i].res->end >= base+num-1)) { + if ((s->io[i].res->start <= res->start) && + (s->io[i].res->end >= res->end)) { s->io[i].InUse -= num; + res->start = res->end = 0; + res->flags = IORESOURCE_IO; /* Free the window if no one else is using it */ if (s->io[i].InUse == 0) { release_resource(s->io[i].res); @@ -329,31 +346,25 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) * don't bother checking the port ranges against the current socket * values. */ -static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) +static int pcmcia_release_io(struct pcmcia_device *p_dev) { struct pcmcia_socket *s = p_dev->socket; int ret = -EINVAL; config_t *c; mutex_lock(&s->ops_mutex); - c = p_dev->function_config; - if (!p_dev->_io) goto out; - p_dev->_io = 0; + c = p_dev->function_config; - if ((c->io.BasePort1 != req->BasePort1) || - (c->io.NumPorts1 != req->NumPorts1) || - (c->io.BasePort2 != req->BasePort2) || - (c->io.NumPorts2 != req->NumPorts2)) - goto out; + release_io_space(s, &c->io[0]); - c->state &= ~CONFIG_IO_REQ; + if (c->io[1].end) + release_io_space(s, &c->io[1]); - release_io_space(s, req->BasePort1, req->NumPorts1); - if (req->NumPorts2) - release_io_space(s, req->BasePort2, req->NumPorts2); + p_dev->_io = 0; + c->state &= ~CONFIG_IO_REQ; out: mutex_unlock(&s->ops_mutex); @@ -486,13 +497,13 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus); } if (req->Present & PRESENT_IOBASE_0) { - u_char b = c->io.BasePort1 & 0xff; + u8 b = c->io[0].start & 0xff; pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b); - b = (c->io.BasePort1 >> 8) & 0xff; + b = (c->io[0].start >> 8) & 0xff; pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b); } if (req->Present & PRESENT_IOSIZE) { - u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1; + u8 b = resource_size(&c->io[0]) + resource_size(&c->io[1]) - 1; pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b); } @@ -526,28 +537,42 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev, EXPORT_SYMBOL(pcmcia_request_configuration); -/** pcmcia_request_io +/** + * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices + * + * pcmcia_request_io() attepts to reserve the IO port ranges specified in + * struct pcmcia_device *p_dev->resource[0] and *p_dev->resource[1]. The + * "start" value is the requested start of the IO port resource; "end" + * relfects the number of ports requested. * - * Request_io() reserves ranges of port addresses for a socket. - * I have not implemented range sharing or alias addressing. + * If io_req_t is passed, those values are converted automatically. */ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) { struct pcmcia_socket *s = p_dev->socket; config_t *c; int ret = -EINVAL; + unsigned int lines = req->IOAddrLines; mutex_lock(&s->ops_mutex); if (!(s->state & SOCKET_PRESENT)) { - dev_dbg(&s->dev, "No card present\n"); + dev_dbg(&s->dev, "pcmcia_request_io: No card present\n"); goto out; } - if (!req) - goto out; - c = p_dev->function_config; + if (req) { + c->io[0].start = req->BasePort1; + c->io[0].end = req->NumPorts1; + c->io[0].flags |= req->Attributes1; + c->io[1].start = req->BasePort2; + c->io[1].end = req->NumPorts2; + c->io[1].flags |= req->Attributes2; + } + + dev_dbg(&s->dev, "pcmcia_request_io: %pR , %pR", &c->io[0], &c->io[1]); + if (c->state & CONFIG_LOCKED) { dev_dbg(&s->dev, "Configuration is locked\n"); goto out; @@ -556,40 +581,30 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) dev_dbg(&s->dev, "IO already configured\n"); goto out; } - if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) { - dev_dbg(&s->dev, "bad attribute setting for IO region 1\n"); - goto out; - } - if ((req->NumPorts2 > 0) && - (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) { - dev_dbg(&s->dev, "bad attribute setting for IO region 2\n"); - goto out; - } - dev_dbg(&s->dev, "trying to allocate resource 1\n"); - ret = alloc_io_space(s, req->Attributes1, &req->BasePort1, - req->NumPorts1, req->IOAddrLines); - if (ret) { - dev_dbg(&s->dev, "allocation of resource 1 failed\n"); + ret = alloc_io_space(s, &c->io[0], lines); + if (ret) goto out; - } - if (req->NumPorts2) { - dev_dbg(&s->dev, "trying to allocate resource 2\n"); - ret = alloc_io_space(s, req->Attributes2, &req->BasePort2, - req->NumPorts2, req->IOAddrLines); + if (c->io[1].end) { + ret = alloc_io_space(s, &c->io[1], lines); if (ret) { - dev_dbg(&s->dev, "allocation of resource 2 failed\n"); - release_io_space(s, req->BasePort1, req->NumPorts1); + release_io_space(s, &c->io[0]); goto out; } - } + } else + c->io[1].start = 0; - c->io = *req; c->state |= CONFIG_IO_REQ; p_dev->_io = 1; - dev_dbg(&s->dev, "allocating resources succeeded: %d\n", ret); + if (!ret) { + req->BasePort1 = c->io[0].start; + req->BasePort2 = c->io[1].start; + } + + dev_dbg(&s->dev, "pcmcia_request_io succeeded: %pR , %pR", + &c->io[0], &c->io[1]); out: mutex_unlock(&s->ops_mutex); @@ -869,7 +884,7 @@ EXPORT_SYMBOL(pcmcia_request_window); void pcmcia_disable_device(struct pcmcia_device *p_dev) { pcmcia_release_configuration(p_dev); - pcmcia_release_io(p_dev, &p_dev->io); + pcmcia_release_io(p_dev); if (p_dev->_irq) { free_irq(p_dev->irq, p_dev->priv); p_dev->_irq = 0; -- cgit v1.1 From 90abdc3b973229bae98dd96649d9f7106cc177a4 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 24 Jul 2010 17:23:51 +0200 Subject: pcmcia: do not use io_req_t when calling pcmcia_request_io() Instead of io_req_t, drivers are now requested to fill out struct pcmcia_device *p_dev->resource[0,1] for up to two ioport ranges. After a call to pcmcia_request_io(), the ports found there are reserved, after calling pcmcia_request_configuration(), they may be used. CC: netdev@vger.kernel.org CC: linux-wireless@vger.kernel.org CC: linux-ide@vger.kernel.org CC: linux-usb@vger.kernel.org CC: laforge@gnumonks.org CC: linux-mtd@lists.infradead.org CC: alsa-devel@alsa-project.org CC: linux-serial@vger.kernel.org CC: Michael Buesch Acked-by: Marcel Holtmann (for drivers/bluetooth/) Signed-off-by: Dominik Brodowski --- drivers/pcmcia/pcmcia_resource.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index fcd48da..a48d4a9 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -70,7 +70,8 @@ static int alloc_io_space(struct pcmcia_socket *s, struct resource *res, res->flags |= IORESOURCE_IO; - dev_dbg(&s->dev, "alloc_io_space request for %pR\n", res); + dev_dbg(&s->dev, "alloc_io_space request for %pR, %d lines\n", + res, lines); align = base ? (lines ? 1<resource[0] and *p_dev->resource[1]. The + * &struct pcmcia_device @p_dev->resource[0] and @p_dev->resource[1]. The * "start" value is the requested start of the IO port resource; "end" - * relfects the number of ports requested. - * - * If io_req_t is passed, those values are converted automatically. + * reflects the number of ports requested. The number of IO lines requested + * is specified in &struct pcmcia_device @p_dev->io_lines. */ -int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) +int pcmcia_request_io(struct pcmcia_device *p_dev) { struct pcmcia_socket *s = p_dev->socket; - config_t *c; + config_t *c = p_dev->function_config; int ret = -EINVAL; - unsigned int lines = req->IOAddrLines; mutex_lock(&s->ops_mutex); + dev_dbg(&s->dev, "pcmcia_request_io: %pR , %pR", &c->io[0], &c->io[1]); if (!(s->state & SOCKET_PRESENT)) { dev_dbg(&s->dev, "pcmcia_request_io: No card present\n"); goto out; } - c = p_dev->function_config; - if (req) { - c->io[0].start = req->BasePort1; - c->io[0].end = req->NumPorts1; - c->io[0].flags |= req->Attributes1; - c->io[1].start = req->BasePort2; - c->io[1].end = req->NumPorts2; - c->io[1].flags |= req->Attributes2; - } - - dev_dbg(&s->dev, "pcmcia_request_io: %pR , %pR", &c->io[0], &c->io[1]); - if (c->state & CONFIG_LOCKED) { dev_dbg(&s->dev, "Configuration is locked\n"); goto out; @@ -582,12 +570,12 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) goto out; } - ret = alloc_io_space(s, &c->io[0], lines); + ret = alloc_io_space(s, &c->io[0], p_dev->io_lines); if (ret) goto out; if (c->io[1].end) { - ret = alloc_io_space(s, &c->io[1], lines); + ret = alloc_io_space(s, &c->io[1], p_dev->io_lines); if (ret) { release_io_space(s, &c->io[0]); goto out; @@ -598,11 +586,6 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req) c->state |= CONFIG_IO_REQ; p_dev->_io = 1; - if (!ret) { - req->BasePort1 = c->io[0].start; - req->BasePort2 = c->io[1].start; - } - dev_dbg(&s->dev, "pcmcia_request_io succeeded: %pR , %pR", &c->io[0], &c->io[1]); out: -- cgit v1.1 From a3d0d4d8dd45779b6e174a8567ffb9b485e472af Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 24 Jul 2010 17:43:10 +0200 Subject: pcmcia: move local definitions out of include/pcmcia/cs.h Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cistpl.c | 3 +++ drivers/pcmcia/cs_internal.h | 3 +++ 2 files changed, 6 insertions(+) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 1733fab..91414a0 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -53,6 +53,9 @@ static const u_int exponent[] = { /* Upper limit on reasonable # of tuples */ #define MAX_TUPLES 200 +/* Bits in IRQInfo1 field */ +#define IRQ_INFO2_VALID 0x10 + /* 16-bit CIS? */ static int cis_width; module_param(cis_width, int, 0444); diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index a85558f..511ac75 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -26,6 +26,9 @@ /* Flags in client state */ #define CLIENT_WIN_REQ(i) (0x1<<(i)) +/* Flag to access all functions */ +#define BIND_FN_ALL 0xff + /* Each card function gets one of these guys */ typedef struct config_t { struct kref ref; -- cgit v1.1 From b5cb259e7fac5536c4ddf350af6a3d6cc950e47e Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 24 Jul 2010 18:46:42 +0200 Subject: pcmcia: remove memreq_t Page already had to be set to 0; Offset can easily be passed as parameter to pcmcia_map_mem_page. CC: netdev@vger.kernel.org CC: linux-wireless@vger.kernel.org CC: linux-ide@vger.kernel.org CC: linux-usb@vger.kernel.org CC: laforge@gnumonks.org CC: linux-mtd@lists.infradead.org CC: linux-bluetooth@vger.kernel.org CC: alsa-devel@alsa-project.org CC: linux-serial@vger.kernel.org CC: Michael Buesch Signed-off-by: Dominik Brodowski --- drivers/pcmcia/pcmcia_resource.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index a48d4a9..975baaa 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -193,7 +193,7 @@ EXPORT_SYMBOL(pcmcia_write_config_byte); int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, - memreq_t *req) + unsigned int offset) { struct pcmcia_socket *s = p_dev->socket; int ret; @@ -201,12 +201,9 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, wh--; if (wh >= MAX_WIN) return -EINVAL; - if (req->Page != 0) { - dev_dbg(&s->dev, "failure: requested page is zero\n"); - return -EINVAL; - } + mutex_lock(&s->ops_mutex); - s->win[wh].card_start = req->CardOffset; + s->win[wh].card_start = offset; ret = s->ops->set_mem_map(s, &s->win[wh]); if (ret) dev_warn(&s->dev, "failed to set_mem_map\n"); -- cgit v1.1 From 0ca724d37af370dbf2d55dc4d6359ead558e5756 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sat, 24 Jul 2010 19:03:02 +0200 Subject: pcmcia: use struct resource for PCMCIA devices, part 2 Use struct resource * also for iomem resources. CC: linux-mtd@lists.infradead.org CC: netdev@vger.kernel.org CC: linux-wireless@vger.kernel.org CC: Jiri Kosina Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs_internal.h | 1 + drivers/pcmcia/ds.c | 6 ++++ drivers/pcmcia/pcmcia_resource.c | 70 ++++++++++++++++++++++------------------ 3 files changed, 45 insertions(+), 32 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 511ac75..37d38b5 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -40,6 +40,7 @@ typedef struct config_t { unsigned int CardValues; struct resource io[MAX_IO_WIN]; /* io ports */ + struct resource mem[MAX_WIN]; /* mem areas */ struct { u_int Attributes; diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 7ddd19a..0bb780c 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -556,9 +556,15 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, c->io[i].name = dev_name(&p_dev->dev); c->io[i].flags = IORESOURCE_IO; } + for (i = 0; i< MAX_WIN; i++) { + c->mem[i].name = dev_name(&p_dev->dev); + c->mem[i].flags = IORESOURCE_MEM; + } } for (i = 0; i < MAX_IO_WIN; i++) p_dev->resource[i] = &p_dev->function_config->io[i]; + for (; i < (MAX_IO_WIN + MAX_WIN); i++) + p_dev->resource[i] = &p_dev->function_config->mem[i-MAX_IO_WIN]; mutex_unlock(&s->ops_mutex); diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index 975baaa..01f8e56 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -196,15 +196,17 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, unsigned int offset) { struct pcmcia_socket *s = p_dev->socket; + struct resource *res = wh; + unsigned int w; int ret; - wh--; - if (wh >= MAX_WIN) + w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1; + if (w >= MAX_WIN) return -EINVAL; mutex_lock(&s->ops_mutex); - s->win[wh].card_start = offset; - ret = s->ops->set_mem_map(s, &s->win[wh]); + s->win[w].card_start = offset; + ret = s->ops->set_mem_map(s, &s->win[w]); if (ret) dev_warn(&s->dev, "failed to set_mem_map\n"); mutex_unlock(&s->ops_mutex); @@ -371,19 +373,22 @@ out: } /* pcmcia_release_io */ -int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh) +int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res) { struct pcmcia_socket *s = p_dev->socket; pccard_mem_map *win; + unsigned int w; - wh--; - if (wh >= MAX_WIN) + dev_dbg(&p_dev->dev, "releasing window %pR\n", res); + + w = ((res->flags & IORESOURCE_BITS & WIN_FLAGS_REQ) >> 2) - 1; + if (w >= MAX_WIN) return -EINVAL; mutex_lock(&s->ops_mutex); - win = &s->win[wh]; + win = &s->win[w]; - if (!(p_dev->_win & CLIENT_WIN_REQ(wh))) { + if (!(p_dev->_win & CLIENT_WIN_REQ(w))) { dev_dbg(&s->dev, "not releasing unknown window\n"); mutex_unlock(&s->ops_mutex); return -EINVAL; @@ -392,7 +397,7 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh) /* Shut down memory window */ win->flags &= ~MAP_ACTIVE; s->ops->set_mem_map(s, win); - s->state &= ~SOCKET_WIN_REQ(wh); + s->state &= ~SOCKET_WIN_REQ(w); /* Release system memory */ if (win->res) { @@ -400,7 +405,7 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh) kfree(win->res); win->res = NULL; } - p_dev->_win &= ~CLIENT_WIN_REQ(wh); + p_dev->_win &= ~CLIENT_WIN_REQ(w); mutex_unlock(&s->ops_mutex); return 0; @@ -775,23 +780,18 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha struct pcmcia_socket *s = p_dev->socket; pccard_mem_map *win; u_long align; + struct resource *res; int w; if (!(s->state & SOCKET_PRESENT)) { dev_dbg(&s->dev, "No card present\n"); return -ENODEV; } - if (req->Attributes & (WIN_PAGED | WIN_SHARED)) { - dev_dbg(&s->dev, "bad attribute setting for iomem region\n"); - return -EINVAL; - } /* Window size defaults to smallest available */ if (req->Size == 0) req->Size = s->map_size; - align = (((s->features & SS_CAP_MEM_ALIGN) || - (req->Attributes & WIN_STRICT_ALIGN)) ? - req->Size : s->map_size); + align = (s->features & SS_CAP_MEM_ALIGN) ? req->Size : s->map_size; if (req->Size & (s->map_size-1)) { dev_dbg(&s->dev, "invalid map size\n"); return -EINVAL; @@ -805,20 +805,21 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha align = 0; /* Allocate system memory window */ + mutex_lock(&s->ops_mutex); for (w = 0; w < MAX_WIN; w++) if (!(s->state & SOCKET_WIN_REQ(w))) break; if (w == MAX_WIN) { dev_dbg(&s->dev, "all windows are used already\n"); + mutex_unlock(&s->ops_mutex); return -EINVAL; } - mutex_lock(&s->ops_mutex); win = &s->win[w]; if (!(s->features & SS_CAP_STATIC_MAP)) { win->res = pcmcia_find_mem_region(req->Base, req->Size, align, - (req->Attributes & WIN_MAP_BELOW_1MB), s); + 0, s); if (!win->res) { dev_dbg(&s->dev, "allocating mem region failed\n"); mutex_unlock(&s->ops_mutex); @@ -829,16 +830,8 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha /* Configure the socket controller */ win->map = w+1; - win->flags = 0; + win->flags = req->Attributes; win->speed = req->AccessSpeed; - if (req->Attributes & WIN_MEMORY_TYPE) - win->flags |= MAP_ATTRIB; - if (req->Attributes & WIN_ENABLE) - win->flags |= MAP_ACTIVE; - if (req->Attributes & WIN_DATA_WIDTH_16) - win->flags |= MAP_16BIT; - if (req->Attributes & WIN_USE_WAIT) - win->flags |= MAP_USE_WAIT; win->card_start = 0; if (s->ops->set_mem_map(s, win) != 0) { @@ -854,8 +847,16 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha else req->Base = win->res->start; + /* convert to new-style resources */ + res = p_dev->resource[w + MAX_IO_WIN]; + res->start = req->Base; + res->end = req->Base + req->Size - 1; + res->flags &= ~IORESOURCE_BITS; + res->flags |= (req->Attributes & WIN_FLAGS_MAP) | (win->map << 2); + dev_dbg(&s->dev, "request_window results in %pR\n", res); + mutex_unlock(&s->ops_mutex); - *wh = w + 1; + *wh = res; return 0; } /* pcmcia_request_window */ @@ -863,13 +864,18 @@ EXPORT_SYMBOL(pcmcia_request_window); void pcmcia_disable_device(struct pcmcia_device *p_dev) { + int i; + for (i = 0; i < MAX_WIN; i++) { + struct resource *res = p_dev->resource[MAX_IO_WIN + i]; + if (res->flags & WIN_FLAGS_REQ) + pcmcia_release_window(p_dev, res); + } + pcmcia_release_configuration(p_dev); pcmcia_release_io(p_dev); if (p_dev->_irq) { free_irq(p_dev->irq, p_dev->priv); p_dev->_irq = 0; } - if (p_dev->win) - pcmcia_release_window(p_dev, p_dev->win); } EXPORT_SYMBOL(pcmcia_disable_device); -- cgit v1.1 From 8f677ea07a2a934ac74ffa57db0f5617aec15ddf Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 25 Jul 2010 11:10:29 +0200 Subject: pcmcia: export resource information to sysfs Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 0bb780c..028c973 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -1011,6 +1011,18 @@ pcmcia_device_stringattr(prod_id2, prod_id[1]); pcmcia_device_stringattr(prod_id3, prod_id[2]); pcmcia_device_stringattr(prod_id4, prod_id[3]); +static ssize_t pcmcia_show_resources(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + char *str = buf; + int i; + + for (i = 0; i < PCMCIA_NUM_RESOURCES; i++) + str += sprintf(str, "%pr\n", p_dev->resource[i]); + + return str - buf; +} static ssize_t pcmcia_show_pm_state(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1081,6 +1093,7 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, static struct device_attribute pcmcia_dev_attrs[] = { __ATTR(function, 0444, func_show, NULL), __ATTR(pm_state, 0644, pcmcia_show_pm_state, pcmcia_store_pm_state), + __ATTR(resources, 0444, pcmcia_show_resources, NULL), __ATTR_RO(func_id), __ATTR_RO(manf_id), __ATTR_RO(card_id), -- cgit v1.1 From ad0c7be28bc7593da43f494f6d074767ea96ca59 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 25 Jul 2010 13:10:22 +0200 Subject: pcmcia: insert PCMCIA device resources into resource tree Insert PCMCIA device resources into the resource tree. However, this is currently only implemented for sockets which do not statically map the resources. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs_internal.h | 3 +- drivers/pcmcia/ds.c | 4 +-- drivers/pcmcia/pcmcia_resource.c | 74 +++++++++++++++++++++++++--------------- drivers/pcmcia/rsrc_iodyn.c | 5 ++- drivers/pcmcia/rsrc_mgr.c | 3 +- drivers/pcmcia/rsrc_nonstatic.c | 5 ++- 6 files changed, 60 insertions(+), 34 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h index 37d38b5..da055dc 100644 --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -62,7 +62,8 @@ struct pccard_resource_ops { unsigned int attr, unsigned int *base, unsigned int num, - unsigned int align); + unsigned int align, + struct resource **parent); struct resource* (*find_mem) (unsigned long base, unsigned long num, unsigned long align, int low, struct pcmcia_socket *s); diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 028c973..55570d9 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -553,11 +553,11 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, p_dev->function_config = c; kref_init(&c->ref); for (i = 0; i < MAX_IO_WIN; i++) { - c->io[i].name = dev_name(&p_dev->dev); + c->io[i].name = p_dev->devname; c->io[i].flags = IORESOURCE_IO; } for (i = 0; i< MAX_WIN; i++) { - c->mem[i].name = dev_name(&p_dev->dev); + c->mem[i].name = p_dev->devname; c->mem[i].flags = IORESOURCE_MEM; } } diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index 01f8e56..d48437f 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -56,6 +56,33 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, } +static void release_io_space(struct pcmcia_socket *s, struct resource *res) +{ + resource_size_t num = resource_size(res); + int i; + + dev_dbg(&s->dev, "release_io_space for %pR\n", res); + + for (i = 0; i < MAX_IO_WIN; i++) { + if (!s->io[i].res) + continue; + if ((s->io[i].res->start <= res->start) && + (s->io[i].res->end >= res->end)) { + s->io[i].InUse -= num; + if (res->parent) + release_resource(res); + res->start = res->end = 0; + res->flags = IORESOURCE_IO; + /* Free the window if no one else is using it */ + if (s->io[i].InUse == 0) { + release_resource(s->io[i].res); + kfree(s->io[i].res); + s->io[i].res = NULL; + } + } + } +} /* release_io_space */ + /** alloc_io_space * * Special stuff for managing IO windows, because they are scarce @@ -87,43 +114,28 @@ static int alloc_io_space(struct pcmcia_socket *s, struct resource *res, align = 0; } - ret = s->resource_ops->find_io(s, res->flags, &base, num, align); + ret = s->resource_ops->find_io(s, res->flags, &base, num, align, + &res->parent); if (ret) { - dev_dbg(&s->dev, "alloc_io_space request returned %d", ret); + dev_dbg(&s->dev, "alloc_io_space request failed (%d)\n", ret); return -EINVAL; } res->start = base; res->end = res->start + num - 1; - dev_dbg(&s->dev, "alloc_io_space request returned %pR, %d\n", res, ret); - return 0; -} /* alloc_io_space */ - -static void release_io_space(struct pcmcia_socket *s, struct resource *res) -{ - resource_size_t num = resource_size(res); - int i; - - dev_dbg(&s->dev, "release_io_space for %pR\n", res); - - for (i = 0; i < MAX_IO_WIN; i++) { - if (!s->io[i].res) - continue; - if ((s->io[i].res->start <= res->start) && - (s->io[i].res->end >= res->end)) { - s->io[i].InUse -= num; - res->start = res->end = 0; - res->flags = IORESOURCE_IO; - /* Free the window if no one else is using it */ - if (s->io[i].InUse == 0) { - release_resource(s->io[i].res); - kfree(s->io[i].res); - s->io[i].res = NULL; - } + if (res->parent) { + ret = request_resource(res->parent, res); + if (ret) { + dev_warn(&s->dev, + "request_resource %pR failed: %d\n", res, ret); + res->parent = NULL; + release_io_space(s, res); } } -} /* release_io_space */ + dev_dbg(&s->dev, "alloc_io_space request result %d: %pR\n", ret, res); + return ret; +} /* alloc_io_space */ /** @@ -401,6 +413,7 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res) /* Release system memory */ if (win->res) { + release_resource(res); release_resource(win->res); kfree(win->res); win->res = NULL; @@ -853,6 +866,11 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha res->end = req->Base + req->Size - 1; res->flags &= ~IORESOURCE_BITS; res->flags |= (req->Attributes & WIN_FLAGS_MAP) | (win->map << 2); + res->flags |= IORESOURCE_MEM; + res->parent = win->res; + if (win->res) + request_resource(&iomem_resource, res); + dev_dbg(&s->dev, "request_window results in %pR\n", res); mutex_unlock(&s->ops_mutex); diff --git a/drivers/pcmcia/rsrc_iodyn.c b/drivers/pcmcia/rsrc_iodyn.c index 3b1dce2..8510c35 100644 --- a/drivers/pcmcia/rsrc_iodyn.c +++ b/drivers/pcmcia/rsrc_iodyn.c @@ -87,7 +87,7 @@ static struct resource *__iodyn_find_io_region(struct pcmcia_socket *s, static int iodyn_find_io(struct pcmcia_socket *s, unsigned int attr, unsigned int *base, unsigned int num, - unsigned int align) + unsigned int align, struct resource **parent) { int i, ret = 0; @@ -128,6 +128,7 @@ static int iodyn_find_io(struct pcmcia_socket *s, unsigned int attr, ((res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS)); s->io[i].InUse = num; + *parent = res; return 0; } @@ -139,6 +140,7 @@ static int iodyn_find_io(struct pcmcia_socket *s, unsigned int attr, continue; *base = try; s->io[i].InUse += num; + *parent = res; return 0; } @@ -151,6 +153,7 @@ static int iodyn_find_io(struct pcmcia_socket *s, unsigned int attr, continue; *base = try; s->io[i].InUse += num; + *parent = res; return 0; } } diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c index b433a79..4e80421 100644 --- a/drivers/pcmcia/rsrc_mgr.c +++ b/drivers/pcmcia/rsrc_mgr.c @@ -47,11 +47,12 @@ struct resource *pcmcia_make_resource(unsigned long start, unsigned long end, static int static_find_io(struct pcmcia_socket *s, unsigned int attr, unsigned int *base, unsigned int num, - unsigned int align) + unsigned int align, struct resource **parent) { if (!s->io_offset) return -EINVAL; *base = s->io_offset | (*base & 0x0fff); + *parent = NULL; return 0; } diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index c17a17d..96f348b 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -718,7 +718,7 @@ static struct resource *__nonstatic_find_io_region(struct pcmcia_socket *s, static int nonstatic_find_io(struct pcmcia_socket *s, unsigned int attr, unsigned int *base, unsigned int num, - unsigned int align) + unsigned int align, struct resource **parent) { int i, ret = 0; @@ -760,6 +760,7 @@ static int nonstatic_find_io(struct pcmcia_socket *s, unsigned int attr, ((res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS)); s->io[i].InUse = num; + *parent = res; return 0; } @@ -775,6 +776,7 @@ static int nonstatic_find_io(struct pcmcia_socket *s, unsigned int attr, continue; *base = try; s->io[i].InUse += num; + *parent = res; return 0; } } @@ -793,6 +795,7 @@ static int nonstatic_find_io(struct pcmcia_socket *s, unsigned int attr, continue; *base = try; s->io[i].InUse += num; + *parent = res; return 0; } } -- cgit v1.1 From 127c03cdbad9bd5af5d7f33bd31a1015a90cb77f Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Tue, 3 Aug 2010 09:33:45 +0200 Subject: pcmcia: avoid buffer overflow in pcmcia_setup_isa_irq NR_IRQS may be as low as 16, causing a (harmless?) buffer overflow in pcmcia_setup_isa_irq(): static u8 pcmcia_used_irq[NR_IRQS]; ... if ((try < 32) && pcmcia_used_irq[irq]) continue; This is read-only, so if this address would be non-zero, it would just mean we would not attempt an IRQ >= NR_IRQS -- which would fail anyway! And as request_irq() fails for an irq >= NR_IRQS, the setting code path: pcmcia_used_irq[irq]++; is never reached as well. Reported-by: Christoph Fritz CC: stable@kernel.org Signed-off-by: Dominik Brodowski Signed-off-by: Christoph Fritz --- drivers/pcmcia/pcmcia_resource.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index d48437f..54aa1c2 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -677,7 +677,7 @@ EXPORT_SYMBOL(__pcmcia_request_exclusive_irq); #ifdef CONFIG_PCMCIA_PROBE /* mask of IRQs already reserved by other cards, we should avoid using them */ -static u8 pcmcia_used_irq[NR_IRQS]; +static u8 pcmcia_used_irq[32]; static irqreturn_t test_action(int cpl, void *dev_id) { @@ -700,6 +700,9 @@ static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type) for (try = 0; try < 64; try++) { irq = try % 32; + if (irq > NR_IRQS) + continue; + /* marked as available by driver, not blocked by userspace? */ if (!((mask >> irq) & 1)) continue; -- cgit v1.1