cache.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. EXPORT_SYMBOL(flush_icache_range);
  62. void hexagon_clean_dcache_range(unsigned long start, unsigned long end)
  63. {
  64. unsigned long lines = spanlines(start, end-1);
  65. unsigned long i, flags;
  66. start &= ~(LINESIZE - 1);
  67. local_irq_save(flags);
  68. for (i = 0; i < lines; i++) {
  69. __asm__ __volatile__ (
  70. " dccleana(%0); "
  71. :
  72. : "r" (start)
  73. );
  74. start += LINESIZE;
  75. }
  76. local_irq_restore(flags);
  77. }
  78. void hexagon_inv_dcache_range(unsigned long start, unsigned long end)
  79. {
  80. unsigned long lines = spanlines(start, end-1);
  81. unsigned long i, flags;
  82. start &= ~(LINESIZE - 1);
  83. local_irq_save(flags);
  84. for (i = 0; i < lines; i++) {
  85. __asm__ __volatile__ (
  86. " dcinva(%0); "
  87. :
  88. : "r" (start)
  89. );
  90. start += LINESIZE;
  91. }
  92. local_irq_restore(flags);
  93. }
  94. /*
  95. * This is just really brutal and shouldn't be used anyways,
  96. * especially on V2. Left here just in case.
  97. */
  98. void flush_cache_all_hexagon(void)
  99. {
  100. unsigned long flags;
  101. local_irq_save(flags);
  102. __vmcache_ickill();
  103. __vmcache_dckill();
  104. __vmcache_l2kill();
  105. local_irq_restore(flags);
  106. mb();
  107. }
  108. void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
  109. unsigned long vaddr, void *dst, void *src, int len)
  110. {
  111. memcpy(dst, src, len);
  112. if (vma->vm_flags & VM_EXEC) {
  113. flush_icache_range((unsigned long) dst,
  114. (unsigned long) dst + len);
  115. }
  116. }