1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx Zynq MPSoC Firmware driver
5 * Copyright (C) 2018-2019 Xilinx, Inc.
12 #include <zynqmp_firmware.h>
13 #include <asm/cache.h>
14 #include <asm/ptrace.h>
16 #if defined(CONFIG_ZYNQMP_IPI)
18 #include <asm/arch/sys_proto.h>
20 #define PMUFW_PAYLOAD_ARG_CNT 8
22 #define XST_PM_NO_ACCESS 2002L
23 #define XST_PM_ALREADY_CONFIGURED 2009L
26 struct mbox_chan tx_chan;
27 struct mbox_chan rx_chan;
30 static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
32 struct zynqmp_ipi_msg msg;
34 u32 buffer[PAYLOAD_ARG_CNT];
39 if (req_len > PMUFW_PAYLOAD_ARG_CNT ||
40 res_maxlen > PMUFW_PAYLOAD_ARG_CNT)
43 if (!(zynqmp_power.tx_chan.dev) || !(&zynqmp_power.rx_chan.dev))
46 debug("%s, Sending IPI message with ID: 0x%0x\n", __func__, req[0]);
49 ret = mbox_send(&zynqmp_power.tx_chan, &msg);
51 debug("%s: Sending message failed\n", __func__);
57 ret = mbox_recv(&zynqmp_power.rx_chan, &msg, 100);
59 debug("%s: Receiving message failed\n", __func__);
64 unsigned int zynqmp_firmware_version(void)
67 u32 ret_payload[PAYLOAD_ARG_CNT];
68 static u32 pm_api_version = ZYNQMP_PM_VERSION_INVALID;
71 * Get PMU version only once and later
72 * just return stored values instead of
75 if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) {
77 ret = xilinx_pm_request(PM_GET_API_VERSION, 0, 0, 0, 0,
80 panic("PMUFW is not found - Please load it!\n");
82 pm_api_version = ret_payload[1];
83 if (pm_api_version < ZYNQMP_PM_VERSION)
84 panic("PMUFW version error. Expected: v%d.%d\n",
85 ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR);
88 return pm_api_version;
92 * Send a configuration object to the PMU firmware.
94 * @cfg_obj: Pointer to the configuration object
95 * @size: Size of @cfg_obj in bytes
97 void zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size)
100 u32 ret_payload[PAYLOAD_ARG_CNT];
102 if (IS_ENABLED(CONFIG_SPL_BUILD))
103 printf("Loading new PMUFW cfg obj (%ld bytes)\n", size);
105 flush_dcache_range((ulong)cfg_obj, (ulong)(cfg_obj + size));
107 err = xilinx_pm_request(PM_SET_CONFIGURATION, (u32)(u64)cfg_obj, 0, 0,
109 if (err == XST_PM_NO_ACCESS) {
110 printf("PMUFW no permission to change config object\n");
114 if (err == XST_PM_ALREADY_CONFIGURED) {
115 debug("PMUFW Node is already configured\n");
120 printf("Cannot load PMUFW configuration object (%d)\n", err);
123 printf("PMUFW returned 0x%08x status!\n", ret_payload[0]);
125 if ((err || ret_payload[0]) && IS_ENABLED(CONFIG_SPL_BUILD))
126 panic("PMUFW config object loading failed in EL3\n");
129 static int zynqmp_power_probe(struct udevice *dev)
133 debug("%s, (dev=%p)\n", __func__, dev);
135 ret = mbox_get_by_name(dev, "tx", &zynqmp_power.tx_chan);
137 debug("%s: Cannot find tx mailbox\n", __func__);
141 ret = mbox_get_by_name(dev, "rx", &zynqmp_power.rx_chan);
143 debug("%s: Cannot find rx mailbox\n", __func__);
147 ret = zynqmp_firmware_version();
148 printf("PMUFW:\tv%d.%d\n",
149 ret >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
150 ret & ZYNQMP_PM_VERSION_MINOR_MASK);
155 static const struct udevice_id zynqmp_power_ids[] = {
156 { .compatible = "xlnx,zynqmp-power" },
160 U_BOOT_DRIVER(zynqmp_power) = {
161 .name = "zynqmp_power",
162 .id = UCLASS_FIRMWARE,
163 .of_match = zynqmp_power_ids,
164 .probe = zynqmp_power_probe,
168 int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
169 u32 arg3, u32 *ret_payload)
171 debug("%s at EL%d, API ID: 0x%0x\n", __func__, current_el(), api_id);
173 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
174 #if defined(CONFIG_ZYNQMP_IPI)
176 * Use fixed payload and arg size as the EL2 call. The firmware
177 * is capable to handle PMUFW_PAYLOAD_ARG_CNT bytes but the
178 * firmware API is limited by the SMC call size
180 u32 regs[] = {api_id, arg0, arg1, arg2, arg3};
183 if (api_id == PM_FPGA_LOAD) {
184 /* Swap addr_hi/low because of incompatibility */
191 ret = ipi_req(regs, PAYLOAD_ARG_CNT, ret_payload,
200 * Added SIP service call Function Identifier
201 * Make sure to stay in x0 register
205 regs.regs[0] = PM_SIP_SVC | api_id;
206 regs.regs[1] = ((u64)arg1 << 32) | arg0;
207 regs.regs[2] = ((u64)arg3 << 32) | arg2;
212 ret_payload[0] = (u32)regs.regs[0];
213 ret_payload[1] = upper_32_bits(regs.regs[0]);
214 ret_payload[2] = (u32)regs.regs[1];
215 ret_payload[3] = upper_32_bits(regs.regs[1]);
216 ret_payload[4] = (u32)regs.regs[2];
220 return (ret_payload) ? ret_payload[0] : 0;
223 static const struct udevice_id zynqmp_firmware_ids[] = {
224 { .compatible = "xlnx,zynqmp-firmware" },
225 { .compatible = "xlnx,versal-firmware"},
229 U_BOOT_DRIVER(zynqmp_firmware) = {
230 .id = UCLASS_FIRMWARE,
231 .name = "zynqmp_firmware",
232 .of_match = zynqmp_firmware_ids,