diff mbox series

[11/15] soc: mediatek: Add cmdq_insert_backup_cookie before EOC for secure pkt

Message ID 20230918192204.32263-12-jason-jh.lin@mediatek.com (mailing list archive)
State New, archived
Headers show
Series Add CMDQ secure driver for SVP | expand

Commit Message

Jason-JH Lin (林睿祥) Sept. 18, 2023, 7:22 p.m. UTC
Add cmdq_insert_backup_cookie to append some commands before EOC:
1. Get GCE HW thread execute count from the GCE HW register.
2. Add 1 to the execute count and then store into a shared memory.
3. Set a software event siganl as secure irq to GCE HW.

Since the value of execute count + 1 is stored in a shared memory,
CMDQ driver in the normal world can use it to handle task done in irq
handler and CMDQ driver in the secure world will use it to schedule
the task slot for each secure thread.

Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
---
 drivers/soc/mediatek/mtk-cmdq-helper.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

CK Hu (胡俊光) Sept. 19, 2023, 3:04 a.m. UTC | #1
Hi, Jason:

On Tue, 2023-09-19 at 03:22 +0800, Jason-JH.Lin wrote:
> Add cmdq_insert_backup_cookie to append some commands before EOC:
> 1. Get GCE HW thread execute count from the GCE HW register.
> 2. Add 1 to the execute count and then store into a shared memory.
> 3. Set a software event siganl as secure irq to GCE HW.
> 
> Since the value of execute count + 1 is stored in a shared memory,
> CMDQ driver in the normal world can use it to handle task done in irq
> handler and CMDQ driver in the secure world will use it to schedule
> the task slot for each secure thread.
> 
> Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> ---
>  drivers/soc/mediatek/mtk-cmdq-helper.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c
> b/drivers/soc/mediatek/mtk-cmdq-helper.c
> index bbb127620bb3..7b5392878aba 100644
> --- a/drivers/soc/mediatek/mtk-cmdq-helper.c
> +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c
> @@ -8,6 +8,7 @@
>  #include <linux/module.h>
>  #include <linux/mailbox_controller.h>
>  #include <linux/of.h>
> +#include <linux/mailbox/mtk-cmdq-sec-mailbox.h>
>  #include <linux/soc/mediatek/mtk-cmdq.h>
>  
>  #define CMDQ_WRITE_ENABLE_MASK	BIT(0)
> @@ -153,7 +154,9 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt)
>  
>  	dma_unmap_single(client->chan->mbox->dev, pkt->pa_base, pkt-
> >buf_size,
>  			 DMA_TO_DEVICE);
> +
>  	kfree(pkt->va_base);
> +	kfree(pkt->sec_data);
>  	kfree(pkt);
>  }
>  EXPORT_SYMBOL(cmdq_pkt_destroy);
> @@ -458,6 +461,12 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
>  	struct cmdq_instruction inst = { {0} };
>  	int err;
>  
> +	if (pkt->sec_data) {
> +		err = cmdq_sec_insert_backup_cookie(pkt);
> +		if (err < 0)
> +			return err;
> +	}

Client driver could directly call cmdq_sec_insert_backup_cookie()
before call cmdq_pkt_finalize(). I would like helper provide simple API
and client driver would integrate simple API to what they want.

Regards,
CK

> +
>  	/* insert EOC and generate IRQ for each command iteration */
>  	inst.op = CMDQ_CODE_EOC;
>  	inst.value = CMDQ_EOC_IRQ_EN;
Jason-JH Lin (林睿祥) Sept. 21, 2023, 2:28 p.m. UTC | #2
Hi CK,

Thanks for the reivews.

On Tue, 2023-09-19 at 03:04 +0000, CK Hu (胡俊光) wrote:
> Hi, Jason:
> 
> On Tue, 2023-09-19 at 03:22 +0800, Jason-JH.Lin wrote:
> > Add cmdq_insert_backup_cookie to append some commands before EOC:
> > 1. Get GCE HW thread execute count from the GCE HW register.
> > 2. Add 1 to the execute count and then store into a shared memory.
> > 3. Set a software event siganl as secure irq to GCE HW.
> > 
> > Since the value of execute count + 1 is stored in a shared memory,
> > CMDQ driver in the normal world can use it to handle task done in
> > irq
> > handler and CMDQ driver in the secure world will use it to schedule
> > the task slot for each secure thread.
> > 
> > Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> > ---
> >  drivers/soc/mediatek/mtk-cmdq-helper.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> > 
> > diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c
> > b/drivers/soc/mediatek/mtk-cmdq-helper.c
> > index bbb127620bb3..7b5392878aba 100644
> > --- a/drivers/soc/mediatek/mtk-cmdq-helper.c
> > +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c
> > @@ -8,6 +8,7 @@
> >  #include <linux/module.h>
> >  #include <linux/mailbox_controller.h>
> >  #include <linux/of.h>
> > +#include <linux/mailbox/mtk-cmdq-sec-mailbox.h>
> >  #include <linux/soc/mediatek/mtk-cmdq.h>
> >  
> >  #define CMDQ_WRITE_ENABLE_MASK	BIT(0)
> > @@ -153,7 +154,9 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt)
> >  
> >  	dma_unmap_single(client->chan->mbox->dev, pkt->pa_base, pkt-
> > > buf_size,
> > 
> >  			 DMA_TO_DEVICE);
> > +
> >  	kfree(pkt->va_base);
> > +	kfree(pkt->sec_data);
> >  	kfree(pkt);
> >  }
> >  EXPORT_SYMBOL(cmdq_pkt_destroy);
> > @@ -458,6 +461,12 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
> >  	struct cmdq_instruction inst = { {0} };
> >  	int err;
> >  
> > +	if (pkt->sec_data) {
> > +		err = cmdq_sec_insert_backup_cookie(pkt);
> > +		if (err < 0)
> > +			return err;
> > +	}
> 
> Client driver could directly call cmdq_sec_insert_backup_cookie()
> before call cmdq_pkt_finalize(). I would like helper provide simple
> API
> and client driver would integrate simple API to what they want.
> 
OK, I'll move this to the client driver.
Thanks.

Regards,
Jason-JH.Lin

> Regards,
> CK
> 
> > +
> >  	/* insert EOC and generate IRQ for each command iteration */
> >  	inst.op = CMDQ_CODE_EOC;
> >  	inst.value = CMDQ_EOC_IRQ_EN;
diff mbox series

Patch

diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c
index bbb127620bb3..7b5392878aba 100644
--- a/drivers/soc/mediatek/mtk-cmdq-helper.c
+++ b/drivers/soc/mediatek/mtk-cmdq-helper.c
@@ -8,6 +8,7 @@ 
 #include <linux/module.h>
 #include <linux/mailbox_controller.h>
 #include <linux/of.h>
+#include <linux/mailbox/mtk-cmdq-sec-mailbox.h>
 #include <linux/soc/mediatek/mtk-cmdq.h>
 
 #define CMDQ_WRITE_ENABLE_MASK	BIT(0)
@@ -153,7 +154,9 @@  void cmdq_pkt_destroy(struct cmdq_pkt *pkt)
 
 	dma_unmap_single(client->chan->mbox->dev, pkt->pa_base, pkt->buf_size,
 			 DMA_TO_DEVICE);
+
 	kfree(pkt->va_base);
+	kfree(pkt->sec_data);
 	kfree(pkt);
 }
 EXPORT_SYMBOL(cmdq_pkt_destroy);
@@ -458,6 +461,12 @@  int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
 	struct cmdq_instruction inst = { {0} };
 	int err;
 
+	if (pkt->sec_data) {
+		err = cmdq_sec_insert_backup_cookie(pkt);
+		if (err < 0)
+			return err;
+	}
+
 	/* insert EOC and generate IRQ for each command iteration */
 	inst.op = CMDQ_CODE_EOC;
 	inst.value = CMDQ_EOC_IRQ_EN;