Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plat-k3: Add locks for TI-SCI protocol #7089

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions core/arch/arm/plat-k3/drivers/ti_sci.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include <assert.h>
#include <kernel/thread.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer kernel/mutex.h for mutex support.

#include <malloc.h>
#include <platform_config.h>
#include <string.h>
Expand All @@ -20,6 +21,7 @@
#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 @@ -66,7 +68,6 @@ static int ti_sci_setup_xfer(uint16_t msg_type, uint32_t msg_flags,
}

hdr = (struct ti_sci_msg_hdr *)tx_buf;
hdr->seq = ++message_sequence;
hdr->type = msg_type;
hdr->host = OPTEE_HOST_ID;
hdr->flags = msg_flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED;
Expand All @@ -80,6 +81,27 @@ static int ti_sci_setup_xfer(uint16_t msg_type, uint32_t msg_flags,
return 0;
}

/**
* ti_sci_send_request() - Send request to mailbox channel
*
* @xfer: Transfer to initiate and wait for response
*
* Return: 0 if all goes well, else appropriate error message
*/
static inline int ti_sci_send_request(struct ti_sci_xfer *xfer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could drop the inline attribute. Not strictly needed. But since there are such inline directive for many of the functions in this source file, maybe my comment is out of the scope of this P-R.

{
struct k3_sec_proxy_msg *msg = &xfer->tx_message;
struct ti_sci_msg_hdr *hdr = NULL;

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

FMSG("Sending %x with seq %u host %u", msg->type, msg->seq, msg->host);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type is uint16_t, seq and host are uint8_t, hence use PRIu16 and PRIu8. Ditto at line 146.

	FMSG("Sending %#"PRIx16" with seq %"PRIu8" host %"PRIu8,
	     msg->type, msg->seq, msg->host);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original line doesn't even compile.. Building with CFG_TEE_CORE_LOG_LEVEL=4 shows that. type, seq, and host are members of hdr, not msg.


/* Send the message */
return k3_sec_proxy_send(msg);
}

/**
* ti_sci_get_response() - Receive response from mailbox channel
*
Expand Down Expand Up @@ -121,6 +143,8 @@ static inline int ti_sci_get_response(struct ti_sci_xfer *xfer)
return TEE_ERROR_ACCESS_DENIED;
}

FMSG("Receive %x with seq %u host %u", msg->type, msg->seq, msg->host);

return 0;
}

Expand All @@ -133,25 +157,27 @@ static inline int ti_sci_get_response(struct ti_sci_xfer *xfer)
*/
static inline int ti_sci_do_xfer(struct ti_sci_xfer *xfer)
{
struct k3_sec_proxy_msg *msg = &xfer->tx_message;
int ret = 0;

/* Send the message */
ret = k3_sec_proxy_send(msg);
mutex_lock(&ti_sci_mutex_lock);

ret = ti_sci_send_request(xfer);
if (ret) {
EMSG("Message sending failed (%d)", ret);
return ret;
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);
return ret;
goto unlock;
}

return 0;
unlock:
mutex_unlock(&ti_sci_mutex_lock);
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way and out of the scope of this change: I see k3_sec_proxy_xxx() return TEE_Result values while caller use int. Likely something to be fixed at some point of time.

}

int ti_sci_get_revision(struct ti_sci_msg_resp_version *rev_info)
Expand Down
Loading