Skip to content

Commit 2af2b50

Browse files
geerturobherring
authored andcommitted
of: fdt: Add generic support for handling usable memory range property
Add support for handling the "linux,usable-memory-range" property in the "/chosen" node to the FDT core code. This can co-exist safely with the architecture-specific handling, until the latter has been removed. Signed-off-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/3bd69bada93ee59b7d23c38b3527fc1654e19343.1628670468.git.geert+renesas@glider.be
1 parent f7e7ce9 commit 2af2b50

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Documentation/devicetree/bindings/chosen.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ a different secondary CPU release mechanism)
7979
linux,usable-memory-range
8080
-------------------------
8181

82-
This property (arm64 only) holds a base address and size, describing a
83-
limited region in which memory may be considered available for use by
84-
the kernel. Memory outside of this range is not available for use.
82+
This property holds a base address and size, describing a limited region in
83+
which memory may be considered available for use by the kernel. Memory outside
84+
of this range is not available for use.
8585

8686
This property describes a limitation: memory within this range is only
8787
valid when also described through another mechanism that the kernel

drivers/of/fdt.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,32 @@ static void __init early_init_dt_check_for_elfcorehdr(unsigned long node)
972972
elfcorehdr_addr, elfcorehdr_size);
973973
}
974974

975+
static phys_addr_t cap_mem_addr;
976+
static phys_addr_t cap_mem_size;
977+
978+
/**
979+
* early_init_dt_check_for_usable_mem_range - Decode usable memory range
980+
* location from flat tree
981+
* @node: reference to node containing usable memory range location ('chosen')
982+
*/
983+
static void __init early_init_dt_check_for_usable_mem_range(unsigned long node)
984+
{
985+
const __be32 *prop;
986+
int len;
987+
988+
pr_debug("Looking for usable-memory-range property... ");
989+
990+
prop = of_get_flat_dt_prop(node, "linux,usable-memory-range", &len);
991+
if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells)))
992+
return;
993+
994+
cap_mem_addr = dt_mem_next_cell(dt_root_addr_cells, &prop);
995+
cap_mem_size = dt_mem_next_cell(dt_root_size_cells, &prop);
996+
997+
pr_debug("cap_mem_start=%pa cap_mem_size=%pa\n", &cap_mem_addr,
998+
&cap_mem_size);
999+
}
1000+
9751001
#ifdef CONFIG_SERIAL_EARLYCON
9761002

9771003
int __init early_init_dt_scan_chosen_stdout(void)
@@ -1120,6 +1146,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
11201146

11211147
early_init_dt_check_for_initrd(node);
11221148
early_init_dt_check_for_elfcorehdr(node);
1149+
early_init_dt_check_for_usable_mem_range(node);
11231150

11241151
/* Retrieve command line */
11251152
p = of_get_flat_dt_prop(node, "bootargs", &l);
@@ -1253,6 +1280,9 @@ void __init early_init_dt_scan_nodes(void)
12531280

12541281
/* Setup memory, calling early_init_dt_add_memory_arch */
12551282
of_scan_flat_dt(early_init_dt_scan_memory, NULL);
1283+
1284+
/* Handle linux,usable-memory-range property */
1285+
memblock_cap_memory_range(cap_mem_addr, cap_mem_size);
12561286
}
12571287

12581288
bool __init early_init_dt_scan(void *params)

0 commit comments

Comments
 (0)