blob: dea58b5581022148190ad5693aafad197f935809 [file] [log] [blame]
Rajan Vaja833be322019-02-15 04:45:32 -08001// SPDX-License-Identifier: GPL-2.0
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +02002/*
3 * Xilinx Zynq MPSoC Firmware driver
4 *
5 * Copyright (C) 2018-2019 Xilinx, Inc.
6 */
Rajan Vaja833be322019-02-15 04:45:32 -08007
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +02008#include <common.h>
Rajan Vaja833be322019-02-15 04:45:32 -08009#include <dm.h>
Michal Simek81efd2a2019-10-04 15:45:29 +020010#include <zynqmp_firmware.h>
Rajan Vaja833be322019-02-15 04:45:32 -080011
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +020012#if defined(CONFIG_ZYNQMP_IPI)
13#include <mailbox.h>
14#include <asm/arch/sys_proto.h>
15
Ibai Erkiaga99b2c282019-09-27 11:37:00 +010016#define PMUFW_PAYLOAD_ARG_CNT 8
17
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +020018struct zynqmp_power {
19 struct mbox_chan tx_chan;
20 struct mbox_chan rx_chan;
21} zynqmp_power;
22
Ibai Erkiaga99b2c282019-09-27 11:37:00 +010023static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
24{
25 struct zynqmp_ipi_msg msg;
26 int ret;
27
28 if (req_len > PMUFW_PAYLOAD_ARG_CNT ||
29 res_maxlen > PMUFW_PAYLOAD_ARG_CNT)
30 return -EINVAL;
31
32 if (!(zynqmp_power.tx_chan.dev) || !(&zynqmp_power.rx_chan.dev))
33 return -EINVAL;
34
35 msg.buf = (u32 *)req;
36 msg.len = req_len;
37 ret = mbox_send(&zynqmp_power.tx_chan, &msg);
38 if (ret) {
39 debug("%s: Sending message failed\n", __func__);
40 return ret;
41 }
42
43 msg.buf = res;
44 msg.len = res_maxlen;
45 ret = mbox_recv(&zynqmp_power.rx_chan, &msg, 100);
46 if (ret)
47 debug("%s: Receiving message failed\n", __func__);
48
49 return ret;
50}
51
Michal Simekd9d98eb72019-09-27 14:08:41 +020052static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen)
53{
54 if (IS_ENABLED(CONFIG_SPL_BUILD))
55 return ipi_req(req, req_len, res, res_maxlen);
56
Michal Simek4c3de372019-10-04 15:35:45 +020057 return xilinx_pm_request(req[0], 0, 0, 0, 0, res);
Michal Simekd9d98eb72019-09-27 14:08:41 +020058}
59
Ibai Erkiaga99b2c282019-09-27 11:37:00 +010060unsigned int zynqmp_firmware_version(void)
61{
62 int ret;
63 u32 ret_payload[PAYLOAD_ARG_CNT];
64 static u32 pm_api_version = ZYNQMP_PM_VERSION_INVALID;
65
66 /*
67 * Get PMU version only once and later
68 * just return stored values instead of
69 * asking PMUFW again.
70 **/
71 if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) {
Michal Simekd9d98eb72019-09-27 14:08:41 +020072 const u32 request[] = { PM_GET_API_VERSION };
Ibai Erkiaga99b2c282019-09-27 11:37:00 +010073
Michal Simekd9d98eb72019-09-27 14:08:41 +020074 ret = send_req(request, ARRAY_SIZE(request), ret_payload, 2);
Ibai Erkiaga99b2c282019-09-27 11:37:00 +010075 if (ret)
76 panic("PMUFW is not found - Please load it!\n");
77
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);
82 }
83
84 return pm_api_version;
85};
86
Michal Simeka95f0d92019-09-27 14:20:00 +020087/**
88 * Send a configuration object to the PMU firmware.
89 *
90 * @cfg_obj: Pointer to the configuration object
91 * @size: Size of @cfg_obj in bytes
92 */
93void zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size)
94{
95 const u32 request[] = {
96 PM_SET_CONFIGURATION,
97 (u32)((u64)cfg_obj)
98 };
99 u32 response;
100 int err;
101
102 printf("Loading new PMUFW cfg obj (%ld bytes)\n", size);
103
104 err = send_req(request, ARRAY_SIZE(request), &response, 1);
105 if (err)
106 panic("Cannot load PMUFW configuration object (%d)\n", err);
107 if (response != 0)
108 panic("PMUFW returned 0x%08x status!\n", response);
109}
110
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +0200111static int zynqmp_power_probe(struct udevice *dev)
112{
Michal Simek8ece0722019-10-10 11:26:16 +0200113 int ret;
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +0200114
115 debug("%s, (dev=%p)\n", __func__, dev);
116
117 ret = mbox_get_by_name(dev, "tx", &zynqmp_power.tx_chan);
118 if (ret) {
Michal Simek8ece0722019-10-10 11:26:16 +0200119 debug("%s: Cannot find tx mailbox\n", __func__);
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +0200120 return ret;
121 }
122
123 ret = mbox_get_by_name(dev, "rx", &zynqmp_power.rx_chan);
Ibai Erkiaga99b2c282019-09-27 11:37:00 +0100124 if (ret) {
Michal Simek8ece0722019-10-10 11:26:16 +0200125 debug("%s: Cannot find rx mailbox\n", __func__);
Ibai Erkiaga99b2c282019-09-27 11:37:00 +0100126 return ret;
127 }
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +0200128
Ibai Erkiaga99b2c282019-09-27 11:37:00 +0100129 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);
133
134 return 0;
Ibai Erkiagad47ed6f2019-09-27 12:51:41 +0200135};
136
137static const struct udevice_id zynqmp_power_ids[] = {
138 { .compatible = "xlnx,zynqmp-power" },
139 { }
140};
141
142U_BOOT_DRIVER(zynqmp_power) = {
143 .name = "zynqmp_power",
144 .id = UCLASS_FIRMWARE,
145 .of_match = zynqmp_power_ids,
146 .probe = zynqmp_power_probe,
147};
148#endif
149
Michal Simek4c3de372019-10-04 15:35:45 +0200150int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
151 u32 arg3, u32 *ret_payload)
Michal Simek81efd2a2019-10-04 15:45:29 +0200152{
153 /*
154 * Added SIP service call Function Identifier
155 * Make sure to stay in x0 register
156 */
157 struct pt_regs regs;
158
Michal Simek4ca6e952019-10-10 11:09:15 +0200159 if (current_el() == 3) {
160 printf("%s: Can't call SMC from EL3 context\n", __func__);
161 return -EPERM;
162 }
Michal Simek81efd2a2019-10-04 15:45:29 +0200163
Michal Simek4c3de372019-10-04 15:35:45 +0200164 regs.regs[0] = PM_SIP_SVC | api_id;
Michal Simek81efd2a2019-10-04 15:45:29 +0200165 regs.regs[1] = ((u64)arg1 << 32) | arg0;
166 regs.regs[2] = ((u64)arg3 << 32) | arg2;
167
168 smc_call(&regs);
169
170 if (ret_payload) {
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];
176 }
177
178 return regs.regs[0];
179}
180
Rajan Vaja833be322019-02-15 04:45:32 -0800181static const struct udevice_id zynqmp_firmware_ids[] = {
182 { .compatible = "xlnx,zynqmp-firmware" },
Siva Durga Prasad Paladuguf7a71202019-06-23 12:24:57 +0530183 { .compatible = "xlnx,versal-firmware"},
Rajan Vaja833be322019-02-15 04:45:32 -0800184 { }
185};
186
187U_BOOT_DRIVER(zynqmp_firmware) = {
188 .id = UCLASS_FIRMWARE,
189 .name = "zynqmp-firmware",
190 .probe = dm_scan_fdt_dev,
191 .of_match = zynqmp_firmware_ids,
192};