dma.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * linux/arch/arm26/kernel/dma.c
  3. *
  4. * Copyright (C) 1998-1999 Dave Gilbert / Russell King
  5. * Copyright (C) 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. * DMA functions specific to Archimedes and A5000 architecture
  12. */
  13. #include <linux/sched.h>
  14. #include <linux/init.h>
  15. #include <asm/dma.h>
  16. #include <asm/fiq.h>
  17. #include <asm/irq.h>
  18. #include <asm/io.h>
  19. #include <asm/hardware.h>
  20. #include <asm/mach-types.h>
  21. #define DPRINTK(x...) printk(KERN_DEBUG x)
  22. #if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
  23. extern unsigned char fdc1772_dma_read, fdc1772_dma_read_end;
  24. extern unsigned char fdc1772_dma_write, fdc1772_dma_write_end;
  25. extern void fdc1772_setupdma(unsigned int count,unsigned int addr);
  26. static void arc_floppy_data_enable_dma(dmach_t channel, dma_t *dma)
  27. {
  28. DPRINTK("arc_floppy_data_enable_dma\n");
  29. if (dma->using_sg)
  30. BUG();
  31. switch (dma->dma_mode) {
  32. case DMA_MODE_READ: { /* read */
  33. unsigned long flags;
  34. DPRINTK("enable_dma fdc1772 data read\n");
  35. local_save_flags_cli(flags);
  36. clf();
  37. memcpy ((void *)0x1c, (void *)&fdc1772_dma_read,
  38. &fdc1772_dma_read_end - &fdc1772_dma_read);
  39. fdc1772_setupdma(dma->buf.length, dma->buf.__address); /* Sets data pointer up */
  40. enable_fiq(FIQ_FLOPPYDATA);
  41. local_irq_restore(flags);
  42. }
  43. break;
  44. case DMA_MODE_WRITE: { /* write */
  45. unsigned long flags;
  46. DPRINTK("enable_dma fdc1772 data write\n");
  47. local_save_flags_cli(flags);
  48. clf();
  49. memcpy ((void *)0x1c, (void *)&fdc1772_dma_write,
  50. &fdc1772_dma_write_end - &fdc1772_dma_write);
  51. fdc1772_setupdma(dma->buf.length, dma->buf.__address); /* Sets data pointer up */
  52. enable_fiq(FIQ_FLOPPYDATA);
  53. local_irq_restore(flags);
  54. }
  55. break;
  56. default:
  57. printk ("enable_dma: dma%d not initialised\n", channel);
  58. }
  59. }
  60. static int arc_floppy_data_get_dma_residue(dmach_t channel, dma_t *dma)
  61. {
  62. extern unsigned int fdc1772_bytestogo;
  63. /* 10/1/1999 DAG - I presume its the number of bytes left? */
  64. return fdc1772_bytestogo;
  65. }
  66. static void arc_floppy_cmdend_enable_dma(dmach_t channel, dma_t *dma)
  67. {
  68. /* Need to build a branch at the FIQ address */
  69. extern void fdc1772_comendhandler(void);
  70. unsigned long flags;
  71. DPRINTK("arc_floppy_cmdend_enable_dma\n");
  72. /*printk("enable_dma fdc1772 command end FIQ\n");*/
  73. save_flags(flags);
  74. clf();
  75. /* B fdc1772_comendhandler */
  76. *((unsigned int *)0x1c)=0xea000000 |
  77. (((unsigned int)fdc1772_comendhandler-(0x1c+8))/4);
  78. local_irq_restore(flags);
  79. }
  80. static int arc_floppy_cmdend_get_dma_residue(dmach_t channel, dma_t *dma)
  81. {
  82. /* 10/1/1999 DAG - Presume whether there is an outstanding command? */
  83. extern unsigned int fdc1772_fdc_int_done;
  84. /* Explicit! If the int done is 0 then 1 int to go */
  85. return (fdc1772_fdc_int_done==0)?1:0;
  86. }
  87. static void arc_disable_dma(dmach_t channel, dma_t *dma)
  88. {
  89. disable_fiq(dma->dma_irq);
  90. }
  91. static struct dma_ops arc_floppy_data_dma_ops = {
  92. .type = "FIQDMA",
  93. .enable = arc_floppy_data_enable_dma,
  94. .disable = arc_disable_dma,
  95. .residue = arc_floppy_data_get_dma_residue,
  96. };
  97. static struct dma_ops arc_floppy_cmdend_dma_ops = {
  98. .type = "FIQCMD",
  99. .enable = arc_floppy_cmdend_enable_dma,
  100. .disable = arc_disable_dma,
  101. .residue = arc_floppy_cmdend_get_dma_residue,
  102. };
  103. #endif
  104. #ifdef CONFIG_ARCH_A5K
  105. static struct fiq_handler fh = {
  106. .name = "floppydata"
  107. };
  108. static int a5k_floppy_get_dma_residue(dmach_t channel, dma_t *dma)
  109. {
  110. struct pt_regs regs;
  111. get_fiq_regs(&regs);
  112. return regs.ARM_r9;
  113. }
  114. static void a5k_floppy_enable_dma(dmach_t channel, dma_t *dma)
  115. {
  116. struct pt_regs regs;
  117. void *fiqhandler_start;
  118. unsigned int fiqhandler_length;
  119. extern void floppy_fiqsetup(unsigned long len, unsigned long addr,
  120. unsigned long port);
  121. if (dma->using_sg)
  122. BUG();
  123. if (dma->dma_mode == DMA_MODE_READ) {
  124. extern unsigned char floppy_fiqin_start, floppy_fiqin_end;
  125. fiqhandler_start = &floppy_fiqin_start;
  126. fiqhandler_length = &floppy_fiqin_end - &floppy_fiqin_start;
  127. } else {
  128. extern unsigned char floppy_fiqout_start, floppy_fiqout_end;
  129. fiqhandler_start = &floppy_fiqout_start;
  130. fiqhandler_length = &floppy_fiqout_end - &floppy_fiqout_start;
  131. }
  132. if (claim_fiq(&fh)) {
  133. printk("floppydma: couldn't claim FIQ.\n");
  134. return;
  135. }
  136. memcpy((void *)0x1c, fiqhandler_start, fiqhandler_length);
  137. regs.ARM_r9 = dma->buf.length;
  138. regs.ARM_r10 = (unsigned long)dma->buf.__address;
  139. regs.ARM_fp = FLOPPYDMA_BASE;
  140. set_fiq_regs(&regs);
  141. enable_fiq(dma->dma_irq);
  142. }
  143. static void a5k_floppy_disable_dma(dmach_t channel, dma_t *dma)
  144. {
  145. disable_fiq(dma->dma_irq);
  146. release_fiq(&fh);
  147. }
  148. static struct dma_ops a5k_floppy_dma_ops = {
  149. .type = "FIQDMA",
  150. .enable = a5k_floppy_enable_dma,
  151. .disable = a5k_floppy_disable_dma,
  152. .residue = a5k_floppy_get_dma_residue,
  153. };
  154. #endif
  155. /*
  156. * This is virtual DMA - we don't need anything here
  157. */
  158. static void sound_enable_disable_dma(dmach_t channel, dma_t *dma)
  159. {
  160. }
  161. static struct dma_ops sound_dma_ops = {
  162. .type = "VIRTUAL",
  163. .enable = sound_enable_disable_dma,
  164. .disable = sound_enable_disable_dma,
  165. };
  166. void __init arch_dma_init(dma_t *dma)
  167. {
  168. #if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
  169. if (machine_is_archimedes()) {
  170. dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
  171. dma[DMA_VIRTUAL_FLOPPY0].d_ops = &arc_floppy_data_dma_ops;
  172. dma[DMA_VIRTUAL_FLOPPY1].dma_irq = 1;
  173. dma[DMA_VIRTUAL_FLOPPY1].d_ops = &arc_floppy_cmdend_dma_ops;
  174. }
  175. #endif
  176. #ifdef CONFIG_ARCH_A5K
  177. if (machine_is_a5k()) {
  178. dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
  179. dma[DMA_VIRTUAL_FLOPPY0].d_ops = &a5k_floppy_dma_ops;
  180. }
  181. #endif
  182. dma[DMA_VIRTUAL_SOUND].d_ops = &sound_dma_ops;
  183. }