cache.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Cache management functions for Hexagon
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <linux/mm.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/hexagon_vm.h>
  23. #define spanlines(start, end) \
  24. (((end - (start & ~(LINESIZE - 1))) >> LINEBITS) + 1)
  25. void flush_dcache_range(unsigned long start, unsigned long end)
  26. {
  27. unsigned long lines = spanlines(start, end-1);
  28. unsigned long i, flags;
  29. start &= ~(LINESIZE - 1);
  30. local_irq_save(flags);
  31. for (i = 0; i < lines; i++) {
  32. __asm__ __volatile__ (
  33. " dccleaninva(%0); "
  34. :
  35. : "r" (start)
  36. );
  37. start += LINESIZE;
  38. }
  39. local_irq_restore(flags);
  40. }
  41. void flush_icache_range(unsigned long start, unsigned long end)
  42. {
  43. unsigned long lines = spanlines(start, end-1);
  44. unsigned long i, flags;
  45. start &= ~(LINESIZE - 1);
  46. local_irq_save(flags);
  47. for (i = 0; i < lines; i++) {
  48. __asm__ __volatile__ (
  49. " dccleana(%0); "
  50. " icinva(%0); "
  51. :
  52. : "r" (start)
  53. );
  54. start += LINESIZE;
  55. }
  56. __asm__ __volatile__ (
  57. "isync"
  58. );
  59. local_irq_restore(flags);
  60. }
  61. void hexagon_clean_dcache_range(unsigned long start, unsigned long end)
  62. {
  63. unsigned long lines = spanlines(start, end-1);
  64. unsigned long i, flags;
  65. start &= ~(LINESIZE - 1);
  66. local_irq_save(flags);
  67. for (i = 0; i < lines; i++) {
  68. __asm__ __volatile__ (
  69. " dccleana(%0); "
  70. :
  71. : "r" (start)
  72. );
  73. start += LINESIZE;
  74. }
  75. local_irq_restore(flags);
  76. }
  77. void hexagon_inv_dcache_range(unsigned long start, unsigned long end)
  78. {
  79. unsigned long lines = spanlines(start, end-1);
  80. unsigned long i, flags;
  81. start &= ~(LINESIZE - 1);
  82. local_irq_save(flags);
  83. for (i = 0; i < lines; i++) {
  84. __asm__ __volatile__ (
  85. " dcinva(%0); "
  86. :
  87. : "r" (start)
  88. );
  89. start += LINESIZE;
  90. }
  91. local_irq_restore(flags);
  92. }
  93. /*
  94. * This is just really brutal and shouldn't be used anyways,
  95. * especially on V2. Left here just in case.
  96. */
  97. void flush_cache_all_hexagon(void)
  98. {
  99. unsigned long flags;
  100. local_irq_save(flags);
  101. __vmcache_ickill();
  102. __vmcache_dckill();
  103. __vmcache_l2kill();
  104. local_irq_restore(flags);
  105. mb();
  106. }