30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/sched.h>
36 #include <linux/reboot.h>
38 #include <linux/slab.h>
41 #include <linux/device.h>
50 #include <mach/hardware.h>
52 #include <asm/mmu_context.h>
54 #include <asm/tlbflush.h>
76 static unsigned int ectcr;
90 static inline unsigned short ecard_getu16(
unsigned char *
v)
92 return v[0] | v[1] << 8;
95 static inline signed long ecard_gets24(
unsigned char *
v)
97 return v[0] | v[1] << 8 | v[2] << 16 | ((v[2] & 0x80) ? 0xff000000 : 0);
100 static inline ecard_t *slot_to_ecard(
unsigned int slot)
136 unsigned int off = req->
address;
147 static unsigned int index;
150 page = (off >> 12) * 4;
160 if (off == 0 ||
index > off) {
169 while (
index < off) {
179 unsigned long base = (ec->
easi
187 *buf++ =
readb(pbase + off);
196 *(
unsigned long *)0x108 = 0;
212 static void ecard_init_pgtables(
struct mm_struct *mm)
227 pgd_t *src_pgd, *dst_pgd;
239 vma.vm_flags = VM_EXEC;
246 static int ecard_init_mm(
void)
258 ecard_init_pgtables(mm);
272 panic(
"kecardd: unable to alloc mm\n");
313 ecard_readbytes(
void *
addr,
ecard_t *ec,
int off,
int len,
int useld)
317 req.
fn = ecard_task_readbytes;
337 ecard_readbytes(&excd, ec, index, 8, useld);
339 if (
c_id(&excd) == 0) {
340 if (!useld && ec->
loader) {
347 if (
c_id(&excd) == 0xf0) {
351 if (
c_id(&excd) == 0x80) {
356 ecard_readbytes(ec->
loader, ec,
358 c_len(&excd), useld);
364 if (
c_id(&excd) ==
id && num-- == 0)
368 if (
c_id(&excd) & 0x80) {
369 switch (
c_id(&excd) & 0x70) {
371 ecard_readbytes((
unsigned char *)excd.
d.
string, ec,
386 static void ecard_def_irq_enable(
ecard_t *ec,
int irqnr)
390 static void ecard_def_irq_disable(
ecard_t *ec,
int irqnr)
394 static int ecard_def_irq_pending(
ecard_t *ec)
399 static void ecard_def_fiq_enable(
ecard_t *ec,
int fiqnr)
401 panic(
"ecard_def_fiq_enable called - impossible");
404 static void ecard_def_fiq_disable(
ecard_t *ec,
int fiqnr)
406 panic(
"ecard_def_fiq_disable called - impossible");
409 static int ecard_def_fiq_pending(
ecard_t *ec)
415 ecard_def_irq_enable,
416 ecard_def_irq_disable,
417 ecard_def_irq_pending,
418 ecard_def_fiq_enable,
419 ecard_def_fiq_disable,
420 ecard_def_fiq_pending
429 static void ecard_irq_unmask(
struct irq_data *
d)
431 ecard_t *ec = irq_data_get_irq_chip_data(d);
435 ec->
ops = &ecard_default_ops;
441 "enable IRQs for %d\n", d->
irq);
445 static void ecard_irq_mask(
struct irq_data *d)
447 ecard_t *ec = irq_data_get_irq_chip_data(d);
451 ec->
ops = &ecard_default_ops;
458 static struct irq_chip ecard_chip = {
460 .irq_ack = ecard_irq_mask,
461 .irq_mask = ecard_irq_mask,
462 .irq_unmask = ecard_irq_unmask,
467 ecard_t *ec = slot_to_ecard(fiqnr);
471 ec->
ops = &ecard_default_ops;
477 "enable FIQs for %d\n", fiqnr);
483 ecard_t *ec = slot_to_ecard(fiqnr);
487 ec->
ops = &ecard_default_ops;
494 static void ecard_dump_irq_state(
void)
498 printk(
"Expansion card IRQ state:\n");
500 for (ec = cards; ec; ec = ec->
next) {
504 printk(
" %d: %sclaimed, ",
508 ec->
ops != &ecard_default_ops)
512 printk(
"irqaddr %p, mask = %02X, status = %02X\n",
519 static unsigned long last;
531 if (last == jiffies) {
533 if (lockup > 1000000) {
535 "disabling all expansion card interrupts\n");
538 ecard_dump_irq_state();
550 ecard_dump_irq_state();
555 ecard_irq_handler(
unsigned int irq,
struct irq_desc *desc)
561 for (ec = cards; ec; ec = ec->
next) {
580 ecard_check_lockup(desc);
591 ectcr &= ~(1 <<
slot);
605 address += speed << 19;
628 if (ec->
cid.id == 0) {
632 ec->
cid.manufacturer, ec->
cid.product);
649 static int ecard_devices_proc_show(
struct seq_file *m,
void *
v)
667 .open = ecard_devices_proc_open,
675 static void ecard_proc_init(
void)
678 proc_create(
"devices", 0, proc_bus_ecard_dir, &bus_ecard_proc_fops);
681 #define ec_set_resource(ec,nr,st,sz) \
683 (ec)->resource[nr].name = dev_name(&ec->dev); \
684 (ec)->resource[nr].start = st; \
685 (ec)->resource[nr].end = (st) + (sz) - 1; \
686 (ec)->resource[nr].flags = IORESOURCE_MEM; \
717 ec->
ops = &ecard_default_ops;
734 #ifdef CONFIG_ARCH_RPC
753 dev_err(&ec->
dev,
"resource(s) not available\n");
783 str +=
sprintf(str,
"%08x %08x %08lx\n",
794 return sprintf(buf,
"%u\n", ec->
cid.manufacturer);
806 return sprintf(buf,
"%s\n", ec->
easi ?
"EASI" :
"IOC");
828 ec->
dev.driver->name)) {
864 unsigned long offset,
unsigned long maxsize)
869 if (offset > (end - start))
873 if (maxsize && end - start > maxsize)
874 end = start + maxsize;
894 ec = ecard_alloc_card(type, slot);
905 ecard_readbytes(&
cid, ec, 0, 16, 0);
913 ec->
cid.manufacturer = ecard_getu16(
cid.r_manu);
914 ec->
cid.product = ecard_getu16(
cid.r_prod);
915 ec->
cid.country =
cid.r_country;
916 ec->
cid.irqmask =
cid.r_irqmask;
917 ec->
cid.irqoff = ecard_gets24(
cid.r_irqoff);
918 ec->
cid.fiqmask =
cid.r_fiqmask;
919 ec->
cid.fiqoff = ecard_gets24(
cid.r_fiqoff);
946 irq_set_chip_and_handler(ec->
irq, &ecard_chip,
952 #ifdef CONFIG_ARCH_RPC
958 for (ecp = &cards; *ecp; ecp = &(*ecp)->
next);
961 slot_to_expcard[
slot] = ec;
980 static int __init ecard_init(
void)
985 irqbase = irq_alloc_descs(-1, 0, 8, -1);
994 return PTR_ERR(task);
997 printk(
"Probing expansion cards\n");
999 for (slot = 0; slot < 8; slot ++) {
1001 ecard_probe(slot, irqbase + slot,
ECARD_IOC);
1031 static int ecard_drv_probe(
struct device *dev)
1038 id = ecard_match_device(drv->
id_table, ec);
1041 ret = drv->
probe(ec,
id);
1047 static int ecard_drv_remove(
struct device *dev)
1059 ec->
ops = &ecard_default_ops;
1072 static void ecard_drv_shutdown(
struct device *dev)
1088 req.
fn = ecard_task_reset;
1115 ret = ec->
cid.id == drv->
id;
1123 .dev_attrs = ecard_dev_attrs,
1124 .match = ecard_match,
1125 .probe = ecard_drv_probe,
1126 .remove = ecard_drv_remove,
1127 .shutdown = ecard_drv_shutdown,
1130 static int ecard_bus_init(
void)