highmem.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/highmem.h>
  23. #include <linux/module.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. void *kmap_atomic_prot(struct page *page, pgprot_t prot)
  31. {
  32. unsigned long vaddr;
  33. int idx, type;
  34. preempt_disable();
  35. pagefault_disable();
  36. if (!PageHighMem(page))
  37. return page_address(page);
  38. type = kmap_atomic_idx_push();
  39. idx = type + KM_TYPE_NR*smp_processor_id();
  40. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  41. #ifdef CONFIG_DEBUG_HIGHMEM
  42. BUG_ON(!pte_none(*(kmap_pte-idx)));
  43. #endif
  44. __set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot), 1);
  45. local_flush_tlb_page(NULL, vaddr);
  46. return (void*) vaddr;
  47. }
  48. EXPORT_SYMBOL(kmap_atomic_prot);
  49. void __kunmap_atomic(void *kvaddr)
  50. {
  51. unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
  52. int type;
  53. if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
  54. pagefault_enable();
  55. preempt_enable();
  56. return;
  57. }
  58. type = kmap_atomic_idx();
  59. #ifdef CONFIG_DEBUG_HIGHMEM
  60. {
  61. unsigned int idx;
  62. idx = type + KM_TYPE_NR * smp_processor_id();
  63. BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
  64. /*
  65. * force other mappings to Oops if they'll try to access
  66. * this pte without first remap it
  67. */
  68. pte_clear(&init_mm, vaddr, kmap_pte-idx);
  69. local_flush_tlb_page(NULL, vaddr);
  70. }
  71. #endif
  72. kmap_atomic_idx_pop();
  73. pagefault_enable();
  74. preempt_enable();
  75. }
  76. EXPORT_SYMBOL(__kunmap_atomic);