pgtable_32.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/sched.h>
  3. #include <linux/kernel.h>
  4. #include <linux/errno.h>
  5. #include <linux/mm.h>
  6. #include <linux/nmi.h>
  7. #include <linux/swap.h>
  8. #include <linux/smp.h>
  9. #include <linux/highmem.h>
  10. #include <linux/pagemap.h>
  11. #include <linux/spinlock.h>
  12. #include <asm/cpu_entry_area.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/pgalloc.h>
  15. #include <asm/fixmap.h>
  16. #include <asm/e820/api.h>
  17. #include <asm/tlb.h>
  18. #include <asm/tlbflush.h>
  19. #include <asm/io.h>
  20. unsigned int __VMALLOC_RESERVE = 128 << 20;
  21. /*
  22. * Associate a virtual page frame with a given physical page frame
  23. * and protection flags for that frame.
  24. */
  25. void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
  26. {
  27. pgd_t *pgd;
  28. p4d_t *p4d;
  29. pud_t *pud;
  30. pmd_t *pmd;
  31. pte_t *pte;
  32. pgd = swapper_pg_dir + pgd_index(vaddr);
  33. if (pgd_none(*pgd)) {
  34. BUG();
  35. return;
  36. }
  37. p4d = p4d_offset(pgd, vaddr);
  38. if (p4d_none(*p4d)) {
  39. BUG();
  40. return;
  41. }
  42. pud = pud_offset(p4d, vaddr);
  43. if (pud_none(*pud)) {
  44. BUG();
  45. return;
  46. }
  47. pmd = pmd_offset(pud, vaddr);
  48. if (pmd_none(*pmd)) {
  49. BUG();
  50. return;
  51. }
  52. pte = pte_offset_kernel(pmd, vaddr);
  53. if (!pte_none(pteval))
  54. set_pte_at(&init_mm, vaddr, pte, pteval);
  55. else
  56. pte_clear(&init_mm, vaddr, pte);
  57. /*
  58. * It's enough to flush this one mapping.
  59. * (PGE mappings get flushed as well)
  60. */
  61. __flush_tlb_one_kernel(vaddr);
  62. }
  63. unsigned long __FIXADDR_TOP = 0xfffff000;
  64. EXPORT_SYMBOL(__FIXADDR_TOP);
  65. /*
  66. * vmalloc=size forces the vmalloc area to be exactly 'size'
  67. * bytes. This can be used to increase (or decrease) the
  68. * vmalloc area - the default is 128m.
  69. */
  70. static int __init parse_vmalloc(char *arg)
  71. {
  72. if (!arg)
  73. return -EINVAL;
  74. /* Add VMALLOC_OFFSET to the parsed value due to vm area guard hole*/
  75. __VMALLOC_RESERVE = memparse(arg, &arg) + VMALLOC_OFFSET;
  76. return 0;
  77. }
  78. early_param("vmalloc", parse_vmalloc);
  79. /*
  80. * reservetop=size reserves a hole at the top of the kernel address space which
  81. * a hypervisor can load into later. Needed for dynamically loaded hypervisors,
  82. * so relocating the fixmap can be done before paging initialization.
  83. */
  84. static int __init parse_reservetop(char *arg)
  85. {
  86. unsigned long address;
  87. if (!arg)
  88. return -EINVAL;
  89. address = memparse(arg, &arg);
  90. reserve_top_address(address);
  91. early_ioremap_init();
  92. return 0;
  93. }
  94. early_param("reservetop", parse_reservetop);