[PATCH V6] ARM: mach-shmobile: Don't init CNTVOFF/counter if PSCI is available

From: Oleksandr Tyshchenko
Date: Wed May 29 2019 - 12:08:48 EST


From: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>

If PSCI is available then most likely we are running on PSCI-enabled
U-Boot which, we assume, has already taken care of resetting CNTVOFF
and updating counter module before switching to non-secure mode
and we don't need to.

As the psci_smp_available() helper always returns false if CONFIG_SMP
is disabled, it can't be used safely as an indicator of PSCI usage.
For that reason, we check for the mandatory PSCI operation to be
available.

Please note, an extra check to prevent secure_cntvoff_init() from
being called for secondary CPUs in headsmp-apmu.S is not needed,
as SMP code for APMU based system is not executed if PSCI is in use.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
CC: Julien Grall <julien.grall@xxxxxxx>
Reviewed-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>

---
You can find previous discussions here:
[v1] https://lkml.org/lkml/2019/4/17/810
[v2] https://lkml.org/lkml/2019/5/3/338
[v3] https://lkml.org/lkml/2019/5/10/415
[RFC] https://lkml.org/lkml/2019/5/10/473
[v4] https://lkml.org/lkml/2019/5/14/550
[v5] https://lkml.org/lkml/2019/5/17/219

Changes in v2:
- Clarify patch subject/description
- Don't use CONFIG_ARM_PSCI option, check whether the PSCI is available,
by using psci_smp_available()
- Check whether we are running on top of Xen, by using xen_domain()

Changes in v3:
- Don't check for the presence of Xen

Changes in v4:
- Don't use psci_smp_available() helper, check for psci_ops.cpu_on
directly
- Skip updating counter module if PSCI is available

Changes in v5:
- Check for psci_ops.cpu_on if CONFIG_ARM_PSCI_FW is defined

Changes in v6:
- Use reverse Xmas tree declaration order
- Use #ifdef instead of #if defined()
- Add Geert's R-b
---
arch/arm/mach-shmobile/setup-rcar-gen2.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c
index eea60b2..9e4bc18 100644
--- a/arch/arm/mach-shmobile/setup-rcar-gen2.c
+++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c
@@ -17,6 +17,7 @@
#include <linux/of.h>
#include <linux/of_fdt.h>
#include <linux/of_platform.h>
+#include <linux/psci.h>
#include <asm/mach/arch.h>
#include <asm/secure_cntvoff.h>
#include "common.h"
@@ -60,9 +61,24 @@ static unsigned int __init get_extal_freq(void)

void __init rcar_gen2_timer_init(void)
{
+ bool need_update = true;
void __iomem *base;
u32 freq;

+ /*
+ * If PSCI is available then most likely we are running on PSCI-enabled
+ * U-Boot which, we assume, has already taken care of resetting CNTVOFF
+ * and updating counter module before switching to non-secure mode
+ * and we don't need to.
+ */
+#ifdef CONFIG_ARM_PSCI_FW
+ if (psci_ops.cpu_on)
+ need_update = false;
+#endif
+
+ if (need_update == false)
+ goto skip_update;
+
secure_cntvoff_init();

if (of_machine_is_compatible("renesas,r8a7745") ||
@@ -102,6 +118,7 @@ void __init rcar_gen2_timer_init(void)

iounmap(base);

+skip_update:
of_clk_init(NULL);
timer_probe();
}
--
2.7.4