Skip to content

Commit 6f1e9e9

Browse files
committed
RISC-V: Move setup_vm() to mm/init.c
The setup_vm() is responsible for setting up initial page table hence should be placed in mm/init.c. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Palmer Dabbelt <palmer@sifive.com>
1 parent 0651c26 commit 6f1e9e9

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

arch/riscv/kernel/setup.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -69,55 +69,6 @@ void __init smp_setup_processor_id(void)
6969
cpuid_to_hartid_map(0) = boot_cpu_hartid;
7070
}
7171

72-
pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
73-
pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
74-
75-
#ifndef __PAGETABLE_PMD_FOLDED
76-
#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT)
77-
pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss;
78-
pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
79-
#endif
80-
81-
asmlinkage void __init setup_vm(void)
82-
{
83-
extern char _start;
84-
uintptr_t i;
85-
uintptr_t pa = (uintptr_t) &_start;
86-
pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC);
87-
88-
va_pa_offset = PAGE_OFFSET - pa;
89-
pfn_base = PFN_DOWN(pa);
90-
91-
/* Sanity check alignment and size */
92-
BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
93-
BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0);
94-
95-
#ifndef __PAGETABLE_PMD_FOLDED
96-
trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
97-
pfn_pgd(PFN_DOWN((uintptr_t)trampoline_pmd),
98-
__pgprot(_PAGE_TABLE));
99-
trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot);
100-
101-
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
102-
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
103-
swapper_pg_dir[o] =
104-
pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i,
105-
__pgprot(_PAGE_TABLE));
106-
}
107-
for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++)
108-
swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot);
109-
#else
110-
trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
111-
pfn_pgd(PFN_DOWN(pa), prot);
112-
113-
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
114-
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
115-
swapper_pg_dir[o] =
116-
pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot);
117-
}
118-
#endif
119-
}
120-
12172
void __init parse_dtb(unsigned int hartid, void *dtb)
12273
{
12374
if (!early_init_dt_scan(__va(dtb)))

arch/riscv/mm/init.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,52 @@ void __init setup_bootmem(void)
140140
&memblock.memory, 0);
141141
}
142142
}
143+
144+
pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
145+
pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
146+
147+
#ifndef __PAGETABLE_PMD_FOLDED
148+
#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT)
149+
pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss;
150+
pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
151+
#endif
152+
153+
asmlinkage void __init setup_vm(void)
154+
{
155+
extern char _start;
156+
uintptr_t i;
157+
uintptr_t pa = (uintptr_t) &_start;
158+
pgprot_t prot = __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_EXEC);
159+
160+
va_pa_offset = PAGE_OFFSET - pa;
161+
pfn_base = PFN_DOWN(pa);
162+
163+
/* Sanity check alignment and size */
164+
BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
165+
BUG_ON((pa % (PAGE_SIZE * PTRS_PER_PTE)) != 0);
166+
167+
#ifndef __PAGETABLE_PMD_FOLDED
168+
trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
169+
pfn_pgd(PFN_DOWN((uintptr_t)trampoline_pmd),
170+
__pgprot(_PAGE_TABLE));
171+
trampoline_pmd[0] = pfn_pmd(PFN_DOWN(pa), prot);
172+
173+
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
174+
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
175+
swapper_pg_dir[o] =
176+
pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i,
177+
__pgprot(_PAGE_TABLE));
178+
}
179+
for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++)
180+
swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot);
181+
#else
182+
trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
183+
pfn_pgd(PFN_DOWN(pa), prot);
184+
185+
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
186+
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
187+
swapper_pg_dir[o] =
188+
pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot);
189+
}
190+
#endif
191+
}

0 commit comments

Comments
 (0)