highmem.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * arch/arm/mm/highmem.c -- ARM highmem support
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: september 8, 2008
  6. * Copyright: Marvell Semiconductors Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/highmem.h>
  14. #include <linux/interrupt.h>
  15. #include <asm/fixmap.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/tlbflush.h>
  18. #include "mm.h"
  19. static inline void set_fixmap_pte(int idx, pte_t pte)
  20. {
  21. unsigned long vaddr = __fix_to_virt(idx);
  22. pte_t *ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
  23. set_pte_ext(ptep, pte, 0);
  24. local_flush_tlb_kernel_page(vaddr);
  25. }
  26. static inline pte_t get_fixmap_pte(unsigned long vaddr)
  27. {
  28. pte_t *ptep = pte_offset_kernel(pmd_off_k(vaddr), vaddr);
  29. return *ptep;
  30. }
  31. void *kmap(struct page *page)
  32. {
  33. might_sleep();
  34. if (!PageHighMem(page))
  35. return page_address(page);
  36. return kmap_high(page);
  37. }
  38. EXPORT_SYMBOL(kmap);
  39. void kunmap(struct page *page)
  40. {
  41. BUG_ON(in_interrupt());
  42. if (!PageHighMem(page))
  43. return;
  44. kunmap_high(page);
  45. }
  46. EXPORT_SYMBOL(kunmap);
  47. void *kmap_atomic(struct page *page)
  48. {
  49. unsigned int idx;
  50. unsigned long vaddr;
  51. void *kmap;
  52. int type;
  53. preempt_disable();
  54. pagefault_disable();
  55. if (!PageHighMem(page))
  56. return page_address(page);
  57. #ifdef CONFIG_DEBUG_HIGHMEM
  58. /*
  59. * There is no cache coherency issue when non VIVT, so force the
  60. * dedicated kmap usage for better debugging purposes in that case.
  61. */
  62. if (!cache_is_vivt())
  63. kmap = NULL;
  64. else
  65. #endif
  66. kmap = kmap_high_get(page);
  67. if (kmap)
  68. return kmap;
  69. type = kmap_atomic_idx_push();
  70. idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  71. vaddr = __fix_to_virt(idx);
  72. #ifdef CONFIG_DEBUG_HIGHMEM
  73. /*
  74. * With debugging enabled, kunmap_atomic forces that entry to 0.
  75. * Make sure it was indeed properly unmapped.
  76. */
  77. BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
  78. #endif
  79. /*
  80. * When debugging is off, kunmap_atomic leaves the previous mapping
  81. * in place, so the contained TLB flush ensures the TLB is updated
  82. * with the new mapping.
  83. */
  84. set_fixmap_pte(idx, mk_pte(page, kmap_prot));
  85. return (void *)vaddr;
  86. }
  87. EXPORT_SYMBOL(kmap_atomic);
  88. void __kunmap_atomic(void *kvaddr)
  89. {
  90. unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
  91. int idx, type;
  92. if (kvaddr >= (void *)FIXADDR_START) {
  93. type = kmap_atomic_idx();
  94. idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  95. if (cache_is_vivt())
  96. __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE);
  97. #ifdef CONFIG_DEBUG_HIGHMEM
  98. BUG_ON(vaddr != __fix_to_virt(idx));
  99. set_fixmap_pte(idx, __pte(0));
  100. #else
  101. (void) idx; /* to kill a warning */
  102. #endif
  103. kmap_atomic_idx_pop();
  104. } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
  105. /* this address was obtained through kmap_high_get() */
  106. kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
  107. }
  108. pagefault_enable();
  109. preempt_enable();
  110. }
  111. EXPORT_SYMBOL(__kunmap_atomic);
  112. void *kmap_atomic_pfn(unsigned long pfn)
  113. {
  114. unsigned long vaddr;
  115. int idx, type;
  116. struct page *page = pfn_to_page(pfn);
  117. preempt_disable();
  118. pagefault_disable();
  119. if (!PageHighMem(page))
  120. return page_address(page);
  121. type = kmap_atomic_idx_push();
  122. idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  123. vaddr = __fix_to_virt(idx);
  124. #ifdef CONFIG_DEBUG_HIGHMEM
  125. BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
  126. #endif
  127. set_fixmap_pte(idx, pfn_pte(pfn, kmap_prot));
  128. return (void *)vaddr;
  129. }