Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 2 | /** |
| 3 | * (C) Copyright 2014, Cavium Inc. |
Michal Simek | 9778d9d | 2017-05-29 09:11:32 +0200 | [diff] [blame] | 4 | * (C) Copyright 2017, Xilinx Inc. |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 5 | * |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 6 | **/ |
| 7 | |
| 8 | #include <asm-offsets.h> |
| 9 | #include <config.h> |
| 10 | #include <version.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <asm/cache.h> |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 12 | #include <asm/macro.h> |
Beniamino Galvani | b8845e1 | 2016-05-08 08:30:14 +0200 | [diff] [blame] | 13 | #include <asm/psci.h> |
Simon Glass | 1e26864 | 2020-05-10 11:39:55 -0600 | [diff] [blame] | 14 | #include <asm/ptrace.h> |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 15 | #include <asm/system.h> |
| 16 | |
| 17 | /* |
| 18 | * Issue the hypervisor call |
| 19 | * |
| 20 | * x0~x7: input arguments |
| 21 | * x0~x3: output arguments |
| 22 | */ |
Heinrich Schuchardt | 26f09d0 | 2018-10-18 12:29:40 +0200 | [diff] [blame] | 23 | static void hvc_call(struct pt_regs *args) |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 24 | { |
| 25 | asm volatile( |
| 26 | "ldr x0, %0\n" |
| 27 | "ldr x1, %1\n" |
| 28 | "ldr x2, %2\n" |
| 29 | "ldr x3, %3\n" |
| 30 | "ldr x4, %4\n" |
| 31 | "ldr x5, %5\n" |
| 32 | "ldr x6, %6\n" |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 33 | "hvc #0\n" |
| 34 | "str x0, %0\n" |
| 35 | "str x1, %1\n" |
| 36 | "str x2, %2\n" |
| 37 | "str x3, %3\n" |
| 38 | : "+m" (args->regs[0]), "+m" (args->regs[1]), |
| 39 | "+m" (args->regs[2]), "+m" (args->regs[3]) |
| 40 | : "m" (args->regs[4]), "m" (args->regs[5]), |
Ibai Erkiaga | b0b5b9f | 2019-02-25 10:11:45 +0000 | [diff] [blame] | 41 | "m" (args->regs[6]) |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 42 | : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
| 43 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", |
| 44 | "x16", "x17"); |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * void smc_call(arg0, arg1...arg7) |
| 49 | * |
| 50 | * issue the secure monitor call |
| 51 | * |
| 52 | * x0~x7: input arguments |
| 53 | * x0~x3: output arguments |
| 54 | */ |
| 55 | |
Heinrich Schuchardt | 26f09d0 | 2018-10-18 12:29:40 +0200 | [diff] [blame] | 56 | void smc_call(struct pt_regs *args) |
Sergey Temerkhanov | 064949c | 2015-10-14 09:55:46 -0700 | [diff] [blame] | 57 | { |
| 58 | asm volatile( |
| 59 | "ldr x0, %0\n" |
| 60 | "ldr x1, %1\n" |
| 61 | "ldr x2, %2\n" |
| 62 | "ldr x3, %3\n" |
| 63 | "ldr x4, %4\n" |
| 64 | "ldr x5, %5\n" |
| 65 | "ldr x6, %6\n" |
| 66 | "smc #0\n" |
| 67 | "str x0, %0\n" |
| 68 | "str x1, %1\n" |
| 69 | "str x2, %2\n" |
| 70 | "str x3, %3\n" |
| 71 | : "+m" (args->regs[0]), "+m" (args->regs[1]), |
| 72 | "+m" (args->regs[2]), "+m" (args->regs[3]) |
| 73 | : "m" (args->regs[4]), "m" (args->regs[5]), |
| 74 | "m" (args->regs[6]) |
| 75 | : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", |
| 76 | "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", |
| 77 | "x16", "x17"); |
| 78 | } |
Beniamino Galvani | b8845e1 | 2016-05-08 08:30:14 +0200 | [diff] [blame] | 79 | |
Alexander Graf | a5b1832 | 2016-08-16 21:08:46 +0200 | [diff] [blame] | 80 | /* |
| 81 | * For now, all systems we support run at least in EL2 and thus |
| 82 | * trigger PSCI calls to EL3 using SMC. If anyone ever wants to |
| 83 | * use PSCI on U-Boot running below a hypervisor, please detect |
| 84 | * this and set the flag accordingly. |
| 85 | */ |
Heinrich Schuchardt | 26f09d0 | 2018-10-18 12:29:40 +0200 | [diff] [blame] | 86 | static const bool use_smc_for_psci = true; |
Alexander Graf | a5b1832 | 2016-08-16 21:08:46 +0200 | [diff] [blame] | 87 | |
Heinrich Schuchardt | 26f09d0 | 2018-10-18 12:29:40 +0200 | [diff] [blame] | 88 | void __noreturn psci_system_reset(void) |
Beniamino Galvani | b8845e1 | 2016-05-08 08:30:14 +0200 | [diff] [blame] | 89 | { |
| 90 | struct pt_regs regs; |
| 91 | |
| 92 | regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_RESET; |
| 93 | |
Alexander Graf | a5b1832 | 2016-08-16 21:08:46 +0200 | [diff] [blame] | 94 | if (use_smc_for_psci) |
Beniamino Galvani | b8845e1 | 2016-05-08 08:30:14 +0200 | [diff] [blame] | 95 | smc_call(®s); |
| 96 | else |
| 97 | hvc_call(®s); |
| 98 | |
| 99 | while (1) |
| 100 | ; |
| 101 | } |
Alexander Graf | 467c83e | 2016-08-16 21:08:47 +0200 | [diff] [blame] | 102 | |
Rajesh Ravi | 45bbe71 | 2019-11-22 14:50:01 -0800 | [diff] [blame] | 103 | void __noreturn psci_system_reset2(u32 reset_level, u32 cookie) |
| 104 | { |
| 105 | struct pt_regs regs; |
| 106 | |
| 107 | regs.regs[0] = ARM_PSCI_0_2_FN64_SYSTEM_RESET2; |
| 108 | regs.regs[1] = PSCI_RESET2_TYPE_VENDOR | reset_level; |
| 109 | regs.regs[2] = cookie; |
| 110 | if (use_smc_for_psci) |
| 111 | smc_call(®s); |
| 112 | else |
| 113 | hvc_call(®s); |
| 114 | |
| 115 | while (1) |
| 116 | ; |
| 117 | } |
| 118 | |
Heinrich Schuchardt | 26f09d0 | 2018-10-18 12:29:40 +0200 | [diff] [blame] | 119 | void __noreturn psci_system_off(void) |
Alexander Graf | 467c83e | 2016-08-16 21:08:47 +0200 | [diff] [blame] | 120 | { |
| 121 | struct pt_regs regs; |
| 122 | |
| 123 | regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_OFF; |
| 124 | |
| 125 | if (use_smc_for_psci) |
| 126 | smc_call(®s); |
| 127 | else |
| 128 | hvc_call(®s); |
| 129 | |
| 130 | while (1) |
| 131 | ; |
| 132 | } |