pg-sh7705.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * arch/sh/mm/pg-sh7705.c
  3. *
  4. * Copyright (C) 1999, 2000 Niibe Yutaka
  5. * Copyright (C) 2004 Alex Song
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. *
  11. */
  12. #include <linux/init.h>
  13. #include <linux/mman.h>
  14. #include <linux/mm.h>
  15. #include <linux/threads.h>
  16. #include <asm/addrspace.h>
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/processor.h>
  20. #include <asm/cache.h>
  21. #include <asm/io.h>
  22. #include <asm/uaccess.h>
  23. #include <asm/pgalloc.h>
  24. #include <asm/mmu_context.h>
  25. #include <asm/cacheflush.h>
  26. static inline void __flush_purge_virtual_region(void *p1, void *virt, int size)
  27. {
  28. unsigned long v;
  29. unsigned long begin, end;
  30. unsigned long p1_begin;
  31. begin = L1_CACHE_ALIGN((unsigned long)virt);
  32. end = L1_CACHE_ALIGN((unsigned long)virt + size);
  33. p1_begin = (unsigned long)p1 & ~(L1_CACHE_BYTES - 1);
  34. /* do this the slow way as we may not have TLB entries
  35. * for virt yet. */
  36. for (v = begin; v < end; v += L1_CACHE_BYTES) {
  37. unsigned long p;
  38. unsigned long ways, addr;
  39. p = __pa(p1_begin);
  40. ways = cpu_data->dcache.ways;
  41. addr = CACHE_OC_ADDRESS_ARRAY;
  42. do {
  43. unsigned long data;
  44. addr |= (v & cpu_data->dcache.entry_mask);
  45. data = ctrl_inl(addr);
  46. if ((data & CACHE_PHYSADDR_MASK) ==
  47. (p & CACHE_PHYSADDR_MASK)) {
  48. data &= ~(SH_CACHE_UPDATED|SH_CACHE_VALID);
  49. ctrl_outl(data, addr);
  50. }
  51. addr += cpu_data->dcache.way_incr;
  52. } while (--ways);
  53. p1_begin += L1_CACHE_BYTES;
  54. }
  55. }
  56. /*
  57. * clear_user_page
  58. * @to: P1 address
  59. * @address: U0 address to be mapped
  60. */
  61. void clear_user_page(void *to, unsigned long address, struct page *pg)
  62. {
  63. struct page *page = virt_to_page(to);
  64. __set_bit(PG_mapped, &page->flags);
  65. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0) {
  66. clear_page(to);
  67. __flush_wback_region(to, PAGE_SIZE);
  68. } else {
  69. __flush_purge_virtual_region(to,
  70. (void *)(address & 0xfffff000),
  71. PAGE_SIZE);
  72. clear_page(to);
  73. __flush_wback_region(to, PAGE_SIZE);
  74. }
  75. }
  76. /*
  77. * copy_user_page
  78. * @to: P1 address
  79. * @from: P1 address
  80. * @address: U0 address to be mapped
  81. */
  82. void copy_user_page(void *to, void *from, unsigned long address, struct page *pg)
  83. {
  84. struct page *page = virt_to_page(to);
  85. __set_bit(PG_mapped, &page->flags);
  86. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0) {
  87. copy_page(to, from);
  88. __flush_wback_region(to, PAGE_SIZE);
  89. } else {
  90. __flush_purge_virtual_region(to,
  91. (void *)(address & 0xfffff000),
  92. PAGE_SIZE);
  93. copy_page(to, from);
  94. __flush_wback_region(to, PAGE_SIZE);
  95. }
  96. }
  97. /*
  98. * For SH7705, we have our own implementation for ptep_get_and_clear
  99. * Copied from pg-sh4.c
  100. */
  101. inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  102. {
  103. pte_t pte = *ptep;
  104. pte_clear(mm, addr, ptep);
  105. if (!pte_not_present(pte)) {
  106. unsigned long pfn = pte_pfn(pte);
  107. if (pfn_valid(pfn)) {
  108. struct page *page = pfn_to_page(pfn);
  109. struct address_space *mapping = page_mapping(page);
  110. if (!mapping || !mapping_writably_mapped(mapping))
  111. __clear_bit(PG_mapped, &page->flags);
  112. }
  113. }
  114. return pte;
  115. }