dma-arc.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:6k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/arch/arm/kernel/dma-arc.c
  3.  *
  4.  *  Copyright (C) 1998-1999 Dave Gilbert / Russell King
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  *
  10.  *  DMA functions specific to Archimedes and A5000 architecture
  11.  */
  12. #include <linux/config.h>
  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. #include <asm/mach/dma.h>
  22. #define DPRINTK(x...) printk(KERN_DEBUG x)
  23. #if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
  24. static void arc_floppy_data_enable_dma(dmach_t channel, dma_t *dma)
  25. {
  26. DPRINTK("arc_floppy_data_enable_dman");
  27. switch (dma->dma_mode) {
  28. case DMA_MODE_READ: { /* read */
  29. extern unsigned char fdc1772_dma_read, fdc1772_dma_read_end;
  30. extern void fdc1772_setupdma(unsigned int count,unsigned int addr);
  31. unsigned long flags;
  32. DPRINTK("enable_dma fdc1772 data readn");
  33. save_flags(flags);
  34. clf();
  35. memcpy ((void *)0x1c, (void *)&fdc1772_dma_read,
  36. &fdc1772_dma_read_end - &fdc1772_dma_read);
  37. fdc1772_setupdma(dma->buf.length, dma->buf.address); /* Sets data pointer up */
  38. enable_fiq(FIQ_FLOPPYDATA);
  39. restore_flags(flags);
  40.    }
  41.    break;
  42. case DMA_MODE_WRITE: { /* write */
  43. extern unsigned char fdc1772_dma_write, fdc1772_dma_write_end;
  44. extern void fdc1772_setupdma(unsigned int count,unsigned int addr);
  45. unsigned long flags;
  46. DPRINTK("enable_dma fdc1772 data writen");
  47. save_flags(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. restore_flags(flags);
  54.     }
  55.     break;
  56. default:
  57. printk ("enable_dma: dma%d not initialisedn", 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_dman");
  72. /*printk("enable_dma fdc1772 command end FIQn");*/
  73. save_flags(flags);
  74. clf();
  75. /* B fdc1772_comendhandler */
  76. *((unsigned int *)0x1c)=0xea000000 |
  77. (((unsigned int)fdc1772_comendhandler-(0x1c+8))/4);
  78. restore_flags(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->dma_mode == DMA_MODE_READ) {
  122. extern unsigned char floppy_fiqin_start, floppy_fiqin_end;
  123. fiqhandler_start = &floppy_fiqin_start;
  124. fiqhandler_length = &floppy_fiqin_end - &floppy_fiqin_start;
  125. } else {
  126. extern unsigned char floppy_fiqout_start, floppy_fiqout_end;
  127. fiqhandler_start = &floppy_fiqout_start;
  128. fiqhandler_length = &floppy_fiqout_end - &floppy_fiqout_start;
  129. }
  130. if (claim_fiq(&fh)) {
  131. printk("floppydma: couldn't claim FIQ.n");
  132. return;
  133. }
  134. memcpy((void *)0x1c, fiqhandler_start, fiqhandler_length);
  135. regs.ARM_r9 = dma->buf.length;
  136. regs.ARM_r10 = (unsigned long)dma->buf.address;
  137. regs.ARM_fp = FLOPPYDMA_BASE;
  138. set_fiq_regs(&regs);
  139. enable_fiq(dma->dma_irq);
  140. }
  141. static void a5k_floppy_disable_dma(dmach_t channel, dma_t *dma)
  142. {
  143. disable_fiq(dma->dma_irq);
  144. release_fiq(&fh);
  145. }
  146. static struct dma_ops a5k_floppy_dma_ops = {
  147. type: "FIQDMA",
  148. enable: a5k_floppy_enable_dma,
  149. disable: a5k_floppy_disable_dma,
  150. residue: a5k_floppy_get_dma_residue,
  151. };
  152. #endif
  153. /*
  154.  * This is virtual DMA - we don't need anything here
  155.  */
  156. static void sound_enable_disable_dma(dmach_t channel, dma_t *dma)
  157. {
  158. }
  159. static struct dma_ops sound_dma_ops = {
  160. type: "VIRTUAL",
  161. enable: sound_enable_disable_dma,
  162. disable: sound_enable_disable_dma,
  163. };
  164. void __init arch_dma_init(dma_t *dma)
  165. {
  166. #if defined(CONFIG_BLK_DEV_FD1772) || defined(CONFIG_BLK_DEV_FD1772_MODULE)
  167. if (machine_is_archimedes()) {
  168. dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
  169. dma[DMA_VIRTUAL_FLOPPY0].d_ops   = &arc_floppy_data_dma_ops;
  170. dma[DMA_VIRTUAL_FLOPPY1].dma_irq = 1;
  171. dma[DMA_VIRTUAL_FLOPPY1].d_ops   = &arc_floppy_cmdend_dma_ops;
  172. }
  173. #endif
  174. #ifdef CONFIG_ARCH_A5K
  175. if (machine_is_a5k()) {
  176. dma[DMA_VIRTUAL_FLOPPY0].dma_irq = FIQ_FLOPPYDATA;
  177. dma[DMA_VIRTUAL_FLOPPY0].d_ops   = &a5k_floppy_dma_ops;
  178. }
  179. #endif
  180. dma[DMA_VIRTUAL_SOUND].d_ops = &sound_dma_ops;
  181. }