Skip to contentSkip to conversation

lib: utils: Fix sbi_hartid_to_scratch() usage in ACLINT drivers

PATCH New Anup Patel 3 participants 3 messages Jul 5, 2023 – Jul 9, 2023

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 lib: utils: Fix sbi_hartid_to_scratch() usage in ACLINT drivers

The cold_init() functions of ACLINT drivers should skip the HART is sbi_hartid_to_scratch() returns NULL because we might be dealing with a HART that is disabled in the device tree.

---
 lib/utils/ipi/aclint_mswi.c     | 7 ++++++-
 lib/utils/timer/aclint_mtimer.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
lib/utils/ipi/aclint_mswi.c +6 -1
index f47b3bc..140a49b 100644
@@ -101,8 +101,13 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)
 	/* Update MSWI pointer in scratch space */
 	for (i = 0; i < mswi->hart_count; i++) {
 		scratch = sbi_hartid_to_scratch(mswi->first_hartid + i);
+		/*
+		 * We don't need to fail if scratch pointer is not available
+		 * because we might be dealing with hartid of a HART disabled
+		 * in the device tree.
+		 */
 		if (!scratch)
-			return SBI_ENOENT;
+			continue;
 		mswi_set_hart_data_ptr(scratch, mswi);
 	}
 
lib/utils/timer/aclint_mtimer.c +6 -1
index 13af5d8..271e625 100644
@@ -219,8 +219,13 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
 	/* Update MTIMER pointer in scratch space */
 	for (i = 0; i < mt->hart_count; i++) {
 		scratch = sbi_hartid_to_scratch(mt->first_hartid + i);
+		/*
+		 * We don't need to fail if scratch pointer is not available
+		 * because we might be dealing with hartid of a HART disabled
+		 * in the device tree.
+		 */
 		if (!scratch)
-			return SBI_ENOENT;
+			continue;
 		mtimer_set_hart_data_ptr(scratch, mt);
 	}
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/1 lib: utils: Fix sbi_hartid_to_scratch() usage in ACLINT drivers

? 2023-07-05???? 12:15 +0530?Anup Patel???

Quoted 5 lines

The cold_init() functions of ACLINT drivers should skip the HART is sbi_hartid_to_scratch() returns NULL because we might be dealing with a HART that is disabled in the device tree.

Look good to me

Quoted 47 lines

---
?lib/utils/ipi/aclint_mswi.c???? | 7 ++++++- ?lib/utils/timer/aclint_mtimer.c | 7 ++++++- ?2 files changed, 12 insertions(+), 2 deletions(-)

lib/utils/ipi/aclint_mswi.c +0 -0
index f47b3bc..140a49b 100644
@@ -101,8 +101,13 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)

????????/* Update MSWI pointer in scratch space */
????????for (i = 0; i < mswi->hart_count; i++) { ????????????????scratch = sbi_hartid_to_scratch(mswi->first_hartid + i); +???????????????/*
+??????????????? * We don't need to fail if scratch pointer is not available +??????????????? * because we might be dealing with hartid of a HART disabled +??????????????? * in the device tree.
+??????????????? */
????????????????if (!scratch)
-???????????????????????return SBI_ENOENT; +???????????????????????continue; ????????????????mswi_set_hart_data_ptr(scratch, mswi);
????????}
?

lib/utils/timer/aclint_mtimer.c +0 -0
index 13af5d8..271e625 100644
@@ -219,8 +219,13 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,

????????/* Update MTIMER pointer in scratch space */
????????for (i = 0; i < mt->hart_count; i++) { ????????????????scratch = sbi_hartid_to_scratch(mt->first_hartid + i); +???????????????/*
+??????????????? * We don't need to fail if scratch pointer is not available +??????????????? * because we might be dealing with hartid of a HART disabled +??????????????? * in the device tree.
+??????????????? */
????????????????if (!scratch)
-???????????????????????return SBI_ENOENT; +???????????????????????continue; ????????????????mtimer_set_hart_data_ptr(scratch, mt);
????????}
?

Signature · 1 line
2.34.1
Applied
#2 lore raw

PATCH 1/1 lib: utils: Fix sbi_hartid_to_scratch() usage in ACLINT drivers

In reply to Anup Patel
Quoted 6 lines · On Wed, Jul 5, 2023 at 12:15?PM Anup Patel <[email protected]> wrote:

The cold_init() functions of ACLINT drivers should skip the HART is sbi_hartid_to_scratch() returns NULL because we might be dealing with a HART that is disabled in the device tree.

Applied this patch to the riscv/opensbi repo.

Regards,
Anup

Quoted 46 lines
---
 lib/utils/ipi/aclint_mswi.c     | 7 ++++++-
 lib/utils/timer/aclint_mtimer.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
lib/utils/ipi/aclint_mswi.c +6 -1
index f47b3bc..140a49b 100644
@@ -101,8 +101,13 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)
        /* Update MSWI pointer in scratch space */
        for (i = 0; i < mswi->hart_count; i++) {
                scratch = sbi_hartid_to_scratch(mswi->first_hartid + i);
+               /*
+                * We don't need to fail if scratch pointer is not available
+                * because we might be dealing with hartid of a HART disabled
+                * in the device tree.
+                */
                if (!scratch)
-                       return SBI_ENOENT;
+                       continue;
                mswi_set_hart_data_ptr(scratch, mswi);
        }
 
lib/utils/timer/aclint_mtimer.c +6 -2
index 13af5d8..271e625 100644
@@ -219,8 +219,13 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
        /* Update MTIMER pointer in scratch space */
        for (i = 0; i < mt->hart_count; i++) {
                scratch = sbi_hartid_to_scratch(mt->first_hartid + i);
+               /*
+                * We don't need to fail if scratch pointer is not available
+                * because we might be dealing with hartid of a HART disabled
+                * in the device tree.
+                */
                if (!scratch)
-                       return SBI_ENOENT;
+                       continue;
                mtimer_set_hart_data_ptr(scratch, mt);
        }
 
--

2.34.1