All of lore.kernel.org
 help / color / mirror / Atom feed
From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
To: Leonid Komarianskyi <Leonid_Komarianskyi@epam.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Michal Orzel <michal.orzel@amd.com>
Subject: Re: [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
Date: Thu, 21 Aug 2025 16:00:34 +0000	[thread overview]
Message-ID: <87h5y0ekbi.fsf@epam.com> (raw)
In-Reply-To: <7e6477a83ab65220ef1c5dd22f4ef3536fbbdd5c.1754568795.git.leonid_komarianskyi@epam.com> (Leonid Komarianskyi's message of "Thu, 7 Aug 2025 12:33:30 +0000")


Hi,

Leonid Komarianskyi <Leonid_Komarianskyi@epam.com> writes:

> Currently, many common functions perform the same operations to calculate
> GIC register addresses. This patch consolidates the similar code into
> a separate helper function to improve maintainability and reduce duplication.
> This refactoring also simplifies the implementation of eSPI support in future
> changes.
>
> Signed-off-by: Leonid Komarianskyi <leonid_komarianskyi@epam.com>

Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>

>
> ---
> Changes in V2:
> - no changes
> ---
>  xen/arch/arm/gic-v3.c          | 99 ++++++++++++++++++++++------------
>  xen/arch/arm/include/asm/irq.h |  1 +
>  2 files changed, 67 insertions(+), 33 deletions(-)
>
> diff --git a/xen/arch/arm/gic-v3.c b/xen/arch/arm/gic-v3.c
> index cd3e1acf79..8fd78aba44 100644
> --- a/xen/arch/arm/gic-v3.c
> +++ b/xen/arch/arm/gic-v3.c
> @@ -445,17 +445,62 @@ static void gicv3_dump_state(const struct vcpu *v)
>      }
>  }
>  
> +static void __iomem *get_addr_by_offset(struct irq_desc *irqd, u32 offset)
> +{
> +    switch ( irqd->irq )
> +    {
> +    case 0 ... (NR_GIC_LOCAL_IRQS - 1):
> +        switch ( offset )
> +        {
> +        case GICD_ISENABLER:
> +        case GICD_ICENABLER:
> +        case GICD_ISPENDR:
> +        case GICD_ICPENDR:
> +        case GICD_ISACTIVER:
> +        case GICD_ICACTIVER:
> +            return (GICD_RDIST_SGI_BASE + offset);
> +        case GICD_ICFGR:
> +            return (GICD_RDIST_SGI_BASE + GICR_ICFGR1);
> +        case GICD_IPRIORITYR:
> +            return (GICD_RDIST_SGI_BASE + GICR_IPRIORITYR0 + irqd->irq);
> +        default:
> +            break;
> +        }
> +    case NR_GIC_LOCAL_IRQS ... SPI_MAX_INTID:
> +        switch ( offset )
> +        {
> +        case GICD_ISENABLER:
> +        case GICD_ICENABLER:
> +        case GICD_ISPENDR:
> +        case GICD_ICPENDR:
> +        case GICD_ISACTIVER:
> +        case GICD_ICACTIVER:
> +            return (GICD + offset + (irqd->irq / 32) * 4);
> +        case GICD_ICFGR:
> +            return (GICD + GICD_ICFGR + (irqd->irq / 16) * 4);
> +        case GICD_IROUTER:
> +            return (GICD + GICD_IROUTER + irqd->irq * 8);
> +        case GICD_IPRIORITYR:
> +            return (GICD + GICD_IPRIORITYR + irqd->irq);
> +        default:
> +            break;
> +        }
> +    default:
> +        break;
> +    }
> +
> +    /* Something went wrong, we shouldn't be able to reach here */
> +    panic("Invalid offset 0x%x for IRQ#%d", offset, irqd->irq);
> +
> +    return NULL;
> +}
> +
>  static void gicv3_poke_irq(struct irq_desc *irqd, u32 offset, bool wait_for_rwp)
>  {
>      u32 mask = 1U << (irqd->irq % 32);
> -    void __iomem *base;
> -
> -    if ( irqd->irq < NR_GIC_LOCAL_IRQS )
> -        base = GICD_RDIST_SGI_BASE;
> -    else
> -        base = GICD;
> +    void __iomem *addr = get_addr_by_offset(irqd, offset);
>  
> -    writel_relaxed(mask, base + offset + (irqd->irq / 32) * 4);
> +    writel_relaxed(mask, addr);
>  
>      if ( wait_for_rwp )
>          gicv3_wait_for_rwp(irqd->irq);
> @@ -463,15 +508,9 @@ static void gicv3_poke_irq(struct irq_desc *irqd, u32 offset, bool wait_for_rwp)
>  
>  static bool gicv3_peek_irq(struct irq_desc *irqd, u32 offset)
>  {
> -    void __iomem *base;
> -    unsigned int irq = irqd->irq;
> -
> -    if ( irq >= NR_GIC_LOCAL_IRQS)
> -        base = GICD + (irq / 32) * 4;
> -    else
> -        base = GICD_RDIST_SGI_BASE;
> +    void __iomem *addr = get_addr_by_offset(irqd, offset);
>  
> -    return !!(readl(base + offset) & (1U << (irq % 32)));
> +    return !!(readl(addr) & (1U << (irqd->irq % 32)));
>  }
>  
>  static void gicv3_unmask_irq(struct irq_desc *irqd)
> @@ -558,30 +597,26 @@ static inline uint64_t gicv3_mpidr_to_affinity(int cpu)
>  static void gicv3_set_irq_type(struct irq_desc *desc, unsigned int type)
>  {
>      uint32_t cfg, actual, edgebit;
> -    void __iomem *base;
> -    unsigned int irq = desc->irq;
> +    void __iomem *addr;
>  
>      /* SGI's are always edge-triggered not need to call GICD_ICFGR0 */
> -    ASSERT(irq >= NR_GIC_SGI);
> +    ASSERT(desc->irq >= NR_GIC_SGI);
>  
>      spin_lock(&gicv3.lock);
>  
> -    if ( irq >= NR_GIC_LOCAL_IRQS)
> -        base = GICD + GICD_ICFGR + (irq / 16) * 4;
> -    else
> -        base = GICD_RDIST_SGI_BASE + GICR_ICFGR1;
> +    addr = get_addr_by_offset(desc, GICD_ICFGR);
>  
> -    cfg = readl_relaxed(base);
> +    cfg = readl_relaxed(addr);
>  
> -    edgebit = 2u << (2 * (irq % 16));
> +    edgebit = 2u << (2 * (desc->irq % 16));
>      if ( type & IRQ_TYPE_LEVEL_MASK )
>          cfg &= ~edgebit;
>      else if ( type & IRQ_TYPE_EDGE_BOTH )
>          cfg |= edgebit;
>  
> -    writel_relaxed(cfg, base);
> +    writel_relaxed(cfg, addr);
>  
> -    actual = readl_relaxed(base);
> +    actual = readl_relaxed(addr);
>      if ( ( cfg & edgebit ) ^ ( actual & edgebit ) )
>      {
>          printk(XENLOG_WARNING "GICv3: WARNING: "
> @@ -600,15 +635,12 @@ static void gicv3_set_irq_type(struct irq_desc *desc, unsigned int type)
>  static void gicv3_set_irq_priority(struct irq_desc *desc,
>                                     unsigned int priority)
>  {
> -    unsigned int irq = desc->irq;
> +    void __iomem *addr;
>  
>      spin_lock(&gicv3.lock);
>  
> -    /* Set priority */
> -    if ( irq < NR_GIC_LOCAL_IRQS )
> -        writeb_relaxed(priority, GICD_RDIST_SGI_BASE + GICR_IPRIORITYR0 + irq);
> -    else
> -        writeb_relaxed(priority, GICD + GICD_IPRIORITYR + irq);
> +    addr = get_addr_by_offset(desc, GICD_IPRIORITYR);
> +    writeb_relaxed(priority, addr);
>  
>      spin_unlock(&gicv3.lock);
>  }
> @@ -1273,6 +1305,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)
>  {
>      unsigned int cpu;
>      uint64_t affinity;
> +    void __iomem *addr = get_addr_by_offset(desc, GICD_IROUTER);
>  
>      ASSERT(!cpumask_empty(mask));
>  
> @@ -1284,7 +1317,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask)
>      affinity &= ~GICD_IROUTER_SPI_MODE_ANY;
>  
>      if ( desc->irq >= NR_GIC_LOCAL_IRQS )
> -        writeq_relaxed_non_atomic(affinity, (GICD + GICD_IROUTER + desc->irq * 8));
> +        writeq_relaxed_non_atomic(affinity, addr);
>  
>      spin_unlock(&gicv3.lock);
>  }
> diff --git a/xen/arch/arm/include/asm/irq.h b/xen/arch/arm/include/asm/irq.h
> index fce7e42a33..5bc6475eb4 100644
> --- a/xen/arch/arm/include/asm/irq.h
> +++ b/xen/arch/arm/include/asm/irq.h
> @@ -29,6 +29,7 @@ struct arch_irq_desc {
>   */
>  #define NR_IRQS		1024
>  
> +#define SPI_MAX_INTID   1019
>  #define LPI_OFFSET      8192
>  
>  /* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */

-- 
WBR, Volodymyr

  parent reply	other threads:[~2025-08-21 16:00 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-07 12:33 [PATCH v2 00/10] Introduce eSPI support Leonid Komarianskyi
2025-08-07 12:33 ` [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 03/10] xen/arm: vgic: implement helper functions for virq checks Leonid Komarianskyi
2025-08-21 15:46     ` Volodymyr Babchuk
2025-08-22  7:55       ` Leonid Komarianskyi
2025-08-22 12:28         ` Volodymyr Babchuk
2025-08-22 15:08           ` Leonid Komarianskyi
2025-08-23 12:29     ` Oleksandr Tyshchenko
2025-08-24 18:08       ` Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 02/10] xen/arm: gic: implement helper functions for INTID checks Leonid Komarianskyi
2025-08-21 15:39     ` Volodymyr Babchuk
2025-08-21 16:24       ` Julien Grall
2025-08-22  7:30         ` Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range Leonid Komarianskyi
2025-08-21 15:59     ` Volodymyr Babchuk
2025-08-21 16:46       ` Julien Grall
2025-08-21 16:59         ` Volodymyr Babchuk
2025-08-21 17:13           ` Julien Grall
2025-08-21 17:38             ` Volodymyr Babchuk
2025-08-22 12:41             ` Leonid Komarianskyi
2025-08-22 12:59       ` Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 05/10] xen/arm: gicv3: implement handling of GICv3.1 eSPI Leonid Komarianskyi
2025-08-21 16:16     ` Volodymyr Babchuk
2025-08-22 14:39       ` Leonid Komarianskyi
2025-08-23 14:23     ` Oleksandr Tyshchenko
2025-08-24 18:17       ` Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 06/10] xen/arm/irq: allow eSPI processing in the do_IRQ function Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 07/10] xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing Leonid Komarianskyi
2025-08-21 16:27     ` Volodymyr Babchuk
2025-08-22  6:56       ` Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 08/10] xen/arm: vgic: add resource management for extended SPIs Leonid Komarianskyi
2025-08-21 16:43     ` Volodymyr Babchuk
2025-08-22  8:27       ` Leonid Komarianskyi
2025-08-23 14:39     ` Oleksandr Tyshchenko
2025-08-24 18:28       ` Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 09/10] xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs Leonid Komarianskyi
2025-08-21 16:46     ` Volodymyr Babchuk
2025-08-22  7:08       ` Leonid Komarianskyi
2025-08-22 12:26         ` Volodymyr Babchuk
2025-08-22 15:03           ` Leonid Komarianskyi
2025-08-23 13:02     ` Oleksandr Tyshchenko
2025-08-24 18:47       ` Leonid Komarianskyi
2025-08-07 12:33   ` [PATCH v2 10/10] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers Leonid Komarianskyi
2025-08-21 16:17     ` Oleksandr Tyshchenko
2025-08-22 10:47       ` Leonid Komarianskyi
2025-08-21 17:26     ` Volodymyr Babchuk
2025-08-22 10:00       ` Leonid Komarianskyi
2025-08-25 14:07       ` Leonid Komarianskyi
2025-08-21 16:00   ` Volodymyr Babchuk [this message]
2025-08-21 16:14   ` [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations Julien Grall
2025-08-22  9:09     ` Leonid Komarianskyi
2025-08-22  9:38       ` Julien Grall
2025-08-22 10:09         ` Leonid Komarianskyi
2025-08-24 17:21 ` [PATCH v2 00/10] Introduce eSPI support Oleksandr Tyshchenko
2025-08-24 18:58   ` Leonid Komarianskyi

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=87h5y0ekbi.fsf@epam.com \
    --to=volodymyr_babchuk@epam.com \
    --cc=Leonid_Komarianskyi@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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.