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 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 9 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 11 | #include <arch_helpers.h> |
| 12 | #include <common/bl_common.h> |
| 13 | #include <common/debug.h> |
| 14 | #include <common/desc_image_load.h> |
| 15 | #include <lib/optee_utils.h> |
| 16 | #include <lib/xlat_tables/xlat_mmu_helpers.h> |
| 17 | #include <lib/xlat_tables/xlat_tables_defs.h> |
Ying-Chun Liu (PaulLiu) | 3452738 | 2019-01-22 03:27:55 +0800 | [diff] [blame] | 18 | #include <drivers/generic_delay_timer.h> |
| 19 | #include <drivers/rpi3/gpio/rpi3_gpio.h> |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 20 | |
| 21 | #include "rpi3_private.h" |
| 22 | |
| 23 | /* Data structure which holds the extents of the trusted SRAM for BL2 */ |
| 24 | static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE); |
| 25 | |
Ying-Chun Liu (PaulLiu) | 3452738 | 2019-01-22 03:27:55 +0800 | [diff] [blame] | 26 | /* rpi3 GPIO setup function. */ |
| 27 | static void rpi3_gpio_setup(void) |
| 28 | { |
| 29 | struct rpi3_gpio_params params; |
| 30 | |
| 31 | memset(¶ms, 0, sizeof(struct rpi3_gpio_params)); |
| 32 | params.reg_base = RPI3_GPIO_BASE; |
| 33 | |
| 34 | rpi3_gpio_init(¶ms); |
| 35 | } |
| 36 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 37 | /******************************************************************************* |
| 38 | * 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 | ******************************************************************************/ |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 42 | |
| 43 | void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 44 | u_register_t arg2, u_register_t arg3) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 45 | { |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 46 | meminfo_t *mem_layout = (meminfo_t *) arg1; |
| 47 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 48 | /* Initialize the console to provide early debug support */ |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 49 | rpi3_console_init(); |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 50 | |
Ying-Chun Liu (PaulLiu) | 3452738 | 2019-01-22 03:27:55 +0800 | [diff] [blame] | 51 | /* Enable arch timer */ |
| 52 | generic_delay_timer_init(); |
| 53 | |
| 54 | /* Setup GPIO driver */ |
| 55 | rpi3_gpio_setup(); |
| 56 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 57 | /* Setup the BL2 memory layout */ |
| 58 | bl2_tzram_layout = *mem_layout; |
| 59 | |
| 60 | plat_rpi3_io_setup(); |
| 61 | } |
| 62 | |
| 63 | void bl2_platform_setup(void) |
| 64 | { |
| 65 | /* |
| 66 | * This is where a TrustZone address space controller and other |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 67 | * security related peripherals would be configured. |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 68 | */ |
| 69 | } |
| 70 | |
| 71 | /******************************************************************************* |
| 72 | * Perform the very early platform specific architectural setup here. |
| 73 | ******************************************************************************/ |
| 74 | void bl2_plat_arch_setup(void) |
| 75 | { |
| 76 | rpi3_setup_page_tables(bl2_tzram_layout.total_base, |
| 77 | bl2_tzram_layout.total_size, |
| 78 | BL_CODE_BASE, BL_CODE_END, |
| 79 | BL_RO_DATA_BASE, BL_RO_DATA_END |
| 80 | #if USE_COHERENT_MEM |
| 81 | , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 82 | #endif |
| 83 | ); |
| 84 | |
| 85 | enable_mmu_el1(0); |
| 86 | } |
| 87 | |
| 88 | /******************************************************************************* |
| 89 | * This function can be used by the platforms to update/use image |
| 90 | * information for given `image_id`. |
| 91 | ******************************************************************************/ |
| 92 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 93 | { |
| 94 | int err = 0; |
| 95 | 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] | 96 | #ifdef SPD_opteed |
| 97 | bl_mem_params_node_t *pager_mem_params = NULL; |
| 98 | bl_mem_params_node_t *paged_mem_params = NULL; |
| 99 | #endif |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 100 | |
| 101 | assert(bl_mem_params != NULL); |
| 102 | |
| 103 | switch (image_id) { |
| 104 | case BL32_IMAGE_ID: |
Ying-Chun Liu (PaulLiu) | d9f76e6 | 2018-06-10 02:00:27 +0800 | [diff] [blame] | 105 | #ifdef SPD_opteed |
| 106 | pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID); |
| 107 | assert(pager_mem_params); |
| 108 | |
| 109 | paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID); |
| 110 | assert(paged_mem_params); |
| 111 | |
| 112 | err = parse_optee_header(&bl_mem_params->ep_info, |
| 113 | &pager_mem_params->image_info, |
| 114 | &paged_mem_params->image_info); |
| 115 | if (err != 0) |
| 116 | WARN("OPTEE header parse error.\n"); |
| 117 | #endif |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 118 | bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry(); |
| 119 | break; |
| 120 | |
| 121 | case BL33_IMAGE_ID: |
| 122 | /* BL33 expects to receive the primary CPU MPID (through r0) */ |
| 123 | bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr(); |
| 124 | bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry(); |
| 125 | break; |
| 126 | |
Jonathan Wright | ff957ed | 2018-03-14 15:24:00 +0000 | [diff] [blame] | 127 | default: |
| 128 | /* Do nothing in default case */ |
| 129 | break; |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | return err; |
| 133 | } |