Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Xilinx Zynq MPSoC Firmware driver |
| 4 | * |
| 5 | * Copyright (C) 2018-2019 Xilinx, Inc. |
| 6 | */ |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 7 | |
Michal Simek | 58ba267 | 2021-11-18 13:00:02 +0100 | [diff] [blame] | 8 | #include <cpu_func.h> |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 9 | #include <dm.h> |
Tanmay Shah | a7c0d3f | 2023-12-04 13:56:19 -0800 | [diff] [blame] | 10 | #include <dm/device_compat.h> |
Michal Simek | 0fd9f36 | 2022-02-07 10:27:37 +0100 | [diff] [blame] | 11 | #include <dm/lists.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 13 | #include <zynqmp_firmware.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 14 | #include <asm/cache.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 15 | #include <asm/ptrace.h> |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 16 | |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 17 | #if defined(CONFIG_ZYNQMP_IPI) |
| 18 | #include <mailbox.h> |
| 19 | #include <asm/arch/sys_proto.h> |
| 20 | |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 21 | #define PMUFW_PAYLOAD_ARG_CNT 8 |
| 22 | |
Michal Simek | 5f42112 | 2020-04-27 11:51:40 +0200 | [diff] [blame] | 23 | #define XST_PM_NO_ACCESS 2002L |
Michal Simek | 0ce829f | 2022-01-14 13:25:37 +0100 | [diff] [blame] | 24 | #define XST_PM_ALREADY_CONFIGURED 2009L |
Michal Simek | 5f42112 | 2020-04-27 11:51:40 +0200 | [diff] [blame] | 25 | |
Stefan Herbrechtsmeier | 43358c8 | 2023-05-23 14:42:14 +0200 | [diff] [blame] | 26 | static struct zynqmp_power { |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 27 | struct mbox_chan tx_chan; |
| 28 | struct mbox_chan rx_chan; |
Stefan Herbrechtsmeier | 43358c8 | 2023-05-23 14:42:14 +0200 | [diff] [blame] | 29 | } zynqmp_power __section(".data"); |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 30 | |
Michal Simek | 783e74c | 2022-01-14 13:25:35 +0100 | [diff] [blame] | 31 | #define NODE_ID_LOCATION 5 |
| 32 | |
| 33 | static unsigned int xpm_configobject[] = { |
| 34 | /**********************************************************************/ |
| 35 | /* HEADER */ |
| 36 | 2, /* Number of remaining words in the header */ |
| 37 | 1, /* Number of sections included in config object */ |
| 38 | PM_CONFIG_OBJECT_TYPE_OVERLAY, /* Type of Config object as overlay */ |
| 39 | /**********************************************************************/ |
| 40 | /* SLAVE SECTION */ |
| 41 | |
| 42 | PM_CONFIG_SLAVE_SECTION_ID, /* Section ID */ |
| 43 | 1, /* Number of slaves */ |
| 44 | |
| 45 | 0, /* Node ID which will be changed below */ |
| 46 | PM_SLAVE_FLAG_IS_SHAREABLE, |
| 47 | PM_CONFIG_IPI_PSU_CORTEXA53_0_MASK | |
| 48 | PM_CONFIG_IPI_PSU_CORTEXR5_0_MASK | |
| 49 | PM_CONFIG_IPI_PSU_CORTEXR5_1_MASK, /* IPI Mask */ |
| 50 | }; |
| 51 | |
Michal Simek | 07168c6 | 2022-01-14 13:25:38 +0100 | [diff] [blame] | 52 | static unsigned int xpm_configobject_close[] = { |
| 53 | /**********************************************************************/ |
| 54 | /* HEADER */ |
| 55 | 2, /* Number of remaining words in the header */ |
| 56 | 1, /* Number of sections included in config object */ |
| 57 | PM_CONFIG_OBJECT_TYPE_OVERLAY, /* Type of Config object as overlay */ |
| 58 | /**********************************************************************/ |
| 59 | /* SET CONFIG SECTION */ |
| 60 | PM_CONFIG_SET_CONFIG_SECTION_ID, |
| 61 | 0U, /* Loading permission to Overlay config object */ |
| 62 | }; |
| 63 | |
| 64 | int zynqmp_pmufw_config_close(void) |
| 65 | { |
Stefan Herbrechtsmeier | c4c1410 | 2023-05-23 14:42:13 +0200 | [diff] [blame] | 66 | return zynqmp_pmufw_load_config_object(xpm_configobject_close, |
| 67 | sizeof(xpm_configobject_close)); |
Michal Simek | 07168c6 | 2022-01-14 13:25:38 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Michal Simek | 783e74c | 2022-01-14 13:25:35 +0100 | [diff] [blame] | 70 | int zynqmp_pmufw_node(u32 id) |
| 71 | { |
Stefan Herbrechtsmeier | c4c1410 | 2023-05-23 14:42:13 +0200 | [diff] [blame] | 72 | static bool check = true; |
| 73 | static bool permission = true; |
| 74 | |
| 75 | if (check) { |
| 76 | check = false; |
Ashok Reddy Soma | a3e5db2 | 2022-07-22 02:46:55 -0600 | [diff] [blame] | 77 | |
Stefan Herbrechtsmeier | c4c1410 | 2023-05-23 14:42:13 +0200 | [diff] [blame] | 78 | if (zynqmp_pmufw_node(NODE_OCM_BANK_0) == -EACCES) { |
| 79 | printf("PMUFW: No permission to change config object\n"); |
| 80 | permission = false; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (!permission) |
Ashok Reddy Soma | a3e5db2 | 2022-07-22 02:46:55 -0600 | [diff] [blame] | 85 | return 0; |
| 86 | |
Michal Simek | 783e74c | 2022-01-14 13:25:35 +0100 | [diff] [blame] | 87 | /* Record power domain id */ |
| 88 | xpm_configobject[NODE_ID_LOCATION] = id; |
| 89 | |
Stefan Herbrechtsmeier | c4c1410 | 2023-05-23 14:42:13 +0200 | [diff] [blame] | 90 | return zynqmp_pmufw_load_config_object(xpm_configobject, |
| 91 | sizeof(xpm_configobject)); |
Michal Simek | 783e74c | 2022-01-14 13:25:35 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Stefan Herbrechtsmeier | 44b9f79 | 2022-06-20 18:36:37 +0200 | [diff] [blame] | 94 | static int do_pm_probe(void) |
| 95 | { |
| 96 | struct udevice *dev; |
| 97 | int ret; |
| 98 | |
| 99 | ret = uclass_get_device_by_driver(UCLASS_FIRMWARE, |
| 100 | DM_DRIVER_GET(zynqmp_power), |
| 101 | &dev); |
| 102 | if (ret) |
| 103 | debug("%s: Probing device failed: %d\n", __func__, ret); |
| 104 | |
| 105 | return ret; |
| 106 | } |
| 107 | |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 108 | static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen) |
| 109 | { |
| 110 | struct zynqmp_ipi_msg msg; |
| 111 | int ret; |
Michal Simek | ae655fb | 2021-10-15 16:57:39 +0200 | [diff] [blame] | 112 | u32 buffer[PAYLOAD_ARG_CNT]; |
| 113 | |
| 114 | if (!res) |
| 115 | res = buffer; |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 116 | |
| 117 | if (req_len > PMUFW_PAYLOAD_ARG_CNT || |
| 118 | res_maxlen > PMUFW_PAYLOAD_ARG_CNT) |
| 119 | return -EINVAL; |
| 120 | |
Stefan Herbrechtsmeier | 44b9f79 | 2022-06-20 18:36:37 +0200 | [diff] [blame] | 121 | if (!(zynqmp_power.tx_chan.dev) || !(zynqmp_power.rx_chan.dev)) { |
| 122 | ret = do_pm_probe(); |
| 123 | if (ret) |
| 124 | return ret; |
| 125 | } |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 126 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 127 | debug("%s, Sending IPI message with ID: 0x%0x\n", __func__, req[0]); |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 128 | msg.buf = (u32 *)req; |
| 129 | msg.len = req_len; |
| 130 | ret = mbox_send(&zynqmp_power.tx_chan, &msg); |
| 131 | if (ret) { |
| 132 | debug("%s: Sending message failed\n", __func__); |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | msg.buf = res; |
| 137 | msg.len = res_maxlen; |
| 138 | ret = mbox_recv(&zynqmp_power.rx_chan, &msg, 100); |
| 139 | if (ret) |
| 140 | debug("%s: Receiving message failed\n", __func__); |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | unsigned int zynqmp_firmware_version(void) |
| 146 | { |
| 147 | int ret; |
| 148 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
| 149 | static u32 pm_api_version = ZYNQMP_PM_VERSION_INVALID; |
| 150 | |
| 151 | /* |
| 152 | * Get PMU version only once and later |
| 153 | * just return stored values instead of |
| 154 | * asking PMUFW again. |
| 155 | **/ |
| 156 | if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) { |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 157 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 158 | ret = xilinx_pm_request(PM_GET_API_VERSION, 0, 0, 0, 0, |
| 159 | ret_payload); |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 160 | if (ret) |
| 161 | panic("PMUFW is not found - Please load it!\n"); |
| 162 | |
| 163 | pm_api_version = ret_payload[1]; |
| 164 | if (pm_api_version < ZYNQMP_PM_VERSION) |
| 165 | panic("PMUFW version error. Expected: v%d.%d\n", |
| 166 | ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR); |
| 167 | } |
| 168 | |
| 169 | return pm_api_version; |
| 170 | }; |
| 171 | |
T Karthik Reddy | 22a8bf8 | 2022-03-30 11:07:57 +0200 | [diff] [blame] | 172 | int zynqmp_pm_set_gem_config(u32 node, enum pm_gem_config_type config, u32 value) |
| 173 | { |
| 174 | int ret; |
| 175 | |
| 176 | ret = xilinx_pm_request(PM_IOCTL, node, IOCTL_SET_GEM_CONFIG, |
| 177 | config, value, NULL); |
| 178 | if (ret) |
| 179 | printf("%s: node %d: set_gem_config %d failed\n", |
| 180 | __func__, node, config); |
| 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |
Ashok Reddy Soma | 87cdd35 | 2022-02-23 15:36:03 +0100 | [diff] [blame] | 185 | int zynqmp_pm_set_sd_config(u32 node, enum pm_sd_config_type config, u32 value) |
| 186 | { |
| 187 | int ret; |
| 188 | |
| 189 | ret = xilinx_pm_request(PM_IOCTL, node, IOCTL_SET_SD_CONFIG, |
| 190 | config, value, NULL); |
| 191 | if (ret) |
| 192 | printf("%s: node %d: set_sd_config %d failed\n", |
| 193 | __func__, node, config); |
| 194 | |
| 195 | return ret; |
| 196 | } |
| 197 | |
Ashok Reddy Soma | 40bf26b | 2023-08-10 23:48:27 -0600 | [diff] [blame] | 198 | int zynqmp_pm_feature(const u32 api_id) |
| 199 | { |
| 200 | int ret; |
| 201 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
| 202 | |
| 203 | /* Check feature check API version */ |
| 204 | ret = xilinx_pm_request(PM_FEATURE_CHECK, api_id, 0, 0, 0, |
| 205 | ret_payload); |
Venkatesh Yadav Abbarapu | 94454fc | 2023-10-11 08:26:47 +0530 | [diff] [blame] | 206 | if (ret) |
| 207 | return ret; |
Ashok Reddy Soma | 40bf26b | 2023-08-10 23:48:27 -0600 | [diff] [blame] | 208 | |
| 209 | /* Return feature check version */ |
| 210 | return ret_payload[1] & FIRMWARE_VERSION_MASK; |
| 211 | } |
| 212 | |
Ashok Reddy Soma | 87cdd35 | 2022-02-23 15:36:03 +0100 | [diff] [blame] | 213 | int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id) |
| 214 | { |
| 215 | int ret; |
| 216 | u32 *bit_mask; |
| 217 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
| 218 | |
| 219 | /* Input arguments validation */ |
| 220 | if (id >= 64 || (api_id != PM_IOCTL && api_id != PM_QUERY_DATA)) |
| 221 | return -EINVAL; |
| 222 | |
| 223 | /* Check feature check API version */ |
| 224 | ret = xilinx_pm_request(PM_FEATURE_CHECK, PM_FEATURE_CHECK, 0, 0, 0, |
| 225 | ret_payload); |
| 226 | if (ret) |
| 227 | return ret; |
| 228 | |
| 229 | /* Check if feature check version 2 is supported or not */ |
| 230 | if ((ret_payload[1] & FIRMWARE_VERSION_MASK) == PM_API_VERSION_2) { |
| 231 | /* |
| 232 | * Call feature check for IOCTL/QUERY API to get IOCTL ID or |
| 233 | * QUERY ID feature status. |
| 234 | */ |
| 235 | |
| 236 | ret = xilinx_pm_request(PM_FEATURE_CHECK, api_id, 0, 0, 0, |
| 237 | ret_payload); |
| 238 | if (ret) |
| 239 | return ret; |
| 240 | |
| 241 | bit_mask = &ret_payload[2]; |
| 242 | if ((bit_mask[(id / 32)] & BIT((id % 32))) == 0) |
| 243 | return -EOPNOTSUPP; |
| 244 | } else { |
| 245 | return -ENODATA; |
| 246 | } |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 251 | /** |
| 252 | * Send a configuration object to the PMU firmware. |
| 253 | * |
| 254 | * @cfg_obj: Pointer to the configuration object |
| 255 | * @size: Size of @cfg_obj in bytes |
Stefan Herbrechtsmeier | 764301a | 2023-05-23 14:42:10 +0200 | [diff] [blame] | 256 | * Return: 0 on success otherwise negative errno. |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 257 | */ |
Ashok Reddy Soma | 406bc8a | 2022-07-22 02:46:54 -0600 | [diff] [blame] | 258 | int zynqmp_pmufw_load_config_object(const void *cfg_obj, size_t size) |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 259 | { |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 260 | int err; |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 261 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 262 | |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 263 | if (IS_ENABLED(CONFIG_XPL_BUILD)) |
Michal Simek | 957b248 | 2022-01-14 13:25:36 +0100 | [diff] [blame] | 264 | printf("Loading new PMUFW cfg obj (%ld bytes)\n", size); |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 265 | |
Michal Simek | 58ba267 | 2021-11-18 13:00:02 +0100 | [diff] [blame] | 266 | flush_dcache_range((ulong)cfg_obj, (ulong)(cfg_obj + size)); |
| 267 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 268 | err = xilinx_pm_request(PM_SET_CONFIGURATION, (u32)(u64)cfg_obj, 0, 0, |
| 269 | 0, ret_payload); |
Michal Simek | 5f42112 | 2020-04-27 11:51:40 +0200 | [diff] [blame] | 270 | if (err == XST_PM_NO_ACCESS) { |
Ashok Reddy Soma | 406bc8a | 2022-07-22 02:46:54 -0600 | [diff] [blame] | 271 | return -EACCES; |
Michal Simek | 5f42112 | 2020-04-27 11:51:40 +0200 | [diff] [blame] | 272 | } |
| 273 | |
Michal Simek | 0ce829f | 2022-01-14 13:25:37 +0100 | [diff] [blame] | 274 | if (err == XST_PM_ALREADY_CONFIGURED) { |
| 275 | debug("PMUFW Node is already configured\n"); |
Ashok Reddy Soma | 406bc8a | 2022-07-22 02:46:54 -0600 | [diff] [blame] | 276 | return -ENODEV; |
Michal Simek | 0ce829f | 2022-01-14 13:25:37 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 279 | if (err) |
Michal Simek | 5f42112 | 2020-04-27 11:51:40 +0200 | [diff] [blame] | 280 | printf("Cannot load PMUFW configuration object (%d)\n", err); |
| 281 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 282 | if (ret_payload[0]) |
| 283 | printf("PMUFW returned 0x%08x status!\n", ret_payload[0]); |
Michal Simek | 5f42112 | 2020-04-27 11:51:40 +0200 | [diff] [blame] | 284 | |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 285 | if ((err || ret_payload[0]) && IS_ENABLED(CONFIG_XPL_BUILD)) |
Michal Simek | 5f42112 | 2020-04-27 11:51:40 +0200 | [diff] [blame] | 286 | panic("PMUFW config object loading failed in EL3\n"); |
Ashok Reddy Soma | 406bc8a | 2022-07-22 02:46:54 -0600 | [diff] [blame] | 287 | |
| 288 | return 0; |
Michal Simek | a95f0d9 | 2019-09-27 14:20:00 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 291 | static int zynqmp_power_probe(struct udevice *dev) |
| 292 | { |
Tanmay Shah | a7c0d3f | 2023-12-04 13:56:19 -0800 | [diff] [blame] | 293 | struct udevice *ipi_dev; |
| 294 | ofnode ipi_node; |
Michal Simek | 8ece072 | 2019-10-10 11:26:16 +0200 | [diff] [blame] | 295 | int ret; |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 296 | |
| 297 | debug("%s, (dev=%p)\n", __func__, dev); |
| 298 | |
Tanmay Shah | a7c0d3f | 2023-12-04 13:56:19 -0800 | [diff] [blame] | 299 | /* |
| 300 | * Probe all IPI parent node driver. It is important to have IPI |
| 301 | * devices available when requested by mbox_get_by* API. |
| 302 | * If IPI device isn't available, then mailbox request fails and |
| 303 | * that causes system boot failure. |
| 304 | * To avoid this make sure all IPI parent drivers are probed here, |
| 305 | * and IPI parent driver binds each child node to mailbox driver. |
| 306 | * This way mbox_get_by_* API will have correct mailbox device |
| 307 | * driver probed. |
| 308 | */ |
| 309 | ofnode_for_each_compatible_node(ipi_node, "xlnx,zynqmp-ipi-mailbox") { |
| 310 | ret = uclass_get_device_by_ofnode(UCLASS_NOP, ipi_node, &ipi_dev); |
| 311 | if (ret) { |
| 312 | dev_err(dev, "failed to get IPI device from node %s\n", |
| 313 | ofnode_get_name(ipi_node)); |
| 314 | return ret; |
| 315 | } |
| 316 | } |
| 317 | |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 318 | ret = mbox_get_by_name(dev, "tx", &zynqmp_power.tx_chan); |
| 319 | if (ret) { |
Michal Simek | 8ece072 | 2019-10-10 11:26:16 +0200 | [diff] [blame] | 320 | debug("%s: Cannot find tx mailbox\n", __func__); |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | ret = mbox_get_by_name(dev, "rx", &zynqmp_power.rx_chan); |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 325 | if (ret) { |
Michal Simek | 8ece072 | 2019-10-10 11:26:16 +0200 | [diff] [blame] | 326 | debug("%s: Cannot find rx mailbox\n", __func__); |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 327 | return ret; |
| 328 | } |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 329 | |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 330 | ret = zynqmp_firmware_version(); |
| 331 | printf("PMUFW:\tv%d.%d\n", |
| 332 | ret >> ZYNQMP_PM_VERSION_MAJOR_SHIFT, |
| 333 | ret & ZYNQMP_PM_VERSION_MINOR_MASK); |
| 334 | |
| 335 | return 0; |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | static const struct udevice_id zynqmp_power_ids[] = { |
| 339 | { .compatible = "xlnx,zynqmp-power" }, |
| 340 | { } |
| 341 | }; |
| 342 | |
| 343 | U_BOOT_DRIVER(zynqmp_power) = { |
| 344 | .name = "zynqmp_power", |
| 345 | .id = UCLASS_FIRMWARE, |
| 346 | .of_match = zynqmp_power_ids, |
| 347 | .probe = zynqmp_power_probe, |
| 348 | }; |
| 349 | #endif |
| 350 | |
Michal Simek | 4c3de37 | 2019-10-04 15:35:45 +0200 | [diff] [blame] | 351 | int __maybe_unused xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, |
| 352 | u32 arg3, u32 *ret_payload) |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 353 | { |
Michal Simek | a198214 | 2023-06-01 13:34:34 +0200 | [diff] [blame] | 354 | debug("%s at EL%d, API ID: 0x%0x, 0x%0x, 0x%0x, 0x%0x, 0x%0x\n", |
| 355 | __func__, current_el(), api_id, arg0, arg1, arg2, arg3); |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 356 | |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 357 | if (IS_ENABLED(CONFIG_XPL_BUILD) || current_el() == 3) { |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 358 | #if defined(CONFIG_ZYNQMP_IPI) |
| 359 | /* |
| 360 | * Use fixed payload and arg size as the EL2 call. The firmware |
| 361 | * is capable to handle PMUFW_PAYLOAD_ARG_CNT bytes but the |
| 362 | * firmware API is limited by the SMC call size |
| 363 | */ |
| 364 | u32 regs[] = {api_id, arg0, arg1, arg2, arg3}; |
Michal Simek | 577385a | 2021-10-15 16:57:38 +0200 | [diff] [blame] | 365 | int ret; |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 366 | |
Michal Simek | f33d95b | 2020-10-05 15:23:28 +0200 | [diff] [blame] | 367 | if (api_id == PM_FPGA_LOAD) { |
| 368 | /* Swap addr_hi/low because of incompatibility */ |
| 369 | u32 temp = regs[1]; |
| 370 | |
| 371 | regs[1] = regs[2]; |
| 372 | regs[2] = temp; |
| 373 | } |
| 374 | |
Michal Simek | 577385a | 2021-10-15 16:57:38 +0200 | [diff] [blame] | 375 | ret = ipi_req(regs, PAYLOAD_ARG_CNT, ret_payload, |
| 376 | PAYLOAD_ARG_CNT); |
| 377 | if (ret) |
| 378 | return ret; |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 379 | #else |
Michal Simek | 4ca6e95 | 2019-10-10 11:09:15 +0200 | [diff] [blame] | 380 | return -EPERM; |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 381 | #endif |
| 382 | } else { |
| 383 | /* |
| 384 | * Added SIP service call Function Identifier |
| 385 | * Make sure to stay in x0 register |
| 386 | */ |
| 387 | struct pt_regs regs; |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 388 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 389 | regs.regs[0] = PM_SIP_SVC | api_id; |
| 390 | regs.regs[1] = ((u64)arg1 << 32) | arg0; |
| 391 | regs.regs[2] = ((u64)arg3 << 32) | arg2; |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 392 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 393 | smc_call(®s); |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 394 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 395 | if (ret_payload) { |
| 396 | ret_payload[0] = (u32)regs.regs[0]; |
| 397 | ret_payload[1] = upper_32_bits(regs.regs[0]); |
| 398 | ret_payload[2] = (u32)regs.regs[1]; |
| 399 | ret_payload[3] = upper_32_bits(regs.regs[1]); |
| 400 | ret_payload[4] = (u32)regs.regs[2]; |
| 401 | } |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 402 | |
Ibai Erkiaga | 22712ea | 2020-08-04 23:17:27 +0100 | [diff] [blame] | 403 | } |
| 404 | return (ret_payload) ? ret_payload[0] : 0; |
Michal Simek | 81efd2a | 2019-10-04 15:45:29 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 407 | static const struct udevice_id zynqmp_firmware_ids[] = { |
| 408 | { .compatible = "xlnx,zynqmp-firmware" }, |
Siva Durga Prasad Paladugu | f7a7120 | 2019-06-23 12:24:57 +0530 | [diff] [blame] | 409 | { .compatible = "xlnx,versal-firmware"}, |
Jay Buddhabhatti | bc62eb2 | 2022-09-19 14:21:06 +0200 | [diff] [blame] | 410 | { .compatible = "xlnx,versal-net-firmware"}, |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 411 | { } |
| 412 | }; |
| 413 | |
Michal Simek | 0fd9f36 | 2022-02-07 10:27:37 +0100 | [diff] [blame] | 414 | static int zynqmp_firmware_bind(struct udevice *dev) |
| 415 | { |
| 416 | int ret; |
| 417 | struct udevice *child; |
| 418 | |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 419 | if ((IS_ENABLED(CONFIG_XPL_BUILD) && |
Michal Simek | 259af93 | 2022-02-28 17:13:15 +0100 | [diff] [blame] | 420 | IS_ENABLED(CONFIG_SPL_POWER_DOMAIN) && |
| 421 | IS_ENABLED(CONFIG_ZYNQMP_POWER_DOMAIN)) || |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 422 | (!IS_ENABLED(CONFIG_XPL_BUILD) && |
Michal Simek | 259af93 | 2022-02-28 17:13:15 +0100 | [diff] [blame] | 423 | IS_ENABLED(CONFIG_ZYNQMP_POWER_DOMAIN))) { |
Michal Simek | 0fd9f36 | 2022-02-07 10:27:37 +0100 | [diff] [blame] | 424 | ret = device_bind_driver_to_node(dev, "zynqmp_power_domain", |
| 425 | "zynqmp_power_domain", |
| 426 | dev_ofnode(dev), &child); |
| 427 | if (ret) { |
| 428 | printf("zynqmp power domain driver is not bound: %d\n", ret); |
| 429 | return ret; |
| 430 | } |
| 431 | } |
| 432 | |
Stefan Herbrechtsmeier | 00e6156 | 2023-05-23 14:42:11 +0200 | [diff] [blame] | 433 | return 0; |
Michal Simek | 0fd9f36 | 2022-02-07 10:27:37 +0100 | [diff] [blame] | 434 | } |
| 435 | |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 436 | U_BOOT_DRIVER(zynqmp_firmware) = { |
| 437 | .id = UCLASS_FIRMWARE, |
Michal Simek | 3309308 | 2020-01-07 08:50:34 +0100 | [diff] [blame] | 438 | .name = "zynqmp_firmware", |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 439 | .of_match = zynqmp_firmware_ids, |
Michal Simek | 0fd9f36 | 2022-02-07 10:27:37 +0100 | [diff] [blame] | 440 | .bind = zynqmp_firmware_bind, |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 441 | }; |