sunxi_prepare_dtb.c 1.1 KB

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