diff options
Diffstat (limited to 'drivers/pcmcia/cs.c')
| -rw-r--r-- | drivers/pcmcia/cs.c | 417 |
1 files changed, 101 insertions, 316 deletions
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index 4e4c964f7e01..edfc17a30687 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -1,35 +1,16 @@ -/*====================================================================== - - Kernel Card Services -- core services - - cs.c 1.271 2000/10/02 20:27:49 - - The contents of this file are subject to the Mozilla Public - License Version 1.1 (the "License"); you may not use this file - except in compliance with the License. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - Software distributed under the License is distributed on an "AS - IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - implied. See the License for the specific language governing - rights and limitations under the License. - - The initial developer of the original code is David A. Hinds - <dahinds@users.sourceforge.net>. Portions created by David A. Hinds - are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - - Alternatively, the contents of this file may be used under the - terms of the GNU General Public License version 2 (the "GPL"), in which - case the provisions of the GPL are applicable instead of the - above. If you wish to allow the use of your version of this file - only under the terms of the GPL and not to allow others to use - your version of this file under the MPL, indicate your decision - by deleting the provisions above and replace them with the notice - and other provisions required by the GPL. If you do not delete - the provisions above, a recipient may use your version of this - file under either the MPL or the GPL. - -======================================================================*/ +/* + * cs.c -- Kernel Card Services - core services + * + * 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 + * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds + * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. + * + * (C) 1999 David A. Hinds + */ #include <linux/module.h> #include <linux/moduleparam.h> @@ -60,6 +41,7 @@ #include <pcmcia/bulkmem.h> #include <pcmcia/cistpl.h> #include <pcmcia/cisreg.h> +#include <pcmcia/ds.h> #include "cs_internal.h" #ifdef CONFIG_PCI @@ -92,7 +74,7 @@ static const char *options = "options: " OPTIONS; MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); MODULE_DESCRIPTION("Linux Kernel Card Services\noptions:" OPTIONS); -MODULE_LICENSE("Dual MPL/GPL"); +MODULE_LICENSE("GPL"); #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444) @@ -132,6 +114,8 @@ socket_state_t dead_socket = { /* List of all sockets, protected by a rwsem */ LIST_HEAD(pcmcia_socket_list); DECLARE_RWSEM(pcmcia_socket_list_rwsem); +EXPORT_SYMBOL(pcmcia_socket_list); +EXPORT_SYMBOL(pcmcia_socket_list_rwsem); /*==================================================================== @@ -189,16 +173,32 @@ int pcmcia_socket_dev_resume(struct device *dev) EXPORT_SYMBOL(pcmcia_socket_dev_resume); +struct pcmcia_socket * pcmcia_get_socket(struct pcmcia_socket *skt) +{ + struct class_device *cl_dev = class_device_get(&skt->dev); + if (!cl_dev) + return NULL; + skt = class_get_devdata(cl_dev); + if (!try_module_get(skt->owner)) { + class_device_put(&skt->dev); + return NULL; + } + return (skt); +} +EXPORT_SYMBOL(pcmcia_get_socket); + + +void pcmcia_put_socket(struct pcmcia_socket *skt) +{ + module_put(skt->owner); + class_device_put(&skt->dev); +} +EXPORT_SYMBOL(pcmcia_put_socket); + + static void pcmcia_release_socket(struct class_device *class_dev) { struct pcmcia_socket *socket = class_get_devdata(class_dev); - client_t *client; - - while (socket->clients) { - client = socket->clients; - socket->clients = socket->clients->next; - kfree(client); - } complete(&socket->socket_released); } @@ -212,11 +212,17 @@ int pcmcia_register_socket(struct pcmcia_socket *socket) { int ret; - if (!socket || !socket->ops || !socket->dev.dev) + if (!socket || !socket->ops || !socket->dev.dev || !socket->resource_ops) return -EINVAL; cs_dbg(socket, 0, "pcmcia_register_socket(0x%p)\n", socket->ops); + if (socket->resource_ops->init) { + ret = socket->resource_ops->init(socket); + if (ret) + return (ret); + } + /* try to obtain a socket number [yes, it gets ugly if we * register more than 2^sizeof(unsigned int) pcmcia * sockets... but the socket number is deprecated @@ -305,6 +311,7 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket) up_write(&pcmcia_socket_list_rwsem); /* wait for sysfs to drop all references */ + release_resource_db(socket); wait_for_completion(&socket->socket_released); } /* pcmcia_unregister_socket */ EXPORT_SYMBOL(pcmcia_unregister_socket); @@ -349,12 +356,8 @@ static void free_regions(memory_handle_t *list) } } -static int send_event(struct pcmcia_socket *s, event_t event, int priority); - static void shutdown_socket(struct pcmcia_socket *s) { - client_t **c; - cs_dbg(s, 1, "shutdown_socket\n"); /* Blank out the socket state */ @@ -372,15 +375,6 @@ static void shutdown_socket(struct pcmcia_socket *s) kfree(s->config); s->config = NULL; } - for (c = &s->clients; *c; ) { - if ((*c)->state & CLIENT_UNBOUND) { - client_t *d = *c; - *c = (*c)->next; - kfree(d); - } else { - c = &((*c)->next); - } - } free_regions(&s->a_region); free_regions(&s->c_region); @@ -395,45 +389,44 @@ static void shutdown_socket(struct pcmcia_socket *s) /*====================================================================== - The central event handler. Send_event() sends an event to all - valid clients. Parse_events() interprets the event bits from + 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) { - client_t *client = s->clients; - int ret; - cs_dbg(s, 1, "send_event(event %d, pri %d)\n", - event, priority); - ret = 0; - if (s->state & SOCKET_CARDBUS) - return 0; - for (; client; client = client->next) { - if (client->state & (CLIENT_UNBOUND|CLIENT_STALE)) - continue; - if (client->EventMask & event) { - ret = EVENT(client, event, priority); - if (ret != 0) - return ret; - } - } - return ret; -} /* send_event */ + int ret; + + if (s->state & SOCKET_CARDBUS) + return 0; + + cs_dbg(s, 1, "send_event(event %d, pri %d, callback 0x%p)\n", + event, priority, s->callback); + + 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; +} static void socket_remove_drivers(struct pcmcia_socket *skt) { - client_t *client; - cs_dbg(skt, 4, "remove_drivers\n"); send_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH); - - for (client = skt->clients; client; client = client->next) - if (!(client->Attributes & INFO_MASTER_CLIENT)) - client->state |= CLIENT_STALE; } static void socket_shutdown(struct pcmcia_socket *skt) @@ -756,7 +749,7 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events) ======================================================================*/ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base, - ioaddr_t num, u_int lines, char *name) + ioaddr_t num, u_int lines) { int i; ioaddr_t try, align; @@ -788,7 +781,7 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base, return 1; for (i = 0; i < MAX_IO_WIN; i++) { if (s->io[i].NumPorts == 0) { - s->io[i].res = find_io_region(*base, num, align, name, s); + s->io[i].res = find_io_region(*base, num, align, s); if (s->io[i].res) { s->io[i].Attributes = attr; s->io[i].BasePort = *base = s->io[i].res->start; @@ -888,49 +881,6 @@ int pccard_access_configuration_register(struct pcmcia_socket *s, } /* access_configuration_register */ EXPORT_SYMBOL(pccard_access_configuration_register); -/*====================================================================*/ - -int pcmcia_deregister_client(client_handle_t handle) -{ - client_t **client; - struct pcmcia_socket *s; - u_long flags; - int i; - - if (CHECK_HANDLE(handle)) - return CS_BAD_HANDLE; - - s = SOCKET(handle); - cs_dbg(s, 1, "deregister_client(%p)\n", handle); - - if (handle->state & - (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED)) - return CS_IN_USE; - for (i = 0; i < MAX_WIN; i++) - if (handle->state & CLIENT_WIN_REQ(i)) - return CS_IN_USE; - - if ((handle->state & CLIENT_STALE) || - (handle->Attributes & INFO_MASTER_CLIENT)) { - spin_lock_irqsave(&s->lock, flags); - client = &s->clients; - while ((*client) && ((*client) != handle)) - client = &(*client)->next; - if (*client == NULL) { - spin_unlock_irqrestore(&s->lock, flags); - return CS_BAD_HANDLE; - } - *client = handle->next; - handle->client_magic = 0; - kfree(handle); - spin_unlock_irqrestore(&s->lock, flags); - } else { - handle->state = CLIENT_UNBOUND; - handle->event_handler = NULL; - } - - return CS_SUCCESS; -} /* deregister_client */ /*====================================================================*/ @@ -1014,53 +964,6 @@ int pcmcia_get_card_services_info(servinfo_t *info) return CS_SUCCESS; } /* get_card_services_info */ -#ifdef CONFIG_PCMCIA_OBSOLETE - -/*====================================================================== - - Note that get_first_client() *does* recognize the Socket field - in the request structure. - -======================================================================*/ - -int pcmcia_get_first_client(client_handle_t *handle, client_req_t *req) -{ - socket_t s; - struct pcmcia_socket *socket; - if (req->Attributes & CLIENT_THIS_SOCKET) - s = req->Socket; - else - s = 0; - socket = pcmcia_get_socket_by_nr(s); - if (!socket) - return CS_BAD_SOCKET; - if (socket->clients == NULL) - return CS_NO_MORE_ITEMS; - *handle = socket->clients; - return CS_SUCCESS; -} /* get_first_client */ -EXPORT_SYMBOL(pcmcia_get_first_client); - -/*====================================================================*/ - -int pcmcia_get_next_client(client_handle_t *handle, client_req_t *req) -{ - struct pcmcia_socket *s; - if ((handle == NULL) || CHECK_HANDLE(*handle)) - return CS_BAD_HANDLE; - if ((*handle)->next == NULL) { - if (req->Attributes & CLIENT_THIS_SOCKET) - return CS_NO_MORE_ITEMS; - s = (*handle)->Socket; - if (s->clients == NULL) - return CS_NO_MORE_ITEMS; - *handle = s->clients; - } else - *handle = (*handle)->next; - return CS_SUCCESS; -} /* get_next_client */ -EXPORT_SYMBOL(pcmcia_get_next_client); -#endif /* CONFIG_PCMCIA_OBSOLETE */ /*====================================================================*/ @@ -1251,117 +1154,33 @@ int pcmcia_modify_configuration(client_handle_t handle, return CS_SUCCESS; } /* modify_configuration */ -#ifdef CONFIG_PCMCIA_OBSOLETE - -/*====================================================================== - - Modify the attributes of a window returned by RequestWindow. - -======================================================================*/ - -int pcmcia_modify_window(window_handle_t win, modwin_t *req) +/* register pcmcia_callback */ +int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) { - if ((win == NULL) || (win->magic != WINDOW_MAGIC)) - return CS_BAD_HANDLE; - - win->ctl.flags &= ~(MAP_ATTRIB|MAP_ACTIVE); - if (req->Attributes & WIN_MEMORY_TYPE) - win->ctl.flags |= MAP_ATTRIB; - if (req->Attributes & WIN_ENABLE) - win->ctl.flags |= MAP_ACTIVE; - if (req->Attributes & WIN_DATA_WIDTH_16) - win->ctl.flags |= MAP_16BIT; - if (req->Attributes & WIN_USE_WAIT) - win->ctl.flags |= MAP_USE_WAIT; - win->ctl.speed = req->AccessSpeed; - win->sock->ops->set_mem_map(win->sock, &win->ctl); - - return CS_SUCCESS; -} /* modify_window */ -EXPORT_SYMBOL(pcmcia_modify_window); - -#endif /* CONFIG_PCMCIA_OBSOLETE */ - + int ret = 0; -/*====================================================================== + /* s->skt_sem also protects s->callback */ + down(&s->skt_sem); - 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. - -======================================================================*/ - -int pcmcia_register_client(client_handle_t *handle, client_reg_t *req) -{ - client_t *client = NULL; - struct pcmcia_socket *s; - - /* Look for unbound client with matching dev_info */ - down_read(&pcmcia_socket_list_rwsem); - list_for_each_entry(s, &pcmcia_socket_list, socket_list) { - client = s->clients; - while (client != NULL) { - if ((strcmp(client->dev_info, (char *)req->dev_info) == 0) - && (client->state & CLIENT_UNBOUND)) break; - client = client->next; - } - if (client != NULL) break; - } - up_read(&pcmcia_socket_list_rwsem); - if (client == NULL) - return CS_OUT_OF_RESOURCE; + if (c) { + /* registration */ + if (s->callback) { + ret = -EBUSY; + goto err; + } - /* - * Prevent this racing with a card insertion. - */ - down(&s->skt_sem); - *handle = client; - client->state &= ~CLIENT_UNBOUND; - client->Socket = s; - client->Attributes = req->Attributes; - client->EventMask = req->EventMask; - client->event_handler = req->event_handler; - client->event_callback_args = req->event_callback_args; - client->event_callback_args.client_handle = client; - - if (s->state & SOCKET_CARDBUS) - client->state |= CLIENT_CARDBUS; - - if ((!(s->state & SOCKET_CARDBUS)) && (s->functions == 0) && - (client->Function != BIND_FN_ALL)) { - cistpl_longlink_mfc_t mfc; - if (pccard_read_tuple(s, client->Function, CISTPL_LONGLINK_MFC, &mfc) - == CS_SUCCESS) - s->functions = mfc.nfn; - else - s->functions = 1; - s->config = kmalloc(sizeof(config_t) * s->functions, - GFP_KERNEL); - if (!s->config) - goto out_no_resource; - memset(s->config, 0, sizeof(config_t) * s->functions); - } - - cs_dbg(s, 1, "register_client(): client 0x%p, dev %s\n", - client, client->dev_info); - if (client->EventMask & CS_EVENT_REGISTRATION_COMPLETE) - EVENT(client, CS_EVENT_REGISTRATION_COMPLETE, CS_EVENT_PRI_LOW); - - if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) { - if (client->EventMask & CS_EVENT_CARD_INSERTION) - EVENT(client, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); - else - client->PendingEvents |= CS_EVENT_CARD_INSERTION; - } + s->callback = c; - up(&s->skt_sem); - return CS_SUCCESS; + if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) + send_event(s, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); + } else + s->callback = NULL; + err: + up(&s->skt_sem); - out_no_resource: - up(&s->skt_sem); - return CS_OUT_OF_RESOURCE; -} /* register_client */ + return ret; +} +EXPORT_SYMBOL(pccard_register_pcmcia); /*====================================================================*/ @@ -1685,14 +1504,12 @@ int pcmcia_request_io(client_handle_t handle, io_req_t *req) return CS_BAD_ATTRIBUTE; if (alloc_io_space(s, req->Attributes1, &req->BasePort1, - req->NumPorts1, req->IOAddrLines, - handle->dev_info)) + req->NumPorts1, req->IOAddrLines)) return CS_IN_USE; if (req->NumPorts2) { if (alloc_io_space(s, req->Attributes2, &req->BasePort2, - req->NumPorts2, req->IOAddrLines, - handle->dev_info)) { + req->NumPorts2, req->IOAddrLines)) { release_io_space(s, req->BasePort1, req->NumPorts1); return CS_IN_USE; } @@ -1720,6 +1537,7 @@ int pcmcia_request_irq(client_handle_t handle, irq_req_t *req) struct pcmcia_socket *s; config_t *c; int ret = CS_IN_USE, irq = 0; + struct pcmcia_device *p_dev = handle_to_pdev(handle); if (CHECK_HANDLE(handle)) return CS_BAD_HANDLE; @@ -1769,7 +1587,7 @@ int pcmcia_request_irq(client_handle_t handle, irq_req_t *req) ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) || (s->functions > 1) || (irq == s->pci_irq)) ? SA_SHIRQ : 0, - handle->dev_info, req->Instance)) + p_dev->dev.bus_id, req->Instance)) return CS_IN_USE; } @@ -1832,8 +1650,7 @@ int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle if (!(s->features & SS_CAP_STATIC_MAP)) { win->ctl.res = find_mem_region(req->Base, req->Size, align, - (req->Attributes & WIN_MAP_BELOW_1MB), - (*handle)->dev_info, s); + (req->Attributes & WIN_MAP_BELOW_1MB), s); if (!win->ctl.res) return CS_IN_USE; } @@ -2022,47 +1839,16 @@ int pcmcia_insert_card(struct pcmcia_socket *skt) /*====================================================================== - Maybe this should send a CS_EVENT_CARD_INSERTION event if we - haven't sent one to this client yet? - -======================================================================*/ - -#ifdef CONFIG_PCMCIA_OBSOLETE -int pcmcia_set_event_mask(client_handle_t handle, eventmask_t *mask) -{ - u_int events, bit; - if (CHECK_HANDLE(handle)) - return CS_BAD_HANDLE; - if (handle->Attributes & CONF_EVENT_MASK_VALID) - return CS_BAD_SOCKET; - handle->EventMask = mask->EventMask; - events = handle->PendingEvents & handle->EventMask; - handle->PendingEvents -= events; - while (events != 0) { - bit = ((events ^ (events-1)) + 1) >> 1; - EVENT(handle, bit, CS_EVENT_PRI_LOW); - events -= bit; - } - return CS_SUCCESS; -} /* set_event_mask */ -EXPORT_SYMBOL(pcmcia_set_event_mask); - -#endif /* CONFIG_PCMCIA_OBSOLETE */ - -/*====================================================================== - OS-specific module glue goes here ======================================================================*/ /* in alpha order */ -EXPORT_SYMBOL(pcmcia_deregister_client); EXPORT_SYMBOL(pcmcia_eject_card); EXPORT_SYMBOL(pcmcia_get_card_services_info); EXPORT_SYMBOL(pcmcia_get_mem_page); EXPORT_SYMBOL(pcmcia_insert_card); EXPORT_SYMBOL(pcmcia_map_mem_page); EXPORT_SYMBOL(pcmcia_modify_configuration); -EXPORT_SYMBOL(pcmcia_register_client); EXPORT_SYMBOL(pcmcia_release_configuration); EXPORT_SYMBOL(pcmcia_release_io); EXPORT_SYMBOL(pcmcia_release_irq); @@ -2100,7 +1886,6 @@ static int __init init_pcmcia_cs(void) static void __exit exit_pcmcia_cs(void) { printk(KERN_INFO "unloading Kernel Card Services\n"); - release_resource_db(); class_interface_unregister(&pccard_sysfs_interface); class_unregister(&pcmcia_socket_class); } |
