summaryrefslogtreecommitdiffstats
path: root/arch/arm/cpu/atf.c
blob: d01e20508c7a7a2aadf83a9f63e4cf91f22005b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// SPDX-License-Identifier: GPL-2.0-only

#include <common.h>
#include <asm/atf_common.h>
#include <asm/system.h>

static inline void raw_write_daif(unsigned int daif)
{
	__asm__ __volatile__("msr DAIF, %0\n\t" : : "r" (daif) : "memory");
}

void bl31_entry(uintptr_t bl31_entry, uintptr_t bl32_entry,
		uintptr_t bl33_entry, uintptr_t fdt_addr)
{
	struct atf_image_info bl31_image_info = {
		.h = {
			.type = ATF_PARAM_IMAGE_BINARY,
			.version = ATF_VERSION_1,
			.size = sizeof(bl31_image_info),
		},
	};
	struct atf_image_info bl32_image_info = {
		.h = {
			.type = ATF_PARAM_IMAGE_BINARY,
			.version = ATF_VERSION_1,
			.size = sizeof(bl32_image_info),
		},
	};
	struct entry_point_info bl32_ep_info = {
		.h = {
			.type = ATF_PARAM_EP,
			.version = ATF_VERSION_1,
			.attr = ATF_EP_SECURE,
			.size = sizeof(bl32_ep_info),
		},
		.pc = bl32_entry,
		.spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXECPTIONS),
		.args = {
			.arg3 = fdt_addr,
		},
	};
	struct atf_image_info bl33_image_info = {
		.h = {
			.type = ATF_PARAM_IMAGE_BINARY,
			.version = ATF_VERSION_1,
			.size = sizeof(bl33_image_info),
		},
	};
	struct entry_point_info bl33_ep_info = {
		.h = {
			.type = ATF_PARAM_EP,
			.version = ATF_VERSION_1,
			.attr = ATF_EP_NON_SECURE,
			.size = sizeof(bl33_ep_info),
		},
		.pc = bl33_entry,
		.spsr = SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXECPTIONS),
		.args = {
			/* BL33 expects to receive the primary CPU MPID (through x0) */
			.arg0 = 0xffff & read_mpidr(),
		},
	};
	struct bl31_params bl31_params = {
		.h = {
			.type = ATF_PARAM_BL31,
			.version = ATF_VERSION_1,
			.size = sizeof(bl31_params),
		},
		.bl31_image_info = &bl31_image_info,
		.bl32_ep_info = &bl32_ep_info,
		.bl32_image_info = &bl32_image_info,
		.bl33_ep_info = &bl33_ep_info,
		.bl33_image_info = &bl33_image_info,
	};
	void (*atf_entry)(struct bl31_params *params, uintptr_t plat_params);

	raw_write_daif(SPSR_EXCEPTION_MASK);

	atf_entry = (void *)bl31_entry;

	atf_entry(&bl31_params, fdt_addr);
}

struct bl2_to_bl31_params_mem_v2 *bl2_plat_get_bl31_params_v2(uintptr_t bl32_entry,
					uintptr_t bl33_entry, uintptr_t fdt_addr)
{
	static struct bl2_to_bl31_params_mem_v2 p = {
		.bl_params = {
			.h = {
				.type = ATF_PARAM_BL_PARAMS,
				.version = ATF_VERSION_2,
				.size = sizeof(struct bl_params),
				.attr = 0,
			},
			.head = &p.bl31_params_node,
		},
		.bl31_params_node = {
			.image_id = ATF_BL31_IMAGE_ID,
			.image_info = &p.bl31_image_info,
			.ep_info = &p.bl31_ep_info,
			.next_params_info = &p.bl32_params_node,
		},
		.bl32_params_node = {
			.image_id = ATF_BL32_IMAGE_ID,
			.image_info = &p.bl32_image_info,
			.ep_info = &p.bl32_ep_info,
			.next_params_info = &p.bl33_params_node,
		},
		.bl33_params_node = {
			.image_id = ATF_BL33_IMAGE_ID,
			.image_info = &p.bl33_image_info,
			.ep_info = &p.bl33_ep_info,
			.next_params_info = NULL,
		},
		.bl32_ep_info = {
			.h = {
				.type = ATF_PARAM_EP,
				.version = ATF_VERSION_2,
				.size = sizeof(struct entry_point_info),
				.attr = ATF_EP_SECURE,
			},
			.spsr = SPSR_64(MODE_EL1, MODE_SP_ELX, DISABLE_ALL_EXECPTIONS),
		},
		.bl33_ep_info = {
			.h = {
				.type = ATF_PARAM_EP,
				.version = ATF_VERSION_2,
				.size = sizeof(struct entry_point_info),
				.attr = ATF_EP_NON_SECURE,
			},
			.spsr = SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXECPTIONS),
		},
		.bl33_image_info = {
			.h = {
				.type = ATF_PARAM_IMAGE_BINARY,
				.version = ATF_VERSION_2,
				.size = sizeof(struct atf_image_info),
				.attr = 0,
			},
		},
		.bl32_image_info = {
			.h = {
				.type = ATF_PARAM_IMAGE_BINARY,
				.version = ATF_VERSION_2,
				.size = sizeof(struct atf_image_info),
				.attr = ATF_EP_SECURE,
			},
		},
		.bl31_image_info = {
			.h = {
				.type = ATF_PARAM_IMAGE_BINARY,
				.version = ATF_VERSION_2,
				.size = sizeof(struct atf_image_info),
				.attr = 0,
			},
		},
	};

	p.bl33_ep_info.args.arg0 = 0xffff & read_mpidr();
	p.bl33_ep_info.pc = bl33_entry;
	p.bl32_ep_info.args.arg3 = fdt_addr;
	p.bl32_ep_info.pc = bl32_entry;

	return &p;
}

void bl31_entry_v2(uintptr_t bl31_entry, struct bl_params *params, void *fdt_addr)
{
	void (*atf_entry)(struct bl_params *params, uintptr_t plat_params);

	raw_write_daif(SPSR_EXCEPTION_MASK);

	atf_entry = (void *)bl31_entry;

	atf_entry(params, (uintptr_t)fdt_addr);
}