blob: 31ff8206eded201319958442d46c2b13545a004f [file] [log] [blame]
Haojian Zhuang5f281b32017-05-24 08:45:05 +08001/*
Yann Gautieradbf1d12021-03-22 14:21:15 +01002 * Copyright (c) 2017-2021, 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>
Scott Brandene5dcf982020-08-25 13:49:32 -07009#include <inttypes.h>
10#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <string.h>
12
13#include <arch_helpers.h>
14#include <bl1/tbbr/tbbr_img_desc.h>
15#include <common/bl_common.h>
16#include <common/debug.h>
17#include <drivers/arm/pl011.h>
18#include <drivers/mmc.h>
19#include <drivers/synopsys/dw_mmc.h>
20#include <lib/mmio.h>
21#include <plat/common/platform.h>
22
Haojian Zhuang5f281b32017-05-24 08:45:05 +080023#include <hi6220.h>
Michael Brandlafdff3c2018-02-22 16:30:30 +010024#include <hikey_def.h>
25#include <hikey_layout.h>
Haojian Zhuang5f281b32017-05-24 08:45:05 +080026
Haojian Zhuang5f281b32017-05-24 08:45:05 +080027#include "hikey_private.h"
28
Haojian Zhuang5f281b32017-05-24 08:45:05 +080029/* Data structure which holds the extents of the trusted RAM for BL1 */
30static meminfo_t bl1_tzram_layout;
Andre Przywara2b1b1a52020-01-25 00:58:35 +000031static console_t console;
Yann Gautieradbf1d12021-03-22 14:21:15 +010032static struct mmc_device_info mmc_info;
Haojian Zhuang5f281b32017-05-24 08:45:05 +080033
34enum {
35 BOOT_NORMAL = 0,
36 BOOT_USB_DOWNLOAD,
37 BOOT_UART_DOWNLOAD,
38};
39
40meminfo_t *bl1_plat_sec_mem_layout(void)
41{
42 return &bl1_tzram_layout;
43}
44
45/*
46 * Perform any BL1 specific platform actions.
47 */
48void bl1_early_platform_setup(void)
49{
Haojian Zhuang5f281b32017-05-24 08:45:05 +080050 /* Initialize the console to provide early debug support */
Jerome Forissieraebe95d2018-11-08 10:17:47 +000051 console_pl011_register(CONSOLE_BASE, PL011_UART_CLK_IN_HZ,
52 PL011_BAUDRATE, &console);
Haojian Zhuang5f281b32017-05-24 08:45:05 +080053
54 /* Allow BL1 to see the whole Trusted RAM */
55 bl1_tzram_layout.total_base = BL1_RW_BASE;
56 bl1_tzram_layout.total_size = BL1_RW_SIZE;
57
Haojian Zhuang5f281b32017-05-24 08:45:05 +080058 INFO("BL1: 0x%lx - 0x%lx [size = %lu]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
Victor Chong2d9a42d2017-08-17 15:21:10 +090059 BL1_RAM_LIMIT - BL1_RAM_BASE); /* bl1_size */
Haojian Zhuang5f281b32017-05-24 08:45:05 +080060}
61
62/*
63 * Perform the very early platform specific architecture setup here. At the
64 * moment this only does basic initialization. Later architectural setup
65 * (bl1_arch_setup()) does not do anything platform specific.
66 */
67void bl1_plat_arch_setup(void)
68{
69 hikey_init_mmu_el3(bl1_tzram_layout.total_base,
70 bl1_tzram_layout.total_size,
71 BL1_RO_BASE,
72 BL1_RO_LIMIT,
Joel Hutton5cc3bc82018-03-21 11:40:57 +000073 BL_COHERENT_RAM_BASE,
74 BL_COHERENT_RAM_END);
Haojian Zhuang5f281b32017-05-24 08:45:05 +080075}
76
Haojian Zhuang5f281b32017-05-24 08:45:05 +080077/*
78 * Function which will perform any remaining platform-specific setup that can
79 * occur after the MMU and data cache have been enabled.
80 */
81void bl1_platform_setup(void)
82{
83 dw_mmc_params_t params;
84
85 assert((HIKEY_BL1_MMC_DESC_BASE >= SRAM_BASE) &&
86 ((SRAM_BASE + SRAM_SIZE) >=
87 (HIKEY_BL1_MMC_DATA_BASE + HIKEY_BL1_MMC_DATA_SIZE)));
88 hikey_sp804_init();
89 hikey_gpio_init();
90 hikey_pmussi_init();
91 hikey_hi6553_init();
92
Haojian Zhuange1be9042017-10-18 19:56:02 +080093 hikey_rtc_init();
94
Haojian Zhuang5f281b32017-05-24 08:45:05 +080095 hikey_mmc_pll_init();
96
97 memset(&params, 0, sizeof(dw_mmc_params_t));
98 params.reg_base = DWMMC0_BASE;
99 params.desc_base = HIKEY_BL1_MMC_DESC_BASE;
100 params.desc_size = 1 << 20;
101 params.clk_rate = 24 * 1000 * 1000;
Haojian Zhuange9713772018-08-04 18:07:10 +0800102 params.bus_width = MMC_BUS_WIDTH_8;
103 params.flags = MMC_FLAG_CMD23;
Yann Gautieradbf1d12021-03-22 14:21:15 +0100104 mmc_info.mmc_dev_type = MMC_IS_EMMC;
105 dw_mmc_init(&params, &mmc_info);
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800106
107 hikey_io_setup();
108}
109
110/*
111 * The following function checks if Firmware update is needed,
112 * by checking if TOC in FIP image is valid or not.
113 */
114unsigned int bl1_plat_get_next_image_id(void)
115{
116 int32_t boot_mode;
117 unsigned int ret;
118
119 boot_mode = mmio_read_32(ONCHIPROM_PARAM_BASE);
120 switch (boot_mode) {
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800121 case BOOT_USB_DOWNLOAD:
122 case BOOT_UART_DOWNLOAD:
123 ret = NS_BL1U_IMAGE_ID;
124 break;
125 default:
126 WARN("Invalid boot mode is found:%d\n", boot_mode);
127 panic();
128 }
129 return ret;
130}
131
132image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
133{
134 unsigned int index = 0;
135
136 while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) {
137 if (bl1_tbbr_image_descs[index].image_id == image_id)
138 return &bl1_tbbr_image_descs[index];
139
140 index++;
141 }
142
143 return NULL;
144}
145
146void bl1_plat_set_ep_info(unsigned int image_id,
147 entry_point_info_t *ep_info)
148{
Haojian Zhuang24c83372018-03-02 14:25:41 +0800149 uint64_t data = 0;
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800150
151 if (image_id == BL2_IMAGE_ID)
Haojian Zhuangb755da32018-01-25 16:10:14 +0800152 panic();
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800153 inv_dcache_range(NS_BL1U_BASE, NS_BL1U_SIZE);
154 __asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
155 do {
156 data |= 3 << 20;
157 __asm__ volatile ("msr cpacr_el1, %0" : : "r"(data));
158 __asm__ volatile ("mrs %0, cpacr_el1" : "=r"(data));
159 } while ((data & (3 << 20)) != (3 << 20));
Scott Brandene5dcf982020-08-25 13:49:32 -0700160 INFO("cpacr_el1:0x%" PRIx64 "\n", data);
Haojian Zhuang5f281b32017-05-24 08:45:05 +0800161
162 ep_info->args.arg0 = 0xffff & read_mpidr();
163 ep_info->spsr = SPSR_64(MODE_EL1, MODE_SP_ELX,
164 DISABLE_ALL_EXCEPTIONS);
165}