cache-inv-icache.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Invalidate icache when dcache doesn't need invalidation as it's in
  2. * write-through mode
  3. *
  4. * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public Licence
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the Licence, or (at your option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/mm.h>
  14. #include <asm/cacheflush.h>
  15. /**
  16. * flush_icache_page_range - Flush dcache and invalidate icache for part of a
  17. * single page
  18. * @start: The starting virtual address of the page part.
  19. * @end: The ending virtual address of the page part.
  20. *
  21. * Invalidate the icache for part of a single page, as determined by the
  22. * virtual addresses given. The page must be in the paged area. The dcache is
  23. * not flushed as the cache must be in write-through mode to get here.
  24. */
  25. static void flush_icache_page_range(unsigned long start, unsigned long end)
  26. {
  27. unsigned long addr, size, off;
  28. struct page *page;
  29. pgd_t *pgd;
  30. pud_t *pud;
  31. pmd_t *pmd;
  32. pte_t *ppte, pte;
  33. /* work out how much of the page to flush */
  34. off = start & ~PAGE_MASK;
  35. size = end - start;
  36. /* get the physical address the page is mapped to from the page
  37. * tables */
  38. pgd = pgd_offset(current->mm, start);
  39. if (!pgd || !pgd_val(*pgd))
  40. return;
  41. pud = pud_offset(pgd, start);
  42. if (!pud || !pud_val(*pud))
  43. return;
  44. pmd = pmd_offset(pud, start);
  45. if (!pmd || !pmd_val(*pmd))
  46. return;
  47. ppte = pte_offset_map(pmd, start);
  48. if (!ppte)
  49. return;
  50. pte = *ppte;
  51. pte_unmap(ppte);
  52. if (pte_none(pte))
  53. return;
  54. page = pte_page(pte);
  55. if (!page)
  56. return;
  57. addr = page_to_phys(page);
  58. /* invalidate the icache coverage on that region */
  59. mn10300_icache_inv_range2(addr + off, size);
  60. }
  61. /**
  62. * flush_icache_range - Globally flush dcache and invalidate icache for region
  63. * @start: The starting virtual address of the region.
  64. * @end: The ending virtual address of the region.
  65. *
  66. * This is used by the kernel to globally flush some code it has just written
  67. * from the dcache back to RAM and then to globally invalidate the icache over
  68. * that region so that that code can be run on all CPUs in the system.
  69. */
  70. void flush_icache_range(unsigned long start, unsigned long end)
  71. {
  72. unsigned long start_page, end_page;
  73. if (end > 0x80000000UL) {
  74. /* addresses above 0xa0000000 do not go through the cache */
  75. if (end > 0xa0000000UL) {
  76. end = 0xa0000000UL;
  77. if (start >= end)
  78. return;
  79. }
  80. /* kernel addresses between 0x80000000 and 0x9fffffff do not
  81. * require page tables, so we just map such addresses
  82. * directly */
  83. start_page = (start >= 0x80000000UL) ? start : 0x80000000UL;
  84. mn10300_dcache_flush_range(start_page, end);
  85. mn10300_icache_inv_range(start_page, end);
  86. if (start_page == start)
  87. return;
  88. end = start_page;
  89. }
  90. start_page = start & PAGE_MASK;
  91. end_page = end & PAGE_MASK;
  92. if (start_page == end_page) {
  93. /* the first and last bytes are on the same page */
  94. flush_icache_page_range(start, end);
  95. } else if (start_page + 1 == end_page) {
  96. /* split over two virtually contiguous pages */
  97. flush_icache_page_range(start, end_page);
  98. flush_icache_page_range(end_page, end);
  99. } else {
  100. /* more than 2 pages; just flush the entire cache */
  101. mn10300_icache_inv();
  102. }
  103. }
  104. EXPORT_SYMBOL(flush_icache_range);