Skip to content

Commit 243f8de

Browse files
Ming Wangchenhuacai
authored andcommitted
LoongArch: Support mem=<size> kernel parameter
The LoongArch mem= parameter parser was previously limited to the mem=<size>@<start> format. This was inconvenient for the common use case of simply capping the total system memory, as it forced users to manually specify a start address. It was also inconsistent with the behavior on other architectures. This patch enhances the parser in early_parse_mem() to also support the more user-friendly mem=<size> format. The implementation now checks for the presence of the '@' symbol to determine the user's intent: - If mem=<size> is provided (no '@'), the kernel now calls memblock_enforce_memory_limit(). This trims memory from the top down to the specified size. - If mem=<size>@<start> is provided, the original behavior is retained for backward compatibility. This allows for defining specific memory banks. This change introduces an important usage rule reflected in the code's comments: the mem=<size> format should only be specified once on the kernel command line. It acts as a single, global cap on total memory. In contrast, the mem=<size>@<start> format can be specified multiple times to define several distinct memory regions. Signed-off-by: Ming Wang <wangming01@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent a1a81b5 commit 243f8de

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

arch/loongarch/kernel/setup.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ static int __init early_parse_mem(char *p)
191191
return -EINVAL;
192192
}
193193

194+
start = 0;
195+
size = memparse(p, &p);
196+
if (*p == '@') /* Every mem=... should contain '@' */
197+
start = memparse(p + 1, &p);
198+
else { /* Only one mem=... is allowed if no '@' */
199+
usermem = 1;
200+
memblock_enforce_memory_limit(size);
201+
return 0;
202+
}
203+
194204
/*
195205
* If a user specifies memory size, we
196206
* blow away any automatically generated
@@ -201,14 +211,6 @@ static int __init early_parse_mem(char *p)
201211
memblock_remove(memblock_start_of_DRAM(),
202212
memblock_end_of_DRAM() - memblock_start_of_DRAM());
203213
}
204-
start = 0;
205-
size = memparse(p, &p);
206-
if (*p == '@')
207-
start = memparse(p + 1, &p);
208-
else {
209-
pr_err("Invalid format!\n");
210-
return -EINVAL;
211-
}
212214

213215
if (!IS_ENABLED(CONFIG_NUMA))
214216
memblock_add(start, size);

0 commit comments

Comments
 (0)