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 <linux/compat.h>
16 #include <linux/err.h>
17 #include <linux/soc/ti/k3-sec-proxy.h>
18 #include <linux/soc/ti/ti_sci_protocol.h>
22 /* List of all TI SCI devices active in system */
23 static LIST_HEAD(ti_sci_list);
26 * struct ti_sci_xfer - Structure representing a message flow
27 * @tx_message: Transmit message
28 * @rx_len: Receive message length
31 struct k3_sec_proxy_msg tx_message;
36 * struct ti_sci_rm_type_map - Structure representing TISCI Resource
37 * management representation of dev_ids.
38 * @dev_id: TISCI device ID
39 * @type: Corresponding id as identified by TISCI RM.
41 * Note: This is used only as a work around for using RM range apis
42 * for AM654 SoC. For future SoCs dev_id will be used as type
43 * for RM range APIs. In order to maintain ABI backward compatibility
44 * type is not being changed for AM654 SoC.
46 struct ti_sci_rm_type_map {
52 * struct ti_sci_desc - Description of SoC integration
53 * @default_host_id: Host identifier representing the compute entity
54 * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
55 * @max_msgs: Maximum number of messages that can be pending
56 * simultaneously in the system
57 * @max_msg_size: Maximum size of data per message that can be handled.
58 * @rm_type_map: RM resource type mapping structure.
62 int max_rx_timeout_ms;
65 struct ti_sci_rm_type_map *rm_type_map;
69 * struct ti_sci_info - Structure representing a TI SCI instance
70 * @dev: Device pointer
71 * @desc: SoC description for this instance
72 * @handle: Instance of TI SCI handle to send to clients.
73 * @chan_tx: Transmit mailbox channel
74 * @chan_rx: Receive mailbox channel
77 * @is_secure: Determines if the communication is through secure threads.
78 * @host_id: Host identifier representing the compute entity
79 * @seq: Seq id used for verification for tx and rx message.
83 const struct ti_sci_desc *desc;
84 struct ti_sci_handle handle;
85 struct mbox_chan chan_tx;
86 struct mbox_chan chan_rx;
87 struct mbox_chan chan_notify;
88 struct ti_sci_xfer xfer;
89 struct list_head list;
95 #define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle)
98 * ti_sci_setup_one_xfer() - Setup one message type
99 * @info: Pointer to SCI entity information
100 * @msg_type: Message type
101 * @msg_flags: Flag to set for the message
102 * @buf: Buffer to be send to mailbox channel
103 * @tx_message_size: transmit message size
104 * @rx_message_size: receive message size
106 * Helper function which is used by various command functions that are
107 * exposed to clients of this driver for allocating a message traffic event.
109 * Return: Corresponding ti_sci_xfer pointer if all went fine,
110 * else appropriate error pointer.
112 static struct ti_sci_xfer *ti_sci_setup_one_xfer(struct ti_sci_info *info,
113 u16 msg_type, u32 msg_flags,
115 size_t tx_message_size,
116 size_t rx_message_size)
118 struct ti_sci_xfer *xfer = &info->xfer;
119 struct ti_sci_msg_hdr *hdr;
121 /* Ensure we have sane transfer sizes */
122 if (rx_message_size > info->desc->max_msg_size ||
123 tx_message_size > info->desc->max_msg_size ||
124 rx_message_size < sizeof(*hdr) || tx_message_size < sizeof(*hdr))
125 return ERR_PTR(-ERANGE);
127 info->seq = ~info->seq;
128 xfer->tx_message.buf = buf;
129 xfer->tx_message.len = tx_message_size;
130 xfer->rx_len = (u8)rx_message_size;
132 hdr = (struct ti_sci_msg_hdr *)buf;
133 hdr->seq = info->seq;
134 hdr->type = msg_type;
135 hdr->host = info->host_id;
136 hdr->flags = msg_flags;
142 * ti_sci_get_response() - Receive response from mailbox channel
143 * @info: Pointer to SCI entity information
144 * @xfer: Transfer to initiate and wait for response
145 * @chan: Channel to receive the response
147 * Return: -ETIMEDOUT in case of no response, if transmit error,
148 * return corresponding error, else if all goes well,
151 static inline int ti_sci_get_response(struct ti_sci_info *info,
152 struct ti_sci_xfer *xfer,
153 struct mbox_chan *chan)
155 struct k3_sec_proxy_msg *msg = &xfer->tx_message;
156 struct ti_sci_secure_msg_hdr *secure_hdr;
157 struct ti_sci_msg_hdr *hdr;
160 /* Receive the response */
161 ret = mbox_recv(chan, msg, info->desc->max_rx_timeout_ms);
163 dev_err(info->dev, "%s: Message receive failed. ret = %d\n",
168 /* ToDo: Verify checksum */
169 if (info->is_secure) {
170 secure_hdr = (struct ti_sci_secure_msg_hdr *)msg->buf;
171 msg->buf = (u32 *)((void *)msg->buf + sizeof(*secure_hdr));
174 /* msg is updated by mailbox driver */
175 hdr = (struct ti_sci_msg_hdr *)msg->buf;
177 /* Sanity check for message response */
178 if (hdr->seq != info->seq) {
179 dev_dbg(info->dev, "%s: Message for %d is not expected\n",
184 if (msg->len > info->desc->max_msg_size) {
185 dev_err(info->dev, "%s: Unable to handle %zu xfer (max %d)\n",
186 __func__, msg->len, info->desc->max_msg_size);
190 if (msg->len < xfer->rx_len) {
191 dev_err(info->dev, "%s: Recv xfer %zu < expected %d length\n",
192 __func__, msg->len, xfer->rx_len);
199 * ti_sci_do_xfer() - Do one transfer
200 * @info: Pointer to SCI entity information
201 * @xfer: Transfer to initiate and wait for response
203 * Return: 0 if all went fine, else return appropriate error.
205 static inline int ti_sci_do_xfer(struct ti_sci_info *info,
206 struct ti_sci_xfer *xfer)
208 struct k3_sec_proxy_msg *msg = &xfer->tx_message;
209 u8 secure_buf[info->desc->max_msg_size];
210 struct ti_sci_secure_msg_hdr secure_hdr;
213 if (info->is_secure) {
214 /* ToDo: get checksum of the entire message */
215 secure_hdr.checksum = 0;
216 secure_hdr.reserved = 0;
217 memcpy(&secure_buf[sizeof(secure_hdr)], xfer->tx_message.buf,
218 xfer->tx_message.len);
220 xfer->tx_message.buf = (u32 *)secure_buf;
221 xfer->tx_message.len += sizeof(secure_hdr);
222 xfer->rx_len += sizeof(secure_hdr);
225 /* Send the message */
226 ret = mbox_send(&info->chan_tx, msg);
228 dev_err(info->dev, "%s: Message sending failed. ret = %d\n",
233 return ti_sci_get_response(info, xfer, &info->chan_rx);
237 * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity
238 * @handle: pointer to TI SCI handle
240 * Updates the SCI information in the internal data structure.
242 * Return: 0 if all went fine, else return appropriate error.
244 static int ti_sci_cmd_get_revision(struct ti_sci_handle *handle)
246 struct ti_sci_msg_resp_version *rev_info;
247 struct ti_sci_version_info *ver;
248 struct ti_sci_msg_hdr hdr;
249 struct ti_sci_info *info;
250 struct ti_sci_xfer *xfer;
254 return PTR_ERR(handle);
258 info = handle_to_ti_sci_info(handle);
260 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_VERSION, 0x0,
261 (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr),
265 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
269 ret = ti_sci_do_xfer(info, xfer);
271 dev_err(info->dev, "Mbox communication fail %d\n", ret);
275 rev_info = (struct ti_sci_msg_resp_version *)xfer->tx_message.buf;
277 ver = &handle->version;
278 ver->abi_major = rev_info->abi_major;
279 ver->abi_minor = rev_info->abi_minor;
280 ver->firmware_revision = rev_info->firmware_revision;
281 strncpy(ver->firmware_description, rev_info->firmware_description,
282 sizeof(ver->firmware_description));
288 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
289 * @r: pointer to response buffer
291 * Return: true if the response was an ACK, else returns false.
293 static inline bool ti_sci_is_response_ack(void *r)
295 struct ti_sci_msg_hdr *hdr = r;
297 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false;
301 * cmd_set_board_config_using_msg() - Common command to send board configuration
303 * @handle: pointer to TI SCI handle
304 * @msg_type: One of the TISCI message types to set board configuration
305 * @addr: Address where the board config structure is located
306 * @size: Size of the board config structure
308 * Return: 0 if all went well, else returns appropriate error value.
310 static int cmd_set_board_config_using_msg(const struct ti_sci_handle *handle,
311 u16 msg_type, u64 addr, u32 size)
313 struct ti_sci_msg_board_config req;
314 struct ti_sci_msg_hdr *resp;
315 struct ti_sci_info *info;
316 struct ti_sci_xfer *xfer;
320 return PTR_ERR(handle);
324 info = handle_to_ti_sci_info(handle);
326 xfer = ti_sci_setup_one_xfer(info, msg_type,
327 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
328 (u32 *)&req, sizeof(req), sizeof(*resp));
331 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
334 req.boardcfgp_high = (addr >> 32) & 0xffffffff;
335 req.boardcfgp_low = addr & 0xffffffff;
336 req.boardcfg_size = size;
338 ret = ti_sci_do_xfer(info, xfer);
340 dev_err(info->dev, "Mbox send fail %d\n", ret);
344 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
346 if (!ti_sci_is_response_ack(resp))
353 * ti_sci_cmd_set_board_config() - Command to send board configuration message
354 * @handle: pointer to TI SCI handle
355 * @addr: Address where the board config structure is located
356 * @size: Size of the board config structure
358 * Return: 0 if all went well, else returns appropriate error value.
360 static int ti_sci_cmd_set_board_config(const struct ti_sci_handle *handle,
363 return cmd_set_board_config_using_msg(handle,
364 TI_SCI_MSG_BOARD_CONFIG,
369 * ti_sci_cmd_set_board_config_rm() - Command to send board resource
370 * management configuration
371 * @handle: pointer to TI SCI handle
372 * @addr: Address where the board RM config structure is located
373 * @size: Size of the RM config structure
375 * Return: 0 if all went well, else returns appropriate error value.
378 int ti_sci_cmd_set_board_config_rm(const struct ti_sci_handle *handle,
381 return cmd_set_board_config_using_msg(handle,
382 TI_SCI_MSG_BOARD_CONFIG_RM,
387 * ti_sci_cmd_set_board_config_security() - Command to send board security
388 * configuration message
389 * @handle: pointer to TI SCI handle
390 * @addr: Address where the board security config structure is located
391 * @size: Size of the security config structure
393 * Return: 0 if all went well, else returns appropriate error value.
396 int ti_sci_cmd_set_board_config_security(const struct ti_sci_handle *handle,
399 return cmd_set_board_config_using_msg(handle,
400 TI_SCI_MSG_BOARD_CONFIG_SECURITY,
405 * ti_sci_cmd_set_board_config_pm() - Command to send board power and clock
406 * configuration message
407 * @handle: pointer to TI SCI handle
408 * @addr: Address where the board PM config structure is located
409 * @size: Size of the PM config structure
411 * Return: 0 if all went well, else returns appropriate error value.
413 static int ti_sci_cmd_set_board_config_pm(const struct ti_sci_handle *handle,
416 return cmd_set_board_config_using_msg(handle,
417 TI_SCI_MSG_BOARD_CONFIG_PM,
422 * ti_sci_set_device_state() - Set device state helper
423 * @handle: pointer to TI SCI handle
424 * @id: Device identifier
425 * @flags: flags to setup for the device
426 * @state: State to move the device to
428 * Return: 0 if all went well, else returns appropriate error value.
430 static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
431 u32 id, u32 flags, u8 state)
433 struct ti_sci_msg_req_set_device_state req;
434 struct ti_sci_msg_hdr *resp;
435 struct ti_sci_info *info;
436 struct ti_sci_xfer *xfer;
440 return PTR_ERR(handle);
444 info = handle_to_ti_sci_info(handle);
446 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
447 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
448 (u32 *)&req, sizeof(req), sizeof(*resp));
451 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
457 ret = ti_sci_do_xfer(info, xfer);
459 dev_err(info->dev, "Mbox send fail %d\n", ret);
463 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
465 if (!ti_sci_is_response_ack(resp))
472 * ti_sci_get_device_state() - Get device state helper
473 * @handle: Handle to the device
474 * @id: Device Identifier
475 * @clcnt: Pointer to Context Loss Count
476 * @resets: pointer to resets
477 * @p_state: pointer to p_state
478 * @c_state: pointer to c_state
480 * Return: 0 if all went fine, else return appropriate error.
482 static int ti_sci_get_device_state(const struct ti_sci_handle *handle,
483 u32 id, u32 *clcnt, u32 *resets,
484 u8 *p_state, u8 *c_state)
486 struct ti_sci_msg_resp_get_device_state *resp;
487 struct ti_sci_msg_req_get_device_state req;
488 struct ti_sci_info *info;
489 struct ti_sci_xfer *xfer;
493 return PTR_ERR(handle);
497 if (!clcnt && !resets && !p_state && !c_state)
500 info = handle_to_ti_sci_info(handle);
502 /* Response is expected, so need of any flags */
503 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_DEVICE_STATE, 0,
504 (u32 *)&req, sizeof(req), sizeof(*resp));
507 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
512 ret = ti_sci_do_xfer(info, xfer);
514 dev_err(dev, "Mbox send fail %d\n", ret);
518 resp = (struct ti_sci_msg_resp_get_device_state *)xfer->tx_message.buf;
519 if (!ti_sci_is_response_ack(resp))
523 *clcnt = resp->context_loss_count;
525 *resets = resp->resets;
527 *p_state = resp->programmed_state;
529 *c_state = resp->current_state;
535 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
536 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
537 * @id: Device Identifier
539 * Request for the device - NOTE: the client MUST maintain integrity of
540 * usage count by balancing get_device with put_device. No refcounting is
541 * managed by driver for that purpose.
543 * NOTE: The request is for exclusive access for the processor.
545 * Return: 0 if all went fine, else return appropriate error.
547 static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
549 return ti_sci_set_device_state(handle, id,
550 MSG_FLAG_DEVICE_EXCLUSIVE,
551 MSG_DEVICE_SW_STATE_ON);
555 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
556 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
557 * @id: Device Identifier
559 * Request for the device - NOTE: the client MUST maintain integrity of
560 * usage count by balancing get_device with put_device. No refcounting is
561 * managed by driver for that purpose.
563 * Return: 0 if all went fine, else return appropriate error.
565 static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
567 return ti_sci_set_device_state(handle, id,
568 MSG_FLAG_DEVICE_EXCLUSIVE,
569 MSG_DEVICE_SW_STATE_RETENTION);
573 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
574 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
575 * @id: Device Identifier
577 * Request for the device - NOTE: the client MUST maintain integrity of
578 * usage count by balancing get_device with put_device. No refcounting is
579 * managed by driver for that purpose.
581 * Return: 0 if all went fine, else return appropriate error.
583 static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
585 return ti_sci_set_device_state(handle, id,
586 0, MSG_DEVICE_SW_STATE_AUTO_OFF);
590 * ti_sci_cmd_dev_is_valid() - Is the device valid
591 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
592 * @id: Device Identifier
594 * Return: 0 if all went fine and the device ID is valid, else return
597 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
601 /* check the device state which will also tell us if the ID is valid */
602 return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused);
606 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
607 * @handle: Pointer to TISCI handle
608 * @id: Device Identifier
609 * @count: Pointer to Context Loss counter to populate
611 * Return: 0 if all went fine, else return appropriate error.
613 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
616 return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
620 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
621 * @handle: Pointer to TISCI handle
622 * @id: Device Identifier
623 * @r_state: true if requested to be idle
625 * Return: 0 if all went fine, else return appropriate error.
627 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
636 ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
640 *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
646 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
647 * @handle: Pointer to TISCI handle
648 * @id: Device Identifier
649 * @r_state: true if requested to be stopped
650 * @curr_state: true if currently stopped.
652 * Return: 0 if all went fine, else return appropriate error.
654 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
655 bool *r_state, bool *curr_state)
660 if (!r_state && !curr_state)
664 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
669 *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
671 *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
677 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
678 * @handle: Pointer to TISCI handle
679 * @id: Device Identifier
680 * @r_state: true if requested to be ON
681 * @curr_state: true if currently ON and active
683 * Return: 0 if all went fine, else return appropriate error.
685 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
686 bool *r_state, bool *curr_state)
691 if (!r_state && !curr_state)
695 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
700 *r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
702 *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
708 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
709 * @handle: Pointer to TISCI handle
710 * @id: Device Identifier
711 * @curr_state: true if currently transitioning.
713 * Return: 0 if all went fine, else return appropriate error.
715 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
724 ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
728 *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
734 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
736 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
737 * @id: Device Identifier
738 * @reset_state: Device specific reset bit field
740 * Return: 0 if all went fine, else return appropriate error.
742 static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
743 u32 id, u32 reset_state)
745 struct ti_sci_msg_req_set_device_resets req;
746 struct ti_sci_msg_hdr *resp;
747 struct ti_sci_info *info;
748 struct ti_sci_xfer *xfer;
752 return PTR_ERR(handle);
756 info = handle_to_ti_sci_info(handle);
758 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_RESETS,
759 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
760 (u32 *)&req, sizeof(req), sizeof(*resp));
763 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
767 req.resets = reset_state;
769 ret = ti_sci_do_xfer(info, xfer);
771 dev_err(info->dev, "Mbox send fail %d\n", ret);
775 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
777 if (!ti_sci_is_response_ack(resp))
784 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
786 * @handle: Pointer to TISCI handle
787 * @id: Device Identifier
788 * @reset_state: Pointer to reset state to populate
790 * Return: 0 if all went fine, else return appropriate error.
792 static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
793 u32 id, u32 *reset_state)
795 return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
800 * ti_sci_set_clock_state() - Set clock state helper
801 * @handle: pointer to TI SCI handle
802 * @dev_id: Device identifier this request is for
803 * @clk_id: Clock identifier for the device for this request.
804 * Each device has it's own set of clock inputs. This indexes
805 * which clock input to modify.
806 * @flags: Header flags as needed
807 * @state: State to request for the clock.
809 * Return: 0 if all went well, else returns appropriate error value.
811 static int ti_sci_set_clock_state(const struct ti_sci_handle *handle,
812 u32 dev_id, u8 clk_id,
815 struct ti_sci_msg_req_set_clock_state req;
816 struct ti_sci_msg_hdr *resp;
817 struct ti_sci_info *info;
818 struct ti_sci_xfer *xfer;
822 return PTR_ERR(handle);
826 info = handle_to_ti_sci_info(handle);
828 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_STATE,
829 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
830 (u32 *)&req, sizeof(req), sizeof(*resp));
833 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
838 req.request_state = state;
840 ret = ti_sci_do_xfer(info, xfer);
842 dev_err(info->dev, "Mbox send fail %d\n", ret);
846 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
848 if (!ti_sci_is_response_ack(resp))
855 * ti_sci_cmd_get_clock_state() - Get clock state helper
856 * @handle: pointer to TI SCI handle
857 * @dev_id: Device identifier this request is for
858 * @clk_id: Clock identifier for the device for this request.
859 * Each device has it's own set of clock inputs. This indexes
860 * which clock input to modify.
861 * @programmed_state: State requested for clock to move to
862 * @current_state: State that the clock is currently in
864 * Return: 0 if all went well, else returns appropriate error value.
866 static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle *handle,
867 u32 dev_id, u8 clk_id,
868 u8 *programmed_state, u8 *current_state)
870 struct ti_sci_msg_resp_get_clock_state *resp;
871 struct ti_sci_msg_req_get_clock_state req;
872 struct ti_sci_info *info;
873 struct ti_sci_xfer *xfer;
877 return PTR_ERR(handle);
881 if (!programmed_state && !current_state)
884 info = handle_to_ti_sci_info(handle);
886 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_STATE,
887 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
888 (u32 *)&req, sizeof(req), sizeof(*resp));
891 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
897 ret = ti_sci_do_xfer(info, xfer);
899 dev_err(info->dev, "Mbox send fail %d\n", ret);
903 resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->tx_message.buf;
905 if (!ti_sci_is_response_ack(resp))
908 if (programmed_state)
909 *programmed_state = resp->programmed_state;
911 *current_state = resp->current_state;
917 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
918 * @handle: pointer to TI SCI handle
919 * @dev_id: Device identifier this request is for
920 * @clk_id: Clock identifier for the device for this request.
921 * Each device has it's own set of clock inputs. This indexes
922 * which clock input to modify.
923 * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false'
924 * @can_change_freq: 'true' if frequency change is desired, else 'false'
925 * @enable_input_term: 'true' if input termination is desired, else 'false'
927 * Return: 0 if all went well, else returns appropriate error value.
929 static int ti_sci_cmd_get_clock(const struct ti_sci_handle *handle, u32 dev_id,
930 u8 clk_id, bool needs_ssc, bool can_change_freq,
931 bool enable_input_term)
935 flags |= needs_ssc ? MSG_FLAG_CLOCK_ALLOW_SSC : 0;
936 flags |= can_change_freq ? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE : 0;
937 flags |= enable_input_term ? MSG_FLAG_CLOCK_INPUT_TERM : 0;
939 return ti_sci_set_clock_state(handle, dev_id, clk_id, flags,
940 MSG_CLOCK_SW_STATE_REQ);
944 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
945 * @handle: pointer to TI SCI handle
946 * @dev_id: Device identifier this request is for
947 * @clk_id: Clock identifier for the device for this request.
948 * Each device has it's own set of clock inputs. This indexes
949 * which clock input to modify.
951 * NOTE: This clock must have been requested by get_clock previously.
953 * Return: 0 if all went well, else returns appropriate error value.
955 static int ti_sci_cmd_idle_clock(const struct ti_sci_handle *handle,
956 u32 dev_id, u8 clk_id)
958 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
959 MSG_CLOCK_SW_STATE_UNREQ);
963 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
964 * @handle: pointer to TI SCI handle
965 * @dev_id: Device identifier this request is for
966 * @clk_id: Clock identifier for the device for this request.
967 * Each device has it's own set of clock inputs. This indexes
968 * which clock input to modify.
970 * NOTE: This clock must have been requested by get_clock previously.
972 * Return: 0 if all went well, else returns appropriate error value.
974 static int ti_sci_cmd_put_clock(const struct ti_sci_handle *handle,
975 u32 dev_id, u8 clk_id)
977 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
978 MSG_CLOCK_SW_STATE_AUTO);
982 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
983 * @handle: pointer to TI SCI handle
984 * @dev_id: Device identifier this request is for
985 * @clk_id: Clock identifier for the device for this request.
986 * Each device has it's own set of clock inputs. This indexes
987 * which clock input to modify.
988 * @req_state: state indicating if the clock is auto managed
990 * Return: 0 if all went well, else returns appropriate error value.
992 static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle *handle,
993 u32 dev_id, u8 clk_id, bool *req_state)
1001 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, &state, NULL);
1005 *req_state = (state == MSG_CLOCK_SW_STATE_AUTO);
1010 * ti_sci_cmd_clk_is_on() - Is the clock ON
1011 * @handle: pointer to TI SCI handle
1012 * @dev_id: Device identifier this request is for
1013 * @clk_id: Clock identifier for the device for this request.
1014 * Each device has it's own set of clock inputs. This indexes
1015 * which clock input to modify.
1016 * @req_state: state indicating if the clock is managed by us and enabled
1017 * @curr_state: state indicating if the clock is ready for operation
1019 * Return: 0 if all went well, else returns appropriate error value.
1021 static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle *handle, u32 dev_id,
1022 u8 clk_id, bool *req_state, bool *curr_state)
1024 u8 c_state = 0, r_state = 0;
1027 if (!req_state && !curr_state)
1030 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1031 &r_state, &c_state);
1036 *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ);
1038 *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY);
1043 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1044 * @handle: pointer to TI SCI handle
1045 * @dev_id: Device identifier this request is for
1046 * @clk_id: Clock identifier for the device for this request.
1047 * Each device has it's own set of clock inputs. This indexes
1048 * which clock input to modify.
1049 * @req_state: state indicating if the clock is managed by us and disabled
1050 * @curr_state: state indicating if the clock is NOT ready for operation
1052 * Return: 0 if all went well, else returns appropriate error value.
1054 static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle *handle, u32 dev_id,
1055 u8 clk_id, bool *req_state, bool *curr_state)
1057 u8 c_state = 0, r_state = 0;
1060 if (!req_state && !curr_state)
1063 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1064 &r_state, &c_state);
1069 *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ);
1071 *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY);
1076 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1077 * @handle: pointer to TI SCI handle
1078 * @dev_id: Device identifier this request is for
1079 * @clk_id: Clock identifier for the device for this request.
1080 * Each device has it's own set of clock inputs. This indexes
1081 * which clock input to modify.
1082 * @parent_id: Parent clock identifier to set
1084 * Return: 0 if all went well, else returns appropriate error value.
1086 static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle *handle,
1087 u32 dev_id, u8 clk_id, u8 parent_id)
1089 struct ti_sci_msg_req_set_clock_parent req;
1090 struct ti_sci_msg_hdr *resp;
1091 struct ti_sci_info *info;
1092 struct ti_sci_xfer *xfer;
1096 return PTR_ERR(handle);
1100 info = handle_to_ti_sci_info(handle);
1102 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_PARENT,
1103 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1104 (u32 *)&req, sizeof(req), sizeof(*resp));
1106 ret = PTR_ERR(xfer);
1107 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1110 req.dev_id = dev_id;
1111 req.clk_id = clk_id;
1112 req.parent_id = parent_id;
1114 ret = ti_sci_do_xfer(info, xfer);
1116 dev_err(info->dev, "Mbox send fail %d\n", ret);
1120 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1122 if (!ti_sci_is_response_ack(resp))
1129 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1130 * @handle: pointer to TI SCI handle
1131 * @dev_id: Device identifier this request is for
1132 * @clk_id: Clock identifier for the device for this request.
1133 * Each device has it's own set of clock inputs. This indexes
1134 * which clock input to modify.
1135 * @parent_id: Current clock parent
1137 * Return: 0 if all went well, else returns appropriate error value.
1139 static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle,
1140 u32 dev_id, u8 clk_id, u8 *parent_id)
1142 struct ti_sci_msg_resp_get_clock_parent *resp;
1143 struct ti_sci_msg_req_get_clock_parent req;
1144 struct ti_sci_info *info;
1145 struct ti_sci_xfer *xfer;
1149 return PTR_ERR(handle);
1150 if (!handle || !parent_id)
1153 info = handle_to_ti_sci_info(handle);
1155 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_PARENT,
1156 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1157 (u32 *)&req, sizeof(req), sizeof(*resp));
1159 ret = PTR_ERR(xfer);
1160 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1163 req.dev_id = dev_id;
1164 req.clk_id = clk_id;
1166 ret = ti_sci_do_xfer(info, xfer);
1168 dev_err(info->dev, "Mbox send fail %d\n", ret);
1172 resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->tx_message.buf;
1174 if (!ti_sci_is_response_ack(resp))
1177 *parent_id = resp->parent_id;
1183 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1184 * @handle: pointer to TI SCI handle
1185 * @dev_id: Device identifier this request is for
1186 * @clk_id: Clock identifier for the device for this request.
1187 * Each device has it's own set of clock inputs. This indexes
1188 * which clock input to modify.
1189 * @num_parents: Returns he number of parents to the current clock.
1191 * Return: 0 if all went well, else returns appropriate error value.
1193 static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle *handle,
1194 u32 dev_id, u8 clk_id,
1197 struct ti_sci_msg_resp_get_clock_num_parents *resp;
1198 struct ti_sci_msg_req_get_clock_num_parents req;
1199 struct ti_sci_info *info;
1200 struct ti_sci_xfer *xfer;
1204 return PTR_ERR(handle);
1205 if (!handle || !num_parents)
1208 info = handle_to_ti_sci_info(handle);
1210 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS,
1211 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1212 (u32 *)&req, sizeof(req), sizeof(*resp));
1214 ret = PTR_ERR(xfer);
1215 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1218 req.dev_id = dev_id;
1219 req.clk_id = clk_id;
1221 ret = ti_sci_do_xfer(info, xfer);
1223 dev_err(info->dev, "Mbox send fail %d\n", ret);
1227 resp = (struct ti_sci_msg_resp_get_clock_num_parents *)
1228 xfer->tx_message.buf;
1230 if (!ti_sci_is_response_ack(resp))
1233 *num_parents = resp->num_parents;
1239 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1240 * @handle: pointer to TI SCI handle
1241 * @dev_id: Device identifier this request is for
1242 * @clk_id: Clock identifier for the device for this request.
1243 * Each device has it's own set of clock inputs. This indexes
1244 * which clock input to modify.
1245 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1246 * allowable programmed frequency and does not account for clock
1247 * tolerances and jitter.
1248 * @target_freq: The target clock frequency in Hz. A frequency will be
1249 * processed as close to this target frequency as possible.
1250 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1251 * allowable programmed frequency and does not account for clock
1252 * tolerances and jitter.
1253 * @match_freq: Frequency match in Hz response.
1255 * Return: 0 if all went well, else returns appropriate error value.
1257 static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle *handle,
1258 u32 dev_id, u8 clk_id, u64 min_freq,
1259 u64 target_freq, u64 max_freq,
1262 struct ti_sci_msg_resp_query_clock_freq *resp;
1263 struct ti_sci_msg_req_query_clock_freq req;
1264 struct ti_sci_info *info;
1265 struct ti_sci_xfer *xfer;
1269 return PTR_ERR(handle);
1270 if (!handle || !match_freq)
1273 info = handle_to_ti_sci_info(handle);
1275 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_QUERY_CLOCK_FREQ,
1276 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1277 (u32 *)&req, sizeof(req), sizeof(*resp));
1279 ret = PTR_ERR(xfer);
1280 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1283 req.dev_id = dev_id;
1284 req.clk_id = clk_id;
1285 req.min_freq_hz = min_freq;
1286 req.target_freq_hz = target_freq;
1287 req.max_freq_hz = max_freq;
1289 ret = ti_sci_do_xfer(info, xfer);
1291 dev_err(info->dev, "Mbox send fail %d\n", ret);
1295 resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->tx_message.buf;
1297 if (!ti_sci_is_response_ack(resp))
1300 *match_freq = resp->freq_hz;
1306 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1307 * @handle: pointer to TI SCI handle
1308 * @dev_id: Device identifier this request is for
1309 * @clk_id: Clock identifier for the device for this request.
1310 * Each device has it's own set of clock inputs. This indexes
1311 * which clock input to modify.
1312 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1313 * allowable programmed frequency and does not account for clock
1314 * tolerances and jitter.
1315 * @target_freq: The target clock frequency in Hz. A frequency will be
1316 * processed as close to this target frequency as possible.
1317 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1318 * allowable programmed frequency and does not account for clock
1319 * tolerances and jitter.
1321 * Return: 0 if all went well, else returns appropriate error value.
1323 static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle *handle,
1324 u32 dev_id, u8 clk_id, u64 min_freq,
1325 u64 target_freq, u64 max_freq)
1327 struct ti_sci_msg_req_set_clock_freq req;
1328 struct ti_sci_msg_hdr *resp;
1329 struct ti_sci_info *info;
1330 struct ti_sci_xfer *xfer;
1334 return PTR_ERR(handle);
1338 info = handle_to_ti_sci_info(handle);
1340 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_FREQ,
1341 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1342 (u32 *)&req, sizeof(req), sizeof(*resp));
1344 ret = PTR_ERR(xfer);
1345 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1348 req.dev_id = dev_id;
1349 req.clk_id = clk_id;
1350 req.min_freq_hz = min_freq;
1351 req.target_freq_hz = target_freq;
1352 req.max_freq_hz = max_freq;
1354 ret = ti_sci_do_xfer(info, xfer);
1356 dev_err(info->dev, "Mbox send fail %d\n", ret);
1360 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1362 if (!ti_sci_is_response_ack(resp))
1369 * ti_sci_cmd_clk_get_freq() - Get current frequency
1370 * @handle: pointer to TI SCI handle
1371 * @dev_id: Device identifier this request is for
1372 * @clk_id: Clock identifier for the device for this request.
1373 * Each device has it's own set of clock inputs. This indexes
1374 * which clock input to modify.
1375 * @freq: Currently frequency in Hz
1377 * Return: 0 if all went well, else returns appropriate error value.
1379 static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle,
1380 u32 dev_id, u8 clk_id, u64 *freq)
1382 struct ti_sci_msg_resp_get_clock_freq *resp;
1383 struct ti_sci_msg_req_get_clock_freq req;
1384 struct ti_sci_info *info;
1385 struct ti_sci_xfer *xfer;
1389 return PTR_ERR(handle);
1390 if (!handle || !freq)
1393 info = handle_to_ti_sci_info(handle);
1395 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_FREQ,
1396 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1397 (u32 *)&req, sizeof(req), sizeof(*resp));
1399 ret = PTR_ERR(xfer);
1400 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1403 req.dev_id = dev_id;
1404 req.clk_id = clk_id;
1406 ret = ti_sci_do_xfer(info, xfer);
1408 dev_err(info->dev, "Mbox send fail %d\n", ret);
1412 resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->tx_message.buf;
1414 if (!ti_sci_is_response_ack(resp))
1417 *freq = resp->freq_hz;
1423 * ti_sci_cmd_core_reboot() - Command to request system reset
1424 * @handle: pointer to TI SCI handle
1426 * Return: 0 if all went well, else returns appropriate error value.
1428 static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle)
1430 struct ti_sci_msg_req_reboot req;
1431 struct ti_sci_msg_hdr *resp;
1432 struct ti_sci_info *info;
1433 struct ti_sci_xfer *xfer;
1437 return PTR_ERR(handle);
1441 info = handle_to_ti_sci_info(handle);
1443 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SYS_RESET,
1444 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1445 (u32 *)&req, sizeof(req), sizeof(*resp));
1447 ret = PTR_ERR(xfer);
1448 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1452 ret = ti_sci_do_xfer(info, xfer);
1454 dev_err(dev, "Mbox send fail %d\n", ret);
1458 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1460 if (!ti_sci_is_response_ack(resp))
1466 static int ti_sci_get_resource_type(struct ti_sci_info *info, u16 dev_id,
1469 struct ti_sci_rm_type_map *rm_type_map = info->desc->rm_type_map;
1473 /* If map is not provided then assume dev_id is used as type */
1479 for (i = 0; rm_type_map[i].dev_id; i++) {
1480 if (rm_type_map[i].dev_id == dev_id) {
1481 *type = rm_type_map[i].type;
1494 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1495 * to a host. Resource is uniquely identified by
1497 * @handle: Pointer to TISCI handle.
1498 * @dev_id: TISCI device ID.
1499 * @subtype: Resource assignment subtype that is being requested
1500 * from the given device.
1501 * @s_host: Host processor ID to which the resources are allocated
1502 * @range_start: Start index of the resource range
1503 * @range_num: Number of resources in the range
1505 * Return: 0 if all went fine, else return appropriate error.
1507 static int ti_sci_get_resource_range(const struct ti_sci_handle *handle,
1508 u32 dev_id, u8 subtype, u8 s_host,
1509 u16 *range_start, u16 *range_num)
1511 struct ti_sci_msg_resp_get_resource_range *resp;
1512 struct ti_sci_msg_req_get_resource_range req;
1513 struct ti_sci_xfer *xfer;
1514 struct ti_sci_info *info;
1519 return PTR_ERR(handle);
1523 info = handle_to_ti_sci_info(handle);
1525 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE,
1526 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1527 (u32 *)&req, sizeof(req), sizeof(*resp));
1529 ret = PTR_ERR(xfer);
1530 dev_err(dev, "Message alloc failed(%d)\n", ret);
1534 ret = ti_sci_get_resource_type(info, dev_id, &type);
1536 dev_err(dev, "rm type lookup failed for %u\n", dev_id);
1540 req.secondary_host = s_host;
1541 req.type = type & MSG_RM_RESOURCE_TYPE_MASK;
1542 req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK;
1544 ret = ti_sci_do_xfer(info, xfer);
1546 dev_err(dev, "Mbox send fail %d\n", ret);
1550 resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->tx_message.buf;
1551 if (!ti_sci_is_response_ack(resp)) {
1553 } else if (!resp->range_start && !resp->range_num) {
1556 *range_start = resp->range_start;
1557 *range_num = resp->range_num;
1565 * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1566 * that is same as ti sci interface host.
1567 * @handle: Pointer to TISCI handle.
1568 * @dev_id: TISCI device ID.
1569 * @subtype: Resource assignment subtype that is being requested
1570 * from the given device.
1571 * @range_start: Start index of the resource range
1572 * @range_num: Number of resources in the range
1574 * Return: 0 if all went fine, else return appropriate error.
1576 static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle,
1577 u32 dev_id, u8 subtype,
1578 u16 *range_start, u16 *range_num)
1580 return ti_sci_get_resource_range(handle, dev_id, subtype,
1581 TI_SCI_IRQ_SECONDARY_HOST_INVALID,
1582 range_start, range_num);
1586 * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1587 * assigned to a specified host.
1588 * @handle: Pointer to TISCI handle.
1589 * @dev_id: TISCI device ID.
1590 * @subtype: Resource assignment subtype that is being requested
1591 * from the given device.
1592 * @s_host: Host processor ID to which the resources are allocated
1593 * @range_start: Start index of the resource range
1594 * @range_num: Number of resources in the range
1596 * Return: 0 if all went fine, else return appropriate error.
1599 int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle,
1600 u32 dev_id, u8 subtype, u8 s_host,
1601 u16 *range_start, u16 *range_num)
1603 return ti_sci_get_resource_range(handle, dev_id, subtype, s_host,
1604 range_start, range_num);
1608 * ti_sci_cmd_query_msmc() - Command to query currently available msmc memory
1609 * @handle: pointer to TI SCI handle
1610 * @msms_start: MSMC start as returned by tisci
1611 * @msmc_end: MSMC end as returned by tisci
1613 * Return: 0 if all went well, else returns appropriate error value.
1615 static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle,
1616 u64 *msmc_start, u64 *msmc_end)
1618 struct ti_sci_msg_resp_query_msmc *resp;
1619 struct ti_sci_msg_hdr req;
1620 struct ti_sci_info *info;
1621 struct ti_sci_xfer *xfer;
1625 return PTR_ERR(handle);
1629 info = handle_to_ti_sci_info(handle);
1631 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_QUERY_MSMC,
1632 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1633 (u32 *)&req, sizeof(req), sizeof(*resp));
1635 ret = PTR_ERR(xfer);
1636 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1640 ret = ti_sci_do_xfer(info, xfer);
1642 dev_err(dev, "Mbox send fail %d\n", ret);
1646 resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf;
1648 if (!ti_sci_is_response_ack(resp))
1651 *msmc_start = ((u64)resp->msmc_start_high << TISCI_ADDR_HIGH_SHIFT) |
1652 resp->msmc_start_low;
1653 *msmc_end = ((u64)resp->msmc_end_high << TISCI_ADDR_HIGH_SHIFT) |
1660 * ti_sci_cmd_proc_request() - Command to request a physical processor control
1661 * @handle: Pointer to TI SCI handle
1662 * @proc_id: Processor ID this request is for
1664 * Return: 0 if all went well, else returns appropriate error value.
1666 static int ti_sci_cmd_proc_request(const struct ti_sci_handle *handle,
1669 struct ti_sci_msg_req_proc_request req;
1670 struct ti_sci_msg_hdr *resp;
1671 struct ti_sci_info *info;
1672 struct ti_sci_xfer *xfer;
1676 return PTR_ERR(handle);
1680 info = handle_to_ti_sci_info(handle);
1682 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_REQUEST,
1683 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1684 (u32 *)&req, sizeof(req), sizeof(*resp));
1686 ret = PTR_ERR(xfer);
1687 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1690 req.processor_id = proc_id;
1692 ret = ti_sci_do_xfer(info, xfer);
1694 dev_err(info->dev, "Mbox send fail %d\n", ret);
1698 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1700 if (!ti_sci_is_response_ack(resp))
1707 * ti_sci_cmd_proc_release() - Command to release a physical processor control
1708 * @handle: Pointer to TI SCI handle
1709 * @proc_id: Processor ID this request is for
1711 * Return: 0 if all went well, else returns appropriate error value.
1713 static int ti_sci_cmd_proc_release(const struct ti_sci_handle *handle,
1716 struct ti_sci_msg_req_proc_release req;
1717 struct ti_sci_msg_hdr *resp;
1718 struct ti_sci_info *info;
1719 struct ti_sci_xfer *xfer;
1723 return PTR_ERR(handle);
1727 info = handle_to_ti_sci_info(handle);
1729 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_RELEASE,
1730 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1731 (u32 *)&req, sizeof(req), sizeof(*resp));
1733 ret = PTR_ERR(xfer);
1734 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1737 req.processor_id = proc_id;
1739 ret = ti_sci_do_xfer(info, xfer);
1741 dev_err(info->dev, "Mbox send fail %d\n", ret);
1745 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1747 if (!ti_sci_is_response_ack(resp))
1754 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
1755 * control to a host in the processor's access
1757 * @handle: Pointer to TI SCI handle
1758 * @proc_id: Processor ID this request is for
1759 * @host_id: Host ID to get the control of the processor
1761 * Return: 0 if all went well, else returns appropriate error value.
1763 static int ti_sci_cmd_proc_handover(const struct ti_sci_handle *handle,
1764 u8 proc_id, u8 host_id)
1766 struct ti_sci_msg_req_proc_handover req;
1767 struct ti_sci_msg_hdr *resp;
1768 struct ti_sci_info *info;
1769 struct ti_sci_xfer *xfer;
1773 return PTR_ERR(handle);
1777 info = handle_to_ti_sci_info(handle);
1779 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_HANDOVER,
1780 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1781 (u32 *)&req, sizeof(req), sizeof(*resp));
1783 ret = PTR_ERR(xfer);
1784 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1787 req.processor_id = proc_id;
1788 req.host_id = host_id;
1790 ret = ti_sci_do_xfer(info, xfer);
1792 dev_err(info->dev, "Mbox send fail %d\n", ret);
1796 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1798 if (!ti_sci_is_response_ack(resp))
1805 * ti_sci_cmd_set_proc_boot_cfg() - Command to set the processor boot
1806 * configuration flags
1807 * @handle: Pointer to TI SCI handle
1808 * @proc_id: Processor ID this request is for
1809 * @config_flags_set: Configuration flags to be set
1810 * @config_flags_clear: Configuration flags to be cleared.
1812 * Return: 0 if all went well, else returns appropriate error value.
1814 static int ti_sci_cmd_set_proc_boot_cfg(const struct ti_sci_handle *handle,
1815 u8 proc_id, u64 bootvector,
1816 u32 config_flags_set,
1817 u32 config_flags_clear)
1819 struct ti_sci_msg_req_set_proc_boot_config req;
1820 struct ti_sci_msg_hdr *resp;
1821 struct ti_sci_info *info;
1822 struct ti_sci_xfer *xfer;
1826 return PTR_ERR(handle);
1830 info = handle_to_ti_sci_info(handle);
1832 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CONFIG,
1833 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1834 (u32 *)&req, sizeof(req), sizeof(*resp));
1836 ret = PTR_ERR(xfer);
1837 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1840 req.processor_id = proc_id;
1841 req.bootvector_low = bootvector & TISCI_ADDR_LOW_MASK;
1842 req.bootvector_high = (bootvector & TISCI_ADDR_HIGH_MASK) >>
1843 TISCI_ADDR_HIGH_SHIFT;
1844 req.config_flags_set = config_flags_set;
1845 req.config_flags_clear = config_flags_clear;
1847 ret = ti_sci_do_xfer(info, xfer);
1849 dev_err(info->dev, "Mbox send fail %d\n", ret);
1853 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1855 if (!ti_sci_is_response_ack(resp))
1862 * ti_sci_cmd_set_proc_boot_ctrl() - Command to set the processor boot
1864 * @handle: Pointer to TI SCI handle
1865 * @proc_id: Processor ID this request is for
1866 * @control_flags_set: Control flags to be set
1867 * @control_flags_clear: Control flags to be cleared
1869 * Return: 0 if all went well, else returns appropriate error value.
1871 static int ti_sci_cmd_set_proc_boot_ctrl(const struct ti_sci_handle *handle,
1872 u8 proc_id, u32 control_flags_set,
1873 u32 control_flags_clear)
1875 struct ti_sci_msg_req_set_proc_boot_ctrl req;
1876 struct ti_sci_msg_hdr *resp;
1877 struct ti_sci_info *info;
1878 struct ti_sci_xfer *xfer;
1882 return PTR_ERR(handle);
1886 info = handle_to_ti_sci_info(handle);
1888 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CTRL,
1889 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1890 (u32 *)&req, sizeof(req), sizeof(*resp));
1892 ret = PTR_ERR(xfer);
1893 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1896 req.processor_id = proc_id;
1897 req.control_flags_set = control_flags_set;
1898 req.control_flags_clear = control_flags_clear;
1900 ret = ti_sci_do_xfer(info, xfer);
1902 dev_err(info->dev, "Mbox send fail %d\n", ret);
1906 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1908 if (!ti_sci_is_response_ack(resp))
1915 * ti_sci_cmd_proc_auth_boot_image() - Command to authenticate and load the
1916 * image and then set the processor configuration flags.
1917 * @handle: Pointer to TI SCI handle
1918 * @image_addr: Memory address at which payload image and certificate is
1919 * located in memory, this is updated if the image data is
1920 * moved during authentication.
1921 * @image_size: This is updated with the final size of the image after
1924 * Return: 0 if all went well, else returns appropriate error value.
1926 static int ti_sci_cmd_proc_auth_boot_image(const struct ti_sci_handle *handle,
1927 u64 *image_addr, u32 *image_size)
1929 struct ti_sci_msg_req_proc_auth_boot_image req;
1930 struct ti_sci_msg_resp_proc_auth_boot_image *resp;
1931 struct ti_sci_info *info;
1932 struct ti_sci_xfer *xfer;
1936 return PTR_ERR(handle);
1940 info = handle_to_ti_sci_info(handle);
1942 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_AUTH_BOOT_IMIAGE,
1943 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1944 (u32 *)&req, sizeof(req), sizeof(*resp));
1946 ret = PTR_ERR(xfer);
1947 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1950 req.cert_addr_low = *image_addr & TISCI_ADDR_LOW_MASK;
1951 req.cert_addr_high = (*image_addr & TISCI_ADDR_HIGH_MASK) >>
1952 TISCI_ADDR_HIGH_SHIFT;
1954 ret = ti_sci_do_xfer(info, xfer);
1956 dev_err(info->dev, "Mbox send fail %d\n", ret);
1960 resp = (struct ti_sci_msg_resp_proc_auth_boot_image *)xfer->tx_message.buf;
1962 if (!ti_sci_is_response_ack(resp))
1965 *image_addr = (resp->image_addr_low & TISCI_ADDR_LOW_MASK) |
1966 (((u64)resp->image_addr_high <<
1967 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
1968 *image_size = resp->image_size;
1974 * ti_sci_cmd_get_proc_boot_status() - Command to get the processor boot status
1975 * @handle: Pointer to TI SCI handle
1976 * @proc_id: Processor ID this request is for
1978 * Return: 0 if all went well, else returns appropriate error value.
1980 static int ti_sci_cmd_get_proc_boot_status(const struct ti_sci_handle *handle,
1981 u8 proc_id, u64 *bv, u32 *cfg_flags,
1982 u32 *ctrl_flags, u32 *sts_flags)
1984 struct ti_sci_msg_resp_get_proc_boot_status *resp;
1985 struct ti_sci_msg_req_get_proc_boot_status req;
1986 struct ti_sci_info *info;
1987 struct ti_sci_xfer *xfer;
1991 return PTR_ERR(handle);
1995 info = handle_to_ti_sci_info(handle);
1997 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_GET_PROC_BOOT_STATUS,
1998 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1999 (u32 *)&req, sizeof(req), sizeof(*resp));
2001 ret = PTR_ERR(xfer);
2002 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2005 req.processor_id = proc_id;
2007 ret = ti_sci_do_xfer(info, xfer);
2009 dev_err(info->dev, "Mbox send fail %d\n", ret);
2013 resp = (struct ti_sci_msg_resp_get_proc_boot_status *)
2014 xfer->tx_message.buf;
2016 if (!ti_sci_is_response_ack(resp))
2018 *bv = (resp->bootvector_low & TISCI_ADDR_LOW_MASK) |
2019 (((u64)resp->bootvector_high <<
2020 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2021 *cfg_flags = resp->config_flags;
2022 *ctrl_flags = resp->control_flags;
2023 *sts_flags = resp->status_flags;
2029 * ti_sci_cmd_ring_config() - configure RA ring
2030 * @handle: pointer to TI SCI handle
2031 * @valid_params: Bitfield defining validity of ring configuration parameters.
2032 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2033 * @index: Ring index.
2034 * @addr_lo: The ring base address lo 32 bits
2035 * @addr_hi: The ring base address hi 32 bits
2036 * @count: Number of ring elements.
2037 * @mode: The mode of the ring
2038 * @size: The ring element size.
2039 * @order_id: Specifies the ring's bus order ID.
2041 * Return: 0 if all went well, else returns appropriate error value.
2043 * See @ti_sci_msg_rm_ring_cfg_req for more info.
2045 static int ti_sci_cmd_ring_config(const struct ti_sci_handle *handle,
2046 u32 valid_params, u16 nav_id, u16 index,
2047 u32 addr_lo, u32 addr_hi, u32 count,
2048 u8 mode, u8 size, u8 order_id)
2050 struct ti_sci_msg_rm_ring_cfg_resp *resp;
2051 struct ti_sci_msg_rm_ring_cfg_req req;
2052 struct ti_sci_xfer *xfer;
2053 struct ti_sci_info *info;
2057 return PTR_ERR(handle);
2061 info = handle_to_ti_sci_info(handle);
2063 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_CFG,
2064 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2065 (u32 *)&req, sizeof(req), sizeof(*resp));
2067 ret = PTR_ERR(xfer);
2068 dev_err(info->dev, "RM_RA:Message config failed(%d)\n", ret);
2071 req.valid_params = valid_params;
2072 req.nav_id = nav_id;
2074 req.addr_lo = addr_lo;
2075 req.addr_hi = addr_hi;
2079 req.order_id = order_id;
2081 ret = ti_sci_do_xfer(info, xfer);
2083 dev_err(info->dev, "RM_RA:Mbox config send fail %d\n", ret);
2087 resp = (struct ti_sci_msg_rm_ring_cfg_resp *)xfer->tx_message.buf;
2089 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2092 dev_dbg(info->dev, "RM_RA:config ring %u ret:%d\n", index, ret);
2097 * ti_sci_cmd_ring_get_config() - get RA ring configuration
2098 * @handle: pointer to TI SCI handle
2099 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2100 * @index: Ring index.
2101 * @addr_lo: returns ring's base address lo 32 bits
2102 * @addr_hi: returns ring's base address hi 32 bits
2103 * @count: returns number of ring elements.
2104 * @mode: returns mode of the ring
2105 * @size: returns ring element size.
2106 * @order_id: returns ring's bus order ID.
2108 * Return: 0 if all went well, else returns appropriate error value.
2110 * See @ti_sci_msg_rm_ring_get_cfg_req for more info.
2112 static int ti_sci_cmd_ring_get_config(const struct ti_sci_handle *handle,
2113 u32 nav_id, u32 index, u8 *mode,
2114 u32 *addr_lo, u32 *addr_hi,
2115 u32 *count, u8 *size, u8 *order_id)
2117 struct ti_sci_msg_rm_ring_get_cfg_resp *resp;
2118 struct ti_sci_msg_rm_ring_get_cfg_req req;
2119 struct ti_sci_xfer *xfer;
2120 struct ti_sci_info *info;
2124 return PTR_ERR(handle);
2128 info = handle_to_ti_sci_info(handle);
2130 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_GET_CFG,
2131 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2132 (u32 *)&req, sizeof(req), sizeof(*resp));
2134 ret = PTR_ERR(xfer);
2136 "RM_RA:Message get config failed(%d)\n", ret);
2139 req.nav_id = nav_id;
2142 ret = ti_sci_do_xfer(info, xfer);
2144 dev_err(info->dev, "RM_RA:Mbox get config send fail %d\n", ret);
2148 resp = (struct ti_sci_msg_rm_ring_get_cfg_resp *)xfer->tx_message.buf;
2150 if (!ti_sci_is_response_ack(resp)) {
2156 *addr_lo = resp->addr_lo;
2158 *addr_hi = resp->addr_hi;
2160 *count = resp->count;
2164 *order_id = resp->order_id;
2168 dev_dbg(info->dev, "RM_RA:get config ring %u ret:%d\n", index, ret);
2172 static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle *handle,
2173 u32 nav_id, u32 src_thread, u32 dst_thread)
2175 struct ti_sci_msg_hdr *resp;
2176 struct ti_sci_msg_psil_pair req;
2177 struct ti_sci_xfer *xfer;
2178 struct ti_sci_info *info;
2182 return PTR_ERR(handle);
2186 info = handle_to_ti_sci_info(handle);
2188 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_PAIR,
2189 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2190 (u32 *)&req, sizeof(req), sizeof(*resp));
2192 ret = PTR_ERR(xfer);
2193 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2196 req.nav_id = nav_id;
2197 req.src_thread = src_thread;
2198 req.dst_thread = dst_thread;
2200 ret = ti_sci_do_xfer(info, xfer);
2202 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2206 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2207 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2210 dev_dbg(info->dev, "RM_PSIL: nav: %u link pair %u->%u ret:%u\n",
2211 nav_id, src_thread, dst_thread, ret);
2215 static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle *handle,
2216 u32 nav_id, u32 src_thread, u32 dst_thread)
2218 struct ti_sci_msg_hdr *resp;
2219 struct ti_sci_msg_psil_unpair req;
2220 struct ti_sci_xfer *xfer;
2221 struct ti_sci_info *info;
2225 return PTR_ERR(handle);
2229 info = handle_to_ti_sci_info(handle);
2231 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_UNPAIR,
2232 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2233 (u32 *)&req, sizeof(req), sizeof(*resp));
2235 ret = PTR_ERR(xfer);
2236 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2239 req.nav_id = nav_id;
2240 req.src_thread = src_thread;
2241 req.dst_thread = dst_thread;
2243 ret = ti_sci_do_xfer(info, xfer);
2245 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2249 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2250 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2253 dev_dbg(info->dev, "RM_PSIL: link unpair %u->%u ret:%u\n",
2254 src_thread, dst_thread, ret);
2258 static int ti_sci_cmd_rm_udmap_tx_ch_cfg(
2259 const struct ti_sci_handle *handle,
2260 const struct ti_sci_msg_rm_udmap_tx_ch_cfg *params)
2262 struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *resp;
2263 struct ti_sci_msg_rm_udmap_tx_ch_cfg_req req;
2264 struct ti_sci_xfer *xfer;
2265 struct ti_sci_info *info;
2269 return PTR_ERR(handle);
2273 info = handle_to_ti_sci_info(handle);
2275 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_TX_CH_CFG,
2276 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2277 (u32 *)&req, sizeof(req), sizeof(*resp));
2279 ret = PTR_ERR(xfer);
2280 dev_err(info->dev, "Message TX_CH_CFG alloc failed(%d)\n", ret);
2283 req.valid_params = params->valid_params;
2284 req.nav_id = params->nav_id;
2285 req.index = params->index;
2286 req.tx_pause_on_err = params->tx_pause_on_err;
2287 req.tx_filt_einfo = params->tx_filt_einfo;
2288 req.tx_filt_pswords = params->tx_filt_pswords;
2289 req.tx_atype = params->tx_atype;
2290 req.tx_chan_type = params->tx_chan_type;
2291 req.tx_supr_tdpkt = params->tx_supr_tdpkt;
2292 req.tx_fetch_size = params->tx_fetch_size;
2293 req.tx_credit_count = params->tx_credit_count;
2294 req.txcq_qnum = params->txcq_qnum;
2295 req.tx_priority = params->tx_priority;
2296 req.tx_qos = params->tx_qos;
2297 req.tx_orderid = params->tx_orderid;
2298 req.fdepth = params->fdepth;
2299 req.tx_sched_priority = params->tx_sched_priority;
2301 ret = ti_sci_do_xfer(info, xfer);
2303 dev_err(info->dev, "Mbox send TX_CH_CFG fail %d\n", ret);
2308 (struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *)xfer->tx_message.buf;
2309 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2312 dev_dbg(info->dev, "TX_CH_CFG: chn %u ret:%u\n", params->index, ret);
2316 static int ti_sci_cmd_rm_udmap_rx_ch_cfg(
2317 const struct ti_sci_handle *handle,
2318 const struct ti_sci_msg_rm_udmap_rx_ch_cfg *params)
2320 struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *resp;
2321 struct ti_sci_msg_rm_udmap_rx_ch_cfg_req req;
2322 struct ti_sci_xfer *xfer;
2323 struct ti_sci_info *info;
2327 return PTR_ERR(handle);
2331 info = handle_to_ti_sci_info(handle);
2333 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_RX_CH_CFG,
2334 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2335 (u32 *)&req, sizeof(req), sizeof(*resp));
2337 ret = PTR_ERR(xfer);
2338 dev_err(info->dev, "Message RX_CH_CFG alloc failed(%d)\n", ret);
2342 req.valid_params = params->valid_params;
2343 req.nav_id = params->nav_id;
2344 req.index = params->index;
2345 req.rx_fetch_size = params->rx_fetch_size;
2346 req.rxcq_qnum = params->rxcq_qnum;
2347 req.rx_priority = params->rx_priority;
2348 req.rx_qos = params->rx_qos;
2349 req.rx_orderid = params->rx_orderid;
2350 req.rx_sched_priority = params->rx_sched_priority;
2351 req.flowid_start = params->flowid_start;
2352 req.flowid_cnt = params->flowid_cnt;
2353 req.rx_pause_on_err = params->rx_pause_on_err;
2354 req.rx_atype = params->rx_atype;
2355 req.rx_chan_type = params->rx_chan_type;
2356 req.rx_ignore_short = params->rx_ignore_short;
2357 req.rx_ignore_long = params->rx_ignore_long;
2359 ret = ti_sci_do_xfer(info, xfer);
2361 dev_err(info->dev, "Mbox send RX_CH_CFG fail %d\n", ret);
2366 (struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *)xfer->tx_message.buf;
2367 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2370 dev_dbg(info->dev, "RX_CH_CFG: chn %u ret:%d\n", params->index, ret);
2374 static int ti_sci_cmd_rm_udmap_rx_flow_cfg(
2375 const struct ti_sci_handle *handle,
2376 const struct ti_sci_msg_rm_udmap_flow_cfg *params)
2378 struct ti_sci_msg_rm_udmap_flow_cfg_resp *resp;
2379 struct ti_sci_msg_rm_udmap_flow_cfg_req req;
2380 struct ti_sci_xfer *xfer;
2381 struct ti_sci_info *info;
2385 return PTR_ERR(handle);
2389 info = handle_to_ti_sci_info(handle);
2391 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_FLOW_CFG,
2392 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2393 (u32 *)&req, sizeof(req), sizeof(*resp));
2395 ret = PTR_ERR(xfer);
2396 dev_err(dev, "RX_FL_CFG: Message alloc failed(%d)\n", ret);
2400 req.valid_params = params->valid_params;
2401 req.nav_id = params->nav_id;
2402 req.flow_index = params->flow_index;
2403 req.rx_einfo_present = params->rx_einfo_present;
2404 req.rx_psinfo_present = params->rx_psinfo_present;
2405 req.rx_error_handling = params->rx_error_handling;
2406 req.rx_desc_type = params->rx_desc_type;
2407 req.rx_sop_offset = params->rx_sop_offset;
2408 req.rx_dest_qnum = params->rx_dest_qnum;
2409 req.rx_src_tag_hi = params->rx_src_tag_hi;
2410 req.rx_src_tag_lo = params->rx_src_tag_lo;
2411 req.rx_dest_tag_hi = params->rx_dest_tag_hi;
2412 req.rx_dest_tag_lo = params->rx_dest_tag_lo;
2413 req.rx_src_tag_hi_sel = params->rx_src_tag_hi_sel;
2414 req.rx_src_tag_lo_sel = params->rx_src_tag_lo_sel;
2415 req.rx_dest_tag_hi_sel = params->rx_dest_tag_hi_sel;
2416 req.rx_dest_tag_lo_sel = params->rx_dest_tag_lo_sel;
2417 req.rx_fdq0_sz0_qnum = params->rx_fdq0_sz0_qnum;
2418 req.rx_fdq1_qnum = params->rx_fdq1_qnum;
2419 req.rx_fdq2_qnum = params->rx_fdq2_qnum;
2420 req.rx_fdq3_qnum = params->rx_fdq3_qnum;
2421 req.rx_ps_location = params->rx_ps_location;
2423 ret = ti_sci_do_xfer(info, xfer);
2425 dev_err(dev, "RX_FL_CFG: Mbox send fail %d\n", ret);
2430 (struct ti_sci_msg_rm_udmap_flow_cfg_resp *)xfer->tx_message.buf;
2431 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2434 dev_dbg(info->dev, "RX_FL_CFG: %u ret:%d\n", params->flow_index, ret);
2439 * ti_sci_cmd_set_fwl_region() - Request for configuring a firewall region
2440 * @handle: pointer to TI SCI handle
2441 * @region: region configuration parameters
2443 * Return: 0 if all went well, else returns appropriate error value.
2445 static int ti_sci_cmd_set_fwl_region(const struct ti_sci_handle *handle,
2446 const struct ti_sci_msg_fwl_region *region)
2448 struct ti_sci_msg_fwl_set_firewall_region_req req;
2449 struct ti_sci_msg_hdr *resp;
2450 struct ti_sci_info *info;
2451 struct ti_sci_xfer *xfer;
2455 return PTR_ERR(handle);
2459 info = handle_to_ti_sci_info(handle);
2461 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_SET,
2462 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2463 (u32 *)&req, sizeof(req), sizeof(*resp));
2465 ret = PTR_ERR(xfer);
2466 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2470 req.fwl_id = region->fwl_id;
2471 req.region = region->region;
2472 req.n_permission_regs = region->n_permission_regs;
2473 req.control = region->control;
2474 req.permissions[0] = region->permissions[0];
2475 req.permissions[1] = region->permissions[1];
2476 req.permissions[2] = region->permissions[2];
2477 req.start_address = region->start_address;
2478 req.end_address = region->end_address;
2480 ret = ti_sci_do_xfer(info, xfer);
2482 dev_err(info->dev, "Mbox send fail %d\n", ret);
2486 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2488 if (!ti_sci_is_response_ack(resp))
2495 * ti_sci_cmd_get_fwl_region() - Request for getting a firewall region
2496 * @handle: pointer to TI SCI handle
2497 * @region: region configuration parameters
2499 * Return: 0 if all went well, else returns appropriate error value.
2501 static int ti_sci_cmd_get_fwl_region(const struct ti_sci_handle *handle,
2502 struct ti_sci_msg_fwl_region *region)
2504 struct ti_sci_msg_fwl_get_firewall_region_req req;
2505 struct ti_sci_msg_fwl_get_firewall_region_resp *resp;
2506 struct ti_sci_info *info;
2507 struct ti_sci_xfer *xfer;
2511 return PTR_ERR(handle);
2515 info = handle_to_ti_sci_info(handle);
2517 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_GET,
2518 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2519 (u32 *)&req, sizeof(req), sizeof(*resp));
2521 ret = PTR_ERR(xfer);
2522 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2526 req.fwl_id = region->fwl_id;
2527 req.region = region->region;
2528 req.n_permission_regs = region->n_permission_regs;
2530 ret = ti_sci_do_xfer(info, xfer);
2532 dev_err(info->dev, "Mbox send fail %d\n", ret);
2536 resp = (struct ti_sci_msg_fwl_get_firewall_region_resp *)xfer->tx_message.buf;
2538 if (!ti_sci_is_response_ack(resp))
2541 region->fwl_id = resp->fwl_id;
2542 region->region = resp->region;
2543 region->n_permission_regs = resp->n_permission_regs;
2544 region->control = resp->control;
2545 region->permissions[0] = resp->permissions[0];
2546 region->permissions[1] = resp->permissions[1];
2547 region->permissions[2] = resp->permissions[2];
2548 region->start_address = resp->start_address;
2549 region->end_address = resp->end_address;
2555 * ti_sci_cmd_change_fwl_owner() - Request for changing a firewall owner
2556 * @handle: pointer to TI SCI handle
2557 * @region: region configuration parameters
2559 * Return: 0 if all went well, else returns appropriate error value.
2561 static int ti_sci_cmd_change_fwl_owner(const struct ti_sci_handle *handle,
2562 struct ti_sci_msg_fwl_owner *owner)
2564 struct ti_sci_msg_fwl_change_owner_info_req req;
2565 struct ti_sci_msg_fwl_change_owner_info_resp *resp;
2566 struct ti_sci_info *info;
2567 struct ti_sci_xfer *xfer;
2571 return PTR_ERR(handle);
2575 info = handle_to_ti_sci_info(handle);
2577 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_GET,
2578 TISCI_MSG_FWL_CHANGE_OWNER,
2579 (u32 *)&req, sizeof(req), sizeof(*resp));
2581 ret = PTR_ERR(xfer);
2582 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2586 req.fwl_id = owner->fwl_id;
2587 req.region = owner->region;
2588 req.owner_index = owner->owner_index;
2590 ret = ti_sci_do_xfer(info, xfer);
2592 dev_err(info->dev, "Mbox send fail %d\n", ret);
2596 resp = (struct ti_sci_msg_fwl_change_owner_info_resp *)xfer->tx_message.buf;
2598 if (!ti_sci_is_response_ack(resp))
2601 owner->fwl_id = resp->fwl_id;
2602 owner->region = resp->region;
2603 owner->owner_index = resp->owner_index;
2604 owner->owner_privid = resp->owner_privid;
2605 owner->owner_permission_bits = resp->owner_permission_bits;
2611 * ti_sci_setup_ops() - Setup the operations structures
2612 * @info: pointer to TISCI pointer
2614 static void ti_sci_setup_ops(struct ti_sci_info *info)
2616 struct ti_sci_ops *ops = &info->handle.ops;
2617 struct ti_sci_board_ops *bops = &ops->board_ops;
2618 struct ti_sci_dev_ops *dops = &ops->dev_ops;
2619 struct ti_sci_clk_ops *cops = &ops->clk_ops;
2620 struct ti_sci_core_ops *core_ops = &ops->core_ops;
2621 struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
2622 struct ti_sci_proc_ops *pops = &ops->proc_ops;
2623 struct ti_sci_rm_ringacc_ops *rops = &ops->rm_ring_ops;
2624 struct ti_sci_rm_psil_ops *psilops = &ops->rm_psil_ops;
2625 struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops;
2626 struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops;
2628 bops->board_config = ti_sci_cmd_set_board_config;
2629 bops->board_config_rm = ti_sci_cmd_set_board_config_rm;
2630 bops->board_config_security = ti_sci_cmd_set_board_config_security;
2631 bops->board_config_pm = ti_sci_cmd_set_board_config_pm;
2633 dops->get_device = ti_sci_cmd_get_device;
2634 dops->idle_device = ti_sci_cmd_idle_device;
2635 dops->put_device = ti_sci_cmd_put_device;
2636 dops->is_valid = ti_sci_cmd_dev_is_valid;
2637 dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt;
2638 dops->is_idle = ti_sci_cmd_dev_is_idle;
2639 dops->is_stop = ti_sci_cmd_dev_is_stop;
2640 dops->is_on = ti_sci_cmd_dev_is_on;
2641 dops->is_transitioning = ti_sci_cmd_dev_is_trans;
2642 dops->set_device_resets = ti_sci_cmd_set_device_resets;
2643 dops->get_device_resets = ti_sci_cmd_get_device_resets;
2645 cops->get_clock = ti_sci_cmd_get_clock;
2646 cops->idle_clock = ti_sci_cmd_idle_clock;
2647 cops->put_clock = ti_sci_cmd_put_clock;
2648 cops->is_auto = ti_sci_cmd_clk_is_auto;
2649 cops->is_on = ti_sci_cmd_clk_is_on;
2650 cops->is_off = ti_sci_cmd_clk_is_off;
2652 cops->set_parent = ti_sci_cmd_clk_set_parent;
2653 cops->get_parent = ti_sci_cmd_clk_get_parent;
2654 cops->get_num_parents = ti_sci_cmd_clk_get_num_parents;
2656 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;
2657 cops->set_freq = ti_sci_cmd_clk_set_freq;
2658 cops->get_freq = ti_sci_cmd_clk_get_freq;
2660 core_ops->reboot_device = ti_sci_cmd_core_reboot;
2661 core_ops->query_msmc = ti_sci_cmd_query_msmc;
2663 rm_core_ops->get_range = ti_sci_cmd_get_resource_range;
2664 rm_core_ops->get_range_from_shost =
2665 ti_sci_cmd_get_resource_range_from_shost;
2667 pops->proc_request = ti_sci_cmd_proc_request;
2668 pops->proc_release = ti_sci_cmd_proc_release;
2669 pops->proc_handover = ti_sci_cmd_proc_handover;
2670 pops->set_proc_boot_cfg = ti_sci_cmd_set_proc_boot_cfg;
2671 pops->set_proc_boot_ctrl = ti_sci_cmd_set_proc_boot_ctrl;
2672 pops->proc_auth_boot_image = ti_sci_cmd_proc_auth_boot_image;
2673 pops->get_proc_boot_status = ti_sci_cmd_get_proc_boot_status;
2675 rops->config = ti_sci_cmd_ring_config;
2676 rops->get_config = ti_sci_cmd_ring_get_config;
2678 psilops->pair = ti_sci_cmd_rm_psil_pair;
2679 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
2681 udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg;
2682 udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg;
2683 udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg;
2685 fwl_ops->set_fwl_region = ti_sci_cmd_set_fwl_region;
2686 fwl_ops->get_fwl_region = ti_sci_cmd_get_fwl_region;
2687 fwl_ops->change_fwl_owner = ti_sci_cmd_change_fwl_owner;
2691 * ti_sci_get_handle_from_sysfw() - Get the TI SCI handle of the SYSFW
2692 * @dev: Pointer to the SYSFW device
2694 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2698 struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *sci_dev)
2701 return ERR_PTR(-EINVAL);
2703 struct ti_sci_info *info = dev_get_priv(sci_dev);
2706 return ERR_PTR(-EINVAL);
2708 struct ti_sci_handle *handle = &info->handle;
2711 return ERR_PTR(-EINVAL);
2717 * ti_sci_get_handle() - Get the TI SCI handle for a device
2718 * @dev: Pointer to device for which we want SCI handle
2720 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2723 const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
2726 return ERR_PTR(-EINVAL);
2728 struct udevice *sci_dev = dev_get_parent(dev);
2730 return ti_sci_get_handle_from_sysfw(sci_dev);
2734 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
2736 * @propname: property name containing phandle on TISCI node
2738 * Return: pointer to handle if successful, else appropriate error value.
2740 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
2741 const char *property)
2743 struct ti_sci_info *entry, *info = NULL;
2747 err = ofnode_read_u32(dev_ofnode(dev), property, &phandle);
2749 return ERR_PTR(err);
2751 node = ofnode_get_by_phandle(phandle);
2752 if (!ofnode_valid(node))
2753 return ERR_PTR(-EINVAL);
2755 list_for_each_entry(entry, &ti_sci_list, list)
2756 if (ofnode_equal(dev_ofnode(entry->dev), node)) {
2762 return ERR_PTR(-ENODEV);
2764 return &info->handle;
2768 * ti_sci_of_to_info() - generate private data from device tree
2769 * @dev: corresponding system controller interface device
2770 * @info: pointer to driver specific private data
2772 * Return: 0 if all goes good, else appropriate error message.
2774 static int ti_sci_of_to_info(struct udevice *dev, struct ti_sci_info *info)
2778 ret = mbox_get_by_name(dev, "tx", &info->chan_tx);
2780 dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n",
2785 ret = mbox_get_by_name(dev, "rx", &info->chan_rx);
2787 dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n",
2792 /* Notify channel is optional. Enable only if populated */
2793 ret = mbox_get_by_name(dev, "notify", &info->chan_notify);
2795 dev_dbg(dev, "%s: Acquiring notify channel failed. ret = %d\n",
2799 info->host_id = dev_read_u32_default(dev, "ti,host-id",
2800 info->desc->default_host_id);
2802 info->is_secure = dev_read_bool(dev, "ti,secure-host");
2808 * ti_sci_probe() - Basic probe
2809 * @dev: corresponding system controller interface device
2811 * Return: 0 if all goes good, else appropriate error message.
2813 static int ti_sci_probe(struct udevice *dev)
2815 struct ti_sci_info *info;
2818 debug("%s(dev=%p)\n", __func__, dev);
2820 info = dev_get_priv(dev);
2821 info->desc = (void *)dev_get_driver_data(dev);
2823 ret = ti_sci_of_to_info(dev, info);
2825 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
2832 list_add_tail(&info->list, &ti_sci_list);
2833 ti_sci_setup_ops(info);
2835 ret = ti_sci_cmd_get_revision(&info->handle);
2841 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
2842 * @res: Pointer to the TISCI resource
2844 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
2846 u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
2850 for (set = 0; set < res->sets; set++) {
2851 free_bit = find_first_zero_bit(res->desc[set].res_map,
2852 res->desc[set].num);
2853 if (free_bit != res->desc[set].num) {
2854 set_bit(free_bit, res->desc[set].res_map);
2855 return res->desc[set].start + free_bit;
2859 return TI_SCI_RESOURCE_NULL;
2863 * ti_sci_release_resource() - Release a resource from TISCI resource.
2864 * @res: Pointer to the TISCI resource
2866 void ti_sci_release_resource(struct ti_sci_resource *res, u16 id)
2870 for (set = 0; set < res->sets; set++) {
2871 if (res->desc[set].start <= id &&
2872 (res->desc[set].num + res->desc[set].start) > id)
2873 clear_bit(id - res->desc[set].start,
2874 res->desc[set].res_map);
2879 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
2880 * @handle: TISCI handle
2881 * @dev: Device pointer to which the resource is assigned
2882 * @of_prop: property name by which the resource are represented
2884 * Note: This function expects of_prop to be in the form of tuples
2885 * <type, subtype>. Allocates and initializes ti_sci_resource structure
2886 * for each of_prop. Client driver can directly call
2887 * ti_sci_(get_free, release)_resource apis for handling the resource.
2889 * Return: Pointer to ti_sci_resource if all went well else appropriate
2892 struct ti_sci_resource *
2893 devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
2894 struct udevice *dev, u32 dev_id, char *of_prop)
2896 u32 resource_subtype;
2898 struct ti_sci_resource *res;
2902 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
2904 return ERR_PTR(-ENOMEM);
2906 sets = dev_read_size(dev, of_prop);
2908 dev_err(dev, "%s resource type ids not available\n", of_prop);
2909 return ERR_PTR(sets);
2911 temp = malloc(sets);
2912 sets /= sizeof(u32);
2915 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
2918 return ERR_PTR(-ENOMEM);
2920 ret = ti_sci_get_resource_type(handle_to_ti_sci_info(handle), dev_id,
2923 dev_err(dev, "No valid resource type for %u\n", dev_id);
2924 return ERR_PTR(-EINVAL);
2927 ret = dev_read_u32_array(dev, of_prop, temp, res->sets);
2929 return ERR_PTR(-EINVAL);
2931 for (i = 0; i < res->sets; i++) {
2932 resource_subtype = temp[i];
2933 ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
2935 &res->desc[i].start,
2938 dev_err(dev, "type %d subtype %d not allocated for host %d\n",
2939 resource_type, resource_subtype,
2940 handle_to_ti_sci_info(handle)->host_id);
2941 return ERR_PTR(ret);
2944 dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n",
2945 resource_type, resource_subtype, res->desc[i].start,
2948 res->desc[i].res_map =
2949 devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) *
2950 sizeof(*res->desc[i].res_map), GFP_KERNEL);
2951 if (!res->desc[i].res_map)
2952 return ERR_PTR(-ENOMEM);
2958 /* Description for K2G */
2959 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = {
2960 .default_host_id = 2,
2961 /* Conservative duration */
2962 .max_rx_timeout_ms = 10000,
2963 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
2966 .rm_type_map = NULL,
2969 static struct ti_sci_rm_type_map ti_sci_am654_rm_type_map[] = {
2970 {.dev_id = 56, .type = 0x00b}, /* GIC_IRQ */
2971 {.dev_id = 179, .type = 0x000}, /* MAIN_NAV_UDMASS_IA0 */
2972 {.dev_id = 187, .type = 0x009}, /* MAIN_NAV_RA */
2973 {.dev_id = 188, .type = 0x006}, /* MAIN_NAV_UDMAP */
2974 {.dev_id = 194, .type = 0x007}, /* MCU_NAV_UDMAP */
2975 {.dev_id = 195, .type = 0x00a}, /* MCU_NAV_RA */
2976 {.dev_id = 0, .type = 0x000}, /* end of table */
2979 /* Description for AM654 */
2980 static const struct ti_sci_desc ti_sci_pmmc_am654_desc = {
2981 .default_host_id = 12,
2982 /* Conservative duration */
2983 .max_rx_timeout_ms = 10000,
2984 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
2987 .rm_type_map = ti_sci_am654_rm_type_map,
2990 static const struct udevice_id ti_sci_ids[] = {
2992 .compatible = "ti,k2g-sci",
2993 .data = (ulong)&ti_sci_pmmc_k2g_desc
2996 .compatible = "ti,am654-sci",
2997 .data = (ulong)&ti_sci_pmmc_am654_desc
3002 U_BOOT_DRIVER(ti_sci) = {
3004 .id = UCLASS_FIRMWARE,
3005 .of_match = ti_sci_ids,
3006 .probe = ti_sci_probe,
3007 .priv_auto_alloc_size = sizeof(struct ti_sci_info),