rpi3_bl2_setup.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <platform_def.h>
  8. #include <arch_helpers.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <common/desc_image_load.h>
  12. #include <lib/optee_utils.h>
  13. #include <lib/xlat_tables/xlat_mmu_helpers.h>
  14. #include <lib/xlat_tables/xlat_tables_defs.h>
  15. #include <drivers/generic_delay_timer.h>
  16. #include <drivers/rpi3/gpio/rpi3_gpio.h>
  17. #include <drivers/rpi3/sdhost/rpi3_sdhost.h>
  18. #include <rpi_shared.h>
  19. /* Data structure which holds the extents of the trusted SRAM for BL2 */
  20. static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
  21. /* Data structure which holds the MMC info */
  22. static struct mmc_device_info mmc_info;
  23. static void rpi3_sdhost_setup(void)
  24. {
  25. struct rpi3_sdhost_params params;
  26. memset(&params, 0, sizeof(struct rpi3_sdhost_params));
  27. params.reg_base = RPI3_SDHOST_BASE;
  28. params.bus_width = MMC_BUS_WIDTH_1;
  29. params.clk_rate = 50000000;
  30. params.clk_rate_initial = (RPI3_SDHOST_MAX_CLOCK / HC_CLOCKDIVISOR_MAXVAL);
  31. mmc_info.mmc_dev_type = MMC_IS_SD_HC;
  32. mmc_info.ocr_voltage = OCR_3_2_3_3 | OCR_3_3_3_4;
  33. rpi3_sdhost_init(&params, &mmc_info);
  34. }
  35. /*******************************************************************************
  36. * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
  37. * in x0. This memory layout is sitting at the base of the free trusted SRAM.
  38. * Copy it to a safe location before its reclaimed by later BL2 functionality.
  39. ******************************************************************************/
  40. void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  41. u_register_t arg2, u_register_t arg3)
  42. {
  43. meminfo_t *mem_layout = (meminfo_t *) arg1;
  44. /* Initialize the console to provide early debug support */
  45. rpi3_console_init();
  46. /* Enable arch timer */
  47. generic_delay_timer_init();
  48. /* Setup GPIO driver */
  49. rpi3_gpio_init();
  50. /* Setup the BL2 memory layout */
  51. bl2_tzram_layout = *mem_layout;
  52. /* Setup SDHost driver */
  53. rpi3_sdhost_setup();
  54. plat_rpi3_io_setup();
  55. }
  56. void bl2_platform_setup(void)
  57. {
  58. /*
  59. * This is where a TrustZone address space controller and other
  60. * security related peripherals would be configured.
  61. */
  62. }
  63. /*******************************************************************************
  64. * Perform the very early platform specific architectural setup here.
  65. ******************************************************************************/
  66. void bl2_plat_arch_setup(void)
  67. {
  68. rpi3_setup_page_tables(bl2_tzram_layout.total_base,
  69. bl2_tzram_layout.total_size,
  70. BL_CODE_BASE, BL_CODE_END,
  71. BL_RO_DATA_BASE, BL_RO_DATA_END
  72. #if USE_COHERENT_MEM
  73. , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END
  74. #endif
  75. );
  76. enable_mmu_el1(0);
  77. }
  78. /*******************************************************************************
  79. * This function can be used by the platforms to update/use image
  80. * information for given `image_id`.
  81. ******************************************************************************/
  82. int bl2_plat_handle_post_image_load(unsigned int image_id)
  83. {
  84. int err = 0;
  85. bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
  86. #ifdef SPD_opteed
  87. bl_mem_params_node_t *pager_mem_params = NULL;
  88. bl_mem_params_node_t *paged_mem_params = NULL;
  89. #endif
  90. assert(bl_mem_params != NULL);
  91. switch (image_id) {
  92. case BL32_IMAGE_ID:
  93. #ifdef SPD_opteed
  94. pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
  95. assert(pager_mem_params);
  96. paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
  97. assert(paged_mem_params);
  98. err = parse_optee_header(&bl_mem_params->ep_info,
  99. &pager_mem_params->image_info,
  100. &paged_mem_params->image_info);
  101. if (err != 0)
  102. WARN("OPTEE header parse error.\n");
  103. #endif
  104. bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry();
  105. break;
  106. case BL33_IMAGE_ID:
  107. /* BL33 expects to receive the primary CPU MPID (through r0) */
  108. bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
  109. bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry();
  110. /* Shutting down the SDHost driver to let BL33 drives SDHost.*/
  111. rpi3_sdhost_stop();
  112. break;
  113. default:
  114. /* Do nothing in default case */
  115. break;
  116. }
  117. return err;
  118. }