apusys_rv.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (c) 2023, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /* TF-A system header */
  7. #include <common/debug.h>
  8. #include <drivers/delay_timer.h>
  9. #include <lib/mmio.h>
  10. #include <lib/spinlock.h>
  11. /* Vendor header */
  12. #include "apusys.h"
  13. #include "apusys_rv.h"
  14. #include "apusys_rv_mbox_mpu.h"
  15. #include "emi_mpu.h"
  16. static spinlock_t apusys_rv_lock;
  17. void apusys_rv_mbox_mpu_init(void)
  18. {
  19. int i;
  20. for (i = 0; i < APU_MBOX_NUM; i++) {
  21. mmio_write_32(APU_MBOX_FUNC_CFG(i),
  22. (MBOX_CTRL_LOCK |
  23. (mbox_mpu_setting_tab[i].no_mpu << MBOX_NO_MPU_SHIFT)));
  24. mmio_write_32(APU_MBOX_DOMAIN_CFG(i),
  25. (MBOX_CTRL_LOCK |
  26. (mbox_mpu_setting_tab[i].rx_ns << MBOX_RX_NS_SHIFT) |
  27. (mbox_mpu_setting_tab[i].rx_domain << MBOX_RX_DOMAIN_SHIFT) |
  28. (mbox_mpu_setting_tab[i].tx_ns << MBOX_TX_NS_SHIFT) |
  29. (mbox_mpu_setting_tab[i].tx_domain << MBOX_TX_DOMAIN_SHIFT)));
  30. }
  31. }
  32. int apusys_kernel_apusys_rv_setup_reviser(void)
  33. {
  34. spin_lock(&apusys_rv_lock);
  35. mmio_write_32(USERFW_CTXT, CFG_4GB_SEL_EN | CFG_4GB_SEL);
  36. mmio_write_32(SECUREFW_CTXT, CFG_4GB_SEL_EN | CFG_4GB_SEL);
  37. mmio_write_32(UP_IOMMU_CTRL, MMU_CTRL_LOCK | MMU_CTRL | MMU_EN);
  38. mmio_write_32(UP_NORMAL_DOMAIN_NS,
  39. (UP_NORMAL_DOMAIN << UP_DOMAIN_SHIFT) | (UP_NORMAL_NS << UP_NS_SHIFT));
  40. mmio_write_32(UP_PRI_DOMAIN_NS,
  41. (UP_PRI_DOMAIN << UP_DOMAIN_SHIFT) | (UP_PRI_NS << UP_NS_SHIFT));
  42. mmio_write_32(UP_CORE0_VABASE0,
  43. VLD | PARTIAL_ENABLE | (THREAD_NUM_PRI << THREAD_NUM_SHIFT));
  44. mmio_write_32(UP_CORE0_MVABASE0, VASIZE_1MB | (APU_SEC_FW_IOVA >> MVA_34BIT_SHIFT));
  45. mmio_write_32(UP_CORE0_VABASE1,
  46. VLD | PARTIAL_ENABLE | (THREAD_NUM_NORMAL << THREAD_NUM_SHIFT));
  47. mmio_write_32(UP_CORE0_MVABASE1, VASIZE_1MB | (APU_SEC_FW_IOVA >> MVA_34BIT_SHIFT));
  48. spin_unlock(&apusys_rv_lock);
  49. return 0;
  50. }
  51. int apusys_kernel_apusys_rv_reset_mp(void)
  52. {
  53. spin_lock(&apusys_rv_lock);
  54. mmio_write_32(MD32_SYS_CTRL, MD32_SYS_CTRL_RST);
  55. dsb();
  56. udelay(RESET_DEALY_US);
  57. mmio_write_32(MD32_SYS_CTRL, MD32_G2B_CG_EN | MD32_DBG_EN | MD32_DM_AWUSER_IOMMU_EN |
  58. MD32_DM_ARUSER_IOMMU_EN | MD32_PM_AWUSER_IOMMU_EN | MD32_PM_ARUSER_IOMMU_EN |
  59. MD32_SOFT_RSTN);
  60. mmio_write_32(MD32_CLK_CTRL, MD32_CLK_EN);
  61. mmio_write_32(UP_WAKE_HOST_MASK0, WDT_IRQ_EN);
  62. mmio_write_32(UP_WAKE_HOST_MASK1, MBOX0_IRQ_EN | MBOX1_IRQ_EN | MBOX2_IRQ_EN);
  63. spin_unlock(&apusys_rv_lock);
  64. return 0;
  65. }
  66. int apusys_kernel_apusys_rv_setup_boot(void)
  67. {
  68. spin_lock(&apusys_rv_lock);
  69. mmio_write_32(MD32_BOOT_CTRL, APU_SEC_FW_IOVA);
  70. mmio_write_32(MD32_PRE_DEFINE, (PREDEFINE_CACHE_TCM << PREDEF_1G_OFS) |
  71. (PREDEFINE_CACHE << PREDEF_2G_OFS) | (PREDEFINE_CACHE << PREDEF_3G_OFS) |
  72. (PREDEFINE_CACHE << PREDEF_4G_OFS));
  73. spin_unlock(&apusys_rv_lock);
  74. return 0;
  75. }
  76. int apusys_kernel_apusys_rv_start_mp(void)
  77. {
  78. spin_lock(&apusys_rv_lock);
  79. mmio_write_32(MD32_RUNSTALL, MD32_RUN);
  80. spin_unlock(&apusys_rv_lock);
  81. return 0;
  82. }
  83. int apusys_kernel_apusys_rv_stop_mp(void)
  84. {
  85. spin_lock(&apusys_rv_lock);
  86. mmio_write_32(MD32_RUNSTALL, MD32_STALL);
  87. spin_unlock(&apusys_rv_lock);
  88. return 0;
  89. }
  90. int apusys_kernel_apusys_rv_setup_sec_mem(void)
  91. {
  92. int ret;
  93. spin_lock(&apusys_rv_lock);
  94. ret = set_apu_emi_mpu_region();
  95. if (ret != 0) {
  96. ERROR(MODULE_TAG "%s: set emimpu protection failed\n", __func__);
  97. }
  98. spin_unlock(&apusys_rv_lock);
  99. return ret;
  100. }
  101. int apusys_kernel_apusys_rv_disable_wdt_isr(void)
  102. {
  103. spin_lock(&apusys_rv_lock);
  104. mmio_clrbits_32(WDT_CTRL0, WDT_EN);
  105. spin_unlock(&apusys_rv_lock);
  106. return 0;
  107. }
  108. int apusys_kernel_apusys_rv_clear_wdt_isr(void)
  109. {
  110. spin_lock(&apusys_rv_lock);
  111. mmio_clrbits_32(UP_INT_EN2, DBG_APB_EN);
  112. mmio_write_32(WDT_INT, WDT_INT_W1C);
  113. spin_unlock(&apusys_rv_lock);
  114. return 0;
  115. }
  116. int apusys_kernel_apusys_rv_cg_gating(void)
  117. {
  118. spin_lock(&apusys_rv_lock);
  119. mmio_write_32(MD32_CLK_CTRL, MD32_CLK_DIS);
  120. spin_unlock(&apusys_rv_lock);
  121. return 0;
  122. }
  123. int apusys_kernel_apusys_rv_cg_ungating(void)
  124. {
  125. spin_lock(&apusys_rv_lock);
  126. mmio_write_32(MD32_CLK_CTRL, MD32_CLK_EN);
  127. spin_unlock(&apusys_rv_lock);
  128. return 0;
  129. }