summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorKefeng Wang <wangkefeng.wang@huawei.com>2021-06-02 11:55:17 +0300
committerPalmer Dabbelt <palmerdabbelt@google.com>2021-06-15 18:59:04 +0300
commitc9811e379b211c67ba29fb09d6f644dd44cfcff2 (patch)
tree934a861454ea1fa563314c5bb20196982f2907ca /arch
parentce3aca0465e31c20ada1270ac6547ba28b610ab2 (diff)
downloadlinux-c9811e379b211c67ba29fb09d6f644dd44cfcff2.tar.xz
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 <wangkefeng.wang@huawei.com> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/riscv/mm/init.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 30b204546ceb..3a5190a09987 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -123,19 +123,40 @@ void __init mem_init(void)
print_vm_layout();
}
+/*
+ * The default maximal physical memory size is -PAGE_OFFSET,
+ * limit the memory size via mem.
+ */
+static phys_addr_t memory_limit = -PAGE_OFFSET;
+
+static int __init early_mem(char *p)
+{
+ u64 size;
+
+ if (!p)
+ return 1;
+
+ size = memparse(p, &p) & PAGE_MASK;
+ memory_limit = min_t(u64, size, memory_limit);
+
+ pr_notice("Memory limited to %lldMB\n", (u64)memory_limit >> 20);
+
+ return 0;
+}
+early_param("mem", early_mem);
+
static void __init setup_bootmem(void)
{
phys_addr_t vmlinux_end = __pa_symbol(&_end);
phys_addr_t vmlinux_start = __pa_symbol(&_start);
- phys_addr_t dram_end = memblock_end_of_DRAM();
phys_addr_t max_mapped_addr = __pa(~(ulong)0);
+ phys_addr_t dram_end;
#ifdef CONFIG_XIP_KERNEL
vmlinux_start = __pa_symbol(&_sdata);
#endif
- /* The maximal physical memory size is -PAGE_OFFSET. */
- memblock_enforce_memory_limit(-PAGE_OFFSET);
+ memblock_enforce_memory_limit(memory_limit);
/*
* Reserve from the start of the kernel to the end of the kernel
@@ -150,6 +171,7 @@ static void __init setup_bootmem(void)
#endif
memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
+ dram_end = memblock_end_of_DRAM();
/*
* memblock allocator is not aware of the fact that last 4K bytes of
* the addressable memory can not be mapped because of IS_ERR_VALUE