16fa8e72eSAndre Przywara /* 26fa8e72eSAndre Przywara * Copyright (c) 2021, ARM Limited. All rights reserved. 36fa8e72eSAndre Przywara * 46fa8e72eSAndre Przywara * SPDX-License-Identifier: BSD-3-Clause 56fa8e72eSAndre Przywara */ 66fa8e72eSAndre Przywara 76fa8e72eSAndre Przywara #include <libfdt.h> 86fa8e72eSAndre Przywara 96fa8e72eSAndre Przywara #include <common/debug.h> 106fa8e72eSAndre Przywara #include <common/fdt_fixup.h> 116fa8e72eSAndre Przywara #include <common/fdt_wrappers.h> 126fa8e72eSAndre Przywara 136fa8e72eSAndre Przywara #include <sunxi_private.h> 146fa8e72eSAndre Przywara 156fa8e72eSAndre Przywara void sunxi_prepare_dtb(void *fdt) 166fa8e72eSAndre Przywara { 176fa8e72eSAndre Przywara int ret; 186fa8e72eSAndre Przywara 196fa8e72eSAndre Przywara if (fdt == NULL || fdt_check_header(fdt) != 0) { 206fa8e72eSAndre Przywara return; 216fa8e72eSAndre Przywara } 226fa8e72eSAndre Przywara 236fa8e72eSAndre Przywara ret = fdt_open_into(fdt, fdt, 0x10000); 246fa8e72eSAndre Przywara if (ret < 0) { 256fa8e72eSAndre Przywara ERROR("Preparing devicetree at %p: error %d\n", fdt, ret); 266fa8e72eSAndre Przywara return; 276fa8e72eSAndre Przywara } 286fa8e72eSAndre Przywara 296fa8e72eSAndre Przywara #ifdef SUNXI_BL31_IN_DRAM 306fa8e72eSAndre Przywara /* Reserve memory used by Trusted Firmware. */ 316fa8e72eSAndre Przywara if (fdt_add_reserved_memory(fdt, "tf-a@40000000", BL31_BASE, 326fa8e72eSAndre Przywara BL31_LIMIT - BL31_BASE)) { 336fa8e72eSAndre Przywara WARN("Failed to add reserved memory nodes to DT.\n"); 346fa8e72eSAndre Przywara } 356fa8e72eSAndre Przywara #endif 366fa8e72eSAndre Przywara 37*ee5b26fdSAndre Przywara sunxi_soc_fdt_fixup(fdt); 38*ee5b26fdSAndre Przywara 39e2b18771SSamuel Holland if (sunxi_psci_is_scpi()) { 40e2b18771SSamuel Holland ret = fdt_add_cpu_idle_states(fdt, sunxi_idle_states); 41e2b18771SSamuel Holland if (ret < 0) { 42e2b18771SSamuel Holland WARN("Failed to add idle states to DT: %d\n", ret); 43e2b18771SSamuel Holland } 44e2b18771SSamuel Holland } 45e2b18771SSamuel Holland 466fa8e72eSAndre Przywara ret = fdt_pack(fdt); 476fa8e72eSAndre Przywara if (ret < 0) { 486fa8e72eSAndre Przywara ERROR("Failed to pack devicetree at %p: error %d\n", 496fa8e72eSAndre Przywara fdt, ret); 5079808f10SSamuel Holland } 5179808f10SSamuel Holland 526fa8e72eSAndre Przywara clean_dcache_range((uintptr_t)fdt, fdt_blob_size(fdt)); 536fa8e72eSAndre Przywara INFO("Changed devicetree.\n"); 546fa8e72eSAndre Przywara } 55