Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 1 | /* |
Andre Przywara | 4ea3bd3 | 2019-07-09 14:32:11 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, 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> |
Ying-Chun Liu (PaulLiu) | de6f2f4 | 2019-01-30 04:20:38 +0800 | [diff] [blame] | 20 | #include <drivers/rpi3/sdhost/rpi3_sdhost.h> |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 21 | |
Andre Przywara | 4ea3bd3 | 2019-07-09 14:32:11 +0100 | [diff] [blame] | 22 | #include <rpi_shared.h> |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 23 | |
| 24 | /* Data structure which holds the extents of the trusted SRAM for BL2 */ |
| 25 | static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE); |
| 26 | |
Ying-Chun Liu (PaulLiu) | de6f2f4 | 2019-01-30 04:20:38 +0800 | [diff] [blame] | 27 | /* Data structure which holds the MMC info */ |
| 28 | static struct mmc_device_info mmc_info; |
| 29 | |
| 30 | static void rpi3_sdhost_setup(void) |
| 31 | { |
| 32 | struct rpi3_sdhost_params params; |
| 33 | |
| 34 | memset(¶ms, 0, sizeof(struct rpi3_sdhost_params)); |
| 35 | params.reg_base = RPI3_SDHOST_BASE; |
Ying-Chun Liu (PaulLiu) | a5cdc08 | 2019-02-12 22:41:06 +0800 | [diff] [blame] | 36 | params.bus_width = MMC_BUS_WIDTH_1; |
| 37 | params.clk_rate = 50000000; |
Rob Newberry | 5db3008 | 2023-03-30 10:43:21 -0700 | [diff] [blame] | 38 | params.clk_rate_initial = (RPI3_SDHOST_MAX_CLOCK / HC_CLOCKDIVISOR_MAXVAL); |
Ying-Chun Liu (PaulLiu) | de6f2f4 | 2019-01-30 04:20:38 +0800 | [diff] [blame] | 39 | mmc_info.mmc_dev_type = MMC_IS_SD_HC; |
Rob Newberry | 5db3008 | 2023-03-30 10:43:21 -0700 | [diff] [blame] | 40 | mmc_info.ocr_voltage = OCR_3_2_3_3 | OCR_3_3_3_4; |
Ying-Chun Liu (PaulLiu) | de6f2f4 | 2019-01-30 04:20:38 +0800 | [diff] [blame] | 41 | rpi3_sdhost_init(¶ms, &mmc_info); |
| 42 | } |
| 43 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 44 | /******************************************************************************* |
| 45 | * BL1 has passed the extents of the trusted SRAM that should be visible to BL2 |
| 46 | * in x0. This memory layout is sitting at the base of the free trusted SRAM. |
| 47 | * Copy it to a safe location before its reclaimed by later BL2 functionality. |
| 48 | ******************************************************************************/ |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 49 | |
| 50 | void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 51 | u_register_t arg2, u_register_t arg3) |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 52 | { |
Antonio Nino Diaz | 83d8c79 | 2018-08-17 14:25:08 +0100 | [diff] [blame] | 53 | meminfo_t *mem_layout = (meminfo_t *) arg1; |
| 54 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 55 | /* Initialize the console to provide early debug support */ |
Andre Przywara | 57ccecc | 2020-03-10 12:33:16 +0000 | [diff] [blame] | 56 | rpi3_console_init(); |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 57 | |
Ying-Chun Liu (PaulLiu) | 3452738 | 2019-01-22 03:27:55 +0800 | [diff] [blame] | 58 | /* Enable arch timer */ |
| 59 | generic_delay_timer_init(); |
| 60 | |
| 61 | /* Setup GPIO driver */ |
Andre Przywara | 203e7c4 | 2020-03-11 16:10:40 +0000 | [diff] [blame] | 62 | rpi3_gpio_init(); |
Ying-Chun Liu (PaulLiu) | 3452738 | 2019-01-22 03:27:55 +0800 | [diff] [blame] | 63 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 64 | /* Setup the BL2 memory layout */ |
| 65 | bl2_tzram_layout = *mem_layout; |
| 66 | |
Ying-Chun Liu (PaulLiu) | de6f2f4 | 2019-01-30 04:20:38 +0800 | [diff] [blame] | 67 | /* Setup SDHost driver */ |
| 68 | rpi3_sdhost_setup(); |
| 69 | |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 70 | plat_rpi3_io_setup(); |
| 71 | } |
| 72 | |
| 73 | void bl2_platform_setup(void) |
| 74 | { |
| 75 | /* |
| 76 | * This is where a TrustZone address space controller and other |
Antonio Nino Diaz | 1f47002 | 2018-03-27 09:39:47 +0100 | [diff] [blame] | 77 | * security related peripherals would be configured. |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 78 | */ |
| 79 | } |
| 80 | |
| 81 | /******************************************************************************* |
| 82 | * Perform the very early platform specific architectural setup here. |
| 83 | ******************************************************************************/ |
| 84 | void bl2_plat_arch_setup(void) |
| 85 | { |
| 86 | rpi3_setup_page_tables(bl2_tzram_layout.total_base, |
| 87 | bl2_tzram_layout.total_size, |
| 88 | BL_CODE_BASE, BL_CODE_END, |
| 89 | BL_RO_DATA_BASE, BL_RO_DATA_END |
| 90 | #if USE_COHERENT_MEM |
| 91 | , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END |
| 92 | #endif |
| 93 | ); |
| 94 | |
| 95 | enable_mmu_el1(0); |
| 96 | } |
| 97 | |
| 98 | /******************************************************************************* |
| 99 | * This function can be used by the platforms to update/use image |
| 100 | * information for given `image_id`. |
| 101 | ******************************************************************************/ |
| 102 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 103 | { |
| 104 | int err = 0; |
| 105 | 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] | 106 | #ifdef SPD_opteed |
| 107 | bl_mem_params_node_t *pager_mem_params = NULL; |
| 108 | bl_mem_params_node_t *paged_mem_params = NULL; |
| 109 | #endif |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 110 | |
| 111 | assert(bl_mem_params != NULL); |
| 112 | |
| 113 | switch (image_id) { |
| 114 | case BL32_IMAGE_ID: |
Ying-Chun Liu (PaulLiu) | d9f76e6 | 2018-06-10 02:00:27 +0800 | [diff] [blame] | 115 | #ifdef SPD_opteed |
| 116 | pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID); |
| 117 | assert(pager_mem_params); |
| 118 | |
| 119 | paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID); |
| 120 | assert(paged_mem_params); |
| 121 | |
| 122 | err = parse_optee_header(&bl_mem_params->ep_info, |
| 123 | &pager_mem_params->image_info, |
| 124 | &paged_mem_params->image_info); |
| 125 | if (err != 0) |
| 126 | WARN("OPTEE header parse error.\n"); |
| 127 | #endif |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 128 | bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry(); |
| 129 | break; |
| 130 | |
| 131 | case BL33_IMAGE_ID: |
| 132 | /* BL33 expects to receive the primary CPU MPID (through r0) */ |
| 133 | bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr(); |
| 134 | bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry(); |
Ying-Chun Liu (PaulLiu) | de6f2f4 | 2019-01-30 04:20:38 +0800 | [diff] [blame] | 135 | |
| 136 | /* Shutting down the SDHost driver to let BL33 drives SDHost.*/ |
| 137 | rpi3_sdhost_stop(); |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 138 | break; |
| 139 | |
Jonathan Wright | ff957ed | 2018-03-14 15:24:00 +0000 | [diff] [blame] | 140 | default: |
| 141 | /* Do nothing in default case */ |
| 142 | break; |
Antonio Nino Diaz | ae6779e | 2017-11-06 14:49:04 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return err; |
| 146 | } |