blob: 53a2c72b8c5cc118c01d1d2cc7a4947e8c5a6acf [file] [log] [blame]
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00001/*
Antonio Nino Diaz1f470022018-03-27 09:39:47 +01002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <arch_helpers.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <common/desc_image_load.h>
15#include <lib/optee_utils.h>
16#include <lib/xlat_tables/xlat_mmu_helpers.h>
17#include <lib/xlat_tables/xlat_tables_defs.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000018
19#include "rpi3_private.h"
20
21/* Data structure which holds the extents of the trusted SRAM for BL2 */
22static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
23
24/*******************************************************************************
25 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
26 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
27 * Copy it to a safe location before its reclaimed by later BL2 functionality.
28 ******************************************************************************/
Antonio Nino Diaz83d8c792018-08-17 14:25:08 +010029
30void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
31 u_register_t arg2, u_register_t arg3)
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000032{
Antonio Nino Diaz83d8c792018-08-17 14:25:08 +010033 meminfo_t *mem_layout = (meminfo_t *) arg1;
34
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000035 /* Initialize the console to provide early debug support */
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010036 rpi3_console_init();
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000037
38 /* Setup the BL2 memory layout */
39 bl2_tzram_layout = *mem_layout;
40
41 plat_rpi3_io_setup();
42}
43
44void bl2_platform_setup(void)
45{
46 /*
47 * This is where a TrustZone address space controller and other
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010048 * security related peripherals would be configured.
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000049 */
50}
51
52/*******************************************************************************
53 * Perform the very early platform specific architectural setup here.
54 ******************************************************************************/
55void bl2_plat_arch_setup(void)
56{
57 rpi3_setup_page_tables(bl2_tzram_layout.total_base,
58 bl2_tzram_layout.total_size,
59 BL_CODE_BASE, BL_CODE_END,
60 BL_RO_DATA_BASE, BL_RO_DATA_END
61#if USE_COHERENT_MEM
62 , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END
63#endif
64 );
65
66 enable_mmu_el1(0);
67}
68
69/*******************************************************************************
70 * This function can be used by the platforms to update/use image
71 * information for given `image_id`.
72 ******************************************************************************/
73int bl2_plat_handle_post_image_load(unsigned int image_id)
74{
75 int err = 0;
76 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080077#ifdef SPD_opteed
78 bl_mem_params_node_t *pager_mem_params = NULL;
79 bl_mem_params_node_t *paged_mem_params = NULL;
80#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000081
82 assert(bl_mem_params != NULL);
83
84 switch (image_id) {
85 case BL32_IMAGE_ID:
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080086#ifdef SPD_opteed
87 pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
88 assert(pager_mem_params);
89
90 paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
91 assert(paged_mem_params);
92
93 err = parse_optee_header(&bl_mem_params->ep_info,
94 &pager_mem_params->image_info,
95 &paged_mem_params->image_info);
96 if (err != 0)
97 WARN("OPTEE header parse error.\n");
98#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000099 bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry();
100 break;
101
102 case BL33_IMAGE_ID:
103 /* BL33 expects to receive the primary CPU MPID (through r0) */
104 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
105 bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry();
106 break;
107
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000108 default:
109 /* Do nothing in default case */
110 break;
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000111 }
112
113 return err;
114}