cache.S 2.7 KB

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