-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: master
Are you sure you want to change the base?
Changes from all commits
6b7f2b2
5336f69
2886a65
58cf0c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
*/ | ||
|
||
#include <assert.h> | ||
#include <kernel/thread.h> | ||
#include <malloc.h> | ||
#include <platform_config.h> | ||
#include <string.h> | ||
|
@@ -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 | ||
|
@@ -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; | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could drop the |
||
{ | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FMSG("Sending %#"PRIx16" with seq %"PRIu8" host %"PRIu8,
msg->type, msg->seq, msg->host); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original line doesn't even compile.. Building with |
||
|
||
/* Send the message */ | ||
return k3_sec_proxy_send(msg); | ||
} | ||
|
||
/** | ||
* ti_sci_get_response() - Receive response from mailbox channel | ||
* | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
int ti_sci_get_revision(struct ti_sci_msg_resp_version *rev_info) | ||
|
There was a problem hiding this comment.
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.