Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 1 | /* |
| 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 Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 9 | #include <assert.h> |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 10 | #include <bl_common.h> |
| 11 | #include <console.h> |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 12 | #include <debug.h> |
| 13 | #include <desc_image_load.h> |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 14 | #include <marvell_def.h> |
| 15 | #include <platform_def.h> |
| 16 | #include <plat_marvell.h> |
| 17 | #include <string.h> |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 18 | #include <utils.h> |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 19 | |
| 20 | /* Data structure which holds the extents of the trusted SRAM for BL2 */ |
| 21 | static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE); |
| 22 | |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 23 | /* Weak definitions may be overridden in specific MARVELL standard platform */ |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 24 | #pragma weak bl2_early_platform_setup2 |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 25 | #pragma weak bl2_platform_setup |
| 26 | #pragma weak bl2_plat_arch_setup |
| 27 | #pragma weak bl2_plat_sec_mem_layout |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 28 | |
| 29 | meminfo_t *bl2_plat_sec_mem_layout(void) |
| 30 | { |
| 31 | return &bl2_tzram_layout; |
| 32 | } |
| 33 | |
| 34 | /***************************************************************************** |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 35 | * 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 | */ |
| 40 | void marvell_bl2_early_platform_setup(meminfo_t *mem_layout) |
| 41 | { |
| 42 | /* Initialize the console to provide early debug support */ |
| 43 | console_init(PLAT_MARVELL_BOOT_UART_BASE, |
| 44 | PLAT_MARVELL_BOOT_UART_CLK_IN_HZ, |
| 45 | MARVELL_CONSOLE_BAUDRATE); |
| 46 | |
| 47 | /* Setup the BL2 memory layout */ |
| 48 | bl2_tzram_layout = *mem_layout; |
| 49 | |
| 50 | /* Initialise the IO layer and register platform IO devices */ |
| 51 | plat_marvell_io_setup(); |
| 52 | } |
| 53 | |
Antonio Nino Diaz | 7966221 | 2018-09-24 17:15:46 +0100 | [diff] [blame] | 54 | |
| 55 | void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 56 | u_register_t arg2, u_register_t arg3) |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 57 | { |
Antonio Nino Diaz | 7966221 | 2018-09-24 17:15:46 +0100 | [diff] [blame] | 58 | struct meminfo *mem_layout = (struct meminfo *)arg1; |
| 59 | |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 60 | marvell_bl2_early_platform_setup(mem_layout); |
| 61 | } |
| 62 | |
| 63 | void bl2_platform_setup(void) |
| 64 | { |
| 65 | /* Nothing to do */ |
| 66 | } |
| 67 | |
| 68 | /***************************************************************************** |
| 69 | * Perform the very early platform specific architectural setup here. At the |
| 70 | * moment this is only initializes the mmu in a quick and dirty way. |
| 71 | ***************************************************************************** |
| 72 | */ |
| 73 | void marvell_bl2_plat_arch_setup(void) |
| 74 | { |
| 75 | marvell_setup_page_tables(bl2_tzram_layout.total_base, |
| 76 | bl2_tzram_layout.total_size, |
| 77 | BL_CODE_BASE, |
| 78 | BL_CODE_END, |
| 79 | BL_RO_DATA_BASE, |
| 80 | BL_RO_DATA_END |
| 81 | #if USE_COHERENT_MEM |
| 82 | , BL_COHERENT_RAM_BASE, |
| 83 | BL_COHERENT_RAM_END |
| 84 | #endif |
| 85 | ); |
| 86 | enable_mmu_el1(0); |
| 87 | } |
| 88 | |
| 89 | void bl2_plat_arch_setup(void) |
| 90 | { |
| 91 | marvell_bl2_plat_arch_setup(); |
| 92 | } |
| 93 | |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 94 | int marvell_bl2_handle_post_image_load(unsigned int image_id) |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 95 | { |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 96 | int err = 0; |
| 97 | bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id); |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 98 | |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 99 | assert(bl_mem_params); |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 100 | |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 101 | switch (image_id) { |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 102 | |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 103 | case BL33_IMAGE_ID: |
| 104 | /* BL33 expects to receive the primary CPU MPID (through r0) */ |
| 105 | bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr(); |
| 106 | bl_mem_params->ep_info.spsr = marvell_get_spsr_for_bl33_entry(); |
| 107 | break; |
Grzegorz Jaszczyk | 62c2486 | 2018-10-04 09:44:56 +0200 | [diff] [blame] | 108 | #ifdef SCP_BL2_BASE |
| 109 | case SCP_BL2_IMAGE_ID: |
| 110 | /* The subsequent handling of SCP_BL2 is platform specific */ |
| 111 | err = bl2_plat_handle_scp_bl2(&bl_mem_params->image_info); |
| 112 | if (err) { |
| 113 | WARN("Failure in platform-specific handling of SCP_BL2 image.\n"); |
| 114 | } |
| 115 | break; |
| 116 | #endif |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 117 | default: |
| 118 | /* Do nothing in default case */ |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | return err; |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 123 | |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 124 | } |
| 125 | |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 126 | /******************************************************************************* |
| 127 | * This function can be used by the platforms to update/use image |
| 128 | * information for given `image_id`. |
| 129 | ******************************************************************************/ |
| 130 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 131 | { |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 132 | return marvell_bl2_handle_post_image_load(image_id); |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 133 | } |
Konstantin Porotchkin | d973c03 | 2018-10-02 17:45:15 +0300 | [diff] [blame] | 134 | |