blob: d0b12ad2bc3ad2a77b356b1fda7304b2a408bb54 [file] [log] [blame]
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02001/*
Joel Hutton5cc3bc82018-03-21 11:40:57 +00002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <assert.h>
9#include <bl_common.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020010#include <debug.h>
Victor Chong539408d2018-01-03 01:53:08 +090011#include <dw_mmc.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020012#include <errno.h>
13#include <generic_delay_timer.h>
Haojian Zhuang3eff4092018-08-04 18:07:26 +080014#include <mmc.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020015#include <mmio.h>
Jerome Forissier74a19f22018-11-08 11:57:30 +000016#include <pl011.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020017#include <pl061_gpio.h>
18#include <platform.h>
19#include <platform_def.h>
20#include <string.h>
21#include <tbbr_img_def.h>
22#include "../../bl1/bl1_private.h"
23#include "hi3798cv200.h"
24#include "plat_private.h"
25
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020026/* Data structure which holds the extents of the trusted RAM for BL1 */
27static meminfo_t bl1_tzram_layout;
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010028static meminfo_t bl2_tzram_layout;
Jerome Forissier74a19f22018-11-08 11:57:30 +000029static console_pl011_t console;
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020030
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010031/*
32 * Cannot use default weak implementation in bl1_main.c because BL1 RW data is
33 * not at the top of the secure memory.
34 */
35int bl1_plat_handle_post_image_load(unsigned int image_id)
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020036{
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010037 image_desc_t *image_desc;
38 entry_point_info_t *ep_info;
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020039
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010040 if (image_id != BL2_IMAGE_ID)
41 return 0;
42
43 /* Get the image descriptor */
44 image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
45 assert(image_desc != NULL);
46
47 /* Get the entry point info */
48 ep_info = &image_desc->ep_info;
Victor Chong175dd8a2018-02-01 00:35:22 +090049
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010050 bl2_tzram_layout.total_base = BL2_BASE;
51 bl2_tzram_layout.total_size = BL32_LIMIT - BL2_BASE;
Victor Chong175dd8a2018-02-01 00:35:22 +090052
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010053 flush_dcache_range((uintptr_t)&bl2_tzram_layout, sizeof(meminfo_t));
Victor Chong175dd8a2018-02-01 00:35:22 +090054
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010055 ep_info->args.arg1 = (uintptr_t)&bl2_tzram_layout;
56
57 VERBOSE("BL1: BL2 memory layout address = %p\n",
58 (void *)&bl2_tzram_layout);
59
60 return 0;
Victor Chong175dd8a2018-02-01 00:35:22 +090061}
Victor Chong175dd8a2018-02-01 00:35:22 +090062
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020063void bl1_early_platform_setup(void)
64{
65 /* Initialize the console to provide early debug support */
Jerome Forissier74a19f22018-11-08 11:57:30 +000066 console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
67 PL011_BAUDRATE, &console);
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020068
69 /* Allow BL1 to see the whole Trusted RAM */
Victor Chong175dd8a2018-02-01 00:35:22 +090070 bl1_tzram_layout.total_base = BL1_RW_BASE;
71 bl1_tzram_layout.total_size = BL1_RW_SIZE;
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020072
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020073 INFO("BL1: 0x%lx - 0x%lx [size = %zu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
74 BL1_RAM_LIMIT - BL1_RAM_BASE);
75}
76
77void bl1_plat_arch_setup(void)
78{
79 plat_configure_mmu_el3(bl1_tzram_layout.total_base,
80 bl1_tzram_layout.total_size,
Victor Chong175dd8a2018-02-01 00:35:22 +090081 BL1_RO_BASE, /* l-loader and BL1 ROM */
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020082 BL1_RO_LIMIT,
Joel Hutton5cc3bc82018-03-21 11:40:57 +000083 BL_COHERENT_RAM_BASE,
84 BL_COHERENT_RAM_END);
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020085}
86
87void bl1_platform_setup(void)
88{
89 int i;
Victor Chongf0c7c612018-01-16 00:29:47 +090090#if !POPLAR_RECOVERY
Shawn Guod793ff02018-09-27 16:48:00 +080091 struct mmc_device_info info;
Victor Chong539408d2018-01-03 01:53:08 +090092 dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
Victor Chongf0c7c612018-01-16 00:29:47 +090093#endif
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020094
95 generic_delay_timer_init();
96
97 pl061_gpio_init();
98 for (i = 0; i < GPIO_MAX; i++)
99 pl061_gpio_register(GPIO_BASE(i), i);
100
Victor Chongf0c7c612018-01-16 00:29:47 +0900101#if !POPLAR_RECOVERY
Victor Chong539408d2018-01-03 01:53:08 +0900102 /* SoC-specific emmc register are initialized/configured by bootrom */
103 INFO("BL1: initializing emmc\n");
Haojian Zhuang3eff4092018-08-04 18:07:26 +0800104 info.mmc_dev_type = MMC_IS_EMMC;
105 dw_mmc_init(&params, &info);
Victor Chongf0c7c612018-01-16 00:29:47 +0900106#endif
Victor Chong539408d2018-01-03 01:53:08 +0900107
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200108 plat_io_setup();
109}
110
111unsigned int bl1_plat_get_next_image_id(void)
112{
113 return BL2_IMAGE_ID;
114}