Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, ARM Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <libfdt.h> |
| 8 | |
| 9 | #include <common/debug.h> |
| 10 | #include <common/fdt_fixup.h> |
| 11 | #include <common/fdt_wrappers.h> |
| 12 | |
| 13 | #include <sunxi_private.h> |
| 14 | |
| 15 | void sunxi_prepare_dtb(void *fdt) |
| 16 | { |
| 17 | int ret; |
| 18 | |
| 19 | if (fdt == NULL || fdt_check_header(fdt) != 0) { |
| 20 | return; |
| 21 | } |
| 22 | ret = fdt_open_into(fdt, fdt, 0x100000); |
| 23 | if (ret < 0) { |
| 24 | ERROR("Preparing devicetree at %p: error %d\n", fdt, ret); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | /* Reserve memory used by Trusted Firmware. */ |
| 29 | if (fdt_add_reserved_memory(fdt, "tf-a@40000000", BL31_BASE, |
| 30 | BL31_LIMIT - BL31_BASE)) { |
| 31 | WARN("Failed to add reserved memory nodes to DT.\n"); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | ret = fdt_pack(fdt); |
| 36 | if (ret < 0) { |
| 37 | ERROR("Failed to pack devicetree at %p: error %d\n", |
| 38 | fdt, ret); |
| 39 | } else { |
| 40 | clean_dcache_range((uintptr_t)fdt, fdt_blob_size(fdt)); |
| 41 | INFO("Changed devicetree to reserve BL31 memory.\n"); |
| 42 | } |
| 43 | } |