blob: f01ead4e2356f523f4b3255d979417ceaf73332f [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Sergey Temerkhanov900f88f2015-10-14 09:55:51 -07002/**
3 * (C) Copyright 2014, Cavium Inc.
Sergey Temerkhanov900f88f2015-10-14 09:55:51 -07004**/
5
6#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -06007#include <command.h>
Simon Glass90526e92020-05-10 11:39:56 -06008#include <asm/cache.h>
Sergey Temerkhanov900f88f2015-10-14 09:55:51 -07009#include <asm/io.h>
10
11#include <asm/system.h>
12#include <cavium/thunderx_svc.h>
13#include <cavium/atf.h>
14#include <cavium/atf_part.h>
15
16#include <asm/psci.h>
17
18#include <malloc.h>
19
Sergey Temerkhanov900f88f2015-10-14 09:55:51 -070020ssize_t atf_read_mmc(uintptr_t offset, void *buffer, size_t size)
21{
22 struct pt_regs regs;
23 regs.regs[0] = THUNDERX_MMC_READ;
24 regs.regs[1] = offset;
25 regs.regs[2] = size;
26 regs.regs[3] = (uintptr_t)buffer;
27
28 smc_call(&regs);
29
30 return regs.regs[0];
31}
32
33ssize_t atf_read_nor(uintptr_t offset, void *buffer, size_t size)
34{
35 struct pt_regs regs;
36 regs.regs[0] = THUNDERX_NOR_READ;
37 regs.regs[1] = offset;
38 regs.regs[2] = size;
39 regs.regs[3] = (uintptr_t)buffer;
40
41 smc_call(&regs);
42
43 return regs.regs[0];
44}
45
46ssize_t atf_get_pcount(void)
47{
48 struct pt_regs regs;
49 regs.regs[0] = THUNDERX_PART_COUNT;
50
51 smc_call(&regs);
52
53 return regs.regs[0];
54}
55
56ssize_t atf_get_part(struct storage_partition *part, unsigned int index)
57{
58 struct pt_regs regs;
59 regs.regs[0] = THUNDERX_GET_PART;
60 regs.regs[1] = (uintptr_t)part;
61 regs.regs[2] = index;
62
63 smc_call(&regs);
64
65 return regs.regs[0];
66}
67
68ssize_t atf_erase_nor(uintptr_t offset, size_t size)
69{
70 struct pt_regs regs;
71
72 regs.regs[0] = THUNDERX_NOR_ERASE;
73 regs.regs[1] = offset;
74
75 smc_call(&regs);
76
77 return regs.regs[0];
78}
79
80ssize_t atf_write_nor(uintptr_t offset, const void *buffer, size_t size)
81{
82 struct pt_regs regs;
83
84 regs.regs[0] = THUNDERX_NOR_WRITE;
85 regs.regs[1] = offset;
86 regs.regs[2] = size;
87 regs.regs[3] = (uintptr_t)buffer;
88
89 smc_call(&regs);
90
91 return regs.regs[0];
92}
93
94ssize_t atf_write_mmc(uintptr_t offset, const void *buffer, size_t size)
95{
96 struct pt_regs regs;
97
98 regs.regs[0] = THUNDERX_MMC_WRITE;
99 regs.regs[1] = offset;
100 regs.regs[2] = size;
101 regs.regs[3] = (uintptr_t)buffer;
102
103 smc_call(&regs);
104
105 return regs.regs[0];
106}
107
108ssize_t atf_dram_size(unsigned int node)
109{
110 struct pt_regs regs;
111 regs.regs[0] = THUNDERX_DRAM_SIZE;
112 regs.regs[1] = node;
113
114 smc_call(&regs);
115
116 return regs.regs[0];
117}
118
119ssize_t atf_node_count(void)
120{
121 struct pt_regs regs;
122 regs.regs[0] = THUNDERX_NODE_COUNT;
123
124 smc_call(&regs);
125
126 return regs.regs[0];
127}
128
129ssize_t atf_env_count(void)
130{
131 struct pt_regs regs;
132 regs.regs[0] = THUNDERX_ENV_COUNT;
133
134 smc_call(&regs);
135
136 return regs.regs[0];
137}
138
139ssize_t atf_env_string(size_t index, char *str)
140{
141 uint64_t *buf = (void *)str;
142 struct pt_regs regs;
143 regs.regs[0] = THUNDERX_ENV_STRING;
144 regs.regs[1] = index;
145
146 smc_call(&regs);
147
148 if (regs.regs > 0) {
149 buf[0] = regs.regs[0];
150 buf[1] = regs.regs[1];
151 buf[2] = regs.regs[2];
152 buf[3] = regs.regs[3];
153
154 return 1;
155 } else {
156 return regs.regs[0];
157 }
158}
159
160#ifdef CONFIG_CMD_ATF
161
162static void atf_print_ver(void)
163{
164 struct pt_regs regs;
165 regs.regs[0] = ARM_STD_SVC_VERSION;
166
167 smc_call(&regs);
168
169 printf("ARM Std FW version: %ld.%ld\n", regs.regs[0], regs.regs[1]);
170
171 regs.regs[0] = THUNDERX_SVC_VERSION;
172
173 smc_call(&regs);
174
175 printf("ThunderX OEM ver: %ld.%ld\n", regs.regs[0], regs.regs[1]);
176}
177
178static void atf_print_uid(void)
179{
180}
181
182static void atf_print_part_table(void)
183{
184 size_t pcount;
185 unsigned long i;
186 int ret;
187 char *ptype;
188
189 struct storage_partition *part = (void *)CONFIG_SYS_LOWMEM_BASE;
190
191 pcount = atf_get_pcount();
192
193 printf("Partition count: %lu\n\n", pcount);
194 printf("%10s %10s %10s\n", "Type", "Size", "Offset");
195
196 for (i = 0; i < pcount; i++) {
197 ret = atf_get_part(part, i);
198
199 if (ret < 0) {
200 printf("Uknown error while reading partition: %d\n",
201 ret);
202 return;
203 }
204
205 switch (part->type) {
206 case PARTITION_NBL1FW_REST:
207 ptype = "NBL1FW";
208 break;
209 case PARTITION_BL2_BL31:
210 ptype = "BL2_BL31";
211 break;
212 case PARTITION_UBOOT:
213 ptype = "BOOTLDR";
214 break;
215 case PARTITION_KERNEL:
216 ptype = "KERNEL";
217 break;
218 case PARTITION_DEVICE_TREE:
219 ptype = "DEVTREE";
220 break;
221 default:
222 ptype = "UNKNOWN";
223 }
224 printf("%10s %10d %10lx\n", ptype, part->size, part->offset);
225 }
226}
227
Simon Glass09140112020-05-10 11:40:03 -0600228int do_atf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Sergey Temerkhanov900f88f2015-10-14 09:55:51 -0700229{
230 ssize_t ret;
231 size_t size, offset;
232 void *buffer = 0;
233 unsigned int index, node;
234 char str[4 * sizeof(uint64_t)];
235
236 if ((argc == 5) && !strcmp(argv[1], "readmmc")) {
237 buffer = (void *)simple_strtoul(argv[2], NULL, 16);
238 offset = simple_strtoul(argv[3], NULL, 10);
239 size = simple_strtoul(argv[4], NULL, 10);
240
241 ret = atf_read_mmc(offset, buffer, size);
242 } else if ((argc == 5) && !strcmp(argv[1], "readnor")) {
243 buffer = (void *)simple_strtoul(argv[2], NULL, 16);
244 offset = simple_strtoul(argv[3], NULL, 10);
245 size = simple_strtoul(argv[4], NULL, 10);
246
247 ret = atf_read_nor(offset, buffer, size);
248 } else if ((argc == 5) && !strcmp(argv[1], "writemmc")) {
249 buffer = (void *)simple_strtoul(argv[2], NULL, 16);
250 offset = simple_strtoul(argv[3], NULL, 10);
251 size = simple_strtoul(argv[4], NULL, 10);
252
253 ret = atf_write_mmc(offset, buffer, size);
254 } else if ((argc == 5) && !strcmp(argv[1], "writenor")) {
255 buffer = (void *)simple_strtoul(argv[2], NULL, 16);
256 offset = simple_strtoul(argv[3], NULL, 10);
257 size = simple_strtoul(argv[4], NULL, 10);
258
259 ret = atf_write_nor(offset, buffer, size);
260 } else if ((argc == 2) && !strcmp(argv[1], "part")) {
261 atf_print_part_table();
262 } else if ((argc == 4) && !strcmp(argv[1], "erasenor")) {
263 offset = simple_strtoul(argv[2], NULL, 10);
264 size = simple_strtoul(argv[3], NULL, 10);
265
266 ret = atf_erase_nor(offset, size);
267 } else if ((argc == 2) && !strcmp(argv[1], "envcount")) {
268 ret = atf_env_count();
269 printf("Number of environment strings: %zd\n", ret);
270 } else if ((argc == 3) && !strcmp(argv[1], "envstring")) {
271 index = simple_strtoul(argv[2], NULL, 10);
272 ret = atf_env_string(index, str);
273 if (ret > 0)
274 printf("Environment string %d: %s\n", index, str);
275 else
276 printf("Return code: %zd\n", ret);
277 } else if ((argc == 3) && !strcmp(argv[1], "dramsize")) {
278 node = simple_strtoul(argv[2], NULL, 10);
279 ret = atf_dram_size(node);
280 printf("DRAM size: %zd Mbytes\n", ret >> 20);
281 } else if ((argc == 2) && !strcmp(argv[1], "nodes")) {
282 ret = atf_node_count();
283 printf("Nodes count: %zd\n", ret);
284 } else if ((argc == 2) && !strcmp(argv[1], "ver")) {
285 atf_print_ver();
286 } else if ((argc == 2) && !strcmp(argv[1], "uid")) {
287 atf_print_uid();
288 } else {
289 return CMD_RET_USAGE;
290 }
291
292 return 0;
293}
294
295U_BOOT_CMD(
296 atf, 10, 1, do_atf,
297 "issue calls to ATF",
298 "\t readmmc addr offset size - read MMC card\n"
299 "\t readnor addr offset size - read NOR flash\n"
300 "\t writemmc addr offset size - write MMC card\n"
301 "\t writenor addr offset size - write NOR flash\n"
302 "\t erasenor offset size - erase NOR flash\n"
303 "\t nodes - number of nodes\n"
304 "\t dramsize node - size of DRAM attached to node\n"
305 "\t envcount - number of environment strings\n"
306 "\t envstring index - print the environment string\n"
307 "\t part - print MMC partition table\n"
308 "\t ver - print ATF call set versions\n"
309);
310
311#endif