Amit Nagal | 3a7d304 | 2023-07-10 10:32:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Advanced Micro Devices, Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
Akshay Belsare | e3f2a10 | 2023-07-19 10:07:50 +0530 | [diff] [blame] | 7 | #include <common/debug.h> |
Amit Nagal | 3a7d304 | 2023-07-10 10:32:15 +0530 | [diff] [blame] | 8 | #include <common/fdt_fixup.h> |
| 9 | #include <common/fdt_wrappers.h> |
Akshay Belsare | e3f2a10 | 2023-07-19 10:07:50 +0530 | [diff] [blame] | 10 | #include <libfdt.h> |
Amit Nagal | 3a7d304 | 2023-07-10 10:32:15 +0530 | [diff] [blame] | 11 | |
| 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)) |
| 16 | void 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 |
| 49 | void prepare_dtb(void) |
| 50 | { |
| 51 | } |
| 52 | #endif |