Merge changes from topic "ti-sci-cleanup" into integration
* changes:
feat(ti): synchronize access to secure proxy threads
refactor(ti): remove inline directive from ti_sci and sec_proxy drivers
refactor(ti): refactor ti_sci_{setup,do}_xfer to allow zero size response
feat(ti): add sub and patch version number support
diff --git a/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c b/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c
index a0bfdee..1bed229 100644
--- a/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c
+++ b/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c
@@ -130,7 +130,7 @@
*
* Return: 0 if all goes well, else appropriate error message
*/
-static inline int k3_sec_proxy_verify_thread(struct k3_sec_proxy_thread *spt,
+static int k3_sec_proxy_verify_thread(struct k3_sec_proxy_thread *spt,
uint32_t dir)
{
/* Check for any errors already available */
diff --git a/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.h b/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.h
index f4b0b4b..4005102 100644
--- a/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.h
+++ b/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.h
@@ -53,7 +53,7 @@
};
/**
- * k3_sec_proxy_send() - Send data over a Secure Proxy thread
+ * k3_sec_proxy_clear_rx_thread() - Clear a receive Secure Proxy thread
* @id: Channel Identifier
* @msg: Pointer to k3_sec_proxy_msg
*
diff --git a/plat/ti/k3/common/drivers/ti_sci/ti_sci.c b/plat/ti/k3/common/drivers/ti_sci/ti_sci.c
index ade10a6..dacef74 100644
--- a/plat/ti/k3/common/drivers/ti_sci/ti_sci.c
+++ b/plat/ti/k3/common/drivers/ti_sci/ti_sci.c
@@ -13,6 +13,7 @@
#include <string.h>
#include <platform_def.h>
+#include <lib/bakery_lock.h>
#include <common/debug.h>
#include <sec_proxy.h>
@@ -25,6 +26,8 @@
#endif
static uint8_t message_sequence;
+DEFINE_BAKERY_LOCK(ti_sci_xfer_lock);
+
/**
* struct ti_sci_xfer - Structure representing a message flow
* @tx_message: Transmit message
@@ -62,7 +65,6 @@
/* Ensure we have sane transfer sizes */
if (rx_message_size > TI_SCI_MAX_MESSAGE_SIZE ||
tx_message_size > TI_SCI_MAX_MESSAGE_SIZE ||
- rx_message_size < sizeof(*hdr) ||
tx_message_size < sizeof(*hdr))
return -ERANGE;
@@ -70,7 +72,11 @@
hdr->seq = ++message_sequence;
hdr->type = msg_type;
hdr->host = TI_SCI_HOST_ID;
- hdr->flags = msg_flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED;
+ hdr->flags = msg_flags;
+ /* Request a response if rx_message_size is non-zero */
+ if (rx_message_size != 0U) {
+ hdr->flags |= TI_SCI_FLAG_REQ_ACK_ON_PROCESSED;
+ }
xfer->tx_message.buf = tx_buf;
xfer->tx_message.len = tx_message_size;
@@ -89,10 +95,9 @@
*
* Return: 0 if all goes well, else appropriate error message
*/
-static inline int ti_sci_get_response(struct ti_sci_xfer *xfer,
- enum k3_sec_proxy_chan_id chan)
+static int ti_sci_get_response(struct k3_sec_proxy_msg *msg,
+ enum k3_sec_proxy_chan_id chan)
{
- struct k3_sec_proxy_msg *msg = &xfer->rx_message;
struct ti_sci_msg_hdr *hdr;
unsigned int retry = 5;
int ret;
@@ -138,11 +143,14 @@
*
* Return: 0 if all goes well, else appropriate error message
*/
-static inline int ti_sci_do_xfer(struct ti_sci_xfer *xfer)
+static int ti_sci_do_xfer(struct ti_sci_xfer *xfer)
{
- struct k3_sec_proxy_msg *msg = &xfer->tx_message;
+ struct k3_sec_proxy_msg *tx_msg = &xfer->tx_message;
+ struct k3_sec_proxy_msg *rx_msg = &xfer->rx_message;
int ret;
+ bakery_lock_get(&ti_sci_xfer_lock);
+
/* Clear any spurious messages in receive queue */
ret = k3_sec_proxy_clear_rx_thread(SP_RESPONSE);
if (ret) {
@@ -151,19 +159,23 @@
}
/* Send the message */
- ret = k3_sec_proxy_send(SP_HIGH_PRIORITY, msg);
+ ret = k3_sec_proxy_send(SP_HIGH_PRIORITY, tx_msg);
if (ret) {
ERROR("Message sending failed (%d)\n", ret);
return ret;
}
- /* Get the response */
- ret = ti_sci_get_response(xfer, SP_RESPONSE);
- if (ret) {
- ERROR("Failed to get response (%d)\n", ret);
- return ret;
+ /* Get the response if requested */
+ if (rx_msg->len != 0U) {
+ ret = ti_sci_get_response(rx_msg, SP_RESPONSE);
+ if (ret != 0U) {
+ ERROR("Failed to get response (%d)\n", ret);
+ return ret;
+ }
}
+ bakery_lock_release(&ti_sci_xfer_lock);
+
return 0;
}
@@ -398,35 +410,27 @@
int ti_sci_device_put_no_wait(uint32_t id)
{
struct ti_sci_msg_req_set_device_state req;
- struct ti_sci_msg_hdr *hdr;
- struct k3_sec_proxy_msg tx_message;
+ struct ti_sci_xfer xfer;
int ret;
- /* Ensure we have sane transfer size */
- if (sizeof(req) > TI_SCI_MAX_MESSAGE_SIZE)
- return -ERANGE;
-
- hdr = (struct ti_sci_msg_hdr *)&req;
- hdr->seq = ++message_sequence;
- hdr->type = TI_SCI_MSG_SET_DEVICE_STATE;
- hdr->host = TI_SCI_HOST_ID;
- /* Setup with NORESPONSE flag to keep response queue clean */
- hdr->flags = TI_SCI_FLAG_REQ_GENERIC_NORESPONSE;
+ ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_DEVICE_STATE, 0,
+ &req, sizeof(req),
+ NULL, 0,
+ &xfer);
+ if (ret != 0U) {
+ ERROR("Message alloc failed (%d)\n", ret);
+ return ret;
+ }
req.id = id;
req.state = MSG_DEVICE_SW_STATE_AUTO_OFF;
- tx_message.buf = (uint8_t *)&req;
- tx_message.len = sizeof(req);
-
- /* Send message */
- ret = k3_sec_proxy_send(SP_HIGH_PRIORITY, &tx_message);
- if (ret) {
- ERROR("Message sending failed (%d)\n", ret);
+ ret = ti_sci_do_xfer(&xfer);
+ if (ret != 0U) {
+ ERROR("Transfer send failed (%d)\n", ret);
return ret;
}
- /* Return without waiting for response */
return 0;
}
@@ -1382,36 +1386,28 @@
uint32_t control_flags_clear)
{
struct ti_sci_msg_req_set_proc_boot_ctrl req;
- struct ti_sci_msg_hdr *hdr;
- struct k3_sec_proxy_msg tx_message;
+ struct ti_sci_xfer xfer;
int ret;
- /* Ensure we have sane transfer size */
- if (sizeof(req) > TI_SCI_MAX_MESSAGE_SIZE)
- return -ERANGE;
-
- hdr = (struct ti_sci_msg_hdr *)&req;
- hdr->seq = ++message_sequence;
- hdr->type = TISCI_MSG_SET_PROC_BOOT_CTRL;
- hdr->host = TI_SCI_HOST_ID;
- /* Setup with NORESPONSE flag to keep response queue clean */
- hdr->flags = TI_SCI_FLAG_REQ_GENERIC_NORESPONSE;
+ ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_DEVICE_STATE, 0,
+ &req, sizeof(req),
+ NULL, 0,
+ &xfer);
+ if (ret != 0U) {
+ ERROR("Message alloc failed (%d)\n", ret);
+ return ret;
+ }
req.processor_id = proc_id;
req.control_flags_set = control_flags_set;
req.control_flags_clear = control_flags_clear;
- tx_message.buf = (uint8_t *)&req;
- tx_message.len = sizeof(req);
-
- /* Send message */
- ret = k3_sec_proxy_send(SP_HIGH_PRIORITY, &tx_message);
- if (ret) {
- ERROR("Message sending failed (%d)\n", ret);
+ ret = ti_sci_do_xfer(&xfer);
+ if (ret != 0U) {
+ ERROR("Transfer send failed (%d)\n", ret);
return ret;
}
- /* Return without waiting for response */
return 0;
}
@@ -1624,20 +1620,17 @@
uint32_t status_flags_1_clr_any_wait)
{
struct ti_sci_msg_req_wait_proc_boot_status req;
- struct ti_sci_msg_hdr *hdr;
- struct k3_sec_proxy_msg tx_message;
+ struct ti_sci_xfer xfer;
int ret;
- /* Ensure we have sane transfer size */
- if (sizeof(req) > TI_SCI_MAX_MESSAGE_SIZE)
- return -ERANGE;
-
- hdr = (struct ti_sci_msg_hdr *)&req;
- hdr->seq = ++message_sequence;
- hdr->type = TISCI_MSG_WAIT_PROC_BOOT_STATUS;
- hdr->host = TI_SCI_HOST_ID;
- /* Setup with NORESPONSE flag to keep response queue clean */
- hdr->flags = TI_SCI_FLAG_REQ_GENERIC_NORESPONSE;
+ ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_DEVICE_STATE, 0,
+ &req, sizeof(req),
+ NULL, 0,
+ &xfer);
+ if (ret != 0U) {
+ ERROR("Message alloc failed (%d)\n", ret);
+ return ret;
+ }
req.processor_id = proc_id;
req.num_wait_iterations = num_wait_iterations;
@@ -1649,17 +1642,12 @@
req.status_flags_1_clr_all_wait = status_flags_1_clr_all_wait;
req.status_flags_1_clr_any_wait = status_flags_1_clr_any_wait;
- tx_message.buf = (uint8_t *)&req;
- tx_message.len = sizeof(req);
-
- /* Send message */
- ret = k3_sec_proxy_send(SP_HIGH_PRIORITY, &tx_message);
- if (ret) {
- ERROR("Message sending failed (%d)\n", ret);
+ ret = ti_sci_do_xfer(&xfer);
+ if (ret != 0U) {
+ ERROR("Transfer send failed (%d)\n", ret);
return ret;
}
- /* Return without waiting for response */
return 0;
}
@@ -1678,39 +1666,30 @@
uint64_t core_resume_addr)
{
struct ti_sci_msg_req_enter_sleep req;
- struct ti_sci_msg_hdr *hdr;
- struct k3_sec_proxy_msg tx_message;
+ struct ti_sci_xfer xfer;
int ret;
- /* Ensure we have sane transfer size */
- if (sizeof(req) > TI_SCI_MAX_MESSAGE_SIZE) {
- return -ERANGE;
+ ret = ti_sci_setup_one_xfer(TI_SCI_MSG_GET_DEVICE_STATE, 0,
+ &req, sizeof(req),
+ NULL, 0,
+ &xfer);
+ if (ret != 0U) {
+ ERROR("Message alloc failed (%d)\n", ret);
+ return ret;
}
- hdr = (struct ti_sci_msg_hdr *)&req;
- hdr->seq = ++message_sequence;
- hdr->type = TI_SCI_MSG_ENTER_SLEEP;
- hdr->host = TI_SCI_HOST_ID;
- /* Setup with NORESPONSE flag to keep response queue clean */
- hdr->flags = TI_SCI_FLAG_REQ_GENERIC_NORESPONSE;
-
req.processor_id = proc_id;
req.mode = mode;
req.core_resume_lo = core_resume_addr & TISCI_ADDR_LOW_MASK;
req.core_resume_hi = (core_resume_addr & TISCI_ADDR_HIGH_MASK) >>
TISCI_ADDR_HIGH_SHIFT;
- tx_message.buf = (uint8_t *)&req;
- tx_message.len = sizeof(req);
-
- /* Send message */
- ret = k3_sec_proxy_send(SP_HIGH_PRIORITY, &tx_message);
- if (ret != 0) {
- ERROR("Message sending failed (%d)\n", ret);
+ ret = ti_sci_do_xfer(&xfer);
+ if (ret != 0U) {
+ ERROR("Transfer send failed (%d)\n", ret);
return ret;
}
- /* Return without waiting for response */
return 0;
}
diff --git a/plat/ti/k3/common/drivers/ti_sci/ti_sci_protocol.h b/plat/ti/k3/common/drivers/ti_sci/ti_sci_protocol.h
index 1b1a910..36909f5 100644
--- a/plat/ti/k3/common/drivers/ti_sci/ti_sci_protocol.h
+++ b/plat/ti/k3/common/drivers/ti_sci/ti_sci_protocol.h
@@ -73,18 +73,30 @@
} __packed;
/**
- * struct ti_sci_msg_resp_version - Response for a message
+ * struct ti_sci_msg_version_req - Request for firmware version information
+ * @hdr: Generic header
+ *
+ * Request for TI_SCI_MSG_VERSION
+ */
+struct ti_sci_msg_req_version {
+ struct ti_sci_msg_hdr hdr;
+} __packed;
+
+/**
+ * struct ti_sci_msg_resp_version - Response for firmware version information
* @hdr: Generic header
* @firmware_description: String describing the firmware
* @firmware_revision: Firmware revision
* @abi_major: Major version of the ABI that firmware supports
* @abi_minor: Minor version of the ABI that firmware supports
+ * @sub_version: Sub-version number of the firmware
+ * @patch_version: Patch-version number of the firmware.
*
* In general, ABI version changes follow the rule that minor version increments
* are backward compatible. Major revision changes in ABI may not be
* backward compatible.
*
- * Response to a generic message with message type TI_SCI_MSG_VERSION
+ * Response to request TI_SCI_MSG_VERSION
*/
struct ti_sci_msg_resp_version {
struct ti_sci_msg_hdr hdr;
@@ -93,6 +105,8 @@
uint16_t firmware_revision;
uint8_t abi_major;
uint8_t abi_minor;
+ uint8_t sub_version;
+ uint8_t patch_version;
} __packed;
/**