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 * 1000);
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,
261 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
262 (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr),
266 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
270 ret = ti_sci_do_xfer(info, xfer);
272 dev_err(info->dev, "Mbox communication fail %d\n", ret);
276 rev_info = (struct ti_sci_msg_resp_version *)xfer->tx_message.buf;
278 ver = &handle->version;
279 ver->abi_major = rev_info->abi_major;
280 ver->abi_minor = rev_info->abi_minor;
281 ver->firmware_revision = rev_info->firmware_revision;
282 strncpy(ver->firmware_description, rev_info->firmware_description,
283 sizeof(ver->firmware_description));
289 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
290 * @r: pointer to response buffer
292 * Return: true if the response was an ACK, else returns false.
294 static inline bool ti_sci_is_response_ack(void *r)
296 struct ti_sci_msg_hdr *hdr = r;
298 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false;
302 * cmd_set_board_config_using_msg() - Common command to send board configuration
304 * @handle: pointer to TI SCI handle
305 * @msg_type: One of the TISCI message types to set board configuration
306 * @addr: Address where the board config structure is located
307 * @size: Size of the board config structure
309 * Return: 0 if all went well, else returns appropriate error value.
311 static int cmd_set_board_config_using_msg(const struct ti_sci_handle *handle,
312 u16 msg_type, u64 addr, u32 size)
314 struct ti_sci_msg_board_config req;
315 struct ti_sci_msg_hdr *resp;
316 struct ti_sci_info *info;
317 struct ti_sci_xfer *xfer;
321 return PTR_ERR(handle);
325 info = handle_to_ti_sci_info(handle);
327 xfer = ti_sci_setup_one_xfer(info, msg_type,
328 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
329 (u32 *)&req, sizeof(req), sizeof(*resp));
332 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
335 req.boardcfgp_high = (addr >> 32) & 0xffffffff;
336 req.boardcfgp_low = addr & 0xffffffff;
337 req.boardcfg_size = size;
339 ret = ti_sci_do_xfer(info, xfer);
341 dev_err(info->dev, "Mbox send fail %d\n", ret);
345 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
347 if (!ti_sci_is_response_ack(resp))
354 * ti_sci_cmd_set_board_config() - Command to send board configuration message
355 * @handle: pointer to TI SCI handle
356 * @addr: Address where the board config structure is located
357 * @size: Size of the board config structure
359 * Return: 0 if all went well, else returns appropriate error value.
361 static int ti_sci_cmd_set_board_config(const struct ti_sci_handle *handle,
364 return cmd_set_board_config_using_msg(handle,
365 TI_SCI_MSG_BOARD_CONFIG,
370 * ti_sci_cmd_set_board_config_rm() - Command to send board resource
371 * management configuration
372 * @handle: pointer to TI SCI handle
373 * @addr: Address where the board RM config structure is located
374 * @size: Size of the RM config structure
376 * Return: 0 if all went well, else returns appropriate error value.
379 int ti_sci_cmd_set_board_config_rm(const struct ti_sci_handle *handle,
382 return cmd_set_board_config_using_msg(handle,
383 TI_SCI_MSG_BOARD_CONFIG_RM,
388 * ti_sci_cmd_set_board_config_security() - Command to send board security
389 * configuration message
390 * @handle: pointer to TI SCI handle
391 * @addr: Address where the board security config structure is located
392 * @size: Size of the security config structure
394 * Return: 0 if all went well, else returns appropriate error value.
397 int ti_sci_cmd_set_board_config_security(const struct ti_sci_handle *handle,
400 return cmd_set_board_config_using_msg(handle,
401 TI_SCI_MSG_BOARD_CONFIG_SECURITY,
406 * ti_sci_cmd_set_board_config_pm() - Command to send board power and clock
407 * configuration message
408 * @handle: pointer to TI SCI handle
409 * @addr: Address where the board PM config structure is located
410 * @size: Size of the PM config structure
412 * Return: 0 if all went well, else returns appropriate error value.
414 static int ti_sci_cmd_set_board_config_pm(const struct ti_sci_handle *handle,
417 return cmd_set_board_config_using_msg(handle,
418 TI_SCI_MSG_BOARD_CONFIG_PM,
423 * ti_sci_set_device_state() - Set device state helper
424 * @handle: pointer to TI SCI handle
425 * @id: Device identifier
426 * @flags: flags to setup for the device
427 * @state: State to move the device to
429 * Return: 0 if all went well, else returns appropriate error value.
431 static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
432 u32 id, u32 flags, u8 state)
434 struct ti_sci_msg_req_set_device_state req;
435 struct ti_sci_msg_hdr *resp;
436 struct ti_sci_info *info;
437 struct ti_sci_xfer *xfer;
441 return PTR_ERR(handle);
445 info = handle_to_ti_sci_info(handle);
447 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
448 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
449 (u32 *)&req, sizeof(req), sizeof(*resp));
452 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
458 ret = ti_sci_do_xfer(info, xfer);
460 dev_err(info->dev, "Mbox send fail %d\n", ret);
464 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
466 if (!ti_sci_is_response_ack(resp))
473 * ti_sci_get_device_state() - Get device state helper
474 * @handle: Handle to the device
475 * @id: Device Identifier
476 * @clcnt: Pointer to Context Loss Count
477 * @resets: pointer to resets
478 * @p_state: pointer to p_state
479 * @c_state: pointer to c_state
481 * Return: 0 if all went fine, else return appropriate error.
483 static int ti_sci_get_device_state(const struct ti_sci_handle *handle,
484 u32 id, u32 *clcnt, u32 *resets,
485 u8 *p_state, u8 *c_state)
487 struct ti_sci_msg_resp_get_device_state *resp;
488 struct ti_sci_msg_req_get_device_state req;
489 struct ti_sci_info *info;
490 struct ti_sci_xfer *xfer;
494 return PTR_ERR(handle);
498 if (!clcnt && !resets && !p_state && !c_state)
501 info = handle_to_ti_sci_info(handle);
503 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_DEVICE_STATE,
504 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
505 (u32 *)&req, sizeof(req), sizeof(*resp));
508 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
513 ret = ti_sci_do_xfer(info, xfer);
515 dev_err(dev, "Mbox send fail %d\n", ret);
519 resp = (struct ti_sci_msg_resp_get_device_state *)xfer->tx_message.buf;
520 if (!ti_sci_is_response_ack(resp))
524 *clcnt = resp->context_loss_count;
526 *resets = resp->resets;
528 *p_state = resp->programmed_state;
530 *c_state = resp->current_state;
536 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
537 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
538 * @id: Device Identifier
540 * Request for the device - NOTE: the client MUST maintain integrity of
541 * usage count by balancing get_device with put_device. No refcounting is
542 * managed by driver for that purpose.
544 * NOTE: The request is for exclusive access for the processor.
546 * Return: 0 if all went fine, else return appropriate error.
548 static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
550 return ti_sci_set_device_state(handle, id,
551 MSG_FLAG_DEVICE_EXCLUSIVE,
552 MSG_DEVICE_SW_STATE_ON);
556 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
557 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
558 * @id: Device Identifier
560 * Request for the device - NOTE: the client MUST maintain integrity of
561 * usage count by balancing get_device with put_device. No refcounting is
562 * managed by driver for that purpose.
564 * Return: 0 if all went fine, else return appropriate error.
566 static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
568 return ti_sci_set_device_state(handle, id,
569 MSG_FLAG_DEVICE_EXCLUSIVE,
570 MSG_DEVICE_SW_STATE_RETENTION);
574 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
575 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
576 * @id: Device Identifier
578 * Request for the device - NOTE: the client MUST maintain integrity of
579 * usage count by balancing get_device with put_device. No refcounting is
580 * managed by driver for that purpose.
582 * Return: 0 if all went fine, else return appropriate error.
584 static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
586 return ti_sci_set_device_state(handle, id,
587 0, MSG_DEVICE_SW_STATE_AUTO_OFF);
591 * ti_sci_cmd_dev_is_valid() - Is the device valid
592 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
593 * @id: Device Identifier
595 * Return: 0 if all went fine and the device ID is valid, else return
598 static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
602 /* check the device state which will also tell us if the ID is valid */
603 return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused);
607 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
608 * @handle: Pointer to TISCI handle
609 * @id: Device Identifier
610 * @count: Pointer to Context Loss counter to populate
612 * Return: 0 if all went fine, else return appropriate error.
614 static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
617 return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
621 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
622 * @handle: Pointer to TISCI handle
623 * @id: Device Identifier
624 * @r_state: true if requested to be idle
626 * Return: 0 if all went fine, else return appropriate error.
628 static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
637 ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
641 *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
647 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
648 * @handle: Pointer to TISCI handle
649 * @id: Device Identifier
650 * @r_state: true if requested to be stopped
651 * @curr_state: true if currently stopped.
653 * Return: 0 if all went fine, else return appropriate error.
655 static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
656 bool *r_state, bool *curr_state)
661 if (!r_state && !curr_state)
665 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
670 *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
672 *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
678 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
679 * @handle: Pointer to TISCI handle
680 * @id: Device Identifier
681 * @r_state: true if requested to be ON
682 * @curr_state: true if currently ON and active
684 * Return: 0 if all went fine, else return appropriate error.
686 static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
687 bool *r_state, bool *curr_state)
692 if (!r_state && !curr_state)
696 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
701 *r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
703 *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
709 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
710 * @handle: Pointer to TISCI handle
711 * @id: Device Identifier
712 * @curr_state: true if currently transitioning.
714 * Return: 0 if all went fine, else return appropriate error.
716 static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
725 ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
729 *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
735 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
737 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
738 * @id: Device Identifier
739 * @reset_state: Device specific reset bit field
741 * Return: 0 if all went fine, else return appropriate error.
743 static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
744 u32 id, u32 reset_state)
746 struct ti_sci_msg_req_set_device_resets req;
747 struct ti_sci_msg_hdr *resp;
748 struct ti_sci_info *info;
749 struct ti_sci_xfer *xfer;
753 return PTR_ERR(handle);
757 info = handle_to_ti_sci_info(handle);
759 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_RESETS,
760 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
761 (u32 *)&req, sizeof(req), sizeof(*resp));
764 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
768 req.resets = reset_state;
770 ret = ti_sci_do_xfer(info, xfer);
772 dev_err(info->dev, "Mbox send fail %d\n", ret);
776 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
778 if (!ti_sci_is_response_ack(resp))
785 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
787 * @handle: Pointer to TISCI handle
788 * @id: Device Identifier
789 * @reset_state: Pointer to reset state to populate
791 * Return: 0 if all went fine, else return appropriate error.
793 static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
794 u32 id, u32 *reset_state)
796 return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
801 * ti_sci_set_clock_state() - Set clock state helper
802 * @handle: pointer to TI SCI handle
803 * @dev_id: Device identifier this request is for
804 * @clk_id: Clock identifier for the device for this request.
805 * Each device has it's own set of clock inputs. This indexes
806 * which clock input to modify.
807 * @flags: Header flags as needed
808 * @state: State to request for the clock.
810 * Return: 0 if all went well, else returns appropriate error value.
812 static int ti_sci_set_clock_state(const struct ti_sci_handle *handle,
813 u32 dev_id, u8 clk_id,
816 struct ti_sci_msg_req_set_clock_state req;
817 struct ti_sci_msg_hdr *resp;
818 struct ti_sci_info *info;
819 struct ti_sci_xfer *xfer;
823 return PTR_ERR(handle);
827 info = handle_to_ti_sci_info(handle);
829 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_STATE,
830 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
831 (u32 *)&req, sizeof(req), sizeof(*resp));
834 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
839 req.request_state = state;
841 ret = ti_sci_do_xfer(info, xfer);
843 dev_err(info->dev, "Mbox send fail %d\n", ret);
847 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
849 if (!ti_sci_is_response_ack(resp))
856 * ti_sci_cmd_get_clock_state() - Get clock state helper
857 * @handle: pointer to TI SCI handle
858 * @dev_id: Device identifier this request is for
859 * @clk_id: Clock identifier for the device for this request.
860 * Each device has it's own set of clock inputs. This indexes
861 * which clock input to modify.
862 * @programmed_state: State requested for clock to move to
863 * @current_state: State that the clock is currently in
865 * Return: 0 if all went well, else returns appropriate error value.
867 static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle *handle,
868 u32 dev_id, u8 clk_id,
869 u8 *programmed_state, u8 *current_state)
871 struct ti_sci_msg_resp_get_clock_state *resp;
872 struct ti_sci_msg_req_get_clock_state req;
873 struct ti_sci_info *info;
874 struct ti_sci_xfer *xfer;
878 return PTR_ERR(handle);
882 if (!programmed_state && !current_state)
885 info = handle_to_ti_sci_info(handle);
887 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_STATE,
888 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
889 (u32 *)&req, sizeof(req), sizeof(*resp));
892 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
898 ret = ti_sci_do_xfer(info, xfer);
900 dev_err(info->dev, "Mbox send fail %d\n", ret);
904 resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->tx_message.buf;
906 if (!ti_sci_is_response_ack(resp))
909 if (programmed_state)
910 *programmed_state = resp->programmed_state;
912 *current_state = resp->current_state;
918 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
919 * @handle: pointer to TI SCI handle
920 * @dev_id: Device identifier this request is for
921 * @clk_id: Clock identifier for the device for this request.
922 * Each device has it's own set of clock inputs. This indexes
923 * which clock input to modify.
924 * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false'
925 * @can_change_freq: 'true' if frequency change is desired, else 'false'
926 * @enable_input_term: 'true' if input termination is desired, else 'false'
928 * Return: 0 if all went well, else returns appropriate error value.
930 static int ti_sci_cmd_get_clock(const struct ti_sci_handle *handle, u32 dev_id,
931 u8 clk_id, bool needs_ssc, bool can_change_freq,
932 bool enable_input_term)
936 flags |= needs_ssc ? MSG_FLAG_CLOCK_ALLOW_SSC : 0;
937 flags |= can_change_freq ? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE : 0;
938 flags |= enable_input_term ? MSG_FLAG_CLOCK_INPUT_TERM : 0;
940 return ti_sci_set_clock_state(handle, dev_id, clk_id, flags,
941 MSG_CLOCK_SW_STATE_REQ);
945 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
946 * @handle: pointer to TI SCI handle
947 * @dev_id: Device identifier this request is for
948 * @clk_id: Clock identifier for the device for this request.
949 * Each device has it's own set of clock inputs. This indexes
950 * which clock input to modify.
952 * NOTE: This clock must have been requested by get_clock previously.
954 * Return: 0 if all went well, else returns appropriate error value.
956 static int ti_sci_cmd_idle_clock(const struct ti_sci_handle *handle,
957 u32 dev_id, u8 clk_id)
959 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
960 MSG_CLOCK_SW_STATE_UNREQ);
964 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
965 * @handle: pointer to TI SCI handle
966 * @dev_id: Device identifier this request is for
967 * @clk_id: Clock identifier for the device for this request.
968 * Each device has it's own set of clock inputs. This indexes
969 * which clock input to modify.
971 * NOTE: This clock must have been requested by get_clock previously.
973 * Return: 0 if all went well, else returns appropriate error value.
975 static int ti_sci_cmd_put_clock(const struct ti_sci_handle *handle,
976 u32 dev_id, u8 clk_id)
978 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
979 MSG_CLOCK_SW_STATE_AUTO);
983 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
984 * @handle: pointer to TI SCI handle
985 * @dev_id: Device identifier this request is for
986 * @clk_id: Clock identifier for the device for this request.
987 * Each device has it's own set of clock inputs. This indexes
988 * which clock input to modify.
989 * @req_state: state indicating if the clock is auto managed
991 * Return: 0 if all went well, else returns appropriate error value.
993 static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle *handle,
994 u32 dev_id, u8 clk_id, bool *req_state)
1002 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, &state, NULL);
1006 *req_state = (state == MSG_CLOCK_SW_STATE_AUTO);
1011 * ti_sci_cmd_clk_is_on() - Is the clock ON
1012 * @handle: pointer to TI SCI handle
1013 * @dev_id: Device identifier this request is for
1014 * @clk_id: Clock identifier for the device for this request.
1015 * Each device has it's own set of clock inputs. This indexes
1016 * which clock input to modify.
1017 * @req_state: state indicating if the clock is managed by us and enabled
1018 * @curr_state: state indicating if the clock is ready for operation
1020 * Return: 0 if all went well, else returns appropriate error value.
1022 static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle *handle, u32 dev_id,
1023 u8 clk_id, bool *req_state, bool *curr_state)
1025 u8 c_state = 0, r_state = 0;
1028 if (!req_state && !curr_state)
1031 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1032 &r_state, &c_state);
1037 *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ);
1039 *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY);
1044 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1045 * @handle: pointer to TI SCI handle
1046 * @dev_id: Device identifier this request is for
1047 * @clk_id: Clock identifier for the device for this request.
1048 * Each device has it's own set of clock inputs. This indexes
1049 * which clock input to modify.
1050 * @req_state: state indicating if the clock is managed by us and disabled
1051 * @curr_state: state indicating if the clock is NOT ready for operation
1053 * Return: 0 if all went well, else returns appropriate error value.
1055 static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle *handle, u32 dev_id,
1056 u8 clk_id, bool *req_state, bool *curr_state)
1058 u8 c_state = 0, r_state = 0;
1061 if (!req_state && !curr_state)
1064 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1065 &r_state, &c_state);
1070 *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ);
1072 *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY);
1077 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1078 * @handle: pointer to TI SCI handle
1079 * @dev_id: Device identifier this request is for
1080 * @clk_id: Clock identifier for the device for this request.
1081 * Each device has it's own set of clock inputs. This indexes
1082 * which clock input to modify.
1083 * @parent_id: Parent clock identifier to set
1085 * Return: 0 if all went well, else returns appropriate error value.
1087 static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle *handle,
1088 u32 dev_id, u8 clk_id, u8 parent_id)
1090 struct ti_sci_msg_req_set_clock_parent req;
1091 struct ti_sci_msg_hdr *resp;
1092 struct ti_sci_info *info;
1093 struct ti_sci_xfer *xfer;
1097 return PTR_ERR(handle);
1101 info = handle_to_ti_sci_info(handle);
1103 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_PARENT,
1104 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1105 (u32 *)&req, sizeof(req), sizeof(*resp));
1107 ret = PTR_ERR(xfer);
1108 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1111 req.dev_id = dev_id;
1112 req.clk_id = clk_id;
1113 req.parent_id = parent_id;
1115 ret = ti_sci_do_xfer(info, xfer);
1117 dev_err(info->dev, "Mbox send fail %d\n", ret);
1121 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1123 if (!ti_sci_is_response_ack(resp))
1130 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1131 * @handle: pointer to TI SCI handle
1132 * @dev_id: Device identifier this request is for
1133 * @clk_id: Clock identifier for the device for this request.
1134 * Each device has it's own set of clock inputs. This indexes
1135 * which clock input to modify.
1136 * @parent_id: Current clock parent
1138 * Return: 0 if all went well, else returns appropriate error value.
1140 static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle,
1141 u32 dev_id, u8 clk_id, u8 *parent_id)
1143 struct ti_sci_msg_resp_get_clock_parent *resp;
1144 struct ti_sci_msg_req_get_clock_parent req;
1145 struct ti_sci_info *info;
1146 struct ti_sci_xfer *xfer;
1150 return PTR_ERR(handle);
1151 if (!handle || !parent_id)
1154 info = handle_to_ti_sci_info(handle);
1156 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_PARENT,
1157 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1158 (u32 *)&req, sizeof(req), sizeof(*resp));
1160 ret = PTR_ERR(xfer);
1161 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1164 req.dev_id = dev_id;
1165 req.clk_id = clk_id;
1167 ret = ti_sci_do_xfer(info, xfer);
1169 dev_err(info->dev, "Mbox send fail %d\n", ret);
1173 resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->tx_message.buf;
1175 if (!ti_sci_is_response_ack(resp))
1178 *parent_id = resp->parent_id;
1184 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1185 * @handle: pointer to TI SCI handle
1186 * @dev_id: Device identifier this request is for
1187 * @clk_id: Clock identifier for the device for this request.
1188 * Each device has it's own set of clock inputs. This indexes
1189 * which clock input to modify.
1190 * @num_parents: Returns he number of parents to the current clock.
1192 * Return: 0 if all went well, else returns appropriate error value.
1194 static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle *handle,
1195 u32 dev_id, u8 clk_id,
1198 struct ti_sci_msg_resp_get_clock_num_parents *resp;
1199 struct ti_sci_msg_req_get_clock_num_parents req;
1200 struct ti_sci_info *info;
1201 struct ti_sci_xfer *xfer;
1205 return PTR_ERR(handle);
1206 if (!handle || !num_parents)
1209 info = handle_to_ti_sci_info(handle);
1211 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS,
1212 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1213 (u32 *)&req, sizeof(req), sizeof(*resp));
1215 ret = PTR_ERR(xfer);
1216 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1219 req.dev_id = dev_id;
1220 req.clk_id = clk_id;
1222 ret = ti_sci_do_xfer(info, xfer);
1224 dev_err(info->dev, "Mbox send fail %d\n", ret);
1228 resp = (struct ti_sci_msg_resp_get_clock_num_parents *)
1229 xfer->tx_message.buf;
1231 if (!ti_sci_is_response_ack(resp))
1234 *num_parents = resp->num_parents;
1240 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1241 * @handle: pointer to TI SCI handle
1242 * @dev_id: Device identifier this request is for
1243 * @clk_id: Clock identifier for the device for this request.
1244 * Each device has it's own set of clock inputs. This indexes
1245 * which clock input to modify.
1246 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1247 * allowable programmed frequency and does not account for clock
1248 * tolerances and jitter.
1249 * @target_freq: The target clock frequency in Hz. A frequency will be
1250 * processed as close to this target frequency as possible.
1251 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1252 * allowable programmed frequency and does not account for clock
1253 * tolerances and jitter.
1254 * @match_freq: Frequency match in Hz response.
1256 * Return: 0 if all went well, else returns appropriate error value.
1258 static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle *handle,
1259 u32 dev_id, u8 clk_id, u64 min_freq,
1260 u64 target_freq, u64 max_freq,
1263 struct ti_sci_msg_resp_query_clock_freq *resp;
1264 struct ti_sci_msg_req_query_clock_freq req;
1265 struct ti_sci_info *info;
1266 struct ti_sci_xfer *xfer;
1270 return PTR_ERR(handle);
1271 if (!handle || !match_freq)
1274 info = handle_to_ti_sci_info(handle);
1276 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_QUERY_CLOCK_FREQ,
1277 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1278 (u32 *)&req, sizeof(req), sizeof(*resp));
1280 ret = PTR_ERR(xfer);
1281 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1284 req.dev_id = dev_id;
1285 req.clk_id = clk_id;
1286 req.min_freq_hz = min_freq;
1287 req.target_freq_hz = target_freq;
1288 req.max_freq_hz = max_freq;
1290 ret = ti_sci_do_xfer(info, xfer);
1292 dev_err(info->dev, "Mbox send fail %d\n", ret);
1296 resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->tx_message.buf;
1298 if (!ti_sci_is_response_ack(resp))
1301 *match_freq = resp->freq_hz;
1307 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1308 * @handle: pointer to TI SCI handle
1309 * @dev_id: Device identifier this request is for
1310 * @clk_id: Clock identifier for the device for this request.
1311 * Each device has it's own set of clock inputs. This indexes
1312 * which clock input to modify.
1313 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1314 * allowable programmed frequency and does not account for clock
1315 * tolerances and jitter.
1316 * @target_freq: The target clock frequency in Hz. A frequency will be
1317 * processed as close to this target frequency as possible.
1318 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1319 * allowable programmed frequency and does not account for clock
1320 * tolerances and jitter.
1322 * Return: 0 if all went well, else returns appropriate error value.
1324 static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle *handle,
1325 u32 dev_id, u8 clk_id, u64 min_freq,
1326 u64 target_freq, u64 max_freq)
1328 struct ti_sci_msg_req_set_clock_freq req;
1329 struct ti_sci_msg_hdr *resp;
1330 struct ti_sci_info *info;
1331 struct ti_sci_xfer *xfer;
1335 return PTR_ERR(handle);
1339 info = handle_to_ti_sci_info(handle);
1341 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_FREQ,
1342 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1343 (u32 *)&req, sizeof(req), sizeof(*resp));
1345 ret = PTR_ERR(xfer);
1346 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1349 req.dev_id = dev_id;
1350 req.clk_id = clk_id;
1351 req.min_freq_hz = min_freq;
1352 req.target_freq_hz = target_freq;
1353 req.max_freq_hz = max_freq;
1355 ret = ti_sci_do_xfer(info, xfer);
1357 dev_err(info->dev, "Mbox send fail %d\n", ret);
1361 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1363 if (!ti_sci_is_response_ack(resp))
1370 * ti_sci_cmd_clk_get_freq() - Get current frequency
1371 * @handle: pointer to TI SCI handle
1372 * @dev_id: Device identifier this request is for
1373 * @clk_id: Clock identifier for the device for this request.
1374 * Each device has it's own set of clock inputs. This indexes
1375 * which clock input to modify.
1376 * @freq: Currently frequency in Hz
1378 * Return: 0 if all went well, else returns appropriate error value.
1380 static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle,
1381 u32 dev_id, u8 clk_id, u64 *freq)
1383 struct ti_sci_msg_resp_get_clock_freq *resp;
1384 struct ti_sci_msg_req_get_clock_freq req;
1385 struct ti_sci_info *info;
1386 struct ti_sci_xfer *xfer;
1390 return PTR_ERR(handle);
1391 if (!handle || !freq)
1394 info = handle_to_ti_sci_info(handle);
1396 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_FREQ,
1397 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1398 (u32 *)&req, sizeof(req), sizeof(*resp));
1400 ret = PTR_ERR(xfer);
1401 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1404 req.dev_id = dev_id;
1405 req.clk_id = clk_id;
1407 ret = ti_sci_do_xfer(info, xfer);
1409 dev_err(info->dev, "Mbox send fail %d\n", ret);
1413 resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->tx_message.buf;
1415 if (!ti_sci_is_response_ack(resp))
1418 *freq = resp->freq_hz;
1424 * ti_sci_cmd_core_reboot() - Command to request system reset
1425 * @handle: pointer to TI SCI handle
1427 * Return: 0 if all went well, else returns appropriate error value.
1429 static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle)
1431 struct ti_sci_msg_req_reboot req;
1432 struct ti_sci_msg_hdr *resp;
1433 struct ti_sci_info *info;
1434 struct ti_sci_xfer *xfer;
1438 return PTR_ERR(handle);
1442 info = handle_to_ti_sci_info(handle);
1444 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SYS_RESET,
1445 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1446 (u32 *)&req, sizeof(req), sizeof(*resp));
1448 ret = PTR_ERR(xfer);
1449 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1453 ret = ti_sci_do_xfer(info, xfer);
1455 dev_err(dev, "Mbox send fail %d\n", ret);
1459 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1461 if (!ti_sci_is_response_ack(resp))
1467 static int ti_sci_get_resource_type(struct ti_sci_info *info, u16 dev_id,
1470 struct ti_sci_rm_type_map *rm_type_map = info->desc->rm_type_map;
1474 /* If map is not provided then assume dev_id is used as type */
1480 for (i = 0; rm_type_map[i].dev_id; i++) {
1481 if (rm_type_map[i].dev_id == dev_id) {
1482 *type = rm_type_map[i].type;
1495 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1496 * to a host. Resource is uniquely identified by
1498 * @handle: Pointer to TISCI handle.
1499 * @dev_id: TISCI device ID.
1500 * @subtype: Resource assignment subtype that is being requested
1501 * from the given device.
1502 * @s_host: Host processor ID to which the resources are allocated
1503 * @range_start: Start index of the resource range
1504 * @range_num: Number of resources in the range
1506 * Return: 0 if all went fine, else return appropriate error.
1508 static int ti_sci_get_resource_range(const struct ti_sci_handle *handle,
1509 u32 dev_id, u8 subtype, u8 s_host,
1510 u16 *range_start, u16 *range_num)
1512 struct ti_sci_msg_resp_get_resource_range *resp;
1513 struct ti_sci_msg_req_get_resource_range req;
1514 struct ti_sci_xfer *xfer;
1515 struct ti_sci_info *info;
1520 return PTR_ERR(handle);
1524 info = handle_to_ti_sci_info(handle);
1526 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE,
1527 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1528 (u32 *)&req, sizeof(req), sizeof(*resp));
1530 ret = PTR_ERR(xfer);
1531 dev_err(dev, "Message alloc failed(%d)\n", ret);
1535 ret = ti_sci_get_resource_type(info, dev_id, &type);
1537 dev_err(dev, "rm type lookup failed for %u\n", dev_id);
1541 req.secondary_host = s_host;
1542 req.type = type & MSG_RM_RESOURCE_TYPE_MASK;
1543 req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK;
1545 ret = ti_sci_do_xfer(info, xfer);
1547 dev_err(dev, "Mbox send fail %d\n", ret);
1551 resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->tx_message.buf;
1552 if (!ti_sci_is_response_ack(resp)) {
1554 } else if (!resp->range_start && !resp->range_num) {
1557 *range_start = resp->range_start;
1558 *range_num = resp->range_num;
1566 * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1567 * that is same as ti sci interface host.
1568 * @handle: Pointer to TISCI handle.
1569 * @dev_id: TISCI device ID.
1570 * @subtype: Resource assignment subtype that is being requested
1571 * from the given device.
1572 * @range_start: Start index of the resource range
1573 * @range_num: Number of resources in the range
1575 * Return: 0 if all went fine, else return appropriate error.
1577 static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle,
1578 u32 dev_id, u8 subtype,
1579 u16 *range_start, u16 *range_num)
1581 return ti_sci_get_resource_range(handle, dev_id, subtype,
1582 TI_SCI_IRQ_SECONDARY_HOST_INVALID,
1583 range_start, range_num);
1587 * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1588 * assigned to a specified host.
1589 * @handle: Pointer to TISCI handle.
1590 * @dev_id: TISCI device ID.
1591 * @subtype: Resource assignment subtype that is being requested
1592 * from the given device.
1593 * @s_host: Host processor ID to which the resources are allocated
1594 * @range_start: Start index of the resource range
1595 * @range_num: Number of resources in the range
1597 * Return: 0 if all went fine, else return appropriate error.
1600 int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle,
1601 u32 dev_id, u8 subtype, u8 s_host,
1602 u16 *range_start, u16 *range_num)
1604 return ti_sci_get_resource_range(handle, dev_id, subtype, s_host,
1605 range_start, range_num);
1609 * ti_sci_cmd_query_msmc() - Command to query currently available msmc memory
1610 * @handle: pointer to TI SCI handle
1611 * @msms_start: MSMC start as returned by tisci
1612 * @msmc_end: MSMC end as returned by tisci
1614 * Return: 0 if all went well, else returns appropriate error value.
1616 static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle,
1617 u64 *msmc_start, u64 *msmc_end)
1619 struct ti_sci_msg_resp_query_msmc *resp;
1620 struct ti_sci_msg_hdr req;
1621 struct ti_sci_info *info;
1622 struct ti_sci_xfer *xfer;
1626 return PTR_ERR(handle);
1630 info = handle_to_ti_sci_info(handle);
1632 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_QUERY_MSMC,
1633 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1634 (u32 *)&req, sizeof(req), sizeof(*resp));
1636 ret = PTR_ERR(xfer);
1637 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1641 ret = ti_sci_do_xfer(info, xfer);
1643 dev_err(dev, "Mbox send fail %d\n", ret);
1647 resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf;
1649 if (!ti_sci_is_response_ack(resp))
1652 *msmc_start = ((u64)resp->msmc_start_high << TISCI_ADDR_HIGH_SHIFT) |
1653 resp->msmc_start_low;
1654 *msmc_end = ((u64)resp->msmc_end_high << TISCI_ADDR_HIGH_SHIFT) |
1661 * ti_sci_cmd_proc_request() - Command to request a physical processor control
1662 * @handle: Pointer to TI SCI handle
1663 * @proc_id: Processor ID this request is for
1665 * Return: 0 if all went well, else returns appropriate error value.
1667 static int ti_sci_cmd_proc_request(const struct ti_sci_handle *handle,
1670 struct ti_sci_msg_req_proc_request req;
1671 struct ti_sci_msg_hdr *resp;
1672 struct ti_sci_info *info;
1673 struct ti_sci_xfer *xfer;
1677 return PTR_ERR(handle);
1681 info = handle_to_ti_sci_info(handle);
1683 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_REQUEST,
1684 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1685 (u32 *)&req, sizeof(req), sizeof(*resp));
1687 ret = PTR_ERR(xfer);
1688 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1691 req.processor_id = proc_id;
1693 ret = ti_sci_do_xfer(info, xfer);
1695 dev_err(info->dev, "Mbox send fail %d\n", ret);
1699 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1701 if (!ti_sci_is_response_ack(resp))
1708 * ti_sci_cmd_proc_release() - Command to release a physical processor control
1709 * @handle: Pointer to TI SCI handle
1710 * @proc_id: Processor ID this request is for
1712 * Return: 0 if all went well, else returns appropriate error value.
1714 static int ti_sci_cmd_proc_release(const struct ti_sci_handle *handle,
1717 struct ti_sci_msg_req_proc_release req;
1718 struct ti_sci_msg_hdr *resp;
1719 struct ti_sci_info *info;
1720 struct ti_sci_xfer *xfer;
1724 return PTR_ERR(handle);
1728 info = handle_to_ti_sci_info(handle);
1730 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_RELEASE,
1731 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1732 (u32 *)&req, sizeof(req), sizeof(*resp));
1734 ret = PTR_ERR(xfer);
1735 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1738 req.processor_id = proc_id;
1740 ret = ti_sci_do_xfer(info, xfer);
1742 dev_err(info->dev, "Mbox send fail %d\n", ret);
1746 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1748 if (!ti_sci_is_response_ack(resp))
1755 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
1756 * control to a host in the processor's access
1758 * @handle: Pointer to TI SCI handle
1759 * @proc_id: Processor ID this request is for
1760 * @host_id: Host ID to get the control of the processor
1762 * Return: 0 if all went well, else returns appropriate error value.
1764 static int ti_sci_cmd_proc_handover(const struct ti_sci_handle *handle,
1765 u8 proc_id, u8 host_id)
1767 struct ti_sci_msg_req_proc_handover req;
1768 struct ti_sci_msg_hdr *resp;
1769 struct ti_sci_info *info;
1770 struct ti_sci_xfer *xfer;
1774 return PTR_ERR(handle);
1778 info = handle_to_ti_sci_info(handle);
1780 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_HANDOVER,
1781 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1782 (u32 *)&req, sizeof(req), sizeof(*resp));
1784 ret = PTR_ERR(xfer);
1785 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1788 req.processor_id = proc_id;
1789 req.host_id = host_id;
1791 ret = ti_sci_do_xfer(info, xfer);
1793 dev_err(info->dev, "Mbox send fail %d\n", ret);
1797 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1799 if (!ti_sci_is_response_ack(resp))
1806 * ti_sci_cmd_set_proc_boot_cfg() - Command to set the processor boot
1807 * configuration flags
1808 * @handle: Pointer to TI SCI handle
1809 * @proc_id: Processor ID this request is for
1810 * @config_flags_set: Configuration flags to be set
1811 * @config_flags_clear: Configuration flags to be cleared.
1813 * Return: 0 if all went well, else returns appropriate error value.
1815 static int ti_sci_cmd_set_proc_boot_cfg(const struct ti_sci_handle *handle,
1816 u8 proc_id, u64 bootvector,
1817 u32 config_flags_set,
1818 u32 config_flags_clear)
1820 struct ti_sci_msg_req_set_proc_boot_config req;
1821 struct ti_sci_msg_hdr *resp;
1822 struct ti_sci_info *info;
1823 struct ti_sci_xfer *xfer;
1827 return PTR_ERR(handle);
1831 info = handle_to_ti_sci_info(handle);
1833 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CONFIG,
1834 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1835 (u32 *)&req, sizeof(req), sizeof(*resp));
1837 ret = PTR_ERR(xfer);
1838 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1841 req.processor_id = proc_id;
1842 req.bootvector_low = bootvector & TISCI_ADDR_LOW_MASK;
1843 req.bootvector_high = (bootvector & TISCI_ADDR_HIGH_MASK) >>
1844 TISCI_ADDR_HIGH_SHIFT;
1845 req.config_flags_set = config_flags_set;
1846 req.config_flags_clear = config_flags_clear;
1848 ret = ti_sci_do_xfer(info, xfer);
1850 dev_err(info->dev, "Mbox send fail %d\n", ret);
1854 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1856 if (!ti_sci_is_response_ack(resp))
1863 * ti_sci_cmd_set_proc_boot_ctrl() - Command to set the processor boot
1865 * @handle: Pointer to TI SCI handle
1866 * @proc_id: Processor ID this request is for
1867 * @control_flags_set: Control flags to be set
1868 * @control_flags_clear: Control flags to be cleared
1870 * Return: 0 if all went well, else returns appropriate error value.
1872 static int ti_sci_cmd_set_proc_boot_ctrl(const struct ti_sci_handle *handle,
1873 u8 proc_id, u32 control_flags_set,
1874 u32 control_flags_clear)
1876 struct ti_sci_msg_req_set_proc_boot_ctrl req;
1877 struct ti_sci_msg_hdr *resp;
1878 struct ti_sci_info *info;
1879 struct ti_sci_xfer *xfer;
1883 return PTR_ERR(handle);
1887 info = handle_to_ti_sci_info(handle);
1889 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CTRL,
1890 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1891 (u32 *)&req, sizeof(req), sizeof(*resp));
1893 ret = PTR_ERR(xfer);
1894 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1897 req.processor_id = proc_id;
1898 req.control_flags_set = control_flags_set;
1899 req.control_flags_clear = control_flags_clear;
1901 ret = ti_sci_do_xfer(info, xfer);
1903 dev_err(info->dev, "Mbox send fail %d\n", ret);
1907 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
1909 if (!ti_sci_is_response_ack(resp))
1916 * ti_sci_cmd_proc_auth_boot_image() - Command to authenticate and load the
1917 * image and then set the processor configuration flags.
1918 * @handle: Pointer to TI SCI handle
1919 * @image_addr: Memory address at which payload image and certificate is
1920 * located in memory, this is updated if the image data is
1921 * moved during authentication.
1922 * @image_size: This is updated with the final size of the image after
1925 * Return: 0 if all went well, else returns appropriate error value.
1927 static int ti_sci_cmd_proc_auth_boot_image(const struct ti_sci_handle *handle,
1928 u64 *image_addr, u32 *image_size)
1930 struct ti_sci_msg_req_proc_auth_boot_image req;
1931 struct ti_sci_msg_resp_proc_auth_boot_image *resp;
1932 struct ti_sci_info *info;
1933 struct ti_sci_xfer *xfer;
1937 return PTR_ERR(handle);
1941 info = handle_to_ti_sci_info(handle);
1943 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_AUTH_BOOT_IMIAGE,
1944 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1945 (u32 *)&req, sizeof(req), sizeof(*resp));
1947 ret = PTR_ERR(xfer);
1948 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
1951 req.cert_addr_low = *image_addr & TISCI_ADDR_LOW_MASK;
1952 req.cert_addr_high = (*image_addr & TISCI_ADDR_HIGH_MASK) >>
1953 TISCI_ADDR_HIGH_SHIFT;
1955 ret = ti_sci_do_xfer(info, xfer);
1957 dev_err(info->dev, "Mbox send fail %d\n", ret);
1961 resp = (struct ti_sci_msg_resp_proc_auth_boot_image *)xfer->tx_message.buf;
1963 if (!ti_sci_is_response_ack(resp))
1966 *image_addr = (resp->image_addr_low & TISCI_ADDR_LOW_MASK) |
1967 (((u64)resp->image_addr_high <<
1968 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
1969 *image_size = resp->image_size;
1975 * ti_sci_cmd_get_proc_boot_status() - Command to get the processor boot status
1976 * @handle: Pointer to TI SCI handle
1977 * @proc_id: Processor ID this request is for
1979 * Return: 0 if all went well, else returns appropriate error value.
1981 static int ti_sci_cmd_get_proc_boot_status(const struct ti_sci_handle *handle,
1982 u8 proc_id, u64 *bv, u32 *cfg_flags,
1983 u32 *ctrl_flags, u32 *sts_flags)
1985 struct ti_sci_msg_resp_get_proc_boot_status *resp;
1986 struct ti_sci_msg_req_get_proc_boot_status req;
1987 struct ti_sci_info *info;
1988 struct ti_sci_xfer *xfer;
1992 return PTR_ERR(handle);
1996 info = handle_to_ti_sci_info(handle);
1998 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_GET_PROC_BOOT_STATUS,
1999 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2000 (u32 *)&req, sizeof(req), sizeof(*resp));
2002 ret = PTR_ERR(xfer);
2003 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2006 req.processor_id = proc_id;
2008 ret = ti_sci_do_xfer(info, xfer);
2010 dev_err(info->dev, "Mbox send fail %d\n", ret);
2014 resp = (struct ti_sci_msg_resp_get_proc_boot_status *)
2015 xfer->tx_message.buf;
2017 if (!ti_sci_is_response_ack(resp))
2019 *bv = (resp->bootvector_low & TISCI_ADDR_LOW_MASK) |
2020 (((u64)resp->bootvector_high <<
2021 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2022 *cfg_flags = resp->config_flags;
2023 *ctrl_flags = resp->control_flags;
2024 *sts_flags = resp->status_flags;
2030 * ti_sci_cmd_ring_config() - configure RA ring
2031 * @handle: pointer to TI SCI handle
2032 * @valid_params: Bitfield defining validity of ring configuration parameters.
2033 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2034 * @index: Ring index.
2035 * @addr_lo: The ring base address lo 32 bits
2036 * @addr_hi: The ring base address hi 32 bits
2037 * @count: Number of ring elements.
2038 * @mode: The mode of the ring
2039 * @size: The ring element size.
2040 * @order_id: Specifies the ring's bus order ID.
2042 * Return: 0 if all went well, else returns appropriate error value.
2044 * See @ti_sci_msg_rm_ring_cfg_req for more info.
2046 static int ti_sci_cmd_ring_config(const struct ti_sci_handle *handle,
2047 u32 valid_params, u16 nav_id, u16 index,
2048 u32 addr_lo, u32 addr_hi, u32 count,
2049 u8 mode, u8 size, u8 order_id)
2051 struct ti_sci_msg_rm_ring_cfg_resp *resp;
2052 struct ti_sci_msg_rm_ring_cfg_req req;
2053 struct ti_sci_xfer *xfer;
2054 struct ti_sci_info *info;
2058 return PTR_ERR(handle);
2062 info = handle_to_ti_sci_info(handle);
2064 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_CFG,
2065 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2066 (u32 *)&req, sizeof(req), sizeof(*resp));
2068 ret = PTR_ERR(xfer);
2069 dev_err(info->dev, "RM_RA:Message config failed(%d)\n", ret);
2072 req.valid_params = valid_params;
2073 req.nav_id = nav_id;
2075 req.addr_lo = addr_lo;
2076 req.addr_hi = addr_hi;
2080 req.order_id = order_id;
2082 ret = ti_sci_do_xfer(info, xfer);
2084 dev_err(info->dev, "RM_RA:Mbox config send fail %d\n", ret);
2088 resp = (struct ti_sci_msg_rm_ring_cfg_resp *)xfer->tx_message.buf;
2090 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2093 dev_dbg(info->dev, "RM_RA:config ring %u ret:%d\n", index, ret);
2098 * ti_sci_cmd_ring_get_config() - get RA ring configuration
2099 * @handle: pointer to TI SCI handle
2100 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2101 * @index: Ring index.
2102 * @addr_lo: returns ring's base address lo 32 bits
2103 * @addr_hi: returns ring's base address hi 32 bits
2104 * @count: returns number of ring elements.
2105 * @mode: returns mode of the ring
2106 * @size: returns ring element size.
2107 * @order_id: returns ring's bus order ID.
2109 * Return: 0 if all went well, else returns appropriate error value.
2111 * See @ti_sci_msg_rm_ring_get_cfg_req for more info.
2113 static int ti_sci_cmd_ring_get_config(const struct ti_sci_handle *handle,
2114 u32 nav_id, u32 index, u8 *mode,
2115 u32 *addr_lo, u32 *addr_hi,
2116 u32 *count, u8 *size, u8 *order_id)
2118 struct ti_sci_msg_rm_ring_get_cfg_resp *resp;
2119 struct ti_sci_msg_rm_ring_get_cfg_req req;
2120 struct ti_sci_xfer *xfer;
2121 struct ti_sci_info *info;
2125 return PTR_ERR(handle);
2129 info = handle_to_ti_sci_info(handle);
2131 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_GET_CFG,
2132 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2133 (u32 *)&req, sizeof(req), sizeof(*resp));
2135 ret = PTR_ERR(xfer);
2137 "RM_RA:Message get config failed(%d)\n", ret);
2140 req.nav_id = nav_id;
2143 ret = ti_sci_do_xfer(info, xfer);
2145 dev_err(info->dev, "RM_RA:Mbox get config send fail %d\n", ret);
2149 resp = (struct ti_sci_msg_rm_ring_get_cfg_resp *)xfer->tx_message.buf;
2151 if (!ti_sci_is_response_ack(resp)) {
2157 *addr_lo = resp->addr_lo;
2159 *addr_hi = resp->addr_hi;
2161 *count = resp->count;
2165 *order_id = resp->order_id;
2169 dev_dbg(info->dev, "RM_RA:get config ring %u ret:%d\n", index, ret);
2173 static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle *handle,
2174 u32 nav_id, u32 src_thread, u32 dst_thread)
2176 struct ti_sci_msg_hdr *resp;
2177 struct ti_sci_msg_psil_pair req;
2178 struct ti_sci_xfer *xfer;
2179 struct ti_sci_info *info;
2183 return PTR_ERR(handle);
2187 info = handle_to_ti_sci_info(handle);
2189 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_PAIR,
2190 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2191 (u32 *)&req, sizeof(req), sizeof(*resp));
2193 ret = PTR_ERR(xfer);
2194 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2197 req.nav_id = nav_id;
2198 req.src_thread = src_thread;
2199 req.dst_thread = dst_thread;
2201 ret = ti_sci_do_xfer(info, xfer);
2203 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2207 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2208 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2211 dev_dbg(info->dev, "RM_PSIL: nav: %u link pair %u->%u ret:%u\n",
2212 nav_id, src_thread, dst_thread, ret);
2216 static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle *handle,
2217 u32 nav_id, u32 src_thread, u32 dst_thread)
2219 struct ti_sci_msg_hdr *resp;
2220 struct ti_sci_msg_psil_unpair req;
2221 struct ti_sci_xfer *xfer;
2222 struct ti_sci_info *info;
2226 return PTR_ERR(handle);
2230 info = handle_to_ti_sci_info(handle);
2232 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_UNPAIR,
2233 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2234 (u32 *)&req, sizeof(req), sizeof(*resp));
2236 ret = PTR_ERR(xfer);
2237 dev_err(info->dev, "RM_PSIL:Message alloc failed(%d)\n", ret);
2240 req.nav_id = nav_id;
2241 req.src_thread = src_thread;
2242 req.dst_thread = dst_thread;
2244 ret = ti_sci_do_xfer(info, xfer);
2246 dev_err(info->dev, "RM_PSIL:Mbox send fail %d\n", ret);
2250 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2251 ret = ti_sci_is_response_ack(resp) ? 0 : -ENODEV;
2254 dev_dbg(info->dev, "RM_PSIL: link unpair %u->%u ret:%u\n",
2255 src_thread, dst_thread, ret);
2259 static int ti_sci_cmd_rm_udmap_tx_ch_cfg(
2260 const struct ti_sci_handle *handle,
2261 const struct ti_sci_msg_rm_udmap_tx_ch_cfg *params)
2263 struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *resp;
2264 struct ti_sci_msg_rm_udmap_tx_ch_cfg_req req;
2265 struct ti_sci_xfer *xfer;
2266 struct ti_sci_info *info;
2270 return PTR_ERR(handle);
2274 info = handle_to_ti_sci_info(handle);
2276 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_TX_CH_CFG,
2277 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2278 (u32 *)&req, sizeof(req), sizeof(*resp));
2280 ret = PTR_ERR(xfer);
2281 dev_err(info->dev, "Message TX_CH_CFG alloc failed(%d)\n", ret);
2284 req.valid_params = params->valid_params;
2285 req.nav_id = params->nav_id;
2286 req.index = params->index;
2287 req.tx_pause_on_err = params->tx_pause_on_err;
2288 req.tx_filt_einfo = params->tx_filt_einfo;
2289 req.tx_filt_pswords = params->tx_filt_pswords;
2290 req.tx_atype = params->tx_atype;
2291 req.tx_chan_type = params->tx_chan_type;
2292 req.tx_supr_tdpkt = params->tx_supr_tdpkt;
2293 req.tx_fetch_size = params->tx_fetch_size;
2294 req.tx_credit_count = params->tx_credit_count;
2295 req.txcq_qnum = params->txcq_qnum;
2296 req.tx_priority = params->tx_priority;
2297 req.tx_qos = params->tx_qos;
2298 req.tx_orderid = params->tx_orderid;
2299 req.fdepth = params->fdepth;
2300 req.tx_sched_priority = params->tx_sched_priority;
2302 ret = ti_sci_do_xfer(info, xfer);
2304 dev_err(info->dev, "Mbox send TX_CH_CFG fail %d\n", ret);
2309 (struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *)xfer->tx_message.buf;
2310 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2313 dev_dbg(info->dev, "TX_CH_CFG: chn %u ret:%u\n", params->index, ret);
2317 static int ti_sci_cmd_rm_udmap_rx_ch_cfg(
2318 const struct ti_sci_handle *handle,
2319 const struct ti_sci_msg_rm_udmap_rx_ch_cfg *params)
2321 struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *resp;
2322 struct ti_sci_msg_rm_udmap_rx_ch_cfg_req req;
2323 struct ti_sci_xfer *xfer;
2324 struct ti_sci_info *info;
2328 return PTR_ERR(handle);
2332 info = handle_to_ti_sci_info(handle);
2334 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_RX_CH_CFG,
2335 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2336 (u32 *)&req, sizeof(req), sizeof(*resp));
2338 ret = PTR_ERR(xfer);
2339 dev_err(info->dev, "Message RX_CH_CFG alloc failed(%d)\n", ret);
2343 req.valid_params = params->valid_params;
2344 req.nav_id = params->nav_id;
2345 req.index = params->index;
2346 req.rx_fetch_size = params->rx_fetch_size;
2347 req.rxcq_qnum = params->rxcq_qnum;
2348 req.rx_priority = params->rx_priority;
2349 req.rx_qos = params->rx_qos;
2350 req.rx_orderid = params->rx_orderid;
2351 req.rx_sched_priority = params->rx_sched_priority;
2352 req.flowid_start = params->flowid_start;
2353 req.flowid_cnt = params->flowid_cnt;
2354 req.rx_pause_on_err = params->rx_pause_on_err;
2355 req.rx_atype = params->rx_atype;
2356 req.rx_chan_type = params->rx_chan_type;
2357 req.rx_ignore_short = params->rx_ignore_short;
2358 req.rx_ignore_long = params->rx_ignore_long;
2360 ret = ti_sci_do_xfer(info, xfer);
2362 dev_err(info->dev, "Mbox send RX_CH_CFG fail %d\n", ret);
2367 (struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *)xfer->tx_message.buf;
2368 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2371 dev_dbg(info->dev, "RX_CH_CFG: chn %u ret:%d\n", params->index, ret);
2375 static int ti_sci_cmd_rm_udmap_rx_flow_cfg(
2376 const struct ti_sci_handle *handle,
2377 const struct ti_sci_msg_rm_udmap_flow_cfg *params)
2379 struct ti_sci_msg_rm_udmap_flow_cfg_resp *resp;
2380 struct ti_sci_msg_rm_udmap_flow_cfg_req req;
2381 struct ti_sci_xfer *xfer;
2382 struct ti_sci_info *info;
2386 return PTR_ERR(handle);
2390 info = handle_to_ti_sci_info(handle);
2392 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_FLOW_CFG,
2393 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2394 (u32 *)&req, sizeof(req), sizeof(*resp));
2396 ret = PTR_ERR(xfer);
2397 dev_err(dev, "RX_FL_CFG: Message alloc failed(%d)\n", ret);
2401 req.valid_params = params->valid_params;
2402 req.nav_id = params->nav_id;
2403 req.flow_index = params->flow_index;
2404 req.rx_einfo_present = params->rx_einfo_present;
2405 req.rx_psinfo_present = params->rx_psinfo_present;
2406 req.rx_error_handling = params->rx_error_handling;
2407 req.rx_desc_type = params->rx_desc_type;
2408 req.rx_sop_offset = params->rx_sop_offset;
2409 req.rx_dest_qnum = params->rx_dest_qnum;
2410 req.rx_src_tag_hi = params->rx_src_tag_hi;
2411 req.rx_src_tag_lo = params->rx_src_tag_lo;
2412 req.rx_dest_tag_hi = params->rx_dest_tag_hi;
2413 req.rx_dest_tag_lo = params->rx_dest_tag_lo;
2414 req.rx_src_tag_hi_sel = params->rx_src_tag_hi_sel;
2415 req.rx_src_tag_lo_sel = params->rx_src_tag_lo_sel;
2416 req.rx_dest_tag_hi_sel = params->rx_dest_tag_hi_sel;
2417 req.rx_dest_tag_lo_sel = params->rx_dest_tag_lo_sel;
2418 req.rx_fdq0_sz0_qnum = params->rx_fdq0_sz0_qnum;
2419 req.rx_fdq1_qnum = params->rx_fdq1_qnum;
2420 req.rx_fdq2_qnum = params->rx_fdq2_qnum;
2421 req.rx_fdq3_qnum = params->rx_fdq3_qnum;
2422 req.rx_ps_location = params->rx_ps_location;
2424 ret = ti_sci_do_xfer(info, xfer);
2426 dev_err(dev, "RX_FL_CFG: Mbox send fail %d\n", ret);
2431 (struct ti_sci_msg_rm_udmap_flow_cfg_resp *)xfer->tx_message.buf;
2432 ret = ti_sci_is_response_ack(resp) ? 0 : -EINVAL;
2435 dev_dbg(info->dev, "RX_FL_CFG: %u ret:%d\n", params->flow_index, ret);
2440 * ti_sci_cmd_set_fwl_region() - Request for configuring a firewall region
2441 * @handle: pointer to TI SCI handle
2442 * @region: region configuration parameters
2444 * Return: 0 if all went well, else returns appropriate error value.
2446 static int ti_sci_cmd_set_fwl_region(const struct ti_sci_handle *handle,
2447 const struct ti_sci_msg_fwl_region *region)
2449 struct ti_sci_msg_fwl_set_firewall_region_req req;
2450 struct ti_sci_msg_hdr *resp;
2451 struct ti_sci_info *info;
2452 struct ti_sci_xfer *xfer;
2456 return PTR_ERR(handle);
2460 info = handle_to_ti_sci_info(handle);
2462 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_SET,
2463 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2464 (u32 *)&req, sizeof(req), sizeof(*resp));
2466 ret = PTR_ERR(xfer);
2467 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2471 req.fwl_id = region->fwl_id;
2472 req.region = region->region;
2473 req.n_permission_regs = region->n_permission_regs;
2474 req.control = region->control;
2475 req.permissions[0] = region->permissions[0];
2476 req.permissions[1] = region->permissions[1];
2477 req.permissions[2] = region->permissions[2];
2478 req.start_address = region->start_address;
2479 req.end_address = region->end_address;
2481 ret = ti_sci_do_xfer(info, xfer);
2483 dev_err(info->dev, "Mbox send fail %d\n", ret);
2487 resp = (struct ti_sci_msg_hdr *)xfer->tx_message.buf;
2489 if (!ti_sci_is_response_ack(resp))
2496 * ti_sci_cmd_get_fwl_region() - Request for getting a firewall region
2497 * @handle: pointer to TI SCI handle
2498 * @region: region configuration parameters
2500 * Return: 0 if all went well, else returns appropriate error value.
2502 static int ti_sci_cmd_get_fwl_region(const struct ti_sci_handle *handle,
2503 struct ti_sci_msg_fwl_region *region)
2505 struct ti_sci_msg_fwl_get_firewall_region_req req;
2506 struct ti_sci_msg_fwl_get_firewall_region_resp *resp;
2507 struct ti_sci_info *info;
2508 struct ti_sci_xfer *xfer;
2512 return PTR_ERR(handle);
2516 info = handle_to_ti_sci_info(handle);
2518 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_GET,
2519 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2520 (u32 *)&req, sizeof(req), sizeof(*resp));
2522 ret = PTR_ERR(xfer);
2523 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2527 req.fwl_id = region->fwl_id;
2528 req.region = region->region;
2529 req.n_permission_regs = region->n_permission_regs;
2531 ret = ti_sci_do_xfer(info, xfer);
2533 dev_err(info->dev, "Mbox send fail %d\n", ret);
2537 resp = (struct ti_sci_msg_fwl_get_firewall_region_resp *)xfer->tx_message.buf;
2539 if (!ti_sci_is_response_ack(resp))
2542 region->fwl_id = resp->fwl_id;
2543 region->region = resp->region;
2544 region->n_permission_regs = resp->n_permission_regs;
2545 region->control = resp->control;
2546 region->permissions[0] = resp->permissions[0];
2547 region->permissions[1] = resp->permissions[1];
2548 region->permissions[2] = resp->permissions[2];
2549 region->start_address = resp->start_address;
2550 region->end_address = resp->end_address;
2556 * ti_sci_cmd_change_fwl_owner() - Request for changing a firewall owner
2557 * @handle: pointer to TI SCI handle
2558 * @region: region configuration parameters
2560 * Return: 0 if all went well, else returns appropriate error value.
2562 static int ti_sci_cmd_change_fwl_owner(const struct ti_sci_handle *handle,
2563 struct ti_sci_msg_fwl_owner *owner)
2565 struct ti_sci_msg_fwl_change_owner_info_req req;
2566 struct ti_sci_msg_fwl_change_owner_info_resp *resp;
2567 struct ti_sci_info *info;
2568 struct ti_sci_xfer *xfer;
2572 return PTR_ERR(handle);
2576 info = handle_to_ti_sci_info(handle);
2578 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_CHANGE_OWNER,
2579 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2580 (u32 *)&req, sizeof(req), sizeof(*resp));
2582 ret = PTR_ERR(xfer);
2583 dev_err(info->dev, "Message alloc failed(%d)\n", ret);
2587 req.fwl_id = owner->fwl_id;
2588 req.region = owner->region;
2589 req.owner_index = owner->owner_index;
2591 ret = ti_sci_do_xfer(info, xfer);
2593 dev_err(info->dev, "Mbox send fail %d\n", ret);
2597 resp = (struct ti_sci_msg_fwl_change_owner_info_resp *)xfer->tx_message.buf;
2599 if (!ti_sci_is_response_ack(resp))
2602 owner->fwl_id = resp->fwl_id;
2603 owner->region = resp->region;
2604 owner->owner_index = resp->owner_index;
2605 owner->owner_privid = resp->owner_privid;
2606 owner->owner_permission_bits = resp->owner_permission_bits;
2612 * ti_sci_setup_ops() - Setup the operations structures
2613 * @info: pointer to TISCI pointer
2615 static void ti_sci_setup_ops(struct ti_sci_info *info)
2617 struct ti_sci_ops *ops = &info->handle.ops;
2618 struct ti_sci_board_ops *bops = &ops->board_ops;
2619 struct ti_sci_dev_ops *dops = &ops->dev_ops;
2620 struct ti_sci_clk_ops *cops = &ops->clk_ops;
2621 struct ti_sci_core_ops *core_ops = &ops->core_ops;
2622 struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
2623 struct ti_sci_proc_ops *pops = &ops->proc_ops;
2624 struct ti_sci_rm_ringacc_ops *rops = &ops->rm_ring_ops;
2625 struct ti_sci_rm_psil_ops *psilops = &ops->rm_psil_ops;
2626 struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops;
2627 struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops;
2629 bops->board_config = ti_sci_cmd_set_board_config;
2630 bops->board_config_rm = ti_sci_cmd_set_board_config_rm;
2631 bops->board_config_security = ti_sci_cmd_set_board_config_security;
2632 bops->board_config_pm = ti_sci_cmd_set_board_config_pm;
2634 dops->get_device = ti_sci_cmd_get_device;
2635 dops->idle_device = ti_sci_cmd_idle_device;
2636 dops->put_device = ti_sci_cmd_put_device;
2637 dops->is_valid = ti_sci_cmd_dev_is_valid;
2638 dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt;
2639 dops->is_idle = ti_sci_cmd_dev_is_idle;
2640 dops->is_stop = ti_sci_cmd_dev_is_stop;
2641 dops->is_on = ti_sci_cmd_dev_is_on;
2642 dops->is_transitioning = ti_sci_cmd_dev_is_trans;
2643 dops->set_device_resets = ti_sci_cmd_set_device_resets;
2644 dops->get_device_resets = ti_sci_cmd_get_device_resets;
2646 cops->get_clock = ti_sci_cmd_get_clock;
2647 cops->idle_clock = ti_sci_cmd_idle_clock;
2648 cops->put_clock = ti_sci_cmd_put_clock;
2649 cops->is_auto = ti_sci_cmd_clk_is_auto;
2650 cops->is_on = ti_sci_cmd_clk_is_on;
2651 cops->is_off = ti_sci_cmd_clk_is_off;
2653 cops->set_parent = ti_sci_cmd_clk_set_parent;
2654 cops->get_parent = ti_sci_cmd_clk_get_parent;
2655 cops->get_num_parents = ti_sci_cmd_clk_get_num_parents;
2657 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;
2658 cops->set_freq = ti_sci_cmd_clk_set_freq;
2659 cops->get_freq = ti_sci_cmd_clk_get_freq;
2661 core_ops->reboot_device = ti_sci_cmd_core_reboot;
2662 core_ops->query_msmc = ti_sci_cmd_query_msmc;
2664 rm_core_ops->get_range = ti_sci_cmd_get_resource_range;
2665 rm_core_ops->get_range_from_shost =
2666 ti_sci_cmd_get_resource_range_from_shost;
2668 pops->proc_request = ti_sci_cmd_proc_request;
2669 pops->proc_release = ti_sci_cmd_proc_release;
2670 pops->proc_handover = ti_sci_cmd_proc_handover;
2671 pops->set_proc_boot_cfg = ti_sci_cmd_set_proc_boot_cfg;
2672 pops->set_proc_boot_ctrl = ti_sci_cmd_set_proc_boot_ctrl;
2673 pops->proc_auth_boot_image = ti_sci_cmd_proc_auth_boot_image;
2674 pops->get_proc_boot_status = ti_sci_cmd_get_proc_boot_status;
2676 rops->config = ti_sci_cmd_ring_config;
2677 rops->get_config = ti_sci_cmd_ring_get_config;
2679 psilops->pair = ti_sci_cmd_rm_psil_pair;
2680 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
2682 udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg;
2683 udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg;
2684 udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg;
2686 fwl_ops->set_fwl_region = ti_sci_cmd_set_fwl_region;
2687 fwl_ops->get_fwl_region = ti_sci_cmd_get_fwl_region;
2688 fwl_ops->change_fwl_owner = ti_sci_cmd_change_fwl_owner;
2692 * ti_sci_get_handle_from_sysfw() - Get the TI SCI handle of the SYSFW
2693 * @dev: Pointer to the SYSFW device
2695 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2699 struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *sci_dev)
2702 return ERR_PTR(-EINVAL);
2704 struct ti_sci_info *info = dev_get_priv(sci_dev);
2707 return ERR_PTR(-EINVAL);
2709 struct ti_sci_handle *handle = &info->handle;
2712 return ERR_PTR(-EINVAL);
2718 * ti_sci_get_handle() - Get the TI SCI handle for a device
2719 * @dev: Pointer to device for which we want SCI handle
2721 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2724 const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
2727 return ERR_PTR(-EINVAL);
2729 struct udevice *sci_dev = dev_get_parent(dev);
2731 return ti_sci_get_handle_from_sysfw(sci_dev);
2735 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
2737 * @propname: property name containing phandle on TISCI node
2739 * Return: pointer to handle if successful, else appropriate error value.
2741 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
2742 const char *property)
2744 struct ti_sci_info *entry, *info = NULL;
2748 err = ofnode_read_u32(dev_ofnode(dev), property, &phandle);
2750 return ERR_PTR(err);
2752 node = ofnode_get_by_phandle(phandle);
2753 if (!ofnode_valid(node))
2754 return ERR_PTR(-EINVAL);
2756 list_for_each_entry(entry, &ti_sci_list, list)
2757 if (ofnode_equal(dev_ofnode(entry->dev), node)) {
2763 return ERR_PTR(-ENODEV);
2765 return &info->handle;
2769 * ti_sci_of_to_info() - generate private data from device tree
2770 * @dev: corresponding system controller interface device
2771 * @info: pointer to driver specific private data
2773 * Return: 0 if all goes good, else appropriate error message.
2775 static int ti_sci_of_to_info(struct udevice *dev, struct ti_sci_info *info)
2779 ret = mbox_get_by_name(dev, "tx", &info->chan_tx);
2781 dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n",
2786 ret = mbox_get_by_name(dev, "rx", &info->chan_rx);
2788 dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n",
2793 /* Notify channel is optional. Enable only if populated */
2794 ret = mbox_get_by_name(dev, "notify", &info->chan_notify);
2796 dev_dbg(dev, "%s: Acquiring notify channel failed. ret = %d\n",
2800 info->host_id = dev_read_u32_default(dev, "ti,host-id",
2801 info->desc->default_host_id);
2803 info->is_secure = dev_read_bool(dev, "ti,secure-host");
2809 * ti_sci_probe() - Basic probe
2810 * @dev: corresponding system controller interface device
2812 * Return: 0 if all goes good, else appropriate error message.
2814 static int ti_sci_probe(struct udevice *dev)
2816 struct ti_sci_info *info;
2819 debug("%s(dev=%p)\n", __func__, dev);
2821 info = dev_get_priv(dev);
2822 info->desc = (void *)dev_get_driver_data(dev);
2824 ret = ti_sci_of_to_info(dev, info);
2826 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
2833 list_add_tail(&info->list, &ti_sci_list);
2834 ti_sci_setup_ops(info);
2836 ret = ti_sci_cmd_get_revision(&info->handle);
2842 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
2843 * @res: Pointer to the TISCI resource
2845 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
2847 u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
2851 for (set = 0; set < res->sets; set++) {
2852 free_bit = find_first_zero_bit(res->desc[set].res_map,
2853 res->desc[set].num);
2854 if (free_bit != res->desc[set].num) {
2855 set_bit(free_bit, res->desc[set].res_map);
2856 return res->desc[set].start + free_bit;
2860 return TI_SCI_RESOURCE_NULL;
2864 * ti_sci_release_resource() - Release a resource from TISCI resource.
2865 * @res: Pointer to the TISCI resource
2867 void ti_sci_release_resource(struct ti_sci_resource *res, u16 id)
2871 for (set = 0; set < res->sets; set++) {
2872 if (res->desc[set].start <= id &&
2873 (res->desc[set].num + res->desc[set].start) > id)
2874 clear_bit(id - res->desc[set].start,
2875 res->desc[set].res_map);
2880 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
2881 * @handle: TISCI handle
2882 * @dev: Device pointer to which the resource is assigned
2883 * @of_prop: property name by which the resource are represented
2885 * Note: This function expects of_prop to be in the form of tuples
2886 * <type, subtype>. Allocates and initializes ti_sci_resource structure
2887 * for each of_prop. Client driver can directly call
2888 * ti_sci_(get_free, release)_resource apis for handling the resource.
2890 * Return: Pointer to ti_sci_resource if all went well else appropriate
2893 struct ti_sci_resource *
2894 devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
2895 struct udevice *dev, u32 dev_id, char *of_prop)
2897 u32 resource_subtype;
2899 struct ti_sci_resource *res;
2903 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
2905 return ERR_PTR(-ENOMEM);
2907 sets = dev_read_size(dev, of_prop);
2909 dev_err(dev, "%s resource type ids not available\n", of_prop);
2910 return ERR_PTR(sets);
2912 temp = malloc(sets);
2913 sets /= sizeof(u32);
2916 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
2919 return ERR_PTR(-ENOMEM);
2921 ret = ti_sci_get_resource_type(handle_to_ti_sci_info(handle), dev_id,
2924 dev_err(dev, "No valid resource type for %u\n", dev_id);
2925 return ERR_PTR(-EINVAL);
2928 ret = dev_read_u32_array(dev, of_prop, temp, res->sets);
2930 return ERR_PTR(-EINVAL);
2932 for (i = 0; i < res->sets; i++) {
2933 resource_subtype = temp[i];
2934 ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
2936 &res->desc[i].start,
2939 dev_err(dev, "type %d subtype %d not allocated for host %d\n",
2940 resource_type, resource_subtype,
2941 handle_to_ti_sci_info(handle)->host_id);
2942 return ERR_PTR(ret);
2945 dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n",
2946 resource_type, resource_subtype, res->desc[i].start,
2949 res->desc[i].res_map =
2950 devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) *
2951 sizeof(*res->desc[i].res_map), GFP_KERNEL);
2952 if (!res->desc[i].res_map)
2953 return ERR_PTR(-ENOMEM);
2959 /* Description for K2G */
2960 static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = {
2961 .default_host_id = 2,
2962 /* Conservative duration */
2963 .max_rx_timeout_ms = 10000,
2964 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
2967 .rm_type_map = NULL,
2970 static struct ti_sci_rm_type_map ti_sci_am654_rm_type_map[] = {
2971 {.dev_id = 56, .type = 0x00b}, /* GIC_IRQ */
2972 {.dev_id = 179, .type = 0x000}, /* MAIN_NAV_UDMASS_IA0 */
2973 {.dev_id = 187, .type = 0x009}, /* MAIN_NAV_RA */
2974 {.dev_id = 188, .type = 0x006}, /* MAIN_NAV_UDMAP */
2975 {.dev_id = 194, .type = 0x007}, /* MCU_NAV_UDMAP */
2976 {.dev_id = 195, .type = 0x00a}, /* MCU_NAV_RA */
2977 {.dev_id = 0, .type = 0x000}, /* end of table */
2980 /* Description for AM654 */
2981 static const struct ti_sci_desc ti_sci_pmmc_am654_desc = {
2982 .default_host_id = 12,
2983 /* Conservative duration */
2984 .max_rx_timeout_ms = 10000,
2985 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
2988 .rm_type_map = ti_sci_am654_rm_type_map,
2991 static const struct udevice_id ti_sci_ids[] = {
2993 .compatible = "ti,k2g-sci",
2994 .data = (ulong)&ti_sci_pmmc_k2g_desc
2997 .compatible = "ti,am654-sci",
2998 .data = (ulong)&ti_sci_pmmc_am654_desc
3003 U_BOOT_DRIVER(ti_sci) = {
3005 .id = UCLASS_FIRMWARE,
3006 .of_match = ti_sci_ids,
3007 .probe = ti_sci_probe,
3008 .priv_auto_alloc_size = sizeof(struct ti_sci_info),