blob: a08bdfa72b64f3458eb79608e0f02ba1df26dbcd [file] [log] [blame]
Haojian Zhuang5f281b32017-05-24 08:45:05 +08001/*
Haojian Zhuangb755da32018-01-25 16:10:14 +08002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Haojian Zhuang5f281b32017-05-24 08:45:05 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Haojian Zhuang5f281b32017-05-24 08:45:05 +08007#include <assert.h>
Haojian Zhuang5f281b32017-05-24 08:45:05 +08008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <string.h>
10
11#include <arch_helpers.h>
12#include <bl1/tbbr/tbbr_img_desc.h>
13#include <common/bl_common.h>
14#include <common/debug.h>
15#include <drivers/arm/pl011.h>
16#include <drivers/mmc.h>
17#include <drivers/synopsys/dw_mmc.h>
18#include <lib/mmio.h>
19#include <plat/common/platform.h>
20
Haojian Zhuang5f281b32017-05-24 08:45:05 +080021#include <hi6220.h>
Michael Brandlafdff3c2018-02-22 16:30:30 +010022#include <hikey_def.h>
23#include <hikey_layout.h>
Haojian Zhuang5f281b32017-05-24 08:45:05 +080024
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000025#include "../../../bl1/bl1_private.h"
Haojian Zhuang5f281b32017-05-24 08:45:05 +080026#include "hikey_private.h"
27
Haojian Zhuang5f281b32017-05-24 08:45:05 +080028/* Data structure which holds the extents of the trusted RAM for BL1 */
29static meminfo_t bl1_tzram_layout;
Jerome Forissieraebe95d2018-11-08 10:17:47 +000030static console_pl011_t console;
Haojian Zhuang5f281b32017-05-24 08:45:05 +080031
32enum {
33 BOOT_NORMAL = 0,
34 BOOT_USB_DOWNLOAD,
35 BOOT_UART_DOWNLOAD,
36};
37
38meminfo_t *bl1_plat_sec_mem_layout(void)
39{
40 return &bl1_tzram_layout;
41}
42
43/*
44 * Perform any BL1 specific platform actions.
45 */
46void bl1_early_platform_setup(void)
47{
Haojian Zhuang5f281b32017-05-24 08:45:05 +080048 /* Initialize the console to provide early debug support */
Jerome Forissieraebe95d2018-11-08 10:17:47 +000049 console_pl011_register(CONSOLE_BASE, PL011_UART_CLK_IN_HZ,
50 PL011_BAUDRATE, &console);
Haojian Zhuang5f281b32017-05-24 08:45:05 +080051
52 /* Allow BL1 to see the whole Trusted RAM */
53 bl1_tzram_layout.total_base = BL1_RW_BASE;
54 bl1_tzram_layout.total_size = BL1_RW_SIZE;
55
Haojian Zhuang5f281b32017-05-24 08:45:05 +080056 INFO("BL1: 0x%lx - 0x%lx [size = %lu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
Victor Chong2d9a42d2017-08-17 15:21:10 +090057 BL1_RAM_LIMIT - BL1_RAM_BASE); /* bl1_size */
Haojian Zhuang5f281b32017-05-24 08:45:05 +080058}
59
60/*
61 * Perform the very early platform specific architecture setup here. At the
62 * moment this only does basic initialization. Later architectural setup
63 * (bl1_arch_setup()) does not do anything platform specific.
64 */
65void bl1_plat_arch_setup(void)
66{
67 hikey_init_mmu_el3(bl1_tzram_layout.total_base,
68 bl1_tzram_layout.total_size,
69 BL1_RO_BASE,
70 BL1_RO_LIMIT,
Joel Hutton5cc3bc82018-03-21 11:40:57 +000071 BL_COHERENT_RAM_BASE,
72 BL_COHERENT_RAM_END);
Haojian Zhuang5f281b32017-05-24 08:45:05 +080073}
74
Haojian Zhuang5f281b32017-05-24 08:45:05 +080075/*
76 * Function which will perform any remaining platform-specific setup that can
77 * occur after the MMU and data cache have been enabled.
78 */
79void bl1_platform_setup(void)
80{
81 dw_mmc_params_t params;
Haojian Zhuange9713772018-08-04 18:07:10 +080082 struct mmc_device_info info;
Haojian Zhuang5f281b32017-05-24 08:45:05 +080083
84 assert((HIKEY_BL1_MMC_DESC_BASE >= SRAM_BASE) &&
85 ((SRAM_BASE + SRAM_SIZE) >=
86 (HIKEY_BL1_MMC_DATA_BASE + HIKEY_BL1_MMC_DATA_SIZE)));
87 hikey_sp804_init();
88 hikey_gpio_init();
89 hikey_pmussi_init();
90 hikey_hi6553_init();
91
Haojian Zhuange1be9042017-10-18 19:56:02 +080092 hikey_rtc_init();
93
Haojian Zhuang5f281b32017-05-24 08:45:05 +080094 hikey_mmc_pll_init();
95
96 memset(&params, 0, sizeof(dw_mmc_params_t));
97 params.reg_base = DWMMC0_BASE;
98 params.desc_base = HIKEY_BL1_MMC_DESC_BASE;
99 params.desc_size = 1 << 20;
100 params.clk_rate = 24 * 1000 * 1000;
Haojian Zhuange9713772018-08-04 18:07:10 +0800101 params.bus_width = MMC_BUS_WIDTH_8;
102 params.flags = MMC_FLAG_CMD23;
103 info.mmc_dev_type = MMC_IS_EMMC;
104 dw_mmc_init(&params, &info);
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800105
106 hikey_io_setup();
107}
108
109/*
110 * The following function checks if Firmware update is needed,
111 * by checking if TOC in FIP image is valid or not.
112 */
113unsigned int bl1_plat_get_next_image_id(void)
114{
115 int32_t boot_mode;
116 unsigned int ret;
117
118 boot_mode = mmio_read_32(ONCHIPROM_PARAM_BASE);
119 switch (boot_mode) {
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800120 case BOOT_USB_DOWNLOAD:
121 case BOOT_UART_DOWNLOAD:
122 ret = NS_BL1U_IMAGE_ID;
123 break;
124 default:
125 WARN("Invalid boot mode is found:%d\n", boot_mode);
126 panic();
127 }
128 return ret;
129}
130
131image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
132{
133 unsigned int index = 0;
134
135 while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) {
136 if (bl1_tbbr_image_descs[index].image_id == image_id)
137 return &bl1_tbbr_image_descs[index];
138
139 index++;
140 }
141
142 return NULL;
143}
144
145void bl1_plat_set_ep_info(unsigned int image_id,
146 entry_point_info_t *ep_info)
147{
Haojian Zhuang24c83372018-03-02 14:25:41 +0800148 uint64_t data = 0;
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800149
150 if (image_id == BL2_IMAGE_ID)
Haojian Zhuangb755da32018-01-25 16:10:14 +0800151 panic();
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800152 inv_dcache_range(NS_BL1U_BASE, NS_BL1U_SIZE);
153 __asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
154 do {
155 data |= 3 << 20;
156 __asm__ volatile ("msr cpacr_el1, %0" : : "r"(data));
157 __asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
158 } while ((data & (3 << 20)) != (3 << 20));
Masahiro Yamadae93a0f42018-02-02 15:09:36 +0900159 INFO("cpacr_el1:0x%llx\n", data);
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800160
161 ep_info->args.arg0 = 0xffff & read_mpidr();
162 ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
163 DISABLE_ALL_EXCEPTIONS);
164}