From: Andre Przywara Date: Thu, 11 Jul 2019 00:45:39 +0000 (+0100) Subject: rpi4: Amend DTB to advertise PSCI X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f67fa69cb6937a7fc559bbec4a7acce5edefa888;p=project%2Fbcm63xx%2Fatf.git rpi4: Amend DTB to advertise PSCI The device tree provided by the official Raspberry Pi firmware uses spin tables for SMP bringup. One of the benefit of having TF-A is that it provides PSCI services, so let's rewrite the DTB to advertise PSCI instead of spin tables. This uses the (newly exported) routine from the QEMU platform port. Change-Id: Ifddcb14041ca253a333f8c2d5e97a42db152470c Signed-off-by: Andre Przywara --- diff --git a/plat/rpi/rpi4/platform.mk b/plat/rpi/rpi4/platform.mk index 6ac21691..2038021a 100644 --- a/plat/rpi/rpi4/platform.mk +++ b/plat/rpi/rpi4/platform.mk @@ -25,6 +25,7 @@ BL31_SOURCES += lib/cpus/aarch64/cortex_a72.S \ plat/rpi/common/rpi3_pm.c \ plat/common/plat_psci_common.c \ plat/rpi/common/rpi3_topology.c \ + common/fdt_fixup.c \ ${LIBFDT_SRCS} # For now we only support BL31, using the kernel loaded by the GPU firmware. diff --git a/plat/rpi/rpi4/rpi4_bl31_setup.c b/plat/rpi/rpi4/rpi4_bl31_setup.c index f5f74bdd..e1b6c897 100644 --- a/plat/rpi/rpi4/rpi4_bl31_setup.c +++ b/plat/rpi/rpi4/rpi4_bl31_setup.c @@ -9,12 +9,15 @@ #include #include +#include #include #include #include #include #include #include +#include +#include #include @@ -179,6 +182,18 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, void bl31_plat_arch_setup(void) { + /* + * Is the dtb_ptr32 pointer valid? If yes, map the DTB region. + * We map the 2MB region the DTB start address lives in, plus + * the next 2MB, to have enough room for expansion. + */ + if (stub_magic == 0) { + unsigned long long dtb_region = dtb_ptr32; + + dtb_region &= ~0x1fffff; /* Align to 2 MB. */ + mmap_add_region(dtb_region, dtb_region, 4U << 20, + MT_MEMORY | MT_RW | MT_NS); + } /* * Add the first page of memory, which holds the stub magic, * the kernel and the DT address. @@ -198,8 +213,50 @@ void bl31_plat_arch_setup(void) enable_mmu_el3(0); } +static uint32_t dtb_size(const void *dtb) +{ + const uint32_t *dtb_header = dtb; + + return fdt32_to_cpu(dtb_header[1]); +} + +static void rpi4_prepare_dtb(void) +{ + void *dtb = (void *)rpi4_get_dtb_address(); + int ret; + + /* Return if no device tree is detected */ + if (fdt_check_header(dtb) != 0) + return; + + ret = fdt_open_into(dtb, dtb, 0x100000); + if (ret < 0) { + ERROR("Invalid Device Tree at %p: error %d\n", dtb, ret); + return; + } + + if (dt_add_psci_node(dtb)) { + ERROR("Failed to add PSCI Device Tree node\n"); + return; + } + + if (dt_add_psci_cpu_enable_methods(dtb)) { + ERROR("Failed to add PSCI cpu enable methods in Device Tree\n"); + return; + } + + ret = fdt_pack(dtb); + if (ret < 0) + ERROR("Failed to pack Device Tree at %p: error %d\n", dtb, ret); + + clean_dcache_range((uintptr_t)dtb, dtb_size(dtb)); + INFO("Changed device tree to advertise PSCI.\n"); +} + void bl31_platform_setup(void) { + rpi4_prepare_dtb(); + /* Configure the interrupt controller */ gicv2_driver_init(&rpi4_gic_data); gicv2_distif_init();