ds.c 33 KB

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