Fix: Restartable Sequences: testing: ip-relative x86-64
[deliverable/linux.git] / arch / arm64 / kernel / psci.c
CommitLineData
e790f1de
WD
1/*
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.
5 *
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.
10 *
11 * Copyright (C) 2013 ARM Limited
12 *
13 * Author: Will Deacon <will.deacon@arm.com>
14 */
15
16#define pr_fmt(fmt) "psci: " fmt
17
18#include <linux/init.h>
19#include <linux/of.h>
00ef54bb 20#include <linux/smp.h>
c814ca02 21#include <linux/delay.h>
bff60792 22#include <linux/psci.h>
bff60792 23
e71246a2 24#include <uapi/linux/psci.h>
e790f1de
WD
25
26#include <asm/compiler.h>
cd1aebf5 27#include <asm/cpu_ops.h>
e790f1de 28#include <asm/errno.h>
00ef54bb 29#include <asm/smp_plat.h>
18910ab0 30
819a8826 31static int __init cpu_psci_cpu_init(unsigned int cpu)
00ef54bb
MR
32{
33 return 0;
34}
35
cd1aebf5 36static int __init cpu_psci_cpu_prepare(unsigned int cpu)
00ef54bb 37{
00ef54bb
MR
38 if (!psci_ops.cpu_on) {
39 pr_err("no cpu_on method, not booting CPU%d\n", cpu);
40 return -ENODEV;
41 }
42
00ef54bb
MR
43 return 0;
44}
45
652af899
MR
46static int cpu_psci_cpu_boot(unsigned int cpu)
47{
48 int err = psci_ops.cpu_on(cpu_logical_map(cpu), __pa(secondary_entry));
49 if (err)
288ac26c 50 pr_err("failed to boot CPU%d (%d)\n", cpu, err);
652af899
MR
51
52 return err;
53}
54
831ccf79
MR
55#ifdef CONFIG_HOTPLUG_CPU
56static int cpu_psci_cpu_disable(unsigned int cpu)
57{
58 /* Fail early if we don't have CPU_OFF support */
59 if (!psci_ops.cpu_off)
60 return -EOPNOTSUPP;
ff3010e6
MR
61
62 /* Trusted OS will deny CPU_OFF */
63 if (psci_tos_resident_on(cpu))
64 return -EPERM;
65
831ccf79
MR
66 return 0;
67}
68
69static void cpu_psci_cpu_die(unsigned int cpu)
70{
71 int ret;
72 /*
73 * There are no known implementations of PSCI actually using the
74 * power state field, pass a sensible default for now.
75 */
c8cc4273
MR
76 u32 state = PSCI_POWER_STATE_TYPE_POWER_DOWN <<
77 PSCI_0_2_POWER_STATE_TYPE_SHIFT;
831ccf79
MR
78
79 ret = psci_ops.cpu_off(state);
80
288ac26c 81 pr_crit("unable to power off CPU%u (%d)\n", cpu, ret);
831ccf79 82}
c814ca02
AC
83
84static int cpu_psci_cpu_kill(unsigned int cpu)
85{
86 int err, i;
87
88 if (!psci_ops.affinity_info)
6b99c68c 89 return 0;
c814ca02
AC
90 /*
91 * cpu_kill could race with cpu_die and we can
92 * potentially end up declaring this cpu undead
93 * while it is dying. So, try again a few times.
94 */
95
96 for (i = 0; i < 10; i++) {
97 err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
98 if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
99 pr_info("CPU%d killed.\n", cpu);
6b99c68c 100 return 0;
c814ca02
AC
101 }
102
103 msleep(10);
104 pr_info("Retrying again to check for CPU kill\n");
105 }
106
107 pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
108 cpu, err);
6b99c68c 109 return -ETIMEDOUT;
c814ca02 110}
831ccf79
MR
111#endif
112
cd1aebf5 113const struct cpu_operations cpu_psci_ops = {
00ef54bb 114 .name = "psci",
18910ab0 115#ifdef CONFIG_CPU_IDLE
8b6f2499
LP
116 .cpu_init_idle = psci_cpu_init_idle,
117 .cpu_suspend = psci_cpu_suspend_enter,
18910ab0 118#endif
cd1aebf5
MR
119 .cpu_init = cpu_psci_cpu_init,
120 .cpu_prepare = cpu_psci_cpu_prepare,
652af899 121 .cpu_boot = cpu_psci_cpu_boot,
831ccf79
MR
122#ifdef CONFIG_HOTPLUG_CPU
123 .cpu_disable = cpu_psci_cpu_disable,
124 .cpu_die = cpu_psci_cpu_die,
c814ca02 125 .cpu_kill = cpu_psci_cpu_kill,
831ccf79 126#endif
00ef54bb
MR
127};
128
This page took 0.20708 seconds and 5 git commands to generate.