Skip to contentSkip to conversation

T-Head C9xx CLINT support

PATCH New Icenowy Zheng 3 participants 9 messages Dec 12, 2022 – Dec 17, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover T-Head C9xx CLINT support

This patchset tries to add support for T-Head C9xx's CLINT to OpenSBI.

For MSWI part, the T-Head CLINT is fully compatible with the SiFive one, so it's just simply adding a compatible string.

For MTIMER part, it's first needed to implement a quirk for MTIME-less timer (thus only MTIMECMP is present), then the compatible string is added and bound to the quirk.

To instantiate such a T-Head flavored CLINT via DT, this patchset depends on DT bindings declared in [1].

[1] https://www.spinics.net/lists/kernel/msg4597447.html

Icenowy Zheng (3):
lib: utils/ipi: mswi: add T-Head C9xx CLINT compatible
lib: utils/timer: mtimer: add a quirk for lacking mtime register
lib: utils/timer: mtimer: add T-Head C9xx CLINT compatible

 lib/utils/ipi/fdt_ipi_mswi.c       |  1 +
 lib/utils/timer/aclint_mtimer.c    | 11 ++++++---
 lib/utils/timer/fdt_timer_mtimer.c | 36 +++++++++++++++++++++---------
 3 files changed, 35 insertions(+), 13 deletions(-)
Signature · 1 line
2.38.1
#1 lore raw

PATCH v2 1/3 lib: utils/ipi: mswi: add T-Head C9xx CLINT compatible

Althoug the MTIMER part of a C9xx CLINT differs from a SiFive one, the MSWI part is compliant.

Add T-Head C9xx CLINT compatible string to fdt_ipi_mswi code, sharing the same codepath with SiFive CLINT.

---
Changes in v2:
- Added Anup's reviewed tag.

 lib/utils/ipi/fdt_ipi_mswi.c | 1 +
 1 file changed, 1 insertion(+)
lib/utils/ipi/fdt_ipi_mswi.c +1 -0
index 0176941..4dc91f2 100644
@@ -56,6 +56,7 @@ static const unsigned long clint_offset = CLINT_MSWI_OFFSET;
 static const struct fdt_match ipi_mswi_match[] = {
 	{ .compatible = "riscv,clint0", .data = &clint_offset },
 	{ .compatible = "sifive,clint0", .data = &clint_offset },
+	{ .compatible = "thead,c900-clint", .data = &clint_offset },
 	{ .compatible = "riscv,aclint-mswi" },
 	{ },
 };
Signature · 1 line
2.38.1
#2 lore raw

PATCH v2 2/3 lib: utils/timer: mtimer: add a quirk for lacking mtime register

In reply to Icenowy Zheng

T-Head developers surely have a different understanding of time CSR and CLINT's mtime register with SiFive ones, that they did not implement the mtime register at all -- as shown in openC906 source code, their time CSR value is just exposed at the top of their processor IP block and expects an external continous counter, which makes it not overrideable, and thus mtime register is not implemented, even not for reading. However, if CLINTEE is not enabled in T-Head's MXSTATUS extended CSR, these systems still rely on the mtimecmp registers to generate timer interrupts. This makes it necessary to implement T-Head C9xx CLINT support in OpenSBI MTIMER driver, which skips implementing reading mtime register and falls back to default code that reads time CSR.

Add a quirk into MTIMER driver, which represents a mtime register is lacking and time CSR value should be used instead.

---
Changes in v2:
- Dropped has_mtime field in aclint_mtimer_data, use mtime_size = 0 (which is disallowed before) to mark absence of mtime.
- Dropped the code that specially handle the existence of mtime when registering memory ranges -- the function will just be a no-op when size is 0.

 lib/utils/timer/aclint_mtimer.c    | 11 ++++++++---
 lib/utils/timer/fdt_timer_mtimer.c | 30 ++++++++++++++++++++----------
 2 files changed, 28 insertions(+), 13 deletions(-)
lib/utils/timer/aclint_mtimer.c +8 -3
index 3f00c21..1846a9a 100644
@@ -149,10 +149,10 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
 	int rc;
 
 	/* Sanity checks */
-	if (!mt || !mt->mtime_size ||
+	if (!mt ||
 	    (mt->hart_count && !mt->mtimecmp_size) ||
-	    (mt->mtime_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
-	    (mt->mtime_size & (ACLINT_MTIMER_ALIGN - 1)) ||
+	    (mt->mtime_size && (mt->mtime_addr & (ACLINT_MTIMER_ALIGN - 1))) ||
+	    (mt->mtime_size && (mt->mtime_size & (ACLINT_MTIMER_ALIGN - 1))) ||
 	    (mt->mtimecmp_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
 	    (mt->mtimecmp_size & (ACLINT_MTIMER_ALIGN - 1)) ||
 	    (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) ||
@@ -178,6 +178,11 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
 	for (i = 0; i < mt->hart_count; i++)
 		mtimer_hartid2data[mt->first_hartid + i] = mt;
 
+	if (!mt->mtime_size) {
+		/* Disable reading mtime when mtime is not available */
+		mtimer.timer_value = NULL;
+	}
+
 	/* Add MTIMER regions to the root domain */
 	if (mt->mtime_addr == (mt->mtimecmp_addr + mt->mtimecmp_size)) {
 		rc = sbi_domain_root_add_memrange(mt->mtimecmp_addr,
lib/utils/timer/fdt_timer_mtimer.c +20 -10
index 7b8546b..a0adc70 100644
@@ -18,6 +18,7 @@
 struct timer_mtimer_quirks {
 	unsigned int	mtime_offset;
 	bool		has_64bit_mmio;
+	bool		without_mtime;
 };
 
 static unsigned long mtimer_count = 0;
@@ -53,12 +54,16 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
 		/* Set CLINT addresses */
 		mt->mtimecmp_addr = addr[0] + ACLINT_DEFAULT_MTIMECMP_OFFSET;
 		mt->mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE;
-		mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET;
-		mt->mtime_size = size[0] - mt->mtimecmp_size;
-		/* Adjust MTIMER address and size for CLINT device */
-		mt->mtime_addr += quirks->mtime_offset;
+		if (!quirks->without_mtime) {
+			mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET;
+			mt->mtime_size = size[0] - mt->mtimecmp_size;
+			/* Adjust MTIMER address and size for CLINT device */
+			mt->mtime_addr += quirks->mtime_offset;
+			mt->mtime_size -= quirks->mtime_offset;
+		} else {
+			mt->mtime_addr = mt->mtime_size = 0;
+		}
 		mt->mtimecmp_addr += quirks->mtime_offset;
-		mt->mtime_size -= quirks->mtime_offset;
 		/* Apply additional CLINT quirks */
 		mt->has_64bit_mmio = quirks->has_64bit_mmio;
 	} else { /* RISC-V ACLINT MTIMER */
@@ -70,12 +75,17 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
 	}
 
 	/* Check if MTIMER device has shared MTIME address */
-	mt->has_shared_mtime = false;
-	for (i = 0; i < mtimer_count; i++) {
-		if (mtimer[i].mtime_addr == mt->mtime_addr) {
-			mt->has_shared_mtime = true;
-			break;
+	if (mt->mtime_size) {
+		mt->has_shared_mtime = false;
+		for (i = 0; i < mtimer_count; i++) {
+			if (mtimer[i].mtime_addr == mt->mtime_addr) {
+				mt->has_shared_mtime = true;
+				break;
+			}
 		}
+	} else {
+		/* Assume shared time CSR */
+		mt->has_shared_mtime = true;
 	}
 
 	/* Initialize the MTIMER device */
Signature · 1 line
2.38.1
#3 lore raw

PATCH v2 2/3 lib: utils/timer: mtimer: add a quirk for lacking mtime register

Quoted 14 lines · Icenowy Zheng

T-Head developers surely have a different understanding of time CSR and CLINT's mtime register with SiFive ones, that they did not implement the mtime register at all -- as shown in openC906 source code, their time CSR value is just exposed at the top of their processor IP block and expects an external continous counter, which makes it not overrideable, and thus mtime register is not implemented, even not for reading. However, if CLINTEE is not enabled in T-Head's MXSTATUS extended CSR, these systems still rely on the mtimecmp registers to generate timer interrupts. This makes it necessary to implement T-Head C9xx CLINT support in OpenSBI MTIMER driver, which skips implementing reading mtime register and falls back to default code that reads time CSR.

Quoted 4 lines

Add a quirk into MTIMER driver, which represents a mtime register is lacking and time CSR value should be used instead.

Looks good to me.

Regards,
Anup

Quoted 102 lines

---
Changes in v2:
- Dropped has_mtime field in aclint_mtimer_data, use mtime_size = 0 (which is disallowed before) to mark absence of mtime.
- Dropped the code that specially handle the existence of mtime when registering memory ranges -- the function will just be a no-op when size is 0.

 lib/utils/timer/aclint_mtimer.c    | 11 ++++++++---
 lib/utils/timer/fdt_timer_mtimer.c | 30 ++++++++++++++++++++----------
 2 files changed, 28 insertions(+), 13 deletions(-)
lib/utils/timer/aclint_mtimer.c +8 -3
index 3f00c21..1846a9a 100644
@@ -149,10 +149,10 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
        int rc;
 
        /* Sanity checks */
-       if (!mt || !mt->mtime_size ||
+       if (!mt ||
            (mt->hart_count && !mt->mtimecmp_size) ||
-           (mt->mtime_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
-           (mt->mtime_size & (ACLINT_MTIMER_ALIGN - 1)) ||
+           (mt->mtime_size && (mt->mtime_addr & (ACLINT_MTIMER_ALIGN - 1))) ||
+           (mt->mtime_size && (mt->mtime_size & (ACLINT_MTIMER_ALIGN - 1))) ||
            (mt->mtimecmp_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
            (mt->mtimecmp_size & (ACLINT_MTIMER_ALIGN - 1)) ||
            (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) ||
@@ -178,6 +178,11 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
        for (i = 0; i < mt->hart_count; i++)
                mtimer_hartid2data[mt->first_hartid + i] = mt;
 
+       if (!mt->mtime_size) {
+               /* Disable reading mtime when mtime is not available */
+               mtimer.timer_value = NULL;
+       }
+
        /* Add MTIMER regions to the root domain */
        if (mt->mtime_addr == (mt->mtimecmp_addr + mt->mtimecmp_size)) {
                rc = sbi_domain_root_add_memrange(mt->mtimecmp_addr,
lib/utils/timer/fdt_timer_mtimer.c +20 -11
index 7b8546b..a0adc70 100644
@@ -18,6 +18,7 @@
 struct timer_mtimer_quirks {
        unsigned int    mtime_offset;
        bool            has_64bit_mmio;
+       bool            without_mtime;
 };
 
 static unsigned long mtimer_count = 0;
@@ -53,12 +54,16 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
                /* Set CLINT addresses */
                mt->mtimecmp_addr = addr[0] + ACLINT_DEFAULT_MTIMECMP_OFFSET;
                mt->mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE;
-               mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET;
-               mt->mtime_size = size[0] - mt->mtimecmp_size;
-               /* Adjust MTIMER address and size for CLINT device */
-               mt->mtime_addr += quirks->mtime_offset;
+               if (!quirks->without_mtime) {
+                       mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET;
+                       mt->mtime_size = size[0] - mt->mtimecmp_size;
+                       /* Adjust MTIMER address and size for CLINT device */
+                       mt->mtime_addr += quirks->mtime_offset;
+                       mt->mtime_size -= quirks->mtime_offset;
+               } else {
+                       mt->mtime_addr = mt->mtime_size = 0;
+               }
                mt->mtimecmp_addr += quirks->mtime_offset;
-               mt->mtime_size -= quirks->mtime_offset;
                /* Apply additional CLINT quirks */
                mt->has_64bit_mmio = quirks->has_64bit_mmio;
        } else { /* RISC-V ACLINT MTIMER */
@@ -70,12 +75,17 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
        }
 
        /* Check if MTIMER device has shared MTIME address */
-       mt->has_shared_mtime = false;
-       for (i = 0; i < mtimer_count; i++) {
-               if (mtimer[i].mtime_addr == mt->mtime_addr) {
-                       mt->has_shared_mtime = true;
-                       break;
+       if (mt->mtime_size) {
+               mt->has_shared_mtime = false;
+               for (i = 0; i < mtimer_count; i++) {
+                       if (mtimer[i].mtime_addr == mt->mtime_addr) {
+                               mt->has_shared_mtime = true;
+                               break;
+                       }
                }
+       } else {
+               /* Assume shared time CSR */
+               mt->has_shared_mtime = true;
        }
 
        /* Initialize the MTIMER device */
--

2.38.1

#4 lore raw

PATCH v2 2/3 lib: utils/timer: mtimer: add a quirk for lacking mtime register

In reply to Icenowy Zheng

? 2022-12-12???? 16:22 +0800?Icenowy Zheng???

Quoted 37 lines

T-Head developers surely have a different understanding of time CSR and CLINT's mtime register with SiFive ones, that they did not implement the mtime register at all -- as shown in openC906 source code, their time CSR value is just exposed at the top of their processor IP block and expects an external continous counter, which makes it not overrideable, and thus mtime register is not implemented, even not for reading. However, if CLINTEE is not enabled in T-Head's MXSTATUS extended CSR, these systems still rely on the mtimecmp registers to generate timer interrupts. This makes it necessary to implement T-Head C9xx CLINT support in OpenSBI MTIMER driver, which skips implementing reading mtime register and falls back to default code that reads time CSR.

Add a quirk into MTIMER driver, which represents a mtime register is lacking and time CSR value should be used instead.

---
Changes in v2:
- Dropped has_mtime field in aclint_mtimer_data, use mtime_size = 0 ? (which is disallowed before) to mark absence of mtime.
- Dropped the code that specially handle the existence of mtime when ? registering memory ranges -- the function will just be a no-op when ? size is 0.

?lib/utils/timer/aclint_mtimer.c??? | 11 ++++++++--- ?lib/utils/timer/fdt_timer_mtimer.c | 30 ++++++++++++++++++++---------- ?2 files changed, 28 insertions(+), 13 deletions(-)

lib/utils/timer/aclint_mtimer.c +0 -0
index 3f00c21..1846a9a 100644
@@ -149,10 +149,10 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
 ????????int rc;

?
????????/* Sanity checks */

Quoted 6 lines
-???????if (!mt || !mt->mtime_size ||
+???????if (!mt ||
??????????? (mt->hart_count && !mt->mtimecmp_size) ||
-?????????? (mt->mtime_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
-?????????? (mt->mtime_size & (ACLINT_MTIMER_ALIGN - 1)) ||

+?????????? (mt->mtime_size && (mt->mtime_addr & (ACLINT_MTIMER_ALIGN - 1))) ||

typo.
mt->mtime_size should be mt->mtime_addr.

Regards,
Xiang W

Quoted 77 lines

+?????????? (mt->mtime_size && (mt->mtime_size & (ACLINT_MTIMER_ALIGN - 1))) ||

??????????? (mt->mtimecmp_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
??????????? (mt->mtimecmp_size & (ACLINT_MTIMER_ALIGN - 1)) ||

??????????? (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) ||

lib/utils/timer/aclint_mtimer.c +0 -0
@@ -178,6 +178,11 @@ int aclint_mtimer_cold_init(struct aclint_mtimer_data *mt,
 ????????for (i = 0; i < mt->hart_count; i++)
 ????????????????mtimer_hartid2data[mt->first_hartid + i] = mt;

?
+???????if (!mt->mtime_size) {
+???????????????/* Disable reading mtime when mtime is not available */ +???????????????mtimer.timer_value = NULL;
+???????}
+
????????/* Add MTIMER regions to the root domain */ ????????if (mt->mtime_addr == (mt->mtimecmp_addr + mt->mtimecmp_size)) { ????????????????rc = sbi_domain_root_add_memrange(mt->mtimecmp_addr,

lib/utils/timer/fdt_timer_mtimer.c +1 -0
index 7b8546b..a0adc70 100644
@@ -18,6 +18,7 @@
 ?struct timer_mtimer_quirks {
 ????????unsigned int????mtime_offset;
 ????????bool????????????has_64bit_mmio;
+???????bool????????????without_mtime;
 ?};

?
?static unsigned long mtimer_count = 0;

lib/utils/timer/fdt_timer_mtimer.c +0 -0
@@ -53,12 +54,16 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,

????????????????/* Set CLINT addresses */ ????????????????mt->mtimecmp_addr = addr[0] + ACLINT_DEFAULT_MTIMECMP_OFFSET; ????????????????mt->mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE; -???????????????mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET; -???????????????mt->mtime_size = size[0] - mt->mtimecmp_size; -???????????????/* Adjust MTIMER address and size for CLINT device */ -???????????????mt->mtime_addr += quirks->mtime_offset; +???????????????if (!quirks->without_mtime) { +???????????????????????mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET; +???????????????????????mt->mtime_size = size[0] - mt->mtimecmp_size; +???????????????????????/* Adjust MTIMER address and size for CLINT device */ +???????????????????????mt->mtime_addr += quirks->mtime_offset; +???????????????????????mt->mtime_size -= quirks->mtime_offset; +???????????????} else {
+???????????????????????mt->mtime_addr = mt->mtime_size = 0; +???????????????}
????????????????mt->mtimecmp_addr += quirks->mtime_offset; -???????????????mt->mtime_size -= quirks->mtime_offset; ????????????????/* Apply additional CLINT quirks */ ????????????????mt->has_64bit_mmio = quirks->has_64bit_mmio; ????????} else { /* RISC-V ACLINT MTIMER */

lib/utils/timer/fdt_timer_mtimer.c +0 -0
@@ -70,12 +75,17 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
 ????????}

?
????????/* Check if MTIMER device has shared MTIME address */ -???????mt->has_shared_mtime = false;
-???????for (i = 0; i < mtimer_count; i++) { -???????????????if (mtimer[i].mtime_addr == mt->mtime_addr) { -???????????????????????mt->has_shared_mtime = true; -???????????????????????break;
+???????if (mt->mtime_size) { +???????????????mt->has_shared_mtime = false; +???????????????for (i = 0; i < mtimer_count; i++) { +???????????????????????if (mtimer[i].mtime_addr == mt->mtime_addr) { +???????????????????????????????mt->has_shared_mtime = true; +???????????????????????????????break; +???????????????????????}
????????????????}
+???????} else {
+???????????????/* Assume shared time CSR */ +???????????????mt->has_shared_mtime = true;
????????}
?
????????/* Initialize the MTIMER device */

Signature · 1 line
2.38.1
#5 lore raw

PATCH v2 2/3 lib: utils/timer: mtimer: add a quirk for lacking mtime register

? 2022-12-13???? 16:01 +0800?Xiang W???

Quoted 52 lines

? 2022-12-12???? 16:22 +0800?Icenowy Zheng???

Quoted 51 lines

T-Head developers surely have a different understanding of time CSR and
CLINT's mtime register with SiFive ones, that they did not implement
the mtime register at all -- as shown in openC906 source code, their
time CSR value is just exposed at the top of their processor IP block
and expects an external continous counter, which makes it not overrideable, and thus mtime register is not implemented, even not for
reading. However, if CLINTEE is not enabled in T-Head's MXSTATUS extended CSR, these systems still rely on the mtimecmp registers to generate timer interrupts. This makes it necessary to implement T- Head
C9xx CLINT support in OpenSBI MTIMER driver, which skips implementing
reading mtime register and falls back to default code that reads time
CSR.

Add a quirk into MTIMER driver, which represents a mtime register is
lacking and time CSR value should be used instead.

---
Changes in v2:
- Dropped has_mtime field in aclint_mtimer_data, use mtime_size = 0 ? (which is disallowed before) to mark absence of mtime.
- Dropped the code that specially handle the existence of mtime when
? registering memory ranges -- the function will just be a no-op when
? size is 0.

?lib/utils/timer/aclint_mtimer.c??? | 11 ++++++++--- ?lib/utils/timer/fdt_timer_mtimer.c | 30 ++++++++++++++++++++------
----
?2 files changed, 28 insertions(+), 13 deletions(-)

lib/utils/timer/aclint_mtimer.c +0 -0
index 3f00c21..1846a9a 100644
@@ -149,10 +149,10 @@ int aclint_mtimer_cold_init(struct
 aclint_mtimer_data *mt,
 ????????int rc;

?
????????/* Sanity checks */

Quoted 8 lines
Quoted 7 lines
-???????if (!mt || !mt->mtime_size ||
+???????if (!mt ||
??????????? (mt->hart_count && !mt->mtimecmp_size) ||
-?????????? (mt->mtime_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
-?????????? (mt->mtime_size & (ACLINT_MTIMER_ALIGN - 1)) ||

+?????????? (mt->mtime_size && (mt->mtime_addr &
(ACLINT_MTIMER_ALIGN - 1))) ||

typo.

Not a typo, mtime_size = 0 here means the mtime register is just not available, so we do sanity check on mtime_addr based on the existence of mtime, thus mtime_size.

Quoted 98 lines

mt->mtime_size should be mt->mtime_addr.

Regards,
Xiang W

Quoted 92 lines

+?????????? (mt->mtime_size && (mt->mtime_size &
(ACLINT_MTIMER_ALIGN - 1))) ||

??????????? (mt->mtimecmp_addr & (ACLINT_MTIMER_ALIGN - 1)) ||
??????????? (mt->mtimecmp_size & (ACLINT_MTIMER_ALIGN - 1)) ||

??????????? (mt->first_hartid >= SBI_HARTMASK_MAX_BITS) ||

lib/utils/timer/aclint_mtimer.c +0 -0
@@ -178,6 +178,11 @@ int aclint_mtimer_cold_init(struct
 aclint_mtimer_data *mt,
 ????????for (i = 0; i < mt->hart_count; i++)
 ????????????????mtimer_hartid2data[mt->first_hartid + i] = mt;

?
+???????if (!mt->mtime_size) {
+???????????????/* Disable reading mtime when mtime is not available */
+???????????????mtimer.timer_value = NULL; +???????}
+
????????/* Add MTIMER regions to the root domain */ ????????if (mt->mtime_addr == (mt->mtimecmp_addr + mt-

Quoted 1 line

mtimecmp_size)) {

????????????????rc = sbi_domain_root_add_memrange(mt-

Quoted 1 line

mtimecmp_addr,

lib/utils/timer/fdt_timer_mtimer.c +1 -0
index 7b8546b..a0adc70 100644
@@ -18,6 +18,7 @@
 ?struct timer_mtimer_quirks {
 ????????unsigned int????mtime_offset;
 ????????bool????????????has_64bit_mmio;
+???????bool????????????without_mtime;
 ?};

?
?static unsigned long mtimer_count = 0;

lib/utils/timer/fdt_timer_mtimer.c +0 -0
@@ -53,12 +54,16 @@ static int timer_mtimer_cold_init(void *fdt,
 int nodeoff,

????????????????/* Set CLINT addresses */ ????????????????mt->mtimecmp_addr = addr[0] + ACLINT_DEFAULT_MTIMECMP_OFFSET; ????????????????mt->mtimecmp_size = ACLINT_DEFAULT_MTIMECMP_SIZE; -???????????????mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET; -???????????????mt->mtime_size = size[0] - mt->mtimecmp_size; -???????????????/* Adjust MTIMER address and size for CLINT device */
-???????????????mt->mtime_addr += quirks->mtime_offset; +???????????????if (!quirks->without_mtime) { +???????????????????????mt->mtime_addr = addr[0] + ACLINT_DEFAULT_MTIME_OFFSET; +???????????????????????mt->mtime_size = size[0] - mt-

Quoted 1 line

mtimecmp_size;

+???????????????????????/* Adjust MTIMER address and size for CLINT device */
+???????????????????????mt->mtime_addr += quirks->mtime_offset; +???????????????????????mt->mtime_size -= quirks->mtime_offset; +???????????????} else { +???????????????????????mt->mtime_addr = mt->mtime_size = 0; +???????????????}
????????????????mt->mtimecmp_addr += quirks->mtime_offset; -???????????????mt->mtime_size -= quirks->mtime_offset; ????????????????/* Apply additional CLINT quirks */ ????????????????mt->has_64bit_mmio = quirks->has_64bit_mmio; ????????} else { /* RISC-V ACLINT MTIMER */

lib/utils/timer/fdt_timer_mtimer.c +0 -0
@@ -70,12 +75,17 @@ static int timer_mtimer_cold_init(void *fdt,
 int nodeoff,
 ????????}

?
????????/* Check if MTIMER device has shared MTIME address */ -???????mt->has_shared_mtime = false;
-???????for (i = 0; i < mtimer_count; i++) { -???????????????if (mtimer[i].mtime_addr == mt->mtime_addr) { -???????????????????????mt->has_shared_mtime = true; -???????????????????????break;
+???????if (mt->mtime_size) { +???????????????mt->has_shared_mtime = false; +???????????????for (i = 0; i < mtimer_count; i++) { +???????????????????????if (mtimer[i].mtime_addr == mt->mtime_addr) {
+???????????????????????????????mt->has_shared_mtime = true; +???????????????????????????????break; +???????????????????????}
????????????????}
+???????} else {
+???????????????/* Assume shared time CSR */ +???????????????mt->has_shared_mtime = true;
????????}
?
????????/* Initialize the MTIMER device */

Signature · 1 line
2.38.1
#6 lore raw

PATCH v2 3/3 lib: utils/timer: mtimer: add T-Head C9xx CLINT compatible

In reply to Icenowy Zheng

As we already added the quirk for lacking mtime register to MTIMER driver, add T-Head C9xx CLINT compatible to it and wire the quirk.

---
No changes in v2.

 lib/utils/timer/fdt_timer_mtimer.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/utils/timer/fdt_timer_mtimer.c +6 -0
index a0adc70..5244f98 100644
@@ -124,9 +124,15 @@ static const struct timer_mtimer_quirks sifive_clint_quirks = {
 	.has_64bit_mmio	= true,
 };
 
+static const struct timer_mtimer_quirks thead_clint_quirks = {
+	.mtime_offset	= CLINT_MTIMER_OFFSET,
+	.without_mtime  = true,
+};
+
 static const struct fdt_match timer_mtimer_match[] = {
 	{ .compatible = "riscv,clint0", .data = &sifive_clint_quirks },
 	{ .compatible = "sifive,clint0", .data = &sifive_clint_quirks },
+	{ .compatible = "thead,c900-clint", .data = &thead_clint_quirks },
 	{ .compatible = "riscv,aclint-mtimer" },
 	{ },
 };
Signature · 1 line
2.38.1
#7 lore raw

PATCH v2 3/3 lib: utils/timer: mtimer: add T-Head C9xx CLINT compatible

Quoted 5 lines · Icenowy Zheng

As we already added the quirk for lacking mtime register to MTIMER driver, add T-Head C9xx CLINT compatible to it and wire the quirk.

Looks good to me.

Regards,
Anup

Quoted 29 lines

---
No changes in v2.

 lib/utils/timer/fdt_timer_mtimer.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/utils/timer/fdt_timer_mtimer.c +6 -1
index a0adc70..5244f98 100644
@@ -124,9 +124,15 @@ static const struct timer_mtimer_quirks sifive_clint_quirks = {
        .has_64bit_mmio = true,
 };
 
+static const struct timer_mtimer_quirks thead_clint_quirks = {
+       .mtime_offset   = CLINT_MTIMER_OFFSET,
+       .without_mtime  = true,
+};
+
 static const struct fdt_match timer_mtimer_match[] = {
        { .compatible = "riscv,clint0", .data = &sifive_clint_quirks },
        { .compatible = "sifive,clint0", .data = &sifive_clint_quirks },
+       { .compatible = "thead,c900-clint", .data = &thead_clint_quirks },
        { .compatible = "riscv,aclint-mtimer" },
        { },
 };
--

2.38.1

Applied
#8 lore raw

v2 cover T-Head C9xx CLINT support

In reply to Icenowy Zheng
Quoted 13 lines · Icenowy Zheng

This patchset tries to add support for T-Head C9xx's CLINT to OpenSBI.

For MSWI part, the T-Head CLINT is fully compatible with the SiFive one, so it's just simply adding a compatible string.

For MTIMER part, it's first needed to implement a quirk for MTIME-less timer (thus only MTIMECMP is present), then the compatible string is added and bound to the quirk.

To instantiate such a T-Head flavored CLINT via DT, this patchset depends on DT bindings declared in [1].

Quoted 6 lines

[1] https://www.spinics.net/lists/kernel/msg4597447.html

Icenowy Zheng (3):
lib: utils/ipi: mswi: add T-Head C9xx CLINT compatible
lib: utils/timer: mtimer: add a quirk for lacking mtime register
lib: utils/timer: mtimer: add T-Head C9xx CLINT compatible

Applied this series to the riscv/opensbi repo.

Thanks,
Anup

Quoted 9 lines
 lib/utils/ipi/fdt_ipi_mswi.c       |  1 +
 lib/utils/timer/aclint_mtimer.c    | 11 ++++++---
 lib/utils/timer/fdt_timer_mtimer.c | 36 +++++++++++++++++++++---------
 3 files changed, 35 insertions(+), 13 deletions(-)

--
2.38.1