Skip to contentSkip to conversation

drm/accel/ivpu: send exact IPC message size instead of union size

PATCH New Md Shofiqul Islam 1 participant 1 message May 31

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 drm/accel/ivpu: send exact IPC message size instead of union size

The IPC header data_size field is documented to carry the size of the JSM payload. Previously it was always set to sizeof(struct vpu_jsm_msg) which is the size of the full union of all possible payloads, not the size of the specific message being sent.

Introduce two helpers in ivpu_ipc.h:
IVPU_JSM_MSG_BASE_SIZE -- header-only size for messages with no payload
IVPU_JSM_MSG_SIZE(m) -- header + sizeof(payload.m) for messages that
carry a specific payload member

Thread an explicit msg_size argument through ivpu_ipc_tx_prepare(), ivpu_ipc_send(), ivpu_ipc_send_receive_internal(), ivpu_ipc_send_receive() and ivpu_ipc_send_and_wait(), then update all 25 call-sites in ivpu_jsm_msg.c to pass the appropriate size.

This resolves the TODO comment added in commit introducing the IPC layer.

---
 drivers/accel/ivpu/ivpu_ipc.c     | 27 ++++++-----
 drivers/accel/ivpu/ivpu_ipc.h     | 16 +++++--
 drivers/accel/ivpu/ivpu_jsm_msg.c | 75 ++++++++++++++++++++-----------
 3 files changed, 77 insertions(+), 41 deletions(-)
drivers/accel/ivpu/ivpu_ipc.c +15 -12
index f47df092b..0c042a7ee 100644
@@ -65,7 +65,7 @@ static void ivpu_ipc_mem_fini(struct ivpu_device *vdev)
 
 static int
 ivpu_ipc_tx_prepare(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
-		    struct vpu_jsm_msg *req)
+		    struct vpu_jsm_msg *req, u32 msg_size)
 {
 	struct ivpu_ipc_info *ipc = vdev->ipc;
 	struct ivpu_ipc_tx_buf *tx_buf;
@@ -97,8 +97,7 @@ ivpu_ipc_tx_prepare(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
 
 	memset(tx_buf, 0, sizeof(*tx_buf));
 	tx_buf->ipc.data_addr = jsm_vpu_addr;
-	/* TODO: Set data_size to actual JSM message size, not union of all messages */
-	tx_buf->ipc.data_size = sizeof(*req);
+	tx_buf->ipc.data_size = msg_size;
 	tx_buf->ipc.channel = cons->channel;
 	tx_buf->ipc.src_node = 0;
 	tx_buf->ipc.dst_node = 1;
@@ -210,7 +209,8 @@ void ivpu_ipc_consumer_del(struct ivpu_device *vdev, struct ivpu_ipc_consumer *c
 	ivpu_ipc_tx_release(vdev, cons->tx_vpu_addr);
 }
 
-int ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons, struct vpu_jsm_msg *req)
+int ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
+		  struct vpu_jsm_msg *req, u32 msg_size)
 {
 	struct ivpu_ipc_info *ipc = vdev->ipc;
 	int ret;
@@ -222,7 +222,7 @@ int ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons, stru
 		goto unlock;
 	}
 
-	ret = ivpu_ipc_tx_prepare(vdev, cons, req);
+	ret = ivpu_ipc_tx_prepare(vdev, cons, req, msg_size);
 	if (ret)
 		goto unlock;
 
@@ -296,7 +296,8 @@ int ivpu_ipc_receive(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
 int
 ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
 			       enum vpu_ipc_msg_type expected_resp_type,
-			       struct vpu_jsm_msg *resp, u32 channel, unsigned long timeout_ms)
+			       struct vpu_jsm_msg *resp, u32 channel, unsigned long timeout_ms,
+			       u32 msg_size)
 {
 	struct ivpu_ipc_consumer cons;
 	int ret;
@@ -306,7 +307,7 @@ ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *req
 
 	ivpu_ipc_consumer_add(vdev, &cons, channel, NULL);
 
-	ret = ivpu_ipc_send(vdev, &cons, req);
+	ret = ivpu_ipc_send(vdev, &cons, req, msg_size);
 	if (ret) {
 		ivpu_warn_ratelimited(vdev, "IPC send failed: %d\n", ret);
 		goto consumer_del;
@@ -331,7 +332,7 @@ ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *req
 
 int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
 			  enum vpu_ipc_msg_type expected_resp, struct vpu_jsm_msg *resp,
-			  u32 channel, unsigned long timeout_ms)
+			  u32 channel, unsigned long timeout_ms, u32 msg_size)
 {
 	struct vpu_jsm_msg hb_req = { .type = VPU_JSM_MSG_QUERY_ENGINE_HB };
 	struct vpu_jsm_msg hb_resp;
@@ -341,13 +342,15 @@ int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
 	if (ret < 0)
 		return ret;
 
-	ret = ivpu_ipc_send_receive_internal(vdev, req, expected_resp, resp, channel, timeout_ms);
+	ret = ivpu_ipc_send_receive_internal(vdev, req, expected_resp, resp, channel, timeout_ms,
+					     msg_size);
 	if (ret != -ETIMEDOUT)
 		goto rpm_put;
 
 	hb_ret = ivpu_ipc_send_receive_internal(vdev, &hb_req, VPU_JSM_MSG_QUERY_ENGINE_HB_DONE,
 						&hb_resp, VPU_IPC_CHAN_ASYNC_CMD,
-						vdev->timeout.jsm);
+						vdev->timeout.jsm,
+						IVPU_JSM_MSG_BASE_SIZE);
 	if (hb_ret == -ETIMEDOUT)
 		ivpu_pm_trigger_recovery(vdev, "IPC timeout");
 
@@ -357,7 +360,7 @@ int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
 }
 
 int ivpu_ipc_send_and_wait(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
-			   u32 channel, unsigned long timeout_ms)
+			   u32 channel, unsigned long timeout_ms, u32 msg_size)
 {
 	struct ivpu_ipc_consumer cons;
 	int ret;
@@ -368,7 +371,7 @@ int ivpu_ipc_send_and_wait(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
 
 	ivpu_ipc_consumer_add(vdev, &cons, channel, NULL);
 
-	ret = ivpu_ipc_send(vdev, &cons, req);
+	ret = ivpu_ipc_send(vdev, &cons, req, msg_size);
 	if (ret) {
 		ivpu_warn_ratelimited(vdev, "IPC send failed: %d\n", ret);
 		goto consumer_del;
drivers/accel/ivpu/ivpu_ipc.h +12 -4
index b524a1985..c1b2ef3d7 100644
@@ -11,6 +11,13 @@
 
 #include "vpu_jsm_api.h"
 
+/* Size of a JSM message with no payload */
+#define IVPU_JSM_MSG_BASE_SIZE ((u32)offsetof(struct vpu_jsm_msg, payload))
+/* Size of a JSM message with a specific payload member */
+#define IVPU_JSM_MSG_SIZE(member) \
+	((u32)(offsetof(struct vpu_jsm_msg, payload) + \
+	       sizeof(((struct vpu_jsm_msg *)0)->payload.member)))
+
 struct ivpu_bo;
 
 /* VPU FW boot notification */
@@ -97,17 +104,18 @@ void ivpu_ipc_consumer_add(struct ivpu_device *vdev, struct ivpu_ipc_consumer *c
 void ivpu_ipc_consumer_del(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons);
 
 int ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
-		  struct vpu_jsm_msg *req);
+		  struct vpu_jsm_msg *req, u32 msg_size);
 int ivpu_ipc_receive(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
 		     struct ivpu_ipc_hdr *ipc_buf, struct vpu_jsm_msg *jsm_msg,
 		     unsigned long timeout_ms);
 int ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
 				   enum vpu_ipc_msg_type expected_resp_type,
-				   struct vpu_jsm_msg *resp, u32 channel, unsigned long timeout_ms);
+				   struct vpu_jsm_msg *resp, u32 channel, unsigned long timeout_ms,
+				   u32 msg_size);
 int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
 			  enum vpu_ipc_msg_type expected_resp, struct vpu_jsm_msg *resp,
-			  u32 channel, unsigned long timeout_ms);
+			  u32 channel, unsigned long timeout_ms, u32 msg_size);
 int ivpu_ipc_send_and_wait(struct ivpu_device *vdev, struct vpu_jsm_msg *req,
-			   u32 channel, unsigned long timeout_ms);
+			   u32 channel, unsigned long timeout_ms, u32 msg_size);
 
 #endif /* __IVPU_IPC_H__ */
drivers/accel/ivpu/ivpu_jsm_msg.c +50 -25

223 lines not on this page · raw message

Signature · 1 line
2.51.1