mmup_common.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2024, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <inttypes.h>
  7. #include <common/debug.h>
  8. #include <lib/mmio.h>
  9. #include "mmup_common.h"
  10. #include "vcp_helper.h"
  11. #include "vcp_reg.h"
  12. #define MODULE_TAG "[MMUP]"
  13. bool mmup_smc_rstn_set(bool boot_ok)
  14. {
  15. if (mmio_read_32(VCP_GPR_CORE1_REBOOT) != 0 &&
  16. mmio_read_32(VCP_R_CORE1_STATUS) != 0 &&
  17. (mmio_read_32(VCP_R_GIPC_IN_SET) & B_GIPC3_SETCLR_1) == 0 &&
  18. (mmio_read_32(VCP_R_GIPC_IN_CLR) & B_GIPC3_SETCLR_1) == 0 &&
  19. mmio_read_32(VCP_GPR_CORE1_REBOOT) != VCP_CORE_RDY_TO_REBOOT) {
  20. ERROR("%s: [%s] mmup reset set fail!GIPC 0x%x 0x%x REBOOT 0x%x\n",
  21. MODULE_TAG, __func__, mmio_read_32(VCP_R_GIPC_IN_SET),
  22. mmio_read_32(VCP_R_GIPC_IN_CLR),
  23. mmio_read_32(VCP_GPR_CORE1_REBOOT));
  24. return false;
  25. }
  26. mmio_write_32(VCP_R_CORE1_SW_RSTN_SET, BIT(0));
  27. /* reset sec control */
  28. mmio_write_32(VCP_R_SEC_CTRL_2, 0);
  29. /* reset domain setting */
  30. mmio_write_32(VCP_R_S_DOM_EN0_31, 0x0);
  31. mmio_write_32(VCP_R_S_DOM_EN32_63, 0x0);
  32. mmio_write_32(VCP_R_NS_DOM_EN0_31, 0x0);
  33. mmio_write_32(VCP_R_NS_DOM_EN32_63, 0x0);
  34. /* reset sec setting */
  35. mmio_clrbits_32(VCP_R_DYN_SECURE,
  36. RESET_NS_SECURE_B_REGION << VCP_NS_SECURE_B_REGION_ENABLE);
  37. if (boot_ok)
  38. mmio_write_32(VCP_GPR_CORE1_REBOOT, VCP_CORE_REBOOT_OK);
  39. dsbsy();
  40. return true;
  41. }
  42. bool mmup_smc_rstn_clr(void)
  43. {
  44. if ((mmio_read_32(VCP_R_CORE1_SW_RSTN_SET) & BIT(0)) == 1) {
  45. ERROR("%s: [%s] mmup not reset set !\n", MODULE_TAG, __func__);
  46. return false;
  47. }
  48. if ((get_mmup_fw_size() == 0) || get_mmup_l2tcm_offset() == 0) {
  49. ERROR("%s: [%s] mmup no enough l2tcm to run !\n", MODULE_TAG, __func__);
  50. return false;
  51. }
  52. mmio_write_32(VCP_R_SEC_DOMAIN_MMPC, VCP_DOMAIN_SET_MMPC);
  53. /* enable IOVA Mode */
  54. mmio_write_32(VCP_R_AXIOMMUEN_DEV_APC, BIT(0));
  55. /* reset secure setting */
  56. mmio_setbits_32(VCP_R_SEC_CTRL_2, CORE1_SEC_BIT_SEL);
  57. /* l2tcm offset*/
  58. mmio_setbits_32(VCP_R_SEC_CTRL, VCP_OFFSET_ENABLE_P | VCP_OFFSET_ENABLE_B);
  59. mmio_write_32(R_L2TCM_OFFSET_RANGE_0_LOW, 0x0);
  60. mmio_write_32(R_L2TCM_OFFSET_RANGE_0_HIGH, round_up(get_mmup_fw_size(), PAGE_SIZE));
  61. mmio_write_32(R_L2TCM_OFFSET, get_mmup_l2tcm_offset());
  62. /* start vcp-mmup */
  63. mmio_write_32(VCP_R_CORE1_SW_RSTN_CLR, BIT(0));
  64. dsbsy();
  65. return true;
  66. }