2 * linux/arch/arm/kernel/ecard.c
4 * Copyright 1995-2001 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Find all installed expansion cards, and handle interrupts from them.
12 * Created from information from Acorns RiscOS3 PRMs
14 * 08-Dec-1996 RMK Added code for the 9'th expansion card - the ether
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 * 15-Feb-1998 RMK Added DMA support
24 * 12-Sep-1998 RMK Added EASI support
25 * 10-Jan-1999 RMK Run loaders in a simulated RISC OS environment.
26 * 17-Apr-1999 RMK Support for EASI Type C cycles.
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/sched.h>
35 #include <linux/interrupt.h>
36 #include <linux/completion.h>
37 #include <linux/reboot.h>
39 #include <linux/slab.h>
40 #include <linux/proc_fs.h>
41 #include <linux/device.h>
42 #include <linux/init.h>
45 #include <asm/ecard.h>
46 #include <asm/hardware.h>
49 #include <asm/mmu_context.h>
50 #include <asm/mach/irq.h>
51 #include <asm/tlbflush.h>
53 #ifndef CONFIG_ARCH_RPC
57 struct ecard_request {
58 void (*fn)(struct ecard_request *);
62 unsigned int use_loader;
64 struct completion *complete;
67 struct expcard_blacklist {
68 unsigned short manufacturer;
69 unsigned short product;
73 static ecard_t *cards;
74 static ecard_t *slot_to_expcard[MAX_ECARDS];
75 static unsigned int ectcr;
77 static unsigned int have_expmask;
80 /* List of descriptions of cards which don't have an extended
81 * identification, or chunk directories containing a description.
83 static struct expcard_blacklist __initdata blacklist[] = {
84 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
88 ecard_loader_reset(unsigned long base, loader_t loader);
90 ecard_loader_read(int off, unsigned long base, loader_t loader);
92 static inline unsigned short ecard_getu16(unsigned char *v)
94 return v[0] | v[1] << 8;
97 static inline signed long ecard_gets24(unsigned char *v)
99 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
102 static inline ecard_t *slot_to_ecard(unsigned int slot)
104 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
107 /* ===================== Expansion card daemon ======================== */
109 * Since the loader programs on the expansion cards need to be run
110 * in a specific environment, create a separate task with this
111 * environment up, and pass requests to this task as and when we
114 * This should allow 99% of loaders to be called from Linux.
116 * From a security standpoint, we trust the card vendors. This
117 * may be a misplaced trust.
119 static void ecard_task_reset(struct ecard_request *req)
121 struct expansion_card *ec = req->ec;
122 struct resource *res;
124 res = ec->slot_no == 8
125 ? &ec->resource[ECARD_RES_MEMC]
126 : ec->type == ECARD_EASI
127 ? &ec->resource[ECARD_RES_EASI]
128 : &ec->resource[ECARD_RES_IOCSYNC];
130 ecard_loader_reset(res->start, ec->loader);
133 static void ecard_task_readbytes(struct ecard_request *req)
135 struct expansion_card *ec = req->ec;
136 unsigned char *buf = req->buffer;
137 unsigned int len = req->length;
138 unsigned int off = req->address;
140 if (ec->slot_no == 8) {
141 void __iomem *base = (void __iomem *)
142 ec->resource[ECARD_RES_MEMC].start;
145 * The card maintains an index which increments the address
146 * into a 4096-byte page on each access. We need to keep
147 * track of the counter.
149 static unsigned int index;
152 page = (off >> 12) * 4;
159 * If we are reading offset 0, or our current index is
160 * greater than the offset, reset the hardware index counter.
162 if (off == 0 || index > off) {
168 * Increment the hardware index counter until we get to the
169 * required offset. The read bytes are discarded.
171 while (index < off) {
177 *buf++ = readb(base + page);
181 unsigned long base = (ec->type == ECARD_EASI
182 ? &ec->resource[ECARD_RES_EASI]
183 : &ec->resource[ECARD_RES_IOCSYNC])->start;
184 void __iomem *pbase = (void __iomem *)base;
186 if (!req->use_loader || !ec->loader) {
189 *buf++ = readb(pbase + off);
195 * The following is required by some
196 * expansion card loader programs.
198 *(unsigned long *)0x108 = 0;
199 *buf++ = ecard_loader_read(off++, base,
207 static DECLARE_WAIT_QUEUE_HEAD(ecard_wait);
208 static struct ecard_request *ecard_req;
209 static DECLARE_MUTEX(ecard_sem);
212 * Set up the expansion card daemon's page tables.
214 static void ecard_init_pgtables(struct mm_struct *mm)
216 struct vm_area_struct vma;
218 /* We want to set up the page tables for the following mapping:
220 * 0x03000000 0x03000000
221 * 0x03010000 unmapped
222 * 0x03210000 0x03210000
223 * 0x03400000 unmapped
224 * 0x08000000 0x08000000
225 * 0x10000000 unmapped
227 * FIXME: we don't follow this 100% yet.
229 pgd_t *src_pgd, *dst_pgd;
231 src_pgd = pgd_offset(mm, (unsigned long)IO_BASE);
232 dst_pgd = pgd_offset(mm, IO_START);
234 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (IO_SIZE / PGDIR_SIZE));
236 src_pgd = pgd_offset(mm, EASI_BASE);
237 dst_pgd = pgd_offset(mm, EASI_START);
239 memcpy(dst_pgd, src_pgd, sizeof(pgd_t) * (EASI_SIZE / PGDIR_SIZE));
243 flush_tlb_range(&vma, IO_START, IO_START + IO_SIZE);
244 flush_tlb_range(&vma, EASI_START, EASI_START + EASI_SIZE);
247 static int ecard_init_mm(void)
249 struct mm_struct * mm = mm_alloc();
250 struct mm_struct *active_mm = current->active_mm;
256 current->active_mm = mm;
257 activate_mm(active_mm, mm);
259 ecard_init_pgtables(mm);
264 ecard_task(void * unused)
266 daemonize("kecardd");
269 * Allocate a mm. We're not a lazy-TLB kernel task since we need
270 * to set page table entries where the user space would be. Note
271 * that this also creates the page tables. Failure is not an
275 panic("kecardd: unable to alloc mm\n");
278 struct ecard_request *req;
280 wait_event_interruptible(ecard_wait, ecard_req != NULL);
282 req = xchg(&ecard_req, NULL);
285 complete(req->complete);
291 * Wake the expansion card daemon to action our request.
293 * FIXME: The test here is not sufficient to detect if the
296 static void ecard_call(struct ecard_request *req)
298 DECLARE_COMPLETION(completion);
300 req->complete = &completion;
304 wake_up(&ecard_wait);
307 * Now wait for kecardd to run.
309 wait_for_completion(&completion);
313 /* ======================= Mid-level card control ===================== */
316 ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
318 struct ecard_request req;
320 req.fn = ecard_task_readbytes;
324 req.use_loader = useld;
330 int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
332 struct ex_chunk_dir excd;
340 ecard_readbytes(&excd, ec, index, 8, useld);
342 if (c_id(&excd) == 0) {
343 if (!useld && ec->loader) {
350 if (c_id(&excd) == 0xf0) { /* link */
351 index = c_start(&excd);
354 if (c_id(&excd) == 0x80) { /* loader */
356 ec->loader = (loader_t)kmalloc(c_len(&excd),
359 ecard_readbytes(ec->loader, ec,
361 c_len(&excd), useld);
367 if (c_id(&excd) == id && num-- == 0)
371 if (c_id(&excd) & 0x80) {
372 switch (c_id(&excd) & 0x70) {
374 ecard_readbytes((unsigned char *)excd.d.string, ec,
375 (int)c_start(&excd), c_len(&excd),
382 cd->start_offset = c_start(&excd);
383 memcpy(cd->d.string, excd.d.string, 256);
387 /* ======================= Interrupt control ============================ */
389 static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
392 if (irqnr < 4 && have_expmask) {
393 have_expmask |= 1 << irqnr;
394 __raw_writeb(have_expmask, EXPMASK_ENABLE);
399 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
402 if (irqnr < 4 && have_expmask) {
403 have_expmask &= ~(1 << irqnr);
404 __raw_writeb(have_expmask, EXPMASK_ENABLE);
409 static int ecard_def_irq_pending(ecard_t *ec)
411 return !ec->irqmask || readb(ec->irqaddr) & ec->irqmask;
414 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
416 panic("ecard_def_fiq_enable called - impossible");
419 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
421 panic("ecard_def_fiq_disable called - impossible");
424 static int ecard_def_fiq_pending(ecard_t *ec)
426 return !ec->fiqmask || readb(ec->fiqaddr) & ec->fiqmask;
429 static expansioncard_ops_t ecard_default_ops = {
430 ecard_def_irq_enable,
431 ecard_def_irq_disable,
432 ecard_def_irq_pending,
433 ecard_def_fiq_enable,
434 ecard_def_fiq_disable,
435 ecard_def_fiq_pending
439 * Enable and disable interrupts from expansion cards.
440 * (interrupts are disabled for these functions).
442 * They are not meant to be called directly, but via enable/disable_irq.
444 static void ecard_irq_unmask(unsigned int irqnr)
446 ecard_t *ec = slot_to_ecard(irqnr - 32);
450 ec->ops = &ecard_default_ops;
452 if (ec->claimed && ec->ops->irqenable)
453 ec->ops->irqenable(ec, irqnr);
455 printk(KERN_ERR "ecard: rejecting request to "
456 "enable IRQs for %d\n", irqnr);
460 static void ecard_irq_mask(unsigned int irqnr)
462 ecard_t *ec = slot_to_ecard(irqnr - 32);
466 ec->ops = &ecard_default_ops;
468 if (ec->ops && ec->ops->irqdisable)
469 ec->ops->irqdisable(ec, irqnr);
473 static struct irqchip ecard_chip = {
474 .ack = ecard_irq_mask,
475 .mask = ecard_irq_mask,
476 .unmask = ecard_irq_unmask,
479 void ecard_enablefiq(unsigned int fiqnr)
481 ecard_t *ec = slot_to_ecard(fiqnr);
485 ec->ops = &ecard_default_ops;
487 if (ec->claimed && ec->ops->fiqenable)
488 ec->ops->fiqenable(ec, fiqnr);
490 printk(KERN_ERR "ecard: rejecting request to "
491 "enable FIQs for %d\n", fiqnr);
495 void ecard_disablefiq(unsigned int fiqnr)
497 ecard_t *ec = slot_to_ecard(fiqnr);
501 ec->ops = &ecard_default_ops;
503 if (ec->ops->fiqdisable)
504 ec->ops->fiqdisable(ec, fiqnr);
508 static void ecard_dump_irq_state(void)
512 printk("Expansion card IRQ state:\n");
514 for (ec = cards; ec; ec = ec->next) {
515 if (ec->slot_no == 8)
518 printk(" %d: %sclaimed, ",
519 ec->slot_no, ec->claimed ? "" : "not ");
521 if (ec->ops && ec->ops->irqpending &&
522 ec->ops != &ecard_default_ops)
523 printk("irq %spending\n",
524 ec->ops->irqpending(ec) ? "" : "not ");
526 printk("irqaddr %p, mask = %02X, status = %02X\n",
527 ec->irqaddr, ec->irqmask, readb(ec->irqaddr));
531 static void ecard_check_lockup(struct irqdesc *desc)
533 static unsigned long last;
537 * If the timer interrupt has not run since the last million
538 * unrecognised expansion card interrupts, then there is
539 * something seriously wrong. Disable the expansion card
540 * interrupts so at least we can continue.
542 * Maybe we ought to start a timer to re-enable them some time
545 if (last == jiffies) {
547 if (lockup > 1000000) {
548 printk(KERN_ERR "\nInterrupt lockup detected - "
549 "disabling all expansion card interrupts\n");
551 desc->chip->mask(IRQ_EXPANSIONCARD);
552 ecard_dump_irq_state();
558 * If we did not recognise the source of this interrupt,
559 * warn the user, but don't flood the user with these messages.
561 if (!last || time_after(jiffies, last + 5*HZ)) {
563 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
564 ecard_dump_irq_state();
569 ecard_irq_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
574 desc->chip->mask(irq);
575 for (ec = cards; ec; ec = ec->next) {
578 if (!ec->claimed || ec->irq == NO_IRQ || ec->slot_no == 8)
581 if (ec->ops && ec->ops->irqpending)
582 pending = ec->ops->irqpending(ec);
584 pending = ecard_default_ops.irqpending(ec);
587 struct irqdesc *d = irq_desc + ec->irq;
588 desc_handle_irq(ec->irq, d, regs);
592 desc->chip->unmask(irq);
595 ecard_check_lockup(desc);
599 static unsigned char priority_masks[] =
601 0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff
604 static unsigned char first_set[] =
606 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
607 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00
611 ecard_irqexp_handler(unsigned int irq, struct irqdesc *desc, struct pt_regs *regs)
613 const unsigned int statusmask = 15;
616 status = __raw_readb(EXPMASK_STATUS) & statusmask;
618 unsigned int slot = first_set[status];
619 ecard_t *ec = slot_to_ecard(slot);
622 struct irqdesc *d = irqdesc + ec->irq;
624 * this ugly code is so that we can operate a
625 * prioritorising system:
627 * Card 0 highest priority
630 * Card 3 lowest priority
632 * Serial cards should go in 0/1, ethernet/scsi in 2/3
633 * otherwise you will lose serial data at high speeds!
635 desc_handle_irq(ec->irq, d, regs);
637 printk(KERN_WARNING "card%d: interrupt from unclaimed "
639 have_expmask &= ~(1 << slot);
640 __raw_writeb(have_expmask, EXPMASK_ENABLE);
643 printk(KERN_WARNING "Wild interrupt from backplane (masks)\n");
646 static int __init ecard_probeirqhw(void)
651 __raw_writeb(0x00, EXPMASK_ENABLE);
652 __raw_writeb(0xff, EXPMASK_STATUS);
653 found = (__raw_readb(EXPMASK_STATUS) & 15) == 0;
654 __raw_writeb(0xff, EXPMASK_ENABLE);
657 printk(KERN_DEBUG "Expansion card interrupt "
658 "management hardware found\n");
660 /* for each card present, set a bit to '1' */
661 have_expmask = 0x80000000;
663 for (ec = cards; ec; ec = ec->next)
664 have_expmask |= 1 << ec->slot_no;
666 __raw_writeb(have_expmask, EXPMASK_ENABLE);
672 #define ecard_irqexp_handler NULL
673 #define ecard_probeirqhw() (0)
676 #ifndef IO_EC_MEMC8_BASE
677 #define IO_EC_MEMC8_BASE 0
680 unsigned int __ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
682 unsigned long address = 0;
683 int slot = ec->slot_no;
685 if (ec->slot_no == 8)
686 return IO_EC_MEMC8_BASE;
688 ectcr &= ~(1 << slot);
693 address = IO_EC_MEMC_BASE + (slot << 12);
698 address = IO_EC_IOC_BASE + (slot << 12);
699 #ifdef IO_EC_IOC4_BASE
701 address = IO_EC_IOC4_BASE + ((slot - 4) << 12);
704 address += speed << 17;
707 #ifdef IO_EC_EASI_BASE
709 address = IO_EC_EASI_BASE + (slot << 22);
710 if (speed == ECARD_FAST)
719 iomd_writeb(ectcr, IOMD_ECTCR);
724 static int ecard_prints(char *buffer, ecard_t *ec)
726 char *start = buffer;
728 buffer += sprintf(buffer, " %d: %s ", ec->slot_no,
729 ec->type == ECARD_EASI ? "EASI" : " ");
731 if (ec->cid.id == 0) {
732 struct in_chunk_dir incd;
734 buffer += sprintf(buffer, "[%04X:%04X] ",
735 ec->cid.manufacturer, ec->cid.product);
737 if (!ec->card_desc && ec->cid.cd &&
738 ecard_readchunk(&incd, ec, 0xf5, 0)) {
739 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
742 strcpy((char *)ec->card_desc, incd.d.string);
745 buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
747 buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);
749 return buffer - start;
752 static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count)
759 while (ec && count > cnt) {
760 len = ecard_prints(buf, ec);
764 *start = buf + (pos - (at - len));
772 return (count > cnt) ? cnt : count;
775 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
777 static void ecard_proc_init(void)
779 proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);
780 create_proc_info_entry("devices", 0, proc_bus_ecard_dir,
784 #define ec_set_resource(ec,nr,st,sz) \
786 (ec)->resource[nr].name = ec->dev.bus_id; \
787 (ec)->resource[nr].start = st; \
788 (ec)->resource[nr].end = (st) + (sz) - 1; \
789 (ec)->resource[nr].flags = IORESOURCE_MEM; \
792 static void __init ecard_free_card(struct expansion_card *ec)
796 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
797 if (ec->resource[i].flags)
798 release_resource(&ec->resource[i]);
803 static struct expansion_card *__init ecard_alloc_card(int type, int slot)
805 struct expansion_card *ec;
809 ec = kmalloc(sizeof(ecard_t), GFP_KERNEL);
811 ec = ERR_PTR(-ENOMEM);
815 memset(ec, 0, sizeof(ecard_t));
822 ec->ops = &ecard_default_ops;
824 snprintf(ec->dev.bus_id, sizeof(ec->dev.bus_id), "ecard%d", slot);
825 ec->dev.parent = NULL;
826 ec->dev.bus = &ecard_bus_type;
827 ec->dev.dma_mask = &ec->dma_mask;
828 ec->dma_mask = (u64)0xffffffff;
831 ec_set_resource(ec, ECARD_RES_MEMC,
832 PODSLOT_MEMC_BASE + (slot << 14),
834 base = PODSLOT_IOC0_BASE + (slot << 14);
836 base = PODSLOT_IOC4_BASE + ((slot - 4) << 14);
838 #ifdef CONFIG_ARCH_RPC
840 ec_set_resource(ec, ECARD_RES_EASI,
841 PODSLOT_EASI_BASE + (slot << 24),
846 ec_set_resource(ec, ECARD_RES_MEMC, NETSLOT_BASE, NETSLOT_SIZE);
850 for (i = 0; i <= ECARD_RES_IOCSYNC - ECARD_RES_IOCSLOW; i++)
851 ec_set_resource(ec, i + ECARD_RES_IOCSLOW,
852 base + (i << 19), PODSLOT_IOC_SIZE);
854 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
855 if (ec->resource[i].flags &&
856 request_resource(&iomem_resource, &ec->resource[i])) {
857 printk(KERN_ERR "%s: resource(s) not available\n",
859 ec->resource[i].end -= ec->resource[i].start;
860 ec->resource[i].start = 0;
861 ec->resource[i].flags = 0;
869 static ssize_t ecard_show_irq(struct device *dev, struct device_attribute *attr, char *buf)
871 struct expansion_card *ec = ECARD_DEV(dev);
872 return sprintf(buf, "%u\n", ec->irq);
875 static ssize_t ecard_show_dma(struct device *dev, struct device_attribute *attr, char *buf)
877 struct expansion_card *ec = ECARD_DEV(dev);
878 return sprintf(buf, "%u\n", ec->dma);
881 static ssize_t ecard_show_resources(struct device *dev, struct device_attribute *attr, char *buf)
883 struct expansion_card *ec = ECARD_DEV(dev);
887 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
888 str += sprintf(str, "%08lx %08lx %08lx\n",
889 ec->resource[i].start,
891 ec->resource[i].flags);
896 static ssize_t ecard_show_vendor(struct device *dev, struct device_attribute *attr, char *buf)
898 struct expansion_card *ec = ECARD_DEV(dev);
899 return sprintf(buf, "%u\n", ec->cid.manufacturer);
902 static ssize_t ecard_show_device(struct device *dev, struct device_attribute *attr, char *buf)
904 struct expansion_card *ec = ECARD_DEV(dev);
905 return sprintf(buf, "%u\n", ec->cid.product);
908 static ssize_t ecard_show_type(struct device *dev, struct device_attribute *attr, char *buf)
910 struct expansion_card *ec = ECARD_DEV(dev);
911 return sprintf(buf, "%s\n", ec->type == ECARD_EASI ? "EASI" : "IOC");
914 static struct device_attribute ecard_dev_attrs[] = {
915 __ATTR(device, S_IRUGO, ecard_show_device, NULL),
916 __ATTR(dma, S_IRUGO, ecard_show_dma, NULL),
917 __ATTR(irq, S_IRUGO, ecard_show_irq, NULL),
918 __ATTR(resource, S_IRUGO, ecard_show_resources, NULL),
919 __ATTR(type, S_IRUGO, ecard_show_type, NULL),
920 __ATTR(vendor, S_IRUGO, ecard_show_vendor, NULL),
925 int ecard_request_resources(struct expansion_card *ec)
929 for (i = 0; i < ECARD_NUM_RESOURCES; i++) {
930 if (ecard_resource_end(ec, i) &&
931 !request_mem_region(ecard_resource_start(ec, i),
932 ecard_resource_len(ec, i),
933 ec->dev.driver->name)) {
941 if (ecard_resource_end(ec, i))
942 release_mem_region(ecard_resource_start(ec, i),
943 ecard_resource_len(ec, i));
947 EXPORT_SYMBOL(ecard_request_resources);
949 void ecard_release_resources(struct expansion_card *ec)
953 for (i = 0; i < ECARD_NUM_RESOURCES; i++)
954 if (ecard_resource_end(ec, i))
955 release_mem_region(ecard_resource_start(ec, i),
956 ecard_resource_len(ec, i));
958 EXPORT_SYMBOL(ecard_release_resources);
961 * Probe for an expansion card.
963 * If bit 1 of the first byte of the card is set, then the
964 * card does not exist.
967 ecard_probe(int slot, card_type_t type)
974 ec = ecard_alloc_card(type, slot);
981 if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
985 ecard_readbytes(&cid, ec, 0, 16, 0);
989 ec->cid.id = cid.r_id;
990 ec->cid.cd = cid.r_cd;
991 ec->cid.is = cid.r_is;
993 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
994 ec->cid.product = ecard_getu16(cid.r_prod);
995 ec->cid.country = cid.r_country;
996 ec->cid.irqmask = cid.r_irqmask;
997 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
998 ec->cid.fiqmask = cid.r_fiqmask;
999 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
1001 ec->irqaddr = (void __iomem *)ioaddr(ec->podaddr);
1004 ec->irqmask = ec->cid.irqmask;
1005 ec->irqaddr += ec->cid.irqoff;
1006 ec->fiqmask = ec->cid.fiqmask;
1007 ec->fiqaddr += ec->cid.fiqoff;
1013 for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
1014 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
1015 blacklist[i].product == ec->cid.product) {
1016 ec->card_desc = blacklist[i].type;
1021 * hook the interrupt handlers
1024 ec->irq = 32 + slot;
1025 set_irq_chip(ec->irq, &ecard_chip);
1026 set_irq_handler(ec->irq, do_level_IRQ);
1027 set_irq_flags(ec->irq, IRQF_VALID);
1030 #ifdef IO_EC_MEMC8_BASE
1034 #ifdef CONFIG_ARCH_RPC
1035 /* On RiscPC, only first two slots have DMA capability */
1040 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
1043 slot_to_expcard[slot] = ec;
1045 device_register(&ec->dev);
1050 ecard_free_card(ec);
1056 * Initialise the expansion card system.
1057 * Locate all hardware - interrupt management and
1060 static int __init ecard_init(void)
1062 int slot, irqhw, ret;
1064 ret = kernel_thread(ecard_task, NULL, CLONE_KERNEL);
1066 printk(KERN_ERR "Ecard: unable to create kernel thread: %d\n",
1071 printk("Probing expansion cards\n");
1073 for (slot = 0; slot < 8; slot ++) {
1074 if (ecard_probe(slot, ECARD_EASI) == -ENODEV)
1075 ecard_probe(slot, ECARD_IOC);
1078 #ifdef IO_EC_MEMC8_BASE
1079 ecard_probe(8, ECARD_IOC);
1082 irqhw = ecard_probeirqhw();
1084 set_irq_chained_handler(IRQ_EXPANSIONCARD,
1085 irqhw ? ecard_irqexp_handler : ecard_irq_handler);
1092 subsys_initcall(ecard_init);
1097 static const struct ecard_id *
1098 ecard_match_device(const struct ecard_id *ids, struct expansion_card *ec)
1102 for (i = 0; ids[i].manufacturer != 65535; i++)
1103 if (ec->cid.manufacturer == ids[i].manufacturer &&
1104 ec->cid.product == ids[i].product)
1110 static int ecard_drv_probe(struct device *dev)
1112 struct expansion_card *ec = ECARD_DEV(dev);
1113 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1114 const struct ecard_id *id;
1117 id = ecard_match_device(drv->id_table, ec);
1120 ret = drv->probe(ec, id);
1126 static int ecard_drv_remove(struct device *dev)
1128 struct expansion_card *ec = ECARD_DEV(dev);
1129 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1138 * Before rebooting, we must make sure that the expansion card is in a
1139 * sensible state, so it can be re-detected. This means that the first
1140 * page of the ROM must be visible. We call the expansion cards reset
1143 static void ecard_drv_shutdown(struct device *dev)
1145 struct expansion_card *ec = ECARD_DEV(dev);
1146 struct ecard_driver *drv = ECARD_DRV(dev->driver);
1147 struct ecard_request req;
1154 * If this card has a loader, call the reset handler.
1157 req.fn = ecard_task_reset;
1163 int ecard_register_driver(struct ecard_driver *drv)
1165 drv->drv.bus = &ecard_bus_type;
1166 drv->drv.probe = ecard_drv_probe;
1167 drv->drv.remove = ecard_drv_remove;
1168 drv->drv.shutdown = ecard_drv_shutdown;
1170 return driver_register(&drv->drv);
1173 void ecard_remove_driver(struct ecard_driver *drv)
1175 driver_unregister(&drv->drv);
1178 static int ecard_match(struct device *_dev, struct device_driver *_drv)
1180 struct expansion_card *ec = ECARD_DEV(_dev);
1181 struct ecard_driver *drv = ECARD_DRV(_drv);
1184 if (drv->id_table) {
1185 ret = ecard_match_device(drv->id_table, ec) != NULL;
1187 ret = ec->cid.id == drv->id;
1193 struct bus_type ecard_bus_type = {
1195 .dev_attrs = ecard_dev_attrs,
1196 .match = ecard_match,
1199 static int ecard_bus_init(void)
1201 return bus_register(&ecard_bus_type);
1204 postcore_initcall(ecard_bus_init);
1206 EXPORT_SYMBOL(ecard_readchunk);
1207 EXPORT_SYMBOL(__ecard_address);
1208 EXPORT_SYMBOL(ecard_register_driver);
1209 EXPORT_SYMBOL(ecard_remove_driver);
1210 EXPORT_SYMBOL(ecard_bus_type);