All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Changhuang Liang <changhuang.liang@starfivetech.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>
Cc: Ley Foon Tan <leyfoon.tan@starfivetech.com>,
	Jack Zhu <jack.zhu@starfivetech.com>,
	Changhuang Liang <changhuang.liang@starfivetech.com>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 2/2] irqchip: Add StarFive external interrupt controller
Date: Tue, 13 Feb 2024 10:03:12 +0100	[thread overview]
Message-ID: <87cyt0ivn3.ffs@tglx> (raw)
In-Reply-To: <20240130055843.216342-3-changhuang.liang@starfivetech.com>

On Mon, Jan 29 2024 at 21:58, Changhuang Liang wrote:
> +
> +struct starfive_irq_chip {
> +	void __iomem *base;
> +	struct irq_domain *root_domain;
> +	struct clk *clk;
> +};

https://www.kernel.org/doc/html/latest/process/maintainer-tip.html#struct-declarations-and-initializers

Please.

> +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?

> +	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.

> +}
> +
> +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));
> +}
> +
> +static struct irq_chip intc_dev = {
> +	.name = "starfive jh8100 intc",
> +	.irq_unmask = starfive_intc_unmask,
> +	.irq_mask = starfive_intc_mask,
> +};

See documentation please.

> +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.

> +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

> +	unsigned long value = 0;

Pointless initialization

> +	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);
> +	}
> +
> +	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

> +	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) {
> +		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

  reply	other threads:[~2024-02-13  9:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  5:58 [PATCH v2 0/2] Add JH8100 external interrupt controller support Changhuang Liang
2024-01-30  5:58 ` [PATCH v2 1/2] dt-bindings: interrupt-controller: Add starfive,jh8100-intc Changhuang Liang
2024-01-30  5:58 ` [PATCH v2 2/2] irqchip: Add StarFive external interrupt controller Changhuang Liang
2024-02-13  9:03   ` Thomas Gleixner [this message]
2024-02-18  2:36     ` 回复: " Changhuang Liang
2024-02-20  9:28       ` Thomas Gleixner
2024-02-20  9:39         ` 回复: " Changhuang Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cyt0ivn3.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=changhuang.liang@starfivetech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jack.zhu@starfivetech.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=leyfoon.tan@starfivetech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.