Merge tag 'for-linus-20190706' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / arch / arm64 / kernel / psci.c
blob85ee7d07889e785c6128a09e1b04dbe5639695eb
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
4 * Copyright (C) 2013 ARM Limited
6 * Author: Will Deacon <will.deacon@arm.com>
7 */
9 #define pr_fmt(fmt) "psci: " fmt
11 #include <linux/init.h>
12 #include <linux/of.h>
13 #include <linux/smp.h>
14 #include <linux/delay.h>
15 #include <linux/psci.h>
16 #include <linux/mm.h>
18 #include <uapi/linux/psci.h>
20 #include <asm/cpu_ops.h>
21 #include <asm/errno.h>
22 #include <asm/smp_plat.h>
24 static int __init cpu_psci_cpu_init(unsigned int cpu)
26 return 0;
29 static int __init cpu_psci_cpu_prepare(unsigned int cpu)
31 if (!psci_ops.cpu_on) {
32 pr_err("no cpu_on method, not booting CPU%d\n", cpu);
33 return -ENODEV;
36 return 0;
39 static int cpu_psci_cpu_boot(unsigned int cpu)
41 int err = psci_ops.cpu_on(cpu_logical_map(cpu), __pa_symbol(secondary_entry));
42 if (err)
43 pr_err("failed to boot CPU%d (%d)\n", cpu, err);
45 return err;
48 #ifdef CONFIG_HOTPLUG_CPU
49 static int cpu_psci_cpu_disable(unsigned int cpu)
51 /* Fail early if we don't have CPU_OFF support */
52 if (!psci_ops.cpu_off)
53 return -EOPNOTSUPP;
55 /* Trusted OS will deny CPU_OFF */
56 if (psci_tos_resident_on(cpu))
57 return -EPERM;
59 return 0;
62 static void cpu_psci_cpu_die(unsigned int cpu)
64 int ret;
66 * There are no known implementations of PSCI actually using the
67 * power state field, pass a sensible default for now.
69 u32 state = PSCI_POWER_STATE_TYPE_POWER_DOWN <<
70 PSCI_0_2_POWER_STATE_TYPE_SHIFT;
72 ret = psci_ops.cpu_off(state);
74 pr_crit("unable to power off CPU%u (%d)\n", cpu, ret);
77 static int cpu_psci_cpu_kill(unsigned int cpu)
79 int err, i;
81 if (!psci_ops.affinity_info)
82 return 0;
84 * cpu_kill could race with cpu_die and we can
85 * potentially end up declaring this cpu undead
86 * while it is dying. So, try again a few times.
89 for (i = 0; i < 10; i++) {
90 err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
91 if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
92 pr_info("CPU%d killed.\n", cpu);
93 return 0;
96 msleep(10);
97 pr_info("Retrying again to check for CPU kill\n");
100 pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
101 cpu, err);
102 return -ETIMEDOUT;
104 #endif
106 const struct cpu_operations cpu_psci_ops = {
107 .name = "psci",
108 #ifdef CONFIG_CPU_IDLE
109 .cpu_init_idle = psci_cpu_init_idle,
110 .cpu_suspend = psci_cpu_suspend_enter,
111 #endif
112 .cpu_init = cpu_psci_cpu_init,
113 .cpu_prepare = cpu_psci_cpu_prepare,
114 .cpu_boot = cpu_psci_cpu_boot,
115 #ifdef CONFIG_HOTPLUG_CPU
116 .cpu_disable = cpu_psci_cpu_disable,
117 .cpu_die = cpu_psci_cpu_die,
118 .cpu_kill = cpu_psci_cpu_kill,
119 #endif