lib: utils: Make sure that hartid and the scratch are aligned
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 lib: utils: Make sure that hartid and the scratch are aligned
Harts associated with an ACLINT_MSWI need not have sequential hartids. It is insufficient to use first_hartid and hart_count. To account for non-sequential hart ids, include the empty hard-ids' generate hart-count.
---
hart_count = last_hart_id - first_hart_id +1
count = number of harts
For sequential hart_id's, count = hart_count
For non-sequential hart_id's, count < hart_count
--- lib/utils/fdt/fdt_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/utils/fdt/fdt_helper.c +1 -2
@@ -1046,8 +1046,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ; }return 0 ;
Signature · 1 line
2.43.0
PATCH v2 1/1 lib: utils: Make sure that hartid and the scratch are aligned
Hi Raj,
Quoted 3 lines · Raj Vishwanathan
Harts associated with an
ACLINT_MSWIneed not have sequential hartids. It is insufficient to usefirst_hartidandhart_count. To account for non-sequential hart ids, include the empty hard-ids' generate hart-count.
This doesn't help, because the expression (hartid - first_hartid) is still used to calculate MMIO addresses. See for example mtimer_event_start() and mswi_ipi_send(). If there is a gap in the hartids mapped to the ACLINT MTIMER/MSWI indexes, these functions will compute the wrong MMIO address and fail to set the timer or send an IPI.
Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
Regards,
Samuel
Quoted 25 lines
Signed-off-by Raj Vishwanathan <[email protected]>---
hart_count=last_hart_id-first_hart_id+1
count = number of harts
For sequential hart_id's, count =hart_count
For non-sequential hart_id's, count <hart_count--- lib/utils/fdt/fdt_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +1
-2@@ -1046,8 +1046,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ; }return 0 ;
PATCH v2 1/1 lib: utils: Make sure that hartid and the scratch are aligned
Samuel
Thanks for the quick review. I took a quick look and in our case, where the hart-id's are not sequential, I see that there will be gaps in the MMIO space but nothing should break
I will do a deeper study and respond specifically to your questions.
Raj
Quoted 47 lines · On Thu, Feb 13, 2025 at 2:58?PM Samuel Holland <[email protected]>…
Hi Raj,
Quoted 3 lines · Raj Vishwanathan
Harts associated with an
ACLINT_MSWIneed not have sequential hartids. It is insufficient to usefirst_hartidandhart_count. To account for non-sequential hart ids, include the empty hard-ids' generate hart-count.This doesn't help, because the expression (hartid -
first_hartid) is still used to calculate MMIO addresses. See for examplemtimer_event_start()andmswi_ipi_send(). If there is a gap in the hartids mapped to the ACLINT MTIMER/MSWI indexes, these functions will compute the wrong MMIO address and fail to set the timer or send an IPI.Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
Regards,
SamuelQuoted 25 lines
Signed-off-by Raj Vishwanathan <[email protected]>---
hart_count=last_hart_id-first_hart_id+1
count = number of harts
For sequential hart_id's, count =hart_count
For non-sequential hart_id's, count <hart_count--- lib/utils/fdt/fdt_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +1
-2@@ -1046,8 +1046,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ; }return 0 ;
PATCH v2 1/1 lib: utils: Make sure that hartid and the scratch are aligned
Hi Samuel
I reviewed the two files for mstimer and mswi_ipi and they seem to be correct. We use the same "hartid - first_hartid" to access MMIO addresses. So, the current mtimer_event_start() and mswi_ipi_send() implementations work as is.
Quoted 3 lines
Quoted 3 lines
Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
ACLINT index is actually "hartid - first_hartid"
Let me know if you have any further comments.
Raj
Quoted 60 lines · On Thu, Feb 13, 2025 at 10:01?PM Raj Vishwanathan <[email protected]>…
Samuel
Thanks for the quick review. I took a quick look and in our case, where the hart-id's are not sequential, I see that there will be gaps in the MMIO space but nothing should break
I will do a deeper study and respond specifically to your questions.
Raj
Quoted 47 lines · On Thu, Feb 13, 2025 at 2:58?PM Samuel Holland <[email protected]>…
Hi Raj,
Quoted 3 lines · Raj Vishwanathan
Harts associated with an
ACLINT_MSWIneed not have sequential hartids. It is insufficient to usefirst_hartidandhart_count. To account for non-sequential hart ids, include the empty hard-ids' generate hart-count.This doesn't help, because the expression (hartid -
first_hartid) is still used to calculate MMIO addresses. See for examplemtimer_event_start()andmswi_ipi_send(). If there is a gap in the hartids mapped to the ACLINT MTIMER/MSWI indexes, these functions will compute the wrong MMIO address and fail to set the timer or send an IPI.Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
Regards,
SamuelQuoted 25 lines
Signed-off-by Raj Vishwanathan <[email protected]>---
hart_count=last_hart_id-first_hart_id+1
count = number of harts
For sequential hart_id's, count =hart_count
For non-sequential hart_id's, count <hart_count--- lib/utils/fdt/fdt_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +1
-2@@ -1046,8 +1046,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ; }return 0 ;
PATCH v2 1/1 lib: utils: Make sure that hartid and the scratch are aligned
Hi Raj,
Quoted 4 lines · Raj Vishwanathan
I reviewed the two files for mstimer and
mswi_ipiand they seem to be correct. We use the same "hartid -first_hartid" to access MMIO addresses. So, the currentmtimer_event_start()andmswi_ipi_send()implementations work as is.
OK, I looked at the MIPS P8700 reference manual and see what you mean: "The MSIP register for hart mhartid is accessed at GCR_BASE + 0x50000 + 4 * mhartid[11:0]." So there is no gap in the mapping, instead there is a gap in the register space.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
Quoted 28 lines
ACLINT index is actually "hartid -
first_hartid"Let me know if you have any further comments.
Raj
Quoted 20 lines · On Thu, Feb 13, 2025 at 10:01?PM Raj Vishwanathan <[email protected]>…
Samuel
Thanks for the quick review. I took a quick look and in our case, where the hart-id's are not sequential, I see that there will be gaps in the MMIO space but nothing should break
I will do a deeper study and respond specifically to your questions.
Raj
Quoted 7 lines · On Thu, Feb 13, 2025 at 2:58?PM Samuel Holland <[email protected]>…
Hi Raj,
Quoted 3 lines · Raj Vishwanathan
Harts associated with an
ACLINT_MSWIneed not have sequential hartids. It is insufficient to usefirst_hartidandhart_count. To account for non-sequential hart ids, include the empty hard-ids' generate hart-count.
s/hard/hart/
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
This doesn't help, because the expression (hartid -
first_hartid) is still used to calculate MMIO addresses. See for examplemtimer_event_start()andmswi_ipi_send(). If there is a gap in the hartids mapped to the ACLINT MTIMER/MSWI indexes, these functions will compute the wrong MMIO address and fail to set the timer or send an IPI.Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
Regards,
SamuelQuoted 17 lines
Signed-off-by Raj Vishwanathan <[email protected]>---
hart_count=last_hart_id-first_hart_id+1
count = number of harts
For sequential hart_id's, count =hart_count
For non-sequential hart_id's, count <hart_count--- lib/utils/fdt/fdt_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +0
-0@@ -1046,8 +1046,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lib/utils/fdt/fdt_helper.c int fdt_parse_aclint_node(const void *fdt, int nodeoffset, · line 1049
Quoted 5 lines
lib/utils/fdt/fdt_helper.c +1
-2if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ;
Now that I understand the context, this looks like the right change to make.
Please remove the hart_count variable entirely, since it is now unused. Also please fix the spacing in this line. With those changes:
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
lib/utils/fdt/fdt_helper.c +0
-0}return 0 ;
PATCH v2 1/1 lib: utils: Make sure that hartid and the scratch are aligned
Samuel
I appreciate your response. I will make the changes and send out the changes soon.
Many thanks
Raj
Quoted 98 lines · On Mon, Feb 24, 2025 at 6:00?PM Samuel Holland <[email protected]>…
Hi Raj,
Quoted 4 lines · Raj Vishwanathan
I reviewed the two files for mstimer and
mswi_ipiand they seem to be correct. We use the same "hartid -first_hartid" to access MMIO addresses. So, the currentmtimer_event_start()andmswi_ipi_send()implementations work as is.OK, I looked at the MIPS P8700 reference manual and see what you mean: "The MSIP register for hart mhartid is accessed at
GCR_BASE+0x50000+ 4 * mhartid[11:0]." So there is no gap in the mapping, instead there is a gap in the register space.Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
Quoted 28 lines
ACLINT index is actually "hartid -
first_hartid"Let me know if you have any further comments.
Raj
Quoted 20 lines · On Thu, Feb 13, 2025 at 10:01?PM Raj Vishwanathan <[email protected]>…
Samuel
Thanks for the quick review. I took a quick look and in our case, where the hart-id's are not sequential, I see that there will be gaps in the MMIO space but nothing should break
I will do a deeper study and respond specifically to your questions.
Raj
Quoted 7 lines · On Thu, Feb 13, 2025 at 2:58?PM Samuel Holland <[email protected]>…
Hi Raj,
Quoted 3 lines · Raj Vishwanathan
Harts associated with an
ACLINT_MSWIneed not have sequential hartids. It is insufficient to usefirst_hartidandhart_count. To account for non-sequential hart ids, include the empty hard-ids' generate hart-count.s/hard/hart/
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
This doesn't help, because the expression (hartid -
first_hartid) is still used to calculate MMIO addresses. See for examplemtimer_event_start()andmswi_ipi_send(). If there is a gap in the hartids mapped to the ACLINT MTIMER/MSWI indexes, these functions will compute the wrong MMIO address and fail to set the timer or send an IPI.Either each device instance needs an array of [ACLINT index] => [hart index] mappings, or the ACLINT index needs to be recorded separately in a new per-hart scratch variable.
Regards,
SamuelQuoted 17 lines
Signed-off-by Raj Vishwanathan <[email protected]>---
hart_count=last_hart_id-first_hart_id+1
count = number of harts
For sequential hart_id's, count =hart_count
For non-sequential hart_id's, count <hart_count--- lib/utils/fdt/fdt_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/utils/fdt/fdt_helper.c +0
-0@@ -1046,8 +1046,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lib/utils/fdt/fdt_helper.c int fdt_parse_aclint_node(const void *fdt, int nodeoffset, · line 1049
Quoted 5 lines
lib/utils/fdt/fdt_helper.c +1
-2if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ;Now that I understand the context, this looks like the right change to make.
Please remove the
hart_countvariable entirely, since it is now unused. Also please fix the spacing in this line. With those changes:Reviewed-by Samuel Holland <[email protected]>Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
lib/utils/fdt/fdt_helper.c +0
-0}return 0 ;
PATCH v3 1/1 lib: utils: Make sure that hartid and the scratch are aligned
In reply to Raj VishwanathanHarts associated with an ACLINT_MSWI need not have sequential hartids. It is insufficient to use first_hartid and hart_count. To account for non-sequential hart ids, include the empty hart-ids' generate hart-count.
---hart_count = last_hart_id - first_hart_id +1
count = number of harts
For sequential hart_id's, count = hart_count
For non-sequential hart_id's, count < hart_count
--- lib/utils/fdt/fdt_helper.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
lib/utils/fdt/fdt_helper.c +3 -6
@@ -986,7 +986,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, {const fdt32_t *val;int i, rc, count, cpu_offset, cpu_intc_offset; -u32 phandle, hwirq, hartid, first_hartid, last_hartid, hart_count; +u32 phandle, hwirq, hartid, first_hartid, last_hartid;u32 match_hwirq = (for_timer) ?IRQ_M_TIMER :IRQ_M_SOFT ; if (nodeoffset < 0 || !fdt ||
@@ -1015,7 +1015,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, count = count /sizeof (fdt32_t); first_hartid =-1U ; - hart_count = last_hartid =0 ; + last_hartid =0 ;for (i =0 ; i < (count /2 ); i++) { phandle =fdt32_to_cpu (val[2 * i]); hwirq =fdt32_to_cpu (val[(2 * i) +1 ]);
@@ -1040,16 +1040,13 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, first_hartid = hartid;if (hartid > last_hartid) last_hartid = hartid; - hart_count++; } }if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ; } -return 0 ; }
Signature · 1 line
2.43.0
PATCH v3 1/1 lib: utils: Make sure that hartid and the scratch are aligned
Quoted 39 lines · Raj Vishwanathan
Harts associated with an
ACLINT_MSWIneed not have sequential hartids. It is insufficient to usefirst_hartidandhart_count. To account for non-sequential hart ids, include the empty hart-ids' generate hart-count.Signed-off-by Raj Vishwanathan <[email protected]>---
hart_count=last_hart_id-first_hart_id+1
count = number of harts
For sequential hart_id's, count =hart_count
For non-sequential hart_id's, count <hart_count--- lib/utils/fdt/fdt_helper.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)lib/utils/fdt/fdt_helper.c +2
-2@@ -986,7 +986,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, {const fdt32_t *val;int i, rc, count, cpu_offset, cpu_intc_offset; -u32 phandle, hwirq, hartid, first_hartid, last_hartid, hart_count; +u32 phandle, hwirq, hartid, first_hartid, last_hartid;u32 match_hwirq = (for_timer) ?IRQ_M_TIMER :IRQ_M_SOFT ; if (nodeoffset < 0 || !fdt ||@@ -1015,7 +1015,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, count = count /sizeof (fdt32_t); first_hartid =-1U ; - hart_count = last_hartid =0 ; + last_hartid =0 ;for (i =0 ; i < (count /2 ); i++) { phandle =fdt32_to_cpu (val[2 * i]); hwirq =fdt32_to_cpu (val[(2 * i) +1 ]);@@ -1040,16 +1040,13 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, first_hartid = hartid;if (hartid > last_hartid)
lib/utils/fdt/fdt_helper.c int fdt_parse_aclint_node(const void *fdt, int nodeoffset, · line 1048
Quoted 10 lines
lib/utils/fdt/fdt_helper.c +1
-3last_hartid = hartid; - hart_count++; } }if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ;
You still have an extra space before the assignment here.
lib/utils/fdt/fdt_helper.c int fdt_parse_aclint_node(const void *fdt, int nodeoffset, · line 1052
Quoted 2 lines
lib/utils/fdt/fdt_helper.c +0
-1} -
Unrelated change.
With those style issues fixed:
Quoted 3 lines
lib/utils/fdt/fdt_helper.c +0
-0return 0 ; }
PATCH v3 1/1 lib: utils: Make sure that hartid and the scratch are aligned
In reply to Raj VishwanathanHarts associated with an ACLINT_MSWI need not have sequential hartids. It is insufficient to use first_hartid and hart_count. To account for non-sequential hart ids, include the empty hart-ids' generate hart-count.
---hart_count = last_hart_id - first_hart_id +1
count = number of harts
For sequential hart_id's, count = hart_count
For non-sequential hart_id's, count < hart_count
--- lib/utils/fdt/fdt_helper.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
lib/utils/fdt/fdt_helper.c +3 -6
@@ -986,7 +986,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, {const fdt32_t *val;int i, rc, count, cpu_offset, cpu_intc_offset; -u32 phandle, hwirq, hartid, first_hartid, last_hartid, hart_count; +u32 phandle, hwirq, hartid, first_hartid, last_hartid;u32 match_hwirq = (for_timer) ?IRQ_M_TIMER :IRQ_M_SOFT ; if (nodeoffset < 0 || !fdt ||
@@ -1015,7 +1015,7 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, count = count /sizeof (fdt32_t); first_hartid =-1U ; - hart_count = last_hartid =0 ; + last_hartid =0 ;for (i =0 ; i < (count /2 ); i++) { phandle =fdt32_to_cpu (val[2 * i]); hwirq =fdt32_to_cpu (val[(2 * i) +1 ]);
@@ -1040,16 +1040,13 @@ int fdt_parse_aclint_node(const void *fdt, int nodeoffset, first_hartid = hartid;if (hartid > last_hartid) last_hartid = hartid; - hart_count++; } }if ((last_hartid >= first_hartid) && first_hartid !=-1U ) { *out_first_hartid = first_hartid; - count = last_hartid - first_hartid +1 ; - *out_hart_count = (hart_count < count) ? hart_count : count; + *out_hart_count = last_hartid - first_hartid +1 ; } -return 0 ; }
Signature · 1 line
2.43.0