Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: cmdline: Add support for 'memmap' parameter

Implement support for parsing 'memmap' kernel command line parameter.

This patch covers parsing of the following two formats for 'memmap'
parameter values:

- nn[KMG]@ss[KMG]
- nn[KMG]$ss[KMG]

([KMG] = K M or G (kilo, mega, giga))

These two allowed formats for parameter value are already documented
in file kernel-parameters.txt in Documentation/admin-guide folder.
Some architectures already support them, but Mips did not prior to
this patch.

Excerpt from Documentation/admin-guide/kernel-parameters.txt:

memmap=nn[KMG]@ss[KMG]
[KNL] Force usage of a specific region of memory.
Region of memory to be used is from ss to ss+nn.

memmap=nn[KMG]$ss[KMG]
Mark specific memory as reserved.
Region of memory to be reserved is from ss to ss+nn.
Example: Exclude memory from 0x18690000-0x1869ffff
memmap=64K$0x18690000
or
memmap=0x10000$0x18690000

There is no need to update this documentation file with respect to
this patch.

Signed-off-by: Miodrag Dinic <miodrag.dinic@imgtec.com>
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com>
Cc: James.Hogan@imgtec.com
Cc: Paul.Burton@imgtec.com
Cc: Raghu.Gandham@imgtec.com
Cc: Leonid.Yegoshin@imgtec.com
Cc: Douglas.Leung@imgtec.com
Cc: Petar.Jovanovic@imgtec.com
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/16508/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Miodrag Dinic and committed by
Ralf Baechle
296a7624 b9c4dc2c

+40
+40
arch/mips/kernel/setup.c
··· 670 670 } 671 671 early_param("mem", early_parse_mem); 672 672 673 + static int __init early_parse_memmap(char *p) 674 + { 675 + char *oldp; 676 + u64 start_at, mem_size; 677 + 678 + if (!p) 679 + return -EINVAL; 680 + 681 + if (!strncmp(p, "exactmap", 8)) { 682 + pr_err("\"memmap=exactmap\" invalid on MIPS\n"); 683 + return 0; 684 + } 685 + 686 + oldp = p; 687 + mem_size = memparse(p, &p); 688 + if (p == oldp) 689 + return -EINVAL; 690 + 691 + if (*p == '@') { 692 + start_at = memparse(p+1, &p); 693 + add_memory_region(start_at, mem_size, BOOT_MEM_RAM); 694 + } else if (*p == '#') { 695 + pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n"); 696 + return -EINVAL; 697 + } else if (*p == '$') { 698 + start_at = memparse(p+1, &p); 699 + add_memory_region(start_at, mem_size, BOOT_MEM_RESERVED); 700 + } else { 701 + pr_err("\"memmap\" invalid format!\n"); 702 + return -EINVAL; 703 + } 704 + 705 + if (*p == '\0') { 706 + usermem = 1; 707 + return 0; 708 + } else 709 + return -EINVAL; 710 + } 711 + early_param("memmap", early_parse_memmap); 712 + 673 713 #ifdef CONFIG_PROC_VMCORE 674 714 unsigned long setup_elfcorehdr, setup_elfcorehdr_size; 675 715 static int __init early_parse_elfcorehdr(char *p)