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>
14 #include <dm/device.h>
15 #include <dm/devres.h>
16 #include <linux/compat.h>
17 #include <linux/err.h>
18 #include <linux/soc/ti/k3-sec-proxy.h>
19 #include <linux/soc/ti/ti_sci_protocol.h>
23 /* List of all TI SCI devices active in system */
24 static LIST_HEAD(ti_sci_list);
27 * struct ti_sci_xfer - Structure representing a message flow
28 * @tx_message: Transmit message
29 * @rx_len: Receive message length
32 struct k3_sec_proxy_msg tx_message;
37 * struct ti_sci_rm_type_map - Structure representing TISCI Resource
38 * management representation of dev_ids.
39 * @dev_id: TISCI device ID
40 * @type: Corresponding id as identified by TISCI RM.
42 * Note: This is used only as a work around for using RM range apis
43 * for AM654 SoC. For future SoCs dev_id will be used as type
44 * for RM range APIs. In order to maintain ABI backward compatibility
45 * type is not being changed for AM654 SoC.
47 struct ti_sci_rm_type_map {
53 * struct ti_sci_desc - Description of SoC integration
54 * @default_host_id: Host identifier representing the compute entity
55 * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
56 * @max_msgs: Maximum number of messages that can be pending
57 * simultaneously in the system
58 * @max_msg_size: Maximum size of data per message that can be handled.
59 * @rm_type_map: RM resource type mapping structure.
63 int max_rx_timeout_ms;
66 struct ti_sci_rm_type_map *rm_type_map;
70 * struct ti_sci_info - Structure representing a TI SCI instance
71 * @dev: Device pointer
72 * @desc: SoC description for this instance
73 * @handle: Instance of TI SCI handle to send to clients.
74 * @chan_tx: Transmit mailbox channel
75 * @chan_rx: Receive mailbox channel
78 * @is_secure: Determines if the communication is through secure threads.
79 * @host_id: Host identifier representing the compute entity
80 * @seq: Seq id used for verification for tx and rx message.
84 const struct ti_sci_desc *desc;
85 struct ti_sci_handle handle;
86 struct mbox_chan chan_tx;
87 struct mbox_chan chan_rx;
88 struct mbox_chan chan_notify;
89 struct ti_sci_xfer xfer;
90 struct list_head list;
91 struct list_head dev_list;
97 struct ti_sci_exclusive_dev {
100 struct list_head list;
103 #define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle)
106 * ti_sci_setup_one_xfer() - Setup one message type
107 * @info: Pointer to SCI entity information
108 * @msg_type: Message type
109 * @msg_flags: Flag to set for the message
110 * @buf: Buffer to be send to mailbox channel
111 * @tx_message_size: transmit message size
112 * @rx_message_size: receive message size. may be set to zero for send-only
115 * Helper function which is used by various command functions that are
116 * exposed to clients of this driver for allocating a message traffic event.
118 * Return: Corresponding ti_sci_xfer pointer if all went fine,
119 * else appropriate error pointer.
121 static struct ti_sci_xfer *ti_sci_setup_one_xfer(struct ti_sci_info *info,
122 u16 msg_type, u32 msg_flags,
124 size_t tx_message_size,
125 size_t rx_message_size)
127 struct ti_sci_xfer *xfer = &info->xfer;
128 struct ti_sci_msg_hdr *hdr;
130 /* Ensure we have sane transfer sizes */
131 if (rx_message_size > info->desc->max_msg_size ||
132 tx_message_size > info->desc->max_msg_size ||
133 (rx_message_size > 0 && rx_message_size < sizeof(*hdr)) ||
134 tx_message_size < sizeof(*hdr))
135 return ERR_PTR(-ERANGE);
137 info->seq = ~info->seq;
138 xfer->tx_message.buf = buf;
139 xfer->tx_message.len = tx_message_size;
140 xfer->rx_len = (u8)rx_message_size;
142 hdr = (struct ti_sci_msg_hdr *)buf;
143 hdr->seq = info->seq;
144 hdr->type = msg_type;
145 hdr->host = info->host_id;
146 hdr->flags = msg_flags;
152 * ti_sci_get_response() - Receive response from mailbox channel
153 * @info: Pointer to SCI entity information
154 * @xfer: Transfer to initiate and wait for response
155 * @chan: Channel to receive the response
157 * Return: -ETIMEDOUT in case of no response, if transmit error,
158 * return corresponding error, else if all goes well,
161 static inline int ti_sci_get_response(struct ti_sci_info *info,
162 struct ti_sci_xfer *xfer,
163 struct mbox_chan *chan)
165 struct k3_sec_proxy_msg *msg = &xfer->tx_message;
166 struct ti_sci_secure_msg_hdr *secure_hdr;
167 struct ti_sci_msg_hdr *hdr;
170 /* Receive the response */
171 ret = mbox_recv(chan, msg, info->desc->max_rx_timeout_ms * 1000);
173 dev_err(info->dev, "%s: Message receive failed. ret = %d\n",
178 /* ToDo: Verify checksum */
179 if (info->is_secure) {
180 secure_hdr = (struct ti_sci_secure_msg_hdr *)msg->buf;
181 msg->buf = (u32 *)((void *)msg->buf + sizeof(*secure_hdr));
184 /* msg is updated by mailbox driver */
185 hdr = (struct ti_sci_msg_hdr *)msg->buf;
187 /* Sanity check for message response */
188 if (hdr->seq != info->seq) {
189 dev_dbg(info->dev, "%s: Message for %d is not expected\n",
194 if (msg->len > info->desc->max_msg_size) {
195 dev_err(info->dev, "%s: Unable to handle %zu xfer (max %d)\n",
196 __func__, msg->len, info->desc->max_msg_size);
200 if (msg->len < xfer->rx_len) {
201 dev_err(info->dev, "%s: Recv xfer %zu < expected %d length\n",
202 __func__, msg->len, xfer->rx_len);
209 * ti_sci_do_xfer() - Do one transfer
210 * @info: Pointer to SCI entity information
211 * @xfer: Transfer to initiate and wait for response
213 * Return: 0 if all went fine, else return appropriate error.
215 static inline int ti_sci_do_xfer(struct ti_sci_info *info,
216 struct ti_sci_xfer *xfer)
218 struct k3_sec_proxy_msg *msg = &xfer->tx_message;
219 u8 secure_buf[info->desc->max_msg_size];
220 struct ti_sci_secure_msg_hdr secure_hdr;
223 if (info->is_secure) {
224 /* ToDo: get checksum of the entire message */
225 secure_hdr.checksum = 0;
226 secure_hdr.reserved = 0;
227 memcpy(&secure_buf[sizeof(secure_hdr)], xfer->tx_message.buf,
228 xfer->tx_message.len);
230 xfer->tx_message.buf = (u32 *)secure_buf;
231 xfer->tx_message.len += sizeof(secure_hdr);
234 xfer->rx_len += sizeof(secure_hdr);
237 /* Send the message */
238 ret = mbox_send(&info->chan_tx, msg);
240 dev_err(info->dev, "%s: Message sending failed. ret = %d\n",
245 /* Get response if requested */
247 ret = ti_sci_get_response(info, xfer, &info->chan_rx);
253 * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity
254 * @handle: pointer to TI SCI handle
256 * Updates the SCI information in the internal data structure.
258 * Return: 0 if all went fine, else return appropriate error.
260 static int ti_sci_cmd_get_revision(struct ti_sci_handle *handle)
262 struct ti_sci_msg_resp_version *rev_info;
263 struct ti_sci_version_info *ver;
264 struct ti_sci_msg_hdr hdr;
265 struct ti_sci_info *info;
266 struct ti_sci_xfer *xfer;
270 return PTR_ERR(handle);
274 info = handle_to_ti_sci_info(handle);
276 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_VERSION,
277 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
278 (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr),
282 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
286 ret = ti_sci_do_xfer(info, xfer);
288 dev_err(info->dev, "Mbox communication fail %d\n", ret);
292 rev_info = (struct ti_sci_msg_resp_version *)xfer->tx_message.buf;
294 ver = &handle->version;
295 ver->abi_major = rev_info->abi_major;
296 ver->abi_minor = rev_info->abi_minor;
297 ver->firmware_revision = rev_info->firmware_revision;
298 strncpy(ver->firmware_description, rev_info->firmware_description,
299 sizeof(ver->firmware_description));
305 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
306 * @r: pointer to response buffer
308 * Return: true if the response was an ACK, else returns false.
310 static inline bool ti_sci_is_response_ack(void *r)
312 struct ti_sci_msg_hdr *hdr = r;
314 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false;
318 * cmd_set_board_config_using_msg() - Common command to send board configuration
320 * @handle: pointer to TI SCI handle
321 * @msg_type: One of the TISCI message types to set board configuration
322 * @addr: Address where the board config structure is located
323 * @size: Size of the board config structure
325 * Return: 0 if all went well, else returns appropriate error value.
327 static int cmd_set_board_config_using_msg(const struct ti_sci_handle *handle,
328 u16 msg_type, u64 addr, u32 size)
330 struct ti_sci_msg_board_config req;
331 struct ti_sci_msg_hdr *resp;
332 struct ti_sci_info *info;
333 struct ti_sci_xfer *xfer;
337 return PTR_ERR(handle);
341 info = handle_to_ti_sci_info(handle);
343 xfer = ti_sci_setup_one_xfer(info, msg_type,
344 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
345 (u32 *)&req, sizeof(req), sizeof(*resp));
348 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
351 req.boardcfgp_high = (addr >> 32) & 0xffffffff;
352 req.boardcfgp_low = addr & 0xffffffff;
353 req.boardcfg_size = size;
355 ret = ti_sci_do_xfer(info, xfer);
357 dev_err(info->dev, "Mbox send fail %d\n", ret);
361 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
363 if (!ti_sci_is_response_ack(resp))
370 * ti_sci_cmd_set_board_config() - Command to send board configuration message
371 * @handle: pointer to TI SCI handle
372 * @addr: Address where the board config structure is located
373 * @size: Size of the board config structure
375 * Return: 0 if all went well, else returns appropriate error value.
377 static int ti_sci_cmd_set_board_config(const struct ti_sci_handle *handle,
380 return cmd_set_board_config_using_msg(handle,
381 TI_SCI_MSG_BOARD_CONFIG,
386 * ti_sci_cmd_set_board_config_rm() - Command to send board resource
387 * management configuration
388 * @handle: pointer to TI SCI handle
389 * @addr: Address where the board RM config structure is located
390 * @size: Size of the RM config structure
392 * Return: 0 if all went well, else returns appropriate error value.
395 int ti_sci_cmd_set_board_config_rm(const struct ti_sci_handle *handle,
398 return cmd_set_board_config_using_msg(handle,
399 TI_SCI_MSG_BOARD_CONFIG_RM,
404 * ti_sci_cmd_set_board_config_security() - Command to send board security
405 * configuration message
406 * @handle: pointer to TI SCI handle
407 * @addr: Address where the board security config structure is located
408 * @size: Size of the security config structure
410 * Return: 0 if all went well, else returns appropriate error value.
413 int ti_sci_cmd_set_board_config_security(const struct ti_sci_handle *handle,
416 return cmd_set_board_config_using_msg(handle,
417 TI_SCI_MSG_BOARD_CONFIG_SECURITY,
422 * ti_sci_cmd_set_board_config_pm() - Command to send board power and clock
423 * configuration message
424 * @handle: pointer to TI SCI handle
425 * @addr: Address where the board PM config structure is located
426 * @size: Size of the PM config structure
428 * Return: 0 if all went well, else returns appropriate error value.
430 static int ti_sci_cmd_set_board_config_pm(const struct ti_sci_handle *handle,
433 return cmd_set_board_config_using_msg(handle,
434 TI_SCI_MSG_BOARD_CONFIG_PM,
438 static struct ti_sci_exclusive_dev
439 *ti_sci_get_exclusive_dev(struct list_head *dev_list, u32 id)
441 struct ti_sci_exclusive_dev *dev;
443 list_for_each_entry(dev, dev_list, list)
450 static void ti_sci_add_exclusive_dev(struct ti_sci_info *info, u32 id)
452 struct ti_sci_exclusive_dev *dev;
454 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
460 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
463 INIT_LIST_HEAD(&dev->list);
464 list_add_tail(&dev->list, &info->dev_list);
467 static void ti_sci_delete_exclusive_dev(struct ti_sci_info *info, u32 id)
469 struct ti_sci_exclusive_dev *dev;
471 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
480 * ti_sci_set_device_state() - Set device state helper
481 * @handle: pointer to TI SCI handle
482 * @id: Device identifier
483 * @flags: flags to setup for the device
484 * @state: State to move the device to
486 * Return: 0 if all went well, else returns appropriate error value.
488 static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
489 u32 id, u32 flags, u8 state)
491 struct ti_sci_msg_req_set_device_state req;
492 struct ti_sci_msg_hdr *resp;
493 struct ti_sci_info *info;
494 struct ti_sci_xfer *xfer;
498 return PTR_ERR(handle);
502 info = handle_to_ti_sci_info(handle);
504 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
505 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
506 (u32 *)&req, sizeof(req), sizeof(*resp));
509 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
515 ret = ti_sci_do_xfer(info, xfer);
517 dev_err(info->dev, "Mbox send fail %d\n", ret);
521 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
523 if (!ti_sci_is_response_ack(resp))
526 if (state == MSG_DEVICE_SW_STATE_AUTO_OFF)
527 ti_sci_delete_exclusive_dev(info, id);
528 else if (flags & MSG_FLAG_DEVICE_EXCLUSIVE)
529 ti_sci_add_exclusive_dev(info, id);
535 * ti_sci_set_device_state_no_wait() - Set device state helper without
536 * requesting or waiting for a response.
537 * @handle: pointer to TI SCI handle
538 * @id: Device identifier
539 * @flags: flags to setup for the device
540 * @state: State to move the device to
542 * Return: 0 if all went well, else returns appropriate error value.
544 static int ti_sci_set_device_state_no_wait(const struct ti_sci_handle *handle,
545 u32 id, u32 flags, u8 state)
547 struct ti_sci_msg_req_set_device_state req;
548 struct ti_sci_info *info;
549 struct ti_sci_xfer *xfer;
553 return PTR_ERR(handle);
557 info = handle_to_ti_sci_info(handle);
559 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
560 flags | TI_SCI_FLAG_REQ_GENERIC_NORESPONSE,
561 (u32 *)&req, sizeof(req), 0);
564 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
570 ret = ti_sci_do_xfer(info, xfer);
572 dev_err(info->dev, "Mbox send fail %d\n", ret);
578 * ti_sci_get_device_state() - Get device state helper
579 * @handle: Handle to the device
580 * @id: Device Identifier
581 * @clcnt: Pointer to Context Loss Count
582 * @resets: pointer to resets
583 * @p_state: pointer to p_state
584 * @c_state: pointer to c_state
586 * Return: 0 if all went fine, else return appropriate error.
588 static int ti_sci_get_device_state(const struct ti_sci_handle *handle,
589 u32 id, u32 *clcnt, u32 *resets,
590 u8 *p_state, u8 *c_state)
592 struct ti_sci_msg_resp_get_device_state *resp;
593 struct ti_sci_msg_req_get_device_state req;
594 struct ti_sci_info *info;
595 struct ti_sci_xfer *xfer;
599 return PTR_ERR(handle);
603 if (!clcnt && !resets && !p_state && !c_state)
606 info = handle_to_ti_sci_info(handle);
608 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_DEVICE_STATE,
609 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
610 (u32 *)&req, sizeof(req), sizeof(*resp));
613 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
618 ret = ti_sci_do_xfer(info, xfer);
620 dev_err(dev, "Mbox send fail %d\n", ret);
624 resp = (struct ti_sci_msg_resp_get_device_state *)xfer->tx_message.buf;
625 if (!ti_sci_is_response_ack(resp))
629 *clcnt = resp->context_loss_count;
631 *resets = resp->resets;
633 *p_state = resp->programmed_state;
635 *c_state = resp->current_state;
641 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
642 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
643 * @id: Device Identifier
645 * Request for the device - NOTE: the client MUST maintain integrity of
646 * usage count by balancing get_device with put_device. No refcounting is
647 * managed by driver for that purpose.
649 * NOTE: The request is for exclusive access for the processor.
651 * Return: 0 if all went fine, else return appropriate error.
653 static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
655 return ti_sci_set_device_state(handle, id, 0,
656 MSG_DEVICE_SW_STATE_ON);
659 static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle *handle,
662 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
663 MSG_DEVICE_SW_STATE_ON);
667 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
668 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
669 * @id: Device Identifier
671 * Request for the device - NOTE: the client MUST maintain integrity of
672 * usage count by balancing get_device with put_device. No refcounting is
673 * managed by driver for that purpose.
675 * Return: 0 if all went fine, else return appropriate error.
677 static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
679 return ti_sci_set_device_state(handle, id,
681 MSG_DEVICE_SW_STATE_RETENTION);
684 static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle *handle,
687 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
688 MSG_DEVICE_SW_STATE_RETENTION);
692 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
693 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
694 * @id: Device Identifier
696 * Request for the device - NOTE: the client MUST maintain integrity of
697 * usage count by balancing get_device with put_device. No refcounting is
698 * managed by driver for that purpose.
700 * Return: 0 if all went fine, else return appropriate error.
702 static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
704 return ti_sci_set_device_state(handle, id, 0,
705 MSG_DEVICE_SW_STATE_AUTO_OFF);
709 int ti_sci_cmd_release_exclusive_devices(const struct ti_sci_handle *handle)
711 struct ti_sci_exclusive_dev *dev, *tmp;
712 struct ti_sci_info *info;
715 info = handle_to_ti_sci_info(handle);
717 list_for_each_entry_safe(dev, tmp, &info->dev_list, list) {
719 debug("%s: id = %d, cnt = %d\n", __func__, dev->id, cnt);
720 for (i = 0; i < cnt; i++)
721 ti_sci_cmd_put_device(handle, dev->id);
728 * ti_sci_cmd_dev_is_valid() - Is the device valid
729 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
730 * @id: Device Identifier
732 * Return: 0 if all went fine and the device ID is valid, else return
735 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
739 /* check the device state which will also tell us if the ID is valid */
740 return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused);
744 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
745 * @handle: Pointer to TISCI handle
746 * @id: Device Identifier
747 * @count: Pointer to Context Loss counter to populate
749 * Return: 0 if all went fine, else return appropriate error.
751 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
754 return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
758 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
759 * @handle: Pointer to TISCI handle
760 * @id: Device Identifier
761 * @r_state: true if requested to be idle
763 * Return: 0 if all went fine, else return appropriate error.
765 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
774 ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
778 *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
784 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
785 * @handle: Pointer to TISCI handle
786 * @id: Device Identifier
787 * @r_state: true if requested to be stopped
788 * @curr_state: true if currently stopped.
790 * Return: 0 if all went fine, else return appropriate error.
792 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
793 bool *r_state, bool *curr_state)
798 if (!r_state && !curr_state)
802 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
807 *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
809 *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
815 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
816 * @handle: Pointer to TISCI handle
817 * @id: Device Identifier
818 * @r_state: true if requested to be ON
819 * @curr_state: true if currently ON and active
821 * Return: 0 if all went fine, else return appropriate error.
823 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
824 bool *r_state, bool *curr_state)
829 if (!r_state && !curr_state)
833 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
838 *r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
840 *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
846 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
847 * @handle: Pointer to TISCI handle
848 * @id: Device Identifier
849 * @curr_state: true if currently transitioning.
851 * Return: 0 if all went fine, else return appropriate error.
853 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
862 ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
866 *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
872 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
874 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
875 * @id: Device Identifier
876 * @reset_state: Device specific reset bit field
878 * Return: 0 if all went fine, else return appropriate error.
880 static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
881 u32 id, u32 reset_state)
883 struct ti_sci_msg_req_set_device_resets req;
884 struct ti_sci_msg_hdr *resp;
885 struct ti_sci_info *info;
886 struct ti_sci_xfer *xfer;
890 return PTR_ERR(handle);
894 info = handle_to_ti_sci_info(handle);
896 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_RESETS,
897 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
898 (u32 *)&req, sizeof(req), sizeof(*resp));
901 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
905 req.resets = reset_state;
907 ret = ti_sci_do_xfer(info, xfer);
909 dev_err(info->dev, "Mbox send fail %d\n", ret);
913 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
915 if (!ti_sci_is_response_ack(resp))
922 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
924 * @handle: Pointer to TISCI handle
925 * @id: Device Identifier
926 * @reset_state: Pointer to reset state to populate
928 * Return: 0 if all went fine, else return appropriate error.
930 static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
931 u32 id, u32 *reset_state)
933 return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
938 * ti_sci_set_clock_state() - Set clock state helper
939 * @handle: pointer to TI SCI handle
940 * @dev_id: Device identifier this request is for
941 * @clk_id: Clock identifier for the device for this request.
942 * Each device has it's own set of clock inputs. This indexes
943 * which clock input to modify.
944 * @flags: Header flags as needed
945 * @state: State to request for the clock.
947 * Return: 0 if all went well, else returns appropriate error value.
949 static int ti_sci_set_clock_state(const struct ti_sci_handle *handle,
950 u32 dev_id, u8 clk_id,
953 struct ti_sci_msg_req_set_clock_state req;
954 struct ti_sci_msg_hdr *resp;
955 struct ti_sci_info *info;
956 struct ti_sci_xfer *xfer;
960 return PTR_ERR(handle);
964 info = handle_to_ti_sci_info(handle);
966 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_STATE,
967 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
968 (u32 *)&req, sizeof(req), sizeof(*resp));
971 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
976 req.request_state = state;
978 ret = ti_sci_do_xfer(info, xfer);
980 dev_err(info->dev, "Mbox send fail %d\n", ret);
984 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
986 if (!ti_sci_is_response_ack(resp))
993 * ti_sci_cmd_get_clock_state() - Get clock state helper
994 * @handle: pointer to TI SCI handle
995 * @dev_id: Device identifier this request is for
996 * @clk_id: Clock identifier for the device for this request.
997 * Each device has it's own set of clock inputs. This indexes
998 * which clock input to modify.
999 * @programmed_state: State requested for clock to move to
1000 * @current_state: State that the clock is currently in
1002 * Return: 0 if all went well, else returns appropriate error value.
1004 static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle *handle,
1005 u32 dev_id, u8 clk_id,
1006 u8 *programmed_state, u8 *current_state)
1008 struct ti_sci_msg_resp_get_clock_state *resp;
1009 struct ti_sci_msg_req_get_clock_state req;
1010 struct ti_sci_info *info;
1011 struct ti_sci_xfer *xfer;
1015 return PTR_ERR(handle);
1019 if (!programmed_state && !current_state)
1022 info = handle_to_ti_sci_info(handle);
1024 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_STATE,
1025 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1026 (u32 *)&req, sizeof(req), sizeof(*resp));
1028 ret = PTR_ERR(xfer);
1029 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1032 req.dev_id = dev_id;
1033 req.clk_id = clk_id;
1035 ret = ti_sci_do_xfer(info, xfer);
1037 dev_err(info->dev, "Mbox send fail %d\n", ret);
1041 resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->tx_message.buf;
1043 if (!ti_sci_is_response_ack(resp))
1046 if (programmed_state)
1047 *programmed_state = resp->programmed_state;
1049 *current_state = resp->current_state;
1055 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
1056 * @handle: pointer to TI SCI handle
1057 * @dev_id: Device identifier this request is for
1058 * @clk_id: Clock identifier for the device for this request.
1059 * Each device has it's own set of clock inputs. This indexes
1060 * which clock input to modify.
1061 * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false'
1062 * @can_change_freq: 'true' if frequency change is desired, else 'false'
1063 * @enable_input_term: 'true' if input termination is desired, else 'false'
1065 * Return: 0 if all went well, else returns appropriate error value.
1067 static int ti_sci_cmd_get_clock(const struct ti_sci_handle *handle, u32 dev_id,
1068 u8 clk_id, bool needs_ssc, bool can_change_freq,
1069 bool enable_input_term)
1073 flags |= needs_ssc ? MSG_FLAG_CLOCK_ALLOW_SSC : 0;
1074 flags |= can_change_freq ? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE : 0;
1075 flags |= enable_input_term ? MSG_FLAG_CLOCK_INPUT_TERM : 0;
1077 return ti_sci_set_clock_state(handle, dev_id, clk_id, flags,
1078 MSG_CLOCK_SW_STATE_REQ);
1082 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
1083 * @handle: pointer to TI SCI handle
1084 * @dev_id: Device identifier this request is for
1085 * @clk_id: Clock identifier for the device for this request.
1086 * Each device has it's own set of clock inputs. This indexes
1087 * which clock input to modify.
1089 * NOTE: This clock must have been requested by get_clock previously.
1091 * Return: 0 if all went well, else returns appropriate error value.
1093 static int ti_sci_cmd_idle_clock(const struct ti_sci_handle *handle,
1094 u32 dev_id, u8 clk_id)
1096 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1097 MSG_CLOCK_SW_STATE_UNREQ);
1101 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
1102 * @handle: pointer to TI SCI handle
1103 * @dev_id: Device identifier this request is for
1104 * @clk_id: Clock identifier for the device for this request.
1105 * Each device has it's own set of clock inputs. This indexes
1106 * which clock input to modify.
1108 * NOTE: This clock must have been requested by get_clock previously.
1110 * Return: 0 if all went well, else returns appropriate error value.
1112 static int ti_sci_cmd_put_clock(const struct ti_sci_handle *handle,
1113 u32 dev_id, u8 clk_id)
1115 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1116 MSG_CLOCK_SW_STATE_AUTO);
1120 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
1121 * @handle: pointer to TI SCI handle
1122 * @dev_id: Device identifier this request is for
1123 * @clk_id: Clock identifier for the device for this request.
1124 * Each device has it's own set of clock inputs. This indexes
1125 * which clock input to modify.
1126 * @req_state: state indicating if the clock is auto managed
1128 * Return: 0 if all went well, else returns appropriate error value.
1130 static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle *handle,
1131 u32 dev_id, u8 clk_id, bool *req_state)
1139 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, &state, NULL);
1143 *req_state = (state == MSG_CLOCK_SW_STATE_AUTO);
1148 * ti_sci_cmd_clk_is_on() - Is the clock ON
1149 * @handle: pointer to TI SCI handle
1150 * @dev_id: Device identifier this request is for
1151 * @clk_id: Clock identifier for the device for this request.
1152 * Each device has it's own set of clock inputs. This indexes
1153 * which clock input to modify.
1154 * @req_state: state indicating if the clock is managed by us and enabled
1155 * @curr_state: state indicating if the clock is ready for operation
1157 * Return: 0 if all went well, else returns appropriate error value.
1159 static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle *handle, u32 dev_id,
1160 u8 clk_id, bool *req_state, bool *curr_state)
1162 u8 c_state = 0, r_state = 0;
1165 if (!req_state && !curr_state)
1168 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1169 &r_state, &c_state);
1174 *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ);
1176 *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY);
1181 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1182 * @handle: pointer to TI SCI handle
1183 * @dev_id: Device identifier this request is for
1184 * @clk_id: Clock identifier for the device for this request.
1185 * Each device has it's own set of clock inputs. This indexes
1186 * which clock input to modify.
1187 * @req_state: state indicating if the clock is managed by us and disabled
1188 * @curr_state: state indicating if the clock is NOT ready for operation
1190 * Return: 0 if all went well, else returns appropriate error value.
1192 static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle *handle, u32 dev_id,
1193 u8 clk_id, bool *req_state, bool *curr_state)
1195 u8 c_state = 0, r_state = 0;
1198 if (!req_state && !curr_state)
1201 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1202 &r_state, &c_state);
1207 *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ);
1209 *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY);
1214 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1215 * @handle: pointer to TI SCI handle
1216 * @dev_id: Device identifier this request is for
1217 * @clk_id: Clock identifier for the device for this request.
1218 * Each device has it's own set of clock inputs. This indexes
1219 * which clock input to modify.
1220 * @parent_id: Parent clock identifier to set
1222 * Return: 0 if all went well, else returns appropriate error value.
1224 static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle *handle,
1225 u32 dev_id, u8 clk_id, u8 parent_id)
1227 struct ti_sci_msg_req_set_clock_parent req;
1228 struct ti_sci_msg_hdr *resp;
1229 struct ti_sci_info *info;
1230 struct ti_sci_xfer *xfer;
1234 return PTR_ERR(handle);
1238 info = handle_to_ti_sci_info(handle);
1240 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_PARENT,
1241 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1242 (u32 *)&req, sizeof(req), sizeof(*resp));
1244 ret = PTR_ERR(xfer);
1245 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1248 req.dev_id = dev_id;
1249 req.clk_id = clk_id;
1250 req.parent_id = parent_id;
1252 ret = ti_sci_do_xfer(info, xfer);
1254 dev_err(info->dev, "Mbox send fail %d\n", ret);
1258 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1260 if (!ti_sci_is_response_ack(resp))
1267 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1268 * @handle: pointer to TI SCI handle
1269 * @dev_id: Device identifier this request is for
1270 * @clk_id: Clock identifier for the device for this request.
1271 * Each device has it's own set of clock inputs. This indexes
1272 * which clock input to modify.
1273 * @parent_id: Current clock parent
1275 * Return: 0 if all went well, else returns appropriate error value.
1277 static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle,
1278 u32 dev_id, u8 clk_id, u8 *parent_id)
1280 struct ti_sci_msg_resp_get_clock_parent *resp;
1281 struct ti_sci_msg_req_get_clock_parent req;
1282 struct ti_sci_info *info;
1283 struct ti_sci_xfer *xfer;
1287 return PTR_ERR(handle);
1288 if (!handle || !parent_id)
1291 info = handle_to_ti_sci_info(handle);
1293 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_PARENT,
1294 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1295 (u32 *)&req, sizeof(req), sizeof(*resp));
1297 ret = PTR_ERR(xfer);
1298 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1301 req.dev_id = dev_id;
1302 req.clk_id = clk_id;
1304 ret = ti_sci_do_xfer(info, xfer);
1306 dev_err(info->dev, "Mbox send fail %d\n", ret);
1310 resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->tx_message.buf;
1312 if (!ti_sci_is_response_ack(resp))
1315 *parent_id = resp->parent_id;
1321 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1322 * @handle: pointer to TI SCI handle
1323 * @dev_id: Device identifier this request is for
1324 * @clk_id: Clock identifier for the device for this request.
1325 * Each device has it's own set of clock inputs. This indexes
1326 * which clock input to modify.
1327 * @num_parents: Returns he number of parents to the current clock.
1329 * Return: 0 if all went well, else returns appropriate error value.
1331 static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle *handle,
1332 u32 dev_id, u8 clk_id,
1335 struct ti_sci_msg_resp_get_clock_num_parents *resp;
1336 struct ti_sci_msg_req_get_clock_num_parents req;
1337 struct ti_sci_info *info;
1338 struct ti_sci_xfer *xfer;
1342 return PTR_ERR(handle);
1343 if (!handle || !num_parents)
1346 info = handle_to_ti_sci_info(handle);
1348 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS,
1349 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1350 (u32 *)&req, sizeof(req), sizeof(*resp));
1352 ret = PTR_ERR(xfer);
1353 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1356 req.dev_id = dev_id;
1357 req.clk_id = clk_id;
1359 ret = ti_sci_do_xfer(info, xfer);
1361 dev_err(info->dev, "Mbox send fail %d\n", ret);
1365 resp = (struct ti_sci_msg_resp_get_clock_num_parents *)
1366 xfer->tx_message.buf;
1368 if (!ti_sci_is_response_ack(resp))
1371 *num_parents = resp->num_parents;
1377 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1378 * @handle: pointer to TI SCI handle
1379 * @dev_id: Device identifier this request is for
1380 * @clk_id: Clock identifier for the device for this request.
1381 * Each device has it's own set of clock inputs. This indexes
1382 * which clock input to modify.
1383 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1384 * allowable programmed frequency and does not account for clock
1385 * tolerances and jitter.
1386 * @target_freq: The target clock frequency in Hz. A frequency will be
1387 * processed as close to this target frequency as possible.
1388 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1389 * allowable programmed frequency and does not account for clock
1390 * tolerances and jitter.
1391 * @match_freq: Frequency match in Hz response.
1393 * Return: 0 if all went well, else returns appropriate error value.
1395 static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle *handle,
1396 u32 dev_id, u8 clk_id, u64 min_freq,
1397 u64 target_freq, u64 max_freq,
1400 struct ti_sci_msg_resp_query_clock_freq *resp;
1401 struct ti_sci_msg_req_query_clock_freq req;
1402 struct ti_sci_info *info;
1403 struct ti_sci_xfer *xfer;
1407 return PTR_ERR(handle);
1408 if (!handle || !match_freq)
1411 info = handle_to_ti_sci_info(handle);
1413 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_QUERY_CLOCK_FREQ,
1414 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1415 (u32 *)&req, sizeof(req), sizeof(*resp));
1417 ret = PTR_ERR(xfer);
1418 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1421 req.dev_id = dev_id;
1422 req.clk_id = clk_id;
1423 req.min_freq_hz = min_freq;
1424 req.target_freq_hz = target_freq;
1425 req.max_freq_hz = max_freq;
1427 ret = ti_sci_do_xfer(info, xfer);
1429 dev_err(info->dev, "Mbox send fail %d\n", ret);
1433 resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->tx_message.buf;
1435 if (!ti_sci_is_response_ack(resp))
1438 *match_freq = resp->freq_hz;
1444 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1445 * @handle: pointer to TI SCI handle
1446 * @dev_id: Device identifier this request is for
1447 * @clk_id: Clock identifier for the device for this request.
1448 * Each device has it's own set of clock inputs. This indexes
1449 * which clock input to modify.
1450 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1451 * allowable programmed frequency and does not account for clock
1452 * tolerances and jitter.
1453 * @target_freq: The target clock frequency in Hz. A frequency will be
1454 * processed as close to this target frequency as possible.
1455 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1456 * allowable programmed frequency and does not account for clock
1457 * tolerances and jitter.
1459 * Return: 0 if all went well, else returns appropriate error value.
1461 static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle *handle,
1462 u32 dev_id, u8 clk_id, u64 min_freq,
1463 u64 target_freq, u64 max_freq)
1465 struct ti_sci_msg_req_set_clock_freq req;
1466 struct ti_sci_msg_hdr *resp;
1467 struct ti_sci_info *info;
1468 struct ti_sci_xfer *xfer;
1472 return PTR_ERR(handle);
1476 info = handle_to_ti_sci_info(handle);
1478 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_FREQ,
1479 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1480 (u32 *)&req, sizeof(req), sizeof(*resp));
1482 ret = PTR_ERR(xfer);
1483 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1486 req.dev_id = dev_id;
1487 req.clk_id = clk_id;
1488 req.min_freq_hz = min_freq;
1489 req.target_freq_hz = target_freq;
1490 req.max_freq_hz = max_freq;
1492 ret = ti_sci_do_xfer(info, xfer);
1494 dev_err(info->dev, "Mbox send fail %d\n", ret);
1498 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1500 if (!ti_sci_is_response_ack(resp))
1507 * ti_sci_cmd_clk_get_freq() - Get current frequency
1508 * @handle: pointer to TI SCI handle
1509 * @dev_id: Device identifier this request is for
1510 * @clk_id: Clock identifier for the device for this request.
1511 * Each device has it's own set of clock inputs. This indexes
1512 * which clock input to modify.
1513 * @freq: Currently frequency in Hz
1515 * Return: 0 if all went well, else returns appropriate error value.
1517 static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle,
1518 u32 dev_id, u8 clk_id, u64 *freq)
1520 struct ti_sci_msg_resp_get_clock_freq *resp;
1521 struct ti_sci_msg_req_get_clock_freq req;
1522 struct ti_sci_info *info;
1523 struct ti_sci_xfer *xfer;
1527 return PTR_ERR(handle);
1528 if (!handle || !freq)
1531 info = handle_to_ti_sci_info(handle);
1533 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_FREQ,
1534 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1535 (u32 *)&req, sizeof(req), sizeof(*resp));
1537 ret = PTR_ERR(xfer);
1538 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1541 req.dev_id = dev_id;
1542 req.clk_id = clk_id;
1544 ret = ti_sci_do_xfer(info, xfer);
1546 dev_err(info->dev, "Mbox send fail %d\n", ret);
1550 resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->tx_message.buf;
1552 if (!ti_sci_is_response_ack(resp))
1555 *freq = resp->freq_hz;
1561 * ti_sci_cmd_core_reboot() - Command to request system reset
1562 * @handle: pointer to TI SCI handle
1564 * Return: 0 if all went well, else returns appropriate error value.
1566 static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle)
1568 struct ti_sci_msg_req_reboot req;
1569 struct ti_sci_msg_hdr *resp;
1570 struct ti_sci_info *info;
1571 struct ti_sci_xfer *xfer;
1575 return PTR_ERR(handle);
1579 info = handle_to_ti_sci_info(handle);
1581 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SYS_RESET,
1582 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1583 (u32 *)&req, sizeof(req), sizeof(*resp));
1585 ret = PTR_ERR(xfer);
1586 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1590 ret = ti_sci_do_xfer(info, xfer);
1592 dev_err(dev, "Mbox send fail %d\n", ret);
1596 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1598 if (!ti_sci_is_response_ack(resp))
1604 static int ti_sci_get_resource_type(struct ti_sci_info *info, u16 dev_id,
1607 struct ti_sci_rm_type_map *rm_type_map = info->desc->rm_type_map;
1611 /* If map is not provided then assume dev_id is used as type */
1617 for (i = 0; rm_type_map[i].dev_id; i++) {
1618 if (rm_type_map[i].dev_id == dev_id) {
1619 *type = rm_type_map[i].type;
1632 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1633 * to a host. Resource is uniquely identified by
1635 * @handle: Pointer to TISCI handle.
1636 * @dev_id: TISCI device ID.
1637 * @subtype: Resource assignment subtype that is being requested
1638 * from the given device.
1639 * @s_host: Host processor ID to which the resources are allocated
1640 * @range_start: Start index of the resource range
1641 * @range_num: Number of resources in the range
1643 * Return: 0 if all went fine, else return appropriate error.
1645 static int ti_sci_get_resource_range(const struct ti_sci_handle *handle,
1646 u32 dev_id, u8 subtype, u8 s_host,
1647 u16 *range_start, u16 *range_num)
1649 struct ti_sci_msg_resp_get_resource_range *resp;
1650 struct ti_sci_msg_req_get_resource_range req;
1651 struct ti_sci_xfer *xfer;
1652 struct ti_sci_info *info;
1657 return PTR_ERR(handle);
1661 info = handle_to_ti_sci_info(handle);
1663 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE,
1664 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1665 (u32 *)&req, sizeof(req), sizeof(*resp));
1667 ret = PTR_ERR(xfer);
1668 dev_err(dev, "Message alloc failed(%d)\n", ret);
1672 ret = ti_sci_get_resource_type(info, dev_id, &type);
1674 dev_err(dev, "rm type lookup failed for %u\n", dev_id);
1678 req.secondary_host = s_host;
1679 req.type = type & MSG_RM_RESOURCE_TYPE_MASK;
1680 req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK;
1682 ret = ti_sci_do_xfer(info, xfer);
1684 dev_err(dev, "Mbox send fail %d\n", ret);
1688 resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->tx_message.buf;
1689 if (!ti_sci_is_response_ack(resp)) {
1691 } else if (!resp->range_start && !resp->range_num) {
1694 *range_start = resp->range_start;
1695 *range_num = resp->range_num;
1703 * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1704 * that is same as ti sci interface host.
1705 * @handle: Pointer to TISCI handle.
1706 * @dev_id: TISCI device ID.
1707 * @subtype: Resource assignment subtype that is being requested
1708 * from the given device.
1709 * @range_start: Start index of the resource range
1710 * @range_num: Number of resources in the range
1712 * Return: 0 if all went fine, else return appropriate error.
1714 static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle,
1715 u32 dev_id, u8 subtype,
1716 u16 *range_start, u16 *range_num)
1718 return ti_sci_get_resource_range(handle, dev_id, subtype,
1719 TI_SCI_IRQ_SECONDARY_HOST_INVALID,
1720 range_start, range_num);
1724 * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1725 * assigned to a specified host.
1726 * @handle: Pointer to TISCI handle.
1727 * @dev_id: TISCI device ID.
1728 * @subtype: Resource assignment subtype that is being requested
1729 * from the given device.
1730 * @s_host: Host processor ID to which the resources are allocated
1731 * @range_start: Start index of the resource range
1732 * @range_num: Number of resources in the range
1734 * Return: 0 if all went fine, else return appropriate error.
1737 int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle,
1738 u32 dev_id, u8 subtype, u8 s_host,
1739 u16 *range_start, u16 *range_num)
1741 return ti_sci_get_resource_range(handle, dev_id, subtype, s_host,
1742 range_start, range_num);
1746 * ti_sci_cmd_query_msmc() - Command to query currently available msmc memory
1747 * @handle: pointer to TI SCI handle
1748 * @msms_start: MSMC start as returned by tisci
1749 * @msmc_end: MSMC end as returned by tisci
1751 * Return: 0 if all went well, else returns appropriate error value.
1753 static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle,
1754 u64 *msmc_start, u64 *msmc_end)
1756 struct ti_sci_msg_resp_query_msmc *resp;
1757 struct ti_sci_msg_hdr req;
1758 struct ti_sci_info *info;
1759 struct ti_sci_xfer *xfer;
1763 return PTR_ERR(handle);
1767 info = handle_to_ti_sci_info(handle);
1769 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_QUERY_MSMC,
1770 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1771 (u32 *)&req, sizeof(req), sizeof(*resp));
1773 ret = PTR_ERR(xfer);
1774 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1778 ret = ti_sci_do_xfer(info, xfer);
1780 dev_err(dev, "Mbox send fail %d\n", ret);
1784 resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf;
1786 if (!ti_sci_is_response_ack(resp))
1789 *msmc_start = ((u64)resp->msmc_start_high << TISCI_ADDR_HIGH_SHIFT) |
1790 resp->msmc_start_low;
1791 *msmc_end = ((u64)resp->msmc_end_high << TISCI_ADDR_HIGH_SHIFT) |
1798 * ti_sci_cmd_proc_request() - Command to request a physical processor control
1799 * @handle: Pointer to TI SCI handle
1800 * @proc_id: Processor ID this request is for
1802 * Return: 0 if all went well, else returns appropriate error value.
1804 static int ti_sci_cmd_proc_request(const struct ti_sci_handle *handle,
1807 struct ti_sci_msg_req_proc_request req;
1808 struct ti_sci_msg_hdr *resp;
1809 struct ti_sci_info *info;
1810 struct ti_sci_xfer *xfer;
1814 return PTR_ERR(handle);
1818 info = handle_to_ti_sci_info(handle);
1820 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_REQUEST,
1821 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1822 (u32 *)&req, sizeof(req), sizeof(*resp));
1824 ret = PTR_ERR(xfer);
1825 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1828 req.processor_id = proc_id;
1830 ret = ti_sci_do_xfer(info, xfer);
1832 dev_err(info->dev, "Mbox send fail %d\n", ret);
1836 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1838 if (!ti_sci_is_response_ack(resp))
1845 * ti_sci_cmd_proc_release() - Command to release a physical processor control
1846 * @handle: Pointer to TI SCI handle
1847 * @proc_id: Processor ID this request is for
1849 * Return: 0 if all went well, else returns appropriate error value.
1851 static int ti_sci_cmd_proc_release(const struct ti_sci_handle *handle,
1854 struct ti_sci_msg_req_proc_release req;
1855 struct ti_sci_msg_hdr *resp;
1856 struct ti_sci_info *info;
1857 struct ti_sci_xfer *xfer;
1861 return PTR_ERR(handle);
1865 info = handle_to_ti_sci_info(handle);
1867 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_RELEASE,
1868 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1869 (u32 *)&req, sizeof(req), sizeof(*resp));
1871 ret = PTR_ERR(xfer);
1872 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1875 req.processor_id = proc_id;
1877 ret = ti_sci_do_xfer(info, xfer);
1879 dev_err(info->dev, "Mbox send fail %d\n", ret);
1883 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1885 if (!ti_sci_is_response_ack(resp))
1892 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
1893 * control to a host in the processor's access
1895 * @handle: Pointer to TI SCI handle
1896 * @proc_id: Processor ID this request is for
1897 * @host_id: Host ID to get the control of the processor
1899 * Return: 0 if all went well, else returns appropriate error value.
1901 static int ti_sci_cmd_proc_handover(const struct ti_sci_handle *handle,
1902 u8 proc_id, u8 host_id)
1904 struct ti_sci_msg_req_proc_handover req;
1905 struct ti_sci_msg_hdr *resp;
1906 struct ti_sci_info *info;
1907 struct ti_sci_xfer *xfer;
1911 return PTR_ERR(handle);
1915 info = handle_to_ti_sci_info(handle);
1917 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_HANDOVER,
1918 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1919 (u32 *)&req, sizeof(req), sizeof(*resp));
1921 ret = PTR_ERR(xfer);
1922 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1925 req.processor_id = proc_id;
1926 req.host_id = host_id;
1928 ret = ti_sci_do_xfer(info, xfer);
1930 dev_err(info->dev, "Mbox send fail %d\n", ret);
1934 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1936 if (!ti_sci_is_response_ack(resp))
1943 * ti_sci_cmd_set_proc_boot_cfg() - Command to set the processor boot
1944 * configuration flags
1945 * @handle: Pointer to TI SCI handle
1946 * @proc_id: Processor ID this request is for
1947 * @config_flags_set: Configuration flags to be set
1948 * @config_flags_clear: Configuration flags to be cleared.
1950 * Return: 0 if all went well, else returns appropriate error value.
1952 static int ti_sci_cmd_set_proc_boot_cfg(const struct ti_sci_handle *handle,
1953 u8 proc_id, u64 bootvector,
1954 u32 config_flags_set,
1955 u32 config_flags_clear)
1957 struct ti_sci_msg_req_set_proc_boot_config req;
1958 struct ti_sci_msg_hdr *resp;
1959 struct ti_sci_info *info;
1960 struct ti_sci_xfer *xfer;
1964 return PTR_ERR(handle);
1968 info = handle_to_ti_sci_info(handle);
1970 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CONFIG,
1971 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1972 (u32 *)&req, sizeof(req), sizeof(*resp));
1974 ret = PTR_ERR(xfer);
1975 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1978 req.processor_id = proc_id;
1979 req.bootvector_low = bootvector & TISCI_ADDR_LOW_MASK;
1980 req.bootvector_high = (bootvector & TISCI_ADDR_HIGH_MASK) >>
1981 TISCI_ADDR_HIGH_SHIFT;
1982 req.config_flags_set = config_flags_set;
1983 req.config_flags_clear = config_flags_clear;
1985 ret = ti_sci_do_xfer(info, xfer);
1987 dev_err(info->dev, "Mbox send fail %d\n", ret);
1991 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1993 if (!ti_sci_is_response_ack(resp))
2000 * ti_sci_cmd_set_proc_boot_ctrl() - Command to set the processor boot
2002 * @handle: Pointer to TI SCI handle
2003 * @proc_id: Processor ID this request is for
2004 * @control_flags_set: Control flags to be set
2005 * @control_flags_clear: Control flags to be cleared
2007 * Return: 0 if all went well, else returns appropriate error value.
2009 static int ti_sci_cmd_set_proc_boot_ctrl(const struct ti_sci_handle *handle,
2010 u8 proc_id, u32 control_flags_set,
2011 u32 control_flags_clear)
2013 struct ti_sci_msg_req_set_proc_boot_ctrl req;
2014 struct ti_sci_msg_hdr *resp;
2015 struct ti_sci_info *info;
2016 struct ti_sci_xfer *xfer;
2020 return PTR_ERR(handle);
2024 info = handle_to_ti_sci_info(handle);
2026 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CTRL,
2027 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2028 (u32 *)&req, sizeof(req), sizeof(*resp));
2030 ret = PTR_ERR(xfer);
2031 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2034 req.processor_id = proc_id;
2035 req.control_flags_set = control_flags_set;
2036 req.control_flags_clear = control_flags_clear;
2038 ret = ti_sci_do_xfer(info, xfer);
2040 dev_err(info->dev, "Mbox send fail %d\n", ret);
2044 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2046 if (!ti_sci_is_response_ack(resp))
2053 * ti_sci_cmd_proc_auth_boot_image() - Command to authenticate and load the
2054 * image and then set the processor configuration flags.
2055 * @handle: Pointer to TI SCI handle
2056 * @image_addr: Memory address at which payload image and certificate is
2057 * located in memory, this is updated if the image data is
2058 * moved during authentication.
2059 * @image_size: This is updated with the final size of the image after
2062 * Return: 0 if all went well, else returns appropriate error value.
2064 static int ti_sci_cmd_proc_auth_boot_image(const struct ti_sci_handle *handle,
2065 u64 *image_addr, u32 *image_size)
2067 struct ti_sci_msg_req_proc_auth_boot_image req;
2068 struct ti_sci_msg_resp_proc_auth_boot_image *resp;
2069 struct ti_sci_info *info;
2070 struct ti_sci_xfer *xfer;
2074 return PTR_ERR(handle);
2078 info = handle_to_ti_sci_info(handle);
2080 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_AUTH_BOOT_IMIAGE,
2081 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2082 (u32 *)&req, sizeof(req), sizeof(*resp));
2084 ret = PTR_ERR(xfer);
2085 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2088 req.cert_addr_low = *image_addr & TISCI_ADDR_LOW_MASK;
2089 req.cert_addr_high = (*image_addr & TISCI_ADDR_HIGH_MASK) >>
2090 TISCI_ADDR_HIGH_SHIFT;
2092 ret = ti_sci_do_xfer(info, xfer);
2094 dev_err(info->dev, "Mbox send fail %d\n", ret);
2098 resp = (struct ti_sci_msg_resp_proc_auth_boot_image *)xfer->tx_message.buf;
2100 if (!ti_sci_is_response_ack(resp))
2103 *image_addr = (resp->image_addr_low & TISCI_ADDR_LOW_MASK) |
2104 (((u64)resp->image_addr_high <<
2105 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2106 *image_size = resp->image_size;
2112 * ti_sci_cmd_get_proc_boot_status() - Command to get the processor boot status
2113 * @handle: Pointer to TI SCI handle
2114 * @proc_id: Processor ID this request is for
2116 * Return: 0 if all went well, else returns appropriate error value.
2118 static int ti_sci_cmd_get_proc_boot_status(const struct ti_sci_handle *handle,
2119 u8 proc_id, u64 *bv, u32 *cfg_flags,
2120 u32 *ctrl_flags, u32 *sts_flags)
2122 struct ti_sci_msg_resp_get_proc_boot_status *resp;
2123 struct ti_sci_msg_req_get_proc_boot_status req;
2124 struct ti_sci_info *info;
2125 struct ti_sci_xfer *xfer;
2129 return PTR_ERR(handle);
2133 info = handle_to_ti_sci_info(handle);
2135 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_GET_PROC_BOOT_STATUS,
2136 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2137 (u32 *)&req, sizeof(req), sizeof(*resp));
2139 ret = PTR_ERR(xfer);
2140 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2143 req.processor_id = proc_id;
2145 ret = ti_sci_do_xfer(info, xfer);
2147 dev_err(info->dev, "Mbox send fail %d\n", ret);
2151 resp = (struct ti_sci_msg_resp_get_proc_boot_status *)
2152 xfer->tx_message.buf;
2154 if (!ti_sci_is_response_ack(resp))
2156 *bv = (resp->bootvector_low & TISCI_ADDR_LOW_MASK) |
2157 (((u64)resp->bootvector_high <<
2158 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2159 *cfg_flags = resp->config_flags;
2160 *ctrl_flags = resp->control_flags;
2161 *sts_flags = resp->status_flags;
2167 * ti_sci_proc_wait_boot_status_no_wait() - Helper function to wait for a
2168 * processor boot status without requesting or
2169 * waiting for a response.
2170 * @proc_id: Processor ID this request is for
2171 * @num_wait_iterations: Total number of iterations we will check before
2172 * we will timeout and give up
2173 * @num_match_iterations: How many iterations should we have continued
2174 * status to account for status bits glitching.
2175 * This is to make sure that match occurs for
2176 * consecutive checks. This implies that the
2177 * worst case should consider that the stable
2178 * time should at the worst be num_wait_iterations
2179 * num_match_iterations to prevent timeout.
2180 * @delay_per_iteration_us: Specifies how long to wait (in micro seconds)
2181 * between each status checks. This is the minimum
2182 * duration, and overhead of register reads and
2183 * checks are on top of this and can vary based on
2184 * varied conditions.
2185 * @delay_before_iterations_us: Specifies how long to wait (in micro seconds)
2186 * before the very first check in the first
2187 * iteration of status check loop. This is the
2188 * minimum duration, and overhead of register
2189 * reads and checks are.
2190 * @status_flags_1_set_all_wait:If non-zero, Specifies that all bits of the
2191 * status matching this field requested MUST be 1.
2192 * @status_flags_1_set_any_wait:If non-zero, Specifies that at least one of the
2193 * bits matching this field requested MUST be 1.
2194 * @status_flags_1_clr_all_wait:If non-zero, Specifies that all bits of the
2195 * status matching this field requested MUST be 0.
2196 * @status_flags_1_clr_any_wait:If non-zero, Specifies that at least one of the
2197 * bits matching this field requested MUST be 0.
2199 * Return: 0 if all goes well, else appropriate error message
2202 ti_sci_proc_wait_boot_status_no_wait(const struct ti_sci_handle *handle,
2204 u8 num_wait_iterations,
2205 u8 num_match_iterations,
2206 u8 delay_per_iteration_us,
2207 u8 delay_before_iterations_us,
2208 u32 status_flags_1_set_all_wait,
2209 u32 status_flags_1_set_any_wait,
2210 u32 status_flags_1_clr_all_wait,
2211 u32 status_flags_1_clr_any_wait)
2213 struct ti_sci_msg_req_wait_proc_boot_status req;
2214 struct ti_sci_info *info;
2215 struct ti_sci_xfer *xfer;
2219 return PTR_ERR(handle);
2223 info = handle_to_ti_sci_info(handle);
2225 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_WAIT_PROC_BOOT_STATUS,
2226 TI_SCI_FLAG_REQ_GENERIC_NORESPONSE,
2227 (u32 *)&req, sizeof(req), 0);
2229 ret = PTR_ERR(xfer);
2230 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2233 req.processor_id = proc_id;
2234 req.num_wait_iterations = num_wait_iterations;
2235 req.num_match_iterations = num_match_iterations;
2236 req.delay_per_iteration_us = delay_per_iteration_us;
2237 req.delay_before_iterations_us = delay_before_iterations_us;
2238 req.status_flags_1_set_all_wait = status_flags_1_set_all_wait;
2239 req.status_flags_1_set_any_wait = status_flags_1_set_any_wait;
2240 req.status_flags_1_clr_all_wait = status_flags_1_clr_all_wait;
2241 req.status_flags_1_clr_any_wait = status_flags_1_clr_any_wait;
2243 ret = ti_sci_do_xfer(info, xfer);
2245 dev_err(info->dev, "Mbox send fail %d\n", ret);
2251 * ti_sci_cmd_proc_shutdown_no_wait() - Command to shutdown a core without
2252 * requesting or waiting for a response. Note that this API call
2253 * should be followed by placing the respective processor into
2254 * either WFE or WFI mode.
2255 * @handle: Pointer to TI SCI handle
2256 * @proc_id: Processor ID this request is for
2258 * Return: 0 if all went well, else returns appropriate error value.
2260 static int ti_sci_cmd_proc_shutdown_no_wait(const struct ti_sci_handle *handle,
2266 * Send the core boot status wait message waiting for either WFE or
2267 * WFI without requesting or waiting for a TISCI response with the
2268 * maximum wait time to give us the best chance to get to the WFE/WFI
2269 * command that should follow the invocation of this API before the
2270 * DMSC-internal processing of this command times out. Note that
2271 * waiting for the R5 WFE/WFI flags will also work on an ARMV8 type
2272 * core as the related flag bit positions are the same.
2274 ret = ti_sci_proc_wait_boot_status_no_wait(handle, proc_id,
2275 U8_MAX, 100, U8_MAX, U8_MAX,
2276 0, PROC_BOOT_STATUS_FLAG_R5_WFE | PROC_BOOT_STATUS_FLAG_R5_WFI,
2279 dev_err(info->dev, "Sending core %u wait message fail %d\n",
2285 * Release a processor managed by TISCI without requesting or waiting
2288 ret = ti_sci_set_device_state_no_wait(handle, proc_id, 0,
2289 MSG_DEVICE_SW_STATE_AUTO_OFF);
2291 dev_err(info->dev, "Sending core %u shutdown message fail %d\n",
2298 * ti_sci_cmd_ring_config() - configure RA ring
2299 * @handle: pointer to TI SCI handle
2300 * @valid_params: Bitfield defining validity of ring configuration parameters.
2301 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2302 * @index: Ring index.
2303 * @addr_lo: The ring base address lo 32 bits
2304 * @addr_hi: The ring base address hi 32 bits
2305 * @count: Number of ring elements.
2306 * @mode: The mode of the ring
2307 * @size: The ring element size.
2308 * @order_id: Specifies the ring's bus order ID.
2310 * Return: 0 if all went well, else returns appropriate error value.
2312 * See @ti_sci_msg_rm_ring_cfg_req for more info.
2314 static int ti_sci_cmd_ring_config(const struct ti_sci_handle *handle,
2315 u32 valid_params, u16 nav_id, u16 index,
2316 u32 addr_lo, u32 addr_hi, u32 count,
2317 u8 mode, u8 size, u8 order_id)
2319 struct ti_sci_msg_rm_ring_cfg_resp *resp;
2320 struct ti_sci_msg_rm_ring_cfg_req req;
2321 struct ti_sci_xfer *xfer;
2322 struct ti_sci_info *info;
2326 return PTR_ERR(handle);
2330 info = handle_to_ti_sci_info(handle);
2332 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_CFG,
2333 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2334 (u32 *)&req, sizeof(req), sizeof(*resp));
2336 ret = PTR_ERR(xfer);
2337 dev_err(info->dev, "RM_RA:Message config failed(%d)\n", ret);
2340 req.valid_params = valid_params;
2341 req.nav_id = nav_id;
2343 req.addr_lo = addr_lo;
2344 req.addr_hi = addr_hi;
2348 req.order_id = order_id;
2350 ret = ti_sci_do_xfer(info, xfer);
2352 dev_err(info->dev, "RM_RA:Mbox config send fail %d\n", ret);
2356 resp = (struct ti_sci_msg_rm_ring_cfg_resp *)xfer->tx_message.buf;
2358 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2361 dev_dbg(info->dev, "RM_RA:config ring %u ret:%d\n", index, ret);
2366 * ti_sci_cmd_ring_get_config() - get RA ring configuration
2367 * @handle: pointer to TI SCI handle
2368 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2369 * @index: Ring index.
2370 * @addr_lo: returns ring's base address lo 32 bits
2371 * @addr_hi: returns ring's base address hi 32 bits
2372 * @count: returns number of ring elements.
2373 * @mode: returns mode of the ring
2374 * @size: returns ring element size.
2375 * @order_id: returns ring's bus order ID.
2377 * Return: 0 if all went well, else returns appropriate error value.
2379 * See @ti_sci_msg_rm_ring_get_cfg_req for more info.
2381 static int ti_sci_cmd_ring_get_config(const struct ti_sci_handle *handle,
2382 u32 nav_id, u32 index, u8 *mode,
2383 u32 *addr_lo, u32 *addr_hi,
2384 u32 *count, u8 *size, u8 *order_id)
2386 struct ti_sci_msg_rm_ring_get_cfg_resp *resp;
2387 struct ti_sci_msg_rm_ring_get_cfg_req req;
2388 struct ti_sci_xfer *xfer;
2389 struct ti_sci_info *info;
2393 return PTR_ERR(handle);
2397 info = handle_to_ti_sci_info(handle);
2399 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_GET_CFG,
2400 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2401 (u32 *)&req, sizeof(req), sizeof(*resp));
2403 ret = PTR_ERR(xfer);
2405 "RM_RA:Message get config failed(%d)\n", ret);
2408 req.nav_id = nav_id;
2411 ret = ti_sci_do_xfer(info, xfer);
2413 dev_err(info->dev, "RM_RA:Mbox get config send fail %d\n", ret);
2417 resp = (struct ti_sci_msg_rm_ring_get_cfg_resp *)xfer->tx_message.buf;
2419 if (!ti_sci_is_response_ack(resp)) {
2425 *addr_lo = resp->addr_lo;
2427 *addr_hi = resp->addr_hi;
2429 *count = resp->count;
2433 *order_id = resp->order_id;
2437 dev_dbg(info->dev, "RM_RA:get config ring %u ret:%d\n", index, ret);
2441 static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle *handle,
2442 u32 nav_id, u32 src_thread, u32 dst_thread)
2444 struct ti_sci_msg_hdr *resp;
2445 struct ti_sci_msg_psil_pair req;
2446 struct ti_sci_xfer *xfer;
2447 struct ti_sci_info *info;
2451 return PTR_ERR(handle);
2455 info = handle_to_ti_sci_info(handle);
2457 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_PAIR,
2458 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2459 (u32 *)&req, sizeof(req), sizeof(*resp));
2461 ret = PTR_ERR(xfer);
2462 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2465 req.nav_id = nav_id;
2466 req.src_thread = src_thread;
2467 req.dst_thread = dst_thread;
2469 ret = ti_sci_do_xfer(info, xfer);
2471 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2475 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2476 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2479 dev_dbg(info->dev, "RM_PSIL: nav: %u link pair %u->%u ret:%u\n",
2480 nav_id, src_thread, dst_thread, ret);
2484 static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle *handle,
2485 u32 nav_id, u32 src_thread, u32 dst_thread)
2487 struct ti_sci_msg_hdr *resp;
2488 struct ti_sci_msg_psil_unpair req;
2489 struct ti_sci_xfer *xfer;
2490 struct ti_sci_info *info;
2494 return PTR_ERR(handle);
2498 info = handle_to_ti_sci_info(handle);
2500 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_UNPAIR,
2501 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2502 (u32 *)&req, sizeof(req), sizeof(*resp));
2504 ret = PTR_ERR(xfer);
2505 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2508 req.nav_id = nav_id;
2509 req.src_thread = src_thread;
2510 req.dst_thread = dst_thread;
2512 ret = ti_sci_do_xfer(info, xfer);
2514 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2518 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2519 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2522 dev_dbg(info->dev, "RM_PSIL: link unpair %u->%u ret:%u\n",
2523 src_thread, dst_thread, ret);
2527 static int ti_sci_cmd_rm_udmap_tx_ch_cfg(
2528 const struct ti_sci_handle *handle,
2529 const struct ti_sci_msg_rm_udmap_tx_ch_cfg *params)
2531 struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *resp;
2532 struct ti_sci_msg_rm_udmap_tx_ch_cfg_req req;
2533 struct ti_sci_xfer *xfer;
2534 struct ti_sci_info *info;
2538 return PTR_ERR(handle);
2542 info = handle_to_ti_sci_info(handle);
2544 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_TX_CH_CFG,
2545 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2546 (u32 *)&req, sizeof(req), sizeof(*resp));
2548 ret = PTR_ERR(xfer);
2549 dev_err(info->dev, "Message TX_CH_CFG alloc failed(%d)\n", ret);
2552 req.valid_params = params->valid_params;
2553 req.nav_id = params->nav_id;
2554 req.index = params->index;
2555 req.tx_pause_on_err = params->tx_pause_on_err;
2556 req.tx_filt_einfo = params->tx_filt_einfo;
2557 req.tx_filt_pswords = params->tx_filt_pswords;
2558 req.tx_atype = params->tx_atype;
2559 req.tx_chan_type = params->tx_chan_type;
2560 req.tx_supr_tdpkt = params->tx_supr_tdpkt;
2561 req.tx_fetch_size = params->tx_fetch_size;
2562 req.tx_credit_count = params->tx_credit_count;
2563 req.txcq_qnum = params->txcq_qnum;
2564 req.tx_priority = params->tx_priority;
2565 req.tx_qos = params->tx_qos;
2566 req.tx_orderid = params->tx_orderid;
2567 req.fdepth = params->fdepth;
2568 req.tx_sched_priority = params->tx_sched_priority;
2570 ret = ti_sci_do_xfer(info, xfer);
2572 dev_err(info->dev, "Mbox send TX_CH_CFG fail %d\n", ret);
2577 (struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *)xfer->tx_message.buf;
2578 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2581 dev_dbg(info->dev, "TX_CH_CFG: chn %u ret:%u\n", params->index, ret);
2585 static int ti_sci_cmd_rm_udmap_rx_ch_cfg(
2586 const struct ti_sci_handle *handle,
2587 const struct ti_sci_msg_rm_udmap_rx_ch_cfg *params)
2589 struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *resp;
2590 struct ti_sci_msg_rm_udmap_rx_ch_cfg_req req;
2591 struct ti_sci_xfer *xfer;
2592 struct ti_sci_info *info;
2596 return PTR_ERR(handle);
2600 info = handle_to_ti_sci_info(handle);
2602 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_RX_CH_CFG,
2603 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2604 (u32 *)&req, sizeof(req), sizeof(*resp));
2606 ret = PTR_ERR(xfer);
2607 dev_err(info->dev, "Message RX_CH_CFG alloc failed(%d)\n", ret);
2611 req.valid_params = params->valid_params;
2612 req.nav_id = params->nav_id;
2613 req.index = params->index;
2614 req.rx_fetch_size = params->rx_fetch_size;
2615 req.rxcq_qnum = params->rxcq_qnum;
2616 req.rx_priority = params->rx_priority;
2617 req.rx_qos = params->rx_qos;
2618 req.rx_orderid = params->rx_orderid;
2619 req.rx_sched_priority = params->rx_sched_priority;
2620 req.flowid_start = params->flowid_start;
2621 req.flowid_cnt = params->flowid_cnt;
2622 req.rx_pause_on_err = params->rx_pause_on_err;
2623 req.rx_atype = params->rx_atype;
2624 req.rx_chan_type = params->rx_chan_type;
2625 req.rx_ignore_short = params->rx_ignore_short;
2626 req.rx_ignore_long = params->rx_ignore_long;
2628 ret = ti_sci_do_xfer(info, xfer);
2630 dev_err(info->dev, "Mbox send RX_CH_CFG fail %d\n", ret);
2635 (struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *)xfer->tx_message.buf;
2636 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2639 dev_dbg(info->dev, "RX_CH_CFG: chn %u ret:%d\n", params->index, ret);
2643 static int ti_sci_cmd_rm_udmap_rx_flow_cfg(
2644 const struct ti_sci_handle *handle,
2645 const struct ti_sci_msg_rm_udmap_flow_cfg *params)
2647 struct ti_sci_msg_rm_udmap_flow_cfg_resp *resp;
2648 struct ti_sci_msg_rm_udmap_flow_cfg_req req;
2649 struct ti_sci_xfer *xfer;
2650 struct ti_sci_info *info;
2654 return PTR_ERR(handle);
2658 info = handle_to_ti_sci_info(handle);
2660 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_FLOW_CFG,
2661 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2662 (u32 *)&req, sizeof(req), sizeof(*resp));
2664 ret = PTR_ERR(xfer);
2665 dev_err(dev, "RX_FL_CFG: Message alloc failed(%d)\n", ret);
2669 req.valid_params = params->valid_params;
2670 req.nav_id = params->nav_id;
2671 req.flow_index = params->flow_index;
2672 req.rx_einfo_present = params->rx_einfo_present;
2673 req.rx_psinfo_present = params->rx_psinfo_present;
2674 req.rx_error_handling = params->rx_error_handling;
2675 req.rx_desc_type = params->rx_desc_type;
2676 req.rx_sop_offset = params->rx_sop_offset;
2677 req.rx_dest_qnum = params->rx_dest_qnum;
2678 req.rx_src_tag_hi = params->rx_src_tag_hi;
2679 req.rx_src_tag_lo = params->rx_src_tag_lo;
2680 req.rx_dest_tag_hi = params->rx_dest_tag_hi;
2681 req.rx_dest_tag_lo = params->rx_dest_tag_lo;
2682 req.rx_src_tag_hi_sel = params->rx_src_tag_hi_sel;
2683 req.rx_src_tag_lo_sel = params->rx_src_tag_lo_sel;
2684 req.rx_dest_tag_hi_sel = params->rx_dest_tag_hi_sel;
2685 req.rx_dest_tag_lo_sel = params->rx_dest_tag_lo_sel;
2686 req.rx_fdq0_sz0_qnum = params->rx_fdq0_sz0_qnum;
2687 req.rx_fdq1_qnum = params->rx_fdq1_qnum;
2688 req.rx_fdq2_qnum = params->rx_fdq2_qnum;
2689 req.rx_fdq3_qnum = params->rx_fdq3_qnum;
2690 req.rx_ps_location = params->rx_ps_location;
2692 ret = ti_sci_do_xfer(info, xfer);
2694 dev_err(dev, "RX_FL_CFG: Mbox send fail %d\n", ret);
2699 (struct ti_sci_msg_rm_udmap_flow_cfg_resp *)xfer->tx_message.buf;
2700 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2703 dev_dbg(info->dev, "RX_FL_CFG: %u ret:%d\n", params->flow_index, ret);
2708 * ti_sci_cmd_set_fwl_region() - Request for configuring a firewall region
2709 * @handle: pointer to TI SCI handle
2710 * @region: region configuration parameters
2712 * Return: 0 if all went well, else returns appropriate error value.
2714 static int ti_sci_cmd_set_fwl_region(const struct ti_sci_handle *handle,
2715 const struct ti_sci_msg_fwl_region *region)
2717 struct ti_sci_msg_fwl_set_firewall_region_req req;
2718 struct ti_sci_msg_hdr *resp;
2719 struct ti_sci_info *info;
2720 struct ti_sci_xfer *xfer;
2724 return PTR_ERR(handle);
2728 info = handle_to_ti_sci_info(handle);
2730 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_SET,
2731 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2732 (u32 *)&req, sizeof(req), sizeof(*resp));
2734 ret = PTR_ERR(xfer);
2735 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2739 req.fwl_id = region->fwl_id;
2740 req.region = region->region;
2741 req.n_permission_regs = region->n_permission_regs;
2742 req.control = region->control;
2743 req.permissions[0] = region->permissions[0];
2744 req.permissions[1] = region->permissions[1];
2745 req.permissions[2] = region->permissions[2];
2746 req.start_address = region->start_address;
2747 req.end_address = region->end_address;
2749 ret = ti_sci_do_xfer(info, xfer);
2751 dev_err(info->dev, "Mbox send fail %d\n", ret);
2755 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2757 if (!ti_sci_is_response_ack(resp))
2764 * ti_sci_cmd_get_fwl_region() - Request for getting a firewall region
2765 * @handle: pointer to TI SCI handle
2766 * @region: region configuration parameters
2768 * Return: 0 if all went well, else returns appropriate error value.
2770 static int ti_sci_cmd_get_fwl_region(const struct ti_sci_handle *handle,
2771 struct ti_sci_msg_fwl_region *region)
2773 struct ti_sci_msg_fwl_get_firewall_region_req req;
2774 struct ti_sci_msg_fwl_get_firewall_region_resp *resp;
2775 struct ti_sci_info *info;
2776 struct ti_sci_xfer *xfer;
2780 return PTR_ERR(handle);
2784 info = handle_to_ti_sci_info(handle);
2786 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_GET,
2787 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2788 (u32 *)&req, sizeof(req), sizeof(*resp));
2790 ret = PTR_ERR(xfer);
2791 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2795 req.fwl_id = region->fwl_id;
2796 req.region = region->region;
2797 req.n_permission_regs = region->n_permission_regs;
2799 ret = ti_sci_do_xfer(info, xfer);
2801 dev_err(info->dev, "Mbox send fail %d\n", ret);
2805 resp = (struct ti_sci_msg_fwl_get_firewall_region_resp *)xfer->tx_message.buf;
2807 if (!ti_sci_is_response_ack(resp))
2810 region->fwl_id = resp->fwl_id;
2811 region->region = resp->region;
2812 region->n_permission_regs = resp->n_permission_regs;
2813 region->control = resp->control;
2814 region->permissions[0] = resp->permissions[0];
2815 region->permissions[1] = resp->permissions[1];
2816 region->permissions[2] = resp->permissions[2];
2817 region->start_address = resp->start_address;
2818 region->end_address = resp->end_address;
2824 * ti_sci_cmd_change_fwl_owner() - Request for changing a firewall owner
2825 * @handle: pointer to TI SCI handle
2826 * @region: region configuration parameters
2828 * Return: 0 if all went well, else returns appropriate error value.
2830 static int ti_sci_cmd_change_fwl_owner(const struct ti_sci_handle *handle,
2831 struct ti_sci_msg_fwl_owner *owner)
2833 struct ti_sci_msg_fwl_change_owner_info_req req;
2834 struct ti_sci_msg_fwl_change_owner_info_resp *resp;
2835 struct ti_sci_info *info;
2836 struct ti_sci_xfer *xfer;
2840 return PTR_ERR(handle);
2844 info = handle_to_ti_sci_info(handle);
2846 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_CHANGE_OWNER,
2847 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2848 (u32 *)&req, sizeof(req), sizeof(*resp));
2850 ret = PTR_ERR(xfer);
2851 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2855 req.fwl_id = owner->fwl_id;
2856 req.region = owner->region;
2857 req.owner_index = owner->owner_index;
2859 ret = ti_sci_do_xfer(info, xfer);
2861 dev_err(info->dev, "Mbox send fail %d\n", ret);
2865 resp = (struct ti_sci_msg_fwl_change_owner_info_resp *)xfer->tx_message.buf;
2867 if (!ti_sci_is_response_ack(resp))
2870 owner->fwl_id = resp->fwl_id;
2871 owner->region = resp->region;
2872 owner->owner_index = resp->owner_index;
2873 owner->owner_privid = resp->owner_privid;
2874 owner->owner_permission_bits = resp->owner_permission_bits;
2880 * ti_sci_setup_ops() - Setup the operations structures
2881 * @info: pointer to TISCI pointer
2883 static void ti_sci_setup_ops(struct ti_sci_info *info)
2885 struct ti_sci_ops *ops = &info->handle.ops;
2886 struct ti_sci_board_ops *bops = &ops->board_ops;
2887 struct ti_sci_dev_ops *dops = &ops->dev_ops;
2888 struct ti_sci_clk_ops *cops = &ops->clk_ops;
2889 struct ti_sci_core_ops *core_ops = &ops->core_ops;
2890 struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
2891 struct ti_sci_proc_ops *pops = &ops->proc_ops;
2892 struct ti_sci_rm_ringacc_ops *rops = &ops->rm_ring_ops;
2893 struct ti_sci_rm_psil_ops *psilops = &ops->rm_psil_ops;
2894 struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops;
2895 struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops;
2897 bops->board_config = ti_sci_cmd_set_board_config;
2898 bops->board_config_rm = ti_sci_cmd_set_board_config_rm;
2899 bops->board_config_security = ti_sci_cmd_set_board_config_security;
2900 bops->board_config_pm = ti_sci_cmd_set_board_config_pm;
2902 dops->get_device = ti_sci_cmd_get_device;
2903 dops->get_device_exclusive = ti_sci_cmd_get_device_exclusive;
2904 dops->idle_device = ti_sci_cmd_idle_device;
2905 dops->idle_device_exclusive = ti_sci_cmd_idle_device_exclusive;
2906 dops->put_device = ti_sci_cmd_put_device;
2907 dops->is_valid = ti_sci_cmd_dev_is_valid;
2908 dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt;
2909 dops->is_idle = ti_sci_cmd_dev_is_idle;
2910 dops->is_stop = ti_sci_cmd_dev_is_stop;
2911 dops->is_on = ti_sci_cmd_dev_is_on;
2912 dops->is_transitioning = ti_sci_cmd_dev_is_trans;
2913 dops->set_device_resets = ti_sci_cmd_set_device_resets;
2914 dops->get_device_resets = ti_sci_cmd_get_device_resets;
2915 dops->release_exclusive_devices = ti_sci_cmd_release_exclusive_devices;
2917 cops->get_clock = ti_sci_cmd_get_clock;
2918 cops->idle_clock = ti_sci_cmd_idle_clock;
2919 cops->put_clock = ti_sci_cmd_put_clock;
2920 cops->is_auto = ti_sci_cmd_clk_is_auto;
2921 cops->is_on = ti_sci_cmd_clk_is_on;
2922 cops->is_off = ti_sci_cmd_clk_is_off;
2924 cops->set_parent = ti_sci_cmd_clk_set_parent;
2925 cops->get_parent = ti_sci_cmd_clk_get_parent;
2926 cops->get_num_parents = ti_sci_cmd_clk_get_num_parents;
2928 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;
2929 cops->set_freq = ti_sci_cmd_clk_set_freq;
2930 cops->get_freq = ti_sci_cmd_clk_get_freq;
2932 core_ops->reboot_device = ti_sci_cmd_core_reboot;
2933 core_ops->query_msmc = ti_sci_cmd_query_msmc;
2935 rm_core_ops->get_range = ti_sci_cmd_get_resource_range;
2936 rm_core_ops->get_range_from_shost =
2937 ti_sci_cmd_get_resource_range_from_shost;
2939 pops->proc_request = ti_sci_cmd_proc_request;
2940 pops->proc_release = ti_sci_cmd_proc_release;
2941 pops->proc_handover = ti_sci_cmd_proc_handover;
2942 pops->set_proc_boot_cfg = ti_sci_cmd_set_proc_boot_cfg;
2943 pops->set_proc_boot_ctrl = ti_sci_cmd_set_proc_boot_ctrl;
2944 pops->proc_auth_boot_image = ti_sci_cmd_proc_auth_boot_image;
2945 pops->get_proc_boot_status = ti_sci_cmd_get_proc_boot_status;
2946 pops->proc_shutdown_no_wait = ti_sci_cmd_proc_shutdown_no_wait;
2948 rops->config = ti_sci_cmd_ring_config;
2949 rops->get_config = ti_sci_cmd_ring_get_config;
2951 psilops->pair = ti_sci_cmd_rm_psil_pair;
2952 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
2954 udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg;
2955 udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg;
2956 udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg;
2958 fwl_ops->set_fwl_region = ti_sci_cmd_set_fwl_region;
2959 fwl_ops->get_fwl_region = ti_sci_cmd_get_fwl_region;
2960 fwl_ops->change_fwl_owner = ti_sci_cmd_change_fwl_owner;
2964 * ti_sci_get_handle_from_sysfw() - Get the TI SCI handle of the SYSFW
2965 * @dev: Pointer to the SYSFW device
2967 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2971 struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *sci_dev)
2974 return ERR_PTR(-EINVAL);
2976 struct ti_sci_info *info = dev_get_priv(sci_dev);
2979 return ERR_PTR(-EINVAL);
2981 struct ti_sci_handle *handle = &info->handle;
2984 return ERR_PTR(-EINVAL);
2990 * ti_sci_get_handle() - Get the TI SCI handle for a device
2991 * @dev: Pointer to device for which we want SCI handle
2993 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2996 const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
2999 return ERR_PTR(-EINVAL);
3001 struct udevice *sci_dev = dev_get_parent(dev);
3003 return ti_sci_get_handle_from_sysfw(sci_dev);
3007 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
3009 * @propname: property name containing phandle on TISCI node
3011 * Return: pointer to handle if successful, else appropriate error value.
3013 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
3014 const char *property)
3016 struct ti_sci_info *entry, *info = NULL;
3020 err = ofnode_read_u32(dev_ofnode(dev), property, &phandle);
3022 return ERR_PTR(err);
3024 node = ofnode_get_by_phandle(phandle);
3025 if (!ofnode_valid(node))
3026 return ERR_PTR(-EINVAL);
3028 list_for_each_entry(entry, &ti_sci_list, list)
3029 if (ofnode_equal(dev_ofnode(entry->dev), node)) {
3035 return ERR_PTR(-ENODEV);
3037 return &info->handle;
3041 * ti_sci_of_to_info() - generate private data from device tree
3042 * @dev: corresponding system controller interface device
3043 * @info: pointer to driver specific private data
3045 * Return: 0 if all goes good, else appropriate error message.
3047 static int ti_sci_of_to_info(struct udevice *dev, struct ti_sci_info *info)
3051 ret = mbox_get_by_name(dev, "tx", &info->chan_tx);
3053 dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n",
3058 ret = mbox_get_by_name(dev, "rx", &info->chan_rx);
3060 dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n",
3065 /* Notify channel is optional. Enable only if populated */
3066 ret = mbox_get_by_name(dev, "notify", &info->chan_notify);
3068 dev_dbg(dev, "%s: Acquiring notify channel failed. ret = %d\n",
3072 info->host_id = dev_read_u32_default(dev, "ti,host-id",
3073 info->desc->default_host_id);
3075 info->is_secure = dev_read_bool(dev, "ti,secure-host");
3081 * ti_sci_probe() - Basic probe
3082 * @dev: corresponding system controller interface device
3084 * Return: 0 if all goes good, else appropriate error message.
3086 static int ti_sci_probe(struct udevice *dev)
3088 struct ti_sci_info *info;
3091 debug("%s(dev=%p)\n", __func__, dev);
3093 info = dev_get_priv(dev);
3094 info->desc = (void *)dev_get_driver_data(dev);
3096 ret = ti_sci_of_to_info(dev, info);
3098 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
3105 list_add_tail(&info->list, &ti_sci_list);
3106 ti_sci_setup_ops(info);
3108 ret = ti_sci_cmd_get_revision(&info->handle);
3110 INIT_LIST_HEAD(&info->dev_list);
3116 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
3117 * @res: Pointer to the TISCI resource
3119 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
3121 u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
3125 for (set = 0; set < res->sets; set++) {
3126 free_bit = find_first_zero_bit(res->desc[set].res_map,
3127 res->desc[set].num);
3128 if (free_bit != res->desc[set].num) {
3129 set_bit(free_bit, res->desc[set].res_map);
3130 return res->desc[set].start + free_bit;
3134 return TI_SCI_RESOURCE_NULL;
3138 * ti_sci_release_resource() - Release a resource from TISCI resource.
3139 * @res: Pointer to the TISCI resource
3141 void ti_sci_release_resource(struct ti_sci_resource *res, u16 id)
3145 for (set = 0; set < res->sets; set++) {
3146 if (res->desc[set].start <= id &&
3147 (res->desc[set].num + res->desc[set].start) > id)
3148 clear_bit(id - res->desc[set].start,
3149 res->desc[set].res_map);
3154 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
3155 * @handle: TISCI handle
3156 * @dev: Device pointer to which the resource is assigned
3157 * @of_prop: property name by which the resource are represented
3159 * Note: This function expects of_prop to be in the form of tuples
3160 * <type, subtype>. Allocates and initializes ti_sci_resource structure
3161 * for each of_prop. Client driver can directly call
3162 * ti_sci_(get_free, release)_resource apis for handling the resource.
3164 * Return: Pointer to ti_sci_resource if all went well else appropriate
3167 struct ti_sci_resource *
3168 devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
3169 struct udevice *dev, u32 dev_id, char *of_prop)
3171 u32 resource_subtype;
3173 struct ti_sci_resource *res;
3174 bool valid_set = false;
3178 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
3180 return ERR_PTR(-ENOMEM);
3182 sets = dev_read_size(dev, of_prop);
3184 dev_err(dev, "%s resource type ids not available\n", of_prop);
3185 return ERR_PTR(sets);
3187 temp = malloc(sets);
3188 sets /= sizeof(u32);
3191 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
3194 return ERR_PTR(-ENOMEM);
3196 ret = ti_sci_get_resource_type(handle_to_ti_sci_info(handle), dev_id,
3199 dev_err(dev, "No valid resource type for %u\n", dev_id);
3200 return ERR_PTR(-EINVAL);
3203 ret = dev_read_u32_array(dev, of_prop, temp, res->sets);
3205 return ERR_PTR(-EINVAL);
3207 for (i = 0; i < res->sets; i++) {
3208 resource_subtype = temp[i];
3209 ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
3211 &res->desc[i].start,
3214 dev_dbg(dev, "type %d subtype %d not allocated for host %d\n",
3215 resource_type, resource_subtype,
3216 handle_to_ti_sci_info(handle)->host_id);
3217 res->desc[i].start = 0;
3218 res->desc[i].num = 0;
3223 dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n",
3224 resource_type, resource_subtype, res->desc[i].start,
3227 res->desc[i].res_map =
3228 devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) *
3229 sizeof(*res->desc[i].res_map), GFP_KERNEL);
3230 if (!res->desc[i].res_map)
3231 return ERR_PTR(-ENOMEM);
3237 return ERR_PTR(-EINVAL);
3240 /* Description for K2G */
3241 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = {
3242 .default_host_id = 2,
3243 /* Conservative duration */
3244 .max_rx_timeout_ms = 10000,
3245 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3248 .rm_type_map = NULL,
3251 static struct ti_sci_rm_type_map ti_sci_am654_rm_type_map[] = {
3252 {.dev_id = 56, .type = 0x00b}, /* GIC_IRQ */
3253 {.dev_id = 179, .type = 0x000}, /* MAIN_NAV_UDMASS_IA0 */
3254 {.dev_id = 187, .type = 0x009}, /* MAIN_NAV_RA */
3255 {.dev_id = 188, .type = 0x006}, /* MAIN_NAV_UDMAP */
3256 {.dev_id = 194, .type = 0x007}, /* MCU_NAV_UDMAP */
3257 {.dev_id = 195, .type = 0x00a}, /* MCU_NAV_RA */
3258 {.dev_id = 0, .type = 0x000}, /* end of table */
3261 /* Description for AM654 */
3262 static const struct ti_sci_desc ti_sci_pmmc_am654_desc = {
3263 .default_host_id = 12,
3264 /* Conservative duration */
3265 .max_rx_timeout_ms = 10000,
3266 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3269 .rm_type_map = ti_sci_am654_rm_type_map,
3272 static const struct udevice_id ti_sci_ids[] = {
3274 .compatible = "ti,k2g-sci",
3275 .data = (ulong)&ti_sci_pmmc_k2g_desc
3278 .compatible = "ti,am654-sci",
3279 .data = (ulong)&ti_sci_pmmc_am654_desc
3284 U_BOOT_DRIVER(ti_sci) = {
3286 .id = UCLASS_FIRMWARE,
3287 .of_match = ti_sci_ids,
3288 .probe = ti_sci_probe,
3289 .priv_auto_alloc_size = sizeof(struct ti_sci_info),