Skip to contentSkip to conversation

lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

PATCH New Samuel Holland 5 participants 7 messages Oct 18, 2021 – Nov 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver.

---

Changes in v2:
- Use the thead,c900-plic compatible instead of the D1 compatible.
- Also apply this change to other T-HEAD device tree examples.
- Remove the plic-delegate code from the thead,reset-sample driver.
- Drop the return value from thead_plic_plat_init().

The compatible string is added in the patch series here:
https://lore.kernel.org/linux-riscv/20211016032200.2869998-1-guoren at kernel.org/T/

---
 docs/platform/thead-c9xx.md          | 12 +++---------
 lib/utils/irqchip/fdt_irqchip_plic.c | 15 +++++++++++++++
 lib/utils/reset/fdt_reset_thead.c    |  8 --------
 3 files changed, 18 insertions(+), 17 deletions(-)
docs/platform/thead-c9xx.md +3 -9
index c0daeb7..3490ed5 100644
@@ -51,11 +51,6 @@ DTS Example1: (Single core, eg: Allwinner D1 - c906)
 		compatible = "simple-bus";
 		ranges;
 
-		reset: reset-sample {
-			compatible = "thead,reset-sample";
-			plic-delegate = <0x0 0x101ffffc>;
-		};
-
 		clint0: clint at 14000000 {
 			compatible = "riscv,clint0";
 			interrupts-extended = <
@@ -67,7 +62,8 @@ DTS Example1: (Single core, eg: Allwinner D1 - c906)
 
 		intc: interrupt-controller@10000000 {
 			#interrupt-cells = <1>;
-			compatible = "riscv,plic0";
+			compatible = "allwinner,sun20i-d1-plic",
+				     "thead,c900-plic";
 			interrupt-controller;
 			interrupts-extended = <
 				&cpu0_intc  0xffffffff &cpu0_intc  9
@@ -150,7 +146,6 @@ DTS Example2: (Multi cores with soc reset-regs)
 
 		reset: reset-sample {
 			compatible = "thead,reset-sample";
-			plic-delegate = <0xff 0xd81ffffc>;
 			entry-reg = <0xff 0xff019050>;
 			entry-cnt = <4>;
 			control-reg = <0xff 0xff015004>;
@@ -173,7 +168,7 @@ DTS Example2: (Multi cores with soc reset-regs)
 
 		intc: interrupt-controller at ffd8000000 {
 			#interrupt-cells = <1>;
-			compatible = "riscv,plic0";
+			compatible = "thead,c900-plic";
 			interrupt-controller;
 			interrupts-extended = <
 				&cpu0_intc  0xffffffff &cpu0_intc  9
@@ -194,7 +189,6 @@ DTS Example2: (Multi cores with old reset csrs)
 ```
 	reset: reset-sample {
 		compatible = "thead,reset-sample";
-		plic-delegate = <0xff 0xd81ffffc>;
 		using-csr-reset;
 		csr-copy = <0x7c0 0x7c1 0x7c2 0x7c3 0x7c5 0x7cc
 			    0x3b0 0x3b1 0x3b2 0x3b3
lib/utils/irqchip/fdt_irqchip_plic.c +15 -0
index 18d2797..8d375be 100644
@@ -9,6 +9,7 @@
 
 #include <libfdt.h>
 #include <sbi/riscv_asm.h>
+#include <sbi/riscv_io.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
 #include <sbi_utils/fdt/fdt_helper.h>
@@ -91,6 +92,11 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
 	if (rc)
 		return rc;
 
+	if (match->data) {
+		void (*plic_plat_init)(struct plic_data *) = match->data;
+		plic_plat_init(pd);
+	}
+
 	rc = plic_cold_irqchip_init(pd);
 	if (rc)
 		return rc;
@@ -106,9 +112,18 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
 	return irqchip_plic_update_hartid_table(fdt, nodeoff, pd);
 }
 
+#define THEAD_PLIC_CTRL_REG 0x1ffffc
+
+static void thead_plic_plat_init(struct plic_data *pd)
+{
+	writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG);
+}
+
 static const struct fdt_match irqchip_plic_match[] = {
 	{ .compatible = "riscv,plic0" },
 	{ .compatible = "sifive,plic-1.0.0" },
+	{ .compatible = "thead,c900-plic",
+	  .data = thead_plic_plat_init },
 	{ },
 };
 
lib/utils/reset/fdt_reset_thead.c +0 -8
index 750b7aa..d491687 100644
@@ -82,14 +82,6 @@ static int thead_reset_init(void *fdt, int nodeoff,
 			clone_csrs(cnt);
 	}
 
-
-	/* Delegate plic enable regs for S-mode */
-	val = fdt_getprop(fdt, nodeoff, "plic-delegate", &len);
-	if (len > 0 && val) {
-		p = (void *)(ulong)fdt64_to_cpu(*val);
-		writel(BIT(0), p);
-	}
-
 	/* Old reset method for secondary harts */
 	if (fdt_getprop(fdt, nodeoff, "using-csr-reset", &len)) {
 		csr_write(0x7c7, (ulong)&__thead_pre_start_warm);
Signature · 1 line
2.32.0
#1 lore raw

PATCH v2 1/1 lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

Quoted 16 lines · Samuel Holland

The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver.

---

Changes in v2:
- Use the thead,c900-plic compatible instead of the D1 compatible.
- Also apply this change to other T-HEAD device tree examples.
- Remove the plic-delegate code from the thead,reset-sample driver.
- Drop the return value from thead_plic_plat_init().

Quoted 8 lines

The compatible string is added in the patch series here:
https://lore.kernel.org/linux-riscv/20211016032200.2869998-1-guoren at kernel.org/T/

---
 docs/platform/thead-c9xx.md          | 12 +++---------
 lib/utils/irqchip/fdt_irqchip_plic.c | 15 +++++++++++++++
 lib/utils/reset/fdt_reset_thead.c    |  8 --------
 3 files changed, 18 insertions(+), 17 deletions(-)
Applied
#2 lore raw

PATCH v2 1/1 lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

In reply to Samuel Holland
Quoted 8 lines · Samuel Holland

The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver.

Quoted 7 lines

---

Changes in v2:
- Use the thead,c900-plic compatible instead of the D1 compatible.
- Also apply this change to other T-HEAD device tree examples.
- Remove the plic-delegate code from the thead,reset-sample driver.
- Drop the return value from thead_plic_plat_init().

Looks good to me.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 130 lines

The compatible string is added in the patch series here:
https://lore.kernel.org/linux-riscv/20211016032200.2869998-1-guoren at kernel.org/T/

---
 docs/platform/thead-c9xx.md          | 12 +++---------
 lib/utils/irqchip/fdt_irqchip_plic.c | 15 +++++++++++++++
 lib/utils/reset/fdt_reset_thead.c    |  8 --------
 3 files changed, 18 insertions(+), 17 deletions(-)
docs/platform/thead-c9xx.md +3 -9
index c0daeb7..3490ed5 100644
@@ -51,11 +51,6 @@ DTS Example1: (Single core, eg: Allwinner D1 - c906)
                compatible = "simple-bus";
                ranges;
 
-               reset: reset-sample {
-                       compatible = "thead,reset-sample";
-                       plic-delegate = <0x0 0x101ffffc>;
-               };
-
                clint0: clint at 14000000 {
                        compatible = "riscv,clint0";
                        interrupts-extended = <
@@ -67,7 +62,8 @@ DTS Example1: (Single core, eg: Allwinner D1 - c906)
 
                intc: interrupt-controller at 10000000 {
                        #interrupt-cells = <1>;
-                       compatible = "riscv,plic0";
+                       compatible = "allwinner,sun20i-d1-plic",
+                                    "thead,c900-plic";
                        interrupt-controller;
                        interrupts-extended = <
                                &cpu0_intc  0xffffffff &cpu0_intc  9
@@ -150,7 +146,6 @@ DTS Example2: (Multi cores with soc reset-regs)
 
                reset: reset-sample {
                        compatible = "thead,reset-sample";
-                       plic-delegate = <0xff 0xd81ffffc>;
                        entry-reg = <0xff 0xff019050>;
                        entry-cnt = <4>;
                        control-reg = <0xff 0xff015004>;
@@ -173,7 +168,7 @@ DTS Example2: (Multi cores with soc reset-regs)
 
                intc: interrupt-controller at ffd8000000 {
                        #interrupt-cells = <1>;
-                       compatible = "riscv,plic0";
+                       compatible = "thead,c900-plic";
                        interrupt-controller;
                        interrupts-extended = <
                                &cpu0_intc  0xffffffff &cpu0_intc  9
@@ -194,7 +189,6 @@ DTS Example2: (Multi cores with old reset csrs)
 ```
        reset: reset-sample {
                compatible = "thead,reset-sample";
-               plic-delegate = <0xff 0xd81ffffc>;
                using-csr-reset;
                csr-copy = <0x7c0 0x7c1 0x7c2 0x7c3 0x7c5 0x7cc
                            0x3b0 0x3b1 0x3b2 0x3b3
lib/utils/irqchip/fdt_irqchip_plic.c +15 -0
index 18d2797..8d375be 100644
@@ -9,6 +9,7 @@
 
 #include <libfdt.h>
 #include <sbi/riscv_asm.h>
+#include <sbi/riscv_io.h>
 #include <sbi/sbi_error.h>
 #include <sbi/sbi_hartmask.h>
 #include <sbi_utils/fdt/fdt_helper.h>
@@ -91,6 +92,11 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
        if (rc)
                return rc;
 
+       if (match->data) {
+               void (*plic_plat_init)(struct plic_data *) = match->data;
+               plic_plat_init(pd);
+       }
+
        rc = plic_cold_irqchip_init(pd);
        if (rc)
                return rc;
@@ -106,9 +112,18 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
        return irqchip_plic_update_hartid_table(fdt, nodeoff, pd);
 }
 
+#define THEAD_PLIC_CTRL_REG 0x1ffffc
+
+static void thead_plic_plat_init(struct plic_data *pd)
+{
+       writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG);
+}
+
 static const struct fdt_match irqchip_plic_match[] = {
        { .compatible = "riscv,plic0" },
        { .compatible = "sifive,plic-1.0.0" },
+       { .compatible = "thead,c900-plic",
+         .data = thead_plic_plat_init },
        { },
 };
 
lib/utils/reset/fdt_reset_thead.c +0 -9
index 750b7aa..d491687 100644
@@ -82,14 +82,6 @@ static int thead_reset_init(void *fdt, int nodeoff,
                        clone_csrs(cnt);
        }
 
-
-       /* Delegate plic enable regs for S-mode */
-       val = fdt_getprop(fdt, nodeoff, "plic-delegate", &len);
-       if (len > 0 && val) {
-               p = (void *)(ulong)fdt64_to_cpu(*val);
-               writel(BIT(0), p);
-       }
-
        /* Old reset method for secondary harts */
        if (fdt_getprop(fdt, nodeoff, "using-csr-reset", &len)) {
                csr_write(0x7c7, (ulong)&__thead_pre_start_warm);
--

2.32.0

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#3 lore raw

PATCH v2 1/1 lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Anup" == Anup Patel <[email protected]> writes:

Hi,

Quoted 22 lines · Samuel Holland
Quoted 8 lines

The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver.

Quoted 7 lines

---

Changes in v2:
- Use the thead,c900-plic compatible instead of the D1 compatible.
- Also apply this change to other T-HEAD device tree examples.
- Remove the plic-delegate code from the thead,reset-sample driver.
- Drop the return value from thead_plic_plat_init().

Looks good to me.

Applied this patch to the riscv/opensbi repo.

..

Quoted 7 lines
Quoted 7 lines

static const struct fdt_match irqchip_plic_match[] = { { .compatible = "riscv,plic0" },
{ .compatible = "sifive,plic-1.0.0" },

lib/utils/irqchip/fdt_irqchip_plic.c +2 -0
+       { .compatible = "thead,c900-plic",
+         .data = thead_plic_plat_init },

{ },
};

Sorry, old thread but I just noticed now that the thead,c900-plic compatible should ideally have been before the sifive one, so DTBs with both compatibles behave correctly (drivers are matched according to the order of the driver compatible, NOT the order of the compatible in the DTB).

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH v2 1/1 lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

Quoted 38 lines · Peter Korsgaard
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Anup" == Anup Patel <[email protected]> writes:

Hi,

Quoted 22 lines · Samuel Holland
Quoted 8 lines

The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver.

Quoted 7 lines

---

Changes in v2:
- Use the thead,c900-plic compatible instead of the D1 compatible.
- Also apply this change to other T-HEAD device tree examples.
- Remove the plic-delegate code from the thead,reset-sample driver.
- Drop the return value from thead_plic_plat_init().

Looks good to me.

Applied this patch to the riscv/opensbi repo.

..

Quoted 7 lines
Quoted 7 lines

static const struct fdt_match irqchip_plic_match[] = { { .compatible = "riscv,plic0" },
{ .compatible = "sifive,plic-1.0.0" },

lib/utils/irqchip/fdt_irqchip_plic.c +2 -0
+       { .compatible = "thead,c900-plic",
+         .data = thead_plic_plat_init },

{ },
};

Quoted 5 lines

Sorry, old thread but I just noticed now that the thead,c900-plic compatible should ideally have been before the sifive one, so DTBs with both compatibles behave correctly (drivers are matched according to the order of the driver compatible, NOT the order of the compatible in the DTB).

Based on discussions on LKML, the T-HEAD PLIC is not compliant with RISC-V PLIC (and SiFive PLIC) so SiFive compatible string should not be used for any T-HEAD C9xx based board.

@Guo Ren I see that you have dropped the DT bindings patch in your recent patch. You need to include the DT bindings patch in your kernel series.

Regards,
Anup

Quoted 8 lines

--
Bye, Peter Korsgaard

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#5 lore raw

PATCH v2 1/1 lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

Quoted 42 lines · Anup Patel
Quoted 36 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Anup" == Anup Patel <[email protected]> writes:

Hi,

Quoted 22 lines · Samuel Holland
Quoted 8 lines

The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver.

Quoted 7 lines

---

Changes in v2:
- Use the thead,c900-plic compatible instead of the D1 compatible.
- Also apply this change to other T-HEAD device tree examples.
- Remove the plic-delegate code from the thead,reset-sample driver.
- Drop the return value from thead_plic_plat_init().

Looks good to me.

Applied this patch to the riscv/opensbi repo.

..

Quoted 7 lines
Quoted 7 lines

static const struct fdt_match irqchip_plic_match[] = { { .compatible = "riscv,plic0" },
{ .compatible = "sifive,plic-1.0.0" },

lib/utils/irqchip/fdt_irqchip_plic.c +2 -0
+       { .compatible = "thead,c900-plic",
+         .data = thead_plic_plat_init },

{ },
};

Quoted 5 lines

Sorry, old thread but I just noticed now that the thead,c900-plic compatible should ideally have been before the sifive one, so DTBs with both compatibles behave correctly (drivers are matched according to the order of the driver compatible, NOT the order of the compatible in the DTB).

Quoted 7 lines

Based on discussions on LKML, the T-HEAD PLIC is not compliant with RISC-V PLIC (and SiFive PLIC) so SiFive compatible string should not be used for any T-HEAD C9xx based board.

@Guo Ren I see that you have dropped the DT bindings patch in your recent patch. You need to include the DT bindings patch in your kernel series.

Okay

Quoted 11 lines

Regards,
Anup

Quoted 7 lines

--
Bye, Peter Korsgaard

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

#6 lore raw

PATCH v2 1/1 lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

In reply to Samuel Holland
Quoted 136 lines · Samuel Holland

The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver.

---

Changes in v2:
- Use the thead,c900-plic compatible instead of the D1 compatible.
- Also apply this change to other T-HEAD device tree examples.
- Remove the plic-delegate code from the thead,reset-sample driver.
- Drop the return value from thead_plic_plat_init().

The compatible string is added in the patch series here:
https://lore.kernel.org/linux-riscv/20211016032200.2869998-1-guoren at kernel.org/T/

---
  docs/platform/thead-c9xx.md          | 12 +++---------
  lib/utils/irqchip/fdt_irqchip_plic.c | 15 +++++++++++++++
  lib/utils/reset/fdt_reset_thead.c    |  8 --------
  3 files changed, 18 insertions(+), 17 deletions(-)
docs/platform/thead-c9xx.md +3 -9
index c0daeb7..3490ed5 100644
@@ -51,11 +51,6 @@ DTS Example1: (Single core, eg: Allwinner D1 - c906)
  		compatible = "simple-bus";
  		ranges;
 
-		reset: reset-sample {
-			compatible = "thead,reset-sample";
-			plic-delegate = <0x0 0x101ffffc>;
-		};
-
  		clint0: clint at 14000000 {
  			compatible = "riscv,clint0";
  			interrupts-extended = <
@@ -67,7 +62,8 @@ DTS Example1: (Single core, eg: Allwinner D1 - c906)
 
  		intc: interrupt-controller at 10000000 {
  			#interrupt-cells = <1>;
-			compatible = "riscv,plic0";
+			compatible = "allwinner,sun20i-d1-plic",
+				     "thead,c900-plic";
  			interrupt-controller;
  			interrupts-extended = <
  				&cpu0_intc  0xffffffff &cpu0_intc  9
@@ -150,7 +146,6 @@ DTS Example2: (Multi cores with soc reset-regs)
 
  		reset: reset-sample {
  			compatible = "thead,reset-sample";
-			plic-delegate = <0xff 0xd81ffffc>;
  			entry-reg = <0xff 0xff019050>;
  			entry-cnt = <4>;
  			control-reg = <0xff 0xff015004>;
@@ -173,7 +168,7 @@ DTS Example2: (Multi cores with soc reset-regs)
 
  		intc: interrupt-controller at ffd8000000 {
  			#interrupt-cells = <1>;
-			compatible = "riscv,plic0";
+			compatible = "thead,c900-plic";
  			interrupt-controller;
  			interrupts-extended = <
  				&cpu0_intc  0xffffffff &cpu0_intc  9
@@ -194,7 +189,6 @@ DTS Example2: (Multi cores with old reset csrs)
  ```
  	reset: reset-sample {
  		compatible = "thead,reset-sample";
-		plic-delegate = <0xff 0xd81ffffc>;
  		using-csr-reset;
  		csr-copy = <0x7c0 0x7c1 0x7c2 0x7c3 0x7c5 0x7cc
  			    0x3b0 0x3b1 0x3b2 0x3b3
lib/utils/irqchip/fdt_irqchip_plic.c +15 -0
index 18d2797..8d375be 100644
@@ -9,6 +9,7 @@
 
  #include <libfdt.h>
  #include <sbi/riscv_asm.h>
+#include <sbi/riscv_io.h>
  #include <sbi/sbi_error.h>
  #include <sbi/sbi_hartmask.h>
  #include <sbi_utils/fdt/fdt_helper.h>
@@ -91,6 +92,11 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
  	if (rc)
  		return rc;
 
+	if (match->data) {
+		void (*plic_plat_init)(struct plic_data *) = match->data;
+		plic_plat_init(pd);
+	}
+
  	rc = plic_cold_irqchip_init(pd);
  	if (rc)
  		return rc;
@@ -106,9 +112,18 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
  	return irqchip_plic_update_hartid_table(fdt, nodeoff, pd);
  }
 
+#define THEAD_PLIC_CTRL_REG 0x1ffffc
+
+static void thead_plic_plat_init(struct plic_data *pd)
+{
+	writel_relaxed(BIT(0), (void *)pd->addr + THEAD_PLIC_CTRL_REG);
+}
+
  static const struct fdt_match irqchip_plic_match[] = {
  	{ .compatible = "riscv,plic0" },
  	{ .compatible = "sifive,plic-1.0.0" },
+	{ .compatible = "thead,c900-plic",
+	  .data = thead_plic_plat_init },
  	{ },
  };
 
lib/utils/reset/fdt_reset_thead.c +0 -8
index 750b7aa..d491687 100644
@@ -82,14 +82,6 @@ static int thead_reset_init(void *fdt, int nodeoff,
  			clone_csrs(cnt);
  	}
 
-
-	/* Delegate plic enable regs for S-mode */
-	val = fdt_getprop(fdt, nodeoff, "plic-delegate", &len);
-	if (len > 0 && val) {
-		p = (void *)(ulong)fdt64_to_cpu(*val);
-		writel(BIT(0), p);
-	}
-
  	/* Old reset method for secondary harts */
  	if (fdt_getprop(fdt, nodeoff, "using-csr-reset", &len)) {
  		csr_write(0x7c7, (ulong)&__thead_pre_start_warm);