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