From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: stefano.stabellini@citrix.com,
Julien Grall <julien.grall@linaro.org>,
tim@xen.org, ian.campbell@citrix.com,
Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v7 6/6] xen/arm: IRQ: Handle multiple action per IRQ
Date: Fri, 16 May 2014 15:40:32 +0100 [thread overview]
Message-ID: <1400251232-7695-7-git-send-email-julien.grall@linaro.org> (raw)
In-Reply-To: <1400251232-7695-1-git-send-email-julien.grall@linaro.org>
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.
Signed-off-by: Julien Grall <julien.grall@linaro.org>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
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(-)
diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c
index 1b62d83..3a9a688 100644
--- a/xen/arch/arm/irq.c
+++ b/xen/arch/arm/irq.c
@@ -171,7 +171,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); */
@@ -182,7 +181,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);
@@ -214,12 +213,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);
}
@@ -236,34 +244,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;
}
@@ -291,7 +336,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;
@@ -355,7 +400,7 @@ int route_irq_to_guest(struct domain *d, unsigned int irq,
goto out;
}
- retval = __setup_irq(desc, action);
+ retval = __setup_irq(desc, 0, action);
if ( retval )
goto out;
diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h
index ef291ff..1c3abcf 100644
--- a/xen/include/asm-arm/config.h
+++ b/xen/include/asm-arm/config.h
@@ -37,6 +37,8 @@
#define CONFIG_VIDEO 1
+#define CONFIG_IRQ_HAS_MULTIPLE_ACTION 1
+
#define OPT_CONSOLE_STR "dtuart"
#ifdef MAX_PHYS_CPUS
diff --git a/xen/include/xen/irq.h b/xen/include/xen/irq.h
index f9a18d8..40c0f3f 100644
--- a/xen/include/xen/irq.h
+++ b/xen/include/xen/irq.h
@@ -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)
--
1.7.10.4
prev parent reply other threads:[~2014-05-16 14:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 14:40 [PATCH v7 0/6] xen/arm: Interrupt management reworking Julien Grall
2014-05-16 14:40 ` [PATCH v7 1/6] xen/arm: IRQ: Store IRQ type in arch_irq_desc Julien Grall
2014-05-21 12:27 ` Ian Campbell
2014-05-16 14:40 ` [PATCH v7 2/6] xen/arm: IRQ: Replace {request, setup}_dt_irq by {request, setup}_irq Julien Grall
2014-05-16 14:40 ` [PATCH v7 3/6] xen/arm: Replace route_guest_dt_irq by route_guest_irq Julien Grall
2014-05-16 14:40 ` [PATCH v7 4/6] xen: IRQ: Add dev_id parameter to release_irq Julien Grall
2014-05-16 14:40 ` [PATCH v7 5/6] xen/arm: IRQ: extend {request, setup}_irq to take an irqflags in parameter Julien Grall
2014-05-16 14:40 ` Julien Grall [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400251232-7695-7-git-send-email-julien.grall@linaro.org \
--to=julien.grall@linaro.org \
--cc=ian.campbell@citrix.com \
--cc=jbeulich@suse.com \
--cc=stefano.stabellini@citrix.com \
--cc=tim@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).