memoryOperation.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* linux/arch/arm/plat-s3c24xx/dma.c
  2. *
  3. * Copyright 2003-2006 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2410 DMA core
  7. *
  8. * http://armlinux.simtec.co.uk/
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #ifdef CONFIG_S3C2410_DMA_DEBUG
  15. #define DEBUG
  16. #endif
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/sched.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/syscore_ops.h>
  23. #include <linux/slab.h>
  24. #include <linux/errno.h>
  25. #include <linux/io.h>
  26. #include <asm/irq.h>
  27. #include <mach/hardware.h>
  28. #include <mach/dma.h>
  29. #include <mach/map.h>
  30. #include <plat/dma-s3c24xx.h>
  31. #include <plat/regs-dma.h>
  32. /* io map for dma */
  33. static void __iomem *dma_base;
  34. static struct kmem_cache *dma_kmem;
  35. static int dma_channels;
  36. static struct s3c24xx_dma_selection dma_sel;
  37. /* debugging functions */
  38. #define BUF_MAGIC (0xcafebabe)
  39. #define dmawarn(fmt...) printk(KERN_DEBUG fmt)
  40. #define dma_regaddr(chan, reg) ((chan)->regs + (reg))
  41. #if 1
  42. #define dma_wrreg(chan, reg, val) writel((val), (chan)->regs + (reg))
  43. #else
  44. static inline void
  45. dma_wrreg(struct s3c2410_dma_chan *chan, int reg, unsigned long val)
  46. {
  47. pr_debug("writing %08x to register %08x\n",(unsigned int)val,reg);
  48. writel(val, dma_regaddr(chan, reg));
  49. }
  50. #endif
  51. #define dma_rdreg(chan, reg) readl((chan)->regs + (reg))
  52. /* captured register state for debug */
  53. struct s3c2410_dma_regstate {
  54. unsigned long dcsrc;
  55. unsigned long disrc;
  56. unsigned long dstat;
  57. unsigned long dcon;
  58. unsigned long dmsktrig;
  59. };
  60. #ifdef CONFIG_S3C2410_DMA_DEBUG
  61. /* dmadbg_showregs
  62. *
  63. * simple debug routine to print the current state of the dma registers
  64. */
  65. static void
  66. dmadbg_capture(struct s3c2410_dma_chan *chan, struct s3c2410_dma_regstate *regs)
  67. {
  68. regs->dcsrc = dma_rdreg(chan, S3C2410_DMA_DCSRC);
  69. regs->disrc = dma_rdreg(chan, S3C2410_DMA_DISRC);
  70. regs->dstat = dma_rdreg(chan, S3C2410_DMA_DSTAT);
  71. regs->dcon = dma_rdreg(chan, S3C2410_DMA_DCON);
  72. regs->dmsktrig = dma_rdreg(chan, S3C2410_DMA_DMASKTRIG);
  73. }
  74. static void
  75. dmadbg_dumpregs(const char *fname, int line, struct s3c2410_dma_chan *chan,
  76. struct s3c2410_dma_regstate *regs)
  77. {
  78. printk(KERN_DEBUG "dma%d: %s:%d: DCSRC=%08lx, DISRC=%08lx, DSTAT=%08lx DMT=%02lx, DCON=%08lx\n",
  79. chan->number, fname, line,
  80. regs->dcsrc, regs->disrc, regs->dstat, regs->dmsktrig,
  81. regs->dcon);
  82. }
  83. static void
  84. dmadbg_showchan(const char *fname, int line, struct s3c2410_dma_chan *chan)
  85. {
  86. struct s3c2410_dma_regstate state;
  87. dmadbg_capture(chan, &state);
  88. printk(KERN_DEBUG "dma%d: %s:%d: ls=%d, cur=%p, %p %p\n",
  89. chan->number, fname, line, chan->load_state,
  90. chan->curr, chan->next, chan->end);
  91. dmadbg_dumpregs(fname, line, chan, &state);
  92. }
  93. static void
  94. dmadbg_showregs(const char *fname, int line, struct s3c2410_dma_chan *chan)
  95. {
  96. struct s3c2410_dma_regstate state;
  97. dmadbg_capture(chan, &state);
  98. dmadbg_dumpregs(fname, line, chan, &state);
  99. }
  100. #define dbg_showregs(chan) dmadbg_showregs(__func__, __LINE__, (chan))
  101. #define dbg_showchan(chan) dmadbg_showchan(__func__, __LINE__, (chan))
  102. #else
  103. #define dbg_showregs(chan) do { } while(0)
  104. #define dbg_showchan(chan) do { } while(0)
  105. #endif /* CONFIG_S3C2410_DMA_DEBUG */
  106. /* s3c2410_dma_stats_timeout
  107. *
  108. * Update DMA stats from timeout info
  109. */
  110. static void
  111. s3c2410_dma_stats_timeout(struct s3c2410_dma_stats *stats, int val)
  112. {
  113. if (stats == NULL)
  114. return;
  115. if (val > stats->timeout_longest)
  116. stats->timeout_longest = val;
  117. if (val < stats->timeout_shortest)
  118. stats->timeout_shortest = val;
  119. stats->timeout_avg += val;
  120. }
  121. /* s3c2410_dma_waitforload
  122. *
  123. * wait for the DMA engine to load a buffer, and update the state accordingly
  124. */
  125. static int
  126. s3c2410_dma_waitforload(struct s3c2410_dma_chan *chan, int line)
  127. {
  128. int timeout = chan->load_timeout;
  129. int took;
  130. if (chan->load_state != S3C2410_DMALOAD_1LOADED) {
  131. printk(KERN_ERR "dma%d: s3c2410_dma_waitforload() called in loadstate %d from line %d\n", chan->number, chan->load_state, line);
  132. return 0;
  133. }
  134. if (chan->stats != NULL)
  135. chan->stats->loads++;
  136. while (--timeout > 0) {
  137. if ((dma_rdreg(chan, S3C2410_DMA_DSTAT) << (32-20)) != 0) {
  138. took = chan->load_timeout - timeout;
  139. s3c2410_dma_stats_timeout(chan->stats, took);
  140. switch (chan->load_state) {
  141. case S3C2410_DMALOAD_1LOADED:
  142. chan->load_state = S3C2410_DMALOAD_1RUNNING;
  143. break;
  144. default:
  145. printk(KERN_ERR "dma%d: unknown load_state in s3c2410_dma_waitforload() %d\n", chan->number, chan->load_state);
  146. }
  147. return 1;
  148. }
  149. }
  150. if (chan->stats != NULL) {
  151. chan->stats->timeout_failed++;
  152. }
  153. return 0;
  154. }