- pre3:
[davej-history.git] / arch / arm / kernel / ecard.c
blob38fd2a69cf126bd0885bd1e99f00e1a9ff1671cd
1 /*
2 * linux/arch/arm/kernel/ecard.c
4 * Find all installed expansion cards, and handle interrupts from them.
6 * Copyright 1995-1998 Russell King
8 * Created from information from Acorns RiscOS3 PRMs
10 * 08-Dec-1996 RMK Added code for the 9'th expansion card - the ether
11 * podule slot.
12 * 06-May-1997 RMK Added blacklist for cards whose loader doesn't work.
13 * 12-Sep-1997 RMK Created new handling of interrupt enables/disables
14 * - cards can now register their own routine to control
15 * interrupts (recommended).
16 * 29-Sep-1997 RMK Expansion card interrupt hardware not being re-enabled
17 * on reset from Linux. (Caused cards not to respond
18 * under RiscOS without hard reset).
19 * 15-Feb-1998 RMK Added DMA support
20 * 12-Sep-1998 RMK Added EASI support
21 * 10-Jan-1999 RMK Run loaders in a simulated RISC OS environment.
22 * 17-Apr-1999 RMK Support for EASI Type C cycles.
25 #define ECARD_C
26 #define __KERNEL_SYSCALLS__
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/sched.h>
33 #include <linux/interrupt.h>
34 #include <linux/mm.h>
35 #include <linux/malloc.h>
36 #include <linux/proc_fs.h>
37 #include <linux/init.h>
39 #include <asm/dma.h>
40 #include <asm/ecard.h>
41 #include <asm/hardware.h>
42 #include <asm/io.h>
43 #include <asm/irq.h>
44 #include <asm/pgalloc.h>
45 #include <asm/mmu_context.h>
47 #ifndef CONFIG_ARCH_RPC
48 #define HAVE_EXPMASK
49 #endif
51 enum req {
52 req_readbytes,
53 req_reset
56 struct ecard_request {
57 enum req req;
58 ecard_t *ec;
59 unsigned int address;
60 unsigned int length;
61 unsigned int use_loader;
62 void *buffer;
65 struct expcard_blacklist {
66 unsigned short manufacturer;
67 unsigned short product;
68 const char *type;
71 static ecard_t *cards;
72 static ecard_t *slot_to_expcard[MAX_ECARDS];
73 static unsigned int ectcr;
74 #ifdef HAS_EXPMASK
75 static unsigned int have_expmask;
76 #endif
78 /* List of descriptions of cards which don't have an extended
79 * identification, or chunk directories containing a description.
81 static struct expcard_blacklist __initdata blacklist[] = {
82 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
85 asmlinkage extern int
86 ecard_loader_reset(volatile unsigned char *pa, loader_t loader);
87 asmlinkage extern int
88 ecard_loader_read(int off, volatile unsigned char *pa, loader_t loader);
89 extern int setup_arm_irq(int, struct irqaction *);
90 extern void do_ecard_IRQ(int, struct pt_regs *);
93 static void
94 ecard_irq_noexpmask(int intr_no, void *dev_id, struct pt_regs *regs);
96 static struct irqaction irqexpansioncard = {
97 ecard_irq_noexpmask, SA_INTERRUPT, 0, "expansion cards", NULL, NULL
100 static inline unsigned short
101 ecard_getu16(unsigned char *v)
103 return v[0] | v[1] << 8;
106 static inline signed long
107 ecard_gets24(unsigned char *v)
109 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
112 static inline ecard_t *
113 slot_to_ecard(unsigned int slot)
115 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
118 /* ===================== Expansion card daemon ======================== */
120 * Since the loader programs on the expansion cards need to be run
121 * in a specific environment, create a separate task with this
122 * environment up, and pass requests to this task as and when we
123 * need to.
125 * This should allow 99% of loaders to be called from Linux.
127 * From a security standpoint, we trust the card vendors. This
128 * may be a misplaced trust.
130 #define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
131 #define POD_INT_ADDR(x) ((volatile unsigned char *)\
132 ((BUS_ADDR((x)) - IO_BASE) + IO_START))
134 static void
135 ecard_task_reset(struct ecard_request *req)
137 if (req->ec == NULL) {
138 ecard_t *ec;
140 for (ec = cards; ec; ec = ec->next) {
141 printk(KERN_DEBUG "Resetting card %d\n",
142 ec->slot_no);
144 if (ec->loader)
145 ecard_loader_reset(POD_INT_ADDR(ec->podaddr),
146 ec->loader);
148 printk(KERN_DEBUG "All cards reset\n");
149 } else if (req->ec->loader)
150 ecard_loader_reset(POD_INT_ADDR(req->ec->podaddr),
151 req->ec->loader);
154 static void
155 ecard_task_readbytes(struct ecard_request *req)
157 unsigned char *buf = (unsigned char *)req->buffer;
158 volatile unsigned char *base_addr =
159 (volatile unsigned char *)POD_INT_ADDR(req->ec->podaddr);
160 unsigned int len = req->length;
162 if (req->ec->slot_no == 8) {
164 * The card maintains an index which
165 * increments the address into a 4096-byte
166 * page on each access. We need to keep
167 * track of the counter.
169 static unsigned int index;
170 unsigned int offset, page;
171 unsigned char byte = 0; /* keep gcc quiet */
173 offset = req->address & 4095;
174 page = req->address >> 12;
176 if (page > 256)
177 return;
179 page *= 4;
181 if (offset == 0 || index > offset) {
183 * We need to reset the index counter.
185 *base_addr = 0;
186 index = 0;
189 while (index <= offset) {
190 byte = base_addr[page];
191 index += 1;
194 while (len--) {
195 *buf++ = byte;
196 if (len) {
197 byte = base_addr[page];
198 index += 1;
201 } else {
202 unsigned int off = req->address;
204 if (!req->use_loader || !req->ec->loader) {
205 off *= 4;
206 while (len--) {
207 *buf++ = base_addr[off];
208 off += 4;
210 } else {
211 while(len--) {
213 * The following is required by some
214 * expansion card loader programs.
216 *(unsigned long *)0x108 = 0;
217 *buf++ = ecard_loader_read(off++, base_addr,
218 req->ec->loader);
225 #ifdef CONFIG_CPU_32
226 static pid_t ecard_pid;
227 static wait_queue_head_t ecard_wait;
228 static wait_queue_head_t ecard_done;
229 static struct ecard_request *ecard_req;
231 /* to be removed when exec_mmap becomes extern */
232 static int exec_mmap(void)
234 struct mm_struct * mm, * old_mm;
236 old_mm = current->mm;
237 if (old_mm && atomic_read(&old_mm->mm_users) == 1) {
238 flush_cache_mm(old_mm);
239 mm_release();
240 exit_mmap(old_mm);
241 flush_tlb_mm(old_mm);
242 return 0;
245 mm = mm_alloc();
246 if (mm) {
247 struct mm_struct *active_mm = current->active_mm;
249 current->mm = mm;
250 current->active_mm = mm;
251 activate_mm(active_mm, mm);
252 mm_release();
253 if (old_mm) {
254 if (active_mm != old_mm) BUG();
255 mmput(old_mm);
256 return 0;
258 mmdrop(active_mm);
259 return 0;
261 return -ENOMEM;
265 * Set up the expansion card
266 * daemon's environment.
268 static void ecard_init_task(int force)
270 /* We want to set up the page tables for the following mapping:
271 * Virtual Physical
272 * 0x03000000 0x03000000
273 * 0x03010000 unmapped
274 * 0x03210000 0x03210000
275 * 0x03400000 unmapped
276 * 0x08000000 0x08000000
277 * 0x10000000 unmapped
279 * FIXME: we don't follow this 100% yet.
281 pgd_t *src_pgd, *dst_pgd;
282 unsigned int dst_addr = IO_START;
284 if (!force)
285 exec_mmap();
287 src_pgd = pgd_offset(current->mm, IO_BASE);
288 dst_pgd = pgd_offset(current->mm, dst_addr);
290 while (dst_addr < IO_START + IO_SIZE) {
291 *dst_pgd++ = *src_pgd++;
292 dst_addr += PGDIR_SIZE;
295 flush_tlb_range(current->mm, IO_START, IO_START + IO_SIZE);
297 dst_addr = EASI_START;
298 src_pgd = pgd_offset(current->mm, EASI_BASE);
299 dst_pgd = pgd_offset(current->mm, dst_addr);
301 while (dst_addr < EASI_START + EASI_SIZE) {
302 *dst_pgd++ = *src_pgd++;
303 dst_addr += PGDIR_SIZE;
306 flush_tlb_range(current->mm, EASI_START, EASI_START + EASI_SIZE);
309 static int
310 ecard_task(void * unused)
312 struct task_struct *tsk = current;
314 tsk->session = 1;
315 tsk->pgrp = 1;
318 * We don't want /any/ signals, not even SIGKILL
320 sigfillset(&tsk->blocked);
321 sigemptyset(&tsk->pending.signal);
322 recalc_sigpending(tsk);
324 strcpy(tsk->comm, "kecardd");
327 * Set up the environment
329 ecard_init_task(0);
331 while (1) {
332 struct ecard_request *req;
334 do {
335 req = xchg(&ecard_req, NULL);
337 if (req == NULL) {
338 sigemptyset(&tsk->pending.signal);
339 interruptible_sleep_on(&ecard_wait);
341 } while (req == NULL);
343 switch (req->req) {
344 case req_readbytes:
345 ecard_task_readbytes(req);
346 break;
348 case req_reset:
349 ecard_task_reset(req);
350 break;
352 wake_up(&ecard_done);
357 * Wake the expansion card daemon to action our request.
359 * FIXME: The test here is not sufficient to detect if the
360 * kcardd is running.
362 static inline void
363 ecard_call(struct ecard_request *req)
366 * If we're called from task 0, or from an
367 * interrupt (will be keyboard interrupt),
368 * we forcefully set up the memory map, and
369 * call the loader. We can't schedule, or
370 * sleep for this call.
372 if ((current == &init_task || in_interrupt()) &&
373 req->req == req_reset && req->ec == NULL) {
374 ecard_init_task(1);
375 ecard_task_reset(req);
376 } else {
377 if (ecard_pid <= 0)
378 ecard_pid = kernel_thread(ecard_task, NULL,
379 CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
381 ecard_req = req;
383 wake_up(&ecard_wait);
385 sleep_on(&ecard_done);
388 #else
390 * On 26-bit processors, we don't need the kcardd thread to access the
391 * expansion card loaders. We do it directly.
393 static inline void
394 ecard_call(struct ecard_request *req)
396 if (req->req == req_reset)
397 ecard_task_reset(req);
398 else
399 ecard_task_readbytes(req);
401 #endif
403 /* ======================= Mid-level card control ===================== */
405 * This is called to reset the loaders for each expansion card on reboot.
407 * This is required to make sure that the card is in the correct state
408 * that RiscOS expects it to be.
410 void
411 ecard_reset(int slot)
413 struct ecard_request req;
415 req.req = req_reset;
417 if (slot < 0)
418 req.ec = NULL;
419 else
420 req.ec = slot_to_ecard(slot);
422 ecard_call(&req);
424 #ifdef HAS_EXPMASK
425 if (have_expmask && slot < 0) {
426 have_expmask |= ~0;
427 EXPMASK_ENABLE = have_expmask;
429 #endif
432 static void
433 ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
435 struct ecard_request req;
437 req.req = req_readbytes;
438 req.ec = ec;
439 req.address = off;
440 req.length = len;
441 req.use_loader = useld;
442 req.buffer = addr;
444 ecard_call(&req);
447 int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
449 struct ex_chunk_dir excd;
450 int index = 16;
451 int useld = 0;
453 if (!ec->cid.cd)
454 return 0;
456 while(1) {
457 ecard_readbytes(&excd, ec, index, 8, useld);
458 index += 8;
459 if (c_id(&excd) == 0) {
460 if (!useld && ec->loader) {
461 useld = 1;
462 index = 0;
463 continue;
465 return 0;
467 if (c_id(&excd) == 0xf0) { /* link */
468 index = c_start(&excd);
469 continue;
471 if (c_id(&excd) == 0x80) { /* loader */
472 if (!ec->loader) {
473 ec->loader = (loader_t)kmalloc(c_len(&excd),
474 GFP_KERNEL);
475 if (ec->loader)
476 ecard_readbytes(ec->loader, ec,
477 (int)c_start(&excd),
478 c_len(&excd), useld);
479 else
480 return 0;
482 continue;
484 if (c_id(&excd) == id && num-- == 0)
485 break;
488 if (c_id(&excd) & 0x80) {
489 switch (c_id(&excd) & 0x70) {
490 case 0x70:
491 ecard_readbytes((unsigned char *)excd.d.string, ec,
492 (int)c_start(&excd), c_len(&excd),
493 useld);
494 break;
495 case 0x00:
496 break;
499 cd->start_offset = c_start(&excd);
500 memcpy(cd->d.string, excd.d.string, 256);
501 return 1;
504 /* ======================= Interrupt control ============================ */
506 static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
508 #ifdef HAS_EXPMASK
509 if (irqnr < 4 && have_expmask) {
510 have_expmask |= 1 << irqnr;
511 EXPMASK_ENABLE = have_expmask;
513 #endif
516 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
518 #ifdef HAS_EXPMASK
519 if (irqnr < 4 && have_expmask) {
520 have_expmask &= ~(1 << irqnr);
521 EXPMASK_ENABLE = have_expmask;
523 #endif
526 static int ecard_def_irq_pending(ecard_t *ec)
528 return !ec->irqmask || ec->irqaddr[0] & ec->irqmask;
531 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
533 panic("ecard_def_fiq_enable called - impossible");
536 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
538 panic("ecard_def_fiq_disable called - impossible");
541 static int ecard_def_fiq_pending(ecard_t *ec)
543 return !ec->fiqmask || ec->fiqaddr[0] & ec->fiqmask;
546 static expansioncard_ops_t ecard_default_ops = {
547 ecard_def_irq_enable,
548 ecard_def_irq_disable,
549 ecard_def_irq_pending,
550 ecard_def_fiq_enable,
551 ecard_def_fiq_disable,
552 ecard_def_fiq_pending
556 * Enable and disable interrupts from expansion cards.
557 * (interrupts are disabled for these functions).
559 * They are not meant to be called directly, but via enable/disable_irq.
561 void ecard_enableirq(unsigned int irqnr)
563 ecard_t *ec = slot_to_ecard(irqnr - 32);
565 if (ec) {
566 if (!ec->ops)
567 ec->ops = &ecard_default_ops;
569 if (ec->claimed && ec->ops->irqenable)
570 ec->ops->irqenable(ec, irqnr);
571 else
572 printk(KERN_ERR "ecard: rejecting request to "
573 "enable IRQs for %d\n", irqnr);
577 void ecard_disableirq(unsigned int irqnr)
579 ecard_t *ec = slot_to_ecard(irqnr - 32);
581 if (ec) {
582 if (!ec->ops)
583 ec->ops = &ecard_default_ops;
585 if (ec->ops && ec->ops->irqdisable)
586 ec->ops->irqdisable(ec, irqnr);
590 void ecard_enablefiq(unsigned int fiqnr)
592 ecard_t *ec = slot_to_ecard(fiqnr);
594 if (ec) {
595 if (!ec->ops)
596 ec->ops = &ecard_default_ops;
598 if (ec->claimed && ec->ops->fiqenable)
599 ec->ops->fiqenable(ec, fiqnr);
600 else
601 printk(KERN_ERR "ecard: rejecting request to "
602 "enable FIQs for %d\n", fiqnr);
606 void ecard_disablefiq(unsigned int fiqnr)
608 ecard_t *ec = slot_to_ecard(fiqnr);
610 if (ec) {
611 if (!ec->ops)
612 ec->ops = &ecard_default_ops;
614 if (ec->ops->fiqdisable)
615 ec->ops->fiqdisable(ec, fiqnr);
619 static void
620 ecard_dump_irq_state(ecard_t *ec)
622 printk(" %d: %sclaimed, ",
623 ec->slot_no,
624 ec->claimed ? "" : "not ");
626 if (ec->ops && ec->ops->irqpending &&
627 ec->ops != &ecard_default_ops)
628 printk("irq %spending\n",
629 ec->ops->irqpending(ec) ? "" : "not ");
630 else
631 printk("irqaddr %p, mask = %02X, status = %02X\n",
632 ec->irqaddr, ec->irqmask, *ec->irqaddr);
635 static void
636 ecard_check_lockup(void)
638 static int last, lockup;
639 ecard_t *ec;
642 * If the timer interrupt has not run since the last million
643 * unrecognised expansion card interrupts, then there is
644 * something seriously wrong. Disable the expansion card
645 * interrupts so at least we can continue.
647 * Maybe we ought to start a timer to re-enable them some time
648 * later?
650 if (last == jiffies) {
651 lockup += 1;
652 if (lockup > 1000000) {
653 printk(KERN_ERR "\nInterrupt lockup detected - "
654 "disabling all expansion card interrupts\n");
656 disable_irq(IRQ_EXPANSIONCARD);
658 printk("Expansion card IRQ state:\n");
660 for (ec = cards; ec; ec = ec->next)
661 ecard_dump_irq_state(ec);
663 } else
664 lockup = 0;
667 * If we did not recognise the source of this interrupt,
668 * warn the user, but don't flood the user with these messages.
670 if (!last || time_after(jiffies, last + 5*HZ)) {
671 last = jiffies;
672 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
676 static void
677 ecard_irq_noexpmask(int intr_no, void *dev_id, struct pt_regs *regs)
679 ecard_t *ec;
680 int called = 0;
682 for (ec = cards; ec; ec = ec->next) {
683 int pending;
685 if (!ec->claimed || ec->irq == NO_IRQ || ec->slot_no == 8)
686 continue;
688 if (ec->ops && ec->ops->irqpending)
689 pending = ec->ops->irqpending(ec);
690 else
691 pending = ecard_default_ops.irqpending(ec);
693 if (pending) {
694 do_ecard_IRQ(ec->irq, regs);
695 called ++;
698 cli();
700 if (called == 0)
701 ecard_check_lockup();
704 #ifdef HAS_EXPMASK
705 static unsigned char priority_masks[] =
707 0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff
710 static unsigned char first_set[] =
712 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
713 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00
716 static void
717 ecard_irq_expmask(int intr_no, void *dev_id, struct pt_regs *regs)
719 const unsigned int statusmask = 15;
720 unsigned int status;
722 status = EXPMASK_STATUS & statusmask;
723 if (status) {
724 unsigned int slot;
725 ecard_t *ec;
726 again:
727 slot = first_set[status];
728 ec = slot_to_ecard(slot);
729 if (ec->claimed) {
730 unsigned int oldexpmask;
732 * this ugly code is so that we can operate a
733 * prioritorising system:
735 * Card 0 highest priority
736 * Card 1
737 * Card 2
738 * Card 3 lowest priority
740 * Serial cards should go in 0/1, ethernet/scsi in 2/3
741 * otherwise you will lose serial data at high speeds!
743 oldexpmask = have_expmask;
744 EXPMASK_ENABLE = (have_expmask &= priority_masks[slot]);
745 sti();
746 do_ecard_IRQ(ec->irq, regs);
747 cli();
748 EXPMASK_ENABLE = have_expmask = oldexpmask;
749 status = EXPMASK_STATUS & statusmask;
750 if (status)
751 goto again;
752 } else {
753 printk(KERN_WARNING "card%d: interrupt from unclaimed "
754 "card???\n", slot);
755 EXPMASK_ENABLE = (have_expmask &= ~(1 << slot));
757 } else
758 printk(KERN_WARNING "Wild interrupt from backplane (masks)\n");
761 static void __init
762 ecard_probeirqhw(void)
764 ecard_t *ec;
765 int found;
767 EXPMASK_ENABLE = 0x00;
768 EXPMASK_STATUS = 0xff;
769 found = ((EXPMASK_STATUS & 15) == 0);
770 EXPMASK_ENABLE = 0xff;
772 if (!found)
773 return;
775 printk(KERN_DEBUG "Expansion card interrupt "
776 "management hardware found\n");
778 irqexpansioncard.handler = ecard_irq_expmask;
780 /* for each card present, set a bit to '1' */
781 have_expmask = 0x80000000;
783 for (ec = cards; ec; ec = ec->next)
784 have_expmask |= 1 << ec->slot_no;
786 EXPMASK_ENABLE = have_expmask;
788 #else
789 #define ecard_probeirqhw()
790 #endif
792 #ifndef IO_EC_MEMC8_BASE
793 #define IO_EC_MEMC8_BASE 0
794 #endif
796 unsigned int ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
798 unsigned long address = 0;
799 int slot = ec->slot_no;
801 if (ec->slot_no == 8)
802 return IO_EC_MEMC8_BASE;
804 ectcr &= ~(1 << slot);
806 switch (type) {
807 case ECARD_MEMC:
808 if (slot < 4)
809 address = IO_EC_MEMC_BASE + (slot << 12);
810 break;
812 case ECARD_IOC:
813 if (slot < 4)
814 address = IO_EC_IOC_BASE + (slot << 12);
815 #ifdef IO_EC_IOC4_BASE
816 else
817 address = IO_EC_IOC4_BASE + ((slot - 4) << 12);
818 #endif
819 if (address)
820 address += speed << 17;
821 break;
823 #ifdef IO_EC_EASI_BASE
824 case ECARD_EASI:
825 address = IO_EC_EASI_BASE + (slot << 22);
826 if (speed == ECARD_FAST)
827 ectcr |= 1 << slot;
828 break;
829 #endif
830 default:
831 break;
834 #ifdef IOMD_ECTCR
835 outb(ectcr, IOMD_ECTCR);
836 #endif
837 return address;
840 static int ecard_prints(char *buffer, ecard_t *ec)
842 char *start = buffer;
844 buffer += sprintf(buffer, " %d: %s ", ec->slot_no,
845 ec->type == ECARD_EASI ? "EASI" : " ");
847 if (ec->cid.id == 0) {
848 struct in_chunk_dir incd;
850 buffer += sprintf(buffer, "[%04X:%04X] ",
851 ec->cid.manufacturer, ec->cid.product);
853 if (!ec->card_desc && ec->cid.cd &&
854 ecard_readchunk(&incd, ec, 0xf5, 0)) {
855 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
857 if (ec->card_desc)
858 strcpy((char *)ec->card_desc, incd.d.string);
861 buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
862 } else
863 buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);
865 return buffer - start;
868 static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count)
870 ecard_t *ec = cards;
871 off_t at = 0;
872 int len, cnt;
874 cnt = 0;
875 while (ec && count > cnt) {
876 len = ecard_prints(buf, ec);
877 at += len;
878 if (at >= pos) {
879 if (!*start) {
880 *start = buf + (pos - (at - len));
881 cnt = at - pos;
882 } else
883 cnt += len;
884 buf += len;
886 ec = ec->next;
888 return (count > cnt) ? cnt : count;
891 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
893 static void ecard_proc_init(void)
895 proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);
896 create_proc_info_entry("devices", 0, proc_bus_ecard_dir,
897 get_ecard_dev_info);
901 * Probe for an expansion card.
903 * If bit 1 of the first byte of the card is set, then the
904 * card does not exist.
906 static int __init
907 ecard_probe(int slot, card_type_t type)
909 ecard_t **ecp;
910 ecard_t *ec;
911 struct ex_ecid cid;
912 int i, rc = -ENOMEM;
914 ec = kmalloc(sizeof(ecard_t), GFP_KERNEL);
916 if (!ec)
917 goto nodev;
919 memset(ec, 0, sizeof(ecard_t));
921 ec->slot_no = slot;
922 ec->type = type;
923 ec->irq = NO_IRQ;
924 ec->fiq = NO_IRQ;
925 ec->dma = NO_DMA;
926 ec->card_desc = NULL;
927 ec->ops = &ecard_default_ops;
929 rc = -ENODEV;
930 if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
931 goto nodev;
933 cid.r_zero = 1;
934 ecard_readbytes(&cid, ec, 0, 16, 0);
935 if (cid.r_zero)
936 goto nodev;
938 ec->cid.id = cid.r_id;
939 ec->cid.cd = cid.r_cd;
940 ec->cid.is = cid.r_is;
941 ec->cid.w = cid.r_w;
942 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
943 ec->cid.product = ecard_getu16(cid.r_prod);
944 ec->cid.country = cid.r_country;
945 ec->cid.irqmask = cid.r_irqmask;
946 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
947 ec->cid.fiqmask = cid.r_fiqmask;
948 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
949 ec->fiqaddr =
950 ec->irqaddr = (unsigned char *)ioaddr(ec->podaddr);
952 if (ec->cid.is) {
953 ec->irqmask = ec->cid.irqmask;
954 ec->irqaddr += ec->cid.irqoff;
955 ec->fiqmask = ec->cid.fiqmask;
956 ec->fiqaddr += ec->cid.fiqoff;
957 } else {
958 ec->irqmask = 1;
959 ec->fiqmask = 4;
962 for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
963 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
964 blacklist[i].product == ec->cid.product) {
965 ec->card_desc = blacklist[i].type;
966 break;
969 ec->irq = 32 + slot;
970 #ifdef IO_EC_MEMC8_BASE
971 if (slot == 8)
972 ec->irq = 11;
973 #endif
974 #ifdef CONFIG_ARCH_RPC
975 /* On RiscPC, only first two slots have DMA capability */
976 if (slot < 2)
977 ec->dma = 2 + slot;
978 #endif
979 #if 0 /* We don't support FIQs on expansion cards at the moment */
980 ec->fiq = 96 + slot;
981 #endif
983 rc = 0;
985 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
987 *ecp = ec;
989 nodev:
990 if (rc && ec)
991 kfree(ec);
992 else
993 slot_to_expcard[slot] = ec;
995 return rc;
998 static ecard_t *finding_pos;
1000 void ecard_startfind(void)
1002 finding_pos = NULL;
1005 ecard_t *ecard_find(int cid, const card_ids *cids)
1007 if (!finding_pos)
1008 finding_pos = cards;
1009 else
1010 finding_pos = finding_pos->next;
1012 for (; finding_pos; finding_pos = finding_pos->next) {
1013 if (finding_pos->claimed)
1014 continue;
1016 if (!cids) {
1017 if ((finding_pos->cid.id ^ cid) == 0)
1018 break;
1019 } else {
1020 unsigned int manufacturer, product;
1021 int i;
1023 manufacturer = finding_pos->cid.manufacturer;
1024 product = finding_pos->cid.product;
1026 for (i = 0; cids[i].manufacturer != 65535; i++)
1027 if (manufacturer == cids[i].manufacturer &&
1028 product == cids[i].product)
1029 break;
1031 if (cids[i].manufacturer != 65535)
1032 break;
1036 return finding_pos;
1039 static void __init ecard_free_all(void)
1041 ecard_t *ec, *ecn;
1043 for (ec = cards; ec; ec = ecn) {
1044 ecn = ec->next;
1046 kfree(ec);
1049 cards = NULL;
1051 memset(slot_to_expcard, 0, sizeof(slot_to_expcard));
1055 * Initialise the expansion card system.
1056 * Locate all hardware - interrupt management and
1057 * actual cards.
1059 void __init ecard_init(void)
1061 int slot;
1063 #ifdef CONFIG_CPU_32
1064 init_waitqueue_head(&ecard_wait);
1065 init_waitqueue_head(&ecard_done);
1066 #endif
1068 printk("Probing expansion cards\n");
1070 for (slot = 0; slot < 8; slot ++) {
1071 if (ecard_probe(slot, ECARD_EASI) == -ENODEV)
1072 ecard_probe(slot, ECARD_IOC);
1075 #ifdef IO_EC_MEMC8_BASE
1076 ecard_probe(8, ECARD_IOC);
1077 #endif
1079 ecard_probeirqhw();
1081 if (setup_arm_irq(IRQ_EXPANSIONCARD, &irqexpansioncard)) {
1082 printk(KERN_ERR "Unable to claim IRQ%d for expansion cards\n",
1083 IRQ_EXPANSIONCARD);
1084 ecard_free_all();
1087 ecard_proc_init();
1090 EXPORT_SYMBOL(ecard_startfind);
1091 EXPORT_SYMBOL(ecard_find);
1092 EXPORT_SYMBOL(ecard_readchunk);
1093 EXPORT_SYMBOL(ecard_address);