1 // SPDX-License-Identifier: GPL-2.0+
3 * Texas Instruments System Control Interface Protocol Driver
4 * Based on drivers/firmware/ti_sci.c from Linux.
6 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
7 * Lokesh Vutla <lokeshvutla@ti.com>
16 #include <dm/device.h>
17 #include <dm/device_compat.h>
18 #include <dm/devres.h>
19 #include <linux/bitops.h>
20 #include <linux/compat.h>
21 #include <linux/err.h>
22 #include <linux/soc/ti/k3-sec-proxy.h>
23 #include <linux/soc/ti/ti_sci_protocol.h>
26 #include "ti_sci_static_data.h"
28 /* List of all TI SCI devices active in system */
29 static LIST_HEAD(ti_sci_list);
32 * struct ti_sci_xfer - Structure representing a message flow
33 * @tx_message: Transmit message
34 * @rx_len: Receive message length
37 struct k3_sec_proxy_msg tx_message;
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.
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.
52 struct ti_sci_rm_type_map {
58 * struct ti_sci_desc - Description of SoC integration
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.
67 int max_rx_timeout_ms;
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
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.
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;
94 struct list_head dev_list;
100 struct ti_sci_exclusive_dev {
103 struct list_head list;
106 #define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle)
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
115 * @rx_message_size: receive message size. may be set to zero for send-only
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.
121 * Return: Corresponding ti_sci_xfer pointer if all went fine,
122 * else appropriate error pointer.
124 static struct ti_sci_xfer *ti_sci_setup_one_xfer(struct ti_sci_info *info,
125 u16 msg_type, u32 msg_flags,
127 size_t tx_message_size,
128 size_t rx_message_size)
130 struct ti_sci_xfer *xfer = &info->xfer;
131 struct ti_sci_msg_hdr *hdr;
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 ||
136 (rx_message_size > 0 && rx_message_size < sizeof(*hdr)) ||
137 tx_message_size < sizeof(*hdr))
138 return ERR_PTR(-ERANGE);
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;
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;
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
160 * Return: -ETIMEDOUT in case of no response, if transmit error,
161 * return corresponding error, else if all goes well,
164 static inline int ti_sci_get_response(struct ti_sci_info *info,
165 struct ti_sci_xfer *xfer,
166 struct mbox_chan *chan)
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;
173 /* Receive the response */
174 ret = mbox_recv(chan, msg, info->desc->max_rx_timeout_ms * 1000);
176 dev_err(info->dev, "%s: Message receive failed. ret = %d\n",
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));
187 /* msg is updated by mailbox driver */
188 hdr = (struct ti_sci_msg_hdr *)msg->buf;
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",
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);
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);
212 * ti_sci_do_xfer() - Do one transfer
213 * @info: Pointer to SCI entity information
214 * @xfer: Transfer to initiate and wait for response
216 * Return: 0 if all went fine, else return appropriate error.
218 static inline int ti_sci_do_xfer(struct ti_sci_info *info,
219 struct ti_sci_xfer *xfer)
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;
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);
233 xfer->tx_message.buf = (u32 *)secure_buf;
234 xfer->tx_message.len += sizeof(secure_hdr);
237 xfer->rx_len += sizeof(secure_hdr);
240 /* Send the message */
241 ret = mbox_send(&info->chan_tx, msg);
243 dev_err(info->dev, "%s: Message sending failed. ret = %d\n",
248 /* Get response if requested */
250 ret = ti_sci_get_response(info, xfer, &info->chan_rx);
256 * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity
257 * @handle: pointer to TI SCI handle
259 * Updates the SCI information in the internal data structure.
261 * Return: 0 if all went fine, else return appropriate error.
263 static int ti_sci_cmd_get_revision(struct ti_sci_handle *handle)
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;
273 return PTR_ERR(handle);
277 info = handle_to_ti_sci_info(handle);
279 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_VERSION,
280 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
281 (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr),
285 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
289 ret = ti_sci_do_xfer(info, xfer);
293 rev_info = (struct ti_sci_msg_resp_version *)xfer->tx_message.buf;
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));
306 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
307 * @r: pointer to response buffer
309 * Return: true if the response was an ACK, else returns false.
311 static inline bool ti_sci_is_response_ack(void *r)
313 struct ti_sci_msg_hdr *hdr = r;
315 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false;
319 * cmd_set_board_config_using_msg() - Common command to send board configuration
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
326 * Return: 0 if all went well, else returns appropriate error value.
328 static int cmd_set_board_config_using_msg(const struct ti_sci_handle *handle,
329 u16 msg_type, u64 addr, u32 size)
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;
338 return PTR_ERR(handle);
342 info = handle_to_ti_sci_info(handle);
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));
349 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
352 req.boardcfgp_high = (addr >> 32) & 0xffffffff;
353 req.boardcfgp_low = addr & 0xffffffff;
354 req.boardcfg_size = size;
356 ret = ti_sci_do_xfer(info, xfer);
360 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
362 if (!ti_sci_is_response_ack(resp))
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
374 * Return: 0 if all went well, else returns appropriate error value.
376 static int ti_sci_cmd_set_board_config(const struct ti_sci_handle *handle,
379 return cmd_set_board_config_using_msg(handle,
380 TI_SCI_MSG_BOARD_CONFIG,
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
391 * Return: 0 if all went well, else returns appropriate error value.
394 int ti_sci_cmd_set_board_config_rm(const struct ti_sci_handle *handle,
397 return cmd_set_board_config_using_msg(handle,
398 TI_SCI_MSG_BOARD_CONFIG_RM,
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
409 * Return: 0 if all went well, else returns appropriate error value.
412 int ti_sci_cmd_set_board_config_security(const struct ti_sci_handle *handle,
415 return cmd_set_board_config_using_msg(handle,
416 TI_SCI_MSG_BOARD_CONFIG_SECURITY,
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
427 * Return: 0 if all went well, else returns appropriate error value.
429 static int ti_sci_cmd_set_board_config_pm(const struct ti_sci_handle *handle,
432 return cmd_set_board_config_using_msg(handle,
433 TI_SCI_MSG_BOARD_CONFIG_PM,
437 static struct ti_sci_exclusive_dev
438 *ti_sci_get_exclusive_dev(struct list_head *dev_list, u32 id)
440 struct ti_sci_exclusive_dev *dev;
442 list_for_each_entry(dev, dev_list, list)
449 static void ti_sci_add_exclusive_dev(struct ti_sci_info *info, u32 id)
451 struct ti_sci_exclusive_dev *dev;
453 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
459 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
462 INIT_LIST_HEAD(&dev->list);
463 list_add_tail(&dev->list, &info->dev_list);
466 static void ti_sci_delete_exclusive_dev(struct ti_sci_info *info, u32 id)
468 struct ti_sci_exclusive_dev *dev;
470 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
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
485 * Return: 0 if all went well, else returns appropriate error value.
487 static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
488 u32 id, u32 flags, u8 state)
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;
497 return PTR_ERR(handle);
501 info = handle_to_ti_sci_info(handle);
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));
508 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
514 ret = ti_sci_do_xfer(info, xfer);
518 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
520 if (!ti_sci_is_response_ack(resp))
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);
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
539 * Return: 0 if all went well, else returns appropriate error value.
541 static int ti_sci_set_device_state_no_wait(const struct ti_sci_handle *handle,
542 u32 id, u32 flags, u8 state)
544 struct ti_sci_msg_req_set_device_state req;
545 struct ti_sci_info *info;
546 struct ti_sci_xfer *xfer;
550 return PTR_ERR(handle);
554 info = handle_to_ti_sci_info(handle);
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);
561 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
567 ret = ti_sci_do_xfer(info, xfer);
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
583 * Return: 0 if all went fine, else return appropriate error.
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)
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;
596 return PTR_ERR(handle);
600 if (!clcnt && !resets && !p_state && !c_state)
603 info = handle_to_ti_sci_info(handle);
605 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_DEVICE_STATE,
606 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
607 (u32 *)&req, sizeof(req), sizeof(*resp));
610 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
615 ret = ti_sci_do_xfer(info, xfer);
619 resp = (struct ti_sci_msg_resp_get_device_state *)xfer->tx_message.buf;
620 if (!ti_sci_is_response_ack(resp))
624 *clcnt = resp->context_loss_count;
626 *resets = resp->resets;
628 *p_state = resp->programmed_state;
630 *c_state = resp->current_state;
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
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.
644 * NOTE: The request is for exclusive access for the processor.
646 * Return: 0 if all went fine, else return appropriate error.
648 static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
650 return ti_sci_set_device_state(handle, id, 0,
651 MSG_DEVICE_SW_STATE_ON);
654 static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle *handle,
657 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
658 MSG_DEVICE_SW_STATE_ON);
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
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.
670 * Return: 0 if all went fine, else return appropriate error.
672 static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
674 return ti_sci_set_device_state(handle, id,
676 MSG_DEVICE_SW_STATE_RETENTION);
679 static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle *handle,
682 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
683 MSG_DEVICE_SW_STATE_RETENTION);
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
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.
695 * Return: 0 if all went fine, else return appropriate error.
697 static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
699 return ti_sci_set_device_state(handle, id, 0,
700 MSG_DEVICE_SW_STATE_AUTO_OFF);
704 int ti_sci_cmd_release_exclusive_devices(const struct ti_sci_handle *handle)
706 struct ti_sci_exclusive_dev *dev, *tmp;
707 struct ti_sci_info *info;
710 info = handle_to_ti_sci_info(handle);
712 list_for_each_entry_safe(dev, tmp, &info->dev_list, list) {
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);
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
727 * Return: 0 if all went fine and the device ID is valid, else return
730 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
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);
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
744 * Return: 0 if all went fine, else return appropriate error.
746 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
749 return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
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
758 * Return: 0 if all went fine, else return appropriate error.
760 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
769 ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
773 *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
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.
785 * Return: 0 if all went fine, else return appropriate error.
787 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
788 bool *r_state, bool *curr_state)
793 if (!r_state && !curr_state)
797 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
802 *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
804 *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
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
816 * Return: 0 if all went fine, else return appropriate error.
818 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
819 bool *r_state, bool *curr_state)
824 if (!r_state && !curr_state)
828 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
833 *r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
835 *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
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.
846 * Return: 0 if all went fine, else return appropriate error.
848 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
857 ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
861 *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
867 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
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
873 * Return: 0 if all went fine, else return appropriate error.
875 static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
876 u32 id, u32 reset_state)
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;
885 return PTR_ERR(handle);
889 info = handle_to_ti_sci_info(handle);
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));
896 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
900 req.resets = reset_state;
902 ret = ti_sci_do_xfer(info, xfer);
906 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
908 if (!ti_sci_is_response_ack(resp))
915 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
917 * @handle: Pointer to TISCI handle
918 * @id: Device Identifier
919 * @reset_state: Pointer to reset state to populate
921 * Return: 0 if all went fine, else return appropriate error.
923 static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
924 u32 id, u32 *reset_state)
926 return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
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.
940 * Return: 0 if all went well, else returns appropriate error value.
942 static int ti_sci_set_clock_state(const struct ti_sci_handle *handle,
943 u32 dev_id, u8 clk_id,
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;
953 return PTR_ERR(handle);
957 info = handle_to_ti_sci_info(handle);
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));
964 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
969 req.request_state = state;
971 ret = ti_sci_do_xfer(info, xfer);
975 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
977 if (!ti_sci_is_response_ack(resp))
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
993 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
1006 return PTR_ERR(handle);
1010 if (!programmed_state && !current_state)
1013 info = handle_to_ti_sci_info(handle);
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));
1019 ret = PTR_ERR(xfer);
1020 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1023 req.dev_id = dev_id;
1024 req.clk_id = clk_id;
1026 ret = ti_sci_do_xfer(info, xfer);
1030 resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->tx_message.buf;
1032 if (!ti_sci_is_response_ack(resp))
1035 if (programmed_state)
1036 *programmed_state = resp->programmed_state;
1038 *current_state = resp->current_state;
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'
1054 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
1066 return ti_sci_set_clock_state(handle, dev_id, clk_id, flags,
1067 MSG_CLOCK_SW_STATE_REQ);
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.
1078 * NOTE: This clock must have been requested by get_clock previously.
1080 * Return: 0 if all went well, else returns appropriate error value.
1082 static int ti_sci_cmd_idle_clock(const struct ti_sci_handle *handle,
1083 u32 dev_id, u8 clk_id)
1085 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1086 MSG_CLOCK_SW_STATE_UNREQ);
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.
1097 * NOTE: This clock must have been requested by get_clock previously.
1099 * Return: 0 if all went well, else returns appropriate error value.
1101 static int ti_sci_cmd_put_clock(const struct ti_sci_handle *handle,
1102 u32 dev_id, u8 clk_id)
1104 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1105 MSG_CLOCK_SW_STATE_AUTO);
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
1117 * Return: 0 if all went well, else returns appropriate error value.
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)
1128 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, &state, NULL);
1132 *req_state = (state == MSG_CLOCK_SW_STATE_AUTO);
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
1146 * Return: 0 if all went well, else returns appropriate error value.
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)
1151 u8 c_state = 0, r_state = 0;
1154 if (!req_state && !curr_state)
1157 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1158 &r_state, &c_state);
1163 *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ);
1165 *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY);
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
1179 * Return: 0 if all went well, else returns appropriate error value.
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)
1184 u8 c_state = 0, r_state = 0;
1187 if (!req_state && !curr_state)
1190 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1191 &r_state, &c_state);
1196 *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ);
1198 *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY);
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
1211 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
1223 return PTR_ERR(handle);
1227 info = handle_to_ti_sci_info(handle);
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));
1233 ret = PTR_ERR(xfer);
1234 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1237 req.dev_id = dev_id;
1238 req.clk_id = clk_id;
1239 req.parent_id = parent_id;
1241 ret = ti_sci_do_xfer(info, xfer);
1245 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1247 if (!ti_sci_is_response_ack(resp))
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
1262 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
1274 return PTR_ERR(handle);
1275 if (!handle || !parent_id)
1278 info = handle_to_ti_sci_info(handle);
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));
1284 ret = PTR_ERR(xfer);
1285 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1288 req.dev_id = dev_id;
1289 req.clk_id = clk_id;
1291 ret = ti_sci_do_xfer(info, xfer);
1295 resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->tx_message.buf;
1297 if (!ti_sci_is_response_ack(resp))
1300 *parent_id = resp->parent_id;
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.
1314 * Return: 0 if all went well, else returns appropriate error value.
1316 static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle *handle,
1317 u32 dev_id, u8 clk_id,
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;
1327 return PTR_ERR(handle);
1328 if (!handle || !num_parents)
1331 info = handle_to_ti_sci_info(handle);
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));
1337 ret = PTR_ERR(xfer);
1338 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1341 req.dev_id = dev_id;
1342 req.clk_id = clk_id;
1344 ret = ti_sci_do_xfer(info, xfer);
1348 resp = (struct ti_sci_msg_resp_get_clock_num_parents *)
1349 xfer->tx_message.buf;
1351 if (!ti_sci_is_response_ack(resp))
1354 *num_parents = resp->num_parents;
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.
1376 * Return: 0 if all went well, else returns appropriate error value.
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,
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;
1390 return PTR_ERR(handle);
1391 if (!handle || !match_freq)
1394 info = handle_to_ti_sci_info(handle);
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));
1400 ret = PTR_ERR(xfer);
1401 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
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;
1410 ret = ti_sci_do_xfer(info, xfer);
1414 resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->tx_message.buf;
1416 if (!ti_sci_is_response_ack(resp))
1419 *match_freq = resp->freq_hz;
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.
1440 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
1453 return PTR_ERR(handle);
1457 info = handle_to_ti_sci_info(handle);
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));
1463 ret = PTR_ERR(xfer);
1464 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
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;
1473 ret = ti_sci_do_xfer(info, xfer);
1477 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1479 if (!ti_sci_is_response_ack(resp))
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
1494 * Return: 0 if all went well, else returns appropriate error value.
1496 static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle,
1497 u32 dev_id, u8 clk_id, u64 *freq)
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;
1506 return PTR_ERR(handle);
1507 if (!handle || !freq)
1510 info = handle_to_ti_sci_info(handle);
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));
1516 ret = PTR_ERR(xfer);
1517 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1520 req.dev_id = dev_id;
1521 req.clk_id = clk_id;
1523 ret = ti_sci_do_xfer(info, xfer);
1527 resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->tx_message.buf;
1529 if (!ti_sci_is_response_ack(resp))
1532 *freq = resp->freq_hz;
1538 * ti_sci_cmd_core_reboot() - Command to request system reset
1539 * @handle: pointer to TI SCI handle
1541 * Return: 0 if all went well, else returns appropriate error value.
1543 static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle)
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;
1552 return PTR_ERR(handle);
1556 info = handle_to_ti_sci_info(handle);
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));
1562 ret = PTR_ERR(xfer);
1563 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1568 ret = ti_sci_do_xfer(info, xfer);
1572 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1574 if (!ti_sci_is_response_ack(resp))
1581 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1582 * to a host. Resource is uniquely identified by
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
1592 * Return: 0 if all went fine, else return appropriate error.
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)
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;
1605 return PTR_ERR(handle);
1609 info = handle_to_ti_sci_info(handle);
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));
1615 ret = PTR_ERR(xfer);
1616 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1620 req.secondary_host = s_host;
1621 req.type = dev_id & MSG_RM_RESOURCE_TYPE_MASK;
1622 req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK;
1624 ret = ti_sci_do_xfer(info, xfer);
1628 resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->tx_message.buf;
1629 if (!ti_sci_is_response_ack(resp)) {
1631 } else if (!resp->range_start && !resp->range_num) {
1634 *range_start = resp->range_start;
1635 *range_num = resp->range_num;
1642 static int __maybe_unused
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)
1647 struct ti_sci_resource_static_data *data;
1651 data = &rm_static_data[i];
1656 if (data->dev_id != dev_id || data->subtype != subtype) {
1661 *range_start = data->range_start;
1662 *range_num = data->range_num;
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
1680 * Return: 0 if all went fine, else return appropriate error.
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)
1686 return ti_sci_get_resource_range(handle, dev_id, subtype,
1687 TI_SCI_IRQ_SECONDARY_HOST_INVALID,
1688 range_start, range_num);
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
1702 * Return: 0 if all went fine, else return appropriate error.
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)
1709 return ti_sci_get_resource_range(handle, dev_id, subtype, s_host,
1710 range_start, range_num);
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
1719 * Return: 0 if all went well, else returns appropriate error value.
1721 static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle,
1722 u64 *msmc_start, u64 *msmc_end)
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;
1731 return PTR_ERR(handle);
1735 info = handle_to_ti_sci_info(handle);
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));
1741 ret = PTR_ERR(xfer);
1742 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1746 ret = ti_sci_do_xfer(info, xfer);
1750 resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf;
1752 if (!ti_sci_is_response_ack(resp))
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) |
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
1768 * Return: 0 if all went well, else returns appropriate error value.
1770 static int ti_sci_cmd_proc_request(const struct ti_sci_handle *handle,
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;
1780 return PTR_ERR(handle);
1784 info = handle_to_ti_sci_info(handle);
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));
1790 ret = PTR_ERR(xfer);
1791 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1794 req.processor_id = proc_id;
1796 ret = ti_sci_do_xfer(info, xfer);
1800 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1802 if (!ti_sci_is_response_ack(resp))
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
1813 * Return: 0 if all went well, else returns appropriate error value.
1815 static int ti_sci_cmd_proc_release(const struct ti_sci_handle *handle,
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;
1825 return PTR_ERR(handle);
1829 info = handle_to_ti_sci_info(handle);
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));
1835 ret = PTR_ERR(xfer);
1836 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1839 req.processor_id = proc_id;
1841 ret = ti_sci_do_xfer(info, xfer);
1845 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1847 if (!ti_sci_is_response_ack(resp))
1854 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
1855 * control to a host in the processor's access
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
1861 * Return: 0 if all went well, else returns appropriate error value.
1863 static int ti_sci_cmd_proc_handover(const struct ti_sci_handle *handle,
1864 u8 proc_id, u8 host_id)
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;
1873 return PTR_ERR(handle);
1877 info = handle_to_ti_sci_info(handle);
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));
1883 ret = PTR_ERR(xfer);
1884 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1887 req.processor_id = proc_id;
1888 req.host_id = host_id;
1890 ret = ti_sci_do_xfer(info, xfer);
1894 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1896 if (!ti_sci_is_response_ack(resp))
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.
1910 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
1924 return PTR_ERR(handle);
1928 info = handle_to_ti_sci_info(handle);
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));
1934 ret = PTR_ERR(xfer);
1935 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
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;
1945 ret = ti_sci_do_xfer(info, xfer);
1949 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1951 if (!ti_sci_is_response_ack(resp))
1958 * ti_sci_cmd_set_proc_boot_ctrl() - Command to set the processor boot
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
1965 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
1978 return PTR_ERR(handle);
1982 info = handle_to_ti_sci_info(handle);
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));
1988 ret = PTR_ERR(xfer);
1989 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1992 req.processor_id = proc_id;
1993 req.control_flags_set = control_flags_set;
1994 req.control_flags_clear = control_flags_clear;
1996 ret = ti_sci_do_xfer(info, xfer);
2000 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2002 if (!ti_sci_is_response_ack(resp))
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
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
2018 * Return: 0 if all went well, else returns appropriate error value.
2020 static int ti_sci_cmd_proc_auth_boot_image(const struct ti_sci_handle *handle,
2021 u64 *image_addr, u32 *image_size)
2023 struct ti_sci_msg_req_proc_auth_boot_image req;
2024 struct ti_sci_msg_resp_proc_auth_boot_image *resp;
2025 struct ti_sci_info *info;
2026 struct ti_sci_xfer *xfer;
2030 return PTR_ERR(handle);
2034 info = handle_to_ti_sci_info(handle);
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));
2040 ret = PTR_ERR(xfer);
2041 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2044 req.cert_addr_low = *image_addr & TISCI_ADDR_LOW_MASK;
2045 req.cert_addr_high = (*image_addr & TISCI_ADDR_HIGH_MASK) >>
2046 TISCI_ADDR_HIGH_SHIFT;
2048 ret = ti_sci_do_xfer(info, xfer);
2052 resp = (struct ti_sci_msg_resp_proc_auth_boot_image *)xfer->tx_message.buf;
2054 if (!ti_sci_is_response_ack(resp))
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;
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
2070 * Return: 0 if all went well, else returns appropriate error value.
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)
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;
2083 return PTR_ERR(handle);
2087 info = handle_to_ti_sci_info(handle);
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));
2093 ret = PTR_ERR(xfer);
2094 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2097 req.processor_id = proc_id;
2099 ret = ti_sci_do_xfer(info, xfer);
2103 resp = (struct ti_sci_msg_resp_get_proc_boot_status *)
2104 xfer->tx_message.buf;
2106 if (!ti_sci_is_response_ack(resp))
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;
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.
2151 * Return: 0 if all goes well, else appropriate error message
2154 ti_sci_proc_wait_boot_status_no_wait(const struct ti_sci_handle *handle,
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)
2165 struct ti_sci_msg_req_wait_proc_boot_status req;
2166 struct ti_sci_info *info;
2167 struct ti_sci_xfer *xfer;
2171 return PTR_ERR(handle);
2175 info = handle_to_ti_sci_info(handle);
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);
2181 ret = PTR_ERR(xfer);
2182 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
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;
2195 ret = ti_sci_do_xfer(info, xfer);
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
2210 * Return: 0 if all went well, else returns appropriate error value.
2212 static int ti_sci_cmd_proc_shutdown_no_wait(const struct ti_sci_handle *handle,
2216 struct ti_sci_info *info;
2219 return PTR_ERR(handle);
2223 info = handle_to_ti_sci_info(handle);
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.
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,
2239 dev_err(info->dev, "Sending core %u wait message fail %d\n",
2245 * Release a processor managed by TISCI without requesting or waiting
2248 ret = ti_sci_set_device_state_no_wait(handle, proc_id, 0,
2249 MSG_DEVICE_SW_STATE_AUTO_OFF);
2251 dev_err(info->dev, "Sending core %u shutdown message fail %d\n",
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.
2270 * Return: 0 if all went well, else returns appropriate error value.
2272 * See @ti_sci_msg_rm_ring_cfg_req for more info.
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)
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;
2286 return PTR_ERR(handle);
2290 info = handle_to_ti_sci_info(handle);
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));
2296 ret = PTR_ERR(xfer);
2297 dev_err(info->dev, "RM_RA:Message config failed(%d)\n", ret);
2300 req.valid_params = valid_params;
2301 req.nav_id = nav_id;
2303 req.addr_lo = addr_lo;
2304 req.addr_hi = addr_hi;
2308 req.order_id = order_id;
2310 ret = ti_sci_do_xfer(info, xfer);
2314 resp = (struct ti_sci_msg_rm_ring_cfg_resp *)xfer->tx_message.buf;
2316 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2319 dev_dbg(info->dev, "RM_RA:config ring %u ret:%d\n", index, ret);
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)
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;
2333 return PTR_ERR(handle);
2337 info = handle_to_ti_sci_info(handle);
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));
2343 ret = PTR_ERR(xfer);
2344 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2347 req.nav_id = nav_id;
2348 req.src_thread = src_thread;
2349 req.dst_thread = dst_thread;
2351 ret = ti_sci_do_xfer(info, xfer);
2355 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2356 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2359 dev_dbg(info->dev, "RM_PSIL: nav: %u link pair %u->%u ret:%u\n",
2360 nav_id, src_thread, dst_thread, ret);
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)
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;
2374 return PTR_ERR(handle);
2378 info = handle_to_ti_sci_info(handle);
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));
2384 ret = PTR_ERR(xfer);
2385 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2388 req.nav_id = nav_id;
2389 req.src_thread = src_thread;
2390 req.dst_thread = dst_thread;
2392 ret = ti_sci_do_xfer(info, xfer);
2396 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2397 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2400 dev_dbg(info->dev, "RM_PSIL: link unpair %u->%u ret:%u\n",
2401 src_thread, dst_thread, ret);
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)
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;
2416 return PTR_ERR(handle);
2420 info = handle_to_ti_sci_info(handle);
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));
2426 ret = PTR_ERR(xfer);
2427 dev_err(info->dev, "Message TX_CH_CFG alloc failed(%d)\n", ret);
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;
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;
2451 ret = ti_sci_do_xfer(info, xfer);
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;
2460 dev_dbg(info->dev, "TX_CH_CFG: chn %u ret:%u\n", params->index, ret);
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)
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;
2475 return PTR_ERR(handle);
2479 info = handle_to_ti_sci_info(handle);
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));
2485 ret = PTR_ERR(xfer);
2486 dev_err(info->dev, "Message RX_CH_CFG alloc failed(%d)\n", ret);
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;
2507 ret = ti_sci_do_xfer(info, xfer);
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;
2516 dev_dbg(info->dev, "RX_CH_CFG: chn %u ret:%d\n", params->index, ret);
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)
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;
2531 return PTR_ERR(handle);
2535 info = handle_to_ti_sci_info(handle);
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));
2541 ret = PTR_ERR(xfer);
2542 dev_err(info->dev, "RX_FL_CFG: Message alloc failed(%d)\n",
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;
2570 ret = ti_sci_do_xfer(info, xfer);
2575 (struct ti_sci_msg_rm_udmap_flow_cfg_resp *)xfer->tx_message.buf;
2576 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2579 dev_dbg(info->dev, "RX_FL_CFG: %u ret:%d\n", params->flow_index, ret);
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
2588 * Return: 0 if all went well, else returns appropriate error value.
2590 static int ti_sci_cmd_set_fwl_region(const struct ti_sci_handle *handle,
2591 const struct ti_sci_msg_fwl_region *region)
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;
2600 return PTR_ERR(handle);
2604 info = handle_to_ti_sci_info(handle);
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));
2610 ret = PTR_ERR(xfer);
2611 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
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;
2625 ret = ti_sci_do_xfer(info, xfer);
2629 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2631 if (!ti_sci_is_response_ack(resp))
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
2642 * Return: 0 if all went well, else returns appropriate error value.
2644 static int ti_sci_cmd_get_fwl_region(const struct ti_sci_handle *handle,
2645 struct ti_sci_msg_fwl_region *region)
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;
2654 return PTR_ERR(handle);
2658 info = handle_to_ti_sci_info(handle);
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));
2664 ret = PTR_ERR(xfer);
2665 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2669 req.fwl_id = region->fwl_id;
2670 req.region = region->region;
2671 req.n_permission_regs = region->n_permission_regs;
2673 ret = ti_sci_do_xfer(info, xfer);
2677 resp = (struct ti_sci_msg_fwl_get_firewall_region_resp *)xfer->tx_message.buf;
2679 if (!ti_sci_is_response_ack(resp))
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;
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
2700 * Return: 0 if all went well, else returns appropriate error value.
2702 static int ti_sci_cmd_change_fwl_owner(const struct ti_sci_handle *handle,
2703 struct ti_sci_msg_fwl_owner *owner)
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;
2712 return PTR_ERR(handle);
2716 info = handle_to_ti_sci_info(handle);
2718 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_CHANGE_OWNER,
2719 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2720 (u32 *)&req, sizeof(req), sizeof(*resp));
2722 ret = PTR_ERR(xfer);
2723 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2727 req.fwl_id = owner->fwl_id;
2728 req.region = owner->region;
2729 req.owner_index = owner->owner_index;
2731 ret = ti_sci_do_xfer(info, xfer);
2735 resp = (struct ti_sci_msg_fwl_change_owner_info_resp *)xfer->tx_message.buf;
2737 if (!ti_sci_is_response_ack(resp))
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;
2750 * ti_sci_setup_ops() - Setup the operations structures
2751 * @info: pointer to TISCI pointer
2753 static void ti_sci_setup_ops(struct ti_sci_info *info)
2755 struct ti_sci_ops *ops = &info->handle.ops;
2756 struct ti_sci_board_ops *bops = &ops->board_ops;
2757 struct ti_sci_dev_ops *dops = &ops->dev_ops;
2758 struct ti_sci_clk_ops *cops = &ops->clk_ops;
2759 struct ti_sci_core_ops *core_ops = &ops->core_ops;
2760 struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
2761 struct ti_sci_proc_ops *pops = &ops->proc_ops;
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;
2765 struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops;
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;
2772 dops->get_device = ti_sci_cmd_get_device;
2773 dops->get_device_exclusive = ti_sci_cmd_get_device_exclusive;
2774 dops->idle_device = ti_sci_cmd_idle_device;
2775 dops->idle_device_exclusive = ti_sci_cmd_idle_device_exclusive;
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;
2785 dops->release_exclusive_devices = ti_sci_cmd_release_exclusive_devices;
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;
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;
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;
2802 core_ops->reboot_device = ti_sci_cmd_core_reboot;
2803 core_ops->query_msmc = ti_sci_cmd_query_msmc;
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;
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;
2816 pops->proc_shutdown_no_wait = ti_sci_cmd_proc_shutdown_no_wait;
2818 rops->config = ti_sci_cmd_ring_config;
2820 psilops->pair = ti_sci_cmd_rm_psil_pair;
2821 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
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;
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;
2833 * ti_sci_get_handle_from_sysfw() - Get the TI SCI handle of the SYSFW
2834 * @dev: Pointer to the SYSFW device
2836 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2840 struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *sci_dev)
2843 return ERR_PTR(-EINVAL);
2845 struct ti_sci_info *info = dev_get_priv(sci_dev);
2848 return ERR_PTR(-EINVAL);
2850 struct ti_sci_handle *handle = &info->handle;
2853 return ERR_PTR(-EINVAL);
2859 * ti_sci_get_handle() - Get the TI SCI handle for a device
2860 * @dev: Pointer to device for which we want SCI handle
2862 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2865 const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
2868 return ERR_PTR(-EINVAL);
2870 struct udevice *sci_dev = dev_get_parent(dev);
2872 return ti_sci_get_handle_from_sysfw(sci_dev);
2876 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
2878 * @propname: property name containing phandle on TISCI node
2880 * Return: pointer to handle if successful, else appropriate error value.
2882 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
2883 const char *property)
2885 struct ti_sci_info *entry, *info = NULL;
2889 err = ofnode_read_u32(dev_ofnode(dev), property, &phandle);
2891 return ERR_PTR(err);
2893 node = ofnode_get_by_phandle(phandle);
2894 if (!ofnode_valid(node))
2895 return ERR_PTR(-EINVAL);
2897 list_for_each_entry(entry, &ti_sci_list, list)
2898 if (ofnode_equal(dev_ofnode(entry->dev), node)) {
2904 return ERR_PTR(-ENODEV);
2906 return &info->handle;
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
2914 * Return: 0 if all goes good, else appropriate error message.
2916 static int ti_sci_of_to_info(struct udevice *dev, struct ti_sci_info *info)
2920 ret = mbox_get_by_name(dev, "tx", &info->chan_tx);
2922 dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n",
2927 ret = mbox_get_by_name(dev, "rx", &info->chan_rx);
2929 dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n",
2934 /* Notify channel is optional. Enable only if populated */
2935 ret = mbox_get_by_name(dev, "notify", &info->chan_notify);
2937 dev_dbg(dev, "%s: Acquiring notify channel failed. ret = %d\n",
2941 info->host_id = dev_read_u32_default(dev, "ti,host-id",
2942 info->desc->default_host_id);
2944 info->is_secure = dev_read_bool(dev, "ti,secure-host");
2950 * ti_sci_probe() - Basic probe
2951 * @dev: corresponding system controller interface device
2953 * Return: 0 if all goes good, else appropriate error message.
2955 static int ti_sci_probe(struct udevice *dev)
2957 struct ti_sci_info *info;
2960 debug("%s(dev=%p)\n", __func__, dev);
2962 info = dev_get_priv(dev);
2963 info->desc = (void *)dev_get_driver_data(dev);
2965 ret = ti_sci_of_to_info(dev, info);
2967 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
2974 list_add_tail(&info->list, &ti_sci_list);
2975 ti_sci_setup_ops(info);
2977 ret = ti_sci_cmd_get_revision(&info->handle);
2979 INIT_LIST_HEAD(&info->dev_list);
2985 * ti_sci_dm_probe() - Basic probe for DM to TIFS SCI
2986 * @dev: corresponding system controller interface device
2988 * Return: 0 if all goes good, else appropriate error message.
2990 static __maybe_unused int ti_sci_dm_probe(struct udevice *dev)
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;
3000 debug("%s(dev=%p)\n", __func__, dev);
3002 info = dev_get_priv(dev);
3003 info->desc = (void *)dev_get_driver_data(dev);
3005 ret = ti_sci_of_to_info(dev, info);
3007 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
3014 list_add_tail(&info->list, &ti_sci_list);
3016 ops = &info->handle.ops;
3018 rm_core_ops = &ops->rm_core_ops;
3019 rm_core_ops->get_range = ti_sci_cmd_get_resource_range_static;
3021 rops = &ops->rm_ring_ops;
3022 rops->config = ti_sci_cmd_ring_config;
3024 psilops = &ops->rm_psil_ops;
3025 psilops->pair = ti_sci_cmd_rm_psil_pair;
3026 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
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;
3037 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
3038 * @res: Pointer to the TISCI resource
3040 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
3042 u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
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;
3055 return TI_SCI_RESOURCE_NULL;
3059 * ti_sci_release_resource() - Release a resource from TISCI resource.
3060 * @res: Pointer to the TISCI resource
3062 void ti_sci_release_resource(struct ti_sci_resource *res, u16 id)
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);
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
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.
3085 * Return: Pointer to ti_sci_resource if all went well else appropriate
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)
3092 u32 resource_subtype;
3093 struct ti_sci_resource *res;
3094 bool valid_set = false;
3098 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
3100 return ERR_PTR(-ENOMEM);
3102 sets = dev_read_size(dev, of_prop);
3104 dev_err(dev, "%s resource type ids not available\n", of_prop);
3105 return ERR_PTR(sets);
3107 temp = malloc(sets);
3108 sets /= sizeof(u32);
3111 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
3114 return ERR_PTR(-ENOMEM);
3116 ret = dev_read_u32_array(dev, of_prop, temp, res->sets);
3118 return ERR_PTR(-EINVAL);
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,
3124 &res->desc[i].start,
3127 dev_dbg(dev, "type %d subtype %d not allocated for host %d\n",
3128 dev_id, resource_subtype,
3129 handle_to_ti_sci_info(handle)->host_id);
3130 res->desc[i].start = 0;
3131 res->desc[i].num = 0;
3136 dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n",
3137 dev_id, resource_subtype, res->desc[i].start,
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);
3150 return ERR_PTR(-EINVAL);
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! */
3163 /* Description for AM654 */
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! */
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,
3181 static const struct udevice_id ti_sci_ids[] = {
3183 .compatible = "ti,k2g-sci",
3184 .data = (ulong)&ti_sci_pmmc_k2g_desc
3187 .compatible = "ti,am654-sci",
3188 .data = (ulong)&ti_sci_pmmc_am654_desc
3193 static __maybe_unused const struct udevice_id ti_sci_dm_ids[] = {
3195 .compatible = "ti,j721e-dm-sci",
3196 .data = (ulong)&ti_sci_dm_j721e_desc
3201 U_BOOT_DRIVER(ti_sci) = {
3203 .id = UCLASS_FIRMWARE,
3204 .of_match = ti_sci_ids,
3205 .probe = ti_sci_probe,
3206 .priv_auto = sizeof(struct ti_sci_info),
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),