dma.c 5.6 KB

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