Received: by 10.223.185.116 with SMTP id b49csp886682wrg; Fri, 23 Feb 2018 08:19:27 -0800 (PST) X-Google-Smtp-Source: AH8x2269cZ3ODRFX6liH/3BN/BZh628KR0rqcrIVPH/jdaXnMn9PyJSIGO/kAno5KTQvWVzFKt37 X-Received: by 2002:a17:902:c1:: with SMTP id a59-v6mr2162926pla.284.1519402767757; Fri, 23 Feb 2018 08:19:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519402767; cv=none; d=google.com; s=arc-20160816; b=SuMXcAtIqiBdsiCpjIkg7Nf7NzGbCsFb+1m3OK2rvjMtCNYI4I1fX3adLyS/IMf57D 8uifnhD4L6ijKiZTCaGkwi1gHQ3v1+WQy38oNEy/BHbuBU2iywjsp9TXi8zSY1yQGIwA 0S7wpBT5x0jn5xgSa9aKr0uODsgAZ74MEJSeriaikNo4WHvpocZTCgvn1FcDsNguShd5 cOzHDoAWf8iT0qsCjmmLdNDwui/RHHUdGZk7PemaVDoq68Qm/WD+Qfz3ldbh8zdSdm0S 8wYeXl2PpmUvFlMbCqIsV54NmorQpuXiyRyrp6zCZpyoH8MPg64FHy1aqmNj4xZKZCLw j6Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :arc-authentication-results; bh=vGbGasxFSbZMM7AIPLNMr/o+kJPj2T6zh+rFl5+F3og=; b=R0bQB8yBtMblPPircLK6UCzEcdU/pTnaKnJvYznf+cFBC6zzbiht3QOvahiLqT01z9 FZfTIbbsGrcmWreHBkkev7zMSW6k6d+nQrADlR7mORRHbmUM0k4YFS0zj36qi1tnbBaB xBICdV57e/6ezEDyYpHXcqCttUsUuAE1GVOsejEDphWFtBs440vyxRqgQJr8knZid/+d VDTCmthG2WgtaMcT5zF2/taUn3ft0DkYar/Z3W2fElTEZouA2H3Bf7r3iwlAtZaDQXKD zKkDWWoff39x45379s0AbGAPo5ZC9T1ZopFNoxPaI3vR9OPtYjXBwulBKI5bWPE1jJ3V Rt/g== ARC-Authentication-Results: i=1; mx.google.com; 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 m9-v6si2017685plt.6.2018.02.23.08.18.50; Fri, 23 Feb 2018 08:19:27 -0800 (PST) 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; 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 S1751789AbeBWQRi convert rfc822-to-8bit (ORCPT + 99 others); Fri, 23 Feb 2018 11:17:38 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37257 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589AbeBWQRg (ORCPT ); Fri, 23 Feb 2018 11:17:36 -0500 Received: by mail-wm0-f67.google.com with SMTP id m207so5553611wma.2; Fri, 23 Feb 2018 08:17:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ncVOfXUOa149yVJZc+h2IRq9qG/gOQwLDpMU+GSn0A4=; b=feJU7mglc1cXissOjQxdjbGmIcPfyJdkm5YZ4m6gvR2E5rRBKfheltahLViuCiERVX ZFp/KH6xIyDXUHk+1Xl5vLfrKhhl4tIpa5NXC9XUBu1EA1UxNuaNMllQABBgIPAUelms qbgSW+eqR2F61ikgSRCQprt1Udi4nvqLCuezlxSbptK2zu9iXJ4+oj04NZ99/0a6ltW4 xH+w6R0gsnfVm3jrRSt4iukf+QEtZ8yt6iG3C9QWR8lgzEg50rm4ZoC5ouGK3kQdzHEn U6MiiXWTspbZlvyZE8FBd6DMocqb+h97R07pErvo+98od6WEuLjE8o8YCQUPLQwDKYOm lGKQ== X-Gm-Message-State: APf1xPDfcNkHO3nRLZxmi/7b9Nl6PETecddlZ6HEbSkawNnH1aRtP9N0 x5vSCZbzHwpK9kDtoen+gUiQ0msZ X-Received: by 10.80.214.206 with SMTP id l14mr3537933edj.44.1519402654548; Fri, 23 Feb 2018 08:17:34 -0800 (PST) Received: from mail-wr0-f173.google.com (mail-wr0-f173.google.com. [209.85.128.173]) by smtp.gmail.com with ESMTPSA id f19sm2671632edd.84.2018.02.23.08.17.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 08:17:33 -0800 (PST) Received: by mail-wr0-f173.google.com with SMTP id p104so14627443wrc.12; Fri, 23 Feb 2018 08:17:33 -0800 (PST) X-Received: by 10.223.152.73 with SMTP id v67mr2117670wrb.19.1519402653633; Fri, 23 Feb 2018 08:17:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.134.148 with HTTP; Fri, 23 Feb 2018 08:17:13 -0800 (PST) In-Reply-To: <20180223133742.26044-11-mylene.josserand@bootlin.com> References: <20180223133742.26044-1-mylene.josserand@bootlin.com> <20180223133742.26044-11-mylene.josserand@bootlin.com> From: Chen-Yu Tsai Date: Sat, 24 Feb 2018 00:17:13 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 10/10] ARM: sunxi: smp: Add initialization of CNTVOFF To: =?UTF-8?Q?Myl=C3=A8ne_Josserand?= Cc: Maxime Ripard , Russell King , Rob Herring , Mark Rutland , devicetree , linux-arm-kernel , linux-kernel , LABBE Corentin , Thomas Petazzoni , quentin.schulz@bootlin.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 23, 2018 at 9:37 PM, Mylène Josserand wrote: > On Cortex-A7, the CNTVOFF register from arch timer is uninitialized. > It should be done by the bootloader but it is currently not the case, > even for boot CPU because this SoC is booting in secure mode. > It leads to an random offset value meaning that each CPU will have a > different time, which isn't working very well. > > Add assembly code used for boot CPU and secondary CPU cores to make > sure that the CNTVOFF register is initialized. > > Signed-off-by: Mylène Josserand > --- > arch/arm/mach-sunxi/headsmp.S | 21 +++++++++++++++++++++ > arch/arm/mach-sunxi/sunxi.c | 4 ++++ > 2 files changed, 25 insertions(+) > > diff --git a/arch/arm/mach-sunxi/headsmp.S b/arch/arm/mach-sunxi/headsmp.S > index d5c97e945e69..605896251927 100644 > --- a/arch/arm/mach-sunxi/headsmp.S > +++ b/arch/arm/mach-sunxi/headsmp.S > @@ -65,9 +65,30 @@ ENTRY(sunxi_mc_smp_cluster_cache_enable) > first: .word sunxi_mc_smp_first_comer - . > ENDPROC(sunxi_mc_smp_cluster_cache_enable) > > +ENTRY(sunxi_init_cntvoff) > + /* > + * CNTVOFF has to be initialized either from non-secure Hypervisor > + * mode or secure Monitor mode with SCR.NS==1. If TrustZone is enabled > + * then it should be handled by the secure code > + */ > + cps #MON_MODE > + mrc p15, 0, r1, c1, c1, 0 /* Get Secure Config */ > + orr r0, r1, #1 > + mcr p15, 0, r0, c1, c1, 0 /* Set Non Secure bit */ > + instr_sync > + mov r0, #0 > + mcrr p15, 4, r0, r0, c14 /* CNTVOFF = 0 */ > + instr_sync > + mcr p15, 0, r1, c1, c1, 0 /* Set Secure bit */ > + instr_sync > + cps #SVC_MODE > + ret lr > +ENDPROC(sunxi_init_cntvoff) There is no need to move all the assembly into a separate file, just to add this function. Everything can be inlined as a naked function. The "instr_sync" macro can be replaced with "isb", which is what it expands to anyway. I really want to keep everything self-contained without global symbols, and in C files if possible. > + > #ifdef CONFIG_SMP > ENTRY(sunxi_boot) > bl sunxi_mc_smp_cluster_cache_enable > + bl sunxi_init_cntvoff > b secondary_startup > ENDPROC(sunxi_boot) > > diff --git a/arch/arm/mach-sunxi/sunxi.c b/arch/arm/mach-sunxi/sunxi.c > index 5e9602ce1573..4bb041492b54 100644 > --- a/arch/arm/mach-sunxi/sunxi.c > +++ b/arch/arm/mach-sunxi/sunxi.c > @@ -37,8 +37,12 @@ static const char * const sun6i_board_dt_compat[] = { > }; > > extern void __init sun6i_reset_init(void); > +extern void sunxi_init_cntvoff(void); > + > static void __init sun6i_timer_init(void) > { > + sunxi_init_cntvoff(); You should check the enable-method to see if PSCI is set or not, as an indicator whether the kernel is booted secure or non-secure. AFAIK trying to set CNTVOFF under non-secure would be very bad. Regards ChenYu > + > of_clk_init(NULL); > if (IS_ENABLED(CONFIG_RESET_CONTROLLER)) > sun6i_reset_init(); > -- > 2.11.0 >