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