blob: 13e8c0155b8fb1f3537279817c7a4ad87ef08a41 [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
7#include <arch_helpers.h>
8#include <assert.h>
9#include <bl_common.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000010#include <debug.h>
11#include <desc_image_load.h>
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080012#include <optee_utils.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000013#include <platform_def.h>
14#include <xlat_mmu_helpers.h>
15#include <xlat_tables_defs.h>
16
17#include "rpi3_private.h"
18
19/* Data structure which holds the extents of the trusted SRAM for BL2 */
20static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
21
22/*******************************************************************************
23 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
24 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
25 * Copy it to a safe location before its reclaimed by later BL2 functionality.
26 ******************************************************************************/
27void bl2_early_platform_setup(meminfo_t *mem_layout)
28{
29 /* Initialize the console to provide early debug support */
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010030 rpi3_console_init();
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000031
32 /* Setup the BL2 memory layout */
33 bl2_tzram_layout = *mem_layout;
34
35 plat_rpi3_io_setup();
36}
37
38void bl2_platform_setup(void)
39{
40 /*
41 * This is where a TrustZone address space controller and other
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010042 * security related peripherals would be configured.
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000043 */
44}
45
46/*******************************************************************************
47 * Perform the very early platform specific architectural setup here.
48 ******************************************************************************/
49void bl2_plat_arch_setup(void)
50{
51 rpi3_setup_page_tables(bl2_tzram_layout.total_base,
52 bl2_tzram_layout.total_size,
53 BL_CODE_BASE, BL_CODE_END,
54 BL_RO_DATA_BASE, BL_RO_DATA_END
55#if USE_COHERENT_MEM
56 , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END
57#endif
58 );
59
60 enable_mmu_el1(0);
61}
62
63/*******************************************************************************
64 * This function can be used by the platforms to update/use image
65 * information for given `image_id`.
66 ******************************************************************************/
67int bl2_plat_handle_post_image_load(unsigned int image_id)
68{
69 int err = 0;
70 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 +080071#ifdef SPD_opteed
72 bl_mem_params_node_t *pager_mem_params = NULL;
73 bl_mem_params_node_t *paged_mem_params = NULL;
74#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000075
76 assert(bl_mem_params != NULL);
77
78 switch (image_id) {
79 case BL32_IMAGE_ID:
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080080#ifdef SPD_opteed
81 pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
82 assert(pager_mem_params);
83
84 paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
85 assert(paged_mem_params);
86
87 err = parse_optee_header(&bl_mem_params->ep_info,
88 &pager_mem_params->image_info,
89 &paged_mem_params->image_info);
90 if (err != 0)
91 WARN("OPTEE header parse error.\n");
92#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000093 bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry();
94 break;
95
96 case BL33_IMAGE_ID:
97 /* BL33 expects to receive the primary CPU MPID (through r0) */
98 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
99 bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry();
100 break;
101
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000102 default:
103 /* Do nothing in default case */
104 break;
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000105 }
106
107 return err;
108}