^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright (C) 1995-2005 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Copyright (C) 2012 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) // Copyright (C) 2013-2017 Andes Technology Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/nodemask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/tlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) DEFINE_SPINLOCK(anon_alias_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * empty_zero_page is a special page that is used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * zero-initialized data and COW.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct page *empty_zero_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) EXPORT_SYMBOL(empty_zero_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void __init zone_sizes_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) max_zone_pfn[ZONE_NORMAL] = max_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) max_zone_pfn[ZONE_HIGHMEM] = max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) free_area_init(max_zone_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Map all physical memory under high_memory into kernel's address space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * This is explicitly coded for two-level page tables, so if you need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * something else then this needs to change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static void __init map_ram(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long v, p, e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) pgd_t *pge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) p4d_t *p4e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) pud_t *pue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) pmd_t *pme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) pte_t *pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* These mark extents of read-only kernel pages...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * ...from vmlinux.lds.S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) p = (u32) memblock_start_of_DRAM() & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) e = min((u32) memblock_end_of_DRAM(), (u32) __pa(high_memory));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) v = (u32) __va(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) pge = pgd_offset_k(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) while (p < e) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) p4e = p4d_offset(pge, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) pue = pud_offset(p4e, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) pme = pmd_offset(pue, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if ((u32) pue != (u32) pge || (u32) pme != (u32) pge) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) panic("%s: Kernel hardcoded for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) "two-level page tables", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Alloc one page for holding PTE's... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) __func__, PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) set_pmd(pme, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* Fill the newly allocated page with PTE'S */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) for (j = 0; p < e && j < PTRS_PER_PTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) v += PAGE_SIZE, p += PAGE_SIZE, j++, pte++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /* Create mapping between p and v. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* TODO: more fine grant for page access permission */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) set_pte(pte, __pte(p + pgprot_val(PAGE_KERNEL)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) pge++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static pmd_t *fixmap_pmd_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static void __init fixedrange_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) pmd_t *pmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) pte_t *pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #endif /* CONFIG_HIGHMEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * Fixed mappings:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) vaddr = __fix_to_virt(__end_of_fixed_addresses - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) pmd = pmd_off_k(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) fixmap_pmd_p = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (!fixmap_pmd_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) __func__, PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) set_pmd(pmd, __pmd(__pa(fixmap_pmd_p) + _PAGE_KERNEL_TABLE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Permanent kmaps:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) vaddr = PKMAP_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) pmd = pmd_off_k(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (!pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) __func__, PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) set_pmd(pmd, __pmd(__pa(pte) + _PAGE_KERNEL_TABLE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) pkmap_page_table = pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #endif /* CONFIG_HIGHMEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * paging_init() sets up the page tables, initialises the zone memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * maps, and sets up the zero page, bad page and bad page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) void __init paging_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) void *zero_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) pr_info("Setting up paging and PTEs.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* clear out the init_mm.pgd that will contain the kernel's mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) for (i = 0; i < PTRS_PER_PGD; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) swapper_pg_dir[i] = __pgd(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) map_ram();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) fixedrange_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* allocate space for empty_zero_page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!zero_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) __func__, PAGE_SIZE, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) zone_sizes_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) empty_zero_page = virt_to_page(zero_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) flush_dcache_page(empty_zero_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline void __init free_highmem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) unsigned long pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) for (pfn = PFN_UP(__pa(high_memory)); pfn < max_pfn; pfn++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) phys_addr_t paddr = (phys_addr_t) pfn << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (!memblock_is_reserved(paddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) free_highmem_page(pfn_to_page(pfn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static void __init set_max_mapnr_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) max_mapnr = max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * mem_init() marks the free areas in the mem_map and tells us how much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * memory is free. This is done after various parts of the system have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * claimed their memory after the kernel image.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) void __init mem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) phys_addr_t memory_start = memblock_start_of_DRAM();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) BUG_ON(!mem_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) set_max_mapnr_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) free_highmem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* this will put all low memory onto the freelists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) memblock_free_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) mem_init_print_info(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) pr_info("virtual kernel memory layout:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) " fixmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) " pkmap : 0x%08lx - 0x%08lx (%4ld kB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) " consist : 0x%08lx - 0x%08lx (%4ld MB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) " vmalloc : 0x%08lx - 0x%08lx (%4ld MB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) " lowmem : 0x%08lx - 0x%08lx (%4ld MB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) " .init : 0x%08lx - 0x%08lx (%4ld kB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) " .data : 0x%08lx - 0x%08lx (%4ld kB)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) " .text : 0x%08lx - 0x%08lx (%4ld kB)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) FIXADDR_START, FIXADDR_TOP, (FIXADDR_TOP - FIXADDR_START) >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) PKMAP_BASE, PKMAP_BASE + LAST_PKMAP * PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) (LAST_PKMAP * PAGE_SIZE) >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) CONSISTENT_BASE, CONSISTENT_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ((CONSISTENT_END) - (CONSISTENT_BASE)) >> 20, VMALLOC_START,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) (unsigned long)VMALLOC_END, (VMALLOC_END - VMALLOC_START) >> 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) (unsigned long)__va(memory_start), (unsigned long)high_memory,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ((unsigned long)high_memory -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) (unsigned long)__va(memory_start)) >> 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) (unsigned long)&__init_begin, (unsigned long)&__init_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) ((unsigned long)&__init_end -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) (unsigned long)&__init_begin) >> 10, (unsigned long)&_etext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) (unsigned long)&_edata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) (unsigned long)&_text, (unsigned long)&_etext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * Check boundaries twice: Some fundamental inconsistencies can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * be detected at build time already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) BUILD_BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > FIXADDR_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) BUILD_BUG_ON((CONSISTENT_END) > PKMAP_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) BUILD_BUG_ON(VMALLOC_END > CONSISTENT_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) BUILD_BUG_ON(VMALLOC_START >= VMALLOC_END);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) BUG_ON(PKMAP_BASE + LAST_PKMAP * PAGE_SIZE > FIXADDR_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) BUG_ON(CONSISTENT_END > PKMAP_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) BUG_ON(VMALLOC_END > CONSISTENT_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) BUG_ON(VMALLOC_START >= VMALLOC_END);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) BUG_ON((unsigned long)high_memory > VMALLOC_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void __set_fixmap(enum fixed_addresses idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) phys_addr_t phys, pgprot_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) unsigned long addr = __fix_to_virt(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pte_t *pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) pte = (pte_t *)&fixmap_pmd_p[pte_index(addr)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (pgprot_val(flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pte_clear(&init_mm, addr, pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }