blackfin_local.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. #include <asm/mem_map.h>
  27. #define LO(con32) ((con32) & 0xFFFF)
  28. #define lo(con32) ((con32) & 0xFFFF)
  29. #define HI(con32) (((con32) >> 16) & 0xFFFF)
  30. #define hi(con32) (((con32) >> 16) & 0xFFFF)
  31. #define OFFSET_(x) (x & 0x0000FFFF)
  32. #define MK_BMSK_(x) (1 << x)
  33. /* Ideally this should be USEC not MSEC, but the USEC multiplication
  34. * likes to overflow 32bit quantities which is all our assembler
  35. * currently supports ;(
  36. */
  37. #define USEC_PER_MSEC 1000
  38. #define MSEC_PER_SEC 1000
  39. #define BFIN_SCLK (100000000)
  40. #define SCLK_TO_MSEC(sclk) ((MSEC_PER_SEC * ((sclk) / USEC_PER_MSEC)) / (BFIN_SCLK / USEC_PER_MSEC))
  41. #define MSEC_TO_SCLK(msec) ((((BFIN_SCLK / USEC_PER_MSEC) * (msec)) / MSEC_PER_SEC) * USEC_PER_MSEC)
  42. #define L1_CACHE_SHIFT 5
  43. #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  44. #include <asm/linkage.h>
  45. #include <asm/cache.h>
  46. #ifndef __ASSEMBLY__
  47. # ifdef SHARED_RESOURCES
  48. # include <asm/shared_resources.h>
  49. # endif
  50. # include <linux/types.h>
  51. extern u_long get_vco(void);
  52. extern u_long get_cclk(void);
  53. extern u_long get_sclk(void);
  54. # define bfin_revid() (bfin_read_CHIPID() >> 28)
  55. extern bool bfin_os_log_check(void);
  56. extern void bfin_os_log_dump(void);
  57. extern void blackfin_icache_flush_range(const void *, const void *);
  58. extern void blackfin_dcache_flush_range(const void *, const void *);
  59. extern void blackfin_icache_dcache_flush_range(const void *, const void *);
  60. extern void blackfin_dcache_flush_invalidate_range(const void *, const void *);
  61. /* Use DMA to move data from on chip to external memory. The L1 instruction
  62. * regions can only be accessed via DMA, so if the address in question is in
  63. * that region, make sure we attempt to DMA indirectly.
  64. */
  65. # ifdef __ADSPBF561__
  66. /* Core B regions all need dma from Core A */
  67. # define addr_bfin_on_chip_mem(addr) \
  68. ((((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000) || \
  69. (((unsigned long)(addr) & 0xFFC00000) == 0xFF400000))
  70. # else
  71. # define addr_bfin_on_chip_mem(addr) \
  72. (((unsigned long)(addr) & 0xFFF00000) == 0xFFA00000)
  73. # endif
  74. # include <asm/system.h>
  75. #if ANOMALY_05000198
  76. # define NOP_PAD_ANOMALY_05000198 "nop;"
  77. #else
  78. # define NOP_PAD_ANOMALY_05000198
  79. #endif
  80. #define _bfin_readX(addr, size, asm_size, asm_ext) ({ \
  81. u32 __v; \
  82. __asm__ __volatile__( \
  83. NOP_PAD_ANOMALY_05000198 \
  84. "%0 = " #asm_size "[%1]" #asm_ext ";" \
  85. : "=d" (__v) \
  86. : "a" (addr) \
  87. ); \
  88. __v; })
  89. #define _bfin_writeX(addr, val, size, asm_size) \
  90. __asm__ __volatile__( \
  91. NOP_PAD_ANOMALY_05000198 \
  92. #asm_size "[%0] = %1;" \
  93. : \
  94. : "a" (addr), "d" ((u##size)(val)) \
  95. : "memory" \
  96. )
  97. #define bfin_read8(addr) _bfin_readX(addr, 8, b, (z))
  98. #define bfin_read16(addr) _bfin_readX(addr, 16, w, (z))
  99. #define bfin_read32(addr) _bfin_readX(addr, 32, , )
  100. #define bfin_write8(addr, val) _bfin_writeX(addr, val, 8, b)
  101. #define bfin_write16(addr, val) _bfin_writeX(addr, val, 16, w)
  102. #define bfin_write32(addr, val) _bfin_writeX(addr, val, 32, )
  103. #define bfin_read(addr) \
  104. ({ \
  105. sizeof(*(addr)) == 1 ? bfin_read8(addr) : \
  106. sizeof(*(addr)) == 2 ? bfin_read16(addr) : \
  107. sizeof(*(addr)) == 4 ? bfin_read32(addr) : \
  108. ({ BUG(); 0; }); \
  109. })
  110. #define bfin_write(addr, val) \
  111. do { \
  112. switch (sizeof(*(addr))) { \
  113. case 1: bfin_write8(addr, val); break; \
  114. case 2: bfin_write16(addr, val); break; \
  115. case 4: bfin_write32(addr, val); break; \
  116. default: BUG(); \
  117. } \
  118. } while (0)
  119. #define bfin_write_or(addr, bits) \
  120. do { \
  121. typeof(addr) __addr = (addr); \
  122. bfin_write(__addr, bfin_read(__addr) | (bits)); \
  123. } while (0)
  124. #define bfin_write_and(addr, bits) \
  125. do { \
  126. typeof(addr) __addr = (addr); \
  127. bfin_write(__addr, bfin_read(__addr) & (bits)); \
  128. } while (0)
  129. #define bfin_readPTR(addr) bfin_read32(addr)
  130. #define bfin_writePTR(addr, val) bfin_write32(addr, val)
  131. /* SSYNC implementation for C file */
  132. static inline void SSYNC(void)
  133. {
  134. int _tmp;
  135. if (ANOMALY_05000312)
  136. __asm__ __volatile__(
  137. "cli %0;"
  138. "nop;"
  139. "nop;"
  140. "ssync;"
  141. "sti %0;"
  142. : "=d" (_tmp)
  143. );
  144. else if (ANOMALY_05000244)
  145. __asm__ __volatile__(
  146. "nop;"
  147. "nop;"
  148. "nop;"
  149. "ssync;"
  150. );
  151. else
  152. __asm__ __volatile__("ssync;");
  153. }
  154. /* CSYNC implementation for C file */
  155. static inline void CSYNC(void)
  156. {
  157. int _tmp;
  158. if (ANOMALY_05000312)
  159. __asm__ __volatile__(
  160. "cli %0;"
  161. "nop;"
  162. "nop;"
  163. "csync;"
  164. "sti %0;"
  165. : "=d" (_tmp)
  166. );
  167. else if (ANOMALY_05000244)
  168. __asm__ __volatile__(
  169. "nop;"
  170. "nop;"
  171. "nop;"
  172. "csync;"
  173. );
  174. else
  175. __asm__ __volatile__("csync;");
  176. }
  177. #else /* __ASSEMBLY__ */
  178. /* SSYNC & CSYNC implementations for assembly files */
  179. #define ssync(x) SSYNC(x)
  180. #define csync(x) CSYNC(x)
  181. #if ANOMALY_05000312
  182. #define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
  183. #define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
  184. #elif ANOMALY_05000244
  185. #define SSYNC(scratch) nop; nop; nop; SSYNC;
  186. #define CSYNC(scratch) nop; nop; nop; CSYNC;
  187. #else
  188. #define SSYNC(scratch) SSYNC;
  189. #define CSYNC(scratch) CSYNC;
  190. #endif /* ANOMALY_05000312 & ANOMALY_05000244 handling */
  191. #endif /* __ASSEMBLY__ */
  192. #endif