pg-sh4.c 2.3 KB

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