devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/7] Risc-V ACLINT IPI controller
@ 2025-06-09 13:47 Vladimir Kondratiev
  2025-06-09 13:47 ` [PATCH v1 1/7] riscv: helper to parse hart index Vladimir Kondratiev
                   ` (8 more replies)
  0 siblings, 9 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Risc-V specification for the ACLINT IPI controller
describes an "SSWI" device that allows to send IPI by
writing register from the S-mode (Linux kernel),
as opposed to the "MSWI" device that does the same from
the M-mode. Sending IPI through the M-mode requires
extra SBI call, SSWI is much faster. Support for the
SSWI exists for the Thead board, it is almost as by
specification save for reading one custom CSR.

Soon to be released Mobileye SoC based on the MIPS
P8700 Risc-v CPU has pristine ACLINT SSWI.

To support P8700, refactor Thead implementation -
provide generic one while keeping Thead-specific variant.

In addition, support Risc-v "hart index" - it is
required for the MIPS P8700 chip to be released soon

Patches 1 and 2 refactor "hart index" support, replacing
APLIC specific implementation with generic helper

Patch 3 documents generic "riscv,aclint-sswi" and optional
property "riscv,hart-indexes", same as for ACLINT.

Patch 4 promotes Thead-specific SSWI to generic one

Patch 5 adds "riscv,hart-indexes" support

Patches 6 and 7 do some minor improvements for the SSWI

Vladimir Kondratiev (7):
  riscv: helper to parse hart index
  irqchip: riscv aplic: use riscv_get_hart_index()
  dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi
  irqchip: introduce generic Risc-V aclint-sswi
  irqchip: aslint-sswi: resolve hart index
  irqchip: aclint-sswi: reduce data scope
  irqchip: aclint-sswi: remove extra includes

 .../riscv,aclint-sswi.yaml                    |  89 ++++++++++++++
 .../thead,c900-aclint-sswi.yaml               |  58 ---------
 arch/riscv/include/asm/irq.h                  |   2 +
 arch/riscv/kernel/irq.c                       |  34 ++++++
 drivers/irqchip/Kconfig                       |  12 ++
 drivers/irqchip/Makefile                      |   2 +-
 ...d-c900-aclint-sswi.c => irq-aclint-sswi.c} | 114 ++++++++++++------
 drivers/irqchip/irq-riscv-aplic-direct.c      |  16 +--
 8 files changed, 214 insertions(+), 113 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml
 delete mode 100644 Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
 rename drivers/irqchip/{irq-thead-c900-aclint-sswi.c => irq-aclint-sswi.c} (63%)


base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
-- 
2.43.0


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH v1 1/7] riscv: helper to parse hart index
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
@ 2025-06-09 13:47 ` Vladimir Kondratiev
  2025-06-23 12:53   ` Alexandre Ghiti
  2025-06-09 13:47 ` [PATCH v1 2/7] irqchip: riscv aplic: use riscv_get_hart_index() Vladimir Kondratiev
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

RISC-V APLIC specification defines "hart index" in [1]
And similar definitions found for ACLINT in [2]

Quote from [1]:

Within a given interrupt domain, each of the domain’s harts has a unique
index number in the range 0 to 2^14 − 1 (= 16,383). The index number a
domain associates with a hart may or may not have any relationship to the
unique hart identifier (“hart ID”) that the RISC-V Privileged
Architecture assigns to the hart. Two different interrupt domains may
employ entirely different index numbers for the same set of harts.

Further, [1] says in "4.5 Memory-mapped control region for an
interrupt domain":

The array of IDC structures may include some for potential hart index
numbers that are not actual hart index numbers in the domain.
For example, the first IDC structure is always for hart index 0, but 0 is
not necessarily a valid index number for any hart in the domain.

Support arbitrary hart indices specified in an optional property
"riscv,hart-indexes" which is specified as an array of u32 elements, one
per interrupt target, listing hart indexes in the same order as in
"interrupts-extended". If this property is not specified, fallback to use
logical hart indices within the domain.

If property not exist, fall back to logical hart indexes

Link: https://github.com/riscv/riscv-aia [1]
Link: https://github.com/riscvarchive/riscv-aclint [2]
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 arch/riscv/include/asm/irq.h |  2 ++
 arch/riscv/kernel/irq.c      | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h
index 7b038f3b7cb0..59c975f750c9 100644
--- a/arch/riscv/include/asm/irq.h
+++ b/arch/riscv/include/asm/irq.h
@@ -22,6 +22,8 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu);
 void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));
 
 struct fwnode_handle *riscv_get_intc_hwnode(void);
+int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
+			 u32 *hart_index);
 
 #ifdef CONFIG_ACPI
 
diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c
index 9ceda02507ca..efdf505bb776 100644
--- a/arch/riscv/kernel/irq.c
+++ b/arch/riscv/kernel/irq.c
@@ -32,6 +32,40 @@ struct fwnode_handle *riscv_get_intc_hwnode(void)
 }
 EXPORT_SYMBOL_GPL(riscv_get_intc_hwnode);
 
+/**
+ * riscv_get_hart_index() - get hart index for interrupt delivery
+ * @fwnode: interrupt controller node
+ * @logical_index: index within the "interrupts-extended" property
+ * @hart_index: filled with the hart index to use
+ *
+ * Risc-V uses term "hart index" for its interrupt controllers, for the
+ * purpose of the interrupt routing to destination harts.
+ * It may be arbitrary numbers assigned to each destination hart in context
+ * of the particular interrupt domain.
+ *
+ * These numbers encoded in the optional property "riscv,hart-indexes"
+ * that should contain hart index for each interrupt destination in the same
+ * order as in the "interrupts-extended" property. If this property
+ * not exist, it assumed equal to the logical index, i.e. index within the
+ * "interrupts-extended" property.
+ *
+ * Return: error code
+ */
+int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
+			 u32 *hart_index)
+{
+	static const char *prop_hart_index = "riscv,hart-indexes";
+	struct device_node *np = to_of_node(fwnode);
+
+	if (!np || !of_property_present(np, prop_hart_index)) {
+		*hart_index = logical_index;
+		return 0;
+	}
+
+	return of_property_read_u32_index(np, prop_hart_index,
+					  logical_index, hart_index);
+}
+
 #ifdef CONFIG_IRQ_STACKS
 #include <asm/irq_stack.h>
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v1 2/7] irqchip: riscv aplic: use riscv_get_hart_index()
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
  2025-06-09 13:47 ` [PATCH v1 1/7] riscv: helper to parse hart index Vladimir Kondratiev
@ 2025-06-09 13:47 ` Vladimir Kondratiev
  2025-06-12 12:50   ` Thomas Gleixner
  2025-06-09 13:47 ` [PATCH v1 3/7] dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi Vladimir Kondratiev
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Use global helper function instead of the local
implementation

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-riscv-aplic-direct.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/irqchip/irq-riscv-aplic-direct.c b/drivers/irqchip/irq-riscv-aplic-direct.c
index 205ad61d15e4..c2a75bf3d20c 100644
--- a/drivers/irqchip/irq-riscv-aplic-direct.c
+++ b/drivers/irqchip/irq-riscv-aplic-direct.c
@@ -219,20 +219,6 @@ static int aplic_direct_parse_parent_hwirq(struct device *dev, u32 index,
 	return 0;
 }
 
-static int aplic_direct_get_hart_index(struct device *dev, u32 logical_index,
-				       u32 *hart_index)
-{
-	const char *prop_hart_index = "riscv,hart-indexes";
-	struct device_node *np = to_of_node(dev->fwnode);
-
-	if (!np || !of_property_present(np, prop_hart_index)) {
-		*hart_index = logical_index;
-		return 0;
-	}
-
-	return of_property_read_u32_index(np, prop_hart_index, logical_index, hart_index);
-}
-
 int aplic_direct_setup(struct device *dev, void __iomem *regs)
 {
 	int i, j, rc, cpu, current_cpu, setup_count = 0;
@@ -279,7 +265,7 @@ int aplic_direct_setup(struct device *dev, void __iomem *regs)
 		cpumask_set_cpu(cpu, &direct->lmask);
 
 		idc = per_cpu_ptr(&aplic_idcs, cpu);
-		rc = aplic_direct_get_hart_index(dev, i, &idc->hart_index);
+		rc = riscv_get_hart_index(dev->fwnode, i, &idc->hart_index);
 		if (rc) {
 			dev_warn(dev, "hart index not found for IDC%d\n", i);
 			continue;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v1 3/7] dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
  2025-06-09 13:47 ` [PATCH v1 1/7] riscv: helper to parse hart index Vladimir Kondratiev
  2025-06-09 13:47 ` [PATCH v1 2/7] irqchip: riscv aplic: use riscv_get_hart_index() Vladimir Kondratiev
@ 2025-06-09 13:47 ` Vladimir Kondratiev
  2025-06-09 16:01   ` Conor Dooley
  2025-06-09 13:47 ` [PATCH v1 4/7] irqchip: introduce generic Risc-V aclint-sswi Vladimir Kondratiev
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Add generic, Risc-V spec compliant (see [1]) aclint-sswi binding

Thead specific binding preserved, and converted to variant of the
generic aclint-sswi

Link: https://github.com/riscvarchive/riscv-aclint [1]

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 .../riscv,aclint-sswi.yaml                    | 89 +++++++++++++++++++
 .../thead,c900-aclint-sswi.yaml               | 58 ------------
 2 files changed, 89 insertions(+), 58 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml
 delete mode 100644 Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml

diff --git a/Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml b/Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml
new file mode 100644
index 000000000000..cffddfcfcfea
--- /dev/null
+++ b/Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/riscv,aclint-sswi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Risc-V ACLINT Supervisor-level Software Interrupt Device
+
+maintainers:
+  - Inochi Amaoto <inochiama@outlook.com>
+
+description:
+  The SSWI device is a part of the Risc-V ACLINT device. It provides
+  supervisor-level IPI functionality for a set of HARTs on a THEAD
+  platform. It provides a register to set an IPI (SETSSIP) for each
+  HART connected to the SSWI device. See specification
+  https://github.com/riscvarchive/riscv-aclint
+
+  T-HEAD C900 ACLINT is a variant of the ACLINT, using dedicated
+  compatible string
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - sophgo,sg2044-aclint-sswi
+          - const: thead,c900-aclint-sswi
+      - items:
+          - const: riscv,aclint-sswi
+
+  reg:
+    maxItems: 1
+
+  "#interrupt-cells":
+    const: 0
+
+  interrupt-controller: true
+
+  interrupts-extended:
+    minItems: 1
+    maxItems: 4095
+
+  riscv,hart-indexes:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    maxItems: 16384
+    description:
+      A list of hart indexes that APLIC should use to address each hart
+      that is mentioned in the "interrupts-extended"
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - "#interrupt-cells"
+  - interrupt-controller
+  - interrupts-extended
+
+examples:
+  - |
+    //Example 1
+    interrupt-controller@94000000 {
+      compatible = "sophgo,sg2044-aclint-sswi", "thead,c900-aclint-sswi";
+      reg = <0x94000000 0x00004000>;
+      #interrupt-cells = <0>;
+      interrupt-controller;
+      interrupts-extended = <&cpu1intc 1>,
+                            <&cpu2intc 1>,
+                            <&cpu3intc 1>,
+                            <&cpu4intc 1>;
+    };
+
+  - |
+    //Example 2
+    interrupt-controller@94000000 {
+      compatible = "riscv,aclint-sswi";
+      reg = <0x94000000 0x00004000>;
+      #interrupt-cells = <0>;
+      interrupt-controller;
+      interrupts-extended = <&cpu1intc 1>,
+                            <&cpu2intc 1>,
+                            <&cpu3intc 1>,
+                            <&cpu4intc 1>;
+      riscv,hart-indexes = <0 1 0x10 0x11>;
+    };
+
+...
diff --git a/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml b/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
deleted file mode 100644
index 8d330906bbbd..000000000000
--- a/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
+++ /dev/null
@@ -1,58 +0,0 @@
-# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
-%YAML 1.2
----
-$id: http://devicetree.org/schemas/interrupt-controller/thead,c900-aclint-sswi.yaml#
-$schema: http://devicetree.org/meta-schemas/core.yaml#
-
-title: T-HEAD C900 ACLINT Supervisor-level Software Interrupt Device
-
-maintainers:
-  - Inochi Amaoto <inochiama@outlook.com>
-
-description:
-  The SSWI device is a part of the THEAD ACLINT device. It provides
-  supervisor-level IPI functionality for a set of HARTs on a THEAD
-  platform. It provides a register to set an IPI (SETSSIP) for each
-  HART connected to the SSWI device.
-
-properties:
-  compatible:
-    items:
-      - enum:
-          - sophgo,sg2044-aclint-sswi
-      - const: thead,c900-aclint-sswi
-
-  reg:
-    maxItems: 1
-
-  "#interrupt-cells":
-    const: 0
-
-  interrupt-controller: true
-
-  interrupts-extended:
-    minItems: 1
-    maxItems: 4095
-
-additionalProperties: false
-
-required:
-  - compatible
-  - reg
-  - "#interrupt-cells"
-  - interrupt-controller
-  - interrupts-extended
-
-examples:
-  - |
-    interrupt-controller@94000000 {
-      compatible = "sophgo,sg2044-aclint-sswi", "thead,c900-aclint-sswi";
-      reg = <0x94000000 0x00004000>;
-      #interrupt-cells = <0>;
-      interrupt-controller;
-      interrupts-extended = <&cpu1intc 1>,
-                            <&cpu2intc 1>,
-                            <&cpu3intc 1>,
-                            <&cpu4intc 1>;
-    };
-...
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v1 4/7] irqchip: introduce generic Risc-V aclint-sswi
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
                   ` (2 preceding siblings ...)
  2025-06-09 13:47 ` [PATCH v1 3/7] dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi Vladimir Kondratiev
@ 2025-06-09 13:47 ` Vladimir Kondratiev
  2025-06-09 13:47 ` [PATCH v1 5/7] irqchip: aslint-sswi: resolve hart index Vladimir Kondratiev
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Refactor Thead specific implementation of the ACLINT-SSWI
irqchip, providing generic one, according to the Risc-V spec [1]

Preserve Thead-specific version, do it as a customized
variant of the generic one.

Link: https://github.com/riscvarchive/riscv-aclint [1]

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/Kconfig                       | 12 +++
 drivers/irqchip/Makefile                      |  2 +-
 ...d-c900-aclint-sswi.c => irq-aclint-sswi.c} | 91 +++++++++++++------
 3 files changed, 76 insertions(+), 29 deletions(-)
 rename drivers/irqchip/{irq-thead-c900-aclint-sswi.c => irq-aclint-sswi.c} (68%)

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 0d196e447142..c1132dad238e 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -634,12 +634,24 @@ config STARFIVE_JH8100_INTC
 
 	  If you don't know what to do here, say Y.
 
+config RISCV_ACLINT_SSWI
+	bool "RISC-V ACLINT S-mode IPI Interrupt Controller"
+	depends on RISCV
+	depends on SMP
+	select IRQ_DOMAIN_HIERARCHY
+	select GENERIC_IRQ_IPI_MUX
+	help
+	  This enables support for generic ACLINT SSWI device
+
+	  If you don't know what to do here, say Y.
+
 config THEAD_C900_ACLINT_SSWI
 	bool "THEAD C9XX ACLINT S-mode IPI Interrupt Controller"
 	depends on RISCV
 	depends on SMP
 	select IRQ_DOMAIN_HIERARCHY
 	select GENERIC_IRQ_IPI_MUX
+	select RISCV_ACLINT_SSWI
 	help
 	  This enables support for T-HEAD specific ACLINT SSWI device
 	  support.
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 23ca4959e6ce..1168ec92376e 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -105,7 +105,7 @@ obj-$(CONFIG_RISCV_APLIC_MSI)		+= irq-riscv-aplic-msi.o
 obj-$(CONFIG_RISCV_IMSIC)		+= irq-riscv-imsic-state.o irq-riscv-imsic-early.o irq-riscv-imsic-platform.o
 obj-$(CONFIG_SIFIVE_PLIC)		+= irq-sifive-plic.o
 obj-$(CONFIG_STARFIVE_JH8100_INTC)	+= irq-starfive-jh8100-intc.o
-obj-$(CONFIG_THEAD_C900_ACLINT_SSWI)	+= irq-thead-c900-aclint-sswi.o
+obj-$(CONFIG_RISCV_ACLINT_SSWI)		+= irq-aclint-sswi.o
 obj-$(CONFIG_IMX_IRQSTEER)		+= irq-imx-irqsteer.o
 obj-$(CONFIG_IMX_INTMUX)		+= irq-imx-intmux.o
 obj-$(CONFIG_IMX_MU_MSI)		+= irq-imx-mu-msi.o
diff --git a/drivers/irqchip/irq-thead-c900-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
similarity index 68%
rename from drivers/irqchip/irq-thead-c900-aclint-sswi.c
rename to drivers/irqchip/irq-aclint-sswi.c
index 8ff6e7a1363b..dfba34f712ff 100644
--- a/drivers/irqchip/irq-thead-c900-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -3,7 +3,7 @@
  * Copyright (C) 2024 Inochi Amaoto <inochiama@gmail.com>
  */
 
-#define pr_fmt(fmt) "thead-c900-aclint-sswi: " fmt
+#define pr_fmt(fmt) "aclint-sswi: " fmt
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -21,56 +21,51 @@
 #include <asm/sbi.h>
 #include <asm/vendorid_list.h>
 
-#define THEAD_ACLINT_xSWI_REGISTER_SIZE		4
-
-#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
-#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
-
 static int sswi_ipi_virq __ro_after_init;
 static DEFINE_PER_CPU(void __iomem *, sswi_cpu_regs);
 
-static void thead_aclint_sswi_ipi_send(unsigned int cpu)
+static void aclint_sswi_ipi_send(unsigned int cpu)
 {
 	writel(0x1, per_cpu(sswi_cpu_regs, cpu));
 }
 
-static void thead_aclint_sswi_ipi_clear(void)
+static void aclint_sswi_ipi_clear(void)
 {
 	writel_relaxed(0x0, this_cpu_read(sswi_cpu_regs));
 }
 
-static void thead_aclint_sswi_ipi_handle(struct irq_desc *desc)
+static void aclint_sswi_ipi_handle(struct irq_desc *desc)
 {
 	struct irq_chip *chip = irq_desc_get_chip(desc);
 
 	chained_irq_enter(chip, desc);
 
 	csr_clear(CSR_IP, IE_SIE);
-	thead_aclint_sswi_ipi_clear();
+	aclint_sswi_ipi_clear();
 
 	ipi_mux_process();
 
 	chained_irq_exit(chip, desc);
 }
 
-static int thead_aclint_sswi_starting_cpu(unsigned int cpu)
+static int aclint_sswi_starting_cpu(unsigned int cpu)
 {
 	enable_percpu_irq(sswi_ipi_virq, irq_get_trigger_type(sswi_ipi_virq));
 
 	return 0;
 }
 
-static int thead_aclint_sswi_dying_cpu(unsigned int cpu)
+static int aclint_sswi_dying_cpu(unsigned int cpu)
 {
-	thead_aclint_sswi_ipi_clear();
+	aclint_sswi_ipi_clear();
 
 	disable_percpu_irq(sswi_ipi_virq);
 
 	return 0;
 }
 
-static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
-					      void __iomem *reg)
+static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
+					void __iomem *reg)
 {
 	struct of_phandle_args parent;
 	unsigned long hartid;
@@ -97,7 +92,7 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 
 		cpu = riscv_hartid_to_cpuid(hartid);
 
-		per_cpu(sswi_cpu_regs, cpu) = reg + i * THEAD_ACLINT_xSWI_REGISTER_SIZE;
+		per_cpu(sswi_cpu_regs, cpu) = reg + hart_index * 4;
 	}
 
 	pr_info("%pfwP: register %u CPU%s\n", fwnode, contexts, str_plural(contexts));
@@ -105,17 +100,12 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 	return 0;
 }
 
-static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
+static int __init aclint_sswi_probe(struct fwnode_handle *fwnode)
 {
 	struct irq_domain *domain;
 	void __iomem *reg;
 	int virq, rc;
 
-	/* If it is T-HEAD CPU, check whether SSWI is enabled */
-	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
-	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
-		return -ENOTSUPP;
-
 	if (!is_of_node(fwnode))
 		return -EINVAL;
 
@@ -124,7 +114,7 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
 		return -ENOMEM;
 
 	/* Parse SSWI setting */
-	rc = thead_aclint_sswi_parse_irq(fwnode, reg);
+	rc = aclint_sswi_parse_irq(fwnode, reg);
 	if (rc < 0)
 		return rc;
 
@@ -146,22 +136,66 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
 	}
 
 	/* Register SSWI irq and handler */
-	virq = ipi_mux_create(BITS_PER_BYTE, thead_aclint_sswi_ipi_send);
+	virq = ipi_mux_create(BITS_PER_BYTE, aclint_sswi_ipi_send);
 	if (virq <= 0) {
 		pr_err("unable to create muxed IPIs\n");
 		irq_dispose_mapping(sswi_ipi_virq);
 		return virq < 0 ? virq : -ENOMEM;
 	}
 
-	irq_set_chained_handler(sswi_ipi_virq, thead_aclint_sswi_ipi_handle);
+	irq_set_chained_handler(sswi_ipi_virq, aclint_sswi_ipi_handle);
 
 	cpuhp_setup_state(CPUHP_AP_IRQ_THEAD_ACLINT_SSWI_STARTING,
-			  "irqchip/thead-aclint-sswi:starting",
-			  thead_aclint_sswi_starting_cpu,
-			  thead_aclint_sswi_dying_cpu);
+			  "irqchip/aclint-sswi:starting",
+			  aclint_sswi_starting_cpu,
+			  aclint_sswi_dying_cpu);
 
 	riscv_ipi_set_virq_range(virq, BITS_PER_BYTE);
 
+	return 0;
+}
+
+/* generic variant */
+static int __init generic_aclint_sswi_probe(struct fwnode_handle *fwnode)
+{
+	int rc;
+
+	rc = aclint_sswi_probe(fwnode);
+	if (rc)
+		return rc;
+
+	/* Announce that SSWI is providing IPIs */
+	pr_info("providing IPIs using ACLINT SSWI\n");
+
+	return 0;
+}
+
+static int __init generic_aclint_sswi_early_probe(struct device_node *node,
+						  struct device_node *parent)
+{
+	return generic_aclint_sswi_probe(&node->fwnode);
+}
+IRQCHIP_DECLARE(generic_aclint_sswi, "riscv,aclint-sswi", generic_aclint_sswi_early_probe);
+
+#if defined(CONFIG_THEAD_C900_ACLINT_SSWI)
+
+#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
+#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
+
+/* THEAD variant */
+static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
+{
+	int rc;
+
+	/* If it is T-HEAD CPU, check whether SSWI is enabled */
+	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
+	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
+		return -ENOTSUPP;
+
+	rc = aclint_sswi_probe(fwnode);
+	if (rc)
+		return rc;
+
 	/* Announce that SSWI is providing IPIs */
 	pr_info("providing IPIs using THEAD ACLINT SSWI\n");
 
@@ -174,3 +208,4 @@ static int __init thead_aclint_sswi_early_probe(struct device_node *node,
 	return thead_aclint_sswi_probe(&node->fwnode);
 }
 IRQCHIP_DECLARE(thead_aclint_sswi, "thead,c900-aclint-sswi", thead_aclint_sswi_early_probe);
+#endif /* CONFIG_THEAD_C900_ACLINT_SSWI */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v1 5/7] irqchip: aslint-sswi: resolve hart index
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
                   ` (3 preceding siblings ...)
  2025-06-09 13:47 ` [PATCH v1 4/7] irqchip: introduce generic Risc-V aclint-sswi Vladimir Kondratiev
@ 2025-06-09 13:47 ` Vladimir Kondratiev
  2025-06-09 13:47 ` [PATCH v1 6/7] irqchip: aclint-sswi: reduce data scope Vladimir Kondratiev
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Resolve hart index according to assignment in the
"riscv,hart-indexes" property as defined in [1]

Link: https://github.com/riscvarchive/riscv-aclint [1]
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index dfba34f712ff..7ff43f685e92 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -71,6 +71,7 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 	unsigned long hartid;
 	u32 contexts, i;
 	int rc, cpu;
+	u32 hart_index;
 
 	contexts = of_irq_count(to_of_node(fwnode));
 	if (!(contexts)) {
@@ -92,6 +93,11 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 
 		cpu = riscv_hartid_to_cpuid(hartid);
 
+		rc = riscv_get_hart_index(fwnode, i, &hart_index);
+		if (rc) {
+			pr_warn("%pfwP: hart index [%d] not found\n", fwnode, i);
+			return -EINVAL;
+		}
 		per_cpu(sswi_cpu_regs, cpu) = reg + hart_index * 4;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v1 6/7] irqchip: aclint-sswi: reduce data scope
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
                   ` (4 preceding siblings ...)
  2025-06-09 13:47 ` [PATCH v1 5/7] irqchip: aslint-sswi: resolve hart index Vladimir Kondratiev
@ 2025-06-09 13:47 ` Vladimir Kondratiev
  2025-06-09 13:47 ` [PATCH v1 7/7] irqchip: aclint-sswi: remove extra includes Vladimir Kondratiev
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Move variables to the innermost scope where it is used

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index 7ff43f685e92..92237fb44855 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -67,11 +67,7 @@ static int aclint_sswi_dying_cpu(unsigned int cpu)
 static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 					void __iomem *reg)
 {
-	struct of_phandle_args parent;
-	unsigned long hartid;
-	u32 contexts, i;
-	int rc, cpu;
-	u32 hart_index;
+	u32 contexts;
 
 	contexts = of_irq_count(to_of_node(fwnode));
 	if (!(contexts)) {
@@ -79,7 +75,12 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 		return -EINVAL;
 	}
 
-	for (i = 0; i < contexts; i++) {
+	for (u32 i = 0; i < contexts; i++) {
+		struct of_phandle_args parent;
+		unsigned long hartid;
+		int rc, cpu;
+		u32 hart_index;
+
 		rc = of_irq_parse_one(to_of_node(fwnode), i, &parent);
 		if (rc)
 			return rc;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v1 7/7] irqchip: aclint-sswi: remove extra includes
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
                   ` (5 preceding siblings ...)
  2025-06-09 13:47 ` [PATCH v1 6/7] irqchip: aclint-sswi: reduce data scope Vladimir Kondratiev
@ 2025-06-09 13:47 ` Vladimir Kondratiev
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
  8 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-09 13:47 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index 92237fb44855..9c0f75df6e8e 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -6,15 +6,9 @@
 #define pr_fmt(fmt) "aclint-sswi: " fmt
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/irq.h>
 #include <linux/irqchip.h>
 #include <linux/irqchip/chained_irq.h>
-#include <linux/module.h>
-#include <linux/of.h>
 #include <linux/of_address.h>
-#include <linux/of_irq.h>
-#include <linux/pci.h>
 #include <linux/spinlock.h>
 #include <linux/smp.h>
 #include <linux/string_choices.h>
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH v1 3/7] dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi
  2025-06-09 13:47 ` [PATCH v1 3/7] dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi Vladimir Kondratiev
@ 2025-06-09 16:01   ` Conor Dooley
  2025-06-10  9:55     ` Vladimir Kondratiev
  0 siblings, 1 reply; 38+ messages in thread
From: Conor Dooley @ 2025-06-09 16:01 UTC (permalink / raw)
  To: Vladimir Kondratiev
  Cc: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura, linux-kernel, devicetree,
	linux-riscv, sophgo

[-- Attachment #1: Type: text/plain, Size: 4261 bytes --]

On Mon, Jun 09, 2025 at 04:47:45PM +0300, Vladimir Kondratiev wrote:
> Add generic, Risc-V spec compliant (see [1]) aclint-sswi binding
> 
> Thead specific binding preserved, and converted to variant of the
> generic aclint-sswi
> 
> Link: https://github.com/riscvarchive/riscv-aclint [1]

What is the ratification status of this spec?

> 
> Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
> ---
>  .../riscv,aclint-sswi.yaml                    | 89 +++++++++++++++++++
>  .../thead,c900-aclint-sswi.yaml               | 58 ------------
>  2 files changed, 89 insertions(+), 58 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml
>  delete mode 100644 Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
> 
> diff --git a/Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml b/Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml
> new file mode 100644
> index 000000000000..cffddfcfcfea
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/interrupt-controller/riscv,aclint-sswi.yaml
> @@ -0,0 +1,89 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/interrupt-controller/riscv,aclint-sswi.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Risc-V ACLINT Supervisor-level Software Interrupt Device

s/Risc-V/RISC-V/g

> +
> +maintainers:
> +  - Inochi Amaoto <inochiama@outlook.com>
> +
> +description:
> +  The SSWI device is a part of the Risc-V ACLINT device. It provides
> +  supervisor-level IPI functionality for a set of HARTs on a THEAD
> +  platform. It provides a register to set an IPI (SETSSIP) for each
> +  HART connected to the SSWI device. See specification
> +  https://github.com/riscvarchive/riscv-aclint
> +
> +  T-HEAD C900 ACLINT is a variant of the ACLINT, using dedicated
> +  compatible string
> +
> +properties:
> +  compatible:
> +    oneOf:
> +      - items:
> +          - enum:
> +              - sophgo,sg2044-aclint-sswi
> +          - const: thead,c900-aclint-sswi
> +      - items:
> +          - const: riscv,aclint-sswi

You need a specific compatible for your implementation.
Whether or not this compatible is viable depends on the answer to the
ratification status and/or plan for the spec.

> +
> +  reg:
> +    maxItems: 1
> +
> +  "#interrupt-cells":
> +    const: 0
> +
> +  interrupt-controller: true
> +
> +  interrupts-extended:
> +    minItems: 1
> +    maxItems: 4095
> +
> +  riscv,hart-indexes:
> +    $ref: /schemas/types.yaml#/definitions/uint32-array
> +    minItems: 1
> +    maxItems: 16384

maxItems is 4x what is allowed for interrupts-extended. Why?

> +    description:
> +      A list of hart indexes that APLIC should use to address each hart
> +      that is mentioned in the "interrupts-extended"

Please constrain this property to only be permitted on !thead.

> +
> +additionalProperties: false
> +
> +required:
> +  - compatible
> +  - reg
> +  - "#interrupt-cells"
> +  - interrupt-controller
> +  - interrupts-extended
> +
> +examples:
> +  - |
> +    //Example 1
> +    interrupt-controller@94000000 {
> +      compatible = "sophgo,sg2044-aclint-sswi", "thead,c900-aclint-sswi";
> +      reg = <0x94000000 0x00004000>;
> +      #interrupt-cells = <0>;
> +      interrupt-controller;
> +      interrupts-extended = <&cpu1intc 1>,
> +                            <&cpu2intc 1>,
> +                            <&cpu3intc 1>,
> +                            <&cpu4intc 1>;
> +    };
> +
> +  - |
> +    //Example 2
> +    interrupt-controller@94000000 {
> +      compatible = "riscv,aclint-sswi";
> +      reg = <0x94000000 0x00004000>;
> +      #interrupt-cells = <0>;
> +      interrupt-controller;
> +      interrupts-extended = <&cpu1intc 1>,
> +                            <&cpu2intc 1>,
> +                            <&cpu3intc 1>,
> +                            <&cpu4intc 1>;
> +      riscv,hart-indexes = <0 1 0x10 0x11>;

Please be consistent. Hex or decimal, but not both.

Cheers,
Conor.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v1 3/7] dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi
  2025-06-09 16:01   ` Conor Dooley
@ 2025-06-10  9:55     ` Vladimir Kondratiev
  0 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10  9:55 UTC (permalink / raw)
  To: Conor Dooley
  Cc: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, linux-riscv@lists.infradead.org,
	sophgo@lists.linux.dev

>> Link: https://github.com/riscvarchive/riscv-aclint [1]
>What is the ratification status of this spec?

This spec is in a "draft" state, and perspective for its ratification is unclear.
So I understand I can't use "riscv," prefixes, I will convert it to adding
platform-specific variant of the SSWI, and submit v2.

>s/Risc-V/RISC-V/g

Yes sure

>> +    oneOf:
>> +      - items:
>> +          - enum:
>> +              - sophgo,sg2044-aclint-sswi
>> +          - const: thead,c900-aclint-sswi
>> +      - items:
>> +          - const: riscv,aclint-sswi
>You need a specific compatible for your implementation.

Yes, doing this

>Whether or not this compatible is viable depends on the answer to the
>ratification status and/or plan for the spec.

Replacing "riscv," compatible with platform-specific one

>> +  interrupts-extended:
>> +    minItems: 1
>> +    maxItems: 4095
>> +
>> +  riscv,hart-indexes:
>> +    $ref: /schemas/types.yaml#/definitions/uint32-array
>> +    minItems: 1
>> +    maxItems: 16384
>maxItems is 4x what is allowed for interrupts-extended. Why?

Fixing this. It was copied from the dt-bindings for the APLIC where
maxItems for "interrupts-extended" specified as 16384

>Please constrain this property to only be permitted on !thead.

Doing this

>> +      riscv,hart-indexes = <0 1 0x10 0x11>;
>Please be consistent. Hex or decimal, but not both.

Sure

Thanks, Vladimir

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
                   ` (6 preceding siblings ...)
  2025-06-09 13:47 ` [PATCH v1 7/7] irqchip: aclint-sswi: remove extra includes Vladimir Kondratiev
@ 2025-06-10 10:05 ` Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 1/7] riscv: helper to parse hart index Vladimir Kondratiev
                     ` (6 more replies)
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
  8 siblings, 7 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

RISC-V draft specification for the ACLINT IPI controller describes
an "SSWI" device that allows to send IPI by writing register from the
S-mode (Linux kernel), as opposed to the "MSWI" device that does the
same from the M-mode. Sending IPI through the M-mode requires extra
SBI call, SSWI is much faster.

Support for the SSWI exists for the Thead board, it is almost as by
specification save for reading one custom CSR.

Soon to be released Mobileye SoC based on the MIPS P8700 RISC-V CPU has
variant of the ACLINT SSWI device that follows the spec exactly.

To support P8700, refactor Thead implementation, factoring out
generic code that complies with the draft spec, and provide
Thead and MIPS specific variants.

In addition, MIPS P8700 uses non contiguous hart indexes, and thus
requires "riscv,hart-indexes" property.

Patches 1 and 2 refactor "hart index" support, replacing
APLIC specific implementation with generic helper

Patch 3 adds dt-bindings

Patch 4 refactors Thead-specific SSWI, adding MIPS variant

Patch 5 adds "riscv,hart-indexes" support

Patches 6 and 7 do some minor improvements for the SSWI

Changed from v1:
1. RISC-V spec for the ACLINT is in a draft state, then can't
use "riscv," prefix. Restcucture commits to add MIPS specific
ACLINT-SSWI variant instead.

Vladimir Kondratiev (7):
  riscv: helper to parse hart index
  irqchip: riscv aplic: use riscv_get_hart_index()
  dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi
  irqchip: MIPS P800 variant of aclint-sswi
  irqchip: aslint-sswi: resolve hart index
  irqchip: aclint-sswi: reduce data scope
  irqchip: aclint-sswi: remove extra includes

 .../thead,c900-aclint-sswi.yaml               |  64 ++++++++--
 arch/riscv/include/asm/irq.h                  |   2 +
 arch/riscv/kernel/irq.c                       |  34 +++++
 drivers/irqchip/Kconfig                       |  16 +++
 drivers/irqchip/Makefile                      |   2 +-
 ...d-c900-aclint-sswi.c => irq-aclint-sswi.c} | 116 ++++++++++++------
 drivers/irqchip/irq-riscv-aplic-direct.c      |  16 +--
 7 files changed, 186 insertions(+), 64 deletions(-)
 rename drivers/irqchip/{irq-thead-c900-aclint-sswi.c => irq-aclint-sswi.c} (62%)


base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
-- 
2.43.0


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH v2 1/7] riscv: helper to parse hart index
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
@ 2025-06-10 10:05   ` Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 2/7] irqchip: riscv aplic: use riscv_get_hart_index() Vladimir Kondratiev
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

RISC-V APLIC specification defines "hart index" in [1]
And similar definitions found for ACLINT in [2]

Quote from [1]:

Within a given interrupt domain, each of the domain’s harts has a unique
index number in the range 0 to 2^14 − 1 (= 16,383). The index number a
domain associates with a hart may or may not have any relationship to the
unique hart identifier (“hart ID”) that the RISC-V Privileged
Architecture assigns to the hart. Two different interrupt domains may
employ entirely different index numbers for the same set of harts.

Further, [1] says in "4.5 Memory-mapped control region for an
interrupt domain":

The array of IDC structures may include some for potential hart index
numbers that are not actual hart index numbers in the domain.
For example, the first IDC structure is always for hart index 0, but 0 is
not necessarily a valid index number for any hart in the domain.

Support arbitrary hart indices specified in an optional property
"riscv,hart-indexes" which is specified as an array of u32 elements, one
per interrupt target, listing hart indexes in the same order as in
"interrupts-extended". If this property is not specified, fallback to use
logical hart indices within the domain.

If property not exist, fall back to logical hart indexes

Link: https://github.com/riscv/riscv-aia [1]
Link: https://github.com/riscvarchive/riscv-aclint [2]
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 arch/riscv/include/asm/irq.h |  2 ++
 arch/riscv/kernel/irq.c      | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h
index 7b038f3b7cb0..59c975f750c9 100644
--- a/arch/riscv/include/asm/irq.h
+++ b/arch/riscv/include/asm/irq.h
@@ -22,6 +22,8 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu);
 void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));
 
 struct fwnode_handle *riscv_get_intc_hwnode(void);
+int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
+			 u32 *hart_index);
 
 #ifdef CONFIG_ACPI
 
diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c
index 9ceda02507ca..efdf505bb776 100644
--- a/arch/riscv/kernel/irq.c
+++ b/arch/riscv/kernel/irq.c
@@ -32,6 +32,40 @@ struct fwnode_handle *riscv_get_intc_hwnode(void)
 }
 EXPORT_SYMBOL_GPL(riscv_get_intc_hwnode);
 
+/**
+ * riscv_get_hart_index() - get hart index for interrupt delivery
+ * @fwnode: interrupt controller node
+ * @logical_index: index within the "interrupts-extended" property
+ * @hart_index: filled with the hart index to use
+ *
+ * RISC-V uses term "hart index" for its interrupt controllers, for the
+ * purpose of the interrupt routing to destination harts.
+ * It may be arbitrary numbers assigned to each destination hart in context
+ * of the particular interrupt domain.
+ *
+ * These numbers encoded in the optional property "riscv,hart-indexes"
+ * that should contain hart index for each interrupt destination in the same
+ * order as in the "interrupts-extended" property. If this property
+ * not exist, it assumed equal to the logical index, i.e. index within the
+ * "interrupts-extended" property.
+ *
+ * Return: error code
+ */
+int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
+			 u32 *hart_index)
+{
+	static const char *prop_hart_index = "riscv,hart-indexes";
+	struct device_node *np = to_of_node(fwnode);
+
+	if (!np || !of_property_present(np, prop_hart_index)) {
+		*hart_index = logical_index;
+		return 0;
+	}
+
+	return of_property_read_u32_index(np, prop_hart_index,
+					  logical_index, hart_index);
+}
+
 #ifdef CONFIG_IRQ_STACKS
 #include <asm/irq_stack.h>
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v2 2/7] irqchip: riscv aplic: use riscv_get_hart_index()
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 1/7] riscv: helper to parse hart index Vladimir Kondratiev
@ 2025-06-10 10:05   ` Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi Vladimir Kondratiev
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Use global helper function instead of the local
implementation

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-riscv-aplic-direct.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/irqchip/irq-riscv-aplic-direct.c b/drivers/irqchip/irq-riscv-aplic-direct.c
index 205ad61d15e4..c2a75bf3d20c 100644
--- a/drivers/irqchip/irq-riscv-aplic-direct.c
+++ b/drivers/irqchip/irq-riscv-aplic-direct.c
@@ -219,20 +219,6 @@ static int aplic_direct_parse_parent_hwirq(struct device *dev, u32 index,
 	return 0;
 }
 
-static int aplic_direct_get_hart_index(struct device *dev, u32 logical_index,
-				       u32 *hart_index)
-{
-	const char *prop_hart_index = "riscv,hart-indexes";
-	struct device_node *np = to_of_node(dev->fwnode);
-
-	if (!np || !of_property_present(np, prop_hart_index)) {
-		*hart_index = logical_index;
-		return 0;
-	}
-
-	return of_property_read_u32_index(np, prop_hart_index, logical_index, hart_index);
-}
-
 int aplic_direct_setup(struct device *dev, void __iomem *regs)
 {
 	int i, j, rc, cpu, current_cpu, setup_count = 0;
@@ -279,7 +265,7 @@ int aplic_direct_setup(struct device *dev, void __iomem *regs)
 		cpumask_set_cpu(cpu, &direct->lmask);
 
 		idc = per_cpu_ptr(&aplic_idcs, cpu);
-		rc = aplic_direct_get_hart_index(dev, i, &idc->hart_index);
+		rc = riscv_get_hart_index(dev->fwnode, i, &idc->hart_index);
 		if (rc) {
 			dev_warn(dev, "hart index not found for IDC%d\n", i);
 			continue;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v2 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 1/7] riscv: helper to parse hart index Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 2/7] irqchip: riscv aplic: use riscv_get_hart_index() Vladimir Kondratiev
@ 2025-06-10 10:05   ` Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Add ACLINT-SSWI variant for the MIPS P8700. This CPU has
SSWI device compliant with the RISC-V draft spec (see [1])
CPU indexes on this platform are not contiguous, instead
it uses bit-fields to encode hart,core,cluster numbers, thus
property "riscv,hart-indexes" is mandatory

Link: https://github.com/riscvarchive/riscv-aclint [1]

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 .../thead,c900-aclint-sswi.yaml               | 64 ++++++++++++++++---
 1 file changed, 55 insertions(+), 9 deletions(-)

diff --git a/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml b/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
index 8d330906bbbd..c1ab865fcd64 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
+++ b/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
@@ -4,23 +4,32 @@
 $id: http://devicetree.org/schemas/interrupt-controller/thead,c900-aclint-sswi.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: T-HEAD C900 ACLINT Supervisor-level Software Interrupt Device
+title: ACLINT Supervisor-level Software Interrupt Device
 
 maintainers:
   - Inochi Amaoto <inochiama@outlook.com>
 
 description:
-  The SSWI device is a part of the THEAD ACLINT device. It provides
-  supervisor-level IPI functionality for a set of HARTs on a THEAD
-  platform. It provides a register to set an IPI (SETSSIP) for each
-  HART connected to the SSWI device.
+  The SSWI device is a part of the ACLINT device. It provides
+  supervisor-level IPI functionality for a set of HARTs on a supported
+  platforms. It provides a register to set an IPI (SETSSIP) for each
+  HART connected to the SSWI device. See draft specification
+  https://github.com/riscvarchive/riscv-aclint
+
+  Following variants of the SSWI ACLINT supported, using dedicated
+  compatible string
+  - THEAD C900
+  - MIPS P8700
 
 properties:
   compatible:
-    items:
-      - enum:
-          - sophgo,sg2044-aclint-sswi
-      - const: thead,c900-aclint-sswi
+    oneOf:
+      - items:
+          - enum:
+              - sophgo,sg2044-aclint-sswi
+          - const: thead,c900-aclint-sswi
+      - items:
+          - const: mips,p8700-aclint-sswi
 
   reg:
     maxItems: 1
@@ -34,6 +43,14 @@ properties:
     minItems: 1
     maxItems: 4095
 
+  riscv,hart-indexes:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    maxItems: 4095
+    description:
+      A list of hart indexes that APLIC should use to address each hart
+      that is mentioned in the "interrupts-extended"
+
 additionalProperties: false
 
 required:
@@ -43,8 +60,22 @@ required:
   - interrupt-controller
   - interrupts-extended
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: mips,p8700-aclint-sswi
+    then:
+      required:
+        - riscv,hart-indexes
+    else:
+      properties:
+        riscv,hart-indexes: false
+
 examples:
   - |
+    //Example 1
     interrupt-controller@94000000 {
       compatible = "sophgo,sg2044-aclint-sswi", "thead,c900-aclint-sswi";
       reg = <0x94000000 0x00004000>;
@@ -55,4 +86,19 @@ examples:
                             <&cpu3intc 1>,
                             <&cpu4intc 1>;
     };
+
+  - |
+    //Example 2
+    interrupt-controller@94000000 {
+      compatible = "mips,p8700-aclint-sswi";
+      reg = <0x94000000 0x00004000>;
+      #interrupt-cells = <0>;
+      interrupt-controller;
+      interrupts-extended = <&cpu1intc 1>,
+                            <&cpu2intc 1>,
+                            <&cpu3intc 1>,
+                            <&cpu4intc 1>;
+      riscv,hart-indexes = <0x0 0x1 0x10 0x11>;
+    };
+
 ...
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (2 preceding siblings ...)
  2025-06-10 10:05   ` [PATCH v2 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi Vladimir Kondratiev
@ 2025-06-10 10:05   ` Vladimir Kondratiev
  2025-06-10 10:09     ` Inochi Amaoto
  2025-06-12 13:03     ` Thomas Gleixner
  2025-06-10 10:05   ` [PATCH v2 5/7] irqchip: aslint-sswi: resolve hart index Vladimir Kondratiev
                     ` (2 subsequent siblings)
  6 siblings, 2 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Refactor Thead specific implementation of the ACLINT-SSWI irqchip.
Factor out generic code that serves both Thead and MIPS variants.
This generic part is according to the RISC-V draft spec [1].

Link: https://github.com/riscvarchive/riscv-aclint [1]

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/Kconfig                       | 16 ++++
 drivers/irqchip/Makefile                      |  2 +-
 ...d-c900-aclint-sswi.c => irq-aclint-sswi.c} | 93 +++++++++++++------
 3 files changed, 82 insertions(+), 29 deletions(-)
 rename drivers/irqchip/{irq-thead-c900-aclint-sswi.c => irq-aclint-sswi.c} (67%)

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 0d196e447142..be9b54900482 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -634,12 +634,28 @@ config STARFIVE_JH8100_INTC
 
 	  If you don't know what to do here, say Y.
 
+config ACLINT_SSWI
+	bool
+
+config MIPS_P8700_ACLINT_SSWI
+	bool "MIPS P8700 ACLINT S-mode IPI Interrupt Controller"
+	depends on RISCV
+	depends on SMP
+	select IRQ_DOMAIN_HIERARCHY
+	select GENERIC_IRQ_IPI_MUX
+	select ACLINT_SSWI
+	help
+	  This enables support for MIPS P8700 specific ACLINT SSWI device
+
+	  If you don't know what to do here, say Y.
+
 config THEAD_C900_ACLINT_SSWI
 	bool "THEAD C9XX ACLINT S-mode IPI Interrupt Controller"
 	depends on RISCV
 	depends on SMP
 	select IRQ_DOMAIN_HIERARCHY
 	select GENERIC_IRQ_IPI_MUX
+	select ACLINT_SSWI
 	help
 	  This enables support for T-HEAD specific ACLINT SSWI device
 	  support.
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 23ca4959e6ce..0458d6c5d161 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -105,7 +105,7 @@ obj-$(CONFIG_RISCV_APLIC_MSI)		+= irq-riscv-aplic-msi.o
 obj-$(CONFIG_RISCV_IMSIC)		+= irq-riscv-imsic-state.o irq-riscv-imsic-early.o irq-riscv-imsic-platform.o
 obj-$(CONFIG_SIFIVE_PLIC)		+= irq-sifive-plic.o
 obj-$(CONFIG_STARFIVE_JH8100_INTC)	+= irq-starfive-jh8100-intc.o
-obj-$(CONFIG_THEAD_C900_ACLINT_SSWI)	+= irq-thead-c900-aclint-sswi.o
+obj-$(CONFIG_ACLINT_SSWI)		+= irq-aclint-sswi.o
 obj-$(CONFIG_IMX_IRQSTEER)		+= irq-imx-irqsteer.o
 obj-$(CONFIG_IMX_INTMUX)		+= irq-imx-intmux.o
 obj-$(CONFIG_IMX_MU_MSI)		+= irq-imx-mu-msi.o
diff --git a/drivers/irqchip/irq-thead-c900-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
similarity index 67%
rename from drivers/irqchip/irq-thead-c900-aclint-sswi.c
rename to drivers/irqchip/irq-aclint-sswi.c
index 8ff6e7a1363b..ec21785df518 100644
--- a/drivers/irqchip/irq-thead-c900-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -3,7 +3,7 @@
  * Copyright (C) 2024 Inochi Amaoto <inochiama@gmail.com>
  */
 
-#define pr_fmt(fmt) "thead-c900-aclint-sswi: " fmt
+#define pr_fmt(fmt) "aclint-sswi: " fmt
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -21,56 +21,51 @@
 #include <asm/sbi.h>
 #include <asm/vendorid_list.h>
 
-#define THEAD_ACLINT_xSWI_REGISTER_SIZE		4
-
-#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
-#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
-
 static int sswi_ipi_virq __ro_after_init;
 static DEFINE_PER_CPU(void __iomem *, sswi_cpu_regs);
 
-static void thead_aclint_sswi_ipi_send(unsigned int cpu)
+static void aclint_sswi_ipi_send(unsigned int cpu)
 {
 	writel(0x1, per_cpu(sswi_cpu_regs, cpu));
 }
 
-static void thead_aclint_sswi_ipi_clear(void)
+static void aclint_sswi_ipi_clear(void)
 {
 	writel_relaxed(0x0, this_cpu_read(sswi_cpu_regs));
 }
 
-static void thead_aclint_sswi_ipi_handle(struct irq_desc *desc)
+static void aclint_sswi_ipi_handle(struct irq_desc *desc)
 {
 	struct irq_chip *chip = irq_desc_get_chip(desc);
 
 	chained_irq_enter(chip, desc);
 
 	csr_clear(CSR_IP, IE_SIE);
-	thead_aclint_sswi_ipi_clear();
+	aclint_sswi_ipi_clear();
 
 	ipi_mux_process();
 
 	chained_irq_exit(chip, desc);
 }
 
-static int thead_aclint_sswi_starting_cpu(unsigned int cpu)
+static int aclint_sswi_starting_cpu(unsigned int cpu)
 {
 	enable_percpu_irq(sswi_ipi_virq, irq_get_trigger_type(sswi_ipi_virq));
 
 	return 0;
 }
 
-static int thead_aclint_sswi_dying_cpu(unsigned int cpu)
+static int aclint_sswi_dying_cpu(unsigned int cpu)
 {
-	thead_aclint_sswi_ipi_clear();
+	aclint_sswi_ipi_clear();
 
 	disable_percpu_irq(sswi_ipi_virq);
 
 	return 0;
 }
 
-static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
-					      void __iomem *reg)
+static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
+					void __iomem *reg)
 {
 	struct of_phandle_args parent;
 	unsigned long hartid;
@@ -97,7 +92,7 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 
 		cpu = riscv_hartid_to_cpuid(hartid);
 
-		per_cpu(sswi_cpu_regs, cpu) = reg + i * THEAD_ACLINT_xSWI_REGISTER_SIZE;
+		per_cpu(sswi_cpu_regs, cpu) = reg + hart_index * 4;
 	}
 
 	pr_info("%pfwP: register %u CPU%s\n", fwnode, contexts, str_plural(contexts));
@@ -105,17 +100,12 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 	return 0;
 }
 
-static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
+static int __init aclint_sswi_probe(struct fwnode_handle *fwnode)
 {
 	struct irq_domain *domain;
 	void __iomem *reg;
 	int virq, rc;
 
-	/* If it is T-HEAD CPU, check whether SSWI is enabled */
-	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
-	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
-		return -ENOTSUPP;
-
 	if (!is_of_node(fwnode))
 		return -EINVAL;
 
@@ -124,7 +114,7 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
 		return -ENOMEM;
 
 	/* Parse SSWI setting */
-	rc = thead_aclint_sswi_parse_irq(fwnode, reg);
+	rc = aclint_sswi_parse_irq(fwnode, reg);
 	if (rc < 0)
 		return rc;
 
@@ -146,22 +136,68 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
 	}
 
 	/* Register SSWI irq and handler */
-	virq = ipi_mux_create(BITS_PER_BYTE, thead_aclint_sswi_ipi_send);
+	virq = ipi_mux_create(BITS_PER_BYTE, aclint_sswi_ipi_send);
 	if (virq <= 0) {
 		pr_err("unable to create muxed IPIs\n");
 		irq_dispose_mapping(sswi_ipi_virq);
 		return virq < 0 ? virq : -ENOMEM;
 	}
 
-	irq_set_chained_handler(sswi_ipi_virq, thead_aclint_sswi_ipi_handle);
+	irq_set_chained_handler(sswi_ipi_virq, aclint_sswi_ipi_handle);
 
 	cpuhp_setup_state(CPUHP_AP_IRQ_THEAD_ACLINT_SSWI_STARTING,
-			  "irqchip/thead-aclint-sswi:starting",
-			  thead_aclint_sswi_starting_cpu,
-			  thead_aclint_sswi_dying_cpu);
+			  "irqchip/aclint-sswi:starting",
+			  aclint_sswi_starting_cpu,
+			  aclint_sswi_dying_cpu);
 
 	riscv_ipi_set_virq_range(virq, BITS_PER_BYTE);
 
+	return 0;
+}
+
+#if defined(CONFIG_MIPS_P8700_ACLINT_SSWI)
+/* generic/MIPS variant */
+static int __init generic_aclint_sswi_probe(struct fwnode_handle *fwnode)
+{
+	int rc;
+
+	rc = aclint_sswi_probe(fwnode);
+	if (rc)
+		return rc;
+
+	/* Announce that SSWI is providing IPIs */
+	pr_info("providing IPIs using ACLINT SSWI\n");
+
+	return 0;
+}
+
+static int __init generic_aclint_sswi_early_probe(struct device_node *node,
+						  struct device_node *parent)
+{
+	return generic_aclint_sswi_probe(&node->fwnode);
+}
+IRQCHIP_DECLARE(generic_aclint_sswi, "mips,p8700-aclint-sswi", generic_aclint_sswi_early_probe);
+#endif /* CONFIG_MIPS_P8700_ACLINT_SSWI */
+
+#if defined(CONFIG_THEAD_C900_ACLINT_SSWI)
+
+#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
+#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
+
+/* THEAD variant */
+static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
+{
+	int rc;
+
+	/* If it is T-HEAD CPU, check whether SSWI is enabled */
+	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
+	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
+		return -ENOTSUPP;
+
+	rc = aclint_sswi_probe(fwnode);
+	if (rc)
+		return rc;
+
 	/* Announce that SSWI is providing IPIs */
 	pr_info("providing IPIs using THEAD ACLINT SSWI\n");
 
@@ -174,3 +210,4 @@ static int __init thead_aclint_sswi_early_probe(struct device_node *node,
 	return thead_aclint_sswi_probe(&node->fwnode);
 }
 IRQCHIP_DECLARE(thead_aclint_sswi, "thead,c900-aclint-sswi", thead_aclint_sswi_early_probe);
+#endif /* CONFIG_THEAD_C900_ACLINT_SSWI */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v2 5/7] irqchip: aslint-sswi: resolve hart index
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (3 preceding siblings ...)
  2025-06-10 10:05   ` [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
@ 2025-06-10 10:05   ` Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 6/7] irqchip: aclint-sswi: reduce data scope Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 7/7] irqchip: aclint-sswi: remove extra includes Vladimir Kondratiev
  6 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Resolve hart index according to assignment in the
"riscv,hart-indexes" property as defined in [1]

Link: https://github.com/riscvarchive/riscv-aclint [1]
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index ec21785df518..186a021beaef 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -71,6 +71,7 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 	unsigned long hartid;
 	u32 contexts, i;
 	int rc, cpu;
+	u32 hart_index;
 
 	contexts = of_irq_count(to_of_node(fwnode));
 	if (!(contexts)) {
@@ -92,6 +93,11 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 
 		cpu = riscv_hartid_to_cpuid(hartid);
 
+		rc = riscv_get_hart_index(fwnode, i, &hart_index);
+		if (rc) {
+			pr_warn("%pfwP: hart index [%d] not found\n", fwnode, i);
+			return -EINVAL;
+		}
 		per_cpu(sswi_cpu_regs, cpu) = reg + hart_index * 4;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v2 6/7] irqchip: aclint-sswi: reduce data scope
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (4 preceding siblings ...)
  2025-06-10 10:05   ` [PATCH v2 5/7] irqchip: aslint-sswi: resolve hart index Vladimir Kondratiev
@ 2025-06-10 10:05   ` Vladimir Kondratiev
  2025-06-10 10:05   ` [PATCH v2 7/7] irqchip: aclint-sswi: remove extra includes Vladimir Kondratiev
  6 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Move variables to the innermost scope where it is used

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index 186a021beaef..3aa074004dca 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -67,11 +67,7 @@ static int aclint_sswi_dying_cpu(unsigned int cpu)
 static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 					void __iomem *reg)
 {
-	struct of_phandle_args parent;
-	unsigned long hartid;
-	u32 contexts, i;
-	int rc, cpu;
-	u32 hart_index;
+	u32 contexts;
 
 	contexts = of_irq_count(to_of_node(fwnode));
 	if (!(contexts)) {
@@ -79,7 +75,12 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 		return -EINVAL;
 	}
 
-	for (i = 0; i < contexts; i++) {
+	for (u32 i = 0; i < contexts; i++) {
+		struct of_phandle_args parent;
+		unsigned long hartid;
+		int rc, cpu;
+		u32 hart_index;
+
 		rc = of_irq_parse_one(to_of_node(fwnode), i, &parent);
 		if (rc)
 			return rc;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v2 7/7] irqchip: aclint-sswi: remove extra includes
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (5 preceding siblings ...)
  2025-06-10 10:05   ` [PATCH v2 6/7] irqchip: aclint-sswi: reduce data scope Vladimir Kondratiev
@ 2025-06-10 10:05   ` Vladimir Kondratiev
  6 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:05 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index 3aa074004dca..dc437a4f82db 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -6,15 +6,9 @@
 #define pr_fmt(fmt) "aclint-sswi: " fmt
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/irq.h>
 #include <linux/irqchip.h>
 #include <linux/irqchip/chained_irq.h>
-#include <linux/module.h>
-#include <linux/of.h>
 #include <linux/of_address.h>
-#include <linux/of_irq.h>
-#include <linux/pci.h>
 #include <linux/spinlock.h>
 #include <linux/smp.h>
 #include <linux/string_choices.h>
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-10 10:05   ` [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
@ 2025-06-10 10:09     ` Inochi Amaoto
  2025-06-10 10:46       ` Vladimir Kondratiev
  2025-06-12 13:03     ` Thomas Gleixner
  1 sibling, 1 reply; 38+ messages in thread
From: Inochi Amaoto @ 2025-06-10 10:09 UTC (permalink / raw)
  To: Vladimir Kondratiev, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Anup Patel, Chen Wang, Inochi Amaoto,
	Sunil V L, Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo

On Tue, Jun 10, 2025 at 01:05:37PM +0300, Vladimir Kondratiev wrote:
> Refactor Thead specific implementation of the ACLINT-SSWI irqchip.
> Factor out generic code that serves both Thead and MIPS variants.
> This generic part is according to the RISC-V draft spec [1].
> 
> Link: https://github.com/riscvarchive/riscv-aclint [1]
> 
> Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
> ---
>  drivers/irqchip/Kconfig                       | 16 ++++
>  drivers/irqchip/Makefile                      |  2 +-
>  ...d-c900-aclint-sswi.c => irq-aclint-sswi.c} | 93 +++++++++++++------
>  3 files changed, 82 insertions(+), 29 deletions(-)
>  rename drivers/irqchip/{irq-thead-c900-aclint-sswi.c => irq-aclint-sswi.c} (67%)
> 
> diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
> index 0d196e447142..be9b54900482 100644
> --- a/drivers/irqchip/Kconfig
> +++ b/drivers/irqchip/Kconfig
> @@ -634,12 +634,28 @@ config STARFIVE_JH8100_INTC
>  
>  	  If you don't know what to do here, say Y.
>  
> +config ACLINT_SSWI
> +	bool
> +
> +config MIPS_P8700_ACLINT_SSWI
> +	bool "MIPS P8700 ACLINT S-mode IPI Interrupt Controller"
> +	depends on RISCV
> +	depends on SMP
> +	select IRQ_DOMAIN_HIERARCHY
> +	select GENERIC_IRQ_IPI_MUX
> +	select ACLINT_SSWI
> +	help
> +	  This enables support for MIPS P8700 specific ACLINT SSWI device
> +
> +	  If you don't know what to do here, say Y.
> +
>  config THEAD_C900_ACLINT_SSWI
>  	bool "THEAD C9XX ACLINT S-mode IPI Interrupt Controller"
>  	depends on RISCV
>  	depends on SMP
>  	select IRQ_DOMAIN_HIERARCHY
>  	select GENERIC_IRQ_IPI_MUX
> +	select ACLINT_SSWI
>  	help
>  	  This enables support for T-HEAD specific ACLINT SSWI device
>  	  support.
> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
> index 23ca4959e6ce..0458d6c5d161 100644
> --- a/drivers/irqchip/Makefile
> +++ b/drivers/irqchip/Makefile
> @@ -105,7 +105,7 @@ obj-$(CONFIG_RISCV_APLIC_MSI)		+= irq-riscv-aplic-msi.o
>  obj-$(CONFIG_RISCV_IMSIC)		+= irq-riscv-imsic-state.o irq-riscv-imsic-early.o irq-riscv-imsic-platform.o
>  obj-$(CONFIG_SIFIVE_PLIC)		+= irq-sifive-plic.o
>  obj-$(CONFIG_STARFIVE_JH8100_INTC)	+= irq-starfive-jh8100-intc.o
> -obj-$(CONFIG_THEAD_C900_ACLINT_SSWI)	+= irq-thead-c900-aclint-sswi.o
> +obj-$(CONFIG_ACLINT_SSWI)		+= irq-aclint-sswi.o
>  obj-$(CONFIG_IMX_IRQSTEER)		+= irq-imx-irqsteer.o
>  obj-$(CONFIG_IMX_INTMUX)		+= irq-imx-intmux.o
>  obj-$(CONFIG_IMX_MU_MSI)		+= irq-imx-mu-msi.o
> diff --git a/drivers/irqchip/irq-thead-c900-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
> similarity index 67%
> rename from drivers/irqchip/irq-thead-c900-aclint-sswi.c
> rename to drivers/irqchip/irq-aclint-sswi.c
> index 8ff6e7a1363b..ec21785df518 100644
> --- a/drivers/irqchip/irq-thead-c900-aclint-sswi.c
> +++ b/drivers/irqchip/irq-aclint-sswi.c
> @@ -3,7 +3,7 @@
>   * Copyright (C) 2024 Inochi Amaoto <inochiama@gmail.com>
>   */
>  
> -#define pr_fmt(fmt) "thead-c900-aclint-sswi: " fmt
> +#define pr_fmt(fmt) "aclint-sswi: " fmt
>  #include <linux/cpu.h>
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
> @@ -21,56 +21,51 @@
>  #include <asm/sbi.h>
>  #include <asm/vendorid_list.h>
>  
> -#define THEAD_ACLINT_xSWI_REGISTER_SIZE		4
> -
> -#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
> -#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
> -
>  static int sswi_ipi_virq __ro_after_init;
>  static DEFINE_PER_CPU(void __iomem *, sswi_cpu_regs);
>  
> -static void thead_aclint_sswi_ipi_send(unsigned int cpu)
> +static void aclint_sswi_ipi_send(unsigned int cpu)
>  {
>  	writel(0x1, per_cpu(sswi_cpu_regs, cpu));
>  }
>  
> -static void thead_aclint_sswi_ipi_clear(void)
> +static void aclint_sswi_ipi_clear(void)
>  {
>  	writel_relaxed(0x0, this_cpu_read(sswi_cpu_regs));
>  }
>  
> -static void thead_aclint_sswi_ipi_handle(struct irq_desc *desc)
> +static void aclint_sswi_ipi_handle(struct irq_desc *desc)
>  {
>  	struct irq_chip *chip = irq_desc_get_chip(desc);
>  
>  	chained_irq_enter(chip, desc);
>  
>  	csr_clear(CSR_IP, IE_SIE);
> -	thead_aclint_sswi_ipi_clear();
> +	aclint_sswi_ipi_clear();
>  
>  	ipi_mux_process();
>  
>  	chained_irq_exit(chip, desc);
>  }
>  
> -static int thead_aclint_sswi_starting_cpu(unsigned int cpu)
> +static int aclint_sswi_starting_cpu(unsigned int cpu)
>  {
>  	enable_percpu_irq(sswi_ipi_virq, irq_get_trigger_type(sswi_ipi_virq));
>  
>  	return 0;
>  }
>  
> -static int thead_aclint_sswi_dying_cpu(unsigned int cpu)
> +static int aclint_sswi_dying_cpu(unsigned int cpu)
>  {
> -	thead_aclint_sswi_ipi_clear();
> +	aclint_sswi_ipi_clear();
>  
>  	disable_percpu_irq(sswi_ipi_virq);
>  
>  	return 0;
>  }
>  
> -static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
> -					      void __iomem *reg)
> +static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
> +					void __iomem *reg)
>  {
>  	struct of_phandle_args parent;
>  	unsigned long hartid;
> @@ -97,7 +92,7 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
>  
>  		cpu = riscv_hartid_to_cpuid(hartid);
>  
> -		per_cpu(sswi_cpu_regs, cpu) = reg + i * THEAD_ACLINT_xSWI_REGISTER_SIZE;
> +		per_cpu(sswi_cpu_regs, cpu) = reg + hart_index * 4;
>  	}
>  
>  	pr_info("%pfwP: register %u CPU%s\n", fwnode, contexts, str_plural(contexts));
> @@ -105,17 +100,12 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
>  	return 0;
>  }
>  
> -static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
> +static int __init aclint_sswi_probe(struct fwnode_handle *fwnode)
>  {
>  	struct irq_domain *domain;
>  	void __iomem *reg;
>  	int virq, rc;
>  
> -	/* If it is T-HEAD CPU, check whether SSWI is enabled */
> -	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
> -	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
> -		return -ENOTSUPP;
> -
>  	if (!is_of_node(fwnode))
>  		return -EINVAL;
>  
> @@ -124,7 +114,7 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
>  		return -ENOMEM;
>  
>  	/* Parse SSWI setting */
> -	rc = thead_aclint_sswi_parse_irq(fwnode, reg);
> +	rc = aclint_sswi_parse_irq(fwnode, reg);
>  	if (rc < 0)
>  		return rc;
>  
> @@ -146,22 +136,68 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
>  	}
>  
>  	/* Register SSWI irq and handler */
> -	virq = ipi_mux_create(BITS_PER_BYTE, thead_aclint_sswi_ipi_send);
> +	virq = ipi_mux_create(BITS_PER_BYTE, aclint_sswi_ipi_send);
>  	if (virq <= 0) {
>  		pr_err("unable to create muxed IPIs\n");
>  		irq_dispose_mapping(sswi_ipi_virq);
>  		return virq < 0 ? virq : -ENOMEM;
>  	}
>  
> -	irq_set_chained_handler(sswi_ipi_virq, thead_aclint_sswi_ipi_handle);
> +	irq_set_chained_handler(sswi_ipi_virq, aclint_sswi_ipi_handle);
>  
>  	cpuhp_setup_state(CPUHP_AP_IRQ_THEAD_ACLINT_SSWI_STARTING,
> -			  "irqchip/thead-aclint-sswi:starting",
> -			  thead_aclint_sswi_starting_cpu,
> -			  thead_aclint_sswi_dying_cpu);
> +			  "irqchip/aclint-sswi:starting",
> +			  aclint_sswi_starting_cpu,
> +			  aclint_sswi_dying_cpu);
>  
>  	riscv_ipi_set_virq_range(virq, BITS_PER_BYTE);
>  
> +	return 0;
> +}
> +

> +#if defined(CONFIG_MIPS_P8700_ACLINT_SSWI)
> +/* generic/MIPS variant */

I do not think there is a must to add these defines

Regards,
Inochi

> +static int __init generic_aclint_sswi_probe(struct fwnode_handle *fwnode)
> +{
> +	int rc;
> +
> +	rc = aclint_sswi_probe(fwnode);
> +	if (rc)
> +		return rc;
> +
> +	/* Announce that SSWI is providing IPIs */
> +	pr_info("providing IPIs using ACLINT SSWI\n");
> +
> +	return 0;
> +}
> +
> +static int __init generic_aclint_sswi_early_probe(struct device_node *node,
> +						  struct device_node *parent)
> +{
> +	return generic_aclint_sswi_probe(&node->fwnode);
> +}
> +IRQCHIP_DECLARE(generic_aclint_sswi, "mips,p8700-aclint-sswi", generic_aclint_sswi_early_probe);
> +#endif /* CONFIG_MIPS_P8700_ACLINT_SSWI */
> +
> +#if defined(CONFIG_THEAD_C900_ACLINT_SSWI)
> +
> +#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
> +#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
> +
> +/* THEAD variant */
> +static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
> +{
> +	int rc;
> +
> +	/* If it is T-HEAD CPU, check whether SSWI is enabled */
> +	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
> +	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
> +		return -ENOTSUPP;
> +
> +	rc = aclint_sswi_probe(fwnode);
> +	if (rc)
> +		return rc;
> +
>  	/* Announce that SSWI is providing IPIs */
>  	pr_info("providing IPIs using THEAD ACLINT SSWI\n");
>  
> @@ -174,3 +210,4 @@ static int __init thead_aclint_sswi_early_probe(struct device_node *node,
>  	return thead_aclint_sswi_probe(&node->fwnode);
>  }
>  IRQCHIP_DECLARE(thead_aclint_sswi, "thead,c900-aclint-sswi", thead_aclint_sswi_early_probe);
> +#endif /* CONFIG_THEAD_C900_ACLINT_SSWI */
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-10 10:09     ` Inochi Amaoto
@ 2025-06-10 10:46       ` Vladimir Kondratiev
  2025-06-10 10:53         ` Inochi Amaoto
  0 siblings, 1 reply; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 10:46 UTC (permalink / raw)
  To: Inochi Amaoto, Thomas Gleixner, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Anup Patel, Chen Wang, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-riscv@lists.infradead.org, sophgo@lists.linux.dev

>> +#if defined(CONFIG_MIPS_P8700_ACLINT_SSWI)
>> +/* generic/MIPS variant */

>I do not think there is a must to add these defines

OK, if there is no objections from others, I'll remove it. To clarify,
we're about removing both #if defined(CONFIG_MIPS_P8700_ACLINT_SSWI)
and #if defined(CONFIG_THEAD_C900_ACLINT_SSWI) ? And, I'll keep logic in Kconfig to select whole .c file if one of variants selected

Thanks, Vladimir

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-10 10:46       ` Vladimir Kondratiev
@ 2025-06-10 10:53         ` Inochi Amaoto
  2025-06-10 11:09           ` Vladimir Kondratiev
  0 siblings, 1 reply; 38+ messages in thread
From: Inochi Amaoto @ 2025-06-10 10:53 UTC (permalink / raw)
  To: Vladimir Kondratiev, Inochi Amaoto, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Anup Patel, Chen Wang, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-riscv@lists.infradead.org, sophgo@lists.linux.dev

On Tue, Jun 10, 2025 at 10:46:23AM +0000, Vladimir Kondratiev wrote:
> >> +#if defined(CONFIG_MIPS_P8700_ACLINT_SSWI)
> >> +/* generic/MIPS variant */
> 
> >I do not think there is a must to add these defines
> 
> OK, if there is no objections from others, I'll remove it. To clarify,
> we're about removing both #if defined(CONFIG_MIPS_P8700_ACLINT_SSWI)
> and #if defined(CONFIG_THEAD_C900_ACLINT_SSWI) ? And, I'll keep logic in Kconfig to select whole .c file if one of variants selected
> 

I think all should be removed and it is OK to use old THEAD_C900_ACLINT_SSWI
as driver config. At least for now, I see no similar case about using defined.
Maybe the subsystem maintainer can give some more meaningful advice.

Regards,
Inochi

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-10 10:53         ` Inochi Amaoto
@ 2025-06-10 11:09           ` Vladimir Kondratiev
  2025-06-10 11:20             ` Inochi Amaoto
  0 siblings, 1 reply; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-10 11:09 UTC (permalink / raw)
  To: Inochi Amaoto, Thomas Gleixner, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Anup Patel, Chen Wang, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-riscv@lists.infradead.org, sophgo@lists.linux.dev

>I think all should be removed and it is OK to use old >THEAD_C900_ACLINT_SSWI
>as driver config. At least for now, I see no similar case about using defined.
>Maybe the subsystem maintainer can give some more meaningful advice.

OK, I see. Then, in the Kconfig for THEAD_C900_ACLINT_SSWI say it
selects both THEAD and MIPS variants? I am a bit not comfortable
keeping THEAD specific option for non-THEAD stuff. Here it is indeed
good to see what subsystem maintainer will say. If I remove logic added to
the Kconfig, maybe I need to rename a single config option to just
ACLINT_SSWI and list supported variants in help text? If going this way, your
input is important.

Thanks, Vladimir

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-10 11:09           ` Vladimir Kondratiev
@ 2025-06-10 11:20             ` Inochi Amaoto
  0 siblings, 0 replies; 38+ messages in thread
From: Inochi Amaoto @ 2025-06-10 11:20 UTC (permalink / raw)
  To: Vladimir Kondratiev, Inochi Amaoto, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Anup Patel, Chen Wang, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-riscv@lists.infradead.org, sophgo@lists.linux.dev

On Tue, Jun 10, 2025 at 11:09:26AM +0000, Vladimir Kondratiev wrote:
> >I think all should be removed and it is OK to use old >THEAD_C900_ACLINT_SSWI
> >as driver config. At least for now, I see no similar case about using defined.
> >Maybe the subsystem maintainer can give some more meaningful advice.
> 
> OK, I see. Then, in the Kconfig for THEAD_C900_ACLINT_SSWI say it
> selects both THEAD and MIPS variants? I am a bit not comfortable
> keeping THEAD specific option for non-THEAD stuff. Here it is indeed
> good to see what subsystem maintainer will say. If I remove logic added to
> the Kconfig, maybe I need to rename a single config option to just
> ACLINT_SSWI and list supported variants in help text? If going this way, your
> input is important.
> 

IIRC, I was asked to use vendor specific prefix for a vendor driver. I
am not sure how it can be changed when another vendor comes, so let's
wait and see whether there is some advice to improve this.

Regards,
Inochi

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v1 2/7] irqchip: riscv aplic: use riscv_get_hart_index()
  2025-06-09 13:47 ` [PATCH v1 2/7] irqchip: riscv aplic: use riscv_get_hart_index() Vladimir Kondratiev
@ 2025-06-12 12:50   ` Thomas Gleixner
  0 siblings, 0 replies; 38+ messages in thread
From: Thomas Gleixner @ 2025-06-12 12:50 UTC (permalink / raw)
  To: Vladimir Kondratiev, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

On Mon, Jun 09 2025 at 16:47, Vladimir Kondratiev wrote:

Please use the documented subsytem prefix nomenclature:

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#patch-subject

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-10 10:05   ` [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
  2025-06-10 10:09     ` Inochi Amaoto
@ 2025-06-12 13:03     ` Thomas Gleixner
  2025-06-12 14:38       ` Vladimir Kondratiev
  1 sibling, 1 reply; 38+ messages in thread
From: Thomas Gleixner @ 2025-06-12 13:03 UTC (permalink / raw)
  To: Vladimir Kondratiev, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

On Tue, Jun 10 2025 at 13:05, Vladimir Kondratiev wrote:
> +config ACLINT_SSWI
> +	bool
> +
> +config MIPS_P8700_ACLINT_SSWI
> +	bool "MIPS P8700 ACLINT S-mode IPI Interrupt Controller"
> +	depends on RISCV
> +	depends on SMP
> +	select IRQ_DOMAIN_HIERARCHY
> +	select GENERIC_IRQ_IPI_MUX
> +	select ACLINT_SSWI
> +	help
> +	  This enables support for MIPS P8700 specific ACLINT SSWI device
> +
> +	  If you don't know what to do here, say Y.
> +
>  config THEAD_C900_ACLINT_SSWI
>  	bool "THEAD C9XX ACLINT S-mode IPI Interrupt Controller"
>  	depends on RISCV
>  	depends on SMP
>  	select IRQ_DOMAIN_HIERARCHY
>  	select GENERIC_IRQ_IPI_MUX
> +	select ACLINT_SSWI
>  	help
>  	  This enables support for T-HEAD specific ACLINT SSWI device
>  	  support.

That's just exactly the same thing twice for no value. Just rename it to
ACLINT_SSWI and have a list of supported chips in the help text.

The only issue with the rename is, that oldconfig will drop the then
non-existing THEAD_C900_ACLINT_SSWI entry in the previous config. That's
not the end of the world and if really desired this can be solved by
having:

config ACLINT_SSWI
	bool "RISCV ACLINT ...."
	depends on RISCV
	depends on SMP
	select IRQ_DOMAIN_HIERARCHY
	select GENERIC_IRQ_IPI_MUX
	select ACLINT_SSWI
	help
	  This enables support for ACLINT SSWI device on THEAD C9XX and
	  MIPS P8700 devices.

# Backwards compatibility so oldconfig does not drop it.
config THEAD_C900_ACLINT_SSWI
	select ACLINT_SSWI

Or something like that.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-12 13:03     ` Thomas Gleixner
@ 2025-06-12 14:38       ` Vladimir Kondratiev
  0 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:38 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-riscv@lists.infradead.org, sophgo@lists.linux.dev

>> +config ACLINT_SSWI
>> +     bool
>> +
>> +config MIPS_P8700_ACLINT_SSWI
>> +     bool "MIPS P8700 ACLINT S-mode IPI Interrupt Controller"
>> +     depends on RISCV
>> +     depends on SMP
>> +     select IRQ_DOMAIN_HIERARCHY
>> +     select GENERIC_IRQ_IPI_MUX
>> +     select ACLINT_SSWI
>> +     help
>> +       This enables support for MIPS P8700 specific ACLINT SSWI device
>> +
>> +       If you don't know what to do here, say Y.
>> +
>>  config THEAD_C900_ACLINT_SSWI
>>        bool "THEAD C9XX ACLINT S-mode IPI Interrupt Controller"
>>        depends on RISCV
>>        depends on SMP
>>        select IRQ_DOMAIN_HIERARCHY
>>        select GENERIC_IRQ_IPI_MUX
>> +     select ACLINT_SSWI
>>        help
>>          This enables support for T-HEAD specific ACLINT SSWI device
>>          support.
>
>That's just exactly the same thing twice for no value. Just rename it to
>ACLINT_SSWI and have a list of supported chips in the help text.
>
>The only issue with the rename is, that oldconfig will drop the then
>non-existing THEAD_C900_ACLINT_SSWI entry in the previous config. That's
>not the end of the world and if really desired this can be solved by
>having:
>
>config ACLINT_SSWI
>        bool "RISCV ACLINT ...."
>        depends on RISCV
>        depends on SMP
>        select IRQ_DOMAIN_HIERARCHY
>        select GENERIC_IRQ_IPI_MUX
>        select ACLINT_SSWI
>        help
>          This enables support for ACLINT SSWI device on THEAD C9XX and
>          MIPS P8700 devices.
>
># Backwards compatibility so oldconfig does not drop it.
>config THEAD_C900_ACLINT_SSWI
>        select ACLINT_SSWI

Thanks, doing this. Indeed it is more compact and clean.
Submitting v3

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller
  2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
                   ` (7 preceding siblings ...)
  2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
@ 2025-06-12 14:39 ` Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 1/7] riscv: helper to parse hart index Vladimir Kondratiev
                     ` (7 more replies)
  8 siblings, 8 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

RISC-V draft specification for the ACLINT IPI controller describes
an "SSWI" device that allows to send IPI by writing register from the
S-mode (Linux kernel), as opposed to the "MSWI" device that does the
same from the M-mode. Sending IPI through the M-mode requires extra
SBI call, SSWI is much faster.

Support for the SSWI exists for the Thead board, it is almost as by
specification save for reading one custom CSR.

Soon to be released Mobileye SoC based on the MIPS P8700 RISC-V CPU has
variant of the ACLINT SSWI device that follows the spec exactly.

To support P8700, refactor Thead implementation, factoring out
generic code that complies with the draft spec, and provide
Thead and MIPS specific variants.

In addition, MIPS P8700 uses non contiguous hart indexes, and thus
requires "riscv,hart-indexes" property.

Patches 1 and 2 refactor "hart index" support, replacing
APLIC specific implementation with generic helper

Patch 3 adds dt-bindings

Patch 4 refactors Thead-specific SSWI, adding MIPS variant

Patch 5 adds "riscv,hart-indexes" support

Patches 6 and 7 do some minor improvements for the SSWI

Changed from v1:
1. RISC-V spec for the ACLINT is in a draft state, then can't
use "riscv," prefix. Restcucture commits to add MIPS specific
ACLINT-SSWI variant instead.

Changed from v2:
1. fix path prefix as in
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#patch-subject
2. Optimize CONFIG to keep single ACLINT_SSWI supporting all
variants
3. Rename T-HEAD specific CPU hotplug state

Vladimir Kondratiev (7):
  riscv: helper to parse hart index
  irqchip/riscv-aplic: use riscv_get_hart_index()
  dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi
  irqchip: MIPS P800 variant of aclint-sswi
  irqchip/aslint-sswi: resolve hart index
  irqchip/aclint-sswi: reduce data scope
  irqchip/aclint-sswi: remove extra includes

 .../thead,c900-aclint-sswi.yaml               |  64 ++++++++--
 arch/riscv/include/asm/irq.h                  |   2 +
 arch/riscv/kernel/irq.c                       |  34 ++++++
 drivers/irqchip/Kconfig                       |  15 ++-
 drivers/irqchip/Makefile                      |   2 +-
 ...d-c900-aclint-sswi.c => irq-aclint-sswi.c} | 114 ++++++++++++------
 drivers/irqchip/irq-riscv-aplic-direct.c      |  16 +--
 include/linux/cpuhotplug.h                    |   2 +-
 8 files changed, 179 insertions(+), 70 deletions(-)
 rename drivers/irqchip/{irq-thead-c900-aclint-sswi.c => irq-aclint-sswi.c} (63%)


base-commit: 2c4a1f3fe03edab80db66688360685031802160a
-- 
2.43.0


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH v3 1/7] riscv: helper to parse hart index
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
@ 2025-06-12 14:39   ` Vladimir Kondratiev
  2025-06-20 19:31     ` Thomas Gleixner
  2025-06-12 14:39   ` [PATCH v3 2/7] irqchip/riscv-aplic: use riscv_get_hart_index() Vladimir Kondratiev
                     ` (6 subsequent siblings)
  7 siblings, 1 reply; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

RISC-V APLIC specification defines "hart index" in [1]
And similar definitions found for ACLINT in [2]

Quote from [1]:

Within a given interrupt domain, each of the domain’s harts has a unique
index number in the range 0 to 2^14 − 1 (= 16,383). The index number a
domain associates with a hart may or may not have any relationship to the
unique hart identifier (“hart ID”) that the RISC-V Privileged
Architecture assigns to the hart. Two different interrupt domains may
employ entirely different index numbers for the same set of harts.

Further, [1] says in "4.5 Memory-mapped control region for an
interrupt domain":

The array of IDC structures may include some for potential hart index
numbers that are not actual hart index numbers in the domain.
For example, the first IDC structure is always for hart index 0, but 0 is
not necessarily a valid index number for any hart in the domain.

Support arbitrary hart indices specified in an optional property
"riscv,hart-indexes" which is specified as an array of u32 elements, one
per interrupt target, listing hart indexes in the same order as in
"interrupts-extended". If this property is not specified, fallback to use
logical hart indices within the domain.

If property not exist, fall back to logical hart indexes

Link: https://github.com/riscv/riscv-aia [1]
Link: https://github.com/riscvarchive/riscv-aclint [2]
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 arch/riscv/include/asm/irq.h |  2 ++
 arch/riscv/kernel/irq.c      | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h
index 7b038f3b7cb0..59c975f750c9 100644
--- a/arch/riscv/include/asm/irq.h
+++ b/arch/riscv/include/asm/irq.h
@@ -22,6 +22,8 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu);
 void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));
 
 struct fwnode_handle *riscv_get_intc_hwnode(void);
+int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
+			 u32 *hart_index);
 
 #ifdef CONFIG_ACPI
 
diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c
index 9ceda02507ca..b6af20bc300f 100644
--- a/arch/riscv/kernel/irq.c
+++ b/arch/riscv/kernel/irq.c
@@ -32,6 +32,40 @@ struct fwnode_handle *riscv_get_intc_hwnode(void)
 }
 EXPORT_SYMBOL_GPL(riscv_get_intc_hwnode);
 
+/**
+ * riscv_get_hart_index() - get hart index for interrupt delivery
+ * @fwnode: interrupt controller node
+ * @logical_index: index within the "interrupts-extended" property
+ * @hart_index: filled with the hart index to use
+ *
+ * RISC-V uses term "hart index" for its interrupt controllers, for the
+ * purpose of the interrupt routing to destination harts.
+ * It may be arbitrary numbers assigned to each destination hart in context
+ * of the particular interrupt domain.
+ *
+ * These numbers encoded in the optional property "riscv,hart-indexes"
+ * that should contain hart index for each interrupt destination in the same
+ * order as in the "interrupts-extended" property. If this property
+ * not exist, it assumed equal to the logical index, i.e. index within the
+ * "interrupts-extended" property.
+ *
+ * Return: error code
+ */
+int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
+			 u32 *hart_index)
+{
+	static const char *prop_hart_index = "riscv,hart-indexes";
+	struct device_node *np = to_of_node(fwnode);
+
+	if (!np || !of_property_present(np, prop_hart_index)) {
+		*hart_index = logical_index;
+		return 0;
+	}
+
+	return of_property_read_u32_index(np, prop_hart_index,
+					  logical_index, hart_index);
+}
+
 #ifdef CONFIG_IRQ_STACKS
 #include <asm/irq_stack.h>
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v3 2/7] irqchip/riscv-aplic: use riscv_get_hart_index()
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 1/7] riscv: helper to parse hart index Vladimir Kondratiev
@ 2025-06-12 14:39   ` Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi Vladimir Kondratiev
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Use global helper function instead of the local
implementation

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-riscv-aplic-direct.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/irqchip/irq-riscv-aplic-direct.c b/drivers/irqchip/irq-riscv-aplic-direct.c
index 205ad61d15e4..c2a75bf3d20c 100644
--- a/drivers/irqchip/irq-riscv-aplic-direct.c
+++ b/drivers/irqchip/irq-riscv-aplic-direct.c
@@ -219,20 +219,6 @@ static int aplic_direct_parse_parent_hwirq(struct device *dev, u32 index,
 	return 0;
 }
 
-static int aplic_direct_get_hart_index(struct device *dev, u32 logical_index,
-				       u32 *hart_index)
-{
-	const char *prop_hart_index = "riscv,hart-indexes";
-	struct device_node *np = to_of_node(dev->fwnode);
-
-	if (!np || !of_property_present(np, prop_hart_index)) {
-		*hart_index = logical_index;
-		return 0;
-	}
-
-	return of_property_read_u32_index(np, prop_hart_index, logical_index, hart_index);
-}
-
 int aplic_direct_setup(struct device *dev, void __iomem *regs)
 {
 	int i, j, rc, cpu, current_cpu, setup_count = 0;
@@ -279,7 +265,7 @@ int aplic_direct_setup(struct device *dev, void __iomem *regs)
 		cpumask_set_cpu(cpu, &direct->lmask);
 
 		idc = per_cpu_ptr(&aplic_idcs, cpu);
-		rc = aplic_direct_get_hart_index(dev, i, &idc->hart_index);
+		rc = riscv_get_hart_index(dev->fwnode, i, &idc->hart_index);
 		if (rc) {
 			dev_warn(dev, "hart index not found for IDC%d\n", i);
 			continue;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v3 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 1/7] riscv: helper to parse hart index Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 2/7] irqchip/riscv-aplic: use riscv_get_hart_index() Vladimir Kondratiev
@ 2025-06-12 14:39   ` Vladimir Kondratiev
  2025-06-12 15:35     ` Conor Dooley
  2025-06-12 14:39   ` [PATCH v3 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
                     ` (4 subsequent siblings)
  7 siblings, 1 reply; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Add ACLINT-SSWI variant for the MIPS P8700. This CPU has
SSWI device compliant with the RISC-V draft spec (see [1])
CPU indexes on this platform are not contiguous, instead
it uses bit-fields to encode hart,core,cluster numbers, thus
property "riscv,hart-indexes" is mandatory

Link: https://github.com/riscvarchive/riscv-aclint [1]

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 .../thead,c900-aclint-sswi.yaml               | 64 ++++++++++++++++---
 1 file changed, 55 insertions(+), 9 deletions(-)

diff --git a/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml b/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
index 8d330906bbbd..c1ab865fcd64 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
+++ b/Documentation/devicetree/bindings/interrupt-controller/thead,c900-aclint-sswi.yaml
@@ -4,23 +4,32 @@
 $id: http://devicetree.org/schemas/interrupt-controller/thead,c900-aclint-sswi.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: T-HEAD C900 ACLINT Supervisor-level Software Interrupt Device
+title: ACLINT Supervisor-level Software Interrupt Device
 
 maintainers:
   - Inochi Amaoto <inochiama@outlook.com>
 
 description:
-  The SSWI device is a part of the THEAD ACLINT device. It provides
-  supervisor-level IPI functionality for a set of HARTs on a THEAD
-  platform. It provides a register to set an IPI (SETSSIP) for each
-  HART connected to the SSWI device.
+  The SSWI device is a part of the ACLINT device. It provides
+  supervisor-level IPI functionality for a set of HARTs on a supported
+  platforms. It provides a register to set an IPI (SETSSIP) for each
+  HART connected to the SSWI device. See draft specification
+  https://github.com/riscvarchive/riscv-aclint
+
+  Following variants of the SSWI ACLINT supported, using dedicated
+  compatible string
+  - THEAD C900
+  - MIPS P8700
 
 properties:
   compatible:
-    items:
-      - enum:
-          - sophgo,sg2044-aclint-sswi
-      - const: thead,c900-aclint-sswi
+    oneOf:
+      - items:
+          - enum:
+              - sophgo,sg2044-aclint-sswi
+          - const: thead,c900-aclint-sswi
+      - items:
+          - const: mips,p8700-aclint-sswi
 
   reg:
     maxItems: 1
@@ -34,6 +43,14 @@ properties:
     minItems: 1
     maxItems: 4095
 
+  riscv,hart-indexes:
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    maxItems: 4095
+    description:
+      A list of hart indexes that APLIC should use to address each hart
+      that is mentioned in the "interrupts-extended"
+
 additionalProperties: false
 
 required:
@@ -43,8 +60,22 @@ required:
   - interrupt-controller
   - interrupts-extended
 
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: mips,p8700-aclint-sswi
+    then:
+      required:
+        - riscv,hart-indexes
+    else:
+      properties:
+        riscv,hart-indexes: false
+
 examples:
   - |
+    //Example 1
     interrupt-controller@94000000 {
       compatible = "sophgo,sg2044-aclint-sswi", "thead,c900-aclint-sswi";
       reg = <0x94000000 0x00004000>;
@@ -55,4 +86,19 @@ examples:
                             <&cpu3intc 1>,
                             <&cpu4intc 1>;
     };
+
+  - |
+    //Example 2
+    interrupt-controller@94000000 {
+      compatible = "mips,p8700-aclint-sswi";
+      reg = <0x94000000 0x00004000>;
+      #interrupt-cells = <0>;
+      interrupt-controller;
+      interrupts-extended = <&cpu1intc 1>,
+                            <&cpu2intc 1>,
+                            <&cpu3intc 1>,
+                            <&cpu4intc 1>;
+      riscv,hart-indexes = <0x0 0x1 0x10 0x11>;
+    };
+
 ...
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v3 4/7] irqchip: MIPS P800 variant of aclint-sswi
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (2 preceding siblings ...)
  2025-06-12 14:39   ` [PATCH v3 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi Vladimir Kondratiev
@ 2025-06-12 14:39   ` Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 5/7] irqchip/aslint-sswi: resolve hart index Vladimir Kondratiev
                     ` (3 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Refactor Thead specific implementation of the ACLINT-SSWI irqchip.
Factor out generic code that serves both Thead and MIPS variants.
This generic part is according to the RISC-V draft spec [1].

Link: https://github.com/riscvarchive/riscv-aclint [1]

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/Kconfig                       | 15 ++-
 drivers/irqchip/Makefile                      |  2 +-
 ...d-c900-aclint-sswi.c => irq-aclint-sswi.c} | 91 +++++++++++++------
 include/linux/cpuhotplug.h                    |  2 +-
 4 files changed, 75 insertions(+), 35 deletions(-)
 rename drivers/irqchip/{irq-thead-c900-aclint-sswi.c => irq-aclint-sswi.c} (68%)

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 0d196e447142..39f6f421fc75 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -634,18 +634,25 @@ config STARFIVE_JH8100_INTC
 
 	  If you don't know what to do here, say Y.
 
-config THEAD_C900_ACLINT_SSWI
-	bool "THEAD C9XX ACLINT S-mode IPI Interrupt Controller"
+config ACLINT_SSWI
+	bool "RISC-V ACLINT S-mode IPI Interrupt Controller"
 	depends on RISCV
 	depends on SMP
 	select IRQ_DOMAIN_HIERARCHY
 	select GENERIC_IRQ_IPI_MUX
 	help
-	  This enables support for T-HEAD specific ACLINT SSWI device
-	  support.
+	  This enables support for variants of the RISC-V ACLINT-SSWI device.
+	  Supported variants are:
+	  - T-HEAD, with compatible "thead,c900-aclint-sswi"
+	  - MIPS P8700, with compatible "mips,p8700-aclint-sswi"
 
 	  If you don't know what to do here, say Y.
 
+# Backwards compatibility so oldconfig does not drop it.
+config THEAD_C900_ACLINT_SSWI
+	bool
+	select ACLINT_SSWI
+
 config EXYNOS_IRQ_COMBINER
 	bool "Samsung Exynos IRQ combiner support" if COMPILE_TEST
 	depends on (ARCH_EXYNOS && ARM) || COMPILE_TEST
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 23ca4959e6ce..0458d6c5d161 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -105,7 +105,7 @@ obj-$(CONFIG_RISCV_APLIC_MSI)		+= irq-riscv-aplic-msi.o
 obj-$(CONFIG_RISCV_IMSIC)		+= irq-riscv-imsic-state.o irq-riscv-imsic-early.o irq-riscv-imsic-platform.o
 obj-$(CONFIG_SIFIVE_PLIC)		+= irq-sifive-plic.o
 obj-$(CONFIG_STARFIVE_JH8100_INTC)	+= irq-starfive-jh8100-intc.o
-obj-$(CONFIG_THEAD_C900_ACLINT_SSWI)	+= irq-thead-c900-aclint-sswi.o
+obj-$(CONFIG_ACLINT_SSWI)		+= irq-aclint-sswi.o
 obj-$(CONFIG_IMX_IRQSTEER)		+= irq-imx-irqsteer.o
 obj-$(CONFIG_IMX_INTMUX)		+= irq-imx-intmux.o
 obj-$(CONFIG_IMX_MU_MSI)		+= irq-imx-mu-msi.o
diff --git a/drivers/irqchip/irq-thead-c900-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
similarity index 68%
rename from drivers/irqchip/irq-thead-c900-aclint-sswi.c
rename to drivers/irqchip/irq-aclint-sswi.c
index 8ff6e7a1363b..5e133cf29737 100644
--- a/drivers/irqchip/irq-thead-c900-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -3,7 +3,8 @@
  * Copyright (C) 2024 Inochi Amaoto <inochiama@gmail.com>
  */
 
-#define pr_fmt(fmt) "thead-c900-aclint-sswi: " fmt
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -21,56 +22,51 @@
 #include <asm/sbi.h>
 #include <asm/vendorid_list.h>
 
-#define THEAD_ACLINT_xSWI_REGISTER_SIZE		4
-
-#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
-#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
-
 static int sswi_ipi_virq __ro_after_init;
 static DEFINE_PER_CPU(void __iomem *, sswi_cpu_regs);
 
-static void thead_aclint_sswi_ipi_send(unsigned int cpu)
+static void aclint_sswi_ipi_send(unsigned int cpu)
 {
 	writel(0x1, per_cpu(sswi_cpu_regs, cpu));
 }
 
-static void thead_aclint_sswi_ipi_clear(void)
+static void aclint_sswi_ipi_clear(void)
 {
 	writel_relaxed(0x0, this_cpu_read(sswi_cpu_regs));
 }
 
-static void thead_aclint_sswi_ipi_handle(struct irq_desc *desc)
+static void aclint_sswi_ipi_handle(struct irq_desc *desc)
 {
 	struct irq_chip *chip = irq_desc_get_chip(desc);
 
 	chained_irq_enter(chip, desc);
 
 	csr_clear(CSR_IP, IE_SIE);
-	thead_aclint_sswi_ipi_clear();
+	aclint_sswi_ipi_clear();
 
 	ipi_mux_process();
 
 	chained_irq_exit(chip, desc);
 }
 
-static int thead_aclint_sswi_starting_cpu(unsigned int cpu)
+static int aclint_sswi_starting_cpu(unsigned int cpu)
 {
 	enable_percpu_irq(sswi_ipi_virq, irq_get_trigger_type(sswi_ipi_virq));
 
 	return 0;
 }
 
-static int thead_aclint_sswi_dying_cpu(unsigned int cpu)
+static int aclint_sswi_dying_cpu(unsigned int cpu)
 {
-	thead_aclint_sswi_ipi_clear();
+	aclint_sswi_ipi_clear();
 
 	disable_percpu_irq(sswi_ipi_virq);
 
 	return 0;
 }
 
-static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
-					      void __iomem *reg)
+static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
+					void __iomem *reg)
 {
 	struct of_phandle_args parent;
 	unsigned long hartid;
@@ -97,7 +93,7 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 
 		cpu = riscv_hartid_to_cpuid(hartid);
 
-		per_cpu(sswi_cpu_regs, cpu) = reg + i * THEAD_ACLINT_xSWI_REGISTER_SIZE;
+		per_cpu(sswi_cpu_regs, cpu) = reg + hart_index * 4;
 	}
 
 	pr_info("%pfwP: register %u CPU%s\n", fwnode, contexts, str_plural(contexts));
@@ -105,17 +101,12 @@ static int __init thead_aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 	return 0;
 }
 
-static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
+static int __init aclint_sswi_probe(struct fwnode_handle *fwnode)
 {
 	struct irq_domain *domain;
 	void __iomem *reg;
 	int virq, rc;
 
-	/* If it is T-HEAD CPU, check whether SSWI is enabled */
-	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
-	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
-		return -ENOTSUPP;
-
 	if (!is_of_node(fwnode))
 		return -EINVAL;
 
@@ -124,7 +115,7 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
 		return -ENOMEM;
 
 	/* Parse SSWI setting */
-	rc = thead_aclint_sswi_parse_irq(fwnode, reg);
+	rc = aclint_sswi_parse_irq(fwnode, reg);
 	if (rc < 0)
 		return rc;
 
@@ -146,22 +137,64 @@ static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
 	}
 
 	/* Register SSWI irq and handler */
-	virq = ipi_mux_create(BITS_PER_BYTE, thead_aclint_sswi_ipi_send);
+	virq = ipi_mux_create(BITS_PER_BYTE, aclint_sswi_ipi_send);
 	if (virq <= 0) {
 		pr_err("unable to create muxed IPIs\n");
 		irq_dispose_mapping(sswi_ipi_virq);
 		return virq < 0 ? virq : -ENOMEM;
 	}
 
-	irq_set_chained_handler(sswi_ipi_virq, thead_aclint_sswi_ipi_handle);
+	irq_set_chained_handler(sswi_ipi_virq, aclint_sswi_ipi_handle);
 
-	cpuhp_setup_state(CPUHP_AP_IRQ_THEAD_ACLINT_SSWI_STARTING,
-			  "irqchip/thead-aclint-sswi:starting",
-			  thead_aclint_sswi_starting_cpu,
-			  thead_aclint_sswi_dying_cpu);
+	cpuhp_setup_state(CPUHP_AP_IRQ_ACLINT_SSWI_STARTING,
+			  "irqchip/aclint-sswi:starting",
+			  aclint_sswi_starting_cpu,
+			  aclint_sswi_dying_cpu);
 
 	riscv_ipi_set_virq_range(virq, BITS_PER_BYTE);
 
+	return 0;
+}
+
+/* generic/MIPS variant */
+static int __init generic_aclint_sswi_probe(struct fwnode_handle *fwnode)
+{
+	int rc;
+
+	rc = aclint_sswi_probe(fwnode);
+	if (rc)
+		return rc;
+
+	/* Announce that SSWI is providing IPIs */
+	pr_info("providing IPIs using ACLINT SSWI\n");
+
+	return 0;
+}
+
+static int __init generic_aclint_sswi_early_probe(struct device_node *node,
+						  struct device_node *parent)
+{
+	return generic_aclint_sswi_probe(&node->fwnode);
+}
+IRQCHIP_DECLARE(generic_aclint_sswi, "mips,p8700-aclint-sswi", generic_aclint_sswi_early_probe);
+
+/* THEAD variant */
+#define THEAD_C9XX_CSR_SXSTATUS			0x5c0
+#define THEAD_C9XX_SXSTATUS_CLINTEE		BIT(17)
+
+static int __init thead_aclint_sswi_probe(struct fwnode_handle *fwnode)
+{
+	int rc;
+
+	/* If it is T-HEAD CPU, check whether SSWI is enabled */
+	if (riscv_cached_mvendorid(0) == THEAD_VENDOR_ID &&
+	    !(csr_read(THEAD_C9XX_CSR_SXSTATUS) & THEAD_C9XX_SXSTATUS_CLINTEE))
+		return -ENOTSUPP;
+
+	rc = aclint_sswi_probe(fwnode);
+	if (rc)
+		return rc;
+
 	/* Announce that SSWI is providing IPIs */
 	pr_info("providing IPIs using THEAD ACLINT SSWI\n");
 
diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index df366ee15456..d381420bbd5f 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -145,7 +145,7 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_EIOINTC_STARTING,
 	CPUHP_AP_IRQ_AVECINTC_STARTING,
 	CPUHP_AP_IRQ_SIFIVE_PLIC_STARTING,
-	CPUHP_AP_IRQ_THEAD_ACLINT_SSWI_STARTING,
+	CPUHP_AP_IRQ_ACLINT_SSWI_STARTING,
 	CPUHP_AP_IRQ_RISCV_IMSIC_STARTING,
 	CPUHP_AP_IRQ_RISCV_SBI_IPI_STARTING,
 	CPUHP_AP_ARM_MVEBU_COHERENCY,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v3 5/7] irqchip/aslint-sswi: resolve hart index
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (3 preceding siblings ...)
  2025-06-12 14:39   ` [PATCH v3 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
@ 2025-06-12 14:39   ` Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 6/7] irqchip/aclint-sswi: reduce data scope Vladimir Kondratiev
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Resolve hart index according to assignment in the
"riscv,hart-indexes" property as defined in [1]

Link: https://github.com/riscvarchive/riscv-aclint [1]
Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index 5e133cf29737..81d28a53635e 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -72,6 +72,7 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 	unsigned long hartid;
 	u32 contexts, i;
 	int rc, cpu;
+	u32 hart_index;
 
 	contexts = of_irq_count(to_of_node(fwnode));
 	if (!(contexts)) {
@@ -93,6 +94,11 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 
 		cpu = riscv_hartid_to_cpuid(hartid);
 
+		rc = riscv_get_hart_index(fwnode, i, &hart_index);
+		if (rc) {
+			pr_warn("%pfwP: hart index [%d] not found\n", fwnode, i);
+			return -EINVAL;
+		}
 		per_cpu(sswi_cpu_regs, cpu) = reg + hart_index * 4;
 	}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v3 6/7] irqchip/aclint-sswi: reduce data scope
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (4 preceding siblings ...)
  2025-06-12 14:39   ` [PATCH v3 5/7] irqchip/aslint-sswi: resolve hart index Vladimir Kondratiev
@ 2025-06-12 14:39   ` Vladimir Kondratiev
  2025-06-12 14:39   ` [PATCH v3 7/7] irqchip/aclint-sswi: remove extra includes Vladimir Kondratiev
  2025-06-26 13:48   ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Thomas Gleixner
  7 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Move variables to the innermost scope where it is used

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index 81d28a53635e..a604c7e1e416 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -68,11 +68,7 @@ static int aclint_sswi_dying_cpu(unsigned int cpu)
 static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 					void __iomem *reg)
 {
-	struct of_phandle_args parent;
-	unsigned long hartid;
-	u32 contexts, i;
-	int rc, cpu;
-	u32 hart_index;
+	u32 contexts;
 
 	contexts = of_irq_count(to_of_node(fwnode));
 	if (!(contexts)) {
@@ -80,7 +76,12 @@ static int __init aclint_sswi_parse_irq(struct fwnode_handle *fwnode,
 		return -EINVAL;
 	}
 
-	for (i = 0; i < contexts; i++) {
+	for (u32 i = 0; i < contexts; i++) {
+		struct of_phandle_args parent;
+		unsigned long hartid;
+		int rc, cpu;
+		u32 hart_index;
+
 		rc = of_irq_parse_one(to_of_node(fwnode), i, &parent);
 		if (rc)
 			return rc;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH v3 7/7] irqchip/aclint-sswi: remove extra includes
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (5 preceding siblings ...)
  2025-06-12 14:39   ` [PATCH v3 6/7] irqchip/aclint-sswi: reduce data scope Vladimir Kondratiev
@ 2025-06-12 14:39   ` Vladimir Kondratiev
  2025-06-26 13:48   ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Thomas Gleixner
  7 siblings, 0 replies; 38+ messages in thread
From: Vladimir Kondratiev @ 2025-06-12 14:39 UTC (permalink / raw)
  To: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
---
 drivers/irqchip/irq-aclint-sswi.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/irqchip/irq-aclint-sswi.c b/drivers/irqchip/irq-aclint-sswi.c
index a604c7e1e416..51ecb509a984 100644
--- a/drivers/irqchip/irq-aclint-sswi.c
+++ b/drivers/irqchip/irq-aclint-sswi.c
@@ -7,15 +7,9 @@
 
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/irq.h>
 #include <linux/irqchip.h>
 #include <linux/irqchip/chained_irq.h>
-#include <linux/module.h>
-#include <linux/of.h>
 #include <linux/of_address.h>
-#include <linux/of_irq.h>
-#include <linux/pci.h>
 #include <linux/spinlock.h>
 #include <linux/smp.h>
 #include <linux/string_choices.h>
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH v3 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi
  2025-06-12 14:39   ` [PATCH v3 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi Vladimir Kondratiev
@ 2025-06-12 15:35     ` Conor Dooley
  0 siblings, 0 replies; 38+ messages in thread
From: Conor Dooley @ 2025-06-12 15:35 UTC (permalink / raw)
  To: Vladimir Kondratiev
  Cc: Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura, linux-kernel, devicetree,
	linux-riscv, sophgo

[-- Attachment #1: Type: text/plain, Size: 601 bytes --]

On Thu, Jun 12, 2025 at 05:39:07PM +0300, Vladimir Kondratiev wrote:
> Add ACLINT-SSWI variant for the MIPS P8700. This CPU has
> SSWI device compliant with the RISC-V draft spec (see [1])
> CPU indexes on this platform are not contiguous, instead
> it uses bit-fields to encode hart,core,cluster numbers, thus
> property "riscv,hart-indexes" is mandatory
> 
> Link: https://github.com/riscvarchive/riscv-aclint [1]
> 
^ this blank line shouldn't be here fwiw.

> Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>

Acked-by: Conor Dooley <conor.dooley@microchip.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v3 1/7] riscv: helper to parse hart index
  2025-06-12 14:39   ` [PATCH v3 1/7] riscv: helper to parse hart index Vladimir Kondratiev
@ 2025-06-20 19:31     ` Thomas Gleixner
  0 siblings, 0 replies; 38+ messages in thread
From: Thomas Gleixner @ 2025-06-20 19:31 UTC (permalink / raw)
  To: Vladimir Kondratiev, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

On Thu, Jun 12 2025 at 17:39, Vladimir Kondratiev wrote:
> ---
>  arch/riscv/include/asm/irq.h |  2 ++
>  arch/riscv/kernel/irq.c      | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+)

Can the RISCV folks please ack/review this one so this pile can go
through the irqchip tree?


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v1 1/7] riscv: helper to parse hart index
  2025-06-09 13:47 ` [PATCH v1 1/7] riscv: helper to parse hart index Vladimir Kondratiev
@ 2025-06-23 12:53   ` Alexandre Ghiti
  0 siblings, 0 replies; 38+ messages in thread
From: Alexandre Ghiti @ 2025-06-23 12:53 UTC (permalink / raw)
  To: Vladimir Kondratiev, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo

Hi Vladimir,

On 6/9/25 15:47, Vladimir Kondratiev wrote:
> RISC-V APLIC specification defines "hart index" in [1]
> And similar definitions found for ACLINT in [2]
>
> Quote from [1]:
>
> Within a given interrupt domain, each of the domain’s harts has a unique
> index number in the range 0 to 2^14 − 1 (= 16,383). The index number a
> domain associates with a hart may or may not have any relationship to the
> unique hart identifier (“hart ID”) that the RISC-V Privileged
> Architecture assigns to the hart. Two different interrupt domains may
> employ entirely different index numbers for the same set of harts.
>
> Further, [1] says in "4.5 Memory-mapped control region for an
> interrupt domain":
>
> The array of IDC structures may include some for potential hart index
> numbers that are not actual hart index numbers in the domain.
> For example, the first IDC structure is always for hart index 0, but 0 is
> not necessarily a valid index number for any hart in the domain.
>
> Support arbitrary hart indices specified in an optional property
> "riscv,hart-indexes" which is specified as an array of u32 elements, one
> per interrupt target, listing hart indexes in the same order as in
> "interrupts-extended". If this property is not specified, fallback to use
> logical hart indices within the domain.
>
> If property not exist, fall back to logical hart indexes


does not


>
> Link: https://github.com/riscv/riscv-aia [1]
> Link: https://github.com/riscvarchive/riscv-aclint [2]
> Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
> ---
>   arch/riscv/include/asm/irq.h |  2 ++
>   arch/riscv/kernel/irq.c      | 34 ++++++++++++++++++++++++++++++++++
>   2 files changed, 36 insertions(+)
>
> diff --git a/arch/riscv/include/asm/irq.h b/arch/riscv/include/asm/irq.h
> index 7b038f3b7cb0..59c975f750c9 100644
> --- a/arch/riscv/include/asm/irq.h
> +++ b/arch/riscv/include/asm/irq.h
> @@ -22,6 +22,8 @@ void arch_trigger_cpumask_backtrace(const cpumask_t *mask, int exclude_cpu);
>   void riscv_set_intc_hwnode_fn(struct fwnode_handle *(*fn)(void));
>   
>   struct fwnode_handle *riscv_get_intc_hwnode(void);
> +int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
> +			 u32 *hart_index);
>   
>   #ifdef CONFIG_ACPI
>   
> diff --git a/arch/riscv/kernel/irq.c b/arch/riscv/kernel/irq.c
> index 9ceda02507ca..efdf505bb776 100644
> --- a/arch/riscv/kernel/irq.c
> +++ b/arch/riscv/kernel/irq.c
> @@ -32,6 +32,40 @@ struct fwnode_handle *riscv_get_intc_hwnode(void)
>   }
>   EXPORT_SYMBOL_GPL(riscv_get_intc_hwnode);
>   
> +/**
> + * riscv_get_hart_index() - get hart index for interrupt delivery
> + * @fwnode: interrupt controller node
> + * @logical_index: index within the "interrupts-extended" property
> + * @hart_index: filled with the hart index to use
> + *
> + * Risc-V uses term "hart index" for its interrupt controllers, for the


s/Risc-V/RISC-V


> + * purpose of the interrupt routing to destination harts.
> + * It may be arbitrary numbers assigned to each destination hart in context
> + * of the particular interrupt domain.
> + *
> + * These numbers encoded in the optional property "riscv,hart-indexes"
> + * that should contain hart index for each interrupt destination in the same
> + * order as in the "interrupts-extended" property. If this property
> + * not exist, it assumed equal to the logical index, i.e. index within the
> + * "interrupts-extended" property.
> + *
> + * Return: error code


This does not add a lot of value, maybe something like that "Return: 0 
on success, a negative error code otherwise"?


> + */
> +int riscv_get_hart_index(struct fwnode_handle *fwnode, u32 logical_index,
> +			 u32 *hart_index)
> +{
> +	static const char *prop_hart_index = "riscv,hart-indexes";
> +	struct device_node *np = to_of_node(fwnode);
> +
> +	if (!np || !of_property_present(np, prop_hart_index)) {
> +		*hart_index = logical_index;
> +		return 0;
> +	}
> +
> +	return of_property_read_u32_index(np, prop_hart_index,
> +					  logical_index, hart_index);
> +}
> +
>   #ifdef CONFIG_IRQ_STACKS
>   #include <asm/irq_stack.h>
>   


With those nits above fixed, you can add:

Acked-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller
  2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
                     ` (6 preceding siblings ...)
  2025-06-12 14:39   ` [PATCH v3 7/7] irqchip/aclint-sswi: remove extra includes Vladimir Kondratiev
@ 2025-06-26 13:48   ` Thomas Gleixner
  7 siblings, 0 replies; 38+ messages in thread
From: Thomas Gleixner @ 2025-06-26 13:48 UTC (permalink / raw)
  To: Vladimir Kondratiev, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Anup Patel, Chen Wang, Inochi Amaoto, Sunil V L,
	Rafael J . Wysocki, Ryo Takakura
  Cc: linux-kernel, devicetree, linux-riscv, sophgo,
	Vladimir Kondratiev

On Thu, Jun 12 2025 at 17:39, Vladimir Kondratiev wrote:
> Patches 1 and 2 refactor "hart index" support, replacing
> APLIC specific implementation with generic helper
>
> Patch 3 adds dt-bindings
>
> Patch 4 refactors Thead-specific SSWI, adding MIPS variant
>
> Patch 5 adds "riscv,hart-indexes" support
>
> Patches 6 and 7 do some minor improvements for the SSWI

It seems I'm the only one who cares about this series aside of Conor
looking at the DT part and of course Vladimir himself.

This whole thing looks reasonable to me and I'm not longer waiting for
those who keep me busy with their own patches and fail to look at stuff
which affects the architecture/drivers they depend on. I don't want to
hear complaints about any fallout of this further down the road.

Oh well.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2025-06-26 13:48 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09 13:47 [PATCH v1 0/7] Risc-V ACLINT IPI controller Vladimir Kondratiev
2025-06-09 13:47 ` [PATCH v1 1/7] riscv: helper to parse hart index Vladimir Kondratiev
2025-06-23 12:53   ` Alexandre Ghiti
2025-06-09 13:47 ` [PATCH v1 2/7] irqchip: riscv aplic: use riscv_get_hart_index() Vladimir Kondratiev
2025-06-12 12:50   ` Thomas Gleixner
2025-06-09 13:47 ` [PATCH v1 3/7] dt-bindings: interrupt-controller: add generic Risc-v aclint-sswi Vladimir Kondratiev
2025-06-09 16:01   ` Conor Dooley
2025-06-10  9:55     ` Vladimir Kondratiev
2025-06-09 13:47 ` [PATCH v1 4/7] irqchip: introduce generic Risc-V aclint-sswi Vladimir Kondratiev
2025-06-09 13:47 ` [PATCH v1 5/7] irqchip: aslint-sswi: resolve hart index Vladimir Kondratiev
2025-06-09 13:47 ` [PATCH v1 6/7] irqchip: aclint-sswi: reduce data scope Vladimir Kondratiev
2025-06-09 13:47 ` [PATCH v1 7/7] irqchip: aclint-sswi: remove extra includes Vladimir Kondratiev
2025-06-10 10:05 ` [PATCH v2 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
2025-06-10 10:05   ` [PATCH v2 1/7] riscv: helper to parse hart index Vladimir Kondratiev
2025-06-10 10:05   ` [PATCH v2 2/7] irqchip: riscv aplic: use riscv_get_hart_index() Vladimir Kondratiev
2025-06-10 10:05   ` [PATCH v2 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi Vladimir Kondratiev
2025-06-10 10:05   ` [PATCH v2 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
2025-06-10 10:09     ` Inochi Amaoto
2025-06-10 10:46       ` Vladimir Kondratiev
2025-06-10 10:53         ` Inochi Amaoto
2025-06-10 11:09           ` Vladimir Kondratiev
2025-06-10 11:20             ` Inochi Amaoto
2025-06-12 13:03     ` Thomas Gleixner
2025-06-12 14:38       ` Vladimir Kondratiev
2025-06-10 10:05   ` [PATCH v2 5/7] irqchip: aslint-sswi: resolve hart index Vladimir Kondratiev
2025-06-10 10:05   ` [PATCH v2 6/7] irqchip: aclint-sswi: reduce data scope Vladimir Kondratiev
2025-06-10 10:05   ` [PATCH v2 7/7] irqchip: aclint-sswi: remove extra includes Vladimir Kondratiev
2025-06-12 14:39 ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Vladimir Kondratiev
2025-06-12 14:39   ` [PATCH v3 1/7] riscv: helper to parse hart index Vladimir Kondratiev
2025-06-20 19:31     ` Thomas Gleixner
2025-06-12 14:39   ` [PATCH v3 2/7] irqchip/riscv-aplic: use riscv_get_hart_index() Vladimir Kondratiev
2025-06-12 14:39   ` [PATCH v3 3/7] dt-bindings: interrupt-controller: add MIPS P8700 aclint-sswi Vladimir Kondratiev
2025-06-12 15:35     ` Conor Dooley
2025-06-12 14:39   ` [PATCH v3 4/7] irqchip: MIPS P800 variant of aclint-sswi Vladimir Kondratiev
2025-06-12 14:39   ` [PATCH v3 5/7] irqchip/aslint-sswi: resolve hart index Vladimir Kondratiev
2025-06-12 14:39   ` [PATCH v3 6/7] irqchip/aclint-sswi: reduce data scope Vladimir Kondratiev
2025-06-12 14:39   ` [PATCH v3 7/7] irqchip/aclint-sswi: remove extra includes Vladimir Kondratiev
2025-06-26 13:48   ` [PATCH v3 0/7] MIPS P8700 variant of the ACLINT IPI controller Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).