Add JH8100 external interrupt controller support
Subsystems (2)
v2 cover Add JH8100 external interrupt controller support
This patchset adds external interrupt controller driver for the StarFive JH81000 SoC. It can be used to handle high-level input interrupt signals. It also send the output interrupt signal to RISC-V PLIC.
changes since v1:
- Rebased on tag v6.8-rc1.
- Dropped store reset_contorl.
- Replaced "of_reset_control_get_by_index" with of_reset_control_get_exclusive
- Printed the error code via %pe
v1: https://lore.kernel.org/all/[email protected]/
Changhuang Liang (2):
dt-bindings: interrupt-controller: Add starfive,jh8100-intc
irqchip: Add StarFive external interrupt controller
.../starfive,jh8100-intc.yaml | 61 ++++++ MAINTAINERS | 6 + drivers/irqchip/Kconfig | 11 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-starfive-jh8100-intc.c | 180 ++++++++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/starfive,jh8100-intc.yaml create mode 100644 drivers/irqchip/irq-starfive-jh8100-intc.c
--
2.25.1
PATCH v2 1/2 dt-bindings: interrupt-controller: Add starfive,jh8100-intc
StarFive SoCs like the JH8100 use a interrupt controller. Add a binding for it.
--- .../starfive,jh8100-intc.yaml | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/starfive,jh8100-intc.yaml
Documentation/devicetree/bindings/interrupt-controller/starfive,jh8100-intc.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/interrupt-controller/starfive,jh8100-intc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: StarFive External Interrupt Controller + +description: + StarFive SoC JH8100 contain a external interrupt controller. It can be used + to handle high-level input interrupt signals. It also send the output + interrupt signal to RISC-V PLIC. + +maintainers: + - Changhuang Liang <[email protected]> + +properties: + compatible: + const: starfive,jh8100-intc + + reg: + maxItems: 1 + + clocks: + description: APB clock for the interrupt controller + maxItems: 1 + + resets: + description: APB reset for the interrupt controller + maxItems: 1 + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1 + +required: + - compatible + - reg + - clocks + - resets + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + interrupt-controller@12260000 { + compatible = "starfive,jh8100-intc"; + reg = <0x12260000 0x10000>; + clocks = <&syscrg_ne 76>; + resets = <&syscrg_ne 13>; + interrupts = <45>; + interrupt-controller; + #interrupt-cells = <1>; + };
Signature · 1 line
2.25.1
PATCH v2 2/2 irqchip: Add StarFive external interrupt controller
In reply to Changhuang LiangAdd StarFive external interrupt controller for JH8100 SoC.
--- MAINTAINERS | 6 + drivers/irqchip/Kconfig | 11 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-starfive-jh8100-intc.c | 180 +++++++++++++++++++++ 4 files changed, 198 insertions(+) create mode 100644 drivers/irqchip/irq-starfive-jh8100-intc.c
MAINTAINERS +6 -0
@@ -20956,6 +20956,12 @@ F: Documentation/devicetree/bindings/phy/starfive,jh7110-usb-phy.yaml F: drivers/phy/starfive/phy-jh7110-pcie.c F: drivers/phy/starfive/phy-jh7110-usb.c +STARFIVE JH8100 EXTERNAL INTERRUPT CONTROLLER DRIVER +M: Changhuang Liang <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/interrupt-controller/starfive,jh8100-intc.yaml +F: drivers/irqchip/irq-starfive-jh8100-intc.c + STATIC BRANCH/CALL M: Peter Zijlstra <[email protected]> M: Josh Poimboeuf <[email protected]>
drivers/irqchip/Kconfig +11 -0
@@ -546,6 +546,17 @@ config SIFIVE_PLIC select IRQ_DOMAIN_HIERARCHY select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP +config STARFIVE_JH8100_INTC + bool "StarFive JH8100 External Interrupt Controller" + depends on ARCH_STARFIVE || COMPILE_TEST + default ARCH_STARFIVE + select IRQ_DOMAIN_HIERARCHY + help + This enables support for the INTC chip found in StarFive JH8100 + SoC. + + If you don't know what to do here, say Y. + config EXYNOS_IRQ_COMBINER bool "Samsung Exynos IRQ combiner support" if COMPILE_TEST depends on (ARCH_EXYNOS && ARM) || COMPILE_TEST
drivers/irqchip/Makefile +1 -0
@@ -96,6 +96,7 @@ obj-$(CONFIG_CSKY_MPINTC) += irq-csky-mpintc.o obj-$(CONFIG_CSKY_APB_INTC) += irq-csky-apb-intc.o obj-$(CONFIG_RISCV_INTC) += irq-riscv-intc.o obj-$(CONFIG_SIFIVE_PLIC) += irq-sifive-plic.o +obj-$(CONFIG_STARFIVE_JH8100_INTC) += irq-starfive-jh8100-intc.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
drivers/irqchip/irq-starfive-jh8100-intc.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] irqchip: Add StarFive external interrupt controller
drivers/irqchip/irq-starfive-jh8100-intc.c line 32
Quoted 6 lines · Changhuang Liang
drivers/irqchip/irq-starfive-jh8100-intc.c new file +6
-0+ +struct starfive_irq_chip { +void __iomem *base; +struct irq_domain *root_domain; +struct clk *clk; +};
Please.
drivers/irqchip/irq-starfive-jh8100-intc.c line 39
Quoted 6 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +6
-0+static void starfive_intc_mod (struct starfive_irq_chip *irqc,u32 reg,u32 mask,u32 data) +{ +u32 value; + + value =ioread32 (irqc->base + reg) & ~mask; + data &= mask;
Why?
drivers/irqchip/irq-starfive-jh8100-intc.c line 41
Quoted 2 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +2
-0+ data |= value; +iowrite32 (data, irqc->base + reg);
How is this serialized against concurrent invocations of this code on different CPUs for different interrupts?
It's not and this requires a raw_spinlock for protection.
Quoted 11 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +11
-0+} + +static void starfive_intc_unmask (struct irq_data *d) +{ +struct starfive_irq_chip *irqc =irq_data_get_irq_chip_data (d); + +starfive_intc_mod (irqc,STARFIVE_INTC_SRC0_MASK ,BIT (d->hwirq),0 ); +} + +static void starfive_intc_mask (struct irq_data *d) +{
drivers/irqchip/irq-starfive-jh8100-intc.c line 62
Quoted 10 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +10
-0+struct starfive_irq_chip *irqc =irq_data_get_irq_chip_data (d); + +starfive_intc_mod (irqc,STARFIVE_INTC_SRC0_MASK ,BIT (d->hwirq),BIT (d->hwirq)); +} + +static struct irq_chip intc_dev = { + .name ="starfive jh8100 intc" , + .irq_unmask = starfive_intc_unmask, + .irq_mask = starfive_intc_mask, +};
See documentation please.
drivers/irqchip/irq-starfive-jh8100-intc.c line 75
Quoted 12 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +12
-0+static int starfive_intc_map (struct irq_domain *d,unsigned int irq,irq_hw_number_t hwirq) +{ +irq_domain_set_info (d, irq, hwirq, &intc_dev, d->host_data, + handle_level_irq,NULL ,NULL ); + +return 0 ; +} + +static const struct irq_domain_ops starfive_intc_domain_ops = { + .xlate = irq_domain_xlate_onecell, + .map = starfive_intc_map, +};
Ditto.
drivers/irqchip/irq-starfive-jh8100-intc.c line 80
Quoted 4 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +4
-0+static void starfive_intc_irq_handler (struct irq_desc *desc) +{ +struct irq_chip *chip =irq_desc_get_chip (desc); +struct starfive_irq_chip *irqc =irq_data_get_irq_handler_data (&desc->irq_data);
https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#variable-declarations
drivers/irqchip/irq-starfive-jh8100-intc.c line 81
Quoted 1 line
drivers/irqchip/irq-starfive-jh8100-intc.c new file +1
-0+unsigned long value =0 ;
Pointless initialization
Quoted 16 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +16
-0+int hwirq; + +chained_irq_enter (chip, desc); + + value =ioread32 (irqc->base +STARFIVE_INTC_SRC0_INT ); +while (value) { + hwirq =ffs (value) -1 ; + +generic_handle_domain_irq (irqc->root_domain, hwirq); + +starfive_intc_mod (irqc,STARFIVE_INTC_SRC0_CLEAR ,BIT (hwirq),BIT (hwirq)); +starfive_intc_mod (irqc,STARFIVE_INTC_SRC0_CLEAR ,BIT (hwirq),0 ); + +clear_bit (hwirq, &value); + } +
drivers/irqchip/irq-starfive-jh8100-intc.c line 107
Quoted 10 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +10
-0+chained_irq_exit (chip, desc); +} + +static int __init starfive_intc_init (struct device_node *intc, +struct device_node *parent) +{ +struct starfive_irq_chip *irqc; +struct reset_control *rst; +int ret; +int parent_irq;
See Documentation
Quoted 36 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +36
-0+ irqc =kzalloc (sizeof (*irqc),GFP_KERNEL ); +if (!irqc) +return -ENOMEM ; + + irqc->base =of_iomap (intc,0 ); +if (!irqc->base) { +pr_err ("Unable to map IC registers\n" ); + ret = -ENXIO ; + goto err_free; + } + + rst =of_reset_control_get_exclusive (intc,NULL ); +if (IS_ERR (rst)) { +pr_err ("Unable to get reset control %pe\n" , rst); + ret =PTR_ERR (rst); + goto err_unmap; + } + + irqc->clk =of_clk_get (intc,0 ); +if (IS_ERR (irqc->clk)) { +pr_err ("Unable to get clock\n" ); + ret =PTR_ERR (irqc->clk); + goto err_rst; + } + + ret =reset_control_deassert (rst); +if (ret) + goto err_clk; + + ret =clk_prepare_enable (irqc->clk); +if (ret) + goto err_clk; + + irqc->root_domain =irq_domain_add_linear (intc,STARFIVE_INTC_SRC_IRQ_NUM , + &starfive_intc_domain_ops, irqc); +if (!irqc->root_domain) {
drivers/irqchip/irq-starfive-jh8100-intc.c line 154
Quoted 10 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +10
-0+pr_err ("Unable to create IRQ domain\n" ); + ret = -EINVAL ; + goto err_clk; + } + + parent_irq =of_irq_get (intc,0 ); +if (parent_irq <0 ) { +pr_err ("Failed to get main IRQ: %d\n" , parent_irq); + ret = parent_irq; + goto err_clk;
Leaks the interrupt domain, no?
Thanks,
tglx
回复: [PATCH v2 2/2] irqchip: Add StarFive external interrupt controller
Hi, Thomas
Thanks for your comment.
Quoted 1 line · Changhuang Liang
[...]
Quoted 9 lines
drivers/irqchip/irq-starfive-jh8100-intc.c line 39
Quoted 6 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +6
-0+static void starfive_intc_mod (struct starfive_irq_chip *irqc,u32 +reg,u32 mask,u32 data) { +u32 value; + + value =ioread32 (irqc->base + reg) & ~mask; + data &= mask;Why?
If I want to update the reg GENMASK(7, 4) to value 5, the data I will pass in 5 << 4
Quoted 8 lines
drivers/irqchip/irq-starfive-jh8100-intc.c line 41
Quoted 2 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +2
-0+ data |= value; +iowrite32 (data, irqc->base + reg);How is this serialized against concurrent invocations of this code on different CPUs for different interrupts?
It's not and this requires a
raw_spinlockfor protection.
Will use raw_spinlock.
Quoted 14 lines
Quoted 14 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +14
-0+} + +static void starfive_intc_unmask (struct irq_data *d) { +struct starfive_irq_chip *irqc =irq_data_get_irq_chip_data (d); + +starfive_intc_mod (irqc,STARFIVE_INTC_SRC0_MASK ,BIT (d->hwirq),0 ); +} + +static void starfive_intc_mask (struct irq_data *d) { +struct starfive_irq_chip *irqc =irq_data_get_irq_chip_data (d); + +starfive_intc_mod (irqc,STARFIVE_INTC_SRC0_MASK ,BIT (d->hwirq), +BIT (d->hwirq)); } +
[...]
Quoted 17 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ irqc->root_domain = irq_domain_add_linear(intc,
STARFIVE_INTC_SRC_IRQ_NUM,drivers/irqchip/irq-starfive-jh8100-intc.c line 154
Quoted 12 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +12
-0+ &starfive_intc_domain_ops, irqc); +if (!irqc->root_domain) { +pr_err ("Unable to create IRQ domain\n" ); + ret = -EINVAL ; + goto err_clk; + } + + parent_irq =of_irq_get (intc,0 ); +if (parent_irq <0 ) { +pr_err ("Failed to get main IRQ: %d\n" , parent_irq); + ret = parent_irq; + goto err_clk;Leaks the interrupt domain, no?
Quoted 2 lines
Thanks,
Will use irq_domain_remove() free domain.
regards
Changhuang
Re: 回复: [PATCH v2 2/2] irqchip: Add StarFive external interrupt controller
Quoted 12 lines · Changhuang Liang
Quoted 1 line · Changhuang Liang
[...]
Quoted 9 lines
drivers/irqchip/irq-starfive-jh8100-intc.c line 39
Quoted 6 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +6
-0+static void starfive_intc_mod (struct starfive_irq_chip *irqc,u32 +reg,u32 mask,u32 data) { +u32 value; + + value =ioread32 (irqc->base + reg) & ~mask; + data &= mask;Why?
Quoted 2 lines
If I want to update the reg
GENMASK(7, 4)to value 5, the data I will pass in 5 << 4
All call sites pass a single bit to set/clear, right? So this GENMASK argument does not make sense at all.
Thanks,
tglx
回复: 回复: [PATCH v2 2/2] irqchip: Add StarFive external interrupt controller
Hi, Thomas
Quoted 26 lines
-----邮件原件-----
发件人: Thomas Gleixner <[email protected]>
发送时间: 2024年2月20日 17:28
收件人: Changhuang Liang <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Philipp Zabel <[email protected]>
抄送: Leyfoon Tan <[email protected]>; Jack Zhu <[email protected]>; [email protected]; [email protected]
主题: Re: 回复: [PATCH v2 2/2] irqchip: Add StarFive external interrupt controllerQuoted 12 lines · Changhuang Liang
Quoted 1 line · Changhuang Liang
[...]
Quoted 9 lines
drivers/irqchip/irq-starfive-jh8100-intc.c line 39
Quoted 6 lines
drivers/irqchip/irq-starfive-jh8100-intc.c new file +6
-0+static void starfive_intc_mod (struct starfive_irq_chip *irqc,u32 +reg,u32 mask,u32 data) { +u32 value; + + value =ioread32 (irqc->base + reg) & ~mask; + data &= mask;Why?
Quoted 6 lines
Quoted 2 lines
If I want to update the reg
GENMASK(7, 4)to value 5, the data I will pass in 5 << 4All call sites pass a single bit to set/clear, right? So this GENMASK argument does not make sense at all.
Yes, I will update this function