plat_bl31_setup.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 <drivers/marvell/mci.h>
  9. #include <drivers/marvell/mochi/ap_setup.h>
  10. #include <drivers/marvell/mochi/cp110_setup.h>
  11. #include <lib/mmio.h>
  12. #include <armada_common.h>
  13. #include <marvell_plat_priv.h>
  14. #include <marvell_pm.h>
  15. #include <mc_trustzone/mc_trustzone.h>
  16. #include <plat_marvell.h>
  17. #if MSS_SUPPORT
  18. #include <mss_ipc_drv.h>
  19. #include <mss_mem.h>
  20. #include <mss_defs.h>
  21. #endif
  22. /* In Armada-8k family AP806/AP807, CP0 connected to PIDI
  23. * and CP1 connected to IHB via MCI #0
  24. */
  25. #define MVEBU_MCI0 0
  26. static _Bool pm_fw_running;
  27. /* Set a weak stub for platforms that don't need to configure GPIO */
  28. #pragma weak marvell_gpio_config
  29. int marvell_gpio_config(void)
  30. {
  31. return 0;
  32. }
  33. static void marvell_bl31_mpp_init(int cp)
  34. {
  35. uint32_t reg;
  36. /* need to do for CP#0 only */
  37. if (cp)
  38. return;
  39. /*
  40. * Enable CP0 I2C MPPs (MPP: 37-38)
  41. * U-Boot rely on proper MPP settings for I2C EEPROM usage
  42. * (only for CP0)
  43. */
  44. reg = mmio_read_32(MVEBU_CP_MPP_REGS(0, 4));
  45. mmio_write_32(MVEBU_CP_MPP_REGS(0, 4), reg | 0x2200000);
  46. }
  47. #if MSS_SUPPORT
  48. void marvell_bl31_mss_init(void)
  49. {
  50. struct mss_pm_ctrl_block *mss_pm_crtl =
  51. (struct mss_pm_ctrl_block *)MSS_SRAM_PM_CONTROL_BASE;
  52. /* Check that the image was loaded successfully */
  53. if (mss_pm_crtl->handshake != HOST_ACKNOWLEDGMENT) {
  54. NOTICE("MSS PM is not supported in this build\n");
  55. return;
  56. }
  57. /* If we got here it means that the PM firmware is running */
  58. pm_fw_running = 1;
  59. INFO("MSS IPC init\n");
  60. if (mss_pm_crtl->ipc_state == IPC_INITIALIZED)
  61. mv_pm_ipc_init(mss_pm_crtl->ipc_base_address | MVEBU_REGS_BASE);
  62. }
  63. #endif
  64. _Bool is_pm_fw_running(void)
  65. {
  66. return pm_fw_running;
  67. }
  68. /* For TrusTzone we treat the "target" field of addr_map_win
  69. * struct as attribute
  70. */
  71. static const struct addr_map_win tz_map[] = {
  72. {PLAT_MARVELL_ATF_BASE, 0x200000, TZ_PERM_ABORT}
  73. };
  74. /* Configure MC TrustZone regions */
  75. static void marvell_bl31_security_setup(void)
  76. {
  77. int tz_nr, win_id;
  78. tz_nr = ARRAY_SIZE(tz_map);
  79. for (win_id = 0; win_id < tz_nr; win_id++)
  80. tz_enable_win(MVEBU_AP0, tz_map, win_id);
  81. }
  82. /* This function overruns the same function in marvell_bl31_setup.c */
  83. void bl31_plat_arch_setup(void)
  84. {
  85. int cp;
  86. uintptr_t *mailbox = (void *)PLAT_MARVELL_MAILBOX_BASE;
  87. /* initialize the timer for mdelay/udelay functionality */
  88. plat_delay_timer_init();
  89. /* configure apn806 */
  90. ap_init();
  91. /* In marvell_bl31_plat_arch_setup, el3 mmu is configured.
  92. * el3 mmu configuration MUST be called after apn806_init, if not,
  93. * this will cause an hang in init_io_win
  94. * (after setting the IO windows GCR values).
  95. */
  96. if (mailbox[MBOX_IDX_MAGIC] != MVEBU_MAILBOX_MAGIC_NUM ||
  97. mailbox[MBOX_IDX_SUSPEND_MAGIC] != MVEBU_MAILBOX_SUSPEND_STATE)
  98. marvell_bl31_plat_arch_setup();
  99. for (cp = 0; cp < CP_COUNT; cp++) {
  100. cp110_init(MVEBU_CP_REGS_BASE(cp),
  101. STREAM_ID_BASE + (cp * MAX_STREAM_ID_PER_CP));
  102. marvell_bl31_mpp_init(cp);
  103. #if MSS_SUPPORT
  104. /* Release CP MSS CPU from reset once the CP init is done */
  105. mss_start_cp_cm3(cp);
  106. #endif
  107. }
  108. for (cp = 1; cp < CP_COUNT; cp++)
  109. mci_link_tune(cp - 1);
  110. #if MSS_SUPPORT
  111. /* initialize IPC between MSS and ATF */
  112. if (mailbox[MBOX_IDX_MAGIC] != MVEBU_MAILBOX_MAGIC_NUM ||
  113. mailbox[MBOX_IDX_SUSPEND_MAGIC] != MVEBU_MAILBOX_SUSPEND_STATE)
  114. marvell_bl31_mss_init();
  115. #endif
  116. /* Configure GPIO */
  117. marvell_gpio_config();
  118. marvell_bl31_security_setup();
  119. }