blob: 16914dc1eed6cd56c5213288b70f55d30e24fa8c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sergey Temerkhanov064949c2015-10-14 09:55:46 -07002/**
3 * (C) Copyright 2014, Cavium Inc.
Michal Simek9778d9d2017-05-29 09:11:32 +02004 * (C) Copyright 2017, Xilinx Inc.
Sergey Temerkhanov064949c2015-10-14 09:55:46 -07005 *
Sergey Temerkhanov064949c2015-10-14 09:55:46 -07006**/
7
8#include <asm-offsets.h>
9#include <config.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Sergey Temerkhanov064949c2015-10-14 09:55:46 -070011#include <asm/macro.h>
Beniamino Galvanib8845e12016-05-08 08:30:14 +020012#include <asm/psci.h>
Simon Glass1e268642020-05-10 11:39:55 -060013#include <asm/ptrace.h>
Sergey Temerkhanov064949c2015-10-14 09:55:46 -070014#include <asm/system.h>
15
16/*
17 * Issue the hypervisor call
18 *
19 * x0~x7: input arguments
20 * x0~x3: output arguments
21 */
Heinrich Schuchardt26f09d02018-10-18 12:29:40 +020022static void hvc_call(struct pt_regs *args)
Sergey Temerkhanov064949c2015-10-14 09:55:46 -070023{
24 asm volatile(
25 "ldr x0, %0\n"
26 "ldr x1, %1\n"
27 "ldr x2, %2\n"
28 "ldr x3, %3\n"
29 "ldr x4, %4\n"
30 "ldr x5, %5\n"
31 "ldr x6, %6\n"
Sergey Temerkhanov064949c2015-10-14 09:55:46 -070032 "hvc #0\n"
33 "str x0, %0\n"
34 "str x1, %1\n"
35 "str x2, %2\n"
36 "str x3, %3\n"
37 : "+m" (args->regs[0]), "+m" (args->regs[1]),
38 "+m" (args->regs[2]), "+m" (args->regs[3])
39 : "m" (args->regs[4]), "m" (args->regs[5]),
Ibai Erkiagab0b5b9f2019-02-25 10:11:45 +000040 "m" (args->regs[6])
Sergey Temerkhanov064949c2015-10-14 09:55:46 -070041 : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
42 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
43 "x16", "x17");
44}
45
46/*
47 * void smc_call(arg0, arg1...arg7)
48 *
49 * issue the secure monitor call
50 *
51 * x0~x7: input arguments
52 * x0~x3: output arguments
53 */
54
Heinrich Schuchardt26f09d02018-10-18 12:29:40 +020055void smc_call(struct pt_regs *args)
Sergey Temerkhanov064949c2015-10-14 09:55:46 -070056{
57 asm volatile(
58 "ldr x0, %0\n"
59 "ldr x1, %1\n"
60 "ldr x2, %2\n"
61 "ldr x3, %3\n"
62 "ldr x4, %4\n"
63 "ldr x5, %5\n"
64 "ldr x6, %6\n"
65 "smc #0\n"
66 "str x0, %0\n"
67 "str x1, %1\n"
68 "str x2, %2\n"
69 "str x3, %3\n"
70 : "+m" (args->regs[0]), "+m" (args->regs[1]),
71 "+m" (args->regs[2]), "+m" (args->regs[3])
72 : "m" (args->regs[4]), "m" (args->regs[5]),
73 "m" (args->regs[6])
74 : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
75 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
76 "x16", "x17");
77}
Beniamino Galvanib8845e12016-05-08 08:30:14 +020078
Alexander Grafa5b18322016-08-16 21:08:46 +020079/*
80 * For now, all systems we support run at least in EL2 and thus
81 * trigger PSCI calls to EL3 using SMC. If anyone ever wants to
82 * use PSCI on U-Boot running below a hypervisor, please detect
83 * this and set the flag accordingly.
84 */
Heinrich Schuchardt26f09d02018-10-18 12:29:40 +020085static const bool use_smc_for_psci = true;
Alexander Grafa5b18322016-08-16 21:08:46 +020086
Heinrich Schuchardt26f09d02018-10-18 12:29:40 +020087void __noreturn psci_system_reset(void)
Beniamino Galvanib8845e12016-05-08 08:30:14 +020088{
89 struct pt_regs regs;
90
91 regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_RESET;
92
Alexander Grafa5b18322016-08-16 21:08:46 +020093 if (use_smc_for_psci)
Beniamino Galvanib8845e12016-05-08 08:30:14 +020094 smc_call(&regs);
95 else
96 hvc_call(&regs);
97
98 while (1)
99 ;
100}
Alexander Graf467c83e2016-08-16 21:08:47 +0200101
Rajesh Ravi45bbe712019-11-22 14:50:01 -0800102void __noreturn psci_system_reset2(u32 reset_level, u32 cookie)
103{
104 struct pt_regs regs;
105
106 regs.regs[0] = ARM_PSCI_0_2_FN64_SYSTEM_RESET2;
107 regs.regs[1] = PSCI_RESET2_TYPE_VENDOR | reset_level;
108 regs.regs[2] = cookie;
109 if (use_smc_for_psci)
110 smc_call(&regs);
111 else
112 hvc_call(&regs);
113
114 while (1)
115 ;
116}
117
Heinrich Schuchardt26f09d02018-10-18 12:29:40 +0200118void __noreturn psci_system_off(void)
Alexander Graf467c83e2016-08-16 21:08:47 +0200119{
120 struct pt_regs regs;
121
122 regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_OFF;
123
124 if (use_smc_for_psci)
125 smc_call(&regs);
126 else
127 hvc_call(&regs);
128
129 while (1)
130 ;
131}