blob: 3d12d51592e0765f2886734ad3a4c1f95ad9f0a4 [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 */
7#include <common/fdt_fixup.h>
8#include <common/fdt_wrappers.h>
9
10#include <plat_fdt.h>
11#include <platform_def.h>
12
13#if (defined(XILINX_OF_BOARD_DTB_ADDR) && !IS_TFA_IN_OCM(BL31_BASE))
14void prepare_dtb(void)
15{
16 void *dtb = (void *)XILINX_OF_BOARD_DTB_ADDR;
17 int ret;
18
19 /* Return if no device tree is detected */
20 if (fdt_check_header(dtb) != 0) {
21 NOTICE("Can't read DT at %p\n", dtb);
22 return;
23 }
24
25 ret = fdt_open_into(dtb, dtb, XILINX_OF_BOARD_DTB_MAX_SIZE);
26 if (ret < 0) {
27 ERROR("Invalid Device Tree at %p: error %d\n", dtb, ret);
28 return;
29 }
30
31 /* Reserve memory used by Trusted Firmware. */
32 if (fdt_add_reserved_memory(dtb, "tf-a", BL31_BASE, BL31_LIMIT - BL31_BASE + 1)) {
33 WARN("Failed to add reserved memory nodes for BL31 to DT.\n");
34 return;
35 }
36
37 ret = fdt_pack(dtb);
38 if (ret < 0) {
39 ERROR("Failed to pack Device Tree at %p: error %d\n", dtb, ret);
40 return;
41 }
42
43 clean_dcache_range((uintptr_t)dtb, fdt_blob_size(dtb));
44 INFO("Changed device tree to advertise PSCI and reserved memories.\n");
45}
46#else
47void prepare_dtb(void)
48{
49}
50#endif