blackfin_local.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * U-boot - blackfin_local.h
  3. *
  4. * Copyright (c) 2005-2007 Analog Devices Inc.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #ifndef __BLACKFIN_LOCAL_H__
  25. #define __BLACKFIN_LOCAL_H__
  26. #define LO(con32) ((con32) & 0xFFFF)
  27. #define lo(con32) ((con32) & 0xFFFF)
  28. #define HI(con32) (((con32) >> 16) & 0xFFFF)
  29. #define hi(con32) (((con32) >> 16) & 0xFFFF)
  30. #define OFFSET_(x) (x & 0x0000FFFF)
  31. #define MK_BMSK_(x) (1 << x)
  32. /* Ideally this should be USEC not MSEC, but the USEC multiplication
  33. * likes to overflow 32bit quantities which is all our assembler
  34. * currently supports ;(
  35. */
  36. #define USEC_PER_MSEC 1000
  37. #define MSEC_PER_SEC 1000
  38. #define BFIN_SCLK (100000000)
  39. #define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC))
  40. #define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC)
  41. #define L1_CACHE_SHIFT 5
  42. #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  43. #include <asm/linkage.h>
  44. #ifndef __ASSEMBLY__
  45. # ifdef SHARED_RESOURCES
  46. # include <asm/shared_resources.h>
  47. # endif
  48. # include <linux/types.h>
  49. extern u_long get_vco(void);
  50. extern u_long get_cclk(void);
  51. extern u_long get_sclk(void);
  52. # define bfin_revid() (*pCHIPID >> 28)
  53. extern void blackfin_icache_flush_range(const void *, const void *);
  54. extern void blackfin_dcache_flush_range(const void *, const void *);
  55. extern void blackfin_icache_dcache_flush_range(const void *, const void *);
  56. extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
  57. /* Use DMA to move data from on chip to external memory. While this is
  58. * required for only L1 instruction (it is not directly readable by the
  59. * core via data loads), it isn't a huge performance issue for other
  60. * regions (it's probably even faster than core load/stores). However,
  61. * the DMA engine does not have access to the L1 scratchpad, and we
  62. * cannot use DMA inside of the MMR space.
  63. */
  64. # define addr_bfin_on_chip_mem(addr) \
  65. (((unsigned long)(addr) >= 0xef000000 && (unsigned long)addr < SYSMMR_BASE) && \
  66. !((unsigned long)(addr) >= L1_SRAM_SCRATCH && \
  67. (unsigned long)(addr) < L1_SRAM_SCRATCH_END))
  68. # include <asm/system.h>
  69. #if ANOMALY_05000198
  70. # define NOP_PAD_ANOMALY_05000198 "nop;"
  71. #else
  72. # define NOP_PAD_ANOMALY_05000198
  73. #endif
  74. #define bfin_read8(addr) ({ \
  75. uint8_t __v; \
  76. __asm__ __volatile__( \
  77. NOP_PAD_ANOMALY_05000198 \
  78. "%0 = b[%1] (z);" \
  79. : "=d" (__v) \
  80. : "a" (addr) \
  81. ); \
  82. __v; })
  83. #define bfin_read16(addr) ({ \
  84. uint16_t __v; \
  85. __asm__ __volatile__( \
  86. NOP_PAD_ANOMALY_05000198 \
  87. "%0 = w[%1] (z);" \
  88. : "=d" (__v) \
  89. : "a" (addr) \
  90. ); \
  91. __v; })
  92. #define bfin_read32(addr) ({ \
  93. uint32_t __v; \
  94. __asm__ __volatile__( \
  95. NOP_PAD_ANOMALY_05000198 \
  96. "%0 = [%1];" \
  97. : "=d" (__v) \
  98. : "a" (addr) \
  99. ); \
  100. __v; })
  101. #define bfin_readPTR(addr) bfin_read32(addr)
  102. #define bfin_write8(addr, val) \
  103. __asm__ __volatile__( \
  104. NOP_PAD_ANOMALY_05000198 \
  105. "b[%0] = %1;" \
  106. : \
  107. : "a" (addr), "d" (val) \
  108. : "memory" \
  109. )
  110. #define bfin_write16(addr, val) \
  111. __asm__ __volatile__( \
  112. NOP_PAD_ANOMALY_05000198 \
  113. "w[%0] = %1;" \
  114. : \
  115. : "a" (addr), "d" (val) \
  116. : "memory" \
  117. )
  118. #define bfin_write32(addr, val) \
  119. __asm__ __volatile__( \
  120. NOP_PAD_ANOMALY_05000198 \
  121. "[%0] = %1;" \
  122. : \
  123. : "a" (addr), "d" (val) \
  124. : "memory" \
  125. )
  126. #define bfin_writePTR(addr, val) bfin_write32(addr, val)
  127. /* SSYNC implementation for C file */
  128. static inline void SSYNC(void)
  129. {
  130. int _tmp;
  131. if (ANOMALY_05000312)
  132. __asm__ __volatile__(
  133. "cli %0;"
  134. "nop;"
  135. "nop;"
  136. "ssync;"
  137. "sti %0;"
  138. : "=d" (_tmp)
  139. );
  140. else if (ANOMALY_05000244)
  141. __asm__ __volatile__(
  142. "nop;"
  143. "nop;"
  144. "nop;"
  145. "ssync;"
  146. );
  147. else
  148. __asm__ __volatile__("ssync;");
  149. }
  150. /* CSYNC implementation for C file */
  151. static inline void CSYNC(void)
  152. {
  153. int _tmp;
  154. if (ANOMALY_05000312)
  155. __asm__ __volatile__(
  156. "cli %0;"
  157. "nop;"
  158. "nop;"
  159. "csync;"
  160. "sti %0;"
  161. : "=d" (_tmp)
  162. );
  163. else if (ANOMALY_05000244)
  164. __asm__ __volatile__(
  165. "nop;"
  166. "nop;"
  167. "nop;"
  168. "csync;"
  169. );
  170. else
  171. __asm__ __volatile__("csync;");
  172. }
  173. #else /* __ASSEMBLY__ */
  174. /* SSYNC & CSYNC implementations for assembly files */
  175. #define ssync(x) SSYNC(x)
  176. #define csync(x) CSYNC(x)
  177. #if ANOMALY_05000312
  178. #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
  179. #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
  180. #elif ANOMALY_05000244
  181. #define SSYNC(scratch) nop; nop; nop; SSYNC;
  182. #define CSYNC(scratch) nop; nop; nop; CSYNC;
  183. #else
  184. #define SSYNC(scratch) SSYNC;
  185. #define CSYNC(scratch) CSYNC;
  186. #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
  187. #endif /* __ASSEMBLY__ */
  188. #endif