blob: 9c53ea70550dc246f908434c0b68a3365e4f87e4 [file] [log] [blame]
Jeff Ohlsteine14411d2010-11-30 13:06:36 -08001/*
2 * Copyright (C) 2002 ARM Ltd.
3 * All Rights Reserved
4 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
Kumar Gala8fc1b0f2014-01-21 17:14:10 -06005 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
Jeff Ohlsteine14411d2010-11-30 13:06:36 -08006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/errno.h>
14#include <linux/delay.h>
15#include <linux/device.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080016#include <linux/smp.h>
17#include <linux/io.h>
18
Jeff Ohlstein41ff4452011-04-07 17:41:09 -070019#include <asm/cputype.h>
Will Deaconeb504392012-01-20 12:01:12 +010020#include <asm/smp_plat.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080021
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080022#include "scm-boot.h"
23
24#define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x15A0
25#define SCSS_CPU1CORE_RESET 0xD80
26#define SCSS_DBG_STATUS_CORE_PWRDUP 0xE64
27
Rohit Vaswani52b52b42013-06-21 12:17:37 -070028extern void secondary_startup(void);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080029
30static DEFINE_SPINLOCK(boot_lock);
31
Kumar Gala6a032db2014-01-31 13:48:29 -060032#ifdef CONFIG_HOTPLUG_CPU
Kumar Galacf1e8f02014-02-04 15:38:45 -060033static void __ref qcom_cpu_die(unsigned int cpu)
Kumar Gala6a032db2014-01-31 13:48:29 -060034{
35 wfi();
36}
37#endif
38
Jeff Ohlstein41ff4452011-04-07 17:41:09 -070039static inline int get_core_count(void)
40{
41 /* 1 + the PART[1:0] field of MIDR */
42 return ((read_cpuid_id() >> 4) & 3) + 1;
43}
44
Kumar Galacf1e8f02014-02-04 15:38:45 -060045static void qcom_secondary_init(unsigned int cpu)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080046{
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080047 /*
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080048 * Synchronise with the boot thread.
49 */
50 spin_lock(&boot_lock);
51 spin_unlock(&boot_lock);
52}
53
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040054static void prepare_cold_cpu(unsigned int cpu)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080055{
56 int ret;
Rohit Vaswani52b52b42013-06-21 12:17:37 -070057 ret = scm_set_boot_addr(virt_to_phys(secondary_startup),
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080058 SCM_FLAG_COLDBOOT_CPU1);
59 if (ret == 0) {
Stephen Boyd2b222a22011-09-19 10:54:04 -070060 void __iomem *sc1_base_ptr;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080061 sc1_base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
62 if (sc1_base_ptr) {
63 writel(0, sc1_base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
64 writel(0, sc1_base_ptr + SCSS_CPU1CORE_RESET);
65 writel(3, sc1_base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
66 iounmap(sc1_base_ptr);
67 }
68 } else
69 printk(KERN_DEBUG "Failed to set secondary core boot "
70 "address\n");
71}
72
Kumar Galacf1e8f02014-02-04 15:38:45 -060073static int qcom_boot_secondary(unsigned int cpu, struct task_struct *idle)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080074{
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080075 static int cold_boot_done;
76
77 /* Only need to bring cpu out of reset this way once */
78 if (cold_boot_done == false) {
79 prepare_cold_cpu(cpu);
80 cold_boot_done = true;
81 }
82
83 /*
84 * set synchronisation state between this boot processor
85 * and the secondary one
86 */
87 spin_lock(&boot_lock);
88
89 /*
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080090 * Send the secondary CPU a soft interrupt, thereby causing
91 * the boot monitor to read the system wide flags register,
92 * and branch to the address found there.
93 */
Rob Herringb1cffeb2012-11-26 15:05:48 -060094 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080095
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080096 /*
97 * now the secondary core is starting up let it run its
98 * calibrations, then wait for it to finish
99 */
100 spin_unlock(&boot_lock);
101
Rohit Vaswani52b52b42013-06-21 12:17:37 -0700102 return 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800103}
104
105/*
106 * Initialise the CPU possible map early - this describes the CPUs
107 * which may be present or become present in the system. The msm8x60
108 * does not support the ARM SCU, so just set the possible cpu mask to
109 * NR_CPUS.
110 */
Kumar Galacf1e8f02014-02-04 15:38:45 -0600111static void __init qcom_smp_init_cpus(void)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800112{
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700113 unsigned int i, ncores = get_core_count();
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800114
Russell Kinga06f9162011-10-20 22:04:18 +0100115 if (ncores > nr_cpu_ids) {
116 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
117 ncores, nr_cpu_ids);
118 ncores = nr_cpu_ids;
119 }
120
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700121 for (i = 0; i < ncores; i++)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800122 set_cpu_possible(i, true);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800123}
124
Kumar Galacf1e8f02014-02-04 15:38:45 -0600125static void __init qcom_smp_prepare_cpus(unsigned int max_cpus)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800126{
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800127}
Marc Zyngier44ea3492011-09-08 13:15:22 +0100128
Kumar Galacf1e8f02014-02-04 15:38:45 -0600129struct smp_operations qcom_smp_ops __initdata = {
130 .smp_init_cpus = qcom_smp_init_cpus,
131 .smp_prepare_cpus = qcom_smp_prepare_cpus,
132 .smp_secondary_init = qcom_secondary_init,
133 .smp_boot_secondary = qcom_boot_secondary,
Marc Zyngier44ea3492011-09-08 13:15:22 +0100134#ifdef CONFIG_HOTPLUG_CPU
Kumar Galacf1e8f02014-02-04 15:38:45 -0600135 .cpu_die = qcom_cpu_die,
Marc Zyngier44ea3492011-09-08 13:15:22 +0100136#endif
137};