mg_conf_cm3.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2019 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #include <a8k_plat_def.h>
  8. #include <arch_helpers.h>
  9. #include <common/debug.h>
  10. #include <lib/mmio.h>
  11. #include <mss_scp_bl2_format.h>
  12. /* CONFI REGISTERS */
  13. #define MG_CM3_CONFI_BASE(CP) (MVEBU_CP_REGS_BASE(CP) + 0x100000)
  14. #define MG_CM3_SRAM_BASE(CP) MG_CM3_CONFI_BASE(CP)
  15. #define MG_CM3_CONFI_GLOB_CFG_REG(CP) (MG_CM3_CONFI_BASE(CP) + 0x2B500)
  16. #define CM3_CPU_EN_BIT BIT(28)
  17. #define MG_CM3_MG_INT_MFX_REG(CP) (MG_CM3_CONFI_BASE(CP) + 0x2B054)
  18. #define CM3_SYS_RESET_BIT BIT(0)
  19. #define MG_CM3_SHARED_MEM_BASE(CP) (MG_CM3_SRAM_BASE(CP) + 0x1FC00ULL)
  20. #define MG_SRAM_SIZE 0x20000 /* 128KB */
  21. #define MG_ACK_TIMEOUT 10
  22. /**
  23. * struct ap_sharedmem_ctrl - used to pass information between the HOST and CM3
  24. * @init_done: Set by CM3 when ap_proces initialzied. Host check if CM3 set
  25. * this flag to confirm that the process is running
  26. * @lane_nr: Set by Host to mark which comphy lane should be configure. E.g.:
  27. * - A8K development board uses comphy lane 2 for eth0
  28. * - CN913x development board uses comphy lane 4 for eth0
  29. */
  30. struct ap_sharedmem_ctrl {
  31. uint32_t init_done;
  32. uint32_t lane_nr;
  33. };
  34. int mg_image_load(uintptr_t src_addr, uint32_t size, int cp_index)
  35. {
  36. uintptr_t mg_regs = MG_CM3_SRAM_BASE(cp_index);
  37. if (size > MG_SRAM_SIZE) {
  38. ERROR("image is too big to fit into MG CM3 memory\n");
  39. return 1;
  40. }
  41. NOTICE("Loading MG image from address 0x%lx Size 0x%x to MG at 0x%lx\n",
  42. src_addr, size, mg_regs);
  43. /* Copy image to MG CM3 SRAM */
  44. memcpy((void *)mg_regs, (void *)src_addr, size);
  45. /* Don't release MG CM3 from reset - it will be done by next step
  46. * bootloader (e.g. U-Boot), when appriopriate device-tree setup (which
  47. * has enabeld 802.3. auto-neg) will be chosen.
  48. */
  49. return 0;
  50. }
  51. void mg_start_ap_fw(int cp_nr, uint8_t comphy_index)
  52. {
  53. volatile struct ap_sharedmem_ctrl *ap_shared_ctrl =
  54. (void *)MG_CM3_SHARED_MEM_BASE(cp_nr);
  55. int timeout = MG_ACK_TIMEOUT;
  56. if (mmio_read_32(MG_CM3_CONFI_GLOB_CFG_REG(cp_nr)) & CM3_CPU_EN_BIT) {
  57. VERBOSE("cm3 already running\n");
  58. return; /* cm3 already running */
  59. }
  60. /*
  61. * Mark which comphy lane should be used - it will be read via shared
  62. * mem by ap process
  63. */
  64. ap_shared_ctrl->lane_nr = comphy_index;
  65. /* Make sure it took place before enabling cm3 */
  66. dmbst();
  67. mmio_setbits_32(MG_CM3_CONFI_GLOB_CFG_REG(cp_nr), CM3_CPU_EN_BIT);
  68. mmio_setbits_32(MG_CM3_MG_INT_MFX_REG(cp_nr), CM3_SYS_RESET_BIT);
  69. /* Check for ap process initialization by fw */
  70. while (ap_shared_ctrl->init_done != 1 && timeout--)
  71. VERBOSE("Waiting for ap process ack, timeout %d\n", timeout);
  72. if (timeout == 0) {
  73. ERROR("AP process failed, disabling cm3\n");
  74. mmio_clrbits_32(MG_CM3_MG_INT_MFX_REG(cp_nr),
  75. CM3_SYS_RESET_BIT);
  76. mmio_clrbits_32(MG_CM3_CONFI_GLOB_CFG_REG(cp_nr),
  77. CM3_CPU_EN_BIT);
  78. }
  79. }