[rtems commit] bsps/riscv: Fix riscv_get_hart_index_by_phandle()

Sebastian Huber sebh at rtems.org
Fri Mar 17 06:08:32 UTC 2023


Module:    rtems
Branch:    master
Commit:    cbddf5decd7b6128c4b0c59aa9c0669434ff396e
Changeset: http://git.rtems.org/rtems/commit/?id=cbddf5decd7b6128c4b0c59aa9c0669434ff396e

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Mar 15 14:31:20 2023 +0100

bsps/riscv: Fix riscv_get_hart_index_by_phandle()

Take a non-zero RISCV_BOOT_HARTID into account.

---

 bsps/riscv/riscv/start/bspsmp.c   |  2 +-
 bsps/riscv/riscv/start/bspstart.c | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/bsps/riscv/riscv/start/bspsmp.c b/bsps/riscv/riscv/start/bspsmp.c
index ce5792f5b8..34796a5120 100644
--- a/bsps/riscv/riscv/start/bspsmp.c
+++ b/bsps/riscv/riscv/start/bspsmp.c
@@ -46,7 +46,7 @@ void bsp_start_on_secondary_processor(Per_CPU_Control *cpu_self)
 
 uint32_t _CPU_SMP_Initialize(void)
 {
-  return riscv_hart_count - RISCV_BOOT_HARTID;
+  return riscv_hart_count;
 }
 
 bool _CPU_SMP_Start_processor(uint32_t cpu_index)
diff --git a/bsps/riscv/riscv/start/bspstart.c b/bsps/riscv/riscv/start/bspstart.c
index 30d479ce88..f27713b5bf 100644
--- a/bsps/riscv/riscv/start/bspstart.c
+++ b/bsps/riscv/riscv/start/bspstart.c
@@ -111,6 +111,14 @@ static void riscv_find_harts(void)
 
     hart_index = fdt32_to_cpu(val[0]);
 
+#if RISCV_BOOT_HARTID != 0
+    if (hart_index < RISCV_BOOT_HARTID) {
+      continue;
+    }
+
+    hart_index -= RISCV_BOOT_HARTID;
+#endif
+
     if (hart_index >= RTEMS_ARRAY_SIZE(riscv_hart_phandles)) {
       continue;
     }
@@ -166,7 +174,7 @@ uint32_t riscv_get_hart_index_by_phandle(uint32_t phandle)
 
   for (hart_index = 0; hart_index < riscv_hart_count; ++hart_index) {
     if (riscv_hart_phandles[hart_index] == phandle) {
-      return hart_index;
+      return hart_index + RISCV_BOOT_HARTID;
     }
   }
 



More information about the vc mailing list