blob: 9d2dc299559d69cf778f411a68914994497a386b [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <stdio.h>
32#include <string.h>
33#include <assert.h>
34#include <arch_helpers.h>
35#include <console.h>
36#include <platform.h>
37#include <semihosting.h>
38#include <bl_common.h>
39#include <bl31.h>
40#include <runtime_svc.h>
Achin Gupta7aea9082014-02-01 07:51:28 +000041#include <context_mgmt.h>
42
43/*******************************************************************************
44 * Simple function to initialise all BL31 helper libraries.
45 ******************************************************************************/
46void bl31_lib_init()
47{
48 cm_init();
49}
Achin Gupta4f6ad662013-10-25 09:08:21 +010050
Achin Gupta4f6ad662013-10-25 09:08:21 +010051/*******************************************************************************
52 * BL31 is responsible for setting up the runtime services for the primary cpu
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000053 * before passing control to the bootloader (UEFI) or Linux. This function calls
54 * runtime_svc_init() which initializes all registered runtime services. The run
55 * time services would setup enough context for the core to swtich to the next
56 * exception level. When this function returns, the core will switch to the
57 * programmed exception level via. an ERET.
Achin Gupta4f6ad662013-10-25 09:08:21 +010058 ******************************************************************************/
59void bl31_main(void)
60{
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000061 el_change_info *next_image_info;
62 uint32_t scr;
Achin Gupta4f6ad662013-10-25 09:08:21 +010063
64 /* Perform remaining generic architectural setup from EL3 */
65 bl31_arch_setup();
66
67 /* Perform platform setup in BL1 */
68 bl31_platform_setup();
69
70#if defined (__GNUC__)
71 printf("BL31 Built : %s, %s\n\r", __TIME__, __DATE__);
72#endif
Achin Gupta7aea9082014-02-01 07:51:28 +000073 /* Initialise helper libraries */
74 bl31_lib_init();
Achin Gupta4f6ad662013-10-25 09:08:21 +010075
76 /* Initialize the runtime services e.g. psci */
Achin Gupta7421b462014-02-01 18:53:26 +000077 runtime_svc_init();
Achin Gupta4f6ad662013-10-25 09:08:21 +010078
79 /* Clean caches before re-entering normal world */
80 dcsw_op_all(DCCSW);
81
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000082 /*
83 * Setup minimal architectural state of the next highest EL to
84 * allow execution in it immediately upon entering it.
85 */
Achin Gupta4f6ad662013-10-25 09:08:21 +010086 bl31_arch_next_el_setup();
Achin Gupta4f6ad662013-10-25 09:08:21 +010087
Jeenu Viswambharancaa84932014-02-06 10:36:15 +000088 /* Program EL3 registers to enable entry into the next EL */
89 next_image_info = bl31_get_next_image_info();
90 scr = read_scr();
91 if (next_image_info->security_state == NON_SECURE)
92 scr |= SCR_NS_BIT;
93
94 /*
95 * Tell the context mgmt. library to ensure that SP_EL3 points to
96 * the right context to exit from EL3 correctly.
97 */
98 cm_set_el3_eret_context(next_image_info->security_state,
99 next_image_info->entrypoint,
100 next_image_info->spsr,
101 scr);
102
103 /* Finally set the next context */
104 cm_set_next_eret_context(next_image_info->security_state);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100105}