blob: a172d42ab379b109db1d6eef90f8d2118ad98bbb [file] [log] [blame]
Julius Werner745a75f2015-05-11 16:45:56 -07001/*
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 Werner745a75f2015-05-11 16:45:56 -070014 */
15
16#include <arch/cache.h>
Furquan Shaikha384c282015-05-28 12:13:51 -070017#include <arch/lib_helpers.h>
Julius Wernerfe4cbf12015-10-07 18:38:24 -070018#include <arch/mmu.h>
Furquan Shaikha384c282015-05-28 12:13:51 -070019#include <arch/transition.h>
Julius Werner745a75f2015-05-11 16:45:56 -070020#include <arm_tf.h>
21#include <assert.h>
22#include <cbfs.h>
23#include <cbmem.h>
Aaron Durbin64031672018-04-21 14:45:32 -060024#include <compiler.h>
Aaron Durbin899d13d2015-05-15 23:39:23 -050025#include <program_loading.h>
Julius Werner745a75f2015-05-11 16:45:56 -070026
27/*
28 * TODO: Many of these structures are currently unused. Better not fill them out
29 * to make future changes fail fast, rather than try to come up with content
30 * that might turn out to not make sense. Implement later as required.
31 *
32static image_info_t bl31_image_info;
33static image_info_t bl32_image_info;
34static image_info_t bl33_image_info;
Julius Werner745a75f2015-05-11 16:45:56 -070035 */
Furquan Shaikha384c282015-05-28 12:13:51 -070036static entry_point_info_t bl32_ep_info;
Julius Werner745a75f2015-05-11 16:45:56 -070037static entry_point_info_t bl33_ep_info;
38static bl31_params_t bl31_params;
39
Aaron Durbin64031672018-04-21 14:45:32 -060040void __weak *soc_get_bl31_plat_params(bl31_params_t *params)
Furquan Shaikh49d30662015-05-20 11:03:50 -070041{
42 /* Default weak implementation. */
43 return NULL;
44}
45
Julius Werner745a75f2015-05-11 16:45:56 -070046void arm_tf_run_bl31(u64 payload_entry, u64 payload_arg0, u64 payload_spsr)
47{
Aaron Durbin7e7a4df2015-12-08 14:34:35 -060048 struct prog bl31 = PROG_INIT(PROG_BL31, CONFIG_CBFS_PREFIX"/bl31");
Julius Werner745a75f2015-05-11 16:45:56 -070049 void (*bl31_entry)(bl31_params_t *params, void *plat_params) = NULL;
50
Aaron Durbin899d13d2015-05-15 23:39:23 -050051 if (prog_locate(&bl31))
52 die("BL31 not found");
Julius Werner745a75f2015-05-11 16:45:56 -070053
Simon Glass7ae73fc2016-08-27 12:18:38 -060054 bl31_entry = selfload(&bl31, false);
55 if (!bl31_entry)
Aaron Durbin899d13d2015-05-15 23:39:23 -050056 die("BL31 load failed");
57
Julius Werner745a75f2015-05-11 16:45:56 -070058 SET_PARAM_HEAD(&bl31_params, PARAM_BL31, VERSION_1, 0);
Furquan Shaikha384c282015-05-28 12:13:51 -070059
60 if (IS_ENABLED(CONFIG_ARM64_USE_SECURE_OS)) {
Simon Glass17c2b942016-08-27 12:02:09 -060061 struct prog bl32 = PROG_INIT(PROG_BL32,
62 CONFIG_CBFS_PREFIX"/secure_os");
Furquan Shaikha384c282015-05-28 12:13:51 -070063
64 if (prog_locate(&bl32))
Simon Glass17c2b942016-08-27 12:02:09 -060065 die("BL32 not found");
Furquan Shaikha384c282015-05-28 12:13:51 -070066
67 if (cbfs_prog_stage_load(&bl32))
Simon Glass17c2b942016-08-27 12:02:09 -060068 die("BL32 load failed");
Furquan Shaikha384c282015-05-28 12:13:51 -070069
Simon Glass17c2b942016-08-27 12:02:09 -060070 SET_PARAM_HEAD(&bl32_ep_info, PARAM_EP, VERSION_1,
71 PARAM_EP_SECURE);
Furquan Shaikha384c282015-05-28 12:13:51 -070072 bl32_ep_info.pc = (uintptr_t)prog_entry(&bl32);
Simon Glass17c2b942016-08-27 12:02:09 -060073 bl32_ep_info.spsr = SPSR_EXCEPTION_MASK |
74 get_eret_el(EL1, SPSR_USE_L);
Furquan Shaikha384c282015-05-28 12:13:51 -070075 bl31_params.bl32_ep_info = &bl32_ep_info;
76 }
77
Julius Werner745a75f2015-05-11 16:45:56 -070078 bl31_params.bl33_ep_info = &bl33_ep_info;
79
80 SET_PARAM_HEAD(&bl33_ep_info, PARAM_EP, VERSION_1, PARAM_EP_NON_SECURE);
81 bl33_ep_info.pc = payload_entry;
82 bl33_ep_info.spsr = payload_spsr;
83 bl33_ep_info.args.arg0 = payload_arg0;
84
Julius Werner91ebbfd2017-07-25 13:55:43 -070085 /* May update bl31_params if necessary. */
Julius Werner745a75f2015-05-11 16:45:56 -070086 void *bl31_plat_params = soc_get_bl31_plat_params(&bl31_params);
87
Julius Werner91ebbfd2017-07-25 13:55:43 -070088 /* MMU disable will flush cache, so passed params land in memory. */
Julius Werner38345202016-02-01 19:47:10 -080089 raw_write_daif(SPSR_EXCEPTION_MASK);
Julius Wernerfe4cbf12015-10-07 18:38:24 -070090 mmu_disable();
Julius Werner745a75f2015-05-11 16:45:56 -070091 bl31_entry(&bl31_params, bl31_plat_params);
92 die("BL31 returned!");
93}