1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2023, Advanced Micro Devices, Inc. 4 * 5 * Michal Simek <michal.simek@amd.com> 6 */ 7 8#include <cpu_func.h> 9#include <command.h> 10#include <common.h> 11#include <log.h> 12#include <memalign.h> 13#include <versalpl.h> 14#include <zynqmp_firmware.h> 15 16/** 17 * do_versalnet_load_pdi - Handle the "versalnet load pdi" command-line command 18 * @cmdtp: Command data struct pointer 19 * @flag: Command flag 20 * @argc: Command-line argument count 21 * @argv: Array of command-line arguments 22 * 23 * Processes the Versal NET load pdi command 24 * 25 * Return: return 0 on success, Error value if command fails. 26 * CMD_RET_USAGE incase of incorrect/missing parameters. 27 */ 28static int do_versalnet_load_pdi(struct cmd_tbl *cmdtp, int flag, int argc, 29 char * const argv[]) 30{ 31 u32 buf_lo, buf_hi; 32 u32 ret_payload[PAYLOAD_ARG_CNT]; 33 ulong addr, *pdi_buf; 34 size_t len; 35 int ret; 36 37 if (argc != cmdtp->maxargs) { 38 debug("pdi_load: incorrect parameters passed\n"); 39 return CMD_RET_USAGE; 40 } 41 42 addr = simple_strtol(argv[1], NULL, 16); 43 if (!addr) { 44 debug("pdi_load: zero pdi_data address\n"); 45 return CMD_RET_USAGE; 46 } 47 48 len = hextoul(argv[2], NULL); 49 if (!len) { 50 debug("pdi_load: zero size\n"); 51 return CMD_RET_USAGE; 52 } 53 54 pdi_buf = (ulong *)ALIGN((ulong)addr, ARCH_DMA_MINALIGN); 55 if ((ulong)addr != (ulong)pdi_buf) { 56 memcpy((void *)pdi_buf, (void *)addr, len); 57 debug("Pdi addr:0x%lx aligned to 0x%lx\n", 58 addr, (ulong)pdi_buf); 59 } 60 61 flush_dcache_range((ulong)pdi_buf, (ulong)pdi_buf + len); 62 63 buf_lo = lower_32_bits((ulong)pdi_buf); 64 buf_hi = upper_32_bits((ulong)pdi_buf); 65 66 ret = xilinx_pm_request(VERSAL_PM_LOAD_PDI, VERSAL_PM_PDI_TYPE, buf_lo, 67 buf_hi, 0, ret_payload); 68 if (ret) 69 printf("PDI load failed with err: 0x%08x\n", ret); 70 71 return cmd_process_error(cmdtp, ret); 72} 73 74static char versalnet_help_text[] = 75 "loadpdi addr len - Load pdi image\n" 76 "load pdi image at ddr address 'addr' with pdi image size 'len'\n" 77; 78 79U_BOOT_CMD_WITH_SUBCMDS(versalnet, "Versal NET sub-system", versalnet_help_text, 80 U_BOOT_SUBCMD_MKENT(loadpdi, 3, 1, 81 do_versalnet_load_pdi)); 82