T Karthik Reddy | afafd0a | 2020-06-24 03:23:57 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * (C) Copyright 2020 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
| 5 | */ |
| 6 | |
| 7 | #include <cpu_func.h> |
| 8 | #include <command.h> |
| 9 | #include <common.h> |
| 10 | #include <log.h> |
| 11 | #include <memalign.h> |
| 12 | #include <versalpl.h> |
| 13 | #include <zynqmp_firmware.h> |
| 14 | |
| 15 | static int do_versal_load_pdi(struct cmd_tbl *cmdtp, int flag, int argc, |
| 16 | char * const argv[]) |
| 17 | { |
| 18 | u32 buf_lo, buf_hi; |
Ibai Erkiaga | 0768aeb | 2020-08-04 23:17:26 +0100 | [diff] [blame] | 19 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
T Karthik Reddy | afafd0a | 2020-06-24 03:23:57 -0600 | [diff] [blame] | 20 | ulong addr, *pdi_buf; |
| 21 | size_t len; |
| 22 | int ret; |
| 23 | |
| 24 | if (argc != cmdtp->maxargs) { |
| 25 | debug("pdi_load: incorrect parameters passed\n"); |
| 26 | return CMD_RET_USAGE; |
| 27 | } |
| 28 | |
| 29 | addr = simple_strtol(argv[2], NULL, 16); |
| 30 | if (!addr) { |
| 31 | debug("pdi_load: zero pdi_data address\n"); |
| 32 | return CMD_RET_USAGE; |
| 33 | } |
| 34 | |
| 35 | len = simple_strtoul(argv[3], NULL, 16); |
| 36 | if (!len) { |
| 37 | debug("pdi_load: zero size\n"); |
| 38 | return CMD_RET_USAGE; |
| 39 | } |
| 40 | |
| 41 | pdi_buf = (ulong *)ALIGN((ulong)addr, ARCH_DMA_MINALIGN); |
| 42 | if ((ulong)addr != (ulong)pdi_buf) { |
| 43 | memcpy((void *)pdi_buf, (void *)addr, len); |
| 44 | debug("Pdi addr:0x%lx aligned to 0x%lx\n", |
| 45 | addr, (ulong)pdi_buf); |
| 46 | } |
| 47 | |
| 48 | flush_dcache_range((ulong)pdi_buf, (ulong)pdi_buf + len); |
| 49 | |
| 50 | buf_lo = lower_32_bits((ulong)pdi_buf); |
| 51 | buf_hi = upper_32_bits((ulong)pdi_buf); |
| 52 | |
| 53 | ret = xilinx_pm_request(VERSAL_PM_LOAD_PDI, VERSAL_PM_PDI_TYPE, buf_lo, |
| 54 | buf_hi, 0, ret_payload); |
| 55 | if (ret) |
| 56 | printf("PDI load failed with err: 0x%08x\n", ret); |
| 57 | |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | static struct cmd_tbl cmd_versal_sub[] = { |
| 62 | U_BOOT_CMD_MKENT(loadpdi, 4, 1, do_versal_load_pdi, "", ""), |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * do_versal - Handle the "versal" command-line command |
| 67 | * @cmdtp: Command data struct pointer |
| 68 | * @flag: Command flag |
| 69 | * @argc: Command-line argument count |
| 70 | * @argv: Array of command-line arguments |
| 71 | * |
| 72 | * Processes the versal specific commands |
| 73 | * |
| 74 | * Return: return 0 on success, Error value if command fails. |
| 75 | * CMD_RET_USAGE incase of incorrect/missing parameters. |
| 76 | */ |
| 77 | static int do_versal(struct cmd_tbl *cmdtp, int flag, int argc, |
| 78 | char *const argv[]) |
| 79 | { |
| 80 | struct cmd_tbl *c; |
| 81 | int ret = CMD_RET_USAGE; |
| 82 | |
| 83 | if (argc < 2) |
| 84 | return CMD_RET_USAGE; |
| 85 | |
| 86 | c = find_cmd_tbl(argv[1], &cmd_versal_sub[0], |
| 87 | ARRAY_SIZE(cmd_versal_sub)); |
| 88 | if (c) |
| 89 | ret = c->cmd(c, flag, argc, argv); |
| 90 | |
| 91 | return cmd_process_error(c, ret); |
| 92 | } |
| 93 | |
| 94 | #ifdef CONFIG_SYS_LONGHELP |
| 95 | static char versal_help_text[] = |
| 96 | "loadpdi addr len - Load pdi image\n" |
| 97 | "load pdi image at ddr address 'addr' with pdi image size 'len'\n" |
| 98 | ; |
| 99 | #endif |
| 100 | |
| 101 | U_BOOT_CMD(versal, 4, 1, do_versal, |
| 102 | "versal sub-system", |
| 103 | versal_help_text |
| 104 | ) |
| 105 | |