Skip to content

Commit 69ff683

Browse files
Jason-JH.LinAngeloGioacchino Del Regno
authored andcommitted
soc: mediatek: mtk-cmdq: Add cmdq_pkt_acquire_event() function
Add cmdq_pkt_acquire_event() function to support CMDQ user making an instruction for acquiring event. CMDQ users can use cmdq_pkt_acquire_event() as `mutex_lock` and cmdq_pkt_clear_event() as `mutex_unlock` to protect the global resource modified instructions between them. cmdq_pkt_acquire_event() would wait for event to be cleared. After event is cleared by cmdq_pkt_clear_event() in other GCE threads, cmdq_pkt_acquire_event() would set event and keep executing next instruction. So the mutex would work like this: cmdq_pkt_acquire_event() /* mutex lock */ /* critical secton instructions that modified global resource */ cmdq_pkt_clear_event() /* mutex unlock */ Prevent the critical section instructions from being affected by other GCE threads. Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://lore.kernel.org/r/20240307013458.23550-5-jason-jh.lin@mediatek.com Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
1 parent 400e2fa commit 69ff683

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

drivers/soc/mediatek/mtk-cmdq-helper.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,21 @@ int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event, bool clear)
334334
}
335335
EXPORT_SYMBOL(cmdq_pkt_wfe);
336336

337+
int cmdq_pkt_acquire_event(struct cmdq_pkt *pkt, u16 event)
338+
{
339+
struct cmdq_instruction inst = {};
340+
341+
if (event >= CMDQ_MAX_EVENT)
342+
return -EINVAL;
343+
344+
inst.op = CMDQ_CODE_WFE;
345+
inst.value = CMDQ_WFE_UPDATE | CMDQ_WFE_UPDATE_VALUE | CMDQ_WFE_WAIT;
346+
inst.event = event;
347+
348+
return cmdq_pkt_append_command(pkt, inst);
349+
}
350+
EXPORT_SYMBOL(cmdq_pkt_acquire_event);
351+
337352
int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event)
338353
{
339354
struct cmdq_instruction inst = { {0} };

include/linux/soc/mediatek/mtk-cmdq.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ int cmdq_pkt_mem_move(struct cmdq_pkt *pkt, dma_addr_t src_addr, dma_addr_t dst_
206206
*/
207207
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event, bool clear);
208208

209+
/**
210+
* cmdq_pkt_acquire_event() - append acquire event command to the CMDQ packet
211+
* @pkt: the CMDQ packet
212+
* @event: the desired event to be acquired
213+
*
214+
* User can use cmdq_pkt_acquire_event() as `mutex_lock` and cmdq_pkt_clear_event()
215+
* as `mutex_unlock` to protect some `critical section` instructions between them.
216+
* cmdq_pkt_acquire_event() would wait for event to be cleared.
217+
* After event is cleared by cmdq_pkt_clear_event in other GCE threads,
218+
* cmdq_pkt_acquire_event() would set event and keep executing next instruction.
219+
*
220+
* Return: 0 for success; else the error code is returned
221+
*/
222+
int cmdq_pkt_acquire_event(struct cmdq_pkt *pkt, u16 event);
223+
209224
/**
210225
* cmdq_pkt_clear_event() - append clear event command to the CMDQ packet
211226
* @pkt: the CMDQ packet

0 commit comments

Comments
 (0)