From patchwork Fri May 16 14:40:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 30338 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B304220C81 for ; Fri, 16 May 2014 14:42:43 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id i7sf13212255oag.0 for ; Fri, 16 May 2014 07:42:43 -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=FuoDPZOIMxp05+Wgqs/gJivLeyN1gNB9KqmnYI92JVo=; b=CWwteksiXgjkN/v+IiYDiDQn04mQ16F6O5cRTX47H9ISBI/ZNnJV00vi21coY0vn3N /KSOTksSxeRSIoTGHzpcbXssTBpSJDjabswoSkFdjTOrU419WD1xF7PjMPY8GFy5DdYi jW3pOQM8hEiGCTqcMQEPqfVifaAeobqZ8VLXbqP3Xps3ouQZefDkFzXflkcg3ZsG6t+O F/a0BUNFLA6gCs+0q2lxjk+V0oWNUG4YepDksC2JpE4aSn+5GjijLc57VgEQPnYfjXeo dokW3OQrrRxHeKDmxv6oySpTz2bAy5kadLAIKmFUpUpDzs66PYpO8fsrtRLHbkHYAhui uHuQ== X-Gm-Message-State: ALoCoQnE9B4Zyny02ESZbzNvnZvoIdculHf2TQn21RIU64wRlPXhXrnfSgH9P3nnIUx+PB7XyjHA X-Received: by 10.43.173.71 with SMTP id ob7mr7632439icc.19.1400251363315; Fri, 16 May 2014 07:42:43 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.97 with SMTP id g88ls740196qgf.40.gmail; Fri, 16 May 2014 07:42:43 -0700 (PDT) X-Received: by 10.52.136.98 with SMTP id pz2mr596958vdb.70.1400251363163; Fri, 16 May 2014 07:42:43 -0700 (PDT) Received: from mail-ve0-f173.google.com (mail-ve0-f173.google.com [209.85.128.173]) by mx.google.com with ESMTPS id po6si1636595veb.92.2014.05.16.07.42.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 May 2014 07:42:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.173 as permitted sender) client-ip=209.85.128.173; Received: by mail-ve0-f173.google.com with SMTP id pa12so3230586veb.32 for ; Fri, 16 May 2014 07:42:43 -0700 (PDT) X-Received: by 10.52.139.101 with SMTP id qx5mr12118403vdb.17.1400251363069; Fri, 16 May 2014 07:42:43 -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 ib8csp58402vcb; Fri, 16 May 2014 07:42:42 -0700 (PDT) X-Received: by 10.42.31.134 with SMTP id z6mr17208058icc.9.1400251361717; Fri, 16 May 2014 07:42:41 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id pg8si2479364icb.31.2014.05.16.07.42.41 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 16 May 2014 07:42:41 -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 1WlJJY-0005Og-OK; Fri, 16 May 2014 14:40:48 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WlJJX-0005Nz-6a for xen-devel@lists.xenproject.org; Fri, 16 May 2014 14:40:47 +0000 Received: from [85.158.137.68:34317] by server-13.bemta-3.messagelabs.com id CB/44-18692-E6326735; Fri, 16 May 2014 14:40:46 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-8.tower-31.messagelabs.com!1400251245!4370131!1 X-Originating-IP: [74.125.83.44] 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 11911 invoked from network); 16 May 2014 14:40:45 -0000 Received: from mail-ee0-f44.google.com (HELO mail-ee0-f44.google.com) (74.125.83.44) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 16 May 2014 14:40:45 -0000 Received: by mail-ee0-f44.google.com with SMTP id c41so1619927eek.17 for ; Fri, 16 May 2014 07:40:45 -0700 (PDT) X-Received: by 10.14.218.201 with SMTP id k49mr23343135eep.16.1400251245364; Fri, 16 May 2014 07:40:45 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id s46sm20538730ees.3.2014.05.16.07.40.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 May 2014 07:40:44 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 16 May 2014 15:40:32 +0100 Message-Id: <1400251232-7695-7-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1400251232-7695-1-git-send-email-julien.grall@linaro.org> References: <1400251232-7695-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 v7 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.173 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 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)