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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <arch/cache.h> |
Furquan Shaikh | 441df53 | 2014-09-11 16:06:01 -0700 | [diff] [blame] | 21 | #include <arch/lib_helpers.h> |
Furquan Shaikh | abde3b5 | 2014-08-26 15:39:51 -0700 | [diff] [blame] | 22 | #include <arch/secmon.h> |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 23 | #include <arch/stages.h> |
Aaron Durbin | 5add435 | 2014-09-17 11:43:20 -0500 | [diff] [blame] | 24 | #include <arch/spintable.h> |
Furquan Shaikh | 441df53 | 2014-09-11 16:06:01 -0700 | [diff] [blame] | 25 | #include <arch/transition.h> |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 26 | #include <arm_tf.h> |
| 27 | #include <cbmem.h> |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 28 | #include <console/console.h> |
Aaron Durbin | 04654a2 | 2015-03-17 11:43:44 -0500 | [diff] [blame] | 29 | #include <program_loading.h> |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 30 | #include <rules.h> |
Furquan Shaikh | 441df53 | 2014-09-11 16:06:01 -0700 | [diff] [blame] | 31 | #include <string.h> |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 32 | |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 33 | static void run_payload(struct prog *prog) |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 34 | { |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 35 | void (*doit)(void *); |
| 36 | void *arg; |
Furquan Shaikh | abde3b5 | 2014-08-26 15:39:51 -0700 | [diff] [blame] | 37 | |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 38 | doit = prog_entry(prog); |
| 39 | arg = prog_entry_arg(prog); |
Julius Werner | da3a146 | 2015-05-13 11:19:33 -0700 | [diff] [blame^] | 40 | u64 payload_spsr = SPSR_EXCEPTION_MASK | get_eret_el(EL2, SPSR_USE_L); |
Aaron Durbin | 3948e53 | 2015-03-20 13:00:20 -0500 | [diff] [blame] | 41 | |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 42 | if (IS_ENABLED(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE)) |
| 43 | arm_tf_run_bl31((u64)doit, (u64)arg, payload_spsr); |
| 44 | else if (IS_ENABLED(CONFIG_ARM64_USE_SECURE_MONITOR)) |
Julius Werner | 786b122 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 45 | secmon_run(doit, arg); |
| 46 | else { |
Julius Werner | f52602a | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 47 | uint8_t current_el = get_current_el(); |
| 48 | |
Julius Werner | 786b122 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 49 | /* Start the other CPUs spinning. */ |
Julius Werner | b436ce1 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 50 | if (IS_ENABLED(CONFIG_ARM64_USE_SPINTABLE)) |
| 51 | spintable_start(); |
Furquan Shaikh | abde3b5 | 2014-08-26 15:39:51 -0700 | [diff] [blame] | 52 | |
Julius Werner | 883ec98 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 53 | cache_sync_instructions(); |
| 54 | |
Julius Werner | f52602a | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 55 | printk(BIOS_SPEW, "entry = %p\n", doit); |
| 56 | |
Julius Werner | 786b122 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 57 | /* If current EL is not EL3, jump to payload at same EL. */ |
Julius Werner | bbca3a9 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 58 | if (current_el != EL3) |
Julius Werner | 786b122 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 59 | doit(arg); |
Julius Werner | bbca3a9 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 60 | else { |
| 61 | /* If current EL is EL3, we transition to payload in EL2. */ |
| 62 | struct exc_state exc_state; |
| 63 | memset(&exc_state, 0, sizeof(exc_state)); |
Julius Werner | 745a75f | 2015-05-11 16:45:56 -0700 | [diff] [blame] | 64 | exc_state.elx.spsr = payload_spsr; |
Julius Werner | bbca3a9 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 65 | |
| 66 | transition_with_entry(doit, arg, &exc_state); |
Julius Werner | 786b122 | 2015-05-07 16:59:31 -0700 | [diff] [blame] | 67 | } |
Furquan Shaikh | 441df53 | 2014-09-11 16:06:01 -0700 | [diff] [blame] | 68 | } |
Furquan Shaikh | 2af76f4 | 2014-04-28 16:39:40 -0700 | [diff] [blame] | 69 | } |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 70 | |
| 71 | void arch_prog_run(struct prog *prog) |
| 72 | { |
| 73 | void (*doit)(void *); |
| 74 | void *arg; |
| 75 | |
Paul Menzel | 9484f55 | 2015-04-05 18:30:05 +0200 | [diff] [blame] | 76 | if (ENV_RAMSTAGE && prog->type == PROG_PAYLOAD) { |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 77 | run_payload(prog); |
| 78 | return; |
Paul Menzel | 9484f55 | 2015-04-05 18:30:05 +0200 | [diff] [blame] | 79 | } |
Aaron Durbin | b3847e6 | 2015-03-20 15:55:08 -0500 | [diff] [blame] | 80 | |
| 81 | doit = prog_entry(prog); |
| 82 | arg = prog_entry_arg(prog); |
| 83 | |
| 84 | doit(prog_entry_arg(prog)); |
| 85 | } |