Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * SMP support for SoCs with SCU covered by mach-shmobile
0004  *
0005  * Copyright (C) 2013  Magnus Damm
0006  */
0007 #include <linux/cpu.h>
0008 #include <linux/delay.h>
0009 #include <linux/init.h>
0010 #include <linux/io.h>
0011 #include <linux/smp.h>
0012 #include <asm/cacheflush.h>
0013 #include <asm/smp_plat.h>
0014 #include <asm/smp_scu.h>
0015 #include "common.h"
0016 
0017 
0018 static phys_addr_t shmobile_scu_base_phys;
0019 static void __iomem *shmobile_scu_base;
0020 
0021 static int shmobile_scu_cpu_prepare(unsigned int cpu)
0022 {
0023     /* For this particular CPU register SCU SMP boot vector */
0024     shmobile_smp_hook(cpu, __pa_symbol(shmobile_boot_scu),
0025               shmobile_scu_base_phys);
0026     return 0;
0027 }
0028 
0029 void __init shmobile_smp_scu_prepare_cpus(phys_addr_t scu_base_phys,
0030                       unsigned int max_cpus)
0031 {
0032     /* install boot code shared by all CPUs */
0033     shmobile_boot_fn = __pa_symbol(shmobile_smp_boot);
0034 
0035     /* enable SCU and cache coherency on booting CPU */
0036     shmobile_scu_base_phys = scu_base_phys;
0037     shmobile_scu_base = ioremap(scu_base_phys, PAGE_SIZE);
0038     scu_enable(shmobile_scu_base);
0039     scu_power_mode(shmobile_scu_base, SCU_PM_NORMAL);
0040 
0041     /* Use CPU notifier for reset vector control */
0042     cpuhp_setup_state_nocalls(CPUHP_ARM_SHMOBILE_SCU_PREPARE,
0043                   "arm/shmobile-scu:prepare",
0044                   shmobile_scu_cpu_prepare, NULL);
0045 }
0046 
0047 #ifdef CONFIG_HOTPLUG_CPU
0048 void shmobile_smp_scu_cpu_die(unsigned int cpu)
0049 {
0050     /* For this particular CPU deregister boot vector */
0051     shmobile_smp_hook(cpu, 0, 0);
0052 
0053     dsb();
0054     flush_cache_all();
0055 
0056     /* disable cache coherency */
0057     scu_power_mode(shmobile_scu_base, SCU_PM_POWEROFF);
0058 
0059     /* jump to shared mach-shmobile sleep / reset code */
0060     shmobile_smp_sleep();
0061 }
0062 
0063 static int shmobile_smp_scu_psr_core_disabled(int cpu)
0064 {
0065     unsigned long mask = SCU_PM_POWEROFF << (cpu * 8);
0066 
0067     if ((readl(shmobile_scu_base + 8) & mask) == mask)
0068         return 1;
0069 
0070     return 0;
0071 }
0072 
0073 int shmobile_smp_scu_cpu_kill(unsigned int cpu)
0074 {
0075     int k;
0076 
0077     /* this function is running on another CPU than the offline target,
0078      * here we need wait for shutdown code in platform_cpu_die() to
0079      * finish before asking SoC-specific code to power off the CPU core.
0080      */
0081     for (k = 0; k < 1000; k++) {
0082         if (shmobile_smp_scu_psr_core_disabled(cpu))
0083             return 1;
0084 
0085         mdelay(1);
0086     }
0087 
0088     return 0;
0089 }
0090 #endif