blob: 883336f0da76cc9604a65910c3157a65d27c3538 [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
8#include <arch_helpers.h>
Konstantin Porotchkind973c032018-10-02 17:45:15 +03009#include <assert.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030010#include <bl_common.h>
11#include <console.h>
Konstantin Porotchkind973c032018-10-02 17:45:15 +030012#include <debug.h>
13#include <desc_image_load.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030014#include <marvell_def.h>
15#include <platform_def.h>
16#include <plat_marvell.h>
17#include <string.h>
Konstantin Porotchkind973c032018-10-02 17:45:15 +030018#include <utils.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030019
20/* Data structure which holds the extents of the trusted SRAM for BL2 */
21static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
22
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030023/* Weak definitions may be overridden in specific MARVELL standard platform */
Konstantin Porotchkind973c032018-10-02 17:45:15 +030024#pragma weak bl2_early_platform_setup2
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030025#pragma weak bl2_platform_setup
26#pragma weak bl2_plat_arch_setup
27#pragma weak bl2_plat_sec_mem_layout
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030028
29meminfo_t *bl2_plat_sec_mem_layout(void)
30{
31 return &bl2_tzram_layout;
32}
33
34/*****************************************************************************
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030035 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
36 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
37 * Copy it to a safe location before its reclaimed by later BL2 functionality.
38 *****************************************************************************
39 */
40void marvell_bl2_early_platform_setup(meminfo_t *mem_layout)
41{
42 /* Initialize the console to provide early debug support */
Konstantin Porotchkind8e39572018-11-14 17:15:08 +020043 marvell_console_boot_init();
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030044
45 /* Setup the BL2 memory layout */
46 bl2_tzram_layout = *mem_layout;
47
48 /* Initialise the IO layer and register platform IO devices */
49 plat_marvell_io_setup();
50}
51
Antonio Nino Diaz79662212018-09-24 17:15:46 +010052
53void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
54 u_register_t arg2, u_register_t arg3)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030055{
Antonio Nino Diaz79662212018-09-24 17:15:46 +010056 struct meminfo *mem_layout = (struct meminfo *)arg1;
57
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030058 marvell_bl2_early_platform_setup(mem_layout);
59}
60
61void bl2_platform_setup(void)
62{
63 /* Nothing to do */
64}
65
66/*****************************************************************************
67 * Perform the very early platform specific architectural setup here. At the
68 * moment this is only initializes the mmu in a quick and dirty way.
69 *****************************************************************************
70 */
71void marvell_bl2_plat_arch_setup(void)
72{
73 marvell_setup_page_tables(bl2_tzram_layout.total_base,
74 bl2_tzram_layout.total_size,
75 BL_CODE_BASE,
76 BL_CODE_END,
77 BL_RO_DATA_BASE,
78 BL_RO_DATA_END
79#if USE_COHERENT_MEM
80 , BL_COHERENT_RAM_BASE,
81 BL_COHERENT_RAM_END
82#endif
83 );
84 enable_mmu_el1(0);
85}
86
87void bl2_plat_arch_setup(void)
88{
89 marvell_bl2_plat_arch_setup();
90}
91
Konstantin Porotchkind973c032018-10-02 17:45:15 +030092int marvell_bl2_handle_post_image_load(unsigned int image_id)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030093{
Konstantin Porotchkind973c032018-10-02 17:45:15 +030094 int err = 0;
95 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030096
Konstantin Porotchkind973c032018-10-02 17:45:15 +030097 assert(bl_mem_params);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030098
Konstantin Porotchkind973c032018-10-02 17:45:15 +030099 switch (image_id) {
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300100
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300101 case BL33_IMAGE_ID:
102 /* BL33 expects to receive the primary CPU MPID (through r0) */
103 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
104 bl_mem_params->ep_info.spsr = marvell_get_spsr_for_bl33_entry();
105 break;
Grzegorz Jaszczyk62c24862018-10-04 09:44:56 +0200106#ifdef SCP_BL2_BASE
107 case SCP_BL2_IMAGE_ID:
108 /* The subsequent handling of SCP_BL2 is platform specific */
109 err = bl2_plat_handle_scp_bl2(&bl_mem_params->image_info);
110 if (err) {
111 WARN("Failure in platform-specific handling of SCP_BL2 image.\n");
112 }
113 break;
114#endif
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300115 default:
116 /* Do nothing in default case */
117 break;
118 }
119
120 return err;
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300121
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300122}
123
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300124/*******************************************************************************
125 * This function can be used by the platforms to update/use image
126 * information for given `image_id`.
127 ******************************************************************************/
128int bl2_plat_handle_post_image_load(unsigned int image_id)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300129{
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300130 return marvell_bl2_handle_post_image_load(image_id);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300131}
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300132