1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx Zynq MPSoC Firmware driver
5 * Copyright (C) 2018-2019 Xilinx, Inc.
10 #include <zynqmp_firmware.h>
12 #if defined(CONFIG_ZYNQMP_IPI)
14 #include <asm/arch/sys_proto.h>
16 #define PMUFW_PAYLOAD_ARG_CNT 8
19 struct mbox_chan tx_chan;
20 struct mbox_chan rx_chan;
23 static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
25 struct zynqmp_ipi_msg msg;
28 if (req_len > PMUFW_PAYLOAD_ARG_CNT ||
29 res_maxlen > PMUFW_PAYLOAD_ARG_CNT)
32 if (!(zynqmp_power.tx_chan.dev) || !(&zynqmp_power.rx_chan.dev))
37 ret = mbox_send(&zynqmp_power.tx_chan, &msg);
39 debug("%s: Sending message failed\n", __func__);
45 ret = mbox_recv(&zynqmp_power.rx_chan, &msg, 100);
47 debug("%s: Receiving message failed\n", __func__);
52 static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
54 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3)
55 return ipi_req(req, req_len, res, res_maxlen);
57 return xilinx_pm_request(req[0], 0, 0, 0, 0, res);
60 unsigned int zynqmp_firmware_version(void)
63 u32 ret_payload[PAYLOAD_ARG_CNT];
64 static u32 pm_api_version = ZYNQMP_PM_VERSION_INVALID;
67 * Get PMU version only once and later
68 * just return stored values instead of
71 if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) {
72 const u32 request[] = { PM_GET_API_VERSION };
74 ret = send_req(request, ARRAY_SIZE(request), ret_payload, 2);
76 panic("PMUFW is not found - Please load it!\n");
78 pm_api_version = ret_payload[1];
79 if (pm_api_version < ZYNQMP_PM_VERSION)
80 panic("PMUFW version error. Expected: v%d.%d\n",
81 ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR);
84 return pm_api_version;
88 * Send a configuration object to the PMU firmware.
90 * @cfg_obj: Pointer to the configuration object
91 * @size: Size of @cfg_obj in bytes
93 void zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size)
95 const u32 request[] = {
102 printf("Loading new PMUFW cfg obj (%ld bytes)\n", size);
104 err = send_req(request, ARRAY_SIZE(request), &response, 1);
106 panic("Cannot load PMUFW configuration object (%d)\n", err);
108 panic("PMUFW returned 0x%08x status!\n", response);
111 static int zynqmp_power_probe(struct udevice *dev)
115 debug("%s, (dev=%p)\n", __func__, dev);
117 ret = mbox_get_by_name(dev, "tx", &zynqmp_power.tx_chan);
119 debug("%s: Cannot find tx mailbox\n", __func__);
123 ret = mbox_get_by_name(dev, "rx", &zynqmp_power.rx_chan);
125 debug("%s: Cannot find rx mailbox\n", __func__);
129 ret = zynqmp_firmware_version();
130 printf("PMUFW:\tv%d.%d\n",
131 ret >> ZYNQMP_PM_VERSION_MAJOR_SHIFT,
132 ret & ZYNQMP_PM_VERSION_MINOR_MASK);
137 static const struct udevice_id zynqmp_power_ids[] = {
138 { .compatible = "xlnx,zynqmp-power" },
142 U_BOOT_DRIVER(zynqmp_power) = {
143 .name = "zynqmp_power",
144 .id = UCLASS_FIRMWARE,
145 .of_match = zynqmp_power_ids,
146 .probe = zynqmp_power_probe,
150 int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
151 u32 arg3, u32 *ret_payload)
154 * Added SIP service call Function Identifier
155 * Make sure to stay in x0 register
159 if (current_el() == 3) {
160 printf("%s: Can't call SMC from EL3 context\n", __func__);
164 regs.regs[0] = PM_SIP_SVC | api_id;
165 regs.regs[1] = ((u64)arg1 << 32) | arg0;
166 regs.regs[2] = ((u64)arg3 << 32) | arg2;
171 ret_payload[0] = (u32)regs.regs[0];
172 ret_payload[1] = upper_32_bits(regs.regs[0]);
173 ret_payload[2] = (u32)regs.regs[1];
174 ret_payload[3] = upper_32_bits(regs.regs[1]);
175 ret_payload[4] = (u32)regs.regs[2];
181 static const struct udevice_id zynqmp_firmware_ids[] = {
182 { .compatible = "xlnx,zynqmp-firmware" },
183 { .compatible = "xlnx,versal-firmware"},
187 U_BOOT_DRIVER(zynqmp_firmware) = {
188 .id = UCLASS_FIRMWARE,
189 .name = "zynqmp-firmware",
190 .of_match = zynqmp_firmware_ids,