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