pg-sh4.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * arch/sh/mm/pg-sh4.c
  3. *
  4. * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
  5. * Copyright (C) 2002 - 2007 Paul Mundt
  6. *
  7. * Released under the terms of the GNU GPL v2.0.
  8. */
  9. #include <linux/mm.h>
  10. #include <linux/mutex.h>
  11. #include <linux/fs.h>
  12. #include <linux/highmem.h>
  13. #include <linux/module.h>
  14. #include <asm/mmu_context.h>
  15. #include <asm/cacheflush.h>
  16. #define CACHE_ALIAS (current_cpu_data.dcache.alias_mask)
  17. static inline void *kmap_coherent(struct page *page, unsigned long addr)
  18. {
  19. enum fixed_addresses idx;
  20. unsigned long vaddr, flags;
  21. pte_t pte;
  22. inc_preempt_count();
  23. idx = (addr & current_cpu_data.dcache.alias_mask) >> PAGE_SHIFT;
  24. vaddr = __fix_to_virt(FIX_CMAP_END - idx);
  25. pte = mk_pte(page, PAGE_KERNEL);
  26. local_irq_save(flags);
  27. flush_tlb_one(get_asid(), vaddr);
  28. local_irq_restore(flags);
  29. update_mmu_cache(NULL, vaddr, pte);
  30. return (void *)vaddr;
  31. }
  32. static inline void kunmap_coherent(struct page *page)
  33. {
  34. dec_preempt_count();
  35. preempt_check_resched();
  36. }
  37. /*
  38. * clear_user_page
  39. * @to: P1 address
  40. * @address: U0 address to be mapped
  41. * @page: page (virt_to_page(to))
  42. */
  43. void clear_user_page(void *to, unsigned long address, struct page *page)
  44. {
  45. __set_bit(PG_mapped, &page->flags);
  46. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
  47. clear_page(to);
  48. else {
  49. void *vto = kmap_coherent(page, address);
  50. __clear_user_page(vto, to);
  51. kunmap_coherent(vto);
  52. }
  53. }
  54. /*
  55. * copy_user_page
  56. * @to: P1 address
  57. * @from: P1 address
  58. * @address: U0 address to be mapped
  59. * @page: page (virt_to_page(to))
  60. */
  61. void copy_user_page(void *to, void *from, unsigned long address,
  62. struct page *page)
  63. {
  64. __set_bit(PG_mapped, &page->flags);
  65. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
  66. copy_page(to, from);
  67. else {
  68. void *vfrom = kmap_coherent(page, address);
  69. __copy_user_page(vfrom, from, to);
  70. kunmap_coherent(vfrom);
  71. }
  72. }
  73. void copy_user_highpage(struct page *to, struct page *from,
  74. unsigned long vaddr, struct vm_area_struct *vma)
  75. {
  76. void *vfrom, *vto;
  77. __set_bit(PG_mapped, &to->flags);
  78. vto = kmap_atomic(to, KM_USER1);
  79. vfrom = kmap_coherent(from, vaddr);
  80. copy_page(vto, vfrom);
  81. kunmap_coherent(vfrom);
  82. if (((vaddr ^ (unsigned long)vto) & CACHE_ALIAS))
  83. __flush_wback_region(vto, PAGE_SIZE);
  84. kunmap_atomic(vto, KM_USER1);
  85. /* Make sure this page is cleared on other CPU's too before using it */
  86. smp_wmb();
  87. }
  88. EXPORT_SYMBOL(copy_user_highpage);
  89. /*
  90. * For SH-4, we have our own implementation for ptep_get_and_clear
  91. */
  92. inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  93. {
  94. pte_t pte = *ptep;
  95. pte_clear(mm, addr, ptep);
  96. if (!pte_not_present(pte)) {
  97. unsigned long pfn = pte_pfn(pte);
  98. if (pfn_valid(pfn)) {
  99. struct page *page = pfn_to_page(pfn);
  100. struct address_space *mapping = page_mapping(page);
  101. if (!mapping || !mapping_writably_mapped(mapping))
  102. __clear_bit(PG_mapped, &page->flags);
  103. }
  104. }
  105. return pte;
  106. }