blob: 38045153927035ee1daea0076ca44589a1c3724b [file] [log] [blame]
Furquan Shaikh2af76f42014-04-28 16:39:40 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2013 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.
Furquan Shaikh2af76f42014-04-28 16:39:40 -070014 */
15
16#include <arch/cache.h>
Furquan Shaikh441df532014-09-11 16:06:01 -070017#include <arch/lib_helpers.h>
Furquan Shaikh2af76f42014-04-28 16:39:40 -070018#include <arch/stages.h>
Furquan Shaikh441df532014-09-11 16:06:01 -070019#include <arch/transition.h>
Julius Werner745a75f2015-05-11 16:45:56 -070020#include <arm_tf.h>
21#include <cbmem.h>
Aaron Durbin64031672018-04-21 14:45:32 -060022#include <compiler.h>
Furquan Shaikh2af76f42014-04-28 16:39:40 -070023#include <console/console.h>
Aaron Durbin04654a22015-03-17 11:43:44 -050024#include <program_loading.h>
Aaron Durbinb3847e62015-03-20 15:55:08 -050025#include <rules.h>
Furquan Shaikh441df532014-09-11 16:06:01 -070026#include <string.h>
Furquan Shaikh2af76f42014-04-28 16:39:40 -070027
Aaron Durbinb3847e62015-03-20 15:55:08 -050028static void run_payload(struct prog *prog)
Furquan Shaikh2af76f42014-04-28 16:39:40 -070029{
Aaron Durbin3948e532015-03-20 13:00:20 -050030 void (*doit)(void *);
31 void *arg;
Furquan Shaikhabde3b52014-08-26 15:39:51 -070032
Aaron Durbinb3847e62015-03-20 15:55:08 -050033 doit = prog_entry(prog);
34 arg = prog_entry_arg(prog);
Julius Werner38345202016-02-01 19:47:10 -080035 u64 payload_spsr = get_eret_el(EL2, SPSR_USE_L);
Aaron Durbin3948e532015-03-20 13:00:20 -050036
Julius Werner745a75f2015-05-11 16:45:56 -070037 if (IS_ENABLED(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE))
38 arm_tf_run_bl31((u64)doit, (u64)arg, payload_spsr);
Julius Werner786b1222015-05-07 16:59:31 -070039 else {
Julius Wernerf52602a2015-05-07 16:59:31 -070040 uint8_t current_el = get_current_el();
41
Julius Werner883ec982015-05-07 16:59:31 -070042 cache_sync_instructions();
43
Julius Wernerf52602a2015-05-07 16:59:31 -070044 printk(BIOS_SPEW, "entry = %p\n", doit);
45
Julius Werner786b1222015-05-07 16:59:31 -070046 /* If current EL is not EL3, jump to payload at same EL. */
Julius Wernerbbca3a92015-05-07 16:59:31 -070047 if (current_el != EL3)
Julius Werner786b1222015-05-07 16:59:31 -070048 doit(arg);
Julius Wernerbbca3a92015-05-07 16:59:31 -070049 else {
50 /* If current EL is EL3, we transition to payload in EL2. */
51 struct exc_state exc_state;
52 memset(&exc_state, 0, sizeof(exc_state));
Julius Werner745a75f2015-05-11 16:45:56 -070053 exc_state.elx.spsr = payload_spsr;
Julius Wernerbbca3a92015-05-07 16:59:31 -070054
55 transition_with_entry(doit, arg, &exc_state);
Julius Werner786b1222015-05-07 16:59:31 -070056 }
Furquan Shaikh441df532014-09-11 16:06:01 -070057 }
Furquan Shaikh2af76f42014-04-28 16:39:40 -070058}
Aaron Durbinb3847e62015-03-20 15:55:08 -050059
60void arch_prog_run(struct prog *prog)
61{
62 void (*doit)(void *);
63 void *arg;
64
Aaron Durbin7e7a4df2015-12-08 14:34:35 -060065 if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) {
Aaron Durbinb3847e62015-03-20 15:55:08 -050066 run_payload(prog);
67 return;
Paul Menzel9484f552015-04-05 18:30:05 +020068 }
Aaron Durbinb3847e62015-03-20 15:55:08 -050069
70 doit = prog_entry(prog);
71 arg = prog_entry_arg(prog);
72
73 doit(prog_entry_arg(prog));
74}
Julius Werner66a476a2015-10-12 16:45:21 -070075
Vladimir Serbinenkof0d39c42016-02-19 16:44:22 +010076int arch_supports_bounce_buffer(void)
77{
78 return 0;
79}
80
Julius Werner66a476a2015-10-12 16:45:21 -070081/* Generic stage entry point. Can be overridden by board/SoC if needed. */
Aaron Durbin64031672018-04-21 14:45:32 -060082__weak void stage_entry(void)
Julius Werner66a476a2015-10-12 16:45:21 -070083{
84 main();
85}