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