pg-sh4.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <asm/mmu_context.h>
  13. #include <asm/cacheflush.h>
  14. #define CACHE_ALIAS (current_cpu_data.dcache.alias_mask)
  15. static inline void *kmap_coherent(struct page *page, unsigned long addr)
  16. {
  17. enum fixed_addresses idx;
  18. unsigned long vaddr, flags;
  19. pte_t pte;
  20. inc_preempt_count();
  21. idx = (addr & current_cpu_data.dcache.alias_mask) >> PAGE_SHIFT;
  22. vaddr = __fix_to_virt(FIX_CMAP_END - idx);
  23. pte = mk_pte(page, PAGE_KERNEL);
  24. local_irq_save(flags);
  25. flush_tlb_one(get_asid(), vaddr);
  26. local_irq_restore(flags);
  27. update_mmu_cache(NULL, vaddr, pte);
  28. return (void *)vaddr;
  29. }
  30. static inline void kunmap_coherent(struct page *page)
  31. {
  32. dec_preempt_count();
  33. preempt_check_resched();
  34. }
  35. /*
  36. * clear_user_page
  37. * @to: P1 address
  38. * @address: U0 address to be mapped
  39. * @page: page (virt_to_page(to))
  40. */
  41. void clear_user_page(void *to, unsigned long address, struct page *page)
  42. {
  43. __set_bit(PG_mapped, &page->flags);
  44. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
  45. clear_page(to);
  46. else {
  47. void *vto = kmap_coherent(page, address);
  48. __clear_user_page(vto, to);
  49. kunmap_coherent(vto);
  50. }
  51. }
  52. /*
  53. * copy_user_page
  54. * @to: P1 address
  55. * @from: P1 address
  56. * @address: U0 address to be mapped
  57. * @page: page (virt_to_page(to))
  58. */
  59. void copy_user_page(void *to, void *from, unsigned long address,
  60. struct page *page)
  61. {
  62. __set_bit(PG_mapped, &page->flags);
  63. if (((address ^ (unsigned long)to) & CACHE_ALIAS) == 0)
  64. copy_page(to, from);
  65. else {
  66. void *vfrom = kmap_coherent(page, address);
  67. __copy_user_page(vfrom, from, to);
  68. kunmap_coherent(vfrom);
  69. }
  70. }
  71. /*
  72. * For SH-4, we have our own implementation for ptep_get_and_clear
  73. */
  74. inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  75. {
  76. pte_t pte = *ptep;
  77. pte_clear(mm, addr, ptep);
  78. if (!pte_not_present(pte)) {
  79. unsigned long pfn = pte_pfn(pte);
  80. if (pfn_valid(pfn)) {
  81. struct page *page = pfn_to_page(pfn);
  82. struct address_space *mapping = page_mapping(page);
  83. if (!mapping || !mapping_writably_mapped(mapping))
  84. __clear_bit(PG_mapped, &page->flags);
  85. }
  86. }
  87. return pte;
  88. }