highmem.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * High memory support for Xtensa architecture
  3. *
  4. * This file is subject to the terms and conditions of the GNU General
  5. * Public License. See the file "COPYING" in the main directory of
  6. * this archive for more details.
  7. *
  8. * Copyright (C) 2014 Cadence Design Systems Inc.
  9. */
  10. #include <linux/export.h>
  11. #include <linux/highmem.h>
  12. #include <asm/tlbflush.h>
  13. static pte_t *kmap_pte;
  14. #if DCACHE_WAY_SIZE > PAGE_SIZE
  15. unsigned int last_pkmap_nr_arr[DCACHE_N_COLORS];
  16. wait_queue_head_t pkmap_map_wait_arr[DCACHE_N_COLORS];
  17. static void __init kmap_waitqueues_init(void)
  18. {
  19. unsigned int i;
  20. for (i = 0; i < ARRAY_SIZE(pkmap_map_wait_arr); ++i)
  21. init_waitqueue_head(pkmap_map_wait_arr + i);
  22. }
  23. #else
  24. static inline void kmap_waitqueues_init(void)
  25. {
  26. }
  27. #endif
  28. static inline enum fixed_addresses kmap_idx(int type, unsigned long color)
  29. {
  30. return (type + KM_TYPE_NR * smp_processor_id()) * DCACHE_N_COLORS +
  31. color;
  32. }
  33. void *kmap_atomic(struct page *page)
  34. {
  35. enum fixed_addresses idx;
  36. unsigned long vaddr;
  37. pagefault_disable();
  38. if (!PageHighMem(page))
  39. return page_address(page);
  40. idx = kmap_idx(kmap_atomic_idx_push(),
  41. DCACHE_ALIAS(page_to_phys(page)));
  42. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  43. #ifdef CONFIG_DEBUG_HIGHMEM
  44. BUG_ON(!pte_none(*(kmap_pte + idx)));
  45. #endif
  46. set_pte(kmap_pte + idx, mk_pte(page, PAGE_KERNEL_EXEC));
  47. return (void *)vaddr;
  48. }
  49. EXPORT_SYMBOL(kmap_atomic);
  50. void __kunmap_atomic(void *kvaddr)
  51. {
  52. if (kvaddr >= (void *)FIXADDR_START &&
  53. kvaddr < (void *)FIXADDR_TOP) {
  54. int idx = kmap_idx(kmap_atomic_idx(),
  55. DCACHE_ALIAS((unsigned long)kvaddr));
  56. /*
  57. * Force other mappings to Oops if they'll try to access this
  58. * pte without first remap it. Keeping stale mappings around
  59. * is a bad idea also, in case the page changes cacheability
  60. * attributes or becomes a protected page in a hypervisor.
  61. */
  62. pte_clear(&init_mm, kvaddr, kmap_pte + idx);
  63. local_flush_tlb_kernel_range((unsigned long)kvaddr,
  64. (unsigned long)kvaddr + PAGE_SIZE);
  65. kmap_atomic_idx_pop();
  66. }
  67. pagefault_enable();
  68. }
  69. EXPORT_SYMBOL(__kunmap_atomic);
  70. void __init kmap_init(void)
  71. {
  72. unsigned long kmap_vstart;
  73. /* cache the first kmap pte */
  74. kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN);
  75. kmap_pte = kmap_get_fixmap_pte(kmap_vstart);
  76. kmap_waitqueues_init();
  77. }