From patchwork Tue Apr 8 14:43:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 28002 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C8D7B20447 for ; Tue, 8 Apr 2014 14:46:48 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id hw13sf2715886qab.7 for ; Tue, 08 Apr 2014 07:46:48 -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=11/KEXEmh1P06xNgAA/N35lLiZjLMQ0Uz5l53M66Kvg=; b=ZmtUMFd0XLFsb/NDzp/25StzBP3M+UfCqUyH14bajQ7V02wzdL5yOH5cBgbhFrPpxm sJzRKw1hL7zfFFYxoaiIU9shj7pfFdAKowmbSUoevev3rYS/tgBj8v02x9DnpCw4SuAg Pk02cHJ8UaQzBzAUt6Cspotjxjm8z8YUSScexKzjYDf9xtM5UWlL8lH37lpH5Z1tkS4e W8WSnOkw4HrIGBfIhCjfvHPFpjQ1vSUmWaDDx5c16jZaJ+ZUhXIRwocMtA50f/0uW4nD 0XN7LedCe6z+qz+MWWfmbrb0X1YKIMZbpQ5XyVR3z7X2pM3bxlR9kbEfPpoKMmtam0Di p5ZQ== X-Gm-Message-State: ALoCoQnjsu8f/C6MY7KJm91qPFHfQL01Ql3bBgXCGGFZMBz0PZSYfiUFIxYezMqe4qN80VY8zeTl X-Received: by 10.236.27.33 with SMTP id d21mr1543930yha.23.1396968408559; Tue, 08 Apr 2014 07:46:48 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.141 with SMTP id g13ls218085qge.76.gmail; Tue, 08 Apr 2014 07:46:48 -0700 (PDT) X-Received: by 10.221.20.199 with SMTP id qp7mr1944454vcb.24.1396968408278; Tue, 08 Apr 2014 07:46:48 -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 cb3si433145vdc.95.2014.04.08.07.46.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:46:48 -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 db12so832164veb.24 for ; Tue, 08 Apr 2014 07:46:48 -0700 (PDT) X-Received: by 10.220.133.80 with SMTP id e16mr3563215vct.13.1396968408195; Tue, 08 Apr 2014 07:46:48 -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 v8csp251732vcv; Tue, 8 Apr 2014 07:46:47 -0700 (PDT) X-Received: by 10.50.30.6 with SMTP id o6mr26346684igh.43.1396968407336; Tue, 08 Apr 2014 07:46:47 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id n7si3472539iga.32.2014.04.08.07.46.46 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 07:46:47 -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 1WXXGE-0000Ew-11; Tue, 08 Apr 2014 14:44:26 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WXXGC-0000BZ-1V for xen-devel@lists.xenproject.org; Tue, 08 Apr 2014 14:44:24 +0000 Received: from [85.158.139.211:7320] by server-14.bemta-5.messagelabs.com id 6E/F2-15696-74B04435; Tue, 08 Apr 2014 14:44:23 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-4.tower-206.messagelabs.com!1396968262!6196929!1 X-Originating-IP: [74.125.83.46] 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 8599 invoked from network); 8 Apr 2014 14:44:22 -0000 Received: from mail-ee0-f46.google.com (HELO mail-ee0-f46.google.com) (74.125.83.46) by server-4.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 8 Apr 2014 14:44:22 -0000 Received: by mail-ee0-f46.google.com with SMTP id t10so770136eei.19 for ; Tue, 08 Apr 2014 07:44:22 -0700 (PDT) X-Received: by 10.14.88.7 with SMTP id z7mr2475579eee.90.1396968262048; Tue, 08 Apr 2014 07:44:22 -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.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Apr 2014 07:44:20 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 8 Apr 2014 15:43:57 +0100 Message-Id: <1396968247-8768-9-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: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v3 08/18] xen/arm: IRQ: Move IRQ management from gic.c to irq.c 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: The file gic.c contains functions and variables which is not related to the GIC: - release_irq - setup_irq - gic_route_irq_to_guest - {,local_}irq_desc Move all theses functions/variables in irq.c Signed-off-by: Julien Grall Acked-by: Ian Campbell --- Changes in v3: - Split the patch in 2: refactoring + code motion Changes in v2: - Patch added --- xen/arch/arm/gic.c | 102 +--------------------------------- xen/arch/arm/irq.c | 97 ++++++++++++++++++++++++++++++++ xen/arch/arm/platforms/xgene-storm.c | 2 +- xen/include/asm-arm/gic.h | 4 ++ 4 files changed, 105 insertions(+), 100 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index d30b979..5f16fe6 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -52,8 +52,6 @@ static struct { spinlock_t lock; } gic; -static irq_desc_t irq_desc[NR_IRQS]; -static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc); static DEFINE_PER_CPU(uint64_t, lr_mask); static uint8_t nr_lrs; @@ -91,12 +89,6 @@ unsigned int gic_number_lines(void) return gic.lines; } -irq_desc_t *__irq_to_desc(int irq) -{ - if (irq < NR_LOCAL_IRQS) return &this_cpu(local_irq_desc)[irq]; - return &irq_desc[irq-NR_LOCAL_IRQS]; -} - void gic_save_state(struct vcpu *v) { int i; @@ -289,9 +281,9 @@ static int gic_route_irq(unsigned int irq, bool_t level, /* Program the GIC to route an interrupt to a guest * - desc.lock must be held */ -static void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc, - bool_t level, const cpumask_t *cpu_mask, - unsigned int priority) +void gic_route_irq_to_guest(struct domain *d, struct irq_desc *desc, + bool_t level, const cpumask_t *cpu_mask, + unsigned int priority) { struct pending_irq *p; ASSERT(spin_is_locked(&desc->lock)); @@ -595,59 +587,6 @@ void gic_route_spis(void) } } -void release_irq(unsigned int irq) -{ - struct irq_desc *desc; - unsigned long flags; - struct irqaction *action; - - desc = irq_to_desc(irq); - - desc->handler->shutdown(desc); - - spin_lock_irqsave(&desc->lock,flags); - action = desc->action; - desc->action = NULL; - 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) - xfree(action); -} - -static int __setup_irq(struct irq_desc *desc, struct irqaction *new) -{ - if ( desc->action != NULL ) - return -EBUSY; - - desc->action = new; - dsb(sy); - - return 0; -} - -int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new) -{ - int rc; - unsigned long flags; - struct irq_desc *desc; - - desc = irq_to_desc(irq->irq); - - spin_lock_irqsave(&desc->lock, flags); - rc = __setup_irq(desc, new); - spin_unlock_irqrestore(&desc->lock, flags); - - if ( !rc ) - desc->handler->startup(desc); - - return rc; -} - static inline void gic_set_lr(int lr, struct pending_irq *p, unsigned int state) { @@ -895,41 +834,6 @@ void gic_inject(void) GICH[GICH_HCR] &= ~GICH_HCR_UIE; } -int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq, - const char * devname) -{ - struct irqaction *action; - struct irq_desc *desc = irq_to_desc(irq->irq); - unsigned long flags; - int retval; - bool_t level; - - action = xmalloc(struct irqaction); - if (!action) - return -ENOMEM; - - action->dev_id = d; - action->name = devname; - action->free_on_release = 1; - - spin_lock_irqsave(&desc->lock, flags); - - retval = __setup_irq(desc, action); - if ( retval ) - { - xfree(action); - goto out; - } - - level = dt_irq_is_level_triggered(irq); - gic_route_irq_to_guest(d, desc, level, cpumask_of(smp_processor_id()), - GIC_PRI_IRQ); - -out: - spin_unlock_irqrestore(&desc->lock, flags); - return retval; -} - static void do_sgi(struct cpu_user_regs *regs, int othercpu, enum gic_sgi sgi) { /* Lower the priority */ diff --git a/xen/arch/arm/irq.c b/xen/arch/arm/irq.c index 5b66a5c..bb4e049 100644 --- a/xen/arch/arm/irq.c +++ b/xen/arch/arm/irq.c @@ -44,6 +44,15 @@ hw_irq_controller no_irq_type = { .end = end_none }; +static irq_desc_t irq_desc[NR_IRQS]; +static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc); + +irq_desc_t *__irq_to_desc(int irq) +{ + if (irq < NR_LOCAL_IRQS) return &this_cpu(local_irq_desc)[irq]; + return &irq_desc[irq-NR_LOCAL_IRQS]; +} + int __init arch_init_one_irq_desc(struct irq_desc *desc) { return 0; @@ -188,6 +197,94 @@ out_no_end: irq_exit(); } +void release_irq(unsigned int irq) +{ + struct irq_desc *desc; + unsigned long flags; + struct irqaction *action; + + desc = irq_to_desc(irq); + + desc->handler->shutdown(desc); + + spin_lock_irqsave(&desc->lock,flags); + action = desc->action; + desc->action = NULL; + 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 ) + xfree(action); +} + +static int __setup_irq(struct irq_desc *desc, struct irqaction *new) +{ + if ( desc->action != NULL ) + return -EBUSY; + + desc->action = new; + dsb(sy); + + return 0; +} + +int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new) +{ + int rc; + unsigned long flags; + struct irq_desc *desc; + + desc = irq_to_desc(irq->irq); + + spin_lock_irqsave(&desc->lock, flags); + rc = __setup_irq(desc, new); + spin_unlock_irqrestore(&desc->lock, flags); + + if ( !rc ) + desc->handler->startup(desc); + + return rc; +} + +int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq, + const char * devname) +{ + struct irqaction *action; + struct irq_desc *desc = irq_to_desc(irq->irq); + unsigned long flags; + int retval; + bool_t level; + + action = xmalloc(struct irqaction); + if (!action) + return -ENOMEM; + + action->dev_id = d; + action->name = devname; + action->free_on_release = 1; + + spin_lock_irqsave(&desc->lock, flags); + + retval = __setup_irq(desc, action); + if ( retval ) + { + xfree(action); + goto out; + } + + level = dt_irq_is_level_triggered(irq); + gic_route_irq_to_guest(d, desc, level, cpumask_of(smp_processor_id()), + GIC_PRI_IRQ); + +out: + spin_unlock_irqrestore(&desc->lock, flags); + return retval; +} + /* * pirq event channels. We don't use these on ARM, instead we use the * features of the GIC to inject virtualised normal interrupts. diff --git a/xen/arch/arm/platforms/xgene-storm.c b/xen/arch/arm/platforms/xgene-storm.c index 70aab73..af3b71c 100644 --- a/xen/arch/arm/platforms/xgene-storm.c +++ b/xen/arch/arm/platforms/xgene-storm.c @@ -66,7 +66,7 @@ static int map_one_spi(struct domain *d, const char *what, printk("Additional IRQ %u (%s)\n", irq.irq, what); - ret = route_dt_irq_to_guest(d, &irq, what); + ret = gic_route_irq_to_guest(d, &irq, what); if ( ret ) printk("Failed to route %s to dom%d\n", what, d->domain_id); diff --git a/xen/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h index 1b94fd7..18a55c5 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -156,6 +156,7 @@ #ifndef __ASSEMBLY__ #include +#include #define DT_MATCH_GIC DT_MATCH_COMPATIBLE("arm,cortex-a15-gic"), \ DT_MATCH_COMPATIBLE("arm,cortex-a7-gic") @@ -173,6 +174,9 @@ extern struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq); extern void gic_route_dt_irq(const struct dt_irq *irq, const cpumask_t *cpu_mask, unsigned int priority); +extern void gic_route_irq_to_guest(struct domain *, struct irq_desc *desc, + bool_t level, const cpumask_t *cpu_mask, + unsigned int priority); extern void gic_route_ppis(void); extern void gic_route_spis(void);