Skip to contentSkip to conversation

Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ

PATCH Superseded Chun-Kuang Hu 2 participants 7 messages Sep 27, 2020 – Oct 3, 2020

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chun-Kuang Hu

author maintainer
#0 lore raw

cover Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ

CMDQ helper provide timer to detect execution timeout, but DRM driver could have a better way to detect execution timeout by vblank IRQ. For DRM, CMDQ command should execute in vblank, so if it fail to execute in next 2 vblank, timeout happen. Even though we could calculate time between 2 vblank and use timer to delect, this would make things more complicated.

This introduce a series refinement for CMDQ mailbox controller and CMDQ helper. Remove timer handler in helper function because different client have different way to detect timeout. Use standard mailbox callback instead of proprietary one to get the necessary data in callback function. Remove struct cmdq_client to access client instance data by struct mbox_client.

Chun-Kuang Hu (4):
soc / drm: mediatek: cmdq: Remove timeout handler in helper function mailbox / soc / drm: mediatek: Use mailbox rx_callback instead of
cmdq_task_cb
mailbox / soc / drm: mediatek: Remove struct cmdq_client drm/mediatek: Detect CMDQ execution timeout

 drivers/gpu/drm/mediatek/mtk_drm_crtc.c  |  54 ++++++---
 drivers/mailbox/mtk-cmdq-mailbox.c       |  24 ++--
 drivers/soc/mediatek/mtk-cmdq-helper.c   | 146 ++---------------------
 include/linux/mailbox/mtk-cmdq-mailbox.h |  25 +---
 include/linux/soc/mediatek/mtk-cmdq.h    |  54 +--------
 5 files changed, 66 insertions(+), 237 deletions(-)
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 1/4 soc / drm: mediatek: cmdq: Remove timeout handler in helper function

For each client driver, its timeout handler need to dump hardware register or its state machine information, and their way to detect timeout are also different, so remove timeout handler in helper function and let client driver implement its own timeout handler.

---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c |  3 +-
 drivers/soc/mediatek/mtk-cmdq-helper.c  | 41 +------------------------
 include/linux/soc/mediatek/mtk-cmdq.h   | 11 +------
 3 files changed, 3 insertions(+), 52 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1 -2
index 3fc5511330b9..cabeb7fea2be 100644
@@ -824,8 +824,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
 	mtk_crtc->cmdq_client =
 			cmdq_mbox_create(mtk_crtc->mmsys_dev,
-					 drm_crtc_index(&mtk_crtc->base),
-					 2000);
+					 drm_crtc_index(&mtk_crtc->base));
 	if (IS_ERR(mtk_crtc->cmdq_client)) {
 		dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
 			drm_crtc_index(&mtk_crtc->base));
drivers/soc/mediatek/mtk-cmdq-helper.c +1 -40

77 lines not on this page · raw message

include/linux/soc/mediatek/mtk-cmdq.h +1 -10
index 2249ecaf77e4..175bd89f46f8 100644
@@ -11,8 +11,6 @@
 #include <linux/mailbox/mtk-cmdq-mailbox.h>
 #include <linux/timer.h>
 
-#define CMDQ_NO_TIMEOUT		0xffffffffu
-
 struct cmdq_pkt;
 
 struct cmdq_client_reg {
@@ -22,12 +20,8 @@ struct cmdq_client_reg {
 };
 
 struct cmdq_client {
-	spinlock_t lock;
-	u32 pkt_cnt;
 	struct mbox_client client;
 	struct mbox_chan *chan;
-	struct timer_list timer;
-	u32 timeout_ms; /* in unit of microsecond */
 };
 
 /**
@@ -49,13 +43,10 @@ int cmdq_dev_get_client_reg(struct device *dev,
  * cmdq_mbox_create() - create CMDQ mailbox client and channel
  * @dev:	device of CMDQ mailbox client
  * @index:	index of CMDQ mailbox channel
- * @timeout:	timeout of a pkt execution by GCE, in unit of microsecond, set
- *		CMDQ_NO_TIMEOUT if a timer is not used.
  *
  * Return: CMDQ mailbox client pointer
  */
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
-				     u32 timeout);
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
 
 /**
  * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH 2/4 mailbox / soc / drm: mediatek: Use mailbox rx_callback instead of cmdq_task_cb

In reply to Chun-Kuang Hu

rx_callback is a standard mailbox callback mechanism and could cover the function of proprietary cmdq_task_cb, so use the standard one instead of the proprietary one.

---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c  | 17 +++++--
 drivers/mailbox/mtk-cmdq-mailbox.c       | 24 ++++------
 drivers/soc/mediatek/mtk-cmdq-helper.c   | 57 +-----------------------
 include/linux/mailbox/mtk-cmdq-mailbox.h | 24 +++-------
 include/linux/soc/mediatek/mtk-cmdq.h    | 17 +------
 5 files changed, 30 insertions(+), 109 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +14 -3
index cabeb7fea2be..5df2d431418d 100644
@@ -4,9 +4,11 @@
  */
 
 #include <linux/clk.h>
+#include <linux/dma-mapping.h>
 #include <linux/pm_runtime.h>
 #include <linux/soc/mediatek/mtk-cmdq.h>
 #include <linux/soc/mediatek/mtk-mmsys.h>
+#include <linux/mailbox_controller.h>
 
 #include <asm/barrier.h>
 #include <soc/mediatek/smi.h>
@@ -236,9 +238,11 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
 }
 
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
-static void ddp_cmdq_cb(struct cmdq_cb_data data)
+static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
 {
-	cmdq_pkt_destroy(data.data);
+	struct cmdq_cb_data *data = mssg;
+
+	cmdq_pkt_destroy(data->pkt);
 }
 #endif
 
@@ -484,7 +488,11 @@ static void mtk_drm_crtc_hw_config(struct mtk_drm_crtc *mtk_crtc)
 		cmdq_pkt_wfe(cmdq_handle, mtk_crtc->cmdq_event);
 		mtk_crtc_ddp_config(crtc, cmdq_handle);
 		cmdq_pkt_finalize(cmdq_handle);
-		cmdq_pkt_flush_async(cmdq_handle, ddp_cmdq_cb, cmdq_handle);
+		dma_sync_single_for_device(mtk_crtc->cmdq_client->chan->mbox->dev,
+					   cmdq_handle->pa_base,
+					   cmdq_handle->cmd_buf_size,
+					   DMA_TO_DEVICE);
+		cmdq_pkt_flush_async(cmdq_handle);
 	}
 #endif
 	mutex_unlock(&mtk_crtc->hw_lock);
@@ -837,6 +845,9 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
 	if (ret)
 		dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n",
 			drm_crtc_index(&mtk_crtc->base));
+
+	if (mtk_crtc->cmdq_client)
+		mtk_crtc->cmdq_client->client.rx_callback = ddp_cmdq_cb;
 #endif
 	return 0;
 }
drivers/mailbox/mtk-cmdq-mailbox.c +9 -15
index 484d4438cd83..bc11afdebefc 100644
@@ -180,15 +180,13 @@ static bool cmdq_thread_is_in_wfe(struct cmdq_thread *thread)
 	return readl(thread->base + CMDQ_THR_WAIT_TOKEN) & CMDQ_THR_IS_WAITING;
 }
 
-static void cmdq_task_exec_done(struct cmdq_task *task, enum cmdq_cb_status sta)
+static void cmdq_task_exec_done(struct cmdq_task *task, int sta)
 {
-	struct cmdq_task_cb *cb = &task->pkt->async_cb;
 	struct cmdq_cb_data data;
 
-	WARN_ON(cb->cb == (cmdq_async_flush_cb)NULL);
 	data.sta = sta;
-	data.data = cb->data;
-	cb->cb(data);
+	data.pkt = task->pkt;
+	mbox_chan_received_data(task->thread->chan, &data);
 
 	list_del(&task->list_entry);
 }
@@ -244,10 +242,10 @@ static void cmdq_thread_irq_handler(struct cmdq *cmdq,
 			curr_task = task;
 
 		if (!curr_task || curr_pa == task_end_pa - CMDQ_INST_SIZE) {
-			cmdq_task_exec_done(task, CMDQ_CB_NORMAL);
+			cmdq_task_exec_done(task, 0);
 			kfree(task);
 		} else if (err) {
-			cmdq_task_exec_done(task, CMDQ_CB_ERROR);
+			cmdq_task_exec_done(task, -ENOEXEC);
 			cmdq_task_handle_error(curr_task);
 			kfree(task);
 		}
@@ -415,7 +413,7 @@ static void cmdq_mbox_shutdown(struct mbox_chan *chan)
 
 	list_for_each_entry_safe(task, tmp, &thread->task_busy_list,
 				 list_entry) {
-		cmdq_task_exec_done(task, CMDQ_CB_ERROR);
+		cmdq_task_exec_done(task, -ECONNABORTED);
 		kfree(task);
 	}
 
@@ -434,7 +432,6 @@ static void cmdq_mbox_shutdown(struct mbox_chan *chan)
 static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout)
 {
 	struct cmdq_thread *thread = (struct cmdq_thread *)chan->con_priv;
-	struct cmdq_task_cb *cb;
 	struct cmdq_cb_data data;
 	struct cmdq *cmdq = dev_get_drvdata(chan->mbox->dev);
 	struct cmdq_task *task, *tmp;
@@ -451,12 +448,9 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout)
 
 	list_for_each_entry_safe(task, tmp, &thread->task_busy_list,
 				 list_entry) {
-		cb = &task->pkt->async_cb;
-		if (cb->cb) {
-			data.sta = CMDQ_CB_ERROR;
-			data.data = cb->data;
-			cb->cb(data);
-		}
+		data.sta = -ECONNABORTED;
+		data.pkt = task->pkt;
+		mbox_chan_received_data(task->thread->chan, &data);
 		list_del(&task->list_entry);
 		kfree(task);
 	}
drivers/soc/mediatek/mtk-cmdq-helper.c +1 -56

71 lines not on this page · raw message

include/linux/mailbox/mtk-cmdq-mailbox.h +5 -19
index 05eea1aef5aa..2cec4dbaa214 100644
@@ -63,33 +63,19 @@ enum cmdq_code {
 	CMDQ_CODE_LOGIC = 0xa0,
 };
 
-enum cmdq_cb_status {
-	CMDQ_CB_NORMAL = 0,
-	CMDQ_CB_ERROR
-};
-
-struct cmdq_cb_data {
-	enum cmdq_cb_status	sta;
-	void			*data;
-};
-
-typedef void (*cmdq_async_flush_cb)(struct cmdq_cb_data data);
-
-struct cmdq_task_cb {
-	cmdq_async_flush_cb	cb;
-	void			*data;
-};
-
 struct cmdq_pkt {
 	void			*va_base;
 	dma_addr_t		pa_base;
 	size_t			cmd_buf_size; /* command occupied size */
 	size_t			buf_size; /* real buffer size */
-	struct cmdq_task_cb	cb;
-	struct cmdq_task_cb	async_cb;
 	void			*cl;
 };
 
+struct cmdq_cb_data {
+	int sta;
+	struct cmdq_pkt *pkt;
+};
+
 u8 cmdq_get_shift_pa(struct mbox_chan *chan);
 
 #endif /* __MTK_CMDQ_MAILBOX_H__ */
include/linux/soc/mediatek/mtk-cmdq.h +1 -16
index 175bd89f46f8..a09b3f39b861 100644
@@ -178,8 +178,6 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt);
  * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
  *                          packet and call back at the end of done packet
  * @pkt:	the CMDQ packet
- * @cb:		called at the end of done packet
- * @data:	this data will pass back to cb
  *
  * Return: 0 for success; else the error code is returned
  *
@@ -187,19 +185,6 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt);
  * at the end of done packet. Note that this is an ASYNC function. When the
  * function returned, it may or may not be finished.
  */
-int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
-			 void *data);
-
-/**
- * cmdq_pkt_flush() - trigger CMDQ to execute the CMDQ packet
- * @pkt:	the CMDQ packet
- *
- * Return: 0 for success; else the error code is returned
- *
- * Trigger CMDQ to execute the CMDQ packet. Note that this is a
- * synchronous flush function. When the function returned, the recorded
- * commands have been done.
- */
-int cmdq_pkt_flush(struct cmdq_pkt *pkt);
+int cmdq_pkt_flush_async(struct cmdq_pkt *pkt);
 
 #endif	/* __MTK_CMDQ_H__ */
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#3 lore raw

PATCH 3/4 mailbox / soc / drm: mediatek: Remove struct cmdq_client

In reply to Chun-Kuang Hu

In mailbox rx_callback, it pass struct mbox_client to callback function, but it could not map back to client instance because struct cmdq_client use a pointer to struct mbox_client:

struct cmdq_client {
	struct mbox_client client;
	struct mbox_chan *chan;
};
struct client_instance {
	/* client instance data */
	struct cmdq_client *cmdq_client;
};

so remove struct cmdq_client and let client instance define mbox_client as:

struct client_instance {
	/* client instance data */
	struct mbox_client cl;
};

and in rx_callback function, use struct mbox_client to get struct client_instance.

---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c  | 35 ++++++++--------
 drivers/soc/mediatek/mtk-cmdq-helper.c   | 52 ++++--------------------
 include/linux/mailbox/mtk-cmdq-mailbox.h |  1 -
 include/linux/soc/mediatek/mtk-cmdq.h    | 30 +++-----------
 4 files changed, 32 insertions(+), 86 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +19 -16
index 5df2d431418d..f99c9d2032b8 100644
@@ -49,7 +49,8 @@ struct mtk_drm_crtc {
 	bool				pending_async_planes;
 
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
-	struct cmdq_client		*cmdq_client;
+	struct mbox_client		cmdq_cl;
+	struct mbox_chan		*cmdq_chan;
 	u32				cmdq_event;
 #endif
 
@@ -240,9 +241,10 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
 static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
 {
+	struct mtk_drm_crtc *mtk_crtc = container_of(cl, struct mtk_drm_crtc, cmdq_cl);
 	struct cmdq_cb_data *data = mssg;
 
-	cmdq_pkt_destroy(data->pkt);
+	cmdq_pkt_destroy(mtk_crtc->cmdq_chan, data->pkt);
 }
 #endif
 
@@ -481,18 +483,18 @@ static void mtk_drm_crtc_hw_config(struct mtk_drm_crtc *mtk_crtc)
 		mtk_disp_mutex_release(mtk_crtc->mutex);
 	}
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
-	if (mtk_crtc->cmdq_client) {
-		mbox_flush(mtk_crtc->cmdq_client->chan, 2000);
-		cmdq_handle = cmdq_pkt_create(mtk_crtc->cmdq_client, PAGE_SIZE);
+	if (mtk_crtc->cmdq_chan) {
+		mbox_flush(mtk_crtc->cmdq_chan, 2000);
+		cmdq_handle = cmdq_pkt_create(mtk_crtc->cmdq_chan, PAGE_SIZE);
 		cmdq_pkt_clear_event(cmdq_handle, mtk_crtc->cmdq_event);
 		cmdq_pkt_wfe(cmdq_handle, mtk_crtc->cmdq_event);
 		mtk_crtc_ddp_config(crtc, cmdq_handle);
 		cmdq_pkt_finalize(cmdq_handle);
-		dma_sync_single_for_device(mtk_crtc->cmdq_client->chan->mbox->dev,
+		dma_sync_single_for_device(mtk_crtc->cmdq_chan->mbox->dev,
 					   cmdq_handle->pa_base,
 					   cmdq_handle->cmd_buf_size,
 					   DMA_TO_DEVICE);
-		cmdq_pkt_flush_async(cmdq_handle);
+		cmdq_pkt_flush_async(mtk_crtc->cmdq_chan, cmdq_handle);
 	}
 #endif
 	mutex_unlock(&mtk_crtc->hw_lock);
@@ -671,7 +673,7 @@ void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp)
 	struct mtk_drm_private *priv = crtc->dev->dev_private;
 
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
-	if (!priv->data->shadow_register && !mtk_crtc->cmdq_client)
+	if (!priv->data->shadow_register && !mtk_crtc->cmdq_chan)
 #else
 	if (!priv->data->shadow_register)
 #endif
@@ -830,14 +832,18 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
 	mutex_init(&mtk_crtc->hw_lock);
 
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
-	mtk_crtc->cmdq_client =
-			cmdq_mbox_create(mtk_crtc->mmsys_dev,
-					 drm_crtc_index(&mtk_crtc->base));
-	if (IS_ERR(mtk_crtc->cmdq_client)) {
+	mtk_crtc->cmdq_cl.dev = mtk_crtc->mmsys_dev;
+	mtk_crtc->cmdq_cl.tx_block = false;
+	mtk_crtc->cmdq_cl.knows_txdone = true;
+	mtk_crtc->cmdq_cl.rx_callback = ddp_cmdq_cb;
+	mtk_crtc->cmdq_chan = mbox_request_channel(&mtk_crtc->cmdq_cl,
+						   drm_crtc_index(&mtk_crtc->base));
+	if (IS_ERR(mtk_crtc->cmdq_chan)) {
 		dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
 			drm_crtc_index(&mtk_crtc->base));
-		mtk_crtc->cmdq_client = NULL;
+		mtk_crtc->cmdq_chan = NULL;
 	}
+
 	ret = of_property_read_u32_index(priv->mutex_node,
 					 "mediatek,gce-events",
 					 drm_crtc_index(&mtk_crtc->base),
@@ -845,9 +851,6 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
 	if (ret)
 		dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n",
 			drm_crtc_index(&mtk_crtc->base));
-
-	if (mtk_crtc->cmdq_client)
-		mtk_crtc->cmdq_client->client.rx_callback = ddp_cmdq_cb;
 #endif
 	return 0;
 }
drivers/soc/mediatek/mtk-cmdq-helper.c +7 -45

84 lines not on this page · raw message

include/linux/mailbox/mtk-cmdq-mailbox.h +0 -1
index 2cec4dbaa214..ce2eaf7eaf34 100644
@@ -68,7 +68,6 @@ struct cmdq_pkt {
 	dma_addr_t		pa_base;
 	size_t			cmd_buf_size; /* command occupied size */
 	size_t			buf_size; /* real buffer size */
-	void			*cl;
 };
 
 struct cmdq_cb_data {
include/linux/soc/mediatek/mtk-cmdq.h +6 -24
index a09b3f39b861..fb35da22e00c 100644
@@ -19,11 +19,6 @@ struct cmdq_client_reg {
 	u16 size;
 };
 
-struct cmdq_client {
-	struct mbox_client client;
-	struct mbox_chan *chan;
-};
-
 /**
  * cmdq_dev_get_client_reg() - parse cmdq client reg from the device
  *			       node of CMDQ client
@@ -39,35 +34,21 @@ struct cmdq_client {
 int cmdq_dev_get_client_reg(struct device *dev,
 			    struct cmdq_client_reg *client_reg, int idx);
 
-/**
- * cmdq_mbox_create() - create CMDQ mailbox client and channel
- * @dev:	device of CMDQ mailbox client
- * @index:	index of CMDQ mailbox channel
- *
- * Return: CMDQ mailbox client pointer
- */
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
-
-/**
- * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
- * @client:	the CMDQ mailbox client
- */
-void cmdq_mbox_destroy(struct cmdq_client *client);
-
 /**
  * cmdq_pkt_create() - create a CMDQ packet
- * @client:	the CMDQ mailbox client
+ * @chan:	the mailbox channel
  * @size:	required CMDQ buffer size
  *
  * Return: CMDQ packet pointer
  */
-struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size);
+struct cmdq_pkt *cmdq_pkt_create(struct mbox_chan *chan, size_t size);
 
 /**
  * cmdq_pkt_destroy() - destroy the CMDQ packet
+ * @chan:	the mailbox channel
  * @pkt:	the CMDQ packet
  */
-void cmdq_pkt_destroy(struct cmdq_pkt *pkt);
+void cmdq_pkt_destroy(struct mbox_chan *chan, struct cmdq_pkt *pkt);
 
 /**
  * cmdq_pkt_write() - append write command to the CMDQ packet
@@ -177,6 +158,7 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt);
 /**
  * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
  *                          packet and call back at the end of done packet
+ * @chan:	the mailbox channel
  * @pkt:	the CMDQ packet
  *
  * Return: 0 for success; else the error code is returned
@@ -185,6 +167,6 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt);
  * at the end of done packet. Note that this is an ASYNC function. When the
  * function returned, it may or may not be finished.
  */
-int cmdq_pkt_flush_async(struct cmdq_pkt *pkt);
+int cmdq_pkt_flush_async(struct mbox_chan *chan, struct cmdq_pkt *pkt);
 
 #endif	/* __MTK_CMDQ_H__ */
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#4 lore raw

PATCH 4/4 drm/mediatek: Detect CMDQ execution timeout

In reply to Chun-Kuang Hu

CMDQ is used to update display register in vblank period, so it should be execute in next vblank. If it fail to execute in next 2 vblank, tiemout happen.

---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +12 -1
index f99c9d2032b8..71f770e25ad2 100644
@@ -52,6 +52,7 @@ struct mtk_drm_crtc {
 	struct mbox_client		cmdq_cl;
 	struct mbox_chan		*cmdq_chan;
 	u32				cmdq_event;
+	u32				cmdq_vblank_cnt;
 #endif
 
 	struct device			*mmsys_dev;
@@ -244,6 +245,7 @@ static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
 	struct mtk_drm_crtc *mtk_crtc = container_of(cl, struct mtk_drm_crtc, cmdq_cl);
 	struct cmdq_cb_data *data = mssg;
 
+	mtk_crtc->cmdq_vblank_cnt = 0;
 	cmdq_pkt_destroy(mtk_crtc->cmdq_chan, data->pkt);
 }
 #endif
@@ -494,6 +496,11 @@ static void mtk_drm_crtc_hw_config(struct mtk_drm_crtc *mtk_crtc)
 					   cmdq_handle->pa_base,
 					   cmdq_handle->cmd_buf_size,
 					   DMA_TO_DEVICE);
+		/*
+		 * CMDQ command should execute in next vblank,
+		 * If it fail to execute in next 2 vblank, timeout happen.
+		 */
+		mtk_crtc->cmdq_vblank_cnt = 2;
 		cmdq_pkt_flush_async(mtk_crtc->cmdq_chan, cmdq_handle);
 	}
 #endif
@@ -674,10 +681,14 @@ void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp)
 
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
 	if (!priv->data->shadow_register && !mtk_crtc->cmdq_chan)
+		mtk_crtc_ddp_config(crtc, NULL);
+	else if (mtk_crtc->cmdq_vblank_cnt && --mtk_crtc->cmdq_vblank_cnt == 0)
+		DRM_ERROR("mtk_crtc %d CMDQ execute command timeout!\n",
+			  drm_crtc_index(&mtk_crtc->base));
 #else
 	if (!priv->data->shadow_register)
-#endif
 		mtk_crtc_ddp_config(crtc, NULL);
+#endif
 
 	mtk_drm_finish_page_flip(mtk_crtc);
 }
Signature · 1 line
2.17.1
maintainer
#5 lore raw
In reply to Chun-Kuang Hu
Quoted 22 lines · Chun-Kuang Hu

CMDQ helper provide timer to detect execution timeout, but DRM driver could have a better way to detect execution timeout by vblank IRQ. For DRM, CMDQ command should execute in vblank, so if it fail to execute in next 2 vblank, timeout happen. Even though we could calculate time between 2 vblank and use timer to delect, this would make things more complicated.

This introduce a series refinement for CMDQ mailbox controller and CMDQ helper. Remove timer handler in helper function because different client have different way to detect timeout. Use standard mailbox callback instead of proprietary one to get the necessary data in callback function. Remove struct cmdq_client to access client instance data by struct mbox_client.

Chun-Kuang Hu (4):
soc / drm: mediatek: cmdq: Remove timeout handler in helper function mailbox / soc / drm: mediatek: Use mailbox rx_callback instead of
cmdq_task_cb
mailbox / soc / drm: mediatek: Remove struct cmdq_client drm/mediatek: Detect CMDQ execution timeout

Quoted 7 lines
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c  |  54 ++++++---
 drivers/mailbox/mtk-cmdq-mailbox.c       |  24 ++--
 drivers/soc/mediatek/mtk-cmdq-helper.c   | 146 ++---------------------
 include/linux/mailbox/mtk-cmdq-mailbox.h |  25 +---
 include/linux/soc/mediatek/mtk-cmdq.h    |  54 +--------
 5 files changed, 66 insertions(+), 237 deletions(-)

Please break this into two patchsets - one for mailbox and one for its users. Also, CC original author and recent major contributors to mtk-cmdq-mailbox.c

Thanks.

author maintainer
#6 lore raw

Hi, Jassi:

Jassi Brar <[email protected]> 於 2020年10月3日 週六 上午4:30寫道:

Quoted 31 lines · Chun-Kuang Hu
Quoted 22 lines

CMDQ helper provide timer to detect execution timeout, but DRM driver could have a better way to detect execution timeout by vblank IRQ. For DRM, CMDQ command should execute in vblank, so if it fail to execute in next 2 vblank, timeout happen. Even though we could calculate time between 2 vblank and use timer to delect, this would make things more complicated.

This introduce a series refinement for CMDQ mailbox controller and CMDQ helper. Remove timer handler in helper function because different client have different way to detect timeout. Use standard mailbox callback instead of proprietary one to get the necessary data in callback function. Remove struct cmdq_client to access client instance data by struct mbox_client.

Chun-Kuang Hu (4):
soc / drm: mediatek: cmdq: Remove timeout handler in helper function mailbox / soc / drm: mediatek: Use mailbox rx_callback instead of
cmdq_task_cb
mailbox / soc / drm: mediatek: Remove struct cmdq_client drm/mediatek: Detect CMDQ execution timeout

Quoted 7 lines
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c  |  54 ++++++---
 drivers/mailbox/mtk-cmdq-mailbox.c       |  24 ++--
 drivers/soc/mediatek/mtk-cmdq-helper.c   | 146 ++---------------------
 include/linux/mailbox/mtk-cmdq-mailbox.h |  25 +---
 include/linux/soc/mediatek/mtk-cmdq.h    |  54 +--------
 5 files changed, 66 insertions(+), 237 deletions(-)
Quoted 3 lines

Please break this into two patchsets - one for mailbox and one for its users. Also, CC original author and recent major contributors to mtk-cmdq-mailbox.c

Agree with you. But for patch [2/4] ("Use mailbox rx_callback instead of cmdq_task_cb"), I think it would be a long term process. I would break it into:

1. mtk-cmdq-mailbox.c: add rx_callback and keep cmdq_task_cb because client is using cmdq_task_cb.
2. client: change from cmdq_task_cb to rx_callback.
3. mtk-cmdq-mailbox.c: remove cmdq_task_cb.

The three step has dependency, but the 2nd should move to another series, so I would go 1st step first.

Regards,
Chun-Kuang.

Quoted 1 line

Thanks.

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel