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