Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | e44b8c6 | 2020-01-17 13:46:02 +0900 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 7 | #include <errno.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 9 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 11 | #include <common/bl_common.h> |
| 12 | #include <common/debug.h> |
| 13 | #include <common/desc_image_load.h> |
| 14 | #include <common/image_decompress.h> |
| 15 | #include <drivers/io/io_storage.h> |
| 16 | #include <lib/xlat_tables/xlat_tables_v2.h> |
| 17 | #include <plat/common/platform.h> |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 18 | #ifdef UNIPHIER_DECOMPRESS_GZIP |
| 19 | #include <tf_gunzip.h> |
| 20 | #endif |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 21 | |
| 22 | #include "uniphier.h" |
| 23 | |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 24 | #define UNIPHIER_IMAGE_BUF_OFFSET 0x04300000UL |
Masahiro Yamada | e44b8c6 | 2020-01-17 13:46:02 +0900 | [diff] [blame] | 25 | #define UNIPHIER_IMAGE_BUF_SIZE 0x00100000UL |
| 26 | |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 27 | static uintptr_t uniphier_mem_base = UNIPHIER_MEM_BASE; |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 28 | static int uniphier_bl2_kick_scp; |
| 29 | |
Masahiro Yamada | 75bfecb | 2017-12-19 11:56:05 +0900 | [diff] [blame] | 30 | void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1, |
| 31 | u_register_t x2, u_register_t x3) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 32 | { |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 33 | uniphier_console_setup(); |
| 34 | } |
| 35 | |
Masahiro Yamada | 75bfecb | 2017-12-19 11:56:05 +0900 | [diff] [blame] | 36 | void bl2_el3_plat_arch_setup(void) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 37 | { |
| 38 | unsigned int soc; |
| 39 | int skip_scp = 0; |
| 40 | int ret; |
| 41 | |
Masahiro Yamada | e30ec7f | 2020-01-17 13:46:38 +0900 | [diff] [blame] | 42 | uniphier_mmap_setup(); |
Masahiro Yamada | 75bfecb | 2017-12-19 11:56:05 +0900 | [diff] [blame] | 43 | enable_mmu_el3(0); |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 44 | |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 45 | /* add relocation offset (run-time-address - link-address) */ |
| 46 | uniphier_mem_base += BL_CODE_BASE - BL2_BASE; |
| 47 | |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 48 | soc = uniphier_get_soc_id(); |
| 49 | if (soc == UNIPHIER_SOC_UNKNOWN) { |
| 50 | ERROR("unsupported SoC\n"); |
| 51 | plat_error_handler(-ENOTSUP); |
| 52 | } |
| 53 | |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 54 | ret = uniphier_io_setup(soc, uniphier_mem_base); |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 55 | if (ret) { |
| 56 | ERROR("failed to setup io devices\n"); |
| 57 | plat_error_handler(ret); |
| 58 | } |
| 59 | |
| 60 | switch (uniphier_get_boot_master(soc)) { |
| 61 | case UNIPHIER_BOOT_MASTER_THIS: |
| 62 | INFO("Booting from this SoC\n"); |
| 63 | skip_scp = 1; |
| 64 | break; |
| 65 | case UNIPHIER_BOOT_MASTER_SCP: |
| 66 | INFO("Booting from on-chip SCP\n"); |
| 67 | if (uniphier_scp_is_running()) { |
| 68 | INFO("SCP is already running. SCP_BL2 load will be skipped.\n"); |
| 69 | skip_scp = 1; |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * SCP must be kicked every time even if it is already running |
| 74 | * because it polls this event after the reboot of the backend. |
| 75 | */ |
| 76 | uniphier_bl2_kick_scp = 1; |
| 77 | break; |
| 78 | case UNIPHIER_BOOT_MASTER_EXT: |
| 79 | INFO("Booting from external SCP\n"); |
| 80 | skip_scp = 1; |
| 81 | break; |
| 82 | default: |
| 83 | plat_error_handler(-ENOTSUP); |
Jonathan Wright | ff957ed | 2018-03-14 15:24:00 +0000 | [diff] [blame] | 84 | break; |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 85 | } |
| 86 | |
Masahiro Yamada | 4c91c80 | 2018-02-01 21:37:40 +0900 | [diff] [blame] | 87 | if (skip_scp) { |
| 88 | struct image_info *image_info; |
| 89 | |
| 90 | image_info = uniphier_get_image_info(SCP_BL2_IMAGE_ID); |
| 91 | image_info->h.attr |= IMAGE_ATTRIB_SKIP_LOADING; |
| 92 | } |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void bl2_platform_setup(void) |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | void plat_flush_next_bl_params(void) |
| 100 | { |
| 101 | flush_bl_params_desc(); |
| 102 | } |
| 103 | |
| 104 | bl_load_info_t *plat_get_bl_image_load_info(void) |
| 105 | { |
| 106 | return get_bl_load_info_from_mem_params_desc(); |
| 107 | } |
| 108 | |
| 109 | bl_params_t *plat_get_next_bl_params(void) |
| 110 | { |
| 111 | return get_next_bl_params_from_mem_params_desc(); |
| 112 | } |
| 113 | |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 114 | void bl2_plat_preload_setup(void) |
| 115 | { |
| 116 | #ifdef UNIPHIER_DECOMPRESS_GZIP |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 117 | uintptr_t buf_base = uniphier_mem_base + UNIPHIER_IMAGE_BUF_OFFSET; |
Masahiro Yamada | e44b8c6 | 2020-01-17 13:46:02 +0900 | [diff] [blame] | 118 | int ret; |
| 119 | |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 120 | ret = mmap_add_dynamic_region(buf_base, buf_base, |
Masahiro Yamada | e44b8c6 | 2020-01-17 13:46:02 +0900 | [diff] [blame] | 121 | UNIPHIER_IMAGE_BUF_SIZE, |
| 122 | MT_MEMORY | MT_RW | MT_NS); |
| 123 | if (ret) |
| 124 | plat_error_handler(ret); |
| 125 | |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 126 | image_decompress_init(buf_base, UNIPHIER_IMAGE_BUF_SIZE, gunzip); |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 127 | #endif |
Masahiro Yamada | 542ed41 | 2020-01-17 13:46:48 +0900 | [diff] [blame] | 128 | |
| 129 | uniphier_init_image_descs(uniphier_mem_base); |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | int bl2_plat_handle_pre_image_load(unsigned int image_id) |
| 133 | { |
Masahiro Yamada | e44b8c6 | 2020-01-17 13:46:02 +0900 | [diff] [blame] | 134 | struct image_info *image_info; |
| 135 | int ret; |
| 136 | |
| 137 | image_info = uniphier_get_image_info(image_id); |
| 138 | |
| 139 | ret = mmap_add_dynamic_region(image_info->image_base, |
| 140 | image_info->image_base, |
| 141 | image_info->image_max_size, |
| 142 | MT_MEMORY | MT_RW | MT_NS); |
| 143 | if (ret) |
| 144 | return ret; |
| 145 | |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 146 | #ifdef UNIPHIER_DECOMPRESS_GZIP |
Masahiro Yamada | e44b8c6 | 2020-01-17 13:46:02 +0900 | [diff] [blame] | 147 | image_decompress_prepare(image_info); |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 148 | #endif |
| 149 | return 0; |
| 150 | } |
| 151 | |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 152 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 153 | { |
Masahiro Yamada | 2d7fa42 | 2020-01-17 13:46:23 +0900 | [diff] [blame] | 154 | struct image_info *image_info = uniphier_get_image_info(image_id); |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 155 | #ifdef UNIPHIER_DECOMPRESS_GZIP |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 156 | int ret; |
| 157 | |
Masahiro Yamada | 4ff71af | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 158 | if (!(image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) { |
| 159 | ret = image_decompress(uniphier_get_image_info(image_id)); |
| 160 | if (ret) |
| 161 | return ret; |
| 162 | } |
| 163 | #endif |
| 164 | |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 165 | if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp) |
Masahiro Yamada | 2d7fa42 | 2020-01-17 13:46:23 +0900 | [diff] [blame] | 166 | uniphier_scp_start(image_info->image_base); |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 167 | |
| 168 | return 0; |
| 169 | } |