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