Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Texas Instruments System Control Interface Protocol Driver |
| 4 | * Based on drivers/firmware/ti_sci.c from Linux. |
| 5 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 6 | * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/ |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 7 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 8 | */ |
| 9 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 13 | #include <mailbox.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 15 | #include <dm/device.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 16 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 17 | #include <dm/devres.h> |
Andrew Davis | 1ed20d6 | 2024-04-02 11:09:07 -0500 | [diff] [blame] | 18 | #include <dm/lists.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 20 | #include <linux/compat.h> |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 21 | #include <linux/err.h> |
| 22 | #include <linux/soc/ti/k3-sec-proxy.h> |
| 23 | #include <linux/soc/ti/ti_sci_protocol.h> |
| 24 | |
| 25 | #include "ti_sci.h" |
Vignesh Raghavendra | 4214a81 | 2021-06-07 19:47:48 +0530 | [diff] [blame] | 26 | #include "ti_sci_static_data.h" |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 27 | |
| 28 | /* List of all TI SCI devices active in system */ |
| 29 | static LIST_HEAD(ti_sci_list); |
| 30 | |
| 31 | /** |
| 32 | * struct ti_sci_xfer - Structure representing a message flow |
| 33 | * @tx_message: Transmit message |
| 34 | * @rx_len: Receive message length |
| 35 | */ |
| 36 | struct ti_sci_xfer { |
| 37 | struct k3_sec_proxy_msg tx_message; |
| 38 | u8 rx_len; |
| 39 | }; |
| 40 | |
| 41 | /** |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 42 | * struct ti_sci_rm_type_map - Structure representing TISCI Resource |
| 43 | * management representation of dev_ids. |
| 44 | * @dev_id: TISCI device ID |
| 45 | * @type: Corresponding id as identified by TISCI RM. |
| 46 | * |
| 47 | * Note: This is used only as a work around for using RM range apis |
| 48 | * for AM654 SoC. For future SoCs dev_id will be used as type |
| 49 | * for RM range APIs. In order to maintain ABI backward compatibility |
| 50 | * type is not being changed for AM654 SoC. |
| 51 | */ |
| 52 | struct ti_sci_rm_type_map { |
| 53 | u32 dev_id; |
| 54 | u16 type; |
| 55 | }; |
| 56 | |
| 57 | /** |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 58 | * struct ti_sci_desc - Description of SoC integration |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 59 | * @default_host_id: Host identifier representing the compute entity |
| 60 | * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds) |
| 61 | * @max_msgs: Maximum number of messages that can be pending |
| 62 | * simultaneously in the system |
| 63 | * @max_msg_size: Maximum size of data per message that can be handled. |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 64 | */ |
| 65 | struct ti_sci_desc { |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 66 | u8 default_host_id; |
| 67 | int max_rx_timeout_ms; |
| 68 | int max_msgs; |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 69 | int max_msg_size; |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * struct ti_sci_info - Structure representing a TI SCI instance |
| 74 | * @dev: Device pointer |
| 75 | * @desc: SoC description for this instance |
| 76 | * @handle: Instance of TI SCI handle to send to clients. |
| 77 | * @chan_tx: Transmit mailbox channel |
| 78 | * @chan_rx: Receive mailbox channel |
| 79 | * @xfer: xfer info |
| 80 | * @list: list head |
| 81 | * @is_secure: Determines if the communication is through secure threads. |
| 82 | * @host_id: Host identifier representing the compute entity |
| 83 | * @seq: Seq id used for verification for tx and rx message. |
| 84 | */ |
| 85 | struct ti_sci_info { |
| 86 | struct udevice *dev; |
| 87 | const struct ti_sci_desc *desc; |
| 88 | struct ti_sci_handle handle; |
| 89 | struct mbox_chan chan_tx; |
| 90 | struct mbox_chan chan_rx; |
| 91 | struct mbox_chan chan_notify; |
| 92 | struct ti_sci_xfer xfer; |
| 93 | struct list_head list; |
Lokesh Vutla | 0d0412a | 2019-06-07 19:24:41 +0530 | [diff] [blame] | 94 | struct list_head dev_list; |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 95 | bool is_secure; |
| 96 | u8 host_id; |
| 97 | u8 seq; |
| 98 | }; |
| 99 | |
Lokesh Vutla | 0d0412a | 2019-06-07 19:24:41 +0530 | [diff] [blame] | 100 | struct ti_sci_exclusive_dev { |
| 101 | u32 id; |
| 102 | u32 count; |
| 103 | struct list_head list; |
| 104 | }; |
| 105 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 106 | #define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle) |
| 107 | |
| 108 | /** |
| 109 | * ti_sci_setup_one_xfer() - Setup one message type |
| 110 | * @info: Pointer to SCI entity information |
| 111 | * @msg_type: Message type |
| 112 | * @msg_flags: Flag to set for the message |
| 113 | * @buf: Buffer to be send to mailbox channel |
| 114 | * @tx_message_size: transmit message size |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 115 | * @rx_message_size: receive message size. may be set to zero for send-only |
| 116 | * transactions. |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 117 | * |
| 118 | * Helper function which is used by various command functions that are |
| 119 | * exposed to clients of this driver for allocating a message traffic event. |
| 120 | * |
| 121 | * Return: Corresponding ti_sci_xfer pointer if all went fine, |
| 122 | * else appropriate error pointer. |
| 123 | */ |
| 124 | static struct ti_sci_xfer *ti_sci_setup_one_xfer(struct ti_sci_info *info, |
| 125 | u16 msg_type, u32 msg_flags, |
| 126 | u32 *buf, |
| 127 | size_t tx_message_size, |
| 128 | size_t rx_message_size) |
| 129 | { |
| 130 | struct ti_sci_xfer *xfer = &info->xfer; |
| 131 | struct ti_sci_msg_hdr *hdr; |
| 132 | |
| 133 | /* Ensure we have sane transfer sizes */ |
| 134 | if (rx_message_size > info->desc->max_msg_size || |
| 135 | tx_message_size > info->desc->max_msg_size || |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 136 | (rx_message_size > 0 && rx_message_size < sizeof(*hdr)) || |
Andrew Davis | 2256372 | 2022-07-25 20:25:04 -0500 | [diff] [blame] | 137 | tx_message_size < sizeof(*hdr)) { |
| 138 | dev_err(info->dev, "TI-SCI message transfer size not sane\n"); |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 139 | return ERR_PTR(-ERANGE); |
Andrew Davis | 2256372 | 2022-07-25 20:25:04 -0500 | [diff] [blame] | 140 | } |
| 141 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 142 | info->seq = ~info->seq; |
| 143 | xfer->tx_message.buf = buf; |
| 144 | xfer->tx_message.len = tx_message_size; |
| 145 | xfer->rx_len = (u8)rx_message_size; |
| 146 | |
| 147 | hdr = (struct ti_sci_msg_hdr *)buf; |
| 148 | hdr->seq = info->seq; |
| 149 | hdr->type = msg_type; |
| 150 | hdr->host = info->host_id; |
| 151 | hdr->flags = msg_flags; |
| 152 | |
| 153 | return xfer; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * ti_sci_get_response() - Receive response from mailbox channel |
| 158 | * @info: Pointer to SCI entity information |
| 159 | * @xfer: Transfer to initiate and wait for response |
| 160 | * @chan: Channel to receive the response |
| 161 | * |
| 162 | * Return: -ETIMEDOUT in case of no response, if transmit error, |
| 163 | * return corresponding error, else if all goes well, |
| 164 | * return 0. |
| 165 | */ |
Andrew Davis | b3e71b7 | 2022-07-25 20:25:05 -0500 | [diff] [blame] | 166 | static int ti_sci_get_response(struct ti_sci_info *info, |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 167 | struct ti_sci_xfer *xfer, |
| 168 | struct mbox_chan *chan) |
| 169 | { |
| 170 | struct k3_sec_proxy_msg *msg = &xfer->tx_message; |
| 171 | struct ti_sci_secure_msg_hdr *secure_hdr; |
| 172 | struct ti_sci_msg_hdr *hdr; |
| 173 | int ret; |
| 174 | |
| 175 | /* Receive the response */ |
Andreas Dannenberg | 607d4ca | 2019-04-24 14:20:08 -0500 | [diff] [blame] | 176 | ret = mbox_recv(chan, msg, info->desc->max_rx_timeout_ms * 1000); |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 177 | if (ret) { |
| 178 | dev_err(info->dev, "%s: Message receive failed. ret = %d\n", |
| 179 | __func__, ret); |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | /* ToDo: Verify checksum */ |
| 184 | if (info->is_secure) { |
| 185 | secure_hdr = (struct ti_sci_secure_msg_hdr *)msg->buf; |
| 186 | msg->buf = (u32 *)((void *)msg->buf + sizeof(*secure_hdr)); |
| 187 | } |
| 188 | |
| 189 | /* msg is updated by mailbox driver */ |
| 190 | hdr = (struct ti_sci_msg_hdr *)msg->buf; |
| 191 | |
| 192 | /* Sanity check for message response */ |
| 193 | if (hdr->seq != info->seq) { |
| 194 | dev_dbg(info->dev, "%s: Message for %d is not expected\n", |
| 195 | __func__, hdr->seq); |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | if (msg->len > info->desc->max_msg_size) { |
| 200 | dev_err(info->dev, "%s: Unable to handle %zu xfer (max %d)\n", |
| 201 | __func__, msg->len, info->desc->max_msg_size); |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | |
| 205 | if (msg->len < xfer->rx_len) { |
| 206 | dev_err(info->dev, "%s: Recv xfer %zu < expected %d length\n", |
| 207 | __func__, msg->len, xfer->rx_len); |
| 208 | } |
| 209 | |
| 210 | return ret; |
| 211 | } |
| 212 | |
| 213 | /** |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 214 | * ti_sci_is_response_ack() - Generic ACK/NACK message checkup |
| 215 | * @r: pointer to response buffer |
| 216 | * |
| 217 | * Return: true if the response was an ACK, else returns false. |
| 218 | */ |
| 219 | static bool ti_sci_is_response_ack(void *r) |
| 220 | { |
| 221 | struct ti_sci_msg_hdr *hdr = r; |
| 222 | |
| 223 | return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false; |
| 224 | } |
| 225 | |
| 226 | /** |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 227 | * ti_sci_do_xfer() - Do one transfer |
| 228 | * @info: Pointer to SCI entity information |
| 229 | * @xfer: Transfer to initiate and wait for response |
| 230 | * |
| 231 | * Return: 0 if all went fine, else return appropriate error. |
| 232 | */ |
Andrew Davis | b3e71b7 | 2022-07-25 20:25:05 -0500 | [diff] [blame] | 233 | static int ti_sci_do_xfer(struct ti_sci_info *info, |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 234 | struct ti_sci_xfer *xfer) |
| 235 | { |
| 236 | struct k3_sec_proxy_msg *msg = &xfer->tx_message; |
| 237 | u8 secure_buf[info->desc->max_msg_size]; |
Dhruva Gole | d334102 | 2024-01-30 20:29:59 +0530 | [diff] [blame] | 238 | struct ti_sci_secure_msg_hdr *secure_hdr = (struct ti_sci_secure_msg_hdr *)secure_buf; |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 239 | int ret; |
| 240 | |
Dhruva Gole | 5452ebd | 2024-01-30 20:30:00 +0530 | [diff] [blame] | 241 | /* |
| 242 | * The reason why we need the is_secure code is because of boot R5. |
| 243 | * boot R5 starts off in "secure mode" when it hands off from Boot |
| 244 | * ROM over to the Secondary bootloader. The initial set of calls |
| 245 | * we have to make need to be on a secure pipe. |
| 246 | */ |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 247 | if (info->is_secure) { |
| 248 | /* ToDo: get checksum of the entire message */ |
Dhruva Gole | d334102 | 2024-01-30 20:29:59 +0530 | [diff] [blame] | 249 | secure_hdr->checksum = 0; |
| 250 | secure_hdr->reserved = 0; |
| 251 | memcpy(&secure_buf[sizeof(*secure_hdr)], xfer->tx_message.buf, |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 252 | xfer->tx_message.len); |
| 253 | |
| 254 | xfer->tx_message.buf = (u32 *)secure_buf; |
Dhruva Gole | d334102 | 2024-01-30 20:29:59 +0530 | [diff] [blame] | 255 | xfer->tx_message.len += sizeof(*secure_hdr); |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 256 | |
| 257 | if (xfer->rx_len) |
Dhruva Gole | d334102 | 2024-01-30 20:29:59 +0530 | [diff] [blame] | 258 | xfer->rx_len += sizeof(*secure_hdr); |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /* Send the message */ |
| 262 | ret = mbox_send(&info->chan_tx, msg); |
| 263 | if (ret) { |
| 264 | dev_err(info->dev, "%s: Message sending failed. ret = %d\n", |
| 265 | __func__, ret); |
| 266 | return ret; |
| 267 | } |
| 268 | |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 269 | /* Get response if requested */ |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 270 | if (xfer->rx_len) { |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 271 | ret = ti_sci_get_response(info, xfer, &info->chan_rx); |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 272 | if (!ti_sci_is_response_ack(xfer->tx_message.buf)) { |
Andreas Dannenberg | 831b73f | 2023-05-09 16:38:13 -0500 | [diff] [blame] | 273 | dev_err(info->dev, "Message not acknowledged\n"); |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 274 | ret = -ENODEV; |
| 275 | } |
| 276 | } |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 277 | |
| 278 | return ret; |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
| 282 | * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity |
| 283 | * @handle: pointer to TI SCI handle |
| 284 | * |
| 285 | * Updates the SCI information in the internal data structure. |
| 286 | * |
| 287 | * Return: 0 if all went fine, else return appropriate error. |
| 288 | */ |
| 289 | static int ti_sci_cmd_get_revision(struct ti_sci_handle *handle) |
| 290 | { |
| 291 | struct ti_sci_msg_resp_version *rev_info; |
| 292 | struct ti_sci_version_info *ver; |
| 293 | struct ti_sci_msg_hdr hdr; |
| 294 | struct ti_sci_info *info; |
| 295 | struct ti_sci_xfer *xfer; |
| 296 | int ret; |
| 297 | |
| 298 | if (IS_ERR(handle)) |
| 299 | return PTR_ERR(handle); |
| 300 | if (!handle) |
| 301 | return -EINVAL; |
| 302 | |
| 303 | info = handle_to_ti_sci_info(handle); |
| 304 | |
Andrew F. Davis | 8928fbd | 2019-04-29 09:04:11 -0400 | [diff] [blame] | 305 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_VERSION, |
| 306 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 307 | (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr), |
| 308 | sizeof(*rev_info)); |
| 309 | if (IS_ERR(xfer)) { |
| 310 | ret = PTR_ERR(xfer); |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 315 | if (ret) |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 316 | return ret; |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 317 | |
| 318 | rev_info = (struct ti_sci_msg_resp_version *)xfer->tx_message.buf; |
| 319 | |
| 320 | ver = &handle->version; |
| 321 | ver->abi_major = rev_info->abi_major; |
| 322 | ver->abi_minor = rev_info->abi_minor; |
| 323 | ver->firmware_revision = rev_info->firmware_revision; |
| 324 | strncpy(ver->firmware_description, rev_info->firmware_description, |
| 325 | sizeof(ver->firmware_description)); |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | /** |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 331 | * cmd_set_board_config_using_msg() - Common command to send board configuration |
| 332 | * message |
| 333 | * @handle: pointer to TI SCI handle |
| 334 | * @msg_type: One of the TISCI message types to set board configuration |
| 335 | * @addr: Address where the board config structure is located |
| 336 | * @size: Size of the board config structure |
| 337 | * |
| 338 | * Return: 0 if all went well, else returns appropriate error value. |
| 339 | */ |
| 340 | static int cmd_set_board_config_using_msg(const struct ti_sci_handle *handle, |
| 341 | u16 msg_type, u64 addr, u32 size) |
| 342 | { |
| 343 | struct ti_sci_msg_board_config req; |
| 344 | struct ti_sci_msg_hdr *resp; |
| 345 | struct ti_sci_info *info; |
| 346 | struct ti_sci_xfer *xfer; |
| 347 | int ret = 0; |
| 348 | |
| 349 | if (IS_ERR(handle)) |
| 350 | return PTR_ERR(handle); |
| 351 | if (!handle) |
| 352 | return -EINVAL; |
| 353 | |
| 354 | info = handle_to_ti_sci_info(handle); |
| 355 | |
| 356 | xfer = ti_sci_setup_one_xfer(info, msg_type, |
| 357 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 358 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 359 | if (IS_ERR(xfer)) { |
| 360 | ret = PTR_ERR(xfer); |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 361 | return ret; |
| 362 | } |
| 363 | req.boardcfgp_high = (addr >> 32) & 0xffffffff; |
| 364 | req.boardcfgp_low = addr & 0xffffffff; |
| 365 | req.boardcfg_size = size; |
| 366 | |
| 367 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 368 | if (ret) |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 369 | return ret; |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 370 | |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * ti_sci_cmd_set_board_config() - Command to send board configuration message |
| 376 | * @handle: pointer to TI SCI handle |
| 377 | * @addr: Address where the board config structure is located |
| 378 | * @size: Size of the board config structure |
| 379 | * |
| 380 | * Return: 0 if all went well, else returns appropriate error value. |
| 381 | */ |
| 382 | static int ti_sci_cmd_set_board_config(const struct ti_sci_handle *handle, |
| 383 | u64 addr, u32 size) |
| 384 | { |
| 385 | return cmd_set_board_config_using_msg(handle, |
| 386 | TI_SCI_MSG_BOARD_CONFIG, |
| 387 | addr, size); |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * ti_sci_cmd_set_board_config_rm() - Command to send board resource |
| 392 | * management configuration |
| 393 | * @handle: pointer to TI SCI handle |
| 394 | * @addr: Address where the board RM config structure is located |
| 395 | * @size: Size of the RM config structure |
| 396 | * |
| 397 | * Return: 0 if all went well, else returns appropriate error value. |
| 398 | */ |
| 399 | static |
| 400 | int ti_sci_cmd_set_board_config_rm(const struct ti_sci_handle *handle, |
| 401 | u64 addr, u32 size) |
| 402 | { |
| 403 | return cmd_set_board_config_using_msg(handle, |
| 404 | TI_SCI_MSG_BOARD_CONFIG_RM, |
| 405 | addr, size); |
| 406 | } |
| 407 | |
| 408 | /** |
| 409 | * ti_sci_cmd_set_board_config_security() - Command to send board security |
| 410 | * configuration message |
| 411 | * @handle: pointer to TI SCI handle |
| 412 | * @addr: Address where the board security config structure is located |
| 413 | * @size: Size of the security config structure |
| 414 | * |
| 415 | * Return: 0 if all went well, else returns appropriate error value. |
| 416 | */ |
| 417 | static |
| 418 | int ti_sci_cmd_set_board_config_security(const struct ti_sci_handle *handle, |
| 419 | u64 addr, u32 size) |
| 420 | { |
| 421 | return cmd_set_board_config_using_msg(handle, |
| 422 | TI_SCI_MSG_BOARD_CONFIG_SECURITY, |
| 423 | addr, size); |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * ti_sci_cmd_set_board_config_pm() - Command to send board power and clock |
| 428 | * configuration message |
| 429 | * @handle: pointer to TI SCI handle |
| 430 | * @addr: Address where the board PM config structure is located |
| 431 | * @size: Size of the PM config structure |
| 432 | * |
| 433 | * Return: 0 if all went well, else returns appropriate error value. |
| 434 | */ |
| 435 | static int ti_sci_cmd_set_board_config_pm(const struct ti_sci_handle *handle, |
| 436 | u64 addr, u32 size) |
| 437 | { |
| 438 | return cmd_set_board_config_using_msg(handle, |
| 439 | TI_SCI_MSG_BOARD_CONFIG_PM, |
| 440 | addr, size); |
| 441 | } |
| 442 | |
Lokesh Vutla | 0d0412a | 2019-06-07 19:24:41 +0530 | [diff] [blame] | 443 | static struct ti_sci_exclusive_dev |
| 444 | *ti_sci_get_exclusive_dev(struct list_head *dev_list, u32 id) |
| 445 | { |
| 446 | struct ti_sci_exclusive_dev *dev; |
| 447 | |
| 448 | list_for_each_entry(dev, dev_list, list) |
| 449 | if (dev->id == id) |
| 450 | return dev; |
| 451 | |
| 452 | return NULL; |
| 453 | } |
| 454 | |
| 455 | static void ti_sci_add_exclusive_dev(struct ti_sci_info *info, u32 id) |
| 456 | { |
| 457 | struct ti_sci_exclusive_dev *dev; |
| 458 | |
| 459 | dev = ti_sci_get_exclusive_dev(&info->dev_list, id); |
| 460 | if (dev) { |
| 461 | dev->count++; |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 466 | dev->id = id; |
| 467 | dev->count = 1; |
| 468 | INIT_LIST_HEAD(&dev->list); |
| 469 | list_add_tail(&dev->list, &info->dev_list); |
| 470 | } |
| 471 | |
| 472 | static void ti_sci_delete_exclusive_dev(struct ti_sci_info *info, u32 id) |
| 473 | { |
| 474 | struct ti_sci_exclusive_dev *dev; |
| 475 | |
| 476 | dev = ti_sci_get_exclusive_dev(&info->dev_list, id); |
| 477 | if (!dev) |
| 478 | return; |
| 479 | |
| 480 | if (dev->count > 0) |
| 481 | dev->count--; |
| 482 | } |
| 483 | |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 484 | /** |
| 485 | * ti_sci_set_device_state() - Set device state helper |
| 486 | * @handle: pointer to TI SCI handle |
| 487 | * @id: Device identifier |
| 488 | * @flags: flags to setup for the device |
| 489 | * @state: State to move the device to |
| 490 | * |
| 491 | * Return: 0 if all went well, else returns appropriate error value. |
| 492 | */ |
| 493 | static int ti_sci_set_device_state(const struct ti_sci_handle *handle, |
| 494 | u32 id, u32 flags, u8 state) |
| 495 | { |
| 496 | struct ti_sci_msg_req_set_device_state req; |
| 497 | struct ti_sci_msg_hdr *resp; |
| 498 | struct ti_sci_info *info; |
| 499 | struct ti_sci_xfer *xfer; |
| 500 | int ret = 0; |
| 501 | |
| 502 | if (IS_ERR(handle)) |
| 503 | return PTR_ERR(handle); |
| 504 | if (!handle) |
| 505 | return -EINVAL; |
| 506 | |
| 507 | info = handle_to_ti_sci_info(handle); |
| 508 | |
| 509 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE, |
| 510 | flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 511 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 512 | if (IS_ERR(xfer)) { |
| 513 | ret = PTR_ERR(xfer); |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 514 | return ret; |
| 515 | } |
| 516 | req.id = id; |
| 517 | req.state = state; |
| 518 | |
| 519 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 520 | if (ret) |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 521 | return ret; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 522 | |
Lokesh Vutla | 0d0412a | 2019-06-07 19:24:41 +0530 | [diff] [blame] | 523 | if (state == MSG_DEVICE_SW_STATE_AUTO_OFF) |
| 524 | ti_sci_delete_exclusive_dev(info, id); |
| 525 | else if (flags & MSG_FLAG_DEVICE_EXCLUSIVE) |
| 526 | ti_sci_add_exclusive_dev(info, id); |
| 527 | |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 528 | return ret; |
| 529 | } |
| 530 | |
| 531 | /** |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 532 | * ti_sci_set_device_state_no_wait() - Set device state helper without |
| 533 | * requesting or waiting for a response. |
| 534 | * @handle: pointer to TI SCI handle |
| 535 | * @id: Device identifier |
| 536 | * @flags: flags to setup for the device |
| 537 | * @state: State to move the device to |
| 538 | * |
| 539 | * Return: 0 if all went well, else returns appropriate error value. |
| 540 | */ |
| 541 | static int ti_sci_set_device_state_no_wait(const struct ti_sci_handle *handle, |
| 542 | u32 id, u32 flags, u8 state) |
| 543 | { |
| 544 | struct ti_sci_msg_req_set_device_state req; |
| 545 | struct ti_sci_info *info; |
| 546 | struct ti_sci_xfer *xfer; |
| 547 | int ret = 0; |
| 548 | |
| 549 | if (IS_ERR(handle)) |
| 550 | return PTR_ERR(handle); |
| 551 | if (!handle) |
| 552 | return -EINVAL; |
| 553 | |
| 554 | info = handle_to_ti_sci_info(handle); |
| 555 | |
| 556 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE, |
| 557 | flags | TI_SCI_FLAG_REQ_GENERIC_NORESPONSE, |
| 558 | (u32 *)&req, sizeof(req), 0); |
| 559 | if (IS_ERR(xfer)) { |
| 560 | ret = PTR_ERR(xfer); |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 561 | return ret; |
| 562 | } |
| 563 | req.id = id; |
| 564 | req.state = state; |
| 565 | |
| 566 | ret = ti_sci_do_xfer(info, xfer); |
| 567 | if (ret) |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 568 | return ret; |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 569 | |
| 570 | return ret; |
| 571 | } |
| 572 | |
| 573 | /** |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 574 | * ti_sci_get_device_state() - Get device state helper |
| 575 | * @handle: Handle to the device |
| 576 | * @id: Device Identifier |
| 577 | * @clcnt: Pointer to Context Loss Count |
| 578 | * @resets: pointer to resets |
| 579 | * @p_state: pointer to p_state |
| 580 | * @c_state: pointer to c_state |
| 581 | * |
| 582 | * Return: 0 if all went fine, else return appropriate error. |
| 583 | */ |
| 584 | static int ti_sci_get_device_state(const struct ti_sci_handle *handle, |
| 585 | u32 id, u32 *clcnt, u32 *resets, |
| 586 | u8 *p_state, u8 *c_state) |
| 587 | { |
| 588 | struct ti_sci_msg_resp_get_device_state *resp; |
| 589 | struct ti_sci_msg_req_get_device_state req; |
| 590 | struct ti_sci_info *info; |
| 591 | struct ti_sci_xfer *xfer; |
| 592 | int ret = 0; |
| 593 | |
| 594 | if (IS_ERR(handle)) |
| 595 | return PTR_ERR(handle); |
| 596 | if (!handle) |
| 597 | return -EINVAL; |
| 598 | |
| 599 | if (!clcnt && !resets && !p_state && !c_state) |
| 600 | return -EINVAL; |
| 601 | |
| 602 | info = handle_to_ti_sci_info(handle); |
| 603 | |
Andrew F. Davis | 8928fbd | 2019-04-29 09:04:11 -0400 | [diff] [blame] | 604 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_DEVICE_STATE, |
| 605 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 606 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 607 | if (IS_ERR(xfer)) { |
| 608 | ret = PTR_ERR(xfer); |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 609 | return ret; |
| 610 | } |
| 611 | req.id = id; |
| 612 | |
| 613 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 614 | if (ret) |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 615 | return ret; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 616 | |
| 617 | resp = (struct ti_sci_msg_resp_get_device_state *)xfer->tx_message.buf; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 618 | |
| 619 | if (clcnt) |
| 620 | *clcnt = resp->context_loss_count; |
| 621 | if (resets) |
| 622 | *resets = resp->resets; |
| 623 | if (p_state) |
| 624 | *p_state = resp->programmed_state; |
| 625 | if (c_state) |
| 626 | *c_state = resp->current_state; |
| 627 | |
| 628 | return ret; |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * ti_sci_cmd_get_device() - command to request for device managed by TISCI |
| 633 | * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle |
| 634 | * @id: Device Identifier |
| 635 | * |
| 636 | * Request for the device - NOTE: the client MUST maintain integrity of |
| 637 | * usage count by balancing get_device with put_device. No refcounting is |
| 638 | * managed by driver for that purpose. |
| 639 | * |
| 640 | * NOTE: The request is for exclusive access for the processor. |
| 641 | * |
| 642 | * Return: 0 if all went fine, else return appropriate error. |
| 643 | */ |
| 644 | static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id) |
| 645 | { |
Lokesh Vutla | f561300 | 2019-06-07 19:24:39 +0530 | [diff] [blame] | 646 | return ti_sci_set_device_state(handle, id, 0, |
| 647 | MSG_DEVICE_SW_STATE_ON); |
| 648 | } |
| 649 | |
| 650 | static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle *handle, |
| 651 | u32 id) |
| 652 | { |
| 653 | return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE, |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 654 | MSG_DEVICE_SW_STATE_ON); |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI |
| 659 | * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle |
| 660 | * @id: Device Identifier |
| 661 | * |
| 662 | * Request for the device - NOTE: the client MUST maintain integrity of |
| 663 | * usage count by balancing get_device with put_device. No refcounting is |
| 664 | * managed by driver for that purpose. |
| 665 | * |
| 666 | * Return: 0 if all went fine, else return appropriate error. |
| 667 | */ |
| 668 | static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id) |
| 669 | { |
| 670 | return ti_sci_set_device_state(handle, id, |
Lokesh Vutla | f561300 | 2019-06-07 19:24:39 +0530 | [diff] [blame] | 671 | 0, |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 672 | MSG_DEVICE_SW_STATE_RETENTION); |
| 673 | } |
| 674 | |
Lokesh Vutla | f561300 | 2019-06-07 19:24:39 +0530 | [diff] [blame] | 675 | static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle *handle, |
| 676 | u32 id) |
| 677 | { |
| 678 | return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE, |
| 679 | MSG_DEVICE_SW_STATE_RETENTION); |
| 680 | } |
| 681 | |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 682 | /** |
| 683 | * ti_sci_cmd_put_device() - command to release a device managed by TISCI |
| 684 | * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle |
| 685 | * @id: Device Identifier |
| 686 | * |
| 687 | * Request for the device - NOTE: the client MUST maintain integrity of |
| 688 | * usage count by balancing get_device with put_device. No refcounting is |
| 689 | * managed by driver for that purpose. |
| 690 | * |
| 691 | * Return: 0 if all went fine, else return appropriate error. |
| 692 | */ |
| 693 | static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id) |
| 694 | { |
Lokesh Vutla | f561300 | 2019-06-07 19:24:39 +0530 | [diff] [blame] | 695 | return ti_sci_set_device_state(handle, id, 0, |
| 696 | MSG_DEVICE_SW_STATE_AUTO_OFF); |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 697 | } |
| 698 | |
Lokesh Vutla | 0d0412a | 2019-06-07 19:24:41 +0530 | [diff] [blame] | 699 | static |
| 700 | int ti_sci_cmd_release_exclusive_devices(const struct ti_sci_handle *handle) |
| 701 | { |
| 702 | struct ti_sci_exclusive_dev *dev, *tmp; |
| 703 | struct ti_sci_info *info; |
| 704 | int i, cnt; |
| 705 | |
| 706 | info = handle_to_ti_sci_info(handle); |
| 707 | |
| 708 | list_for_each_entry_safe(dev, tmp, &info->dev_list, list) { |
| 709 | cnt = dev->count; |
| 710 | debug("%s: id = %d, cnt = %d\n", __func__, dev->id, cnt); |
| 711 | for (i = 0; i < cnt; i++) |
| 712 | ti_sci_cmd_put_device(handle, dev->id); |
| 713 | } |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 718 | /** |
| 719 | * ti_sci_cmd_dev_is_valid() - Is the device valid |
| 720 | * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle |
| 721 | * @id: Device Identifier |
| 722 | * |
| 723 | * Return: 0 if all went fine and the device ID is valid, else return |
| 724 | * appropriate error. |
| 725 | */ |
| 726 | static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id) |
| 727 | { |
| 728 | u8 unused; |
| 729 | |
| 730 | /* check the device state which will also tell us if the ID is valid */ |
| 731 | return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * ti_sci_cmd_dev_get_clcnt() - Get context loss counter |
| 736 | * @handle: Pointer to TISCI handle |
| 737 | * @id: Device Identifier |
| 738 | * @count: Pointer to Context Loss counter to populate |
| 739 | * |
| 740 | * Return: 0 if all went fine, else return appropriate error. |
| 741 | */ |
| 742 | static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id, |
| 743 | u32 *count) |
| 744 | { |
| 745 | return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL); |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle |
| 750 | * @handle: Pointer to TISCI handle |
| 751 | * @id: Device Identifier |
| 752 | * @r_state: true if requested to be idle |
| 753 | * |
| 754 | * Return: 0 if all went fine, else return appropriate error. |
| 755 | */ |
| 756 | static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id, |
| 757 | bool *r_state) |
| 758 | { |
| 759 | int ret; |
| 760 | u8 state; |
| 761 | |
| 762 | if (!r_state) |
| 763 | return -EINVAL; |
| 764 | |
| 765 | ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL); |
| 766 | if (ret) |
| 767 | return ret; |
| 768 | |
| 769 | *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION); |
| 770 | |
| 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped |
| 776 | * @handle: Pointer to TISCI handle |
| 777 | * @id: Device Identifier |
| 778 | * @r_state: true if requested to be stopped |
| 779 | * @curr_state: true if currently stopped. |
| 780 | * |
| 781 | * Return: 0 if all went fine, else return appropriate error. |
| 782 | */ |
| 783 | static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id, |
| 784 | bool *r_state, bool *curr_state) |
| 785 | { |
| 786 | int ret; |
| 787 | u8 p_state, c_state; |
| 788 | |
| 789 | if (!r_state && !curr_state) |
| 790 | return -EINVAL; |
| 791 | |
| 792 | ret = |
| 793 | ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state); |
| 794 | if (ret) |
| 795 | return ret; |
| 796 | |
| 797 | if (r_state) |
| 798 | *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF); |
| 799 | if (curr_state) |
| 800 | *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF); |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON |
| 807 | * @handle: Pointer to TISCI handle |
| 808 | * @id: Device Identifier |
| 809 | * @r_state: true if requested to be ON |
| 810 | * @curr_state: true if currently ON and active |
| 811 | * |
| 812 | * Return: 0 if all went fine, else return appropriate error. |
| 813 | */ |
| 814 | static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id, |
| 815 | bool *r_state, bool *curr_state) |
| 816 | { |
| 817 | int ret; |
| 818 | u8 p_state, c_state; |
| 819 | |
| 820 | if (!r_state && !curr_state) |
| 821 | return -EINVAL; |
| 822 | |
| 823 | ret = |
| 824 | ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state); |
| 825 | if (ret) |
| 826 | return ret; |
| 827 | |
| 828 | if (r_state) |
| 829 | *r_state = (p_state == MSG_DEVICE_SW_STATE_ON); |
| 830 | if (curr_state) |
| 831 | *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON); |
| 832 | |
| 833 | return 0; |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning |
| 838 | * @handle: Pointer to TISCI handle |
| 839 | * @id: Device Identifier |
| 840 | * @curr_state: true if currently transitioning. |
| 841 | * |
| 842 | * Return: 0 if all went fine, else return appropriate error. |
| 843 | */ |
| 844 | static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id, |
| 845 | bool *curr_state) |
| 846 | { |
| 847 | int ret; |
| 848 | u8 state; |
| 849 | |
| 850 | if (!curr_state) |
| 851 | return -EINVAL; |
| 852 | |
| 853 | ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state); |
| 854 | if (ret) |
| 855 | return ret; |
| 856 | |
| 857 | *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS); |
| 858 | |
| 859 | return 0; |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * ti_sci_cmd_set_device_resets() - command to set resets for device managed |
| 864 | * by TISCI |
| 865 | * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle |
| 866 | * @id: Device Identifier |
| 867 | * @reset_state: Device specific reset bit field |
| 868 | * |
| 869 | * Return: 0 if all went fine, else return appropriate error. |
| 870 | */ |
| 871 | static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle, |
| 872 | u32 id, u32 reset_state) |
| 873 | { |
| 874 | struct ti_sci_msg_req_set_device_resets req; |
| 875 | struct ti_sci_msg_hdr *resp; |
| 876 | struct ti_sci_info *info; |
| 877 | struct ti_sci_xfer *xfer; |
| 878 | int ret = 0; |
| 879 | |
| 880 | if (IS_ERR(handle)) |
| 881 | return PTR_ERR(handle); |
| 882 | if (!handle) |
| 883 | return -EINVAL; |
| 884 | |
| 885 | info = handle_to_ti_sci_info(handle); |
| 886 | |
| 887 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_RESETS, |
| 888 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 889 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 890 | if (IS_ERR(xfer)) { |
| 891 | ret = PTR_ERR(xfer); |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 892 | return ret; |
| 893 | } |
| 894 | req.id = id; |
| 895 | req.resets = reset_state; |
| 896 | |
| 897 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 898 | if (ret) |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 899 | return ret; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 900 | |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 901 | return ret; |
| 902 | } |
| 903 | |
| 904 | /** |
| 905 | * ti_sci_cmd_get_device_resets() - Get reset state for device managed |
| 906 | * by TISCI |
| 907 | * @handle: Pointer to TISCI handle |
| 908 | * @id: Device Identifier |
| 909 | * @reset_state: Pointer to reset state to populate |
| 910 | * |
| 911 | * Return: 0 if all went fine, else return appropriate error. |
| 912 | */ |
| 913 | static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle, |
| 914 | u32 id, u32 *reset_state) |
| 915 | { |
| 916 | return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL, |
| 917 | NULL); |
| 918 | } |
| 919 | |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 920 | /** |
| 921 | * ti_sci_set_clock_state() - Set clock state helper |
| 922 | * @handle: pointer to TI SCI handle |
| 923 | * @dev_id: Device identifier this request is for |
| 924 | * @clk_id: Clock identifier for the device for this request. |
| 925 | * Each device has it's own set of clock inputs. This indexes |
| 926 | * which clock input to modify. |
| 927 | * @flags: Header flags as needed |
| 928 | * @state: State to request for the clock. |
| 929 | * |
| 930 | * Return: 0 if all went well, else returns appropriate error value. |
| 931 | */ |
| 932 | static int ti_sci_set_clock_state(const struct ti_sci_handle *handle, |
| 933 | u32 dev_id, u8 clk_id, |
| 934 | u32 flags, u8 state) |
| 935 | { |
| 936 | struct ti_sci_msg_req_set_clock_state req; |
| 937 | struct ti_sci_msg_hdr *resp; |
| 938 | struct ti_sci_info *info; |
| 939 | struct ti_sci_xfer *xfer; |
| 940 | int ret = 0; |
| 941 | |
| 942 | if (IS_ERR(handle)) |
| 943 | return PTR_ERR(handle); |
| 944 | if (!handle) |
| 945 | return -EINVAL; |
| 946 | |
| 947 | info = handle_to_ti_sci_info(handle); |
| 948 | |
| 949 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_STATE, |
| 950 | flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 951 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 952 | if (IS_ERR(xfer)) { |
| 953 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 954 | return ret; |
| 955 | } |
| 956 | req.dev_id = dev_id; |
| 957 | req.clk_id = clk_id; |
| 958 | req.request_state = state; |
| 959 | |
| 960 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 961 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 962 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 963 | |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 964 | return ret; |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * ti_sci_cmd_get_clock_state() - Get clock state helper |
| 969 | * @handle: pointer to TI SCI handle |
| 970 | * @dev_id: Device identifier this request is for |
| 971 | * @clk_id: Clock identifier for the device for this request. |
| 972 | * Each device has it's own set of clock inputs. This indexes |
| 973 | * which clock input to modify. |
| 974 | * @programmed_state: State requested for clock to move to |
| 975 | * @current_state: State that the clock is currently in |
| 976 | * |
| 977 | * Return: 0 if all went well, else returns appropriate error value. |
| 978 | */ |
| 979 | static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle *handle, |
| 980 | u32 dev_id, u8 clk_id, |
| 981 | u8 *programmed_state, u8 *current_state) |
| 982 | { |
| 983 | struct ti_sci_msg_resp_get_clock_state *resp; |
| 984 | struct ti_sci_msg_req_get_clock_state req; |
| 985 | struct ti_sci_info *info; |
| 986 | struct ti_sci_xfer *xfer; |
| 987 | int ret = 0; |
| 988 | |
| 989 | if (IS_ERR(handle)) |
| 990 | return PTR_ERR(handle); |
| 991 | if (!handle) |
| 992 | return -EINVAL; |
| 993 | |
| 994 | if (!programmed_state && !current_state) |
| 995 | return -EINVAL; |
| 996 | |
| 997 | info = handle_to_ti_sci_info(handle); |
| 998 | |
| 999 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_STATE, |
| 1000 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1001 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1002 | if (IS_ERR(xfer)) { |
| 1003 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1004 | return ret; |
| 1005 | } |
| 1006 | req.dev_id = dev_id; |
| 1007 | req.clk_id = clk_id; |
| 1008 | |
| 1009 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1010 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1011 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1012 | |
| 1013 | resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->tx_message.buf; |
| 1014 | |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1015 | if (programmed_state) |
| 1016 | *programmed_state = resp->programmed_state; |
| 1017 | if (current_state) |
| 1018 | *current_state = resp->current_state; |
| 1019 | |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI |
| 1025 | * @handle: pointer to TI SCI handle |
| 1026 | * @dev_id: Device identifier this request is for |
| 1027 | * @clk_id: Clock identifier for the device for this request. |
| 1028 | * Each device has it's own set of clock inputs. This indexes |
| 1029 | * which clock input to modify. |
| 1030 | * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false' |
| 1031 | * @can_change_freq: 'true' if frequency change is desired, else 'false' |
| 1032 | * @enable_input_term: 'true' if input termination is desired, else 'false' |
| 1033 | * |
| 1034 | * Return: 0 if all went well, else returns appropriate error value. |
| 1035 | */ |
| 1036 | static int ti_sci_cmd_get_clock(const struct ti_sci_handle *handle, u32 dev_id, |
| 1037 | u8 clk_id, bool needs_ssc, bool can_change_freq, |
| 1038 | bool enable_input_term) |
| 1039 | { |
| 1040 | u32 flags = 0; |
| 1041 | |
| 1042 | flags |= needs_ssc ? MSG_FLAG_CLOCK_ALLOW_SSC : 0; |
| 1043 | flags |= can_change_freq ? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE : 0; |
| 1044 | flags |= enable_input_term ? MSG_FLAG_CLOCK_INPUT_TERM : 0; |
| 1045 | |
| 1046 | return ti_sci_set_clock_state(handle, dev_id, clk_id, flags, |
| 1047 | MSG_CLOCK_SW_STATE_REQ); |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * ti_sci_cmd_idle_clock() - Idle a clock which is in our control |
| 1052 | * @handle: pointer to TI SCI handle |
| 1053 | * @dev_id: Device identifier this request is for |
| 1054 | * @clk_id: Clock identifier for the device for this request. |
| 1055 | * Each device has it's own set of clock inputs. This indexes |
| 1056 | * which clock input to modify. |
| 1057 | * |
| 1058 | * NOTE: This clock must have been requested by get_clock previously. |
| 1059 | * |
| 1060 | * Return: 0 if all went well, else returns appropriate error value. |
| 1061 | */ |
| 1062 | static int ti_sci_cmd_idle_clock(const struct ti_sci_handle *handle, |
| 1063 | u32 dev_id, u8 clk_id) |
| 1064 | { |
| 1065 | return ti_sci_set_clock_state(handle, dev_id, clk_id, 0, |
| 1066 | MSG_CLOCK_SW_STATE_UNREQ); |
| 1067 | } |
| 1068 | |
| 1069 | /** |
| 1070 | * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI |
| 1071 | * @handle: pointer to TI SCI handle |
| 1072 | * @dev_id: Device identifier this request is for |
| 1073 | * @clk_id: Clock identifier for the device for this request. |
| 1074 | * Each device has it's own set of clock inputs. This indexes |
| 1075 | * which clock input to modify. |
| 1076 | * |
| 1077 | * NOTE: This clock must have been requested by get_clock previously. |
| 1078 | * |
| 1079 | * Return: 0 if all went well, else returns appropriate error value. |
| 1080 | */ |
| 1081 | static int ti_sci_cmd_put_clock(const struct ti_sci_handle *handle, |
| 1082 | u32 dev_id, u8 clk_id) |
| 1083 | { |
| 1084 | return ti_sci_set_clock_state(handle, dev_id, clk_id, 0, |
| 1085 | MSG_CLOCK_SW_STATE_AUTO); |
| 1086 | } |
| 1087 | |
| 1088 | /** |
| 1089 | * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed |
| 1090 | * @handle: pointer to TI SCI handle |
| 1091 | * @dev_id: Device identifier this request is for |
| 1092 | * @clk_id: Clock identifier for the device for this request. |
| 1093 | * Each device has it's own set of clock inputs. This indexes |
| 1094 | * which clock input to modify. |
| 1095 | * @req_state: state indicating if the clock is auto managed |
| 1096 | * |
| 1097 | * Return: 0 if all went well, else returns appropriate error value. |
| 1098 | */ |
| 1099 | static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle *handle, |
| 1100 | u32 dev_id, u8 clk_id, bool *req_state) |
| 1101 | { |
| 1102 | u8 state = 0; |
| 1103 | int ret; |
| 1104 | |
| 1105 | if (!req_state) |
| 1106 | return -EINVAL; |
| 1107 | |
| 1108 | ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, &state, NULL); |
| 1109 | if (ret) |
| 1110 | return ret; |
| 1111 | |
| 1112 | *req_state = (state == MSG_CLOCK_SW_STATE_AUTO); |
| 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | /** |
| 1117 | * ti_sci_cmd_clk_is_on() - Is the clock ON |
| 1118 | * @handle: pointer to TI SCI handle |
| 1119 | * @dev_id: Device identifier this request is for |
| 1120 | * @clk_id: Clock identifier for the device for this request. |
| 1121 | * Each device has it's own set of clock inputs. This indexes |
| 1122 | * which clock input to modify. |
| 1123 | * @req_state: state indicating if the clock is managed by us and enabled |
| 1124 | * @curr_state: state indicating if the clock is ready for operation |
| 1125 | * |
| 1126 | * Return: 0 if all went well, else returns appropriate error value. |
| 1127 | */ |
| 1128 | static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle *handle, u32 dev_id, |
| 1129 | u8 clk_id, bool *req_state, bool *curr_state) |
| 1130 | { |
| 1131 | u8 c_state = 0, r_state = 0; |
| 1132 | int ret; |
| 1133 | |
| 1134 | if (!req_state && !curr_state) |
| 1135 | return -EINVAL; |
| 1136 | |
| 1137 | ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, |
| 1138 | &r_state, &c_state); |
| 1139 | if (ret) |
| 1140 | return ret; |
| 1141 | |
| 1142 | if (req_state) |
| 1143 | *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ); |
| 1144 | if (curr_state) |
| 1145 | *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY); |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
| 1150 | * ti_sci_cmd_clk_is_off() - Is the clock OFF |
| 1151 | * @handle: pointer to TI SCI handle |
| 1152 | * @dev_id: Device identifier this request is for |
| 1153 | * @clk_id: Clock identifier for the device for this request. |
| 1154 | * Each device has it's own set of clock inputs. This indexes |
| 1155 | * which clock input to modify. |
| 1156 | * @req_state: state indicating if the clock is managed by us and disabled |
| 1157 | * @curr_state: state indicating if the clock is NOT ready for operation |
| 1158 | * |
| 1159 | * Return: 0 if all went well, else returns appropriate error value. |
| 1160 | */ |
| 1161 | static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle *handle, u32 dev_id, |
| 1162 | u8 clk_id, bool *req_state, bool *curr_state) |
| 1163 | { |
| 1164 | u8 c_state = 0, r_state = 0; |
| 1165 | int ret; |
| 1166 | |
| 1167 | if (!req_state && !curr_state) |
| 1168 | return -EINVAL; |
| 1169 | |
| 1170 | ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, |
| 1171 | &r_state, &c_state); |
| 1172 | if (ret) |
| 1173 | return ret; |
| 1174 | |
| 1175 | if (req_state) |
| 1176 | *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ); |
| 1177 | if (curr_state) |
| 1178 | *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY); |
| 1179 | return 0; |
| 1180 | } |
| 1181 | |
| 1182 | /** |
| 1183 | * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock |
| 1184 | * @handle: pointer to TI SCI handle |
| 1185 | * @dev_id: Device identifier this request is for |
| 1186 | * @clk_id: Clock identifier for the device for this request. |
| 1187 | * Each device has it's own set of clock inputs. This indexes |
| 1188 | * which clock input to modify. |
| 1189 | * @parent_id: Parent clock identifier to set |
| 1190 | * |
| 1191 | * Return: 0 if all went well, else returns appropriate error value. |
| 1192 | */ |
| 1193 | static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle *handle, |
| 1194 | u32 dev_id, u8 clk_id, u8 parent_id) |
| 1195 | { |
| 1196 | struct ti_sci_msg_req_set_clock_parent req; |
| 1197 | struct ti_sci_msg_hdr *resp; |
| 1198 | struct ti_sci_info *info; |
| 1199 | struct ti_sci_xfer *xfer; |
| 1200 | int ret = 0; |
| 1201 | |
| 1202 | if (IS_ERR(handle)) |
| 1203 | return PTR_ERR(handle); |
| 1204 | if (!handle) |
| 1205 | return -EINVAL; |
| 1206 | |
| 1207 | info = handle_to_ti_sci_info(handle); |
| 1208 | |
| 1209 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_PARENT, |
| 1210 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1211 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1212 | if (IS_ERR(xfer)) { |
| 1213 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1214 | return ret; |
| 1215 | } |
| 1216 | req.dev_id = dev_id; |
| 1217 | req.clk_id = clk_id; |
| 1218 | req.parent_id = parent_id; |
| 1219 | |
| 1220 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1221 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1222 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1223 | |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1224 | return ret; |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * ti_sci_cmd_clk_get_parent() - Get current parent clock source |
| 1229 | * @handle: pointer to TI SCI handle |
| 1230 | * @dev_id: Device identifier this request is for |
| 1231 | * @clk_id: Clock identifier for the device for this request. |
| 1232 | * Each device has it's own set of clock inputs. This indexes |
| 1233 | * which clock input to modify. |
| 1234 | * @parent_id: Current clock parent |
| 1235 | * |
| 1236 | * Return: 0 if all went well, else returns appropriate error value. |
| 1237 | */ |
| 1238 | static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle, |
| 1239 | u32 dev_id, u8 clk_id, u8 *parent_id) |
| 1240 | { |
| 1241 | struct ti_sci_msg_resp_get_clock_parent *resp; |
| 1242 | struct ti_sci_msg_req_get_clock_parent req; |
| 1243 | struct ti_sci_info *info; |
| 1244 | struct ti_sci_xfer *xfer; |
| 1245 | int ret = 0; |
| 1246 | |
| 1247 | if (IS_ERR(handle)) |
| 1248 | return PTR_ERR(handle); |
| 1249 | if (!handle || !parent_id) |
| 1250 | return -EINVAL; |
| 1251 | |
| 1252 | info = handle_to_ti_sci_info(handle); |
| 1253 | |
| 1254 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_PARENT, |
| 1255 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1256 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1257 | if (IS_ERR(xfer)) { |
| 1258 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1259 | return ret; |
| 1260 | } |
| 1261 | req.dev_id = dev_id; |
| 1262 | req.clk_id = clk_id; |
| 1263 | |
| 1264 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1265 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1266 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1267 | |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 1268 | *parent_id = resp->parent_id; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1269 | |
| 1270 | return ret; |
| 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source |
| 1275 | * @handle: pointer to TI SCI handle |
| 1276 | * @dev_id: Device identifier this request is for |
| 1277 | * @clk_id: Clock identifier for the device for this request. |
| 1278 | * Each device has it's own set of clock inputs. This indexes |
| 1279 | * which clock input to modify. |
| 1280 | * @num_parents: Returns he number of parents to the current clock. |
| 1281 | * |
| 1282 | * Return: 0 if all went well, else returns appropriate error value. |
| 1283 | */ |
| 1284 | static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle *handle, |
| 1285 | u32 dev_id, u8 clk_id, |
| 1286 | u8 *num_parents) |
| 1287 | { |
| 1288 | struct ti_sci_msg_resp_get_clock_num_parents *resp; |
| 1289 | struct ti_sci_msg_req_get_clock_num_parents req; |
| 1290 | struct ti_sci_info *info; |
| 1291 | struct ti_sci_xfer *xfer; |
| 1292 | int ret = 0; |
| 1293 | |
| 1294 | if (IS_ERR(handle)) |
| 1295 | return PTR_ERR(handle); |
| 1296 | if (!handle || !num_parents) |
| 1297 | return -EINVAL; |
| 1298 | |
| 1299 | info = handle_to_ti_sci_info(handle); |
| 1300 | |
| 1301 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS, |
| 1302 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1303 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1304 | if (IS_ERR(xfer)) { |
| 1305 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1306 | return ret; |
| 1307 | } |
| 1308 | req.dev_id = dev_id; |
| 1309 | req.clk_id = clk_id; |
| 1310 | |
| 1311 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1312 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1313 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1314 | |
| 1315 | resp = (struct ti_sci_msg_resp_get_clock_num_parents *) |
| 1316 | xfer->tx_message.buf; |
| 1317 | |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 1318 | *num_parents = resp->num_parents; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1319 | |
| 1320 | return ret; |
| 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency |
| 1325 | * @handle: pointer to TI SCI handle |
| 1326 | * @dev_id: Device identifier this request is for |
| 1327 | * @clk_id: Clock identifier for the device for this request. |
| 1328 | * Each device has it's own set of clock inputs. This indexes |
| 1329 | * which clock input to modify. |
| 1330 | * @min_freq: The minimum allowable frequency in Hz. This is the minimum |
| 1331 | * allowable programmed frequency and does not account for clock |
| 1332 | * tolerances and jitter. |
| 1333 | * @target_freq: The target clock frequency in Hz. A frequency will be |
| 1334 | * processed as close to this target frequency as possible. |
| 1335 | * @max_freq: The maximum allowable frequency in Hz. This is the maximum |
| 1336 | * allowable programmed frequency and does not account for clock |
| 1337 | * tolerances and jitter. |
| 1338 | * @match_freq: Frequency match in Hz response. |
| 1339 | * |
| 1340 | * Return: 0 if all went well, else returns appropriate error value. |
| 1341 | */ |
| 1342 | static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle *handle, |
| 1343 | u32 dev_id, u8 clk_id, u64 min_freq, |
| 1344 | u64 target_freq, u64 max_freq, |
| 1345 | u64 *match_freq) |
| 1346 | { |
| 1347 | struct ti_sci_msg_resp_query_clock_freq *resp; |
| 1348 | struct ti_sci_msg_req_query_clock_freq req; |
| 1349 | struct ti_sci_info *info; |
| 1350 | struct ti_sci_xfer *xfer; |
| 1351 | int ret = 0; |
| 1352 | |
| 1353 | if (IS_ERR(handle)) |
| 1354 | return PTR_ERR(handle); |
| 1355 | if (!handle || !match_freq) |
| 1356 | return -EINVAL; |
| 1357 | |
| 1358 | info = handle_to_ti_sci_info(handle); |
| 1359 | |
| 1360 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_QUERY_CLOCK_FREQ, |
| 1361 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1362 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1363 | if (IS_ERR(xfer)) { |
| 1364 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1365 | return ret; |
| 1366 | } |
| 1367 | req.dev_id = dev_id; |
| 1368 | req.clk_id = clk_id; |
| 1369 | req.min_freq_hz = min_freq; |
| 1370 | req.target_freq_hz = target_freq; |
| 1371 | req.max_freq_hz = max_freq; |
| 1372 | |
| 1373 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1374 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1375 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1376 | |
| 1377 | resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->tx_message.buf; |
| 1378 | |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 1379 | *match_freq = resp->freq_hz; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1380 | |
| 1381 | return ret; |
| 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * ti_sci_cmd_clk_set_freq() - Set a frequency for clock |
| 1386 | * @handle: pointer to TI SCI handle |
| 1387 | * @dev_id: Device identifier this request is for |
| 1388 | * @clk_id: Clock identifier for the device for this request. |
| 1389 | * Each device has it's own set of clock inputs. This indexes |
| 1390 | * which clock input to modify. |
| 1391 | * @min_freq: The minimum allowable frequency in Hz. This is the minimum |
| 1392 | * allowable programmed frequency and does not account for clock |
| 1393 | * tolerances and jitter. |
| 1394 | * @target_freq: The target clock frequency in Hz. A frequency will be |
| 1395 | * processed as close to this target frequency as possible. |
| 1396 | * @max_freq: The maximum allowable frequency in Hz. This is the maximum |
| 1397 | * allowable programmed frequency and does not account for clock |
| 1398 | * tolerances and jitter. |
| 1399 | * |
| 1400 | * Return: 0 if all went well, else returns appropriate error value. |
| 1401 | */ |
| 1402 | static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle *handle, |
| 1403 | u32 dev_id, u8 clk_id, u64 min_freq, |
| 1404 | u64 target_freq, u64 max_freq) |
| 1405 | { |
| 1406 | struct ti_sci_msg_req_set_clock_freq req; |
| 1407 | struct ti_sci_msg_hdr *resp; |
| 1408 | struct ti_sci_info *info; |
| 1409 | struct ti_sci_xfer *xfer; |
| 1410 | int ret = 0; |
| 1411 | |
| 1412 | if (IS_ERR(handle)) |
| 1413 | return PTR_ERR(handle); |
| 1414 | if (!handle) |
| 1415 | return -EINVAL; |
| 1416 | |
| 1417 | info = handle_to_ti_sci_info(handle); |
| 1418 | |
| 1419 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_FREQ, |
| 1420 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1421 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1422 | if (IS_ERR(xfer)) { |
| 1423 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1424 | return ret; |
| 1425 | } |
| 1426 | req.dev_id = dev_id; |
| 1427 | req.clk_id = clk_id; |
| 1428 | req.min_freq_hz = min_freq; |
| 1429 | req.target_freq_hz = target_freq; |
| 1430 | req.max_freq_hz = max_freq; |
| 1431 | |
| 1432 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1433 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1434 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1435 | |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1436 | return ret; |
| 1437 | } |
| 1438 | |
| 1439 | /** |
| 1440 | * ti_sci_cmd_clk_get_freq() - Get current frequency |
| 1441 | * @handle: pointer to TI SCI handle |
| 1442 | * @dev_id: Device identifier this request is for |
| 1443 | * @clk_id: Clock identifier for the device for this request. |
| 1444 | * Each device has it's own set of clock inputs. This indexes |
| 1445 | * which clock input to modify. |
| 1446 | * @freq: Currently frequency in Hz |
| 1447 | * |
| 1448 | * Return: 0 if all went well, else returns appropriate error value. |
| 1449 | */ |
| 1450 | static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle, |
| 1451 | u32 dev_id, u8 clk_id, u64 *freq) |
| 1452 | { |
| 1453 | struct ti_sci_msg_resp_get_clock_freq *resp; |
| 1454 | struct ti_sci_msg_req_get_clock_freq req; |
| 1455 | struct ti_sci_info *info; |
| 1456 | struct ti_sci_xfer *xfer; |
| 1457 | int ret = 0; |
| 1458 | |
| 1459 | if (IS_ERR(handle)) |
| 1460 | return PTR_ERR(handle); |
| 1461 | if (!handle || !freq) |
| 1462 | return -EINVAL; |
| 1463 | |
| 1464 | info = handle_to_ti_sci_info(handle); |
| 1465 | |
| 1466 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_FREQ, |
| 1467 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1468 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1469 | if (IS_ERR(xfer)) { |
| 1470 | ret = PTR_ERR(xfer); |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1471 | return ret; |
| 1472 | } |
| 1473 | req.dev_id = dev_id; |
| 1474 | req.clk_id = clk_id; |
| 1475 | |
| 1476 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1477 | if (ret) |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1478 | return ret; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1479 | |
| 1480 | resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->tx_message.buf; |
| 1481 | |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 1482 | *freq = resp->freq_hz; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 1483 | |
| 1484 | return ret; |
| 1485 | } |
| 1486 | |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 1487 | /** |
| 1488 | * ti_sci_cmd_core_reboot() - Command to request system reset |
| 1489 | * @handle: pointer to TI SCI handle |
| 1490 | * |
| 1491 | * Return: 0 if all went well, else returns appropriate error value. |
| 1492 | */ |
| 1493 | static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle) |
| 1494 | { |
| 1495 | struct ti_sci_msg_req_reboot req; |
| 1496 | struct ti_sci_msg_hdr *resp; |
| 1497 | struct ti_sci_info *info; |
| 1498 | struct ti_sci_xfer *xfer; |
| 1499 | int ret = 0; |
| 1500 | |
| 1501 | if (IS_ERR(handle)) |
| 1502 | return PTR_ERR(handle); |
| 1503 | if (!handle) |
| 1504 | return -EINVAL; |
| 1505 | |
| 1506 | info = handle_to_ti_sci_info(handle); |
| 1507 | |
| 1508 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SYS_RESET, |
| 1509 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1510 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1511 | if (IS_ERR(xfer)) { |
| 1512 | ret = PTR_ERR(xfer); |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 1513 | return ret; |
| 1514 | } |
Dave Gerlach | 366df4e | 2021-05-13 20:10:55 -0500 | [diff] [blame] | 1515 | req.domain = 0; |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 1516 | |
| 1517 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1518 | if (ret) |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 1519 | return ret; |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 1520 | |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 1521 | return ret; |
| 1522 | } |
| 1523 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1524 | /** |
| 1525 | * ti_sci_get_resource_range - Helper to get a range of resources assigned |
| 1526 | * to a host. Resource is uniquely identified by |
| 1527 | * type and subtype. |
| 1528 | * @handle: Pointer to TISCI handle. |
| 1529 | * @dev_id: TISCI device ID. |
| 1530 | * @subtype: Resource assignment subtype that is being requested |
| 1531 | * from the given device. |
| 1532 | * @s_host: Host processor ID to which the resources are allocated |
| 1533 | * @range_start: Start index of the resource range |
| 1534 | * @range_num: Number of resources in the range |
| 1535 | * |
| 1536 | * Return: 0 if all went fine, else return appropriate error. |
| 1537 | */ |
| 1538 | static int ti_sci_get_resource_range(const struct ti_sci_handle *handle, |
| 1539 | u32 dev_id, u8 subtype, u8 s_host, |
| 1540 | u16 *range_start, u16 *range_num) |
| 1541 | { |
| 1542 | struct ti_sci_msg_resp_get_resource_range *resp; |
| 1543 | struct ti_sci_msg_req_get_resource_range req; |
| 1544 | struct ti_sci_xfer *xfer; |
| 1545 | struct ti_sci_info *info; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1546 | int ret = 0; |
| 1547 | |
| 1548 | if (IS_ERR(handle)) |
| 1549 | return PTR_ERR(handle); |
| 1550 | if (!handle) |
| 1551 | return -EINVAL; |
| 1552 | |
| 1553 | info = handle_to_ti_sci_info(handle); |
| 1554 | |
| 1555 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE, |
| 1556 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1557 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1558 | if (IS_ERR(xfer)) { |
| 1559 | ret = PTR_ERR(xfer); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1560 | return ret; |
| 1561 | } |
| 1562 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1563 | req.secondary_host = s_host; |
Lokesh Vutla | 0acf1dc | 2020-08-17 11:00:48 +0530 | [diff] [blame] | 1564 | req.type = dev_id & MSG_RM_RESOURCE_TYPE_MASK; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1565 | req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK; |
| 1566 | |
| 1567 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1568 | if (ret) |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1569 | goto fail; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1570 | |
| 1571 | resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->tx_message.buf; |
Andrew Davis | 04e4393 | 2022-07-25 20:25:06 -0500 | [diff] [blame] | 1572 | if (!resp->range_start && !resp->range_num) { |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1573 | ret = -ENODEV; |
| 1574 | } else { |
| 1575 | *range_start = resp->range_start; |
| 1576 | *range_num = resp->range_num; |
| 1577 | }; |
| 1578 | |
| 1579 | fail: |
| 1580 | return ret; |
| 1581 | } |
| 1582 | |
Vignesh Raghavendra | 4214a81 | 2021-06-07 19:47:48 +0530 | [diff] [blame] | 1583 | static int __maybe_unused |
Vignesh Raghavendra | aa0e3fc | 2021-06-07 19:47:49 +0530 | [diff] [blame] | 1584 | ti_sci_cmd_get_resource_range_static(const struct ti_sci_handle *handle, |
| 1585 | u32 dev_id, u8 subtype, |
| 1586 | u16 *range_start, u16 *range_num) |
Vignesh Raghavendra | 4214a81 | 2021-06-07 19:47:48 +0530 | [diff] [blame] | 1587 | { |
| 1588 | struct ti_sci_resource_static_data *data; |
| 1589 | int i = 0; |
| 1590 | |
| 1591 | while (1) { |
| 1592 | data = &rm_static_data[i]; |
| 1593 | |
| 1594 | if (!data->dev_id) |
| 1595 | return -EINVAL; |
| 1596 | |
| 1597 | if (data->dev_id != dev_id || data->subtype != subtype) { |
| 1598 | i++; |
| 1599 | continue; |
| 1600 | } |
| 1601 | |
| 1602 | *range_start = data->range_start; |
| 1603 | *range_num = data->range_num; |
| 1604 | |
| 1605 | return 0; |
| 1606 | } |
| 1607 | |
| 1608 | return -EINVAL; |
| 1609 | } |
| 1610 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 1611 | /** |
| 1612 | * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host |
| 1613 | * that is same as ti sci interface host. |
| 1614 | * @handle: Pointer to TISCI handle. |
| 1615 | * @dev_id: TISCI device ID. |
| 1616 | * @subtype: Resource assignment subtype that is being requested |
| 1617 | * from the given device. |
| 1618 | * @range_start: Start index of the resource range |
| 1619 | * @range_num: Number of resources in the range |
| 1620 | * |
| 1621 | * Return: 0 if all went fine, else return appropriate error. |
| 1622 | */ |
| 1623 | static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle, |
| 1624 | u32 dev_id, u8 subtype, |
| 1625 | u16 *range_start, u16 *range_num) |
| 1626 | { |
| 1627 | return ti_sci_get_resource_range(handle, dev_id, subtype, |
| 1628 | TI_SCI_IRQ_SECONDARY_HOST_INVALID, |
| 1629 | range_start, range_num); |
| 1630 | } |
| 1631 | |
| 1632 | /** |
| 1633 | * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources |
| 1634 | * assigned to a specified host. |
| 1635 | * @handle: Pointer to TISCI handle. |
| 1636 | * @dev_id: TISCI device ID. |
| 1637 | * @subtype: Resource assignment subtype that is being requested |
| 1638 | * from the given device. |
| 1639 | * @s_host: Host processor ID to which the resources are allocated |
| 1640 | * @range_start: Start index of the resource range |
| 1641 | * @range_num: Number of resources in the range |
| 1642 | * |
| 1643 | * Return: 0 if all went fine, else return appropriate error. |
| 1644 | */ |
| 1645 | static |
| 1646 | int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle, |
| 1647 | u32 dev_id, u8 subtype, u8 s_host, |
| 1648 | u16 *range_start, u16 *range_num) |
| 1649 | { |
| 1650 | return ti_sci_get_resource_range(handle, dev_id, subtype, s_host, |
| 1651 | range_start, range_num); |
| 1652 | } |
| 1653 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1654 | /** |
Lokesh Vutla | 032dce8 | 2019-03-08 11:47:32 +0530 | [diff] [blame] | 1655 | * ti_sci_cmd_query_msmc() - Command to query currently available msmc memory |
| 1656 | * @handle: pointer to TI SCI handle |
| 1657 | * @msms_start: MSMC start as returned by tisci |
| 1658 | * @msmc_end: MSMC end as returned by tisci |
| 1659 | * |
| 1660 | * Return: 0 if all went well, else returns appropriate error value. |
| 1661 | */ |
| 1662 | static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle, |
| 1663 | u64 *msmc_start, u64 *msmc_end) |
| 1664 | { |
| 1665 | struct ti_sci_msg_resp_query_msmc *resp; |
| 1666 | struct ti_sci_msg_hdr req; |
| 1667 | struct ti_sci_info *info; |
| 1668 | struct ti_sci_xfer *xfer; |
| 1669 | int ret = 0; |
| 1670 | |
| 1671 | if (IS_ERR(handle)) |
| 1672 | return PTR_ERR(handle); |
| 1673 | if (!handle) |
| 1674 | return -EINVAL; |
| 1675 | |
| 1676 | info = handle_to_ti_sci_info(handle); |
| 1677 | |
| 1678 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_QUERY_MSMC, |
| 1679 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1680 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1681 | if (IS_ERR(xfer)) { |
| 1682 | ret = PTR_ERR(xfer); |
Lokesh Vutla | 032dce8 | 2019-03-08 11:47:32 +0530 | [diff] [blame] | 1683 | return ret; |
| 1684 | } |
| 1685 | |
| 1686 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1687 | if (ret) |
Lokesh Vutla | 032dce8 | 2019-03-08 11:47:32 +0530 | [diff] [blame] | 1688 | return ret; |
Lokesh Vutla | 032dce8 | 2019-03-08 11:47:32 +0530 | [diff] [blame] | 1689 | |
| 1690 | resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf; |
| 1691 | |
Lokesh Vutla | 032dce8 | 2019-03-08 11:47:32 +0530 | [diff] [blame] | 1692 | *msmc_start = ((u64)resp->msmc_start_high << TISCI_ADDR_HIGH_SHIFT) | |
| 1693 | resp->msmc_start_low; |
| 1694 | *msmc_end = ((u64)resp->msmc_end_high << TISCI_ADDR_HIGH_SHIFT) | |
| 1695 | resp->msmc_end_low; |
| 1696 | |
| 1697 | return ret; |
| 1698 | } |
| 1699 | |
| 1700 | /** |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1701 | * ti_sci_cmd_proc_request() - Command to request a physical processor control |
| 1702 | * @handle: Pointer to TI SCI handle |
| 1703 | * @proc_id: Processor ID this request is for |
| 1704 | * |
| 1705 | * Return: 0 if all went well, else returns appropriate error value. |
| 1706 | */ |
| 1707 | static int ti_sci_cmd_proc_request(const struct ti_sci_handle *handle, |
| 1708 | u8 proc_id) |
| 1709 | { |
| 1710 | struct ti_sci_msg_req_proc_request req; |
| 1711 | struct ti_sci_msg_hdr *resp; |
| 1712 | struct ti_sci_info *info; |
| 1713 | struct ti_sci_xfer *xfer; |
| 1714 | int ret = 0; |
| 1715 | |
| 1716 | if (IS_ERR(handle)) |
| 1717 | return PTR_ERR(handle); |
| 1718 | if (!handle) |
| 1719 | return -EINVAL; |
| 1720 | |
| 1721 | info = handle_to_ti_sci_info(handle); |
| 1722 | |
| 1723 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_REQUEST, |
| 1724 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1725 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1726 | if (IS_ERR(xfer)) { |
| 1727 | ret = PTR_ERR(xfer); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1728 | return ret; |
| 1729 | } |
| 1730 | req.processor_id = proc_id; |
| 1731 | |
| 1732 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1733 | if (ret) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1734 | return ret; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1735 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1736 | return ret; |
| 1737 | } |
| 1738 | |
| 1739 | /** |
| 1740 | * ti_sci_cmd_proc_release() - Command to release a physical processor control |
| 1741 | * @handle: Pointer to TI SCI handle |
| 1742 | * @proc_id: Processor ID this request is for |
| 1743 | * |
| 1744 | * Return: 0 if all went well, else returns appropriate error value. |
| 1745 | */ |
| 1746 | static int ti_sci_cmd_proc_release(const struct ti_sci_handle *handle, |
| 1747 | u8 proc_id) |
| 1748 | { |
| 1749 | struct ti_sci_msg_req_proc_release req; |
| 1750 | struct ti_sci_msg_hdr *resp; |
| 1751 | struct ti_sci_info *info; |
| 1752 | struct ti_sci_xfer *xfer; |
| 1753 | int ret = 0; |
| 1754 | |
| 1755 | if (IS_ERR(handle)) |
| 1756 | return PTR_ERR(handle); |
| 1757 | if (!handle) |
| 1758 | return -EINVAL; |
| 1759 | |
| 1760 | info = handle_to_ti_sci_info(handle); |
| 1761 | |
| 1762 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_RELEASE, |
| 1763 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1764 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1765 | if (IS_ERR(xfer)) { |
| 1766 | ret = PTR_ERR(xfer); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1767 | return ret; |
| 1768 | } |
| 1769 | req.processor_id = proc_id; |
| 1770 | |
| 1771 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1772 | if (ret) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1773 | return ret; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1774 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1775 | return ret; |
| 1776 | } |
| 1777 | |
| 1778 | /** |
| 1779 | * ti_sci_cmd_proc_handover() - Command to handover a physical processor |
| 1780 | * control to a host in the processor's access |
| 1781 | * control list. |
| 1782 | * @handle: Pointer to TI SCI handle |
| 1783 | * @proc_id: Processor ID this request is for |
| 1784 | * @host_id: Host ID to get the control of the processor |
| 1785 | * |
| 1786 | * Return: 0 if all went well, else returns appropriate error value. |
| 1787 | */ |
| 1788 | static int ti_sci_cmd_proc_handover(const struct ti_sci_handle *handle, |
| 1789 | u8 proc_id, u8 host_id) |
| 1790 | { |
| 1791 | struct ti_sci_msg_req_proc_handover req; |
| 1792 | struct ti_sci_msg_hdr *resp; |
| 1793 | struct ti_sci_info *info; |
| 1794 | struct ti_sci_xfer *xfer; |
| 1795 | int ret = 0; |
| 1796 | |
| 1797 | if (IS_ERR(handle)) |
| 1798 | return PTR_ERR(handle); |
| 1799 | if (!handle) |
| 1800 | return -EINVAL; |
| 1801 | |
| 1802 | info = handle_to_ti_sci_info(handle); |
| 1803 | |
| 1804 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_HANDOVER, |
| 1805 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1806 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1807 | if (IS_ERR(xfer)) { |
| 1808 | ret = PTR_ERR(xfer); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1809 | return ret; |
| 1810 | } |
| 1811 | req.processor_id = proc_id; |
| 1812 | req.host_id = host_id; |
| 1813 | |
| 1814 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1815 | if (ret) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1816 | return ret; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1817 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1818 | return ret; |
| 1819 | } |
| 1820 | |
| 1821 | /** |
| 1822 | * ti_sci_cmd_set_proc_boot_cfg() - Command to set the processor boot |
| 1823 | * configuration flags |
| 1824 | * @handle: Pointer to TI SCI handle |
| 1825 | * @proc_id: Processor ID this request is for |
| 1826 | * @config_flags_set: Configuration flags to be set |
| 1827 | * @config_flags_clear: Configuration flags to be cleared. |
| 1828 | * |
| 1829 | * Return: 0 if all went well, else returns appropriate error value. |
| 1830 | */ |
| 1831 | static int ti_sci_cmd_set_proc_boot_cfg(const struct ti_sci_handle *handle, |
| 1832 | u8 proc_id, u64 bootvector, |
| 1833 | u32 config_flags_set, |
| 1834 | u32 config_flags_clear) |
| 1835 | { |
| 1836 | struct ti_sci_msg_req_set_proc_boot_config req; |
| 1837 | struct ti_sci_msg_hdr *resp; |
| 1838 | struct ti_sci_info *info; |
| 1839 | struct ti_sci_xfer *xfer; |
| 1840 | int ret = 0; |
| 1841 | |
| 1842 | if (IS_ERR(handle)) |
| 1843 | return PTR_ERR(handle); |
| 1844 | if (!handle) |
| 1845 | return -EINVAL; |
| 1846 | |
| 1847 | info = handle_to_ti_sci_info(handle); |
| 1848 | |
| 1849 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CONFIG, |
| 1850 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1851 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1852 | if (IS_ERR(xfer)) { |
| 1853 | ret = PTR_ERR(xfer); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1854 | return ret; |
| 1855 | } |
| 1856 | req.processor_id = proc_id; |
| 1857 | req.bootvector_low = bootvector & TISCI_ADDR_LOW_MASK; |
| 1858 | req.bootvector_high = (bootvector & TISCI_ADDR_HIGH_MASK) >> |
| 1859 | TISCI_ADDR_HIGH_SHIFT; |
| 1860 | req.config_flags_set = config_flags_set; |
| 1861 | req.config_flags_clear = config_flags_clear; |
| 1862 | |
| 1863 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1864 | if (ret) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1865 | return ret; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1866 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1867 | return ret; |
| 1868 | } |
| 1869 | |
| 1870 | /** |
| 1871 | * ti_sci_cmd_set_proc_boot_ctrl() - Command to set the processor boot |
| 1872 | * control flags |
| 1873 | * @handle: Pointer to TI SCI handle |
| 1874 | * @proc_id: Processor ID this request is for |
| 1875 | * @control_flags_set: Control flags to be set |
| 1876 | * @control_flags_clear: Control flags to be cleared |
| 1877 | * |
| 1878 | * Return: 0 if all went well, else returns appropriate error value. |
| 1879 | */ |
| 1880 | static int ti_sci_cmd_set_proc_boot_ctrl(const struct ti_sci_handle *handle, |
| 1881 | u8 proc_id, u32 control_flags_set, |
| 1882 | u32 control_flags_clear) |
| 1883 | { |
| 1884 | struct ti_sci_msg_req_set_proc_boot_ctrl req; |
| 1885 | struct ti_sci_msg_hdr *resp; |
| 1886 | struct ti_sci_info *info; |
| 1887 | struct ti_sci_xfer *xfer; |
| 1888 | int ret = 0; |
| 1889 | |
| 1890 | if (IS_ERR(handle)) |
| 1891 | return PTR_ERR(handle); |
| 1892 | if (!handle) |
| 1893 | return -EINVAL; |
| 1894 | |
| 1895 | info = handle_to_ti_sci_info(handle); |
| 1896 | |
| 1897 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CTRL, |
| 1898 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1899 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1900 | if (IS_ERR(xfer)) { |
| 1901 | ret = PTR_ERR(xfer); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1902 | return ret; |
| 1903 | } |
| 1904 | req.processor_id = proc_id; |
| 1905 | req.control_flags_set = control_flags_set; |
| 1906 | req.control_flags_clear = control_flags_clear; |
| 1907 | |
| 1908 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1909 | if (ret) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1910 | return ret; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1911 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1912 | return ret; |
| 1913 | } |
| 1914 | |
| 1915 | /** |
| 1916 | * ti_sci_cmd_proc_auth_boot_image() - Command to authenticate and load the |
| 1917 | * image and then set the processor configuration flags. |
| 1918 | * @handle: Pointer to TI SCI handle |
Andrew F. Davis | 7aa9a08 | 2019-04-12 12:54:44 -0400 | [diff] [blame] | 1919 | * @image_addr: Memory address at which payload image and certificate is |
| 1920 | * located in memory, this is updated if the image data is |
| 1921 | * moved during authentication. |
| 1922 | * @image_size: This is updated with the final size of the image after |
| 1923 | * authentication. |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1924 | * |
| 1925 | * Return: 0 if all went well, else returns appropriate error value. |
| 1926 | */ |
| 1927 | static int ti_sci_cmd_proc_auth_boot_image(const struct ti_sci_handle *handle, |
Andrew F. Davis | 7aa9a08 | 2019-04-12 12:54:44 -0400 | [diff] [blame] | 1928 | u64 *image_addr, u32 *image_size) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1929 | { |
| 1930 | struct ti_sci_msg_req_proc_auth_boot_image req; |
Andrew F. Davis | 7aa9a08 | 2019-04-12 12:54:44 -0400 | [diff] [blame] | 1931 | struct ti_sci_msg_resp_proc_auth_boot_image *resp; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1932 | struct ti_sci_info *info; |
| 1933 | struct ti_sci_xfer *xfer; |
| 1934 | int ret = 0; |
| 1935 | |
| 1936 | if (IS_ERR(handle)) |
| 1937 | return PTR_ERR(handle); |
| 1938 | if (!handle) |
| 1939 | return -EINVAL; |
| 1940 | |
| 1941 | info = handle_to_ti_sci_info(handle); |
| 1942 | |
Jorge Ramirez-Ortiz | b037328 | 2023-01-10 18:29:48 +0100 | [diff] [blame] | 1943 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_AUTH_BOOT_IMAGE, |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1944 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1945 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1946 | if (IS_ERR(xfer)) { |
| 1947 | ret = PTR_ERR(xfer); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1948 | return ret; |
| 1949 | } |
Andrew F. Davis | 7aa9a08 | 2019-04-12 12:54:44 -0400 | [diff] [blame] | 1950 | req.cert_addr_low = *image_addr & TISCI_ADDR_LOW_MASK; |
| 1951 | req.cert_addr_high = (*image_addr & TISCI_ADDR_HIGH_MASK) >> |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1952 | TISCI_ADDR_HIGH_SHIFT; |
| 1953 | |
| 1954 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 1955 | if (ret) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1956 | return ret; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1957 | |
Andrew F. Davis | 7aa9a08 | 2019-04-12 12:54:44 -0400 | [diff] [blame] | 1958 | resp = (struct ti_sci_msg_resp_proc_auth_boot_image *)xfer->tx_message.buf; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1959 | |
Andrew F. Davis | 7aa9a08 | 2019-04-12 12:54:44 -0400 | [diff] [blame] | 1960 | *image_addr = (resp->image_addr_low & TISCI_ADDR_LOW_MASK) | |
| 1961 | (((u64)resp->image_addr_high << |
| 1962 | TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK); |
| 1963 | *image_size = resp->image_size; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1964 | |
| 1965 | return ret; |
| 1966 | } |
| 1967 | |
| 1968 | /** |
| 1969 | * ti_sci_cmd_get_proc_boot_status() - Command to get the processor boot status |
| 1970 | * @handle: Pointer to TI SCI handle |
| 1971 | * @proc_id: Processor ID this request is for |
| 1972 | * |
| 1973 | * Return: 0 if all went well, else returns appropriate error value. |
| 1974 | */ |
| 1975 | static int ti_sci_cmd_get_proc_boot_status(const struct ti_sci_handle *handle, |
| 1976 | u8 proc_id, u64 *bv, u32 *cfg_flags, |
| 1977 | u32 *ctrl_flags, u32 *sts_flags) |
| 1978 | { |
| 1979 | struct ti_sci_msg_resp_get_proc_boot_status *resp; |
| 1980 | struct ti_sci_msg_req_get_proc_boot_status req; |
| 1981 | struct ti_sci_info *info; |
| 1982 | struct ti_sci_xfer *xfer; |
| 1983 | int ret = 0; |
| 1984 | |
| 1985 | if (IS_ERR(handle)) |
| 1986 | return PTR_ERR(handle); |
| 1987 | if (!handle) |
| 1988 | return -EINVAL; |
| 1989 | |
| 1990 | info = handle_to_ti_sci_info(handle); |
| 1991 | |
| 1992 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_GET_PROC_BOOT_STATUS, |
| 1993 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 1994 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 1995 | if (IS_ERR(xfer)) { |
| 1996 | ret = PTR_ERR(xfer); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 1997 | return ret; |
| 1998 | } |
| 1999 | req.processor_id = proc_id; |
| 2000 | |
| 2001 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2002 | if (ret) |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 2003 | return ret; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 2004 | |
| 2005 | resp = (struct ti_sci_msg_resp_get_proc_boot_status *) |
| 2006 | xfer->tx_message.buf; |
| 2007 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 2008 | *bv = (resp->bootvector_low & TISCI_ADDR_LOW_MASK) | |
| 2009 | (((u64)resp->bootvector_high << |
| 2010 | TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK); |
| 2011 | *cfg_flags = resp->config_flags; |
| 2012 | *ctrl_flags = resp->control_flags; |
| 2013 | *sts_flags = resp->status_flags; |
| 2014 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2015 | return ret; |
| 2016 | } |
| 2017 | |
| 2018 | /** |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 2019 | * ti_sci_proc_wait_boot_status_no_wait() - Helper function to wait for a |
| 2020 | * processor boot status without requesting or |
| 2021 | * waiting for a response. |
| 2022 | * @proc_id: Processor ID this request is for |
| 2023 | * @num_wait_iterations: Total number of iterations we will check before |
| 2024 | * we will timeout and give up |
| 2025 | * @num_match_iterations: How many iterations should we have continued |
| 2026 | * status to account for status bits glitching. |
| 2027 | * This is to make sure that match occurs for |
| 2028 | * consecutive checks. This implies that the |
| 2029 | * worst case should consider that the stable |
| 2030 | * time should at the worst be num_wait_iterations |
| 2031 | * num_match_iterations to prevent timeout. |
| 2032 | * @delay_per_iteration_us: Specifies how long to wait (in micro seconds) |
| 2033 | * between each status checks. This is the minimum |
| 2034 | * duration, and overhead of register reads and |
| 2035 | * checks are on top of this and can vary based on |
| 2036 | * varied conditions. |
| 2037 | * @delay_before_iterations_us: Specifies how long to wait (in micro seconds) |
| 2038 | * before the very first check in the first |
| 2039 | * iteration of status check loop. This is the |
| 2040 | * minimum duration, and overhead of register |
| 2041 | * reads and checks are. |
| 2042 | * @status_flags_1_set_all_wait:If non-zero, Specifies that all bits of the |
| 2043 | * status matching this field requested MUST be 1. |
| 2044 | * @status_flags_1_set_any_wait:If non-zero, Specifies that at least one of the |
| 2045 | * bits matching this field requested MUST be 1. |
| 2046 | * @status_flags_1_clr_all_wait:If non-zero, Specifies that all bits of the |
| 2047 | * status matching this field requested MUST be 0. |
| 2048 | * @status_flags_1_clr_any_wait:If non-zero, Specifies that at least one of the |
| 2049 | * bits matching this field requested MUST be 0. |
| 2050 | * |
| 2051 | * Return: 0 if all goes well, else appropriate error message |
| 2052 | */ |
| 2053 | static int |
| 2054 | ti_sci_proc_wait_boot_status_no_wait(const struct ti_sci_handle *handle, |
| 2055 | u8 proc_id, |
| 2056 | u8 num_wait_iterations, |
| 2057 | u8 num_match_iterations, |
| 2058 | u8 delay_per_iteration_us, |
| 2059 | u8 delay_before_iterations_us, |
| 2060 | u32 status_flags_1_set_all_wait, |
| 2061 | u32 status_flags_1_set_any_wait, |
| 2062 | u32 status_flags_1_clr_all_wait, |
| 2063 | u32 status_flags_1_clr_any_wait) |
| 2064 | { |
| 2065 | struct ti_sci_msg_req_wait_proc_boot_status req; |
| 2066 | struct ti_sci_info *info; |
| 2067 | struct ti_sci_xfer *xfer; |
| 2068 | int ret = 0; |
| 2069 | |
| 2070 | if (IS_ERR(handle)) |
| 2071 | return PTR_ERR(handle); |
| 2072 | if (!handle) |
| 2073 | return -EINVAL; |
| 2074 | |
| 2075 | info = handle_to_ti_sci_info(handle); |
| 2076 | |
| 2077 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_WAIT_PROC_BOOT_STATUS, |
| 2078 | TI_SCI_FLAG_REQ_GENERIC_NORESPONSE, |
| 2079 | (u32 *)&req, sizeof(req), 0); |
| 2080 | if (IS_ERR(xfer)) { |
| 2081 | ret = PTR_ERR(xfer); |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 2082 | return ret; |
| 2083 | } |
| 2084 | req.processor_id = proc_id; |
| 2085 | req.num_wait_iterations = num_wait_iterations; |
| 2086 | req.num_match_iterations = num_match_iterations; |
| 2087 | req.delay_per_iteration_us = delay_per_iteration_us; |
| 2088 | req.delay_before_iterations_us = delay_before_iterations_us; |
| 2089 | req.status_flags_1_set_all_wait = status_flags_1_set_all_wait; |
| 2090 | req.status_flags_1_set_any_wait = status_flags_1_set_any_wait; |
| 2091 | req.status_flags_1_clr_all_wait = status_flags_1_clr_all_wait; |
| 2092 | req.status_flags_1_clr_any_wait = status_flags_1_clr_any_wait; |
| 2093 | |
| 2094 | ret = ti_sci_do_xfer(info, xfer); |
| 2095 | if (ret) |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2096 | return ret; |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 2097 | |
| 2098 | return ret; |
| 2099 | } |
| 2100 | |
| 2101 | /** |
| 2102 | * ti_sci_cmd_proc_shutdown_no_wait() - Command to shutdown a core without |
| 2103 | * requesting or waiting for a response. Note that this API call |
| 2104 | * should be followed by placing the respective processor into |
| 2105 | * either WFE or WFI mode. |
| 2106 | * @handle: Pointer to TI SCI handle |
| 2107 | * @proc_id: Processor ID this request is for |
| 2108 | * |
| 2109 | * Return: 0 if all went well, else returns appropriate error value. |
| 2110 | */ |
| 2111 | static int ti_sci_cmd_proc_shutdown_no_wait(const struct ti_sci_handle *handle, |
| 2112 | u8 proc_id) |
| 2113 | { |
| 2114 | int ret; |
Sean Anderson | 405dc24 | 2020-09-15 10:44:38 -0400 | [diff] [blame] | 2115 | struct ti_sci_info *info; |
| 2116 | |
| 2117 | if (IS_ERR(handle)) |
| 2118 | return PTR_ERR(handle); |
| 2119 | if (!handle) |
| 2120 | return -EINVAL; |
| 2121 | |
| 2122 | info = handle_to_ti_sci_info(handle); |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 2123 | |
| 2124 | /* |
| 2125 | * Send the core boot status wait message waiting for either WFE or |
| 2126 | * WFI without requesting or waiting for a TISCI response with the |
| 2127 | * maximum wait time to give us the best chance to get to the WFE/WFI |
| 2128 | * command that should follow the invocation of this API before the |
| 2129 | * DMSC-internal processing of this command times out. Note that |
| 2130 | * waiting for the R5 WFE/WFI flags will also work on an ARMV8 type |
| 2131 | * core as the related flag bit positions are the same. |
| 2132 | */ |
| 2133 | ret = ti_sci_proc_wait_boot_status_no_wait(handle, proc_id, |
| 2134 | U8_MAX, 100, U8_MAX, U8_MAX, |
| 2135 | 0, PROC_BOOT_STATUS_FLAG_R5_WFE | PROC_BOOT_STATUS_FLAG_R5_WFI, |
| 2136 | 0, 0); |
| 2137 | if (ret) { |
| 2138 | dev_err(info->dev, "Sending core %u wait message fail %d\n", |
| 2139 | proc_id, ret); |
| 2140 | return ret; |
| 2141 | } |
| 2142 | |
| 2143 | /* |
| 2144 | * Release a processor managed by TISCI without requesting or waiting |
| 2145 | * for a response. |
| 2146 | */ |
| 2147 | ret = ti_sci_set_device_state_no_wait(handle, proc_id, 0, |
| 2148 | MSG_DEVICE_SW_STATE_AUTO_OFF); |
| 2149 | if (ret) |
| 2150 | dev_err(info->dev, "Sending core %u shutdown message fail %d\n", |
| 2151 | proc_id, ret); |
| 2152 | |
| 2153 | return ret; |
| 2154 | } |
| 2155 | |
| 2156 | /** |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2157 | * ti_sci_cmd_ring_config() - configure RA ring |
| 2158 | * @handle: pointer to TI SCI handle |
| 2159 | * @valid_params: Bitfield defining validity of ring configuration parameters. |
| 2160 | * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated |
| 2161 | * @index: Ring index. |
| 2162 | * @addr_lo: The ring base address lo 32 bits |
| 2163 | * @addr_hi: The ring base address hi 32 bits |
| 2164 | * @count: Number of ring elements. |
| 2165 | * @mode: The mode of the ring |
| 2166 | * @size: The ring element size. |
| 2167 | * @order_id: Specifies the ring's bus order ID. |
| 2168 | * |
| 2169 | * Return: 0 if all went well, else returns appropriate error value. |
| 2170 | * |
| 2171 | * See @ti_sci_msg_rm_ring_cfg_req for more info. |
| 2172 | */ |
| 2173 | static int ti_sci_cmd_ring_config(const struct ti_sci_handle *handle, |
| 2174 | u32 valid_params, u16 nav_id, u16 index, |
| 2175 | u32 addr_lo, u32 addr_hi, u32 count, |
| 2176 | u8 mode, u8 size, u8 order_id) |
| 2177 | { |
| 2178 | struct ti_sci_msg_rm_ring_cfg_resp *resp; |
| 2179 | struct ti_sci_msg_rm_ring_cfg_req req; |
| 2180 | struct ti_sci_xfer *xfer; |
| 2181 | struct ti_sci_info *info; |
| 2182 | int ret = 0; |
| 2183 | |
| 2184 | if (IS_ERR(handle)) |
| 2185 | return PTR_ERR(handle); |
| 2186 | if (!handle) |
| 2187 | return -EINVAL; |
| 2188 | |
| 2189 | info = handle_to_ti_sci_info(handle); |
| 2190 | |
| 2191 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_CFG, |
| 2192 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2193 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2194 | if (IS_ERR(xfer)) { |
| 2195 | ret = PTR_ERR(xfer); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2196 | return ret; |
| 2197 | } |
| 2198 | req.valid_params = valid_params; |
| 2199 | req.nav_id = nav_id; |
| 2200 | req.index = index; |
| 2201 | req.addr_lo = addr_lo; |
| 2202 | req.addr_hi = addr_hi; |
| 2203 | req.count = count; |
| 2204 | req.mode = mode; |
| 2205 | req.size = size; |
| 2206 | req.order_id = order_id; |
| 2207 | |
| 2208 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2209 | if (ret) |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2210 | goto fail; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2211 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2212 | fail: |
| 2213 | dev_dbg(info->dev, "RM_RA:config ring %u ret:%d\n", index, ret); |
| 2214 | return ret; |
| 2215 | } |
| 2216 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2217 | static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle *handle, |
| 2218 | u32 nav_id, u32 src_thread, u32 dst_thread) |
| 2219 | { |
| 2220 | struct ti_sci_msg_hdr *resp; |
| 2221 | struct ti_sci_msg_psil_pair req; |
| 2222 | struct ti_sci_xfer *xfer; |
| 2223 | struct ti_sci_info *info; |
| 2224 | int ret = 0; |
| 2225 | |
| 2226 | if (IS_ERR(handle)) |
| 2227 | return PTR_ERR(handle); |
| 2228 | if (!handle) |
| 2229 | return -EINVAL; |
| 2230 | |
| 2231 | info = handle_to_ti_sci_info(handle); |
| 2232 | |
| 2233 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_PAIR, |
| 2234 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2235 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2236 | if (IS_ERR(xfer)) { |
| 2237 | ret = PTR_ERR(xfer); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2238 | return ret; |
| 2239 | } |
| 2240 | req.nav_id = nav_id; |
| 2241 | req.src_thread = src_thread; |
| 2242 | req.dst_thread = dst_thread; |
| 2243 | |
| 2244 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2245 | if (ret) |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2246 | goto fail; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2247 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2248 | fail: |
| 2249 | dev_dbg(info->dev, "RM_PSIL: nav: %u link pair %u->%u ret:%u\n", |
| 2250 | nav_id, src_thread, dst_thread, ret); |
| 2251 | return ret; |
| 2252 | } |
| 2253 | |
| 2254 | static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle *handle, |
| 2255 | u32 nav_id, u32 src_thread, u32 dst_thread) |
| 2256 | { |
| 2257 | struct ti_sci_msg_hdr *resp; |
| 2258 | struct ti_sci_msg_psil_unpair req; |
| 2259 | struct ti_sci_xfer *xfer; |
| 2260 | struct ti_sci_info *info; |
| 2261 | int ret = 0; |
| 2262 | |
| 2263 | if (IS_ERR(handle)) |
| 2264 | return PTR_ERR(handle); |
| 2265 | if (!handle) |
| 2266 | return -EINVAL; |
| 2267 | |
| 2268 | info = handle_to_ti_sci_info(handle); |
| 2269 | |
| 2270 | xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_UNPAIR, |
| 2271 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2272 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2273 | if (IS_ERR(xfer)) { |
| 2274 | ret = PTR_ERR(xfer); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2275 | return ret; |
| 2276 | } |
| 2277 | req.nav_id = nav_id; |
| 2278 | req.src_thread = src_thread; |
| 2279 | req.dst_thread = dst_thread; |
| 2280 | |
| 2281 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2282 | if (ret) |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2283 | goto fail; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2284 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2285 | fail: |
| 2286 | dev_dbg(info->dev, "RM_PSIL: link unpair %u->%u ret:%u\n", |
| 2287 | src_thread, dst_thread, ret); |
| 2288 | return ret; |
| 2289 | } |
| 2290 | |
| 2291 | static int ti_sci_cmd_rm_udmap_tx_ch_cfg( |
| 2292 | const struct ti_sci_handle *handle, |
| 2293 | const struct ti_sci_msg_rm_udmap_tx_ch_cfg *params) |
| 2294 | { |
| 2295 | struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *resp; |
| 2296 | struct ti_sci_msg_rm_udmap_tx_ch_cfg_req req; |
| 2297 | struct ti_sci_xfer *xfer; |
| 2298 | struct ti_sci_info *info; |
| 2299 | int ret = 0; |
| 2300 | |
| 2301 | if (IS_ERR(handle)) |
| 2302 | return PTR_ERR(handle); |
| 2303 | if (!handle) |
| 2304 | return -EINVAL; |
| 2305 | |
| 2306 | info = handle_to_ti_sci_info(handle); |
| 2307 | |
| 2308 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_TX_CH_CFG, |
| 2309 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2310 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2311 | if (IS_ERR(xfer)) { |
| 2312 | ret = PTR_ERR(xfer); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2313 | return ret; |
| 2314 | } |
| 2315 | req.valid_params = params->valid_params; |
| 2316 | req.nav_id = params->nav_id; |
| 2317 | req.index = params->index; |
| 2318 | req.tx_pause_on_err = params->tx_pause_on_err; |
| 2319 | req.tx_filt_einfo = params->tx_filt_einfo; |
| 2320 | req.tx_filt_pswords = params->tx_filt_pswords; |
| 2321 | req.tx_atype = params->tx_atype; |
| 2322 | req.tx_chan_type = params->tx_chan_type; |
| 2323 | req.tx_supr_tdpkt = params->tx_supr_tdpkt; |
| 2324 | req.tx_fetch_size = params->tx_fetch_size; |
| 2325 | req.tx_credit_count = params->tx_credit_count; |
| 2326 | req.txcq_qnum = params->txcq_qnum; |
| 2327 | req.tx_priority = params->tx_priority; |
| 2328 | req.tx_qos = params->tx_qos; |
| 2329 | req.tx_orderid = params->tx_orderid; |
| 2330 | req.fdepth = params->fdepth; |
| 2331 | req.tx_sched_priority = params->tx_sched_priority; |
Vignesh Raghavendra | a8a2b8a | 2021-05-10 20:06:02 +0530 | [diff] [blame] | 2332 | req.tx_burst_size = params->tx_burst_size; |
| 2333 | req.tx_tdtype = params->tx_tdtype; |
| 2334 | req.extended_ch_type = params->extended_ch_type; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2335 | |
| 2336 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2337 | if (ret) |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2338 | goto fail; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2339 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2340 | fail: |
| 2341 | dev_dbg(info->dev, "TX_CH_CFG: chn %u ret:%u\n", params->index, ret); |
| 2342 | return ret; |
| 2343 | } |
| 2344 | |
| 2345 | static int ti_sci_cmd_rm_udmap_rx_ch_cfg( |
| 2346 | const struct ti_sci_handle *handle, |
| 2347 | const struct ti_sci_msg_rm_udmap_rx_ch_cfg *params) |
| 2348 | { |
| 2349 | struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *resp; |
| 2350 | struct ti_sci_msg_rm_udmap_rx_ch_cfg_req req; |
| 2351 | struct ti_sci_xfer *xfer; |
| 2352 | struct ti_sci_info *info; |
| 2353 | int ret = 0; |
| 2354 | |
| 2355 | if (IS_ERR(handle)) |
| 2356 | return PTR_ERR(handle); |
| 2357 | if (!handle) |
| 2358 | return -EINVAL; |
| 2359 | |
| 2360 | info = handle_to_ti_sci_info(handle); |
| 2361 | |
| 2362 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_RX_CH_CFG, |
| 2363 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2364 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2365 | if (IS_ERR(xfer)) { |
| 2366 | ret = PTR_ERR(xfer); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2367 | return ret; |
| 2368 | } |
| 2369 | |
| 2370 | req.valid_params = params->valid_params; |
| 2371 | req.nav_id = params->nav_id; |
| 2372 | req.index = params->index; |
| 2373 | req.rx_fetch_size = params->rx_fetch_size; |
| 2374 | req.rxcq_qnum = params->rxcq_qnum; |
| 2375 | req.rx_priority = params->rx_priority; |
| 2376 | req.rx_qos = params->rx_qos; |
| 2377 | req.rx_orderid = params->rx_orderid; |
| 2378 | req.rx_sched_priority = params->rx_sched_priority; |
| 2379 | req.flowid_start = params->flowid_start; |
| 2380 | req.flowid_cnt = params->flowid_cnt; |
| 2381 | req.rx_pause_on_err = params->rx_pause_on_err; |
| 2382 | req.rx_atype = params->rx_atype; |
| 2383 | req.rx_chan_type = params->rx_chan_type; |
| 2384 | req.rx_ignore_short = params->rx_ignore_short; |
| 2385 | req.rx_ignore_long = params->rx_ignore_long; |
| 2386 | |
| 2387 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2388 | if (ret) |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2389 | goto fail; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2390 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2391 | fail: |
| 2392 | dev_dbg(info->dev, "RX_CH_CFG: chn %u ret:%d\n", params->index, ret); |
| 2393 | return ret; |
| 2394 | } |
| 2395 | |
| 2396 | static int ti_sci_cmd_rm_udmap_rx_flow_cfg( |
| 2397 | const struct ti_sci_handle *handle, |
| 2398 | const struct ti_sci_msg_rm_udmap_flow_cfg *params) |
| 2399 | { |
| 2400 | struct ti_sci_msg_rm_udmap_flow_cfg_resp *resp; |
| 2401 | struct ti_sci_msg_rm_udmap_flow_cfg_req req; |
| 2402 | struct ti_sci_xfer *xfer; |
| 2403 | struct ti_sci_info *info; |
| 2404 | int ret = 0; |
| 2405 | |
| 2406 | if (IS_ERR(handle)) |
| 2407 | return PTR_ERR(handle); |
| 2408 | if (!handle) |
| 2409 | return -EINVAL; |
| 2410 | |
| 2411 | info = handle_to_ti_sci_info(handle); |
| 2412 | |
| 2413 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_FLOW_CFG, |
| 2414 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2415 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2416 | if (IS_ERR(xfer)) { |
| 2417 | ret = PTR_ERR(xfer); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2418 | return ret; |
| 2419 | } |
| 2420 | |
| 2421 | req.valid_params = params->valid_params; |
| 2422 | req.nav_id = params->nav_id; |
| 2423 | req.flow_index = params->flow_index; |
| 2424 | req.rx_einfo_present = params->rx_einfo_present; |
| 2425 | req.rx_psinfo_present = params->rx_psinfo_present; |
| 2426 | req.rx_error_handling = params->rx_error_handling; |
| 2427 | req.rx_desc_type = params->rx_desc_type; |
| 2428 | req.rx_sop_offset = params->rx_sop_offset; |
| 2429 | req.rx_dest_qnum = params->rx_dest_qnum; |
| 2430 | req.rx_src_tag_hi = params->rx_src_tag_hi; |
| 2431 | req.rx_src_tag_lo = params->rx_src_tag_lo; |
| 2432 | req.rx_dest_tag_hi = params->rx_dest_tag_hi; |
| 2433 | req.rx_dest_tag_lo = params->rx_dest_tag_lo; |
| 2434 | req.rx_src_tag_hi_sel = params->rx_src_tag_hi_sel; |
| 2435 | req.rx_src_tag_lo_sel = params->rx_src_tag_lo_sel; |
| 2436 | req.rx_dest_tag_hi_sel = params->rx_dest_tag_hi_sel; |
| 2437 | req.rx_dest_tag_lo_sel = params->rx_dest_tag_lo_sel; |
| 2438 | req.rx_fdq0_sz0_qnum = params->rx_fdq0_sz0_qnum; |
| 2439 | req.rx_fdq1_qnum = params->rx_fdq1_qnum; |
| 2440 | req.rx_fdq2_qnum = params->rx_fdq2_qnum; |
| 2441 | req.rx_fdq3_qnum = params->rx_fdq3_qnum; |
| 2442 | req.rx_ps_location = params->rx_ps_location; |
| 2443 | |
| 2444 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2445 | if (ret) |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2446 | goto fail; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2447 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2448 | fail: |
| 2449 | dev_dbg(info->dev, "RX_FL_CFG: %u ret:%d\n", params->flow_index, ret); |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 2450 | return ret; |
| 2451 | } |
| 2452 | |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2453 | /** |
| 2454 | * ti_sci_cmd_set_fwl_region() - Request for configuring a firewall region |
| 2455 | * @handle: pointer to TI SCI handle |
| 2456 | * @region: region configuration parameters |
| 2457 | * |
| 2458 | * Return: 0 if all went well, else returns appropriate error value. |
| 2459 | */ |
| 2460 | static int ti_sci_cmd_set_fwl_region(const struct ti_sci_handle *handle, |
| 2461 | const struct ti_sci_msg_fwl_region *region) |
| 2462 | { |
| 2463 | struct ti_sci_msg_fwl_set_firewall_region_req req; |
| 2464 | struct ti_sci_msg_hdr *resp; |
| 2465 | struct ti_sci_info *info; |
| 2466 | struct ti_sci_xfer *xfer; |
| 2467 | int ret = 0; |
| 2468 | |
| 2469 | if (IS_ERR(handle)) |
| 2470 | return PTR_ERR(handle); |
| 2471 | if (!handle) |
| 2472 | return -EINVAL; |
| 2473 | |
| 2474 | info = handle_to_ti_sci_info(handle); |
| 2475 | |
| 2476 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_SET, |
| 2477 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2478 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2479 | if (IS_ERR(xfer)) { |
| 2480 | ret = PTR_ERR(xfer); |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2481 | return ret; |
| 2482 | } |
| 2483 | |
| 2484 | req.fwl_id = region->fwl_id; |
| 2485 | req.region = region->region; |
| 2486 | req.n_permission_regs = region->n_permission_regs; |
| 2487 | req.control = region->control; |
| 2488 | req.permissions[0] = region->permissions[0]; |
| 2489 | req.permissions[1] = region->permissions[1]; |
| 2490 | req.permissions[2] = region->permissions[2]; |
| 2491 | req.start_address = region->start_address; |
| 2492 | req.end_address = region->end_address; |
| 2493 | |
| 2494 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2495 | if (ret) |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2496 | return ret; |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2497 | |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2498 | return 0; |
| 2499 | } |
| 2500 | |
| 2501 | /** |
| 2502 | * ti_sci_cmd_get_fwl_region() - Request for getting a firewall region |
| 2503 | * @handle: pointer to TI SCI handle |
| 2504 | * @region: region configuration parameters |
| 2505 | * |
| 2506 | * Return: 0 if all went well, else returns appropriate error value. |
| 2507 | */ |
| 2508 | static int ti_sci_cmd_get_fwl_region(const struct ti_sci_handle *handle, |
| 2509 | struct ti_sci_msg_fwl_region *region) |
| 2510 | { |
| 2511 | struct ti_sci_msg_fwl_get_firewall_region_req req; |
| 2512 | struct ti_sci_msg_fwl_get_firewall_region_resp *resp; |
| 2513 | struct ti_sci_info *info; |
| 2514 | struct ti_sci_xfer *xfer; |
| 2515 | int ret = 0; |
| 2516 | |
| 2517 | if (IS_ERR(handle)) |
| 2518 | return PTR_ERR(handle); |
| 2519 | if (!handle) |
| 2520 | return -EINVAL; |
| 2521 | |
| 2522 | info = handle_to_ti_sci_info(handle); |
| 2523 | |
| 2524 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_GET, |
| 2525 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
| 2526 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2527 | if (IS_ERR(xfer)) { |
| 2528 | ret = PTR_ERR(xfer); |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2529 | return ret; |
| 2530 | } |
| 2531 | |
| 2532 | req.fwl_id = region->fwl_id; |
| 2533 | req.region = region->region; |
| 2534 | req.n_permission_regs = region->n_permission_regs; |
| 2535 | |
| 2536 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2537 | if (ret) |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2538 | return ret; |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2539 | |
| 2540 | resp = (struct ti_sci_msg_fwl_get_firewall_region_resp *)xfer->tx_message.buf; |
| 2541 | |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2542 | region->fwl_id = resp->fwl_id; |
| 2543 | region->region = resp->region; |
| 2544 | region->n_permission_regs = resp->n_permission_regs; |
| 2545 | region->control = resp->control; |
| 2546 | region->permissions[0] = resp->permissions[0]; |
| 2547 | region->permissions[1] = resp->permissions[1]; |
| 2548 | region->permissions[2] = resp->permissions[2]; |
| 2549 | region->start_address = resp->start_address; |
| 2550 | region->end_address = resp->end_address; |
| 2551 | |
| 2552 | return 0; |
| 2553 | } |
| 2554 | |
| 2555 | /** |
| 2556 | * ti_sci_cmd_change_fwl_owner() - Request for changing a firewall owner |
| 2557 | * @handle: pointer to TI SCI handle |
| 2558 | * @region: region configuration parameters |
| 2559 | * |
| 2560 | * Return: 0 if all went well, else returns appropriate error value. |
| 2561 | */ |
| 2562 | static int ti_sci_cmd_change_fwl_owner(const struct ti_sci_handle *handle, |
| 2563 | struct ti_sci_msg_fwl_owner *owner) |
| 2564 | { |
| 2565 | struct ti_sci_msg_fwl_change_owner_info_req req; |
| 2566 | struct ti_sci_msg_fwl_change_owner_info_resp *resp; |
| 2567 | struct ti_sci_info *info; |
| 2568 | struct ti_sci_xfer *xfer; |
| 2569 | int ret = 0; |
| 2570 | |
| 2571 | if (IS_ERR(handle)) |
| 2572 | return PTR_ERR(handle); |
| 2573 | if (!handle) |
| 2574 | return -EINVAL; |
| 2575 | |
| 2576 | info = handle_to_ti_sci_info(handle); |
| 2577 | |
Andrew F. Davis | 8928fbd | 2019-04-29 09:04:11 -0400 | [diff] [blame] | 2578 | xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_CHANGE_OWNER, |
| 2579 | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED, |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2580 | (u32 *)&req, sizeof(req), sizeof(*resp)); |
| 2581 | if (IS_ERR(xfer)) { |
| 2582 | ret = PTR_ERR(xfer); |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2583 | return ret; |
| 2584 | } |
| 2585 | |
| 2586 | req.fwl_id = owner->fwl_id; |
| 2587 | req.region = owner->region; |
| 2588 | req.owner_index = owner->owner_index; |
| 2589 | |
| 2590 | ret = ti_sci_do_xfer(info, xfer); |
Andrew Davis | 771a16f | 2022-07-25 20:25:03 -0500 | [diff] [blame] | 2591 | if (ret) |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2592 | return ret; |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2593 | |
| 2594 | resp = (struct ti_sci_msg_fwl_change_owner_info_resp *)xfer->tx_message.buf; |
| 2595 | |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2596 | owner->fwl_id = resp->fwl_id; |
| 2597 | owner->region = resp->region; |
| 2598 | owner->owner_index = resp->owner_index; |
| 2599 | owner->owner_privid = resp->owner_privid; |
| 2600 | owner->owner_permission_bits = resp->owner_permission_bits; |
| 2601 | |
| 2602 | return ret; |
| 2603 | } |
| 2604 | |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 2605 | /* |
| 2606 | * ti_sci_setup_ops() - Setup the operations structures |
| 2607 | * @info: pointer to TISCI pointer |
| 2608 | */ |
| 2609 | static void ti_sci_setup_ops(struct ti_sci_info *info) |
| 2610 | { |
| 2611 | struct ti_sci_ops *ops = &info->handle.ops; |
| 2612 | struct ti_sci_board_ops *bops = &ops->board_ops; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 2613 | struct ti_sci_dev_ops *dops = &ops->dev_ops; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 2614 | struct ti_sci_clk_ops *cops = &ops->clk_ops; |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 2615 | struct ti_sci_core_ops *core_ops = &ops->core_ops; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2616 | struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 2617 | struct ti_sci_proc_ops *pops = &ops->proc_ops; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2618 | struct ti_sci_rm_ringacc_ops *rops = &ops->rm_ring_ops; |
| 2619 | struct ti_sci_rm_psil_ops *psilops = &ops->rm_psil_ops; |
| 2620 | struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops; |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2621 | struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops; |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 2622 | |
| 2623 | bops->board_config = ti_sci_cmd_set_board_config; |
| 2624 | bops->board_config_rm = ti_sci_cmd_set_board_config_rm; |
| 2625 | bops->board_config_security = ti_sci_cmd_set_board_config_security; |
| 2626 | bops->board_config_pm = ti_sci_cmd_set_board_config_pm; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 2627 | |
| 2628 | dops->get_device = ti_sci_cmd_get_device; |
Lokesh Vutla | f561300 | 2019-06-07 19:24:39 +0530 | [diff] [blame] | 2629 | dops->get_device_exclusive = ti_sci_cmd_get_device_exclusive; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 2630 | dops->idle_device = ti_sci_cmd_idle_device; |
Lokesh Vutla | f561300 | 2019-06-07 19:24:39 +0530 | [diff] [blame] | 2631 | dops->idle_device_exclusive = ti_sci_cmd_idle_device_exclusive; |
Andreas Dannenberg | 24a4d5e | 2018-08-27 15:57:34 +0530 | [diff] [blame] | 2632 | dops->put_device = ti_sci_cmd_put_device; |
| 2633 | dops->is_valid = ti_sci_cmd_dev_is_valid; |
| 2634 | dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt; |
| 2635 | dops->is_idle = ti_sci_cmd_dev_is_idle; |
| 2636 | dops->is_stop = ti_sci_cmd_dev_is_stop; |
| 2637 | dops->is_on = ti_sci_cmd_dev_is_on; |
| 2638 | dops->is_transitioning = ti_sci_cmd_dev_is_trans; |
| 2639 | dops->set_device_resets = ti_sci_cmd_set_device_resets; |
| 2640 | dops->get_device_resets = ti_sci_cmd_get_device_resets; |
Lokesh Vutla | 0d0412a | 2019-06-07 19:24:41 +0530 | [diff] [blame] | 2641 | dops->release_exclusive_devices = ti_sci_cmd_release_exclusive_devices; |
Lokesh Vutla | d10c80c | 2018-08-27 15:57:35 +0530 | [diff] [blame] | 2642 | |
| 2643 | cops->get_clock = ti_sci_cmd_get_clock; |
| 2644 | cops->idle_clock = ti_sci_cmd_idle_clock; |
| 2645 | cops->put_clock = ti_sci_cmd_put_clock; |
| 2646 | cops->is_auto = ti_sci_cmd_clk_is_auto; |
| 2647 | cops->is_on = ti_sci_cmd_clk_is_on; |
| 2648 | cops->is_off = ti_sci_cmd_clk_is_off; |
| 2649 | |
| 2650 | cops->set_parent = ti_sci_cmd_clk_set_parent; |
| 2651 | cops->get_parent = ti_sci_cmd_clk_get_parent; |
| 2652 | cops->get_num_parents = ti_sci_cmd_clk_get_num_parents; |
| 2653 | |
| 2654 | cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq; |
| 2655 | cops->set_freq = ti_sci_cmd_clk_set_freq; |
| 2656 | cops->get_freq = ti_sci_cmd_clk_get_freq; |
Andreas Dannenberg | 5bd0837 | 2018-08-27 15:57:36 +0530 | [diff] [blame] | 2657 | |
| 2658 | core_ops->reboot_device = ti_sci_cmd_core_reboot; |
Lokesh Vutla | 032dce8 | 2019-03-08 11:47:32 +0530 | [diff] [blame] | 2659 | core_ops->query_msmc = ti_sci_cmd_query_msmc; |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 2660 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2661 | rm_core_ops->get_range = ti_sci_cmd_get_resource_range; |
| 2662 | rm_core_ops->get_range_from_shost = |
| 2663 | ti_sci_cmd_get_resource_range_from_shost; |
| 2664 | |
Lokesh Vutla | b8856af | 2018-08-27 15:57:37 +0530 | [diff] [blame] | 2665 | pops->proc_request = ti_sci_cmd_proc_request; |
| 2666 | pops->proc_release = ti_sci_cmd_proc_release; |
| 2667 | pops->proc_handover = ti_sci_cmd_proc_handover; |
| 2668 | pops->set_proc_boot_cfg = ti_sci_cmd_set_proc_boot_cfg; |
| 2669 | pops->set_proc_boot_ctrl = ti_sci_cmd_set_proc_boot_ctrl; |
| 2670 | pops->proc_auth_boot_image = ti_sci_cmd_proc_auth_boot_image; |
| 2671 | pops->get_proc_boot_status = ti_sci_cmd_get_proc_boot_status; |
Andreas Dannenberg | ca08cb3 | 2019-06-07 19:24:40 +0530 | [diff] [blame] | 2672 | pops->proc_shutdown_no_wait = ti_sci_cmd_proc_shutdown_no_wait; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2673 | |
| 2674 | rops->config = ti_sci_cmd_ring_config; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2675 | |
| 2676 | psilops->pair = ti_sci_cmd_rm_psil_pair; |
| 2677 | psilops->unpair = ti_sci_cmd_rm_psil_unpair; |
| 2678 | |
| 2679 | udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg; |
| 2680 | udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg; |
| 2681 | udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg; |
Andrew F. Davis | 2aafc0c | 2019-04-12 12:54:43 -0400 | [diff] [blame] | 2682 | |
| 2683 | fwl_ops->set_fwl_region = ti_sci_cmd_set_fwl_region; |
| 2684 | fwl_ops->get_fwl_region = ti_sci_cmd_get_fwl_region; |
| 2685 | fwl_ops->change_fwl_owner = ti_sci_cmd_change_fwl_owner; |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | /** |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 2689 | * ti_sci_get_handle_from_sysfw() - Get the TI SCI handle of the SYSFW |
| 2690 | * @dev: Pointer to the SYSFW device |
| 2691 | * |
| 2692 | * Return: pointer to handle if successful, else EINVAL if invalid conditions |
| 2693 | * are encountered. |
| 2694 | */ |
| 2695 | const |
| 2696 | struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *sci_dev) |
| 2697 | { |
Neha Malcom Francis | c7dedd0 | 2023-09-27 18:39:53 +0530 | [diff] [blame] | 2698 | int ret; |
| 2699 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 2700 | if (!sci_dev) |
| 2701 | return ERR_PTR(-EINVAL); |
| 2702 | |
| 2703 | struct ti_sci_info *info = dev_get_priv(sci_dev); |
| 2704 | |
| 2705 | if (!info) |
| 2706 | return ERR_PTR(-EINVAL); |
| 2707 | |
| 2708 | struct ti_sci_handle *handle = &info->handle; |
| 2709 | |
| 2710 | if (!handle) |
| 2711 | return ERR_PTR(-EINVAL); |
| 2712 | |
Neha Malcom Francis | c7dedd0 | 2023-09-27 18:39:53 +0530 | [diff] [blame] | 2713 | ret = ti_sci_cmd_get_revision(handle); |
| 2714 | |
| 2715 | if (ret) |
| 2716 | return ERR_PTR(-EINVAL); |
| 2717 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 2718 | return handle; |
| 2719 | } |
| 2720 | |
| 2721 | /** |
| 2722 | * ti_sci_get_handle() - Get the TI SCI handle for a device |
| 2723 | * @dev: Pointer to device for which we want SCI handle |
| 2724 | * |
| 2725 | * Return: pointer to handle if successful, else EINVAL if invalid conditions |
| 2726 | * are encountered. |
| 2727 | */ |
| 2728 | const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev) |
| 2729 | { |
| 2730 | if (!dev) |
| 2731 | return ERR_PTR(-EINVAL); |
| 2732 | |
| 2733 | struct udevice *sci_dev = dev_get_parent(dev); |
| 2734 | |
| 2735 | return ti_sci_get_handle_from_sysfw(sci_dev); |
| 2736 | } |
| 2737 | |
| 2738 | /** |
| 2739 | * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle |
| 2740 | * @dev: device node |
| 2741 | * @propname: property name containing phandle on TISCI node |
| 2742 | * |
| 2743 | * Return: pointer to handle if successful, else appropriate error value. |
| 2744 | */ |
| 2745 | const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev, |
| 2746 | const char *property) |
| 2747 | { |
| 2748 | struct ti_sci_info *entry, *info = NULL; |
| 2749 | u32 phandle, err; |
| 2750 | ofnode node; |
| 2751 | |
| 2752 | err = ofnode_read_u32(dev_ofnode(dev), property, &phandle); |
| 2753 | if (err) |
| 2754 | return ERR_PTR(err); |
| 2755 | |
| 2756 | node = ofnode_get_by_phandle(phandle); |
| 2757 | if (!ofnode_valid(node)) |
| 2758 | return ERR_PTR(-EINVAL); |
| 2759 | |
| 2760 | list_for_each_entry(entry, &ti_sci_list, list) |
| 2761 | if (ofnode_equal(dev_ofnode(entry->dev), node)) { |
| 2762 | info = entry; |
| 2763 | break; |
| 2764 | } |
| 2765 | |
| 2766 | if (!info) |
| 2767 | return ERR_PTR(-ENODEV); |
| 2768 | |
| 2769 | return &info->handle; |
| 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * ti_sci_of_to_info() - generate private data from device tree |
| 2774 | * @dev: corresponding system controller interface device |
| 2775 | * @info: pointer to driver specific private data |
| 2776 | * |
| 2777 | * Return: 0 if all goes good, else appropriate error message. |
| 2778 | */ |
| 2779 | static int ti_sci_of_to_info(struct udevice *dev, struct ti_sci_info *info) |
| 2780 | { |
| 2781 | int ret; |
| 2782 | |
| 2783 | ret = mbox_get_by_name(dev, "tx", &info->chan_tx); |
| 2784 | if (ret) { |
| 2785 | dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n", |
| 2786 | __func__, ret); |
| 2787 | return ret; |
| 2788 | } |
| 2789 | |
| 2790 | ret = mbox_get_by_name(dev, "rx", &info->chan_rx); |
| 2791 | if (ret) { |
| 2792 | dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n", |
| 2793 | __func__, ret); |
| 2794 | return ret; |
| 2795 | } |
| 2796 | |
| 2797 | /* Notify channel is optional. Enable only if populated */ |
| 2798 | ret = mbox_get_by_name(dev, "notify", &info->chan_notify); |
| 2799 | if (ret) { |
| 2800 | dev_dbg(dev, "%s: Acquiring notify channel failed. ret = %d\n", |
| 2801 | __func__, ret); |
| 2802 | } |
| 2803 | |
| 2804 | info->host_id = dev_read_u32_default(dev, "ti,host-id", |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2805 | info->desc->default_host_id); |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 2806 | |
| 2807 | info->is_secure = dev_read_bool(dev, "ti,secure-host"); |
| 2808 | |
| 2809 | return 0; |
| 2810 | } |
| 2811 | |
| 2812 | /** |
| 2813 | * ti_sci_probe() - Basic probe |
| 2814 | * @dev: corresponding system controller interface device |
| 2815 | * |
| 2816 | * Return: 0 if all goes good, else appropriate error message. |
| 2817 | */ |
| 2818 | static int ti_sci_probe(struct udevice *dev) |
| 2819 | { |
| 2820 | struct ti_sci_info *info; |
| 2821 | int ret; |
| 2822 | |
| 2823 | debug("%s(dev=%p)\n", __func__, dev); |
| 2824 | |
| 2825 | info = dev_get_priv(dev); |
| 2826 | info->desc = (void *)dev_get_driver_data(dev); |
| 2827 | |
| 2828 | ret = ti_sci_of_to_info(dev, info); |
| 2829 | if (ret) { |
| 2830 | dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret); |
| 2831 | return ret; |
| 2832 | } |
| 2833 | |
| 2834 | info->dev = dev; |
| 2835 | info->seq = 0xA; |
| 2836 | |
| 2837 | list_add_tail(&info->list, &ti_sci_list); |
Andreas Dannenberg | 5299c4c | 2018-08-27 15:57:33 +0530 | [diff] [blame] | 2838 | ti_sci_setup_ops(info); |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 2839 | |
Lokesh Vutla | 0d0412a | 2019-06-07 19:24:41 +0530 | [diff] [blame] | 2840 | INIT_LIST_HEAD(&info->dev_list); |
| 2841 | |
Andrew Davis | 1ed20d6 | 2024-04-02 11:09:07 -0500 | [diff] [blame] | 2842 | if (IS_ENABLED(CONFIG_SYSRESET_TI_SCI)) { |
| 2843 | ret = device_bind_driver(dev, "ti-sci-sysreset", "sysreset", NULL); |
| 2844 | if (ret) |
| 2845 | dev_warn(dev, "cannot bind SYSRESET (ret = %d)\n", ret); |
| 2846 | } |
| 2847 | |
Neha Malcom Francis | c7dedd0 | 2023-09-27 18:39:53 +0530 | [diff] [blame] | 2848 | return 0; |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 2849 | } |
| 2850 | |
Vignesh Raghavendra | aa0e3fc | 2021-06-07 19:47:49 +0530 | [diff] [blame] | 2851 | /** |
| 2852 | * ti_sci_dm_probe() - Basic probe for DM to TIFS SCI |
| 2853 | * @dev: corresponding system controller interface device |
| 2854 | * |
| 2855 | * Return: 0 if all goes good, else appropriate error message. |
| 2856 | */ |
| 2857 | static __maybe_unused int ti_sci_dm_probe(struct udevice *dev) |
| 2858 | { |
| 2859 | struct ti_sci_rm_core_ops *rm_core_ops; |
| 2860 | struct ti_sci_rm_udmap_ops *udmap_ops; |
| 2861 | struct ti_sci_rm_ringacc_ops *rops; |
| 2862 | struct ti_sci_rm_psil_ops *psilops; |
| 2863 | struct ti_sci_ops *ops; |
| 2864 | struct ti_sci_info *info; |
| 2865 | int ret; |
| 2866 | |
| 2867 | debug("%s(dev=%p)\n", __func__, dev); |
| 2868 | |
| 2869 | info = dev_get_priv(dev); |
| 2870 | info->desc = (void *)dev_get_driver_data(dev); |
| 2871 | |
| 2872 | ret = ti_sci_of_to_info(dev, info); |
| 2873 | if (ret) { |
| 2874 | dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret); |
| 2875 | return ret; |
| 2876 | } |
| 2877 | |
| 2878 | info->dev = dev; |
| 2879 | info->seq = 0xA; |
| 2880 | |
| 2881 | list_add_tail(&info->list, &ti_sci_list); |
| 2882 | |
| 2883 | ops = &info->handle.ops; |
| 2884 | |
| 2885 | rm_core_ops = &ops->rm_core_ops; |
| 2886 | rm_core_ops->get_range = ti_sci_cmd_get_resource_range_static; |
| 2887 | |
| 2888 | rops = &ops->rm_ring_ops; |
| 2889 | rops->config = ti_sci_cmd_ring_config; |
| 2890 | |
| 2891 | psilops = &ops->rm_psil_ops; |
| 2892 | psilops->pair = ti_sci_cmd_rm_psil_pair; |
| 2893 | psilops->unpair = ti_sci_cmd_rm_psil_unpair; |
| 2894 | |
| 2895 | udmap_ops = &ops->rm_udmap_ops; |
| 2896 | udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg; |
| 2897 | udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg; |
| 2898 | udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg; |
| 2899 | |
| 2900 | return ret; |
| 2901 | } |
| 2902 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2903 | /* |
| 2904 | * ti_sci_get_free_resource() - Get a free resource from TISCI resource. |
| 2905 | * @res: Pointer to the TISCI resource |
| 2906 | * |
| 2907 | * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL. |
| 2908 | */ |
| 2909 | u16 ti_sci_get_free_resource(struct ti_sci_resource *res) |
| 2910 | { |
| 2911 | u16 set, free_bit; |
| 2912 | |
| 2913 | for (set = 0; set < res->sets; set++) { |
| 2914 | free_bit = find_first_zero_bit(res->desc[set].res_map, |
| 2915 | res->desc[set].num); |
| 2916 | if (free_bit != res->desc[set].num) { |
| 2917 | set_bit(free_bit, res->desc[set].res_map); |
| 2918 | return res->desc[set].start + free_bit; |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | return TI_SCI_RESOURCE_NULL; |
| 2923 | } |
| 2924 | |
| 2925 | /** |
| 2926 | * ti_sci_release_resource() - Release a resource from TISCI resource. |
| 2927 | * @res: Pointer to the TISCI resource |
| 2928 | */ |
| 2929 | void ti_sci_release_resource(struct ti_sci_resource *res, u16 id) |
| 2930 | { |
| 2931 | u16 set; |
| 2932 | |
| 2933 | for (set = 0; set < res->sets; set++) { |
| 2934 | if (res->desc[set].start <= id && |
| 2935 | (res->desc[set].num + res->desc[set].start) > id) |
| 2936 | clear_bit(id - res->desc[set].start, |
| 2937 | res->desc[set].res_map); |
| 2938 | } |
| 2939 | } |
| 2940 | |
| 2941 | /** |
| 2942 | * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device |
| 2943 | * @handle: TISCI handle |
| 2944 | * @dev: Device pointer to which the resource is assigned |
| 2945 | * @of_prop: property name by which the resource are represented |
| 2946 | * |
| 2947 | * Note: This function expects of_prop to be in the form of tuples |
| 2948 | * <type, subtype>. Allocates and initializes ti_sci_resource structure |
| 2949 | * for each of_prop. Client driver can directly call |
| 2950 | * ti_sci_(get_free, release)_resource apis for handling the resource. |
| 2951 | * |
| 2952 | * Return: Pointer to ti_sci_resource if all went well else appropriate |
| 2953 | * error pointer. |
| 2954 | */ |
| 2955 | struct ti_sci_resource * |
| 2956 | devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle, |
| 2957 | struct udevice *dev, u32 dev_id, char *of_prop) |
| 2958 | { |
| 2959 | u32 resource_subtype; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2960 | struct ti_sci_resource *res; |
Vignesh Raghavendra | e1164dd | 2019-08-05 12:26:44 -0500 | [diff] [blame] | 2961 | bool valid_set = false; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2962 | int sets, i, ret; |
| 2963 | u32 *temp; |
| 2964 | |
| 2965 | res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL); |
| 2966 | if (!res) |
| 2967 | return ERR_PTR(-ENOMEM); |
| 2968 | |
| 2969 | sets = dev_read_size(dev, of_prop); |
| 2970 | if (sets < 0) { |
| 2971 | dev_err(dev, "%s resource type ids not available\n", of_prop); |
| 2972 | return ERR_PTR(sets); |
| 2973 | } |
| 2974 | temp = malloc(sets); |
| 2975 | sets /= sizeof(u32); |
| 2976 | res->sets = sets; |
| 2977 | |
| 2978 | res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc), |
| 2979 | GFP_KERNEL); |
| 2980 | if (!res->desc) |
| 2981 | return ERR_PTR(-ENOMEM); |
| 2982 | |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2983 | ret = dev_read_u32_array(dev, of_prop, temp, res->sets); |
| 2984 | if (ret) |
| 2985 | return ERR_PTR(-EINVAL); |
| 2986 | |
| 2987 | for (i = 0; i < res->sets; i++) { |
| 2988 | resource_subtype = temp[i]; |
| 2989 | ret = handle->ops.rm_core_ops.get_range(handle, dev_id, |
| 2990 | resource_subtype, |
| 2991 | &res->desc[i].start, |
| 2992 | &res->desc[i].num); |
| 2993 | if (ret) { |
Vignesh Raghavendra | e1164dd | 2019-08-05 12:26:44 -0500 | [diff] [blame] | 2994 | dev_dbg(dev, "type %d subtype %d not allocated for host %d\n", |
Lokesh Vutla | 0acf1dc | 2020-08-17 11:00:48 +0530 | [diff] [blame] | 2995 | dev_id, resource_subtype, |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 2996 | handle_to_ti_sci_info(handle)->host_id); |
Vignesh Raghavendra | e1164dd | 2019-08-05 12:26:44 -0500 | [diff] [blame] | 2997 | res->desc[i].start = 0; |
| 2998 | res->desc[i].num = 0; |
| 2999 | continue; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 3000 | } |
| 3001 | |
Vignesh Raghavendra | e1164dd | 2019-08-05 12:26:44 -0500 | [diff] [blame] | 3002 | valid_set = true; |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 3003 | dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n", |
Lokesh Vutla | 0acf1dc | 2020-08-17 11:00:48 +0530 | [diff] [blame] | 3004 | dev_id, resource_subtype, res->desc[i].start, |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 3005 | res->desc[i].num); |
| 3006 | |
| 3007 | res->desc[i].res_map = |
| 3008 | devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) * |
| 3009 | sizeof(*res->desc[i].res_map), GFP_KERNEL); |
| 3010 | if (!res->desc[i].res_map) |
| 3011 | return ERR_PTR(-ENOMEM); |
| 3012 | } |
| 3013 | |
Vignesh Raghavendra | e1164dd | 2019-08-05 12:26:44 -0500 | [diff] [blame] | 3014 | if (valid_set) |
| 3015 | return res; |
| 3016 | |
| 3017 | return ERR_PTR(-EINVAL); |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | /* Description for K2G */ |
| 3021 | static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { |
| 3022 | .default_host_id = 2, |
| 3023 | /* Conservative duration */ |
| 3024 | .max_rx_timeout_ms = 10000, |
| 3025 | /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */ |
| 3026 | .max_msgs = 20, |
| 3027 | .max_msg_size = 64, |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 3028 | }; |
| 3029 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 3030 | /* Description for AM654 */ |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 3031 | static const struct ti_sci_desc ti_sci_pmmc_am654_desc = { |
| 3032 | .default_host_id = 12, |
| 3033 | /* Conservative duration */ |
| 3034 | .max_rx_timeout_ms = 10000, |
| 3035 | /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */ |
| 3036 | .max_msgs = 20, |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 3037 | .max_msg_size = 60, |
| 3038 | }; |
| 3039 | |
Vignesh Raghavendra | aa0e3fc | 2021-06-07 19:47:49 +0530 | [diff] [blame] | 3040 | /* Description for J721e DM to DMSC communication */ |
| 3041 | static const struct ti_sci_desc ti_sci_dm_j721e_desc = { |
| 3042 | .default_host_id = 3, |
| 3043 | .max_rx_timeout_ms = 10000, |
| 3044 | .max_msgs = 20, |
| 3045 | .max_msg_size = 60, |
| 3046 | }; |
| 3047 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 3048 | static const struct udevice_id ti_sci_ids[] = { |
| 3049 | { |
| 3050 | .compatible = "ti,k2g-sci", |
Grygorii Strashko | d64c5b2 | 2019-02-05 17:31:21 +0530 | [diff] [blame] | 3051 | .data = (ulong)&ti_sci_pmmc_k2g_desc |
| 3052 | }, |
| 3053 | { |
| 3054 | .compatible = "ti,am654-sci", |
| 3055 | .data = (ulong)&ti_sci_pmmc_am654_desc |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 3056 | }, |
| 3057 | { /* Sentinel */ }, |
| 3058 | }; |
| 3059 | |
Vignesh Raghavendra | aa0e3fc | 2021-06-07 19:47:49 +0530 | [diff] [blame] | 3060 | static __maybe_unused const struct udevice_id ti_sci_dm_ids[] = { |
| 3061 | { |
| 3062 | .compatible = "ti,j721e-dm-sci", |
| 3063 | .data = (ulong)&ti_sci_dm_j721e_desc |
| 3064 | }, |
| 3065 | { /* Sentinel */ }, |
| 3066 | }; |
| 3067 | |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 3068 | U_BOOT_DRIVER(ti_sci) = { |
| 3069 | .name = "ti_sci", |
| 3070 | .id = UCLASS_FIRMWARE, |
| 3071 | .of_match = ti_sci_ids, |
| 3072 | .probe = ti_sci_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 3073 | .priv_auto = sizeof(struct ti_sci_info), |
Lokesh Vutla | 5af02db | 2018-08-27 15:57:32 +0530 | [diff] [blame] | 3074 | }; |
Vignesh Raghavendra | aa0e3fc | 2021-06-07 19:47:49 +0530 | [diff] [blame] | 3075 | |
| 3076 | #if IS_ENABLED(CONFIG_K3_DM_FW) |
| 3077 | U_BOOT_DRIVER(ti_sci_dm) = { |
| 3078 | .name = "ti_sci_dm", |
| 3079 | .id = UCLASS_FIRMWARE, |
| 3080 | .of_match = ti_sci_dm_ids, |
| 3081 | .probe = ti_sci_dm_probe, |
| 3082 | .priv_auto = sizeof(struct ti_sci_info), |
| 3083 | }; |
| 3084 | #endif |