cache.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* MN10300 Cache flushing routines
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/mm.h>
  13. #include <linux/mman.h>
  14. #include <linux/threads.h>
  15. #include <asm/page.h>
  16. #include <asm/pgtable.h>
  17. #include <asm/processor.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/io.h>
  20. #include <asm/uaccess.h>
  21. EXPORT_SYMBOL(mn10300_icache_inv);
  22. EXPORT_SYMBOL(mn10300_dcache_inv);
  23. EXPORT_SYMBOL(mn10300_dcache_inv_range);
  24. EXPORT_SYMBOL(mn10300_dcache_inv_range2);
  25. EXPORT_SYMBOL(mn10300_dcache_inv_page);
  26. #ifdef CONFIG_MN10300_CACHE_WBACK
  27. EXPORT_SYMBOL(mn10300_dcache_flush);
  28. EXPORT_SYMBOL(mn10300_dcache_flush_inv);
  29. EXPORT_SYMBOL(mn10300_dcache_flush_inv_range);
  30. EXPORT_SYMBOL(mn10300_dcache_flush_inv_range2);
  31. EXPORT_SYMBOL(mn10300_dcache_flush_inv_page);
  32. EXPORT_SYMBOL(mn10300_dcache_flush_range);
  33. EXPORT_SYMBOL(mn10300_dcache_flush_range2);
  34. EXPORT_SYMBOL(mn10300_dcache_flush_page);
  35. #endif
  36. /*
  37. * write a page back from the dcache and invalidate the icache so that we can
  38. * run code from it that we've just written into it
  39. */
  40. void flush_icache_page(struct vm_area_struct *vma, struct page *page)
  41. {
  42. mn10300_dcache_flush_page(page_to_phys(page));
  43. mn10300_icache_inv();
  44. }
  45. EXPORT_SYMBOL(flush_icache_page);
  46. /*
  47. * write some code we've just written back from the dcache and invalidate the
  48. * icache so that we can run that code
  49. */
  50. void flush_icache_range(unsigned long start, unsigned long end)
  51. {
  52. #ifdef CONFIG_MN10300_CACHE_WBACK
  53. unsigned long addr, size, off;
  54. struct page *page;
  55. pgd_t *pgd;
  56. pud_t *pud;
  57. pmd_t *pmd;
  58. pte_t *ppte, pte;
  59. for (; start < end; start += size) {
  60. /* work out how much of the page to flush */
  61. off = start & (PAGE_SIZE - 1);
  62. size = end - start;
  63. if (size > PAGE_SIZE - off)
  64. size = PAGE_SIZE - off;
  65. /* get the physical address the page is mapped to from the page
  66. * tables */
  67. pgd = pgd_offset(current->mm, start);
  68. if (!pgd || !pgd_val(*pgd))
  69. continue;
  70. pud = pud_offset(pgd, start);
  71. if (!pud || !pud_val(*pud))
  72. continue;
  73. pmd = pmd_offset(pud, start);
  74. if (!pmd || !pmd_val(*pmd))
  75. continue;
  76. ppte = pte_offset_map(pmd, start);
  77. if (!ppte)
  78. continue;
  79. pte = *ppte;
  80. pte_unmap(ppte);
  81. if (pte_none(pte))
  82. continue;
  83. page = pte_page(pte);
  84. if (!page)
  85. continue;
  86. addr = page_to_phys(page);
  87. /* flush the dcache and invalidate the icache coverage on that
  88. * region */
  89. mn10300_dcache_flush_range2(addr + off, size);
  90. }
  91. #endif
  92. mn10300_icache_inv();
  93. }
  94. EXPORT_SYMBOL(flush_icache_range);
  95. /*
  96. * allow userspace to flush the instruction cache
  97. */
  98. asmlinkage long sys_cacheflush(unsigned long start, unsigned long end)
  99. {
  100. if (end < start)
  101. return -EINVAL;
  102. flush_icache_range(start, end);
  103. return 0;
  104. }