blob: dc3e893009aa37181eafce8118968ccea838a92f [file] [log] [blame]
Amit Nagal3a7d3042023-07-10 10:32:15 +05301/*
2 * Copyright (c) 2023, Advanced Micro Devices, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
Akshay Belsaree3f2a102023-07-19 10:07:50 +05307#include <common/debug.h>
Amit Nagal3a7d3042023-07-10 10:32:15 +05308#include <common/fdt_fixup.h>
9#include <common/fdt_wrappers.h>
Akshay Belsaree3f2a102023-07-19 10:07:50 +053010#include <libfdt.h>
Amit Nagal3a7d3042023-07-10 10:32:15 +053011
12#include <plat_fdt.h>
13#include <platform_def.h>
14
15#if (defined(XILINX_OF_BOARD_DTB_ADDR) && !IS_TFA_IN_OCM(BL31_BASE))
16void prepare_dtb(void)
17{
18 void *dtb = (void *)XILINX_OF_BOARD_DTB_ADDR;
19 int ret;
20
21 /* Return if no device tree is detected */
22 if (fdt_check_header(dtb) != 0) {
23 NOTICE("Can't read DT at %p\n", dtb);
24 return;
25 }
26
27 ret = fdt_open_into(dtb, dtb, XILINX_OF_BOARD_DTB_MAX_SIZE);
28 if (ret < 0) {
29 ERROR("Invalid Device Tree at %p: error %d\n", dtb, ret);
30 return;
31 }
32
33 /* Reserve memory used by Trusted Firmware. */
34 if (fdt_add_reserved_memory(dtb, "tf-a", BL31_BASE, BL31_LIMIT - BL31_BASE + 1)) {
35 WARN("Failed to add reserved memory nodes for BL31 to DT.\n");
36 return;
37 }
38
39 ret = fdt_pack(dtb);
40 if (ret < 0) {
41 ERROR("Failed to pack Device Tree at %p: error %d\n", dtb, ret);
42 return;
43 }
44
45 clean_dcache_range((uintptr_t)dtb, fdt_blob_size(dtb));
46 INFO("Changed device tree to advertise PSCI and reserved memories.\n");
47}
48#else
49void prepare_dtb(void)
50{
51}
52#endif