xref: /rk3399_ARM-atf/bl31/bl31_main.c (revision 7421b4653dcfe6b10be5ca7167d2a5f3584c95c1)
1 /*
2  * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3  *
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>
41 #include <context_mgmt.h>
42 
43 /*******************************************************************************
44  * Simple function to initialise all BL31 helper libraries.
45  ******************************************************************************/
46 void bl31_lib_init()
47 {
48 	cm_init();
49 }
50 
51 void bl31_arch_next_el_setup(void);
52 
53 /*******************************************************************************
54  * BL31 is responsible for setting up the runtime services for the primary cpu
55  * before passing control to the bootloader (UEFI) or Linux.
56  ******************************************************************************/
57 void bl31_main(void)
58 {
59 	el_change_info *image_info;
60 
61 	/* Perform remaining generic architectural setup from EL3 */
62 	bl31_arch_setup();
63 
64 	/* Perform platform setup in BL1 */
65 	bl31_platform_setup();
66 
67 #if defined (__GNUC__)
68 	printf("BL31 Built : %s, %s\n\r", __TIME__, __DATE__);
69 #endif
70 	/* Initialise helper libraries */
71 	bl31_lib_init();
72 
73 	/* Initialize the runtime services e.g. psci */
74 	runtime_svc_init();
75 
76 	/* Clean caches before re-entering normal world */
77 	dcsw_op_all(DCCSW);
78 
79 	image_info = bl31_get_next_image_info();
80 	bl31_arch_next_el_setup();
81 	change_el(image_info);
82 
83 	/* There is no valid reason for change_el() to return */
84 	assert(0);
85 }
86