Skip to content

Commit 892de8d

Browse files
committed
lk2nd: smp: refactor fdt functions
Signed-off-by: Eugene Lepshy <fekz115@gmail.com>
1 parent 2600184 commit 892de8d

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

lk2nd/smp/cpu-boot.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,48 @@ static inline uint32_t read_mpidr(void)
4444
return BITS(res, 23, 0);
4545
}
4646

47-
static uint32_t read_phandle_reg(const void *dtb, int node, const char *prop)
47+
static uint32_t read_phandle_value_indexed(const void *dtb, int node,
48+
const char *name, int index)
49+
{
50+
const fdt32_t *val;
51+
int len;
52+
53+
val = fdt_getprop(dtb, node, name, &len);
54+
if (len < (int)sizeof(*val)) {
55+
dprintf(CRITICAL, "Cannot read %s property of node: %d\n",
56+
name, len);
57+
return 0;
58+
}
59+
return fdt32_to_cpu(*(val + index));
60+
}
61+
62+
static uint32_t read_phandle_reg_indexed(const void *dtb, int node,
63+
const char *prop, int index)
4864
{
4965
const fdt32_t *val;
50-
int target, len;
66+
/*
67+
* used_index is index multiplied by 2 because we want to use the first
68+
* value from the second tuple, not the second value from the first tuple
69+
*/
70+
int target, len, used_index = index * 2;
5171

5272
target = lkfdt_lookup_phandle(dtb, node, prop);
5373
if (target < 0) {
5474
dprintf(CRITICAL, "Cannot find %s node in %s: %d\n",
5575
prop, fdt_get_name(dtb, node, NULL), target);
5676
return 0;
5777
}
78+
return read_phandle_value_indexed(dtb, target, "reg", used_index);
79+
}
5880

59-
val = fdt_getprop(dtb, target, "reg", &len);
60-
if (len < (int)sizeof(*val)) {
61-
dprintf(CRITICAL, "Cannot read reg property of %s node: %d\n",
62-
prop, len);
63-
return 0;
64-
}
65-
return fdt32_to_cpu(*val);
81+
static uint32_t read_phandle_value(const void *dtb, int node, const char *name)
82+
{
83+
return read_phandle_value_indexed(dtb, node, name, 0);
84+
}
85+
86+
static uint32_t read_phandle_reg(const void *dtb, int node, const char *prop)
87+
{
88+
return read_phandle_reg_indexed(dtb, node, prop, 0);
6689
}
6790

6891
bool cpu_boot(const void *dtb, int node, uint32_t mpidr)

0 commit comments

Comments
 (0)