Skip to contentSkip to conversation

Initial support for the Realtek DHC SoCs

PATCH Superseded James Tai 6 participants 26 messages Nov 29, 2023 – Dec 22, 2023

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

James Tai

author
#0 lore raw

v3 cover Initial support for the Realtek DHC SoCs

This series introduces an interrupt controller driver for the Realtek DHC (Digital Home Center) SoCs.

Change log:
v2 -> v3:
- Retested the bindings using the new version of the dtschema
- Fixed the order of property items
- Removed redundant files and replaced them with 'realtek,intc.yaml'
- Replaced 'interrupts-extended' with 'interrupts'
- Added a description for 'interrupts'
- Reduced the example code
- Resolved kernel test robot build warnings

v1 -> v2:
- Tested the bindings using 'make dt_binding_check'
- Fixed code style issues
- Resolved kernel test robot build warnings
- Replaced spin_lock_irqsave with raw_spin_lock
- Replaced magic number with macro
- Removed the realtek_intc_set_affinity function

James Tai (6):
dt-bindings: interrupt-controller: Add support for Realtek DHC SoCs
irqchip: Add interrupt controller support for Realtek DHC SoCs
irqchip: Introduce RTD1319 support using the Realtek common interrupt
controller driver
irqchip: Introduce RTD1319D support using the Realtek common interrupt
controller driver
irqchip: Introduce RTD1325 support using the Realtek common interrupt
controller driver
irqchip: Introduce RTD1619B support using the Realtek common interrupt
controller driver

 .../interrupt-controller/realtek,intc.yaml    |  76 ++++++
 drivers/irqchip/Kconfig                       |  28 +++
 drivers/irqchip/Makefile                      |   5 +
 drivers/irqchip/irq-realtek-intc-common.c     | 208 ++++++++++++++++
 drivers/irqchip/irq-realtek-intc-common.h     |  77 ++++++
 drivers/irqchip/irq-realtek-rtd1319.c         | 218 +++++++++++++++++
 drivers/irqchip/irq-realtek-rtd1319d.c        | 227 ++++++++++++++++++
 drivers/irqchip/irq-realtek-rtd1325.c         | 227 ++++++++++++++++++
 drivers/irqchip/irq-realtek-rtd1619b.c        | 217 +++++++++++++++++
 9 files changed, 1283 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml
 create mode 100644 drivers/irqchip/irq-realtek-intc-common.c
 create mode 100644 drivers/irqchip/irq-realtek-intc-common.h
 create mode 100644 drivers/irqchip/irq-realtek-rtd1319.c
 create mode 100644 drivers/irqchip/irq-realtek-rtd1319d.c
 create mode 100644 drivers/irqchip/irq-realtek-rtd1325.c
 create mode 100644 drivers/irqchip/irq-realtek-rtd1619b.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v3 1/6 dt-bindings: interrupt-controller: Add support for Realtek DHC SoCs

Add the YAML documentation for Realtek DHC (Digital Home Center) SoCs.

---
v2 to v3 change:
- Retested the bindings using the new version of the dtschema
- Fixed the order of property items
- Removed redundant files and replaced them with 'realtek,intc.yaml'
- Replaced 'interrupts-extended' with 'interrupts'
- Added a description for 'interrupts'
- Reduced the example code

v1 to v2 change:
- Tested the bindings using 'make dt_binding_check'
- Fixed code style issues

 .../interrupt-controller/realtek,intc.yaml    | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml
Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml new file +76 -0
new file mode 100644
index 000000000000..3aa863b1549d
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/realtek,intc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek DHC SoCs Interrupt Controller
+
+maintainers:
+  - James Tai <[email protected]>
+
+description:
+  This interrupt controller is a component of Realtek DHC (Digital Home Center)
+  SoCs and is designed to receive interrupts from peripheral devices.
+
+  Each DHC SoC has two sets of interrupt controllers, each capable of
+  handling up to 32 interrupts.
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+    enum:
+      - realtek,rtd1319-intc-iso
+      - realtek,rtd1319-intc-misc
+      - realtek,rtd1319d-intc-iso
+      - realtek,rtd1319d-intc-misc
+      - realtek,rtd1325-intc-iso
+      - realtek,rtd1325-intc-misc
+      - realtek,rtd1619b-intc-iso
+      - realtek,rtd1619b-intc-misc
+
+  reg:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 1
+
+  '#address-cells':
+    const: 0
+
+  interrupts:
+    description: |
+      Contains the GIC SPI IRQs mapped to the external interrupt lines.
+    minItems: 2
+    maxItems: 4
+
+required:
+  - compatible
+  - reg
+  - interrupt-controller
+  - '#interrupt-cells'
+  - '#address-cells'
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    realtek_iso_intc: interrupt-controller@40 {
+      compatible = "realtek,rtd1319-intc-iso";
+      reg = <0x00 0x40>;
+      interrupt-parent = <&gic>;
+      interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>,
+                   <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>;
+      interrupt-controller;
+      #address-cells = <0>;
+      #interrupt-cells = <1>;
+    };
+...
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v3 1/6] dt-bindings: interrupt-controller: Add support for Realtek DHC SoCs

Quoted 4 lines · James Tai

Add the YAML documentation for Realtek DHC (Digital Home Center) SoCs.

Drop both. They are not applicable to this patch.

Quoted 8 lines
CC Thomas Gleixner <[email protected]>
CC Marc Zyngier <[email protected]>
CC Rob Herring <[email protected]>
CC Krzysztof Kozlowski <[email protected]>
CC Conor Dooley <[email protected]>

Please drop the autogenerated scripts/get_maintainer.pl CC-entries from commit msg. There is no single need to store automated output of get_maintainers.pl in the git log. It can be easily re-created at any given time, thus its presence in the git history is redundant and obfuscates the log.

If you need it for your own patch management purposes, keep it under the --- separator.

Quoted 63 lines

---
v2 to v3 change:
- Retested the bindings using the new version of the dtschema
- Fixed the order of property items
- Removed redundant files and replaced them with 'realtek,intc.yaml'
- Replaced 'interrupts-extended' with 'interrupts'
- Added a description for 'interrupts'
- Reduced the example code

v1 to v2 change:
- Tested the bindings using 'make dt_binding_check'
- Fixed code style issues

 .../interrupt-controller/realtek,intc.yaml    | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml
Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml new file +39 -0
new file mode 100644
index 000000000000..3aa863b1549d
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/realtek,intc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek DHC SoCs Interrupt Controller
+
+maintainers:
+  - James Tai <[email protected]>
+
+description:
+  This interrupt controller is a component of Realtek DHC (Digital Home Center)
+  SoCs and is designed to receive interrupts from peripheral devices.
+
+  Each DHC SoC has two sets of interrupt controllers, each capable of
+  handling up to 32 interrupts.
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+    enum:
+      - realtek,rtd1319-intc-iso
+      - realtek,rtd1319-intc-misc
+      - realtek,rtd1319d-intc-iso
+      - realtek,rtd1319d-intc-misc
+      - realtek,rtd1325-intc-iso
+      - realtek,rtd1325-intc-misc
+      - realtek,rtd1619b-intc-iso
+      - realtek,rtd1619b-intc-misc
+
+  reg:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  '#interrupt-cells':

Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml line 49

Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/realtek,intc.yaml new file +10 -0
+    const: 1
+
+  '#address-cells':
+    const: 0
+
+  interrupts:
+    description: |
+      Contains the GIC SPI IRQs mapped to the external interrupt lines.
+    minItems: 2
+    maxItems: 4

My previous comments were not addressed. Why lines are not described (items: description:)? Are they all the same? Why you did not respond to clarify this comment?

The rest of my comment here was also ignored. You cannot just ignore comments, but must respond to them or implement them.

To clarify: I expect allOf: block after required: constraining the interrupts per variant.

Best regards,
Krzysztof

#3 lore raw

RE: [PATCH v3 1/6] dt-bindings: interrupt-controller: Add support for Realtek DHC SoCs

Hi Krzysztof,

Quoted 10 lines · James Tai
Quoted 6 lines

Add the YAML documentation for Realtek DHC (Digital Home Center) SoCs.

Closes:
https://lore.kernel.org/oe-kbuild-all/202311180921.ayKhiFHL-lkp@intel.
com/

Drop both. They are not applicable to this patch.

Okay. I will drop them.

Quoted 9 lines
Quoted 8 lines
CC Thomas Gleixner <[email protected]>
CC Marc Zyngier <[email protected]>
CC Rob Herring <[email protected]>
CC Krzysztof Kozlowski <[email protected]>
CC Conor Dooley <[email protected]>
Quoted 8 lines

Please drop the autogenerated scripts/get_maintainer.pl CC-entries from commit msg. There is no single need to store automated output of get_maintainers.pl in the git log. It can be easily re-created at any given time, thus its presence in the git history is redundant and obfuscates the log.

If you need it for your own patch management purposes, keep it under the --- separator.

I will move the CC-entries under the '---' separator.

Quoted 4 lines

My previous comments were not addressed. Why lines are not described (items: description:)? Are they all the same? Why you did not respond to clarify this comment?

I've addressed the previous comments and will include a description for each line in the next patches. I misunderstood your meaning, so I did not provide a clear response.

Quoted 3 lines

The rest of my comment here was also ignored. You cannot just ignore comments, but must respond to them or implement them.

I will improve this part.

Quoted 3 lines

To clarify: I expect allOf: block after required: constraining the interrupts per variant.

I will adjust it in next patches.

Regards,
James

author
#4 lore raw

PATCH v3 2/6 irqchip: Add interrupt controller support for Realtek DHC SoCs

In reply to James Tai

Realtek DHC (Digital Home Center) SoCs share a common interrupt controller design. This universal interrupt controller driver provides support for various variants within the Realtek DHC SoC family.

Each DHC SoC features two sets of extended interrupt controllers, each capable of handling up to 32 interrupts. These expansion controllers are connected to the GIC (Generic Interrupt Controller).

---
v2 to v3 change:
- Resolved kernel test robot build warnings
https://lore.kernel.org/r/[email protected]/

v1 to v2 change:
- Fixed code style issues
- Removed the realtek_intc_set_affinity funcation
- Replaced spin_lock_irqsave with raw_spin_lock

 drivers/irqchip/Kconfig                   |   4 +
 drivers/irqchip/Makefile                  |   1 +
 drivers/irqchip/irq-realtek-intc-common.c | 208 ++++++++++++++++++++++
 drivers/irqchip/irq-realtek-intc-common.h |  77 ++++++++
 4 files changed, 290 insertions(+)
 create mode 100644 drivers/irqchip/irq-realtek-intc-common.c
 create mode 100644 drivers/irqchip/irq-realtek-intc-common.h
drivers/irqchip/Kconfig +4 -0
index f7149d0f3d45..267c3429b48d 100644
@@ -218,6 +218,10 @@ config RDA_INTC
 	bool
 	select IRQ_DOMAIN
 
+config REALTEK_DHC_INTC
+	tristate
+	select IRQ_DOMAIN
+
 config RENESAS_INTC_IRQPIN
 	bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST
 	select IRQ_DOMAIN
drivers/irqchip/Makefile +1 -0
index ffd945fe71aa..f6774af7fde2 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_IRQ_MIPS_CPU)		+= irq-mips-cpu.o
 obj-$(CONFIG_IXP4XX_IRQ)		+= irq-ixp4xx.o
 obj-$(CONFIG_JCORE_AIC)			+= irq-jcore-aic.o
 obj-$(CONFIG_RDA_INTC)			+= irq-rda-intc.o
+obj-$(CONFIG_REALTEK_DHC_INTC)		+= irq-realtek-intc-common.o
 obj-$(CONFIG_RENESAS_INTC_IRQPIN)	+= irq-renesas-intc-irqpin.o
 obj-$(CONFIG_RENESAS_IRQC)		+= irq-renesas-irqc.o
 obj-$(CONFIG_RENESAS_RZA1_IRQC)		+= irq-renesas-rza1.o
drivers/irqchip/irq-realtek-intc-common.c new file +208 -0

208 lines not on this page · raw message

drivers/irqchip/irq-realtek-intc-common.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

drivers/irqchip/irq-realtek-intc-common.c line 145

Quoted 9 lines · James Tai
drivers/irqchip/irq-realtek-intc-common.c new file +9 -0
+static int realtek_intc_subset(struct device_node *node, struct realtek_intc_data *data, int index)
+{
+	struct realtek_intc_subset_data *subset_data = &data->subset_data[index];
+	const struct realtek_intc_subset_cfg *cfg = &data->info->cfg[index];
+	int irq;
+
+	irq = irq_of_parse_and_map(node, index);
+	if (irq <= 0)
+		return irq;

I don't think irq_of_parse_and_map() can return negatives. Only zero on error. Returning zero on error is a historical artifact with IRQ functions and a constant source of bugs. But here returning zero is success. See my blog for more details:
https://staticthinking.wordpress.com/2023/08/07/writing-a-check-for-zero-irq-error-codes/

So this should probably be:

	irq = irq_of_parse_and_map(node, index);
	if (!irq)
		return -ENODEV;

I should create a static checker warning for this... Possibly I should create a static checker warning any time someone does:

	if (foo <= 0)
		return foo;
Quoted 14 lines
drivers/irqchip/irq-realtek-intc-common.c new file +14 -0
+
+	subset_data->common = data;
+	subset_data->cfg = cfg;
+	subset_data->parent_irq = irq;
+	irq_set_chained_handler_and_data(irq, realtek_intc_handler, subset_data);
+
+	return 0;
+}
+
+int realtek_intc_probe(struct platform_device *pdev, const struct realtek_intc_info *info)
+{
+	struct realtek_intc_data *data;
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;

drivers/irqchip/irq-realtek-intc-common.c line 169

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+	int ret, i;
+
+	data = devm_kzalloc(dev, struct_size(data, subset_data, info->cfg_num), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->base = of_iomap(node, 0);
+	if (!data->base) {
+		ret = -ENOMEM;
+		goto out_cleanup;

devm_ allocations are cleaned up automatically so there is no need to call devm_kfree() before returning.

regards,
dan carpenter

Quoted 35 lines
drivers/irqchip/irq-realtek-intc-common.c new file +35 -0
+	}
+
+	data->info = info;
+
+	raw_spin_lock_init(&data->lock);
+
+	data->domain = irq_domain_add_linear(node, 32, &realtek_intc_domain_ops, data);
+	if (!data->domain) {
+		ret = -ENOMEM;
+		goto out_cleanup;
+	}
+
+	data->subset_data_num = info->cfg_num;
+	for (i = 0; i < info->cfg_num; i++) {
+		ret = realtek_intc_subset(node, data, i);
+		if (ret) {
+			WARN(ret, "failed to init subset %d: %d", i, ret);
+			ret = -ENOMEM;
+			goto out_cleanup;
+		}
+	}
+
+	platform_set_drvdata(pdev, data);
+
+	return 0;
+
+out_cleanup:
+
+	if (data->base)
+		iounmap(data->base);
+
+	devm_kfree(dev, data);
+
+	return ret;
+}
#6 lore raw

Re: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

Quoted 22 lines · Dan Carpenter
Quoted 5 lines
drivers/irqchip/irq-realtek-intc-common.c new file +5 -0
+int realtek_intc_probe(struct platform_device *pdev, const struct realtek_intc_info *info)
+{
+	struct realtek_intc_data *data;
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;

drivers/irqchip/irq-realtek-intc-common.c line 169

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+	int ret, i;
+
+	data = devm_kzalloc(dev, struct_size(data, subset_data, info->cfg_num), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->base = of_iomap(node, 0);
+	if (!data->base) {
+		ret = -ENOMEM;
+		goto out_cleanup;

devm_ allocations are cleaned up automatically so there is no need to call devm_kfree() before returning.

regards,
dan carpenter

Quoted 7 lines

drivers/irqchip/irq-realtek-intc-common.c line 176

Quoted 7 lines
drivers/irqchip/irq-realtek-intc-common.c new file +7 -0
+	}
+
+	data->info = info;
+
+	raw_spin_lock_init(&data->lock);
+
+	data->domain = irq_domain_add_linear(node, 32, &realtek_intc_domain_ops, data);

Btw, as I was testing the other static checker warning for <= 0, my static checker really wants this irq_domain_add_linear() to be cleaned up on the error path.

Otherwise it probably leads to a use after free because we free data (automatically or manually) but it's still on a list somewhere.

Quoted 4 lines
Quoted 4 lines
drivers/irqchip/irq-realtek-intc-common.c new file +4 -0
+	if (!data->domain) {
+		ret = -ENOMEM;
+		goto out_cleanup;
+	}
Quoted 8 lines

drivers/irqchip/irq-realtek-intc-common.c line 188

Quoted 8 lines
drivers/irqchip/irq-realtek-intc-common.c new file +8 -0
+
+	data->subset_data_num = info->cfg_num;
+	for (i = 0; i < info->cfg_num; i++) {
+		ret = realtek_intc_subset(node, data, i);
+		if (ret) {
+			WARN(ret, "failed to init subset %d: %d", i, ret);
+			ret = -ENOMEM;
+			goto out_cleanup;

This error path.

regards,
dan carpenter

Quoted 16 lines
Quoted 16 lines
drivers/irqchip/irq-realtek-intc-common.c new file +16 -0
+		}
+	}
+
+	platform_set_drvdata(pdev, data);
+
+	return 0;
+
+out_cleanup:
+
+	if (data->base)
+		iounmap(data->base);
+
+	devm_kfree(dev, data);
+
+	return ret;
+}
#7 lore raw

RE: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

Hi Dan,

Quoted 6 lines
Quoted 5 lines

devm_ allocations are cleaned up automatically so there is no need to call devm_kfree() before returning.

regards,
dan carpenter

I will remove it.

Quoted 13 lines
Quoted 8 lines

drivers/irqchip/irq-realtek-intc-common.c

Quoted 8 lines
drivers/irqchip/irq-realtek-intc-common.c new file +8 -0
+   }
+
+   data->info = info;
+
+   raw_spin_lock_init(&data->lock);
+
+   data->domain = irq_domain_add_linear(node, 32,
+ &realtek_intc_domain_ops, data);

Btw, as I was testing the other static checker warning for <= 0, my static checker really wants this irq_domain_add_linear() to be cleaned up on the error path.

Quoted 3 lines

Otherwise it probably leads to a use after free because we free data (automatically or manually) but it's still on a list somewhere.

I will add 'irq_domain_remove()' to release it.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/irqchip/irq-realtek-intc-common.c new file +4 -0
+   if (!data->domain) {
+           ret = -ENOMEM;
+           goto out_cleanup;
+   }
Quoted 8 lines

drivers/irqchip/irq-realtek-intc-common.c line 188

Quoted 8 lines
drivers/irqchip/irq-realtek-intc-common.c new file +8 -0
+
+   data->subset_data_num = info->cfg_num;
+   for (i = 0; i < info->cfg_num; i++) {
+           ret = realtek_intc_subset(node, data, i);
+           if (ret) {
+                   WARN(ret, "failed to init subset %d: %d", i, ret);
+                   ret = -ENOMEM;
+                   goto out_cleanup;
Quoted 5 lines

This error path.

regards,
dan carpenter

I will add 'irq_domain_remove()' before goto cleanup.

	for (i = 0; i < info->cfg_num; i++) {
		ret = realtek_intc_subset(node, data, i);
		if (ret) {
			WARN(ret, "failed to init subset %d: %d", i, ret);
			irq_domain_remove(data->domain);
			ret = -ENOMEM;
			goto out_cleanup;
		}
	}

Thank you for your feedback.

Regards,
James

#8 lore raw

Re: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

Quoted 58 lines · James Tai [戴志峰]

Hi Dan,

Quoted 6 lines
Quoted 5 lines

devm_ allocations are cleaned up automatically so there is no need to call devm_kfree() before returning.

regards,
dan carpenter

I will remove it.

Quoted 13 lines
Quoted 8 lines

drivers/irqchip/irq-realtek-intc-common.c

Quoted 8 lines
drivers/irqchip/irq-realtek-intc-common.c new file +8 -0
+   }
+
+   data->info = info;
+
+   raw_spin_lock_init(&data->lock);
+
+   data->domain = irq_domain_add_linear(node, 32,
+ &realtek_intc_domain_ops, data);

Btw, as I was testing the other static checker warning for <= 0, my static checker really wants this irq_domain_add_linear() to be cleaned up on the error path.

Quoted 3 lines

Otherwise it probably leads to a use after free because we free data (automatically or manually) but it's still on a list somewhere.

I will add 'irq_domain_remove()' to release it.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/irqchip/irq-realtek-intc-common.c new file +4 -0
+   if (!data->domain) {
+           ret = -ENOMEM;
+           goto out_cleanup;
+   }
Quoted 8 lines

drivers/irqchip/irq-realtek-intc-common.c line 188

Quoted 8 lines
drivers/irqchip/irq-realtek-intc-common.c new file +8 -0
+
+   data->subset_data_num = info->cfg_num;
+   for (i = 0; i < info->cfg_num; i++) {
+           ret = realtek_intc_subset(node, data, i);
+           if (ret) {
+                   WARN(ret, "failed to init subset %d: %d", i, ret);
+                   ret = -ENOMEM;
+                   goto out_cleanup;
Quoted 5 lines

This error path.

regards,
dan carpenter

I will add 'irq_domain_remove()' before goto cleanup.

	for (i = 0; i < info->cfg_num; i++) {
		ret = realtek_intc_subset(node, data, i);
		if (ret) {
			WARN(ret, "failed to init subset %d: %d", i, ret);
			irq_domain_remove(data->domain);
			ret = -ENOMEM;
			goto out_cleanup;
		}
	}
Quoted 1 line

Thank you for your feedback.

You're running into the issue because you're using One Err Label style error handling. It would be better to use normal unwind laddering. See my blog for more info:

https://staticthinking.wordpress.com/2022/04/28/free-the-last-thing-style/

regards,
dan carpenter

maintainer
#10 lore raw

Re: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

In reply to Dan Carpenter
Quoted 16 lines · Dan Carpenter

drivers/irqchip/irq-realtek-intc-common.c line 145

Quoted 9 lines · James Tai
drivers/irqchip/irq-realtek-intc-common.c new file +9 -0
+static int realtek_intc_subset(struct device_node *node, struct realtek_intc_data *data, int index)
+{
+	struct realtek_intc_subset_data *subset_data = &data->subset_data[index];
+	const struct realtek_intc_subset_cfg *cfg = &data->info->cfg[index];
+	int irq;
+
+	irq = irq_of_parse_and_map(node, index);
+	if (irq <= 0)
+		return irq;

I don't think irq_of_parse_and_map() can return negatives. Only zero on error. Returning zero on error is a historical artifact with IRQ functions and a constant source of bugs. But here returning zero is success. See my blog for more details:
https://staticthinking.wordpress.com/2023/08/07/writing-a-check-for-zero-irq-error-codes/

It's worse than that. The irq functions historically returned NO_IRQ on error, but that could be 0 or -1 depending on the arch.

Use of_irq_get() instead. It's a bit better in that it returns an error code for most cases. But still returns 0 on mapping failure.

Rob

#11 lore raw

RE: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

Hi Rob,

Quoted 21 lines · Dan Carpenter
Quoted 4 lines · James Tai

Review

Quoted 3 lines
(quoted diff) +3 -0
+static int realtek_intc_subset(struct device_node *node, struct
+realtek_intc_data *data, int index) {
+   struct realtek_intc_subset_data *subset_data =

&data->subset_data[index];

Quoted 7 lines

drivers/irqchip/irq-realtek-intc-common.c line 145

Quoted 6 lines
drivers/irqchip/irq-realtek-intc-common.c new file +6 -0
+   const struct realtek_intc_subset_cfg *cfg = &data->info->cfg[index];
+   int irq;
+
+   irq = irq_of_parse_and_map(node, index);
+   if (irq <= 0)
+           return irq;
Quoted 6 lines

I don't think irq_of_parse_and_map() can return negatives. Only zero on error. Returning zero on error is a historical artifact with IRQ functions and a constant source of bugs. But here returning zero is success. See my blog for more details:
https://staticthinking.wordpress.com/2023/08/07/writing-a-check-for-ze
ro-irq-error-codes/

Quoted 6 lines

It's worse than that. The irq functions historically returned NO_IRQ on error, but that could be 0 or -1 depending on the arch.

Use of_irq_get() instead. It's a bit better in that it returns an error code for most cases. But still returns 0 on mapping failure.

I will use of_irq_get() instead and adjust the return value of realtek_intc_subset() in the next patches.

Thanks for your feedback.

Regards,
James

#12 lore raw

Re: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

In reply to James Tai
Quoted 11 lines · James Tai

Realtek DHC (Digital Home Center) SoCs share a common interrupt controller design. This universal interrupt controller driver provides support for various variants within the Realtek DHC SoC family.

Each DHC SoC features two sets of extended interrupt controllers, each capable of handling up to 32 interrupts. These expansion controllers are connected to the GIC (Generic Interrupt Controller).

These tags are pointless as they are not related to anything in tree. You addressed review comments and 0-day fallout, but neither Dan nor 0-day reported that the interrupt controller for Realtek DHC SoCs is missing.

drivers/irqchip/irq-realtek-intc-common.c line 16

Quoted 3 lines
drivers/irqchip/irq-realtek-intc-common.c new file +3 -0
+#include "irq-realtek-intc-common.h"
+
+struct realtek_intc_data;

struct realtek_intc_data is declared in irq-realtek-intc-common.h, so what's the point of this forward declaration?

drivers/irqchip/irq-realtek-intc-common.c line 25

Quoted 8 lines
drivers/irqchip/irq-realtek-intc-common.c new file +8 -0
+static inline unsigned int realtek_intc_get_ints(struct realtek_intc_data *data)
+{
+	return readl(data->base + data->info->isr_offset);
+}
+
+static inline void realtek_intc_clear_ints_bit(struct realtek_intc_data *data, int bit)
+{
+	writel(BIT(bit) & ~1, data->base + data->info->isr_offset);

That '& ~1' solves what aside of preventing bit 0 from being written?

Quoted 4 lines
drivers/irqchip/irq-realtek-intc-common.c new file +4 -0
+static int realtek_intc_domain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
+{
+	struct realtek_intc_data *data = d->host_data;
+

drivers/irqchip/irq-realtek-intc-common.c line 134

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+	irq_set_chip_and_handler(irq, &realtek_intc_chip, handle_level_irq);
+	irq_set_chip_data(irq, data);
+	irq_set_probe(irq);
+
+	return 0;
+}
+
+static const struct irq_domain_ops realtek_intc_domain_ops = {
+	.xlate = irq_domain_xlate_onecell,
+	.map = realtek_intc_domain_map,

.xlate = irq_domain_xlate_onecell,
.map = realtek_intc_domain_map,

Please.

drivers/irqchip/irq-realtek-intc-common.c line 143

Quoted 9 lines
drivers/irqchip/irq-realtek-intc-common.c new file +9 -0
+};
+
+static int realtek_intc_subset(struct device_node *node, struct realtek_intc_data *data, int index)
+{
+	struct realtek_intc_subset_data *subset_data = &data->subset_data[index];
+	const struct realtek_intc_subset_cfg *cfg = &data->info->cfg[index];
+	int irq;
+
+	irq = irq_of_parse_and_map(node, index);

irq_of_parse_and_map() returns an 'unsigned int' where 0 is fail.

Quoted 16 lines
drivers/irqchip/irq-realtek-intc-common.c new file +16 -0
+	if (irq <= 0)
+		return irq;
+
+	subset_data->common = data;
+	subset_data->cfg = cfg;
+	subset_data->parent_irq = irq;
+	irq_set_chained_handler_and_data(irq, realtek_intc_handler, subset_data);
+
+	return 0;
+}
+
+int realtek_intc_probe(struct platform_device *pdev, const struct realtek_intc_info *info)
+{
+	struct realtek_intc_data *data;
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;

drivers/irqchip/irq-realtek-intc-common.c line 169

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+	int ret, i;
+
+	data = devm_kzalloc(dev, struct_size(data, subset_data, info->cfg_num), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->base = of_iomap(node, 0);
+	if (!data->base) {
+		ret = -ENOMEM;
+		goto out_cleanup;

devm_kzalloc() is automatically cleaned up when the probe function fails, so 'return -ENOMEM;' is sufficient.

drivers/irqchip/irq-realtek-intc-common.c line 178

Quoted 9 lines
drivers/irqchip/irq-realtek-intc-common.c new file +9 -0
+	}
+
+	data->info = info;
+
+	raw_spin_lock_init(&data->lock);
+
+	data->domain = irq_domain_add_linear(node, 32, &realtek_intc_domain_ops, data);
+	if (!data->domain) {
+		ret = -ENOMEM;

This 'ret = -ENOMEM;' is pointless as the only error code returned in this function is -ENOMEM. So you can just return -ENOMEM in the error path, no?

drivers/irqchip/irq-realtek-intc-common.c line 188

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+		goto out_cleanup;
+	}
+
+	data->subset_data_num = info->cfg_num;
+	for (i = 0; i < info->cfg_num; i++) {
+		ret = realtek_intc_subset(node, data, i);
+		if (ret) {
+			WARN(ret, "failed to init subset %d: %d", i, ret);
+			ret = -ENOMEM;
+			goto out_cleanup;
                if (WARN(ret, "....."))
                	goto cleanup;

drivers/irqchip/irq-realtek-intc-common.c line 199

Quoted 11 lines
drivers/irqchip/irq-realtek-intc-common.c new file +11 -0
+		}
+	}
+
+	platform_set_drvdata(pdev, data);
+
+	return 0;
+
+out_cleanup:
+
+	if (data->base)
+		iounmap(data->base);

Leaks the irqdomain.

drivers/irqchip/irq-realtek-intc-common.c line 201

Quoted 2 lines
drivers/irqchip/irq-realtek-intc-common.c new file +2 -0
+
+	devm_kfree(dev, data);

Pointless exercise.

drivers/irqchip/irq-realtek-intc-common.c line 205

Quoted 3 lines
drivers/irqchip/irq-realtek-intc-common.c new file +3 -0
+	return ret;
+}
+EXPORT_SYMBOL(realtek_intc_probe);

EXPORT_SYMBOL_GPL

drivers/irqchip/irq-realtek-intc-common.h line 19

Quoted 7 lines
drivers/irqchip/irq-realtek-intc-common.h new file +7 -0
+/**
+ * realtek_intc_subset_cfg - subset interrupt mask
+ * @ints_mask: inetrrupt mask
+ */
+struct realtek_intc_subset_cfg {
+	unsigned int	ints_mask;
+};

The value of a struct wrapping a single 'unsigned int' is? What's wrong with using unsigned int (actually you want u32 as this represents a hardware mask) directly? Not enough obfuscation, right?

Quoted 7 lines

+/**
+ * realtek_intc_info - interrupt controller data.
+ * @isr_offset: interrupt status register offset.
+ * @umsk_isr_offset: unmask interrupt status register offset.
+ * @scpu_int_en_offset: interrupt enable register offset.
+ * @cfg: cfg of the subset.
+ * @cfg_num: number of cfg.

* @isr_offset: interrupt status register offset
* @umsk_isr_offset: unmask interrupt status register offset
* @scpu_int_en_offset: interrupt enable register offset

Can you spot the difference?

Please fix all over the place.

Quoted 4 lines

+ */

drivers/irqchip/irq-realtek-intc-common.h new file +3 -0
+struct realtek_intc_info {
+	const struct realtek_intc_subset_cfg *cfg;
+	unsigned int			     isr_offset;

drivers/irqchip/irq-realtek-intc-common.h line 41

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.h new file +10 -0
+	unsigned int			     umsk_isr_offset;
+	unsigned int			     scpu_int_en_offset;
+	const u32			     *isr_to_scpu_int_en_mask;
+	int				     cfg_num;
+};
+
+/**
+ * realtek_intc_subset_data - handler of a interrupt source only handles ints
+ *                            bits in the mask.
+ * @cfg: cfg of the subset.

Seriously. 'cfg of'? This is a description, so can you spell the words out? This is really neither space constraint nor subject to Xitter rules. Fix this all over the place please.

Quoted 22 lines

+ * @common: common data.
+ * @parent_irq: interrupt source.
+ */

drivers/irqchip/irq-realtek-intc-common.h new file +19 -0
+struct realtek_intc_subset_data {
+	const struct realtek_intc_subset_cfg *cfg;
+	struct realtek_intc_data	     *common;
+	int				     parent_irq;
+};
+
+/**
+ * realtek_intc_data - configuration data for realtek interrupt controller driver.
+ * @base: base of interrupt register
+ * @info: info of intc
+ * @domain: interrupt domain
+ * @lock: lock
+ * @saved_en: status of interrupt enable
+ * @subset_data_num: number of subset data
+ * @subset_data: subset data
+ */
+struct realtek_intc_data {
+	void __iomem			*base;
+	const struct realtek_intc_info	*info;

drivers/irqchip/irq-realtek-intc-common.h line 73

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.h new file +10 -0
+	struct irq_domain		*domain;
+	struct raw_spinlock		lock;
+	unsigned int			saved_en;
+	int				subset_data_num;
+	struct realtek_intc_subset_data subset_data[];
+};
+
+#define IRQ_ALWAYS_ENABLED U32_MAX
+#define DISABLE_INTC (0)
+#define CLEAN_INTC_STATUS GENMASK(31, 1)

#define IRQ_ALWAYS_ENABLED U32_MAX
#define DISABLE_INTC (0)
#define CLEAN_INTC_STATUS GENMASK(31, 1)

Please, as that makes this readable.

Thanks,

tglx

#13 lore raw

RE: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

Hi Thomas,

Quoted 9 lines · James Tai
Quoted 8 lines

Realtek DHC (Digital Home Center) SoCs share a common interrupt controller design. This universal interrupt controller driver provides support for various variants within the Realtek DHC SoC family.

Each DHC SoC features two sets of extended interrupt controllers, each capable of handling up to 32 interrupts. These expansion controllers are connected to the GIC (Generic Interrupt Controller).

Quoted 8 lines
Quoted 3 lines

These tags are pointless as they are not related to anything in tree. You addressed review comments and 0-day fallout, but neither Dan nor 0-day reported that the interrupt controller for Realtek DHC SoCs is missing.

I will remove it.

Quoted 7 lines

drivers/irqchip/irq-realtek-intc-common.c line 16

Quoted 3 lines
drivers/irqchip/irq-realtek-intc-common.c new file +3 -0
+#include "irq-realtek-intc-common.h"
+
+struct realtek_intc_data;

struct realtek_intc_data is declared in irq-realtek-intc-common.h, so what's the point of this forward declaration?

This is a meaningless declaration, and I will remove it.

Quoted 10 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static inline unsigned int realtek_intc_get_ints(struct
+realtek_intc_data *data) {
+     return readl(data->base + data->info->isr_offset); }
+
+static inline void realtek_intc_clear_ints_bit(struct
+realtek_intc_data *data, int bit) {
+     writel(BIT(bit) & ~1, data->base + data->info->isr_offset);

That '& ~1' solves what aside of preventing bit 0 from being written?

The ISR register uses bit 0 to clear or set ISR status.
Write 0 to clear bits and write 1 to set bits.
Therefore, to clear the interrupt status, bit 0 should consistently be set to '0'.

Quoted 18 lines
Quoted 4 lines
drivers/irqchip/irq-realtek-intc-common.c new file +4 -0
+static int realtek_intc_domain_map(struct irq_domain *d, unsigned int
+irq, irq_hw_number_t hw) {
+     struct realtek_intc_data *data = d->host_data;
+

drivers/irqchip/irq-realtek-intc-common.c line 134

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+     irq_set_chip_and_handler(irq, &realtek_intc_chip, handle_level_irq);
+     irq_set_chip_data(irq, data);
+     irq_set_probe(irq);
+
+     return 0;
+}
+
+static const struct irq_domain_ops realtek_intc_domain_ops = {
+     .xlate = irq_domain_xlate_onecell,
+     .map = realtek_intc_domain_map,

.xlate = irq_domain_xlate_onecell,
.map = realtek_intc_domain_map,

Quoted 2 lines

Please.

I will fix it.

Quoted 6 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+};
+
+static int realtek_intc_subset(struct device_node *node, struct
+realtek_intc_data *data, int index) {
+     struct realtek_intc_subset_data *subset_data =

&data->subset_data[index];

Quoted 7 lines

drivers/irqchip/irq-realtek-intc-common.c line 143

Quoted 4 lines
drivers/irqchip/irq-realtek-intc-common.c new file +4 -0
+     const struct realtek_intc_subset_cfg *cfg = &data->info->cfg[index];
+     int irq;
+
+     irq = irq_of_parse_and_map(node, index);

irq_of_parse_and_map() returns an 'unsigned int' where 0 is fail.

I will use of_irq_get() instead.

Quoted 29 lines
Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+     if (irq <= 0)
+             return irq;
+
+     subset_data->common = data;
+     subset_data->cfg = cfg;
+     subset_data->parent_irq = irq;
+     irq_set_chained_handler_and_data(irq, realtek_intc_handler,
+ subset_data);
+
+     return 0;

drivers/irqchip/irq-realtek-intc-common.c

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+}
+
+int realtek_intc_probe(struct platform_device *pdev, const struct
+realtek_intc_info *info) {
+     struct realtek_intc_data *data;
+     struct device *dev = &pdev->dev;
+     struct device_node *node = dev->of_node;
+     int ret, i;
+
+     data = devm_kzalloc(dev, struct_size(data, subset_data,

info->cfg_num), GFP_KERNEL);

drivers/irqchip/irq-realtek-intc-common.c line 169

Quoted 7 lines
drivers/irqchip/irq-realtek-intc-common.c new file +7 -0
+     if (!data)
+             return -ENOMEM;
+
+     data->base = of_iomap(node, 0);
+     if (!data->base) {
+             ret = -ENOMEM;
+             goto out_cleanup;
Quoted 2 lines

devm_kzalloc() is automatically cleaned up when the probe function fails, so 'return -ENOMEM;' is sufficient.

I will adjust it.

Quoted 9 lines

drivers/irqchip/irq-realtek-intc-common.c

Quoted 8 lines
drivers/irqchip/irq-realtek-intc-common.c new file +7 -0
+     }
+
+     data->info = info;
+
+     raw_spin_lock_init(&data->lock);
+
+     data->domain = irq_domain_add_linear(node, 32,

&realtek_intc_domain_ops, data);

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+     if (!data->domain) {
+             ret = -ENOMEM;

This 'ret = -ENOMEM;' is pointless as the only error code returned in this function is -ENOMEM. So you can just return -ENOMEM in the error path, no?

Yes. it is pointless and I will adjust it.

Quoted 11 lines

drivers/irqchip/irq-realtek-intc-common.c line 188

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.c new file +10 -0
+             goto out_cleanup;
+     }
+
+     data->subset_data_num = info->cfg_num;
+     for (i = 0; i < info->cfg_num; i++) {
+             ret = realtek_intc_subset(node, data, i);
+             if (ret) {
+                     WARN(ret, "failed to init subset %d: %d", i, ret);
+                     ret = -ENOMEM;
+                     goto out_cleanup;
Quoted 3 lines
               if (WARN(ret, "....."))
                       goto cleanup;

I will fix it.

Quoted 5 lines
Quoted 5 lines
drivers/irqchip/irq-realtek-intc-common.c new file +5 -0
+             }
+     }
+
+     platform_set_drvdata(pdev, data);
+
Quoted 9 lines

drivers/irqchip/irq-realtek-intc-common.c line 199

Quoted 6 lines
drivers/irqchip/irq-realtek-intc-common.c new file +6 -0
+     return 0;
+
+out_cleanup:
+
+     if (data->base)
+             iounmap(data->base);

Leaks the irqdomain.

I will add error handle for irqdomain.

Quoted 5 lines

drivers/irqchip/irq-realtek-intc-common.c line 201

Quoted 2 lines
drivers/irqchip/irq-realtek-intc-common.c new file +2 -0
+
+     devm_kfree(dev, data);

Pointless exercise.

I will remove it.

Quoted 6 lines

drivers/irqchip/irq-realtek-intc-common.c line 205

Quoted 3 lines
drivers/irqchip/irq-realtek-intc-common.c new file +3 -0
+     return ret;
+}
+EXPORT_SYMBOL(realtek_intc_probe);

EXPORT_SYMBOL_GPL

I will fix it.

Quoted 12 lines

drivers/irqchip/irq-realtek-intc-common.h line 19

Quoted 7 lines
drivers/irqchip/irq-realtek-intc-common.h new file +7 -0
+/**
+ * realtek_intc_subset_cfg - subset interrupt mask
+ * @ints_mask: inetrrupt mask
+ */
+struct realtek_intc_subset_cfg {
+     unsigned int    ints_mask;
+};

The value of a struct wrapping a single 'unsigned int' is? What's wrong with using unsigned int (actually you want u32 as this represents a hardware mask) directly? Not enough obfuscation, right?

Yes, it represents a set of hardware masks, so using u32 instead of 'unsigned int' is more appropriate. There are no issues with obfuscation.

Quoted 8 lines
Quoted 7 lines

+/**
+ * realtek_intc_info - interrupt controller data.
+ * @isr_offset: interrupt status register offset.
+ * @umsk_isr_offset: unmask interrupt status register offset.
+ * @scpu_int_en_offset: interrupt enable register offset.
+ * @cfg: cfg of the subset.
+ * @cfg_num: number of cfg.

Quoted 6 lines

* @isr_offset: interrupt status register offset
* @umsk_isr_offset: unmask interrupt status register offset
* @scpu_int_en_offset: interrupt enable register offset

Can you spot the difference?

The interrupt control registers of the DHC platform are not linearly arranged, which necessitates the use of a mechanism for efficient reading and writing of these registers.
The 'scpu_int_en' register serves the purpose of controlling whether peripheral devices' interrupts are enabled or disabled.
The 'isr' register represents the interrupt status. It can mask interrupts using the 'scpu_int_en' register. When the 'scpu_int_en' register disables interrupts, the 'isr' register will not reflect the interrupt status. The 'umsk_isr' register also represents the interrupt status but is not influenced by any other control register to mask interrupts. In short, it reflects the original interrupt status.

Quoted 2 lines

Please fix all over the place.

I will fix it.

Quoted 8 lines

drivers/irqchip/irq-realtek-intc-common.h

Quoted 7 lines

+ */

drivers/irqchip/irq-realtek-intc-common.h new file +6 -0
+struct realtek_intc_info {
+     const struct realtek_intc_subset_cfg *cfg;
+     unsigned int                         isr_offset;
+     unsigned int                         umsk_isr_offset;
+     unsigned int                         scpu_int_en_offset;
+     const u32

*isr_to_scpu_int_en_mask;

Quoted 11 lines

drivers/irqchip/irq-realtek-intc-common.h line 41

Quoted 7 lines
drivers/irqchip/irq-realtek-intc-common.h new file +7 -0
+     int                                  cfg_num;
+};
+
+/**
+ * realtek_intc_subset_data - handler of a interrupt source only handles ints
+ *                            bits in the mask.
+ * @cfg: cfg of the subset.

Seriously. 'cfg of'? This is a description, so can you spell the words out? This is really neither space constraint nor subject to Xitter rules. Fix this all over the place please.

I will adjust the description so that it clearly describes the intended purpose.

Quoted 38 lines

drivers/irqchip/irq-realtek-intc-common.h

Quoted 12 lines

+ * @common: common data.
+ * @parent_irq: interrupt source.
+ */

drivers/irqchip/irq-realtek-intc-common.h new file +8 -0
+struct realtek_intc_subset_data {
+     const struct realtek_intc_subset_cfg *cfg;
+     struct realtek_intc_data             *common;
+     int                                  parent_irq;
+};
+
+/**
+ * realtek_intc_data - configuration data for realtek interrupt controller

driver.

Quoted 10 lines

+ * @base: base of interrupt register
+ * @info: info of intc
+ * @domain: interrupt domain
+ * @lock: lock
+ * @saved_en: status of interrupt enable
+ * @subset_data_num: number of subset data
+ * @subset_data: subset data
+ */

drivers/irqchip/irq-realtek-intc-common.h new file +2 -0
+struct realtek_intc_data {
+     void __iomem                    *base;

drivers/irqchip/irq-realtek-intc-common.h line 73

Quoted 10 lines
drivers/irqchip/irq-realtek-intc-common.h new file +10 -0
+     const struct realtek_intc_info  *info;
+     struct irq_domain               *domain;
+     struct raw_spinlock             lock;
+     unsigned int                    saved_en;
+     int                             subset_data_num;
+     struct realtek_intc_subset_data subset_data[]; };
+
+#define IRQ_ALWAYS_ENABLED U32_MAX
+#define DISABLE_INTC (0)
+#define CLEAN_INTC_STATUS GENMASK(31, 1)
#define IRQ_ALWAYS_ENABLED      U32_MAX
#define DISABLE_INTC            (0)
#define CLEAN_INTC_STATUS       GENMASK(31, 1)
Quoted 2 lines

Please, as that makes this readable.

I will improve it.

Thanks for your feedback.

Regards,
James

#14 lore raw

RE: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

Quoted 11 lines · James Tai [戴志峰]
Quoted 7 lines · James Tai

Review

Quoted 3 lines
(quoted diff) +3 -0
+static inline void realtek_intc_clear_ints_bit(struct
+realtek_intc_data *data, int bit) {
+     writel(BIT(bit) & ~1, data->base + data->info->isr_offset);

That '& ~1' solves what aside of preventing bit 0 from being written?

The ISR register uses bit 0 to clear or set ISR status. Write 0 to clear bits and write 1 to set bits.
Therefore, to clear the interrupt status, bit 0 should consistently be set to '0'.

And how does BIT(bit) with 1 <= bit <= 31 end up having bit 0 set?

Also a comment explaining the reasoning here would be helpful.

#15 lore raw

RE: [PATCH v3 2/6] irqchip: Add interrupt controller support for Realtek DHC SoCs

Hi Thomas,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · James Tai

Review

Quoted 3 lines
(quoted diff) +3 -0
+static inline void realtek_intc_clear_ints_bit(struct
+realtek_intc_data *data, int bit) {
+     writel(BIT(bit) & ~1, data->base + data->info->isr_offset);

That '& ~1' solves what aside of preventing bit 0 from being written?

Quoted 8 lines
Quoted 4 lines

The ISR register uses bit 0 to clear or set ISR status. Write 0 to clear bits and write 1 to set bits.
Therefore, to clear the interrupt status, bit 0 should consistently be set to '0'.

And how does BIT(bit) with 1 <= bit <= 31 end up having bit 0 set?

Also a comment explaining the reasoning here would be helpful.

To perform the clearing action in the ISR register, it's essential that bit 0 remains set to 0.
This is because bit 0 in the ISR register has a specific function for controlling the interrupt status.
When BIT(bit) is used with 1 <= bit <= 31, it generates a bitmask with only that particular bit set to 1, and all other bits, including bit 0, set to 0. The '& ~1' operation is then applied to ensure that even if bit 0 was somehow set, it will be cleared, maintaining the register's functionality.

For example, suppose the current value of the ISR register is 0x4, and we want to clear bit 3. In that case, writing 0x4 (which represents bit 3 set to 1) to the ISR register will clear bit 3.

Thanks for your feedback.

Regards,
James

author
#16 lore raw

PATCH v3 3/6 irqchip: Introduce RTD1319 support using the Realtek common interrupt controller driver

In reply to James Tai

Add support for the RTD1319 platform.

---
v2 to v3 change:
- Unchanged

v1 to v2 change:
- Resolved kernel test robot build warnings
- Replaced magic number with macro
- Fixed code style issues

 drivers/irqchip/Kconfig               |   6 +
 drivers/irqchip/Makefile              |   1 +
 drivers/irqchip/irq-realtek-rtd1319.c | 218 ++++++++++++++++++++++++++
 3 files changed, 225 insertions(+)
 create mode 100644 drivers/irqchip/irq-realtek-rtd1319.c
drivers/irqchip/Kconfig +6 -0
index 267c3429b48d..05856ce885fa 100644
@@ -222,6 +222,12 @@ config REALTEK_DHC_INTC
 	tristate
 	select IRQ_DOMAIN
 
+config REALTEK_RTD1319_INTC
+	tristate "Realtek RTD1319 interrupt controller"
+	select REALTEK_DHC_INTC
+	help
+	  Support for Realtek RTD1319 Interrupt Controller.
+
 config RENESAS_INTC_IRQPIN
 	bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST
 	select IRQ_DOMAIN
drivers/irqchip/Makefile +1 -0
index f6774af7fde2..6a2650b0a924 100644
@@ -48,6 +48,7 @@ obj-$(CONFIG_IXP4XX_IRQ)		+= irq-ixp4xx.o
 obj-$(CONFIG_JCORE_AIC)			+= irq-jcore-aic.o
 obj-$(CONFIG_RDA_INTC)			+= irq-rda-intc.o
 obj-$(CONFIG_REALTEK_DHC_INTC)		+= irq-realtek-intc-common.o
+obj-$(CONFIG_REALTEK_RTD1319_INTC)	+= irq-realtek-rtd1319.o
 obj-$(CONFIG_RENESAS_INTC_IRQPIN)	+= irq-renesas-intc-irqpin.o
 obj-$(CONFIG_RENESAS_IRQC)		+= irq-renesas-irqc.o
 obj-$(CONFIG_RENESAS_RZA1_IRQC)		+= irq-renesas-rza1.o
drivers/irqchip/irq-realtek-rtd1319.c new file +218 -0

218 lines not on this page · raw message

Signature · 1 line
2.25.1
#17 lore raw

Re: [PATCH v3 3/6] irqchip: Introduce RTD1319 support using the Realtek common interrupt controller driver

Quoted 5 lines · James Tai

Add support for the RTD1319 platform.

Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

Again: These tags are just wrong.

drivers/irqchip/irq-realtek-rtd1319.c line 202

Quoted 8 lines
drivers/irqchip/irq-realtek-rtd1319.c new file +8 -0
+static struct platform_driver realtek_intc_rtd1319_driver = {
+	.probe = rtd1319_intc_probe,
+	.driver = {
+		.name = "realtek_intc_rtd1319",
+		.of_match_table = realtek_intc_rtd1319_dt_matches,
+		.suppress_bind_attrs = true,
+		.pm = &realtek_intc_rtd1319_pm_ops,
+	},
	.probe	= rtd1319_intc_probe,
	.driver	= {
		.name			= "realtek_intc_rtd1319",
		.of_match_table		= realtek_intc_rtd1319_dt_matches,
                ....

Please.

drivers/irqchip/irq-realtek-rtd1319.c line 209

Quoted 7 lines
drivers/irqchip/irq-realtek-rtd1319.c new file +7 -0
+};
+
+static int __init realtek_intc_rtd1319_init(void)
+{
+	return platform_driver_register(&realtek_intc_rtd1319_driver);
+}
+core_initcall(realtek_intc_rtd1319_init);

What? This can be built as a module. So how is core_initcall() in any way correct here? module_init() perhaps?

Thanks,

tglx

#18 lore raw

RE: [PATCH v3 3/6] irqchip: Introduce RTD1319 support using the Realtek common interrupt controller driver

Hi Thomas,

Quoted 9 lines · James Tai
Quoted 6 lines

Add support for the RTD1319 platform.

Closes:
https://lore.kernel.org/oe-kbuild-all/202311061208.hJmxGqym-lkp@intel.
com/

Again: These tags are just wrong.

I will remove it.

Quoted 9 lines

drivers/irqchip/irq-realtek-rtd1319.c line 202

Quoted 8 lines
drivers/irqchip/irq-realtek-rtd1319.c new file +8 -0
+static struct platform_driver realtek_intc_rtd1319_driver = {
+     .probe = rtd1319_intc_probe,
+     .driver = {
+             .name = "realtek_intc_rtd1319",
+             .of_match_table = realtek_intc_rtd1319_dt_matches,
+             .suppress_bind_attrs = true,
+             .pm = &realtek_intc_rtd1319_pm_ops,
+     },
Quoted 9 lines
       .probe  = rtd1319_intc_probe,
       .driver = {
               .name                   = "realtek_intc_rtd1319",
               .of_match_table         =
realtek_intc_rtd1319_dt_matches,
               ....

Please.

I will fix it.

Quoted 10 lines

drivers/irqchip/irq-realtek-rtd1319.c line 209

Quoted 6 lines
drivers/irqchip/irq-realtek-rtd1319.c new file +6 -0
+};
+
+static int __init realtek_intc_rtd1319_init(void) {
+     return platform_driver_register(&realtek_intc_rtd1319_driver);
+}
+core_initcall(realtek_intc_rtd1319_init);

What? This can be built as a module. So how is core_initcall() in any way correct here? module_init() perhaps?

I want the driver to be buildable as a module. Based on my test, the 'core_initcall()' works. But, I will use 'module_init()' instead.

Thanks for your feedback.

Regards,
James

#19 lore raw

Re: [PATCH v3 3/6] irqchip: Introduce RTD1319 support using the Realtek common interrupt controller driver

In reply to James Tai
Quoted 60 lines · James Tai

Add support for the RTD1319 platform.

---
v2 to v3 change:
- Unchanged

v1 to v2 change:
- Resolved kernel test robot build warnings
- Replaced magic number with macro
- Fixed code style issues

 drivers/irqchip/Kconfig               |   6 +
 drivers/irqchip/Makefile              |   1 +
 drivers/irqchip/irq-realtek-rtd1319.c | 218 ++++++++++++++++++++++++++
 3 files changed, 225 insertions(+)
 create mode 100644 drivers/irqchip/irq-realtek-rtd1319.c
drivers/irqchip/Kconfig +6 -0
index 267c3429b48d..05856ce885fa 100644
@@ -222,6 +222,12 @@ config REALTEK_DHC_INTC
        tristate
        select IRQ_DOMAIN
 
+config REALTEK_RTD1319_INTC
+       tristate "Realtek RTD1319 interrupt controller"
+       select REALTEK_DHC_INTC
+       help
+         Support for Realtek RTD1319 Interrupt Controller.
+
 config RENESAS_INTC_IRQPIN
        bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST
        select IRQ_DOMAIN
drivers/irqchip/Makefile +1 -0
index f6774af7fde2..6a2650b0a924 100644
@@ -48,6 +48,7 @@ obj-$(CONFIG_IXP4XX_IRQ)              += irq-ixp4xx.o
 obj-$(CONFIG_JCORE_AIC)                        += irq-jcore-aic.o
 obj-$(CONFIG_RDA_INTC)                 += irq-rda-intc.o
 obj-$(CONFIG_REALTEK_DHC_INTC)         += irq-realtek-intc-common.o
+obj-$(CONFIG_REALTEK_RTD1319_INTC)     += irq-realtek-rtd1319.o
 obj-$(CONFIG_RENESAS_INTC_IRQPIN)      += irq-renesas-intc-irqpin.o
 obj-$(CONFIG_RENESAS_IRQC)             += irq-renesas-irqc.o
 obj-$(CONFIG_RENESAS_RZA1_IRQC)                += irq-renesas-rza1.o
drivers/irqchip/irq-realtek-rtd1319.c new file +1 -0
new file mode 100644
index 000000000000..23c13c218b04
@@ -0,0 +1,218 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)

drivers/irqchip/irq-realtek-rtd1319.c line 11

Quoted 10 lines
drivers/irqchip/irq-realtek-rtd1319.c new file +10 -0
+/*
+ * Realtek RTD1319 interrupt controller driver
+ *
+ * Copyright (c) 2023 Realtek Semiconductor Corporation
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/irqchip.h>
+#include <linux/of_device.h>

You probably don't need this header and the implicit includes it makes are dropped now in linux-next. Please check what you actually need and make them explicit.

Rob

#20 lore raw

RE: [PATCH v3 3/6] irqchip: Introduce RTD1319 support using the Realtek common interrupt controller driver

Hi Rob,

Quoted 9 lines
Quoted 9 lines
drivers/irqchip/irq-realtek-rtd1319.c new file +6 -0
@@ -0,0 +1,218 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Realtek RTD1319 interrupt controller driver
+ *
+ * Copyright (c) 2023 Realtek Semiconductor Corporation  */
+
Quoted 9 lines

drivers/irqchip/irq-realtek-rtd1319.c line 11

Quoted 4 lines
drivers/irqchip/irq-realtek-rtd1319.c new file +4 -0
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/irqchip.h>
+#include <linux/of_device.h>

You probably don't need this header and the implicit includes it makes are dropped now in linux-next. Please check what you actually need and make them explicit.

Thanks for the reminder. I will adjust it.

Regards,
James

author
#21 lore raw

PATCH v3 4/6 irqchip: Introduce RTD1319D support using the Realtek common interrupt controller driver

In reply to James Tai

Add support for the RTD1319D platform.

---
v2 to v3 change:
- Unchanged

v1 to v2 change:
- Resolved kernel test robot build warnings
- Replaced magic number with macro
- Fixed code style issues

 drivers/irqchip/Kconfig                |   6 +
 drivers/irqchip/Makefile               |   1 +
 drivers/irqchip/irq-realtek-rtd1319d.c | 227 +++++++++++++++++++++++++
 3 files changed, 234 insertions(+)
 create mode 100644 drivers/irqchip/irq-realtek-rtd1319d.c
drivers/irqchip/Kconfig +6 -0
index 05856ce885fa..c6552c513442 100644
@@ -228,6 +228,12 @@ config REALTEK_RTD1319_INTC
 	help
 	  Support for Realtek RTD1319 Interrupt Controller.
 
+config REALTEK_RTD1319D_INTC
+	tristate "Realtek RTD1319D interrupt controller"
+	select REALTEK_DHC_INTC
+	help
+	  Support for Realtek RTD1319D Interrupt Controller.
+
 config RENESAS_INTC_IRQPIN
 	bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST
 	select IRQ_DOMAIN
drivers/irqchip/Makefile +1 -0
index 6a2650b0a924..c8adaed4c1b2 100644
@@ -49,6 +49,7 @@ obj-$(CONFIG_JCORE_AIC)			+= irq-jcore-aic.o
 obj-$(CONFIG_RDA_INTC)			+= irq-rda-intc.o
 obj-$(CONFIG_REALTEK_DHC_INTC)		+= irq-realtek-intc-common.o
 obj-$(CONFIG_REALTEK_RTD1319_INTC)	+= irq-realtek-rtd1319.o
+obj-$(CONFIG_REALTEK_RTD1319D_INTC)	+= irq-realtek-rtd1319d.o
 obj-$(CONFIG_RENESAS_INTC_IRQPIN)	+= irq-renesas-intc-irqpin.o
 obj-$(CONFIG_RENESAS_IRQC)		+= irq-renesas-irqc.o
 obj-$(CONFIG_RENESAS_RZA1_IRQC)		+= irq-renesas-rza1.o
drivers/irqchip/irq-realtek-rtd1319d.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#22 lore raw

PATCH v3 5/6 irqchip: Introduce RTD1325 support using the Realtek common interrupt controller driver

In reply to James Tai

Add support for the RTD1325 platform.

---
v2 to v3 change:
- Unchanged

v1 to v2 change:
- Resolved kernel test robot build warnings
- Replaced magic number with macro
- Fixed code style issues

 drivers/irqchip/Kconfig               |   6 +
 drivers/irqchip/Makefile              |   1 +
 drivers/irqchip/irq-realtek-rtd1325.c | 227 ++++++++++++++++++++++++++
 3 files changed, 234 insertions(+)
 create mode 100644 drivers/irqchip/irq-realtek-rtd1325.c
drivers/irqchip/Kconfig +6 -0
index c6552c513442..65e2d67d1505 100644
@@ -234,6 +234,12 @@ config REALTEK_RTD1319D_INTC
 	help
 	  Support for Realtek RTD1319D Interrupt Controller.
 
+config REALTEK_RTD1325_INTC
+	tristate "Realtek RTD1325 interrupt controller"
+	select REALTEK_DHC_INTC
+	help
+	  Support for Realtek RTD1325 Interrupt Controller.
+
 config RENESAS_INTC_IRQPIN
 	bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST
 	select IRQ_DOMAIN
drivers/irqchip/Makefile +1 -0
index c8adaed4c1b2..eaa12928d60b 100644
@@ -50,6 +50,7 @@ obj-$(CONFIG_RDA_INTC)			+= irq-rda-intc.o
 obj-$(CONFIG_REALTEK_DHC_INTC)		+= irq-realtek-intc-common.o
 obj-$(CONFIG_REALTEK_RTD1319_INTC)	+= irq-realtek-rtd1319.o
 obj-$(CONFIG_REALTEK_RTD1319D_INTC)	+= irq-realtek-rtd1319d.o
+obj-$(CONFIG_REALTEK_RTD1325_INTC)	+= irq-realtek-rtd1325.o
 obj-$(CONFIG_RENESAS_INTC_IRQPIN)	+= irq-renesas-intc-irqpin.o
 obj-$(CONFIG_RENESAS_IRQC)		+= irq-renesas-irqc.o
 obj-$(CONFIG_RENESAS_RZA1_IRQC)		+= irq-renesas-rza1.o
drivers/irqchip/irq-realtek-rtd1325.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#23 lore raw

PATCH v3 6/6 irqchip: Introduce RTD1619B support using the Realtek common interrupt controller driver

In reply to James Tai

Add support for the RTD1619B platform.

---
v2 to v3 change:
- Unchanged

v1 to v2 change:
- Resolved kernel test robot build warnings
- Replaced magic number with macro
- Fixed code style issues

 drivers/irqchip/Kconfig                |   6 +
 drivers/irqchip/Makefile               |   1 +
 drivers/irqchip/irq-realtek-rtd1619b.c | 217 +++++++++++++++++++++++++
 3 files changed, 224 insertions(+)
 create mode 100644 drivers/irqchip/irq-realtek-rtd1619b.c
drivers/irqchip/Kconfig +6 -0
index 65e2d67d1505..c5b2762df420 100644
@@ -240,6 +240,12 @@ config REALTEK_RTD1325_INTC
 	help
 	  Support for Realtek RTD1325 Interrupt Controller.
 
+config REALTEK_RTD1619B_INTC
+	tristate "Realtek RTD1619B interrupt controller"
+	select REALTEK_DHC_INTC
+	help
+	  Support for Realtek RTD1619B Interrupt Controller.
+
 config RENESAS_INTC_IRQPIN
 	bool "Renesas INTC External IRQ Pin Support" if COMPILE_TEST
 	select IRQ_DOMAIN
drivers/irqchip/Makefile +1 -0
index eaa12928d60b..da308aefcb87 100644
@@ -51,6 +51,7 @@ obj-$(CONFIG_REALTEK_DHC_INTC)		+= irq-realtek-intc-common.o
 obj-$(CONFIG_REALTEK_RTD1319_INTC)	+= irq-realtek-rtd1319.o
 obj-$(CONFIG_REALTEK_RTD1319D_INTC)	+= irq-realtek-rtd1319d.o
 obj-$(CONFIG_REALTEK_RTD1325_INTC)	+= irq-realtek-rtd1325.o
+obj-$(CONFIG_REALTEK_RTD1619B_INTC)	+= irq-realtek-rtd1619b.o
 obj-$(CONFIG_RENESAS_INTC_IRQPIN)	+= irq-renesas-intc-irqpin.o
 obj-$(CONFIG_RENESAS_IRQC)		+= irq-renesas-irqc.o
 obj-$(CONFIG_RENESAS_RZA1_IRQC)		+= irq-renesas-rza1.o
drivers/irqchip/irq-realtek-rtd1619b.c new file +217 -0

217 lines not on this page · raw message

Signature · 1 line
2.25.1
#24 lore raw

Re: [PATCH v3 6/6] irqchip: Introduce RTD1619B support using the Realtek common interrupt controller driver

Quoted 20 lines · James Tai
drivers/irqchip/irq-realtek-rtd1619b.c new file +20 -0
+static int realtek_intc_rtd1619b_suspend(struct device *dev)
+{
+	struct realtek_intc_data *data = dev_get_drvdata(dev);
+	const struct realtek_intc_info *info = data->info;
+
+	data->saved_en = readl(data->base + info->scpu_int_en_offset);
+
+	writel(DISABLE_INTC, data->base + info->scpu_int_en_offset);
+	writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset);
+	writel(CLEAN_INTC_STATUS, data->base + info->isr_offset);
+
+	return 0;
+}
+
+static int realtek_intc_rtd1619b_resume(struct device *dev)
+{
+	struct realtek_intc_data *data = dev_get_drvdata(dev);
+	const struct realtek_intc_info *info = data->info;
+
+	writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset);

drivers/irqchip/irq-realtek-rtd1619b.c line 181

Quoted 10 lines
drivers/irqchip/irq-realtek-rtd1619b.c new file +10 -0
+	writel(CLEAN_INTC_STATUS, data->base + info->isr_offset);
+	writel(data->saved_en, data->base + info->scpu_int_en_offset);
+
+	return 0;
+}
+
+static const struct dev_pm_ops realtek_intc_rtd1619b_pm_ops = {
+	.suspend_noirq = realtek_intc_rtd1619b_suspend,
+	.resume_noirq  = realtek_intc_rtd1619b_resume,
+};

So this is the 4th copy of the same code, really? Why is this not part of the common code?

Thanks,

tglx

#25 lore raw

RE: [PATCH v3 6/6] irqchip: Introduce RTD1619B support using the Realtek common interrupt controller driver

Hi Thomas,

Quoted 23 lines · James Tai
Quoted 22 lines
drivers/irqchip/irq-realtek-rtd1619b.c new file +22 -0
+static int realtek_intc_rtd1619b_suspend(struct device *dev) {
+     struct realtek_intc_data *data = dev_get_drvdata(dev);
+     const struct realtek_intc_info *info = data->info;
+
+     data->saved_en = readl(data->base + info->scpu_int_en_offset);
+
+     writel(DISABLE_INTC, data->base + info->scpu_int_en_offset);
+     writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset);
+     writel(CLEAN_INTC_STATUS, data->base + info->isr_offset);
+
+     return 0;
+}
+
+static int realtek_intc_rtd1619b_resume(struct device *dev) {
+     struct realtek_intc_data *data = dev_get_drvdata(dev);
+     const struct realtek_intc_info *info = data->info;
+
+     writel(CLEAN_INTC_STATUS, data->base + info->umsk_isr_offset);
+     writel(CLEAN_INTC_STATUS, data->base + info->isr_offset);
+     writel(data->saved_en, data->base + info->scpu_int_en_offset);
+
+     return 0;
Quoted 9 lines

drivers/irqchip/irq-realtek-rtd1619b.c

Quoted 5 lines
drivers/irqchip/irq-realtek-rtd1619b.c new file +5 -0
+}
+
+static const struct dev_pm_ops realtek_intc_rtd1619b_pm_ops = {
+     .suspend_noirq = realtek_intc_rtd1619b_suspend,
+     .resume_noirq  = realtek_intc_rtd1619b_resume, };

So this is the 4th copy of the same code, really? Why is this not part of the common code?

Yes it is the same code.
I had originally assumed that each platform would require some different settings, but I've realized that there is no such requirement in the current architecture. I will move this part to the common code.

Thanks for your feedback.

Regards,
James