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/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. /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  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. 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. }
  75. EXPORT_SYMBOL(__kunmap_atomic);