pgtable_32.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <linux/sched.h>
  2. #include <linux/kernel.h>
  3. #include <linux/errno.h>
  4. #include <linux/mm.h>
  5. #include <linux/nmi.h>
  6. #include <linux/swap.h>
  7. #include <linux/smp.h>
  8. #include <linux/highmem.h>
  9. #include <linux/pagemap.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/module.h>
  12. #include <asm/pgtable.h>
  13. #include <asm/pgalloc.h>
  14. #include <asm/fixmap.h>
  15. #include <asm/e820.h>
  16. #include <asm/tlb.h>
  17. #include <asm/tlbflush.h>
  18. #include <asm/io.h>
  19. unsigned int __VMALLOC_RESERVE = 128 << 20;
  20. /*
  21. * Associate a virtual page frame with a given physical page frame
  22. * and protection flags for that frame.
  23. */
  24. void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
  25. {
  26. pgd_t *pgd;
  27. pud_t *pud;
  28. pmd_t *pmd;
  29. pte_t *pte;
  30. pgd = swapper_pg_dir + pgd_index(vaddr);
  31. if (pgd_none(*pgd)) {
  32. BUG();
  33. return;
  34. }
  35. pud = pud_offset(pgd, vaddr);
  36. if (pud_none(*pud)) {
  37. BUG();
  38. return;
  39. }
  40. pmd = pmd_offset(pud, vaddr);
  41. if (pmd_none(*pmd)) {
  42. BUG();
  43. return;
  44. }
  45. pte = pte_offset_kernel(pmd, vaddr);
  46. if (pte_val(pteval))
  47. set_pte_at(&init_mm, vaddr, pte, pteval);
  48. else
  49. pte_clear(&init_mm, vaddr, pte);
  50. /*
  51. * It's enough to flush this one mapping.
  52. * (PGE mappings get flushed as well)
  53. */
  54. __flush_tlb_one(vaddr);
  55. }
  56. /*
  57. * Associate a large virtual page frame with a given physical page frame
  58. * and protection flags for that frame. pfn is for the base of the page,
  59. * vaddr is what the page gets mapped to - both must be properly aligned.
  60. * The pmd must already be instantiated. Assumes PAE mode.
  61. */
  62. void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
  63. {
  64. pgd_t *pgd;
  65. pud_t *pud;
  66. pmd_t *pmd;
  67. if (vaddr & (PMD_SIZE-1)) { /* vaddr is misaligned */
  68. printk(KERN_WARNING "set_pmd_pfn: vaddr misaligned\n");
  69. return; /* BUG(); */
  70. }
  71. if (pfn & (PTRS_PER_PTE-1)) { /* pfn is misaligned */
  72. printk(KERN_WARNING "set_pmd_pfn: pfn misaligned\n");
  73. return; /* BUG(); */
  74. }
  75. pgd = swapper_pg_dir + pgd_index(vaddr);
  76. if (pgd_none(*pgd)) {
  77. printk(KERN_WARNING "set_pmd_pfn: pgd_none\n");
  78. return; /* BUG(); */
  79. }
  80. pud = pud_offset(pgd, vaddr);
  81. pmd = pmd_offset(pud, vaddr);
  82. set_pmd(pmd, pfn_pmd(pfn, flags));
  83. /*
  84. * It's enough to flush this one mapping.
  85. * (PGE mappings get flushed as well)
  86. */
  87. __flush_tlb_one(vaddr);
  88. }
  89. unsigned long __FIXADDR_TOP = 0xfffff000;
  90. EXPORT_SYMBOL(__FIXADDR_TOP);
  91. /*
  92. * vmalloc=size forces the vmalloc area to be exactly 'size'
  93. * bytes. This can be used to increase (or decrease) the
  94. * vmalloc area - the default is 128m.
  95. */
  96. static int __init parse_vmalloc(char *arg)
  97. {
  98. if (!arg)
  99. return -EINVAL;
  100. /* Add VMALLOC_OFFSET to the parsed value due to vm area guard hole*/
  101. __VMALLOC_RESERVE = memparse(arg, &arg) + VMALLOC_OFFSET;
  102. return 0;
  103. }
  104. early_param("vmalloc", parse_vmalloc);
  105. /*
  106. * reservetop=size reserves a hole at the top of the kernel address space which
  107. * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
  108. * so relocating the fixmap can be done before paging initialization.
  109. */
  110. static int __init parse_reservetop(char *arg)
  111. {
  112. unsigned long address;
  113. if (!arg)
  114. return -EINVAL;
  115. address = memparse(arg, &arg);
  116. reserve_top_address(address);
  117. fixup_early_ioremap();
  118. return 0;
  119. }
  120. early_param("reservetop", parse_reservetop);