Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | adbf1d1 | 2021-03-22 14:21:15 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved. |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 7 | #include <assert.h> |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 8 | #include <errno.h> |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 9 | #include <string.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 11 | #include <platform_def.h> |
| 12 | |
| 13 | #include <arch_helpers.h> |
| 14 | #include <common/bl_common.h> |
| 15 | #include <common/debug.h> |
| 16 | #include <common/tbbr/tbbr_img_def.h> |
| 17 | #include <drivers/arm/pl011.h> |
| 18 | #include <drivers/arm/pl061_gpio.h> |
| 19 | #include <drivers/generic_delay_timer.h> |
| 20 | #include <drivers/mmc.h> |
| 21 | #include <drivers/synopsys/dw_mmc.h> |
| 22 | #include <lib/mmio.h> |
| 23 | #include <plat/common/platform.h> |
| 24 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 25 | #include "hi3798cv200.h" |
| 26 | #include "plat_private.h" |
| 27 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 28 | /* Data structure which holds the extents of the trusted RAM for BL1 */ |
| 29 | static meminfo_t bl1_tzram_layout; |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 30 | static meminfo_t bl2_tzram_layout; |
Andre Przywara | 2b1b1a5 | 2020-01-25 00:58:35 +0000 | [diff] [blame] | 31 | static console_t console; |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 32 | |
Yann Gautier | adbf1d1 | 2021-03-22 14:21:15 +0100 | [diff] [blame] | 33 | #if !POPLAR_RECOVERY |
| 34 | static struct mmc_device_info mmc_info; |
| 35 | #endif |
| 36 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 37 | /* |
| 38 | * Cannot use default weak implementation in bl1_main.c because BL1 RW data is |
| 39 | * not at the top of the secure memory. |
| 40 | */ |
| 41 | int bl1_plat_handle_post_image_load(unsigned int image_id) |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 42 | { |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 43 | image_desc_t *image_desc; |
| 44 | entry_point_info_t *ep_info; |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 45 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 46 | if (image_id != BL2_IMAGE_ID) |
| 47 | return 0; |
| 48 | |
| 49 | /* Get the image descriptor */ |
| 50 | image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
| 51 | assert(image_desc != NULL); |
| 52 | |
| 53 | /* Get the entry point info */ |
| 54 | ep_info = &image_desc->ep_info; |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 55 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 56 | bl2_tzram_layout.total_base = BL2_BASE; |
| 57 | bl2_tzram_layout.total_size = BL32_LIMIT - BL2_BASE; |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 58 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 59 | flush_dcache_range((uintptr_t)&bl2_tzram_layout, sizeof(meminfo_t)); |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 60 | |
Antonio Nino Diaz | e93cde1 | 2018-09-24 17:15:15 +0100 | [diff] [blame] | 61 | ep_info->args.arg1 = (uintptr_t)&bl2_tzram_layout; |
| 62 | |
| 63 | VERBOSE("BL1: BL2 memory layout address = %p\n", |
| 64 | (void *)&bl2_tzram_layout); |
| 65 | |
| 66 | return 0; |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 67 | } |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 68 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 69 | void bl1_early_platform_setup(void) |
| 70 | { |
| 71 | /* Initialize the console to provide early debug support */ |
Jerome Forissier | 74a19f2 | 2018-11-08 11:57:30 +0000 | [diff] [blame] | 72 | console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, |
| 73 | PL011_BAUDRATE, &console); |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 74 | |
| 75 | /* Allow BL1 to see the whole Trusted RAM */ |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 76 | bl1_tzram_layout.total_base = BL1_RW_BASE; |
| 77 | bl1_tzram_layout.total_size = BL1_RW_SIZE; |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 78 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 79 | INFO("BL1: 0x%lx - 0x%lx [size = %zu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT, |
| 80 | BL1_RAM_LIMIT - BL1_RAM_BASE); |
| 81 | } |
| 82 | |
| 83 | void bl1_plat_arch_setup(void) |
| 84 | { |
| 85 | plat_configure_mmu_el3(bl1_tzram_layout.total_base, |
| 86 | bl1_tzram_layout.total_size, |
Victor Chong | 175dd8a | 2018-02-01 00:35:22 +0900 | [diff] [blame] | 87 | BL1_RO_BASE, /* l-loader and BL1 ROM */ |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 88 | BL1_RO_LIMIT, |
Joel Hutton | 5cc3bc8 | 2018-03-21 11:40:57 +0000 | [diff] [blame] | 89 | BL_COHERENT_RAM_BASE, |
| 90 | BL_COHERENT_RAM_END); |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void bl1_platform_setup(void) |
| 94 | { |
| 95 | int i; |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 96 | #if !POPLAR_RECOVERY |
Victor Chong | 539408d | 2018-01-03 01:53:08 +0900 | [diff] [blame] | 97 | dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE); |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 98 | #endif |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 99 | |
| 100 | generic_delay_timer_init(); |
| 101 | |
| 102 | pl061_gpio_init(); |
| 103 | for (i = 0; i < GPIO_MAX; i++) |
| 104 | pl061_gpio_register(GPIO_BASE(i), i); |
| 105 | |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 106 | #if !POPLAR_RECOVERY |
Victor Chong | 539408d | 2018-01-03 01:53:08 +0900 | [diff] [blame] | 107 | /* SoC-specific emmc register are initialized/configured by bootrom */ |
| 108 | INFO("BL1: initializing emmc\n"); |
Yann Gautier | adbf1d1 | 2021-03-22 14:21:15 +0100 | [diff] [blame] | 109 | mmc_info.mmc_dev_type = MMC_IS_EMMC; |
| 110 | dw_mmc_init(¶ms, &mmc_info); |
Victor Chong | f0c7c61 | 2018-01-16 00:29:47 +0900 | [diff] [blame] | 111 | #endif |
Victor Chong | 539408d | 2018-01-03 01:53:08 +0900 | [diff] [blame] | 112 | |
Jorge Ramirez-Ortiz | a29d9a6 | 2017-06-28 10:11:31 +0200 | [diff] [blame] | 113 | plat_io_setup(); |
| 114 | } |
| 115 | |
| 116 | unsigned int bl1_plat_get_next_image_id(void) |
| 117 | { |
| 118 | return BL2_IMAGE_ID; |
| 119 | } |