Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 3 | * |
| 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 Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 10 | #include <debug.h> |
| 11 | #include <desc_image_load.h> |
Ying-Chun Liu (PaulLiu) | d9f76e6 | 2018-06-10 02:00:27 +0800 | [diff] [blame] | 12 | #include <optee_utils.h> |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 13 | #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 */ |
| 20 | static 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 | ******************************************************************************/ |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 27 | |
| 28 | void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 29 | u_register_t arg2, u_register_t arg3) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 30 | { |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 31 | meminfo_t *mem_layout = (meminfo_t *) arg1; |
| 32 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 33 | /* Initialize the console to provide early debug support */ |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 34 | rpi3_console_init(); |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 35 | |
| 36 | /* Setup the BL2 memory layout */ |
| 37 | bl2_tzram_layout = *mem_layout; |
| 38 | |
| 39 | plat_rpi3_io_setup(); |
| 40 | } |
| 41 | |
| 42 | void bl2_platform_setup(void) |
| 43 | { |
| 44 | /* |
| 45 | * This is where a TrustZone address space controller and other |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 46 | * security related peripherals would be configured. |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 47 | */ |
| 48 | } |
| 49 | |
| 50 | /******************************************************************************* |
| 51 | * Perform the very early platform specific architectural setup here. |
| 52 | ******************************************************************************/ |
| 53 | void bl2_plat_arch_setup(void) |
| 54 | { |
| 55 | rpi3_setup_page_tables(bl2_tzram_layout.total_base, |
| 56 | bl2_tzram_layout.total_size, |
| 57 | BL_CODE_BASE, BL_CODE_END, |
| 58 | BL_RO_DATA_BASE, BL_RO_DATA_END |
| 59 | #if USE_COHERENT_MEM |
| 60 | , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 61 | #endif |
| 62 | ); |
| 63 | |
| 64 | enable_mmu_el1(0); |
| 65 | } |
| 66 | |
| 67 | /******************************************************************************* |
| 68 | * This function can be used by the platforms to update/use image |
| 69 | * information for given `image_id`. |
| 70 | ******************************************************************************/ |
| 71 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 72 | { |
| 73 | int err = 0; |
| 74 | bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id); |
Ying-Chun Liu (PaulLiu) | d9f76e6 | 2018-06-10 02:00:27 +0800 | [diff] [blame] | 75 | #ifdef SPD_opteed |
| 76 | bl_mem_params_node_t *pager_mem_params = NULL; |
| 77 | bl_mem_params_node_t *paged_mem_params = NULL; |
| 78 | #endif |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 79 | |
| 80 | assert(bl_mem_params != NULL); |
| 81 | |
| 82 | switch (image_id) { |
| 83 | case BL32_IMAGE_ID: |
Ying-Chun Liu (PaulLiu) | d9f76e6 | 2018-06-10 02:00:27 +0800 | [diff] [blame] | 84 | #ifdef SPD_opteed |
| 85 | pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID); |
| 86 | assert(pager_mem_params); |
| 87 | |
| 88 | paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID); |
| 89 | assert(paged_mem_params); |
| 90 | |
| 91 | err = parse_optee_header(&bl_mem_params->ep_info, |
| 92 | &pager_mem_params->image_info, |
| 93 | &paged_mem_params->image_info); |
| 94 | if (err != 0) |
| 95 | WARN("OPTEE header parse error.\n"); |
| 96 | #endif |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 97 | bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry(); |
| 98 | break; |
| 99 | |
| 100 | case BL33_IMAGE_ID: |
| 101 | /* BL33 expects to receive the primary CPU MPID (through r0) */ |
| 102 | bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr(); |
| 103 | bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry(); |
| 104 | break; |
| 105 | |
Jonathan Wright | ff957ed | 2018-03-14 15:24:00 +0000 | [diff] [blame] | 106 | default: |
| 107 | /* Do nothing in default case */ |
| 108 | break; |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | return err; |
| 112 | } |