xref: /rk3399_ARM-atf/plat/hisilicon/poplar/bl1_plat_setup.c (revision f695e1e01a995e66f9f5be5430fef3b7920082f2)
1e35d0edbSJorge Ramirez-Ortiz /*
29f85f9e3SJoel Hutton  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3e35d0edbSJorge Ramirez-Ortiz  *
4e35d0edbSJorge Ramirez-Ortiz  * SPDX-License-Identifier: BSD-3-Clause
5e35d0edbSJorge Ramirez-Ortiz  */
6e35d0edbSJorge Ramirez-Ortiz 
7e35d0edbSJorge Ramirez-Ortiz #include <assert.h>
8e35d0edbSJorge Ramirez-Ortiz #include <errno.h>
9e35d0edbSJorge Ramirez-Ortiz #include <string.h>
1009d40e0eSAntonio Nino Diaz 
1109d40e0eSAntonio Nino Diaz #include <platform_def.h>
1209d40e0eSAntonio Nino Diaz 
1309d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1409d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1509d40e0eSAntonio Nino Diaz #include <common/debug.h>
1609d40e0eSAntonio Nino Diaz #include <common/tbbr/tbbr_img_def.h>
1709d40e0eSAntonio Nino Diaz #include <drivers/arm/pl011.h>
1809d40e0eSAntonio Nino Diaz #include <drivers/arm/pl061_gpio.h>
1909d40e0eSAntonio Nino Diaz #include <drivers/generic_delay_timer.h>
2009d40e0eSAntonio Nino Diaz #include <drivers/mmc.h>
2109d40e0eSAntonio Nino Diaz #include <drivers/synopsys/dw_mmc.h>
2209d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
2309d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
2409d40e0eSAntonio Nino Diaz 
25e35d0edbSJorge Ramirez-Ortiz #include "hi3798cv200.h"
26e35d0edbSJorge Ramirez-Ortiz #include "plat_private.h"
27e35d0edbSJorge Ramirez-Ortiz 
28e35d0edbSJorge Ramirez-Ortiz /* Data structure which holds the extents of the trusted RAM for BL1 */
29e35d0edbSJorge Ramirez-Ortiz static meminfo_t bl1_tzram_layout;
3082fbaa33SAntonio Nino Diaz static meminfo_t bl2_tzram_layout;
31*f695e1e0SAndre Przywara static console_t console;
320d8052a4SVictor Chong 
330d8052a4SVictor Chong /*
3482fbaa33SAntonio Nino Diaz  * Cannot use default weak implementation in bl1_main.c because BL1 RW data is
3582fbaa33SAntonio Nino Diaz  * not at the top of the secure memory.
360d8052a4SVictor Chong  */
3782fbaa33SAntonio Nino Diaz int bl1_plat_handle_post_image_load(unsigned int image_id)
3882fbaa33SAntonio Nino Diaz {
3982fbaa33SAntonio Nino Diaz 	image_desc_t *image_desc;
4082fbaa33SAntonio Nino Diaz 	entry_point_info_t *ep_info;
410d8052a4SVictor Chong 
4282fbaa33SAntonio Nino Diaz 	if (image_id != BL2_IMAGE_ID)
4382fbaa33SAntonio Nino Diaz 		return 0;
4482fbaa33SAntonio Nino Diaz 
4582fbaa33SAntonio Nino Diaz 	/* Get the image descriptor */
4682fbaa33SAntonio Nino Diaz 	image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
4782fbaa33SAntonio Nino Diaz 	assert(image_desc != NULL);
4882fbaa33SAntonio Nino Diaz 
4982fbaa33SAntonio Nino Diaz 	/* Get the entry point info */
5082fbaa33SAntonio Nino Diaz 	ep_info = &image_desc->ep_info;
5182fbaa33SAntonio Nino Diaz 
5282fbaa33SAntonio Nino Diaz 	bl2_tzram_layout.total_base = BL2_BASE;
5382fbaa33SAntonio Nino Diaz 	bl2_tzram_layout.total_size = BL32_LIMIT - BL2_BASE;
5482fbaa33SAntonio Nino Diaz 
5582fbaa33SAntonio Nino Diaz 	flush_dcache_range((uintptr_t)&bl2_tzram_layout, sizeof(meminfo_t));
5682fbaa33SAntonio Nino Diaz 
5782fbaa33SAntonio Nino Diaz 	ep_info->args.arg1 = (uintptr_t)&bl2_tzram_layout;
5882fbaa33SAntonio Nino Diaz 
5982fbaa33SAntonio Nino Diaz 	VERBOSE("BL1: BL2 memory layout address = %p\n",
6082fbaa33SAntonio Nino Diaz 		(void *)&bl2_tzram_layout);
6182fbaa33SAntonio Nino Diaz 
6282fbaa33SAntonio Nino Diaz 	return 0;
630d8052a4SVictor Chong }
640d8052a4SVictor Chong 
65e35d0edbSJorge Ramirez-Ortiz void bl1_early_platform_setup(void)
66e35d0edbSJorge Ramirez-Ortiz {
67e35d0edbSJorge Ramirez-Ortiz 	/* Initialize the console to provide early debug support */
685c58c8b1SJerome Forissier 	console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
695c58c8b1SJerome Forissier 			       PL011_BAUDRATE, &console);
70e35d0edbSJorge Ramirez-Ortiz 
71e35d0edbSJorge Ramirez-Ortiz 	/* Allow BL1 to see the whole Trusted RAM */
720d8052a4SVictor Chong 	bl1_tzram_layout.total_base = BL1_RW_BASE;
730d8052a4SVictor Chong 	bl1_tzram_layout.total_size = BL1_RW_SIZE;
74e35d0edbSJorge Ramirez-Ortiz 
75e35d0edbSJorge Ramirez-Ortiz 	INFO("BL1: 0x%lx - 0x%lx [size = %zu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
76e35d0edbSJorge Ramirez-Ortiz 	     BL1_RAM_LIMIT - BL1_RAM_BASE);
77e35d0edbSJorge Ramirez-Ortiz }
78e35d0edbSJorge Ramirez-Ortiz 
79e35d0edbSJorge Ramirez-Ortiz void bl1_plat_arch_setup(void)
80e35d0edbSJorge Ramirez-Ortiz {
81e35d0edbSJorge Ramirez-Ortiz 	plat_configure_mmu_el3(bl1_tzram_layout.total_base,
82e35d0edbSJorge Ramirez-Ortiz 			       bl1_tzram_layout.total_size,
830d8052a4SVictor Chong 			       BL1_RO_BASE, /* l-loader and BL1 ROM */
84e35d0edbSJorge Ramirez-Ortiz 			       BL1_RO_LIMIT,
859f85f9e3SJoel Hutton 			       BL_COHERENT_RAM_BASE,
869f85f9e3SJoel Hutton 			       BL_COHERENT_RAM_END);
87e35d0edbSJorge Ramirez-Ortiz }
88e35d0edbSJorge Ramirez-Ortiz 
89e35d0edbSJorge Ramirez-Ortiz void bl1_platform_setup(void)
90e35d0edbSJorge Ramirez-Ortiz {
91e35d0edbSJorge Ramirez-Ortiz 	int i;
9215b54e7bSVictor Chong #if !POPLAR_RECOVERY
93d5ed2946SShawn Guo 	struct mmc_device_info info;
9459149bbeSVictor Chong 	dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
9515b54e7bSVictor Chong #endif
96e35d0edbSJorge Ramirez-Ortiz 
97e35d0edbSJorge Ramirez-Ortiz 	generic_delay_timer_init();
98e35d0edbSJorge Ramirez-Ortiz 
99e35d0edbSJorge Ramirez-Ortiz 	pl061_gpio_init();
100e35d0edbSJorge Ramirez-Ortiz 	for (i = 0; i < GPIO_MAX; i++)
101e35d0edbSJorge Ramirez-Ortiz 		pl061_gpio_register(GPIO_BASE(i), i);
102e35d0edbSJorge Ramirez-Ortiz 
10315b54e7bSVictor Chong #if !POPLAR_RECOVERY
10459149bbeSVictor Chong 	/* SoC-specific emmc register are initialized/configured by bootrom */
10559149bbeSVictor Chong 	INFO("BL1: initializing emmc\n");
106eba1b6b3SHaojian Zhuang 	info.mmc_dev_type = MMC_IS_EMMC;
107eba1b6b3SHaojian Zhuang 	dw_mmc_init(&params, &info);
10815b54e7bSVictor Chong #endif
10959149bbeSVictor Chong 
110e35d0edbSJorge Ramirez-Ortiz 	plat_io_setup();
111e35d0edbSJorge Ramirez-Ortiz }
112e35d0edbSJorge Ramirez-Ortiz 
113e35d0edbSJorge Ramirez-Ortiz unsigned int bl1_plat_get_next_image_id(void)
114e35d0edbSJorge Ramirez-Ortiz {
115e35d0edbSJorge Ramirez-Ortiz 	return BL2_IMAGE_ID;
116e35d0edbSJorge Ramirez-Ortiz }
117