Skip to content

Commit c9811e3

Browse files
Kefeng Wangpalmer-dabbelt
Kefeng Wang
authored andcommitted
riscv: Add mem kernel parameter support
The memblock_enforce_memory_limit() could change the memblock range, so move the dram_end assignment after it in bootmem_init(), then support mem= cmdline. Signed-off-by: Kefeng Wang <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent ce3aca0 commit c9811e3

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

arch/riscv/mm/init.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,40 @@ void __init mem_init(void)
123123
print_vm_layout();
124124
}
125125

126+
/*
127+
* The default maximal physical memory size is -PAGE_OFFSET,
128+
* limit the memory size via mem.
129+
*/
130+
static phys_addr_t memory_limit = -PAGE_OFFSET;
131+
132+
static int __init early_mem(char *p)
133+
{
134+
u64 size;
135+
136+
if (!p)
137+
return 1;
138+
139+
size = memparse(p, &p) & PAGE_MASK;
140+
memory_limit = min_t(u64, size, memory_limit);
141+
142+
pr_notice("Memory limited to %lldMB\n", (u64)memory_limit >> 20);
143+
144+
return 0;
145+
}
146+
early_param("mem", early_mem);
147+
126148
static void __init setup_bootmem(void)
127149
{
128150
phys_addr_t vmlinux_end = __pa_symbol(&_end);
129151
phys_addr_t vmlinux_start = __pa_symbol(&_start);
130-
phys_addr_t dram_end = memblock_end_of_DRAM();
131152
phys_addr_t max_mapped_addr = __pa(~(ulong)0);
153+
phys_addr_t dram_end;
132154

133155
#ifdef CONFIG_XIP_KERNEL
134156
vmlinux_start = __pa_symbol(&_sdata);
135157
#endif
136158

137-
/* The maximal physical memory size is -PAGE_OFFSET. */
138-
memblock_enforce_memory_limit(-PAGE_OFFSET);
159+
memblock_enforce_memory_limit(memory_limit);
139160

140161
/*
141162
* Reserve from the start of the kernel to the end of the kernel
@@ -150,6 +171,7 @@ static void __init setup_bootmem(void)
150171
#endif
151172
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
152173

174+
dram_end = memblock_end_of_DRAM();
153175
/*
154176
* memblock allocator is not aware of the fact that last 4K bytes of
155177
* the addressable memory can not be mapped because of IS_ERR_VALUE

0 commit comments

Comments
 (0)