init.c (33331a728c83f380e53a3dbf2be0c1893da1d739) init.c (d279134168c78ac2caa1f7cd2a846579da1c93ac)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4 */
5#include <linux/init.h>
6#include <linux/export.h>
7#include <linux/signal.h>
8#include <linux/sched.h>

--- 138 unchanged lines hidden (view full) ---

147int memory_add_physaddr_to_nid(u64 start)
148{
149 return pa_to_nid(start);
150}
151EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
152#endif
153#endif
154
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4 */
5#include <linux/init.h>
6#include <linux/export.h>
7#include <linux/signal.h>
8#include <linux/sched.h>

--- 138 unchanged lines hidden (view full) ---

147int memory_add_physaddr_to_nid(u64 start)
148{
149 return pa_to_nid(start);
150}
151EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
152#endif
153#endif
154
155static pte_t *fixmap_pte(unsigned long addr)
156{
157 pgd_t *pgd;
158 p4d_t *p4d;
159 pud_t *pud;
160 pmd_t *pmd;
161
162 pgd = pgd_offset_k(addr);
163 p4d = p4d_offset(pgd, addr);
164
165 if (pgd_none(*pgd)) {
166 pud_t *new __maybe_unused;
167
168 new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
169 pgd_populate(&init_mm, pgd, new);
170#ifndef __PAGETABLE_PUD_FOLDED
171 pud_init((unsigned long)new, (unsigned long)invalid_pmd_table);
172#endif
173 }
174
175 pud = pud_offset(p4d, addr);
176 if (pud_none(*pud)) {
177 pmd_t *new __maybe_unused;
178
179 new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
180 pud_populate(&init_mm, pud, new);
181#ifndef __PAGETABLE_PMD_FOLDED
182 pmd_init((unsigned long)new, (unsigned long)invalid_pte_table);
183#endif
184 }
185
186 pmd = pmd_offset(pud, addr);
187 if (pmd_none(*pmd)) {
188 pte_t *new __maybe_unused;
189
190 new = memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
191 pmd_populate_kernel(&init_mm, pmd, new);
192 }
193
194 return pte_offset_kernel(pmd, addr);
195}
196
197void __init __set_fixmap(enum fixed_addresses idx,
198 phys_addr_t phys, pgprot_t flags)
199{
200 unsigned long addr = __fix_to_virt(idx);
201 pte_t *ptep;
202
203 BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
204
205 ptep = fixmap_pte(addr);
206 if (!pte_none(*ptep)) {
207 pte_ERROR(*ptep);
208 return;
209 }
210
211 if (pgprot_val(flags))
212 set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, flags));
213 else {
214 pte_clear(&init_mm, addr, ptep);
215 flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
216 }
217}
218
155/*
156 * Align swapper_pg_dir in to 64K, allows its address to be loaded
157 * with a single LUI instruction in the TLB handlers. If we used
158 * __aligned(64K), its size would get rounded up to the alignment
159 * size, and waste space. So we place it in its own section and align
160 * it in the linker script.
161 */
162pgd_t swapper_pg_dir[_PTRS_PER_PGD] __section(".bss..swapper_pg_dir");
163
164pgd_t invalid_pg_dir[_PTRS_PER_PGD] __page_aligned_bss;
165#ifndef __PAGETABLE_PUD_FOLDED
166pud_t invalid_pud_table[PTRS_PER_PUD] __page_aligned_bss;
167#endif
168#ifndef __PAGETABLE_PMD_FOLDED
169pmd_t invalid_pmd_table[PTRS_PER_PMD] __page_aligned_bss;
170EXPORT_SYMBOL_GPL(invalid_pmd_table);
171#endif
172pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned_bss;
173EXPORT_SYMBOL(invalid_pte_table);
219/*
220 * Align swapper_pg_dir in to 64K, allows its address to be loaded
221 * with a single LUI instruction in the TLB handlers. If we used
222 * __aligned(64K), its size would get rounded up to the alignment
223 * size, and waste space. So we place it in its own section and align
224 * it in the linker script.
225 */
226pgd_t swapper_pg_dir[_PTRS_PER_PGD] __section(".bss..swapper_pg_dir");
227
228pgd_t invalid_pg_dir[_PTRS_PER_PGD] __page_aligned_bss;
229#ifndef __PAGETABLE_PUD_FOLDED
230pud_t invalid_pud_table[PTRS_PER_PUD] __page_aligned_bss;
231#endif
232#ifndef __PAGETABLE_PMD_FOLDED
233pmd_t invalid_pmd_table[PTRS_PER_PMD] __page_aligned_bss;
234EXPORT_SYMBOL_GPL(invalid_pmd_table);
235#endif
236pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned_bss;
237EXPORT_SYMBOL(invalid_pte_table);