smccc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2018
  4. * Michalis Pappas <mpappas@fastmail.fm>
  5. */
  6. #include <asm/psci.h>
  7. #include <common.h>
  8. #include <command.h>
  9. #include <linux/arm-smccc.h>
  10. #include <linux/compiler.h>
  11. #include <linux/psci.h>
  12. static int do_call(struct cmd_tbl *cmdtp, int flag, int argc,
  13. char *const argv[])
  14. {
  15. struct arm_smccc_res res;
  16. unsigned long fid;
  17. unsigned long a1;
  18. unsigned long a2;
  19. unsigned long a3;
  20. unsigned long a4;
  21. unsigned long a5;
  22. unsigned long a6;
  23. unsigned long a7;
  24. if (argc < 2)
  25. return CMD_RET_USAGE;
  26. fid = hextoul(argv[1], NULL);
  27. a1 = argc > 2 ? hextoul(argv[2], NULL) : 0;
  28. a2 = argc > 3 ? hextoul(argv[3], NULL) : 0;
  29. a3 = argc > 4 ? hextoul(argv[4], NULL) : 0;
  30. a4 = argc > 5 ? hextoul(argv[5], NULL) : 0;
  31. a5 = argc > 6 ? hextoul(argv[6], NULL) : 0;
  32. a6 = argc > 7 ? hextoul(argv[7], NULL) : 0;
  33. a7 = argc > 8 ? hextoul(argv[8], NULL) : 0;
  34. if (!strcmp(argv[0], "smc"))
  35. arm_smccc_smc(fid, a1, a2, a3, a4, a5, a6, a7, &res);
  36. else
  37. arm_smccc_hvc(fid, a1, a2, a3, a4, a5, a6, a7, &res);
  38. printf("Res: %ld %ld %ld %ld\n", res.a0, res.a1, res.a2, res.a3);
  39. return 0;
  40. }
  41. #ifdef CONFIG_CMD_SMC
  42. U_BOOT_CMD(
  43. smc, 9, 2, do_call,
  44. "Issue a Secure Monitor Call",
  45. "<fid> [arg1 ... arg6] [id]\n"
  46. " - fid Function ID\n"
  47. " - arg SMC arguments, passed to X1-X6 (default to zero)\n"
  48. " - id Secure OS ID / Session ID, passed to W7 (defaults to zero)\n"
  49. );
  50. #endif
  51. #ifdef CONFIG_CMD_HVC
  52. U_BOOT_CMD(
  53. hvc, 9, 2, do_call,
  54. "Issue a Hypervisor Call",
  55. "<fid> [arg1...arg6] [id]\n"
  56. " - fid Function ID\n"
  57. " - arg HVC arguments, passed to X1-X6 (default to zero)\n"
  58. " - id Session ID, passed to W7 (defaults to zero)\n"
  59. );
  60. #endif