blob: 066f1c18a84691097cf04db560dec35d62874b50 [file] [log] [blame]
Furquan Shaikhabde3b52014-08-26 15:39:51 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 *
21 * secmon_loader.c: Responsible for loading the rmodule, providing entry point
22 * and parameter location for the rmodule.
23 */
24
25#include <arch/lib_helpers.h>
26#include <arch/secmon.h>
27#include <console/console.h>
28#include <rmodule.h>
29#include <string.h>
30
31/* SECMON entry point encoded as an rmodule */
32extern unsigned char _binary_secmon_start[];
33
34typedef void (*secmon_entry_t)(struct secmon_params *);
35
36void __attribute__((weak)) soc_get_secmon_base_size(uint64_t *secmon_base, size_t *secmon_size)
37{
38 /* Default weak implementation initializes to 0 */
39 *secmon_base = 0;
40 *secmon_size = 0;
41}
42
43static secmon_entry_t secmon_load_rmodule(void)
44{
45 struct rmodule secmon_mod;
46 uint64_t secmon_base;
47 size_t secmon_size;
48
49 /* Get base address and size of the area available for secure monitor
50 * rmodule.
51 */
52 soc_get_secmon_base_size(&secmon_base, &secmon_size);
53
54 if ((secmon_base == 0) || (secmon_size == 0)) {
55 printk(BIOS_ERR, "ARM64: secmon_base / secmon_size invalid\n");
56 return NULL;
57 }
58
59 printk(BIOS_DEBUG,"secmon_base:%lx,secmon_size:%lx\n",
60 (unsigned long)secmon_base, (unsigned long)secmon_size);
61
62 /* Fail if can't parse secmon module */
63 if (rmodule_parse(&_binary_secmon_start, &secmon_mod)) {
64 printk(BIOS_ERR, "ARM64: secmon_mod not found\n");
65 return NULL;
66 }
67
68 /* Load rmodule at secmon_base */
69 if (rmodule_load((void *)secmon_base, &secmon_mod)) {
70 printk(BIOS_ERR, "ARM64:secmon_mod cannot load\n");
71 return NULL;
72 }
73
74 /* Identify the entry point for secure monitor */
75 return rmodule_entry(&secmon_mod);
76}
77
78void secmon_run(void (*entry)(void *), void *cb_tables)
79{
80 struct secmon_params params;
81 uint32_t scr;
82
83 printk(BIOS_SPEW, "payload jump @ %p\n", entry);
84
85 if (get_current_el() != EL3) {
86 printk(BIOS_DEBUG, "Secmon Error: Can only be loaded in EL3\n");
87 return;
88 }
89
90 secmon_entry_t doit = secmon_load_rmodule();
91
92 if (doit == NULL)
93 die("ARM64 Error: secmon load error");
94
95 printk(BIOS_DEBUG, "ARM64: Loaded the el3 monitor...jumping to %p\n",
96 doit);
97
98 params.entry = entry;
99 params.arg = cb_tables;
100 params.elx_el = EL2;
101 params.elx_mode = SPSR_USE_L;
102
103 /* We want to enforce the following policies:
104 * NS bit is set for lower EL
105 */
106 scr = raw_read_scr_el3();
107 scr |= SCR_NS;
108 raw_write_scr_el3(scr);
109
110 doit(&params);
111}