]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
feat(ethos-n): add reserved memory address support
authorMikael Olsson <mikael.olsson@arm.com>
Fri, 10 Feb 2023 10:39:40 +0000 (11:39 +0100)
committerJoanna Farley <joanna.farley@arm.com>
Tue, 4 Apr 2023 09:37:37 +0000 (11:37 +0200)
The FCONF parsing of the HW_CONFIG for the Arm(R) Ethos(TM)-N NPU now
supports reading the address of the reserved memory setup for the NPU so
the address can be used in the SiP service for the NPU.

Change-Id: I0968255a966e84896b00ea935d6aa3d5232c5f7b
Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
include/plat/arm/common/fconf_ethosn_getter.h
plat/arm/common/fconf/fconf_ethosn_getter.c

index 5b9a7ed9d05c5d63ee1ea4b5cd333286b29d3516..cafbc3efa04b8f0b913c67ba4f9f2fbecc14f671 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -45,6 +45,7 @@ struct ethosn_core_t {
 
 struct ethosn_device_t {
        bool has_reserved_memory;
+       uint64_t reserved_memory_addr;
        uint32_t num_cores;
        struct ethosn_core_t cores[ETHOSN_DEV_CORE_NUM_MAX];
        uint32_t num_allocators;
index 251471e63b6ae313b4260c6258a44d4baecb4e54..7394e4241269ce75ceb5d670ca6369c579f01bc7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -20,6 +20,38 @@ struct ethosn_sub_allocator_t {
        uint32_t stream_id;
 };
 
+static int fdt_node_read_reserved_memory_addr(const void *fdt,
+                                             int dev_node,
+                                             uint64_t *reserved_mem_addrs)
+{
+       uintptr_t addr;
+       uint32_t phandle;
+       int err;
+       int mem_node;
+
+       err = fdt_read_uint32(fdt, dev_node, "memory-region", &phandle);
+       if (err != 0) {
+               ERROR("FCONF: Failed to get reserved memory phandle\n");
+               return err;
+       }
+
+       mem_node = fdt_node_offset_by_phandle(fdt, phandle);
+       if (mem_node < 0) {
+               ERROR("FCONF: Failed to find reserved memory node from phandle\n");
+               return mem_node;
+       }
+
+       err = fdt_get_reg_props_by_index(fdt, mem_node, 0U, &addr, NULL);
+       if (err != 0) {
+               ERROR("FCONF: Failed to read reserved memory address\n");
+               return err;
+       }
+
+       *reserved_mem_addrs = addr;
+
+       return 0;
+}
+
 static bool fdt_node_has_reserved_memory(const void *fdt, int dev_node)
 {
        return fdt_get_property(fdt, dev_node, "memory-region", NULL) != NULL;
@@ -233,8 +265,10 @@ int fconf_populate_ethosn_config(uintptr_t config)
                struct ethosn_device_t *dev = &ethosn_config.devices[dev_count];
                uint32_t dev_asset_alloc_count = 0U;
                uint32_t dev_core_count = 0U;
+               uint64_t reserved_memory_addr = 0U;
                bool has_reserved_memory;
                int sub_node;
+               int err;
 
                if (!fdt_node_is_enabled(hw_conf_dtb, ethosn_node)) {
                        continue;
@@ -246,8 +280,16 @@ int fconf_populate_ethosn_config(uintptr_t config)
                }
 
                has_reserved_memory = fdt_node_has_reserved_memory(hw_conf_dtb, ethosn_node);
+               if (has_reserved_memory) {
+                       err = fdt_node_read_reserved_memory_addr(hw_conf_dtb,
+                                                                ethosn_node,
+                                                                &reserved_memory_addr);
+                       if (err != 0) {
+                               return err;
+                       }
+               }
+
                fdt_for_each_subnode(sub_node, hw_conf_dtb, ethosn_node) {
-                       int err;
 
                        if (!fdt_node_is_enabled(hw_conf_dtb, sub_node)) {
                                /* Ignore disabled sub node */
@@ -323,6 +365,7 @@ int fconf_populate_ethosn_config(uintptr_t config)
                dev->num_cores = dev_core_count;
                dev->num_allocators = dev_asset_alloc_count;
                dev->has_reserved_memory = has_reserved_memory;
+               dev->reserved_memory_addr = reserved_memory_addr;
                ++dev_count;
        }