aml_sip_svc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <common/runtime_svc.h>
  8. #include <lib/mmio.h>
  9. #include <platform_def.h>
  10. #include <stdint.h>
  11. #include <string.h>
  12. #include "aml_private.h"
  13. struct aml_cpu_info {
  14. uint32_t version;
  15. uint8_t chip_id[16];
  16. };
  17. static int aml_sip_get_chip_id(uint64_t version)
  18. {
  19. struct aml_cpu_info *info = (void *)AML_SHARE_MEM_OUTPUT_BASE;
  20. uint32_t size;
  21. if (version > 2)
  22. return -1;
  23. memset(info, 0, sizeof(struct aml_cpu_info));
  24. if (version == 2) {
  25. info->version = 2;
  26. size = 16;
  27. } else {
  28. info->version = 1;
  29. size = 12;
  30. }
  31. if (aml_scpi_get_chip_id(info->chip_id, size) == 0)
  32. return -1;
  33. return 0;
  34. }
  35. /*******************************************************************************
  36. * This function is responsible for handling all SiP calls
  37. ******************************************************************************/
  38. static uintptr_t aml_sip_handler(uint32_t smc_fid,
  39. u_register_t x1, u_register_t x2,
  40. u_register_t x3, u_register_t x4,
  41. void *cookie, void *handle,
  42. u_register_t flags)
  43. {
  44. switch (smc_fid) {
  45. case AML_SM_GET_SHARE_MEM_INPUT_BASE:
  46. SMC_RET1(handle, AML_SHARE_MEM_INPUT_BASE);
  47. case AML_SM_GET_SHARE_MEM_OUTPUT_BASE:
  48. SMC_RET1(handle, AML_SHARE_MEM_OUTPUT_BASE);
  49. case AML_SM_EFUSE_READ:
  50. {
  51. void *dst = (void *)AML_SHARE_MEM_OUTPUT_BASE;
  52. uint64_t ret = aml_efuse_read(dst, (uint32_t)x1, x2);
  53. SMC_RET1(handle, ret);
  54. }
  55. case AML_SM_EFUSE_USER_MAX:
  56. SMC_RET1(handle, aml_efuse_user_max());
  57. case AML_SM_JTAG_ON:
  58. aml_scpi_jtag_set_state(AML_JTAG_STATE_ON, x1);
  59. SMC_RET1(handle, 0);
  60. case AML_SM_JTAG_OFF:
  61. aml_scpi_jtag_set_state(AML_JTAG_STATE_OFF, x1);
  62. SMC_RET1(handle, 0);
  63. case AML_SM_GET_CHIP_ID:
  64. SMC_RET1(handle, aml_sip_get_chip_id(x1));
  65. default:
  66. ERROR("BL31: Unhandled SIP SMC: 0x%08x\n", smc_fid);
  67. break;
  68. }
  69. SMC_RET1(handle, SMC_UNK);
  70. }
  71. DECLARE_RT_SVC(
  72. aml_sip_handler,
  73. OEN_SIP_START,
  74. OEN_SIP_END,
  75. SMC_TYPE_FAST,
  76. NULL,
  77. aml_sip_handler
  78. );