From patchwork Fri May 10 02:18:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16835 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D2791238F7 for ; Fri, 10 May 2013 02:20:03 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id e11sf3502901wgh.3 for ; Thu, 09 May 2013 19:19:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=I0P01b9m7uiPXScYgWxIgw/G9z3xTOXRPWxVk01FaSE=; b=Apu9YCIcsNPB+sarc0osIy216jygraYUuOE5GLPrnEDoPp2wTlYTVItcNoAnI5CJUt n8QEQlVJcR2VWuF0koe5vsZUIjqQnOxAyzWAl0cx29tzNwSL4hrDqPRchyGbSa6OKlvo axDC+CxzoIIM9eJlVZ7pZqW7uoytUa5PvqkRCh0ZXFkCaNxrPAn0OXQ4V80GtqXIa5MX qdKr1hvn+sOUKREnXo3KsPYuTCAdYnVMignxrb6BurN9GXXv4tS7Wq08ROR9IY7NOLl3 NdSgWUkW+R4cv1yUgguAdede/re3U+C543Tcos5b7jv4SzKmFcijmJD3Ot+RR0WD1Mzj rZAA== X-Received: by 10.180.109.111 with SMTP id hr15mr120591wib.1.1368152378387; Thu, 09 May 2013 19:19:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.180.80.1 with SMTP id n1ls26685wix.41.canary; Thu, 09 May 2013 19:19:38 -0700 (PDT) X-Received: by 10.181.12.14 with SMTP id em14mr717004wid.18.1368152378177; Thu, 09 May 2013 19:19:38 -0700 (PDT) Received: from mail-ve0-x22e.google.com (mail-ve0-x22e.google.com [2607:f8b0:400c:c01::22e]) by mx.google.com with ESMTPS id c16si178957wik.54.2013.05.09.19.19.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 May 2013 19:19:38 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22e is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22e; Received: by mail-ve0-f174.google.com with SMTP id pb11so3401319veb.19 for ; Thu, 09 May 2013 19:19:37 -0700 (PDT) X-Received: by 10.52.36.115 with SMTP id p19mr2748780vdj.8.1368152377017; Thu, 09 May 2013 19:19:37 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.217.15 with SMTP id hk15csp36229vcb; Thu, 9 May 2013 19:19:36 -0700 (PDT) X-Received: by 10.194.62.18 with SMTP id u18mr21338956wjr.53.1368152375266; Thu, 09 May 2013 19:19:35 -0700 (PDT) Received: from mail-we0-x231.google.com (mail-we0-x231.google.com [2a00:1450:400c:c03::231]) by mx.google.com with ESMTPS id mv5si164132wib.84.2013.05.09.19.19.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 May 2013 19:19:35 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c03::231 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c03::231; Received: by mail-we0-f177.google.com with SMTP id q58so3485129wes.36 for ; Thu, 09 May 2013 19:19:34 -0700 (PDT) X-Received: by 10.180.105.195 with SMTP id go3mr756286wib.2.1368152374844; Thu, 09 May 2013 19:19:34 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id dj7sm597075wib.6.2013.05.09.19.19.33 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 May 2013 19:19:34 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: Stefano.Stabellini@eu.citrix.com, ian.campbell@citrix.com, patches@linaro.org, Julien Grall Subject: [PATCH V3 23/41] xen/arm: Retrieve timer interrupts from the device tree Date: Fri, 10 May 2013 03:18:09 +0100 Message-Id: <1368152307-598-24-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1368152307-598-1-git-send-email-julien.grall@linaro.org> References: <1368152307-598-1-git-send-email-julien.grall@linaro.org> X-Gm-Message-State: ALoCoQnvX6cSrJzyVwzFMjGXB2/yIVLjqFLL92iEjoHazlyAX2E7QdibJ6VoLD5mpz162iDGNEJ5 X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22e 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Julien Grall Changes in v3: - Move enum ppi_nr in asm-arm/time.h and rename it to timer_ppi (will be used in vtimer patch) - Prefix all ppi_nr by TIMER_ - Remove spurious 2 when physical IRQ is requested Changes in v2: - Hardcode ppi_nr value - Use the new function request_dt_irq Acked-by: Ian Campbell --- xen/arch/arm/gic.c | 9 ++------ xen/arch/arm/time.c | 53 +++++++++++++++++++++++++++++++++++++++----- xen/include/asm-arm/time.h | 12 ++++++++++ 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index d016845..1197d53 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -488,15 +488,10 @@ void gic_disable_cpu(void) void gic_route_ppis(void) { - /* XXX should get these from DT */ /* GIC maintenance */ gic_route_dt_irq(&gic.maintenance, 1u << smp_processor_id(), 0xa0); - /* Hypervisor Timer */ - gic_route_irq(26, 1, 1u << smp_processor_id(), 0xa0); - /* Virtual Timer */ - gic_route_irq(27, 1, 1u << smp_processor_id(), 0xa0); - /* Physical Timer */ - gic_route_irq(30, 1, 1u << smp_processor_id(), 0xa0); + /* Route timer interrupt */ + route_timer_interrupt(); } void gic_route_spis(void) diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c index 82f69d2..ecb7626 100644 --- a/xen/arch/arm/time.c +++ b/xen/arch/arm/time.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -46,6 +47,8 @@ uint64_t __read_mostly boot_count; * register-mapped time source in the SoC. */ unsigned long __read_mostly cpu_khz; /* CPU clock frequency in kHz. */ +static struct dt_irq timer_irq[MAX_TIMER_PPI]; + /*static inline*/ s_time_t ticks_to_ns(uint64_t ticks) { return muldiv64(ticks, SECONDS(1), 1000 * cpu_khz); @@ -90,6 +93,29 @@ static uint32_t calibrate_timer(void) /* Set up the timer on the boot CPU */ int __init init_xen_time(void) { + struct dt_device_node *dev; + int res; + unsigned int i; + + dev = dt_find_compatible_node(NULL, NULL, "arm,armv7-timer"); + if ( !dev ) + panic("Unable to find a compatible timer in the device tree\n"); + + dt_device_set_used_by(dev, DOMID_XEN); + + /* Retrieve all IRQs for the timer */ + for ( i = TIMER_PHYS_SECURE_PPI; i < MAX_TIMER_PPI; i++ ) + { + res = dt_device_get_irq(dev, i, &timer_irq[i]); + if ( res ) + panic("Timer: Unable to retrieve IRQ %u from the device tree\n", i); + } + + printk("Generic Timer IRQ: phys=%u hyp=%u virt=%u\n", + timer_irq[TIMER_PHYS_NONSECURE_PPI].irq, + timer_irq[TIMER_HYP_PPI].irq, + timer_irq[TIMER_VIRT_PPI].irq); + /* Check that this CPU supports the Generic Timer interface */ if ( !cpu_has_gentimer ) panic("CPU does not support the Generic Timer v1 interface.\n"); @@ -143,7 +169,8 @@ int reprogram_timer(s_time_t timeout) /* Handle the firing timer */ static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs) { - if ( irq == 26 && READ_SYSREG32(CNTHP_CTL_EL2) & CNTx_CTL_PENDING ) + if ( irq == (timer_irq[TIMER_HYP_PPI].irq) && + READ_SYSREG32(CNTHP_CTL_EL2) & CNTx_CTL_PENDING ) { /* Signal the generic timer code to do its work */ raise_softirq(TIMER_SOFTIRQ); @@ -151,7 +178,8 @@ static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs) WRITE_SYSREG32(0, CNTHP_CTL_EL2); } - if (irq == 30 && READ_SYSREG32(CNTP_CTL_EL0) & CNTx_CTL_PENDING ) + if ( irq == (timer_irq[TIMER_PHYS_NONSECURE_PPI].irq) && + READ_SYSREG32(CNTP_CTL_EL0) & CNTx_CTL_PENDING ) { /* Signal the generic timer code to do its work */ raise_softirq(TIMER_SOFTIRQ); @@ -167,6 +195,17 @@ static void vtimer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs) vgic_vcpu_inject_irq(current, irq, 1); } +/* Route timer's IRQ on this CPU */ +void __cpuinit route_timer_interrupt(void) +{ + gic_route_dt_irq(&timer_irq[TIMER_PHYS_NONSECURE_PPI], + 1u << smp_processor_id(), 0xa0); + gic_route_dt_irq(&timer_irq[TIMER_HYP_PPI], + 1u << smp_processor_id(), 0xa0); + gic_route_dt_irq(&timer_irq[TIMER_VIRT_PPI], + 1u << smp_processor_id(), 0xa0); +} + /* Set up the timer interrupt on this CPU */ void __cpuinit init_timer_interrupt(void) { @@ -184,10 +223,12 @@ void __cpuinit init_timer_interrupt(void) WRITE_SYSREG32(0, CNTHP_CTL_EL2); /* Hypervisor's timer disabled */ isb(); - /* XXX Need to find this IRQ number from devicetree? */ - request_irq(26, timer_interrupt, 0, "hyptimer", NULL); - request_irq(27, vtimer_interrupt, 0, "virtimer", NULL); - request_irq(30, timer_interrupt, 0, "phytimer", NULL); + request_dt_irq(&timer_irq[TIMER_HYP_PPI], timer_interrupt, 0, + "hyptimer", NULL); + request_dt_irq(&timer_irq[TIMER_VIRT_PPI], vtimer_interrupt, 0, + "virtimer", NULL); + request_dt_irq(&timer_irq[TIMER_PHYS_NONSECURE_PPI], timer_interrupt, 0, + "phytimer", NULL); } /* Wait a set number of microseconds */ diff --git a/xen/include/asm-arm/time.h b/xen/include/asm-arm/time.h index c16bf08..05833ce 100644 --- a/xen/include/asm-arm/time.h +++ b/xen/include/asm-arm/time.h @@ -11,6 +11,18 @@ static inline cycles_t get_cycles (void) struct tm; struct tm wallclock_time(void); +/* List of timer's IRQ */ +enum timer_ppi +{ + TIMER_PHYS_SECURE_PPI = 0, + TIMER_PHYS_NONSECURE_PPI = 1, + TIMER_VIRT_PPI = 2, + TIMER_HYP_PPI = 3, + MAX_TIMER_PPI = 4, +}; + +/* Route timer's IRQ on this CPU */ +extern void __cpuinit route_timer_interrupt(void); /* Set up the timer interrupt on this CPU */ extern void __cpuinit init_timer_interrupt(void);