2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * Copyright (C) 2013 ARM Limited
16 #define pr_fmt(fmt) "psci: " fmt
18 #include <linux/init.h>
20 #include <linux/smp.h>
21 #include <linux/delay.h>
22 #include <linux/psci.h>
25 #include <uapi/linux/psci.h>
27 #include <asm/compiler.h>
28 #include <asm/cpu_ops.h>
29 #include <asm/errno.h>
30 #include <asm/smp_plat.h>
32 static int __init cpu_psci_cpu_init(unsigned int cpu)
37 static int __init cpu_psci_cpu_prepare(unsigned int cpu)
39 if (!psci_ops.cpu_on) {
40 pr_err("no cpu_on method, not booting CPU%d\n", cpu);
47 static int cpu_psci_cpu_boot(unsigned int cpu)
49 int err = psci_ops.cpu_on(cpu_logical_map(cpu), __pa_symbol(secondary_entry));
51 pr_err("failed to boot CPU%d (%d)\n", cpu, err);
56 #ifdef CONFIG_HOTPLUG_CPU
57 static int cpu_psci_cpu_disable(unsigned int cpu)
59 /* Fail early if we don't have CPU_OFF support */
60 if (!psci_ops.cpu_off)
63 /* Trusted OS will deny CPU_OFF */
64 if (psci_tos_resident_on(cpu))
70 static void cpu_psci_cpu_die(unsigned int cpu)
74 * There are no known implementations of PSCI actually using the
75 * power state field, pass a sensible default for now.
77 u32 state = PSCI_POWER_STATE_TYPE_POWER_DOWN <<
78 PSCI_0_2_POWER_STATE_TYPE_SHIFT;
80 ret = psci_ops.cpu_off(state);
82 pr_crit("unable to power off CPU%u (%d)\n", cpu, ret);
85 static int cpu_psci_cpu_kill(unsigned int cpu)
89 if (!psci_ops.affinity_info)
92 * cpu_kill could race with cpu_die and we can
93 * potentially end up declaring this cpu undead
94 * while it is dying. So, try again a few times.
97 for (i = 0; i < 10; i++) {
98 err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
99 if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
100 pr_info("CPU%d killed.\n", cpu);
105 pr_info("Retrying again to check for CPU kill\n");
108 pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
114 const struct cpu_operations cpu_psci_ops = {
116 #ifdef CONFIG_CPU_IDLE
117 .cpu_init_idle = psci_cpu_init_idle,
118 .cpu_suspend = psci_cpu_suspend_enter,
120 .cpu_init = cpu_psci_cpu_init,
121 .cpu_prepare = cpu_psci_cpu_prepare,
122 .cpu_boot = cpu_psci_cpu_boot,
123 #ifdef CONFIG_HOTPLUG_CPU
124 .cpu_disable = cpu_psci_cpu_disable,
125 .cpu_die = cpu_psci_cpu_die,
126 .cpu_kill = cpu_psci_cpu_kill,