blob: 3c1c39112b88900a708585e643fe0be589bc28de [file] [log] [blame]
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +03001/*
2 * Copyright (C) 2018 Marvell International Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
Konstantin Porotchkind973c032018-10-02 17:45:15 +03008#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <string.h>
10
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030011#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
13#include <arch_helpers.h>
14#include <common/bl_common.h>
15#include <common/debug.h>
16#include <common/desc_image_load.h>
17#include <drivers/console.h>
18#include <lib/utils.h>
19
20#include <marvell_def.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030021#include <plat_marvell.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030022
23/* Data structure which holds the extents of the trusted SRAM for BL2 */
24static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
25
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030026/* Weak definitions may be overridden in specific MARVELL standard platform */
Konstantin Porotchkind973c032018-10-02 17:45:15 +030027#pragma weak bl2_early_platform_setup2
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030028#pragma weak bl2_platform_setup
29#pragma weak bl2_plat_arch_setup
30#pragma weak bl2_plat_sec_mem_layout
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030031
32meminfo_t *bl2_plat_sec_mem_layout(void)
33{
34 return &bl2_tzram_layout;
35}
36
37/*****************************************************************************
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030038 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
39 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
40 * Copy it to a safe location before its reclaimed by later BL2 functionality.
41 *****************************************************************************
42 */
43void marvell_bl2_early_platform_setup(meminfo_t *mem_layout)
44{
45 /* Initialize the console to provide early debug support */
Konstantin Porotchkind8e39572018-11-14 17:15:08 +020046 marvell_console_boot_init();
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030047
48 /* Setup the BL2 memory layout */
49 bl2_tzram_layout = *mem_layout;
50
51 /* Initialise the IO layer and register platform IO devices */
52 plat_marvell_io_setup();
53}
54
Antonio Nino Diaz79662212018-09-24 17:15:46 +010055
56void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
57 u_register_t arg2, u_register_t arg3)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030058{
Antonio Nino Diaz79662212018-09-24 17:15:46 +010059 struct meminfo *mem_layout = (struct meminfo *)arg1;
60
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030061 marvell_bl2_early_platform_setup(mem_layout);
62}
63
64void bl2_platform_setup(void)
65{
66 /* Nothing to do */
67}
68
69/*****************************************************************************
70 * Perform the very early platform specific architectural setup here. At the
71 * moment this is only initializes the mmu in a quick and dirty way.
72 *****************************************************************************
73 */
74void marvell_bl2_plat_arch_setup(void)
75{
76 marvell_setup_page_tables(bl2_tzram_layout.total_base,
77 bl2_tzram_layout.total_size,
78 BL_CODE_BASE,
79 BL_CODE_END,
80 BL_RO_DATA_BASE,
81 BL_RO_DATA_END
82#if USE_COHERENT_MEM
83 , BL_COHERENT_RAM_BASE,
84 BL_COHERENT_RAM_END
85#endif
86 );
87 enable_mmu_el1(0);
88}
89
90void bl2_plat_arch_setup(void)
91{
92 marvell_bl2_plat_arch_setup();
93}
94
Konstantin Porotchkind973c032018-10-02 17:45:15 +030095int marvell_bl2_handle_post_image_load(unsigned int image_id)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030096{
Konstantin Porotchkind973c032018-10-02 17:45:15 +030097 int err = 0;
98 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030099
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300100 assert(bl_mem_params);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300101
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300102 switch (image_id) {
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300103
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300104 case BL33_IMAGE_ID:
105 /* BL33 expects to receive the primary CPU MPID (through r0) */
106 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
107 bl_mem_params->ep_info.spsr = marvell_get_spsr_for_bl33_entry();
108 break;
Grzegorz Jaszczyk62c24862018-10-04 09:44:56 +0200109#ifdef SCP_BL2_BASE
110 case SCP_BL2_IMAGE_ID:
111 /* The subsequent handling of SCP_BL2 is platform specific */
112 err = bl2_plat_handle_scp_bl2(&bl_mem_params->image_info);
113 if (err) {
114 WARN("Failure in platform-specific handling of SCP_BL2 image.\n");
115 }
116 break;
117#endif
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300118 default:
119 /* Do nothing in default case */
120 break;
121 }
122
123 return err;
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300124
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300125}
126
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300127/*******************************************************************************
128 * This function can be used by the platforms to update/use image
129 * information for given `image_id`.
130 ******************************************************************************/
131int bl2_plat_handle_post_image_load(unsigned int image_id)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300132{
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300133 return marvell_bl2_handle_post_image_load(image_id);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300134}
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300135