qemu_bl31_setup.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/bl_common.h>
  8. #include <drivers/arm/pl061_gpio.h>
  9. #include <plat/common/platform.h>
  10. #include "qemu_private.h"
  11. /*
  12. * Placeholder variables for copying the arguments that have been passed to
  13. * BL3-1 from BL2.
  14. */
  15. static entry_point_info_t bl32_image_ep_info;
  16. static entry_point_info_t bl33_image_ep_info;
  17. /*******************************************************************************
  18. * Perform any BL3-1 early platform setup. Here is an opportunity to copy
  19. * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before
  20. * they are lost (potentially). This needs to be done before the MMU is
  21. * initialized so that the memory layout can be used while creating page
  22. * tables. BL2 has flushed this information to memory, so we are guaranteed
  23. * to pick up good data.
  24. ******************************************************************************/
  25. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  26. u_register_t arg2, u_register_t arg3)
  27. {
  28. /* Initialize the console to provide early debug support */
  29. qemu_console_init();
  30. /*
  31. * Check params passed from BL2
  32. */
  33. bl_params_t *params_from_bl2 = (bl_params_t *)arg0;
  34. assert(params_from_bl2);
  35. assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
  36. assert(params_from_bl2->h.version >= VERSION_2);
  37. bl_params_node_t *bl_params = params_from_bl2->head;
  38. /*
  39. * Copy BL33 and BL32 (if present), entry point information.
  40. * They are stored in Secure RAM, in BL2's address space.
  41. */
  42. while (bl_params) {
  43. if (bl_params->image_id == BL32_IMAGE_ID)
  44. bl32_image_ep_info = *bl_params->ep_info;
  45. if (bl_params->image_id == BL33_IMAGE_ID)
  46. bl33_image_ep_info = *bl_params->ep_info;
  47. bl_params = bl_params->next_params_info;
  48. }
  49. if (!bl33_image_ep_info.pc)
  50. panic();
  51. }
  52. void bl31_plat_arch_setup(void)
  53. {
  54. qemu_configure_mmu_el3(BL31_BASE, (BL31_END - BL31_BASE),
  55. BL_CODE_BASE, BL_CODE_END,
  56. BL_RO_DATA_BASE, BL_RO_DATA_END,
  57. BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
  58. }
  59. static void qemu_gpio_init(void)
  60. {
  61. #ifdef SECURE_GPIO_BASE
  62. pl061_gpio_init();
  63. pl061_gpio_register(SECURE_GPIO_BASE, 0);
  64. #endif
  65. }
  66. void bl31_platform_setup(void)
  67. {
  68. plat_qemu_gic_init();
  69. qemu_gpio_init();
  70. }
  71. unsigned int plat_get_syscnt_freq2(void)
  72. {
  73. return SYS_COUNTER_FREQ_IN_TICKS;
  74. }
  75. /*******************************************************************************
  76. * Return a pointer to the 'entry_point_info' structure of the next image
  77. * for the security state specified. BL3-3 corresponds to the non-secure
  78. * image type while BL3-2 corresponds to the secure image type. A NULL
  79. * pointer is returned if the image does not exist.
  80. ******************************************************************************/
  81. entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
  82. {
  83. entry_point_info_t *next_image_info;
  84. assert(sec_state_is_valid(type));
  85. next_image_info = (type == NON_SECURE)
  86. ? &bl33_image_ep_info : &bl32_image_ep_info;
  87. /*
  88. * None of the images on the ARM development platforms can have 0x0
  89. * as the entrypoint
  90. */
  91. if (next_image_info->pc)
  92. return next_image_info;
  93. else
  94. return NULL;
  95. }