cache.S 2.7 KB

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