2 * Reference to the ARM TF Project,
3 * plat/arm/common/arm_bl2_setup.c
4 * Portions copyright (c) 2013-2016, ARM Limited and Contributors. All rights
6 * Copyright (C) 2016 Rockchip Electronic Co.,Ltd
7 * Written by Kever Yang <kever.yang@rock-chips.com>
9 * SPDX-License-Identifier: BSD-3-Clause
13 #include <atf_common.h>
17 static struct bl2_to_bl31_params_mem bl31_params_mem;
18 static struct bl31_params *bl2_to_bl31_params;
21 * bl2_plat_get_bl31_params() - prepare params for bl31.
23 * This function assigns a pointer to the memory that the platform has kept
24 * aside to pass platform specific and trusted firmware related information
25 * to BL31. This memory is allocated by allocating memory to
26 * bl2_to_bl31_params_mem structure which is a superset of all the
27 * structure whose information is passed to BL31
28 * NOTE: This function should be called only once and should be done
29 * before generating params to BL31
31 * @return bl31 params structure pointer
33 struct bl31_params *bl2_plat_get_bl31_params(void)
35 struct entry_point_info *bl33_ep_info;
38 * Initialise the memory for all the arguments that needs to
41 memset(&bl31_params_mem, 0, sizeof(struct bl2_to_bl31_params_mem));
43 /* Assign memory for TF related information */
44 bl2_to_bl31_params = &bl31_params_mem.bl31_params;
45 SET_PARAM_HEAD(bl2_to_bl31_params, ATF_PARAM_BL31, ATF_VERSION_1, 0);
47 /* Fill BL31 related information */
48 SET_PARAM_HEAD(bl2_to_bl31_params->bl31_image_info,
49 ATF_PARAM_IMAGE_BINARY, ATF_VERSION_1, 0);
51 /* Fill BL32 related information if it exists */
53 bl2_to_bl31_params->bl32_ep_info = &bl31_params_mem.bl32_ep_info;
54 SET_PARAM_HEAD(bl2_to_bl31_params->bl32_ep_info, ATF_PARAM_EP,
56 bl2_to_bl31_params->bl32_image_info = &bl31_params_mem.bl32_image_info;
57 SET_PARAM_HEAD(bl2_to_bl31_params->bl32_image_info,
58 ATF_PARAM_IMAGE_BINARY, ATF_VERSION_1, 0);
59 #endif /* BL32_BASE */
61 /* Fill BL33 related information */
62 bl2_to_bl31_params->bl33_ep_info = &bl31_params_mem.bl33_ep_info;
63 bl33_ep_info = &bl31_params_mem.bl33_ep_info;
64 SET_PARAM_HEAD(bl33_ep_info, ATF_PARAM_EP, ATF_VERSION_1,
67 /* BL33 expects to receive the primary CPU MPID (through x0) */
68 bl33_ep_info->args.arg0 = 0xffff & read_mpidr();
69 bl33_ep_info->pc = CONFIG_SYS_TEXT_BASE;
70 bl33_ep_info->spsr = SPSR_64(MODE_EL2, MODE_SP_ELX,
71 DISABLE_ALL_EXECPTIONS);
73 bl2_to_bl31_params->bl33_image_info = &bl31_params_mem.bl33_image_info;
74 SET_PARAM_HEAD(bl2_to_bl31_params->bl33_image_info,
75 ATF_PARAM_IMAGE_BINARY, ATF_VERSION_1, 0);
77 return bl2_to_bl31_params;
80 void raw_write_daif(unsigned int daif)
82 __asm__ __volatile__("msr DAIF, %0\n\t" : : "r" (daif) : "memory");
87 struct bl31_params *bl31_params;
88 void (*entry)(struct bl31_params *params, void *plat_params) = NULL;
90 bl31_params = bl2_plat_get_bl31_params();
91 entry = (void *)CONFIG_SPL_ATF_TEXT_BASE;
93 raw_write_daif(SPSR_EXCEPTION_MASK);
96 entry(bl31_params, NULL);