highmem.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * highmem.c: virtual kernel memory mappings for high memory
  3. *
  4. * PowerPC version, stolen from the i386 version.
  5. *
  6. * Used in CONFIG_HIGHMEM systems for memory pages which
  7. * are not addressable by direct kernel virtual addresses.
  8. *
  9. * Copyright (C) 1999 Gerhard Wichert, Siemens AG
  10. * Gerhard.Wichert@pdb.siemens.de
  11. *
  12. *
  13. * Redesigned the x86 32-bit VM architecture to deal with
  14. * up to 16 Terrabyte physical memory. With current x86 CPUs
  15. * we now support up to 64 Gigabytes physical RAM.
  16. *
  17. * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
  18. *
  19. * Reworked for PowerPC by various contributors. Moved from
  20. * highmem.h by Benjamin Herrenschmidt (c) 2009 IBM Corp.
  21. */
  22. #include <linux/export.h>
  23. #include <linux/highmem.h>
  24. /*
  25. * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
  26. * gives a more generic (and caching) interface. But kmap_atomic can
  27. * be used in IRQ contexts, so in some (very limited) cases we need
  28. * it.
  29. */
  30. #include <asm/tlbflush.h>
  31. void *kmap_atomic_prot(struct page *page, pgprot_t prot)
  32. {
  33. unsigned long vaddr;
  34. int idx, type;
  35. preempt_disable();
  36. pagefault_disable();
  37. if (!PageHighMem(page))
  38. return page_address(page);
  39. type = kmap_atomic_idx_push();
  40. idx = type + KM_TYPE_NR*smp_processor_id();
  41. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  42. #ifdef CONFIG_DEBUG_HIGHMEM
  43. BUG_ON(!pte_none(*(kmap_pte-idx)));
  44. #endif
  45. set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot));
  46. local_flush_tlb_page(NULL, vaddr);
  47. return (void *) vaddr;
  48. }
  49. EXPORT_SYMBOL(kmap_atomic_prot);
  50. void __kunmap_atomic(void *kvaddr)
  51. {
  52. unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
  53. int type;
  54. if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
  55. pagefault_enable();
  56. preempt_enable();
  57. return;
  58. }
  59. type = kmap_atomic_idx();
  60. #ifdef CONFIG_DEBUG_HIGHMEM
  61. {
  62. unsigned int idx;
  63. idx = type + KM_TYPE_NR * smp_processor_id();
  64. BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
  65. /*
  66. * force other mappings to Oops if they'll try to access
  67. * this pte without first remap it
  68. */
  69. pte_clear(&init_mm, vaddr, kmap_pte-idx);
  70. local_flush_tlb_page(NULL, vaddr);
  71. }
  72. #endif
  73. kmap_atomic_idx_pop();
  74. pagefault_enable();
  75. preempt_enable();
  76. }
  77. EXPORT_SYMBOL(__kunmap_atomic);