Merge with Linux 2.4.0-test3-pre2.
[linux-2.6/linux-mips.git] / arch / arm / kernel / ecard.c
blobb4d38e00fea827b7142a166f500ef14b758d0f7c
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 #ifdef CONFIG_ARCH_ARC
48 #include <asm/arch/oldlatches.h>
49 #else
50 #define oldlatch_init()
51 #endif
53 #ifndef CONFIG_ARCH_RPC
54 #define HAVE_EXPMASK
55 #endif
57 enum req {
58 req_readbytes,
59 req_reset
62 struct ecard_request {
63 enum req req;
64 ecard_t *ec;
65 unsigned int address;
66 unsigned int length;
67 unsigned int use_loader;
68 void *buffer;
71 struct expcard_blacklist {
72 unsigned short manufacturer;
73 unsigned short product;
74 const char *type;
77 static ecard_t *cards;
78 static ecard_t *slot_to_expcard[MAX_ECARDS];
79 static unsigned int ectcr;
80 #ifdef HAS_EXPMASK
81 static unsigned int have_expmask;
82 #endif
84 /* List of descriptions of cards which don't have an extended
85 * identification, or chunk directories containing a description.
87 static struct expcard_blacklist __initdata blacklist[] = {
88 { MANU_ACORN, PROD_ACORN_ETHER1, "Acorn Ether1" }
91 asmlinkage extern int
92 ecard_loader_reset(volatile unsigned char *pa, loader_t loader);
93 asmlinkage extern int
94 ecard_loader_read(int off, volatile unsigned char *pa, loader_t loader);
95 extern int setup_arm_irq(int, struct irqaction *);
96 extern void do_ecard_IRQ(int, struct pt_regs *);
99 static void
100 ecard_irq_noexpmask(int intr_no, void *dev_id, struct pt_regs *regs);
102 static struct irqaction irqexpansioncard = {
103 ecard_irq_noexpmask, SA_INTERRUPT, 0, "expansion cards", NULL, NULL
106 static inline unsigned short
107 ecard_getu16(unsigned char *v)
109 return v[0] | v[1] << 8;
112 static inline signed long
113 ecard_gets24(unsigned char *v)
115 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
118 static inline ecard_t *
119 slot_to_ecard(unsigned int slot)
121 return slot < MAX_ECARDS ? slot_to_expcard[slot] : NULL;
124 /* ===================== Expansion card daemon ======================== */
126 * Since the loader programs on the expansion cards need to be run
127 * in a specific environment, create a separate task with this
128 * environment up, and pass requests to this task as and when we
129 * need to.
131 * This should allow 99% of loaders to be called from Linux.
133 * From a security standpoint, we trust the card vendors. This
134 * may be a misplaced trust.
136 #define BUS_ADDR(x) ((((unsigned long)(x)) << 2) + IO_BASE)
137 #define POD_INT_ADDR(x) ((volatile unsigned char *)\
138 ((BUS_ADDR((x)) - IO_BASE) + IO_START))
140 static void
141 ecard_task_reset(struct ecard_request *req)
143 if (req->ec == NULL) {
144 ecard_t *ec;
146 for (ec = cards; ec; ec = ec->next) {
147 printk(KERN_DEBUG "Resetting card %d\n",
148 ec->slot_no);
150 if (ec->loader)
151 ecard_loader_reset(POD_INT_ADDR(ec->podaddr),
152 ec->loader);
154 printk(KERN_DEBUG "All cards reset\n");
155 } else if (req->ec->loader)
156 ecard_loader_reset(POD_INT_ADDR(req->ec->podaddr),
157 req->ec->loader);
160 static void
161 ecard_task_readbytes(struct ecard_request *req)
163 unsigned char *buf = (unsigned char *)req->buffer;
164 volatile unsigned char *base_addr =
165 (volatile unsigned char *)POD_INT_ADDR(req->ec->podaddr);
166 unsigned int len = req->length;
168 if (req->ec->slot_no == 8) {
170 * The card maintains an index which
171 * increments the address into a 4096-byte
172 * page on each access. We need to keep
173 * track of the counter.
175 static unsigned int index;
176 unsigned int offset, page;
177 unsigned char byte = 0; /* keep gcc quiet */
179 offset = req->address & 4095;
180 page = req->address >> 12;
182 if (page > 256)
183 return;
185 page *= 4;
187 if (offset == 0 || index > offset) {
189 * We need to reset the index counter.
191 *base_addr = 0;
192 index = 0;
195 while (index <= offset) {
196 byte = base_addr[page];
197 index += 1;
200 while (len--) {
201 *buf++ = byte;
202 if (len) {
203 byte = base_addr[page];
204 index += 1;
207 } else {
208 unsigned int off = req->address;
210 if (!req->use_loader || !req->ec->loader) {
211 off *= 4;
212 while (len--) {
213 *buf++ = base_addr[off];
214 off += 4;
216 } else {
217 while(len--) {
219 * The following is required by some
220 * expansion card loader programs.
222 *(unsigned long *)0x108 = 0;
223 *buf++ = ecard_loader_read(off++, base_addr,
224 req->ec->loader);
231 #ifdef CONFIG_CPU_32
232 static pid_t ecard_pid;
233 static wait_queue_head_t ecard_wait;
234 static wait_queue_head_t ecard_done;
235 static struct ecard_request *ecard_req;
237 /* to be removed when exec_mmap becomes extern */
238 static int exec_mmap(void)
240 struct mm_struct * mm, * old_mm;
242 old_mm = current->mm;
243 if (old_mm && atomic_read(&old_mm->mm_users) == 1) {
244 flush_cache_mm(old_mm);
245 mm_release();
246 exit_mmap(old_mm);
247 flush_tlb_mm(old_mm);
248 return 0;
251 mm = mm_alloc();
252 if (mm) {
253 struct mm_struct *active_mm = current->active_mm;
255 current->mm = mm;
256 current->active_mm = mm;
257 activate_mm(active_mm, mm);
258 mm_release();
259 if (old_mm) {
260 if (active_mm != old_mm) BUG();
261 mmput(old_mm);
262 return 0;
264 mmdrop(active_mm);
265 return 0;
267 return -ENOMEM;
271 * Set up the expansion card
272 * daemon's environment.
274 static void
275 ecard_init_task(void)
277 /* We want to set up the page tables for the following mapping:
278 * Virtual Physical
279 * 0x03000000 0x03000000
280 * 0x03010000 unmapped
281 * 0x03210000 0x03210000
282 * 0x03400000 unmapped
283 * 0x08000000 0x08000000
284 * 0x10000000 unmapped
286 * FIXME: we don't follow this 100% yet.
288 pgd_t *src_pgd, *dst_pgd;
289 unsigned int dst_addr = IO_START;
291 exec_mmap();
293 src_pgd = pgd_offset(current->mm, IO_BASE);
294 dst_pgd = pgd_offset(current->mm, dst_addr);
296 while (dst_addr < IO_START + IO_SIZE) {
297 *dst_pgd++ = *src_pgd++;
298 dst_addr += PGDIR_SIZE;
301 flush_tlb_range(current->mm, IO_START, IO_START + IO_SIZE);
303 dst_addr = EASI_START;
304 src_pgd = pgd_offset(current->mm, EASI_BASE);
305 dst_pgd = pgd_offset(current->mm, dst_addr);
307 while (dst_addr < EASI_START + EASI_SIZE) {
308 *dst_pgd++ = *src_pgd++;
309 dst_addr += PGDIR_SIZE;
312 flush_tlb_range(current->mm, EASI_START, EASI_START + EASI_SIZE);
315 static int
316 ecard_task(void * unused)
318 current->session = 1;
319 current->pgrp = 1;
322 * We don't want /any/ signals, not even SIGKILL
324 sigfillset(&current->blocked);
325 sigemptyset(&current->signal);
327 strcpy(current->comm, "kecardd");
330 * Set up the environment
332 ecard_init_task();
334 while (1) {
335 struct ecard_request *req;
337 do {
338 req = xchg(&ecard_req, NULL);
340 if (req == NULL) {
341 sigemptyset(&current->signal);
342 interruptible_sleep_on(&ecard_wait);
344 } while (req == NULL);
346 switch (req->req) {
347 case req_readbytes:
348 ecard_task_readbytes(req);
349 break;
351 case req_reset:
352 ecard_task_reset(req);
353 break;
355 wake_up(&ecard_done);
360 * Wake the expansion card daemon to action our request.
362 * FIXME: The test here is not sufficient to detect if the
363 * kcardd is running.
365 static inline void
366 ecard_call(struct ecard_request *req)
369 * If we're called from task 0, or from an
370 * interrupt (will be keyboard interrupt),
371 * we forcefully set up the memory map, and
372 * call the loader. We can't schedule, or
373 * sleep for this call.
375 if ((current == &init_task || in_interrupt()) &&
376 req->req == req_reset && req->ec == NULL) {
377 ecard_init_task();
378 ecard_task_reset(req);
379 } else {
380 if (ecard_pid <= 0)
381 ecard_pid = kernel_thread(ecard_task, NULL, 0);
383 ecard_req = req;
385 wake_up(&ecard_wait);
387 sleep_on(&ecard_done);
390 #else
392 * On 26-bit processors, we don't need the kcardd thread to access the
393 * expansion card loaders. We do it directly.
395 static inline void
396 ecard_call(struct ecard_request *req)
398 if (req->req == req_reset)
399 ecard_task_reset(req);
400 else
401 ecard_task_readbytes(req);
403 #endif
405 /* ======================= Mid-level card control ===================== */
407 * This is called to reset the loaders for each expansion card on reboot.
409 * This is required to make sure that the card is in the correct state
410 * that RiscOS expects it to be.
412 void
413 ecard_reset(int slot)
415 struct ecard_request req;
417 req.req = req_reset;
419 if (slot < 0)
420 req.ec = NULL;
421 else
422 req.ec = slot_to_ecard(slot);
424 ecard_call(&req);
426 #ifdef HAS_EXPMASK
427 if (have_expmask && slot < 0) {
428 have_expmask |= ~0;
429 EXPMASK_ENABLE = have_expmask;
431 #endif
434 static void
435 ecard_readbytes(void *addr, ecard_t *ec, int off, int len, int useld)
437 struct ecard_request req;
439 req.req = req_readbytes;
440 req.ec = ec;
441 req.address = off;
442 req.length = len;
443 req.use_loader = useld;
444 req.buffer = addr;
446 ecard_call(&req);
449 int ecard_readchunk(struct in_chunk_dir *cd, ecard_t *ec, int id, int num)
451 struct ex_chunk_dir excd;
452 int index = 16;
453 int useld = 0;
455 if (!ec->cid.cd)
456 return 0;
458 while(1) {
459 ecard_readbytes(&excd, ec, index, 8, useld);
460 index += 8;
461 if (c_id(&excd) == 0) {
462 if (!useld && ec->loader) {
463 useld = 1;
464 index = 0;
465 continue;
467 return 0;
469 if (c_id(&excd) == 0xf0) { /* link */
470 index = c_start(&excd);
471 continue;
473 if (c_id(&excd) == 0x80) { /* loader */
474 if (!ec->loader) {
475 ec->loader = (loader_t)kmalloc(c_len(&excd),
476 GFP_KERNEL);
477 if (ec->loader)
478 ecard_readbytes(ec->loader, ec,
479 (int)c_start(&excd),
480 c_len(&excd), useld);
481 else
482 return 0;
484 continue;
486 if (c_id(&excd) == id && num-- == 0)
487 break;
490 if (c_id(&excd) & 0x80) {
491 switch (c_id(&excd) & 0x70) {
492 case 0x70:
493 ecard_readbytes((unsigned char *)excd.d.string, ec,
494 (int)c_start(&excd), c_len(&excd),
495 useld);
496 break;
497 case 0x00:
498 break;
501 cd->start_offset = c_start(&excd);
502 memcpy(cd->d.string, excd.d.string, 256);
503 return 1;
506 /* ======================= Interrupt control ============================ */
508 static void ecard_def_irq_enable(ecard_t *ec, int irqnr)
510 #ifdef HAS_EXPMASK
511 if (irqnr < 4 && have_expmask) {
512 have_expmask |= 1 << irqnr;
513 EXPMASK_ENABLE = have_expmask;
515 #endif
518 static void ecard_def_irq_disable(ecard_t *ec, int irqnr)
520 #ifdef HAS_EXPMASK
521 if (irqnr < 4 && have_expmask) {
522 have_expmask &= ~(1 << irqnr);
523 EXPMASK_ENABLE = have_expmask;
525 #endif
528 static int ecard_def_irq_pending(ecard_t *ec)
530 return !ec->irqmask || ec->irqaddr[0] & ec->irqmask;
533 static void ecard_def_fiq_enable(ecard_t *ec, int fiqnr)
535 panic("ecard_def_fiq_enable called - impossible");
538 static void ecard_def_fiq_disable(ecard_t *ec, int fiqnr)
540 panic("ecard_def_fiq_disable called - impossible");
543 static int ecard_def_fiq_pending(ecard_t *ec)
545 return !ec->fiqmask || ec->fiqaddr[0] & ec->fiqmask;
548 static expansioncard_ops_t ecard_default_ops = {
549 ecard_def_irq_enable,
550 ecard_def_irq_disable,
551 ecard_def_irq_pending,
552 ecard_def_fiq_enable,
553 ecard_def_fiq_disable,
554 ecard_def_fiq_pending
558 * Enable and disable interrupts from expansion cards.
559 * (interrupts are disabled for these functions).
561 * They are not meant to be called directly, but via enable/disable_irq.
563 void ecard_enableirq(unsigned int irqnr)
565 ecard_t *ec = slot_to_ecard(irqnr - 32);
567 if (ec) {
568 if (!ec->ops)
569 ec->ops = &ecard_default_ops;
571 if (ec->claimed && ec->ops->irqenable)
572 ec->ops->irqenable(ec, irqnr);
573 else
574 printk(KERN_ERR "ecard: rejecting request to "
575 "enable IRQs for %d\n", irqnr);
579 void ecard_disableirq(unsigned int irqnr)
581 ecard_t *ec = slot_to_ecard(irqnr - 32);
583 if (ec) {
584 if (!ec->ops)
585 ec->ops = &ecard_default_ops;
587 if (ec->ops && ec->ops->irqdisable)
588 ec->ops->irqdisable(ec, irqnr);
592 void ecard_enablefiq(unsigned int fiqnr)
594 ecard_t *ec = slot_to_ecard(fiqnr);
596 if (ec) {
597 if (!ec->ops)
598 ec->ops = &ecard_default_ops;
600 if (ec->claimed && ec->ops->fiqenable)
601 ec->ops->fiqenable(ec, fiqnr);
602 else
603 printk(KERN_ERR "ecard: rejecting request to "
604 "enable FIQs for %d\n", fiqnr);
608 void ecard_disablefiq(unsigned int fiqnr)
610 ecard_t *ec = slot_to_ecard(fiqnr);
612 if (ec) {
613 if (!ec->ops)
614 ec->ops = &ecard_default_ops;
616 if (ec->ops->fiqdisable)
617 ec->ops->fiqdisable(ec, fiqnr);
621 static void
622 ecard_dump_irq_state(ecard_t *ec)
624 printk(" %d: %sclaimed, ",
625 ec->slot_no,
626 ec->claimed ? "" : "not ");
628 if (ec->ops && ec->ops->irqpending &&
629 ec->ops != &ecard_default_ops)
630 printk("irq %spending\n",
631 ec->ops->irqpending(ec) ? "" : "not ");
632 else
633 printk("irqaddr %p, mask = %02X, status = %02X\n",
634 ec->irqaddr, ec->irqmask, *ec->irqaddr);
637 static void
638 ecard_check_lockup(void)
640 static int last, lockup;
641 ecard_t *ec;
644 * If the timer interrupt has not run since the last million
645 * unrecognised expansion card interrupts, then there is
646 * something seriously wrong. Disable the expansion card
647 * interrupts so at least we can continue.
649 * Maybe we ought to start a timer to re-enable them some time
650 * later?
652 if (last == jiffies) {
653 lockup += 1;
654 if (lockup > 1000000) {
655 printk(KERN_ERR "\nInterrupt lockup detected - "
656 "disabling all expansion card interrupts\n");
658 disable_irq(IRQ_EXPANSIONCARD);
660 printk("Expansion card IRQ state:\n");
662 for (ec = cards; ec; ec = ec->next)
663 ecard_dump_irq_state(ec);
665 } else
666 lockup = 0;
669 * If we did not recognise the source of this interrupt,
670 * warn the user, but don't flood the user with these messages.
672 if (!last || time_after(jiffies, last + 5*HZ)) {
673 last = jiffies;
674 printk(KERN_WARNING "Unrecognised interrupt from backplane\n");
678 static void
679 ecard_irq_noexpmask(int intr_no, void *dev_id, struct pt_regs *regs)
681 ecard_t *ec;
682 int called = 0;
684 for (ec = cards; ec; ec = ec->next) {
685 int pending;
687 if (!ec->claimed || ec->irq == NO_IRQ || ec->slot_no == 8)
688 continue;
690 if (ec->ops && ec->ops->irqpending)
691 pending = ec->ops->irqpending(ec);
692 else
693 pending = ecard_default_ops.irqpending(ec);
695 if (pending) {
696 do_ecard_IRQ(ec->irq, regs);
697 called ++;
700 cli();
702 if (called == 0)
703 ecard_check_lockup();
706 #ifdef HAS_EXPMASK
707 static unsigned char priority_masks[] =
709 0xf0, 0xf1, 0xf3, 0xf7, 0xff, 0xff, 0xff, 0xff
712 static unsigned char first_set[] =
714 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
715 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00
718 static void
719 ecard_irq_expmask(int intr_no, void *dev_id, struct pt_regs *regs)
721 const unsigned int statusmask = 15;
722 unsigned int status;
724 status = EXPMASK_STATUS & statusmask;
725 if (status) {
726 unsigned int slot;
727 ecard_t *ec;
728 again:
729 slot = first_set[status];
730 ec = slot_to_ecard(slot);
731 if (ec->claimed) {
732 unsigned int oldexpmask;
734 * this ugly code is so that we can operate a
735 * prioritorising system:
737 * Card 0 highest priority
738 * Card 1
739 * Card 2
740 * Card 3 lowest priority
742 * Serial cards should go in 0/1, ethernet/scsi in 2/3
743 * otherwise you will lose serial data at high speeds!
745 oldexpmask = have_expmask;
746 EXPMASK_ENABLE = (have_expmask &= priority_masks[slot]);
747 sti();
748 do_ecard_IRQ(ec->irq, regs);
749 cli();
750 EXPMASK_ENABLE = have_expmask = oldexpmask;
751 status = EXPMASK_STATUS & statusmask;
752 if (status)
753 goto again;
754 } else {
755 printk(KERN_WARNING "card%d: interrupt from unclaimed "
756 "card???\n", slot);
757 EXPMASK_ENABLE = (have_expmask &= ~(1 << slot));
759 } else
760 printk(KERN_WARNING "Wild interrupt from backplane (masks)\n");
763 static void __init
764 ecard_probeirqhw(void)
766 ecard_t *ec;
767 int found;
769 EXPMASK_ENABLE = 0x00;
770 EXPMASK_STATUS = 0xff;
771 found = ((EXPMASK_STATUS & 15) == 0);
772 EXPMASK_ENABLE = 0xff;
774 if (!found)
775 return;
777 printk(KERN_DEBUG "Expansion card interrupt "
778 "management hardware found\n");
780 irqexpansioncard.handler = ecard_irq_expmask;
782 /* for each card present, set a bit to '1' */
783 have_expmask = 0x80000000;
785 for (ec = cards; ec; ec = ec->next)
786 have_expmask |= 1 << ec->slot_no;
788 EXPMASK_ENABLE = have_expmask;
790 #else
791 #define ecard_probeirqhw()
792 #endif
794 #ifndef IO_EC_MEMC8_BASE
795 #define IO_EC_MEMC8_BASE 0
796 #endif
798 unsigned int ecard_address(ecard_t *ec, card_type_t type, card_speed_t speed)
800 unsigned long address = 0;
801 int slot = ec->slot_no;
803 if (ec->slot_no == 8)
804 return IO_EC_MEMC8_BASE;
806 ectcr &= ~(1 << slot);
808 switch (type) {
809 case ECARD_MEMC:
810 if (slot < 4)
811 address = IO_EC_MEMC_BASE + (slot << 12);
812 break;
814 case ECARD_IOC:
815 if (slot < 4)
816 address = IO_EC_IOC_BASE + (slot << 12);
817 #ifdef IO_EC_IOC4_BASE
818 else
819 address = IO_EC_IOC4_BASE + ((slot - 4) << 12);
820 #endif
821 if (address)
822 address += speed << 17;
823 break;
825 #ifdef IO_EC_EASI_BASE
826 case ECARD_EASI:
827 address = IO_EC_EASI_BASE + (slot << 22);
828 if (speed == ECARD_FAST)
829 ectcr |= 1 << slot;
830 break;
831 #endif
832 default:
833 break;
836 #ifdef IOMD_ECTCR
837 outb(ectcr, IOMD_ECTCR);
838 #endif
839 return address;
842 static int ecard_prints(char *buffer, ecard_t *ec)
844 char *start = buffer;
846 buffer += sprintf(buffer, " %d: %s ", ec->slot_no,
847 ec->type == ECARD_EASI ? "EASI" : " ");
849 if (ec->cid.id == 0) {
850 struct in_chunk_dir incd;
852 buffer += sprintf(buffer, "[%04X:%04X] ",
853 ec->cid.manufacturer, ec->cid.product);
855 if (!ec->card_desc && ec->cid.cd &&
856 ecard_readchunk(&incd, ec, 0xf5, 0)) {
857 ec->card_desc = kmalloc(strlen(incd.d.string)+1, GFP_KERNEL);
859 if (ec->card_desc)
860 strcpy((char *)ec->card_desc, incd.d.string);
863 buffer += sprintf(buffer, "%s\n", ec->card_desc ? ec->card_desc : "*unknown*");
864 } else
865 buffer += sprintf(buffer, "Simple card %d\n", ec->cid.id);
867 return buffer - start;
870 static int get_ecard_dev_info(char *buf, char **start, off_t pos, int count)
872 ecard_t *ec = cards;
873 off_t at = 0;
874 int len, cnt;
876 cnt = 0;
877 while (ec && count > cnt) {
878 len = ecard_prints(buf, ec);
879 at += len;
880 if (at >= pos) {
881 if (!*start) {
882 *start = buf + (pos - (at - len));
883 cnt = at - pos;
884 } else
885 cnt += len;
886 buf += len;
888 ec = ec->next;
890 return (count > cnt) ? cnt : count;
893 static struct proc_dir_entry *proc_bus_ecard_dir = NULL;
895 static void ecard_proc_init(void)
897 proc_bus_ecard_dir = proc_mkdir("ecard", proc_bus);
898 create_proc_info_entry("devices", 0, proc_bus_ecard_dir,
899 get_ecard_dev_info);
903 * Probe for an expansion card.
905 * If bit 1 of the first byte of the card is set, then the
906 * card does not exist.
908 static int __init
909 ecard_probe(int slot, card_type_t type)
911 ecard_t **ecp;
912 ecard_t *ec;
913 struct ex_ecid cid;
914 int i, rc = -ENOMEM;
916 ec = kmalloc(sizeof(ecard_t), GFP_KERNEL);
918 if (!ec)
919 goto nodev;
921 memset(ec, 0, sizeof(ecard_t));
923 ec->slot_no = slot;
924 ec->type = type;
925 ec->irq = NO_IRQ;
926 ec->fiq = NO_IRQ;
927 ec->dma = NO_DMA;
928 ec->card_desc = NULL;
929 ec->ops = &ecard_default_ops;
931 rc = -ENODEV;
932 if ((ec->podaddr = ecard_address(ec, type, ECARD_SYNC)) == 0)
933 goto nodev;
935 cid.r_zero = 1;
936 ecard_readbytes(&cid, ec, 0, 16, 0);
937 if (cid.r_zero)
938 goto nodev;
940 ec->cid.id = cid.r_id;
941 ec->cid.cd = cid.r_cd;
942 ec->cid.is = cid.r_is;
943 ec->cid.w = cid.r_w;
944 ec->cid.manufacturer = ecard_getu16(cid.r_manu);
945 ec->cid.product = ecard_getu16(cid.r_prod);
946 ec->cid.country = cid.r_country;
947 ec->cid.irqmask = cid.r_irqmask;
948 ec->cid.irqoff = ecard_gets24(cid.r_irqoff);
949 ec->cid.fiqmask = cid.r_fiqmask;
950 ec->cid.fiqoff = ecard_gets24(cid.r_fiqoff);
951 ec->fiqaddr =
952 ec->irqaddr = (unsigned char *)ioaddr(ec->podaddr);
954 if (ec->cid.is) {
955 ec->irqmask = ec->cid.irqmask;
956 ec->irqaddr += ec->cid.irqoff;
957 ec->fiqmask = ec->cid.fiqmask;
958 ec->fiqaddr += ec->cid.fiqoff;
959 } else {
960 ec->irqmask = 1;
961 ec->fiqmask = 4;
964 for (i = 0; i < sizeof(blacklist) / sizeof(*blacklist); i++)
965 if (blacklist[i].manufacturer == ec->cid.manufacturer &&
966 blacklist[i].product == ec->cid.product) {
967 ec->card_desc = blacklist[i].type;
968 break;
971 ec->irq = 32 + slot;
972 #ifdef IO_EC_MEMC8_BASE
973 if (slot == 8)
974 ec->irq = 11;
975 #endif
976 #ifdef CONFIG_ARCH_RPC
977 /* On RiscPC, only first two slots have DMA capability */
978 if (slot < 2)
979 ec->dma = 2 + slot;
980 #endif
981 #if 0 /* We don't support FIQs on expansion cards at the moment */
982 ec->fiq = 96 + slot;
983 #endif
985 rc = 0;
987 for (ecp = &cards; *ecp; ecp = &(*ecp)->next);
989 *ecp = ec;
991 nodev:
992 if (rc && ec)
993 kfree(ec);
994 else
995 slot_to_expcard[slot] = ec;
997 return rc;
1000 static ecard_t *finding_pos;
1002 void ecard_startfind(void)
1004 finding_pos = NULL;
1007 ecard_t *ecard_find(int cid, const card_ids *cids)
1009 if (!finding_pos)
1010 finding_pos = cards;
1011 else
1012 finding_pos = finding_pos->next;
1014 for (; finding_pos; finding_pos = finding_pos->next) {
1015 if (finding_pos->claimed)
1016 continue;
1018 if (!cids) {
1019 if ((finding_pos->cid.id ^ cid) == 0)
1020 break;
1021 } else {
1022 unsigned int manufacturer, product;
1023 int i;
1025 manufacturer = finding_pos->cid.manufacturer;
1026 product = finding_pos->cid.product;
1028 for (i = 0; cids[i].manufacturer != 65535; i++)
1029 if (manufacturer == cids[i].manufacturer &&
1030 product == cids[i].product)
1031 break;
1033 if (cids[i].manufacturer != 65535)
1034 break;
1038 return finding_pos;
1041 static void __init ecard_free_all(void)
1043 ecard_t *ec, *ecn;
1045 for (ec = cards; ec; ec = ecn) {
1046 ecn = ec->next;
1048 kfree(ec);
1051 cards = NULL;
1053 memset(slot_to_expcard, 0, sizeof(slot_to_expcard));
1057 * Initialise the expansion card system.
1058 * Locate all hardware - interrupt management and
1059 * actual cards.
1061 void __init ecard_init(void)
1063 int slot;
1065 oldlatch_init();
1067 #ifdef CONFIG_CPU_32
1068 init_waitqueue_head(&ecard_wait);
1069 init_waitqueue_head(&ecard_done);
1070 #endif
1072 printk("Probing expansion cards\n");
1074 for (slot = 0; slot < 8; slot ++) {
1075 if (ecard_probe(slot, ECARD_EASI) == -ENODEV)
1076 ecard_probe(slot, ECARD_IOC);
1079 #ifdef IO_EC_MEMC8_BASE
1080 ecard_probe(8, ECARD_IOC);
1081 #endif
1083 ecard_probeirqhw();
1085 if (setup_arm_irq(IRQ_EXPANSIONCARD, &irqexpansioncard)) {
1086 printk(KERN_ERR "Unable to claim IRQ%d for expansion cards\n",
1087 IRQ_EXPANSIONCARD);
1088 ecard_free_all();
1091 ecard_proc_init();
1094 EXPORT_SYMBOL(ecard_startfind);
1095 EXPORT_SYMBOL(ecard_find);
1096 EXPORT_SYMBOL(ecard_readchunk);
1097 EXPORT_SYMBOL(ecard_address);