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 | } |
Andre Przywara | 9de1222 | 2021-12-19 13:39:40 +0000 | [diff] [blame] | 22 | |
| 23 | ret = fdt_open_into(fdt, fdt, 0x10000); |
Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 24 | if (ret < 0) { |
| 25 | ERROR("Preparing devicetree at %p: error %d\n", fdt, ret); |
| 26 | return; |
| 27 | } |
| 28 | |
Andre Przywara | 9de1222 | 2021-12-19 13:39:40 +0000 | [diff] [blame] | 29 | #ifdef SUNXI_BL31_IN_DRAM |
Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 30 | /* Reserve memory used by Trusted Firmware. */ |
| 31 | if (fdt_add_reserved_memory(fdt, "tf-a@40000000", BL31_BASE, |
| 32 | BL31_LIMIT - BL31_BASE)) { |
| 33 | WARN("Failed to add reserved memory nodes to DT.\n"); |
Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 34 | } |
Andre Przywara | 9de1222 | 2021-12-19 13:39:40 +0000 | [diff] [blame] | 35 | #endif |
Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 36 | |
Samuel Holland | 365966c | 2022-01-22 23:37:12 -0600 | [diff] [blame] | 37 | if (sunxi_psci_is_scpi()) { |
| 38 | ret = fdt_add_cpu_idle_states(fdt, sunxi_idle_states); |
| 39 | if (ret < 0) { |
| 40 | WARN("Failed to add idle states to DT: %d\n", ret); |
| 41 | } |
| 42 | } |
| 43 | |
Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 44 | ret = fdt_pack(fdt); |
| 45 | if (ret < 0) { |
| 46 | ERROR("Failed to pack devicetree at %p: error %d\n", |
| 47 | fdt, ret); |
Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 48 | } |
Samuel Holland | 60fcf32 | 2022-01-23 16:30:08 -0600 | [diff] [blame] | 49 | |
| 50 | clean_dcache_range((uintptr_t)fdt, fdt_blob_size(fdt)); |
| 51 | INFO("Changed devicetree.\n"); |
Andre Przywara | fb83833 | 2020-12-14 12:06:24 +0000 | [diff] [blame] | 52 | } |