hikey_bl31_setup.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <platform_def.h>
  9. #include <arch_helpers.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <common/interrupt_props.h>
  13. #include <drivers/arm/cci.h>
  14. #include <drivers/arm/gicv2.h>
  15. #include <drivers/arm/pl011.h>
  16. #include <lib/mmio.h>
  17. #include <hi6220.h>
  18. #include <hikey_def.h>
  19. #include <hisi_ipc.h>
  20. #include <hisi_pwrc.h>
  21. #include "hikey_private.h"
  22. static entry_point_info_t bl32_ep_info;
  23. static entry_point_info_t bl33_ep_info;
  24. static console_t console;
  25. /******************************************************************************
  26. * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
  27. * interrupts.
  28. *****************************************************************************/
  29. static const interrupt_prop_t g0_interrupt_props[] = {
  30. INTR_PROP_DESC(IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY,
  31. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  32. INTR_PROP_DESC(IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY,
  33. GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
  34. };
  35. /*
  36. * Ideally `arm_gic_data` structure definition should be a `const` but it is
  37. * kept as modifiable for overwriting with different GICD and GICC base when
  38. * running on FVP with VE memory map.
  39. */
  40. gicv2_driver_data_t hikey_gic_data = {
  41. .gicd_base = PLAT_ARM_GICD_BASE,
  42. .gicc_base = PLAT_ARM_GICC_BASE,
  43. .interrupt_props = g0_interrupt_props,
  44. .interrupt_props_num = ARRAY_SIZE(g0_interrupt_props),
  45. };
  46. static const int cci_map[] = {
  47. CCI400_SL_IFACE3_CLUSTER_IX,
  48. CCI400_SL_IFACE4_CLUSTER_IX
  49. };
  50. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  51. {
  52. entry_point_info_t *next_image_info;
  53. next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info;
  54. /* None of the images on this platform can have 0x0 as the entrypoint */
  55. if (next_image_info->pc)
  56. return next_image_info;
  57. return NULL;
  58. }
  59. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  60. u_register_t arg2, u_register_t arg3)
  61. {
  62. void *from_bl2;
  63. from_bl2 = (void *) arg0;
  64. /* Initialize the console to provide early debug support */
  65. console_pl011_register(CONSOLE_BASE, PL011_UART_CLK_IN_HZ,
  66. PL011_BAUDRATE, &console);
  67. /* Initialize CCI driver */
  68. cci_init(CCI400_BASE, cci_map, ARRAY_SIZE(cci_map));
  69. cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
  70. /*
  71. * Check params passed from BL2 should not be NULL,
  72. */
  73. bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
  74. assert(params_from_bl2 != NULL);
  75. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  76. assert(params_from_bl2->h.version >= VERSION_2);
  77. bl_params_node_t *bl_params = params_from_bl2->head;
  78. /*
  79. * Copy BL33 and BL32 (if present), entry point information.
  80. * They are stored in Secure RAM, in BL2's address space.
  81. */
  82. while (bl_params) {
  83. if (bl_params->image_id == BL32_IMAGE_ID)
  84. bl32_ep_info = *bl_params->ep_info;
  85. if (bl_params->image_id == BL33_IMAGE_ID)
  86. bl33_ep_info = *bl_params->ep_info;
  87. bl_params = bl_params->next_params_info;
  88. }
  89. if (bl33_ep_info.pc == 0)
  90. panic();
  91. }
  92. void bl31_plat_arch_setup(void)
  93. {
  94. hikey_init_mmu_el3(BL31_BASE,
  95. BL31_LIMIT - BL31_BASE,
  96. BL_CODE_BASE,
  97. BL_CODE_END,
  98. BL_COHERENT_RAM_BASE,
  99. BL_COHERENT_RAM_END);
  100. }
  101. /* Initialize EDMAC controller with non-secure mode. */
  102. static void hikey_edma_init(void)
  103. {
  104. int i;
  105. uint32_t non_secure;
  106. non_secure = EDMAC_SEC_CTRL_INTR_SEC | EDMAC_SEC_CTRL_GLOBAL_SEC;
  107. mmio_write_32(EDMAC_SEC_CTRL, non_secure);
  108. for (i = 0; i < EDMAC_CHANNEL_NUMS; i++) {
  109. mmio_write_32(EDMAC_AXI_CONF(i), (1 << 6) | (1 << 18));
  110. }
  111. }
  112. void bl31_platform_setup(void)
  113. {
  114. /* Initialize the GIC driver, cpu and distributor interfaces */
  115. gicv2_driver_init(&hikey_gic_data);
  116. gicv2_distif_init();
  117. gicv2_pcpu_distif_init();
  118. gicv2_cpuif_enable();
  119. hikey_edma_init();
  120. hisi_ipc_init();
  121. hisi_pwrc_setup();
  122. }