2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
10 #include "qemu_private.h"
13 static int append_psci_compatible(void *fdt
, int offs
, const char *str
)
15 return fdt_appendprop(fdt
, offs
, "compatible", str
, strlen(str
) + 1);
18 int dt_add_psci_node(void *fdt
)
22 if (fdt_path_offset(fdt
, "/psci") >= 0) {
23 WARN("PSCI Device Tree node already exists!\n");
27 offs
= fdt_path_offset(fdt
, "/");
30 offs
= fdt_add_subnode(fdt
, offs
, "psci");
33 if (append_psci_compatible(fdt
, offs
, "arm,psci-1.0"))
35 if (append_psci_compatible(fdt
, offs
, "arm,psci-0.2"))
37 if (append_psci_compatible(fdt
, offs
, "arm,psci"))
39 if (fdt_setprop_string(fdt
, offs
, "method", "smc"))
41 if (fdt_setprop_u32(fdt
, offs
, "cpu_suspend", PSCI_CPU_SUSPEND_AARCH64
))
43 if (fdt_setprop_u32(fdt
, offs
, "cpu_off", PSCI_CPU_OFF
))
45 if (fdt_setprop_u32(fdt
, offs
, "cpu_on", PSCI_CPU_ON_AARCH64
))
47 if (fdt_setprop_u32(fdt
, offs
, "sys_poweroff", PSCI_SYSTEM_OFF
))
49 if (fdt_setprop_u32(fdt
, offs
, "sys_reset", PSCI_SYSTEM_RESET
))
54 static int check_node_compat_prefix(void *fdt
, int offs
, const char *prefix
)
56 const size_t prefix_len
= strlen(prefix
);
61 prop
= fdt_getprop(fdt
, offs
, "compatible", &plen
);
66 if (memcmp(prop
, prefix
, prefix_len
) == 0)
77 int dt_add_psci_cpu_enable_methods(void *fdt
)
82 offs
= fdt_next_node(fdt
, offs
, NULL
);
85 if (fdt_getprop(fdt
, offs
, "enable-method", NULL
))
86 continue; /* already set */
87 if (check_node_compat_prefix(fdt
, offs
, "arm,cortex-a"))
88 continue; /* no compatible */
89 if (fdt_setprop_string(fdt
, offs
, "enable-method", "psci"))
91 /* Need to restart scanning as offsets may have changed */