Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 |
| 4 | * Michalis Pappas <mpappas@fastmail.fm> |
| 5 | */ |
| 6 | #include <asm/psci.h> |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 7 | #include <command.h> |
Tom Rini | 5c1444f | 2024-04-27 08:10:59 -0600 | [diff] [blame] | 8 | #include <vsprintf.h> |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 9 | #include <linux/arm-smccc.h> |
| 10 | #include <linux/compiler.h> |
| 11 | #include <linux/psci.h> |
| 12 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 13 | static int do_call(struct cmd_tbl *cmdtp, int flag, int argc, |
| 14 | char *const argv[]) |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 15 | { |
| 16 | struct arm_smccc_res res; |
| 17 | |
| 18 | unsigned long fid; |
| 19 | |
| 20 | unsigned long a1; |
| 21 | unsigned long a2; |
| 22 | unsigned long a3; |
| 23 | unsigned long a4; |
| 24 | unsigned long a5; |
| 25 | unsigned long a6; |
| 26 | unsigned long a7; |
| 27 | |
| 28 | if (argc < 2) |
| 29 | return CMD_RET_USAGE; |
| 30 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 31 | fid = hextoul(argv[1], NULL); |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 32 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 33 | a1 = argc > 2 ? hextoul(argv[2], NULL) : 0; |
| 34 | a2 = argc > 3 ? hextoul(argv[3], NULL) : 0; |
| 35 | a3 = argc > 4 ? hextoul(argv[4], NULL) : 0; |
| 36 | a4 = argc > 5 ? hextoul(argv[5], NULL) : 0; |
| 37 | a5 = argc > 6 ? hextoul(argv[6], NULL) : 0; |
| 38 | a6 = argc > 7 ? hextoul(argv[7], NULL) : 0; |
| 39 | a7 = argc > 8 ? hextoul(argv[8], NULL) : 0; |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 40 | |
| 41 | if (!strcmp(argv[0], "smc")) |
| 42 | arm_smccc_smc(fid, a1, a2, a3, a4, a5, a6, a7, &res); |
| 43 | else |
| 44 | arm_smccc_hvc(fid, a1, a2, a3, a4, a5, a6, a7, &res); |
| 45 | |
Michal Simek | f4e197f | 2023-02-15 09:45:21 +0100 | [diff] [blame] | 46 | printf("Res: 0x%lx 0x%lx 0x%lx 0x%lx\n", res.a0, res.a1, res.a2, res.a3); |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | #ifdef CONFIG_CMD_SMC |
| 52 | U_BOOT_CMD( |
Siew Chin Lim | 6aa0714 | 2021-07-15 12:38:54 +0800 | [diff] [blame] | 53 | smc, 9, 2, do_call, |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 54 | "Issue a Secure Monitor Call", |
| 55 | "<fid> [arg1 ... arg6] [id]\n" |
| 56 | " - fid Function ID\n" |
| 57 | " - arg SMC arguments, passed to X1-X6 (default to zero)\n" |
| 58 | " - id Secure OS ID / Session ID, passed to W7 (defaults to zero)\n" |
| 59 | ); |
| 60 | #endif |
| 61 | |
| 62 | #ifdef CONFIG_CMD_HVC |
| 63 | U_BOOT_CMD( |
Siew Chin Lim | 6aa0714 | 2021-07-15 12:38:54 +0800 | [diff] [blame] | 64 | hvc, 9, 2, do_call, |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 65 | "Issue a Hypervisor Call", |
Siew Chin Lim | 6aa0714 | 2021-07-15 12:38:54 +0800 | [diff] [blame] | 66 | "<fid> [arg1...arg6] [id]\n" |
Michalis Pappas | d382d22 | 2018-04-13 10:40:57 +0300 | [diff] [blame] | 67 | " - fid Function ID\n" |
| 68 | " - arg HVC arguments, passed to X1-X6 (default to zero)\n" |
| 69 | " - id Session ID, passed to W7 (defaults to zero)\n" |
| 70 | ); |
| 71 | #endif |