blob: e9bf3a618032685ec6fb0cfd94f01880402e1576 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekd5dae852013-04-22 15:43:02 +02002/*
3 * (C) Copyright 2012-2013, Xilinx, Michal Simek
4 *
5 * (C) Copyright 2012
6 * Joe Hershberger <joe.hershberger@ni.com>
Michal Simekd5dae852013-04-22 15:43:02 +02007 */
8
9#include <common.h>
Simon Glass24b852a2015-11-08 23:47:45 -070010#include <console.h>
Simon Glass9edefc22019-11-14 12:57:37 -070011#include <cpu_func.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060013#include <asm/cache.h>
Michal Simekd5dae852013-04-22 15:43:02 +020014#include <asm/io.h>
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +053015#include <fs.h>
Michal Simekd5dae852013-04-22 15:43:02 +020016#include <zynqpl.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040017#include <linux/sizes.h>
Michal Simekd5dae852013-04-22 15:43:02 +020018#include <asm/arch/hardware.h>
19#include <asm/arch/sys_proto.h>
20
21#define DEVCFG_CTRL_PCFG_PROG_B 0x40000000
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +053022#define DEVCFG_CTRL_PCFG_AES_EFUSE_MASK 0x00001000
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +053023#define DEVCFG_CTRL_PCAP_RATE_EN_MASK 0x02000000
Michal Simekd5dae852013-04-22 15:43:02 +020024#define DEVCFG_ISR_FATAL_ERROR_MASK 0x00740040
25#define DEVCFG_ISR_ERROR_FLAGS_MASK 0x00340840
26#define DEVCFG_ISR_RX_FIFO_OV 0x00040000
27#define DEVCFG_ISR_DMA_DONE 0x00002000
28#define DEVCFG_ISR_PCFG_DONE 0x00000004
29#define DEVCFG_STATUS_DMA_CMD_Q_F 0x80000000
30#define DEVCFG_STATUS_DMA_CMD_Q_E 0x40000000
31#define DEVCFG_STATUS_DMA_DONE_CNT_MASK 0x30000000
32#define DEVCFG_STATUS_PCFG_INIT 0x00000010
Soren Brinkmann5f932272013-06-14 17:43:24 -070033#define DEVCFG_MCTRL_PCAP_LPBK 0x00000010
Michal Simekd5dae852013-04-22 15:43:02 +020034#define DEVCFG_MCTRL_RFIFO_FLUSH 0x00000002
35#define DEVCFG_MCTRL_WFIFO_FLUSH 0x00000001
36
37#ifndef CONFIG_SYS_FPGA_WAIT
38#define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
39#endif
40
41#ifndef CONFIG_SYS_FPGA_PROG_TIME
Michal Simekfd2b10b2013-06-17 13:54:07 +020042#define CONFIG_SYS_FPGA_PROG_TIME (CONFIG_SYS_HZ * 4) /* 4 s */
Michal Simekd5dae852013-04-22 15:43:02 +020043#endif
44
Michal Simekd5dae852013-04-22 15:43:02 +020045#define DUMMY_WORD 0xffffffff
46
47/* Xilinx binary format header */
48static const u32 bin_format[] = {
49 DUMMY_WORD, /* Dummy words */
50 DUMMY_WORD,
51 DUMMY_WORD,
52 DUMMY_WORD,
53 DUMMY_WORD,
54 DUMMY_WORD,
55 DUMMY_WORD,
56 DUMMY_WORD,
57 0x000000bb, /* Sync word */
58 0x11220044, /* Sync word */
59 DUMMY_WORD,
60 DUMMY_WORD,
61 0xaa995566, /* Sync word */
62};
63
64#define SWAP_NO 1
65#define SWAP_DONE 2
66
67/*
68 * Load the whole word from unaligned buffer
69 * Keep in your mind that it is byte loading on little-endian system
70 */
71static u32 load_word(const void *buf, u32 swap)
72{
73 u32 word = 0;
74 u8 *bitc = (u8 *)buf;
75 int p;
76
77 if (swap == SWAP_NO) {
78 for (p = 0; p < 4; p++) {
79 word <<= 8;
80 word |= bitc[p];
81 }
82 } else {
83 for (p = 3; p >= 0; p--) {
84 word <<= 8;
85 word |= bitc[p];
86 }
87 }
88
89 return word;
90}
91
92static u32 check_header(const void *buf)
93{
94 u32 i, pattern;
95 int swap = SWAP_NO;
96 u32 *test = (u32 *)buf;
97
98 debug("%s: Let's check bitstream header\n", __func__);
99
100 /* Checking that passing bin is not a bitstream */
101 for (i = 0; i < ARRAY_SIZE(bin_format); i++) {
102 pattern = load_word(&test[i], swap);
103
104 /*
105 * Bitstreams in binary format are swapped
106 * compare to regular bistream.
107 * Do not swap dummy word but if swap is done assume
108 * that parsing buffer is binary format
109 */
110 if ((__swab32(pattern) != DUMMY_WORD) &&
111 (__swab32(pattern) == bin_format[i])) {
112 pattern = __swab32(pattern);
113 swap = SWAP_DONE;
114 debug("%s: data swapped - let's swap\n", __func__);
115 }
116
117 debug("%s: %d/%x: pattern %x/%x bin_format\n", __func__, i,
118 (u32)&test[i], pattern, bin_format[i]);
119 if (pattern != bin_format[i]) {
120 debug("%s: Bitstream is not recognized\n", __func__);
121 return 0;
122 }
123 }
124 debug("%s: Found bitstream header at %x %s swapinng\n", __func__,
125 (u32)buf, swap == SWAP_NO ? "without" : "with");
126
127 return swap;
128}
129
130static void *check_data(u8 *buf, size_t bsize, u32 *swap)
131{
132 u32 word, p = 0; /* possition */
133
134 /* Because buf doesn't need to be aligned let's read it by chars */
135 for (p = 0; p < bsize; p++) {
136 word = load_word(&buf[p], SWAP_NO);
137 debug("%s: word %x %x/%x\n", __func__, word, p, (u32)&buf[p]);
138
139 /* Find the first bitstream dummy word */
140 if (word == DUMMY_WORD) {
141 debug("%s: Found dummy word at position %x/%x\n",
142 __func__, p, (u32)&buf[p]);
143 *swap = check_header(&buf[p]);
144 if (*swap) {
145 /* FIXME add full bitstream checking here */
146 return &buf[p];
147 }
148 }
149 /* Loop can be huge - support CTRL + C */
150 if (ctrlc())
Michal Simek42a74a02014-04-25 13:51:58 +0200151 return NULL;
Michal Simekd5dae852013-04-22 15:43:02 +0200152 }
Michal Simek42a74a02014-04-25 13:51:58 +0200153 return NULL;
Michal Simekd5dae852013-04-22 15:43:02 +0200154}
155
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530156static int zynq_dma_transfer(u32 srcbuf, u32 srclen, u32 dstbuf, u32 dstlen)
Michal Simekd5dae852013-04-22 15:43:02 +0200157{
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530158 unsigned long ts;
159 u32 isr_status;
Michal Simekd5dae852013-04-22 15:43:02 +0200160
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530161 /* Set up the transfer */
162 writel((u32)srcbuf, &devcfg_base->dma_src_addr);
163 writel(dstbuf, &devcfg_base->dma_dst_addr);
164 writel(srclen, &devcfg_base->dma_src_len);
165 writel(dstlen, &devcfg_base->dma_dst_len);
Michal Simekd5dae852013-04-22 15:43:02 +0200166
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530167 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200168
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530169 /* Polling the PCAP_INIT status for Set */
170 ts = get_timer(0);
171 while (!(isr_status & DEVCFG_ISR_DMA_DONE)) {
172 if (isr_status & DEVCFG_ISR_ERROR_FLAGS_MASK) {
173 debug("%s: Error: isr = 0x%08X\n", __func__,
174 isr_status);
175 debug("%s: Write count = 0x%08X\n", __func__,
176 readl(&devcfg_base->write_count));
177 debug("%s: Read count = 0x%08X\n", __func__,
178 readl(&devcfg_base->read_count));
Michal Simekd5dae852013-04-22 15:43:02 +0200179
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530180 return FPGA_FAIL;
Novasys Ingenieriec83a35f2013-11-27 09:03:01 +0100181 }
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530182 if (get_timer(ts) > CONFIG_SYS_FPGA_PROG_TIME) {
183 printf("%s: Timeout wait for DMA to complete\n",
184 __func__);
185 return FPGA_FAIL;
186 }
187 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200188 }
189
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530190 debug("%s: DMA transfer is done\n", __func__);
191
192 /* Clear out the DMA status */
193 writel(DEVCFG_ISR_DMA_DONE, &devcfg_base->int_sts);
194
195 return FPGA_SUCCESS;
196}
197
Michal Simek5b815c92014-05-02 14:15:27 +0200198static int zynq_dma_xfer_init(bitstream_type bstype)
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530199{
200 u32 status, control, isr_status;
201 unsigned long ts;
202
Soren Brinkmann5f932272013-06-14 17:43:24 -0700203 /* Clear loopback bit */
204 clrbits_le32(&devcfg_base->mctrl, DEVCFG_MCTRL_PCAP_LPBK);
205
Michal Simek5b815c92014-05-02 14:15:27 +0200206 if (bstype != BIT_PARTIAL) {
Michal Simekd5dae852013-04-22 15:43:02 +0200207 zynq_slcr_devcfg_disable();
208
209 /* Setting PCFG_PROG_B signal to high */
210 control = readl(&devcfg_base->ctrl);
211 writel(control | DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +0530212
213 /*
214 * Delay is required if AES efuse is selected as
215 * key source.
216 */
217 if (control & DEVCFG_CTRL_PCFG_AES_EFUSE_MASK)
218 mdelay(5);
219
Michal Simekd5dae852013-04-22 15:43:02 +0200220 /* Setting PCFG_PROG_B signal to low */
221 writel(control & ~DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
222
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +0530223 /*
224 * Delay is required if AES efuse is selected as
225 * key source.
226 */
227 if (control & DEVCFG_CTRL_PCFG_AES_EFUSE_MASK)
228 mdelay(5);
229
Michal Simekd5dae852013-04-22 15:43:02 +0200230 /* Polling the PCAP_INIT status for Reset */
231 ts = get_timer(0);
232 while (readl(&devcfg_base->status) & DEVCFG_STATUS_PCFG_INIT) {
233 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
234 printf("%s: Timeout wait for INIT to clear\n",
235 __func__);
236 return FPGA_FAIL;
237 }
238 }
239
240 /* Setting PCFG_PROG_B signal to high */
241 writel(control | DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
242
243 /* Polling the PCAP_INIT status for Set */
244 ts = get_timer(0);
245 while (!(readl(&devcfg_base->status) &
246 DEVCFG_STATUS_PCFG_INIT)) {
247 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
248 printf("%s: Timeout wait for INIT to set\n",
249 __func__);
250 return FPGA_FAIL;
251 }
252 }
253 }
254
255 isr_status = readl(&devcfg_base->int_sts);
256
257 /* Clear it all, so if Boot ROM comes back, it can proceed */
258 writel(0xFFFFFFFF, &devcfg_base->int_sts);
259
260 if (isr_status & DEVCFG_ISR_FATAL_ERROR_MASK) {
261 debug("%s: Fatal errors in PCAP 0x%X\n", __func__, isr_status);
262
263 /* If RX FIFO overflow, need to flush RX FIFO first */
264 if (isr_status & DEVCFG_ISR_RX_FIFO_OV) {
265 writel(DEVCFG_MCTRL_RFIFO_FLUSH, &devcfg_base->mctrl);
266 writel(0xFFFFFFFF, &devcfg_base->int_sts);
267 }
268 return FPGA_FAIL;
269 }
270
271 status = readl(&devcfg_base->status);
272
273 debug("%s: Status = 0x%08X\n", __func__, status);
274
275 if (status & DEVCFG_STATUS_DMA_CMD_Q_F) {
276 debug("%s: Error: device busy\n", __func__);
277 return FPGA_FAIL;
278 }
279
280 debug("%s: Device ready\n", __func__);
281
282 if (!(status & DEVCFG_STATUS_DMA_CMD_Q_E)) {
283 if (!(readl(&devcfg_base->int_sts) & DEVCFG_ISR_DMA_DONE)) {
284 /* Error state, transfer cannot occur */
285 debug("%s: ISR indicates error\n", __func__);
286 return FPGA_FAIL;
287 } else {
288 /* Clear out the status */
289 writel(DEVCFG_ISR_DMA_DONE, &devcfg_base->int_sts);
290 }
291 }
292
293 if (status & DEVCFG_STATUS_DMA_DONE_CNT_MASK) {
294 /* Clear the count of completed DMA transfers */
295 writel(DEVCFG_STATUS_DMA_DONE_CNT_MASK, &devcfg_base->status);
296 }
297
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530298 return FPGA_SUCCESS;
299}
300
301static u32 *zynq_align_dma_buffer(u32 *buf, u32 len, u32 swap)
302{
303 u32 *new_buf;
304 u32 i;
305
306 if ((u32)buf != ALIGN((u32)buf, ARCH_DMA_MINALIGN)) {
307 new_buf = (u32 *)ALIGN((u32)buf, ARCH_DMA_MINALIGN);
308
309 /*
310 * This might be dangerous but permits to flash if
311 * ARCH_DMA_MINALIGN is greater than header size
312 */
313 if (new_buf > buf) {
314 debug("%s: Aligned buffer is after buffer start\n",
315 __func__);
316 new_buf -= ARCH_DMA_MINALIGN;
317 }
318 printf("%s: Align buffer at %x to %x(swap %d)\n", __func__,
319 (u32)buf, (u32)new_buf, swap);
320
321 for (i = 0; i < (len/4); i++)
322 new_buf[i] = load_word(&buf[i], swap);
323
324 buf = new_buf;
325 } else if (swap != SWAP_DONE) {
326 /* For bitstream which are aligned */
327 u32 *new_buf = (u32 *)buf;
328
329 printf("%s: Bitstream is not swapped(%d) - swap it\n", __func__,
330 swap);
331
332 for (i = 0; i < (len/4); i++)
333 new_buf[i] = load_word(&buf[i], swap);
334 }
335
336 return buf;
337}
338
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530339static int zynq_validate_bitstream(xilinx_desc *desc, const void *buf,
340 size_t bsize, u32 blocksize, u32 *swap,
Michal Simek5b815c92014-05-02 14:15:27 +0200341 bitstream_type *bstype)
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530342{
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530343 u32 *buf_start;
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530344 u32 diff;
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530345
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530346 buf_start = check_data((u8 *)buf, blocksize, swap);
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530347
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530348 if (!buf_start)
349 return FPGA_FAIL;
350
351 /* Check if data is postpone from start */
352 diff = (u32)buf_start - (u32)buf;
353 if (diff) {
354 printf("%s: Bitstream is not validated yet (diff %x)\n",
355 __func__, diff);
356 return FPGA_FAIL;
357 }
358
359 if ((u32)buf < SZ_1M) {
360 printf("%s: Bitstream has to be placed up to 1MB (%x)\n",
361 __func__, (u32)buf);
362 return FPGA_FAIL;
363 }
364
Michal Simek5b815c92014-05-02 14:15:27 +0200365 if (zynq_dma_xfer_init(*bstype))
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530366 return FPGA_FAIL;
367
368 return 0;
369}
370
Michal Simek7a78bd22014-05-02 14:09:30 +0200371static int zynq_load(xilinx_desc *desc, const void *buf, size_t bsize,
372 bitstream_type bstype)
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530373{
374 unsigned long ts; /* Timestamp */
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530375 u32 isr_status, swap;
376
377 /*
378 * send bsize inplace of blocksize as it was not a bitstream
379 * in chunks
380 */
381 if (zynq_validate_bitstream(desc, buf, bsize, bsize, &swap,
Michal Simek5b815c92014-05-02 14:15:27 +0200382 &bstype))
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530383 return FPGA_FAIL;
384
385 buf = zynq_align_dma_buffer((u32 *)buf, bsize, swap);
386
Michal Simekd5dae852013-04-22 15:43:02 +0200387 debug("%s: Source = 0x%08X\n", __func__, (u32)buf);
388 debug("%s: Size = %zu\n", __func__, bsize);
389
Jagannadha Sutradharudu Tekiec4b73f2013-09-20 18:39:47 +0530390 /* flush(clean & invalidate) d-cache range buf */
391 flush_dcache_range((u32)buf, (u32)buf +
392 roundup(bsize, ARCH_DMA_MINALIGN));
393
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530394 if (zynq_dma_transfer((u32)buf | 1, bsize >> 2, 0xffffffff, 0))
395 return FPGA_FAIL;
Michal Simekd5dae852013-04-22 15:43:02 +0200396
397 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200398 /* Check FPGA configuration completion */
399 ts = get_timer(0);
400 while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) {
401 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
402 printf("%s: Timeout wait for FPGA to config\n",
403 __func__);
404 return FPGA_FAIL;
405 }
406 isr_status = readl(&devcfg_base->int_sts);
407 }
408
409 debug("%s: FPGA config done\n", __func__);
410
Michal Simek5b815c92014-05-02 14:15:27 +0200411 if (bstype != BIT_PARTIAL)
Michal Simekd5dae852013-04-22 15:43:02 +0200412 zynq_slcr_devcfg_enable();
413
Siva Durga Prasad Paladugu31f7ce72019-03-23 16:01:36 +0530414 puts("INFO:post config was not run, please run manually if needed\n");
415
Michal Simekd5dae852013-04-22 15:43:02 +0200416 return FPGA_SUCCESS;
417}
418
Luis Aranedad600c4f2018-07-19 03:10:17 -0400419#if defined(CONFIG_CMD_FPGA_LOADFS) && !defined(CONFIG_SPL_BUILD)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530420static int zynq_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
421 fpga_fs_info *fsinfo)
422{
423 unsigned long ts; /* Timestamp */
424 u32 isr_status, swap;
425 u32 partialbit = 0;
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800426 loff_t blocksize, actread;
427 loff_t pos = 0;
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530428 int fstype;
Tien Fong Chee3003c442019-02-15 15:57:07 +0800429 char *interface, *dev_part;
430 const char *filename;
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530431
432 blocksize = fsinfo->blocksize;
433 interface = fsinfo->interface;
434 dev_part = fsinfo->dev_part;
435 filename = fsinfo->filename;
436 fstype = fsinfo->fstype;
437
438 if (fs_set_blk_dev(interface, dev_part, fstype))
439 return FPGA_FAIL;
440
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800441 if (fs_read(filename, (u32) buf, pos, blocksize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530442 return FPGA_FAIL;
443
444 if (zynq_validate_bitstream(desc, buf, bsize, blocksize, &swap,
445 &partialbit))
446 return FPGA_FAIL;
447
448 dcache_disable();
449
450 do {
451 buf = zynq_align_dma_buffer((u32 *)buf, blocksize, swap);
452
453 if (zynq_dma_transfer((u32)buf | 1, blocksize >> 2,
454 0xffffffff, 0))
455 return FPGA_FAIL;
456
457 bsize -= blocksize;
458 pos += blocksize;
459
460 if (fs_set_blk_dev(interface, dev_part, fstype))
461 return FPGA_FAIL;
462
463 if (bsize > blocksize) {
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800464 if (fs_read(filename, (u32) buf, pos, blocksize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530465 return FPGA_FAIL;
466 } else {
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800467 if (fs_read(filename, (u32) buf, pos, bsize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530468 return FPGA_FAIL;
469 }
470 } while (bsize > blocksize);
471
472 buf = zynq_align_dma_buffer((u32 *)buf, blocksize, swap);
473
474 if (zynq_dma_transfer((u32)buf | 1, bsize >> 2, 0xffffffff, 0))
475 return FPGA_FAIL;
476
477 dcache_enable();
478
479 isr_status = readl(&devcfg_base->int_sts);
480
481 /* Check FPGA configuration completion */
482 ts = get_timer(0);
483 while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) {
484 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
485 printf("%s: Timeout wait for FPGA to config\n",
486 __func__);
487 return FPGA_FAIL;
488 }
489 isr_status = readl(&devcfg_base->int_sts);
490 }
491
492 debug("%s: FPGA config done\n", __func__);
493
494 if (!partialbit)
495 zynq_slcr_devcfg_enable();
496
497 return FPGA_SUCCESS;
498}
499#endif
500
Michal Simek14cfc4f2014-03-13 13:07:57 +0100501struct xilinx_fpga_op zynq_op = {
502 .load = zynq_load,
Luis Aranedad600c4f2018-07-19 03:10:17 -0400503#if defined(CONFIG_CMD_FPGA_LOADFS) && !defined(CONFIG_SPL_BUILD)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530504 .loadfs = zynq_loadfs,
505#endif
Michal Simek14cfc4f2014-03-13 13:07:57 +0100506};
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +0530507
508#ifdef CONFIG_CMD_ZYNQ_AES
509/*
510 * Load the encrypted image from src addr and decrypt the image and
511 * place it back the decrypted image into dstaddr.
512 */
513int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen)
514{
515 if (srcaddr < SZ_1M || dstaddr < SZ_1M) {
516 printf("%s: src and dst addr should be > 1M\n",
517 __func__);
518 return FPGA_FAIL;
519 }
520
521 if (zynq_dma_xfer_init(BIT_NONE)) {
522 printf("%s: zynq_dma_xfer_init FAIL\n", __func__);
523 return FPGA_FAIL;
524 }
525
526 writel((readl(&devcfg_base->ctrl) | DEVCFG_CTRL_PCAP_RATE_EN_MASK),
527 &devcfg_base->ctrl);
528
529 debug("%s: Source = 0x%08X\n", __func__, (u32)srcaddr);
530 debug("%s: Size = %zu\n", __func__, srclen);
531
532 /* flush(clean & invalidate) d-cache range buf */
533 flush_dcache_range((u32)srcaddr, (u32)srcaddr +
534 roundup(srclen << 2, ARCH_DMA_MINALIGN));
535 /*
536 * Flush destination address range only if image is not
537 * bitstream.
538 */
539 flush_dcache_range((u32)dstaddr, (u32)dstaddr +
540 roundup(dstlen << 2, ARCH_DMA_MINALIGN));
541
542 if (zynq_dma_transfer(srcaddr | 1, srclen, dstaddr | 1, dstlen))
543 return FPGA_FAIL;
544
545 writel((readl(&devcfg_base->ctrl) & ~DEVCFG_CTRL_PCAP_RATE_EN_MASK),
546 &devcfg_base->ctrl);
547
548 return FPGA_SUCCESS;
549}
550#endif