We want to remove use of DeviceTree from EDK2. One of things EDK2 did was counting cpu cores. Now it gets that value via SMC call.
Change-Id: I1c7fc234ba90ba32433b6e4aa2cf127f26da00fd Signed-off-by: Marcin Juszkiewicz marcin.juszkiewicz@linaro.org --- plat/qemu/qemu_sbsa/sbsa_sip_svc.c | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/plat/qemu/qemu_sbsa/sbsa_sip_svc.c b/plat/qemu/qemu_sbsa/sbsa_sip_svc.c index 05ebec472..587048c33 100644 --- a/plat/qemu/qemu_sbsa/sbsa_sip_svc.c +++ b/plat/qemu/qemu_sbsa/sbsa_sip_svc.c @@ -28,8 +28,12 @@ static int platform_version_minor; #define SIP_SVC_VERSION SIP_FUNCTION_ID(1) #define SIP_SVC_GET_GIC SIP_FUNCTION_ID(100) #define SIP_SVC_GET_GIC_ITS SIP_FUNCTION_ID(101) +#define SIP_SVC_GET_CPU_COUNT SIP_FUNCTION_ID(200)
static uint64_t gic_its_addr; +static uint64_t cpu_count; +static uint64_t dt_first_cpu_node_offset; +static uint64_t dt_first_cpu_node_size;
void sbsa_set_gic_bases(const uintptr_t gicd_base, const uintptr_t gicr_base); uintptr_t sbsa_get_gicd(void); @@ -38,6 +42,7 @@ uintptr_t sbsa_get_gicr(void); void read_platform_config_from_dt(void *dtb) { int node; + int prev; const fdt64_t *data; int err; uintptr_t gicd_base; @@ -91,6 +96,43 @@ void read_platform_config_from_dt(void *dtb) return; } INFO("GICI base = 0x%lx\n", gic_its_addr); + + /* + * QEMU gives us this DeviceTree node: + * + * cpus { + * #size-cells = <0x00>; + * #address-cells = <0x02>; + * + * cpu@0 { + * reg = <0x00 0x00>; + * }; + * + * cpu@1 { + * reg = <0x00 0x01>; + * }; + * }; + */ + node = fdt_path_offset(dtb, "/cpus"); + if (node < 0) { + cpu_count = 1; /* We have at least one in case of missing entry in DT */ + INFO("No /cpus nodes. Found %lx cpus\n", cpu_count); + return; + } + + prev = fdt_first_subnode(dtb, node); + dt_first_cpu_node_offset = prev; + + while (1) { + cpu_count++; + node = fdt_next_subnode(dtb, prev); + if (node < 0) { + break; + } + dt_first_cpu_node_size = node - prev; + prev = node; + } + INFO("Found %lx cpus\n", cpu_count); }
void read_platform_version(void *dtb) @@ -163,6 +205,9 @@ uintptr_t sbsa_sip_smc_handler(uint32_t smc_fid, case SIP_SVC_GET_GIC_ITS: SMC_RET2(handle, NULL, gic_its_addr);
+ case SIP_SVC_GET_CPU_COUNT: + SMC_RET2(handle, NULL, cpu_count); + default: ERROR("%s: unhandled SMC (0x%x) (function id: %d)\n", __func__, smc_fid, smc_fid - SIP_FUNCTION);