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/compat.h>
20 #include <linux/err.h>
21 #include <linux/soc/ti/k3-sec-proxy.h>
22 #include <linux/soc/ti/ti_sci_protocol.h>
26 /* List of all TI SCI devices active in system */
27 static LIST_HEAD(ti_sci_list);
30 * struct ti_sci_xfer - Structure representing a message flow
31 * @tx_message: Transmit message
32 * @rx_len: Receive message length
35 struct k3_sec_proxy_msg tx_message;
40 * struct ti_sci_rm_type_map - Structure representing TISCI Resource
41 * management representation of dev_ids.
42 * @dev_id: TISCI device ID
43 * @type: Corresponding id as identified by TISCI RM.
45 * Note: This is used only as a work around for using RM range apis
46 * for AM654 SoC. For future SoCs dev_id will be used as type
47 * for RM range APIs. In order to maintain ABI backward compatibility
48 * type is not being changed for AM654 SoC.
50 struct ti_sci_rm_type_map {
56 * struct ti_sci_desc - Description of SoC integration
57 * @default_host_id: Host identifier representing the compute entity
58 * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
59 * @max_msgs: Maximum number of messages that can be pending
60 * simultaneously in the system
61 * @max_msg_size: Maximum size of data per message that can be handled.
62 * @rm_type_map: RM resource type mapping structure.
66 int max_rx_timeout_ms;
69 struct ti_sci_rm_type_map *rm_type_map;
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);
291 dev_err(info->dev, "Mbox communication fail %d\n", ret);
295 rev_info = (struct ti_sci_msg_resp_version *)xfer->tx_message.buf;
297 ver = &handle->version;
298 ver->abi_major = rev_info->abi_major;
299 ver->abi_minor = rev_info->abi_minor;
300 ver->firmware_revision = rev_info->firmware_revision;
301 strncpy(ver->firmware_description, rev_info->firmware_description,
302 sizeof(ver->firmware_description));
308 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
309 * @r: pointer to response buffer
311 * Return: true if the response was an ACK, else returns false.
313 static inline bool ti_sci_is_response_ack(void *r)
315 struct ti_sci_msg_hdr *hdr = r;
317 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false;
321 * cmd_set_board_config_using_msg() - Common command to send board configuration
323 * @handle: pointer to TI SCI handle
324 * @msg_type: One of the TISCI message types to set board configuration
325 * @addr: Address where the board config structure is located
326 * @size: Size of the board config structure
328 * Return: 0 if all went well, else returns appropriate error value.
330 static int cmd_set_board_config_using_msg(const struct ti_sci_handle *handle,
331 u16 msg_type, u64 addr, u32 size)
333 struct ti_sci_msg_board_config req;
334 struct ti_sci_msg_hdr *resp;
335 struct ti_sci_info *info;
336 struct ti_sci_xfer *xfer;
340 return PTR_ERR(handle);
344 info = handle_to_ti_sci_info(handle);
346 xfer = ti_sci_setup_one_xfer(info, msg_type,
347 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
348 (u32 *)&req, sizeof(req), sizeof(*resp));
351 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
354 req.boardcfgp_high = (addr >> 32) & 0xffffffff;
355 req.boardcfgp_low = addr & 0xffffffff;
356 req.boardcfg_size = size;
358 ret = ti_sci_do_xfer(info, xfer);
360 dev_err(info->dev, "Mbox send fail %d\n", ret);
364 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
366 if (!ti_sci_is_response_ack(resp))
373 * ti_sci_cmd_set_board_config() - Command to send board configuration message
374 * @handle: pointer to TI SCI handle
375 * @addr: Address where the board config structure is located
376 * @size: Size of the board config structure
378 * Return: 0 if all went well, else returns appropriate error value.
380 static int ti_sci_cmd_set_board_config(const struct ti_sci_handle *handle,
383 return cmd_set_board_config_using_msg(handle,
384 TI_SCI_MSG_BOARD_CONFIG,
389 * ti_sci_cmd_set_board_config_rm() - Command to send board resource
390 * management configuration
391 * @handle: pointer to TI SCI handle
392 * @addr: Address where the board RM config structure is located
393 * @size: Size of the RM config structure
395 * Return: 0 if all went well, else returns appropriate error value.
398 int ti_sci_cmd_set_board_config_rm(const struct ti_sci_handle *handle,
401 return cmd_set_board_config_using_msg(handle,
402 TI_SCI_MSG_BOARD_CONFIG_RM,
407 * ti_sci_cmd_set_board_config_security() - Command to send board security
408 * configuration message
409 * @handle: pointer to TI SCI handle
410 * @addr: Address where the board security config structure is located
411 * @size: Size of the security config structure
413 * Return: 0 if all went well, else returns appropriate error value.
416 int ti_sci_cmd_set_board_config_security(const struct ti_sci_handle *handle,
419 return cmd_set_board_config_using_msg(handle,
420 TI_SCI_MSG_BOARD_CONFIG_SECURITY,
425 * ti_sci_cmd_set_board_config_pm() - Command to send board power and clock
426 * configuration message
427 * @handle: pointer to TI SCI handle
428 * @addr: Address where the board PM config structure is located
429 * @size: Size of the PM config structure
431 * Return: 0 if all went well, else returns appropriate error value.
433 static int ti_sci_cmd_set_board_config_pm(const struct ti_sci_handle *handle,
436 return cmd_set_board_config_using_msg(handle,
437 TI_SCI_MSG_BOARD_CONFIG_PM,
441 static struct ti_sci_exclusive_dev
442 *ti_sci_get_exclusive_dev(struct list_head *dev_list, u32 id)
444 struct ti_sci_exclusive_dev *dev;
446 list_for_each_entry(dev, dev_list, list)
453 static void ti_sci_add_exclusive_dev(struct ti_sci_info *info, u32 id)
455 struct ti_sci_exclusive_dev *dev;
457 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
463 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
466 INIT_LIST_HEAD(&dev->list);
467 list_add_tail(&dev->list, &info->dev_list);
470 static void ti_sci_delete_exclusive_dev(struct ti_sci_info *info, u32 id)
472 struct ti_sci_exclusive_dev *dev;
474 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
483 * ti_sci_set_device_state() - Set device state helper
484 * @handle: pointer to TI SCI handle
485 * @id: Device identifier
486 * @flags: flags to setup for the device
487 * @state: State to move the device to
489 * Return: 0 if all went well, else returns appropriate error value.
491 static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
492 u32 id, u32 flags, u8 state)
494 struct ti_sci_msg_req_set_device_state req;
495 struct ti_sci_msg_hdr *resp;
496 struct ti_sci_info *info;
497 struct ti_sci_xfer *xfer;
501 return PTR_ERR(handle);
505 info = handle_to_ti_sci_info(handle);
507 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
508 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
509 (u32 *)&req, sizeof(req), sizeof(*resp));
512 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
518 ret = ti_sci_do_xfer(info, xfer);
520 dev_err(info->dev, "Mbox send fail %d\n", ret);
524 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
526 if (!ti_sci_is_response_ack(resp))
529 if (state == MSG_DEVICE_SW_STATE_AUTO_OFF)
530 ti_sci_delete_exclusive_dev(info, id);
531 else if (flags & MSG_FLAG_DEVICE_EXCLUSIVE)
532 ti_sci_add_exclusive_dev(info, id);
538 * ti_sci_set_device_state_no_wait() - Set device state helper without
539 * requesting or waiting for a response.
540 * @handle: pointer to TI SCI handle
541 * @id: Device identifier
542 * @flags: flags to setup for the device
543 * @state: State to move the device to
545 * Return: 0 if all went well, else returns appropriate error value.
547 static int ti_sci_set_device_state_no_wait(const struct ti_sci_handle *handle,
548 u32 id, u32 flags, u8 state)
550 struct ti_sci_msg_req_set_device_state req;
551 struct ti_sci_info *info;
552 struct ti_sci_xfer *xfer;
556 return PTR_ERR(handle);
560 info = handle_to_ti_sci_info(handle);
562 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
563 flags | TI_SCI_FLAG_REQ_GENERIC_NORESPONSE,
564 (u32 *)&req, sizeof(req), 0);
567 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
573 ret = ti_sci_do_xfer(info, xfer);
575 dev_err(info->dev, "Mbox send fail %d\n", ret);
581 * ti_sci_get_device_state() - Get device state helper
582 * @handle: Handle to the device
583 * @id: Device Identifier
584 * @clcnt: Pointer to Context Loss Count
585 * @resets: pointer to resets
586 * @p_state: pointer to p_state
587 * @c_state: pointer to c_state
589 * Return: 0 if all went fine, else return appropriate error.
591 static int ti_sci_get_device_state(const struct ti_sci_handle *handle,
592 u32 id, u32 *clcnt, u32 *resets,
593 u8 *p_state, u8 *c_state)
595 struct ti_sci_msg_resp_get_device_state *resp;
596 struct ti_sci_msg_req_get_device_state req;
597 struct ti_sci_info *info;
598 struct ti_sci_xfer *xfer;
602 return PTR_ERR(handle);
606 if (!clcnt && !resets && !p_state && !c_state)
609 info = handle_to_ti_sci_info(handle);
611 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_DEVICE_STATE,
612 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
613 (u32 *)&req, sizeof(req), sizeof(*resp));
616 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
621 ret = ti_sci_do_xfer(info, xfer);
623 dev_err(dev, "Mbox send fail %d\n", ret);
627 resp = (struct ti_sci_msg_resp_get_device_state *)xfer->tx_message.buf;
628 if (!ti_sci_is_response_ack(resp))
632 *clcnt = resp->context_loss_count;
634 *resets = resp->resets;
636 *p_state = resp->programmed_state;
638 *c_state = resp->current_state;
644 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
645 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
646 * @id: Device Identifier
648 * Request for the device - NOTE: the client MUST maintain integrity of
649 * usage count by balancing get_device with put_device. No refcounting is
650 * managed by driver for that purpose.
652 * NOTE: The request is for exclusive access for the processor.
654 * Return: 0 if all went fine, else return appropriate error.
656 static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
658 return ti_sci_set_device_state(handle, id, 0,
659 MSG_DEVICE_SW_STATE_ON);
662 static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle *handle,
665 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
666 MSG_DEVICE_SW_STATE_ON);
670 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
671 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
672 * @id: Device Identifier
674 * Request for the device - NOTE: the client MUST maintain integrity of
675 * usage count by balancing get_device with put_device. No refcounting is
676 * managed by driver for that purpose.
678 * Return: 0 if all went fine, else return appropriate error.
680 static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
682 return ti_sci_set_device_state(handle, id,
684 MSG_DEVICE_SW_STATE_RETENTION);
687 static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle *handle,
690 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
691 MSG_DEVICE_SW_STATE_RETENTION);
695 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
696 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
697 * @id: Device Identifier
699 * Request for the device - NOTE: the client MUST maintain integrity of
700 * usage count by balancing get_device with put_device. No refcounting is
701 * managed by driver for that purpose.
703 * Return: 0 if all went fine, else return appropriate error.
705 static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
707 return ti_sci_set_device_state(handle, id, 0,
708 MSG_DEVICE_SW_STATE_AUTO_OFF);
712 int ti_sci_cmd_release_exclusive_devices(const struct ti_sci_handle *handle)
714 struct ti_sci_exclusive_dev *dev, *tmp;
715 struct ti_sci_info *info;
718 info = handle_to_ti_sci_info(handle);
720 list_for_each_entry_safe(dev, tmp, &info->dev_list, list) {
722 debug("%s: id = %d, cnt = %d\n", __func__, dev->id, cnt);
723 for (i = 0; i < cnt; i++)
724 ti_sci_cmd_put_device(handle, dev->id);
731 * ti_sci_cmd_dev_is_valid() - Is the device valid
732 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
733 * @id: Device Identifier
735 * Return: 0 if all went fine and the device ID is valid, else return
738 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
742 /* check the device state which will also tell us if the ID is valid */
743 return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused);
747 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
748 * @handle: Pointer to TISCI handle
749 * @id: Device Identifier
750 * @count: Pointer to Context Loss counter to populate
752 * Return: 0 if all went fine, else return appropriate error.
754 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
757 return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
761 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
762 * @handle: Pointer to TISCI handle
763 * @id: Device Identifier
764 * @r_state: true if requested to be idle
766 * Return: 0 if all went fine, else return appropriate error.
768 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
777 ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
781 *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
787 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
788 * @handle: Pointer to TISCI handle
789 * @id: Device Identifier
790 * @r_state: true if requested to be stopped
791 * @curr_state: true if currently stopped.
793 * Return: 0 if all went fine, else return appropriate error.
795 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
796 bool *r_state, bool *curr_state)
801 if (!r_state && !curr_state)
805 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
810 *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
812 *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
818 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
819 * @handle: Pointer to TISCI handle
820 * @id: Device Identifier
821 * @r_state: true if requested to be ON
822 * @curr_state: true if currently ON and active
824 * Return: 0 if all went fine, else return appropriate error.
826 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
827 bool *r_state, bool *curr_state)
832 if (!r_state && !curr_state)
836 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
841 *r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
843 *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
849 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
850 * @handle: Pointer to TISCI handle
851 * @id: Device Identifier
852 * @curr_state: true if currently transitioning.
854 * Return: 0 if all went fine, else return appropriate error.
856 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
865 ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
869 *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
875 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
877 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
878 * @id: Device Identifier
879 * @reset_state: Device specific reset bit field
881 * Return: 0 if all went fine, else return appropriate error.
883 static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
884 u32 id, u32 reset_state)
886 struct ti_sci_msg_req_set_device_resets req;
887 struct ti_sci_msg_hdr *resp;
888 struct ti_sci_info *info;
889 struct ti_sci_xfer *xfer;
893 return PTR_ERR(handle);
897 info = handle_to_ti_sci_info(handle);
899 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_RESETS,
900 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
901 (u32 *)&req, sizeof(req), sizeof(*resp));
904 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
908 req.resets = reset_state;
910 ret = ti_sci_do_xfer(info, xfer);
912 dev_err(info->dev, "Mbox send fail %d\n", ret);
916 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
918 if (!ti_sci_is_response_ack(resp))
925 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
927 * @handle: Pointer to TISCI handle
928 * @id: Device Identifier
929 * @reset_state: Pointer to reset state to populate
931 * Return: 0 if all went fine, else return appropriate error.
933 static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
934 u32 id, u32 *reset_state)
936 return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
941 * ti_sci_set_clock_state() - Set clock state helper
942 * @handle: pointer to TI SCI handle
943 * @dev_id: Device identifier this request is for
944 * @clk_id: Clock identifier for the device for this request.
945 * Each device has it's own set of clock inputs. This indexes
946 * which clock input to modify.
947 * @flags: Header flags as needed
948 * @state: State to request for the clock.
950 * Return: 0 if all went well, else returns appropriate error value.
952 static int ti_sci_set_clock_state(const struct ti_sci_handle *handle,
953 u32 dev_id, u8 clk_id,
956 struct ti_sci_msg_req_set_clock_state req;
957 struct ti_sci_msg_hdr *resp;
958 struct ti_sci_info *info;
959 struct ti_sci_xfer *xfer;
963 return PTR_ERR(handle);
967 info = handle_to_ti_sci_info(handle);
969 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_STATE,
970 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
971 (u32 *)&req, sizeof(req), sizeof(*resp));
974 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
979 req.request_state = state;
981 ret = ti_sci_do_xfer(info, xfer);
983 dev_err(info->dev, "Mbox send fail %d\n", ret);
987 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
989 if (!ti_sci_is_response_ack(resp))
996 * ti_sci_cmd_get_clock_state() - Get clock state helper
997 * @handle: pointer to TI SCI handle
998 * @dev_id: Device identifier this request is for
999 * @clk_id: Clock identifier for the device for this request.
1000 * Each device has it's own set of clock inputs. This indexes
1001 * which clock input to modify.
1002 * @programmed_state: State requested for clock to move to
1003 * @current_state: State that the clock is currently in
1005 * Return: 0 if all went well, else returns appropriate error value.
1007 static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle *handle,
1008 u32 dev_id, u8 clk_id,
1009 u8 *programmed_state, u8 *current_state)
1011 struct ti_sci_msg_resp_get_clock_state *resp;
1012 struct ti_sci_msg_req_get_clock_state req;
1013 struct ti_sci_info *info;
1014 struct ti_sci_xfer *xfer;
1018 return PTR_ERR(handle);
1022 if (!programmed_state && !current_state)
1025 info = handle_to_ti_sci_info(handle);
1027 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_STATE,
1028 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1029 (u32 *)&req, sizeof(req), sizeof(*resp));
1031 ret = PTR_ERR(xfer);
1032 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1035 req.dev_id = dev_id;
1036 req.clk_id = clk_id;
1038 ret = ti_sci_do_xfer(info, xfer);
1040 dev_err(info->dev, "Mbox send fail %d\n", ret);
1044 resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->tx_message.buf;
1046 if (!ti_sci_is_response_ack(resp))
1049 if (programmed_state)
1050 *programmed_state = resp->programmed_state;
1052 *current_state = resp->current_state;
1058 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
1059 * @handle: pointer to TI SCI handle
1060 * @dev_id: Device identifier this request is for
1061 * @clk_id: Clock identifier for the device for this request.
1062 * Each device has it's own set of clock inputs. This indexes
1063 * which clock input to modify.
1064 * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false'
1065 * @can_change_freq: 'true' if frequency change is desired, else 'false'
1066 * @enable_input_term: 'true' if input termination is desired, else 'false'
1068 * Return: 0 if all went well, else returns appropriate error value.
1070 static int ti_sci_cmd_get_clock(const struct ti_sci_handle *handle, u32 dev_id,
1071 u8 clk_id, bool needs_ssc, bool can_change_freq,
1072 bool enable_input_term)
1076 flags |= needs_ssc ? MSG_FLAG_CLOCK_ALLOW_SSC : 0;
1077 flags |= can_change_freq ? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE : 0;
1078 flags |= enable_input_term ? MSG_FLAG_CLOCK_INPUT_TERM : 0;
1080 return ti_sci_set_clock_state(handle, dev_id, clk_id, flags,
1081 MSG_CLOCK_SW_STATE_REQ);
1085 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
1086 * @handle: pointer to TI SCI handle
1087 * @dev_id: Device identifier this request is for
1088 * @clk_id: Clock identifier for the device for this request.
1089 * Each device has it's own set of clock inputs. This indexes
1090 * which clock input to modify.
1092 * NOTE: This clock must have been requested by get_clock previously.
1094 * Return: 0 if all went well, else returns appropriate error value.
1096 static int ti_sci_cmd_idle_clock(const struct ti_sci_handle *handle,
1097 u32 dev_id, u8 clk_id)
1099 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1100 MSG_CLOCK_SW_STATE_UNREQ);
1104 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
1105 * @handle: pointer to TI SCI handle
1106 * @dev_id: Device identifier this request is for
1107 * @clk_id: Clock identifier for the device for this request.
1108 * Each device has it's own set of clock inputs. This indexes
1109 * which clock input to modify.
1111 * NOTE: This clock must have been requested by get_clock previously.
1113 * Return: 0 if all went well, else returns appropriate error value.
1115 static int ti_sci_cmd_put_clock(const struct ti_sci_handle *handle,
1116 u32 dev_id, u8 clk_id)
1118 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1119 MSG_CLOCK_SW_STATE_AUTO);
1123 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
1124 * @handle: pointer to TI SCI handle
1125 * @dev_id: Device identifier this request is for
1126 * @clk_id: Clock identifier for the device for this request.
1127 * Each device has it's own set of clock inputs. This indexes
1128 * which clock input to modify.
1129 * @req_state: state indicating if the clock is auto managed
1131 * Return: 0 if all went well, else returns appropriate error value.
1133 static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle *handle,
1134 u32 dev_id, u8 clk_id, bool *req_state)
1142 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, &state, NULL);
1146 *req_state = (state == MSG_CLOCK_SW_STATE_AUTO);
1151 * ti_sci_cmd_clk_is_on() - Is the clock ON
1152 * @handle: pointer to TI SCI handle
1153 * @dev_id: Device identifier this request is for
1154 * @clk_id: Clock identifier for the device for this request.
1155 * Each device has it's own set of clock inputs. This indexes
1156 * which clock input to modify.
1157 * @req_state: state indicating if the clock is managed by us and enabled
1158 * @curr_state: state indicating if the clock is ready for operation
1160 * Return: 0 if all went well, else returns appropriate error value.
1162 static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle *handle, u32 dev_id,
1163 u8 clk_id, bool *req_state, bool *curr_state)
1165 u8 c_state = 0, r_state = 0;
1168 if (!req_state && !curr_state)
1171 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1172 &r_state, &c_state);
1177 *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ);
1179 *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY);
1184 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1185 * @handle: pointer to TI SCI handle
1186 * @dev_id: Device identifier this request is for
1187 * @clk_id: Clock identifier for the device for this request.
1188 * Each device has it's own set of clock inputs. This indexes
1189 * which clock input to modify.
1190 * @req_state: state indicating if the clock is managed by us and disabled
1191 * @curr_state: state indicating if the clock is NOT ready for operation
1193 * Return: 0 if all went well, else returns appropriate error value.
1195 static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle *handle, u32 dev_id,
1196 u8 clk_id, bool *req_state, bool *curr_state)
1198 u8 c_state = 0, r_state = 0;
1201 if (!req_state && !curr_state)
1204 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1205 &r_state, &c_state);
1210 *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ);
1212 *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY);
1217 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1218 * @handle: pointer to TI SCI handle
1219 * @dev_id: Device identifier this request is for
1220 * @clk_id: Clock identifier for the device for this request.
1221 * Each device has it's own set of clock inputs. This indexes
1222 * which clock input to modify.
1223 * @parent_id: Parent clock identifier to set
1225 * Return: 0 if all went well, else returns appropriate error value.
1227 static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle *handle,
1228 u32 dev_id, u8 clk_id, u8 parent_id)
1230 struct ti_sci_msg_req_set_clock_parent req;
1231 struct ti_sci_msg_hdr *resp;
1232 struct ti_sci_info *info;
1233 struct ti_sci_xfer *xfer;
1237 return PTR_ERR(handle);
1241 info = handle_to_ti_sci_info(handle);
1243 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_PARENT,
1244 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1245 (u32 *)&req, sizeof(req), sizeof(*resp));
1247 ret = PTR_ERR(xfer);
1248 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1251 req.dev_id = dev_id;
1252 req.clk_id = clk_id;
1253 req.parent_id = parent_id;
1255 ret = ti_sci_do_xfer(info, xfer);
1257 dev_err(info->dev, "Mbox send fail %d\n", ret);
1261 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1263 if (!ti_sci_is_response_ack(resp))
1270 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1271 * @handle: pointer to TI SCI handle
1272 * @dev_id: Device identifier this request is for
1273 * @clk_id: Clock identifier for the device for this request.
1274 * Each device has it's own set of clock inputs. This indexes
1275 * which clock input to modify.
1276 * @parent_id: Current clock parent
1278 * Return: 0 if all went well, else returns appropriate error value.
1280 static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle,
1281 u32 dev_id, u8 clk_id, u8 *parent_id)
1283 struct ti_sci_msg_resp_get_clock_parent *resp;
1284 struct ti_sci_msg_req_get_clock_parent req;
1285 struct ti_sci_info *info;
1286 struct ti_sci_xfer *xfer;
1290 return PTR_ERR(handle);
1291 if (!handle || !parent_id)
1294 info = handle_to_ti_sci_info(handle);
1296 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_PARENT,
1297 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1298 (u32 *)&req, sizeof(req), sizeof(*resp));
1300 ret = PTR_ERR(xfer);
1301 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1304 req.dev_id = dev_id;
1305 req.clk_id = clk_id;
1307 ret = ti_sci_do_xfer(info, xfer);
1309 dev_err(info->dev, "Mbox send fail %d\n", ret);
1313 resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->tx_message.buf;
1315 if (!ti_sci_is_response_ack(resp))
1318 *parent_id = resp->parent_id;
1324 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1325 * @handle: pointer to TI SCI handle
1326 * @dev_id: Device identifier this request is for
1327 * @clk_id: Clock identifier for the device for this request.
1328 * Each device has it's own set of clock inputs. This indexes
1329 * which clock input to modify.
1330 * @num_parents: Returns he number of parents to the current clock.
1332 * Return: 0 if all went well, else returns appropriate error value.
1334 static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle *handle,
1335 u32 dev_id, u8 clk_id,
1338 struct ti_sci_msg_resp_get_clock_num_parents *resp;
1339 struct ti_sci_msg_req_get_clock_num_parents req;
1340 struct ti_sci_info *info;
1341 struct ti_sci_xfer *xfer;
1345 return PTR_ERR(handle);
1346 if (!handle || !num_parents)
1349 info = handle_to_ti_sci_info(handle);
1351 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS,
1352 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1353 (u32 *)&req, sizeof(req), sizeof(*resp));
1355 ret = PTR_ERR(xfer);
1356 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1359 req.dev_id = dev_id;
1360 req.clk_id = clk_id;
1362 ret = ti_sci_do_xfer(info, xfer);
1364 dev_err(info->dev, "Mbox send fail %d\n", ret);
1368 resp = (struct ti_sci_msg_resp_get_clock_num_parents *)
1369 xfer->tx_message.buf;
1371 if (!ti_sci_is_response_ack(resp))
1374 *num_parents = resp->num_parents;
1380 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1381 * @handle: pointer to TI SCI handle
1382 * @dev_id: Device identifier this request is for
1383 * @clk_id: Clock identifier for the device for this request.
1384 * Each device has it's own set of clock inputs. This indexes
1385 * which clock input to modify.
1386 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1387 * allowable programmed frequency and does not account for clock
1388 * tolerances and jitter.
1389 * @target_freq: The target clock frequency in Hz. A frequency will be
1390 * processed as close to this target frequency as possible.
1391 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1392 * allowable programmed frequency and does not account for clock
1393 * tolerances and jitter.
1394 * @match_freq: Frequency match in Hz response.
1396 * Return: 0 if all went well, else returns appropriate error value.
1398 static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle *handle,
1399 u32 dev_id, u8 clk_id, u64 min_freq,
1400 u64 target_freq, u64 max_freq,
1403 struct ti_sci_msg_resp_query_clock_freq *resp;
1404 struct ti_sci_msg_req_query_clock_freq req;
1405 struct ti_sci_info *info;
1406 struct ti_sci_xfer *xfer;
1410 return PTR_ERR(handle);
1411 if (!handle || !match_freq)
1414 info = handle_to_ti_sci_info(handle);
1416 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_QUERY_CLOCK_FREQ,
1417 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1418 (u32 *)&req, sizeof(req), sizeof(*resp));
1420 ret = PTR_ERR(xfer);
1421 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1424 req.dev_id = dev_id;
1425 req.clk_id = clk_id;
1426 req.min_freq_hz = min_freq;
1427 req.target_freq_hz = target_freq;
1428 req.max_freq_hz = max_freq;
1430 ret = ti_sci_do_xfer(info, xfer);
1432 dev_err(info->dev, "Mbox send fail %d\n", ret);
1436 resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->tx_message.buf;
1438 if (!ti_sci_is_response_ack(resp))
1441 *match_freq = resp->freq_hz;
1447 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1448 * @handle: pointer to TI SCI handle
1449 * @dev_id: Device identifier this request is for
1450 * @clk_id: Clock identifier for the device for this request.
1451 * Each device has it's own set of clock inputs. This indexes
1452 * which clock input to modify.
1453 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1454 * allowable programmed frequency and does not account for clock
1455 * tolerances and jitter.
1456 * @target_freq: The target clock frequency in Hz. A frequency will be
1457 * processed as close to this target frequency as possible.
1458 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1459 * allowable programmed frequency and does not account for clock
1460 * tolerances and jitter.
1462 * Return: 0 if all went well, else returns appropriate error value.
1464 static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle *handle,
1465 u32 dev_id, u8 clk_id, u64 min_freq,
1466 u64 target_freq, u64 max_freq)
1468 struct ti_sci_msg_req_set_clock_freq req;
1469 struct ti_sci_msg_hdr *resp;
1470 struct ti_sci_info *info;
1471 struct ti_sci_xfer *xfer;
1475 return PTR_ERR(handle);
1479 info = handle_to_ti_sci_info(handle);
1481 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_FREQ,
1482 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1483 (u32 *)&req, sizeof(req), sizeof(*resp));
1485 ret = PTR_ERR(xfer);
1486 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1489 req.dev_id = dev_id;
1490 req.clk_id = clk_id;
1491 req.min_freq_hz = min_freq;
1492 req.target_freq_hz = target_freq;
1493 req.max_freq_hz = max_freq;
1495 ret = ti_sci_do_xfer(info, xfer);
1497 dev_err(info->dev, "Mbox send fail %d\n", ret);
1501 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1503 if (!ti_sci_is_response_ack(resp))
1510 * ti_sci_cmd_clk_get_freq() - Get current frequency
1511 * @handle: pointer to TI SCI handle
1512 * @dev_id: Device identifier this request is for
1513 * @clk_id: Clock identifier for the device for this request.
1514 * Each device has it's own set of clock inputs. This indexes
1515 * which clock input to modify.
1516 * @freq: Currently frequency in Hz
1518 * Return: 0 if all went well, else returns appropriate error value.
1520 static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle,
1521 u32 dev_id, u8 clk_id, u64 *freq)
1523 struct ti_sci_msg_resp_get_clock_freq *resp;
1524 struct ti_sci_msg_req_get_clock_freq req;
1525 struct ti_sci_info *info;
1526 struct ti_sci_xfer *xfer;
1530 return PTR_ERR(handle);
1531 if (!handle || !freq)
1534 info = handle_to_ti_sci_info(handle);
1536 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_FREQ,
1537 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1538 (u32 *)&req, sizeof(req), sizeof(*resp));
1540 ret = PTR_ERR(xfer);
1541 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1544 req.dev_id = dev_id;
1545 req.clk_id = clk_id;
1547 ret = ti_sci_do_xfer(info, xfer);
1549 dev_err(info->dev, "Mbox send fail %d\n", ret);
1553 resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->tx_message.buf;
1555 if (!ti_sci_is_response_ack(resp))
1558 *freq = resp->freq_hz;
1564 * ti_sci_cmd_core_reboot() - Command to request system reset
1565 * @handle: pointer to TI SCI handle
1567 * Return: 0 if all went well, else returns appropriate error value.
1569 static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle)
1571 struct ti_sci_msg_req_reboot req;
1572 struct ti_sci_msg_hdr *resp;
1573 struct ti_sci_info *info;
1574 struct ti_sci_xfer *xfer;
1578 return PTR_ERR(handle);
1582 info = handle_to_ti_sci_info(handle);
1584 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SYS_RESET,
1585 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1586 (u32 *)&req, sizeof(req), sizeof(*resp));
1588 ret = PTR_ERR(xfer);
1589 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1593 ret = ti_sci_do_xfer(info, xfer);
1595 dev_err(dev, "Mbox send fail %d\n", ret);
1599 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1601 if (!ti_sci_is_response_ack(resp))
1607 static int ti_sci_get_resource_type(struct ti_sci_info *info, u16 dev_id,
1610 struct ti_sci_rm_type_map *rm_type_map = info->desc->rm_type_map;
1614 /* If map is not provided then assume dev_id is used as type */
1620 for (i = 0; rm_type_map[i].dev_id; i++) {
1621 if (rm_type_map[i].dev_id == dev_id) {
1622 *type = rm_type_map[i].type;
1635 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1636 * to a host. Resource is uniquely identified by
1638 * @handle: Pointer to TISCI handle.
1639 * @dev_id: TISCI device ID.
1640 * @subtype: Resource assignment subtype that is being requested
1641 * from the given device.
1642 * @s_host: Host processor ID to which the resources are allocated
1643 * @range_start: Start index of the resource range
1644 * @range_num: Number of resources in the range
1646 * Return: 0 if all went fine, else return appropriate error.
1648 static int ti_sci_get_resource_range(const struct ti_sci_handle *handle,
1649 u32 dev_id, u8 subtype, u8 s_host,
1650 u16 *range_start, u16 *range_num)
1652 struct ti_sci_msg_resp_get_resource_range *resp;
1653 struct ti_sci_msg_req_get_resource_range req;
1654 struct ti_sci_xfer *xfer;
1655 struct ti_sci_info *info;
1660 return PTR_ERR(handle);
1664 info = handle_to_ti_sci_info(handle);
1666 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE,
1667 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1668 (u32 *)&req, sizeof(req), sizeof(*resp));
1670 ret = PTR_ERR(xfer);
1671 dev_err(dev, "Message alloc failed(%d)\n", ret);
1675 ret = ti_sci_get_resource_type(info, dev_id, &type);
1677 dev_err(dev, "rm type lookup failed for %u\n", dev_id);
1681 req.secondary_host = s_host;
1682 req.type = type & MSG_RM_RESOURCE_TYPE_MASK;
1683 req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK;
1685 ret = ti_sci_do_xfer(info, xfer);
1687 dev_err(dev, "Mbox send fail %d\n", ret);
1691 resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->tx_message.buf;
1692 if (!ti_sci_is_response_ack(resp)) {
1694 } else if (!resp->range_start && !resp->range_num) {
1697 *range_start = resp->range_start;
1698 *range_num = resp->range_num;
1706 * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1707 * that is same as ti sci interface host.
1708 * @handle: Pointer to TISCI handle.
1709 * @dev_id: TISCI device ID.
1710 * @subtype: Resource assignment subtype that is being requested
1711 * from the given device.
1712 * @range_start: Start index of the resource range
1713 * @range_num: Number of resources in the range
1715 * Return: 0 if all went fine, else return appropriate error.
1717 static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle,
1718 u32 dev_id, u8 subtype,
1719 u16 *range_start, u16 *range_num)
1721 return ti_sci_get_resource_range(handle, dev_id, subtype,
1722 TI_SCI_IRQ_SECONDARY_HOST_INVALID,
1723 range_start, range_num);
1727 * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1728 * assigned to a specified host.
1729 * @handle: Pointer to TISCI handle.
1730 * @dev_id: TISCI device ID.
1731 * @subtype: Resource assignment subtype that is being requested
1732 * from the given device.
1733 * @s_host: Host processor ID to which the resources are allocated
1734 * @range_start: Start index of the resource range
1735 * @range_num: Number of resources in the range
1737 * Return: 0 if all went fine, else return appropriate error.
1740 int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle,
1741 u32 dev_id, u8 subtype, u8 s_host,
1742 u16 *range_start, u16 *range_num)
1744 return ti_sci_get_resource_range(handle, dev_id, subtype, s_host,
1745 range_start, range_num);
1749 * ti_sci_cmd_query_msmc() - Command to query currently available msmc memory
1750 * @handle: pointer to TI SCI handle
1751 * @msms_start: MSMC start as returned by tisci
1752 * @msmc_end: MSMC end as returned by tisci
1754 * Return: 0 if all went well, else returns appropriate error value.
1756 static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle,
1757 u64 *msmc_start, u64 *msmc_end)
1759 struct ti_sci_msg_resp_query_msmc *resp;
1760 struct ti_sci_msg_hdr req;
1761 struct ti_sci_info *info;
1762 struct ti_sci_xfer *xfer;
1766 return PTR_ERR(handle);
1770 info = handle_to_ti_sci_info(handle);
1772 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_QUERY_MSMC,
1773 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1774 (u32 *)&req, sizeof(req), sizeof(*resp));
1776 ret = PTR_ERR(xfer);
1777 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1781 ret = ti_sci_do_xfer(info, xfer);
1783 dev_err(dev, "Mbox send fail %d\n", ret);
1787 resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf;
1789 if (!ti_sci_is_response_ack(resp))
1792 *msmc_start = ((u64)resp->msmc_start_high << TISCI_ADDR_HIGH_SHIFT) |
1793 resp->msmc_start_low;
1794 *msmc_end = ((u64)resp->msmc_end_high << TISCI_ADDR_HIGH_SHIFT) |
1801 * ti_sci_cmd_proc_request() - Command to request a physical processor control
1802 * @handle: Pointer to TI SCI handle
1803 * @proc_id: Processor ID this request is for
1805 * Return: 0 if all went well, else returns appropriate error value.
1807 static int ti_sci_cmd_proc_request(const struct ti_sci_handle *handle,
1810 struct ti_sci_msg_req_proc_request req;
1811 struct ti_sci_msg_hdr *resp;
1812 struct ti_sci_info *info;
1813 struct ti_sci_xfer *xfer;
1817 return PTR_ERR(handle);
1821 info = handle_to_ti_sci_info(handle);
1823 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_REQUEST,
1824 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1825 (u32 *)&req, sizeof(req), sizeof(*resp));
1827 ret = PTR_ERR(xfer);
1828 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1831 req.processor_id = proc_id;
1833 ret = ti_sci_do_xfer(info, xfer);
1835 dev_err(info->dev, "Mbox send fail %d\n", ret);
1839 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1841 if (!ti_sci_is_response_ack(resp))
1848 * ti_sci_cmd_proc_release() - Command to release a physical processor control
1849 * @handle: Pointer to TI SCI handle
1850 * @proc_id: Processor ID this request is for
1852 * Return: 0 if all went well, else returns appropriate error value.
1854 static int ti_sci_cmd_proc_release(const struct ti_sci_handle *handle,
1857 struct ti_sci_msg_req_proc_release req;
1858 struct ti_sci_msg_hdr *resp;
1859 struct ti_sci_info *info;
1860 struct ti_sci_xfer *xfer;
1864 return PTR_ERR(handle);
1868 info = handle_to_ti_sci_info(handle);
1870 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_RELEASE,
1871 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1872 (u32 *)&req, sizeof(req), sizeof(*resp));
1874 ret = PTR_ERR(xfer);
1875 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1878 req.processor_id = proc_id;
1880 ret = ti_sci_do_xfer(info, xfer);
1882 dev_err(info->dev, "Mbox send fail %d\n", ret);
1886 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1888 if (!ti_sci_is_response_ack(resp))
1895 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
1896 * control to a host in the processor's access
1898 * @handle: Pointer to TI SCI handle
1899 * @proc_id: Processor ID this request is for
1900 * @host_id: Host ID to get the control of the processor
1902 * Return: 0 if all went well, else returns appropriate error value.
1904 static int ti_sci_cmd_proc_handover(const struct ti_sci_handle *handle,
1905 u8 proc_id, u8 host_id)
1907 struct ti_sci_msg_req_proc_handover req;
1908 struct ti_sci_msg_hdr *resp;
1909 struct ti_sci_info *info;
1910 struct ti_sci_xfer *xfer;
1914 return PTR_ERR(handle);
1918 info = handle_to_ti_sci_info(handle);
1920 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_HANDOVER,
1921 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1922 (u32 *)&req, sizeof(req), sizeof(*resp));
1924 ret = PTR_ERR(xfer);
1925 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1928 req.processor_id = proc_id;
1929 req.host_id = host_id;
1931 ret = ti_sci_do_xfer(info, xfer);
1933 dev_err(info->dev, "Mbox send fail %d\n", ret);
1937 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1939 if (!ti_sci_is_response_ack(resp))
1946 * ti_sci_cmd_set_proc_boot_cfg() - Command to set the processor boot
1947 * configuration flags
1948 * @handle: Pointer to TI SCI handle
1949 * @proc_id: Processor ID this request is for
1950 * @config_flags_set: Configuration flags to be set
1951 * @config_flags_clear: Configuration flags to be cleared.
1953 * Return: 0 if all went well, else returns appropriate error value.
1955 static int ti_sci_cmd_set_proc_boot_cfg(const struct ti_sci_handle *handle,
1956 u8 proc_id, u64 bootvector,
1957 u32 config_flags_set,
1958 u32 config_flags_clear)
1960 struct ti_sci_msg_req_set_proc_boot_config req;
1961 struct ti_sci_msg_hdr *resp;
1962 struct ti_sci_info *info;
1963 struct ti_sci_xfer *xfer;
1967 return PTR_ERR(handle);
1971 info = handle_to_ti_sci_info(handle);
1973 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CONFIG,
1974 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1975 (u32 *)&req, sizeof(req), sizeof(*resp));
1977 ret = PTR_ERR(xfer);
1978 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1981 req.processor_id = proc_id;
1982 req.bootvector_low = bootvector & TISCI_ADDR_LOW_MASK;
1983 req.bootvector_high = (bootvector & TISCI_ADDR_HIGH_MASK) >>
1984 TISCI_ADDR_HIGH_SHIFT;
1985 req.config_flags_set = config_flags_set;
1986 req.config_flags_clear = config_flags_clear;
1988 ret = ti_sci_do_xfer(info, xfer);
1990 dev_err(info->dev, "Mbox send fail %d\n", ret);
1994 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1996 if (!ti_sci_is_response_ack(resp))
2003 * ti_sci_cmd_set_proc_boot_ctrl() - Command to set the processor boot
2005 * @handle: Pointer to TI SCI handle
2006 * @proc_id: Processor ID this request is for
2007 * @control_flags_set: Control flags to be set
2008 * @control_flags_clear: Control flags to be cleared
2010 * Return: 0 if all went well, else returns appropriate error value.
2012 static int ti_sci_cmd_set_proc_boot_ctrl(const struct ti_sci_handle *handle,
2013 u8 proc_id, u32 control_flags_set,
2014 u32 control_flags_clear)
2016 struct ti_sci_msg_req_set_proc_boot_ctrl req;
2017 struct ti_sci_msg_hdr *resp;
2018 struct ti_sci_info *info;
2019 struct ti_sci_xfer *xfer;
2023 return PTR_ERR(handle);
2027 info = handle_to_ti_sci_info(handle);
2029 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CTRL,
2030 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2031 (u32 *)&req, sizeof(req), sizeof(*resp));
2033 ret = PTR_ERR(xfer);
2034 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2037 req.processor_id = proc_id;
2038 req.control_flags_set = control_flags_set;
2039 req.control_flags_clear = control_flags_clear;
2041 ret = ti_sci_do_xfer(info, xfer);
2043 dev_err(info->dev, "Mbox send fail %d\n", ret);
2047 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2049 if (!ti_sci_is_response_ack(resp))
2056 * ti_sci_cmd_proc_auth_boot_image() - Command to authenticate and load the
2057 * image and then set the processor configuration flags.
2058 * @handle: Pointer to TI SCI handle
2059 * @image_addr: Memory address at which payload image and certificate is
2060 * located in memory, this is updated if the image data is
2061 * moved during authentication.
2062 * @image_size: This is updated with the final size of the image after
2065 * Return: 0 if all went well, else returns appropriate error value.
2067 static int ti_sci_cmd_proc_auth_boot_image(const struct ti_sci_handle *handle,
2068 u64 *image_addr, u32 *image_size)
2070 struct ti_sci_msg_req_proc_auth_boot_image req;
2071 struct ti_sci_msg_resp_proc_auth_boot_image *resp;
2072 struct ti_sci_info *info;
2073 struct ti_sci_xfer *xfer;
2077 return PTR_ERR(handle);
2081 info = handle_to_ti_sci_info(handle);
2083 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_AUTH_BOOT_IMIAGE,
2084 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2085 (u32 *)&req, sizeof(req), sizeof(*resp));
2087 ret = PTR_ERR(xfer);
2088 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2091 req.cert_addr_low = *image_addr & TISCI_ADDR_LOW_MASK;
2092 req.cert_addr_high = (*image_addr & TISCI_ADDR_HIGH_MASK) >>
2093 TISCI_ADDR_HIGH_SHIFT;
2095 ret = ti_sci_do_xfer(info, xfer);
2097 dev_err(info->dev, "Mbox send fail %d\n", ret);
2101 resp = (struct ti_sci_msg_resp_proc_auth_boot_image *)xfer->tx_message.buf;
2103 if (!ti_sci_is_response_ack(resp))
2106 *image_addr = (resp->image_addr_low & TISCI_ADDR_LOW_MASK) |
2107 (((u64)resp->image_addr_high <<
2108 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2109 *image_size = resp->image_size;
2115 * ti_sci_cmd_get_proc_boot_status() - Command to get the processor boot status
2116 * @handle: Pointer to TI SCI handle
2117 * @proc_id: Processor ID this request is for
2119 * Return: 0 if all went well, else returns appropriate error value.
2121 static int ti_sci_cmd_get_proc_boot_status(const struct ti_sci_handle *handle,
2122 u8 proc_id, u64 *bv, u32 *cfg_flags,
2123 u32 *ctrl_flags, u32 *sts_flags)
2125 struct ti_sci_msg_resp_get_proc_boot_status *resp;
2126 struct ti_sci_msg_req_get_proc_boot_status req;
2127 struct ti_sci_info *info;
2128 struct ti_sci_xfer *xfer;
2132 return PTR_ERR(handle);
2136 info = handle_to_ti_sci_info(handle);
2138 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_GET_PROC_BOOT_STATUS,
2139 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2140 (u32 *)&req, sizeof(req), sizeof(*resp));
2142 ret = PTR_ERR(xfer);
2143 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2146 req.processor_id = proc_id;
2148 ret = ti_sci_do_xfer(info, xfer);
2150 dev_err(info->dev, "Mbox send fail %d\n", ret);
2154 resp = (struct ti_sci_msg_resp_get_proc_boot_status *)
2155 xfer->tx_message.buf;
2157 if (!ti_sci_is_response_ack(resp))
2159 *bv = (resp->bootvector_low & TISCI_ADDR_LOW_MASK) |
2160 (((u64)resp->bootvector_high <<
2161 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2162 *cfg_flags = resp->config_flags;
2163 *ctrl_flags = resp->control_flags;
2164 *sts_flags = resp->status_flags;
2170 * ti_sci_proc_wait_boot_status_no_wait() - Helper function to wait for a
2171 * processor boot status without requesting or
2172 * waiting for a response.
2173 * @proc_id: Processor ID this request is for
2174 * @num_wait_iterations: Total number of iterations we will check before
2175 * we will timeout and give up
2176 * @num_match_iterations: How many iterations should we have continued
2177 * status to account for status bits glitching.
2178 * This is to make sure that match occurs for
2179 * consecutive checks. This implies that the
2180 * worst case should consider that the stable
2181 * time should at the worst be num_wait_iterations
2182 * num_match_iterations to prevent timeout.
2183 * @delay_per_iteration_us: Specifies how long to wait (in micro seconds)
2184 * between each status checks. This is the minimum
2185 * duration, and overhead of register reads and
2186 * checks are on top of this and can vary based on
2187 * varied conditions.
2188 * @delay_before_iterations_us: Specifies how long to wait (in micro seconds)
2189 * before the very first check in the first
2190 * iteration of status check loop. This is the
2191 * minimum duration, and overhead of register
2192 * reads and checks are.
2193 * @status_flags_1_set_all_wait:If non-zero, Specifies that all bits of the
2194 * status matching this field requested MUST be 1.
2195 * @status_flags_1_set_any_wait:If non-zero, Specifies that at least one of the
2196 * bits matching this field requested MUST be 1.
2197 * @status_flags_1_clr_all_wait:If non-zero, Specifies that all bits of the
2198 * status matching this field requested MUST be 0.
2199 * @status_flags_1_clr_any_wait:If non-zero, Specifies that at least one of the
2200 * bits matching this field requested MUST be 0.
2202 * Return: 0 if all goes well, else appropriate error message
2205 ti_sci_proc_wait_boot_status_no_wait(const struct ti_sci_handle *handle,
2207 u8 num_wait_iterations,
2208 u8 num_match_iterations,
2209 u8 delay_per_iteration_us,
2210 u8 delay_before_iterations_us,
2211 u32 status_flags_1_set_all_wait,
2212 u32 status_flags_1_set_any_wait,
2213 u32 status_flags_1_clr_all_wait,
2214 u32 status_flags_1_clr_any_wait)
2216 struct ti_sci_msg_req_wait_proc_boot_status req;
2217 struct ti_sci_info *info;
2218 struct ti_sci_xfer *xfer;
2222 return PTR_ERR(handle);
2226 info = handle_to_ti_sci_info(handle);
2228 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_WAIT_PROC_BOOT_STATUS,
2229 TI_SCI_FLAG_REQ_GENERIC_NORESPONSE,
2230 (u32 *)&req, sizeof(req), 0);
2232 ret = PTR_ERR(xfer);
2233 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2236 req.processor_id = proc_id;
2237 req.num_wait_iterations = num_wait_iterations;
2238 req.num_match_iterations = num_match_iterations;
2239 req.delay_per_iteration_us = delay_per_iteration_us;
2240 req.delay_before_iterations_us = delay_before_iterations_us;
2241 req.status_flags_1_set_all_wait = status_flags_1_set_all_wait;
2242 req.status_flags_1_set_any_wait = status_flags_1_set_any_wait;
2243 req.status_flags_1_clr_all_wait = status_flags_1_clr_all_wait;
2244 req.status_flags_1_clr_any_wait = status_flags_1_clr_any_wait;
2246 ret = ti_sci_do_xfer(info, xfer);
2248 dev_err(info->dev, "Mbox send fail %d\n", ret);
2254 * ti_sci_cmd_proc_shutdown_no_wait() - Command to shutdown a core without
2255 * requesting or waiting for a response. Note that this API call
2256 * should be followed by placing the respective processor into
2257 * either WFE or WFI mode.
2258 * @handle: Pointer to TI SCI handle
2259 * @proc_id: Processor ID this request is for
2261 * Return: 0 if all went well, else returns appropriate error value.
2263 static int ti_sci_cmd_proc_shutdown_no_wait(const struct ti_sci_handle *handle,
2269 * Send the core boot status wait message waiting for either WFE or
2270 * WFI without requesting or waiting for a TISCI response with the
2271 * maximum wait time to give us the best chance to get to the WFE/WFI
2272 * command that should follow the invocation of this API before the
2273 * DMSC-internal processing of this command times out. Note that
2274 * waiting for the R5 WFE/WFI flags will also work on an ARMV8 type
2275 * core as the related flag bit positions are the same.
2277 ret = ti_sci_proc_wait_boot_status_no_wait(handle, proc_id,
2278 U8_MAX, 100, U8_MAX, U8_MAX,
2279 0, PROC_BOOT_STATUS_FLAG_R5_WFE | PROC_BOOT_STATUS_FLAG_R5_WFI,
2282 dev_err(info->dev, "Sending core %u wait message fail %d\n",
2288 * Release a processor managed by TISCI without requesting or waiting
2291 ret = ti_sci_set_device_state_no_wait(handle, proc_id, 0,
2292 MSG_DEVICE_SW_STATE_AUTO_OFF);
2294 dev_err(info->dev, "Sending core %u shutdown message fail %d\n",
2301 * ti_sci_cmd_ring_config() - configure RA ring
2302 * @handle: pointer to TI SCI handle
2303 * @valid_params: Bitfield defining validity of ring configuration parameters.
2304 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2305 * @index: Ring index.
2306 * @addr_lo: The ring base address lo 32 bits
2307 * @addr_hi: The ring base address hi 32 bits
2308 * @count: Number of ring elements.
2309 * @mode: The mode of the ring
2310 * @size: The ring element size.
2311 * @order_id: Specifies the ring's bus order ID.
2313 * Return: 0 if all went well, else returns appropriate error value.
2315 * See @ti_sci_msg_rm_ring_cfg_req for more info.
2317 static int ti_sci_cmd_ring_config(const struct ti_sci_handle *handle,
2318 u32 valid_params, u16 nav_id, u16 index,
2319 u32 addr_lo, u32 addr_hi, u32 count,
2320 u8 mode, u8 size, u8 order_id)
2322 struct ti_sci_msg_rm_ring_cfg_resp *resp;
2323 struct ti_sci_msg_rm_ring_cfg_req req;
2324 struct ti_sci_xfer *xfer;
2325 struct ti_sci_info *info;
2329 return PTR_ERR(handle);
2333 info = handle_to_ti_sci_info(handle);
2335 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_CFG,
2336 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2337 (u32 *)&req, sizeof(req), sizeof(*resp));
2339 ret = PTR_ERR(xfer);
2340 dev_err(info->dev, "RM_RA:Message config failed(%d)\n", ret);
2343 req.valid_params = valid_params;
2344 req.nav_id = nav_id;
2346 req.addr_lo = addr_lo;
2347 req.addr_hi = addr_hi;
2351 req.order_id = order_id;
2353 ret = ti_sci_do_xfer(info, xfer);
2355 dev_err(info->dev, "RM_RA:Mbox config send fail %d\n", ret);
2359 resp = (struct ti_sci_msg_rm_ring_cfg_resp *)xfer->tx_message.buf;
2361 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2364 dev_dbg(info->dev, "RM_RA:config ring %u ret:%d\n", index, ret);
2368 static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle *handle,
2369 u32 nav_id, u32 src_thread, u32 dst_thread)
2371 struct ti_sci_msg_hdr *resp;
2372 struct ti_sci_msg_psil_pair req;
2373 struct ti_sci_xfer *xfer;
2374 struct ti_sci_info *info;
2378 return PTR_ERR(handle);
2382 info = handle_to_ti_sci_info(handle);
2384 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_PAIR,
2385 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2386 (u32 *)&req, sizeof(req), sizeof(*resp));
2388 ret = PTR_ERR(xfer);
2389 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2392 req.nav_id = nav_id;
2393 req.src_thread = src_thread;
2394 req.dst_thread = dst_thread;
2396 ret = ti_sci_do_xfer(info, xfer);
2398 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2402 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2403 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2406 dev_dbg(info->dev, "RM_PSIL: nav: %u link pair %u->%u ret:%u\n",
2407 nav_id, src_thread, dst_thread, ret);
2411 static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle *handle,
2412 u32 nav_id, u32 src_thread, u32 dst_thread)
2414 struct ti_sci_msg_hdr *resp;
2415 struct ti_sci_msg_psil_unpair req;
2416 struct ti_sci_xfer *xfer;
2417 struct ti_sci_info *info;
2421 return PTR_ERR(handle);
2425 info = handle_to_ti_sci_info(handle);
2427 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_UNPAIR,
2428 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2429 (u32 *)&req, sizeof(req), sizeof(*resp));
2431 ret = PTR_ERR(xfer);
2432 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2435 req.nav_id = nav_id;
2436 req.src_thread = src_thread;
2437 req.dst_thread = dst_thread;
2439 ret = ti_sci_do_xfer(info, xfer);
2441 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2445 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2446 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2449 dev_dbg(info->dev, "RM_PSIL: link unpair %u->%u ret:%u\n",
2450 src_thread, dst_thread, ret);
2454 static int ti_sci_cmd_rm_udmap_tx_ch_cfg(
2455 const struct ti_sci_handle *handle,
2456 const struct ti_sci_msg_rm_udmap_tx_ch_cfg *params)
2458 struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *resp;
2459 struct ti_sci_msg_rm_udmap_tx_ch_cfg_req req;
2460 struct ti_sci_xfer *xfer;
2461 struct ti_sci_info *info;
2465 return PTR_ERR(handle);
2469 info = handle_to_ti_sci_info(handle);
2471 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_TX_CH_CFG,
2472 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2473 (u32 *)&req, sizeof(req), sizeof(*resp));
2475 ret = PTR_ERR(xfer);
2476 dev_err(info->dev, "Message TX_CH_CFG alloc failed(%d)\n", ret);
2479 req.valid_params = params->valid_params;
2480 req.nav_id = params->nav_id;
2481 req.index = params->index;
2482 req.tx_pause_on_err = params->tx_pause_on_err;
2483 req.tx_filt_einfo = params->tx_filt_einfo;
2484 req.tx_filt_pswords = params->tx_filt_pswords;
2485 req.tx_atype = params->tx_atype;
2486 req.tx_chan_type = params->tx_chan_type;
2487 req.tx_supr_tdpkt = params->tx_supr_tdpkt;
2488 req.tx_fetch_size = params->tx_fetch_size;
2489 req.tx_credit_count = params->tx_credit_count;
2490 req.txcq_qnum = params->txcq_qnum;
2491 req.tx_priority = params->tx_priority;
2492 req.tx_qos = params->tx_qos;
2493 req.tx_orderid = params->tx_orderid;
2494 req.fdepth = params->fdepth;
2495 req.tx_sched_priority = params->tx_sched_priority;
2497 ret = ti_sci_do_xfer(info, xfer);
2499 dev_err(info->dev, "Mbox send TX_CH_CFG fail %d\n", ret);
2504 (struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *)xfer->tx_message.buf;
2505 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2508 dev_dbg(info->dev, "TX_CH_CFG: chn %u ret:%u\n", params->index, ret);
2512 static int ti_sci_cmd_rm_udmap_rx_ch_cfg(
2513 const struct ti_sci_handle *handle,
2514 const struct ti_sci_msg_rm_udmap_rx_ch_cfg *params)
2516 struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *resp;
2517 struct ti_sci_msg_rm_udmap_rx_ch_cfg_req req;
2518 struct ti_sci_xfer *xfer;
2519 struct ti_sci_info *info;
2523 return PTR_ERR(handle);
2527 info = handle_to_ti_sci_info(handle);
2529 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_RX_CH_CFG,
2530 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2531 (u32 *)&req, sizeof(req), sizeof(*resp));
2533 ret = PTR_ERR(xfer);
2534 dev_err(info->dev, "Message RX_CH_CFG alloc failed(%d)\n", ret);
2538 req.valid_params = params->valid_params;
2539 req.nav_id = params->nav_id;
2540 req.index = params->index;
2541 req.rx_fetch_size = params->rx_fetch_size;
2542 req.rxcq_qnum = params->rxcq_qnum;
2543 req.rx_priority = params->rx_priority;
2544 req.rx_qos = params->rx_qos;
2545 req.rx_orderid = params->rx_orderid;
2546 req.rx_sched_priority = params->rx_sched_priority;
2547 req.flowid_start = params->flowid_start;
2548 req.flowid_cnt = params->flowid_cnt;
2549 req.rx_pause_on_err = params->rx_pause_on_err;
2550 req.rx_atype = params->rx_atype;
2551 req.rx_chan_type = params->rx_chan_type;
2552 req.rx_ignore_short = params->rx_ignore_short;
2553 req.rx_ignore_long = params->rx_ignore_long;
2555 ret = ti_sci_do_xfer(info, xfer);
2557 dev_err(info->dev, "Mbox send RX_CH_CFG fail %d\n", ret);
2562 (struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *)xfer->tx_message.buf;
2563 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2566 dev_dbg(info->dev, "RX_CH_CFG: chn %u ret:%d\n", params->index, ret);
2570 static int ti_sci_cmd_rm_udmap_rx_flow_cfg(
2571 const struct ti_sci_handle *handle,
2572 const struct ti_sci_msg_rm_udmap_flow_cfg *params)
2574 struct ti_sci_msg_rm_udmap_flow_cfg_resp *resp;
2575 struct ti_sci_msg_rm_udmap_flow_cfg_req req;
2576 struct ti_sci_xfer *xfer;
2577 struct ti_sci_info *info;
2581 return PTR_ERR(handle);
2585 info = handle_to_ti_sci_info(handle);
2587 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_FLOW_CFG,
2588 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2589 (u32 *)&req, sizeof(req), sizeof(*resp));
2591 ret = PTR_ERR(xfer);
2592 dev_err(dev, "RX_FL_CFG: Message alloc failed(%d)\n", ret);
2596 req.valid_params = params->valid_params;
2597 req.nav_id = params->nav_id;
2598 req.flow_index = params->flow_index;
2599 req.rx_einfo_present = params->rx_einfo_present;
2600 req.rx_psinfo_present = params->rx_psinfo_present;
2601 req.rx_error_handling = params->rx_error_handling;
2602 req.rx_desc_type = params->rx_desc_type;
2603 req.rx_sop_offset = params->rx_sop_offset;
2604 req.rx_dest_qnum = params->rx_dest_qnum;
2605 req.rx_src_tag_hi = params->rx_src_tag_hi;
2606 req.rx_src_tag_lo = params->rx_src_tag_lo;
2607 req.rx_dest_tag_hi = params->rx_dest_tag_hi;
2608 req.rx_dest_tag_lo = params->rx_dest_tag_lo;
2609 req.rx_src_tag_hi_sel = params->rx_src_tag_hi_sel;
2610 req.rx_src_tag_lo_sel = params->rx_src_tag_lo_sel;
2611 req.rx_dest_tag_hi_sel = params->rx_dest_tag_hi_sel;
2612 req.rx_dest_tag_lo_sel = params->rx_dest_tag_lo_sel;
2613 req.rx_fdq0_sz0_qnum = params->rx_fdq0_sz0_qnum;
2614 req.rx_fdq1_qnum = params->rx_fdq1_qnum;
2615 req.rx_fdq2_qnum = params->rx_fdq2_qnum;
2616 req.rx_fdq3_qnum = params->rx_fdq3_qnum;
2617 req.rx_ps_location = params->rx_ps_location;
2619 ret = ti_sci_do_xfer(info, xfer);
2621 dev_err(dev, "RX_FL_CFG: Mbox send fail %d\n", ret);
2626 (struct ti_sci_msg_rm_udmap_flow_cfg_resp *)xfer->tx_message.buf;
2627 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2630 dev_dbg(info->dev, "RX_FL_CFG: %u ret:%d\n", params->flow_index, ret);
2635 * ti_sci_cmd_set_fwl_region() - Request for configuring a firewall region
2636 * @handle: pointer to TI SCI handle
2637 * @region: region configuration parameters
2639 * Return: 0 if all went well, else returns appropriate error value.
2641 static int ti_sci_cmd_set_fwl_region(const struct ti_sci_handle *handle,
2642 const struct ti_sci_msg_fwl_region *region)
2644 struct ti_sci_msg_fwl_set_firewall_region_req req;
2645 struct ti_sci_msg_hdr *resp;
2646 struct ti_sci_info *info;
2647 struct ti_sci_xfer *xfer;
2651 return PTR_ERR(handle);
2655 info = handle_to_ti_sci_info(handle);
2657 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_SET,
2658 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2659 (u32 *)&req, sizeof(req), sizeof(*resp));
2661 ret = PTR_ERR(xfer);
2662 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2666 req.fwl_id = region->fwl_id;
2667 req.region = region->region;
2668 req.n_permission_regs = region->n_permission_regs;
2669 req.control = region->control;
2670 req.permissions[0] = region->permissions[0];
2671 req.permissions[1] = region->permissions[1];
2672 req.permissions[2] = region->permissions[2];
2673 req.start_address = region->start_address;
2674 req.end_address = region->end_address;
2676 ret = ti_sci_do_xfer(info, xfer);
2678 dev_err(info->dev, "Mbox send fail %d\n", ret);
2682 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2684 if (!ti_sci_is_response_ack(resp))
2691 * ti_sci_cmd_get_fwl_region() - Request for getting a firewall region
2692 * @handle: pointer to TI SCI handle
2693 * @region: region configuration parameters
2695 * Return: 0 if all went well, else returns appropriate error value.
2697 static int ti_sci_cmd_get_fwl_region(const struct ti_sci_handle *handle,
2698 struct ti_sci_msg_fwl_region *region)
2700 struct ti_sci_msg_fwl_get_firewall_region_req req;
2701 struct ti_sci_msg_fwl_get_firewall_region_resp *resp;
2702 struct ti_sci_info *info;
2703 struct ti_sci_xfer *xfer;
2707 return PTR_ERR(handle);
2711 info = handle_to_ti_sci_info(handle);
2713 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_GET,
2714 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2715 (u32 *)&req, sizeof(req), sizeof(*resp));
2717 ret = PTR_ERR(xfer);
2718 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2722 req.fwl_id = region->fwl_id;
2723 req.region = region->region;
2724 req.n_permission_regs = region->n_permission_regs;
2726 ret = ti_sci_do_xfer(info, xfer);
2728 dev_err(info->dev, "Mbox send fail %d\n", ret);
2732 resp = (struct ti_sci_msg_fwl_get_firewall_region_resp *)xfer->tx_message.buf;
2734 if (!ti_sci_is_response_ack(resp))
2737 region->fwl_id = resp->fwl_id;
2738 region->region = resp->region;
2739 region->n_permission_regs = resp->n_permission_regs;
2740 region->control = resp->control;
2741 region->permissions[0] = resp->permissions[0];
2742 region->permissions[1] = resp->permissions[1];
2743 region->permissions[2] = resp->permissions[2];
2744 region->start_address = resp->start_address;
2745 region->end_address = resp->end_address;
2751 * ti_sci_cmd_change_fwl_owner() - Request for changing a firewall owner
2752 * @handle: pointer to TI SCI handle
2753 * @region: region configuration parameters
2755 * Return: 0 if all went well, else returns appropriate error value.
2757 static int ti_sci_cmd_change_fwl_owner(const struct ti_sci_handle *handle,
2758 struct ti_sci_msg_fwl_owner *owner)
2760 struct ti_sci_msg_fwl_change_owner_info_req req;
2761 struct ti_sci_msg_fwl_change_owner_info_resp *resp;
2762 struct ti_sci_info *info;
2763 struct ti_sci_xfer *xfer;
2767 return PTR_ERR(handle);
2771 info = handle_to_ti_sci_info(handle);
2773 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_CHANGE_OWNER,
2774 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2775 (u32 *)&req, sizeof(req), sizeof(*resp));
2777 ret = PTR_ERR(xfer);
2778 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2782 req.fwl_id = owner->fwl_id;
2783 req.region = owner->region;
2784 req.owner_index = owner->owner_index;
2786 ret = ti_sci_do_xfer(info, xfer);
2788 dev_err(info->dev, "Mbox send fail %d\n", ret);
2792 resp = (struct ti_sci_msg_fwl_change_owner_info_resp *)xfer->tx_message.buf;
2794 if (!ti_sci_is_response_ack(resp))
2797 owner->fwl_id = resp->fwl_id;
2798 owner->region = resp->region;
2799 owner->owner_index = resp->owner_index;
2800 owner->owner_privid = resp->owner_privid;
2801 owner->owner_permission_bits = resp->owner_permission_bits;
2807 * ti_sci_setup_ops() - Setup the operations structures
2808 * @info: pointer to TISCI pointer
2810 static void ti_sci_setup_ops(struct ti_sci_info *info)
2812 struct ti_sci_ops *ops = &info->handle.ops;
2813 struct ti_sci_board_ops *bops = &ops->board_ops;
2814 struct ti_sci_dev_ops *dops = &ops->dev_ops;
2815 struct ti_sci_clk_ops *cops = &ops->clk_ops;
2816 struct ti_sci_core_ops *core_ops = &ops->core_ops;
2817 struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
2818 struct ti_sci_proc_ops *pops = &ops->proc_ops;
2819 struct ti_sci_rm_ringacc_ops *rops = &ops->rm_ring_ops;
2820 struct ti_sci_rm_psil_ops *psilops = &ops->rm_psil_ops;
2821 struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops;
2822 struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops;
2824 bops->board_config = ti_sci_cmd_set_board_config;
2825 bops->board_config_rm = ti_sci_cmd_set_board_config_rm;
2826 bops->board_config_security = ti_sci_cmd_set_board_config_security;
2827 bops->board_config_pm = ti_sci_cmd_set_board_config_pm;
2829 dops->get_device = ti_sci_cmd_get_device;
2830 dops->get_device_exclusive = ti_sci_cmd_get_device_exclusive;
2831 dops->idle_device = ti_sci_cmd_idle_device;
2832 dops->idle_device_exclusive = ti_sci_cmd_idle_device_exclusive;
2833 dops->put_device = ti_sci_cmd_put_device;
2834 dops->is_valid = ti_sci_cmd_dev_is_valid;
2835 dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt;
2836 dops->is_idle = ti_sci_cmd_dev_is_idle;
2837 dops->is_stop = ti_sci_cmd_dev_is_stop;
2838 dops->is_on = ti_sci_cmd_dev_is_on;
2839 dops->is_transitioning = ti_sci_cmd_dev_is_trans;
2840 dops->set_device_resets = ti_sci_cmd_set_device_resets;
2841 dops->get_device_resets = ti_sci_cmd_get_device_resets;
2842 dops->release_exclusive_devices = ti_sci_cmd_release_exclusive_devices;
2844 cops->get_clock = ti_sci_cmd_get_clock;
2845 cops->idle_clock = ti_sci_cmd_idle_clock;
2846 cops->put_clock = ti_sci_cmd_put_clock;
2847 cops->is_auto = ti_sci_cmd_clk_is_auto;
2848 cops->is_on = ti_sci_cmd_clk_is_on;
2849 cops->is_off = ti_sci_cmd_clk_is_off;
2851 cops->set_parent = ti_sci_cmd_clk_set_parent;
2852 cops->get_parent = ti_sci_cmd_clk_get_parent;
2853 cops->get_num_parents = ti_sci_cmd_clk_get_num_parents;
2855 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;
2856 cops->set_freq = ti_sci_cmd_clk_set_freq;
2857 cops->get_freq = ti_sci_cmd_clk_get_freq;
2859 core_ops->reboot_device = ti_sci_cmd_core_reboot;
2860 core_ops->query_msmc = ti_sci_cmd_query_msmc;
2862 rm_core_ops->get_range = ti_sci_cmd_get_resource_range;
2863 rm_core_ops->get_range_from_shost =
2864 ti_sci_cmd_get_resource_range_from_shost;
2866 pops->proc_request = ti_sci_cmd_proc_request;
2867 pops->proc_release = ti_sci_cmd_proc_release;
2868 pops->proc_handover = ti_sci_cmd_proc_handover;
2869 pops->set_proc_boot_cfg = ti_sci_cmd_set_proc_boot_cfg;
2870 pops->set_proc_boot_ctrl = ti_sci_cmd_set_proc_boot_ctrl;
2871 pops->proc_auth_boot_image = ti_sci_cmd_proc_auth_boot_image;
2872 pops->get_proc_boot_status = ti_sci_cmd_get_proc_boot_status;
2873 pops->proc_shutdown_no_wait = ti_sci_cmd_proc_shutdown_no_wait;
2875 rops->config = ti_sci_cmd_ring_config;
2877 psilops->pair = ti_sci_cmd_rm_psil_pair;
2878 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
2880 udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg;
2881 udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg;
2882 udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg;
2884 fwl_ops->set_fwl_region = ti_sci_cmd_set_fwl_region;
2885 fwl_ops->get_fwl_region = ti_sci_cmd_get_fwl_region;
2886 fwl_ops->change_fwl_owner = ti_sci_cmd_change_fwl_owner;
2890 * ti_sci_get_handle_from_sysfw() - Get the TI SCI handle of the SYSFW
2891 * @dev: Pointer to the SYSFW device
2893 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2897 struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *sci_dev)
2900 return ERR_PTR(-EINVAL);
2902 struct ti_sci_info *info = dev_get_priv(sci_dev);
2905 return ERR_PTR(-EINVAL);
2907 struct ti_sci_handle *handle = &info->handle;
2910 return ERR_PTR(-EINVAL);
2916 * ti_sci_get_handle() - Get the TI SCI handle for a device
2917 * @dev: Pointer to device for which we want SCI handle
2919 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2922 const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
2925 return ERR_PTR(-EINVAL);
2927 struct udevice *sci_dev = dev_get_parent(dev);
2929 return ti_sci_get_handle_from_sysfw(sci_dev);
2933 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
2935 * @propname: property name containing phandle on TISCI node
2937 * Return: pointer to handle if successful, else appropriate error value.
2939 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
2940 const char *property)
2942 struct ti_sci_info *entry, *info = NULL;
2946 err = ofnode_read_u32(dev_ofnode(dev), property, &phandle);
2948 return ERR_PTR(err);
2950 node = ofnode_get_by_phandle(phandle);
2951 if (!ofnode_valid(node))
2952 return ERR_PTR(-EINVAL);
2954 list_for_each_entry(entry, &ti_sci_list, list)
2955 if (ofnode_equal(dev_ofnode(entry->dev), node)) {
2961 return ERR_PTR(-ENODEV);
2963 return &info->handle;
2967 * ti_sci_of_to_info() - generate private data from device tree
2968 * @dev: corresponding system controller interface device
2969 * @info: pointer to driver specific private data
2971 * Return: 0 if all goes good, else appropriate error message.
2973 static int ti_sci_of_to_info(struct udevice *dev, struct ti_sci_info *info)
2977 ret = mbox_get_by_name(dev, "tx", &info->chan_tx);
2979 dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n",
2984 ret = mbox_get_by_name(dev, "rx", &info->chan_rx);
2986 dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n",
2991 /* Notify channel is optional. Enable only if populated */
2992 ret = mbox_get_by_name(dev, "notify", &info->chan_notify);
2994 dev_dbg(dev, "%s: Acquiring notify channel failed. ret = %d\n",
2998 info->host_id = dev_read_u32_default(dev, "ti,host-id",
2999 info->desc->default_host_id);
3001 info->is_secure = dev_read_bool(dev, "ti,secure-host");
3007 * ti_sci_probe() - Basic probe
3008 * @dev: corresponding system controller interface device
3010 * Return: 0 if all goes good, else appropriate error message.
3012 static int ti_sci_probe(struct udevice *dev)
3014 struct ti_sci_info *info;
3017 debug("%s(dev=%p)\n", __func__, dev);
3019 info = dev_get_priv(dev);
3020 info->desc = (void *)dev_get_driver_data(dev);
3022 ret = ti_sci_of_to_info(dev, info);
3024 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
3031 list_add_tail(&info->list, &ti_sci_list);
3032 ti_sci_setup_ops(info);
3034 ret = ti_sci_cmd_get_revision(&info->handle);
3036 INIT_LIST_HEAD(&info->dev_list);
3042 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
3043 * @res: Pointer to the TISCI resource
3045 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
3047 u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
3051 for (set = 0; set < res->sets; set++) {
3052 free_bit = find_first_zero_bit(res->desc[set].res_map,
3053 res->desc[set].num);
3054 if (free_bit != res->desc[set].num) {
3055 set_bit(free_bit, res->desc[set].res_map);
3056 return res->desc[set].start + free_bit;
3060 return TI_SCI_RESOURCE_NULL;
3064 * ti_sci_release_resource() - Release a resource from TISCI resource.
3065 * @res: Pointer to the TISCI resource
3067 void ti_sci_release_resource(struct ti_sci_resource *res, u16 id)
3071 for (set = 0; set < res->sets; set++) {
3072 if (res->desc[set].start <= id &&
3073 (res->desc[set].num + res->desc[set].start) > id)
3074 clear_bit(id - res->desc[set].start,
3075 res->desc[set].res_map);
3080 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
3081 * @handle: TISCI handle
3082 * @dev: Device pointer to which the resource is assigned
3083 * @of_prop: property name by which the resource are represented
3085 * Note: This function expects of_prop to be in the form of tuples
3086 * <type, subtype>. Allocates and initializes ti_sci_resource structure
3087 * for each of_prop. Client driver can directly call
3088 * ti_sci_(get_free, release)_resource apis for handling the resource.
3090 * Return: Pointer to ti_sci_resource if all went well else appropriate
3093 struct ti_sci_resource *
3094 devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
3095 struct udevice *dev, u32 dev_id, char *of_prop)
3097 u32 resource_subtype;
3099 struct ti_sci_resource *res;
3100 bool valid_set = false;
3104 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
3106 return ERR_PTR(-ENOMEM);
3108 sets = dev_read_size(dev, of_prop);
3110 dev_err(dev, "%s resource type ids not available\n", of_prop);
3111 return ERR_PTR(sets);
3113 temp = malloc(sets);
3114 sets /= sizeof(u32);
3117 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
3120 return ERR_PTR(-ENOMEM);
3122 ret = ti_sci_get_resource_type(handle_to_ti_sci_info(handle), dev_id,
3125 dev_err(dev, "No valid resource type for %u\n", dev_id);
3126 return ERR_PTR(-EINVAL);
3129 ret = dev_read_u32_array(dev, of_prop, temp, res->sets);
3131 return ERR_PTR(-EINVAL);
3133 for (i = 0; i < res->sets; i++) {
3134 resource_subtype = temp[i];
3135 ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
3137 &res->desc[i].start,
3140 dev_dbg(dev, "type %d subtype %d not allocated for host %d\n",
3141 resource_type, resource_subtype,
3142 handle_to_ti_sci_info(handle)->host_id);
3143 res->desc[i].start = 0;
3144 res->desc[i].num = 0;
3149 dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n",
3150 resource_type, resource_subtype, res->desc[i].start,
3153 res->desc[i].res_map =
3154 devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) *
3155 sizeof(*res->desc[i].res_map), GFP_KERNEL);
3156 if (!res->desc[i].res_map)
3157 return ERR_PTR(-ENOMEM);
3163 return ERR_PTR(-EINVAL);
3166 /* Description for K2G */
3167 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = {
3168 .default_host_id = 2,
3169 /* Conservative duration */
3170 .max_rx_timeout_ms = 10000,
3171 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3174 .rm_type_map = NULL,
3177 static struct ti_sci_rm_type_map ti_sci_am654_rm_type_map[] = {
3178 {.dev_id = 56, .type = 0x00b}, /* GIC_IRQ */
3179 {.dev_id = 179, .type = 0x000}, /* MAIN_NAV_UDMASS_IA0 */
3180 {.dev_id = 187, .type = 0x009}, /* MAIN_NAV_RA */
3181 {.dev_id = 188, .type = 0x006}, /* MAIN_NAV_UDMAP */
3182 {.dev_id = 194, .type = 0x007}, /* MCU_NAV_UDMAP */
3183 {.dev_id = 195, .type = 0x00a}, /* MCU_NAV_RA */
3184 {.dev_id = 0, .type = 0x000}, /* end of table */
3187 /* Description for AM654 */
3188 static const struct ti_sci_desc ti_sci_pmmc_am654_desc = {
3189 .default_host_id = 12,
3190 /* Conservative duration */
3191 .max_rx_timeout_ms = 10000,
3192 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3195 .rm_type_map = ti_sci_am654_rm_type_map,
3198 static const struct udevice_id ti_sci_ids[] = {
3200 .compatible = "ti,k2g-sci",
3201 .data = (ulong)&ti_sci_pmmc_k2g_desc
3204 .compatible = "ti,am654-sci",
3205 .data = (ulong)&ti_sci_pmmc_am654_desc
3210 U_BOOT_DRIVER(ti_sci) = {
3212 .id = UCLASS_FIRMWARE,
3213 .of_match = ti_sci_ids,
3214 .probe = ti_sci_probe,
3215 .priv_auto_alloc_size = sizeof(struct ti_sci_info),