From patchwork Tue Apr 8 14:44:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 27996 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f200.google.com (mail-yk0-f200.google.com [209.85.160.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D146B20447 for ; Tue, 8 Apr 2014 14:46:06 +0000 (UTC) Received: by mail-yk0-f200.google.com with SMTP id q9sf2039476ykb.3 for ; Tue, 08 Apr 2014 07:46:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=y6tri724eZdAjxnsQ2Hr/FSFIS8t/id9eaX8+SlB+Lg=; b=ZZzdsHs3GBGd6H1ljEntnv4vFuWCit0v3HsNe/qjYAdT3jSB/z6VWsmev5VDCD8vMa dCj7hnP/4hSyCJMo6arS1Drt3/VlUGndtZGr/ul4uOxsSQJsH0r1HaHMnfKsJWgMjtik DdfdEmNbhR8xyv+hQX6vtSWFtp3sZ6aU/negbZugJ2kBJ2KKo28FQPUiJV2Wt2uEd3YQ X6c4/hHg4LkDlXgnbmqcVNz3iwtXzHTTNiioJoHTuBGfQwciwtadfMek+RzMnHqHxuMa 1NzjAnFDBlYRVT6HWiVAbLkP3c53RSQa/n0ZtuPxBVBR7Ffs+DeiwMOALfhobPW1YZpz ZLxQ== X-Gm-Message-State: ALoCoQkuArjPEMibbHizkB5cYva7B6Lb2ZYZvEum8dnziUOgfCU3L3w4Q70sRignkV6XROBBYIOj X-Received: by 10.236.125.6 with SMTP id y6mr1764485yhh.3.1396968366555; Tue, 08 Apr 2014 07:46:06 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.100 with SMTP id u91ls211865qgu.74.gmail; Tue, 08 Apr 2014 07:46:06 -0700 (PDT) X-Received: by 10.220.161.8 with SMTP id p8mr3600601vcx.4.1396968366344; Tue, 08 Apr 2014 07:46:06 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id sc7si432874vdc.85.2014.04.08.07.46.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:46:06 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id ld13so830645vcb.5 for ; Tue, 08 Apr 2014 07:46:06 -0700 (PDT) X-Received: by 10.52.78.231 with SMTP id e7mr1774661vdx.28.1396968366254; Tue, 08 Apr 2014 07:46:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.12.8 with SMTP id v8csp251676vcv; Tue, 8 Apr 2014 07:46:05 -0700 (PDT) X-Received: by 10.140.40.47 with SMTP id w44mr3235265qgw.112.1396968365490; Tue, 08 Apr 2014 07:46:05 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id b6si931491qae.145.2014.04.08.07.46.04 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:46:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXXGR-0000Xu-Tz; Tue, 08 Apr 2014 14:44:39 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXXGN-0000R8-Et for xen-devel@lists.xenproject.org; Tue, 08 Apr 2014 14:44:35 +0000 Received: from [85.158.137.68:53211] by server-11.bemta-3.messagelabs.com id 5C/4F-19438-25B04435; Tue, 08 Apr 2014 14:44:34 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-10.tower-31.messagelabs.com!1396968273!5764586!1 X-Originating-IP: [74.125.83.43] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13956 invoked from network); 8 Apr 2014 14:44:33 -0000 Received: from mail-ee0-f43.google.com (HELO mail-ee0-f43.google.com) (74.125.83.43) by server-10.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 8 Apr 2014 14:44:33 -0000 Received: by mail-ee0-f43.google.com with SMTP id e53so771777eek.30 for ; Tue, 08 Apr 2014 07:44:33 -0700 (PDT) X-Received: by 10.14.184.66 with SMTP id r42mr2684226eem.84.1396968273182; Tue, 08 Apr 2014 07:44:33 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id m42sm5031709eex.21.2014.04.08.07.44.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Apr 2014 07:44:32 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 8 Apr 2014 15:44:07 +0100 Message-Id: <1396968247-8768-19-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396968247-8768-1-git-send-email-julien.grall@linaro.org> References: <1396968247-8768-1-git-send-email-julien.grall@linaro.org> Cc: Keir Fraser , ian.campbell@citrix.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v3 18/18] xen/arm: IRQ: Handle multiple action per IRQ X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: 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 Cc: Keir Fraser Cc: Jan Beulich --- 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 | 83 +++++++++++++++++++++++++++++++----------- xen/common/irq.c | 3 ++ xen/include/asm-arm/config.h | 2 + xen/include/xen/irq.h | 8 ++++ 4 files changed, 74 insertions(+), 22 deletions(-) diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index 18217e8..31edfc8 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -68,7 +68,6 @@ static int __init init_irq_data(void) struct irq_desc *desc = irq_to_desc(irq); init_one_irq_desc(desc); desc->irq = irq; - desc->action = NULL; } return 0; @@ -82,7 +81,6 @@ static int __cpuinit init_local_irq_data(void) struct irq_desc *desc = irq_to_desc(irq); 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 @@ -107,11 +105,15 @@ void __cpuinit init_secondary_IRQ(void) static inline struct domain *irq_get_domain(struct irq_desc *desc) { + struct irqaction *action; + ASSERT(spin_is_locked(&desc->lock)); ASSERT(desc->status & IRQ_GUEST); - ASSERT(desc->action != NULL); + ASSERT(!list_empty(&desc->action)); + + action = list_entry(desc->action.next, struct irqaction, next); - return desc->action->dev_id; + return action->dev_id; } int request_irq(unsigned int irq, unsigned int irqflags, @@ -152,7 +154,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); */ @@ -163,7 +164,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 ( list_empty(&desc->action) ) { printk("Unknown %s %#3.3x\n", is_fiq ? "FIQ" : "IRQ", irq); @@ -195,12 +196,14 @@ 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, *next; + desc->status &= ~IRQ_PENDING; spin_unlock_irq(&desc->lock); - action->handler(irq, action->dev_id, regs); + list_for_each_entry_safe(action, next, &desc->action, next) + action->handler(irq, action->dev_id, regs); spin_lock_irq(&desc->lock); } @@ -217,33 +220,69 @@ void release_irq(unsigned int irq, const void *dev_id) { struct irq_desc *desc; unsigned long flags; - struct irqaction *action; + struct irqaction *action; + bool_t found = 0; desc = irq_to_desc(irq); spin_lock_irqsave(&desc->lock,flags); - desc->handler->shutdown(desc); + list_for_each_entry(action, &desc->action, next) + { + if ( action->dev_id == dev_id ) + { + found = 1; + break; + } + } + + if ( !found ) + { + printk(XENLOG_WARNING "Trying to free already-free IRQ %u\n", irq); + return; + } - action = desc->action; - desc->action = NULL; - desc->status &= ~IRQ_GUEST; + /* Found it - remove it from the action list */ + list_del_init(&action->next); + + /* If this was the last action, shut down the IRQ */ + if ( list_empty(&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 ( !list_empty(&desc->action) && + (!(desc->status & IRQF_SHARED) || !shared) ) + return -EINVAL; + if ( shared && new->dev_id == NULL ) + return -EINVAL; + + if ( shared ) + desc->status |= IRQF_SHARED; - desc->action = new; + INIT_LIST_HEAD(&new->next); + list_add_tail(&new->next, &desc->action); dsb(sy); return 0; @@ -270,9 +309,9 @@ int setup_irq(unsigned int irq, unsigned int irqflags, struct irqaction *new) return -EBUSY; } - disabled = (desc->action == NULL); + disabled = list_empty(&desc->action); - rc = __setup_irq(desc, new); + rc = __setup_irq(desc, irqflags, new); if ( rc ) goto err; @@ -320,7 +359,7 @@ int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq, * - Otherwise -> For now, don't allow the IRQ to be shared between * Xen and domains. */ - if ( desc->action != NULL ) + if ( !list_empty(&desc->action) ) { struct domain *ad = irq_get_domain(desc); @@ -337,7 +376,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 ) { xfree(action); diff --git a/xen/common/irq.c b/xen/common/irq.c index 3e55dfa..688e48a 100644 --- a/xen/common/irq.c +++ b/xen/common/irq.c @@ -17,6 +17,9 @@ int init_one_irq_desc(struct irq_desc *desc) spin_lock_init(&desc->lock); cpumask_setall(desc->affinity); INIT_LIST_HEAD(&desc->rl_link); +#ifdef CONFIG_IRQ_HAS_MULTIPLE_ACTION + INIT_LIST_HEAD(&desc->action); +#endif err = arch_init_one_irq_desc(desc); if ( err ) diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h index 5b7b1a8..079e8b9 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..c42b022 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 list_head 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) @@ -68,7 +72,11 @@ typedef struct irq_desc { unsigned int status; /* IRQ status */ hw_irq_controller *handler; struct msi_desc *msi_desc; +#ifdef CONFIG_IRQ_HAS_MULTIPLE_ACTION + struct list_head action; /* IRQ action list */ +#else struct irqaction *action; /* IRQ action list */ +#endif int irq; spinlock_t lock; struct arch_irq_desc arch;