blackfin_local.h 5.0 KB

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