PageRenderTime 65ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/release/src-rt-6.x/linux/linux-2.6/arch/arm26/kernel/ecard.c

https://gitlab.com/envieidoc/advancedtomato2
C | 847 lines | 617 code | 139 blank | 91 comment | 96 complexity | 5fe56bd728188d12d7ba3624e5502e7e MD5 | raw file
  1. /*
  2. * linux/arch/arm26/kernel/ecard.c
  3. *
  4. * Copyright 1995-2001 Russell King
  5. * Copyright 2003 Ian Molton
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Find all installed expansion cards, and handle interrupts from them.
  12. *
  13. * Created from information from Acorns RiscOS3 PRMs
  14. * 15-Jun-2003 IM Modified from ARM32 (RiscPC capable) version
  15. * 10-Jan-1999 RMK Run loaders in a simulated RISC OS environment.
  16. * 06-May-1997 RMK Added blacklist for cards whose loader doesn't work.
  17. * 12-Sep-1997 RMK Created new handling of interrupt enables/disables
  18. * - cards can now register their own routine to control
  19. * interrupts (recommended).
  20. * 29-Sep-1997 RMK Expansion card interrupt hardware not being re-enabled
  21. * on reset from Linux. (Caused cards not to respond
  22. * under RiscOS without hard reset).
  23. *
  24. */
  25. #define ECARD_C
  26. #include <linux/module.h>
  27. #include <linux/kernel.h>
  28. #include <linux/types.h>
  29. #include <linux/sched.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/reboot.h>
  32. #include <linux/mm.h>
  33. #include <linux/slab.h>
  34. #include <linux/proc_fs.h>
  35. #include <linux/device.h>
  36. #include <linux/init.h>
  37. #include <asm/dma.h>
  38. #include <asm/ecard.h>
  39. #include <asm/hardware.h>
  40. #include <asm/io.h>
  41. #include <asm/irq.h>
  42. #include <asm/mmu_context.h>
  43. #include <asm/irqchip.h>
  44. #include <asm/tlbflush.h>
  45. enum req {
  46. req_readbytes,
  47. req_reset
  48. };
  49. struct ecard_request {
  50. enum req req;
  51. ecard_t *ec;
  52. unsigned int address;
  53. unsigned int length;
  54. unsigned int use_loader;
  55. void *buffer;
  56. };
  57. struct expcard_blacklist {
  58. unsigned short manufacturer;
  59. unsigned short product;
  60. const char *type;
  61. };
  62. static ecard_t *cards;
  63. static ecard_t *slot_to_expcard[MAX_ECARDS];
  64. static unsigned int ectcr;
  65. /* List of descriptions of cards which don't have an extended
  66. * identification, or chunk directories containing a description.
  67. */
  68. static struct expcard_blacklist __initdata blacklist[] = {
  69. { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
  70. };
  71. asmlinkage extern int
  72. ecard_loader_reset(volatile unsigned char *pa, loader_t loader);
  73. asmlinkage extern int
  74. ecard_loader_read(int off, volatile unsigned char *pa, loader_t loader);
  75. static const struct ecard_id *
  76. ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec);
  77. static inline unsigned short
  78. ecard_getu16(unsigned char *v)
  79. {
  80. return v[0] | v[1] << 8;
  81. }
  82. static inline signed long
  83. ecard_gets24(unsigned char *v)
  84. {
  85. return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
  86. }
  87. static inline ecard_t *
  88. slot_to_ecard(unsigned int slot)
  89. {
  90. return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
  91. }
  92. /* ===================== Expansion card daemon ======================== */
  93. /*
  94. * Since the loader programs on the expansion cards need to be run
  95. * in a specific environment, create a separate task with this
  96. * environment up, and pass requests to this task as and when we
  97. * need to.
  98. *
  99. * This should allow 99% of loaders to be called from Linux.
  100. *
  101. * From a security standpoint, we trust the card vendors. This
  102. * may be a misplaced trust.
  103. */
  104. #define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
  105. #define POD_INT_ADDR(x) ((volatile unsigned char *)\
  106. ((BUS_ADDR((x)) - IO_BASE) + IO_START))
  107. static inline void ecard_task_reset(struct ecard_request *req)
  108. {
  109. struct expansion_card *ec = req->ec;
  110. if (ec->loader)
  111. ecard_loader_reset(POD_INT_ADDR(ec->podaddr), ec->loader);
  112. }
  113. static void
  114. ecard_task_readbytes(struct ecard_request *req)
  115. {
  116. unsigned char *buf = (unsigned char *)req->buffer;
  117. volatile unsigned char *base_addr =
  118. (volatile unsigned char *)POD_INT_ADDR(req->ec->podaddr);
  119. unsigned int len = req->length;
  120. unsigned int off = req->address;
  121. if (!req->use_loader || !req->ec->loader) {
  122. off *= 4;
  123. while (len--) {
  124. *buf++ = base_addr[off];
  125. off += 4;
  126. }
  127. } else {
  128. while(len--) {
  129. /*
  130. * The following is required by some
  131. * expansion card loader programs.
  132. */
  133. *(unsigned long *)0x108 = 0;
  134. *buf++ = ecard_loader_read(off++, base_addr,
  135. req->ec->loader);
  136. }
  137. }
  138. }
  139. static void ecard_do_request(struct ecard_request *req)
  140. {
  141. switch (req->req) {
  142. case req_readbytes:
  143. ecard_task_readbytes(req);
  144. break;
  145. case req_reset:
  146. ecard_task_reset(req);
  147. break;
  148. }
  149. }
  150. /*
  151. * On 26-bit processors, we don't need the kcardd thread to access the
  152. * expansion card loaders. We do it directly.
  153. */
  154. #define ecard_call(req) ecard_do_request(req)
  155. /* ======================= Mid-level card control ===================== */
  156. static void
  157. ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
  158. {
  159. struct ecard_request req;
  160. req.req = req_readbytes;
  161. req.ec = ec;
  162. req.address = off;
  163. req.length = len;
  164. req.use_loader = useld;
  165. req.buffer = addr;
  166. ecard_call(&req);
  167. }
  168. int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
  169. {
  170. struct ex_chunk_dir excd;
  171. int index = 16;
  172. int useld = 0;
  173. if (!ec->cid.cd)
  174. return 0;
  175. while(1) {
  176. ecard_readbytes(&excd, ec, index, 8, useld);
  177. index += 8;
  178. if (c_id(&excd) == 0) {
  179. if (!useld && ec->loader) {
  180. useld = 1;
  181. index = 0;
  182. continue;
  183. }
  184. return 0;
  185. }
  186. if (c_id(&excd) == 0xf0) { /* link */
  187. index = c_start(&excd);
  188. continue;
  189. }
  190. if (c_id(&excd) == 0x80) { /* loader */
  191. if (!ec->loader) {
  192. ec->loader = kmalloc(c_len(&excd),
  193. GFP_KERNEL);
  194. if (ec->loader)
  195. ecard_readbytes(ec->loader, ec,
  196. (int)c_start(&excd),
  197. c_len(&excd), useld);
  198. else
  199. return 0;
  200. }
  201. continue;
  202. }
  203. if (c_id(&excd) == id && num-- == 0)
  204. break;
  205. }
  206. if (c_id(&excd) & 0x80) {
  207. switch (c_id(&excd) & 0x70) {
  208. case 0x70:
  209. ecard_readbytes((unsigned char *)excd.d.string, ec,
  210. (int)c_start(&excd), c_len(&excd),
  211. useld);
  212. break;
  213. case 0x00:
  214. break;
  215. }
  216. }
  217. cd->start_offset = c_start(&excd);
  218. memcpy(cd->d.string, excd.d.string, 256);
  219. return 1;
  220. }
  221. /* ======================= Interrupt control ============================ */
  222. static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
  223. {
  224. }
  225. static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
  226. {
  227. }
  228. static int ecard_def_irq_pending(ecard_t *ec)
  229. {
  230. return !ec->irqmask || ec->irqaddr[0] & ec->irqmask;
  231. }
  232. static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
  233. {
  234. panic("ecard_def_fiq_enable called - impossible");
  235. }
  236. static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
  237. {
  238. panic("ecard_def_fiq_disable called - impossible");
  239. }
  240. static int ecard_def_fiq_pending(ecard_t *ec)
  241. {
  242. return !ec->fiqmask || ec->fiqaddr[0] & ec->fiqmask;
  243. }
  244. static expansioncard_ops_t ecard_default_ops = {
  245. ecard_def_irq_enable,
  246. ecard_def_irq_disable,
  247. ecard_def_irq_pending,
  248. ecard_def_fiq_enable,
  249. ecard_def_fiq_disable,
  250. ecard_def_fiq_pending
  251. };
  252. /*
  253. * Enable and disable interrupts from expansion cards.
  254. * (interrupts are disabled for these functions).
  255. *
  256. * They are not meant to be called directly, but via enable/disable_irq.
  257. */
  258. static void ecard_irq_unmask(unsigned int irqnr)
  259. {
  260. ecard_t *ec = slot_to_ecard(irqnr - 32);
  261. if (ec) {
  262. if (!ec->ops)
  263. ec->ops = &ecard_default_ops;
  264. if (ec->claimed && ec->ops->irqenable)
  265. ec->ops->irqenable(ec, irqnr);
  266. else
  267. printk(KERN_ERR "ecard: rejecting request to "
  268. "enable IRQs for %d\n", irqnr);
  269. }
  270. }
  271. static void ecard_irq_mask(unsigned int irqnr)
  272. {
  273. ecard_t *ec = slot_to_ecard(irqnr - 32);
  274. if (ec) {
  275. if (!ec->ops)
  276. ec->ops = &ecard_default_ops;
  277. if (ec->ops && ec->ops->irqdisable)
  278. ec->ops->irqdisable(ec, irqnr);
  279. }
  280. }
  281. static struct irqchip ecard_chip = {
  282. .ack = ecard_irq_mask,
  283. .mask = ecard_irq_mask,
  284. .unmask = ecard_irq_unmask,
  285. };
  286. void ecard_enablefiq(unsigned int fiqnr)
  287. {
  288. ecard_t *ec = slot_to_ecard(fiqnr);
  289. if (ec) {
  290. if (!ec->ops)
  291. ec->ops = &ecard_default_ops;
  292. if (ec->claimed && ec->ops->fiqenable)
  293. ec->ops->fiqenable(ec, fiqnr);
  294. else
  295. printk(KERN_ERR "ecard: rejecting request to "
  296. "enable FIQs for %d\n", fiqnr);
  297. }
  298. }
  299. void ecard_disablefiq(unsigned int fiqnr)
  300. {
  301. ecard_t *ec = slot_to_ecard(fiqnr);
  302. if (ec) {
  303. if (!ec->ops)
  304. ec->ops = &ecard_default_ops;
  305. if (ec->ops->fiqdisable)
  306. ec->ops->fiqdisable(ec, fiqnr);
  307. }
  308. }
  309. static void
  310. ecard_dump_irq_state(ecard_t *ec)
  311. {
  312. printk(" %d: %sclaimed, ",
  313. ec->slot_no,
  314. ec->claimed ? "" : "not ");
  315. if (ec->ops && ec->ops->irqpending &&
  316. ec->ops != &ecard_default_ops)
  317. printk("irq %spending\n",
  318. ec->ops->irqpending(ec) ? "" : "not ");
  319. else
  320. printk("irqaddr %p, mask = %02X, status = %02X\n",
  321. ec->irqaddr, ec->irqmask, *ec->irqaddr);
  322. }
  323. static void ecard_check_lockup(struct irqdesc *desc)
  324. {
  325. static int last, lockup;
  326. ecard_t *ec;
  327. /*
  328. * If the timer interrupt has not run since the last million
  329. * unrecognised expansion card interrupts, then there is
  330. * something seriously wrong. Disable the expansion card
  331. * interrupts so at least we can continue.
  332. *
  333. * Maybe we ought to start a timer to re-enable them some time
  334. * later?
  335. */
  336. if (last == jiffies) {
  337. lockup += 1;
  338. if (lockup > 1000000) {
  339. printk(KERN_ERR "\nInterrupt lockup detected - "
  340. "disabling all expansion card interrupts\n");
  341. desc->chip->mask(IRQ_EXPANSIONCARD);
  342. printk("Expansion card IRQ state:\n");
  343. for (ec = cards; ec; ec = ec->next)
  344. ecard_dump_irq_state(ec);
  345. }
  346. } else
  347. lockup = 0;
  348. /*
  349. * If we did not recognise the source of this interrupt,
  350. * warn the user, but don't flood the user with these messages.
  351. */
  352. if (!last || time_after(jiffies, (unsigned long)(last + 5*HZ))) {
  353. last = jiffies;
  354. printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
  355. }
  356. }
  357. static void
  358. ecard_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
  359. {
  360. ecard_t *ec;
  361. int called = 0;
  362. desc->chip->mask(irq);
  363. for (ec = cards; ec; ec = ec->next) {
  364. int pending;
  365. if (!ec->claimed || ec->irq == NO_IRQ)
  366. continue;
  367. if (ec->ops && ec->ops->irqpending)
  368. pending = ec->ops->irqpending(ec);
  369. else
  370. pending = ecard_default_ops.irqpending(ec);
  371. if (pending) {
  372. struct irqdesc *d = irq_desc + ec->irq;
  373. d->handle(ec->irq, d, regs);
  374. called ++;
  375. }
  376. }
  377. desc->chip->unmask(irq);
  378. if (called == 0)
  379. ecard_check_lockup(desc);
  380. }
  381. #define ecard_irqexp_handler NULL
  382. #define ecard_probeirqhw() (0)
  383. unsigned int ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
  384. {
  385. unsigned long address = 0;
  386. int slot = ec->slot_no;
  387. ectcr &= ~(1 << slot);
  388. switch (type) {
  389. case ECARD_MEMC:
  390. address = IO_EC_MEMC_BASE + (slot << 12);
  391. break;
  392. case ECARD_IOC:
  393. address = IO_EC_IOC_BASE + (slot << 12) + (speed << 17);
  394. break;
  395. default:
  396. break;
  397. }
  398. return address;
  399. }
  400. static int ecard_prints(char *buffer, ecard_t *ec)
  401. {
  402. char *start = buffer;
  403. buffer += sprintf(buffer, " %d: ", ec->slot_no);
  404. if (ec->cid.id == 0) {
  405. struct in_chunk_dir incd;
  406. buffer += sprintf(buffer, "[%04X:%04X] ",
  407. ec->cid.manufacturer, ec->cid.product);
  408. if (!ec->card_desc && ec->cid.cd &&
  409. ecard_readchunk(&incd, ec, 0xf5, 0)) {
  410. ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
  411. if (ec->card_desc)
  412. strcpy((char *)ec->card_desc, incd.d.string);
  413. }
  414. buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
  415. } else
  416. buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);
  417. return buffer - start;
  418. }
  419. static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count)
  420. {
  421. ecard_t *ec = cards;
  422. off_t at = 0;
  423. int len, cnt;
  424. cnt = 0;
  425. while (ec && count > cnt) {
  426. len = ecard_prints(buf, ec);
  427. at += len;
  428. if (at >= pos) {
  429. if (!*start) {
  430. *start = buf + (pos - (at - len));
  431. cnt = at - pos;
  432. } else
  433. cnt += len;
  434. buf += len;
  435. }
  436. ec = ec->next;
  437. }
  438. return (count > cnt) ? cnt : count;
  439. }
  440. static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
  441. static void ecard_proc_init(void)
  442. {
  443. proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);
  444. create_proc_info_entry("devices", 0, proc_bus_ecard_dir,
  445. get_ecard_dev_info);
  446. }
  447. #define ec_set_resource(ec,nr,st,sz,flg) \
  448. do { \
  449. (ec)->resource[nr].name = ec->dev.bus_id; \
  450. (ec)->resource[nr].start = st; \
  451. (ec)->resource[nr].end = (st) + (sz) - 1; \
  452. (ec)->resource[nr].flags = flg; \
  453. } while (0)
  454. static void __init ecard_init_resources(struct expansion_card *ec)
  455. {
  456. unsigned long base = PODSLOT_IOC0_BASE;
  457. unsigned int slot = ec->slot_no;
  458. int i;
  459. ec_set_resource(ec, ECARD_RES_MEMC,
  460. PODSLOT_MEMC_BASE + (slot << 14),
  461. PODSLOT_MEMC_SIZE, IORESOURCE_MEM);
  462. for (i = 0; i < ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++) {
  463. ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
  464. base + (slot << 14) + (i << 19),
  465. PODSLOT_IOC_SIZE, IORESOURCE_MEM);
  466. }
  467. for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
  468. if (ec->resource[i].start &&
  469. request_resource(&iomem_resource, &ec->resource[i])) {
  470. printk(KERN_ERR "%s: resource(s) not available\n",
  471. ec->dev.bus_id);
  472. ec->resource[i].end -= ec->resource[i].start;
  473. ec->resource[i].start = 0;
  474. }
  475. }
  476. }
  477. static ssize_t ecard_show_irq(struct device *dev, struct device_attribute *attr, char *buf)
  478. {
  479. struct expansion_card *ec = ECARD_DEV(dev);
  480. return sprintf(buf, "%u\n", ec->irq);
  481. }
  482. static ssize_t ecard_show_vendor(struct device *dev, struct device_attribute *attr, char *buf)
  483. {
  484. struct expansion_card *ec = ECARD_DEV(dev);
  485. return sprintf(buf, "%u\n", ec->cid.manufacturer);
  486. }
  487. static ssize_t ecard_show_device(struct device *dev, struct device_attribute *attr, char *buf)
  488. {
  489. struct expansion_card *ec = ECARD_DEV(dev);
  490. return sprintf(buf, "%u\n", ec->cid.product);
  491. }
  492. static ssize_t ecard_show_dma(struct device *dev, struct device_attribute *attr, char *buf)
  493. {
  494. struct expansion_card *ec = ECARD_DEV(dev);
  495. return sprintf(buf, "%u\n", ec->dma);
  496. }
  497. static ssize_t ecard_show_resources(struct device *dev, struct device_attribute *attr, char *buf)
  498. {
  499. struct expansion_card *ec = ECARD_DEV(dev);
  500. char *str = buf;
  501. int i;
  502. for (i = 0; i < ECARD_NUM_RESOURCES; i++)
  503. str += sprintf(str, "%08lx %08lx %08lx\n",
  504. ec->resource[i].start,
  505. ec->resource[i].end,
  506. ec->resource[i].flags);
  507. return str - buf;
  508. }
  509. static DEVICE_ATTR(irq, S_IRUGO, ecard_show_irq, NULL);
  510. static DEVICE_ATTR(vendor, S_IRUGO, ecard_show_vendor, NULL);
  511. static DEVICE_ATTR(device, S_IRUGO, ecard_show_device, NULL);
  512. static DEVICE_ATTR(dma, S_IRUGO, ecard_show_dma, NULL);
  513. static DEVICE_ATTR(resource, S_IRUGO, ecard_show_resources, NULL);
  514. /*
  515. * Probe for an expansion card.
  516. *
  517. * If bit 1 of the first byte of the card is set, then the
  518. * card does not exist.
  519. */
  520. static int __init
  521. ecard_probe(int slot, card_type_t type)
  522. {
  523. ecard_t **ecp;
  524. ecard_t *ec;
  525. struct ex_ecid cid;
  526. int i, rc = -ENOMEM;
  527. ec = kzalloc(sizeof(ecard_t), GFP_KERNEL);
  528. if (!ec)
  529. goto nomem;
  530. ec->slot_no = slot;
  531. ec->type = type;
  532. ec->irq = NO_IRQ;
  533. ec->fiq = NO_IRQ;
  534. ec->dma = NO_DMA;
  535. ec->card_desc = NULL;
  536. ec->ops = &ecard_default_ops;
  537. rc = -ENODEV;
  538. if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
  539. goto nodev;
  540. cid.r_zero = 1;
  541. ecard_readbytes(&cid, ec, 0, 16, 0);
  542. if (cid.r_zero)
  543. goto nodev;
  544. ec->cid.id = cid.r_id;
  545. ec->cid.cd = cid.r_cd;
  546. ec->cid.is = cid.r_is;
  547. ec->cid.w = cid.r_w;
  548. ec->cid.manufacturer = ecard_getu16(cid.r_manu);
  549. ec->cid.product = ecard_getu16(cid.r_prod);
  550. ec->cid.country = cid.r_country;
  551. ec->cid.irqmask = cid.r_irqmask;
  552. ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
  553. ec->cid.fiqmask = cid.r_fiqmask;
  554. ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
  555. ec->fiqaddr =
  556. ec->irqaddr = (unsigned char *)ioaddr(ec->podaddr);
  557. if (ec->cid.is) {
  558. ec->irqmask = ec->cid.irqmask;
  559. ec->irqaddr += ec->cid.irqoff;
  560. ec->fiqmask = ec->cid.fiqmask;
  561. ec->fiqaddr += ec->cid.fiqoff;
  562. } else {
  563. ec->irqmask = 1;
  564. ec->fiqmask = 4;
  565. }
  566. for (i = 0; i < ARRAY_SIZE(blacklist); i++)
  567. if (blacklist[i].manufacturer == ec->cid.manufacturer &&
  568. blacklist[i].product == ec->cid.product) {
  569. ec->card_desc = blacklist[i].type;
  570. break;
  571. }
  572. snprintf(ec->dev.bus_id, sizeof(ec->dev.bus_id), "ecard%d", slot);
  573. ec->dev.parent = NULL;
  574. ec->dev.bus = &ecard_bus_type;
  575. ec->dev.dma_mask = &ec->dma_mask;
  576. ec->dma_mask = (u64)0xffffffff;
  577. ecard_init_resources(ec);
  578. /*
  579. * hook the interrupt handlers
  580. */
  581. ec->irq = 32 + slot;
  582. set_irq_chip(ec->irq, &ecard_chip);
  583. set_irq_handler(ec->irq, do_level_IRQ);
  584. set_irq_flags(ec->irq, IRQF_VALID);
  585. for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
  586. *ecp = ec;
  587. slot_to_expcard[slot] = ec;
  588. device_register(&ec->dev);
  589. device_create_file(&ec->dev, &dev_attr_dma);
  590. device_create_file(&ec->dev, &dev_attr_irq);
  591. device_create_file(&ec->dev, &dev_attr_resource);
  592. device_create_file(&ec->dev, &dev_attr_vendor);
  593. device_create_file(&ec->dev, &dev_attr_device);
  594. return 0;
  595. nodev:
  596. kfree(ec);
  597. nomem:
  598. return rc;
  599. }
  600. /*
  601. * Initialise the expansion card system.
  602. * Locate all hardware - interrupt management and
  603. * actual cards.
  604. */
  605. static int __init ecard_init(void)
  606. {
  607. int slot, irqhw;
  608. printk("Probing expansion cards\n");
  609. for (slot = 0; slot < MAX_ECARDS; slot ++) {
  610. ecard_probe(slot, ECARD_IOC);
  611. }
  612. irqhw = ecard_probeirqhw();
  613. set_irq_chained_handler(IRQ_EXPANSIONCARD,
  614. irqhw ? ecard_irqexp_handler : ecard_irq_handler);
  615. ecard_proc_init();
  616. return 0;
  617. }
  618. subsys_initcall(ecard_init);
  619. /*
  620. * ECARD "bus"
  621. */
  622. static const struct ecard_id *
  623. ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
  624. {
  625. int i;
  626. for (i = 0; ids[i].manufacturer != 65535; i++)
  627. if (ec->cid.manufacturer == ids[i].manufacturer &&
  628. ec->cid.product == ids[i].product)
  629. return ids + i;
  630. return NULL;
  631. }
  632. static int ecard_drv_probe(struct device *dev)
  633. {
  634. struct expansion_card *ec = ECARD_DEV(dev);
  635. struct ecard_driver *drv = ECARD_DRV(dev->driver);
  636. const struct ecard_id *id;
  637. int ret;
  638. id = ecard_match_device(drv->id_table, ec);
  639. ecard_claim(ec);
  640. ret = drv->probe(ec, id);
  641. if (ret)
  642. ecard_release(ec);
  643. return ret;
  644. }
  645. static int ecard_drv_remove(struct device *dev)
  646. {
  647. struct expansion_card *ec = ECARD_DEV(dev);
  648. struct ecard_driver *drv = ECARD_DRV(dev->driver);
  649. drv->remove(ec);
  650. ecard_release(ec);
  651. return 0;
  652. }
  653. /*
  654. * Before rebooting, we must make sure that the expansion card is in a
  655. * sensible state, so it can be re-detected. This means that the first
  656. * page of the ROM must be visible. We call the expansion cards reset
  657. * handler, if any.
  658. */
  659. static void ecard_drv_shutdown(struct device *dev)
  660. {
  661. struct expansion_card *ec = ECARD_DEV(dev);
  662. struct ecard_driver *drv = ECARD_DRV(dev->driver);
  663. struct ecard_request req;
  664. if (drv->shutdown)
  665. drv->shutdown(ec);
  666. ecard_release(ec);
  667. req.req = req_reset;
  668. req.ec = ec;
  669. ecard_call(&req);
  670. }
  671. int ecard_register_driver(struct ecard_driver *drv)
  672. {
  673. drv->drv.bus = &ecard_bus_type;
  674. drv->drv.probe = ecard_drv_probe;
  675. drv->drv.remove = ecard_drv_remove;
  676. drv->drv.shutdown = ecard_drv_shutdown;
  677. return driver_register(&drv->drv);
  678. }
  679. void ecard_remove_driver(struct ecard_driver *drv)
  680. {
  681. driver_unregister(&drv->drv);
  682. }
  683. static int ecard_match(struct device *_dev, struct device_driver *_drv)
  684. {
  685. struct expansion_card *ec = ECARD_DEV(_dev);
  686. struct ecard_driver *drv = ECARD_DRV(_drv);
  687. int ret;
  688. if (drv->id_table) {
  689. ret = ecard_match_device(drv->id_table, ec) != NULL;
  690. } else {
  691. ret = ec->cid.id == drv->id;
  692. }
  693. return ret;
  694. }
  695. struct bus_type ecard_bus_type = {
  696. .name = "ecard",
  697. .match = ecard_match,
  698. };
  699. static int ecard_bus_init(void)
  700. {
  701. return bus_register(&ecard_bus_type);
  702. }
  703. postcore_initcall(ecard_bus_init);
  704. EXPORT_SYMBOL(ecard_readchunk);
  705. EXPORT_SYMBOL(ecard_address);
  706. EXPORT_SYMBOL(ecard_register_driver);
  707. EXPORT_SYMBOL(ecard_remove_driver);
  708. EXPORT_SYMBOL(ecard_bus_type);