Skip to content

Commit

Permalink
plat-k3: drivers: Remove ti_sci_get_response function
Browse files Browse the repository at this point in the history
Currently since all the code is under mutex, it makes sense to remove
this function and keep it all under ti_sci_do_xfer for easier
readability.

Acked-by: Etienne Carriere <[email protected]>
Signed-off-by: Manorit Chawdhry <[email protected]>
  • Loading branch information
manorit2001 authored and Runyang Chen committed Dec 12, 2024
1 parent f877e41 commit 9041267
Showing 1 changed file with 31 additions and 53 deletions.
84 changes: 31 additions & 53 deletions core/arch/arm/plat-k3/drivers/ti_sci.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "ti_sci.h"
#include "ti_sci_protocol.h"

static uint8_t message_sequence;
static struct mutex ti_sci_mutex_lock = MUTEX_INITIALIZER;

/**
* struct ti_sci_xfer - Structure representing a message flow
Expand Down Expand Up @@ -82,80 +80,60 @@ static int ti_sci_setup_xfer(uint16_t msg_type, uint32_t msg_flags,
}

/**
* ti_sci_get_response() - Receive response from mailbox channel
* ti_sci_do_xfer() - Do one transfer
*
* @xfer: Transfer to initiate and wait for response
* @xfer: Transfer to initiate and wait for response
*
* Return: 0 if all goes well, else appropriate error message
*/
static inline int ti_sci_get_response(struct ti_sci_xfer *xfer)
static int ti_sci_do_xfer(struct ti_sci_xfer *xfer)
{
struct k3_sec_proxy_msg *msg = &xfer->rx_message;
struct ti_sci_msg_hdr *hdr = NULL;
struct k3_sec_proxy_msg *txmsg = &xfer->tx_message;
struct k3_sec_proxy_msg *rxmsg = &xfer->rx_message;
struct ti_sci_msg_hdr *txhdr = (struct ti_sci_msg_hdr *)txmsg->buf;
struct ti_sci_msg_hdr *rxhdr = (struct ti_sci_msg_hdr *)rxmsg->buf;
static uint8_t message_sequence;
static struct mutex ti_sci_mutex_lock = MUTEX_INITIALIZER;
unsigned int retry = 5;
int ret = 0;

mutex_lock(&ti_sci_mutex_lock);

message_sequence++;
txhdr->seq = message_sequence;

/* Send the message */
ret = k3_sec_proxy_send(txmsg);
if (ret) {
EMSG("Message sending failed (%d)", ret);
goto unlock;
}

/* Get the response */
for (; retry > 0; retry--) {
/* Receive the response */
ret = k3_sec_proxy_recv(msg);
ret = k3_sec_proxy_recv(rxmsg);
if (ret) {
EMSG("Message receive failed (%d)", ret);
return ret;
goto unlock;
}

/* msg is updated by Secure Proxy driver */
hdr = (struct ti_sci_msg_hdr *)msg->buf;

/* Sanity check for message response */
if (hdr->seq == message_sequence)
if (rxhdr->seq == message_sequence)
break;

IMSG("Message with sequence ID %u is not expected", hdr->seq);
IMSG("Message with sequence ID %"PRIu8" is not expected",
rxhdr->seq);
}
if (!retry) {
EMSG("Timed out waiting for message");
return TEE_ERROR_BUSY;
}

if (!(hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK)) {
DMSG("Message not acknowledged");
return TEE_ERROR_ACCESS_DENIED;
}

return 0;
}

/**
* ti_sci_do_xfer() - Do one transfer
*
* @xfer: Transfer to initiate and wait for response
*
* Return: 0 if all goes well, else appropriate error message
*/
static inline int ti_sci_do_xfer(struct ti_sci_xfer *xfer)
{
struct k3_sec_proxy_msg *msg = &xfer->tx_message;
struct ti_sci_msg_hdr *hdr = NULL;
int ret = 0;

mutex_lock(&ti_sci_mutex_lock);

hdr = (struct ti_sci_msg_hdr *)msg->buf;
hdr->seq = ++message_sequence;

/* Send the message */
ret = k3_sec_proxy_send(msg);
if (ret) {
EMSG("Message sending failed (%d)", ret);
ret = TEE_ERROR_BUSY;
goto unlock;
}

/* Get the response */
ret = ti_sci_get_response(xfer);
if (ret) {
if ((TEE_Result)ret != TEE_ERROR_ACCESS_DENIED)
EMSG("Failed to get response (%d)", ret);
goto unlock;
if (!(rxhdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK)) {
DMSG("Message not acknowledged");
ret = TEE_ERROR_ACCESS_DENIED;
}

unlock:
Expand Down

0 comments on commit 9041267

Please sign in to comment.