ds.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  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 - 2006 Dominik Brodowski
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/errno.h>
  19. #include <linux/list.h>
  20. #include <linux/delay.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/crc32.h>
  23. #include <linux/firmware.h>
  24. #include <linux/kref.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->probe || !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/
  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/ 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 = kzalloc(sizeof(cisdump_t), GFP_KERNEL);
  226. if (!cis)
  227. goto release;
  228. cis->Length = fw->size + 1;
  229. memcpy(cis->Data, fw->data, fw->size);
  230. if (!pcmcia_replace_cis(s, cis))
  231. ret = 0;
  232. }
  233. release:
  234. release_firmware(fw);
  235. return (ret);
  236. }
  237. #else /* !CONFIG_PCMCIA_LOAD_CIS */
  238. static inline int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
  239. {
  240. return -ENODEV;
  241. }
  242. #endif
  243. /*======================================================================*/
  244. /**
  245. * pcmcia_register_driver - register a PCMCIA driver with the bus core
  246. *
  247. * Registers a PCMCIA driver with the PCMCIA bus core.
  248. */
  249. int pcmcia_register_driver(struct pcmcia_driver *driver)
  250. {
  251. if (!driver)
  252. return -EINVAL;
  253. pcmcia_check_driver(driver);
  254. /* initialize common fields */
  255. driver->drv.bus = &pcmcia_bus_type;
  256. driver->drv.owner = driver->owner;
  257. return driver_register(&driver->drv);
  258. }
  259. EXPORT_SYMBOL(pcmcia_register_driver);
  260. /**
  261. * pcmcia_unregister_driver - unregister a PCMCIA driver with the bus core
  262. */
  263. void pcmcia_unregister_driver(struct pcmcia_driver *driver)
  264. {
  265. driver_unregister(&driver->drv);
  266. }
  267. EXPORT_SYMBOL(pcmcia_unregister_driver);
  268. /* pcmcia_device handling */
  269. struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev)
  270. {
  271. struct device *tmp_dev;
  272. tmp_dev = get_device(&p_dev->dev);
  273. if (!tmp_dev)
  274. return NULL;
  275. return to_pcmcia_dev(tmp_dev);
  276. }
  277. void pcmcia_put_dev(struct pcmcia_device *p_dev)
  278. {
  279. if (p_dev)
  280. put_device(&p_dev->dev);
  281. }
  282. static void pcmcia_release_function(struct kref *ref)
  283. {
  284. struct config_t *c = container_of(ref, struct config_t, ref);
  285. kfree(c);
  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. kref_put(&p_dev->function_config->ref, pcmcia_release_function);
  294. kfree(p_dev);
  295. }
  296. static void pcmcia_add_pseudo_device(struct pcmcia_socket *s)
  297. {
  298. if (!s->pcmcia_state.device_add_pending) {
  299. s->pcmcia_state.device_add_pending = 1;
  300. schedule_work(&s->device_add);
  301. }
  302. return;
  303. }
  304. static int pcmcia_device_probe(struct device * dev)
  305. {
  306. struct pcmcia_device *p_dev;
  307. struct pcmcia_driver *p_drv;
  308. struct pcmcia_device_id *did;
  309. struct pcmcia_socket *s;
  310. int ret = 0;
  311. dev = get_device(dev);
  312. if (!dev)
  313. return -ENODEV;
  314. p_dev = to_pcmcia_dev(dev);
  315. p_drv = to_pcmcia_drv(dev->driver);
  316. s = p_dev->socket;
  317. if ((!p_drv->probe) || (!p_dev->function_config) ||
  318. (!try_module_get(p_drv->owner))) {
  319. ret = -EINVAL;
  320. goto put_dev;
  321. }
  322. ret = p_drv->probe(p_dev);
  323. if (ret)
  324. goto put_module;
  325. /* handle pseudo multifunction devices:
  326. * there are at most two pseudo multifunction devices.
  327. * if we're matching against the first, schedule a
  328. * call which will then check whether there are two
  329. * pseudo devices, and if not, add the second one.
  330. */
  331. did = p_dev->dev.driver_data;
  332. if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) &&
  333. (p_dev->socket->device_count == 1) && (p_dev->device_no == 0))
  334. pcmcia_add_pseudo_device(p_dev->socket);
  335. put_module:
  336. if (ret)
  337. module_put(p_drv->owner);
  338. put_dev:
  339. if (ret)
  340. put_device(dev);
  341. return (ret);
  342. }
  343. /*
  344. * Removes a PCMCIA card from the device tree and socket list.
  345. */
  346. static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *leftover)
  347. {
  348. struct pcmcia_device *p_dev;
  349. struct pcmcia_device *tmp;
  350. unsigned long flags;
  351. ds_dbg(2, "unbind_request(%d)\n", s->sock);
  352. if (!leftover)
  353. s->device_count = 0;
  354. else
  355. s->device_count = 1;
  356. /* unregister all pcmcia_devices registered with this socket, except leftover */
  357. list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) {
  358. if (p_dev == leftover)
  359. continue;
  360. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  361. list_del(&p_dev->socket_device_list);
  362. p_dev->_removed=1;
  363. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  364. device_unregister(&p_dev->dev);
  365. }
  366. return;
  367. }
  368. static int pcmcia_device_remove(struct device * dev)
  369. {
  370. struct pcmcia_device *p_dev;
  371. struct pcmcia_driver *p_drv;
  372. struct pcmcia_device_id *did;
  373. int i;
  374. p_dev = to_pcmcia_dev(dev);
  375. p_drv = to_pcmcia_drv(dev->driver);
  376. /* If we're removing the primary module driving a
  377. * pseudo multi-function card, we need to unbind
  378. * all devices
  379. */
  380. did = p_dev->dev.driver_data;
  381. if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) &&
  382. (p_dev->socket->device_count != 0) &&
  383. (p_dev->device_no == 0))
  384. pcmcia_card_remove(p_dev->socket, p_dev);
  385. /* detach the "instance" */
  386. if (!p_drv)
  387. return 0;
  388. if (p_drv->remove)
  389. p_drv->remove(p_dev);
  390. p_dev->dev_node = NULL;
  391. /* check for proper unloading */
  392. if (p_dev->_irq || p_dev->_io || p_dev->_locked)
  393. printk(KERN_INFO "pcmcia: driver %s did not release config properly\n",
  394. p_drv->drv.name);
  395. for (i = 0; i < MAX_WIN; i++)
  396. if (p_dev->_win & CLIENT_WIN_REQ(i))
  397. printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n",
  398. p_drv->drv.name);
  399. /* references from pcmcia_probe_device */
  400. pcmcia_put_dev(p_dev);
  401. module_put(p_drv->owner);
  402. return 0;
  403. }
  404. /*
  405. * pcmcia_device_query -- determine information about a pcmcia device
  406. */
  407. static int pcmcia_device_query(struct pcmcia_device *p_dev)
  408. {
  409. cistpl_manfid_t manf_id;
  410. cistpl_funcid_t func_id;
  411. cistpl_vers_1_t *vers1;
  412. unsigned int i;
  413. vers1 = kmalloc(sizeof(*vers1), GFP_KERNEL);
  414. if (!vers1)
  415. return -ENOMEM;
  416. if (!pccard_read_tuple(p_dev->socket, p_dev->func,
  417. CISTPL_MANFID, &manf_id)) {
  418. p_dev->manf_id = manf_id.manf;
  419. p_dev->card_id = manf_id.card;
  420. p_dev->has_manf_id = 1;
  421. p_dev->has_card_id = 1;
  422. }
  423. if (!pccard_read_tuple(p_dev->socket, p_dev->func,
  424. CISTPL_FUNCID, &func_id)) {
  425. p_dev->func_id = func_id.func;
  426. p_dev->has_func_id = 1;
  427. } else {
  428. /* rule of thumb: cards with no FUNCID, but with
  429. * common memory device geometry information, are
  430. * probably memory cards (from pcmcia-cs) */
  431. cistpl_device_geo_t *devgeo;
  432. devgeo = kmalloc(sizeof(*devgeo), GFP_KERNEL);
  433. if (!devgeo) {
  434. kfree(vers1);
  435. return -ENOMEM;
  436. }
  437. if (!pccard_read_tuple(p_dev->socket, p_dev->func,
  438. CISTPL_DEVICE_GEO, devgeo)) {
  439. ds_dbg(0, "mem device geometry probably means "
  440. "FUNCID_MEMORY\n");
  441. p_dev->func_id = CISTPL_FUNCID_MEMORY;
  442. p_dev->has_func_id = 1;
  443. }
  444. kfree(devgeo);
  445. }
  446. if (!pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_VERS_1,
  447. vers1)) {
  448. for (i=0; i < vers1->ns; i++) {
  449. char *tmp;
  450. unsigned int length;
  451. tmp = vers1->str + vers1->ofs[i];
  452. length = strlen(tmp) + 1;
  453. if ((length < 2) || (length > 255))
  454. continue;
  455. p_dev->prod_id[i] = kmalloc(sizeof(char) * length,
  456. GFP_KERNEL);
  457. if (!p_dev->prod_id[i])
  458. continue;
  459. p_dev->prod_id[i] = strncpy(p_dev->prod_id[i],
  460. tmp, length);
  461. }
  462. }
  463. kfree(vers1);
  464. return 0;
  465. }
  466. /* device_add_lock is needed to avoid double registration by cardmgr and kernel.
  467. * Serializes pcmcia_device_add; will most likely be removed in future.
  468. *
  469. * While it has the caveat that adding new PCMCIA devices inside(!) device_register()
  470. * won't work, this doesn't matter much at the moment: the driver core doesn't
  471. * support it either.
  472. */
  473. static DEFINE_MUTEX(device_add_lock);
  474. struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
  475. {
  476. struct pcmcia_device *p_dev, *tmp_dev;
  477. unsigned long flags;
  478. int bus_id_len;
  479. s = pcmcia_get_socket(s);
  480. if (!s)
  481. return NULL;
  482. mutex_lock(&device_add_lock);
  483. /* max of 2 devices per card */
  484. if (s->device_count == 2)
  485. goto err_put;
  486. p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL);
  487. if (!p_dev)
  488. goto err_put;
  489. p_dev->socket = s;
  490. p_dev->device_no = (s->device_count++);
  491. p_dev->func = function;
  492. if (s->functions <= function)
  493. s->functions = function + 1;
  494. p_dev->dev.bus = &pcmcia_bus_type;
  495. p_dev->dev.parent = s->dev.dev;
  496. p_dev->dev.release = pcmcia_release_dev;
  497. bus_id_len = sprintf (p_dev->dev.bus_id, "%d.%d", p_dev->socket->sock, p_dev->device_no);
  498. p_dev->devname = kmalloc(6 + bus_id_len + 1, GFP_KERNEL);
  499. if (!p_dev->devname)
  500. goto err_free;
  501. sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
  502. /* compat */
  503. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  504. /*
  505. * p_dev->function_config must be the same for all card functions.
  506. * Note that this is serialized by the device_add_lock, so that
  507. * only one such struct will be created.
  508. */
  509. list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list)
  510. if (p_dev->func == tmp_dev->func) {
  511. p_dev->function_config = tmp_dev->function_config;
  512. kref_get(&p_dev->function_config->ref);
  513. }
  514. /* Add to the list in pcmcia_bus_socket */
  515. list_add(&p_dev->socket_device_list, &s->devices_list);
  516. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  517. if (!p_dev->function_config) {
  518. p_dev->function_config = kzalloc(sizeof(struct config_t),
  519. GFP_KERNEL);
  520. if (!p_dev->function_config)
  521. goto err_unreg;
  522. kref_init(&p_dev->function_config->ref);
  523. }
  524. printk(KERN_NOTICE "pcmcia: registering new device %s\n",
  525. p_dev->devname);
  526. pcmcia_device_query(p_dev);
  527. if (device_register(&p_dev->dev))
  528. goto err_unreg;
  529. mutex_unlock(&device_add_lock);
  530. return p_dev;
  531. err_unreg:
  532. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  533. list_del(&p_dev->socket_device_list);
  534. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  535. err_free:
  536. kfree(p_dev->devname);
  537. kfree(p_dev);
  538. s->device_count--;
  539. err_put:
  540. mutex_unlock(&device_add_lock);
  541. pcmcia_put_socket(s);
  542. return NULL;
  543. }
  544. static int pcmcia_card_add(struct pcmcia_socket *s)
  545. {
  546. cisinfo_t cisinfo;
  547. cistpl_longlink_mfc_t mfc;
  548. unsigned int no_funcs, i;
  549. int ret = 0;
  550. if (!(s->resource_setup_done))
  551. return -EAGAIN; /* try again, but later... */
  552. if (pcmcia_validate_mem(s))
  553. return -EAGAIN; /* try again, but later... */
  554. ret = pccard_validate_cis(s, BIND_FN_ALL, &cisinfo);
  555. if (ret || !cisinfo.Chains) {
  556. ds_dbg(0, "invalid CIS or invalid resources\n");
  557. return -ENODEV;
  558. }
  559. if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc))
  560. no_funcs = mfc.nfn;
  561. else
  562. no_funcs = 1;
  563. for (i=0; i < no_funcs; i++)
  564. pcmcia_device_add(s, i);
  565. return (ret);
  566. }
  567. static void pcmcia_delayed_add_pseudo_device(void *data)
  568. {
  569. struct pcmcia_socket *s = data;
  570. pcmcia_device_add(s, 0);
  571. s->pcmcia_state.device_add_pending = 0;
  572. }
  573. static int pcmcia_requery(struct device *dev, void * _data)
  574. {
  575. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  576. if (!p_dev->dev.driver)
  577. pcmcia_device_query(p_dev);
  578. return 0;
  579. }
  580. static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
  581. {
  582. int no_devices=0;
  583. unsigned long flags;
  584. /* must be called with skt_mutex held */
  585. spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
  586. if (list_empty(&skt->devices_list))
  587. no_devices=1;
  588. spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
  589. /* if no devices were added for this socket yet because of
  590. * missing resource information or other trouble, we need to
  591. * do this now. */
  592. if (no_devices) {
  593. int ret = pcmcia_card_add(skt);
  594. if (ret)
  595. return;
  596. }
  597. /* some device information might have changed because of a CIS
  598. * update or because we can finally read it correctly... so
  599. * determine it again, overwriting old values if necessary. */
  600. bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery);
  601. /* we re-scan all devices, not just the ones connected to this
  602. * socket. This does not matter, though. */
  603. bus_rescan_devices(&pcmcia_bus_type);
  604. }
  605. static inline int pcmcia_devmatch(struct pcmcia_device *dev,
  606. struct pcmcia_device_id *did)
  607. {
  608. if (did->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID) {
  609. if ((!dev->has_manf_id) || (dev->manf_id != did->manf_id))
  610. return 0;
  611. }
  612. if (did->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID) {
  613. if ((!dev->has_card_id) || (dev->card_id != did->card_id))
  614. return 0;
  615. }
  616. if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION) {
  617. if (dev->func != did->function)
  618. return 0;
  619. }
  620. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1) {
  621. if (!dev->prod_id[0])
  622. return 0;
  623. if (strcmp(did->prod_id[0], dev->prod_id[0]))
  624. return 0;
  625. }
  626. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2) {
  627. if (!dev->prod_id[1])
  628. return 0;
  629. if (strcmp(did->prod_id[1], dev->prod_id[1]))
  630. return 0;
  631. }
  632. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3) {
  633. if (!dev->prod_id[2])
  634. return 0;
  635. if (strcmp(did->prod_id[2], dev->prod_id[2]))
  636. return 0;
  637. }
  638. if (did->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4) {
  639. if (!dev->prod_id[3])
  640. return 0;
  641. if (strcmp(did->prod_id[3], dev->prod_id[3]))
  642. return 0;
  643. }
  644. if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) {
  645. if (dev->device_no != did->device_no)
  646. return 0;
  647. }
  648. if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) {
  649. if ((!dev->has_func_id) || (dev->func_id != did->func_id))
  650. return 0;
  651. /* if this is a pseudo-multi-function device,
  652. * we need explicit matches */
  653. if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO)
  654. return 0;
  655. if (dev->device_no)
  656. return 0;
  657. /* also, FUNC_ID matching needs to be activated by userspace
  658. * after it has re-checked that there is no possible module
  659. * with a prod_id/manf_id/card_id match.
  660. */
  661. if (!dev->allow_func_id_match)
  662. return 0;
  663. }
  664. if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
  665. if (!dev->socket->fake_cis)
  666. pcmcia_load_firmware(dev, did->cisfile);
  667. if (!dev->socket->fake_cis)
  668. return 0;
  669. }
  670. if (did->match_flags & PCMCIA_DEV_ID_MATCH_ANONYMOUS) {
  671. int i;
  672. for (i=0; i<4; i++)
  673. if (dev->prod_id[i])
  674. return 0;
  675. if (dev->has_manf_id || dev->has_card_id || dev->has_func_id)
  676. return 0;
  677. }
  678. dev->dev.driver_data = (void *) did;
  679. return 1;
  680. }
  681. static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
  682. struct pcmcia_device * p_dev = to_pcmcia_dev(dev);
  683. struct pcmcia_driver * p_drv = to_pcmcia_drv(drv);
  684. struct pcmcia_device_id *did = p_drv->id_table;
  685. #ifdef CONFIG_PCMCIA_IOCTL
  686. /* matching by cardmgr */
  687. if (p_dev->cardmgr == p_drv)
  688. return 1;
  689. #endif
  690. while (did && did->match_flags) {
  691. if (pcmcia_devmatch(p_dev, did))
  692. return 1;
  693. did++;
  694. }
  695. return 0;
  696. }
  697. #ifdef CONFIG_HOTPLUG
  698. static int pcmcia_bus_uevent(struct device *dev, char **envp, int num_envp,
  699. char *buffer, int buffer_size)
  700. {
  701. struct pcmcia_device *p_dev;
  702. int i, length = 0;
  703. u32 hash[4] = { 0, 0, 0, 0};
  704. if (!dev)
  705. return -ENODEV;
  706. p_dev = to_pcmcia_dev(dev);
  707. /* calculate hashes */
  708. for (i=0; i<4; i++) {
  709. if (!p_dev->prod_id[i])
  710. continue;
  711. hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i]));
  712. }
  713. i = 0;
  714. if (add_uevent_var(envp, num_envp, &i,
  715. buffer, buffer_size, &length,
  716. "SOCKET_NO=%u",
  717. p_dev->socket->sock))
  718. return -ENOMEM;
  719. if (add_uevent_var(envp, num_envp, &i,
  720. buffer, buffer_size, &length,
  721. "DEVICE_NO=%02X",
  722. p_dev->device_no))
  723. return -ENOMEM;
  724. if (add_uevent_var(envp, num_envp, &i,
  725. buffer, buffer_size, &length,
  726. "MODALIAS=pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
  727. "pa%08Xpb%08Xpc%08Xpd%08X",
  728. p_dev->has_manf_id ? p_dev->manf_id : 0,
  729. p_dev->has_card_id ? p_dev->card_id : 0,
  730. p_dev->has_func_id ? p_dev->func_id : 0,
  731. p_dev->func,
  732. p_dev->device_no,
  733. hash[0],
  734. hash[1],
  735. hash[2],
  736. hash[3]))
  737. return -ENOMEM;
  738. envp[i] = NULL;
  739. return 0;
  740. }
  741. #else
  742. static int pcmcia_bus_uevent(struct device *dev, char **envp, int num_envp,
  743. char *buffer, int buffer_size)
  744. {
  745. return -ENODEV;
  746. }
  747. #endif
  748. /************************ per-device sysfs output ***************************/
  749. #define pcmcia_device_attr(field, test, format) \
  750. static ssize_t field##_show (struct device *dev, struct device_attribute *attr, char *buf) \
  751. { \
  752. struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \
  753. return p_dev->test ? sprintf (buf, format, p_dev->field) : -ENODEV; \
  754. }
  755. #define pcmcia_device_stringattr(name, field) \
  756. static ssize_t name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
  757. { \
  758. struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \
  759. return p_dev->field ? sprintf (buf, "%s\n", p_dev->field) : -ENODEV; \
  760. }
  761. pcmcia_device_attr(func, socket, "0x%02x\n");
  762. pcmcia_device_attr(func_id, has_func_id, "0x%02x\n");
  763. pcmcia_device_attr(manf_id, has_manf_id, "0x%04x\n");
  764. pcmcia_device_attr(card_id, has_card_id, "0x%04x\n");
  765. pcmcia_device_stringattr(prod_id1, prod_id[0]);
  766. pcmcia_device_stringattr(prod_id2, prod_id[1]);
  767. pcmcia_device_stringattr(prod_id3, prod_id[2]);
  768. pcmcia_device_stringattr(prod_id4, prod_id[3]);
  769. static ssize_t pcmcia_show_pm_state(struct device *dev, struct device_attribute *attr, char *buf)
  770. {
  771. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  772. if (p_dev->suspended)
  773. return sprintf(buf, "off\n");
  774. else
  775. return sprintf(buf, "on\n");
  776. }
  777. static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute *attr,
  778. const char *buf, size_t count)
  779. {
  780. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  781. int ret = 0;
  782. if (!count)
  783. return -EINVAL;
  784. if ((!p_dev->suspended) && !strncmp(buf, "off", 3))
  785. ret = dpm_runtime_suspend(dev, PMSG_SUSPEND);
  786. else if (p_dev->suspended && !strncmp(buf, "on", 2))
  787. dpm_runtime_resume(dev);
  788. return ret ? ret : count;
  789. }
  790. static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
  791. {
  792. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  793. int i;
  794. u32 hash[4] = { 0, 0, 0, 0};
  795. /* calculate hashes */
  796. for (i=0; i<4; i++) {
  797. if (!p_dev->prod_id[i])
  798. continue;
  799. hash[i] = crc32(0,p_dev->prod_id[i],strlen(p_dev->prod_id[i]));
  800. }
  801. return sprintf(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X"
  802. "pa%08Xpb%08Xpc%08Xpd%08X\n",
  803. p_dev->has_manf_id ? p_dev->manf_id : 0,
  804. p_dev->has_card_id ? p_dev->card_id : 0,
  805. p_dev->has_func_id ? p_dev->func_id : 0,
  806. p_dev->func, p_dev->device_no,
  807. hash[0], hash[1], hash[2], hash[3]);
  808. }
  809. static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
  810. struct device_attribute *attr, const char *buf, size_t count)
  811. {
  812. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  813. if (!count)
  814. return -EINVAL;
  815. mutex_lock(&p_dev->socket->skt_mutex);
  816. p_dev->allow_func_id_match = 1;
  817. mutex_unlock(&p_dev->socket->skt_mutex);
  818. bus_rescan_devices(&pcmcia_bus_type);
  819. return count;
  820. }
  821. static struct device_attribute pcmcia_dev_attrs[] = {
  822. __ATTR(function, 0444, func_show, NULL),
  823. __ATTR(pm_state, 0644, pcmcia_show_pm_state, pcmcia_store_pm_state),
  824. __ATTR_RO(func_id),
  825. __ATTR_RO(manf_id),
  826. __ATTR_RO(card_id),
  827. __ATTR_RO(prod_id1),
  828. __ATTR_RO(prod_id2),
  829. __ATTR_RO(prod_id3),
  830. __ATTR_RO(prod_id4),
  831. __ATTR_RO(modalias),
  832. __ATTR(allow_func_id_match, 0200, NULL, pcmcia_store_allow_func_id_match),
  833. __ATTR_NULL,
  834. };
  835. /* PM support, also needed for reset */
  836. static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
  837. {
  838. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  839. struct pcmcia_driver *p_drv = NULL;
  840. int ret = 0;
  841. if (dev->driver)
  842. p_drv = to_pcmcia_drv(dev->driver);
  843. if (!p_drv)
  844. goto out;
  845. if (p_drv->suspend) {
  846. ret = p_drv->suspend(p_dev);
  847. if (ret)
  848. goto out;
  849. }
  850. if (p_dev->device_no == p_dev->func)
  851. pcmcia_release_configuration(p_dev);
  852. out:
  853. if (!ret)
  854. p_dev->suspended = 1;
  855. return ret;
  856. }
  857. static int pcmcia_dev_resume(struct device * dev)
  858. {
  859. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  860. struct pcmcia_driver *p_drv = NULL;
  861. int ret = 0;
  862. if (dev->driver)
  863. p_drv = to_pcmcia_drv(dev->driver);
  864. if (!p_drv)
  865. goto out;
  866. if (p_dev->device_no == p_dev->func) {
  867. ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
  868. if (ret)
  869. goto out;
  870. }
  871. if (p_drv->resume)
  872. ret = p_drv->resume(p_dev);
  873. out:
  874. if (!ret)
  875. p_dev->suspended = 0;
  876. return ret;
  877. }
  878. static int pcmcia_bus_suspend_callback(struct device *dev, void * _data)
  879. {
  880. struct pcmcia_socket *skt = _data;
  881. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  882. if (p_dev->socket != skt)
  883. return 0;
  884. return dpm_runtime_suspend(dev, PMSG_SUSPEND);
  885. }
  886. static int pcmcia_bus_resume_callback(struct device *dev, void * _data)
  887. {
  888. struct pcmcia_socket *skt = _data;
  889. struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
  890. if (p_dev->socket != skt)
  891. return 0;
  892. dpm_runtime_resume(dev);
  893. return 0;
  894. }
  895. static int pcmcia_bus_resume(struct pcmcia_socket *skt)
  896. {
  897. bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback);
  898. return 0;
  899. }
  900. static int pcmcia_bus_suspend(struct pcmcia_socket *skt)
  901. {
  902. if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt,
  903. pcmcia_bus_suspend_callback)) {
  904. pcmcia_bus_resume(skt);
  905. return -EIO;
  906. }
  907. return 0;
  908. }
  909. /*======================================================================
  910. The card status event handler.
  911. ======================================================================*/
  912. /* Normally, the event is passed to individual drivers after
  913. * informing userspace. Only for CS_EVENT_CARD_REMOVAL this
  914. * is inversed to maintain historic compatibility.
  915. */
  916. static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
  917. {
  918. struct pcmcia_socket *s = pcmcia_get_socket(skt);
  919. if (!s) {
  920. printk(KERN_ERR "PCMCIA obtaining reference to socket %p " \
  921. "failed, event 0x%x lost!\n", skt, event);
  922. return -ENODEV;
  923. }
  924. ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n",
  925. event, priority, skt);
  926. switch (event) {
  927. case CS_EVENT_CARD_REMOVAL:
  928. s->pcmcia_state.present = 0;
  929. pcmcia_card_remove(skt, NULL);
  930. handle_event(skt, event);
  931. break;
  932. case CS_EVENT_CARD_INSERTION:
  933. s->pcmcia_state.present = 1;
  934. pcmcia_card_add(skt);
  935. handle_event(skt, event);
  936. break;
  937. case CS_EVENT_EJECTION_REQUEST:
  938. break;
  939. case CS_EVENT_PM_SUSPEND:
  940. case CS_EVENT_PM_RESUME:
  941. case CS_EVENT_RESET_PHYSICAL:
  942. case CS_EVENT_CARD_RESET:
  943. default:
  944. handle_event(skt, event);
  945. break;
  946. }
  947. pcmcia_put_socket(s);
  948. return 0;
  949. } /* ds_event */
  950. struct pcmcia_device * pcmcia_dev_present(struct pcmcia_device *_p_dev)
  951. {
  952. struct pcmcia_device *p_dev;
  953. struct pcmcia_device *ret = NULL;
  954. p_dev = pcmcia_get_dev(_p_dev);
  955. if (!p_dev)
  956. return NULL;
  957. if (!p_dev->socket->pcmcia_state.present)
  958. goto out;
  959. if (p_dev->_removed)
  960. goto out;
  961. if (p_dev->suspended)
  962. goto out;
  963. ret = p_dev;
  964. out:
  965. pcmcia_put_dev(p_dev);
  966. return ret;
  967. }
  968. EXPORT_SYMBOL(pcmcia_dev_present);
  969. static struct pcmcia_callback pcmcia_bus_callback = {
  970. .owner = THIS_MODULE,
  971. .event = ds_event,
  972. .requery = pcmcia_bus_rescan,
  973. .suspend = pcmcia_bus_suspend,
  974. .resume = pcmcia_bus_resume,
  975. };
  976. static int __devinit pcmcia_bus_add_socket(struct class_device *class_dev,
  977. struct class_interface *class_intf)
  978. {
  979. struct pcmcia_socket *socket = class_get_devdata(class_dev);
  980. int ret;
  981. socket = pcmcia_get_socket(socket);
  982. if (!socket) {
  983. printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket);
  984. return -ENODEV;
  985. }
  986. /*
  987. * Ugly. But we want to wait for the socket threads to have started up.
  988. * We really should let the drivers themselves drive some of this..
  989. */
  990. msleep(250);
  991. #ifdef CONFIG_PCMCIA_IOCTL
  992. init_waitqueue_head(&socket->queue);
  993. #endif
  994. INIT_LIST_HEAD(&socket->devices_list);
  995. INIT_WORK(&socket->device_add, pcmcia_delayed_add_pseudo_device, socket);
  996. memset(&socket->pcmcia_state, 0, sizeof(u8));
  997. socket->device_count = 0;
  998. ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback);
  999. if (ret) {
  1000. printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket);
  1001. pcmcia_put_socket(socket);
  1002. return (ret);
  1003. }
  1004. return 0;
  1005. }
  1006. static void pcmcia_bus_remove_socket(struct class_device *class_dev,
  1007. struct class_interface *class_intf)
  1008. {
  1009. struct pcmcia_socket *socket = class_get_devdata(class_dev);
  1010. if (!socket)
  1011. return;
  1012. socket->pcmcia_state.dead = 1;
  1013. pccard_register_pcmcia(socket, NULL);
  1014. pcmcia_put_socket(socket);
  1015. return;
  1016. }
  1017. /* the pcmcia_bus_interface is used to handle pcmcia socket devices */
  1018. static struct class_interface pcmcia_bus_interface = {
  1019. .class = &pcmcia_socket_class,
  1020. .add = &pcmcia_bus_add_socket,
  1021. .remove = &pcmcia_bus_remove_socket,
  1022. };
  1023. struct bus_type pcmcia_bus_type = {
  1024. .name = "pcmcia",
  1025. .uevent = pcmcia_bus_uevent,
  1026. .match = pcmcia_bus_match,
  1027. .dev_attrs = pcmcia_dev_attrs,
  1028. .probe = pcmcia_device_probe,
  1029. .remove = pcmcia_device_remove,
  1030. .suspend = pcmcia_dev_suspend,
  1031. .resume = pcmcia_dev_resume,
  1032. };
  1033. static int __init init_pcmcia_bus(void)
  1034. {
  1035. spin_lock_init(&pcmcia_dev_list_lock);
  1036. bus_register(&pcmcia_bus_type);
  1037. class_interface_register(&pcmcia_bus_interface);
  1038. pcmcia_setup_ioctl();
  1039. return 0;
  1040. }
  1041. fs_initcall(init_pcmcia_bus); /* one level after subsys_initcall so that
  1042. * pcmcia_socket_class is already registered */
  1043. static void __exit exit_pcmcia_bus(void)
  1044. {
  1045. pcmcia_cleanup_ioctl();
  1046. class_interface_unregister(&pcmcia_bus_interface);
  1047. bus_unregister(&pcmcia_bus_type);
  1048. }
  1049. module_exit(exit_pcmcia_bus);
  1050. MODULE_ALIAS("ds");