Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/cache.h> |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 17 | #include <arch/lib_helpers.h> |
Julius Werner | fe4cbf1 | 2015-10-07 18:38:24 -0700 | [diff] [blame] | 18 | #include <arch/mmu.h> |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 19 | #include <arch/transition.h> |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 20 | #include <arm_tf.h> |
| 21 | #include <assert.h> |
Ting Shen | 0553226 | 2019-01-28 17:22:22 +0800 | [diff] [blame] | 22 | #include <bootmem.h> |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 23 | #include <cbfs.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 24 | #include <program_loading.h> |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 25 | |
| 26 | /* |
| 27 | * TODO: Many of these structures are currently unused. Better not fill them out |
| 28 | * to make future changes fail fast, rather than try to come up with content |
| 29 | * that might turn out to not make sense. Implement later as required. |
| 30 | * |
| 31 | static image_info_t bl31_image_info; |
| 32 | static image_info_t bl32_image_info; |
| 33 | static image_info_t bl33_image_info; |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 34 | */ |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 35 | static entry_point_info_t bl32_ep_info; |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 36 | static entry_point_info_t bl33_ep_info; |
| 37 | static bl31_params_t bl31_params; |
| 38 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 39 | void __weak *soc_get_bl31_plat_params(bl31_params_t *params) |
Furquan Shaikh | 49d3066 | 2015-05-20 11:03:50 -0700 | [diff] [blame] | 40 | { |
| 41 | /* Default weak implementation. */ |
| 42 | return NULL; |
| 43 | } |
| 44 | |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 45 | void arm_tf_run_bl31(u64 payload_entry, u64 payload_arg0, u64 payload_spsr) |
| 46 | { |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 47 | struct prog bl31 = PROG_INIT(PROG_BL31, CONFIG_CBFS_PREFIX"/bl31"); |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 48 | void (*bl31_entry)(bl31_params_t *params, void *plat_params) = NULL; |
| 49 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 50 | if (prog_locate(&bl31)) |
| 51 | die("BL31 not found"); |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 52 | |
Ting Shen | dff29e0 | 2019-01-28 18:15:00 +0800 | [diff] [blame] | 53 | if (!selfload_check(&bl31, BM_MEM_BL31)) |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 54 | die("BL31 load failed"); |
Patrick Rudolph | 59b8f27 | 2018-04-26 09:53:16 +0200 | [diff] [blame] | 55 | bl31_entry = prog_entry(&bl31); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 56 | |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 57 | SET_PARAM_HEAD(&bl31_params, PARAM_BL31, VERSION_1, 0); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 58 | |
| 59 | if (IS_ENABLED(CONFIG_ARM64_USE_SECURE_OS)) { |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 60 | struct prog bl32 = PROG_INIT(PROG_BL32, |
| 61 | CONFIG_CBFS_PREFIX"/secure_os"); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 62 | |
| 63 | if (prog_locate(&bl32)) |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 64 | die("BL32 not found"); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 65 | |
| 66 | if (cbfs_prog_stage_load(&bl32)) |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 67 | die("BL32 load failed"); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 68 | |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 69 | SET_PARAM_HEAD(&bl32_ep_info, PARAM_EP, VERSION_1, |
| 70 | PARAM_EP_SECURE); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 71 | bl32_ep_info.pc = (uintptr_t)prog_entry(&bl32); |
Simon Glass | 17c2b94 | 2016-08-27 12:02:09 -0600 | [diff] [blame] | 72 | bl32_ep_info.spsr = SPSR_EXCEPTION_MASK | |
| 73 | get_eret_el(EL1, SPSR_USE_L); |
Furquan Shaikh | a384c28 | 2015-05-28 12:13:51 -0700 | [diff] [blame] | 74 | bl31_params.bl32_ep_info = &bl32_ep_info; |
| 75 | } |
| 76 | |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 77 | bl31_params.bl33_ep_info = &bl33_ep_info; |
| 78 | |
| 79 | SET_PARAM_HEAD(&bl33_ep_info, PARAM_EP, VERSION_1, PARAM_EP_NON_SECURE); |
| 80 | bl33_ep_info.pc = payload_entry; |
| 81 | bl33_ep_info.spsr = payload_spsr; |
| 82 | bl33_ep_info.args.arg0 = payload_arg0; |
| 83 | |
Julius Werner | 91ebbfd | 2017-07-25 13:55:43 -0700 | [diff] [blame] | 84 | /* May update bl31_params if necessary. */ |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 85 | void *bl31_plat_params = soc_get_bl31_plat_params(&bl31_params); |
| 86 | |
Julius Werner | 91ebbfd | 2017-07-25 13:55:43 -0700 | [diff] [blame] | 87 | /* MMU disable will flush cache, so passed params land in memory. */ |
Julius Werner | 3834520 | 2016-02-01 19:47:10 -0800 | [diff] [blame] | 88 | raw_write_daif(SPSR_EXCEPTION_MASK); |
Julius Werner | fe4cbf1 | 2015-10-07 18:38:24 -0700 | [diff] [blame] | 89 | mmu_disable(); |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 90 | bl31_entry(&bl31_params, bl31_plat_params); |
| 91 | die("BL31 returned!"); |
| 92 | } |