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> |
| 12 | #include <platform.h> |
| 13 | #include <platform_def.h> |
| 14 | #include <xlat_tables_v2.h> |
| 15 | |
| 16 | #include "uniphier.h" |
| 17 | |
Masahiro Yamada | cad2ab5 | 2018-01-30 18:49:37 +0900 | [diff] [blame] | 18 | #define BL2_END (unsigned long)(&__BL2_END__) |
| 19 | #define BL2_SIZE ((BL2_END) - (BL2_BASE)) |
| 20 | |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 21 | static int uniphier_bl2_kick_scp; |
| 22 | |
Masahiro Yamada | 75bfecb | 2017-12-19 11:56:05 +0900 | [diff] [blame] | 23 | void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1, |
| 24 | u_register_t x2, u_register_t x3) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 25 | { |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 26 | uniphier_console_setup(); |
| 27 | } |
| 28 | |
| 29 | static const struct mmap_region uniphier_bl2_mmap[] = { |
Masahiro Yamada | cad2ab5 | 2018-01-30 18:49:37 +0900 | [diff] [blame] | 30 | /* for BL31, BL32 */ |
| 31 | MAP_REGION_FLAT(UNIPHIER_SEC_DRAM_BASE, UNIPHIER_SEC_DRAM_SIZE, |
| 32 | MT_MEMORY | MT_RW | MT_SECURE), |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 33 | /* for SCP, BL33 */ |
| 34 | MAP_REGION_FLAT(UNIPHIER_NS_DRAM_BASE, UNIPHIER_NS_DRAM_SIZE, |
| 35 | MT_MEMORY | MT_RW | MT_NS), |
| 36 | { .size = 0 }, |
| 37 | }; |
| 38 | |
Masahiro Yamada | 75bfecb | 2017-12-19 11:56:05 +0900 | [diff] [blame] | 39 | void bl2_el3_plat_arch_setup(void) |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 40 | { |
| 41 | unsigned int soc; |
| 42 | int skip_scp = 0; |
| 43 | int ret; |
| 44 | |
Masahiro Yamada | cad2ab5 | 2018-01-30 18:49:37 +0900 | [diff] [blame] | 45 | uniphier_mmap_setup(BL2_BASE, BL2_SIZE, uniphier_bl2_mmap); |
Masahiro Yamada | 75bfecb | 2017-12-19 11:56:05 +0900 | [diff] [blame] | 46 | enable_mmu_el3(0); |
Masahiro Yamada | 574388c | 2016-09-03 11:37:40 +0900 | [diff] [blame] | 47 | |
| 48 | soc = uniphier_get_soc_id(); |
| 49 | if (soc == UNIPHIER_SOC_UNKNOWN) { |
| 50 | ERROR("unsupported SoC\n"); |
| 51 | plat_error_handler(-ENOTSUP); |
| 52 | } |
| 53 | |
| 54 | ret = uniphier_io_setup(soc); |
| 55 | if (ret) { |
| 56 | ERROR("failed to setup io devices\n"); |
| 57 | plat_error_handler(ret); |
| 58 | } |
| 59 | |
| 60 | switch (uniphier_get_boot_master(soc)) { |
| 61 | case UNIPHIER_BOOT_MASTER_THIS: |
| 62 | INFO("Booting from this SoC\n"); |
| 63 | skip_scp = 1; |
| 64 | break; |
| 65 | case UNIPHIER_BOOT_MASTER_SCP: |
| 66 | INFO("Booting from on-chip SCP\n"); |
| 67 | if (uniphier_scp_is_running()) { |
| 68 | INFO("SCP is already running. SCP_BL2 load will be skipped.\n"); |
| 69 | skip_scp = 1; |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * SCP must be kicked every time even if it is already running |
| 74 | * because it polls this event after the reboot of the backend. |
| 75 | */ |
| 76 | uniphier_bl2_kick_scp = 1; |
| 77 | break; |
| 78 | case UNIPHIER_BOOT_MASTER_EXT: |
| 79 | INFO("Booting from external SCP\n"); |
| 80 | skip_scp = 1; |
| 81 | break; |
| 82 | default: |
| 83 | plat_error_handler(-ENOTSUP); |
| 84 | } |
| 85 | |
| 86 | if (!skip_scp) { |
| 87 | ret = uniphier_check_image(SCP_BL2_IMAGE_ID); |
| 88 | if (ret) { |
| 89 | WARN("SCP_BL2 image not found. SCP_BL2 load will be skipped.\n"); |
| 90 | WARN("You must setup SCP by other means.\n"); |
| 91 | skip_scp = 1; |
| 92 | uniphier_bl2_kick_scp = 0; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if (skip_scp) |
| 97 | uniphier_image_descs_fixup(); |
| 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 | int bl2_plat_handle_post_image_load(unsigned int image_id) |
| 120 | { |
| 121 | if (image_id == SCP_BL2_IMAGE_ID && uniphier_bl2_kick_scp) |
| 122 | uniphier_scp_start(); |
| 123 | |
| 124 | return 0; |
| 125 | } |