xref: /rk3399_ARM-atf/plat/common/plat_bl_common.c (revision e6937287e4963e0e729dd19d08f44c52c5483382)
1566034fcSSoby Mathew /*
2*e6937287SZelalem  * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
3566034fcSSoby Mathew  *
4566034fcSSoby Mathew  * SPDX-License-Identifier: BSD-3-Clause
5566034fcSSoby Mathew  */
6566034fcSSoby Mathew 
7566034fcSSoby Mathew #include <assert.h>
809d40e0eSAntonio Nino Diaz 
909d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1009d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1109d40e0eSAntonio Nino Diaz #include <common/debug.h>
1209d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h>
1309d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
14566034fcSSoby Mathew 
15566034fcSSoby Mathew /*
16566034fcSSoby Mathew  * The following platform functions are weakly defined. The Platforms
17566034fcSSoby Mathew  * may redefine with strong definition.
18566034fcSSoby Mathew  */
19566034fcSSoby Mathew #pragma weak bl2_el3_plat_prepare_exit
20566034fcSSoby Mathew #pragma weak plat_error_handler
21566034fcSSoby Mathew #pragma weak bl2_plat_preload_setup
22566034fcSSoby Mathew #pragma weak bl2_plat_handle_pre_image_load
23566034fcSSoby Mathew #pragma weak bl2_plat_handle_post_image_load
24566034fcSSoby Mathew #pragma weak plat_try_next_boot_source
25566034fcSSoby Mathew 
26566034fcSSoby Mathew void bl2_el3_plat_prepare_exit(void)
27566034fcSSoby Mathew {
28566034fcSSoby Mathew }
29566034fcSSoby Mathew 
30566034fcSSoby Mathew void __dead2 plat_error_handler(int err)
31566034fcSSoby Mathew {
32566034fcSSoby Mathew 	while (1)
33566034fcSSoby Mathew 		wfi();
34566034fcSSoby Mathew }
35566034fcSSoby Mathew 
36566034fcSSoby Mathew void bl2_plat_preload_setup(void)
37566034fcSSoby Mathew {
38566034fcSSoby Mathew }
39566034fcSSoby Mathew 
40566034fcSSoby Mathew int bl2_plat_handle_pre_image_load(unsigned int image_id)
41566034fcSSoby Mathew {
42566034fcSSoby Mathew 	return 0;
43566034fcSSoby Mathew }
44566034fcSSoby Mathew 
45566034fcSSoby Mathew int bl2_plat_handle_post_image_load(unsigned int image_id)
46566034fcSSoby Mathew {
47566034fcSSoby Mathew 	return 0;
48566034fcSSoby Mathew }
49566034fcSSoby Mathew 
50566034fcSSoby Mathew int plat_try_next_boot_source(void)
51566034fcSSoby Mathew {
52566034fcSSoby Mathew 	return 0;
53566034fcSSoby Mathew }
54a6f340feSSoby Mathew 
550916c38dSRoberto Vargas /*
560916c38dSRoberto Vargas  * Set up the page tables for the generic and platform-specific memory regions.
570916c38dSRoberto Vargas  * The size of the Trusted SRAM seen by the BL image must be specified as well
580916c38dSRoberto Vargas  * as an array specifying the generic memory regions which can be;
590916c38dSRoberto Vargas  * - Code section;
600916c38dSRoberto Vargas  * - Read-only data section;
610916c38dSRoberto Vargas  * - Init code section, if applicable
620916c38dSRoberto Vargas  * - Coherent memory region, if applicable.
630916c38dSRoberto Vargas  */
640916c38dSRoberto Vargas 
650916c38dSRoberto Vargas void __init setup_page_tables(const mmap_region_t *bl_regions,
660916c38dSRoberto Vargas 			      const mmap_region_t *plat_regions)
670916c38dSRoberto Vargas {
680916c38dSRoberto Vargas #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
690916c38dSRoberto Vargas 	const mmap_region_t *regions = bl_regions;
700916c38dSRoberto Vargas 
710916c38dSRoberto Vargas 	while (regions->size != 0U) {
720916c38dSRoberto Vargas 		VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
730916c38dSRoberto Vargas 				regions->base_va,
740916c38dSRoberto Vargas 				regions->base_va + regions->size,
750916c38dSRoberto Vargas 				regions->attr);
760916c38dSRoberto Vargas 		regions++;
770916c38dSRoberto Vargas 	}
780916c38dSRoberto Vargas #endif
790916c38dSRoberto Vargas 	/*
800916c38dSRoberto Vargas 	 * Map the Trusted SRAM with appropriate memory attributes.
810916c38dSRoberto Vargas 	 * Subsequent mappings will adjust the attributes for specific regions.
820916c38dSRoberto Vargas 	 */
830916c38dSRoberto Vargas 	mmap_add(bl_regions);
840916c38dSRoberto Vargas 
850916c38dSRoberto Vargas 	/* Now (re-)map the platform-specific memory regions */
860916c38dSRoberto Vargas 	mmap_add(plat_regions);
870916c38dSRoberto Vargas 
880916c38dSRoberto Vargas 	/* Create the page tables to reflect the above mappings */
890916c38dSRoberto Vargas 	init_xlat_tables();
900916c38dSRoberto Vargas }
91