From patchwork Mon May 12 17:57:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 29992 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f199.google.com (mail-ig0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CA071238EB for ; Mon, 12 May 2014 17:59:45 +0000 (UTC) Received: by mail-ig0-f199.google.com with SMTP id c1sf13969654igq.6 for ; Mon, 12 May 2014 10:59:45 -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=FtZXPq0DsR5o897IkCnidN1rzosP7IZU7uX4qqI1w7A=; b=VewDLJ5vpwWrd/3Dm+YCWFs2MX0dT5zBttHbxr41o4N3P9PfrCFg8F6gfCOON6HaIX hLCl2jmUFZFgdKl8O1yPFKxqbaWHigJ98OaGcO3l6r9WXc3m54A+vBiMZ+MOpJ/ekYcT DaL5sVFIZCuJFGZ8CWgnURcRY0ToWb9TDjZHHQGDMTX2Zv8g0eaK5kFDFLyGWkaoqeoC eouJE4ldYp5DSBvwpUy45HJtoP6FXvst/wOPjJsb8gvgw1gfrb3gskDsNLtUDU25oJPA 3QbSGNvSudf+D1aepigh/upDG/O7mX/ah5NwvVfj8CVIp1o36rRx6J3c1dr0G//pjR+j K+Ew== X-Gm-Message-State: ALoCoQnFGqCSGQCaDdir8+OLkpsWmdSq8SBwP7i+Lj2F8N1BjYXNr2zt/NiitvHYXgDrjA2aJWfv X-Received: by 10.42.236.68 with SMTP id kj4mr12642502icb.6.1399917585096; Mon, 12 May 2014 10:59:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.38.133 with SMTP id t5ls1512373qgt.43.gmail; Mon, 12 May 2014 10:59:45 -0700 (PDT) X-Received: by 10.58.198.75 with SMTP id ja11mr1902885vec.59.1399917584980; Mon, 12 May 2014 10:59:44 -0700 (PDT) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id gq7si2190009vdc.122.2014.05.12.10.59.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 12 May 2014 10:59:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.180 as permitted sender) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id db12so9337451veb.11 for ; Mon, 12 May 2014 10:59:44 -0700 (PDT) X-Received: by 10.220.103.141 with SMTP id k13mr8089474vco.25.1399917584885; Mon, 12 May 2014 10:59:44 -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.221.72 with SMTP id ib8csp88778vcb; Mon, 12 May 2014 10:59:44 -0700 (PDT) X-Received: by 10.58.198.107 with SMTP id jb11mr25003940vec.10.1399917564173; Mon, 12 May 2014 10:59:24 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id tr2si2189838vdc.78.2014.05.12.10.59.23 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 12 May 2014 10:59:24 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) 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 1WjuTt-0005iy-TV; Mon, 12 May 2014 17:57:41 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WjuTr-0005h6-4e for xen-devel@lists.xenproject.org; Mon, 12 May 2014 17:57:39 +0000 Received: from [85.158.143.35:21151] by server-3.bemta-4.messagelabs.com id 80/BD-13602-29B01735; Mon, 12 May 2014 17:57:38 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-7.tower-21.messagelabs.com!1399917456!4420011!1 X-Originating-IP: [74.125.83.48] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14845 invoked from network); 12 May 2014 17:57:36 -0000 Received: from mail-ee0-f48.google.com (HELO mail-ee0-f48.google.com) (74.125.83.48) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 12 May 2014 17:57:36 -0000 Received: by mail-ee0-f48.google.com with SMTP id e49so4910232eek.7 for ; Mon, 12 May 2014 10:57:36 -0700 (PDT) X-Received: by 10.14.7.72 with SMTP id 48mr5920011eeo.114.1399917455961; Mon, 12 May 2014 10:57:35 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id l3sm34404295eeo.43.2014.05.12.10.57.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 May 2014 10:57:34 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 12 May 2014 18:57:17 +0100 Message-Id: <1399917438-21475-7-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399917438-21475-1-git-send-email-julien.grall@linaro.org> References: <1399917438-21475-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v6 6/6] 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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.180 as permitted sender) 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 Acked-by: Jan Beulich Acked-by: Ian Campbell --- 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 5226b58..a5a6c7d 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)