Skip to content

Commit 0106235

Browse files
xhackerustcpalmer-dabbelt
authored andcommitted
riscv: mm: init: Consolidate vars, functions
Consolidate the following items in init.c Staticize global vars as much as possible; Add __initdata mark if the global var isn't needed after init Add __init mark if the func isn't needed after init Add __ro_after_init if the global var is read only after init Signed-off-by: Jisheng Zhang <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 3df952a commit 0106235

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

arch/riscv/include/asm/set_memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static inline int set_memory_rw_nx(unsigned long addr, int numpages) { return 0;
2727
#endif
2828

2929
#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
30-
void protect_kernel_linear_mapping_text_rodata(void);
30+
void __init protect_kernel_linear_mapping_text_rodata(void);
3131
#else
3232
static inline void protect_kernel_linear_mapping_text_rodata(void) {}
3333
#endif

arch/riscv/mm/init.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct pt_alloc_ops {
5454
#endif
5555
};
5656

57-
static phys_addr_t dma32_phys_limit __ro_after_init;
57+
static phys_addr_t dma32_phys_limit __initdata;
5858

5959
static void __init zone_sizes_init(void)
6060
{
@@ -173,7 +173,7 @@ static void __init setup_bootmem(void)
173173
}
174174

175175
#ifdef CONFIG_MMU
176-
static struct pt_alloc_ops _pt_ops __ro_after_init;
176+
static struct pt_alloc_ops _pt_ops __initdata;
177177

178178
#ifdef CONFIG_XIP_KERNEL
179179
#define pt_ops (*(struct pt_alloc_ops *)XIP_FIXUP(&_pt_ops))
@@ -189,13 +189,13 @@ EXPORT_SYMBOL(va_pa_offset);
189189
#endif
190190
/* Offset between kernel mapping virtual address and kernel load address */
191191
#ifdef CONFIG_64BIT
192-
unsigned long va_kernel_pa_offset;
192+
unsigned long va_kernel_pa_offset __ro_after_init;
193193
EXPORT_SYMBOL(va_kernel_pa_offset);
194194
#endif
195195
#ifdef CONFIG_XIP_KERNEL
196196
#define va_kernel_pa_offset (*((unsigned long *)XIP_FIXUP(&va_kernel_pa_offset)))
197197
#endif
198-
unsigned long va_kernel_xip_pa_offset;
198+
unsigned long va_kernel_xip_pa_offset __ro_after_init;
199199
EXPORT_SYMBOL(va_kernel_xip_pa_offset);
200200
#ifdef CONFIG_XIP_KERNEL
201201
#define va_kernel_xip_pa_offset (*((unsigned long *)XIP_FIXUP(&va_kernel_xip_pa_offset)))
@@ -205,7 +205,7 @@ EXPORT_SYMBOL(pfn_base);
205205

206206
pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
207207
pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
208-
pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
208+
static pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
209209

210210
pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
211211

@@ -242,7 +242,7 @@ static inline pte_t *__init get_pte_virt_fixmap(phys_addr_t pa)
242242
return (pte_t *)set_fixmap_offset(FIX_PTE, pa);
243243
}
244244

245-
static inline pte_t *get_pte_virt_late(phys_addr_t pa)
245+
static inline pte_t *__init get_pte_virt_late(phys_addr_t pa)
246246
{
247247
return (pte_t *) __va(pa);
248248
}
@@ -261,7 +261,7 @@ static inline phys_addr_t __init alloc_pte_fixmap(uintptr_t va)
261261
return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE);
262262
}
263263

264-
static phys_addr_t alloc_pte_late(uintptr_t va)
264+
static phys_addr_t __init alloc_pte_late(uintptr_t va)
265265
{
266266
unsigned long vaddr;
267267

@@ -285,10 +285,10 @@ static void __init create_pte_mapping(pte_t *ptep,
285285

286286
#ifndef __PAGETABLE_PMD_FOLDED
287287

288-
pmd_t trampoline_pmd[PTRS_PER_PMD] __page_aligned_bss;
289-
pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
290-
pmd_t early_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
291-
pmd_t early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
288+
static pmd_t trampoline_pmd[PTRS_PER_PMD] __page_aligned_bss;
289+
static pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
290+
static pmd_t early_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
291+
static pmd_t early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
292292

293293
#ifdef CONFIG_XIP_KERNEL
294294
#define trampoline_pmd ((pmd_t *)XIP_FIXUP(trampoline_pmd))
@@ -308,7 +308,7 @@ static pmd_t *__init get_pmd_virt_fixmap(phys_addr_t pa)
308308
return (pmd_t *)set_fixmap_offset(FIX_PMD, pa);
309309
}
310310

311-
static pmd_t *get_pmd_virt_late(phys_addr_t pa)
311+
static pmd_t *__init get_pmd_virt_late(phys_addr_t pa)
312312
{
313313
return (pmd_t *) __va(pa);
314314
}
@@ -325,7 +325,7 @@ static phys_addr_t __init alloc_pmd_fixmap(uintptr_t va)
325325
return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE);
326326
}
327327

328-
static phys_addr_t alloc_pmd_late(uintptr_t va)
328+
static phys_addr_t __init alloc_pmd_late(uintptr_t va)
329329
{
330330
unsigned long vaddr;
331331

@@ -443,14 +443,16 @@ asmlinkage void __init __copy_data(void)
443443
#error "setup_vm() is called from head.S before relocate so it should not use absolute addressing."
444444
#endif
445445

446-
uintptr_t load_pa, load_sz;
446+
static uintptr_t load_pa __initdata;
447+
static uintptr_t load_sz __initdata;
447448
#ifdef CONFIG_XIP_KERNEL
448449
#define load_pa (*((uintptr_t *)XIP_FIXUP(&load_pa)))
449450
#define load_sz (*((uintptr_t *)XIP_FIXUP(&load_sz)))
450451
#endif
451452

452453
#ifdef CONFIG_XIP_KERNEL
453-
uintptr_t xiprom, xiprom_sz;
454+
static uintptr_t xiprom __inidata;
455+
static uintptr_t xiprom_sz __initdata;
454456
#define xiprom_sz (*((uintptr_t *)XIP_FIXUP(&xiprom_sz)))
455457
#define xiprom (*((uintptr_t *)XIP_FIXUP(&xiprom)))
456458

@@ -635,7 +637,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
635637
}
636638

637639
#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
638-
void protect_kernel_linear_mapping_text_rodata(void)
640+
void __init protect_kernel_linear_mapping_text_rodata(void)
639641
{
640642
unsigned long text_start = (unsigned long)lm_alias(_start);
641643
unsigned long init_text_start = (unsigned long)lm_alias(__init_text_begin);
@@ -843,7 +845,7 @@ static void __init reserve_crashkernel(void)
843845
* reserved once we call early_init_fdt_scan_reserved_mem()
844846
* later on.
845847
*/
846-
static int elfcore_hdr_setup(struct reserved_mem *rmem)
848+
static int __init elfcore_hdr_setup(struct reserved_mem *rmem)
847849
{
848850
elfcorehdr_addr = rmem->base;
849851
elfcorehdr_size = rmem->size;

0 commit comments

Comments
 (0)