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