Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 1 | /* |
| 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 Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/cache.h> |
Furquan Shaikh | 441df53 | 2014-09-11 16:06:01 -0700 | [diff] [blame] | 17 | #include <arch/lib_helpers.h> |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 18 | #include <arch/stages.h> |
Furquan Shaikh | 441df53 | 2014-09-11 16:06:01 -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> |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 21 | #include <program_loading.h> |
Furquan Shaikh | 441df53 | 2014-09-11 16:06:01 -0700 | [diff] [blame] | 22 | #include <string.h> |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 23 | |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 24 | static void run_payload(struct prog *prog) |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 25 | { |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 26 | void (*doit)(void *); |
| 27 | void *arg; |
Furquan Shaikh | abde3b5 | 2014-08-26 15:39:51 -0700 | [diff] [blame] | 28 | |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 29 | doit = prog_entry(prog); |
| 30 | arg = prog_entry_arg(prog); |
Julius Werner | 3834520 | 2016-02-01 19:47:10 -0800 | [diff] [blame] | 31 | u64 payload_spsr = get_eret_el(EL2, SPSR_USE_L); |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 32 | |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 33 | if (IS_ENABLED(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 34 | arm_tf_run_bl31((u64)doit, (u64)arg, payload_spsr); |
Julius Werner | 0c5f61a | 2018-08-03 17:14:45 -0700 | [diff] [blame] | 35 | else |
| 36 | transition_to_el2(doit, arg, payload_spsr); |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 37 | } |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 38 | |
| 39 | void arch_prog_run(struct prog *prog) |
| 40 | { |
| 41 | void (*doit)(void *); |
| 42 | void *arg; |
| 43 | |
Aaron Durbin | 7e7a4df | 2015-12-08 14:34:35 -0600 | [diff] [blame] | 44 | if (ENV_RAMSTAGE && prog_type(prog) == PROG_PAYLOAD) { |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 45 | run_payload(prog); |
| 46 | return; |
Paul Menzel | 9484f55 | 2015-04-05 18:30:05 +0200 | [diff] [blame] | 47 | } |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 48 | |
| 49 | doit = prog_entry(prog); |
| 50 | arg = prog_entry_arg(prog); |
| 51 | |
| 52 | doit(prog_entry_arg(prog)); |
| 53 | } |
Julius Werner | 66a476a | 2015-10-12 16:45:21 -0700 | [diff] [blame] | 54 | |
Julius Werner | 66a476a | 2015-10-12 16:45:21 -0700 | [diff] [blame] | 55 | /* Generic stage entry point. Can be overridden by board/SoC if needed. */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 56 | __weak void stage_entry(void) |
Julius Werner | 66a476a | 2015-10-12 16:45:21 -0700 | [diff] [blame] | 57 | { |
| 58 | main(); |
| 59 | } |