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 | |
Amit Nagal | 3a7d304 | 2023-07-10 10:32:15 +0530 | [diff] [blame] | 15 | void prepare_dtb(void) |
| 16 | { |
Amit Nagal | 659c6aa | 2023-08-29 02:44:59 -1200 | [diff] [blame] | 17 | void *dtb; |
Amit Nagal | 3a7d304 | 2023-07-10 10:32:15 +0530 | [diff] [blame] | 18 | int ret; |
Amit Nagal | 659c6aa | 2023-08-29 02:44:59 -1200 | [diff] [blame] | 19 | #if !defined(XILINX_OF_BOARD_DTB_ADDR) |
| 20 | return; |
| 21 | #else |
| 22 | dtb = (void *)XILINX_OF_BOARD_DTB_ADDR; |
| 23 | #endif |
| 24 | if (IS_TFA_IN_OCM(BL31_BASE)) |
| 25 | return; |
Amit Nagal | 3a7d304 | 2023-07-10 10:32:15 +0530 | [diff] [blame] | 26 | |
| 27 | /* Return if no device tree is detected */ |
| 28 | if (fdt_check_header(dtb) != 0) { |
| 29 | NOTICE("Can't read DT at %p\n", dtb); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | ret = fdt_open_into(dtb, dtb, XILINX_OF_BOARD_DTB_MAX_SIZE); |
| 34 | if (ret < 0) { |
| 35 | ERROR("Invalid Device Tree at %p: error %d\n", dtb, ret); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | /* Reserve memory used by Trusted Firmware. */ |
Michal Simek | 53be5f6 | 2023-09-05 12:26:44 +0200 | [diff] [blame] | 40 | if (fdt_add_reserved_memory(dtb, "tf-a", BL31_BASE, BL31_LIMIT - BL31_BASE)) { |
Amit Nagal | 3a7d304 | 2023-07-10 10:32:15 +0530 | [diff] [blame] | 41 | WARN("Failed to add reserved memory nodes for BL31 to DT.\n"); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | ret = fdt_pack(dtb); |
| 46 | if (ret < 0) { |
| 47 | ERROR("Failed to pack Device Tree at %p: error %d\n", dtb, ret); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | clean_dcache_range((uintptr_t)dtb, fdt_blob_size(dtb)); |
| 52 | INFO("Changed device tree to advertise PSCI and reserved memories.\n"); |
| 53 | } |