blob: c2119f389033d25a0ddf6ef46737326950c169b4 [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>
Aaron Durbin04654a22015-03-17 11:43:44 -050021#include <program_loading.h>
Furquan Shaikh441df532014-09-11 16:06:01 -070022#include <string.h>
Furquan Shaikh2af76f42014-04-28 16:39:40 -070023
Aaron Durbinb3847e62015-03-20 15:55:08 -050024static void run_payload(struct prog *prog)
Furquan Shaikh2af76f42014-04-28 16:39:40 -070025{
Aaron Durbin3948e532015-03-20 13:00:20 -050026 void (*doit)(void *);
27 void *arg;
Furquan Shaikhabde3b52014-08-26 15:39:51 -070028
Aaron Durbinb3847e62015-03-20 15:55:08 -050029 doit = prog_entry(prog);
30 arg = prog_entry_arg(prog);
Julius Werner38345202016-02-01 19:47:10 -080031 u64 payload_spsr = get_eret_el(EL2, SPSR_USE_L);
Aaron Durbin3948e532015-03-20 13:00:20 -050032
Julius Werner745a75f2015-05-11 16:45:56 -070033 if (IS_ENABLED(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE))
34 arm_tf_run_bl31((u64)doit, (u64)arg, payload_spsr);
Julius Werner0c5f61a2018-08-03 17:14:45 -070035 else
36 transition_to_el2(doit, arg, payload_spsr);
Furquan Shaikh2af76f42014-04-28 16:39:40 -070037}
Aaron Durbinb3847e62015-03-20 15:55:08 -050038
39void arch_prog_run(struct prog *prog)
40{
41 void (*doit)(void *);
42 void *arg;
43
Aaron Durbin7e7a4df2015-12-08 14:34:35 -060044 if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) {
Aaron Durbinb3847e62015-03-20 15:55:08 -050045 run_payload(prog);
46 return;
Paul Menzel9484f552015-04-05 18:30:05 +020047 }
Aaron Durbinb3847e62015-03-20 15:55:08 -050048
49 doit = prog_entry(prog);
50 arg = prog_entry_arg(prog);
51
52 doit(prog_entry_arg(prog));
53}
Julius Werner66a476a2015-10-12 16:45:21 -070054
Julius Werner66a476a2015-10-12 16:45:21 -070055/* Generic stage entry point. Can be overridden by board/SoC if needed. */
Aaron Durbin64031672018-04-21 14:45:32 -060056__weak void stage_entry(void)
Julius Werner66a476a2015-10-12 16:45:21 -070057{
58 main();
59}