bl1_plat_setup.c 2.85 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
#include <errno.h>
#include <string.h>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include <platform_def.h>

#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <common/tbbr/tbbr_img_def.h>
#include <drivers/arm/pl011.h>
#include <drivers/arm/pl061_gpio.h>
#include <drivers/generic_delay_timer.h>
#include <drivers/mmc.h>
#include <drivers/synopsys/dw_mmc.h>
#include <lib/mmio.h>
#include <plat/common/platform.h>

25
26
27
28
29
#include "hi3798cv200.h"
#include "plat_private.h"

/* Data structure which holds the extents of the trusted RAM for BL1 */
static meminfo_t bl1_tzram_layout;
30
static meminfo_t bl2_tzram_layout;
31
static console_t console;
32

33
34
35
36
#if !POPLAR_RECOVERY
static struct mmc_device_info mmc_info;
#endif

37
38
39
40
41
/*
 * Cannot use default weak implementation in bl1_main.c because BL1 RW data is
 * not at the top of the secure memory.
 */
int bl1_plat_handle_post_image_load(unsigned int image_id)
42
{
43
44
	image_desc_t *image_desc;
	entry_point_info_t *ep_info;
45

46
47
48
49
50
51
52
53
54
	if (image_id != BL2_IMAGE_ID)
		return 0;

	/* Get the image descriptor */
	image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
	assert(image_desc != NULL);

	/* Get the entry point info */
	ep_info = &image_desc->ep_info;
55

56
57
	bl2_tzram_layout.total_base = BL2_BASE;
	bl2_tzram_layout.total_size = BL32_LIMIT - BL2_BASE;
58

59
	flush_dcache_range((uintptr_t)&bl2_tzram_layout, sizeof(meminfo_t));
60

61
62
63
64
65
66
	ep_info->args.arg1 = (uintptr_t)&bl2_tzram_layout;

	VERBOSE("BL1: BL2 memory layout address = %p\n",
		(void *)&bl2_tzram_layout);

	return 0;
67
68
}

69
70
71
void bl1_early_platform_setup(void)
{
	/* Initialize the console to provide early debug support */
72
73
	console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
			       PL011_BAUDRATE, &console);
74
75

	/* Allow BL1 to see the whole Trusted RAM */
76
77
	bl1_tzram_layout.total_base = BL1_RW_BASE;
	bl1_tzram_layout.total_size = BL1_RW_SIZE;
78
79
80
81
82
83
84
85
86

	INFO("BL1: 0x%lx - 0x%lx [size = %zu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
	     BL1_RAM_LIMIT - BL1_RAM_BASE);
}

void bl1_plat_arch_setup(void)
{
	plat_configure_mmu_el3(bl1_tzram_layout.total_base,
			       bl1_tzram_layout.total_size,
87
			       BL1_RO_BASE, /* l-loader and BL1 ROM */
88
			       BL1_RO_LIMIT,
89
90
			       BL_COHERENT_RAM_BASE,
			       BL_COHERENT_RAM_END);
91
92
93
94
95
}

void bl1_platform_setup(void)
{
	int i;
96
#if !POPLAR_RECOVERY
Victor Chong's avatar
Victor Chong committed
97
	dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
98
#endif
99
100
101
102
103
104
105

	generic_delay_timer_init();

	pl061_gpio_init();
	for (i = 0; i < GPIO_MAX; i++)
		pl061_gpio_register(GPIO_BASE(i), i);

106
#if !POPLAR_RECOVERY
Victor Chong's avatar
Victor Chong committed
107
108
	/* SoC-specific emmc register are initialized/configured by bootrom */
	INFO("BL1: initializing emmc\n");
109
110
	mmc_info.mmc_dev_type = MMC_IS_EMMC;
	dw_mmc_init(&params, &mmc_info);
111
#endif
Victor Chong's avatar
Victor Chong committed
112

113
114
115
116
117
118
119
	plat_io_setup();
}

unsigned int bl1_plat_get_next_image_id(void)
{
	return BL2_IMAGE_ID;
}