xref: /linux/arch/riscv/kernel/pi/fdt_early.c (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/types.h>
3 #include <linux/init.h>
4 #include <linux/libfdt.h>
5 
6 /*
7  * Declare the functions that are exported (but prefixed) here so that LLVM
8  * does not complain it lacks the 'static' keyword (which, if added, makes
9  * LLVM complain because the function is actually unused in this file).
10  */
11 u64 get_kaslr_seed(uintptr_t dtb_pa);
12 
13 u64 get_kaslr_seed(uintptr_t dtb_pa)
14 {
15 	int node, len;
16 	fdt64_t *prop;
17 	u64 ret;
18 
19 	node = fdt_path_offset((void *)dtb_pa, "/chosen");
20 	if (node < 0)
21 		return 0;
22 
23 	prop = fdt_getprop_w((void *)dtb_pa, node, "kaslr-seed", &len);
24 	if (!prop || len != sizeof(u64))
25 		return 0;
26 
27 	ret = fdt64_to_cpu(*prop);
28 	*prop = 0;
29 	return ret;
30 }
31