bl1_plat_setup.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2017-2021, 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 <string.h>
  9. #include <platform_def.h>
  10. #include <arch_helpers.h>
  11. #include <common/bl_common.h>
  12. #include <common/debug.h>
  13. #include <common/tbbr/tbbr_img_def.h>
  14. #include <drivers/arm/pl011.h>
  15. #include <drivers/arm/pl061_gpio.h>
  16. #include <drivers/generic_delay_timer.h>
  17. #include <drivers/mmc.h>
  18. #include <drivers/synopsys/dw_mmc.h>
  19. #include <lib/mmio.h>
  20. #include <plat/common/platform.h>
  21. #include "hi3798cv200.h"
  22. #include "plat_private.h"
  23. /* Data structure which holds the extents of the trusted RAM for BL1 */
  24. static meminfo_t bl1_tzram_layout;
  25. static meminfo_t bl2_tzram_layout;
  26. static console_t console;
  27. #if !POPLAR_RECOVERY
  28. static struct mmc_device_info mmc_info;
  29. #endif
  30. /*
  31. * Cannot use default weak implementation in bl1_main.c because BL1 RW data is
  32. * not at the top of the secure memory.
  33. */
  34. int bl1_plat_handle_post_image_load(unsigned int image_id)
  35. {
  36. image_desc_t *image_desc;
  37. entry_point_info_t *ep_info;
  38. if (image_id != BL2_IMAGE_ID)
  39. return 0;
  40. /* Get the image descriptor */
  41. image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
  42. assert(image_desc != NULL);
  43. /* Get the entry point info */
  44. ep_info = &image_desc->ep_info;
  45. bl2_tzram_layout.total_base = BL2_BASE;
  46. bl2_tzram_layout.total_size = BL32_LIMIT - BL2_BASE;
  47. flush_dcache_range((uintptr_t)&bl2_tzram_layout, sizeof(meminfo_t));
  48. ep_info->args.arg1 = (uintptr_t)&bl2_tzram_layout;
  49. VERBOSE("BL1: BL2 memory layout address = %p\n",
  50. (void *)&bl2_tzram_layout);
  51. return 0;
  52. }
  53. void bl1_early_platform_setup(void)
  54. {
  55. /* Initialize the console to provide early debug support */
  56. console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
  57. PL011_BAUDRATE, &console);
  58. /* Allow BL1 to see the whole Trusted RAM */
  59. bl1_tzram_layout.total_base = BL1_RW_BASE;
  60. bl1_tzram_layout.total_size = BL1_RW_SIZE;
  61. INFO("BL1: 0x%lx - 0x%lx [size = %zu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
  62. BL1_RAM_LIMIT - BL1_RAM_BASE);
  63. }
  64. void bl1_plat_arch_setup(void)
  65. {
  66. plat_configure_mmu_el3(bl1_tzram_layout.total_base,
  67. bl1_tzram_layout.total_size,
  68. BL1_RO_BASE, /* l-loader and BL1 ROM */
  69. BL1_RO_LIMIT,
  70. BL_COHERENT_RAM_BASE,
  71. BL_COHERENT_RAM_END);
  72. }
  73. void bl1_platform_setup(void)
  74. {
  75. int i;
  76. #if !POPLAR_RECOVERY
  77. dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
  78. #endif
  79. generic_delay_timer_init();
  80. pl061_gpio_init();
  81. for (i = 0; i < GPIO_MAX; i++)
  82. pl061_gpio_register(GPIO_BASE(i), i);
  83. #if !POPLAR_RECOVERY
  84. /* SoC-specific emmc register are initialized/configured by bootrom */
  85. INFO("BL1: initializing emmc\n");
  86. mmc_info.mmc_dev_type = MMC_IS_EMMC;
  87. dw_mmc_init(&params, &mmc_info);
  88. #endif
  89. plat_io_setup();
  90. }
  91. unsigned int bl1_plat_get_next_image_id(void)
  92. {
  93. return BL2_IMAGE_ID;
  94. }