cache.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Blackfin cache control code
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/linkage.h>
  9. #include <asm/blackfin.h>
  10. #include <asm/cache.h>
  11. #include <asm/page.h>
  12. /* 05000443 - IFLUSH cannot be last instruction in hardware loop */
  13. #if ANOMALY_05000443
  14. # define BROK_FLUSH_INST "IFLUSH"
  15. #else
  16. # define BROK_FLUSH_INST "no anomaly! yeah!"
  17. #endif
  18. /* Since all L1 caches work the same way, we use the same method for flushing
  19. * them. Only the actual flush instruction differs. We write this in asm as
  20. * GCC can be hard to coax into writing nice hardware loops.
  21. *
  22. * Also, we assume the following register setup:
  23. * R0 = start address
  24. * R1 = end address
  25. */
  26. .macro do_flush flushins:req label
  27. R2 = -L1_CACHE_BYTES;
  28. /* start = (start & -L1_CACHE_BYTES) */
  29. R0 = R0 & R2;
  30. /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
  31. R1 += -1;
  32. R1 = R1 & R2;
  33. R1 += L1_CACHE_BYTES;
  34. /* count = (end - start) >> L1_CACHE_SHIFT */
  35. R2 = R1 - R0;
  36. R2 >>= L1_CACHE_SHIFT;
  37. P1 = R2;
  38. .ifnb \label
  39. \label :
  40. .endif
  41. P0 = R0;
  42. LSETUP (1f, 2f) LC1 = P1;
  43. 1:
  44. .ifeqs "\flushins", BROK_FLUSH_INST
  45. \flushins [P0++];
  46. nop;
  47. nop;
  48. 2: nop;
  49. .else
  50. 2: \flushins [P0++];
  51. .endif
  52. RTS;
  53. .endm
  54. #ifdef CONFIG_ICACHE_FLUSH_L1
  55. .section .l1.text
  56. #else
  57. .text
  58. #endif
  59. /* Invalidate all instruction cache lines assocoiated with this memory area */
  60. #ifdef CONFIG_SMP
  61. # define _blackfin_icache_flush_range _blackfin_icache_flush_range_l1
  62. #endif
  63. ENTRY(_blackfin_icache_flush_range)
  64. do_flush IFLUSH
  65. ENDPROC(_blackfin_icache_flush_range)
  66. #ifdef CONFIG_SMP
  67. .text
  68. # undef _blackfin_icache_flush_range
  69. ENTRY(_blackfin_icache_flush_range)
  70. p0.L = LO(DSPID);
  71. p0.H = HI(DSPID);
  72. r3 = [p0];
  73. r3 = r3.b (z);
  74. p2 = r3;
  75. p0.L = _blackfin_iflush_l1_entry;
  76. p0.H = _blackfin_iflush_l1_entry;
  77. p0 = p0 + (p2 << 2);
  78. p1 = [p0];
  79. jump (p1);
  80. ENDPROC(_blackfin_icache_flush_range)
  81. #endif
  82. #ifdef CONFIG_DCACHE_FLUSH_L1
  83. .section .l1.text
  84. #else
  85. .text
  86. #endif
  87. /* Throw away all D-cached data in specified region without any obligation to
  88. * write them back. Since the Blackfin ISA does not have an "invalidate"
  89. * instruction, we use flush/invalidate. Perhaps as a speed optimization we
  90. * could bang on the DTEST MMRs ...
  91. */
  92. ENTRY(_blackfin_dcache_invalidate_range)
  93. do_flush FLUSHINV
  94. ENDPROC(_blackfin_dcache_invalidate_range)
  95. /* Flush all data cache lines assocoiated with this memory area */
  96. ENTRY(_blackfin_dcache_flush_range)
  97. do_flush FLUSH, .Ldfr
  98. ENDPROC(_blackfin_dcache_flush_range)
  99. /* Our headers convert the page structure to an address, so just need to flush
  100. * its contents like normal. We know the start address is page aligned (which
  101. * greater than our cache alignment), as is the end address. So just jump into
  102. * the middle of the dcache flush function.
  103. */
  104. ENTRY(_blackfin_dflush_page)
  105. P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
  106. jump .Ldfr;
  107. ENDPROC(_blackfin_dflush_page)