Skip to contentSkip to conversation

xen/arm: Interrupt management reworking

PATCH Superseded Julien Grall 3 participants 33 messages Apr 22, 2014 – May 2, 2014 Arm Samsung Exynos

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover xen/arm: Interrupt management reworking

Hello,

This is the fourth version of this serie to rework interrupt management for ARM.

Major changes in v4:
- Use a custom single linked list for handling multiple action
- Slightly rework patch #9 (was acked by Ian)
- Remove dependency on Stefano's series for Patch #10
- Change platform_get_irq error code to -1 (impact patch #14 acked by Ian)

For all changes see in each patch.

This series is a dependency for the ARM SMMU drivers.

A working tree can be found here:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch interrupt-mgmt-v4

Sincerely yours,

Julien Grall (18):
xen/arm: timer: replace timer_dt_irq by timer_get_irq xen/arm: IRQ: Use default irq callback from common code for
no_irq_type
xen/arm: IRQ: Rename irq_cfg into arch_irq_desc
xen/arm: IRQ: move gic {,un}lock in gic_set_irq_properties xen/arm: IRQ: drop irq parameter in __setup_irq
xen/arm: IRQ: remove __init from setup_dt_irq, request_dt_irq and
release_irq
xen/arm: IRQ: Rework gic_route_irq_to_guest function xen/arm: IRQ: Move IRQ management from gic.c to irq.c xen/arm: IRQ Introduce irq_get_domain
xen/arm: IRQ: Require desc.lock be held by callers of
hw_irq_controller callbacks
xen/arm: IRQ: Defer routing IRQ to Xen until setup_irq() call xen/arm: IRQ: Do not allow IRQ to be shared between domains and XEN xen/serial: remove serial_dt_irq
xen/arm: IRQ: Store IRQ type in arch_irq_desc
xen/arm: IRQ: Replace {request,setup}_dt_irq by {request,setup}_irq
xen: IRQ: Add dev_id parameter to release_irq
xen/arm: IRQ: extend {request,setup}_irq to take an irqflags in
parameter
xen/arm: IRQ: Handle multiple action per IRQ

 xen/arch/arm/domain_build.c              |   32 +--
 xen/arch/arm/gic.c                       |  230 +++++----------------
 xen/arch/arm/irq.c                       |  321 ++++++++++++++++++++++++++++--
 xen/arch/arm/platforms/xgene-storm.c     |    2 +-
 xen/arch/arm/setup.c                     |    5 +-
 xen/arch/arm/smpboot.c                   |    2 -
 xen/arch/arm/time.c                      |   43 ++--
 xen/arch/arm/vgic.c                      |   10 +
 xen/arch/arm/vtimer.c                    |    4 +-
 xen/arch/x86/hpet.c                      |    2 +-
 xen/arch/x86/i8259.c                     |    2 +-
 xen/arch/x86/irq.c                       |   11 +-
 xen/arch/x86/time.c                      |    2 +-
 xen/drivers/char/exynos4210-uart.c       |   23 +--
 xen/drivers/char/ns16550.c               |   31 +--
 xen/drivers/char/omap-uart.c             |   23 +--
 xen/drivers/char/pl011.c                 |   24 +--
 xen/drivers/char/serial.c                |    9 -
 xen/drivers/passthrough/amd/iommu_init.c |    2 +-
 xen/drivers/passthrough/vtd/iommu.c      |    2 +-
 xen/include/asm-arm/config.h             |    2 +
 xen/include/asm-arm/gic.h                |   16 +-
 xen/include/asm-arm/irq.h                |   12 +-
 xen/include/asm-arm/time.h               |    7 +-
 xen/include/xen/irq.h                    |   11 +-
 xen/include/xen/serial.h                 |    5 -
 26 files changed, 471 insertions(+), 362 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v4 1/18 xen/arm: timer: replace timer_dt_irq by timer_get_irq

The function is nearly only used to retrieve the IRQ number.

There is one place where the IRQ type is used (in domain_build.c) but as the timer IRQ is virtualised for guest we might not have the same property (e.g active-low level sensitive interrupt).

Replace timer_dt_irq by timer_get_irq which will return the IRQ number.

---
Changes in v2:
- Patch added

---
 xen/arch/arm/domain_build.c |   23 +++++++++++++----------
 xen/arch/arm/time.c         |    4 ++--
 xen/arch/arm/vtimer.c       |    4 ++--
 xen/include/asm-arm/time.h  |    4 ++--
 4 files changed, 19 insertions(+), 16 deletions(-)
xen/arch/arm/domain_build.c +13 -10
index 187e071..7bc9bf6 100644
@@ -616,7 +616,7 @@ static int make_timer_node(const struct domain *d, void *fdt,
     u32 len;
     const void *compatible;
     int res;
-    const struct dt_irq *irq;
+    unsigned int irq;
     gic_interrupt_t intrs[3];
     u32 clock_frequency;
     bool_t clock_valid;
@@ -645,17 +645,20 @@ static int make_timer_node(const struct domain *d, void *fdt,
     if ( res )
         return res;
 
-    irq = timer_dt_irq(TIMER_PHYS_SECURE_PPI);
-    DPRINT("  Secure interrupt %u\n", irq->irq);
-    set_interrupt_ppi(intrs[0], irq->irq, 0xf, irq->type);
+    /* The timer IRQ is emulated by Xen. It always exposes an active-low
+     * level-sensitive interrupt */
 
-    irq = timer_dt_irq(TIMER_PHYS_NONSECURE_PPI);
-    DPRINT("  Non secure interrupt %u\n", irq->irq);
-    set_interrupt_ppi(intrs[1], irq->irq, 0xf, irq->type);
+    irq = timer_get_irq(TIMER_PHYS_SECURE_PPI);
+    DPRINT("  Secure interrupt %u\n", irq);
+    set_interrupt_ppi(intrs[0], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    irq = timer_dt_irq(TIMER_VIRT_PPI);
-    DPRINT("  Virt interrupt %u\n", irq->irq);
-    set_interrupt_ppi(intrs[2], irq->irq, 0xf, irq->type);
+    irq = timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
+    DPRINT("  Non secure interrupt %u\n", irq);
+    set_interrupt_ppi(intrs[1], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
+
+    irq = timer_get_irq(TIMER_VIRT_PPI);
+    DPRINT("  Virt interrupt %u\n", irq);
+    set_interrupt_ppi(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
     res = fdt_property_interrupts(fdt, intrs, 3);
     if ( res )
xen/arch/arm/time.c +2 -2
index 8dd4bea..7cad888 100644
@@ -50,11 +50,11 @@ unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz. */
 
 static struct dt_irq timer_irq[MAX_TIMER_PPI];
 
-const struct dt_irq *timer_dt_irq(enum timer_ppi ppi)
+unsigned int timer_get_irq(enum timer_ppi ppi)
 {
     ASSERT(ppi >= TIMER_PHYS_SECURE_PPI && ppi < MAX_TIMER_PPI);
 
-    return &timer_irq[ppi];
+    return timer_irq[ppi].irq;
 }
 
 /*static inline*/ s_time_t ticks_to_ns(uint64_t ticks)
xen/arch/arm/vtimer.c +2 -2
index cb690bb..4822d4f 100644
@@ -65,7 +65,7 @@ int vcpu_vtimer_init(struct vcpu *v)
     t->ctl = 0;
     t->cval = NOW();
     t->irq = d0
-        ? timer_dt_irq(TIMER_PHYS_NONSECURE_PPI)->irq
+        ? timer_get_irq(TIMER_PHYS_NONSECURE_PPI)
         : GUEST_TIMER_PHYS_NS_PPI;
     t->v = v;
 
@@ -73,7 +73,7 @@ int vcpu_vtimer_init(struct vcpu *v)
     init_timer(&t->timer, virt_timer_expired, t, v->processor);
     t->ctl = 0;
     t->irq = d0
-        ? timer_dt_irq(TIMER_VIRT_PPI)->irq
+        ? timer_get_irq(TIMER_VIRT_PPI)
         : GUEST_TIMER_VIRT_PPI;
     t->v = v;
 
xen/include/asm-arm/time.h +2 -2
index d10c737..9bbab0b 100644
@@ -22,8 +22,8 @@ enum timer_ppi
     MAX_TIMER_PPI = 4,
 };
 
-/* Get one of the timer IRQ description */
-const struct dt_irq* timer_dt_irq(enum timer_ppi ppi);
+/* Get one of the timer IRQ number */
+unsigned int timer_get_irq(enum timer_ppi ppi);
 
 /* Route timer's IRQ on this CPU */
 extern void __cpuinit route_timer_interrupt(void);
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v4 2/18 xen/arm: IRQ: Use default irq callback from common code for no_irq_type

In reply to Julien Grall

Most of no_irq_type callback are already defined in common/irq.c. We don't need to recreate our own callbacks.

---
Changes in v2:
- Patch added

---
 xen/arch/arm/irq.c |   14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
xen/arch/arm/irq.c +5 -9
index 3e326b0..5d1ed7f 100644
@@ -27,23 +27,19 @@
 
 #include <asm/gic.h>
 
-static void enable_none(struct irq_desc *irq) { }
-static unsigned int startup_none(struct irq_desc *irq) { return 0; }
-static void disable_none(struct irq_desc *irq) { }
 static void ack_none(struct irq_desc *irq)
 {
     printk("unexpected IRQ trap at irq %02x\n", irq->irq);
 }
 
-#define shutdown_none   disable_none
-#define end_none        enable_none
+static void end_none(struct irq_desc *irq) { }
 
 hw_irq_controller no_irq_type = {
     .typename = "none",
-    .startup = startup_none,
-    .shutdown = shutdown_none,
-    .enable = enable_none,
-    .disable = disable_none,
+    .startup = irq_startup_none,
+    .shutdown = irq_shutdown_none,
+    .enable = irq_enable_none,
+    .disable = irq_disable_none,
     .ack = ack_none,
     .end = end_none
 };
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v4 3/18 xen/arm: IRQ: Rename irq_cfg into arch_irq_desc

In reply to Julien Grall

irq_cfg is never used in the code and arch_irq_desc is an alias to irq_cfg.

---
Changes in v2:
- Patch added

---
 xen/include/asm-arm/irq.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/include/asm-arm/irq.h +1 -2
index 7c20703..3197aec 100644
@@ -14,8 +14,7 @@ struct arch_pirq
 {
 };
 
-struct irq_cfg {
-#define arch_irq_desc irq_cfg
+struct arch_irq_desc {
     int eoi_cpu;
 };
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v4 4/18 xen/arm: IRQ: move gic {, un}lock in gic_set_irq_properties

In reply to Julien Grall

The function gic_set_irq_properties is only called in two places:
- gic_route_irq: the gic.lock is only taken for the call to the former function.
- gic_route_irq_to_guest: the gic.lock is taken for the duration of the function. But the lock is only useful when gic_set_irq_properties.

So we can safely move the lock in gic_set_irq_properties and restrict the critical section for the gic.lock in gic_route_irq_to_guest.

---
Changes in v2:
- Remove useless comment about gic.lock

---
 xen/arch/arm/gic.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
xen/arch/arm/gic.c +6 -6
index 8168b7b..842231a 100644
@@ -221,7 +221,6 @@ static hw_irq_controller gic_guest_irq_type = {
 };
 
 /*
- * - needs to be called with gic.lock held
  * - needs to be called with a valid cpu_mask, ie each cpu in the mask has
  * already called gic_cpu_init
  */
@@ -231,7 +230,11 @@ static void gic_set_irq_properties(unsigned int irq, bool_t level,
 {
     volatile unsigned char *bytereg;
     uint32_t cfg, edgebit;
-    unsigned int mask = gic_cpu_mask(cpu_mask);
+    unsigned int mask;
+
+    spin_lock(&gic.lock);
+
+    mask = gic_cpu_mask(cpu_mask);
 
     /* Set edge / level */
     cfg = GICD[GICD_ICFGR + irq / 16];
@@ -250,6 +253,7 @@ static void gic_set_irq_properties(unsigned int irq, bool_t level,
     bytereg = (unsigned char *) (GICD + GICD_IPRIORITYR);
     bytereg[irq] = priority;
 
+    spin_unlock(&gic.lock);
 }
 
 /* Program the GIC to route an interrupt */
@@ -272,9 +276,7 @@ static int gic_route_irq(unsigned int irq, bool_t level,
 
     desc->handler = &gic_host_irq_type;
 
-    spin_lock(&gic.lock);
     gic_set_irq_properties(irq, level, cpu_mask, priority);
-    spin_unlock(&gic.lock);
 
     spin_unlock_irqrestore(&desc->lock, flags);
     return 0;
@@ -779,7 +781,6 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,
     action->free_on_release = 1;
 
     spin_lock_irqsave(&desc->lock, flags);
-    spin_lock(&gic.lock);
 
     desc->handler = &gic_guest_irq_type;
     desc->status |= IRQ_GUEST;
@@ -800,7 +801,6 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,
     p->desc = desc;
 
 out:
-    spin_unlock(&gic.lock);
     spin_unlock_irqrestore(&desc->lock, flags);
     return retval;
 }
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH v4 5/18 xen/arm: IRQ: drop irq parameter in __setup_irq

In reply to Julien Grall

The IRQ number is already provided by desc and __setup_irq doesn't use it in any case.

---
Changes in v2:
- Patch added

---
 xen/arch/arm/gic.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +3 -4
index 842231a..1934adf 100644
@@ -594,8 +594,7 @@ void __init release_irq(unsigned int irq)
         xfree(action);
 }
 
-static int __setup_irq(struct irq_desc *desc, unsigned int irq,
-                       struct irqaction *new)
+static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
 {
     if ( desc->action != NULL )
         return -EBUSY;
@@ -615,7 +614,7 @@ int __init setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
     desc = irq_to_desc(irq->irq);
 
     spin_lock_irqsave(&desc->lock, flags);
-    rc = __setup_irq(desc, irq->irq, new);
+    rc = __setup_irq(desc, new);
     spin_unlock_irqrestore(&desc->lock, flags);
 
     if ( !rc )
@@ -790,7 +789,7 @@ int gic_route_irq_to_guest(struct domain *d, const struct dt_irq *irq,
     gic_set_irq_properties(irq->irq, level, cpumask_of(smp_processor_id()),
                            GIC_PRI_IRQ);
 
-    retval = __setup_irq(desc, irq->irq, action);
+    retval = __setup_irq(desc, action);
     if (retval) {
         xfree(action);
         goto out;
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH v4 6/18 xen/arm: IRQ: remove __init from setup_dt_irq, request_dt_irq and release_irq

In reply to Julien Grall

These functions will be used in SMMU driver which request interrupt when a device is assigned to a guest.

---
Changes in v2:
- Patch added

---
 xen/arch/arm/gic.c        |    4 ++--
 xen/arch/arm/irq.c        |    6 +++---
 xen/include/asm-arm/irq.h |    8 ++++----
 3 files changed, 9 insertions(+), 9 deletions(-)
xen/arch/arm/gic.c +2 -2
index 1934adf..8d3c155 100644
@@ -570,7 +570,7 @@ void gic_route_spis(void)
     }
 }
 
-void __init release_irq(unsigned int irq)
+void release_irq(unsigned int irq)
 {
     struct irq_desc *desc;
     unsigned long flags;
@@ -605,7 +605,7 @@ static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
     return 0;
 }
 
-int __init setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
+int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
 {
     int rc;
     unsigned long flags;
xen/arch/arm/irq.c +3 -3
index 5d1ed7f..b3bfebc 100644
@@ -89,9 +89,9 @@ void __cpuinit init_secondary_IRQ(void)
     BUG_ON(init_local_irq_data() < 0);
 }
 
-int __init request_dt_irq(const struct dt_irq *irq,
-        void (*handler)(int, void *, struct cpu_user_regs *),
-        const char *devname, void *dev_id)
+int request_dt_irq(const struct dt_irq *irq,
+                   void (*handler)(int, void *, struct cpu_user_regs *),
+                   const char *devname, void *dev_id)
 {
     struct irqaction *action;
     int retval;
xen/include/asm-arm/irq.h +4 -4
index 3197aec..9380987 100644
@@ -39,10 +39,10 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);
 void init_IRQ(void);
 void init_secondary_IRQ(void);
 
-int __init request_dt_irq(const struct dt_irq *irq,
-                          void (*handler)(int, void *, struct cpu_user_regs *),
-                          const char *devname, void *dev_id);
-int __init setup_dt_irq(const struct dt_irq *irq, struct irqaction *new);
+int request_dt_irq(const struct dt_irq *irq,
+                   void (*handler)(int, void *, struct cpu_user_regs *),
+                   const char *devname, void *dev_id);
+int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new);
 
 #endif /* _ASM_HW_IRQ_H */
 /*
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH v4 7/18 xen/arm: IRQ: Rework gic_route_irq_to_guest function

In reply to Julien Grall

The function gic_route_irq_to_guest contains code which is not related to the GIC. Split the function in 2 parts:

- route_dt_irq_to_guest: setup the desc
- gic_route_irq_to_guest: setup correctly the GIC and the desc handler

---
Changes in v3:
- Patch added (split from "Move IRQ management from gic.c to irq.c")

---
 xen/arch/arm/domain_build.c          |    2 +-
 xen/arch/arm/gic.c                   |   43 ++++++++++++++++++++++------------
 xen/arch/arm/platforms/xgene-storm.c |    2 +-
 xen/include/asm-arm/gic.h            |    3 ---
 xen/include/asm-arm/irq.h            |    3 +++
 5 files changed, 33 insertions(+), 20 deletions(-)
xen/arch/arm/domain_build.c +1 -1
index 7bc9bf6..5b636c8 100644
@@ -726,7 +726,7 @@ static int map_device(struct domain *d, const struct dt_device_node *dev)
 
         DPRINT("irq %u = %u type = 0x%x\n", i, irq.irq, irq.type);
         /* Don't check return because the IRQ can be use by multiple device */
-        gic_route_irq_to_guest(d, &irq, dt_node_name(dev));
+        route_dt_irq_to_guest(d, &irq, dt_node_name(dev));
     }
 
     /* Map the address ranges */
xen/arch/arm/gic.c +28 -15

72 lines not on this page · raw message

xen/arch/arm/platforms/xgene-storm.c +1 -1
index af3b71c..70aab73 100644
@@ -66,7 +66,7 @@ static int map_one_spi(struct domain *d, const char *what,
 
     printk("Additional IRQ %u (%s)\n", irq.irq, what);
 
-    ret = gic_route_irq_to_guest(d, &irq, what);
+    ret = route_dt_irq_to_guest(d, &irq, what);
     if ( ret )
         printk("Failed to route %s to dom%d\n", what, d->domain_id);
 
xen/include/asm-arm/gic.h +0 -3
index 071280b..9489c04 100644
@@ -181,9 +181,6 @@ extern void __cpuinit init_maintenance_interrupt(void);
 extern void gic_set_guest_irq(struct vcpu *v, unsigned int irq,
         unsigned int state, unsigned int priority);
 extern void gic_remove_from_queues(struct vcpu *v, unsigned int virtual_irq);
-extern int gic_route_irq_to_guest(struct domain *d,
-                                  const struct dt_irq *irq,
-                                  const char * devname);
 
 /* Accept an interrupt from the GIC and dispatch its handler */
 extern void gic_interrupt(struct cpu_user_regs *regs, int is_fiq);
xen/include/asm-arm/irq.h +3 -0
index 9380987..b52c26f 100644
@@ -44,6 +44,9 @@ int request_dt_irq(const struct dt_irq *irq,
                    const char *devname, void *dev_id);
 int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new);
 
+int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq,
+                          const char *devname);
+
 #endif /* _ASM_HW_IRQ_H */
 /*
  * Local variables:
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH v4 8/18 xen/arm: IRQ: Move IRQ management from gic.c to irq.c

In reply to Julien Grall

The file gic.c contains functions and variables which is not related to the GIC:
- release_irq
- setup_irq
- gic_route_irq_to_guest
- {,local_}irq_desc

Move all theses functions/variables in irq.c

---
Changes in v3:
- Split the patch in 2: refactoring + code motion
Changes in v2:
- Patch added

---
 xen/arch/arm/gic.c        |  102 ++-------------------------------------------
 xen/arch/arm/irq.c        |   97 ++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/gic.h |    4 ++
 3 files changed, 104 insertions(+), 99 deletions(-)
xen/arch/arm/gic.c +3 -99
index 90b129d..77dfecf 100644
@@ -52,8 +52,6 @@ static struct {
     spinlock_t lock;
 } gic;
 
-static irq_desc_t irq_desc[NR_IRQS];
-static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);
 static DEFINE_PER_CPU(uint64_t, lr_mask);
 
 static unsigned nr_lrs;
@@ -88,12 +86,6 @@ unsigned int gic_number_lines(void)
     return gic.lines;
 }
 
-irq_desc_t *__irq_to_desc(int irq)
-{
-    if (irq < NR_LOCAL_IRQS) return &this_cpu(local_irq_desc)[irq];
-    return &irq_desc[irq-NR_LOCAL_IRQS];
-}
-
 void gic_save_state(struct vcpu *v)
 {
     int i;
@@ -285,9 +277,9 @@ static int gic_route_irq(unsigned int irq, bool_t level,
 /* Program the GIC to route an interrupt to a guest
  *   - desc.lock must be held
  */
-static void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc,
-                                   bool_t level, const cpumask_t *cpu_mask,
-                                   unsigned int priority)
+void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc,
+                            bool_t level, const cpumask_t *cpu_mask,
+                            unsigned int priority)
 {
     struct pending_irq *p;
     ASSERT(spin_is_locked(&desc->lock));
@@ -591,59 +583,6 @@ void gic_route_spis(void)
     }
 }
 
-void release_irq(unsigned int irq)
-{
-    struct irq_desc *desc;
-    unsigned long flags;
-   struct irqaction *action;
-
-    desc = irq_to_desc(irq);
-
-    desc->handler->shutdown(desc);
-
-    spin_lock_irqsave(&desc->lock,flags);
-    action = desc->action;
-    desc->action  = NULL;
-    desc->status &= ~IRQ_GUEST;
-
-    spin_unlock_irqrestore(&desc->lock,flags);
-
-    /* Wait to make sure it's not being used on another CPU */
-    do { smp_mb(); } while ( desc->status & IRQ_INPROGRESS );
-
-    if (action && action->free_on_release)
-        xfree(action);
-}
-
-static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
-{
-    if ( desc->action != NULL )
-        return -EBUSY;
-
-    desc->action  = new;
-    dsb(sy);
-
-    return 0;
-}
-
-int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
-{
-    int rc;
-    unsigned long flags;
-    struct irq_desc *desc;
-
-    desc = irq_to_desc(irq->irq);
-
-    spin_lock_irqsave(&desc->lock, flags);
-    rc = __setup_irq(desc, new);
-    spin_unlock_irqrestore(&desc->lock, flags);
-
-    if ( !rc )
-        desc->handler->startup(desc);
-
-    return rc;
-}
-
 static inline void gic_set_lr(int lr, struct pending_irq *p,
         unsigned int state)
 {
@@ -782,41 +721,6 @@ void gic_inject(void)
         gic_inject_irq_start();
 }
 
-int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq,
-                          const char * devname)
-{
-    struct irqaction *action;
-    struct irq_desc *desc = irq_to_desc(irq->irq);
-    unsigned long flags;
-    int retval;
-    bool_t level;
-
-    action = xmalloc(struct irqaction);
-    if (!action)
-        return -ENOMEM;
-
-    action->dev_id = d;
-    action->name = devname;
-    action->free_on_release = 1;
-
-    spin_lock_irqsave(&desc->lock, flags);
-
-    retval = __setup_irq(desc, action);
-    if ( retval )
-    {
-        xfree(action);
-        goto out;
-    }
-
-    level = dt_irq_is_level_triggered(irq);
-    gic_route_irq_to_guest(d, desc, level, cpumask_of(smp_processor_id()),
-                           GIC_PRI_IRQ);
-
-out:
-    spin_unlock_irqrestore(&desc->lock, flags);
-    return retval;
-}
-
 static void do_sgi(struct cpu_user_regs *regs, int othercpu, enum gic_sgi sgi)
 {
     /* Lower the priority */
xen/arch/arm/irq.c +97 -0

109 lines not on this page · raw message

xen/include/asm-arm/gic.h +4 -0
index 9489c04..0e6e325 100644
@@ -153,6 +153,7 @@
 
 #ifndef __ASSEMBLY__
 #include <xen/device_tree.h>
+#include <xen/irq.h>
 
 #define DT_MATCH_GIC    DT_MATCH_COMPATIBLE("arm,cortex-a15-gic"), \
                         DT_MATCH_COMPATIBLE("arm,cortex-a7-gic")
@@ -170,6 +171,9 @@ extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
 extern void gic_route_dt_irq(const struct dt_irq *irq,
                              const cpumask_t *cpu_mask,
                              unsigned int priority);
+extern void gic_route_irq_to_guest(struct domain *, struct irq_desc *desc,
+                                   bool_t level, const cpumask_t *cpu_mask,
+                                   unsigned int priority);
 extern void gic_route_ppis(void);
 extern void gic_route_spis(void);
 
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH v4 9/18 xen/arm: IRQ Introduce irq_get_domain

In reply to Julien Grall

This function retrieves a domain from an IRQ. It will be used in several places (such as do_IRQ) to avoid duplicated code when multiple action will be supported.

---
Changes in v4:
- Return dom_xen when the IRQ is not routed to a guest

Changes in v2:
- Patch added

---
 xen/arch/arm/irq.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
xen/arch/arm/irq.c +13 -1
index f3a30bd..26574ca 100644
@@ -98,6 +98,18 @@ void __cpuinit init_secondary_IRQ(void)
     BUG_ON(init_local_irq_data() < 0);
 }
 
+static inline struct domain *irq_get_domain(struct irq_desc *desc)
+{
+    ASSERT(spin_is_locked(&desc->lock));
+
+    if ( !(desc->status & IRQ_GUEST) )
+        return dom_xen;
+
+    ASSERT(desc->action != NULL);
+
+    return desc->action->dev_id;
+}
+
 int request_dt_irq(const struct dt_irq *irq,
                    void (*handler)(int, void *, struct cpu_user_regs *),
                    const char *devname, void *dev_id)
@@ -156,7 +168,7 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
     if ( desc->status & IRQ_GUEST )
     {
-        struct domain *d = action->dev_id;
+        struct domain *d = irq_get_domain(desc);
 
         desc->handler->end(desc);
 
Signature · 1 line
1.7.10.4
#10 lore raw

PATCH v4 10/18 xen/arm: IRQ: Require desc.lock be held by callers of hw_irq_controller callbacks

In reply to Julien Grall

When multiple action are supported, gic_irq_{startup,shutdown} will have to be called in the same critical section as setup/release. Otherwise there is a race condition if at the same time CPU A is calling release_dt_irq and CPU B is calling setup_dt_irq.

This could end up with the IRQ not being enabled.

At the same time, modify gic_irq_{enable,disable} to require desc.lock be held.

With both of theses changes, ARM's locking requirements is the same as x86's.

---
Changes in v4:
- Fix typo in commit message
- Don't depend on Stefano's interrupt series (will likely be pushed before)

Changes in v3:
- Update commit message
- Require desc.lock also for gic_irq_{enable,disable}
- irqflags is unsigned long not unsigned int

Changes in v2:
- Fix typoes in commit message
- Move this patch earlier in the series => move shutdown() in release_irq and gic_route_irq

---
 xen/arch/arm/gic.c  |   21 +++++++++++----------
 xen/arch/arm/irq.c  |    6 ++++--
 xen/arch/arm/vgic.c |   10 ++++++++++
 3 files changed, 25 insertions(+), 12 deletions(-)
xen/arch/arm/gic.c +11 -10
index 77dfecf..29ecb49 100644
@@ -128,14 +128,14 @@ static void gic_irq_enable(struct irq_desc *desc)
     int irq = desc->irq;
     unsigned long flags;
 
-    spin_lock_irqsave(&desc->lock, flags);
-    spin_lock(&gic.lock);
+    ASSERT(spin_is_locked(&desc->lock));
+
+    spin_lock_irqsave(&gic.lock, flags);
     desc->status &= ~IRQ_DISABLED;
     dsb(sy);
     /* Enable routing */
     GICD[GICD_ISENABLER + irq / 32] = (1u << (irq % 32));
-    spin_unlock(&gic.lock);
-    spin_unlock_irqrestore(&desc->lock, flags);
+    spin_unlock_irqrestore(&gic.lock, flags);
 }
 
 static void gic_irq_disable(struct irq_desc *desc)
@@ -143,18 +143,19 @@ static void gic_irq_disable(struct irq_desc *desc)
     int irq = desc->irq;
     unsigned long flags;
 
-    spin_lock_irqsave(&desc->lock, flags);
-    spin_lock(&gic.lock);
+    ASSERT(spin_is_locked(&desc->lock));
+
+    spin_lock_irqsave(&gic.lock, flags);
     /* Disable routing */
     GICD[GICD_ICENABLER + irq / 32] = (1u << (irq % 32));
     desc->status |= IRQ_DISABLED;
-    spin_unlock(&gic.lock);
-    spin_unlock_irqrestore(&desc->lock, flags);
+    spin_unlock_irqrestore(&gic.lock, flags);
 }
 
 static unsigned int gic_irq_startup(struct irq_desc *desc)
 {
     gic_irq_enable(desc);
+
     return 0;
 }
 
@@ -261,11 +262,11 @@ static int gic_route_irq(unsigned int irq, bool_t level,
     if ( desc->action != NULL )
         return -EBUSY;
 
+    spin_lock_irqsave(&desc->lock, flags);
+
     /* Disable interrupt */
     desc->handler->shutdown(desc);
 
-    spin_lock_irqsave(&desc->lock, flags);
-
     desc->handler = &gic_host_irq_type;
 
     gic_set_irq_properties(irq, level, cpu_mask, priority);
xen/arch/arm/irq.c +4 -2
index 26574ca..b6dd9de 100644
@@ -217,9 +217,10 @@ void release_irq(unsigned int irq)
 
     desc = irq_to_desc(irq);
 
+    spin_lock_irqsave(&desc->lock,flags);
+
     desc->handler->shutdown(desc);
 
-    spin_lock_irqsave(&desc->lock,flags);
     action = desc->action;
     desc->action  = NULL;
     desc->status &= ~IRQ_GUEST;
@@ -254,11 +255,12 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
 
     spin_lock_irqsave(&desc->lock, flags);
     rc = __setup_irq(desc, new);
-    spin_unlock_irqrestore(&desc->lock, flags);
 
     if ( !rc )
         desc->handler->startup(desc);
 
+    spin_unlock_irqrestore(&desc->lock, flags);
+
     return rc;
 }
 
xen/arch/arm/vgic.c +10 -0
index 4a7f8c0..1b95003 100644
@@ -374,6 +374,7 @@ static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
     const unsigned long mask = r;
     struct pending_irq *p;
     unsigned int irq;
+    unsigned long flags;
     int i = 0;
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
@@ -382,7 +383,11 @@ static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
         clear_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
         gic_remove_from_queues(v, irq);
         if ( p->desc != NULL )
+        {
+            spin_lock_irqsave(&p->desc->lock, flags);
             p->desc->handler->disable(p->desc);
+            spin_unlock_irqrestore(&p->desc->lock, flags);
+        }
         i++;
     }
 }
@@ -392,6 +397,7 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
     const unsigned long mask = r;
     struct pending_irq *p;
     unsigned int irq;
+    unsigned long flags;
     int i = 0;
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
@@ -401,7 +407,11 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
         if ( !list_empty(&p->inflight) && !test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) )
             gic_set_guest_irq(v, irq, GICH_LR_PENDING, p->priority);
         if ( p->desc != NULL )
+        {
+            spin_lock_irqsave(&p->desc->lock, flags);
             p->desc->handler->enable(p->desc);
+            spin_unlock_irqrestore(&p->desc->lock, flags);
+        }
         i++;
     }
 }
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH v4 11/18 xen/arm: IRQ: Defer routing IRQ to Xen until setup_irq() call

In reply to Julien Grall

When an IRQ is handling by Xen, setup is done in 2 steps:
- Route the IRQ to the current CPU and set priorities
- Set up the handler

For PPIs, these steps are called on every cpu. For SPIs, they are only called on the boot CPU.

Dividing the setup in two step complicates the code when a new driver is added to Xen (for instance a SMMU driver). Xen can safely route the IRQ when the driver sets up the interrupt handler.

---
Changes in v3:
- Don't need to initialiase disabled
- Typoes and update commit message

Changes in v2:
- Fix typo in commit message
- s/SGI/SPI/ in comments
- Rename gic_route_dt_irq into gic_route_irq_to_xen which is taking a desc now
- Call setup_irq before initializing the GIC IRQ as the first one can fail.

---
 xen/arch/arm/gic.c         |   63 +++++++-------------------------------------
 xen/arch/arm/irq.c         |   24 ++++++++++++++++-
 xen/arch/arm/setup.c       |    2 --
 xen/arch/arm/smpboot.c     |    2 --
 xen/arch/arm/time.c        |   11 --------
 xen/include/asm-arm/gic.h  |   10 +++----
 xen/include/asm-arm/time.h |    3 ---
 7 files changed, 36 insertions(+), 79 deletions(-)
xen/arch/arm/gic.c +9 -54
index 29ecb49..577d85b 100644
@@ -249,30 +249,20 @@ static void gic_set_irq_properties(unsigned int irq, bool_t level,
     spin_unlock(&gic.lock);
 }
 
-/* Program the GIC to route an interrupt */
-static int gic_route_irq(unsigned int irq, bool_t level,
-                         const cpumask_t *cpu_mask, unsigned int priority)
+/* Program the GIC to route an interrupt to the host (i.e. Xen)
+ * - needs to be called with desc.lock held
+ */
+void gic_route_irq_to_xen(struct irq_desc *desc, bool_t level,
+                          const cpumask_t *cpu_mask, unsigned int priority)
 {
-    struct irq_desc *desc = irq_to_desc(irq);
-    unsigned long flags;
-
     ASSERT(priority <= 0xff);     /* Only 8 bits of priority */
-    ASSERT(irq < gic.lines);      /* Can't route interrupts that don't exist */
-
-    if ( desc->action != NULL )
-        return -EBUSY;
-
-    spin_lock_irqsave(&desc->lock, flags);
-
-    /* Disable interrupt */
-    desc->handler->shutdown(desc);
+    ASSERT(desc->irq < gic.lines);/* Can't route interrupts that don't exist */
+    ASSERT(desc->status & IRQ_DISABLED);
+    ASSERT(spin_is_locked(&desc->lock));
 
     desc->handler = &gic_host_irq_type;
 
-    gic_set_irq_properties(irq, level, cpu_mask, priority);
-
-    spin_unlock_irqrestore(&desc->lock, flags);
-    return 0;
+    gic_set_irq_properties(desc->irq, level, cpu_mask, priority);
 }
 
 /* Program the GIC to route an interrupt to a guest
@@ -296,17 +286,6 @@ void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc,
     p->desc = desc;
 }
 
-/* Program the GIC to route an interrupt with a dt_irq */
-void gic_route_dt_irq(const struct dt_irq *irq, const cpumask_t *cpu_mask,
-                      unsigned int priority)
-{
-    bool_t level;
-
-    level = dt_irq_is_level_triggered(irq);
-
-    gic_route_irq(irq->irq, level, cpu_mask, priority);
-}
-
 static void __init gic_dist_init(void)
 {
     uint32_t type;
@@ -560,30 +539,6 @@ void gic_disable_cpu(void)
     spin_unlock(&gic.lock);
 }
 
-void gic_route_ppis(void)
-{
-    /* GIC maintenance */
-    gic_route_dt_irq(&gic.maintenance, cpumask_of(smp_processor_id()),
-                     GIC_PRI_IRQ);
-    /* Route timer interrupt */
-    route_timer_interrupt();
-}
-
-void gic_route_spis(void)
-{
-    int seridx;
-    const struct dt_irq *irq;
-
-    for ( seridx = 0; seridx <= SERHND_IDX; seridx++ )
-    {
-        if ( (irq = serial_dt_irq(seridx)) == NULL )
-            continue;
-
-        gic_route_dt_irq(irq, cpumask_of(smp_processor_id()),
-                         GIC_PRI_IRQ);
-    }
-}
-
 static inline void gic_set_lr(int lr, struct pending_irq *p,
         unsigned int state)
 {
xen/arch/arm/irq.c +23 -1
index b6dd9de..9f1ca40 100644
@@ -250,15 +250,37 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
     int rc;
     unsigned long flags;
     struct irq_desc *desc;
+    bool_t disabled;
 
     desc = irq_to_desc(irq->irq);
 
     spin_lock_irqsave(&desc->lock, flags);
+
+    disabled = (desc->action == NULL);
+
     rc = __setup_irq(desc, new);
+    if ( rc )
+        goto err;
 
-    if ( !rc )
+    /* First time the IRQ is setup */
+    if ( disabled )
+    {
+        bool_t level;
+
+        level = dt_irq_is_level_triggered(irq);
+        /* It's fine to use smp_processor_id() because:
+         * For PPI: irq_desc is banked
+         * For SPI: we don't care for now which CPU will receive the
+         * interrupt
+         * TODO: Handle case where SPI is setup on different CPU than
+         * the targeted CPU and the priority.
+         */
+        gic_route_irq_to_xen(desc, level, cpumask_of(smp_processor_id()),
+                             GIC_PRI_IRQ);
         desc->handler->startup(desc);
+    }
 
+err:
     spin_unlock_irqrestore(&desc->lock, flags);
 
     return rc;
xen/arch/arm/setup.c +0 -2
index 6b77a4c..dec5950 100644
@@ -719,8 +719,6 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     init_IRQ();
 
-    gic_route_ppis();
-    gic_route_spis();
     xsm_dt_init();
 
     init_maintenance_interrupt();
xen/arch/arm/smpboot.c +0 -2
index 7f28b68..cf149da 100644
@@ -287,8 +287,6 @@ void __cpuinit start_secondary(unsigned long boot_phys_offset,
 
     init_secondary_IRQ();
 
-    gic_route_ppis();
-
     init_maintenance_interrupt();
     init_timer_interrupt();
 
xen/arch/arm/time.c +0 -11
index 7cad888..ce96337 100644
@@ -218,17 +218,6 @@ static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
     vgic_vcpu_inject_irq(current, current->arch.virt_timer.irq, 1);
 }
 
-/* Route timer's IRQ on this CPU */
-void __cpuinit route_timer_interrupt(void)
-{
-    gic_route_dt_irq(&timer_irq[TIMER_PHYS_NONSECURE_PPI],
-                     cpumask_of(smp_processor_id()), GIC_PRI_IRQ);
-    gic_route_dt_irq(&timer_irq[TIMER_HYP_PPI],
-                     cpumask_of(smp_processor_id()), GIC_PRI_IRQ);
-    gic_route_dt_irq(&timer_irq[TIMER_VIRT_PPI],
-                     cpumask_of(smp_processor_id()), GIC_PRI_IRQ);
-}
-
 /* Set up the timer interrupt on this CPU */
 void __cpuinit init_timer_interrupt(void)
 {
xen/include/asm-arm/gic.h +4 -6
index 0e6e325..b750b17 100644
@@ -167,15 +167,13 @@ extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int irq,int virtual);
 extern void vgic_clear_pending_irqs(struct vcpu *v);
 extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
 
-/* Program the GIC to route an interrupt with a dt_irq */
-extern void gic_route_dt_irq(const struct dt_irq *irq,
-                             const cpumask_t *cpu_mask,
-                             unsigned int priority);
+/* Program the GIC to route an interrupt */
+extern void gic_route_irq_to_xen(struct irq_desc *desc, bool_t level,
+                                 const cpumask_t *cpu_mask,
+                                 unsigned int priority);
 extern void gic_route_irq_to_guest(struct domain *, struct irq_desc *desc,
                                    bool_t level, const cpumask_t *cpu_mask,
                                    unsigned int priority);
-extern void gic_route_ppis(void);
-extern void gic_route_spis(void);
 
 extern void gic_inject(void);
 extern void gic_clear_pending_irqs(struct vcpu *v);
xen/include/asm-arm/time.h +0 -3
index 9bbab0b..d544b5b 100644
@@ -25,9 +25,6 @@ enum timer_ppi
 /* Get one of the timer IRQ number */
 unsigned int timer_get_irq(enum timer_ppi ppi);
 
-/* Route timer's IRQ on this CPU */
-extern void __cpuinit route_timer_interrupt(void);
-
 /* Set up the timer interrupt on this CPU */
 extern void __cpuinit init_timer_interrupt(void);
 
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH v4 12/18 xen/arm: IRQ: Do not allow IRQ to be shared between domains and XEN

In reply to Julien Grall

The current dt_route_irq_to_guest implementation sets IRQ_GUEST even if the IRQ is correctly setup.

An IRQ can be shared between devices, if the devices are not assigned to the same domain or Xen, then this could result in routing the IRQ to the domain instead of Xen ...

Also avoid to relying on wrong the behaviour when Xen is routing an IRQ to DOM0. Therefore check the return code from route_dt_irq_to_guest in map_device.

---
Changes in v4:
- Don't forget to free action if sanity check has failed

Changes in v3:
- Fix typoes and update commit message

Changes in v2:
- Use EBUSY instead of EADDRINUSE for error code
- Don't hardcode the domain in error message
- Fix typo in error message
- Use irq_get_domain

---
 xen/arch/arm/domain_build.c |    9 +++++++--
 xen/arch/arm/irq.c          |   41 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 6 deletions(-)
xen/arch/arm/domain_build.c +7 -2
index 5b636c8..9dcff1c 100644
@@ -725,8 +725,13 @@ static int map_device(struct domain *d, const struct dt_device_node *dev)
         }
 
         DPRINT("irq %u = %u type = 0x%x\n", i, irq.irq, irq.type);
-        /* Don't check return because the IRQ can be use by multiple device */
-        route_dt_irq_to_guest(d, &irq, dt_node_name(dev));
+        res = route_dt_irq_to_guest(d, &irq, dt_node_name(dev));
+        if ( res )
+        {
+            printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n",
+                   irq.irq, d->domain_id);
+            return res;
+        }
     }
 
     /* Map the address ranges */
xen/arch/arm/irq.c +37 -4

69 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#13 lore raw

PATCH v4 13/18 xen/serial: remove serial_dt_irq

In reply to Julien Grall

This function was only used for ARM IRQ routing which has been removed in an earlier patch.

---
Changes in v2:
- Specify in the commit this patch is ARM specific

---
 xen/drivers/char/exynos4210-uart.c |    8 --------
 xen/drivers/char/ns16550.c         |   11 -----------
 xen/drivers/char/omap-uart.c       |    8 --------
 xen/drivers/char/pl011.c           |    8 --------
 xen/drivers/char/serial.c          |    9 ---------
 xen/include/xen/serial.h           |    5 -----
 6 files changed, 49 deletions(-)
xen/drivers/char/exynos4210-uart.c +0 -8
index d49e1fe..370539c 100644
@@ -275,13 +275,6 @@ static int __init exynos4210_uart_irq(struct serial_port *port)
     return uart->irq.irq;
 }
 
-static const struct dt_irq __init *exynos4210_uart_dt_irq(struct serial_port *port)
-{
-    struct exynos4210_uart *uart = port->uart;
-
-    return &uart->irq;
-}
-
 static const struct vuart_info *exynos4210_vuart_info(struct serial_port *port)
 {
     struct exynos4210_uart *uart = port->uart;
@@ -299,7 +292,6 @@ static struct uart_driver __read_mostly exynos4210_uart_driver = {
     .putc         = exynos4210_uart_putc,
     .getc         = exynos4210_uart_getc,
     .irq          = exynos4210_uart_irq,
-    .dt_irq_get   = exynos4210_uart_dt_irq,
     .vuart_info   = exynos4210_vuart_info,
 };
 
xen/drivers/char/ns16550.c +0 -11
index 4aa33d5..21f086a 100644
@@ -742,14 +742,6 @@ static int __init ns16550_irq(struct serial_port *port)
     return ((uart->irq > 0) ? uart->irq : -1);
 }
 
-#ifdef HAS_DEVICE_TREE
-static const struct dt_irq __init *ns16550_dt_irq(struct serial_port *port)
-{
-    struct ns16550 *uart = port->uart;
-    return &uart->dt_irq;
-}
-#endif
-
 #ifdef CONFIG_ARM
 static const struct vuart_info *ns16550_vuart_info(struct serial_port *port)
 {
@@ -769,9 +761,6 @@ static struct uart_driver __read_mostly ns16550_driver = {
     .putc         = ns16550_putc,
     .getc         = ns16550_getc,
     .irq          = ns16550_irq,
-#ifdef HAS_DEVICE_TREE
-    .dt_irq_get   = ns16550_dt_irq,
-#endif
 #ifdef CONFIG_ARM
     .vuart_info   = ns16550_vuart_info,
 #endif
xen/drivers/char/omap-uart.c +0 -8
index 49ae1a4..b8da509 100644
@@ -262,13 +262,6 @@ static int __init omap_uart_irq(struct serial_port *port)
     return ((uart->irq.irq > 0) ? uart->irq.irq : -1);
 }
 
-static const struct dt_irq __init *omap_uart_dt_irq(struct serial_port *port)
-{
-    struct omap_uart *uart = port->uart;
-
-    return &uart->irq;
-}
-
 static const struct vuart_info *omap_vuart_info(struct serial_port *port)
 {
     struct omap_uart *uart = port->uart;
@@ -286,7 +279,6 @@ static struct uart_driver __read_mostly omap_uart_driver = {
     .putc = omap_uart_putc,
     .getc = omap_uart_getc,
     .irq = omap_uart_irq,
-    .dt_irq_get = omap_uart_dt_irq,
     .vuart_info = omap_vuart_info,
 };
 
xen/drivers/char/pl011.c +0 -8
index 90bf0c6..459e686 100644
@@ -189,13 +189,6 @@ static int __init pl011_irq(struct serial_port *port)
     return ((uart->irq.irq > 0) ? uart->irq.irq : -1);
 }
 
-static const struct dt_irq __init *pl011_dt_irq(struct serial_port *port)
-{
-    struct pl011 *uart = port->uart;
-
-    return &uart->irq;
-}
-
 static const struct vuart_info *pl011_vuart(struct serial_port *port)
 {
     struct pl011 *uart = port->uart;
@@ -213,7 +206,6 @@ static struct uart_driver __read_mostly pl011_driver = {
     .putc         = pl011_putc,
     .getc         = pl011_getc,
     .irq          = pl011_irq,
-    .dt_irq_get   = pl011_dt_irq,
     .vuart_info   = pl011_vuart,
 };
 
xen/drivers/char/serial.c +0 -9
index 9b006f2..44026b1 100644
@@ -500,15 +500,6 @@ int __init serial_irq(int idx)
     return -1;
 }
 
-const struct dt_irq __init *serial_dt_irq(int idx)
-{
-    if ( (idx >= 0) && (idx < ARRAY_SIZE(com)) &&
-         com[idx].driver && com[idx].driver->dt_irq_get )
-        return com[idx].driver->dt_irq_get(&com[idx]);
-
-    return NULL;
-}
-
 const struct vuart_info *serial_vuart_info(int idx)
 {
     if ( (idx >= 0) && (idx < ARRAY_SIZE(com)) &&
xen/include/xen/serial.h +0 -5
index f38c9b7..9f4451b 100644
@@ -81,8 +81,6 @@ struct uart_driver {
     int  (*getc)(struct serial_port *, char *);
     /* Get IRQ number for this port's serial line: returns -1 if none. */
     int  (*irq)(struct serial_port *);
-    /* Get IRQ device node for this port's serial line: returns NULL if none. */
-    const struct dt_irq *(*dt_irq_get)(struct serial_port *);
     /* Get serial information */
     const struct vuart_info *(*vuart_info)(struct serial_port *);
 };
@@ -135,9 +133,6 @@ void serial_end_log_everything(int handle);
 /* Return irq number for specified serial port (identified by index). */
 int serial_irq(int idx);
 
-/* Return irq device node for specified serial port (identified by index). */
-const struct dt_irq *serial_dt_irq(int idx);
-
 /* Retrieve basic UART information to emulate it (base address, size...) */
 const struct vuart_info* serial_vuart_info(int idx);
 
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH v4 14/18 xen/arm: IRQ: Store IRQ type in arch_irq_desc

In reply to Julien Grall

For now, ARM uses different IRQ functions to setup an interrupt handler. This is a bit annoying for common driver because we have to add idefery when an IRQ is setup (see ns16550_init_postirq for an example).

To avoid to completely fork the IRQ management code, we can introduce a field to store the IRQ type (e.g level/edge ...).

This patch also adds platform_get_irq which will retrieve the IRQ from the device tree and setup correctly the IRQ type.

In order to use this solution, we have to move init_IRQ earlier for the boot CPU. It's fine because the code only depends on percpu.

---
Changes in v4:
- Add an ASSERT to check if irq_set_type hasn't failed for PPI on other CPU than 0
- platform_get_irq return -1 in case of error.

Changes in v3:
- irqflags is unsigned long not unsigned int
- fix comment
- don't need to set IRQ type when NONE is used (already set at startup).

Changes in v2:
- Patch added

---
 xen/arch/arm/gic.c        |   23 ++++++------
 xen/arch/arm/irq.c        |   85 +++++++++++++++++++++++++++++++++++++++++----
 xen/arch/arm/setup.c      |    3 +-
 xen/include/asm-arm/gic.h |    5 ++-
 xen/include/asm-arm/irq.h |    3 ++
 5 files changed, 98 insertions(+), 21 deletions(-)
xen/arch/arm/gic.c +13 -10
index 577d85b..4a6ed35 100644
@@ -216,14 +216,19 @@ static hw_irq_controller gic_guest_irq_type = {
 /*
  * - needs to be called with a valid cpu_mask, ie each cpu in the mask has
  * already called gic_cpu_init
+ * - desc.lock must be held
  */
-static void gic_set_irq_properties(unsigned int irq, bool_t level,
+static void gic_set_irq_properties(struct irq_desc *desc,
                                    const cpumask_t *cpu_mask,
                                    unsigned int priority)
 {
     volatile unsigned char *bytereg;
     uint32_t cfg, edgebit;
     unsigned int mask;
+    unsigned int irq = desc->irq;
+    unsigned int type = desc->arch.type;
+
+    ASSERT(spin_is_locked(&desc->lock));
 
     spin_lock(&gic.lock);
 
@@ -232,9 +237,9 @@ static void gic_set_irq_properties(unsigned int irq, bool_t level,
     /* Set edge / level */
     cfg = GICD[GICD_ICFGR + irq / 16];
     edgebit = 2u << (2 * (irq % 16));
-    if ( level )
+    if ( type & DT_IRQ_TYPE_LEVEL_MASK )
         cfg &= ~edgebit;
-    else
+    else if ( type & DT_IRQ_TYPE_EDGE_BOTH )
         cfg |= edgebit;
     GICD[GICD_ICFGR + irq / 16] = cfg;
 
@@ -252,8 +257,8 @@ static void gic_set_irq_properties(unsigned int irq, bool_t level,
 /* Program the GIC to route an interrupt to the host (i.e. Xen)
  * - needs to be called with desc.lock held
  */
-void gic_route_irq_to_xen(struct irq_desc *desc, bool_t level,
-                          const cpumask_t *cpu_mask, unsigned int priority)
+void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask,
+                          unsigned int priority)
 {
     ASSERT(priority <= 0xff);     /* Only 8 bits of priority */
     ASSERT(desc->irq < gic.lines);/* Can't route interrupts that don't exist */
@@ -262,15 +267,14 @@ void gic_route_irq_to_xen(struct irq_desc *desc, bool_t level,
 
     desc->handler = &gic_host_irq_type;
 
-    gic_set_irq_properties(desc->irq, level, cpu_mask, priority);
+    gic_set_irq_properties(desc, cpu_mask, priority);
 }
 
 /* Program the GIC to route an interrupt to a guest
  *   - desc.lock must be held
  */
 void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc,
-                            bool_t level, const cpumask_t *cpu_mask,
-                            unsigned int priority)
+                            const cpumask_t *cpu_mask, unsigned int priority)
 {
     struct pending_irq *p;
     ASSERT(spin_is_locked(&desc->lock));
@@ -278,8 +282,7 @@ void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc,
     desc->handler = &gic_guest_irq_type;
     desc->status |= IRQ_GUEST;
 
-    gic_set_irq_properties(desc->irq, level, cpumask_of(smp_processor_id()),
-                           GIC_PRI_IRQ);
+    gic_set_irq_properties(desc, cpumask_of(smp_processor_id()), GIC_PRI_IRQ);
 
     /* TODO: do not assume delivery to vcpu0 */
     p = irq_to_pending(d->vcpu[0], desc->irq);
xen/arch/arm/irq.c +78 -7

127 lines not on this page · raw message

xen/arch/arm/setup.c +2 -1
index dec5950..40ba26e 100644
@@ -688,6 +688,8 @@ void __init start_xen(unsigned long boot_phys_offset,
     dt_unflatten_host_device_tree();
     dt_irq_xlate = gic_irq_xlate;
 
+    init_IRQ();
+
     dt_uart_init();
     console_init_preirq();
 
@@ -717,7 +719,6 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     tasklet_subsys_init();
 
-    init_IRQ();
 
     xsm_dt_init();
 
xen/include/asm-arm/gic.h +2 -3
index b750b17..80f8dd2 100644
@@ -168,11 +168,10 @@ extern void vgic_clear_pending_irqs(struct vcpu *v);
 extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq);
 
 /* Program the GIC to route an interrupt */
-extern void gic_route_irq_to_xen(struct irq_desc *desc, bool_t level,
-                                 const cpumask_t *cpu_mask,
+extern void gic_route_irq_to_xen(struct irq_desc *desc, const cpumask_t *cpu_mask,
                                  unsigned int priority);
 extern void gic_route_irq_to_guest(struct domain *, struct irq_desc *desc,
-                                   bool_t level, const cpumask_t *cpu_mask,
+                                   const cpumask_t *cpu_mask,
                                    unsigned int priority);
 
 extern void gic_inject(void);
xen/include/asm-arm/irq.h +3 -0
index b52c26f..93d2128 100644
@@ -16,6 +16,7 @@ struct arch_pirq
 
 struct arch_irq_desc {
     int eoi_cpu;
+    unsigned int type;
 };
 
 #define NR_LOCAL_IRQS	32
@@ -46,6 +47,8 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new);
 
 int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq,
                           const char *devname);
+int platform_get_irq(const struct dt_device_node *device,
+                     int index);
 
 #endif /* _ASM_HW_IRQ_H */
 /*
Signature · 1 line
1.7.10.4
#15 lore raw

Re: [PATCH v4 14/18] xen/arm: IRQ: Store IRQ type in arch_irq_desc

xen/arch/arm/irq.c static int __cpuinit init_local_irq_data(void) · line 91

Quoted 10 lines · Julien Grall
xen/arch/arm/irq.c +6 -0
@@ -82,6 +83,12 @@ static int __cpuinit init_local_irq_data(void)
         init_one_irq_desc(desc);
         desc->irq = irq;
         desc->action  = NULL;
+
+        /* PPIs are include in local_irqs, we have to copy the IRQ type from
+         * CPU0 otherwise we may miss the type if the IRQ type has been
+         * set early.
+         */
+        desc->arch.type = per_cpu(local_irq_desc, 0)[irq].arch.type;

I forgot to introduce a boot_cpu macro (as asked by Ian on v2).

I will write a follow-up to remove per_cpu(..., 0) in few places if I don't need to resent this series.

Signature · 1 line
Julien Grall
#16 lore raw

Re: [PATCH v4 14/18] xen/arm: IRQ: Store IRQ type in arch_irq_desc

In reply to Julien Grall
Quoted 7 lines · Julien Grall

For now, ARM uses different IRQ functions to setup an interrupt handler. This is a bit annoying for common driver because we have to add idefery when an IRQ is setup (see ns16550_init_postirq for an example).

To avoid to completely fork the IRQ management code, we can introduce a field to store the IRQ type (e.g level/edge ...).

Quoted 7 lines

This patch also adds platform_get_irq which will retrieve the IRQ from the device tree and setup correctly the IRQ type.

In order to use this solution, we have to move init_IRQ earlier for the boot CPU. It's fine because the code only depends on percpu.

Mostly just grammar nits.

xen/arch/arm/irq.c static int __cpuinit init_local_irq_data(void) · line 87

Quoted 6 lines
xen/arch/arm/irq.c +2 -0
@@ -82,6 +83,12 @@ static int __cpuinit init_local_irq_data(void)
         init_one_irq_desc(desc);
         desc->irq = irq;
         desc->action  = NULL;
+
+        /* PPIs are include in local_irqs, we have to copy the IRQ type from

"included"

xen/arch/arm/irq.c static int __cpuinit init_local_irq_data(void) · line 89

Quoted 2 lines
xen/arch/arm/irq.c +2 -0
+         * CPU0 otherwise we may miss the type if the IRQ type has been
+         * set early.

what does "set early" mean, how early is early? Initialised before secondary CPUs were brought up perhaps?

/* PPIs are included in local_irqs, we copy the IRQ type from
* CPU0 when bringing up secondary cpus in order to pick up any
* configuration done before this CPU came up. For interrupts
* configured after this point this is done in XXX().

Why is the copying not conditional on CPU!=0?

xen/arch/arm/irq.c void pirq_set_affinity(struct domain *d, int pirq, const cpumask_t *mask) · line 431

Quoted 5 lines
xen/arch/arm/irq.c +5 -0
+    /* Setup the IRQ type */
+    if ( irq < NR_LOCAL_IRQS )
+    {
+        unsigned int cpu;
+        /* For PPIs, we need to set IRQ type on every online CPUs */

CPU should be singular here.

xen/arch/arm/irq.c void pirq_set_affinity(struct domain *d, int pirq, const cpumask_t *mask) · line 440

Quoted 9 lines
xen/arch/arm/irq.c +9 -0
+        for_each_cpu( cpu, &cpu_online_map )
+        {
+            desc = &per_cpu(local_irq_desc, cpu)[irq];
+            res = irq_set_type(desc, type);
+            if ( res )
+            {
+                /*
+                 * For PPIs the IRQ type is the same on every CPU. It
+                 * should not fail to other CPU than CPU0

"It should not fail on other CPUs than CPU0" (or "cannot fail" would be stronger, and an assert is pretty strong).

Ian.

#17 lore raw

Re: [PATCH v4 14/18] xen/arm: IRQ: Store IRQ type in arch_irq_desc

Hi Ian,

Sorry for the delay, for some unknown reason I skipped this mail.

Quoted 5 lines · Ian Campbell

xen/arch/arm/irq.c static int __cpuinit init_local_irq_data(void) · line 89

Quoted 2 lines
xen/arch/arm/irq.c +2 -0
+         * CPU0 otherwise we may miss the type if the IRQ type has been
+         * set early.

what does "set early" mean, how early is early? Initialised before secondary CPUs were brought up perhaps?

Yes. I will replace "set early" by "initialised before secondary CPUs were brought up"

Quoted 5 lines

/* PPIs are included in local_irqs, we copy the IRQ type from
* CPU0 when bringing up secondary cpus in order to pick up any
* configuration done before this CPU came up. For interrupts
* configured after this point this is done in XXX().

I guess you suggest to replace the previous comment by this one, right?

Quoted 1 line

Why is the copying not conditional on CPU!=0?

As the CPU were not online (therefore its per_cpu regions is not there) at the time we setup the IRQ we have to unconditionally set the IRQ type.

Regards,

Signature · 1 line
Julien Grall
#18 lore raw

Re: [PATCH v4 14/18] xen/arm: IRQ: Store IRQ type in arch_irq_desc

Quoted 15 lines · Julien Grall

Hi Ian,

Sorry for the delay, for some unknown reason I skipped this mail.

Quoted 5 lines · Ian Campbell

xen/arch/arm/irq.c static int __cpuinit init_local_irq_data(void) · line 89

Quoted 2 lines
xen/arch/arm/irq.c +2 -0
+         * CPU0 otherwise we may miss the type if the IRQ type has been
+         * set early.

what does "set early" mean, how early is early? Initialised before secondary CPUs were brought up perhaps?

Yes. I will replace "set early" by "initialised before secondary CPUs were brought up"

Quoted 1 line
Quoted 6 lines
Quoted 4 lines

/* PPIs are included in local_irqs, we copy the IRQ type from
* CPU0 when bringing up secondary cpus in order to pick up any
* configuration done before this CPU came up. For interrupts
* configured after this point this is done in XXX().

I guess you suggest to replace the previous comment by this one, right?

If it is factually accurate, yes.

Quoted 4 lines
Quoted 1 line

Why is the copying not conditional on CPU!=0?

As the CPU were not online (therefore its per_cpu regions is not there) at the time we setup the IRQ we have to unconditionally set the IRQ type.

But CPU0 must have been online when we setup the IRQ.

IOW if CPU==0 then isn't

        desc->arch.type = per_cpu(local_irq_desc, 0)[irq].arch.type;
equivalent to
        desc->arch.type = desc->arch.type

?

Ian.

#19 lore raw

Re: [PATCH v4 14/18] xen/arm: IRQ: Store IRQ type in arch_irq_desc

Quoted 8 lines · Ian Campbell

But CPU0 must have been online when we setup the IRQ.

IOW if CPU==0 then isn't

         desc->arch.type = per_cpu(local_irq_desc, 0)[irq].arch.type;
equivalent to
         desc->arch.type = desc->arch.type

?

Hmmmm yes, I forgot this case. I will update the patch in the next version.

Signature · 1 line
Julien Grall
#20 lore raw

PATCH v4 15/18 xen/arm: IRQ: Replace {request, setup}_dt_irq by {request, setup}_irq

In reply to Julien Grall

Now that irq_desc stores the type of the IRQ (e.g level/edge,...), we don't need to use specific IRQ function for ARM.

Also replace every call to dt_device_get_irq by platform_get_irq which is a wrapper to this function and setup the IRQ type correctly.

---
Changes in v4:
- platform_get_irq now returns -1 in case of error.

Changes in v3:
- Fix typoes in commit message

Changes in v2:
- Patch added

---
 xen/arch/arm/gic.c                 |   13 +++++++------
 xen/arch/arm/irq.c                 |   23 +++++++++++------------
 xen/arch/arm/time.c                |   30 ++++++++++++++++--------------
 xen/drivers/char/exynos4210-uart.c |   15 ++++++++-------
 xen/drivers/char/ns16550.c         |   18 ++++--------------
 xen/drivers/char/omap-uart.c       |   15 ++++++++-------
 xen/drivers/char/pl011.c           |   18 ++++++++++--------
 xen/include/asm-arm/irq.h          |    5 -----
 8 files changed, 64 insertions(+), 73 deletions(-)
xen/arch/arm/gic.c +7 -6
index 4a6ed35..cb40b0a 100644
@@ -47,7 +47,7 @@ static struct {
     paddr_t hbase;       /* Address of virtual interface registers */
     paddr_t vbase;       /* Address of virtual cpu interface registers */
     unsigned int lines;  /* Number of interrupts (SPIs + PPIs + SGIs) */
-    struct dt_irq maintenance; /* IRQ maintenance */
+    unsigned int maintenance_irq; /* IRQ maintenance */
     unsigned int cpus;
     spinlock_t lock;
 } gic;
@@ -431,9 +431,10 @@ void __init gic_init(void)
     if ( res || !gic.vbase || (gic.vbase & ~PAGE_MASK) )
         panic("GIC: Cannot find a valid address for the virtual CPU");
 
-    res = dt_device_get_irq(node, 0, &gic.maintenance);
-    if ( res )
+    res = platform_get_irq(node, 0);
+    if ( res < 0 )
         panic("GIC: Cannot find the maintenance IRQ");
+    gic.maintenance_irq = res;
 
     /* Set the GIC as the primary interrupt controller */
     dt_interrupt_controller = node;
@@ -447,7 +448,7 @@ void __init gic_init(void)
               "        gic_vcpu_addr=%"PRIpaddr"\n"
               "        gic_maintenance_irq=%u\n",
               gic.dbase, gic.cbase, gic.hbase, gic.vbase,
-              gic.maintenance.irq);
+              gic.maintenance_irq);
 
     if ( (gic.dbase & ~PAGE_MASK) || (gic.cbase & ~PAGE_MASK) ||
          (gic.hbase & ~PAGE_MASK) || (gic.vbase & ~PAGE_MASK) )
@@ -884,8 +885,8 @@ void gic_dump_info(struct vcpu *v)
 
 void __cpuinit init_maintenance_interrupt(void)
 {
-    request_dt_irq(&gic.maintenance, maintenance_interrupt,
-                   "irq-maintenance", NULL);
+    request_irq(gic.maintenance_irq, maintenance_interrupt,
+                "irq-maintenance", NULL);
 }
 
 /*
xen/arch/arm/irq.c +11 -12
index f1d6398..a09ca25 100644
@@ -117,9 +117,9 @@ static inline struct domain *irq_get_domain(struct irq_desc *desc)
     return desc->action->dev_id;
 }
 
-int request_dt_irq(const struct dt_irq *irq,
-                   void (*handler)(int, void *, struct cpu_user_regs *),
-                   const char *devname, void *dev_id)
+int request_irq(unsigned int irq,
+                void (*handler)(int, void *, struct cpu_user_regs *),
+                const char *devname, void *dev_id)
 {
     struct irqaction *action;
     int retval;
@@ -130,13 +130,13 @@ int request_dt_irq(const struct dt_irq *irq,
      * which interrupt is which (messes up the interrupt freeing
      * logic etc).
      */
-    if (irq->irq >= nr_irqs)
+    if ( irq >= nr_irqs )
         return -EINVAL;
-    if (!handler)
+    if ( !handler )
         return -EINVAL;
 
     action = xmalloc(struct irqaction);
-    if (!action)
+    if ( !action )
         return -ENOMEM;
 
     action->handler = handler;
@@ -144,8 +144,8 @@ int request_dt_irq(const struct dt_irq *irq,
     action->dev_id = dev_id;
     action->free_on_release = 1;
 
-    retval = setup_dt_irq(irq, action);
-    if (retval)
+    retval = setup_irq(irq, action);
+    if ( retval )
         xfree(action);
 
     return retval;
@@ -252,14 +252,14 @@ static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
     return 0;
 }
 
-int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
+int setup_irq(unsigned int irq, struct irqaction *new)
 {
     int rc;
     unsigned long flags;
     struct irq_desc *desc;
     bool_t disabled;
 
-    desc = irq_to_desc(irq->irq);
+    desc = irq_to_desc(irq);
 
     spin_lock_irqsave(&desc->lock, flags);
 
@@ -269,7 +269,7 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
 
         spin_unlock_irqrestore(&desc->lock, flags);
         printk(XENLOG_ERR "ERROR: IRQ %u is already in use by the domain %u\n",
-               irq->irq, d->domain_id);
+               irq, d->domain_id);
         return -EBUSY;
     }
 
@@ -289,7 +289,6 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
          * TODO: Handle case where SPI is setup on different CPU than
          * the targeted CPU and the priority.
          */
-        desc->arch.type = irq->type;
         gic_route_irq_to_xen(desc, cpumask_of(smp_processor_id()),
                              GIC_PRI_IRQ);
         desc->handler->startup(desc);
xen/arch/arm/time.c +16 -14
index ce96337..0bff747 100644
@@ -48,13 +48,13 @@ uint64_t __read_mostly boot_count;
  * register-mapped time source in the SoC. */
 unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz. */
 
-static struct dt_irq timer_irq[MAX_TIMER_PPI];
+static unsigned int timer_irq[MAX_TIMER_PPI];
 
 unsigned int timer_get_irq(enum timer_ppi ppi)
 {
     ASSERT(ppi >= TIMER_PHYS_SECURE_PPI && ppi < MAX_TIMER_PPI);
 
-    return timer_irq[ppi].irq;
+    return timer_irq[ppi];
 }
 
 /*static inline*/ s_time_t ticks_to_ns(uint64_t ticks)
@@ -120,15 +120,17 @@ int __init init_xen_time(void)
     /* Retrieve all IRQs for the timer */
     for ( i = TIMER_PHYS_SECURE_PPI; i < MAX_TIMER_PPI; i++ )
     {
-        res = dt_device_get_irq(dev, i, &timer_irq[i]);
-        if ( res )
+        res = platform_get_irq(dev, i);
+
+        if ( res < 0 )
             panic("Timer: Unable to retrieve IRQ %u from the device tree", i);
+        timer_irq[i] = res;
     }
 
     printk("Generic Timer IRQ: phys=%u hyp=%u virt=%u\n",
-           timer_irq[TIMER_PHYS_NONSECURE_PPI].irq,
-           timer_irq[TIMER_HYP_PPI].irq,
-           timer_irq[TIMER_VIRT_PPI].irq);
+           timer_irq[TIMER_PHYS_NONSECURE_PPI],
+           timer_irq[TIMER_HYP_PPI],
+           timer_irq[TIMER_VIRT_PPI]);
 
     res = platform_init_time();
     if ( res )
@@ -192,7 +194,7 @@ int reprogram_timer(s_time_t timeout)
 /* Handle the firing timer */
 static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
 {
-    if ( irq == (timer_irq[TIMER_HYP_PPI].irq) &&
+    if ( irq == (timer_irq[TIMER_HYP_PPI]) &&
          READ_SYSREG32(CNTHP_CTL_EL2) & CNTx_CTL_PENDING )
     {
         /* Signal the generic timer code to do its work */
@@ -201,7 +203,7 @@ static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
         WRITE_SYSREG32(0, CNTHP_CTL_EL2);
     }
 
-    if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI].irq) &&
+    if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI]) &&
          READ_SYSREG32(CNTP_CTL_EL0) & CNTx_CTL_PENDING )
     {
         /* Signal the generic timer code to do its work */
@@ -235,12 +237,12 @@ void __cpuinit init_timer_interrupt(void)
     WRITE_SYSREG32(0, CNTHP_CTL_EL2);   /* Hypervisor's timer disabled */
     isb();
 
-    request_dt_irq(&timer_irq[TIMER_HYP_PPI], timer_interrupt,
-                   "hyptimer", NULL);
-    request_dt_irq(&timer_irq[TIMER_VIRT_PPI], vtimer_interrupt,
+    request_irq(timer_irq[TIMER_HYP_PPI], timer_interrupt,
+                "hyptimer", NULL);
+    request_irq(timer_irq[TIMER_VIRT_PPI], vtimer_interrupt,
                    "virtimer", NULL);
-    request_dt_irq(&timer_irq[TIMER_PHYS_NONSECURE_PPI], timer_interrupt,
-                   "phytimer", NULL);
+    request_irq(timer_irq[TIMER_PHYS_NONSECURE_PPI], timer_interrupt,
+                "phytimer", NULL);
 }
 
 /* Wait a set number of microseconds */
xen/drivers/char/exynos4210-uart.c +8 -7
index 370539c..74ee578 100644
@@ -30,7 +30,7 @@
 
 static struct exynos4210_uart {
     unsigned int baud, clock_hz, data_bits, parity, stop_bits;
-    struct dt_irq irq;
+    unsigned int irq;
     void *regs;
     struct irqaction irqaction;
     struct vuart_info vuart;
@@ -197,9 +197,9 @@ static void __init exynos4210_uart_init_postirq(struct serial_port *port)
     uart->irqaction.name    = "exynos4210_uart";
     uart->irqaction.dev_id  = port;
 
-    if ( (rc = setup_dt_irq(&uart->irq, &uart->irqaction)) != 0 )
+    if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
         dprintk(XENLOG_ERR, "Failed to allocated exynos4210_uart IRQ %d\n",
-                uart->irq.irq);
+                uart->irq);
 
     /* Unmask interrupts */
     exynos4210_write(uart, UINTM, ~UINTM_ALLI);
@@ -272,7 +272,7 @@ static int __init exynos4210_uart_irq(struct serial_port *port)
 {
     struct exynos4210_uart *uart = port->uart;
 
-    return uart->irq.irq;
+    return uart->irq;
 }
 
 static const struct vuart_info *exynos4210_vuart_info(struct serial_port *port)
@@ -323,12 +323,13 @@ static int __init exynos4210_uart_init(struct dt_device_node *dev,
         return res;
     }
 
-    res = dt_device_get_irq(dev, 0, &uart->irq);
-    if ( res )
+    res = platform_get_irq(dev, 0);
+    if ( uart->irq < 0 )
     {
         printk("exynos4210: Unable to retrieve the IRQ\n");
-        return res;
+        return -EINVAL;
     }
+    uart->irq = res;
 
     uart->regs = ioremap_nocache(addr, size);
     if ( !uart->regs )
xen/drivers/char/ns16550.c +4 -14
index 21f086a..6691806 100644
@@ -76,9 +76,6 @@ static struct ns16550 {
     u8 bar_idx;
     bool_t enable_ro; /* Make MMIO devices read only to Dom0 */
 #endif
-#ifdef HAS_DEVICE_TREE
-    struct dt_irq dt_irq;
-#endif
 } ns16550_com[2] = { { 0 } };
 
 struct ns16550_config_mmio {
@@ -612,13 +609,8 @@ static void __init ns16550_init_postirq(struct serial_port *port)
         uart->irqaction.handler = ns16550_interrupt;
         uart->irqaction.name    = "ns16550";
         uart->irqaction.dev_id  = port;
-#ifdef HAS_DEVICE_TREE
-        if ( (rc = setup_dt_irq(&uart->dt_irq, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate ns16550 DT IRQ.\n");
-#else
         if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
             printk("ERROR: Failed to allocate ns16550 IRQ %d\n", uart->irq);
-#endif
     }
 
     ns16550_setup_postirq(uart);
@@ -1172,12 +1164,10 @@ static int __init ns16550_uart_dt_init(struct dt_device_node *dev,
     if ( uart->reg_width != 1 && uart->reg_width != 4 )
         return -EINVAL;
 
-    res = dt_device_get_irq(dev, 0, &uart->dt_irq);
-    if ( res )
-        return res;
-
-    /* The common bit of the driver mostly deals with irq not dt_irq. */
-    uart->irq = uart->dt_irq.irq;
+    res = platform_get_irq(dev, 0);
+    if ( ! res )
+        return -EINVAL;
+    uart->irq = res;
 
     uart->dw_usr_bsy = dt_device_is_compatible(dev, "snps,dw-apb-uart");
 
xen/drivers/char/omap-uart.c +8 -7
index b8da509..e598785 100644
@@ -30,7 +30,7 @@
 
 static struct omap_uart {
     u32 baud, clock_hz, data_bits, parity, stop_bits, fifo_size;
-    struct dt_irq irq;
+    unsigned int irq;
     char __iomem *regs;
     struct irqaction irqaction;
     struct vuart_info vuart;
@@ -205,10 +205,10 @@ static void __init omap_uart_init_postirq(struct serial_port *port)
     uart->irqaction.name = "omap_uart";
     uart->irqaction.dev_id = port;
 
-    if ( setup_dt_irq(&uart->irq, &uart->irqaction) != 0 )
+    if ( setup_irq(uart->irq, &uart->irqaction) != 0 )
     {
         dprintk(XENLOG_ERR, "Failed to allocated omap_uart IRQ %d\n",
-                uart->irq.irq);
+                uart->irq);
         return;
     }
 
@@ -259,7 +259,7 @@ static int __init omap_uart_irq(struct serial_port *port)
 {
     struct omap_uart *uart = port->uart;
 
-    return ((uart->irq.irq > 0) ? uart->irq.irq : -1);
+    return ((uart->irq > 0) ? uart->irq : -1);
 }
 
 static const struct vuart_info *omap_vuart_info(struct serial_port *port)
@@ -317,12 +317,13 @@ static int __init omap_uart_init(struct dt_device_node *dev,
         return res;
     }
 
-    res = dt_device_get_irq(dev, 0, &uart->irq);
-    if ( res )
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
     {
         printk("omap-uart: Unable to retrieve the IRQ\n");
-        return res;
+        return -EINVAL;
     }
+    uart->irq = res;
 
     uart->regs = ioremap_nocache(addr, size);
     if ( !uart->regs )
xen/drivers/char/pl011.c +10 -8
index 459e686..89bda94 100644
@@ -32,7 +32,7 @@
 
 static struct pl011 {
     unsigned int baud, clock_hz, data_bits, parity, stop_bits;
-    struct dt_irq irq;
+    unsigned int irq;
     void __iomem *regs;
     /* UART with IRQ line: interrupt-driven I/O. */
     struct irqaction irqaction;
@@ -132,13 +132,13 @@ static void __init pl011_init_postirq(struct serial_port *port)
     struct pl011 *uart = port->uart;
     int rc;
 
-    if ( uart->irq.irq > 0 )
+    if ( uart->irq > 0 )
     {
         uart->irqaction.handler = pl011_interrupt;
         uart->irqaction.name    = "pl011";
         uart->irqaction.dev_id  = port;
-        if ( (rc = setup_dt_irq(&uart->irq, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq.irq);
+        if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
+            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
     }
 
     /* Clear pending error interrupts */
@@ -186,7 +186,8 @@ static int pl011_getc(struct serial_port *port, char *pc)
 static int __init pl011_irq(struct serial_port *port)
 {
     struct pl011 *uart = port->uart;
-    return ((uart->irq.irq > 0) ? uart->irq.irq : -1);
+
+    return ((uart->irq > 0) ? uart->irq : -1);
 }
 
 static const struct vuart_info *pl011_vuart(struct serial_port *port)
@@ -239,12 +240,13 @@ static int __init pl011_uart_init(struct dt_device_node *dev,
         return res;
     }
 
-    res = dt_device_get_irq(dev, 0, &uart->irq);
-    if ( res )
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
     {
         printk("pl011: Unable to retrieve the IRQ\n");
-        return res;
+        return -EINVAL;
     }
+    uart->irq = res;
 
     uart->regs = ioremap_nocache(addr, size);
     if ( !uart->regs )
xen/include/asm-arm/irq.h +0 -5
index 93d2128..f9b9a9f 100644
@@ -40,11 +40,6 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);
 void init_IRQ(void);
 void init_secondary_IRQ(void);
 
-int request_dt_irq(const struct dt_irq *irq,
-                   void (*handler)(int, void *, struct cpu_user_regs *),
-                   const char *devname, void *dev_id);
-int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new);
-
 int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq,
                           const char *devname);
 int platform_get_irq(const struct dt_device_node *device,
Signature · 1 line
1.7.10.4
author Acked-by Ian Campbell on v4 15/18
#21 lore raw

Re: [PATCH v4 15/18] xen/arm: IRQ: Replace {request, setup}_dt_irq by {request, setup}_irq

Quoted 8 lines · Julien Grall
xen/drivers/char/exynos4210-uart.c +0 -0
index 370539c..74ee578 100644
@@ -30,7 +30,7 @@
 
 static const struct vuart_info *exynos4210_vuart_info(struct serial_port *port)

xen/drivers/char/exynos4210-uart.c static int __init exynos4210_uart_init(struct dt_device_node *dev, · line 327

Quoted 7 lines
xen/drivers/char/exynos4210-uart.c +2 -2
@@ -323,12 +323,13 @@ static int __init exynos4210_uart_init(struct dt_device_node *dev,
         return res;
     }
 
-    res = dt_device_get_irq(dev, 0, &uart->irq);
-    if ( res )
+    res = platform_get_irq(dev, 0);
+    if ( uart->irq < 0 )

Argh, I test the wrong variable here. This should be

if ( res < 0 )

I've copied the slightly modify patch below.

commit 7a98180798deed5e453128bc3556cadef025d894

Author: Julien Grall <[email protected]>
Date:   Thu Mar 27 17:54:27 2014 +0000

xen/arm: IRQ: Replace {request,setup}_dt_irq by {request,setup}_irq

Now that irq_desc stores the type of the IRQ (e.g level/edge,...), we don't need to use specific IRQ function for ARM.

Also replace every call to dt_device_get_irq by platform_get_irq which is a wrapper to this function and setup the IRQ type correctly.

---
Changes in v5:
- exynos4210 was testing the wrong IRQ variable

Changes in v4:
- platform_get_irq now returns -1 in case of error.

Changes in v3:
- Fix typoes in commit message

Changes in v2:
- Patch added

xen/arch/arm/gic.c +7 -6
index 4a6ed35..cb40b0a 100644
@@ -47,7 +47,7 @@ static struct {
     paddr_t hbase;       /* Address of virtual interface registers */
     paddr_t vbase;       /* Address of virtual cpu interface registers */
     unsigned int lines;  /* Number of interrupts (SPIs + PPIs + SGIs) */
-    struct dt_irq maintenance; /* IRQ maintenance */
+    unsigned int maintenance_irq; /* IRQ maintenance */
     unsigned int cpus;
     spinlock_t lock;
 } gic;
@@ -431,9 +431,10 @@ void __init gic_init(void)
     if ( res || !gic.vbase || (gic.vbase & ~PAGE_MASK) )
         panic("GIC: Cannot find a valid address for the virtual CPU");
 
-    res = dt_device_get_irq(node, 0, &gic.maintenance);
-    if ( res )
+    res = platform_get_irq(node, 0);
+    if ( res < 0 )
         panic("GIC: Cannot find the maintenance IRQ");
+    gic.maintenance_irq = res;
 
     /* Set the GIC as the primary interrupt controller */
     dt_interrupt_controller = node;
@@ -447,7 +448,7 @@ void __init gic_init(void)
               "        gic_vcpu_addr=%"PRIpaddr"\n"
               "        gic_maintenance_irq=%u\n",
               gic.dbase, gic.cbase, gic.hbase, gic.vbase,
-              gic.maintenance.irq);
+              gic.maintenance_irq);
 
     if ( (gic.dbase & ~PAGE_MASK) || (gic.cbase & ~PAGE_MASK) ||
          (gic.hbase & ~PAGE_MASK) || (gic.vbase & ~PAGE_MASK) )
@@ -884,8 +885,8 @@ void gic_dump_info(struct vcpu *v)
 
 void __cpuinit init_maintenance_interrupt(void)
 {
-    request_dt_irq(&gic.maintenance, maintenance_interrupt,
-                   "irq-maintenance", NULL);
+    request_irq(gic.maintenance_irq, maintenance_interrupt,
+                "irq-maintenance", NULL);
 }
 
 /*
xen/arch/arm/irq.c +11 -12
index f1d6398..a09ca25 100644
@@ -117,9 +117,9 @@ static inline struct domain *irq_get_domain(struct irq_desc *desc)
     return desc->action->dev_id;
 }
 
-int request_dt_irq(const struct dt_irq *irq,
-                   void (*handler)(int, void *, struct cpu_user_regs *),
-                   const char *devname, void *dev_id)
+int request_irq(unsigned int irq,
+                void (*handler)(int, void *, struct cpu_user_regs *),
+                const char *devname, void *dev_id)
 {
     struct irqaction *action;
     int retval;
@@ -130,13 +130,13 @@ int request_dt_irq(const struct dt_irq *irq,
      * which interrupt is which (messes up the interrupt freeing
      * logic etc).
      */
-    if (irq->irq >= nr_irqs)
+    if ( irq >= nr_irqs )
         return -EINVAL;
-    if (!handler)
+    if ( !handler )
         return -EINVAL;
 
     action = xmalloc(struct irqaction);
-    if (!action)
+    if ( !action )
         return -ENOMEM;
 
     action->handler = handler;
@@ -144,8 +144,8 @@ int request_dt_irq(const struct dt_irq *irq,
     action->dev_id = dev_id;
     action->free_on_release = 1;
 
-    retval = setup_dt_irq(irq, action);
-    if (retval)
+    retval = setup_irq(irq, action);
+    if ( retval )
         xfree(action);
 
     return retval;
@@ -252,14 +252,14 @@ static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
     return 0;
 }
 
-int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
+int setup_irq(unsigned int irq, struct irqaction *new)
 {
     int rc;
     unsigned long flags;
     struct irq_desc *desc;
     bool_t disabled;
 
-    desc = irq_to_desc(irq->irq);
+    desc = irq_to_desc(irq);
 
     spin_lock_irqsave(&desc->lock, flags);
 
@@ -269,7 +269,7 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
 
         spin_unlock_irqrestore(&desc->lock, flags);
         printk(XENLOG_ERR "ERROR: IRQ %u is already in use by the domain %u\n",
-               irq->irq, d->domain_id);
+               irq, d->domain_id);
         return -EBUSY;
     }
 
@@ -289,7 +289,6 @@ int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new)
          * TODO: Handle case where SPI is setup on different CPU than
          * the targeted CPU and the priority.
          */
-        desc->arch.type = irq->type;
         gic_route_irq_to_xen(desc, cpumask_of(smp_processor_id()),
                              GIC_PRI_IRQ);
         desc->handler->startup(desc);
xen/arch/arm/time.c +16 -14
index ce96337..0bff747 100644
@@ -48,13 +48,13 @@ uint64_t __read_mostly boot_count;
  * register-mapped time source in the SoC. */
 unsigned long __read_mostly cpu_khz;  /* CPU clock frequency in kHz. */
 
-static struct dt_irq timer_irq[MAX_TIMER_PPI];
+static unsigned int timer_irq[MAX_TIMER_PPI];
 
 unsigned int timer_get_irq(enum timer_ppi ppi)
 {
     ASSERT(ppi >= TIMER_PHYS_SECURE_PPI && ppi < MAX_TIMER_PPI);
 
-    return timer_irq[ppi].irq;
+    return timer_irq[ppi];
 }
 
 /*static inline*/ s_time_t ticks_to_ns(uint64_t ticks)
@@ -120,15 +120,17 @@ int __init init_xen_time(void)
     /* Retrieve all IRQs for the timer */
     for ( i = TIMER_PHYS_SECURE_PPI; i < MAX_TIMER_PPI; i++ )
     {
-        res = dt_device_get_irq(dev, i, &timer_irq[i]);
-        if ( res )
+        res = platform_get_irq(dev, i);
+
+        if ( res < 0 )
             panic("Timer: Unable to retrieve IRQ %u from the device tree", i);
+        timer_irq[i] = res;
     }
 
     printk("Generic Timer IRQ: phys=%u hyp=%u virt=%u\n",
-           timer_irq[TIMER_PHYS_NONSECURE_PPI].irq,
-           timer_irq[TIMER_HYP_PPI].irq,
-           timer_irq[TIMER_VIRT_PPI].irq);
+           timer_irq[TIMER_PHYS_NONSECURE_PPI],
+           timer_irq[TIMER_HYP_PPI],
+           timer_irq[TIMER_VIRT_PPI]);
 
     res = platform_init_time();
     if ( res )
@@ -192,7 +194,7 @@ int reprogram_timer(s_time_t timeout)
 /* Handle the firing timer */
 static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
 {
-    if ( irq == (timer_irq[TIMER_HYP_PPI].irq) &&
+    if ( irq == (timer_irq[TIMER_HYP_PPI]) &&
          READ_SYSREG32(CNTHP_CTL_EL2) & CNTx_CTL_PENDING )
     {
         /* Signal the generic timer code to do its work */
@@ -201,7 +203,7 @@ static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
         WRITE_SYSREG32(0, CNTHP_CTL_EL2);
     }
 
-    if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI].irq) &&
+    if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI]) &&
          READ_SYSREG32(CNTP_CTL_EL0) & CNTx_CTL_PENDING )
     {
         /* Signal the generic timer code to do its work */
@@ -235,12 +237,12 @@ void __cpuinit init_timer_interrupt(void)
     WRITE_SYSREG32(0, CNTHP_CTL_EL2);   /* Hypervisor's timer disabled */
     isb();
 
-    request_dt_irq(&timer_irq[TIMER_HYP_PPI], timer_interrupt,
-                   "hyptimer", NULL);
-    request_dt_irq(&timer_irq[TIMER_VIRT_PPI], vtimer_interrupt,
+    request_irq(timer_irq[TIMER_HYP_PPI], timer_interrupt,
+                "hyptimer", NULL);
+    request_irq(timer_irq[TIMER_VIRT_PPI], vtimer_interrupt,
                    "virtimer", NULL);
-    request_dt_irq(&timer_irq[TIMER_PHYS_NONSECURE_PPI], timer_interrupt,
-                   "phytimer", NULL);
+    request_irq(timer_irq[TIMER_PHYS_NONSECURE_PPI], timer_interrupt,
+                "phytimer", NULL);
 }
 
 /* Wait a set number of microseconds */
xen/drivers/char/exynos4210-uart.c +8 -7
index 370539c..404ce05 100644
@@ -30,7 +30,7 @@
 
 static struct exynos4210_uart {
     unsigned int baud, clock_hz, data_bits, parity, stop_bits;
-    struct dt_irq irq;
+    unsigned int irq;
     void *regs;
     struct irqaction irqaction;
     struct vuart_info vuart;
@@ -197,9 +197,9 @@ static void __init exynos4210_uart_init_postirq(struct serial_port *port)
     uart->irqaction.name    = "exynos4210_uart";
     uart->irqaction.dev_id  = port;
 
-    if ( (rc = setup_dt_irq(&uart->irq, &uart->irqaction)) != 0 )
+    if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
         dprintk(XENLOG_ERR, "Failed to allocated exynos4210_uart IRQ %d\n",
-                uart->irq.irq);
+                uart->irq);
 
     /* Unmask interrupts */
     exynos4210_write(uart, UINTM, ~UINTM_ALLI);
@@ -272,7 +272,7 @@ static int __init exynos4210_uart_irq(struct serial_port *port)
 {
     struct exynos4210_uart *uart = port->uart;
 
-    return uart->irq.irq;
+    return uart->irq;
 }
 
 static const struct vuart_info *exynos4210_vuart_info(struct serial_port *port)
@@ -323,12 +323,13 @@ static int __init exynos4210_uart_init(struct dt_device_node *dev,
         return res;
     }
 
-    res = dt_device_get_irq(dev, 0, &uart->irq);
-    if ( res )
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
     {
         printk("exynos4210: Unable to retrieve the IRQ\n");
-        return res;
+        return -EINVAL;
     }
+    uart->irq = res;
 
     uart->regs = ioremap_nocache(addr, size);
     if ( !uart->regs )
xen/drivers/char/ns16550.c +4 -14
index 21f086a..6691806 100644
@@ -76,9 +76,6 @@ static struct ns16550 {
     u8 bar_idx;
     bool_t enable_ro; /* Make MMIO devices read only to Dom0 */
 #endif
-#ifdef HAS_DEVICE_TREE
-    struct dt_irq dt_irq;
-#endif
 } ns16550_com[2] = { { 0 } };
 
 struct ns16550_config_mmio {
@@ -612,13 +609,8 @@ static void __init ns16550_init_postirq(struct serial_port *port)
         uart->irqaction.handler = ns16550_interrupt;
         uart->irqaction.name    = "ns16550";
         uart->irqaction.dev_id  = port;
-#ifdef HAS_DEVICE_TREE
-        if ( (rc = setup_dt_irq(&uart->dt_irq, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate ns16550 DT IRQ.\n");
-#else
         if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
             printk("ERROR: Failed to allocate ns16550 IRQ %d\n", uart->irq);
-#endif
     }
 
     ns16550_setup_postirq(uart);
@@ -1172,12 +1164,10 @@ static int __init ns16550_uart_dt_init(struct dt_device_node *dev,
     if ( uart->reg_width != 1 && uart->reg_width != 4 )
         return -EINVAL;
 
-    res = dt_device_get_irq(dev, 0, &uart->dt_irq);
-    if ( res )
-        return res;
-
-    /* The common bit of the driver mostly deals with irq not dt_irq. */
-    uart->irq = uart->dt_irq.irq;
+    res = platform_get_irq(dev, 0);
+    if ( ! res )
+        return -EINVAL;
+    uart->irq = res;
 
     uart->dw_usr_bsy = dt_device_is_compatible(dev, "snps,dw-apb-uart");
 
xen/drivers/char/omap-uart.c +8 -7
index b8da509..e598785 100644
@@ -30,7 +30,7 @@
 
 static struct omap_uart {
     u32 baud, clock_hz, data_bits, parity, stop_bits, fifo_size;
-    struct dt_irq irq;
+    unsigned int irq;
     char __iomem *regs;
     struct irqaction irqaction;
     struct vuart_info vuart;
@@ -205,10 +205,10 @@ static void __init omap_uart_init_postirq(struct serial_port *port)
     uart->irqaction.name = "omap_uart";
     uart->irqaction.dev_id = port;
 
-    if ( setup_dt_irq(&uart->irq, &uart->irqaction) != 0 )
+    if ( setup_irq(uart->irq, &uart->irqaction) != 0 )
     {
         dprintk(XENLOG_ERR, "Failed to allocated omap_uart IRQ %d\n",
-                uart->irq.irq);
+                uart->irq);
         return;
     }
 
@@ -259,7 +259,7 @@ static int __init omap_uart_irq(struct serial_port *port)
 {
     struct omap_uart *uart = port->uart;
 
-    return ((uart->irq.irq > 0) ? uart->irq.irq : -1);
+    return ((uart->irq > 0) ? uart->irq : -1);
 }
 
 static const struct vuart_info *omap_vuart_info(struct serial_port *port)
@@ -317,12 +317,13 @@ static int __init omap_uart_init(struct dt_device_node *dev,
         return res;
     }
 
-    res = dt_device_get_irq(dev, 0, &uart->irq);
-    if ( res )
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
     {
         printk("omap-uart: Unable to retrieve the IRQ\n");
-        return res;
+        return -EINVAL;
     }
+    uart->irq = res;
 
     uart->regs = ioremap_nocache(addr, size);
     if ( !uart->regs )
xen/drivers/char/pl011.c +10 -8
index 459e686..89bda94 100644
@@ -32,7 +32,7 @@
 
 static struct pl011 {
     unsigned int baud, clock_hz, data_bits, parity, stop_bits;
-    struct dt_irq irq;
+    unsigned int irq;
     void __iomem *regs;
     /* UART with IRQ line: interrupt-driven I/O. */
     struct irqaction irqaction;
@@ -132,13 +132,13 @@ static void __init pl011_init_postirq(struct serial_port *port)
     struct pl011 *uart = port->uart;
     int rc;
 
-    if ( uart->irq.irq > 0 )
+    if ( uart->irq > 0 )
     {
         uart->irqaction.handler = pl011_interrupt;
         uart->irqaction.name    = "pl011";
         uart->irqaction.dev_id  = port;
-        if ( (rc = setup_dt_irq(&uart->irq, &uart->irqaction)) != 0 )
-            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq.irq);
+        if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
+            printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
     }
 
     /* Clear pending error interrupts */
@@ -186,7 +186,8 @@ static int pl011_getc(struct serial_port *port, char *pc)
 static int __init pl011_irq(struct serial_port *port)
 {
     struct pl011 *uart = port->uart;
-    return ((uart->irq.irq > 0) ? uart->irq.irq : -1);
+
+    return ((uart->irq > 0) ? uart->irq : -1);
 }
 
 static const struct vuart_info *pl011_vuart(struct serial_port *port)
@@ -239,12 +240,13 @@ static int __init pl011_uart_init(struct dt_device_node *dev,
         return res;
     }
 
-    res = dt_device_get_irq(dev, 0, &uart->irq);
-    if ( res )
+    res = platform_get_irq(dev, 0);
+    if ( res < 0 )
     {
         printk("pl011: Unable to retrieve the IRQ\n");
-        return res;
+        return -EINVAL;
     }
+    uart->irq = res;
 
     uart->regs = ioremap_nocache(addr, size);
     if ( !uart->regs )
xen/include/asm-arm/irq.h +0 -5
index 93d2128..f9b9a9f 100644
@@ -40,11 +40,6 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq);
 void init_IRQ(void);
 void init_secondary_IRQ(void);
 
-int request_dt_irq(const struct dt_irq *irq,
-                   void (*handler)(int, void *, struct cpu_user_regs *),
-                   const char *devname, void *dev_id);
-int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new);
-
 int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq,
                           const char *devname);
 int platform_get_irq(const struct dt_device_node *device,
Signature · 1 line
Julien Grall
#22 lore raw

PATCH v4 16/18 xen: IRQ: Add dev_id parameter to release_irq

In reply to Julien Grall

The new parameter (dev_id) will be used in on ARM to release the right action when support for multiple action is added.

Even if this function is declared in common code, no one is using it. So it's safe to modify the prototype also for x86.

---
Changes in v3:
- Fix typoes in commit message
- Don't remove __init on release_irq for x86

Changes in v2:
- Patch added

---
 xen/arch/arm/irq.c    |    2 +-
 xen/arch/x86/irq.c    |    2 +-
 xen/include/xen/irq.h |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
xen/arch/arm/irq.c +1 -1
index a09ca25..45fbadb 100644
@@ -216,7 +216,7 @@ out_no_end:
     irq_exit();
 }
 
-void release_irq(unsigned int irq)
+void release_irq(unsigned int irq, const void *dev_id)
 {
     struct irq_desc *desc;
     unsigned long flags;
xen/arch/x86/irq.c +1 -1
index 5b5b169..727472d 100644
@@ -983,7 +983,7 @@ int __init request_irq(unsigned int irq,
     return retval;
 }
 
-void __init release_irq(unsigned int irq)
+void __init release_irq(unsigned int irq, const void *dev_id)
 {
     struct irq_desc *desc;
     unsigned long flags;
xen/include/xen/irq.h +1 -1
index f2e6215..1f8bdb3 100644
@@ -90,7 +90,7 @@ int arch_init_one_irq_desc(struct irq_desc *);
 #define irq_desc_initialized(desc) ((desc)->handler != NULL)
 
 extern int setup_irq(unsigned int irq, struct irqaction *);
-extern void release_irq(unsigned int irq);
+extern void release_irq(unsigned int irq, const void *dev_id);
 extern int request_irq(unsigned int irq,
                void (*handler)(int, void *, struct cpu_user_regs *),
                const char * devname, void *dev_id);
Signature · 1 line
1.7.10.4
#23 lore raw

PATCH v4 17/18 xen/arm: IRQ: extend {request, setup}_irq to take an irqflags in parameter

In reply to Julien Grall

The irqflags will be used later on ARM to know if we can shared the IRQ or not.

On x86, the irqflags should always be 0.

---
Changes in v4:
- request_irq should pass irqflags to setup irq on x86

Changes in v3:
- Patch added

---
 xen/arch/arm/gic.c                       |    2 +-
 xen/arch/arm/irq.c                       |    6 +++---
 xen/arch/arm/time.c                      |    6 +++---
 xen/arch/x86/hpet.c                      |    2 +-
 xen/arch/x86/i8259.c                     |    2 +-
 xen/arch/x86/irq.c                       |    9 ++++++---
 xen/arch/x86/time.c                      |    2 +-
 xen/drivers/char/exynos4210-uart.c       |    2 +-
 xen/drivers/char/ns16550.c               |    2 +-
 xen/drivers/char/omap-uart.c             |    2 +-
 xen/drivers/char/pl011.c                 |    2 +-
 xen/drivers/passthrough/amd/iommu_init.c |    2 +-
 xen/drivers/passthrough/vtd/iommu.c      |    2 +-
 xen/include/xen/irq.h                    |    5 +++--
 14 files changed, 25 insertions(+), 21 deletions(-)
xen/arch/arm/gic.c +1 -1
index cb40b0a..39f9621 100644
@@ -885,7 +885,7 @@ void gic_dump_info(struct vcpu *v)
 
 void __cpuinit init_maintenance_interrupt(void)
 {
-    request_irq(gic.maintenance_irq, maintenance_interrupt,
+    request_irq(gic.maintenance_irq, 0, maintenance_interrupt,
                 "irq-maintenance", NULL);
 }
 
xen/arch/arm/irq.c +3 -3
index 45fbadb..1bc960d 100644
@@ -117,7 +117,7 @@ static inline struct domain *irq_get_domain(struct irq_desc *desc)
     return desc->action->dev_id;
 }
 
-int request_irq(unsigned int irq,
+int request_irq(unsigned int irq, unsigned int irqflags,
                 void (*handler)(int, void *, struct cpu_user_regs *),
                 const char *devname, void *dev_id)
 {
@@ -144,7 +144,7 @@ int request_irq(unsigned int irq,
     action->dev_id = dev_id;
     action->free_on_release = 1;
 
-    retval = setup_irq(irq, action);
+    retval = setup_irq(irq, irqflags, action);
     if ( retval )
         xfree(action);
 
@@ -252,7 +252,7 @@ static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
     return 0;
 }
 
-int setup_irq(unsigned int irq, struct irqaction *new)
+int setup_irq(unsigned int irq, unsigned int irqflags, struct irqaction *new)
 {
     int rc;
     unsigned long flags;
xen/arch/arm/time.c +3 -3
index 0bff747..81452b5 100644
@@ -237,11 +237,11 @@ void __cpuinit init_timer_interrupt(void)
     WRITE_SYSREG32(0, CNTHP_CTL_EL2);   /* Hypervisor's timer disabled */
     isb();
 
-    request_irq(timer_irq[TIMER_HYP_PPI], timer_interrupt,
+    request_irq(timer_irq[TIMER_HYP_PPI], 0, timer_interrupt,
                 "hyptimer", NULL);
-    request_irq(timer_irq[TIMER_VIRT_PPI], vtimer_interrupt,
+    request_irq(timer_irq[TIMER_VIRT_PPI], 0, vtimer_interrupt,
                    "virtimer", NULL);
-    request_irq(timer_irq[TIMER_PHYS_NONSECURE_PPI], timer_interrupt,
+    request_irq(timer_irq[TIMER_PHYS_NONSECURE_PPI], 0, timer_interrupt,
                 "phytimer", NULL);
 }
 
xen/arch/x86/hpet.c +1 -1
index 3a4f7e8..0b13f52 100644
@@ -355,7 +355,7 @@ static int __init hpet_setup_msi_irq(struct hpet_event_channel *ch)
     hpet_write32(cfg, HPET_Tn_CFG(ch->idx));
 
     desc->handler = &hpet_msi_type;
-    ret = request_irq(ch->msi.irq, hpet_interrupt_handler, "HPET", ch);
+    ret = request_irq(ch->msi.irq, 0, hpet_interrupt_handler, "HPET", ch);
     if ( ret >= 0 )
         ret = __hpet_setup_msi_irq(desc);
     if ( ret < 0 )
xen/arch/x86/i8259.c +1 -1
index 6fdcce8..a0270c9 100644
@@ -435,6 +435,6 @@ void __init init_IRQ(void)
     outb_p(LATCH & 0xff, PIT_CH0); /* LSB */
     outb(LATCH >> 8, PIT_CH0);     /* MSB */
 
-    setup_irq(2, &cascade);
+    setup_irq(2, 0, &cascade);
 }
 
xen/arch/x86/irq.c +6 -3
index 727472d..dafd338 100644
@@ -949,7 +949,7 @@ static int __init irq_ratelimit_init(void)
 }
 __initcall(irq_ratelimit_init);
 
-int __init request_irq(unsigned int irq,
+int __init request_irq(unsigned int irq, unsigned int irqflags,
         void (*handler)(int, void *, struct cpu_user_regs *),
         const char * devname, void *dev_id)
 {
@@ -976,7 +976,7 @@ int __init request_irq(unsigned int irq,
     action->dev_id = dev_id;
     action->free_on_release = 1;
 
-    retval = setup_irq(irq, action);
+    retval = setup_irq(irq, irqflags, action);
     if (retval)
         xfree(action);
 
@@ -1005,11 +1005,14 @@ void __init release_irq(unsigned int irq, const void *dev_id)
         xfree(action);
 }
 
-int __init setup_irq(unsigned int irq, struct irqaction *new)
+int __init setup_irq(unsigned int irq, unsigned int irqflags,
+                     struct irqaction *new)
 {
     struct irq_desc *desc;
     unsigned long flags;
 
+    ASSERT(irqflags == 0);
+
     desc = irq_to_desc(irq);
  
     spin_lock_irqsave(&desc->lock,flags);
xen/arch/x86/time.c +1 -1
index 93bb5b6..c339f92 100644
@@ -1473,7 +1473,7 @@ void __init early_time_init(void)
     printk("Detected %lu.%03lu MHz processor.\n", 
            cpu_khz / 1000, cpu_khz % 1000);
 
-    setup_irq(0, &irq0);
+    setup_irq(0, 0, &irq0);
 }
 
 /* keep pit enabled for pit_broadcast working while cpuidle enabled */
xen/drivers/char/exynos4210-uart.c +1 -1
index 74ee578..76c0d7e 100644
@@ -197,7 +197,7 @@ static void __init exynos4210_uart_init_postirq(struct serial_port *port)
     uart->irqaction.name    = "exynos4210_uart";
     uart->irqaction.dev_id  = port;
 
-    if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
+    if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
         dprintk(XENLOG_ERR, "Failed to allocated exynos4210_uart IRQ %d\n",
                 uart->irq);
 
xen/drivers/char/ns16550.c +1 -1
index 6691806..161b251 100644
@@ -609,7 +609,7 @@ static void __init ns16550_init_postirq(struct serial_port *port)
         uart->irqaction.handler = ns16550_interrupt;
         uart->irqaction.name    = "ns16550";
         uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
+        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
             printk("ERROR: Failed to allocate ns16550 IRQ %d\n", uart->irq);
     }
 
xen/drivers/char/omap-uart.c +1 -1
index e598785..a798b8d 100644
@@ -205,7 +205,7 @@ static void __init omap_uart_init_postirq(struct serial_port *port)
     uart->irqaction.name = "omap_uart";
     uart->irqaction.dev_id = port;
 
-    if ( setup_irq(uart->irq, &uart->irqaction) != 0 )
+    if ( setup_irq(uart->irq, 0, &uart->irqaction) != 0 )
     {
         dprintk(XENLOG_ERR, "Failed to allocated omap_uart IRQ %d\n",
                 uart->irq);
xen/drivers/char/pl011.c +1 -1
index 89bda94..dd19ce8 100644
@@ -137,7 +137,7 @@ static void __init pl011_init_postirq(struct serial_port *port)
         uart->irqaction.handler = pl011_interrupt;
         uart->irqaction.name    = "pl011";
         uart->irqaction.dev_id  = port;
-        if ( (rc = setup_irq(uart->irq, &uart->irqaction)) != 0 )
+        if ( (rc = setup_irq(uart->irq, 0, &uart->irqaction)) != 0 )
             printk("ERROR: Failed to allocate pl011 IRQ %d\n", uart->irq);
     }
 
xen/drivers/passthrough/amd/iommu_init.c +1 -1
index 4686813..6ae44d9 100644
@@ -815,7 +815,7 @@ static bool_t __init set_iommu_interrupt_handler(struct amd_iommu *iommu)
         handler = &iommu_msi_type;
     ret = __setup_msi_irq(irq_to_desc(irq), &iommu->msi, handler);
     if ( !ret )
-        ret = request_irq(irq, iommu_interrupt_handler, "amd_iommu", iommu);
+        ret = request_irq(irq, 0, iommu_interrupt_handler, "amd_iommu", iommu);
     if ( ret )
     {
         destroy_irq(irq);
xen/drivers/passthrough/vtd/iommu.c +1 -1
index abaa8c9..c94b0d1 100644
@@ -1082,7 +1082,7 @@ static int __init iommu_set_interrupt(struct acpi_drhd_unit *drhd)
 
     desc = irq_to_desc(irq);
     desc->handler = &dma_msi_type;
-    ret = request_irq(irq, iommu_page_fault, "dmar", iommu);
+    ret = request_irq(irq, 0, iommu_page_fault, "dmar", iommu);
     if ( ret )
     {
         desc->handler = &no_irq_type;
xen/include/xen/irq.h +3 -2
index 1f8bdb3..f9a18d8 100644
@@ -89,9 +89,10 @@ int arch_init_one_irq_desc(struct irq_desc *);
 
 #define irq_desc_initialized(desc) ((desc)->handler != NULL)
 
-extern int setup_irq(unsigned int irq, struct irqaction *);
+extern int setup_irq(unsigned int irq, unsigned int irqflags,
+                     struct irqaction *);
 extern void release_irq(unsigned int irq, const void *dev_id);
-extern int request_irq(unsigned int irq,
+extern int request_irq(unsigned int irq, unsigned int irqflags,
                void (*handler)(int, void *, struct cpu_user_regs *),
                const char * devname, void *dev_id);
 
Signature · 1 line
1.7.10.4
#24 lore raw

PATCH v4 18/18 xen/arm: IRQ: Handle multiple action per IRQ

In reply to Julien Grall

On ARM, it may happen (eg ARM SMMU) to setup multiple handler for the same interrupt.

To be able to use multiple action, the driver has to explicitly call {setup,request}_irq with IRQF_SHARED as 2nd parameter.

The behavior stays the same on x86, e.g only one action is handled.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>

---
Changes in v4:
- Go back to a single custom linked list. The double linked-list doesn't fit the requirements (i.e browsing safely without look) and the llist.h from Linux doesn't allow use to delete a node in the middle of the list.

Changes in v3:
- Drop {setup,request}_irq_flags, the current function has been extended on an earlier patch.
- Rename IRQ_SHARED into IRQF_SHARED

Changes in v2:
- Explain design choice
- Introduce CONFIG_IRQ_HAS_MULTIPLE_ACTION
- Use list instead of custom pointer
- release_irq should not shutdown the IRQ at the beginning
- Add IRQ_SHARED flags
- Introduce request_irq_flags and setup_irq_flags
- Fix compilation on x86. Some code are creating the irqaction via = { ... } so the "next" field should be moved toward the end

---
 xen/arch/arm/irq.c           |   79 +++++++++++++++++++++++++++++++++---------
 xen/include/asm-arm/config.h |    2 ++
 xen/include/xen/irq.h        |    4 +++
 3 files changed, 68 insertions(+), 17 deletions(-)
xen/arch/arm/irq.c +62 -17
index 1bc960d..d05c0be 100644
@@ -155,7 +155,6 @@ int request_irq(unsigned int irq, unsigned int irqflags,
 void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 {
     struct irq_desc *desc = irq_to_desc(irq);
-    struct irqaction *action = desc->action;
 
     /* TODO: perfc_incr(irqs); */
 
@@ -166,7 +165,7 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
     spin_lock(&desc->lock);
     desc->handler->ack(desc);
 
-    if ( action == NULL )
+    if ( !desc->action )
     {
         printk("Unknown %s %#3.3x\n",
                is_fiq ? "FIQ" : "IRQ", irq);
@@ -198,12 +197,21 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 
     desc->status |= IRQ_INPROGRESS;
 
-    action = desc->action;
     while ( desc->status & IRQ_PENDING )
     {
+        struct irqaction *action;
+
         desc->status &= ~IRQ_PENDING;
+        action = desc->action;
+
         spin_unlock_irq(&desc->lock);
-        action->handler(irq, action->dev_id, regs);
+
+        do
+        {
+            action->handler(irq, action->dev_id, regs);
+            action = action->next;
+        } while ( action );
+
         spin_lock_irq(&desc->lock);
     }
 
@@ -220,34 +228,71 @@ void release_irq(unsigned int irq, const void *dev_id)
 {
     struct irq_desc *desc;
     unsigned long flags;
-   struct irqaction *action;
+    struct irqaction *action, **action_ptr;
 
     desc = irq_to_desc(irq);
 
     spin_lock_irqsave(&desc->lock,flags);
 
-    desc->handler->shutdown(desc);
+    action_ptr = &desc->action;
+    for ( ;; )
+    {
+        action = *action_ptr;
+        if ( !action )
+        {
+            printk(XENLOG_WARNING "Trying to free already-free IRQ %u\n", irq);
+            spin_unlock_irqrestore(&desc->lock, flags);
+            return;
+        }
+
+        if ( action->dev_id == dev_id )
+            break;
+
+        action_ptr = &action->next;
+    }
+
+    /* Found it - remove it from the action list */
+    *action_ptr = action->next;
 
-    action = desc->action;
-    desc->action  = NULL;
-    desc->status &= ~IRQ_GUEST;
+    /* If this was the last action, shut down the IRQ */
+    if ( !desc->action )
+    {
+        desc->handler->shutdown(desc);
+        desc->status &= ~IRQ_GUEST;
+    }
 
     spin_unlock_irqrestore(&desc->lock,flags);
 
     /* Wait to make sure it's not being used on another CPU */
     do { smp_mb(); } while ( desc->status & IRQ_INPROGRESS );
 
-    if ( action && action->free_on_release )
+    if ( action->free_on_release )
         xfree(action);
 }
 
-static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
+static int __setup_irq(struct irq_desc *desc, unsigned int irqflags,
+                       struct irqaction *new)
 {
-    if ( desc->action != NULL )
-        return -EBUSY;
+    bool_t shared = !!(irqflags & IRQF_SHARED);
+
+    ASSERT(new != NULL);
+
+    /* Sanity checks:
+     *  - if the IRQ is marked as shared
+     *  - dev_id is not NULL when IRQF_SHARED is set
+     */
+    if ( desc->action != NULL && (!(desc->status & IRQF_SHARED) || !shared) )
+        return -EINVAL;
+    if ( shared && new->dev_id == NULL )
+        return -EINVAL;
+
+    if ( shared )
+        desc->status |= IRQF_SHARED;
 
-    desc->action  = new;
-    dsb(sy);
+    new->next = desc->action;
+    dsb(ish);
+    desc->action = new;
+    dsb(ish);
 
     return 0;
 }
@@ -275,7 +320,7 @@ int setup_irq(unsigned int irq, unsigned int irqflags, struct irqaction *new)
 
     disabled = (desc->action == NULL);
 
-    rc = __setup_irq(desc, new);
+    rc = __setup_irq(desc, irqflags, new);
     if ( rc )
         goto err;
 
@@ -340,7 +385,7 @@ int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq,
         goto out;
     }
 
-    retval = __setup_irq(desc, action);
+    retval = __setup_irq(desc, 0, action);
     if ( retval )
         goto out;
 
xen/include/asm-arm/config.h +2 -0
index ef291ff..1c3abcf 100644
@@ -37,6 +37,8 @@
 
 #define CONFIG_VIDEO 1
 
+#define CONFIG_IRQ_HAS_MULTIPLE_ACTION 1
+
 #define OPT_CONSOLE_STR "dtuart"
 
 #ifdef MAX_PHYS_CPUS
xen/include/xen/irq.h +4 -0
index f9a18d8..40c0f3f 100644
@@ -14,6 +14,9 @@ struct irqaction {
     const char *name;
     void *dev_id;
     bool_t free_on_release;
+#ifdef CONFIG_IRQ_HAS_MULTIPLE_ACTION
+    struct irqaction *next;
+#endif
 };
 
 /*
@@ -27,6 +30,7 @@ struct irqaction {
 #define IRQ_MOVE_PENDING  (1u<<5) /* IRQ is migrating to another CPUs */
 #define IRQ_PER_CPU       (1u<<6) /* IRQ is per CPU */
 #define IRQ_GUEST_EOI_PENDING (1u<<7) /* IRQ was disabled, pending a guest EOI */
+#define IRQF_SHARED       (1<<8)  /* IRQ is shared */
 
 /* Special IRQ numbers. */
 #define AUTO_ASSIGN_IRQ         (-1)
Signature · 1 line
1.7.10.4
Acked-by on v4 18/18
#25 lore raw

Re: [PATCH v4 18/18] xen/arm: IRQ: Handle multiple action per IRQ

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 14:58, <[email protected]> wrote:

On ARM, it may happen (eg ARM SMMU) to setup multiple handler for the same interrupt.

To be able to use multiple action, the driver has to explicitly call {setup,request}_irq with IRQF_SHARED as 2nd parameter.

The behavior stays the same on x86, e.g only one action is handled.

For the non-ARM part:

Quoted 218 lines

---
Changes in v4:
- Go back to a single custom linked list. The double linked-list doesn't fit the requirements (i.e browsing safely without look) and the llist.h from Linux doesn't allow use to delete a node in the
middle
of the list.

Changes in v3:
- Drop {setup,request}_irq_flags, the current function has been extended on an earlier patch.
- Rename IRQ_SHARED into IRQF_SHARED

Changes in v2:
- Explain design choice
- Introduce CONFIG_IRQ_HAS_MULTIPLE_ACTION
- Use list instead of custom pointer
- release_irq should not shutdown the IRQ at the beginning
- Add IRQ_SHARED flags
- Introduce request_irq_flags and setup_irq_flags
- Fix compilation on x86. Some code are creating the irqaction via = { ... } so the "next" field should be moved toward the end

---
 xen/arch/arm/irq.c           |   79 +++++++++++++++++++++++++++++++++---------
 xen/include/asm-arm/config.h |    2 ++
 xen/include/xen/irq.h        |    4 +++
 3 files changed, 68 insertions(+), 17 deletions(-)
xen/arch/arm/irq.c +1 -2
index 1bc960d..d05c0be 100644
@@ -155,7 +155,6 @@ int request_irq(unsigned int irq, unsigned int irqflags,
 void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq)
 {
     struct irq_desc *desc = irq_to_desc(irq);
-    struct irqaction *action = desc->action;
 
     /* TODO: perfc_incr(irqs); */
 
@@ -166,7 +165,7 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, 
 int is_fiq)
     spin_lock(&desc->lock);
     desc->handler->ack(desc);
 
-    if ( action == NULL )
+    if ( !desc->action )
     {
         printk("Unknown %s %#3.3x\n",
                is_fiq ? "FIQ" : "IRQ", irq);
xen/arch/arm/irq.c +59 -13
@@ -198,12 +197,21 @@ void do_IRQ(struct cpu_user_regs *regs, unsigned int 
 irq, int is_fiq)
 
     desc->status |= IRQ_INPROGRESS;
 
-    action = desc->action;
     while ( desc->status & IRQ_PENDING )
     {
+        struct irqaction *action;
+
         desc->status &= ~IRQ_PENDING;
+        action = desc->action;
+
         spin_unlock_irq(&desc->lock);
-        action->handler(irq, action->dev_id, regs);
+
+        do
+        {
+            action->handler(irq, action->dev_id, regs);
+            action = action->next;
+        } while ( action );
+
         spin_lock_irq(&desc->lock);
     }
@@ -220,34 +228,71 @@ void release_irq(unsigned int irq, const void *dev_id)
 {
     struct irq_desc *desc;
     unsigned long flags;
-   struct irqaction *action;
+    struct irqaction *action, **action_ptr;
 
     desc = irq_to_desc(irq);
 
     spin_lock_irqsave(&desc->lock,flags);
 
-    desc->handler->shutdown(desc);
+    action_ptr = &desc->action;
+    for ( ;; )
+    {
+        action = *action_ptr;
+        if ( !action )
+        {
+            printk(XENLOG_WARNING "Trying to free already-free IRQ %u\n", 
 irq);
+            spin_unlock_irqrestore(&desc->lock, flags);
+            return;
+        }
+
+        if ( action->dev_id == dev_id )
+            break;
+
+        action_ptr = &action->next;
+    }
+
+    /* Found it - remove it from the action list */
+    *action_ptr = action->next;
 
-    action = desc->action;
-    desc->action  = NULL;
-    desc->status &= ~IRQ_GUEST;
+    /* If this was the last action, shut down the IRQ */
+    if ( !desc->action )
+    {
+        desc->handler->shutdown(desc);
+        desc->status &= ~IRQ_GUEST;
+    }
 
     spin_unlock_irqrestore(&desc->lock,flags);
 
     /* Wait to make sure it's not being used on another CPU */
     do { smp_mb(); } while ( desc->status & IRQ_INPROGRESS );
 
-    if ( action && action->free_on_release )
+    if ( action->free_on_release )
         xfree(action);
 }
 
-static int __setup_irq(struct irq_desc *desc, struct irqaction *new)
+static int __setup_irq(struct irq_desc *desc, unsigned int irqflags,
+                       struct irqaction *new)
 {
-    if ( desc->action != NULL )
-        return -EBUSY;
+    bool_t shared = !!(irqflags & IRQF_SHARED);
+
+    ASSERT(new != NULL);
+
+    /* Sanity checks:
+     *  - if the IRQ is marked as shared
+     *  - dev_id is not NULL when IRQF_SHARED is set
+     */
+    if ( desc->action != NULL && (!(desc->status & IRQF_SHARED) || !shared) )
+        return -EINVAL;
+    if ( shared && new->dev_id == NULL )
+        return -EINVAL;
+
+    if ( shared )
+        desc->status |= IRQF_SHARED;
 
-    desc->action  = new;
-    dsb(sy);
+    new->next = desc->action;
+    dsb(ish);
+    desc->action = new;
+    dsb(ish);
 
     return 0;

}

xen/arch/arm/irq.c +2 -2
@@ -275,7 +320,7 @@ int setup_irq(unsigned int irq, unsigned int irqflags, 
 struct irqaction *new)
 
     disabled = (desc->action == NULL);
 
-    rc = __setup_irq(desc, new);
+    rc = __setup_irq(desc, irqflags, new);
     if ( rc )
         goto err;
@@ -340,7 +385,7 @@ int route_dt_irq_to_guest(struct domain *d, const struct 
 dt_irq *irq,
         goto out;
     }
 
-    retval = __setup_irq(desc, action);
+    retval = __setup_irq(desc, 0, action);
     if ( retval )
         goto out;
xen/include/asm-arm/config.h +2 -0
index ef291ff..1c3abcf 100644
@@ -37,6 +37,8 @@
 
 #define CONFIG_VIDEO 1
 
+#define CONFIG_IRQ_HAS_MULTIPLE_ACTION 1
+
 #define OPT_CONSOLE_STR "dtuart"
 
 #ifdef MAX_PHYS_CPUS
xen/include/xen/irq.h +3 -0
index f9a18d8..40c0f3f 100644
@@ -14,6 +14,9 @@ struct irqaction {
     const char *name;
     void *dev_id;
     bool_t free_on_release;
+#ifdef CONFIG_IRQ_HAS_MULTIPLE_ACTION
+    struct irqaction *next;
+#endif
 };
 
 /*
@@ -27,6 +30,7 @@ struct irqaction {
 #define IRQ_MOVE_PENDING  (1u<<5) /* IRQ is migrating to another CPUs */
 #define IRQ_PER_CPU       (1u<<6) /* IRQ is per CPU */
 #define IRQ_GUEST_EOI_PENDING (1u<<7) /* IRQ was disabled, pending a guest 

EOI */
+#define IRQF_SHARED (1<<8) /* IRQ is shared */

/* Special IRQ numbers. */
#define AUTO_ASSIGN_IRQ (-1)

Signature · 1 line
1.7.10.4
#26 lore raw

Re: [PATCH v4 18/18] xen/arm: IRQ: Handle multiple action per IRQ

In reply to Julien Grall
Quoted 12 lines · Julien Grall

On ARM, it may happen (eg ARM SMMU) to setup multiple handler for the same interrupt.

To be able to use multiple action, the driver has to explicitly call {setup,request}_irq with IRQF_SHARED as 2nd parameter.

The behavior stays the same on x86, e.g only one action is handled.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Quoted 6 lines

---
Changes in v4:
- Go back to a single custom linked list. The double linked-list doesn't fit the requirements (i.e browsing safely without look) and the llist.h from Linux doesn't allow use to delete a node in the middle of the list.

Is this variant any safer?

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 213

Quoted 5 lines
xen/arch/arm/irq.c +5 -0
+        do
+        {
+            action->handler(irq, action->dev_id, regs);
+            action = action->next;
+        } while ( action );

What happens if action is freed and recycled in the midst of this loop?

Ian.

#27 lore raw

Re: [PATCH v4 18/18] xen/arm: IRQ: Handle multiple action per IRQ

Quoted 13 lines · Ian Campbell
Quoted 12 lines · Julien Grall

On ARM, it may happen (eg ARM SMMU) to setup multiple handler for the same interrupt.

To be able to use multiple action, the driver has to explicitly call {setup,request}_irq with IRQF_SHARED as 2nd parameter.

The behavior stays the same on x86, e.g only one action is handled.

Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Quoted 8 lines
Quoted 6 lines

---
Changes in v4:
- Go back to a single custom linked list. The double linked-list doesn't fit the requirements (i.e browsing safely without look) and the llist.h from Linux doesn't allow use to delete a node in the middle of the list.

Is this variant any safer?

Yes, everything is protected by a desc->lock, except in do_IRQ (see below why).

Quoted 7 lines

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 213

Quoted 5 lines
xen/arch/arm/irq.c +5 -0
+        do
+        {
+            action->handler(irq, action->dev_id, regs);
+            action = action->next;
+        } while ( action );

What happens if action is freed and recycled in the midst of this loop?

Nothing, the action won't be free until IRQ_INPROGRESS is set (see do .. while at the end of release_irq).

Regards,

Signature · 1 line
Julien Grall
#28 lore raw

Re: [PATCH v4 18/18] xen/arm: IRQ: Handle multiple action per IRQ

Quoted 10 lines · Julien Grall
Quoted 7 lines

xen/arch/arm/irq.c void do_IRQ(struct cpu_user_regs *regs, unsigned int irq, int is_fiq) · line 213

Quoted 5 lines
xen/arch/arm/irq.c +5 -0
+        do
+        {
+            action->handler(irq, action->dev_id, regs);
+            action = action->next;
+        } while ( action );

What happens if action is freed and recycled in the midst of this loop?

Nothing, the action won't be free until IRQ_INPROGRESS is set (see do .. while at the end of release_irq).

BY that logic wasn't the version which used the list macros also safe then?

Ian.

#29 lore raw

Re: [PATCH v4 18/18] xen/arm: IRQ: Handle multiple action per IRQ

Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 6 lines
Quoted 5 lines
xen/arch/arm/irq.c +5 -0
+        do
+        {
+            action->handler(irq, action->dev_id, regs);
+            action = action->next;
+        } while ( action );
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

What happens if action is freed and recycled in the midst of this loop?

Nothing, the action won't be free until IRQ_INPROGRESS is set (see do .. while at the end of release_irq).

BY that logic wasn't the version which used the list macros also safe then?

No because we had to modify two pointers (next and prev). Here as we modify only one pointer, do_IRQ may or may not call action for a last time.

Signature · 1 line
Julien Grall
#30 lore raw

Re: [PATCH v4 18/18] xen/arm: IRQ: Handle multiple action per IRQ

In reply to Ian Campbell
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 6 lines
Quoted 5 lines
xen/arch/arm/irq.c +5 -0
+        do
+        {
+            action->handler(irq, action->dev_id, regs);
+            action = action->next;
+        } while ( action );
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

What happens if action is freed and recycled in the midst of this loop?

Nothing, the action won't be free until IRQ_INPROGRESS is set (see do .. while at the end of release_irq).

BY that logic wasn't the version which used the list macros also safe then?

No because we had to modify two pointers (next and prev). Here as we modify only one pointer, do_IRQ may or may not call action for a last time.

Signature · 1 line
Julien Grall
#31 lore raw
In reply to Julien Grall

Ian,

Patch #1-13 are all acked, can you apply them to staging?

It will avoid me to send the whole series again.

Thanks !

Quoted 72 lines · Julien Grall

Hello,

This is the fourth version of this serie to rework interrupt management for ARM.

Major changes in v4:
- Use a custom single linked list for handling multiple action
- Slightly rework patch #9 (was acked by Ian)
- Remove dependency on Stefano's series for Patch #10
- Change platform_get_irq error code to -1 (impact patch #14 acked by Ian)

For all changes see in each patch.

This series is a dependency for the ARM SMMU drivers.

A working tree can be found here:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch interrupt-mgmt-v4

Sincerely yours,

Julien Grall (18):
xen/arm: timer: replace timer_dt_irq by timer_get_irq xen/arm: IRQ: Use default irq callback from common code for
no_irq_type
xen/arm: IRQ: Rename irq_cfg into arch_irq_desc
xen/arm: IRQ: move gic {,un}lock in gic_set_irq_properties xen/arm: IRQ: drop irq parameter in __setup_irq
xen/arm: IRQ: remove __init from setup_dt_irq, request_dt_irq and
release_irq
xen/arm: IRQ: Rework gic_route_irq_to_guest function xen/arm: IRQ: Move IRQ management from gic.c to irq.c xen/arm: IRQ Introduce irq_get_domain
xen/arm: IRQ: Require desc.lock be held by callers of
hw_irq_controller callbacks
xen/arm: IRQ: Defer routing IRQ to Xen until setup_irq() call xen/arm: IRQ: Do not allow IRQ to be shared between domains and XEN xen/serial: remove serial_dt_irq
xen/arm: IRQ: Store IRQ type in arch_irq_desc
xen/arm: IRQ: Replace {request,setup}_dt_irq by {request,setup}_irq
xen: IRQ: Add dev_id parameter to release_irq
xen/arm: IRQ: extend {request,setup}_irq to take an irqflags in
parameter
xen/arm: IRQ: Handle multiple action per IRQ

  xen/arch/arm/domain_build.c              |   32 +--
  xen/arch/arm/gic.c                       |  230 +++++----------------
  xen/arch/arm/irq.c                       |  321 ++++++++++++++++++++++++++++--
  xen/arch/arm/platforms/xgene-storm.c     |    2 +-
  xen/arch/arm/setup.c                     |    5 +-
  xen/arch/arm/smpboot.c                   |    2 -
  xen/arch/arm/time.c                      |   43 ++--
  xen/arch/arm/vgic.c                      |   10 +
  xen/arch/arm/vtimer.c                    |    4 +-
  xen/arch/x86/hpet.c                      |    2 +-
  xen/arch/x86/i8259.c                     |    2 +-
  xen/arch/x86/irq.c                       |   11 +-
  xen/arch/x86/time.c                      |    2 +-
  xen/drivers/char/exynos4210-uart.c       |   23 +--
  xen/drivers/char/ns16550.c               |   31 +--
  xen/drivers/char/omap-uart.c             |   23 +--
  xen/drivers/char/pl011.c                 |   24 +--
  xen/drivers/char/serial.c                |    9 -
  xen/drivers/passthrough/amd/iommu_init.c |    2 +-
  xen/drivers/passthrough/vtd/iommu.c      |    2 +-
  xen/include/asm-arm/config.h             |    2 +
  xen/include/asm-arm/gic.h                |   16 +-
  xen/include/asm-arm/irq.h                |   12 +-
  xen/include/asm-arm/time.h               |    7 +-
  xen/include/xen/irq.h                    |   11 +-
  xen/include/xen/serial.h                 |    5 -
  26 files changed, 471 insertions(+), 362 deletions(-)
Signature · 1 line
Julien Grall
#32 lore raw
In reply to Julien Grall
Quoted 9 lines · Julien Grall

Julien Grall (18):
xen/arm: timer: replace timer_dt_irq by timer_get_irq xen/arm: IRQ: Use default irq callback from common code for
no_irq_type
xen/arm: IRQ: Rename irq_cfg into arch_irq_desc xen/arm: IRQ: move gic {,un}lock in gic_set_irq_properties xen/arm: IRQ: drop irq parameter in __setup_irq xen/arm: IRQ: remove __init from setup_dt_irq, request_dt_irq and
release_irq

Quoted 8 lines

xen/arm: IRQ: Rework gic_route_irq_to_guest function xen/arm: IRQ: Move IRQ management from gic.c to irq.c xen/arm: IRQ Introduce irq_get_domain
xen/arm: IRQ: Require desc.lock be held by callers of
hw_irq_controller callbacks
xen/arm: IRQ: Defer routing IRQ to Xen until setup_irq() call xen/arm: IRQ: Do not allow IRQ to be shared between domains and XEN xen/serial: remove serial_dt_irq

Applied up to here.

Quoted 6 lines

xen/arm: IRQ: Store IRQ type in arch_irq_desc
xen/arm: IRQ: Replace {request,setup}_dt_irq by {request,setup}_irq
xen: IRQ: Add dev_id parameter to release_irq
xen/arm: IRQ: extend {request,setup}_irq to take an irqflags in
parameter
xen/arm: IRQ: Handle multiple action per IRQ