1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx Zynq MPSoC Firmware driver
5 * Copyright (C) 2018-2019 Xilinx, Inc.
11 #include <zynqmp_firmware.h>
12 #include <asm/cache.h>
13 #include <asm/ptrace.h>
15 #if defined(CONFIG_ZYNQMP_IPI)
17 #include <asm/arch/sys_proto.h>
19 #define PMUFW_PAYLOAD_ARG_CNT 8
21 #define XST_PM_NO_ACCESS 2002L
24 struct mbox_chan tx_chan;
25 struct mbox_chan rx_chan;
28 static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
30 struct zynqmp_ipi_msg msg;
33 if (req_len > PMUFW_PAYLOAD_ARG_CNT ||
34 res_maxlen > PMUFW_PAYLOAD_ARG_CNT)
37 if (!(zynqmp_power.tx_chan.dev) || !(&zynqmp_power.rx_chan.dev))
42 ret = mbox_send(&zynqmp_power.tx_chan, &msg);
44 debug("%s: Sending message failed\n", __func__);
50 ret = mbox_recv(&zynqmp_power.rx_chan, &msg, 100);
52 debug("%s: Receiving message failed\n", __func__);
57 static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
59 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3)
60 return ipi_req(req, req_len, res, res_maxlen);
62 return xilinx_pm_request(req[0], 0, 0, 0, 0, res);
65 unsigned int zynqmp_firmware_version(void)
68 u32 ret_payload[PAYLOAD_ARG_CNT];
69 static u32 pm_api_version = ZYNQMP_PM_VERSION_INVALID;
72 * Get PMU version only once and later
73 * just return stored values instead of
76 if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) {
77 const u32 request[] = { PM_GET_API_VERSION };
79 ret = send_req(request, ARRAY_SIZE(request), ret_payload, 2);
81 panic("PMUFW is not found - Please load it!\n");
83 pm_api_version = ret_payload[1];
84 if (pm_api_version < ZYNQMP_PM_VERSION)
85 panic("PMUFW version error. Expected: v%d.%d\n",
86 ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR);
89 return pm_api_version;
93 * Send a configuration object to the PMU firmware.
95 * @cfg_obj: Pointer to the configuration object
96 * @size: Size of @cfg_obj in bytes
98 void zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size)
100 const u32 request[] = {
101 PM_SET_CONFIGURATION,
107 printf("Loading new PMUFW cfg obj (%ld bytes)\n", size);
109 err = send_req(request, ARRAY_SIZE(request), &response, 1);
110 if (err == XST_PM_NO_ACCESS) {
111 printf("PMUFW no permission to change config object\n");
116 printf("Cannot load PMUFW configuration object (%d)\n", err);
119 printf("PMUFW returned 0x%08x status!\n", response);
121 if ((err || response) && IS_ENABLED(CONFIG_SPL_BUILD))
122 panic("PMUFW config object loading failed in EL3\n");
125 static int zynqmp_power_probe(struct udevice *dev)
129 debug("%s, (dev=%p)\n", __func__, dev);
131 ret = mbox_get_by_name(dev, "tx", &zynqmp_power.tx_chan);
133 debug("%s: Cannot find tx mailbox\n", __func__);
137 ret = mbox_get_by_name(dev, "rx", &zynqmp_power.rx_chan);
139 debug("%s: Cannot find rx mailbox\n", __func__);
143 ret = zynqmp_firmware_version();
144 printf("PMUFW:\tv%d.%d\n",
145 ret >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
146 ret & ZYNQMP_PM_VERSION_MINOR_MASK);
151 static const struct udevice_id zynqmp_power_ids[] = {
152 { .compatible = "xlnx,zynqmp-power" },
156 U_BOOT_DRIVER(zynqmp_power) = {
157 .name = "zynqmp_power",
158 .id = UCLASS_FIRMWARE,
159 .of_match = zynqmp_power_ids,
160 .probe = zynqmp_power_probe,
164 int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
165 u32 arg3, u32 *ret_payload)
168 * Added SIP service call Function Identifier
169 * Make sure to stay in x0 register
173 if (current_el() == 3) {
174 printf("%s: Can't call SMC from EL3 context\n", __func__);
178 regs.regs[0] = PM_SIP_SVC | api_id;
179 regs.regs[1] = ((u64)arg1 << 32) | arg0;
180 regs.regs[2] = ((u64)arg3 << 32) | arg2;
185 ret_payload[0] = (u32)regs.regs[0];
186 ret_payload[1] = upper_32_bits(regs.regs[0]);
187 ret_payload[2] = (u32)regs.regs[1];
188 ret_payload[3] = upper_32_bits(regs.regs[1]);
189 ret_payload[4] = (u32)regs.regs[2];
195 static const struct udevice_id zynqmp_firmware_ids[] = {
196 { .compatible = "xlnx,zynqmp-firmware" },
197 { .compatible = "xlnx,versal-firmware"},
201 U_BOOT_DRIVER(zynqmp_firmware) = {
202 .id = UCLASS_FIRMWARE,
203 .name = "zynqmp-firmware",
204 .of_match = zynqmp_firmware_ids,