From patchwork Sun Apr 28 23:01:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 16480 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 781092395E for ; Sun, 28 Apr 2013 23:03:39 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id bs12sf2646666qab.6 for ; Sun, 28 Apr 2013 16:02: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=eZkic8xvWI8/39x3JsdLCFjk0Inc9+GNsMm6PMnsz6Y=; b=RKT6KSmv8VAIUJlHBzH3w3vctKYASXxcl4jSmdqZQW6rlmQqzQz91HhGRFwkPRnRlX yNcKTSAEMBbfq/SlxLp671bqyFcbmZfJzNh+rMmJYp4fTcpYiPdjIdac+neTxTkuktB7 q1nNsa5OWfM87WqwjSGscuDuVc8tswl5cELY+GiarQCCoazb/04fyBlkUk03TZsfv0sc 4R/Cv8dwLK5O2ascyiGQ//H2fbC8iLcSw+v/x7WGYokcdO0SqFqzOMkQBbnVaumKGg7t UXJWnz9zJeNVXAid+w7uG/2xe1i1lvteBkZk43ZYFaI5UNlY0zbNaSwqz/Prt4f16tFW FSYw== X-Received: by 10.224.36.66 with SMTP id s2mr4938120qad.6.1367190158397; Sun, 28 Apr 2013 16:02:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.82.83 with SMTP id g19ls2597381qey.51.gmail; Sun, 28 Apr 2013 16:02:38 -0700 (PDT) X-Received: by 10.52.72.106 with SMTP id c10mr20286310vdv.31.1367190158229; Sun, 28 Apr 2013 16:02:38 -0700 (PDT) Received: from mail-ve0-x231.google.com (mail-ve0-x231.google.com [2607:f8b0:400c:c01::231]) by mx.google.com with ESMTPS id gr7si8980206vdc.38.2013.04.28.16.02.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Apr 2013 16:02:37 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::231 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::231; Received: by mail-ve0-f177.google.com with SMTP id cy12so2665346veb.8 for ; Sun, 28 Apr 2013 16:02:37 -0700 (PDT) X-Received: by 10.58.48.166 with SMTP id m6mr19184886ven.59.1367190157746; Sun, 28 Apr 2013 16:02: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.58.127.98 with SMTP id nf2csp33794veb; Sun, 28 Apr 2013 16:02:37 -0700 (PDT) X-Received: by 10.180.85.103 with SMTP id g7mr14101020wiz.23.1367190156728; Sun, 28 Apr 2013 16:02:36 -0700 (PDT) Received: from mail-wg0-x230.google.com (mail-wg0-x230.google.com [2a00:1450:400c:c00::230]) by mx.google.com with ESMTPS id d2si6575616wjy.100.2013.04.28.16.02.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Apr 2013 16:02:36 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c00::230 is neither permitted nor denied by best guess record for domain of julien.grall@linaro.org) client-ip=2a00:1450:400c:c00::230; Received: by mail-wg0-f48.google.com with SMTP id f11so3224996wgh.27 for ; Sun, 28 Apr 2013 16:02:36 -0700 (PDT) X-Received: by 10.180.189.205 with SMTP id gk13mr14078429wic.25.1367190156237; Sun, 28 Apr 2013 16:02:36 -0700 (PDT) Received: from belegaer.uk.xensource.com. (firewall.ctxuk.citrix.com. [46.33.159.2]) by mx.google.com with ESMTPSA id k5sm18711393wiy.5.2013.04.28.16.02.35 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 28 Apr 2013 16:02:35 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Cc: ian.campbell@citrix.com, patches@linaro.org, anthony.perard@citrix.com, stefano.stabellini@eu.citrix.com, Julien Grall Subject: [RFC 14/29] xen/arm: Retrieve timer interrupts from the device tree Date: Mon, 29 Apr 2013 00:01:57 +0100 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQn1WEJX5wyFfMEDVFGGOIAVAKi0QTA4HHMHqhZySJ3vPHaiNyJbslzPtdw1zvB0/pcKsTGL X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::231 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 --- xen/arch/arm/gic.c | 9 ++----- xen/arch/arm/time.c | 59 +++++++++++++++++++++++++++++++++++++++----- xen/include/asm-arm/time.h | 3 +++ 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 9c8049e..ea34e9c 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -484,15 +484,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..63dace2 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,18 @@ uint64_t __read_mostly boot_count; * register-mapped time source in the SoC. */ unsigned long __read_mostly cpu_khz; /* CPU clock frequency in kHz. */ +/* List of timer's IRQ */ +enum ppi_nr +{ + PHYS_SECURE_PPI, + PHYS_NONSECURE_PPI, + VIRT_PPI, + HYP_PPI, + MAX_TIMER_PPI, +}; + +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 +103,28 @@ 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, DT_USED_BY_XEN); + + /* Retrieve all IRQs for the timer */ + for ( i = 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[PHYS_NONSECURE_PPI].irq, timer_irq[HYP_PPI].irq, + timer_irq[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 +178,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[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 +187,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[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 +204,15 @@ 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[PHYS_NONSECURE_PPI], + 1u << smp_processor_id(), 0xa0); + gic_route_dt_irq(&timer_irq[HYP_PPI], 1u << smp_processor_id(), 0xa0); + gic_route_dt_irq(&timer_irq[VIRT_PPI], 1u << smp_processor_id(), 0xa0); +} + /* Set up the timer interrupt on this CPU */ void __cpuinit init_timer_interrupt(void) { @@ -184,10 +230,11 @@ 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_irq(timer_irq[HYP_PPI].irq, timer_interrupt, 0, "hyptimer", NULL); + request_irq(timer_irq[VIRT_PPI].irq, vtimer_interrupt, + 0, "virtimer", NULL); + request_irq(timer_irq[PHYS_NONSECURE_PPI].irq, timer_interrupt, + 2, "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..467bf91 100644 --- a/xen/include/asm-arm/time.h +++ b/xen/include/asm-arm/time.h @@ -12,6 +12,9 @@ struct tm; struct tm wallclock_time(void); +/* 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);