From: Thomas Gleixner <tglx@linutronix.de>
To: Yoshinori Sato <ysato@users.sourceforge.jp>, linux-sh@vger.kernel.org
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>,
glaubitz@physik.fu-berlin.de, maz@kernel.org
Subject: Re: [RFC PATCH v3 14/35] drivers/irqchip: Add SH7751 Internal INTC drivers.
Date: Wed, 18 Oct 2023 10:02:45 +0200 [thread overview]
Message-ID: <87v8b44au2.ffs@tglx> (raw)
In-Reply-To: <b7d3002d7033a94a57577af68a13f4cfc3a88947.1697199949.git.ysato@users.sourceforge.jp>
On Sat, Oct 14 2023 at 23:53, Yoshinori Sato wrote:
> +config RENESAS_SH7751_INTC
> + bool "Renesas SH7751 Interrupt Controller"
> + depends on SH_DEVICE_TREE || COMPILE_TEST
> + select IRQ_DOMAIN
> + select IRQ_DOMAIN_HIERARCHY
IRQ_DOMAIN_HIERARCHY selects IRQ_DOMAIN already
> +struct sh7751_intc_priv {
> + void *icr;
> + void *ipr;
> + void *intpri00;
> + void *intreq00;
> + void *intmsk00;
> + void *intmskclr00;
> + struct iprmap *iprmap;
> + unsigned int num_ipr;
> + bool irlm;
> +};
See the other mail vs. formatting
> +#define ICR_IRLM BIT(7)
> +
> +/* Bitmap of IRQ masked */
> +#define IMASK_PRIORITY 15
> +
> +static DECLARE_BITMAP(imask_mask, IMASK_PRIORITY);
> +static int interrupt_priority;
> +
> +static inline void set_interrupt_registers(int ip)
> +{
> + unsigned long __dummy;
> +
> + asm volatile(
> +#ifdef CONFIG_CPU_HAS_SR_RB
> + "ldc %2, r6_bank\n\t"
> +#endif
> + "stc sr, %0\n\t"
> + "and #0xf0, %0\n\t"
> + "shlr2 %0\n\t"
> + "cmp/eq #0x3c, %0\n\t"
> + "bt/s 1f ! CLI-ed\n\t"
> + " stc sr, %0\n\t"
> + "and %1, %0\n\t"
> + "or %2, %0\n\t"
> + "ldc %0, sr\n"
> + "1:"
> + : "=&z" (__dummy)
> + : "r" (~0xf0), "r" (ip << 4)
> + : "t");
Why has this to be ASM and cannot be done in C with the existing
accessors? Also this really lacks a comment what this is actually doing.
> +}
Missing newline after }.
> +static int search_ipr_comp(const void *a, const void *b)
> +{
> + return (int)a - ((struct iprmap *)b)->irq;
(long)a please. It does not matter on 32-bit, but casting a pointer to
long is the correct way to do it.
> +}
> +
> +static void update_ipr(struct sh7751_intc_priv *priv, int irq, int pval)
> +{
> + void *prireg;
> + struct iprmap *p;
> + u16 pri;
See the othermail vs. variable declarations. Please fix all over the place.
> + p = bsearch((void *)irq, priv->iprmap, priv->num_ipr,
> + sizeof(struct iprmap), search_ipr_comp);
See Documentation vs. line breaks and argument alignment
> + if (p) {
> + prireg = (p->reg < INTPRI00) ? priv->ipr : priv->intpri00;
> + prireg += p->reg & (INTPRI00 - 1);
> + pri = ~(0x000f << p->bits);
No magic numbers please. Use a define.
> + pri &= __raw_readw(prireg);
> + pri |= (pval & 0x0f) << p->bits;
> + __raw_writew(pri, prireg);
> + } else
> + pr_warn_once("%s: undefined IPR in irq %d\n", __FILE__, irq);
Lacks brackets on the else clause.
> +}
> +
> +static void sh7751_disable_irq(struct irq_data *data)
> +{
> + unsigned int irq = data->irq;
> + struct sh7751_intc_priv *priv = data->chip_data;
> +
> + if (irq < 16 && !priv->irlm) {
> + /* IRL encoded externel interrupt */
external
> + /* disable for SR.IMASK */
> + clear_bit(irq, imask_mask);
> + if (interrupt_priority < IMASK_PRIORITY - irq)
> + interrupt_priority = IMASK_PRIORITY - irq;
> + set_interrupt_registers(interrupt_priority);
> + } else
> + /* Internal periphreal interrupt */
peripheral and missing brackets.
> + /* IPR priority is 0 */
> + update_ipr(priv, irq, 0);
> +}
> +
> +static void sh7751_enable_irq(struct irq_data *data)
> +{
> + unsigned int irq = data->irq;
> + struct sh7751_intc_priv *priv = data->chip_data;
> +
> + if (irq < 16 && !priv->irlm) {
> + set_bit(irq, imask_mask);
> + interrupt_priority = IMASK_PRIORITY -
> + find_first_bit(imask_mask, IMASK_PRIORITY);
> + set_interrupt_registers(interrupt_priority);
> + } else
> + update_ipr(priv, irq, 1);
This does a bsearch on every mask/unmask operation. Why can't this be
done once at setup time and cached per interrupt?
This code lacks any form of comment and explanation what all of this is
about. You are not only leaving reviewers and casual readers puzzled,
you yourself will have a hard time understanding this magic 6 month down
the road.
> +}
> +
> +static const struct irq_chip sh7751_irq_chip = {
> + .name = "SH7751-INTC",
> + .irq_unmask = sh7751_enable_irq,
> + .irq_mask = sh7751_disable_irq,
> +};
> +
> +static int irq_sh7751_map(struct irq_domain *h, unsigned int virq,
> + irq_hw_number_t hw_irq_num)
Argument alignment please.
> +{
> + irq_set_chip_and_handler(virq, &sh7751_irq_chip, handle_level_irq);
> + irq_get_irq_data(virq)->chip_data = h->host_data;
> + irq_modify_status(virq, IRQ_NOREQUEST, IRQ_NOPROBE);
> + return 0;
> +}
Newline.
> +static const struct irq_domain_ops irq_ops = {
> + .map = irq_sh7751_map,
> + .xlate = irq_domain_xlate_onecell,
Struct formatting
> +};
> +
> +static int sort_ipr_cmp(const void *a, const void *b)
> +{
> + unsigned int irq_a = ((struct iprmap *)a)->irq;
> + unsigned int irq_b = ((struct iprmap *)b)->irq;
> +
> + return irq_a - irq_b;
Why are irq_a/b unsigned int? The substraction clearly hints signed, no?
> +}
> +
> +static void sort_ipr_swap(void *a, void *b, int sz)
> +{
> + struct iprmap tmp;
> +
> + memcpy(&tmp, a, sizeof(tmp));
> + memcpy(a, b, sizeof(tmp));
> + memcpy(b, &tmp, sizeof(tmp));
> +}
> +
> +static int __init load_ipr_map(struct device_node *intc,
> + struct sh7751_intc_priv *priv)
> +{
> + int num_ipr;
> + struct iprmap *p;
> + u32 val[3];
> + unsigned int i, idx;
> +
> + num_ipr = of_property_count_elems_of_size(intc, "renesas,ipr-map", sizeof(u32) * 3);
> + if (num_ipr < 0)
> + return num_ipr;
> +
> + priv->iprmap = kcalloc(num_ipr, sizeof(struct iprmap), GFP_KERNEL);
> + if (priv->iprmap == NULL) {
> + pr_err("%s: Failed to alloc memory\n", intc->name);
> + return -ENOMEM;
> + }
> + priv->num_ipr = num_ipr;
> +
> + for (p = priv->iprmap, idx = 0; num_ipr > 0; p++, num_ipr--) {
> + for (i = 0; i < 3; idx++, i++) {
> + if (of_property_read_u32_index(intc, "renesas,ipr-map",
> + idx, &val[i])) {
> + pr_err("%s: Failed to load ipr-map\n", intc->name);
> + kfree(priv->iprmap);
> + return -EINVAL;
> + }
> + }
> + p->irq = evt2irq(val[0]);
> + p->reg = val[1];
> + p->bits = val[2];
> + }
> + /* This table will be searched using bsearch, so sort it. */
So this is one of the rare comments in this code. It comments the
obvious as the other comments do too.
Thanks,
tglx
next prev parent reply other threads:[~2023-10-18 8:02 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-14 14:53 [RFC PATCH v3 00/35] Device Tree support for SH7751 based board Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 01/35] arch/sh/boot/compressed/head_32.S: passing FDT address to initialize function Yoshinori Sato
2023-10-14 17:11 ` Sergei Shtylyov
2023-10-14 14:53 ` [RFC PATCH v3 02/35] arch/sh/boards/Kconfig: unified OF supported targets Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 03/35] arch/sh: Disable SH specific modules in OF enabled Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 04/35] include/linux/sh_intc.h: Add stub function "intc_finalize" Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 05/35] arch/sh/kernel/setup.c: Update DT support Yoshinori Sato
2023-10-19 10:01 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 06/35] arch/sh/boards/of-generic.c: some cleanup Yoshinori Sato
2023-10-18 18:37 ` Geert Uytterhoeven
2023-10-26 3:40 ` Yoshinori Sato
2023-10-26 7:20 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 07/35] arch/sh/kernel/time.c: support COMMON_CLK Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 08/35] arch/sh/include/asm: Disable SH specific PCI define in OF enabled Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 09/35] drivers/pci/controller: SH7751 PCI Host bridge driver Yoshinori Sato
2023-10-16 17:27 ` Bjorn Helgaas
2023-10-16 19:52 ` Bjorn Helgaas
2023-10-14 14:53 ` [RFC PATCH v3 10/35] Documentation/devicetree/bindings/pci: renesas,pci-sh7751.yaml new file Yoshinori Sato
2023-10-16 5:28 ` Krzysztof Kozlowski
2023-10-16 11:55 ` Krzysztof Kozlowski
2023-10-14 14:53 ` [RFC PATCH v3 11/35] include/dt-bindings/clock/sh7750.h: cpg-sh7750 binding header Yoshinori Sato
2023-10-18 13:49 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 12/35] drivers/clk/renesas: clk-sh7750.c SH7750/7751 CPG driver Yoshinori Sato
2023-10-18 13:02 ` Geert Uytterhoeven
2023-10-19 7:18 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 13/35] Documentation/devicetree/bindings/clock: Add renesas,sh7750-cpg binding document Yoshinori Sato
2023-10-18 13:41 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 14/35] drivers/irqchip: Add SH7751 Internal INTC drivers Yoshinori Sato
2023-10-17 9:27 ` Geert Uytterhoeven
2023-10-18 8:02 ` Thomas Gleixner [this message]
2023-10-18 8:18 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 15/35] Documentation/devicetree/bindings/interrupt-controller: Add renesas,sh7751-intc.yaml Yoshinori Sato
2023-10-19 11:29 ` Geert Uytterhoeven
2023-10-19 11:38 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 16/35] drivers/irqchip: SH7751 IRL external encoder with enable gate Yoshinori Sato
2023-10-16 18:46 ` Thomas Gleixner
2023-10-16 18:50 ` John Paul Adrian Glaubitz
2023-10-16 21:55 ` Thomas Gleixner
2023-10-17 16:33 ` Thomas Gleixner
2023-10-14 14:53 ` [RFC PATCH v3 17/35] Documentation/devicetree/bindings/interrupt-controller: Add renesas,sh7751-irl-ext.yaml Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 18/35] drivers/tty/serial: sh-sci.c fix SH4 OF support Yoshinori Sato
2023-10-18 8:23 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 19/35] Documentation/devicetree/bindings/serial: renesas,scif.yaml Add SH Yoshinori Sato
2023-10-18 14:04 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 20/35] drivers/mfd: sm501 add some properties Yoshinori Sato
2023-10-19 11:55 ` Lee Jones
2023-10-14 14:53 ` [RFC PATCH v3 21/35] devicetree/binding/display/sm501fb.txt: sm501fb add properies Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 22/35] drivers/clocksource/sh_tmu: Add support CLOCKSOURCE Yoshinori Sato
2023-10-18 16:04 ` Geert Uytterhoeven
2023-10-23 11:40 ` Yoshinori Sato
2023-10-14 14:53 ` [RFC PATCH v3 23/35] Documentation/devicetree/bindings/timer: renesas,tmu.yaml add SH Yoshinori Sato
2023-10-18 19:40 ` Geert Uytterhoeven
2023-10-14 14:53 ` [RFC PATCH v3 24/35] include/dt-binding/interrupt-controller/sh_intc.h: renesas,sh7751-intc.h helper Yoshinori Sato
2023-10-18 13:39 ` Geert Uytterhoeven
2023-10-18 14:03 ` Krzysztof Kozlowski
2023-10-14 14:54 ` [RFC PATCH v3 25/35] Documentation/devicetree/bindings/sh/cpus.yaml: Add SH CPU Yoshinori Sato
2023-10-18 14:27 ` Geert Uytterhoeven
2023-10-25 11:14 ` Yoshinori Sato
2023-10-25 11:33 ` D. Jeff Dionne
2023-10-25 12:04 ` Geert Uytterhoeven
2023-10-25 12:10 ` D. Jeff Dionne
2023-10-25 12:17 ` Geert Uytterhoeven
2023-10-25 12:34 ` D. Jeff Dionne
2023-10-25 12:07 ` Yoshinori Sato
2023-10-25 12:01 ` Geert Uytterhoeven
2023-10-14 14:54 ` [RFC PATCH v3 26/35] arch/sh/boot/dts: SH7751R SoC Internal peripheral definition dtsi Yoshinori Sato
2023-10-19 12:18 ` Geert Uytterhoeven
2023-10-14 14:54 ` [RFC PATCH v3 27/35] Documentation/devicetree/bindings: vendor-prefix add IO DATA DEVICE Inc Yoshinori Sato
2023-10-18 18:43 ` Geert Uytterhoeven
2023-10-14 14:54 ` [RFC PATCH v3 28/35] Documentation/devicetree/bindings/ata: ata-generic.yaml add usl-5p and rts7751r2d Yoshinori Sato
2023-10-15 22:25 ` Damien Le Moal
2023-10-14 14:54 ` [RFC PATCH v3 29/35] Documentation/devicetree/bindings/soc/renesas/sh.yaml: Add SH7751 based target Yoshinori Sato
2023-10-18 18:48 ` Geert Uytterhoeven
2023-10-18 18:49 ` Geert Uytterhoeven
2023-10-18 19:44 ` Geert Uytterhoeven
2023-10-25 11:58 ` Yoshinori Sato
2023-10-25 12:05 ` Yoshinori Sato
2023-10-14 14:54 ` [RFC PATCH v3 30/35] arch/sh/boot/dts: RTS7751R2D Plus DeviceTree Yoshinori Sato
2023-10-19 12:13 ` Geert Uytterhoeven
2023-10-14 14:54 ` [RFC PATCH v3 31/35] arch/sh/boot/dts: LANDISK DeviceTree Yoshinori Sato
2023-10-19 12:14 ` Geert Uytterhoeven
2023-10-14 14:54 ` [RFC PATCH v3 32/35] arch/sh/boot/dts: USL-5P DeviceTree Yoshinori Sato
2023-10-14 14:54 ` [RFC PATCH v3 33/35] arch/sh: Add dtbs target support Yoshinori Sato
2023-10-19 11:54 ` Geert Uytterhoeven
2023-10-14 14:54 ` [RFC PATCH v3 34/35] arch/sh: RTS7751R2D Plus OF defconfig Yoshinori Sato
2023-10-14 14:54 ` [RFC PATCH v3 35/35] arch/sh/configs: LANDISK " Yoshinori Sato
2023-11-07 10:23 ` [RFC PATCH v3 00/35] Device Tree support for SH7751 based board John Paul Adrian Glaubitz
2023-11-08 7:57 ` Yoshinori Sato
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=87v8b44au2.ffs@tglx \
--to=tglx@linutronix.de \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-sh@vger.kernel.org \
--cc=maz@kernel.org \
--cc=ysato@users.sourceforge.jp \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox