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