blob: 8013afef304dfb70ab14150ddc49d43ebebb5902 [file] [log] [blame]
Lokesh Vutla5af02db2018-08-27 15:57:32 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Texas Instruments System Control Interface Protocol Driver
4 * Based on drivers/firmware/ti_sci.c from Linux.
5 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05006 * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
Lokesh Vutla5af02db2018-08-27 15:57:32 +05307 * Lokesh Vutla <lokeshvutla@ti.com>
8 */
9
Lokesh Vutla5af02db2018-08-27 15:57:32 +053010#include <dm.h>
11#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Lokesh Vutla5af02db2018-08-27 15:57:32 +053013#include <mailbox.h>
Simon Glass9bc15642020-02-03 07:36:16 -070014#include <malloc.h>
Lokesh Vutla5af02db2018-08-27 15:57:32 +053015#include <dm/device.h>
Simon Glass9bc15642020-02-03 07:36:16 -070016#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070017#include <dm/devres.h>
Andrew Davis1ed20d62024-04-02 11:09:07 -050018#include <dm/lists.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060019#include <linux/bitops.h>
Grygorii Strashkod64c5b22019-02-05 17:31:21 +053020#include <linux/compat.h>
Lokesh Vutla5af02db2018-08-27 15:57:32 +053021#include <linux/err.h>
22#include <linux/soc/ti/k3-sec-proxy.h>
23#include <linux/soc/ti/ti_sci_protocol.h>
24
25#include "ti_sci.h"
Vignesh Raghavendra4214a812021-06-07 19:47:48 +053026#include "ti_sci_static_data.h"
Lokesh Vutla5af02db2018-08-27 15:57:32 +053027
28/* List of all TI SCI devices active in system */
29static LIST_HEAD(ti_sci_list);
30
31/**
32 * struct ti_sci_xfer - Structure representing a message flow
33 * @tx_message: Transmit message
34 * @rx_len: Receive message length
35 */
36struct ti_sci_xfer {
37 struct k3_sec_proxy_msg tx_message;
38 u8 rx_len;
39};
40
41/**
Grygorii Strashkod64c5b22019-02-05 17:31:21 +053042 * struct ti_sci_rm_type_map - Structure representing TISCI Resource
43 * management representation of dev_ids.
44 * @dev_id: TISCI device ID
45 * @type: Corresponding id as identified by TISCI RM.
46 *
47 * Note: This is used only as a work around for using RM range apis
48 * for AM654 SoC. For future SoCs dev_id will be used as type
49 * for RM range APIs. In order to maintain ABI backward compatibility
50 * type is not being changed for AM654 SoC.
51 */
52struct ti_sci_rm_type_map {
53 u32 dev_id;
54 u16 type;
55};
56
57/**
Lokesh Vutla5af02db2018-08-27 15:57:32 +053058 * struct ti_sci_desc - Description of SoC integration
Grygorii Strashkod64c5b22019-02-05 17:31:21 +053059 * @default_host_id: Host identifier representing the compute entity
60 * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
61 * @max_msgs: Maximum number of messages that can be pending
62 * simultaneously in the system
63 * @max_msg_size: Maximum size of data per message that can be handled.
Lokesh Vutla5af02db2018-08-27 15:57:32 +053064 */
65struct ti_sci_desc {
Grygorii Strashkod64c5b22019-02-05 17:31:21 +053066 u8 default_host_id;
67 int max_rx_timeout_ms;
68 int max_msgs;
Lokesh Vutla5af02db2018-08-27 15:57:32 +053069 int max_msg_size;
70};
71
72/**
73 * struct ti_sci_info - Structure representing a TI SCI instance
74 * @dev: Device pointer
75 * @desc: SoC description for this instance
76 * @handle: Instance of TI SCI handle to send to clients.
77 * @chan_tx: Transmit mailbox channel
78 * @chan_rx: Receive mailbox channel
79 * @xfer: xfer info
80 * @list: list head
81 * @is_secure: Determines if the communication is through secure threads.
82 * @host_id: Host identifier representing the compute entity
83 * @seq: Seq id used for verification for tx and rx message.
84 */
85struct ti_sci_info {
86 struct udevice *dev;
87 const struct ti_sci_desc *desc;
88 struct ti_sci_handle handle;
89 struct mbox_chan chan_tx;
90 struct mbox_chan chan_rx;
91 struct mbox_chan chan_notify;
92 struct ti_sci_xfer xfer;
93 struct list_head list;
Lokesh Vutla0d0412a2019-06-07 19:24:41 +053094 struct list_head dev_list;
Lokesh Vutla5af02db2018-08-27 15:57:32 +053095 bool is_secure;
96 u8 host_id;
97 u8 seq;
98};
99
Lokesh Vutla0d0412a2019-06-07 19:24:41 +0530100struct ti_sci_exclusive_dev {
101 u32 id;
102 u32 count;
103 struct list_head list;
104};
105
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530106#define handle_to_ti_sci_info(h) container_of(h, struct ti_sci_info, handle)
107
108/**
109 * ti_sci_setup_one_xfer() - Setup one message type
110 * @info: Pointer to SCI entity information
111 * @msg_type: Message type
112 * @msg_flags: Flag to set for the message
113 * @buf: Buffer to be send to mailbox channel
114 * @tx_message_size: transmit message size
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530115 * @rx_message_size: receive message size. may be set to zero for send-only
116 * transactions.
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530117 *
118 * Helper function which is used by various command functions that are
119 * exposed to clients of this driver for allocating a message traffic event.
120 *
121 * Return: Corresponding ti_sci_xfer pointer if all went fine,
122 * else appropriate error pointer.
123 */
124static struct ti_sci_xfer *ti_sci_setup_one_xfer(struct ti_sci_info *info,
125 u16 msg_type, u32 msg_flags,
126 u32 *buf,
127 size_t tx_message_size,
128 size_t rx_message_size)
129{
130 struct ti_sci_xfer *xfer = &info->xfer;
131 struct ti_sci_msg_hdr *hdr;
132
133 /* Ensure we have sane transfer sizes */
134 if (rx_message_size > info->desc->max_msg_size ||
135 tx_message_size > info->desc->max_msg_size ||
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530136 (rx_message_size > 0 && rx_message_size < sizeof(*hdr)) ||
Andrew Davis22563722022-07-25 20:25:04 -0500137 tx_message_size < sizeof(*hdr)) {
138 dev_err(info->dev, "TI-SCI message transfer size not sane\n");
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530139 return ERR_PTR(-ERANGE);
Andrew Davis22563722022-07-25 20:25:04 -0500140 }
141
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530142 info->seq = ~info->seq;
143 xfer->tx_message.buf = buf;
144 xfer->tx_message.len = tx_message_size;
145 xfer->rx_len = (u8)rx_message_size;
146
147 hdr = (struct ti_sci_msg_hdr *)buf;
148 hdr->seq = info->seq;
149 hdr->type = msg_type;
150 hdr->host = info->host_id;
151 hdr->flags = msg_flags;
152
153 return xfer;
154}
155
156/**
157 * ti_sci_get_response() - Receive response from mailbox channel
158 * @info: Pointer to SCI entity information
159 * @xfer: Transfer to initiate and wait for response
160 * @chan: Channel to receive the response
161 *
162 * Return: -ETIMEDOUT in case of no response, if transmit error,
163 * return corresponding error, else if all goes well,
164 * return 0.
165 */
Andrew Davisb3e71b72022-07-25 20:25:05 -0500166static int ti_sci_get_response(struct ti_sci_info *info,
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530167 struct ti_sci_xfer *xfer,
168 struct mbox_chan *chan)
169{
170 struct k3_sec_proxy_msg *msg = &xfer->tx_message;
171 struct ti_sci_secure_msg_hdr *secure_hdr;
172 struct ti_sci_msg_hdr *hdr;
173 int ret;
174
175 /* Receive the response */
Andreas Dannenberg607d4ca2019-04-24 14:20:08 -0500176 ret = mbox_recv(chan, msg, info->desc->max_rx_timeout_ms * 1000);
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530177 if (ret) {
178 dev_err(info->dev, "%s: Message receive failed. ret = %d\n",
179 __func__, ret);
180 return ret;
181 }
182
183 /* ToDo: Verify checksum */
184 if (info->is_secure) {
185 secure_hdr = (struct ti_sci_secure_msg_hdr *)msg->buf;
186 msg->buf = (u32 *)((void *)msg->buf + sizeof(*secure_hdr));
187 }
188
189 /* msg is updated by mailbox driver */
190 hdr = (struct ti_sci_msg_hdr *)msg->buf;
191
192 /* Sanity check for message response */
193 if (hdr->seq != info->seq) {
194 dev_dbg(info->dev, "%s: Message for %d is not expected\n",
195 __func__, hdr->seq);
196 return ret;
197 }
198
199 if (msg->len > info->desc->max_msg_size) {
200 dev_err(info->dev, "%s: Unable to handle %zu xfer (max %d)\n",
201 __func__, msg->len, info->desc->max_msg_size);
202 return -EINVAL;
203 }
204
205 if (msg->len < xfer->rx_len) {
206 dev_err(info->dev, "%s: Recv xfer %zu < expected %d length\n",
207 __func__, msg->len, xfer->rx_len);
208 }
209
210 return ret;
211}
212
213/**
Andrew Davis04e43932022-07-25 20:25:06 -0500214 * ti_sci_is_response_ack() - Generic ACK/NACK message checkup
215 * @r: pointer to response buffer
216 *
217 * Return: true if the response was an ACK, else returns false.
218 */
219static bool ti_sci_is_response_ack(void *r)
220{
221 struct ti_sci_msg_hdr *hdr = r;
222
223 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false;
224}
225
226/**
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530227 * ti_sci_do_xfer() - Do one transfer
228 * @info: Pointer to SCI entity information
229 * @xfer: Transfer to initiate and wait for response
230 *
231 * Return: 0 if all went fine, else return appropriate error.
232 */
Andrew Davisb3e71b72022-07-25 20:25:05 -0500233static int ti_sci_do_xfer(struct ti_sci_info *info,
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530234 struct ti_sci_xfer *xfer)
235{
236 struct k3_sec_proxy_msg *msg = &xfer->tx_message;
237 u8 secure_buf[info->desc->max_msg_size];
Dhruva Goled3341022024-01-30 20:29:59 +0530238 struct ti_sci_secure_msg_hdr *secure_hdr = (struct ti_sci_secure_msg_hdr *)secure_buf;
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530239 int ret;
240
Dhruva Gole5452ebd2024-01-30 20:30:00 +0530241 /*
242 * The reason why we need the is_secure code is because of boot R5.
243 * boot R5 starts off in "secure mode" when it hands off from Boot
244 * ROM over to the Secondary bootloader. The initial set of calls
245 * we have to make need to be on a secure pipe.
246 */
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530247 if (info->is_secure) {
248 /* ToDo: get checksum of the entire message */
Dhruva Goled3341022024-01-30 20:29:59 +0530249 secure_hdr->checksum = 0;
250 secure_hdr->reserved = 0;
251 memcpy(&secure_buf[sizeof(*secure_hdr)], xfer->tx_message.buf,
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530252 xfer->tx_message.len);
253
254 xfer->tx_message.buf = (u32 *)secure_buf;
Dhruva Goled3341022024-01-30 20:29:59 +0530255 xfer->tx_message.len += sizeof(*secure_hdr);
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530256
257 if (xfer->rx_len)
Dhruva Goled3341022024-01-30 20:29:59 +0530258 xfer->rx_len += sizeof(*secure_hdr);
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530259 }
260
261 /* Send the message */
262 ret = mbox_send(&info->chan_tx, msg);
263 if (ret) {
264 dev_err(info->dev, "%s: Message sending failed. ret = %d\n",
265 __func__, ret);
266 return ret;
267 }
268
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530269 /* Get response if requested */
Andrew Davis04e43932022-07-25 20:25:06 -0500270 if (xfer->rx_len) {
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530271 ret = ti_sci_get_response(info, xfer, &info->chan_rx);
Andrew Davis04e43932022-07-25 20:25:06 -0500272 if (!ti_sci_is_response_ack(xfer->tx_message.buf)) {
Andreas Dannenberg831b73f2023-05-09 16:38:13 -0500273 dev_err(info->dev, "Message not acknowledged\n");
Andrew Davis04e43932022-07-25 20:25:06 -0500274 ret = -ENODEV;
275 }
276 }
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530277
278 return ret;
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530279}
280
281/**
Moteen Shah3a66db62025-06-09 13:44:31 +0530282 * ti_sci_cmd_query_dm_cap() - Command to query DM firmware's capabilities
283 * @handle: Pointer to TI SCI handle
284 * @fw_caps: Pointer to firmware capabilities
285 *
286 * Return: 0 if all went fine, else return appropriate error.
287 */
288static int ti_sci_cmd_query_dm_cap(struct ti_sci_handle *handle, u64 *fw_caps)
289{
290 struct ti_sci_query_fw_caps_resp *cap_info;
291 struct ti_sci_msg_hdr hdr;
292 struct ti_sci_info *info;
293 struct ti_sci_xfer *xfer;
294 int ret;
295
296 if (IS_ERR(handle))
297 return PTR_ERR(handle);
298 if (!handle)
299 return -EINVAL;
300
301 info = handle_to_ti_sci_info(handle);
302
303 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_QUERY_FW_CAPS,
304 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
305 (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr),
306 sizeof(*cap_info));
307 if (IS_ERR(xfer)) {
308 ret = PTR_ERR(xfer);
309 return ret;
310 }
311
312 ret = ti_sci_do_xfer(info, xfer);
313 if (ret)
314 return ret;
315
316 cap_info = (struct ti_sci_query_fw_caps_resp *)xfer->tx_message.buf;
317
318 *fw_caps = cap_info->fw_caps;
319
320 return 0;
321}
322
323/**
Moteen Shahab114e52025-06-09 13:44:32 +0530324 * ti_sci_cmd_get_dm_version() - command to get the DM version of the SCI
325 * entity
326 * @handle: Pointer to TI SCI handle
327 * @dm_info: Pointer to DM version information structure
328 *
329 * Return: 0 if all went fine, else return appropriate error.
330 */
331
332static int ti_sci_cmd_get_dm_version(struct ti_sci_handle *handle,
333 struct ti_sci_dm_version_info *dm_info)
334{
335 struct ti_sci_msg_dm_resp_version *ver_info;
336 struct ti_sci_msg_hdr hdr;
337 struct ti_sci_info *info;
338 struct ti_sci_xfer *xfer;
339 int ret;
340
341 if (IS_ERR(handle))
342 return PTR_ERR(handle);
343 if (!handle || !dm_info)
344 return -EINVAL;
345
346 info = handle_to_ti_sci_info(handle);
347
348 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_DM_VERSION,
349 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
350 (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr),
351 sizeof(*ver_info));
352 if (IS_ERR(xfer)) {
353 ret = PTR_ERR(xfer);
354 return ret;
355 }
356
357 ret = ti_sci_do_xfer(info, xfer);
358 if (ret)
359 return ret;
360
361 ver_info = (struct ti_sci_msg_dm_resp_version *)xfer->tx_message.buf;
362
363 dm_info->abi_major = ver_info->abi_major;
364 dm_info->abi_minor = ver_info->abi_minor;
365 dm_info->dm_ver = ver_info->version;
366 dm_info->patch_ver = ver_info->patch_version;
367 dm_info->sub_ver = ver_info->sub_version;
368 strlcpy(dm_info->sci_server_version, ver_info->sci_server_version,
369 sizeof(ver_info->sci_server_version));
370 strlcpy(dm_info->rm_pm_hal_version, ver_info->rm_pm_hal_version,
371 sizeof(ver_info->rm_pm_hal_version));
372
373 return 0;
374}
375
376/**
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530377 * ti_sci_cmd_get_revision() - command to get the revision of the SCI entity
378 * @handle: pointer to TI SCI handle
379 *
380 * Updates the SCI information in the internal data structure.
381 *
382 * Return: 0 if all went fine, else return appropriate error.
383 */
384static int ti_sci_cmd_get_revision(struct ti_sci_handle *handle)
385{
386 struct ti_sci_msg_resp_version *rev_info;
387 struct ti_sci_version_info *ver;
388 struct ti_sci_msg_hdr hdr;
389 struct ti_sci_info *info;
390 struct ti_sci_xfer *xfer;
391 int ret;
392
393 if (IS_ERR(handle))
394 return PTR_ERR(handle);
395 if (!handle)
396 return -EINVAL;
397
398 info = handle_to_ti_sci_info(handle);
399
Andrew F. Davis8928fbd2019-04-29 09:04:11 -0400400 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_VERSION,
401 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530402 (u32 *)&hdr, sizeof(struct ti_sci_msg_hdr),
403 sizeof(*rev_info));
404 if (IS_ERR(xfer)) {
405 ret = PTR_ERR(xfer);
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530406 return ret;
407 }
408
409 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -0500410 if (ret)
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530411 return ret;
Lokesh Vutla5af02db2018-08-27 15:57:32 +0530412
413 rev_info = (struct ti_sci_msg_resp_version *)xfer->tx_message.buf;
414
415 ver = &handle->version;
416 ver->abi_major = rev_info->abi_major;
417 ver->abi_minor = rev_info->abi_minor;
418 ver->firmware_revision = rev_info->firmware_revision;
419 strncpy(ver->firmware_description, rev_info->firmware_description,
420 sizeof(ver->firmware_description));
421
422 return 0;
423}
424
425/**
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +0530426 * cmd_set_board_config_using_msg() - Common command to send board configuration
427 * message
428 * @handle: pointer to TI SCI handle
429 * @msg_type: One of the TISCI message types to set board configuration
430 * @addr: Address where the board config structure is located
431 * @size: Size of the board config structure
432 *
433 * Return: 0 if all went well, else returns appropriate error value.
434 */
435static int cmd_set_board_config_using_msg(const struct ti_sci_handle *handle,
436 u16 msg_type, u64 addr, u32 size)
437{
438 struct ti_sci_msg_board_config req;
439 struct ti_sci_msg_hdr *resp;
440 struct ti_sci_info *info;
441 struct ti_sci_xfer *xfer;
442 int ret = 0;
443
444 if (IS_ERR(handle))
445 return PTR_ERR(handle);
446 if (!handle)
447 return -EINVAL;
448
449 info = handle_to_ti_sci_info(handle);
450
451 xfer = ti_sci_setup_one_xfer(info, msg_type,
452 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
453 (u32 *)&req, sizeof(req), sizeof(*resp));
454 if (IS_ERR(xfer)) {
455 ret = PTR_ERR(xfer);
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +0530456 return ret;
457 }
458 req.boardcfgp_high = (addr >> 32) & 0xffffffff;
459 req.boardcfgp_low = addr & 0xffffffff;
460 req.boardcfg_size = size;
461
462 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -0500463 if (ret)
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +0530464 return ret;
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +0530465
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +0530466 return ret;
467}
468
469/**
470 * ti_sci_cmd_set_board_config() - Command to send board configuration message
471 * @handle: pointer to TI SCI handle
472 * @addr: Address where the board config structure is located
473 * @size: Size of the board config structure
474 *
475 * Return: 0 if all went well, else returns appropriate error value.
476 */
477static int ti_sci_cmd_set_board_config(const struct ti_sci_handle *handle,
478 u64 addr, u32 size)
479{
480 return cmd_set_board_config_using_msg(handle,
481 TI_SCI_MSG_BOARD_CONFIG,
482 addr, size);
483}
484
485/**
486 * ti_sci_cmd_set_board_config_rm() - Command to send board resource
487 * management configuration
488 * @handle: pointer to TI SCI handle
489 * @addr: Address where the board RM config structure is located
490 * @size: Size of the RM config structure
491 *
492 * Return: 0 if all went well, else returns appropriate error value.
493 */
494static
495int ti_sci_cmd_set_board_config_rm(const struct ti_sci_handle *handle,
496 u64 addr, u32 size)
497{
498 return cmd_set_board_config_using_msg(handle,
499 TI_SCI_MSG_BOARD_CONFIG_RM,
500 addr, size);
501}
502
503/**
504 * ti_sci_cmd_set_board_config_security() - Command to send board security
505 * configuration message
506 * @handle: pointer to TI SCI handle
507 * @addr: Address where the board security config structure is located
508 * @size: Size of the security config structure
509 *
510 * Return: 0 if all went well, else returns appropriate error value.
511 */
512static
513int ti_sci_cmd_set_board_config_security(const struct ti_sci_handle *handle,
514 u64 addr, u32 size)
515{
516 return cmd_set_board_config_using_msg(handle,
517 TI_SCI_MSG_BOARD_CONFIG_SECURITY,
518 addr, size);
519}
520
521/**
522 * ti_sci_cmd_set_board_config_pm() - Command to send board power and clock
523 * configuration message
524 * @handle: pointer to TI SCI handle
525 * @addr: Address where the board PM config structure is located
526 * @size: Size of the PM config structure
527 *
528 * Return: 0 if all went well, else returns appropriate error value.
529 */
530static int ti_sci_cmd_set_board_config_pm(const struct ti_sci_handle *handle,
531 u64 addr, u32 size)
532{
533 return cmd_set_board_config_using_msg(handle,
534 TI_SCI_MSG_BOARD_CONFIG_PM,
535 addr, size);
536}
537
Lokesh Vutla0d0412a2019-06-07 19:24:41 +0530538static struct ti_sci_exclusive_dev
539*ti_sci_get_exclusive_dev(struct list_head *dev_list, u32 id)
540{
541 struct ti_sci_exclusive_dev *dev;
542
543 list_for_each_entry(dev, dev_list, list)
544 if (dev->id == id)
545 return dev;
546
547 return NULL;
548}
549
550static void ti_sci_add_exclusive_dev(struct ti_sci_info *info, u32 id)
551{
552 struct ti_sci_exclusive_dev *dev;
553
554 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
555 if (dev) {
556 dev->count++;
557 return;
558 }
559
560 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
561 dev->id = id;
562 dev->count = 1;
563 INIT_LIST_HEAD(&dev->list);
564 list_add_tail(&dev->list, &info->dev_list);
565}
566
567static void ti_sci_delete_exclusive_dev(struct ti_sci_info *info, u32 id)
568{
569 struct ti_sci_exclusive_dev *dev;
570
571 dev = ti_sci_get_exclusive_dev(&info->dev_list, id);
572 if (!dev)
573 return;
574
575 if (dev->count > 0)
576 dev->count--;
577}
578
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530579/**
580 * ti_sci_set_device_state() - Set device state helper
581 * @handle: pointer to TI SCI handle
582 * @id: Device identifier
583 * @flags: flags to setup for the device
584 * @state: State to move the device to
585 *
586 * Return: 0 if all went well, else returns appropriate error value.
587 */
588static int ti_sci_set_device_state(const struct ti_sci_handle *handle,
589 u32 id, u32 flags, u8 state)
590{
591 struct ti_sci_msg_req_set_device_state req;
592 struct ti_sci_msg_hdr *resp;
593 struct ti_sci_info *info;
594 struct ti_sci_xfer *xfer;
595 int ret = 0;
596
597 if (IS_ERR(handle))
598 return PTR_ERR(handle);
599 if (!handle)
600 return -EINVAL;
601
602 info = handle_to_ti_sci_info(handle);
603
604 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
605 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
606 (u32 *)&req, sizeof(req), sizeof(*resp));
607 if (IS_ERR(xfer)) {
608 ret = PTR_ERR(xfer);
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530609 return ret;
610 }
611 req.id = id;
612 req.state = state;
613
614 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -0500615 if (ret)
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530616 return ret;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530617
Lokesh Vutla0d0412a2019-06-07 19:24:41 +0530618 if (state == MSG_DEVICE_SW_STATE_AUTO_OFF)
619 ti_sci_delete_exclusive_dev(info, id);
620 else if (flags & MSG_FLAG_DEVICE_EXCLUSIVE)
621 ti_sci_add_exclusive_dev(info, id);
622
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530623 return ret;
624}
625
626/**
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530627 * ti_sci_set_device_state_no_wait() - Set device state helper without
628 * requesting or waiting for a response.
629 * @handle: pointer to TI SCI handle
630 * @id: Device identifier
631 * @flags: flags to setup for the device
632 * @state: State to move the device to
633 *
634 * Return: 0 if all went well, else returns appropriate error value.
635 */
636static int ti_sci_set_device_state_no_wait(const struct ti_sci_handle *handle,
637 u32 id, u32 flags, u8 state)
638{
639 struct ti_sci_msg_req_set_device_state req;
640 struct ti_sci_info *info;
641 struct ti_sci_xfer *xfer;
642 int ret = 0;
643
644 if (IS_ERR(handle))
645 return PTR_ERR(handle);
646 if (!handle)
647 return -EINVAL;
648
649 info = handle_to_ti_sci_info(handle);
650
651 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_STATE,
652 flags | TI_SCI_FLAG_REQ_GENERIC_NORESPONSE,
653 (u32 *)&req, sizeof(req), 0);
654 if (IS_ERR(xfer)) {
655 ret = PTR_ERR(xfer);
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530656 return ret;
657 }
658 req.id = id;
659 req.state = state;
660
661 ret = ti_sci_do_xfer(info, xfer);
662 if (ret)
Andrew Davis771a16f2022-07-25 20:25:03 -0500663 return ret;
Andreas Dannenbergca08cb32019-06-07 19:24:40 +0530664
665 return ret;
666}
667
668/**
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530669 * ti_sci_get_device_state() - Get device state helper
670 * @handle: Handle to the device
671 * @id: Device Identifier
672 * @clcnt: Pointer to Context Loss Count
673 * @resets: pointer to resets
674 * @p_state: pointer to p_state
675 * @c_state: pointer to c_state
676 *
677 * Return: 0 if all went fine, else return appropriate error.
678 */
679static int ti_sci_get_device_state(const struct ti_sci_handle *handle,
680 u32 id, u32 *clcnt, u32 *resets,
681 u8 *p_state, u8 *c_state)
682{
683 struct ti_sci_msg_resp_get_device_state *resp;
684 struct ti_sci_msg_req_get_device_state req;
685 struct ti_sci_info *info;
686 struct ti_sci_xfer *xfer;
687 int ret = 0;
688
689 if (IS_ERR(handle))
690 return PTR_ERR(handle);
691 if (!handle)
692 return -EINVAL;
693
694 if (!clcnt && !resets && !p_state && !c_state)
695 return -EINVAL;
696
697 info = handle_to_ti_sci_info(handle);
698
Andrew F. Davis8928fbd2019-04-29 09:04:11 -0400699 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_DEVICE_STATE,
700 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530701 (u32 *)&req, sizeof(req), sizeof(*resp));
702 if (IS_ERR(xfer)) {
703 ret = PTR_ERR(xfer);
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530704 return ret;
705 }
706 req.id = id;
707
708 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -0500709 if (ret)
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530710 return ret;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530711
712 resp = (struct ti_sci_msg_resp_get_device_state *)xfer->tx_message.buf;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530713
714 if (clcnt)
715 *clcnt = resp->context_loss_count;
716 if (resets)
717 *resets = resp->resets;
718 if (p_state)
719 *p_state = resp->programmed_state;
720 if (c_state)
721 *c_state = resp->current_state;
722
723 return ret;
724}
725
726/**
727 * ti_sci_cmd_get_device() - command to request for device managed by TISCI
728 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
729 * @id: Device Identifier
730 *
731 * Request for the device - NOTE: the client MUST maintain integrity of
732 * usage count by balancing get_device with put_device. No refcounting is
733 * managed by driver for that purpose.
734 *
735 * NOTE: The request is for exclusive access for the processor.
736 *
737 * Return: 0 if all went fine, else return appropriate error.
738 */
739static int ti_sci_cmd_get_device(const struct ti_sci_handle *handle, u32 id)
740{
Lokesh Vutlaf5613002019-06-07 19:24:39 +0530741 return ti_sci_set_device_state(handle, id, 0,
742 MSG_DEVICE_SW_STATE_ON);
743}
744
745static int ti_sci_cmd_get_device_exclusive(const struct ti_sci_handle *handle,
746 u32 id)
747{
748 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530749 MSG_DEVICE_SW_STATE_ON);
750}
751
752/**
753 * ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI
754 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
755 * @id: Device Identifier
756 *
757 * Request for the device - NOTE: the client MUST maintain integrity of
758 * usage count by balancing get_device with put_device. No refcounting is
759 * managed by driver for that purpose.
760 *
761 * Return: 0 if all went fine, else return appropriate error.
762 */
763static int ti_sci_cmd_idle_device(const struct ti_sci_handle *handle, u32 id)
764{
765 return ti_sci_set_device_state(handle, id,
Lokesh Vutlaf5613002019-06-07 19:24:39 +0530766 0,
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530767 MSG_DEVICE_SW_STATE_RETENTION);
768}
769
Lokesh Vutlaf5613002019-06-07 19:24:39 +0530770static int ti_sci_cmd_idle_device_exclusive(const struct ti_sci_handle *handle,
771 u32 id)
772{
773 return ti_sci_set_device_state(handle, id, MSG_FLAG_DEVICE_EXCLUSIVE,
774 MSG_DEVICE_SW_STATE_RETENTION);
775}
776
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530777/**
778 * ti_sci_cmd_put_device() - command to release a device managed by TISCI
779 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
780 * @id: Device Identifier
781 *
782 * Request for the device - NOTE: the client MUST maintain integrity of
783 * usage count by balancing get_device with put_device. No refcounting is
784 * managed by driver for that purpose.
785 *
786 * Return: 0 if all went fine, else return appropriate error.
787 */
788static int ti_sci_cmd_put_device(const struct ti_sci_handle *handle, u32 id)
789{
Lokesh Vutlaf5613002019-06-07 19:24:39 +0530790 return ti_sci_set_device_state(handle, id, 0,
791 MSG_DEVICE_SW_STATE_AUTO_OFF);
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530792}
793
Nishanth Menona15ff772025-04-07 07:15:54 -0500794static int ti_sci_cmd_release_exclusive_devices(void)
Lokesh Vutla0d0412a2019-06-07 19:24:41 +0530795{
796 struct ti_sci_exclusive_dev *dev, *tmp;
797 struct ti_sci_info *info;
798 int i, cnt;
799
Nishanth Menona15ff772025-04-07 07:15:54 -0500800 /*
801 * Scan all ti_sci_list registrations, since with FIT images, we could
802 * have started with one device tree registration and switched over
803 * to a final version. This prevents exclusive devices identified
804 * during the first probe to be left orphan.
805 */
806 list_for_each_entry(info, &ti_sci_list, list) {
807 list_for_each_entry_safe(dev, tmp, &info->dev_list, list) {
808 cnt = dev->count;
809 debug("%s: id = %d, cnt = %d\n", __func__, dev->id, cnt);
810 for (i = 0; i < cnt; i++)
811 ti_sci_cmd_put_device(&info->handle, dev->id);
812 }
Lokesh Vutla0d0412a2019-06-07 19:24:41 +0530813 }
814
815 return 0;
816}
817
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530818/**
819 * ti_sci_cmd_dev_is_valid() - Is the device valid
820 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
821 * @id: Device Identifier
822 *
823 * Return: 0 if all went fine and the device ID is valid, else return
824 * appropriate error.
825 */
826static int ti_sci_cmd_dev_is_valid(const struct ti_sci_handle *handle, u32 id)
827{
828 u8 unused;
829
830 /* check the device state which will also tell us if the ID is valid */
831 return ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &unused);
832}
833
834/**
835 * ti_sci_cmd_dev_get_clcnt() - Get context loss counter
836 * @handle: Pointer to TISCI handle
837 * @id: Device Identifier
838 * @count: Pointer to Context Loss counter to populate
839 *
840 * Return: 0 if all went fine, else return appropriate error.
841 */
842static int ti_sci_cmd_dev_get_clcnt(const struct ti_sci_handle *handle, u32 id,
843 u32 *count)
844{
845 return ti_sci_get_device_state(handle, id, count, NULL, NULL, NULL);
846}
847
848/**
849 * ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle
850 * @handle: Pointer to TISCI handle
851 * @id: Device Identifier
852 * @r_state: true if requested to be idle
853 *
854 * Return: 0 if all went fine, else return appropriate error.
855 */
856static int ti_sci_cmd_dev_is_idle(const struct ti_sci_handle *handle, u32 id,
857 bool *r_state)
858{
859 int ret;
860 u8 state;
861
862 if (!r_state)
863 return -EINVAL;
864
865 ret = ti_sci_get_device_state(handle, id, NULL, NULL, &state, NULL);
866 if (ret)
867 return ret;
868
869 *r_state = (state == MSG_DEVICE_SW_STATE_RETENTION);
870
871 return 0;
872}
873
874/**
875 * ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped
876 * @handle: Pointer to TISCI handle
877 * @id: Device Identifier
878 * @r_state: true if requested to be stopped
879 * @curr_state: true if currently stopped.
880 *
881 * Return: 0 if all went fine, else return appropriate error.
882 */
883static int ti_sci_cmd_dev_is_stop(const struct ti_sci_handle *handle, u32 id,
884 bool *r_state, bool *curr_state)
885{
886 int ret;
887 u8 p_state, c_state;
888
889 if (!r_state && !curr_state)
890 return -EINVAL;
891
892 ret =
893 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
894 if (ret)
895 return ret;
896
897 if (r_state)
898 *r_state = (p_state == MSG_DEVICE_SW_STATE_AUTO_OFF);
899 if (curr_state)
900 *curr_state = (c_state == MSG_DEVICE_HW_STATE_OFF);
901
902 return 0;
903}
904
905/**
906 * ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON
907 * @handle: Pointer to TISCI handle
908 * @id: Device Identifier
909 * @r_state: true if requested to be ON
910 * @curr_state: true if currently ON and active
911 *
912 * Return: 0 if all went fine, else return appropriate error.
913 */
914static int ti_sci_cmd_dev_is_on(const struct ti_sci_handle *handle, u32 id,
915 bool *r_state, bool *curr_state)
916{
917 int ret;
918 u8 p_state, c_state;
919
920 if (!r_state && !curr_state)
921 return -EINVAL;
922
923 ret =
924 ti_sci_get_device_state(handle, id, NULL, NULL, &p_state, &c_state);
925 if (ret)
926 return ret;
927
928 if (r_state)
929 *r_state = (p_state == MSG_DEVICE_SW_STATE_ON);
930 if (curr_state)
931 *curr_state = (c_state == MSG_DEVICE_HW_STATE_ON);
932
933 return 0;
934}
935
936/**
937 * ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning
938 * @handle: Pointer to TISCI handle
939 * @id: Device Identifier
940 * @curr_state: true if currently transitioning.
941 *
942 * Return: 0 if all went fine, else return appropriate error.
943 */
944static int ti_sci_cmd_dev_is_trans(const struct ti_sci_handle *handle, u32 id,
945 bool *curr_state)
946{
947 int ret;
948 u8 state;
949
950 if (!curr_state)
951 return -EINVAL;
952
953 ret = ti_sci_get_device_state(handle, id, NULL, NULL, NULL, &state);
954 if (ret)
955 return ret;
956
957 *curr_state = (state == MSG_DEVICE_HW_STATE_TRANS);
958
959 return 0;
960}
961
962/**
963 * ti_sci_cmd_set_device_resets() - command to set resets for device managed
964 * by TISCI
965 * @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle
966 * @id: Device Identifier
967 * @reset_state: Device specific reset bit field
968 *
969 * Return: 0 if all went fine, else return appropriate error.
970 */
971static int ti_sci_cmd_set_device_resets(const struct ti_sci_handle *handle,
972 u32 id, u32 reset_state)
973{
974 struct ti_sci_msg_req_set_device_resets req;
975 struct ti_sci_msg_hdr *resp;
976 struct ti_sci_info *info;
977 struct ti_sci_xfer *xfer;
978 int ret = 0;
979
980 if (IS_ERR(handle))
981 return PTR_ERR(handle);
982 if (!handle)
983 return -EINVAL;
984
985 info = handle_to_ti_sci_info(handle);
986
987 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_DEVICE_RESETS,
988 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
989 (u32 *)&req, sizeof(req), sizeof(*resp));
990 if (IS_ERR(xfer)) {
991 ret = PTR_ERR(xfer);
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530992 return ret;
993 }
994 req.id = id;
995 req.resets = reset_state;
996
997 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -0500998 if (ret)
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +0530999 return ret;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +05301000
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +05301001 return ret;
1002}
1003
1004/**
1005 * ti_sci_cmd_get_device_resets() - Get reset state for device managed
1006 * by TISCI
1007 * @handle: Pointer to TISCI handle
1008 * @id: Device Identifier
1009 * @reset_state: Pointer to reset state to populate
1010 *
1011 * Return: 0 if all went fine, else return appropriate error.
1012 */
1013static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle,
1014 u32 id, u32 *reset_state)
1015{
1016 return ti_sci_get_device_state(handle, id, NULL, reset_state, NULL,
1017 NULL);
1018}
1019
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301020/**
1021 * ti_sci_set_clock_state() - Set clock state helper
1022 * @handle: pointer to TI SCI handle
1023 * @dev_id: Device identifier this request is for
1024 * @clk_id: Clock identifier for the device for this request.
1025 * Each device has it's own set of clock inputs. This indexes
1026 * which clock input to modify.
1027 * @flags: Header flags as needed
1028 * @state: State to request for the clock.
1029 *
1030 * Return: 0 if all went well, else returns appropriate error value.
1031 */
1032static int ti_sci_set_clock_state(const struct ti_sci_handle *handle,
1033 u32 dev_id, u8 clk_id,
1034 u32 flags, u8 state)
1035{
1036 struct ti_sci_msg_req_set_clock_state req;
1037 struct ti_sci_msg_hdr *resp;
1038 struct ti_sci_info *info;
1039 struct ti_sci_xfer *xfer;
1040 int ret = 0;
1041
1042 if (IS_ERR(handle))
1043 return PTR_ERR(handle);
1044 if (!handle)
1045 return -EINVAL;
1046
1047 info = handle_to_ti_sci_info(handle);
1048
1049 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_STATE,
1050 flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1051 (u32 *)&req, sizeof(req), sizeof(*resp));
1052 if (IS_ERR(xfer)) {
1053 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301054 return ret;
1055 }
1056 req.dev_id = dev_id;
1057 req.clk_id = clk_id;
1058 req.request_state = state;
1059
1060 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001061 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301062 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301063
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301064 return ret;
1065}
1066
1067/**
1068 * ti_sci_cmd_get_clock_state() - Get clock state helper
1069 * @handle: pointer to TI SCI handle
1070 * @dev_id: Device identifier this request is for
1071 * @clk_id: Clock identifier for the device for this request.
1072 * Each device has it's own set of clock inputs. This indexes
1073 * which clock input to modify.
1074 * @programmed_state: State requested for clock to move to
1075 * @current_state: State that the clock is currently in
1076 *
1077 * Return: 0 if all went well, else returns appropriate error value.
1078 */
1079static int ti_sci_cmd_get_clock_state(const struct ti_sci_handle *handle,
1080 u32 dev_id, u8 clk_id,
1081 u8 *programmed_state, u8 *current_state)
1082{
1083 struct ti_sci_msg_resp_get_clock_state *resp;
1084 struct ti_sci_msg_req_get_clock_state req;
1085 struct ti_sci_info *info;
1086 struct ti_sci_xfer *xfer;
1087 int ret = 0;
1088
1089 if (IS_ERR(handle))
1090 return PTR_ERR(handle);
1091 if (!handle)
1092 return -EINVAL;
1093
1094 if (!programmed_state && !current_state)
1095 return -EINVAL;
1096
1097 info = handle_to_ti_sci_info(handle);
1098
1099 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_STATE,
1100 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1101 (u32 *)&req, sizeof(req), sizeof(*resp));
1102 if (IS_ERR(xfer)) {
1103 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301104 return ret;
1105 }
1106 req.dev_id = dev_id;
1107 req.clk_id = clk_id;
1108
1109 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001110 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301111 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301112
1113 resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->tx_message.buf;
1114
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301115 if (programmed_state)
1116 *programmed_state = resp->programmed_state;
1117 if (current_state)
1118 *current_state = resp->current_state;
1119
1120 return ret;
1121}
1122
1123/**
1124 * ti_sci_cmd_get_clock() - Get control of a clock from TI SCI
1125 * @handle: pointer to TI SCI handle
1126 * @dev_id: Device identifier this request is for
1127 * @clk_id: Clock identifier for the device for this request.
1128 * Each device has it's own set of clock inputs. This indexes
1129 * which clock input to modify.
1130 * @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false'
1131 * @can_change_freq: 'true' if frequency change is desired, else 'false'
1132 * @enable_input_term: 'true' if input termination is desired, else 'false'
1133 *
1134 * Return: 0 if all went well, else returns appropriate error value.
1135 */
1136static int ti_sci_cmd_get_clock(const struct ti_sci_handle *handle, u32 dev_id,
1137 u8 clk_id, bool needs_ssc, bool can_change_freq,
1138 bool enable_input_term)
1139{
1140 u32 flags = 0;
1141
1142 flags |= needs_ssc ? MSG_FLAG_CLOCK_ALLOW_SSC : 0;
1143 flags |= can_change_freq ? MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE : 0;
1144 flags |= enable_input_term ? MSG_FLAG_CLOCK_INPUT_TERM : 0;
1145
1146 return ti_sci_set_clock_state(handle, dev_id, clk_id, flags,
1147 MSG_CLOCK_SW_STATE_REQ);
1148}
1149
1150/**
1151 * ti_sci_cmd_idle_clock() - Idle a clock which is in our control
1152 * @handle: pointer to TI SCI handle
1153 * @dev_id: Device identifier this request is for
1154 * @clk_id: Clock identifier for the device for this request.
1155 * Each device has it's own set of clock inputs. This indexes
1156 * which clock input to modify.
1157 *
1158 * NOTE: This clock must have been requested by get_clock previously.
1159 *
1160 * Return: 0 if all went well, else returns appropriate error value.
1161 */
1162static int ti_sci_cmd_idle_clock(const struct ti_sci_handle *handle,
1163 u32 dev_id, u8 clk_id)
1164{
1165 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1166 MSG_CLOCK_SW_STATE_UNREQ);
1167}
1168
1169/**
1170 * ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI
1171 * @handle: pointer to TI SCI handle
1172 * @dev_id: Device identifier this request is for
1173 * @clk_id: Clock identifier for the device for this request.
1174 * Each device has it's own set of clock inputs. This indexes
1175 * which clock input to modify.
1176 *
1177 * NOTE: This clock must have been requested by get_clock previously.
1178 *
1179 * Return: 0 if all went well, else returns appropriate error value.
1180 */
1181static int ti_sci_cmd_put_clock(const struct ti_sci_handle *handle,
1182 u32 dev_id, u8 clk_id)
1183{
1184 return ti_sci_set_clock_state(handle, dev_id, clk_id, 0,
1185 MSG_CLOCK_SW_STATE_AUTO);
1186}
1187
1188/**
1189 * ti_sci_cmd_clk_is_auto() - Is the clock being auto managed
1190 * @handle: pointer to TI SCI handle
1191 * @dev_id: Device identifier this request is for
1192 * @clk_id: Clock identifier for the device for this request.
1193 * Each device has it's own set of clock inputs. This indexes
1194 * which clock input to modify.
1195 * @req_state: state indicating if the clock is auto managed
1196 *
1197 * Return: 0 if all went well, else returns appropriate error value.
1198 */
1199static int ti_sci_cmd_clk_is_auto(const struct ti_sci_handle *handle,
1200 u32 dev_id, u8 clk_id, bool *req_state)
1201{
1202 u8 state = 0;
1203 int ret;
1204
1205 if (!req_state)
1206 return -EINVAL;
1207
1208 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id, &state, NULL);
1209 if (ret)
1210 return ret;
1211
1212 *req_state = (state == MSG_CLOCK_SW_STATE_AUTO);
1213 return 0;
1214}
1215
1216/**
1217 * ti_sci_cmd_clk_is_on() - Is the clock ON
1218 * @handle: pointer to TI SCI handle
1219 * @dev_id: Device identifier this request is for
1220 * @clk_id: Clock identifier for the device for this request.
1221 * Each device has it's own set of clock inputs. This indexes
1222 * which clock input to modify.
1223 * @req_state: state indicating if the clock is managed by us and enabled
1224 * @curr_state: state indicating if the clock is ready for operation
1225 *
1226 * Return: 0 if all went well, else returns appropriate error value.
1227 */
1228static int ti_sci_cmd_clk_is_on(const struct ti_sci_handle *handle, u32 dev_id,
1229 u8 clk_id, bool *req_state, bool *curr_state)
1230{
1231 u8 c_state = 0, r_state = 0;
1232 int ret;
1233
1234 if (!req_state && !curr_state)
1235 return -EINVAL;
1236
1237 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1238 &r_state, &c_state);
1239 if (ret)
1240 return ret;
1241
1242 if (req_state)
1243 *req_state = (r_state == MSG_CLOCK_SW_STATE_REQ);
1244 if (curr_state)
1245 *curr_state = (c_state == MSG_CLOCK_HW_STATE_READY);
1246 return 0;
1247}
1248
1249/**
1250 * ti_sci_cmd_clk_is_off() - Is the clock OFF
1251 * @handle: pointer to TI SCI handle
1252 * @dev_id: Device identifier this request is for
1253 * @clk_id: Clock identifier for the device for this request.
1254 * Each device has it's own set of clock inputs. This indexes
1255 * which clock input to modify.
1256 * @req_state: state indicating if the clock is managed by us and disabled
1257 * @curr_state: state indicating if the clock is NOT ready for operation
1258 *
1259 * Return: 0 if all went well, else returns appropriate error value.
1260 */
1261static int ti_sci_cmd_clk_is_off(const struct ti_sci_handle *handle, u32 dev_id,
1262 u8 clk_id, bool *req_state, bool *curr_state)
1263{
1264 u8 c_state = 0, r_state = 0;
1265 int ret;
1266
1267 if (!req_state && !curr_state)
1268 return -EINVAL;
1269
1270 ret = ti_sci_cmd_get_clock_state(handle, dev_id, clk_id,
1271 &r_state, &c_state);
1272 if (ret)
1273 return ret;
1274
1275 if (req_state)
1276 *req_state = (r_state == MSG_CLOCK_SW_STATE_UNREQ);
1277 if (curr_state)
1278 *curr_state = (c_state == MSG_CLOCK_HW_STATE_NOT_READY);
1279 return 0;
1280}
1281
1282/**
1283 * ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock
1284 * @handle: pointer to TI SCI handle
1285 * @dev_id: Device identifier this request is for
1286 * @clk_id: Clock identifier for the device for this request.
1287 * Each device has it's own set of clock inputs. This indexes
1288 * which clock input to modify.
1289 * @parent_id: Parent clock identifier to set
1290 *
1291 * Return: 0 if all went well, else returns appropriate error value.
1292 */
1293static int ti_sci_cmd_clk_set_parent(const struct ti_sci_handle *handle,
1294 u32 dev_id, u8 clk_id, u8 parent_id)
1295{
1296 struct ti_sci_msg_req_set_clock_parent req;
1297 struct ti_sci_msg_hdr *resp;
1298 struct ti_sci_info *info;
1299 struct ti_sci_xfer *xfer;
1300 int ret = 0;
1301
1302 if (IS_ERR(handle))
1303 return PTR_ERR(handle);
1304 if (!handle)
1305 return -EINVAL;
1306
1307 info = handle_to_ti_sci_info(handle);
1308
1309 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_PARENT,
1310 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1311 (u32 *)&req, sizeof(req), sizeof(*resp));
1312 if (IS_ERR(xfer)) {
1313 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301314 return ret;
1315 }
1316 req.dev_id = dev_id;
1317 req.clk_id = clk_id;
1318 req.parent_id = parent_id;
1319
1320 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001321 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301322 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301323
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301324 return ret;
1325}
1326
1327/**
1328 * ti_sci_cmd_clk_get_parent() - Get current parent clock source
1329 * @handle: pointer to TI SCI handle
1330 * @dev_id: Device identifier this request is for
1331 * @clk_id: Clock identifier for the device for this request.
1332 * Each device has it's own set of clock inputs. This indexes
1333 * which clock input to modify.
1334 * @parent_id: Current clock parent
1335 *
1336 * Return: 0 if all went well, else returns appropriate error value.
1337 */
1338static int ti_sci_cmd_clk_get_parent(const struct ti_sci_handle *handle,
1339 u32 dev_id, u8 clk_id, u8 *parent_id)
1340{
1341 struct ti_sci_msg_resp_get_clock_parent *resp;
1342 struct ti_sci_msg_req_get_clock_parent req;
1343 struct ti_sci_info *info;
1344 struct ti_sci_xfer *xfer;
1345 int ret = 0;
1346
1347 if (IS_ERR(handle))
1348 return PTR_ERR(handle);
1349 if (!handle || !parent_id)
1350 return -EINVAL;
1351
1352 info = handle_to_ti_sci_info(handle);
1353
1354 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_PARENT,
1355 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1356 (u32 *)&req, sizeof(req), sizeof(*resp));
1357 if (IS_ERR(xfer)) {
1358 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301359 return ret;
1360 }
1361 req.dev_id = dev_id;
1362 req.clk_id = clk_id;
1363
1364 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001365 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301366 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301367
Andrew Davis04e43932022-07-25 20:25:06 -05001368 *parent_id = resp->parent_id;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301369
1370 return ret;
1371}
1372
1373/**
1374 * ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source
1375 * @handle: pointer to TI SCI handle
1376 * @dev_id: Device identifier this request is for
1377 * @clk_id: Clock identifier for the device for this request.
1378 * Each device has it's own set of clock inputs. This indexes
1379 * which clock input to modify.
1380 * @num_parents: Returns he number of parents to the current clock.
1381 *
1382 * Return: 0 if all went well, else returns appropriate error value.
1383 */
1384static int ti_sci_cmd_clk_get_num_parents(const struct ti_sci_handle *handle,
1385 u32 dev_id, u8 clk_id,
1386 u8 *num_parents)
1387{
1388 struct ti_sci_msg_resp_get_clock_num_parents *resp;
1389 struct ti_sci_msg_req_get_clock_num_parents req;
1390 struct ti_sci_info *info;
1391 struct ti_sci_xfer *xfer;
1392 int ret = 0;
1393
1394 if (IS_ERR(handle))
1395 return PTR_ERR(handle);
1396 if (!handle || !num_parents)
1397 return -EINVAL;
1398
1399 info = handle_to_ti_sci_info(handle);
1400
1401 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_NUM_CLOCK_PARENTS,
1402 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1403 (u32 *)&req, sizeof(req), sizeof(*resp));
1404 if (IS_ERR(xfer)) {
1405 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301406 return ret;
1407 }
1408 req.dev_id = dev_id;
1409 req.clk_id = clk_id;
1410
1411 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001412 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301413 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301414
1415 resp = (struct ti_sci_msg_resp_get_clock_num_parents *)
1416 xfer->tx_message.buf;
1417
Andrew Davis04e43932022-07-25 20:25:06 -05001418 *num_parents = resp->num_parents;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301419
1420 return ret;
1421}
1422
1423/**
1424 * ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency
1425 * @handle: pointer to TI SCI handle
1426 * @dev_id: Device identifier this request is for
1427 * @clk_id: Clock identifier for the device for this request.
1428 * Each device has it's own set of clock inputs. This indexes
1429 * which clock input to modify.
1430 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1431 * allowable programmed frequency and does not account for clock
1432 * tolerances and jitter.
1433 * @target_freq: The target clock frequency in Hz. A frequency will be
1434 * processed as close to this target frequency as possible.
1435 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1436 * allowable programmed frequency and does not account for clock
1437 * tolerances and jitter.
1438 * @match_freq: Frequency match in Hz response.
1439 *
1440 * Return: 0 if all went well, else returns appropriate error value.
1441 */
1442static int ti_sci_cmd_clk_get_match_freq(const struct ti_sci_handle *handle,
1443 u32 dev_id, u8 clk_id, u64 min_freq,
1444 u64 target_freq, u64 max_freq,
1445 u64 *match_freq)
1446{
1447 struct ti_sci_msg_resp_query_clock_freq *resp;
1448 struct ti_sci_msg_req_query_clock_freq req;
1449 struct ti_sci_info *info;
1450 struct ti_sci_xfer *xfer;
1451 int ret = 0;
1452
1453 if (IS_ERR(handle))
1454 return PTR_ERR(handle);
1455 if (!handle || !match_freq)
1456 return -EINVAL;
1457
1458 info = handle_to_ti_sci_info(handle);
1459
1460 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_QUERY_CLOCK_FREQ,
1461 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1462 (u32 *)&req, sizeof(req), sizeof(*resp));
1463 if (IS_ERR(xfer)) {
1464 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301465 return ret;
1466 }
1467 req.dev_id = dev_id;
1468 req.clk_id = clk_id;
1469 req.min_freq_hz = min_freq;
1470 req.target_freq_hz = target_freq;
1471 req.max_freq_hz = max_freq;
1472
1473 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001474 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301475 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301476
1477 resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->tx_message.buf;
1478
Andrew Davis04e43932022-07-25 20:25:06 -05001479 *match_freq = resp->freq_hz;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301480
1481 return ret;
1482}
1483
1484/**
1485 * ti_sci_cmd_clk_set_freq() - Set a frequency for clock
1486 * @handle: pointer to TI SCI handle
1487 * @dev_id: Device identifier this request is for
1488 * @clk_id: Clock identifier for the device for this request.
1489 * Each device has it's own set of clock inputs. This indexes
1490 * which clock input to modify.
1491 * @min_freq: The minimum allowable frequency in Hz. This is the minimum
1492 * allowable programmed frequency and does not account for clock
1493 * tolerances and jitter.
1494 * @target_freq: The target clock frequency in Hz. A frequency will be
1495 * processed as close to this target frequency as possible.
1496 * @max_freq: The maximum allowable frequency in Hz. This is the maximum
1497 * allowable programmed frequency and does not account for clock
1498 * tolerances and jitter.
1499 *
1500 * Return: 0 if all went well, else returns appropriate error value.
1501 */
1502static int ti_sci_cmd_clk_set_freq(const struct ti_sci_handle *handle,
1503 u32 dev_id, u8 clk_id, u64 min_freq,
1504 u64 target_freq, u64 max_freq)
1505{
1506 struct ti_sci_msg_req_set_clock_freq req;
1507 struct ti_sci_msg_hdr *resp;
1508 struct ti_sci_info *info;
1509 struct ti_sci_xfer *xfer;
1510 int ret = 0;
1511
1512 if (IS_ERR(handle))
1513 return PTR_ERR(handle);
1514 if (!handle)
1515 return -EINVAL;
1516
1517 info = handle_to_ti_sci_info(handle);
1518
1519 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SET_CLOCK_FREQ,
1520 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1521 (u32 *)&req, sizeof(req), sizeof(*resp));
1522 if (IS_ERR(xfer)) {
1523 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301524 return ret;
1525 }
1526 req.dev_id = dev_id;
1527 req.clk_id = clk_id;
1528 req.min_freq_hz = min_freq;
1529 req.target_freq_hz = target_freq;
1530 req.max_freq_hz = max_freq;
1531
1532 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001533 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301534 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301535
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301536 return ret;
1537}
1538
1539/**
1540 * ti_sci_cmd_clk_get_freq() - Get current frequency
1541 * @handle: pointer to TI SCI handle
1542 * @dev_id: Device identifier this request is for
1543 * @clk_id: Clock identifier for the device for this request.
1544 * Each device has it's own set of clock inputs. This indexes
1545 * which clock input to modify.
1546 * @freq: Currently frequency in Hz
1547 *
1548 * Return: 0 if all went well, else returns appropriate error value.
1549 */
1550static int ti_sci_cmd_clk_get_freq(const struct ti_sci_handle *handle,
1551 u32 dev_id, u8 clk_id, u64 *freq)
1552{
1553 struct ti_sci_msg_resp_get_clock_freq *resp;
1554 struct ti_sci_msg_req_get_clock_freq req;
1555 struct ti_sci_info *info;
1556 struct ti_sci_xfer *xfer;
1557 int ret = 0;
1558
1559 if (IS_ERR(handle))
1560 return PTR_ERR(handle);
1561 if (!handle || !freq)
1562 return -EINVAL;
1563
1564 info = handle_to_ti_sci_info(handle);
1565
1566 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_CLOCK_FREQ,
1567 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1568 (u32 *)&req, sizeof(req), sizeof(*resp));
1569 if (IS_ERR(xfer)) {
1570 ret = PTR_ERR(xfer);
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301571 return ret;
1572 }
1573 req.dev_id = dev_id;
1574 req.clk_id = clk_id;
1575
1576 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001577 if (ret)
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301578 return ret;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301579
1580 resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->tx_message.buf;
1581
Andrew Davis04e43932022-07-25 20:25:06 -05001582 *freq = resp->freq_hz;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05301583
1584 return ret;
1585}
1586
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05301587/**
1588 * ti_sci_cmd_core_reboot() - Command to request system reset
1589 * @handle: pointer to TI SCI handle
1590 *
1591 * Return: 0 if all went well, else returns appropriate error value.
1592 */
1593static int ti_sci_cmd_core_reboot(const struct ti_sci_handle *handle)
1594{
1595 struct ti_sci_msg_req_reboot req;
1596 struct ti_sci_msg_hdr *resp;
1597 struct ti_sci_info *info;
1598 struct ti_sci_xfer *xfer;
1599 int ret = 0;
1600
1601 if (IS_ERR(handle))
1602 return PTR_ERR(handle);
1603 if (!handle)
1604 return -EINVAL;
1605
1606 info = handle_to_ti_sci_info(handle);
1607
1608 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_SYS_RESET,
1609 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1610 (u32 *)&req, sizeof(req), sizeof(*resp));
1611 if (IS_ERR(xfer)) {
1612 ret = PTR_ERR(xfer);
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05301613 return ret;
1614 }
Dave Gerlach366df4e2021-05-13 20:10:55 -05001615 req.domain = 0;
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05301616
1617 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001618 if (ret)
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05301619 return ret;
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05301620
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05301621 return ret;
1622}
1623
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301624/**
1625 * ti_sci_get_resource_range - Helper to get a range of resources assigned
1626 * to a host. Resource is uniquely identified by
1627 * type and subtype.
1628 * @handle: Pointer to TISCI handle.
1629 * @dev_id: TISCI device ID.
1630 * @subtype: Resource assignment subtype that is being requested
1631 * from the given device.
1632 * @s_host: Host processor ID to which the resources are allocated
1633 * @range_start: Start index of the resource range
1634 * @range_num: Number of resources in the range
1635 *
1636 * Return: 0 if all went fine, else return appropriate error.
1637 */
1638static int ti_sci_get_resource_range(const struct ti_sci_handle *handle,
1639 u32 dev_id, u8 subtype, u8 s_host,
1640 u16 *range_start, u16 *range_num)
1641{
1642 struct ti_sci_msg_resp_get_resource_range *resp;
1643 struct ti_sci_msg_req_get_resource_range req;
1644 struct ti_sci_xfer *xfer;
1645 struct ti_sci_info *info;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301646 int ret = 0;
1647
1648 if (IS_ERR(handle))
1649 return PTR_ERR(handle);
1650 if (!handle)
1651 return -EINVAL;
1652
1653 info = handle_to_ti_sci_info(handle);
1654
1655 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_GET_RESOURCE_RANGE,
1656 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1657 (u32 *)&req, sizeof(req), sizeof(*resp));
1658 if (IS_ERR(xfer)) {
1659 ret = PTR_ERR(xfer);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301660 return ret;
1661 }
1662
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301663 req.secondary_host = s_host;
Lokesh Vutla0acf1dc2020-08-17 11:00:48 +05301664 req.type = dev_id & MSG_RM_RESOURCE_TYPE_MASK;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301665 req.subtype = subtype & MSG_RM_RESOURCE_SUBTYPE_MASK;
1666
1667 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001668 if (ret)
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301669 goto fail;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301670
1671 resp = (struct ti_sci_msg_resp_get_resource_range *)xfer->tx_message.buf;
Andrew Davis04e43932022-07-25 20:25:06 -05001672 if (!resp->range_start && !resp->range_num) {
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301673 ret = -ENODEV;
1674 } else {
1675 *range_start = resp->range_start;
1676 *range_num = resp->range_num;
1677 };
1678
1679fail:
1680 return ret;
1681}
1682
Vignesh Raghavendra4214a812021-06-07 19:47:48 +05301683static int __maybe_unused
Vignesh Raghavendraaa0e3fc2021-06-07 19:47:49 +05301684ti_sci_cmd_get_resource_range_static(const struct ti_sci_handle *handle,
1685 u32 dev_id, u8 subtype,
1686 u16 *range_start, u16 *range_num)
Vignesh Raghavendra4214a812021-06-07 19:47:48 +05301687{
1688 struct ti_sci_resource_static_data *data;
1689 int i = 0;
1690
1691 while (1) {
1692 data = &rm_static_data[i];
1693
1694 if (!data->dev_id)
1695 return -EINVAL;
1696
1697 if (data->dev_id != dev_id || data->subtype != subtype) {
1698 i++;
1699 continue;
1700 }
1701
1702 *range_start = data->range_start;
1703 *range_num = data->range_num;
1704
1705 return 0;
1706 }
1707
1708 return -EINVAL;
1709}
1710
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05301711/**
1712 * ti_sci_cmd_get_resource_range - Get a range of resources assigned to host
1713 * that is same as ti sci interface host.
1714 * @handle: Pointer to TISCI handle.
1715 * @dev_id: TISCI device ID.
1716 * @subtype: Resource assignment subtype that is being requested
1717 * from the given device.
1718 * @range_start: Start index of the resource range
1719 * @range_num: Number of resources in the range
1720 *
1721 * Return: 0 if all went fine, else return appropriate error.
1722 */
1723static int ti_sci_cmd_get_resource_range(const struct ti_sci_handle *handle,
1724 u32 dev_id, u8 subtype,
1725 u16 *range_start, u16 *range_num)
1726{
1727 return ti_sci_get_resource_range(handle, dev_id, subtype,
1728 TI_SCI_IRQ_SECONDARY_HOST_INVALID,
1729 range_start, range_num);
1730}
1731
1732/**
1733 * ti_sci_cmd_get_resource_range_from_shost - Get a range of resources
1734 * assigned to a specified host.
1735 * @handle: Pointer to TISCI handle.
1736 * @dev_id: TISCI device ID.
1737 * @subtype: Resource assignment subtype that is being requested
1738 * from the given device.
1739 * @s_host: Host processor ID to which the resources are allocated
1740 * @range_start: Start index of the resource range
1741 * @range_num: Number of resources in the range
1742 *
1743 * Return: 0 if all went fine, else return appropriate error.
1744 */
1745static
1746int ti_sci_cmd_get_resource_range_from_shost(const struct ti_sci_handle *handle,
1747 u32 dev_id, u8 subtype, u8 s_host,
1748 u16 *range_start, u16 *range_num)
1749{
1750 return ti_sci_get_resource_range(handle, dev_id, subtype, s_host,
1751 range_start, range_num);
1752}
1753
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301754/**
Lokesh Vutla032dce82019-03-08 11:47:32 +05301755 * ti_sci_cmd_query_msmc() - Command to query currently available msmc memory
1756 * @handle: pointer to TI SCI handle
1757 * @msms_start: MSMC start as returned by tisci
1758 * @msmc_end: MSMC end as returned by tisci
1759 *
1760 * Return: 0 if all went well, else returns appropriate error value.
1761 */
1762static int ti_sci_cmd_query_msmc(const struct ti_sci_handle *handle,
1763 u64 *msmc_start, u64 *msmc_end)
1764{
1765 struct ti_sci_msg_resp_query_msmc *resp;
1766 struct ti_sci_msg_hdr req;
1767 struct ti_sci_info *info;
1768 struct ti_sci_xfer *xfer;
1769 int ret = 0;
1770
1771 if (IS_ERR(handle))
1772 return PTR_ERR(handle);
1773 if (!handle)
1774 return -EINVAL;
1775
1776 info = handle_to_ti_sci_info(handle);
1777
1778 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_QUERY_MSMC,
1779 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1780 (u32 *)&req, sizeof(req), sizeof(*resp));
1781 if (IS_ERR(xfer)) {
1782 ret = PTR_ERR(xfer);
Lokesh Vutla032dce82019-03-08 11:47:32 +05301783 return ret;
1784 }
1785
1786 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001787 if (ret)
Lokesh Vutla032dce82019-03-08 11:47:32 +05301788 return ret;
Lokesh Vutla032dce82019-03-08 11:47:32 +05301789
1790 resp = (struct ti_sci_msg_resp_query_msmc *)xfer->tx_message.buf;
1791
Lokesh Vutla032dce82019-03-08 11:47:32 +05301792 *msmc_start = ((u64)resp->msmc_start_high << TISCI_ADDR_HIGH_SHIFT) |
1793 resp->msmc_start_low;
1794 *msmc_end = ((u64)resp->msmc_end_high << TISCI_ADDR_HIGH_SHIFT) |
1795 resp->msmc_end_low;
1796
1797 return ret;
1798}
1799
1800/**
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301801 * ti_sci_cmd_proc_request() - Command to request a physical processor control
1802 * @handle: Pointer to TI SCI handle
1803 * @proc_id: Processor ID this request is for
1804 *
1805 * Return: 0 if all went well, else returns appropriate error value.
1806 */
1807static int ti_sci_cmd_proc_request(const struct ti_sci_handle *handle,
1808 u8 proc_id)
1809{
1810 struct ti_sci_msg_req_proc_request req;
1811 struct ti_sci_msg_hdr *resp;
1812 struct ti_sci_info *info;
1813 struct ti_sci_xfer *xfer;
1814 int ret = 0;
1815
1816 if (IS_ERR(handle))
1817 return PTR_ERR(handle);
1818 if (!handle)
1819 return -EINVAL;
1820
1821 info = handle_to_ti_sci_info(handle);
1822
1823 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_REQUEST,
1824 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1825 (u32 *)&req, sizeof(req), sizeof(*resp));
1826 if (IS_ERR(xfer)) {
1827 ret = PTR_ERR(xfer);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301828 return ret;
1829 }
1830 req.processor_id = proc_id;
1831
1832 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001833 if (ret)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301834 return ret;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301835
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301836 return ret;
1837}
1838
1839/**
1840 * ti_sci_cmd_proc_release() - Command to release a physical processor control
1841 * @handle: Pointer to TI SCI handle
1842 * @proc_id: Processor ID this request is for
1843 *
1844 * Return: 0 if all went well, else returns appropriate error value.
1845 */
1846static int ti_sci_cmd_proc_release(const struct ti_sci_handle *handle,
1847 u8 proc_id)
1848{
1849 struct ti_sci_msg_req_proc_release req;
1850 struct ti_sci_msg_hdr *resp;
1851 struct ti_sci_info *info;
1852 struct ti_sci_xfer *xfer;
1853 int ret = 0;
1854
1855 if (IS_ERR(handle))
1856 return PTR_ERR(handle);
1857 if (!handle)
1858 return -EINVAL;
1859
1860 info = handle_to_ti_sci_info(handle);
1861
1862 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_RELEASE,
1863 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1864 (u32 *)&req, sizeof(req), sizeof(*resp));
1865 if (IS_ERR(xfer)) {
1866 ret = PTR_ERR(xfer);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301867 return ret;
1868 }
1869 req.processor_id = proc_id;
1870
1871 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001872 if (ret)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301873 return ret;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301874
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301875 return ret;
1876}
1877
1878/**
1879 * ti_sci_cmd_proc_handover() - Command to handover a physical processor
1880 * control to a host in the processor's access
1881 * control list.
1882 * @handle: Pointer to TI SCI handle
1883 * @proc_id: Processor ID this request is for
1884 * @host_id: Host ID to get the control of the processor
1885 *
1886 * Return: 0 if all went well, else returns appropriate error value.
1887 */
1888static int ti_sci_cmd_proc_handover(const struct ti_sci_handle *handle,
1889 u8 proc_id, u8 host_id)
1890{
1891 struct ti_sci_msg_req_proc_handover req;
1892 struct ti_sci_msg_hdr *resp;
1893 struct ti_sci_info *info;
1894 struct ti_sci_xfer *xfer;
1895 int ret = 0;
1896
1897 if (IS_ERR(handle))
1898 return PTR_ERR(handle);
1899 if (!handle)
1900 return -EINVAL;
1901
1902 info = handle_to_ti_sci_info(handle);
1903
1904 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_HANDOVER,
1905 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1906 (u32 *)&req, sizeof(req), sizeof(*resp));
1907 if (IS_ERR(xfer)) {
1908 ret = PTR_ERR(xfer);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301909 return ret;
1910 }
1911 req.processor_id = proc_id;
1912 req.host_id = host_id;
1913
1914 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001915 if (ret)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301916 return ret;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301917
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301918 return ret;
1919}
1920
1921/**
1922 * ti_sci_cmd_set_proc_boot_cfg() - Command to set the processor boot
1923 * configuration flags
1924 * @handle: Pointer to TI SCI handle
1925 * @proc_id: Processor ID this request is for
1926 * @config_flags_set: Configuration flags to be set
1927 * @config_flags_clear: Configuration flags to be cleared.
1928 *
1929 * Return: 0 if all went well, else returns appropriate error value.
1930 */
1931static int ti_sci_cmd_set_proc_boot_cfg(const struct ti_sci_handle *handle,
1932 u8 proc_id, u64 bootvector,
1933 u32 config_flags_set,
1934 u32 config_flags_clear)
1935{
1936 struct ti_sci_msg_req_set_proc_boot_config req;
1937 struct ti_sci_msg_hdr *resp;
1938 struct ti_sci_info *info;
1939 struct ti_sci_xfer *xfer;
1940 int ret = 0;
1941
1942 if (IS_ERR(handle))
1943 return PTR_ERR(handle);
1944 if (!handle)
1945 return -EINVAL;
1946
1947 info = handle_to_ti_sci_info(handle);
1948
1949 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CONFIG,
1950 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1951 (u32 *)&req, sizeof(req), sizeof(*resp));
1952 if (IS_ERR(xfer)) {
1953 ret = PTR_ERR(xfer);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301954 return ret;
1955 }
1956 req.processor_id = proc_id;
1957 req.bootvector_low = bootvector & TISCI_ADDR_LOW_MASK;
1958 req.bootvector_high = (bootvector & TISCI_ADDR_HIGH_MASK) >>
1959 TISCI_ADDR_HIGH_SHIFT;
1960 req.config_flags_set = config_flags_set;
1961 req.config_flags_clear = config_flags_clear;
1962
1963 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05001964 if (ret)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301965 return ret;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301966
Lokesh Vutlab8856af2018-08-27 15:57:37 +05301967 return ret;
1968}
1969
1970/**
1971 * ti_sci_cmd_set_proc_boot_ctrl() - Command to set the processor boot
1972 * control flags
1973 * @handle: Pointer to TI SCI handle
1974 * @proc_id: Processor ID this request is for
1975 * @control_flags_set: Control flags to be set
1976 * @control_flags_clear: Control flags to be cleared
1977 *
1978 * Return: 0 if all went well, else returns appropriate error value.
1979 */
1980static int ti_sci_cmd_set_proc_boot_ctrl(const struct ti_sci_handle *handle,
1981 u8 proc_id, u32 control_flags_set,
1982 u32 control_flags_clear)
1983{
1984 struct ti_sci_msg_req_set_proc_boot_ctrl req;
1985 struct ti_sci_msg_hdr *resp;
1986 struct ti_sci_info *info;
1987 struct ti_sci_xfer *xfer;
1988 int ret = 0;
1989
1990 if (IS_ERR(handle))
1991 return PTR_ERR(handle);
1992 if (!handle)
1993 return -EINVAL;
1994
1995 info = handle_to_ti_sci_info(handle);
1996
1997 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_SET_PROC_BOOT_CTRL,
1998 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
1999 (u32 *)&req, sizeof(req), sizeof(*resp));
2000 if (IS_ERR(xfer)) {
2001 ret = PTR_ERR(xfer);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302002 return ret;
2003 }
2004 req.processor_id = proc_id;
2005 req.control_flags_set = control_flags_set;
2006 req.control_flags_clear = control_flags_clear;
2007
2008 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002009 if (ret)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302010 return ret;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302011
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302012 return ret;
2013}
2014
2015/**
2016 * ti_sci_cmd_proc_auth_boot_image() - Command to authenticate and load the
2017 * image and then set the processor configuration flags.
2018 * @handle: Pointer to TI SCI handle
Andrew F. Davis7aa9a082019-04-12 12:54:44 -04002019 * @image_addr: Memory address at which payload image and certificate is
2020 * located in memory, this is updated if the image data is
2021 * moved during authentication.
2022 * @image_size: This is updated with the final size of the image after
2023 * authentication.
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302024 *
2025 * Return: 0 if all went well, else returns appropriate error value.
2026 */
2027static int ti_sci_cmd_proc_auth_boot_image(const struct ti_sci_handle *handle,
Andrew F. Davis7aa9a082019-04-12 12:54:44 -04002028 u64 *image_addr, u32 *image_size)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302029{
2030 struct ti_sci_msg_req_proc_auth_boot_image req;
Andrew F. Davis7aa9a082019-04-12 12:54:44 -04002031 struct ti_sci_msg_resp_proc_auth_boot_image *resp;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302032 struct ti_sci_info *info;
2033 struct ti_sci_xfer *xfer;
2034 int ret = 0;
2035
2036 if (IS_ERR(handle))
2037 return PTR_ERR(handle);
2038 if (!handle)
2039 return -EINVAL;
2040
2041 info = handle_to_ti_sci_info(handle);
2042
Jorge Ramirez-Ortizb0373282023-01-10 18:29:48 +01002043 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_PROC_AUTH_BOOT_IMAGE,
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302044 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2045 (u32 *)&req, sizeof(req), sizeof(*resp));
2046 if (IS_ERR(xfer)) {
2047 ret = PTR_ERR(xfer);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302048 return ret;
2049 }
Andrew F. Davis7aa9a082019-04-12 12:54:44 -04002050 req.cert_addr_low = *image_addr & TISCI_ADDR_LOW_MASK;
2051 req.cert_addr_high = (*image_addr & TISCI_ADDR_HIGH_MASK) >>
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302052 TISCI_ADDR_HIGH_SHIFT;
2053
2054 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002055 if (ret)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302056 return ret;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302057
Andrew F. Davis7aa9a082019-04-12 12:54:44 -04002058 resp = (struct ti_sci_msg_resp_proc_auth_boot_image *)xfer->tx_message.buf;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302059
Andrew F. Davis7aa9a082019-04-12 12:54:44 -04002060 *image_addr = (resp->image_addr_low & TISCI_ADDR_LOW_MASK) |
2061 (((u64)resp->image_addr_high <<
2062 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2063 *image_size = resp->image_size;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302064
2065 return ret;
2066}
2067
2068/**
2069 * ti_sci_cmd_get_proc_boot_status() - Command to get the processor boot status
2070 * @handle: Pointer to TI SCI handle
2071 * @proc_id: Processor ID this request is for
2072 *
2073 * Return: 0 if all went well, else returns appropriate error value.
2074 */
2075static int ti_sci_cmd_get_proc_boot_status(const struct ti_sci_handle *handle,
2076 u8 proc_id, u64 *bv, u32 *cfg_flags,
2077 u32 *ctrl_flags, u32 *sts_flags)
2078{
2079 struct ti_sci_msg_resp_get_proc_boot_status *resp;
2080 struct ti_sci_msg_req_get_proc_boot_status req;
2081 struct ti_sci_info *info;
2082 struct ti_sci_xfer *xfer;
2083 int ret = 0;
2084
2085 if (IS_ERR(handle))
2086 return PTR_ERR(handle);
2087 if (!handle)
2088 return -EINVAL;
2089
2090 info = handle_to_ti_sci_info(handle);
2091
2092 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_GET_PROC_BOOT_STATUS,
2093 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2094 (u32 *)&req, sizeof(req), sizeof(*resp));
2095 if (IS_ERR(xfer)) {
2096 ret = PTR_ERR(xfer);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302097 return ret;
2098 }
2099 req.processor_id = proc_id;
2100
2101 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002102 if (ret)
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302103 return ret;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302104
2105 resp = (struct ti_sci_msg_resp_get_proc_boot_status *)
2106 xfer->tx_message.buf;
2107
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302108 *bv = (resp->bootvector_low & TISCI_ADDR_LOW_MASK) |
2109 (((u64)resp->bootvector_high <<
2110 TISCI_ADDR_HIGH_SHIFT) & TISCI_ADDR_HIGH_MASK);
2111 *cfg_flags = resp->config_flags;
2112 *ctrl_flags = resp->control_flags;
2113 *sts_flags = resp->status_flags;
2114
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302115 return ret;
2116}
2117
2118/**
Andreas Dannenbergca08cb32019-06-07 19:24:40 +05302119 * ti_sci_proc_wait_boot_status_no_wait() - Helper function to wait for a
2120 * processor boot status without requesting or
2121 * waiting for a response.
2122 * @proc_id: Processor ID this request is for
2123 * @num_wait_iterations: Total number of iterations we will check before
2124 * we will timeout and give up
2125 * @num_match_iterations: How many iterations should we have continued
2126 * status to account for status bits glitching.
2127 * This is to make sure that match occurs for
2128 * consecutive checks. This implies that the
2129 * worst case should consider that the stable
2130 * time should at the worst be num_wait_iterations
2131 * num_match_iterations to prevent timeout.
2132 * @delay_per_iteration_us: Specifies how long to wait (in micro seconds)
2133 * between each status checks. This is the minimum
2134 * duration, and overhead of register reads and
2135 * checks are on top of this and can vary based on
2136 * varied conditions.
2137 * @delay_before_iterations_us: Specifies how long to wait (in micro seconds)
2138 * before the very first check in the first
2139 * iteration of status check loop. This is the
2140 * minimum duration, and overhead of register
2141 * reads and checks are.
2142 * @status_flags_1_set_all_wait:If non-zero, Specifies that all bits of the
2143 * status matching this field requested MUST be 1.
2144 * @status_flags_1_set_any_wait:If non-zero, Specifies that at least one of the
2145 * bits matching this field requested MUST be 1.
2146 * @status_flags_1_clr_all_wait:If non-zero, Specifies that all bits of the
2147 * status matching this field requested MUST be 0.
2148 * @status_flags_1_clr_any_wait:If non-zero, Specifies that at least one of the
2149 * bits matching this field requested MUST be 0.
2150 *
2151 * Return: 0 if all goes well, else appropriate error message
2152 */
2153static int
2154ti_sci_proc_wait_boot_status_no_wait(const struct ti_sci_handle *handle,
2155 u8 proc_id,
2156 u8 num_wait_iterations,
2157 u8 num_match_iterations,
2158 u8 delay_per_iteration_us,
2159 u8 delay_before_iterations_us,
2160 u32 status_flags_1_set_all_wait,
2161 u32 status_flags_1_set_any_wait,
2162 u32 status_flags_1_clr_all_wait,
2163 u32 status_flags_1_clr_any_wait)
2164{
2165 struct ti_sci_msg_req_wait_proc_boot_status req;
2166 struct ti_sci_info *info;
2167 struct ti_sci_xfer *xfer;
2168 int ret = 0;
2169
2170 if (IS_ERR(handle))
2171 return PTR_ERR(handle);
2172 if (!handle)
2173 return -EINVAL;
2174
2175 info = handle_to_ti_sci_info(handle);
2176
2177 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_WAIT_PROC_BOOT_STATUS,
2178 TI_SCI_FLAG_REQ_GENERIC_NORESPONSE,
2179 (u32 *)&req, sizeof(req), 0);
2180 if (IS_ERR(xfer)) {
2181 ret = PTR_ERR(xfer);
Andreas Dannenbergca08cb32019-06-07 19:24:40 +05302182 return ret;
2183 }
2184 req.processor_id = proc_id;
2185 req.num_wait_iterations = num_wait_iterations;
2186 req.num_match_iterations = num_match_iterations;
2187 req.delay_per_iteration_us = delay_per_iteration_us;
2188 req.delay_before_iterations_us = delay_before_iterations_us;
2189 req.status_flags_1_set_all_wait = status_flags_1_set_all_wait;
2190 req.status_flags_1_set_any_wait = status_flags_1_set_any_wait;
2191 req.status_flags_1_clr_all_wait = status_flags_1_clr_all_wait;
2192 req.status_flags_1_clr_any_wait = status_flags_1_clr_any_wait;
2193
2194 ret = ti_sci_do_xfer(info, xfer);
2195 if (ret)
Andrew Davis771a16f2022-07-25 20:25:03 -05002196 return ret;
Andreas Dannenbergca08cb32019-06-07 19:24:40 +05302197
2198 return ret;
2199}
2200
2201/**
2202 * ti_sci_cmd_proc_shutdown_no_wait() - Command to shutdown a core without
2203 * requesting or waiting for a response. Note that this API call
2204 * should be followed by placing the respective processor into
2205 * either WFE or WFI mode.
2206 * @handle: Pointer to TI SCI handle
2207 * @proc_id: Processor ID this request is for
2208 *
2209 * Return: 0 if all went well, else returns appropriate error value.
2210 */
2211static int ti_sci_cmd_proc_shutdown_no_wait(const struct ti_sci_handle *handle,
2212 u8 proc_id)
2213{
2214 int ret;
Sean Anderson405dc242020-09-15 10:44:38 -04002215 struct ti_sci_info *info;
2216
2217 if (IS_ERR(handle))
2218 return PTR_ERR(handle);
2219 if (!handle)
2220 return -EINVAL;
2221
2222 info = handle_to_ti_sci_info(handle);
Andreas Dannenbergca08cb32019-06-07 19:24:40 +05302223
2224 /*
2225 * Send the core boot status wait message waiting for either WFE or
2226 * WFI without requesting or waiting for a TISCI response with the
2227 * maximum wait time to give us the best chance to get to the WFE/WFI
2228 * command that should follow the invocation of this API before the
2229 * DMSC-internal processing of this command times out. Note that
2230 * waiting for the R5 WFE/WFI flags will also work on an ARMV8 type
2231 * core as the related flag bit positions are the same.
2232 */
2233 ret = ti_sci_proc_wait_boot_status_no_wait(handle, proc_id,
2234 U8_MAX, 100, U8_MAX, U8_MAX,
2235 0, PROC_BOOT_STATUS_FLAG_R5_WFE | PROC_BOOT_STATUS_FLAG_R5_WFI,
2236 0, 0);
2237 if (ret) {
2238 dev_err(info->dev, "Sending core %u wait message fail %d\n",
2239 proc_id, ret);
2240 return ret;
2241 }
2242
2243 /*
2244 * Release a processor managed by TISCI without requesting or waiting
2245 * for a response.
2246 */
2247 ret = ti_sci_set_device_state_no_wait(handle, proc_id, 0,
2248 MSG_DEVICE_SW_STATE_AUTO_OFF);
2249 if (ret)
2250 dev_err(info->dev, "Sending core %u shutdown message fail %d\n",
2251 proc_id, ret);
2252
2253 return ret;
2254}
2255
2256/**
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302257 * ti_sci_cmd_ring_config() - configure RA ring
2258 * @handle: pointer to TI SCI handle
2259 * @valid_params: Bitfield defining validity of ring configuration parameters.
2260 * @nav_id: Device ID of Navigator Subsystem from which the ring is allocated
2261 * @index: Ring index.
2262 * @addr_lo: The ring base address lo 32 bits
2263 * @addr_hi: The ring base address hi 32 bits
2264 * @count: Number of ring elements.
2265 * @mode: The mode of the ring
2266 * @size: The ring element size.
2267 * @order_id: Specifies the ring's bus order ID.
2268 *
2269 * Return: 0 if all went well, else returns appropriate error value.
2270 *
2271 * See @ti_sci_msg_rm_ring_cfg_req for more info.
2272 */
2273static int ti_sci_cmd_ring_config(const struct ti_sci_handle *handle,
2274 u32 valid_params, u16 nav_id, u16 index,
2275 u32 addr_lo, u32 addr_hi, u32 count,
2276 u8 mode, u8 size, u8 order_id)
2277{
2278 struct ti_sci_msg_rm_ring_cfg_resp *resp;
2279 struct ti_sci_msg_rm_ring_cfg_req req;
2280 struct ti_sci_xfer *xfer;
2281 struct ti_sci_info *info;
2282 int ret = 0;
2283
2284 if (IS_ERR(handle))
2285 return PTR_ERR(handle);
2286 if (!handle)
2287 return -EINVAL;
2288
2289 info = handle_to_ti_sci_info(handle);
2290
2291 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_RING_CFG,
2292 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2293 (u32 *)&req, sizeof(req), sizeof(*resp));
2294 if (IS_ERR(xfer)) {
2295 ret = PTR_ERR(xfer);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302296 return ret;
2297 }
2298 req.valid_params = valid_params;
2299 req.nav_id = nav_id;
2300 req.index = index;
2301 req.addr_lo = addr_lo;
2302 req.addr_hi = addr_hi;
2303 req.count = count;
2304 req.mode = mode;
2305 req.size = size;
2306 req.order_id = order_id;
2307
2308 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002309 if (ret)
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302310 goto fail;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302311
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302312fail:
2313 dev_dbg(info->dev, "RM_RA:config ring %u ret:%d\n", index, ret);
2314 return ret;
2315}
2316
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302317static int ti_sci_cmd_rm_psil_pair(const struct ti_sci_handle *handle,
2318 u32 nav_id, u32 src_thread, u32 dst_thread)
2319{
2320 struct ti_sci_msg_hdr *resp;
2321 struct ti_sci_msg_psil_pair req;
2322 struct ti_sci_xfer *xfer;
2323 struct ti_sci_info *info;
2324 int ret = 0;
2325
2326 if (IS_ERR(handle))
2327 return PTR_ERR(handle);
2328 if (!handle)
2329 return -EINVAL;
2330
2331 info = handle_to_ti_sci_info(handle);
2332
2333 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_PAIR,
2334 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2335 (u32 *)&req, sizeof(req), sizeof(*resp));
2336 if (IS_ERR(xfer)) {
2337 ret = PTR_ERR(xfer);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302338 return ret;
2339 }
2340 req.nav_id = nav_id;
2341 req.src_thread = src_thread;
2342 req.dst_thread = dst_thread;
2343
2344 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002345 if (ret)
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302346 goto fail;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302347
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302348fail:
2349 dev_dbg(info->dev, "RM_PSIL: nav: %u link pair %u->%u ret:%u\n",
2350 nav_id, src_thread, dst_thread, ret);
2351 return ret;
2352}
2353
2354static int ti_sci_cmd_rm_psil_unpair(const struct ti_sci_handle *handle,
2355 u32 nav_id, u32 src_thread, u32 dst_thread)
2356{
2357 struct ti_sci_msg_hdr *resp;
2358 struct ti_sci_msg_psil_unpair req;
2359 struct ti_sci_xfer *xfer;
2360 struct ti_sci_info *info;
2361 int ret = 0;
2362
2363 if (IS_ERR(handle))
2364 return PTR_ERR(handle);
2365 if (!handle)
2366 return -EINVAL;
2367
2368 info = handle_to_ti_sci_info(handle);
2369
2370 xfer = ti_sci_setup_one_xfer(info, TI_SCI_MSG_RM_PSIL_UNPAIR,
2371 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2372 (u32 *)&req, sizeof(req), sizeof(*resp));
2373 if (IS_ERR(xfer)) {
2374 ret = PTR_ERR(xfer);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302375 return ret;
2376 }
2377 req.nav_id = nav_id;
2378 req.src_thread = src_thread;
2379 req.dst_thread = dst_thread;
2380
2381 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002382 if (ret)
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302383 goto fail;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302384
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302385fail:
2386 dev_dbg(info->dev, "RM_PSIL: link unpair %u->%u ret:%u\n",
2387 src_thread, dst_thread, ret);
2388 return ret;
2389}
2390
2391static int ti_sci_cmd_rm_udmap_tx_ch_cfg(
2392 const struct ti_sci_handle *handle,
2393 const struct ti_sci_msg_rm_udmap_tx_ch_cfg *params)
2394{
2395 struct ti_sci_msg_rm_udmap_tx_ch_cfg_resp *resp;
2396 struct ti_sci_msg_rm_udmap_tx_ch_cfg_req req;
2397 struct ti_sci_xfer *xfer;
2398 struct ti_sci_info *info;
2399 int ret = 0;
2400
2401 if (IS_ERR(handle))
2402 return PTR_ERR(handle);
2403 if (!handle)
2404 return -EINVAL;
2405
2406 info = handle_to_ti_sci_info(handle);
2407
2408 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_TX_CH_CFG,
2409 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2410 (u32 *)&req, sizeof(req), sizeof(*resp));
2411 if (IS_ERR(xfer)) {
2412 ret = PTR_ERR(xfer);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302413 return ret;
2414 }
2415 req.valid_params = params->valid_params;
2416 req.nav_id = params->nav_id;
2417 req.index = params->index;
2418 req.tx_pause_on_err = params->tx_pause_on_err;
2419 req.tx_filt_einfo = params->tx_filt_einfo;
2420 req.tx_filt_pswords = params->tx_filt_pswords;
2421 req.tx_atype = params->tx_atype;
2422 req.tx_chan_type = params->tx_chan_type;
2423 req.tx_supr_tdpkt = params->tx_supr_tdpkt;
2424 req.tx_fetch_size = params->tx_fetch_size;
2425 req.tx_credit_count = params->tx_credit_count;
2426 req.txcq_qnum = params->txcq_qnum;
2427 req.tx_priority = params->tx_priority;
2428 req.tx_qos = params->tx_qos;
2429 req.tx_orderid = params->tx_orderid;
2430 req.fdepth = params->fdepth;
2431 req.tx_sched_priority = params->tx_sched_priority;
Vignesh Raghavendraa8a2b8a2021-05-10 20:06:02 +05302432 req.tx_burst_size = params->tx_burst_size;
2433 req.tx_tdtype = params->tx_tdtype;
2434 req.extended_ch_type = params->extended_ch_type;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302435
2436 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002437 if (ret)
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302438 goto fail;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302439
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302440fail:
2441 dev_dbg(info->dev, "TX_CH_CFG: chn %u ret:%u\n", params->index, ret);
2442 return ret;
2443}
2444
2445static int ti_sci_cmd_rm_udmap_rx_ch_cfg(
2446 const struct ti_sci_handle *handle,
2447 const struct ti_sci_msg_rm_udmap_rx_ch_cfg *params)
2448{
2449 struct ti_sci_msg_rm_udmap_rx_ch_cfg_resp *resp;
2450 struct ti_sci_msg_rm_udmap_rx_ch_cfg_req req;
2451 struct ti_sci_xfer *xfer;
2452 struct ti_sci_info *info;
2453 int ret = 0;
2454
2455 if (IS_ERR(handle))
2456 return PTR_ERR(handle);
2457 if (!handle)
2458 return -EINVAL;
2459
2460 info = handle_to_ti_sci_info(handle);
2461
2462 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_RX_CH_CFG,
2463 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2464 (u32 *)&req, sizeof(req), sizeof(*resp));
2465 if (IS_ERR(xfer)) {
2466 ret = PTR_ERR(xfer);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302467 return ret;
2468 }
2469
2470 req.valid_params = params->valid_params;
2471 req.nav_id = params->nav_id;
2472 req.index = params->index;
2473 req.rx_fetch_size = params->rx_fetch_size;
2474 req.rxcq_qnum = params->rxcq_qnum;
2475 req.rx_priority = params->rx_priority;
2476 req.rx_qos = params->rx_qos;
2477 req.rx_orderid = params->rx_orderid;
2478 req.rx_sched_priority = params->rx_sched_priority;
2479 req.flowid_start = params->flowid_start;
2480 req.flowid_cnt = params->flowid_cnt;
2481 req.rx_pause_on_err = params->rx_pause_on_err;
2482 req.rx_atype = params->rx_atype;
2483 req.rx_chan_type = params->rx_chan_type;
2484 req.rx_ignore_short = params->rx_ignore_short;
2485 req.rx_ignore_long = params->rx_ignore_long;
2486
2487 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002488 if (ret)
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302489 goto fail;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302490
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302491fail:
2492 dev_dbg(info->dev, "RX_CH_CFG: chn %u ret:%d\n", params->index, ret);
2493 return ret;
2494}
2495
2496static int ti_sci_cmd_rm_udmap_rx_flow_cfg(
2497 const struct ti_sci_handle *handle,
2498 const struct ti_sci_msg_rm_udmap_flow_cfg *params)
2499{
2500 struct ti_sci_msg_rm_udmap_flow_cfg_resp *resp;
2501 struct ti_sci_msg_rm_udmap_flow_cfg_req req;
2502 struct ti_sci_xfer *xfer;
2503 struct ti_sci_info *info;
2504 int ret = 0;
2505
2506 if (IS_ERR(handle))
2507 return PTR_ERR(handle);
2508 if (!handle)
2509 return -EINVAL;
2510
2511 info = handle_to_ti_sci_info(handle);
2512
2513 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_RM_UDMAP_FLOW_CFG,
2514 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2515 (u32 *)&req, sizeof(req), sizeof(*resp));
2516 if (IS_ERR(xfer)) {
2517 ret = PTR_ERR(xfer);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302518 return ret;
2519 }
2520
2521 req.valid_params = params->valid_params;
2522 req.nav_id = params->nav_id;
2523 req.flow_index = params->flow_index;
2524 req.rx_einfo_present = params->rx_einfo_present;
2525 req.rx_psinfo_present = params->rx_psinfo_present;
2526 req.rx_error_handling = params->rx_error_handling;
2527 req.rx_desc_type = params->rx_desc_type;
2528 req.rx_sop_offset = params->rx_sop_offset;
2529 req.rx_dest_qnum = params->rx_dest_qnum;
2530 req.rx_src_tag_hi = params->rx_src_tag_hi;
2531 req.rx_src_tag_lo = params->rx_src_tag_lo;
2532 req.rx_dest_tag_hi = params->rx_dest_tag_hi;
2533 req.rx_dest_tag_lo = params->rx_dest_tag_lo;
2534 req.rx_src_tag_hi_sel = params->rx_src_tag_hi_sel;
2535 req.rx_src_tag_lo_sel = params->rx_src_tag_lo_sel;
2536 req.rx_dest_tag_hi_sel = params->rx_dest_tag_hi_sel;
2537 req.rx_dest_tag_lo_sel = params->rx_dest_tag_lo_sel;
2538 req.rx_fdq0_sz0_qnum = params->rx_fdq0_sz0_qnum;
2539 req.rx_fdq1_qnum = params->rx_fdq1_qnum;
2540 req.rx_fdq2_qnum = params->rx_fdq2_qnum;
2541 req.rx_fdq3_qnum = params->rx_fdq3_qnum;
2542 req.rx_ps_location = params->rx_ps_location;
2543
2544 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002545 if (ret)
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302546 goto fail;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302547
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302548fail:
2549 dev_dbg(info->dev, "RX_FL_CFG: %u ret:%d\n", params->flow_index, ret);
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302550 return ret;
2551}
2552
Kishon Vijay Abraham Ie9876c82024-08-26 15:55:06 +05302553static int ti_sci_cmd_rm_udmap_rx_flow_cfg_noop(const struct ti_sci_handle *handle,
2554 const struct ti_sci_msg_rm_udmap_flow_cfg *params)
2555{
2556 return 0;
2557}
2558
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002559/**
2560 * ti_sci_cmd_set_fwl_region() - Request for configuring a firewall region
2561 * @handle: pointer to TI SCI handle
2562 * @region: region configuration parameters
2563 *
2564 * Return: 0 if all went well, else returns appropriate error value.
2565 */
2566static int ti_sci_cmd_set_fwl_region(const struct ti_sci_handle *handle,
2567 const struct ti_sci_msg_fwl_region *region)
2568{
2569 struct ti_sci_msg_fwl_set_firewall_region_req req;
2570 struct ti_sci_msg_hdr *resp;
2571 struct ti_sci_info *info;
2572 struct ti_sci_xfer *xfer;
2573 int ret = 0;
2574
2575 if (IS_ERR(handle))
2576 return PTR_ERR(handle);
2577 if (!handle)
2578 return -EINVAL;
2579
2580 info = handle_to_ti_sci_info(handle);
2581
2582 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_SET,
2583 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2584 (u32 *)&req, sizeof(req), sizeof(*resp));
2585 if (IS_ERR(xfer)) {
2586 ret = PTR_ERR(xfer);
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002587 return ret;
2588 }
2589
2590 req.fwl_id = region->fwl_id;
2591 req.region = region->region;
2592 req.n_permission_regs = region->n_permission_regs;
2593 req.control = region->control;
2594 req.permissions[0] = region->permissions[0];
2595 req.permissions[1] = region->permissions[1];
2596 req.permissions[2] = region->permissions[2];
2597 req.start_address = region->start_address;
2598 req.end_address = region->end_address;
2599
2600 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002601 if (ret)
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002602 return ret;
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002603
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002604 return 0;
2605}
2606
2607/**
2608 * ti_sci_cmd_get_fwl_region() - Request for getting a firewall region
2609 * @handle: pointer to TI SCI handle
2610 * @region: region configuration parameters
2611 *
2612 * Return: 0 if all went well, else returns appropriate error value.
2613 */
2614static int ti_sci_cmd_get_fwl_region(const struct ti_sci_handle *handle,
2615 struct ti_sci_msg_fwl_region *region)
2616{
2617 struct ti_sci_msg_fwl_get_firewall_region_req req;
2618 struct ti_sci_msg_fwl_get_firewall_region_resp *resp;
2619 struct ti_sci_info *info;
2620 struct ti_sci_xfer *xfer;
2621 int ret = 0;
2622
2623 if (IS_ERR(handle))
2624 return PTR_ERR(handle);
2625 if (!handle)
2626 return -EINVAL;
2627
2628 info = handle_to_ti_sci_info(handle);
2629
2630 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_GET,
2631 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
2632 (u32 *)&req, sizeof(req), sizeof(*resp));
2633 if (IS_ERR(xfer)) {
2634 ret = PTR_ERR(xfer);
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002635 return ret;
2636 }
2637
2638 req.fwl_id = region->fwl_id;
2639 req.region = region->region;
2640 req.n_permission_regs = region->n_permission_regs;
2641
2642 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002643 if (ret)
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002644 return ret;
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002645
2646 resp = (struct ti_sci_msg_fwl_get_firewall_region_resp *)xfer->tx_message.buf;
2647
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002648 region->fwl_id = resp->fwl_id;
2649 region->region = resp->region;
2650 region->n_permission_regs = resp->n_permission_regs;
2651 region->control = resp->control;
2652 region->permissions[0] = resp->permissions[0];
2653 region->permissions[1] = resp->permissions[1];
2654 region->permissions[2] = resp->permissions[2];
2655 region->start_address = resp->start_address;
2656 region->end_address = resp->end_address;
2657
2658 return 0;
2659}
2660
2661/**
2662 * ti_sci_cmd_change_fwl_owner() - Request for changing a firewall owner
2663 * @handle: pointer to TI SCI handle
2664 * @region: region configuration parameters
2665 *
2666 * Return: 0 if all went well, else returns appropriate error value.
2667 */
2668static int ti_sci_cmd_change_fwl_owner(const struct ti_sci_handle *handle,
2669 struct ti_sci_msg_fwl_owner *owner)
2670{
2671 struct ti_sci_msg_fwl_change_owner_info_req req;
2672 struct ti_sci_msg_fwl_change_owner_info_resp *resp;
2673 struct ti_sci_info *info;
2674 struct ti_sci_xfer *xfer;
2675 int ret = 0;
2676
2677 if (IS_ERR(handle))
2678 return PTR_ERR(handle);
2679 if (!handle)
2680 return -EINVAL;
2681
2682 info = handle_to_ti_sci_info(handle);
2683
Andrew F. Davis8928fbd2019-04-29 09:04:11 -04002684 xfer = ti_sci_setup_one_xfer(info, TISCI_MSG_FWL_CHANGE_OWNER,
2685 TI_SCI_FLAG_REQ_ACK_ON_PROCESSED,
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002686 (u32 *)&req, sizeof(req), sizeof(*resp));
2687 if (IS_ERR(xfer)) {
2688 ret = PTR_ERR(xfer);
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002689 return ret;
2690 }
2691
2692 req.fwl_id = owner->fwl_id;
2693 req.region = owner->region;
2694 req.owner_index = owner->owner_index;
2695
2696 ret = ti_sci_do_xfer(info, xfer);
Andrew Davis771a16f2022-07-25 20:25:03 -05002697 if (ret)
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002698 return ret;
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002699
2700 resp = (struct ti_sci_msg_fwl_change_owner_info_resp *)xfer->tx_message.buf;
2701
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002702 owner->fwl_id = resp->fwl_id;
2703 owner->region = resp->region;
2704 owner->owner_index = resp->owner_index;
2705 owner->owner_privid = resp->owner_privid;
2706 owner->owner_permission_bits = resp->owner_permission_bits;
2707
2708 return ret;
2709}
2710
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +05302711/*
2712 * ti_sci_setup_ops() - Setup the operations structures
2713 * @info: pointer to TISCI pointer
2714 */
2715static void ti_sci_setup_ops(struct ti_sci_info *info)
2716{
2717 struct ti_sci_ops *ops = &info->handle.ops;
2718 struct ti_sci_board_ops *bops = &ops->board_ops;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +05302719 struct ti_sci_dev_ops *dops = &ops->dev_ops;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05302720 struct ti_sci_clk_ops *cops = &ops->clk_ops;
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05302721 struct ti_sci_core_ops *core_ops = &ops->core_ops;
Moteen Shah3a66db62025-06-09 13:44:31 +05302722 struct ti_sci_firmware_ops *fw_ops = &ops->fw_ops;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302723 struct ti_sci_rm_core_ops *rm_core_ops = &ops->rm_core_ops;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302724 struct ti_sci_proc_ops *pops = &ops->proc_ops;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302725 struct ti_sci_rm_ringacc_ops *rops = &ops->rm_ring_ops;
2726 struct ti_sci_rm_psil_ops *psilops = &ops->rm_psil_ops;
2727 struct ti_sci_rm_udmap_ops *udmap_ops = &ops->rm_udmap_ops;
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002728 struct ti_sci_fwl_ops *fwl_ops = &ops->fwl_ops;
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +05302729
2730 bops->board_config = ti_sci_cmd_set_board_config;
2731 bops->board_config_rm = ti_sci_cmd_set_board_config_rm;
2732 bops->board_config_security = ti_sci_cmd_set_board_config_security;
2733 bops->board_config_pm = ti_sci_cmd_set_board_config_pm;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +05302734
2735 dops->get_device = ti_sci_cmd_get_device;
Lokesh Vutlaf5613002019-06-07 19:24:39 +05302736 dops->get_device_exclusive = ti_sci_cmd_get_device_exclusive;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +05302737 dops->idle_device = ti_sci_cmd_idle_device;
Lokesh Vutlaf5613002019-06-07 19:24:39 +05302738 dops->idle_device_exclusive = ti_sci_cmd_idle_device_exclusive;
Andreas Dannenberg24a4d5e2018-08-27 15:57:34 +05302739 dops->put_device = ti_sci_cmd_put_device;
2740 dops->is_valid = ti_sci_cmd_dev_is_valid;
2741 dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt;
2742 dops->is_idle = ti_sci_cmd_dev_is_idle;
2743 dops->is_stop = ti_sci_cmd_dev_is_stop;
2744 dops->is_on = ti_sci_cmd_dev_is_on;
2745 dops->is_transitioning = ti_sci_cmd_dev_is_trans;
2746 dops->set_device_resets = ti_sci_cmd_set_device_resets;
2747 dops->get_device_resets = ti_sci_cmd_get_device_resets;
Lokesh Vutla0d0412a2019-06-07 19:24:41 +05302748 dops->release_exclusive_devices = ti_sci_cmd_release_exclusive_devices;
Lokesh Vutlad10c80c2018-08-27 15:57:35 +05302749
2750 cops->get_clock = ti_sci_cmd_get_clock;
2751 cops->idle_clock = ti_sci_cmd_idle_clock;
2752 cops->put_clock = ti_sci_cmd_put_clock;
2753 cops->is_auto = ti_sci_cmd_clk_is_auto;
2754 cops->is_on = ti_sci_cmd_clk_is_on;
2755 cops->is_off = ti_sci_cmd_clk_is_off;
2756
2757 cops->set_parent = ti_sci_cmd_clk_set_parent;
2758 cops->get_parent = ti_sci_cmd_clk_get_parent;
2759 cops->get_num_parents = ti_sci_cmd_clk_get_num_parents;
2760
2761 cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq;
2762 cops->set_freq = ti_sci_cmd_clk_set_freq;
2763 cops->get_freq = ti_sci_cmd_clk_get_freq;
Andreas Dannenberg5bd08372018-08-27 15:57:36 +05302764
2765 core_ops->reboot_device = ti_sci_cmd_core_reboot;
Lokesh Vutla032dce82019-03-08 11:47:32 +05302766 core_ops->query_msmc = ti_sci_cmd_query_msmc;
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302767
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302768 rm_core_ops->get_range = ti_sci_cmd_get_resource_range;
2769 rm_core_ops->get_range_from_shost =
2770 ti_sci_cmd_get_resource_range_from_shost;
2771
Lokesh Vutlab8856af2018-08-27 15:57:37 +05302772 pops->proc_request = ti_sci_cmd_proc_request;
2773 pops->proc_release = ti_sci_cmd_proc_release;
2774 pops->proc_handover = ti_sci_cmd_proc_handover;
2775 pops->set_proc_boot_cfg = ti_sci_cmd_set_proc_boot_cfg;
2776 pops->set_proc_boot_ctrl = ti_sci_cmd_set_proc_boot_ctrl;
2777 pops->proc_auth_boot_image = ti_sci_cmd_proc_auth_boot_image;
2778 pops->get_proc_boot_status = ti_sci_cmd_get_proc_boot_status;
Andreas Dannenbergca08cb32019-06-07 19:24:40 +05302779 pops->proc_shutdown_no_wait = ti_sci_cmd_proc_shutdown_no_wait;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302780
2781 rops->config = ti_sci_cmd_ring_config;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302782
2783 psilops->pair = ti_sci_cmd_rm_psil_pair;
2784 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
2785
2786 udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg;
2787 udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg;
2788 udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg;
Andrew F. Davis2aafc0c2019-04-12 12:54:43 -04002789
2790 fwl_ops->set_fwl_region = ti_sci_cmd_set_fwl_region;
2791 fwl_ops->get_fwl_region = ti_sci_cmd_get_fwl_region;
2792 fwl_ops->change_fwl_owner = ti_sci_cmd_change_fwl_owner;
Moteen Shah3a66db62025-06-09 13:44:31 +05302793
Moteen Shahab114e52025-06-09 13:44:32 +05302794 fw_ops->get_dm_version = ti_sci_cmd_get_dm_version;
Moteen Shah3a66db62025-06-09 13:44:31 +05302795 fw_ops->query_dm_cap = ti_sci_cmd_query_dm_cap;
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +05302796}
2797
2798/**
Lokesh Vutla5af02db2018-08-27 15:57:32 +05302799 * ti_sci_get_handle_from_sysfw() - Get the TI SCI handle of the SYSFW
2800 * @dev: Pointer to the SYSFW device
2801 *
2802 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2803 * are encountered.
2804 */
2805const
2806struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *sci_dev)
2807{
Neha Malcom Francisc7dedd02023-09-27 18:39:53 +05302808 int ret;
2809
Lokesh Vutla5af02db2018-08-27 15:57:32 +05302810 if (!sci_dev)
2811 return ERR_PTR(-EINVAL);
2812
2813 struct ti_sci_info *info = dev_get_priv(sci_dev);
2814
2815 if (!info)
2816 return ERR_PTR(-EINVAL);
2817
2818 struct ti_sci_handle *handle = &info->handle;
2819
2820 if (!handle)
2821 return ERR_PTR(-EINVAL);
2822
Neha Malcom Francisc7dedd02023-09-27 18:39:53 +05302823 ret = ti_sci_cmd_get_revision(handle);
2824
2825 if (ret)
2826 return ERR_PTR(-EINVAL);
2827
Lokesh Vutla5af02db2018-08-27 15:57:32 +05302828 return handle;
2829}
2830
2831/**
2832 * ti_sci_get_handle() - Get the TI SCI handle for a device
2833 * @dev: Pointer to device for which we want SCI handle
2834 *
2835 * Return: pointer to handle if successful, else EINVAL if invalid conditions
2836 * are encountered.
2837 */
2838const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
2839{
2840 if (!dev)
2841 return ERR_PTR(-EINVAL);
2842
2843 struct udevice *sci_dev = dev_get_parent(dev);
2844
2845 return ti_sci_get_handle_from_sysfw(sci_dev);
2846}
2847
2848/**
2849 * ti_sci_get_by_phandle() - Get the TI SCI handle using DT phandle
2850 * @dev: device node
2851 * @propname: property name containing phandle on TISCI node
2852 *
2853 * Return: pointer to handle if successful, else appropriate error value.
2854 */
2855const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
2856 const char *property)
2857{
2858 struct ti_sci_info *entry, *info = NULL;
2859 u32 phandle, err;
2860 ofnode node;
2861
2862 err = ofnode_read_u32(dev_ofnode(dev), property, &phandle);
2863 if (err)
2864 return ERR_PTR(err);
2865
2866 node = ofnode_get_by_phandle(phandle);
2867 if (!ofnode_valid(node))
2868 return ERR_PTR(-EINVAL);
2869
2870 list_for_each_entry(entry, &ti_sci_list, list)
2871 if (ofnode_equal(dev_ofnode(entry->dev), node)) {
2872 info = entry;
2873 break;
2874 }
2875
2876 if (!info)
2877 return ERR_PTR(-ENODEV);
2878
2879 return &info->handle;
2880}
2881
2882/**
2883 * ti_sci_of_to_info() - generate private data from device tree
2884 * @dev: corresponding system controller interface device
2885 * @info: pointer to driver specific private data
2886 *
2887 * Return: 0 if all goes good, else appropriate error message.
2888 */
2889static int ti_sci_of_to_info(struct udevice *dev, struct ti_sci_info *info)
2890{
2891 int ret;
2892
2893 ret = mbox_get_by_name(dev, "tx", &info->chan_tx);
2894 if (ret) {
2895 dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n",
2896 __func__, ret);
2897 return ret;
2898 }
2899
2900 ret = mbox_get_by_name(dev, "rx", &info->chan_rx);
2901 if (ret) {
2902 dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n",
2903 __func__, ret);
2904 return ret;
2905 }
2906
2907 /* Notify channel is optional. Enable only if populated */
2908 ret = mbox_get_by_name(dev, "notify", &info->chan_notify);
2909 if (ret) {
2910 dev_dbg(dev, "%s: Acquiring notify channel failed. ret = %d\n",
2911 __func__, ret);
2912 }
2913
2914 info->host_id = dev_read_u32_default(dev, "ti,host-id",
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05302915 info->desc->default_host_id);
Lokesh Vutla5af02db2018-08-27 15:57:32 +05302916
2917 info->is_secure = dev_read_bool(dev, "ti,secure-host");
2918
2919 return 0;
2920}
2921
2922/**
2923 * ti_sci_probe() - Basic probe
2924 * @dev: corresponding system controller interface device
2925 *
2926 * Return: 0 if all goes good, else appropriate error message.
2927 */
2928static int ti_sci_probe(struct udevice *dev)
2929{
2930 struct ti_sci_info *info;
2931 int ret;
2932
2933 debug("%s(dev=%p)\n", __func__, dev);
2934
2935 info = dev_get_priv(dev);
2936 info->desc = (void *)dev_get_driver_data(dev);
2937
2938 ret = ti_sci_of_to_info(dev, info);
2939 if (ret) {
2940 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
2941 return ret;
2942 }
2943
2944 info->dev = dev;
2945 info->seq = 0xA;
2946
Udit Kumar24b11a42025-04-29 22:44:40 +05302947 INIT_LIST_HEAD(&info->dev_list);
2948
Lokesh Vutla5af02db2018-08-27 15:57:32 +05302949 list_add_tail(&info->list, &ti_sci_list);
Andreas Dannenberg5299c4c2018-08-27 15:57:33 +05302950 ti_sci_setup_ops(info);
Lokesh Vutla5af02db2018-08-27 15:57:32 +05302951
Andrew Davis1ed20d62024-04-02 11:09:07 -05002952 if (IS_ENABLED(CONFIG_SYSRESET_TI_SCI)) {
2953 ret = device_bind_driver(dev, "ti-sci-sysreset", "sysreset", NULL);
2954 if (ret)
2955 dev_warn(dev, "cannot bind SYSRESET (ret = %d)\n", ret);
2956 }
2957
Neha Malcom Francisc7dedd02023-09-27 18:39:53 +05302958 return 0;
Lokesh Vutla5af02db2018-08-27 15:57:32 +05302959}
2960
Vignesh Raghavendraaa0e3fc2021-06-07 19:47:49 +05302961/**
2962 * ti_sci_dm_probe() - Basic probe for DM to TIFS SCI
2963 * @dev: corresponding system controller interface device
2964 *
2965 * Return: 0 if all goes good, else appropriate error message.
2966 */
2967static __maybe_unused int ti_sci_dm_probe(struct udevice *dev)
2968{
2969 struct ti_sci_rm_core_ops *rm_core_ops;
2970 struct ti_sci_rm_udmap_ops *udmap_ops;
2971 struct ti_sci_rm_ringacc_ops *rops;
2972 struct ti_sci_rm_psil_ops *psilops;
2973 struct ti_sci_ops *ops;
2974 struct ti_sci_info *info;
2975 int ret;
2976
2977 debug("%s(dev=%p)\n", __func__, dev);
2978
2979 info = dev_get_priv(dev);
2980 info->desc = (void *)dev_get_driver_data(dev);
2981
2982 ret = ti_sci_of_to_info(dev, info);
2983 if (ret) {
2984 dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
2985 return ret;
2986 }
2987
2988 info->dev = dev;
2989 info->seq = 0xA;
2990
Udit Kumar24b11a42025-04-29 22:44:40 +05302991 INIT_LIST_HEAD(&info->dev_list);
2992
Vignesh Raghavendraaa0e3fc2021-06-07 19:47:49 +05302993 list_add_tail(&info->list, &ti_sci_list);
2994
2995 ops = &info->handle.ops;
2996
2997 rm_core_ops = &ops->rm_core_ops;
2998 rm_core_ops->get_range = ti_sci_cmd_get_resource_range_static;
2999
3000 rops = &ops->rm_ring_ops;
3001 rops->config = ti_sci_cmd_ring_config;
3002
3003 psilops = &ops->rm_psil_ops;
3004 psilops->pair = ti_sci_cmd_rm_psil_pair;
3005 psilops->unpair = ti_sci_cmd_rm_psil_unpair;
3006
3007 udmap_ops = &ops->rm_udmap_ops;
3008 udmap_ops->tx_ch_cfg = ti_sci_cmd_rm_udmap_tx_ch_cfg;
3009 udmap_ops->rx_ch_cfg = ti_sci_cmd_rm_udmap_rx_ch_cfg;
Kishon Vijay Abraham Ie9876c82024-08-26 15:55:06 +05303010 udmap_ops->rx_flow_cfg = ti_sci_cmd_rm_udmap_rx_flow_cfg_noop;
Vignesh Raghavendraaa0e3fc2021-06-07 19:47:49 +05303011
3012 return ret;
3013}
3014
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303015/*
3016 * ti_sci_get_free_resource() - Get a free resource from TISCI resource.
3017 * @res: Pointer to the TISCI resource
3018 *
3019 * Return: resource num if all went ok else TI_SCI_RESOURCE_NULL.
3020 */
3021u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
3022{
3023 u16 set, free_bit;
3024
3025 for (set = 0; set < res->sets; set++) {
3026 free_bit = find_first_zero_bit(res->desc[set].res_map,
3027 res->desc[set].num);
3028 if (free_bit != res->desc[set].num) {
3029 set_bit(free_bit, res->desc[set].res_map);
3030 return res->desc[set].start + free_bit;
3031 }
3032 }
3033
3034 return TI_SCI_RESOURCE_NULL;
3035}
3036
3037/**
3038 * ti_sci_release_resource() - Release a resource from TISCI resource.
3039 * @res: Pointer to the TISCI resource
3040 */
3041void ti_sci_release_resource(struct ti_sci_resource *res, u16 id)
3042{
3043 u16 set;
3044
3045 for (set = 0; set < res->sets; set++) {
3046 if (res->desc[set].start <= id &&
3047 (res->desc[set].num + res->desc[set].start) > id)
3048 clear_bit(id - res->desc[set].start,
3049 res->desc[set].res_map);
3050 }
3051}
3052
3053/**
3054 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
3055 * @handle: TISCI handle
3056 * @dev: Device pointer to which the resource is assigned
3057 * @of_prop: property name by which the resource are represented
3058 *
3059 * Note: This function expects of_prop to be in the form of tuples
3060 * <type, subtype>. Allocates and initializes ti_sci_resource structure
3061 * for each of_prop. Client driver can directly call
3062 * ti_sci_(get_free, release)_resource apis for handling the resource.
3063 *
3064 * Return: Pointer to ti_sci_resource if all went well else appropriate
3065 * error pointer.
3066 */
3067struct ti_sci_resource *
3068devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
3069 struct udevice *dev, u32 dev_id, char *of_prop)
3070{
3071 u32 resource_subtype;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303072 struct ti_sci_resource *res;
Vignesh Raghavendrae1164dd2019-08-05 12:26:44 -05003073 bool valid_set = false;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303074 int sets, i, ret;
3075 u32 *temp;
3076
3077 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
3078 if (!res)
3079 return ERR_PTR(-ENOMEM);
3080
3081 sets = dev_read_size(dev, of_prop);
3082 if (sets < 0) {
3083 dev_err(dev, "%s resource type ids not available\n", of_prop);
3084 return ERR_PTR(sets);
3085 }
3086 temp = malloc(sets);
3087 sets /= sizeof(u32);
3088 res->sets = sets;
3089
3090 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
3091 GFP_KERNEL);
3092 if (!res->desc)
3093 return ERR_PTR(-ENOMEM);
3094
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303095 ret = dev_read_u32_array(dev, of_prop, temp, res->sets);
3096 if (ret)
3097 return ERR_PTR(-EINVAL);
3098
3099 for (i = 0; i < res->sets; i++) {
3100 resource_subtype = temp[i];
3101 ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
3102 resource_subtype,
3103 &res->desc[i].start,
3104 &res->desc[i].num);
3105 if (ret) {
Vignesh Raghavendrae1164dd2019-08-05 12:26:44 -05003106 dev_dbg(dev, "type %d subtype %d not allocated for host %d\n",
Lokesh Vutla0acf1dc2020-08-17 11:00:48 +05303107 dev_id, resource_subtype,
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303108 handle_to_ti_sci_info(handle)->host_id);
Vignesh Raghavendrae1164dd2019-08-05 12:26:44 -05003109 res->desc[i].start = 0;
3110 res->desc[i].num = 0;
3111 continue;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303112 }
3113
Vignesh Raghavendrae1164dd2019-08-05 12:26:44 -05003114 valid_set = true;
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303115 dev_dbg(dev, "res type = %d, subtype = %d, start = %d, num = %d\n",
Lokesh Vutla0acf1dc2020-08-17 11:00:48 +05303116 dev_id, resource_subtype, res->desc[i].start,
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303117 res->desc[i].num);
3118
3119 res->desc[i].res_map =
3120 devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) *
3121 sizeof(*res->desc[i].res_map), GFP_KERNEL);
3122 if (!res->desc[i].res_map)
3123 return ERR_PTR(-ENOMEM);
3124 }
3125
Vignesh Raghavendrae1164dd2019-08-05 12:26:44 -05003126 if (valid_set)
3127 return res;
3128
3129 return ERR_PTR(-EINVAL);
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303130}
3131
3132/* Description for K2G */
3133static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = {
3134 .default_host_id = 2,
3135 /* Conservative duration */
3136 .max_rx_timeout_ms = 10000,
3137 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3138 .max_msgs = 20,
3139 .max_msg_size = 64,
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303140};
3141
Lokesh Vutla5af02db2018-08-27 15:57:32 +05303142/* Description for AM654 */
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303143static const struct ti_sci_desc ti_sci_pmmc_am654_desc = {
3144 .default_host_id = 12,
3145 /* Conservative duration */
3146 .max_rx_timeout_ms = 10000,
3147 /* Limited by MBOX_TX_QUEUE_LEN. K2G can handle upto 128 messages! */
3148 .max_msgs = 20,
Lokesh Vutla5af02db2018-08-27 15:57:32 +05303149 .max_msg_size = 60,
3150};
3151
Vignesh Raghavendraaa0e3fc2021-06-07 19:47:49 +05303152/* Description for J721e DM to DMSC communication */
3153static const struct ti_sci_desc ti_sci_dm_j721e_desc = {
3154 .default_host_id = 3,
3155 .max_rx_timeout_ms = 10000,
3156 .max_msgs = 20,
3157 .max_msg_size = 60,
3158};
3159
Lokesh Vutla5af02db2018-08-27 15:57:32 +05303160static const struct udevice_id ti_sci_ids[] = {
3161 {
3162 .compatible = "ti,k2g-sci",
Grygorii Strashkod64c5b22019-02-05 17:31:21 +05303163 .data = (ulong)&ti_sci_pmmc_k2g_desc
3164 },
3165 {
3166 .compatible = "ti,am654-sci",
3167 .data = (ulong)&ti_sci_pmmc_am654_desc
Lokesh Vutla5af02db2018-08-27 15:57:32 +05303168 },
3169 { /* Sentinel */ },
3170};
3171
Vignesh Raghavendraaa0e3fc2021-06-07 19:47:49 +05303172static __maybe_unused const struct udevice_id ti_sci_dm_ids[] = {
3173 {
3174 .compatible = "ti,j721e-dm-sci",
3175 .data = (ulong)&ti_sci_dm_j721e_desc
3176 },
3177 { /* Sentinel */ },
3178};
3179
Lokesh Vutla5af02db2018-08-27 15:57:32 +05303180U_BOOT_DRIVER(ti_sci) = {
3181 .name = "ti_sci",
3182 .id = UCLASS_FIRMWARE,
3183 .of_match = ti_sci_ids,
3184 .probe = ti_sci_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -07003185 .priv_auto = sizeof(struct ti_sci_info),
Manorit Chawdhry27f161c2024-12-17 14:24:37 +05303186 .flags = DM_FLAG_PRE_RELOC,
Lokesh Vutla5af02db2018-08-27 15:57:32 +05303187};
Vignesh Raghavendraaa0e3fc2021-06-07 19:47:49 +05303188
3189#if IS_ENABLED(CONFIG_K3_DM_FW)
3190U_BOOT_DRIVER(ti_sci_dm) = {
3191 .name = "ti_sci_dm",
3192 .id = UCLASS_FIRMWARE,
3193 .of_match = ti_sci_dm_ids,
3194 .probe = ti_sci_dm_probe,
3195 .priv_auto = sizeof(struct ti_sci_info),
3196};
3197#endif