xref: /rk3399_ARM-atf/plat/allwinner/common/sunxi_prepare_dtb.c (revision 79808f10c32d441572666551b1545846079af15b)
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 
376fa8e72eSAndre Przywara 	ret = fdt_pack(fdt);
386fa8e72eSAndre Przywara 	if (ret < 0) {
396fa8e72eSAndre Przywara 		ERROR("Failed to pack devicetree at %p: error %d\n",
406fa8e72eSAndre Przywara 		      fdt, ret);
41*79808f10SSamuel Holland 	}
42*79808f10SSamuel Holland 
436fa8e72eSAndre Przywara 	clean_dcache_range((uintptr_t)fdt, fdt_blob_size(fdt));
446fa8e72eSAndre Przywara 	INFO("Changed devicetree.\n");
456fa8e72eSAndre Przywara }
46