ds.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /*
  2. * ds.c -- 16-bit PCMCIA core support
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * The initial developer of the original code is David A. Hinds
  9. * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  10. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  11. *
  12. * (C) 1999 David A. Hinds
  13. * (C) 2003 - 2004 Dominik Brodowski
  14. */
  15. #include <linux/config.h>
  16. #include <linux/module.h>
  17. #include <linux/moduleparam.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/major.h>
  21. #include <linux/string.h>
  22. #include <linux/errno.h>
  23. #include <linux/slab.h>
  24. #include <linux/mm.h>
  25. #include <linux/fcntl.h>
  26. #include <linux/sched.h>
  27. #include <linux/smp_lock.h>
  28. #include <linux/timer.h>
  29. #include <linux/ioctl.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/poll.h>
  32. #include <linux/pci.h>
  33. #include <linux/list.h>
  34. #include <linux/delay.h>
  35. #include <linux/kref.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/crc32.h>
  38. #include <linux/firmware.h>
  39. #include <asm/atomic.h>
  40. #define IN_CARD_SERVICES
  41. #include <pcmcia/version.h>
  42. #include <pcmcia/cs_types.h>
  43. #include <pcmcia/cs.h>
  44. #include <pcmcia/bulkmem.h>
  45. #include <pcmcia/cistpl.h>
  46. #include <pcmcia/ds.h>
  47. #include <pcmcia/ss.h>
  48. #include "cs_internal.h"
  49. #include "ds_internal.h"
  50. /*====================================================================*/
  51. /* Module parameters */
  52. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  53. MODULE_DESCRIPTION("PCMCIA Driver Services");
  54. MODULE_LICENSE("GPL");
  55. #ifdef DEBUG
  56. int ds_pc_debug;
  57. module_param_named(pc_debug, ds_pc_debug, int, 0644);
  58. #define ds_dbg(lvl, fmt, arg...) do { \
  59. if (ds_pc_debug > (lvl)) \
  60. printk(KERN_DEBUG "ds: " fmt , ## arg); \
  61. } while (0)
  62. #else
  63. #define ds_dbg(lvl, fmt, arg...) do { } while (0)
  64. #endif
  65. spinlock_t pcmcia_dev_list_lock;
  66. static int unbind_request(struct pcmcia_bus_socket *s);
  67. /*====================================================================*/
  68. /* code which was in cs.c before */
  69. /* String tables for error messages */
  70. typedef struct lookup_t {
  71. int key;
  72. char *msg;
  73. } lookup_t;
  74. static const lookup_t error_table[] = {
  75. { CS_SUCCESS, "Operation succeeded" },
  76. { CS_BAD_ADAPTER, "Bad adapter" },
  77. { CS_BAD_ATTRIBUTE, "Bad attribute", },
  78. { CS_BAD_BASE, "Bad base address" },
  79. { CS_BAD_EDC, "Bad EDC" },
  80. { CS_BAD_IRQ, "Bad IRQ" },
  81. { CS_BAD_OFFSET, "Bad offset" },
  82. { CS_BAD_PAGE, "Bad page number" },
  83. { CS_READ_FAILURE, "Read failure" },
  84. { CS_BAD_SIZE, "Bad size" },
  85. { CS_BAD_SOCKET, "Bad socket" },
  86. { CS_BAD_TYPE, "Bad type" },
  87. { CS_BAD_VCC, "Bad Vcc" },
  88. { CS_BAD_VPP, "Bad Vpp" },
  89. { CS_BAD_WINDOW, "Bad window" },
  90. { CS_WRITE_FAILURE, "Write failure" },
  91. { CS_NO_CARD, "No card present" },
  92. { CS_UNSUPPORTED_FUNCTION, "Usupported function" },
  93. { CS_UNSUPPORTED_MODE, "Unsupported mode" },
  94. { CS_BAD_SPEED, "Bad speed" },
  95. { CS_BUSY, "Resource busy" },
  96. { CS_GENERAL_FAILURE, "General failure" },
  97. { CS_WRITE_PROTECTED, "Write protected" },
  98. { CS_BAD_ARG_LENGTH, "Bad argument length" },
  99. { CS_BAD_ARGS, "Bad arguments" },
  100. { CS_CONFIGURATION_LOCKED, "Configuration locked" },
  101. { CS_IN_USE, "Resource in use" },
  102. { CS_NO_MORE_ITEMS, "No more items" },
  103. { CS_OUT_OF_RESOURCE, "Out of resource" },
  104. { CS_BAD_HANDLE, "Bad handle" },
  105. { CS_BAD_TUPLE, "Bad CIS tuple" }
  106. };
  107. static const lookup_t service_table[] = {
  108. { AccessConfigurationRegister, "AccessConfigurationRegister" },
  109. { AddSocketServices, "AddSocketServices" },
  110. { AdjustResourceInfo, "AdjustResourceInfo" },
  111. { CheckEraseQueue, "CheckEraseQueue" },
  112. { CloseMemory, "CloseMemory" },
  113. { DeregisterClient, "DeregisterClient" },
  114. { DeregisterEraseQueue, "DeregisterEraseQueue" },
  115. { GetCardServicesInfo, "GetCardServicesInfo" },
  116. { GetClientInfo, "GetClientInfo" },
  117. { GetConfigurationInfo, "GetConfigurationInfo" },
  118. { GetEventMask, "GetEventMask" },
  119. { GetFirstClient, "GetFirstClient" },
  120. { GetFirstRegion, "GetFirstRegion" },
  121. { GetFirstTuple, "GetFirstTuple" },
  122. { GetNextClient, "GetNextClient" },
  123. { GetNextRegion, "GetNextRegion" },
  124. { GetNextTuple, "GetNextTuple" },
  125. { GetStatus, "GetStatus" },
  126. { GetTupleData, "GetTupleData" },
  127. { MapMemPage, "MapMemPage" },
  128. { ModifyConfiguration, "ModifyConfiguration" },
  129. { ModifyWindow, "ModifyWindow" },
  130. { OpenMemory, "OpenMemory" },
  131. { ParseTuple, "ParseTuple" },
  132. { ReadMemory, "ReadMemory" },
  133. { RegisterClient, "RegisterClient" },
  134. { RegisterEraseQueue, "RegisterEraseQueue" },
  135. { RegisterMTD, "RegisterMTD" },
  136. { ReleaseConfiguration, "ReleaseConfiguration" },
  137. { ReleaseIO, "ReleaseIO" },
  138. { ReleaseIRQ, "ReleaseIRQ" },
  139. { ReleaseWindow, "ReleaseWindow" },
  140. { RequestConfiguration, "RequestConfiguration" },
  141. { RequestIO, "RequestIO" },
  142. { RequestIRQ, "RequestIRQ" },
  143. { RequestSocketMask, "RequestSocketMask" },
  144. { RequestWindow, "RequestWindow" },
  145. { ResetCard, "ResetCard" },
  146. { SetEventMask, "SetEventMask" },
  147. { ValidateCIS, "ValidateCIS" },
  148. { WriteMemory, "WriteMemory" },
  149. { BindDevice, "BindDevice" },
  150. { BindMTD, "BindMTD" },
  151. { ReportError, "ReportError" },
  152. { SuspendCard, "SuspendCard" },
  153. { ResumeCard, "ResumeCard" },
  154. { EjectCard, "EjectCard" },
  155. { InsertCard, "InsertCard" },
  156. { ReplaceCIS, "ReplaceCIS" }
  157. };
  158. static int pcmcia_report_error(client_handle_t handle, error_info_t *err)
  159. {
  160. int i;
  161. char *serv;
  162. if (CHECK_HANDLE(handle))
  163. printk(KERN_NOTICE);
  164. else {
  165. struct pcmcia_device *p_dev = handle_to_pdev(handle);
  166. printk(KERN_NOTICE "%s: ", p_dev->dev.bus_id);
  167. }
  168. for (i = 0; i < ARRAY_SIZE(service_table); i++)
  169. if (service_table[i].key == err->func)
  170. break;
  171. if (i < ARRAY_SIZE(service_table))
  172. serv = service_table[i].msg;
  173. else
  174. serv = "Unknown service number";
  175. for (i = 0; i < ARRAY_SIZE(error_table); i++)
  176. if (error_table[i].key == err->retcode)
  177. break;
  178. if (i < ARRAY_SIZE(error_table))
  179. printk("%s: %s\n", serv, error_table[i].msg);
  180. else
  181. printk("%s: Unknown error code %#x\n", serv, err->retcode);
  182. return CS_SUCCESS;
  183. } /* report_error */
  184. /* end of code which was in cs.c before */
  185. /*======================================================================*/
  186. void cs_error(client_handle_t handle, int func, int ret)
  187. {
  188. error_info_t err = { func, ret };
  189. pcmcia_report_error(handle, &err);
  190. }
  191. EXPORT_SYMBOL(cs_error);
  192. static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
  193. {
  194. struct pcmcia_device_id *did = p_drv->id_table;
  195. unsigned int i;
  196. u32 hash;
  197. while (did && did->match_flags) {
  198. for (i=0; i<4; i++) {
  199. if (!did->prod_id[i])
  200. continue;
  201. hash = crc32(0, did->prod_id[i], strlen(did->prod_id[i]));
  202. if (hash == did->prod_id_hash[i])
  203. continue;
  204. printk(KERN_DEBUG "pcmcia: %s: invalid hash for "
  205. "product string \"%s\": is 0x%x, should "
  206. "be 0x%x\n", p_drv->drv.name, did->prod_id[i],
  207. did->prod_id_hash[i], hash);
  208. printk(KERN_DEBUG "pcmcia: see "
  209. "Documentation/pcmcia/devicetable.txt for "
  210. "details\n");
  211. }
  212. did++;
  213. }
  214. return;
  215. }
  216. #ifdef CONFIG_PCMCIA_LOAD_CIS
  217. /**
  218. * pcmcia_load_firmware - load CIS from userspace if device-provided is broken
  219. * @dev - the pcmcia device which needs a CIS override
  220. * @filename - requested filename in /lib/firmware/cis/
  221. *
  222. * This uses the in-kernel firmware loading mechanism to use a "fake CIS" if
  223. * the one provided by the card is broken. The firmware files reside in
  224. * /lib/firmware/cis/ in userspace.
  225. */
  226. static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
  227. {
  228. struct pcmcia_socket *s = dev->socket;
  229. const struct firmware *fw;
  230. char path[20];
  231. int ret=-ENOMEM;
  232. cisdump_t *cis;
  233. if (!filename)
  234. return -EINVAL;
  235. ds_dbg(1, "trying to load firmware %s\n", filename);
  236. if (strlen(filename) > 14)
  237. return -EINVAL;
  238. snprintf(path, 20, "%s", filename);
  239. if (request_firmware(&fw, path, &dev->dev) == 0) {
  240. if (fw->size >= CISTPL_MAX_CIS_SIZE)
  241. goto release;
  242. cis = kmalloc(sizeof(cisdump_t), GFP_KERNEL);
  243. if (!cis)
  244. goto release;
  245. memset(cis, 0, sizeof(cisdump_t));
  246. cis->Length = fw->size + 1;
  247. memcpy(cis->Data, fw->data, fw->size);
  248. if (!pcmcia_replace_cis(s, cis))
  249. ret = 0;
  250. }
  251. release:
  252. release_firmware(fw);
  253. return (ret);
  254. }
  255. #else /* !CONFIG_PCMCIA_LOAD_CIS */
  256. static inline int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
  257. {
  258. return -ENODEV;
  259. }
  260. #endif
  261. /*======================================================================*/
  262. void pcmcia_release_bus_socket(struct kref *refcount)
  263. {
  264. struct pcmcia_bus_socket *s = container_of(refcount, struct pcmcia_bus_socket, refcount);
  265. pcmcia_put_socket(s->parent);
  266. kfree(s);
  267. }
  268. void pcmcia_put_bus_socket(struct pcmcia_bus_socket *s)
  269. {
  270. kref_put(&s->refcount, pcmcia_release_bus_socket);
  271. }
  272. struct pcmcia_bus_socket *pcmcia_get_bus_socket(struct pcmcia_bus_socket *s)
  273. {
  274. kref_get(&s->refcount);
  275. return (s);
  276. }
  277. /**
  278. * pcmcia_register_driver - register a PCMCIA driver with the bus core
  279. *
  280. * Registers a PCMCIA driver with the PCMCIA bus core.
  281. */
  282. static int pcmcia_device_probe(struct device *dev);
  283. static int pcmcia_device_remove(struct device * dev);
  284. int pcmcia_register_driver(struct pcmcia_driver *driver)
  285. {
  286. if (!driver)
  287. return -EINVAL;
  288. pcmcia_check_driver(driver);
  289. /* initialize common fields */
  290. driver->drv.bus = &pcmcia_bus_type;
  291. driver->drv.owner = driver->owner;
  292. driver->drv.probe = pcmcia_device_probe;
  293. driver->drv.remove = pcmcia_device_remove;
  294. return driver_register(&driver->drv);
  295. }
  296. EXPORT_SYMBOL(pcmcia_register_driver);
  297. /**
  298. * pcmcia_unregister_driver - unregister a PCMCIA driver with the bus core
  299. */
  300. void pcmcia_unregister_driver(struct pcmcia_driver *driver)
  301. {
  302. driver_unregister(&driver->drv);
  303. }
  304. EXPORT_SYMBOL(pcmcia_unregister_driver);
  305. /* pcmcia_device handling */
  306. struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev)
  307. {
  308. struct device *tmp_dev;
  309. tmp_dev = get_device(&p_dev->dev);
  310. if (!tmp_dev)
  311. return NULL;
  312. return to_pcmcia_dev(tmp_dev);
  313. }
  314. void pcmcia_put_dev(struct pcmcia_device *p_dev)
  315. {
  316. if (p_dev)
  317. put_device(&p_dev->dev);
  318. }
  319. static void pcmcia_release_dev(struct device *dev)
  320. {
  321. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  322. ds_dbg(1, "releasing dev %p\n", p_dev);
  323. pcmcia_put_bus_socket(p_dev->socket->pcmcia);
  324. kfree(p_dev);
  325. }
  326. static int pcmcia_device_probe(struct device * dev)
  327. {
  328. struct pcmcia_device *p_dev;
  329. struct pcmcia_driver *p_drv;
  330. int ret = 0;
  331. dev = get_device(dev);
  332. if (!dev)
  333. return -ENODEV;
  334. p_dev = to_pcmcia_dev(dev);
  335. p_drv = to_pcmcia_drv(dev->driver);
  336. if (!try_module_get(p_drv->owner)) {
  337. ret = -EINVAL;
  338. goto put_dev;
  339. }
  340. if (p_drv->attach) {
  341. p_dev->instance = p_drv->attach();
  342. if ((!p_dev->instance) || (p_dev->client.state & CLIENT_UNBOUND)) {
  343. printk(KERN_NOTICE "ds: unable to create instance "
  344. "of '%s'!\n", p_drv->drv.name);
  345. ret = -EINVAL;
  346. }
  347. }
  348. if (ret)
  349. module_put(p_drv->owner);
  350. put_dev:
  351. if ((ret) || !(p_drv->attach))
  352. put_device(dev);
  353. return (ret);
  354. }
  355. static int pcmcia_device_remove(struct device * dev)
  356. {
  357. struct pcmcia_device *p_dev;
  358. struct pcmcia_driver *p_drv;
  359. /* detach the "instance" */
  360. p_dev = to_pcmcia_dev(dev);
  361. p_drv = to_pcmcia_drv(dev->driver);
  362. if (p_drv) {
  363. if ((p_drv->detach) && (p_dev->instance)) {
  364. p_drv->detach(p_dev->instance);
  365. /* from pcmcia_probe_device */
  366. put_device(&p_dev->dev);
  367. }
  368. module_put(p_drv->owner);
  369. }
  370. return 0;
  371. }
  372. /*
  373. * pcmcia_device_query -- determine information about a pcmcia device
  374. */
  375. static int pcmcia_device_query(struct pcmcia_device *p_dev)
  376. {
  377. cistpl_manfid_t manf_id;
  378. cistpl_funcid_t func_id;
  379. cistpl_vers_1_t vers1;
  380. unsigned int i;
  381. if (!pccard_read_tuple(p_dev->socket, p_dev->func,
  382. CISTPL_MANFID, &manf_id)) {
  383. p_dev->manf_id = manf_id.manf;
  384. p_dev->card_id = manf_id.card;
  385. p_dev->has_manf_id = 1;
  386. p_dev->has_card_id = 1;
  387. }
  388. if (!pccard_read_tuple(p_dev->socket, p_dev->func,
  389. CISTPL_FUNCID, &func_id)) {
  390. p_dev->func_id = func_id.func;
  391. p_dev->has_func_id = 1;
  392. } else {
  393. /* rule of thumb: cards with no FUNCID, but with
  394. * common memory device geometry information, are
  395. * probably memory cards (from pcmcia-cs) */
  396. cistpl_device_geo_t devgeo;
  397. if (!pccard_read_tuple(p_dev->socket, p_dev->func,
  398. CISTPL_DEVICE_GEO, &devgeo)) {
  399. ds_dbg(0, "mem device geometry probably means "
  400. "FUNCID_MEMORY\n");
  401. p_dev->func_id = CISTPL_FUNCID_MEMORY;
  402. p_dev->has_func_id = 1;
  403. }
  404. }
  405. if (!pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_VERS_1,
  406. &vers1)) {
  407. for (i=0; i < vers1.ns; i++) {
  408. char *tmp;
  409. unsigned int length;
  410. tmp = vers1.str + vers1.ofs[i];
  411. length = strlen(tmp) + 1;
  412. if ((length < 3) || (length > 255))
  413. continue;
  414. p_dev->prod_id[i] = kmalloc(sizeof(char) * length,
  415. GFP_KERNEL);
  416. if (!p_dev->prod_id[i])
  417. continue;
  418. p_dev->prod_id[i] = strncpy(p_dev->prod_id[i],
  419. tmp, length);
  420. }
  421. }
  422. return 0;
  423. }
  424. /* device_add_lock is needed to avoid double registration by cardmgr and kernel.
  425. * Serializes pcmcia_device_add; will most likely be removed in future.
  426. *
  427. * While it has the caveat that adding new PCMCIA devices inside(!) device_register()
  428. * won't work, this doesn't matter much at the moment: the driver core doesn't
  429. * support it either.
  430. */
  431. static DECLARE_MUTEX(device_add_lock);
  432. struct pcmcia_device * pcmcia_device_add(struct pcmcia_bus_socket *s, unsigned int function)
  433. {
  434. struct pcmcia_device *p_dev;
  435. unsigned long flags;
  436. s = pcmcia_get_bus_socket(s);
  437. if (!s)
  438. return NULL;
  439. down(&device_add_lock);
  440. /* max of 2 devices per card */
  441. if (s->device_count == 2)
  442. goto err_put;
  443. p_dev = kmalloc(sizeof(struct pcmcia_device), GFP_KERNEL);
  444. if (!p_dev)
  445. goto err_put;
  446. memset(p_dev, 0, sizeof(struct pcmcia_device));
  447. p_dev->socket = s->parent;
  448. p_dev->device_no = (s->device_count++);
  449. p_dev->func = function;
  450. p_dev->dev.bus = &pcmcia_bus_type;
  451. p_dev->dev.parent = s->parent->dev.dev;
  452. p_dev->dev.release = pcmcia_release_dev;
  453. sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no);
  454. /* compat */
  455. p_dev->client.client_magic = CLIENT_MAGIC;
  456. p_dev->client.Socket = s->parent;
  457. p_dev->client.Function = function;
  458. p_dev->client.state = CLIENT_UNBOUND;
  459. /* Add to the list in pcmcia_bus_socket */
  460. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  461. list_add_tail(&p_dev->socket_device_list, &s->devices_list);
  462. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  463. pcmcia_device_query(p_dev);
  464. if (device_register(&p_dev->dev)) {
  465. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  466. list_del(&p_dev->socket_device_list);
  467. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  468. goto err_free;
  469. }
  470. up(&device_add_lock);
  471. return p_dev;
  472. err_free:
  473. kfree(p_dev);
  474. s->device_count--;
  475. err_put:
  476. up(&device_add_lock);
  477. pcmcia_put_bus_socket(s);
  478. return NULL;
  479. }
  480. static int pcmcia_card_add(struct pcmcia_socket *s)
  481. {
  482. cisinfo_t cisinfo;
  483. cistpl_longlink_mfc_t mfc;
  484. unsigned int no_funcs, i;
  485. int ret = 0;
  486. if (!(s->resource_setup_done))
  487. return -EAGAIN; /* try again, but later... */
  488. pcmcia_validate_mem(s);
  489. ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo);
  490. if (ret || !cisinfo.Chains) {
  491. ds_dbg(0, "invalid CIS or invalid resources\n");
  492. return -ENODEV;
  493. }
  494. if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc))
  495. no_funcs = mfc.nfn;
  496. else
  497. no_funcs = 1;
  498. /* this doesn't handle multifunction devices on one pcmcia function
  499. * yet. */
  500. for (i=0; i < no_funcs; i++)
  501. pcmcia_device_add(s->pcmcia, i);
  502. return (ret);
  503. }
  504. static void pcmcia_delayed_add_pseudo_device(void *data)
  505. {
  506. struct pcmcia_bus_socket *s = data;
  507. pcmcia_device_add(s, 0);
  508. s->device_add_pending = 0;
  509. }
  510. static inline void pcmcia_add_pseudo_device(struct pcmcia_bus_socket *s)
  511. {
  512. if (!s->device_add_pending) {
  513. schedule_work(&s->device_add);
  514. s->device_add_pending = 1;
  515. }
  516. return;
  517. }
  518. static int pcmcia_requery(struct device *dev, void * _data)
  519. {
  520. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  521. if (!p_dev->dev.driver)
  522. pcmcia_device_query(p_dev);
  523. return 0;
  524. }
  525. static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
  526. {
  527. int no_devices=0;
  528. unsigned long flags;
  529. /* must be called with skt_sem held */
  530. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  531. if (list_empty(&skt->pcmcia->devices_list))
  532. no_devices=1;
  533. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  534. /* if no devices were added for this socket yet because of
  535. * missing resource information or other trouble, we need to
  536. * do this now. */
  537. if (no_devices) {
  538. int ret = pcmcia_card_add(skt);
  539. if (ret)
  540. return;
  541. }
  542. /* some device information might have changed because of a CIS
  543. * update or because we can finally read it correctly... so
  544. * determine it again, overwriting old values if necessary. */
  545. bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery);
  546. /* we re-scan all devices, not just the ones connected to this
  547. * socket. This does not matter, though. */
  548. bus_rescan_devices(&pcmcia_bus_type);
  549. }
  550. static inline int pcmcia_devmatch(struct pcmcia_device *dev,
  551. struct pcmcia_device_id *did)
  552. {
  553. if (did->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID) {
  554. if ((!dev->has_manf_id) || (dev->manf_id != did->manf_id))
  555. return 0;
  556. }
  557. if (did->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID) {
  558. if ((!dev->has_card_id) || (dev->card_id != did->card_id))
  559. return 0;
  560. }
  561. if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION) {
  562. if (dev->func != did->function)
  563. return 0;
  564. }
  565. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1) {
  566. if (!dev->prod_id[0])
  567. return 0;
  568. if (strcmp(did->prod_id[0], dev->prod_id[0]))
  569. return 0;
  570. }
  571. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2) {
  572. if (!dev->prod_id[1])
  573. return 0;
  574. if (strcmp(did->prod_id[1], dev->prod_id[1]))
  575. return 0;
  576. }
  577. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3) {
  578. if (!dev->prod_id[2])
  579. return 0;
  580. if (strcmp(did->prod_id[2], dev->prod_id[2]))
  581. return 0;
  582. }
  583. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4) {
  584. if (!dev->prod_id[3])
  585. return 0;
  586. if (strcmp(did->prod_id[3], dev->prod_id[3]))
  587. return 0;
  588. }
  589. if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) {
  590. /* handle pseudo multifunction devices:
  591. * there are at most two pseudo multifunction devices.
  592. * if we're matching against the first, schedule a
  593. * call which will then check whether there are two
  594. * pseudo devices, and if not, add the second one.
  595. */
  596. if (dev->device_no == 0)
  597. pcmcia_add_pseudo_device(dev->socket->pcmcia);
  598. if (dev->device_no != did->device_no)
  599. return 0;
  600. }
  601. if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) {
  602. if ((!dev->has_func_id) || (dev->func_id != did->func_id))
  603. return 0;
  604. /* if this is a pseudo-multi-function device,
  605. * we need explicit matches */
  606. if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO)
  607. return 0;
  608. if (dev->device_no)
  609. return 0;
  610. /* also, FUNC_ID matching needs to be activated by userspace
  611. * after it has re-checked that there is no possible module
  612. * with a prod_id/manf_id/card_id match.
  613. */
  614. if (!dev->allow_func_id_match)
  615. return 0;
  616. }
  617. if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
  618. if (!dev->socket->fake_cis)
  619. pcmcia_load_firmware(dev, did->cisfile);
  620. if (!dev->socket->fake_cis)
  621. return 0;
  622. }
  623. if (did->match_flags & PCMCIA_DEV_ID_MATCH_ANONYMOUS) {
  624. int i;
  625. for (i=0; i<4; i++)
  626. if (dev->prod_id[i])
  627. return 0;
  628. if (dev->has_manf_id || dev->has_card_id || dev->has_func_id)
  629. return 0;
  630. }
  631. dev->dev.driver_data = (void *) did;
  632. return 1;
  633. }
  634. static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
  635. struct pcmcia_device * p_dev = to_pcmcia_dev(dev);
  636. struct pcmcia_driver * p_drv = to_pcmcia_drv(drv);
  637. struct pcmcia_device_id *did = p_drv->id_table;
  638. /* matching by cardmgr */
  639. if (p_dev->cardmgr == p_drv)
  640. return 1;
  641. while (did && did->match_flags) {
  642. if (pcmcia_devmatch(p_dev, did))
  643. return 1;
  644. did++;
  645. }
  646. return 0;
  647. }
  648. #ifdef CONFIG_HOTPLUG
  649. static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp,
  650. char *buffer, int buffer_size)
  651. {
  652. struct pcmcia_device *p_dev;
  653. int i, length = 0;
  654. u32 hash[4] = { 0, 0, 0, 0};
  655. if (!dev)
  656. return -ENODEV;
  657. p_dev = to_pcmcia_dev(dev);
  658. /* calculate hashes */
  659. for (i=0; i<4; i++) {
  660. if (!p_dev->prod_id[i])
  661. continue;
  662. hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i]));
  663. }
  664. i = 0;
  665. if (add_hotplug_env_var(envp, num_envp, &i,
  666. buffer, buffer_size, &length,
  667. "SOCKET_NO=%u",
  668. p_dev->socket->sock))
  669. return -ENOMEM;
  670. if (add_hotplug_env_var(envp, num_envp, &i,
  671. buffer, buffer_size, &length,
  672. "DEVICE_NO=%02X",
  673. p_dev->device_no))
  674. return -ENOMEM;
  675. if (add_hotplug_env_var(envp, num_envp, &i,
  676. buffer, buffer_size, &length,
  677. "MODALIAS=pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
  678. "pa%08Xpb%08Xpc%08Xpd%08X",
  679. p_dev->has_manf_id ? p_dev->manf_id : 0,
  680. p_dev->has_card_id ? p_dev->card_id : 0,
  681. p_dev->has_func_id ? p_dev->func_id : 0,
  682. p_dev->func,
  683. p_dev->device_no,
  684. hash[0],
  685. hash[1],
  686. hash[2],
  687. hash[3]))
  688. return -ENOMEM;
  689. envp[i] = NULL;
  690. return 0;
  691. }
  692. #else
  693. static int pcmcia_bus_hotplug(struct device *dev, char **envp, int num_envp,
  694. char *buffer, int buffer_size)
  695. {
  696. return -ENODEV;
  697. }
  698. #endif
  699. /************************ per-device sysfs output ***************************/
  700. #define pcmcia_device_attr(field, test, format) \
  701. static ssize_t field##_show (struct device *dev, struct device_attribute *attr, char *buf) \
  702. { \
  703. struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \
  704. return p_dev->test ? sprintf (buf, format, p_dev->field) : -ENODEV; \
  705. }
  706. #define pcmcia_device_stringattr(name, field) \
  707. static ssize_t name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
  708. { \
  709. struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \
  710. return p_dev->field ? sprintf (buf, "%s\n", p_dev->field) : -ENODEV; \
  711. }
  712. pcmcia_device_attr(func, socket, "0x%02x\n");
  713. pcmcia_device_attr(func_id, has_func_id, "0x%02x\n");
  714. pcmcia_device_attr(manf_id, has_manf_id, "0x%04x\n");
  715. pcmcia_device_attr(card_id, has_card_id, "0x%04x\n");
  716. pcmcia_device_stringattr(prod_id1, prod_id[0]);
  717. pcmcia_device_stringattr(prod_id2, prod_id[1]);
  718. pcmcia_device_stringattr(prod_id3, prod_id[2]);
  719. pcmcia_device_stringattr(prod_id4, prod_id[3]);
  720. static ssize_t pcmcia_store_allow_func_id_match (struct device * dev, struct device_attribute *attr,
  721. const char * buf, size_t count)
  722. {
  723. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  724. if (!count)
  725. return -EINVAL;
  726. down(&p_dev->socket->skt_sem);
  727. p_dev->allow_func_id_match = 1;
  728. up(&p_dev->socket->skt_sem);
  729. bus_rescan_devices(&pcmcia_bus_type);
  730. return count;
  731. }
  732. static struct device_attribute pcmcia_dev_attrs[] = {
  733. __ATTR(function, 0444, func_show, NULL),
  734. __ATTR_RO(func_id),
  735. __ATTR_RO(manf_id),
  736. __ATTR_RO(card_id),
  737. __ATTR_RO(prod_id1),
  738. __ATTR_RO(prod_id2),
  739. __ATTR_RO(prod_id3),
  740. __ATTR_RO(prod_id4),
  741. __ATTR(allow_func_id_match, 0200, NULL, pcmcia_store_allow_func_id_match),
  742. __ATTR_NULL,
  743. };
  744. /*======================================================================
  745. The card status event handler.
  746. ======================================================================*/
  747. struct send_event_data {
  748. struct pcmcia_socket *skt;
  749. event_t event;
  750. int priority;
  751. };
  752. static int send_event_callback(struct device *dev, void * _data)
  753. {
  754. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  755. struct send_event_data *data = _data;
  756. /* we get called for all sockets, but may only pass the event
  757. * for drivers _on the affected socket_ */
  758. if (p_dev->socket != data->skt)
  759. return 0;
  760. if (p_dev->client.state & (CLIENT_UNBOUND|CLIENT_STALE))
  761. return 0;
  762. if (p_dev->client.EventMask & data->event)
  763. return EVENT(&p_dev->client, data->event, data->priority);
  764. return 0;
  765. }
  766. static int send_event(struct pcmcia_socket *s, event_t event, int priority)
  767. {
  768. int ret = 0;
  769. struct send_event_data private;
  770. struct pcmcia_bus_socket *skt = pcmcia_get_bus_socket(s->pcmcia);
  771. if (!skt)
  772. return 0;
  773. private.skt = s;
  774. private.event = event;
  775. private.priority = priority;
  776. ret = bus_for_each_dev(&pcmcia_bus_type, NULL, &private, send_event_callback);
  777. pcmcia_put_bus_socket(skt);
  778. return ret;
  779. } /* send_event */
  780. /* Normally, the event is passed to individual drivers after
  781. * informing userspace. Only for CS_EVENT_CARD_REMOVAL this
  782. * is inversed to maintain historic compatibility.
  783. */
  784. static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
  785. {
  786. struct pcmcia_bus_socket *s = skt->pcmcia;
  787. int ret = 0;
  788. ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n",
  789. event, priority, s);
  790. switch (event) {
  791. case CS_EVENT_CARD_REMOVAL:
  792. s->state &= ~DS_SOCKET_PRESENT;
  793. send_event(skt, event, priority);
  794. unbind_request(s);
  795. handle_event(s, event);
  796. break;
  797. case CS_EVENT_CARD_INSERTION:
  798. s->state |= DS_SOCKET_PRESENT;
  799. pcmcia_card_add(skt);
  800. handle_event(s, event);
  801. break;
  802. case CS_EVENT_EJECTION_REQUEST:
  803. ret = send_event(skt, event, priority);
  804. break;
  805. default:
  806. handle_event(s, event);
  807. send_event(skt, event, priority);
  808. break;
  809. }
  810. return 0;
  811. } /* ds_event */
  812. int pcmcia_register_client(client_handle_t *handle, client_reg_t *req)
  813. {
  814. client_t *client = NULL;
  815. struct pcmcia_socket *s;
  816. struct pcmcia_bus_socket *skt = NULL;
  817. struct pcmcia_device *p_dev = NULL;
  818. /* Look for unbound client with matching dev_info */
  819. down_read(&pcmcia_socket_list_rwsem);
  820. list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
  821. unsigned long flags;
  822. if (s->state & SOCKET_CARDBUS)
  823. continue;
  824. skt = s->pcmcia;
  825. if (!skt)
  826. continue;
  827. skt = pcmcia_get_bus_socket(skt);
  828. if (!skt)
  829. continue;
  830. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  831. list_for_each_entry(p_dev, &skt->devices_list, socket_device_list) {
  832. struct pcmcia_driver *p_drv;
  833. p_dev = pcmcia_get_dev(p_dev);
  834. if (!p_dev)
  835. continue;
  836. if (!(p_dev->client.state & CLIENT_UNBOUND) ||
  837. (!p_dev->dev.driver)) {
  838. pcmcia_put_dev(p_dev);
  839. continue;
  840. }
  841. p_drv = to_pcmcia_drv(p_dev->dev.driver);
  842. if (!strncmp(p_drv->drv.name, (char *)req->dev_info, DEV_NAME_LEN)) {
  843. client = &p_dev->client;
  844. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  845. goto found;
  846. }
  847. pcmcia_put_dev(p_dev);
  848. }
  849. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  850. pcmcia_put_bus_socket(skt);
  851. }
  852. found:
  853. up_read(&pcmcia_socket_list_rwsem);
  854. if (!p_dev || !client)
  855. return -ENODEV;
  856. pcmcia_put_bus_socket(skt); /* safe, as we already hold a reference from bind_device */
  857. *handle = client;
  858. client->state &= ~CLIENT_UNBOUND;
  859. client->Socket = s;
  860. client->EventMask = req->EventMask;
  861. client->event_handler = req->event_handler;
  862. client->event_callback_args = req->event_callback_args;
  863. client->event_callback_args.client_handle = client;
  864. if (s->state & SOCKET_CARDBUS)
  865. client->state |= CLIENT_CARDBUS;
  866. if ((!(s->state & SOCKET_CARDBUS)) && (s->functions == 0) &&
  867. (client->Function != BIND_FN_ALL)) {
  868. cistpl_longlink_mfc_t mfc;
  869. if (pccard_read_tuple(s, client->Function, CISTPL_LONGLINK_MFC, &mfc)
  870. == CS_SUCCESS)
  871. s->functions = mfc.nfn;
  872. else
  873. s->functions = 1;
  874. s->config = kmalloc(sizeof(config_t) * s->functions,
  875. GFP_KERNEL);
  876. if (!s->config)
  877. goto out_no_resource;
  878. memset(s->config, 0, sizeof(config_t) * s->functions);
  879. }
  880. ds_dbg(1, "register_client(): client 0x%p, dev %s\n",
  881. client, p_dev->dev.bus_id);
  882. if (client->EventMask & CS_EVENT_REGISTRATION_COMPLETE)
  883. EVENT(client, CS_EVENT_REGISTRATION_COMPLETE, CS_EVENT_PRI_LOW);
  884. if ((s->state & (SOCKET_PRESENT|SOCKET_CARDBUS)) == SOCKET_PRESENT) {
  885. if (client->EventMask & CS_EVENT_CARD_INSERTION)
  886. EVENT(client, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW);
  887. }
  888. return CS_SUCCESS;
  889. out_no_resource:
  890. pcmcia_put_dev(p_dev);
  891. return CS_OUT_OF_RESOURCE;
  892. } /* register_client */
  893. EXPORT_SYMBOL(pcmcia_register_client);
  894. /* unbind _all_ devices attached to a given pcmcia_bus_socket. The
  895. * drivers have been called with EVENT_CARD_REMOVAL before.
  896. */
  897. static int unbind_request(struct pcmcia_bus_socket *s)
  898. {
  899. struct pcmcia_device *p_dev;
  900. unsigned long flags;
  901. ds_dbg(2, "unbind_request(%d)\n", s->parent->sock);
  902. s->device_count = 0;
  903. for (;;) {
  904. /* unregister all pcmcia_devices registered with this socket*/
  905. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  906. if (list_empty(&s->devices_list)) {
  907. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  908. return 0;
  909. }
  910. p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list);
  911. list_del(&p_dev->socket_device_list);
  912. p_dev->client.state |= CLIENT_STALE;
  913. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  914. device_unregister(&p_dev->dev);
  915. }
  916. return 0;
  917. } /* unbind_request */
  918. int pcmcia_deregister_client(client_handle_t handle)
  919. {
  920. struct pcmcia_socket *s;
  921. int i;
  922. struct pcmcia_device *p_dev = handle_to_pdev(handle);
  923. if (CHECK_HANDLE(handle))
  924. return CS_BAD_HANDLE;
  925. s = SOCKET(handle);
  926. ds_dbg(1, "deregister_client(%p)\n", handle);
  927. if (handle->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED))
  928. goto warn_out;
  929. for (i = 0; i < MAX_WIN; i++)
  930. if (handle->state & CLIENT_WIN_REQ(i))
  931. goto warn_out;
  932. if (handle->state & CLIENT_STALE) {
  933. handle->client_magic = 0;
  934. handle->state &= ~CLIENT_STALE;
  935. pcmcia_put_dev(p_dev);
  936. } else {
  937. handle->state = CLIENT_UNBOUND;
  938. handle->event_handler = NULL;
  939. }
  940. return CS_SUCCESS;
  941. warn_out:
  942. printk(KERN_WARNING "ds: deregister_client was called too early.\n");
  943. return CS_IN_USE;
  944. } /* deregister_client */
  945. EXPORT_SYMBOL(pcmcia_deregister_client);
  946. static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev)
  947. {
  948. struct pcmcia_socket *socket = class_get_devdata(class_dev);
  949. struct pcmcia_bus_socket *s;
  950. int ret;
  951. s = kmalloc(sizeof(struct pcmcia_bus_socket), GFP_KERNEL);
  952. if(!s)
  953. return -ENOMEM;
  954. memset(s, 0, sizeof(struct pcmcia_bus_socket));
  955. /* get reference to parent socket */
  956. s->parent = pcmcia_get_socket(socket);
  957. if (!s->parent) {
  958. printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket);
  959. kfree (s);
  960. return -ENODEV;
  961. }
  962. kref_init(&s->refcount);
  963. /*
  964. * Ugly. But we want to wait for the socket threads to have started up.
  965. * We really should let the drivers themselves drive some of this..
  966. */
  967. msleep(250);
  968. #ifdef CONFIG_PCMCIA_IOCTL
  969. init_waitqueue_head(&s->queue);
  970. #endif
  971. INIT_LIST_HEAD(&s->devices_list);
  972. INIT_WORK(&s->device_add, pcmcia_delayed_add_pseudo_device, s);
  973. /* Set up hotline to Card Services */
  974. s->callback.owner = THIS_MODULE;
  975. s->callback.event = &ds_event;
  976. s->callback.requery = &pcmcia_bus_rescan;
  977. socket->pcmcia = s;
  978. ret = pccard_register_pcmcia(socket, &s->callback);
  979. if (ret) {
  980. printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket);
  981. pcmcia_put_bus_socket(s);
  982. socket->pcmcia = NULL;
  983. return (ret);
  984. }
  985. return 0;
  986. }
  987. static void pcmcia_bus_remove_socket(struct class_device *class_dev)
  988. {
  989. struct pcmcia_socket *socket = class_get_devdata(class_dev);
  990. if (!socket || !socket->pcmcia)
  991. return;
  992. pccard_register_pcmcia(socket, NULL);
  993. socket->pcmcia->state |= DS_SOCKET_DEAD;
  994. pcmcia_put_bus_socket(socket->pcmcia);
  995. socket->pcmcia = NULL;
  996. return;
  997. }
  998. /* the pcmcia_bus_interface is used to handle pcmcia socket devices */
  999. static struct class_interface pcmcia_bus_interface = {
  1000. .class = &pcmcia_socket_class,
  1001. .add = &pcmcia_bus_add_socket,
  1002. .remove = &pcmcia_bus_remove_socket,
  1003. };
  1004. struct bus_type pcmcia_bus_type = {
  1005. .name = "pcmcia",
  1006. .hotplug = pcmcia_bus_hotplug,
  1007. .match = pcmcia_bus_match,
  1008. .dev_attrs = pcmcia_dev_attrs,
  1009. };
  1010. static int __init init_pcmcia_bus(void)
  1011. {
  1012. spin_lock_init(&pcmcia_dev_list_lock);
  1013. bus_register(&pcmcia_bus_type);
  1014. class_interface_register(&pcmcia_bus_interface);
  1015. pcmcia_setup_ioctl();
  1016. return 0;
  1017. }
  1018. fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that
  1019. * pcmcia_socket_class is already registered */
  1020. static void __exit exit_pcmcia_bus(void)
  1021. {
  1022. pcmcia_cleanup_ioctl();
  1023. class_interface_unregister(&pcmcia_bus_interface);
  1024. bus_unregister(&pcmcia_bus_type);
  1025. }
  1026. module_exit(exit_pcmcia_bus);
  1027. MODULE_ALIAS("ds");