highmem.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_high_prot(struct page *page, pgprot_t prot)
  34. {
  35. enum fixed_addresses idx;
  36. unsigned long vaddr;
  37. idx = kmap_idx(kmap_atomic_idx_push(),
  38. DCACHE_ALIAS(page_to_phys(page)));
  39. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  40. #ifdef CONFIG_DEBUG_HIGHMEM
  41. BUG_ON(!pte_none(*(kmap_pte + idx)));
  42. #endif
  43. set_pte(kmap_pte + idx, mk_pte(page, prot));
  44. return (void *)vaddr;
  45. }
  46. EXPORT_SYMBOL(kmap_atomic_high_prot);
  47. void kunmap_atomic_high(void *kvaddr)
  48. {
  49. if (kvaddr >= (void *)FIXADDR_START &&
  50. kvaddr < (void *)FIXADDR_TOP) {
  51. int idx = kmap_idx(kmap_atomic_idx(),
  52. DCACHE_ALIAS((unsigned long)kvaddr));
  53. /*
  54. * Force other mappings to Oops if they'll try to access this
  55. * pte without first remap it. Keeping stale mappings around
  56. * is a bad idea also, in case the page changes cacheability
  57. * attributes or becomes a protected page in a hypervisor.
  58. */
  59. pte_clear(&init_mm, kvaddr, kmap_pte + idx);
  60. local_flush_tlb_kernel_range((unsigned long)kvaddr,
  61. (unsigned long)kvaddr + PAGE_SIZE);
  62. kmap_atomic_idx_pop();
  63. }
  64. }
  65. EXPORT_SYMBOL(kunmap_atomic_high);
  66. void __init kmap_init(void)
  67. {
  68. unsigned long kmap_vstart;
  69. /* Check if this memory layout is broken because PKMAP overlaps
  70. * page table.
  71. */
  72. BUILD_BUG_ON(PKMAP_BASE < TLBTEMP_BASE_1 + TLBTEMP_SIZE);
  73. /* cache the first kmap pte */
  74. kmap_vstart = __fix_to_virt(FIX_KMAP_BEGIN);
  75. kmap_pte = virt_to_kpte(kmap_vstart);
  76. kmap_waitqueues_init();
  77. }