cache.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. ENTRY(_blackfin_icache_flush_range)
  61. do_flush IFLUSH
  62. ENDPROC(_blackfin_icache_flush_range)
  63. #ifdef CONFIG_DCACHE_FLUSH_L1
  64. .section .l1.text
  65. #else
  66. .text
  67. #endif
  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)