Patrick Georgi | 0a3d4e0 | 2020-03-04 14:39:09 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 3 | #include <arch/lib_helpers.h> |
Julius Werner | fe4cbf1 | 2015-10-07 18:38:24 -0700 | [diff] [blame] | 4 | #include <arch/mmu.h> |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 5 | #include <arch/transition.h> |
Julius Werner | 0a8da74 | 2019-08-02 12:45:24 -0700 | [diff] [blame] | 6 | #include <bl31.h> |
Ting Shen | 0553226 | 2019-01-28 17:22:22 +0800 | [diff] [blame] | 7 | #include <bootmem.h> |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 8 | #include <cbfs.h> |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 9 | #include <cbmem.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 10 | #include <console/console.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 11 | #include <program_loading.h> |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 12 | |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 13 | #include <arm-trusted-firmware/include/export/common/bl_common_exp.h> |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 14 | |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 15 | static entry_point_info_t bl32_ep_info = { |
| 16 | .h = { |
| 17 | .type = PARAM_EP, |
| 18 | .version = PARAM_VERSION_1, |
| 19 | .size = sizeof(bl32_ep_info), |
| 20 | .attr = EP_SECURE, |
| 21 | }, |
| 22 | }; |
| 23 | static entry_point_info_t bl33_ep_info = { |
| 24 | .h = { |
| 25 | .type = PARAM_EP, |
| 26 | .version = PARAM_VERSION_1, |
| 27 | .size = sizeof(bl33_ep_info), |
| 28 | .attr = EP_NON_SECURE, |
| 29 | }, |
| 30 | }; |
| 31 | |
| 32 | static bl_params_node_t bl32_params_node = { |
| 33 | .image_id = BL32_IMAGE_ID, |
| 34 | .ep_info = &bl32_ep_info, |
| 35 | }; |
| 36 | static bl_params_node_t bl33_params_node = { |
| 37 | .image_id = BL33_IMAGE_ID, |
| 38 | .ep_info = &bl33_ep_info, |
| 39 | }; |
| 40 | |
| 41 | static bl_params_t bl_params = { |
| 42 | .h = { |
| 43 | .type = PARAM_BL_PARAMS, |
| 44 | .version = PARAM_VERSION_2, |
| 45 | .size = sizeof(bl_params), |
| 46 | .attr = 0, |
| 47 | }, |
| 48 | .head = &bl33_params_node, |
| 49 | }; |
| 50 | |
| 51 | static struct bl_aux_param_header *bl_aux_params; |
| 52 | |
| 53 | /* Only works when using the default soc_get_bl31_plat_params() below. */ |
| 54 | void register_bl31_aux_param(struct bl_aux_param_header *param) |
Furquan Shaikh | 49d3066 | 2015-05-20 11:03:50 -0700 | [diff] [blame] | 55 | { |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 56 | param->next = (uintptr_t)bl_aux_params; |
| 57 | bl_aux_params = param; |
| 58 | } |
| 59 | |
| 60 | /* Default implementation. All newly added SoCs should use this if possible! */ |
| 61 | __weak void *soc_get_bl31_plat_params(void) |
| 62 | { |
| 63 | static struct bl_aux_param_uint64 cbtable_param = { |
| 64 | .h = { .type = BL_AUX_PARAM_COREBOOT_TABLE, }, |
| 65 | }; |
| 66 | if (!cbtable_param.value) { |
| 67 | cbtable_param.value = (uint64_t)cbmem_find(CBMEM_ID_CBTABLE); |
| 68 | if (cbtable_param.value) |
| 69 | register_bl31_aux_param(&cbtable_param.h); |
| 70 | } |
| 71 | return bl_aux_params; |
Furquan Shaikh | 49d3066 | 2015-05-20 11:03:50 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Julius Werner | 0a8da74 | 2019-08-02 12:45:24 -0700 | [diff] [blame] | 74 | void run_bl31(u64 payload_entry, u64 payload_arg0, u64 payload_spsr) |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 75 | { |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 76 | struct prog bl31 = PROG_INIT(PROG_BL31, CONFIG_CBFS_PREFIX"/bl31"); |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 77 | void (*bl31_entry)(bl_params_t *params, void *plat_params) = NULL; |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 78 | |
Ting Shen | dff29e0 | 2019-01-28 18:15:00 +0800 | [diff] [blame] | 79 | if (!selfload_check(&bl31, BM_MEM_BL31)) |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 80 | die("BL31 load failed"); |
Patrick Rudolph | 59b8f27 | 2018-04-26 09:53:16 +0200 | [diff] [blame] | 81 | bl31_entry = prog_entry(&bl31); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 82 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 83 | if (CONFIG(ARM64_USE_SECURE_OS)) { |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 84 | struct prog bl32 = PROG_INIT(PROG_BL32, |
| 85 | CONFIG_CBFS_PREFIX"/secure_os"); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 86 | |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 87 | if (cbfs_prog_stage_load(&bl32)) |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 88 | die("BL32 load failed"); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 89 | |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 90 | bl32_ep_info.pc = (uintptr_t)prog_entry(&bl32); |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 91 | bl32_ep_info.spsr = SPSR_EXCEPTION_MASK | |
| 92 | get_eret_el(EL1, SPSR_USE_L); |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 93 | bl33_params_node.next_params_info = &bl32_params_node; |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 96 | bl33_ep_info.pc = payload_entry; |
| 97 | bl33_ep_info.spsr = payload_spsr; |
| 98 | bl33_ep_info.args.arg0 = payload_arg0; |
| 99 | |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 100 | void *bl31_plat_params = soc_get_bl31_plat_params(); |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 101 | |
Julius Werner | 91ebbfd | 2017-07-25 13:55:43 -0700 | [diff] [blame] | 102 | /* MMU disable will flush cache, so passed params land in memory. */ |
Julius Werner | 3834520 | 2016-02-01 19:47:10 -0800 | [diff] [blame] | 103 | raw_write_daif(SPSR_EXCEPTION_MASK); |
Julius Werner | fe4cbf1 | 2015-10-07 18:38:24 -0700 | [diff] [blame] | 104 | mmu_disable(); |
Julius Werner | b3f24b4 | 2019-05-28 21:01:37 -0700 | [diff] [blame] | 105 | bl31_entry(&bl_params, bl31_plat_params); |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 106 | die("BL31 returned!"); |
| 107 | } |