mrvl_sip_svc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2018 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <common/debug.h>
  8. #include <common/runtime_svc.h>
  9. #include <drivers/marvell/cache_llc.h>
  10. #include <drivers/marvell/mochi/ap_setup.h>
  11. #include <drivers/rambus/trng_ip_76.h>
  12. #include <lib/smccc.h>
  13. #include <marvell_plat_priv.h>
  14. #include <plat_marvell.h>
  15. #include "comphy/phy-comphy-cp110.h"
  16. #include "secure_dfx_access/dfx.h"
  17. #include "ddr_phy_access.h"
  18. #include <stdbool.h>
  19. /* #define DEBUG_COMPHY */
  20. #ifdef DEBUG_COMPHY
  21. #define debug(format...) NOTICE(format)
  22. #else
  23. #define debug(format, arg...)
  24. #endif
  25. /* Comphy related FID's */
  26. #define MV_SIP_COMPHY_POWER_ON 0x82000001
  27. #define MV_SIP_COMPHY_POWER_OFF 0x82000002
  28. #define MV_SIP_COMPHY_PLL_LOCK 0x82000003
  29. #define MV_SIP_COMPHY_XFI_TRAIN 0x82000004
  30. #define MV_SIP_COMPHY_DIG_RESET 0x82000005
  31. /* Miscellaneous FID's' */
  32. #define MV_SIP_DRAM_SIZE 0x82000010
  33. #define MV_SIP_LLC_ENABLE 0x82000011
  34. #define MV_SIP_PMU_IRQ_ENABLE 0x82000012
  35. #define MV_SIP_PMU_IRQ_DISABLE 0x82000013
  36. #define MV_SIP_DFX 0x82000014
  37. #define MV_SIP_DDR_PHY_WRITE 0x82000015
  38. #define MV_SIP_DDR_PHY_READ 0x82000016
  39. /* TRNG */
  40. #define MV_SIP_RNG_64 0xC200FF11
  41. #define MAX_LANE_NR 6
  42. #define MVEBU_COMPHY_OFFSET 0x441000
  43. #define MVEBU_CP_BASE_MASK (~0xffffff)
  44. /* Common PHY register */
  45. #define COMPHY_TRX_TRAIN_CTRL_REG_0_OFFS 0x120a2c
  46. /* This macro is used to identify COMPHY related calls from SMC function ID */
  47. #define is_comphy_fid(fid) \
  48. ((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_DIG_RESET)
  49. _Bool is_cp_range_valid(u_register_t *addr)
  50. {
  51. int cp_nr;
  52. *addr &= MVEBU_CP_BASE_MASK;
  53. for (cp_nr = 0; cp_nr < CP_NUM; cp_nr++) {
  54. if (*addr == MVEBU_CP_REGS_BASE(cp_nr))
  55. return true;
  56. }
  57. return false;
  58. }
  59. uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid,
  60. u_register_t x1,
  61. u_register_t x2,
  62. u_register_t x3,
  63. u_register_t x4,
  64. void *cookie,
  65. void *handle,
  66. u_register_t flags)
  67. {
  68. u_register_t ret, read, x5 = x1;
  69. int i;
  70. debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n",
  71. __func__, smc_fid, x1, x2, x3);
  72. if (is_comphy_fid(smc_fid)) {
  73. /* validate address passed via x1 */
  74. if (!is_cp_range_valid(&x1)) {
  75. ERROR("%s: Wrong smc (0x%x) address: %lx\n",
  76. __func__, smc_fid, x1);
  77. SMC_RET1(handle, SMC_UNK);
  78. }
  79. x5 = x1 + COMPHY_TRX_TRAIN_CTRL_REG_0_OFFS;
  80. x1 += MVEBU_COMPHY_OFFSET;
  81. if (x2 >= MAX_LANE_NR) {
  82. ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n",
  83. __func__, smc_fid, x2);
  84. SMC_RET1(handle, SMC_UNK);
  85. }
  86. }
  87. switch (smc_fid) {
  88. /* Comphy related FID's */
  89. case MV_SIP_COMPHY_POWER_ON:
  90. /* x1: comphy_base, x2: comphy_index, x3: comphy_mode */
  91. ret = mvebu_cp110_comphy_power_on(x1, x2, x3, x5);
  92. SMC_RET1(handle, ret);
  93. case MV_SIP_COMPHY_POWER_OFF:
  94. /* x1: comphy_base, x2: comphy_index */
  95. ret = mvebu_cp110_comphy_power_off(x1, x2, x3);
  96. SMC_RET1(handle, ret);
  97. case MV_SIP_COMPHY_PLL_LOCK:
  98. /* x1: comphy_base, x2: comphy_index */
  99. ret = mvebu_cp110_comphy_is_pll_locked(x1, x2);
  100. SMC_RET1(handle, ret);
  101. case MV_SIP_COMPHY_XFI_TRAIN:
  102. /* x1: comphy_base, x2: comphy_index */
  103. ret = mvebu_cp110_comphy_xfi_rx_training(x1, x2);
  104. SMC_RET1(handle, ret);
  105. case MV_SIP_COMPHY_DIG_RESET:
  106. /* x1: comphy_base, x2: comphy_index, x3: mode, x4: command */
  107. ret = mvebu_cp110_comphy_digital_reset(x1, x2, x3, x4);
  108. SMC_RET1(handle, ret);
  109. /* Miscellaneous FID's' */
  110. case MV_SIP_DRAM_SIZE:
  111. ret = mvebu_get_dram_size(MVEBU_REGS_BASE);
  112. SMC_RET1(handle, ret);
  113. case MV_SIP_LLC_ENABLE:
  114. for (i = 0; i < ap_get_count(); i++)
  115. llc_runtime_enable(i);
  116. SMC_RET1(handle, 0);
  117. #ifdef MVEBU_PMU_IRQ_WA
  118. case MV_SIP_PMU_IRQ_ENABLE:
  119. mvebu_pmu_interrupt_enable();
  120. SMC_RET1(handle, 0);
  121. case MV_SIP_PMU_IRQ_DISABLE:
  122. mvebu_pmu_interrupt_disable();
  123. SMC_RET1(handle, 0);
  124. #endif
  125. case MV_SIP_DFX:
  126. if (x1 >= MV_SIP_DFX_THERMAL_INIT &&
  127. x1 <= MV_SIP_DFX_THERMAL_SEL_CHANNEL) {
  128. ret = mvebu_dfx_thermal_handle(x1, &read, x2, x3);
  129. SMC_RET2(handle, ret, read);
  130. }
  131. if (x1 >= MV_SIP_DFX_SREAD && x1 <= MV_SIP_DFX_SWRITE) {
  132. ret = mvebu_dfx_misc_handle(x1, &read, x2, x3);
  133. SMC_RET2(handle, ret, read);
  134. }
  135. SMC_RET1(handle, SMC_UNK);
  136. case MV_SIP_DDR_PHY_WRITE:
  137. ret = mvebu_ddr_phy_write(x1, x2);
  138. SMC_RET1(handle, ret);
  139. case MV_SIP_DDR_PHY_READ:
  140. read = 0;
  141. ret = mvebu_ddr_phy_read(x1, (uint16_t *)&read);
  142. SMC_RET2(handle, ret, read);
  143. case MV_SIP_RNG_64:
  144. if ((x1 % 2 + 1) > sizeof(read)/4) {
  145. ERROR("%s: Maximum %ld random bytes per SMC call\n",
  146. __func__, sizeof(read));
  147. SMC_RET1(handle, SMC_UNK);
  148. }
  149. ret = eip76_rng_get_random((uint8_t *)&read, 4 * (x1 % 2 + 1));
  150. SMC_RET2(handle, ret, read);
  151. default:
  152. ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
  153. SMC_RET1(handle, SMC_UNK);
  154. }
  155. }
  156. /* Define a runtime service descriptor for fast SMC calls */
  157. DECLARE_RT_SVC(
  158. marvell_sip_svc,
  159. OEN_SIP_START,
  160. OEN_SIP_END,
  161. SMC_TYPE_FAST,
  162. NULL,
  163. mrvl_sip_smc_handler
  164. );