From patchwork Tue Apr 22 12:58:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 28794 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 63788203AC for ; Tue, 22 Apr 2014 13:05:58 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id j17sf34587028oag.10 for ; Tue, 22 Apr 2014 06:05:57 -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=8dI2yZv4xabiFkbeAoZoRUosy5liieKwACjx2VQcAoE=; b=DFWcPyY5uIzCgUX9J6Kc7XtZ9Q4XTVBAXRiGJ5KWZwE45cSGDBcVcZMmF0B094Yfuz goMhsbNaEF8pHtgVaGdrxSsno9AS7Q7VDuC0DWGfhB5ZuInxi0hX0mzr/BDBUgEWzbdL Re+z5GKWdzsszFip7gw48eEuM/+D3R2e1IzD+fvrh39+iGcwLnjSGW1phHLaiYCWC4Rn 1JbXjX8kUksp2Nvob6VCIEo9M3laAYzGcL3RoheCsFxhlZ9RIjSGx/p5saILC3PgMLuh EJN6yGpPMocf1uIRtWPbmgfghz6WaUtCphdMzRDmfB/EovK3LtoU0vf+dTdJA2stAqfK //uA== X-Gm-Message-State: ALoCoQn0g7RTduY94gcIpd6jk37GGLCk+k1AJU+T30vWhLDJcKWf9QZy+OHXy5tAU3giPfGV8RGj X-Received: by 10.182.158.135 with SMTP id wu7mr22142141obb.19.1398171957865; Tue, 22 Apr 2014 06:05:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.100.164 with SMTP id s33ls73549qge.57.gmail; Tue, 22 Apr 2014 06:05:57 -0700 (PDT) X-Received: by 10.220.106.7 with SMTP id v7mr10473vco.46.1398171957748; Tue, 22 Apr 2014 06:05:57 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id ud8si6351768vdc.15.2014.04.22.06.05.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Apr 2014 06:05:57 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id db12so9306053veb.24 for ; Tue, 22 Apr 2014 06:05:57 -0700 (PDT) X-Received: by 10.58.198.75 with SMTP id ja11mr652vec.59.1398171957631; Tue, 22 Apr 2014 06:05:57 -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 ib8csp23007vcb; Tue, 22 Apr 2014 06:05:57 -0700 (PDT) X-Received: by 10.52.123.39 with SMTP id lx7mr30529457vdb.22.1398171956650; Tue, 22 Apr 2014 06:05:56 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id sh5si6862760vdc.158.2014.04.22.06.05.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 22 Apr 2014 06:05:56 -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 1WcaLY-0002dy-7K; Tue, 22 Apr 2014 13:02:48 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WcaIc-0001j7-OS for xen-devel@lists.xenproject.org; Tue, 22 Apr 2014 12:59:47 +0000 Received: from [85.158.143.35:47529] by server-1.bemta-4.messagelabs.com id 94/2F-09853-CA766535; Tue, 22 Apr 2014 12:59:24 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-15.tower-21.messagelabs.com!1398171563!249261!1 X-Originating-IP: [74.125.83.47] 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 28334 invoked from network); 22 Apr 2014 12:59:24 -0000 Received: from mail-ee0-f47.google.com (HELO mail-ee0-f47.google.com) (74.125.83.47) by server-15.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 22 Apr 2014 12:59:24 -0000 Received: by mail-ee0-f47.google.com with SMTP id b15so4573307eek.6 for ; Tue, 22 Apr 2014 05:59:23 -0700 (PDT) X-Received: by 10.15.81.135 with SMTP id x7mr13213685eey.61.1398171563695; Tue, 22 Apr 2014 05:59:23 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id x45sm112862825eef.15.2014.04.22.05.59.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Apr 2014 05:59:22 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 22 Apr 2014 13:58:50 +0100 Message-Id: <1398171530-27391-19-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398171530-27391-1-git-send-email-julien.grall@linaro.org> References: <1398171530-27391-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 v4 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.128.179 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 Acked-by: Jan Beulich --- 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 1bc960d..d05c0be 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -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; 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)