Skip to content

Commit 0651c26

Browse files
committed
RISC-V: Move setup_bootmem() to mm/init.c
The setup_bootmem() mainly populates memblocks and does early memory reservations. The right location for this function is mm/init.c. It calls setup_initrd() so we move that as well. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Palmer Dabbelt <palmer@sifive.com> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
1 parent 680f9b8 commit 0651c26

File tree

3 files changed

+71
-72
lines changed

3 files changed

+71
-72
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
404404
#define kern_addr_valid(addr) (1) /* FIXME */
405405
#endif
406406

407+
extern void setup_bootmem(void);
407408
extern void paging_init(void);
408409

409410
static inline void pgtable_cache_init(void)

arch/riscv/kernel/setup.c

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <linux/mm.h>
2424
#include <linux/memblock.h>
2525
#include <linux/sched.h>
26-
#include <linux/initrd.h>
2726
#include <linux/console.h>
2827
#include <linux/screen_info.h>
2928
#include <linux/of_fdt.h>
@@ -70,34 +69,6 @@ void __init smp_setup_processor_id(void)
7069
cpuid_to_hartid_map(0) = boot_cpu_hartid;
7170
}
7271

73-
#ifdef CONFIG_BLK_DEV_INITRD
74-
static void __init setup_initrd(void)
75-
{
76-
unsigned long size;
77-
78-
if (initrd_start >= initrd_end) {
79-
pr_info("initrd not found or empty");
80-
goto disable;
81-
}
82-
if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
83-
pr_err("initrd extends beyond end of memory");
84-
goto disable;
85-
}
86-
87-
size = initrd_end - initrd_start;
88-
memblock_reserve(__pa(initrd_start), size);
89-
initrd_below_start_ok = 1;
90-
91-
pr_info("Initial ramdisk at: 0x%p (%lu bytes)\n",
92-
(void *)(initrd_start), size);
93-
return;
94-
disable:
95-
pr_cont(" - disabling initrd\n");
96-
initrd_start = 0;
97-
initrd_end = 0;
98-
}
99-
#endif /* CONFIG_BLK_DEV_INITRD */
100-
10172
pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
10273
pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
10374

@@ -159,49 +130,6 @@ void __init parse_dtb(unsigned int hartid, void *dtb)
159130
#endif
160131
}
161132

162-
static void __init setup_bootmem(void)
163-
{
164-
struct memblock_region *reg;
165-
phys_addr_t mem_size = 0;
166-
167-
/* Find the memory region containing the kernel */
168-
for_each_memblock(memory, reg) {
169-
phys_addr_t vmlinux_end = __pa(_end);
170-
phys_addr_t end = reg->base + reg->size;
171-
172-
if (reg->base <= vmlinux_end && vmlinux_end <= end) {
173-
/*
174-
* Reserve from the start of the region to the end of
175-
* the kernel
176-
*/
177-
memblock_reserve(reg->base, vmlinux_end - reg->base);
178-
mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET);
179-
}
180-
}
181-
BUG_ON(mem_size == 0);
182-
183-
set_max_mapnr(PFN_DOWN(mem_size));
184-
max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());
185-
186-
#ifdef CONFIG_BLK_DEV_INITRD
187-
setup_initrd();
188-
#endif /* CONFIG_BLK_DEV_INITRD */
189-
190-
early_init_fdt_reserve_self();
191-
early_init_fdt_scan_reserved_mem();
192-
memblock_allow_resize();
193-
memblock_dump_all();
194-
195-
for_each_memblock(memory, reg) {
196-
unsigned long start_pfn = memblock_region_memory_base_pfn(reg);
197-
unsigned long end_pfn = memblock_region_memory_end_pfn(reg);
198-
199-
memblock_set_node(PFN_PHYS(start_pfn),
200-
PFN_PHYS(end_pfn - start_pfn),
201-
&memblock.memory, 0);
202-
}
203-
}
204-
205133
void __init setup_arch(char **cmdline_p)
206134
{
207135
init_mm.start_code = (unsigned long) _stext;

arch/riscv/mm/init.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/initrd.h>
1818
#include <linux/swap.h>
1919
#include <linux/sizes.h>
20+
#include <linux/of_fdt.h>
2021

2122
#include <asm/tlbflush.h>
2223
#include <asm/sections.h>
@@ -66,7 +67,76 @@ void free_initmem(void)
6667
}
6768

6869
#ifdef CONFIG_BLK_DEV_INITRD
70+
static void __init setup_initrd(void)
71+
{
72+
unsigned long size;
73+
74+
if (initrd_start >= initrd_end) {
75+
pr_info("initrd not found or empty");
76+
goto disable;
77+
}
78+
if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
79+
pr_err("initrd extends beyond end of memory");
80+
goto disable;
81+
}
82+
83+
size = initrd_end - initrd_start;
84+
memblock_reserve(__pa(initrd_start), size);
85+
initrd_below_start_ok = 1;
86+
87+
pr_info("Initial ramdisk at: 0x%p (%lu bytes)\n",
88+
(void *)(initrd_start), size);
89+
return;
90+
disable:
91+
pr_cont(" - disabling initrd\n");
92+
initrd_start = 0;
93+
initrd_end = 0;
94+
}
95+
6996
void free_initrd_mem(unsigned long start, unsigned long end)
7097
{
7198
}
7299
#endif /* CONFIG_BLK_DEV_INITRD */
100+
101+
void __init setup_bootmem(void)
102+
{
103+
struct memblock_region *reg;
104+
phys_addr_t mem_size = 0;
105+
106+
/* Find the memory region containing the kernel */
107+
for_each_memblock(memory, reg) {
108+
phys_addr_t vmlinux_end = __pa(_end);
109+
phys_addr_t end = reg->base + reg->size;
110+
111+
if (reg->base <= vmlinux_end && vmlinux_end <= end) {
112+
/*
113+
* Reserve from the start of the region to the end of
114+
* the kernel
115+
*/
116+
memblock_reserve(reg->base, vmlinux_end - reg->base);
117+
mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET);
118+
}
119+
}
120+
BUG_ON(mem_size == 0);
121+
122+
set_max_mapnr(PFN_DOWN(mem_size));
123+
max_low_pfn = PFN_DOWN(memblock_end_of_DRAM());
124+
125+
#ifdef CONFIG_BLK_DEV_INITRD
126+
setup_initrd();
127+
#endif /* CONFIG_BLK_DEV_INITRD */
128+
129+
early_init_fdt_reserve_self();
130+
early_init_fdt_scan_reserved_mem();
131+
memblock_allow_resize();
132+
memblock_dump_all();
133+
134+
for_each_memblock(memory, reg) {
135+
unsigned long start_pfn = memblock_region_memory_base_pfn(reg);
136+
unsigned long end_pfn = memblock_region_memory_end_pfn(reg);
137+
138+
memblock_set_node(PFN_PHYS(start_pfn),
139+
PFN_PHYS(end_pfn - start_pfn),
140+
&memblock.memory, 0);
141+
}
142+
}

0 commit comments

Comments
 (0)