Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1323231ybg; Fri, 18 Oct 2019 15:58:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUPAqi+0YkO6PQBO3/0RSadfKldinA9sOyvnaGj+TO94G14UM+uICL29IXIRXxaVpnd/UW X-Received: by 2002:a17:906:130c:: with SMTP id w12mr10903650ejb.142.1571439519747; Fri, 18 Oct 2019 15:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571439519; cv=none; d=google.com; s=arc-20160816; b=cMI3M4oeOIuqzfIMJTe20ltdOKQ+tl3SFbJyuUXt3l9wH6CJHxQMOZtd+6i42nwDET 2NvFoTCsxg25A4vFJWrRU6FjgapW1vYWC6pHMmcIeXl+3/i1ZcMMSO0II1TG1JukDitz NJHjIczW7jlfuBOfWwPxQnS5dnOiGwHW1oYLktIyZ8vdJG8874T5TZVqov+gwFwkBGW3 IMRJSityfYBMeBI+rEkPXCrPMUt03af+LkSASjUnKst0ZJhKU4qIz4ULcHjzKpU4kJ96 sGPBc3W3O51l39rkoXUx8hdl6ckHr2jT64on/ADa3xTrCuiHTFJXoXJekon06oc2QOX4 Z8jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Be+nqHFdPq0NG3pyh4Rq7hQf+czCYg0L1pW1x7p+760=; b=gMdj/mZ3HUTI/k1gUzxcXR5AnjXq3GwEkTB7H9UMeLvWzKbSpNJ1W5Bgs1L+L9IWp8 sfP5F6qFCOX6zwmgxQWccXgiOgzT50fjWXJgJhlwnkB0HLaVm9EcYE9VLXf7pSQA3KEx jQr0kIQ2mNKzScXeZZOLnsd12m3Va1DfBGfMy/KOOwtXgtNk8asnx5Cq7qDffsxD3yih 0HooyuQ6AD10NOngH5GyyYfCV9U4cpPfP4jJDf5Q0xVe+e3xU0s3LmI1gEcWl0EdYvov hpfcjmhJV2vPNZ4Fg52wE4MslPpe5+gsp3Xl2E4cq62ykJwHFraQy7rgrj8MDyjC3u2l ZH+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=DoA6IJxv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 90si5786465edj.72.2019.10.18.15.58.16; Fri, 18 Oct 2019 15:58:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=DoA6IJxv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404143AbfJRFt4 (ORCPT + 99 others); Fri, 18 Oct 2019 01:49:56 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51848 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbfJRFtz (ORCPT ); Fri, 18 Oct 2019 01:49:55 -0400 Received: by mail-wm1-f66.google.com with SMTP id 7so4796083wme.1 for ; Thu, 17 Oct 2019 22:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Be+nqHFdPq0NG3pyh4Rq7hQf+czCYg0L1pW1x7p+760=; b=DoA6IJxv26NmgWjkeJeBKv/mm4gBftt7CZNlftvhSbQVjLZT75mE7vzu4UmAD3XZPr MRZM0pDFz2HNMJySzUfEeVzKl1VbHaCSxmAkUVujCaolp5Wh+9U/Ly3OfHSQKuvrGup6 17AV7GSnpvpJFD26BfqTFd0Vq4dAvC4GfuQJZvzcGAxuaYucrdMCrnPHINXF+JFR7V2G Jp5KD1aPBzQSYNWWB+1DBO3+Y51RVtciU2HDBz2oHOnZZnFnAxepA6Ai3+9sWhQ7eM+F DUpXaFYjmHize5NmajKvCdL3pkf0OuvGiewLyWcoSTIHUVbZdvAoBbsATT4micGZ7Tw1 0Z2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Be+nqHFdPq0NG3pyh4Rq7hQf+czCYg0L1pW1x7p+760=; b=Bow/FAs7Hlf6kuZ1z0QnjcaA883H2r5r4C3l8Q1Eda/dWRU57ywN5R8bN54l6QPfps TeSwtu80BOO/HpD8evRX9Gj9WgUkPAe6bkCXYLJ2bYF5aAgcIO/5KJz8ad4ih3Q7jd3m Lu0qQQooaAhibCbbd55n/A0IXQ44wj54xlhFFk/zyy7/qYao2Q/bohmPRTAJCh43QheQ 5eQGGXeT0/fBXKLJjx8HLbgnAajrfaJ6JltDL66pHREUx0PmGRoFUOypga8KuNBJKCCW nhIXmYqZdW7moj7URZHYy6z1WWZHD00sn8zXz4WwQN8Y+oGwv63ANiAotoyvvLAZBH/k TRKw== X-Gm-Message-State: APjAAAUA5NX/sLEp14NL3wcTMhItWy7HYgnY9GYi003X408F/sw4a58Y +mHkUn06nLzCwreFGOyvDraJeVAQ9JRRRlNra+/qVZWVHwM= X-Received: by 2002:a05:600c:214f:: with SMTP id v15mr5252538wml.177.1571367467638; Thu, 17 Oct 2019 19:57:47 -0700 (PDT) MIME-Version: 1.0 References: <20191017173743.5430-1-hch@lst.de> <20191017173743.5430-9-hch@lst.de> In-Reply-To: <20191017173743.5430-9-hch@lst.de> From: Anup Patel Date: Fri, 18 Oct 2019 08:27:36 +0530 Message-ID: Subject: Re: [PATCH 08/15] riscv: add support for MMIO access to the timer registers To: Christoph Hellwig Cc: Palmer Dabbelt , Paul Walmsley , Damien Le Moal , linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 17, 2019 at 11:08 PM Christoph Hellwig wrote: > > When running in M-mode we can't use the SBI to set the timer, and > don't have access to the time CSR as that usually is emulated by > M-mode. Instead provide code that directly accesses the MMIO for > the timer. > > Signed-off-by: Christoph Hellwig > --- > arch/riscv/include/asm/sbi.h | 3 ++- > arch/riscv/include/asm/timex.h | 19 +++++++++++++++++-- > drivers/clocksource/timer-riscv.c | 21 +++++++++++++++++---- > 3 files changed, 36 insertions(+), 7 deletions(-) > > diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h > index 0cb74eccc73f..a4774bafe033 100644 > --- a/arch/riscv/include/asm/sbi.h > +++ b/arch/riscv/include/asm/sbi.h > @@ -95,7 +95,8 @@ static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, > SBI_CALL_4(SBI_REMOTE_SFENCE_VMA_ASID, hart_mask, start, size, asid); > } > #else /* CONFIG_RISCV_SBI */ > -/* stub to for code is only reachable under IS_ENABLED(CONFIG_RISCV_SBI): */ > +/* stubs to for code is only reachable under IS_ENABLED(CONFIG_RISCV_SBI): */ > +void sbi_set_timer(uint64_t stime_value); > void sbi_remote_fence_i(const unsigned long *hart_mask); > #endif /* CONFIG_RISCV_SBI */ > #endif /* _ASM_RISCV_SBI_H */ > diff --git a/arch/riscv/include/asm/timex.h b/arch/riscv/include/asm/timex.h > index c7ef131b9e4c..e17837d61667 100644 > --- a/arch/riscv/include/asm/timex.h > +++ b/arch/riscv/include/asm/timex.h > @@ -7,12 +7,25 @@ > #define _ASM_RISCV_TIMEX_H > > #include > +#include > > typedef unsigned long cycles_t; > > +extern u64 __iomem *riscv_time_val; > +extern u64 __iomem *riscv_time_cmp; > + > +#ifdef CONFIG_64BIT > +#define mmio_get_cycles() readq_relaxed(riscv_time_val) > +#else > +#define mmio_get_cycles() readl_relaxed(riscv_time_val) > +#define mmio_get_cycles_hi() readl_relaxed(((u32 *)riscv_time_val) + 1) > +#endif > + > static inline cycles_t get_cycles(void) > { > - return csr_read(CSR_TIME); > + if (IS_ENABLED(CONFIG_RISCV_SBI)) > + return csr_read(CSR_TIME); > + return mmio_get_cycles(); > } > #define get_cycles get_cycles > > @@ -24,7 +37,9 @@ static inline u64 get_cycles64(void) > #else /* CONFIG_64BIT */ > static inline u32 get_cycles_hi(void) > { > - return csr_read(CSR_TIMEH); > + if (IS_ENABLED(CONFIG_RISCV_SBI)) > + return csr_read(CSR_TIMEH); > + return mmio_get_cycles_hi(); > } > > static inline u64 get_cycles64(void) > diff --git a/drivers/clocksource/timer-riscv.c b/drivers/clocksource/timer-riscv.c > index 5d2fdc3e28a9..2b9fbc4ebe49 100644 > --- a/drivers/clocksource/timer-riscv.c > +++ b/drivers/clocksource/timer-riscv.c > @@ -3,9 +3,9 @@ > * Copyright (C) 2012 Regents of the University of California > * Copyright (C) 2017 SiFive > * > - * All RISC-V systems have a timer attached to every hart. These timers can be > - * read from the "time" and "timeh" CSRs, and can use the SBI to setup > - * events. > + * All RISC-V systems have a timer attached to every hart. These timers can > + * either be read from the "time" and "timeh" CSRs, and can use the SBI to > + * setup events, or directly accessed using MMIO registers. > */ > #include > #include > @@ -13,14 +13,27 @@ > #include > #include > #include > +#include > #include > #include > > +u64 __iomem *riscv_time_cmp; > +u64 __iomem *riscv_time_val; > + > +static inline void mmio_set_timer(u64 val) > +{ > + writeq_relaxed(val, > + riscv_time_cmp + cpuid_to_hartid_map(smp_processor_id())); > +} > + > static int riscv_clock_next_event(unsigned long delta, > struct clock_event_device *ce) > { > csr_set(CSR_XIE, XIE_XTIE); > - sbi_set_timer(get_cycles64() + delta); > + if (IS_ENABLED(CONFIG_RISCV_SBI)) > + sbi_set_timer(get_cycles64() + delta); > + else > + mmio_set_timer(get_cycles64() + delta); > return 0; > } > > -- > 2.20.1 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv LGTM. Reviewed-by: Anup Patel Regards, Anup