From patchwork Thu Apr 3 20:41:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 27707 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9D1FD20490 for ; Thu, 3 Apr 2014 20:44:19 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id jt11sf8549496pbb.11 for ; Thu, 03 Apr 2014 13:44:18 -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=Fok9vlahmmVIALB5wvc6bcpS/uz/vlpi359MDQT9vxM=; b=dax7nwqOBec/fl+DlwTBKzujInVEVaHIeK4ntZkCch3Xix3qkQbnL5pzfcbT0j6yp8 RLaw3L9AtPl5h4p+Ih5u5deI6medongQbMFcq8hwlmSczAln7boEhqAh/WNkvy5edAtV fsWPAC8bNrlUPA13bmk5Hdliqkh7uzQ5lRNR6umbycYhEb5yRzUB+H/0xjG6uJSnGFe6 kR/nGq/jKmQjxjr5rb7ws9Awe3rv4nAa2w1BIjRSENLS4XrGNuFsf5aFgItNHg8fMGr8 EBC64g8Mh/tlzYSIEsaLWZCgUUdi6sM0CDlMGvg1g3DdxNymw5xSCfSyMt4Kvutb86RE vhfg== X-Gm-Message-State: ALoCoQlIwG/TBbFPYOgE93N4lo8xtSqRT6eEA4zjjKXLyEfaP+TBGVgJtttVI8LY6VGf73BtXYy6 X-Received: by 10.66.219.69 with SMTP id pm5mr5084225pac.8.1396557858830; Thu, 03 Apr 2014 13:44:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.76 with SMTP id b70ls811080qgd.97.gmail; Thu, 03 Apr 2014 13:44:18 -0700 (PDT) X-Received: by 10.58.107.65 with SMTP id ha1mr1398744veb.1.1396557858733; Thu, 03 Apr 2014 13:44:18 -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 s10si1405880vco.164.2014.04.03.13.44.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Apr 2014 13:44:18 -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 db12so729980veb.10 for ; Thu, 03 Apr 2014 13:44:18 -0700 (PDT) X-Received: by 10.52.126.107 with SMTP id mx11mr7496433vdb.41.1396557858650; Thu, 03 Apr 2014 13:44:18 -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 v8csp59804vcv; Thu, 3 Apr 2014 13:44:17 -0700 (PDT) X-Received: by 10.58.122.164 with SMTP id lt4mr1376845veb.2.1396557844535; Thu, 03 Apr 2014 13:44:04 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id gs7si1404799vdc.164.2014.04.03.13.44.03 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 03 Apr 2014 13:44:04 -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 1WVoT6-0008DU-EE; Thu, 03 Apr 2014 20:42:36 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WVoT4-0008Ci-IL for xen-devel@lists.xenproject.org; Thu, 03 Apr 2014 20:42:34 +0000 Received: from [85.158.139.211:36624] by server-10.bemta-5.messagelabs.com id 6B/75-27081-9B7CD335; Thu, 03 Apr 2014 20:42:33 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-13.tower-206.messagelabs.com!1396557752!5339720!1 X-Originating-IP: [209.85.212.182] 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 19875 invoked from network); 3 Apr 2014 20:42:32 -0000 Received: from mail-wi0-f182.google.com (HELO mail-wi0-f182.google.com) (209.85.212.182) by server-13.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 3 Apr 2014 20:42:32 -0000 Received: by mail-wi0-f182.google.com with SMTP id d1so101994wiv.3 for ; Thu, 03 Apr 2014 13:42:32 -0700 (PDT) X-Received: by 10.180.105.227 with SMTP id gp3mr14456830wib.41.1396557752431; Thu, 03 Apr 2014 13:42:32 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id t50sm14510572eev.28.2014.04.03.13.42.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Apr 2014 13:42:32 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 3 Apr 2014 21:41:58 +0100 Message-Id: <1396557727-19102-8-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1396557727-19102-1-git-send-email-julien.grall@linaro.org> References: <1396557727-19102-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 v2 07/16] 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 and split gic_route_irq_to_guest in 2 parts: - route_dt_irq_to_guest: setup the desc - gic_route_irq_to_guest: setup correctly the GIC and the desc handler Signed-off-by: Julien Grall --- Changes in v2: - Patch added --- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic.c | 125 ++++++++----------------------------------- xen/arch/arm/irq.c | 97 +++++++++++++++++++++++++++++++++ xen/include/asm-arm/gic.h | 7 +-- xen/include/asm-arm/irq.h | 3 ++ 5 files changed, 126 insertions(+), 108 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2035390..e7b1674 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -719,7 +719,7 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) DPRINT("irq %u = %u type = 0x%x\n", i, irq.irq, irq.type); /* Don't check return because the IRQ can be use by multiple device */ - gic_route_irq_to_guest(d, &irq, dt_node_name(dev)); + route_dt_irq_to_guest(d, &irq, dt_node_name(dev)); } /* Map the address ranges */ diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 36cf93d..82e0316 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 unsigned nr_lrs; @@ -88,12 +86,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; @@ -282,6 +274,27 @@ static int gic_route_irq(unsigned int irq, bool_t level, return 0; } +/* Program the GIC to route an interrupt to a guest + * - desc.lock must be held + */ +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)); + + desc->handler = &gic_guest_irq_type; + desc->status |= IRQ_GUEST; + + gic_set_irq_properties(desc->irq, level, cpumask_of(smp_processor_id()), + GIC_PRI_IRQ); + + /* TODO: do not assume delivery to vcpu0 */ + p = irq_to_pending(d->vcpu[0], desc->irq); + p->desc = desc; +} + /* Program the GIC to route an interrupt with a dt_irq */ void gic_route_dt_irq(const struct dt_irq *irq, const cpumask_t *cpu_mask, unsigned int priority) @@ -570,59 +583,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) { @@ -761,49 +721,6 @@ void gic_inject(void) gic_inject_irq_start(); } -int gic_route_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; - struct pending_irq *p; - - 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); - - desc->handler = &gic_guest_irq_type; - desc->status |= IRQ_GUEST; - - level = dt_irq_is_level_triggered(irq); - - gic_set_irq_properties(irq->irq, level, cpumask_of(smp_processor_id()), - GIC_PRI_IRQ); - - retval = __setup_irq(desc, action); - if (retval) { - xfree(action); - goto out; - } - - /* TODO: do not assume delivery to vcpu0 */ - p = irq_to_pending(d->vcpu[0], irq->irq); - p->desc = desc; - -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 b3bfebc..f3a30bd 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/include/asm-arm/gic.h b/xen/include/asm-arm/gic.h index 071280b..0e6e325 100644 --- a/xen/include/asm-arm/gic.h +++ b/xen/include/asm-arm/gic.h @@ -153,6 +153,7 @@ #ifndef __ASSEMBLY__ #include +#include #define DT_MATCH_GIC DT_MATCH_COMPATIBLE("arm,cortex-a15-gic"), \ DT_MATCH_COMPATIBLE("arm,cortex-a7-gic") @@ -170,6 +171,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); @@ -181,9 +185,6 @@ extern void __cpuinit init_maintenance_interrupt(void); extern void gic_set_guest_irq(struct vcpu *v, unsigned int irq, unsigned int state, unsigned int priority); extern void gic_remove_from_queues(struct vcpu *v, unsigned int virtual_irq); -extern int gic_route_irq_to_guest(struct domain *d, - const struct dt_irq *irq, - const char * devname); /* Accept an interrupt from the GIC and dispatch its handler */ extern void gic_interrupt(struct cpu_user_regs *regs, int is_fiq); diff --git a/xen/include/asm-arm/irq.h b/xen/include/asm-arm/irq.h index 9380987..b52c26f 100644 --- a/xen/include/asm-arm/irq.h +++ b/xen/include/asm-arm/irq.h @@ -44,6 +44,9 @@ int request_dt_irq(const struct dt_irq *irq, const char *devname, void *dev_id); int setup_dt_irq(const struct dt_irq *irq, struct irqaction *new); +int route_dt_irq_to_guest(struct domain *d, const struct dt_irq *irq, + const char *devname); + #endif /* _ASM_HW_IRQ_H */ /* * Local variables: