X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fpcmcia%2Fcistpl.c;h=e29a6ddf2fd7e18af9b2c58cfeca312d1b67cec3;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=317ca50a3db3b86e9729820237916cfe6fd3f4cd;hpb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;p=linux-2.6.git diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 317ca50a3..e29a6ddf2 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c @@ -1,35 +1,16 @@ -/*====================================================================== - - PCMCIA Card Information Structure parser - - cistpl.c 1.99 2002/10/24 06:11:48 - - 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 - . 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. - -======================================================================*/ +/* + * cistpl.c -- 16-bit PCMCIA Card Information Structure parser + * + * 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 + */ #include #include @@ -97,6 +78,7 @@ void release_cis_mem(struct pcmcia_socket *s) s->cis_virt = NULL; } } +EXPORT_SYMBOL(release_cis_mem); /* * Map the card memory at "card_offset" into virtual space. @@ -108,8 +90,7 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag { pccard_mem_map *mem = &s->cis_mem; if (!(s->features & SS_CAP_STATIC_MAP) && mem->res == NULL) { - mem->res = find_mem_region(0, s->map_size, s->map_size, 0, - "card services", s); + mem->res = find_mem_region(0, s->map_size, s->map_size, 0, s); if (mem->res == NULL) { printk(KERN_NOTICE "cs: unable to map card memory!\n"); return NULL; @@ -331,7 +312,16 @@ void destroy_cis_cache(struct pcmcia_socket *s) list_del(&cis->node); kfree(cis); } + + /* + * If there was a fake CIS, destroy that as well. + */ + if (s->fake_cis) { + kfree(s->fake_cis); + s->fake_cis = NULL; + } } +EXPORT_SYMBOL(destroy_cis_cache); /*====================================================================== @@ -376,12 +366,8 @@ int verify_cis_cache(struct pcmcia_socket *s) ======================================================================*/ -int pcmcia_replace_cis(client_handle_t handle, cisdump_t *cis) +int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis) { - struct pcmcia_socket *s; - if (CHECK_HANDLE(handle)) - return CS_BAD_HANDLE; - s = SOCKET(handle); if (s->fake_cis != NULL) { kfree(s->fake_cis); s->fake_cis = NULL; @@ -414,14 +400,12 @@ typedef struct tuple_flags { #define MFC_FN(f) (((tuple_flags *)(&(f)))->mfc_fn) #define SPACE(f) (((tuple_flags *)(&(f)))->space) -int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple); +int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *tuple); -int pcmcia_get_first_tuple(client_handle_t handle, tuple_t *tuple) +int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple) { - struct pcmcia_socket *s; - if (CHECK_HANDLE(handle)) + if (!s) return CS_BAD_HANDLE; - s = SOCKET(handle); if (!(s->state & SOCKET_PRESENT)) return CS_NO_CARD; tuple->TupleLink = tuple->Flags = 0; @@ -443,16 +427,17 @@ int pcmcia_get_first_tuple(client_handle_t handle, tuple_t *tuple) !(tuple->Attributes & TUPLE_RETURN_COMMON)) { cisdata_t req = tuple->DesiredTuple; tuple->DesiredTuple = CISTPL_LONGLINK_MFC; - if (pcmcia_get_next_tuple(handle, tuple) == CS_SUCCESS) { + if (pccard_get_next_tuple(s, function, tuple) == CS_SUCCESS) { tuple->DesiredTuple = CISTPL_LINKTARGET; - if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) + if (pccard_get_next_tuple(s, function, tuple) != CS_SUCCESS) return CS_NO_MORE_ITEMS; } else tuple->CISOffset = tuple->TupleLink = 0; tuple->DesiredTuple = req; } - return pcmcia_get_next_tuple(handle, tuple); + return pccard_get_next_tuple(s, function, tuple); } +EXPORT_SYMBOL(pccard_get_first_tuple); static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) { @@ -494,15 +479,13 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) return -1; } -int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple) +int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple) { - struct pcmcia_socket *s; u_char link[2], tmp; int ofs, i, attr; - - if (CHECK_HANDLE(handle)) + + if (!s) return CS_BAD_HANDLE; - s = SOCKET(handle); if (!(s->state & SOCKET_PRESENT)) return CS_NO_CARD; @@ -554,14 +537,14 @@ int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple) case CISTPL_LONGLINK_MFC: tuple->LinkOffset = ofs + 3; LINK_SPACE(tuple->Flags) = attr; - if (handle->Function == BIND_FN_ALL) { + if (function == BIND_FN_ALL) { /* Follow all the MFC links */ read_cis_cache(s, attr, ofs+2, 1, &tmp); MFC_FN(tuple->Flags) = tmp; } else { /* Follow exactly one of the links */ MFC_FN(tuple->Flags) = 1; - tuple->LinkOffset += handle->Function * 5; + tuple->LinkOffset += function * 5; } break; case CISTPL_NO_LINK: @@ -589,20 +572,18 @@ int pcmcia_get_next_tuple(client_handle_t handle, tuple_t *tuple) tuple->CISOffset = ofs + 2; return CS_SUCCESS; } +EXPORT_SYMBOL(pccard_get_next_tuple); /*====================================================================*/ #define _MIN(a, b) (((a) < (b)) ? (a) : (b)) -int pcmcia_get_tuple_data(client_handle_t handle, tuple_t *tuple) +int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) { - struct pcmcia_socket *s; u_int len; - - if (CHECK_HANDLE(handle)) - return CS_BAD_HANDLE; - s = SOCKET(handle); + if (!s) + return CS_BAD_HANDLE; if (tuple->TupleLink < tuple->TupleOffset) return CS_NO_MORE_ITEMS; @@ -615,6 +596,8 @@ int pcmcia_get_tuple_data(client_handle_t handle, tuple_t *tuple) _MIN(len, tuple->TupleDataMax), tuple->TupleData); return CS_SUCCESS; } +EXPORT_SYMBOL(pccard_get_tuple_data); + /*====================================================================== @@ -1320,7 +1303,7 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt) /*====================================================================*/ -int pcmcia_parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) +int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse) { int ret = CS_SUCCESS; @@ -1401,6 +1384,7 @@ int pcmcia_parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse } return ret; } +EXPORT_SYMBOL(pccard_parse_tuple); /*====================================================================== @@ -1408,7 +1392,7 @@ int pcmcia_parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse ======================================================================*/ -int read_tuple(client_handle_t handle, cisdata_t code, void *parse) +int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse) { tuple_t tuple; cisdata_t *buf; @@ -1419,18 +1403,19 @@ int read_tuple(client_handle_t handle, cisdata_t code, void *parse) return CS_OUT_OF_RESOURCE; tuple.DesiredTuple = code; tuple.Attributes = TUPLE_RETURN_COMMON; - ret = pcmcia_get_first_tuple(handle, &tuple); + ret = pccard_get_first_tuple(s, function, &tuple); if (ret != CS_SUCCESS) goto done; tuple.TupleData = buf; tuple.TupleOffset = 0; tuple.TupleDataMax = 255; - ret = pcmcia_get_tuple_data(handle, &tuple); + ret = pccard_get_tuple_data(s, &tuple); if (ret != CS_SUCCESS) goto done; - ret = pcmcia_parse_tuple(handle, &tuple, parse); + ret = pccard_parse_tuple(&tuple, parse); done: kfree(buf); return ret; } +EXPORT_SYMBOL(pccard_read_tuple); /*====================================================================== @@ -1442,14 +1427,15 @@ done: ======================================================================*/ -int pcmcia_validate_cis(client_handle_t handle, cisinfo_t *info) +int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, cisinfo_t *info) { tuple_t *tuple; cisparse_t *p; int ret, reserved, dev_ok = 0, ident_ok = 0; - if (CHECK_HANDLE(handle)) + if (!s) return CS_BAD_HANDLE; + tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); if (tuple == NULL) return CS_OUT_OF_RESOURCE; @@ -1462,30 +1448,30 @@ int pcmcia_validate_cis(client_handle_t handle, cisinfo_t *info) info->Chains = reserved = 0; tuple->DesiredTuple = RETURN_FIRST_TUPLE; tuple->Attributes = TUPLE_RETURN_COMMON; - ret = pcmcia_get_first_tuple(handle, tuple); + ret = pccard_get_first_tuple(s, function, tuple); if (ret != CS_SUCCESS) goto done; /* First tuple should be DEVICE; we should really have either that or a CFTABLE_ENTRY of some sort */ if ((tuple->TupleCode == CISTPL_DEVICE) || - (read_tuple(handle, CISTPL_CFTABLE_ENTRY, p) == CS_SUCCESS) || - (read_tuple(handle, CISTPL_CFTABLE_ENTRY_CB, p) == CS_SUCCESS)) + (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY, p) == CS_SUCCESS) || + (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY_CB, p) == CS_SUCCESS)) dev_ok++; /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 tuple, for card identification. Certain old D-Link and Linksys cards have only a broken VERS_2 tuple; hence the bogus test. */ - if ((read_tuple(handle, CISTPL_MANFID, p) == CS_SUCCESS) || - (read_tuple(handle, CISTPL_VERS_1, p) == CS_SUCCESS) || - (read_tuple(handle, CISTPL_VERS_2, p) != CS_NO_MORE_ITEMS)) + if ((pccard_read_tuple(s, function, CISTPL_MANFID, p) == CS_SUCCESS) || + (pccard_read_tuple(s, function, CISTPL_VERS_1, p) == CS_SUCCESS) || + (pccard_read_tuple(s, function, CISTPL_VERS_2, p) != CS_NO_MORE_ITEMS)) ident_ok++; if (!dev_ok && !ident_ok) goto done; for (info->Chains = 1; info->Chains < MAX_TUPLES; info->Chains++) { - ret = pcmcia_get_next_tuple(handle, tuple); + ret = pccard_get_next_tuple(s, function, tuple); if (ret != CS_SUCCESS) break; if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || @@ -1501,4 +1487,4 @@ done: kfree(p); return CS_SUCCESS; } - +EXPORT_SYMBOL(pccard_validate_cis);