arm_arch_svc_setup.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arm_arch_svc.h>
  7. #include <debug.h>
  8. #include <errata_report.h>
  9. #include <runtime_svc.h>
  10. #include <smcc.h>
  11. #include <smcc_helpers.h>
  12. #include <workaround_cve_2017_5715.h>
  13. static int32_t smccc_version(void)
  14. {
  15. return MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION);
  16. }
  17. static int32_t smccc_arch_features(u_register_t arg)
  18. {
  19. int ret;
  20. switch (arg) {
  21. case SMCCC_VERSION:
  22. case SMCCC_ARCH_FEATURES:
  23. return SMC_OK;
  24. case SMCCC_ARCH_WORKAROUND_1:
  25. ret = check_workaround_cve_2017_5715();
  26. if (ret == ERRATA_APPLIES)
  27. return 0;
  28. else if (ret == ERRATA_NOT_APPLIES)
  29. return 1;
  30. return -1; /* ERRATA_MISSING */
  31. default:
  32. return SMC_UNK;
  33. }
  34. }
  35. /*
  36. * Top-level Arm Architectural Service SMC handler.
  37. */
  38. static uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid,
  39. u_register_t x1,
  40. u_register_t x2,
  41. u_register_t x3,
  42. u_register_t x4,
  43. void *cookie,
  44. void *handle,
  45. u_register_t flags)
  46. {
  47. switch (smc_fid) {
  48. case SMCCC_VERSION:
  49. SMC_RET1(handle, smccc_version());
  50. case SMCCC_ARCH_FEATURES:
  51. SMC_RET1(handle, smccc_arch_features(x1));
  52. #if WORKAROUND_CVE_2017_5715
  53. case SMCCC_ARCH_WORKAROUND_1:
  54. /*
  55. * The workaround has already been applied on affected PEs
  56. * during entry to EL3. On unaffected PEs, this function
  57. * has no effect.
  58. */
  59. SMC_RET0(handle);
  60. #endif
  61. default:
  62. WARN("Unimplemented Arm Architecture Service Call: 0x%x \n",
  63. smc_fid);
  64. SMC_RET1(handle, SMC_UNK);
  65. }
  66. }
  67. /* Register Standard Service Calls as runtime service */
  68. DECLARE_RT_SVC(
  69. arm_arch_svc,
  70. OEN_ARM_START,
  71. OEN_ARM_END,
  72. SMC_TYPE_FAST,
  73. NULL,
  74. arm_arch_svc_smc_handler
  75. );