blob: de71969399fe0ad2c05203a9c4b3ab103a01de71 [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>
Simon Glassc05ed002020-05-10 11:40:11 -060017#include <linux/delay.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040018#include <linux/sizes.h>
Michal Simekd5dae852013-04-22 15:43:02 +020019#include <asm/arch/hardware.h>
20#include <asm/arch/sys_proto.h>
21
22#define DEVCFG_CTRL_PCFG_PROG_B 0x40000000
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +053023#define DEVCFG_CTRL_PCFG_AES_EFUSE_MASK 0x00001000
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +053024#define DEVCFG_CTRL_PCAP_RATE_EN_MASK 0x02000000
Michal Simekd5dae852013-04-22 15:43:02 +020025#define DEVCFG_ISR_FATAL_ERROR_MASK 0x00740040
26#define DEVCFG_ISR_ERROR_FLAGS_MASK 0x00340840
27#define DEVCFG_ISR_RX_FIFO_OV 0x00040000
28#define DEVCFG_ISR_DMA_DONE 0x00002000
29#define DEVCFG_ISR_PCFG_DONE 0x00000004
30#define DEVCFG_STATUS_DMA_CMD_Q_F 0x80000000
31#define DEVCFG_STATUS_DMA_CMD_Q_E 0x40000000
32#define DEVCFG_STATUS_DMA_DONE_CNT_MASK 0x30000000
33#define DEVCFG_STATUS_PCFG_INIT 0x00000010
Soren Brinkmann5f932272013-06-14 17:43:24 -070034#define DEVCFG_MCTRL_PCAP_LPBK 0x00000010
Michal Simekd5dae852013-04-22 15:43:02 +020035#define DEVCFG_MCTRL_RFIFO_FLUSH 0x00000002
36#define DEVCFG_MCTRL_WFIFO_FLUSH 0x00000001
37
38#ifndef CONFIG_SYS_FPGA_WAIT
39#define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/100 /* 10 ms */
40#endif
41
42#ifndef CONFIG_SYS_FPGA_PROG_TIME
Michal Simekfd2b10b2013-06-17 13:54:07 +020043#define CONFIG_SYS_FPGA_PROG_TIME (CONFIG_SYS_HZ * 4) /* 4 s */
Michal Simekd5dae852013-04-22 15:43:02 +020044#endif
45
Michal Simekd5dae852013-04-22 15:43:02 +020046#define DUMMY_WORD 0xffffffff
47
48/* Xilinx binary format header */
49static const u32 bin_format[] = {
50 DUMMY_WORD, /* Dummy words */
51 DUMMY_WORD,
52 DUMMY_WORD,
53 DUMMY_WORD,
54 DUMMY_WORD,
55 DUMMY_WORD,
56 DUMMY_WORD,
57 DUMMY_WORD,
58 0x000000bb, /* Sync word */
59 0x11220044, /* Sync word */
60 DUMMY_WORD,
61 DUMMY_WORD,
62 0xaa995566, /* Sync word */
63};
64
65#define SWAP_NO 1
66#define SWAP_DONE 2
67
68/*
69 * Load the whole word from unaligned buffer
70 * Keep in your mind that it is byte loading on little-endian system
71 */
72static u32 load_word(const void *buf, u32 swap)
73{
74 u32 word = 0;
75 u8 *bitc = (u8 *)buf;
76 int p;
77
78 if (swap == SWAP_NO) {
79 for (p = 0; p < 4; p++) {
80 word <<= 8;
81 word |= bitc[p];
82 }
83 } else {
84 for (p = 3; p >= 0; p--) {
85 word <<= 8;
86 word |= bitc[p];
87 }
88 }
89
90 return word;
91}
92
93static u32 check_header(const void *buf)
94{
95 u32 i, pattern;
96 int swap = SWAP_NO;
97 u32 *test = (u32 *)buf;
98
99 debug("%s: Let's check bitstream header\n", __func__);
100
101 /* Checking that passing bin is not a bitstream */
102 for (i = 0; i < ARRAY_SIZE(bin_format); i++) {
103 pattern = load_word(&test[i], swap);
104
105 /*
106 * Bitstreams in binary format are swapped
107 * compare to regular bistream.
108 * Do not swap dummy word but if swap is done assume
109 * that parsing buffer is binary format
110 */
111 if ((__swab32(pattern) != DUMMY_WORD) &&
112 (__swab32(pattern) == bin_format[i])) {
113 pattern = __swab32(pattern);
114 swap = SWAP_DONE;
115 debug("%s: data swapped - let's swap\n", __func__);
116 }
117
118 debug("%s: %d/%x: pattern %x/%x bin_format\n", __func__, i,
119 (u32)&test[i], pattern, bin_format[i]);
120 if (pattern != bin_format[i]) {
121 debug("%s: Bitstream is not recognized\n", __func__);
122 return 0;
123 }
124 }
125 debug("%s: Found bitstream header at %x %s swapinng\n", __func__,
126 (u32)buf, swap == SWAP_NO ? "without" : "with");
127
128 return swap;
129}
130
131static void *check_data(u8 *buf, size_t bsize, u32 *swap)
132{
133 u32 word, p = 0; /* possition */
134
135 /* Because buf doesn't need to be aligned let's read it by chars */
136 for (p = 0; p < bsize; p++) {
137 word = load_word(&buf[p], SWAP_NO);
138 debug("%s: word %x %x/%x\n", __func__, word, p, (u32)&buf[p]);
139
140 /* Find the first bitstream dummy word */
141 if (word == DUMMY_WORD) {
142 debug("%s: Found dummy word at position %x/%x\n",
143 __func__, p, (u32)&buf[p]);
144 *swap = check_header(&buf[p]);
145 if (*swap) {
146 /* FIXME add full bitstream checking here */
147 return &buf[p];
148 }
149 }
150 /* Loop can be huge - support CTRL + C */
151 if (ctrlc())
Michal Simek42a74a02014-04-25 13:51:58 +0200152 return NULL;
Michal Simekd5dae852013-04-22 15:43:02 +0200153 }
Michal Simek42a74a02014-04-25 13:51:58 +0200154 return NULL;
Michal Simekd5dae852013-04-22 15:43:02 +0200155}
156
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530157static int zynq_dma_transfer(u32 srcbuf, u32 srclen, u32 dstbuf, u32 dstlen)
Michal Simekd5dae852013-04-22 15:43:02 +0200158{
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530159 unsigned long ts;
160 u32 isr_status;
Michal Simekd5dae852013-04-22 15:43:02 +0200161
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530162 /* Set up the transfer */
163 writel((u32)srcbuf, &devcfg_base->dma_src_addr);
164 writel(dstbuf, &devcfg_base->dma_dst_addr);
165 writel(srclen, &devcfg_base->dma_src_len);
166 writel(dstlen, &devcfg_base->dma_dst_len);
Michal Simekd5dae852013-04-22 15:43:02 +0200167
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530168 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200169
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530170 /* Polling the PCAP_INIT status for Set */
171 ts = get_timer(0);
172 while (!(isr_status & DEVCFG_ISR_DMA_DONE)) {
173 if (isr_status & DEVCFG_ISR_ERROR_FLAGS_MASK) {
174 debug("%s: Error: isr = 0x%08X\n", __func__,
175 isr_status);
176 debug("%s: Write count = 0x%08X\n", __func__,
177 readl(&devcfg_base->write_count));
178 debug("%s: Read count = 0x%08X\n", __func__,
179 readl(&devcfg_base->read_count));
Michal Simekd5dae852013-04-22 15:43:02 +0200180
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530181 return FPGA_FAIL;
Novasys Ingenieriec83a35f2013-11-27 09:03:01 +0100182 }
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530183 if (get_timer(ts) > CONFIG_SYS_FPGA_PROG_TIME) {
184 printf("%s: Timeout wait for DMA to complete\n",
185 __func__);
186 return FPGA_FAIL;
187 }
188 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200189 }
190
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530191 debug("%s: DMA transfer is done\n", __func__);
192
193 /* Clear out the DMA status */
194 writel(DEVCFG_ISR_DMA_DONE, &devcfg_base->int_sts);
195
196 return FPGA_SUCCESS;
197}
198
Michal Simek5b815c92014-05-02 14:15:27 +0200199static int zynq_dma_xfer_init(bitstream_type bstype)
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530200{
201 u32 status, control, isr_status;
202 unsigned long ts;
203
Soren Brinkmann5f932272013-06-14 17:43:24 -0700204 /* Clear loopback bit */
205 clrbits_le32(&devcfg_base->mctrl, DEVCFG_MCTRL_PCAP_LPBK);
206
Siva Durga Prasad Paladugu3427f4d2015-12-09 18:46:43 +0530207 if (bstype != BIT_PARTIAL && bstype != BIT_NONE) {
Michal Simekd5dae852013-04-22 15:43:02 +0200208 zynq_slcr_devcfg_disable();
209
210 /* Setting PCFG_PROG_B signal to high */
211 control = readl(&devcfg_base->ctrl);
212 writel(control | DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +0530213
214 /*
215 * Delay is required if AES efuse is selected as
216 * key source.
217 */
218 if (control & DEVCFG_CTRL_PCFG_AES_EFUSE_MASK)
219 mdelay(5);
220
Michal Simekd5dae852013-04-22 15:43:02 +0200221 /* Setting PCFG_PROG_B signal to low */
222 writel(control & ~DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
223
Siva Durga Prasad Paladugu71723aa2018-03-06 17:37:09 +0530224 /*
225 * Delay is required if AES efuse is selected as
226 * key source.
227 */
228 if (control & DEVCFG_CTRL_PCFG_AES_EFUSE_MASK)
229 mdelay(5);
230
Michal Simekd5dae852013-04-22 15:43:02 +0200231 /* Polling the PCAP_INIT status for Reset */
232 ts = get_timer(0);
233 while (readl(&devcfg_base->status) & DEVCFG_STATUS_PCFG_INIT) {
234 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
235 printf("%s: Timeout wait for INIT to clear\n",
236 __func__);
237 return FPGA_FAIL;
238 }
239 }
240
241 /* Setting PCFG_PROG_B signal to high */
242 writel(control | DEVCFG_CTRL_PCFG_PROG_B, &devcfg_base->ctrl);
243
244 /* Polling the PCAP_INIT status for Set */
245 ts = get_timer(0);
246 while (!(readl(&devcfg_base->status) &
247 DEVCFG_STATUS_PCFG_INIT)) {
248 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
249 printf("%s: Timeout wait for INIT to set\n",
250 __func__);
251 return FPGA_FAIL;
252 }
253 }
254 }
255
256 isr_status = readl(&devcfg_base->int_sts);
257
258 /* Clear it all, so if Boot ROM comes back, it can proceed */
259 writel(0xFFFFFFFF, &devcfg_base->int_sts);
260
261 if (isr_status & DEVCFG_ISR_FATAL_ERROR_MASK) {
262 debug("%s: Fatal errors in PCAP 0x%X\n", __func__, isr_status);
263
264 /* If RX FIFO overflow, need to flush RX FIFO first */
265 if (isr_status & DEVCFG_ISR_RX_FIFO_OV) {
266 writel(DEVCFG_MCTRL_RFIFO_FLUSH, &devcfg_base->mctrl);
267 writel(0xFFFFFFFF, &devcfg_base->int_sts);
268 }
269 return FPGA_FAIL;
270 }
271
272 status = readl(&devcfg_base->status);
273
274 debug("%s: Status = 0x%08X\n", __func__, status);
275
276 if (status & DEVCFG_STATUS_DMA_CMD_Q_F) {
277 debug("%s: Error: device busy\n", __func__);
278 return FPGA_FAIL;
279 }
280
281 debug("%s: Device ready\n", __func__);
282
283 if (!(status & DEVCFG_STATUS_DMA_CMD_Q_E)) {
284 if (!(readl(&devcfg_base->int_sts) & DEVCFG_ISR_DMA_DONE)) {
285 /* Error state, transfer cannot occur */
286 debug("%s: ISR indicates error\n", __func__);
287 return FPGA_FAIL;
288 } else {
289 /* Clear out the status */
290 writel(DEVCFG_ISR_DMA_DONE, &devcfg_base->int_sts);
291 }
292 }
293
294 if (status & DEVCFG_STATUS_DMA_DONE_CNT_MASK) {
295 /* Clear the count of completed DMA transfers */
296 writel(DEVCFG_STATUS_DMA_DONE_CNT_MASK, &devcfg_base->status);
297 }
298
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530299 return FPGA_SUCCESS;
300}
301
302static u32 *zynq_align_dma_buffer(u32 *buf, u32 len, u32 swap)
303{
304 u32 *new_buf;
305 u32 i;
306
307 if ((u32)buf != ALIGN((u32)buf, ARCH_DMA_MINALIGN)) {
308 new_buf = (u32 *)ALIGN((u32)buf, ARCH_DMA_MINALIGN);
309
310 /*
311 * This might be dangerous but permits to flash if
312 * ARCH_DMA_MINALIGN is greater than header size
313 */
314 if (new_buf > buf) {
315 debug("%s: Aligned buffer is after buffer start\n",
316 __func__);
317 new_buf -= ARCH_DMA_MINALIGN;
318 }
319 printf("%s: Align buffer at %x to %x(swap %d)\n", __func__,
320 (u32)buf, (u32)new_buf, swap);
321
322 for (i = 0; i < (len/4); i++)
323 new_buf[i] = load_word(&buf[i], swap);
324
325 buf = new_buf;
326 } else if (swap != SWAP_DONE) {
327 /* For bitstream which are aligned */
328 u32 *new_buf = (u32 *)buf;
329
330 printf("%s: Bitstream is not swapped(%d) - swap it\n", __func__,
331 swap);
332
333 for (i = 0; i < (len/4); i++)
334 new_buf[i] = load_word(&buf[i], swap);
335 }
336
337 return buf;
338}
339
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530340static int zynq_validate_bitstream(xilinx_desc *desc, const void *buf,
341 size_t bsize, u32 blocksize, u32 *swap,
Michal Simek5b815c92014-05-02 14:15:27 +0200342 bitstream_type *bstype)
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530343{
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530344 u32 *buf_start;
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530345 u32 diff;
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530346
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530347 buf_start = check_data((u8 *)buf, blocksize, swap);
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530348
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530349 if (!buf_start)
350 return FPGA_FAIL;
351
352 /* Check if data is postpone from start */
353 diff = (u32)buf_start - (u32)buf;
354 if (diff) {
355 printf("%s: Bitstream is not validated yet (diff %x)\n",
356 __func__, diff);
357 return FPGA_FAIL;
358 }
359
360 if ((u32)buf < SZ_1M) {
361 printf("%s: Bitstream has to be placed up to 1MB (%x)\n",
362 __func__, (u32)buf);
363 return FPGA_FAIL;
364 }
365
Michal Simek5b815c92014-05-02 14:15:27 +0200366 if (zynq_dma_xfer_init(*bstype))
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530367 return FPGA_FAIL;
368
369 return 0;
370}
371
Michal Simek7a78bd22014-05-02 14:09:30 +0200372static int zynq_load(xilinx_desc *desc, const void *buf, size_t bsize,
373 bitstream_type bstype)
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530374{
375 unsigned long ts; /* Timestamp */
Siva Durga Prasad Paladugu31081852014-03-13 11:57:34 +0530376 u32 isr_status, swap;
377
378 /*
379 * send bsize inplace of blocksize as it was not a bitstream
380 * in chunks
381 */
382 if (zynq_validate_bitstream(desc, buf, bsize, bsize, &swap,
Michal Simek5b815c92014-05-02 14:15:27 +0200383 &bstype))
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530384 return FPGA_FAIL;
385
386 buf = zynq_align_dma_buffer((u32 *)buf, bsize, swap);
387
Michal Simekd5dae852013-04-22 15:43:02 +0200388 debug("%s: Source = 0x%08X\n", __func__, (u32)buf);
389 debug("%s: Size = %zu\n", __func__, bsize);
390
Jagannadha Sutradharudu Tekiec4b73f2013-09-20 18:39:47 +0530391 /* flush(clean & invalidate) d-cache range buf */
392 flush_dcache_range((u32)buf, (u32)buf +
393 roundup(bsize, ARCH_DMA_MINALIGN));
394
Siva Durga Prasad Paladugua0735a32014-03-12 17:09:26 +0530395 if (zynq_dma_transfer((u32)buf | 1, bsize >> 2, 0xffffffff, 0))
396 return FPGA_FAIL;
Michal Simekd5dae852013-04-22 15:43:02 +0200397
398 isr_status = readl(&devcfg_base->int_sts);
Michal Simekd5dae852013-04-22 15:43:02 +0200399 /* Check FPGA configuration completion */
400 ts = get_timer(0);
401 while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) {
402 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
403 printf("%s: Timeout wait for FPGA to config\n",
404 __func__);
405 return FPGA_FAIL;
406 }
407 isr_status = readl(&devcfg_base->int_sts);
408 }
409
410 debug("%s: FPGA config done\n", __func__);
411
Michal Simek5b815c92014-05-02 14:15:27 +0200412 if (bstype != BIT_PARTIAL)
Michal Simekd5dae852013-04-22 15:43:02 +0200413 zynq_slcr_devcfg_enable();
414
Siva Durga Prasad Paladugu31f7ce72019-03-23 16:01:36 +0530415 puts("INFO:post config was not run, please run manually if needed\n");
416
Michal Simekd5dae852013-04-22 15:43:02 +0200417 return FPGA_SUCCESS;
418}
419
Luis Aranedad600c4f2018-07-19 03:10:17 -0400420#if defined(CONFIG_CMD_FPGA_LOADFS) && !defined(CONFIG_SPL_BUILD)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530421static int zynq_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
422 fpga_fs_info *fsinfo)
423{
424 unsigned long ts; /* Timestamp */
425 u32 isr_status, swap;
426 u32 partialbit = 0;
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800427 loff_t blocksize, actread;
428 loff_t pos = 0;
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530429 int fstype;
Tien Fong Chee3003c442019-02-15 15:57:07 +0800430 char *interface, *dev_part;
431 const char *filename;
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530432
433 blocksize = fsinfo->blocksize;
434 interface = fsinfo->interface;
435 dev_part = fsinfo->dev_part;
436 filename = fsinfo->filename;
437 fstype = fsinfo->fstype;
438
439 if (fs_set_blk_dev(interface, dev_part, fstype))
440 return FPGA_FAIL;
441
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800442 if (fs_read(filename, (u32) buf, pos, blocksize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530443 return FPGA_FAIL;
444
445 if (zynq_validate_bitstream(desc, buf, bsize, blocksize, &swap,
446 &partialbit))
447 return FPGA_FAIL;
448
449 dcache_disable();
450
451 do {
452 buf = zynq_align_dma_buffer((u32 *)buf, blocksize, swap);
453
454 if (zynq_dma_transfer((u32)buf | 1, blocksize >> 2,
455 0xffffffff, 0))
456 return FPGA_FAIL;
457
458 bsize -= blocksize;
459 pos += blocksize;
460
461 if (fs_set_blk_dev(interface, dev_part, fstype))
462 return FPGA_FAIL;
463
464 if (bsize > blocksize) {
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800465 if (fs_read(filename, (u32) buf, pos, blocksize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530466 return FPGA_FAIL;
467 } else {
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800468 if (fs_read(filename, (u32) buf, pos, bsize, &actread) < 0)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530469 return FPGA_FAIL;
470 }
471 } while (bsize > blocksize);
472
473 buf = zynq_align_dma_buffer((u32 *)buf, blocksize, swap);
474
475 if (zynq_dma_transfer((u32)buf | 1, bsize >> 2, 0xffffffff, 0))
476 return FPGA_FAIL;
477
478 dcache_enable();
479
480 isr_status = readl(&devcfg_base->int_sts);
481
482 /* Check FPGA configuration completion */
483 ts = get_timer(0);
484 while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) {
485 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
486 printf("%s: Timeout wait for FPGA to config\n",
487 __func__);
488 return FPGA_FAIL;
489 }
490 isr_status = readl(&devcfg_base->int_sts);
491 }
492
493 debug("%s: FPGA config done\n", __func__);
494
495 if (!partialbit)
496 zynq_slcr_devcfg_enable();
497
498 return FPGA_SUCCESS;
499}
500#endif
501
Michal Simek14cfc4f2014-03-13 13:07:57 +0100502struct xilinx_fpga_op zynq_op = {
503 .load = zynq_load,
Luis Aranedad600c4f2018-07-19 03:10:17 -0400504#if defined(CONFIG_CMD_FPGA_LOADFS) && !defined(CONFIG_SPL_BUILD)
Siva Durga Prasad Paladugu1a897662014-03-14 16:35:37 +0530505 .loadfs = zynq_loadfs,
506#endif
Michal Simek14cfc4f2014-03-13 13:07:57 +0100507};
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +0530508
509#ifdef CONFIG_CMD_ZYNQ_AES
510/*
511 * Load the encrypted image from src addr and decrypt the image and
512 * place it back the decrypted image into dstaddr.
513 */
Siva Durga Prasad Paladugu3427f4d2015-12-09 18:46:43 +0530514int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen,
515 u8 bstype)
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +0530516{
T Karthik Reddy1d9632a2019-03-12 20:20:20 +0530517 u32 isr_status, ts;
518
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +0530519 if (srcaddr < SZ_1M || dstaddr < SZ_1M) {
520 printf("%s: src and dst addr should be > 1M\n",
521 __func__);
522 return FPGA_FAIL;
523 }
524
Siva Durga Prasad Paladugu3427f4d2015-12-09 18:46:43 +0530525 if (zynq_dma_xfer_init(bstype)) {
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +0530526 printf("%s: zynq_dma_xfer_init FAIL\n", __func__);
527 return FPGA_FAIL;
528 }
529
530 writel((readl(&devcfg_base->ctrl) | DEVCFG_CTRL_PCAP_RATE_EN_MASK),
531 &devcfg_base->ctrl);
532
533 debug("%s: Source = 0x%08X\n", __func__, (u32)srcaddr);
534 debug("%s: Size = %zu\n", __func__, srclen);
535
536 /* flush(clean & invalidate) d-cache range buf */
537 flush_dcache_range((u32)srcaddr, (u32)srcaddr +
538 roundup(srclen << 2, ARCH_DMA_MINALIGN));
539 /*
540 * Flush destination address range only if image is not
541 * bitstream.
542 */
543 flush_dcache_range((u32)dstaddr, (u32)dstaddr +
544 roundup(dstlen << 2, ARCH_DMA_MINALIGN));
545
546 if (zynq_dma_transfer(srcaddr | 1, srclen, dstaddr | 1, dstlen))
547 return FPGA_FAIL;
548
T Karthik Reddy1d9632a2019-03-12 20:20:20 +0530549 if (bstype == BIT_FULL) {
550 isr_status = readl(&devcfg_base->int_sts);
551 /* Check FPGA configuration completion */
552 ts = get_timer(0);
553 while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) {
554 if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) {
555 printf("%s: Timeout wait for FPGA to config\n",
556 __func__);
557 return FPGA_FAIL;
558 }
559 isr_status = readl(&devcfg_base->int_sts);
560 }
561 printf("%s: FPGA config done\n", __func__);
562 zynq_slcr_devcfg_enable();
563 }
Siva Durga Prasad Paladugu37e3a362018-06-26 15:02:19 +0530564
565 return FPGA_SUCCESS;
566}
567#endif