Skip to content

Commit 9f7f269

Browse files
committed
Merge tag 'v5.9-next-soc' of https://git.kernel.org/pub/scm/linux/kernel/git/matthias.bgg/linux into arm/drivers
cmdq helper: - add new functionality for writing and reading values to and from addresses * tag 'v5.9-next-soc' of https://git.kernel.org/pub/scm/linux/kernel/git/matthias.bgg/linux: drm/mediatek: reduce clear event soc: mediatek: cmdq: add clear option in cmdq_pkt_wfe api soc: mediatek: cmdq: add jump function soc: mediatek: cmdq: add write_s_mask value function soc: mediatek: cmdq: add write_s value function soc: mediatek: cmdq: add read_s function soc: mediatek: cmdq: add write_s_mask function soc: mediatek: cmdq: add write_s function soc: mediatek: cmdq: add address shift in jump soc: mediatek: mtk-infracfg: Fix kerneldoc Link: https://lore.kernel.org/r/ac672cc9-059c-b768-3a67-1f674d4a2b7a@gmail.com Signed-off-by: Olof Johansson <olof@lixom.net>
2 parents 64de2cd + bee1abc commit 9f7f269

5 files changed

Lines changed: 208 additions & 10 deletions

File tree

drivers/gpu/drm/mediatek/mtk_drm_crtc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static void mtk_drm_crtc_hw_config(struct mtk_drm_crtc *mtk_crtc)
481481
mbox_flush(mtk_crtc->cmdq_client->chan, 2000);
482482
cmdq_handle = cmdq_pkt_create(mtk_crtc->cmdq_client, PAGE_SIZE);
483483
cmdq_pkt_clear_event(cmdq_handle, mtk_crtc->cmdq_event);
484-
cmdq_pkt_wfe(cmdq_handle, mtk_crtc->cmdq_event);
484+
cmdq_pkt_wfe(cmdq_handle, mtk_crtc->cmdq_event, false);
485485
mtk_crtc_ddp_config(crtc, cmdq_handle);
486486
cmdq_pkt_finalize(cmdq_handle);
487487
cmdq_pkt_flush_async(cmdq_handle, ddp_cmdq_cb, cmdq_handle);

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

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
#define CMDQ_POLL_ENABLE_MASK BIT(0)
1414
#define CMDQ_EOC_IRQ_EN BIT(0)
1515
#define CMDQ_REG_TYPE 1
16+
#define CMDQ_JUMP_RELATIVE 1
1617

1718
struct cmdq_instruction {
1819
union {
1920
u32 value;
2021
u32 mask;
22+
struct {
23+
u16 arg_c;
24+
u16 src_reg;
25+
};
2126
};
2227
union {
2328
u16 offset;
@@ -223,15 +228,104 @@ int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
223228
}
224229
EXPORT_SYMBOL(cmdq_pkt_write_mask);
225230

226-
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event)
231+
int cmdq_pkt_read_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx, u16 addr_low,
232+
u16 reg_idx)
233+
{
234+
struct cmdq_instruction inst = {};
235+
236+
inst.op = CMDQ_CODE_READ_S;
237+
inst.dst_t = CMDQ_REG_TYPE;
238+
inst.sop = high_addr_reg_idx;
239+
inst.reg_dst = reg_idx;
240+
inst.src_reg = addr_low;
241+
242+
return cmdq_pkt_append_command(pkt, inst);
243+
}
244+
EXPORT_SYMBOL(cmdq_pkt_read_s);
245+
246+
int cmdq_pkt_write_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
247+
u16 addr_low, u16 src_reg_idx)
248+
{
249+
struct cmdq_instruction inst = {};
250+
251+
inst.op = CMDQ_CODE_WRITE_S;
252+
inst.src_t = CMDQ_REG_TYPE;
253+
inst.sop = high_addr_reg_idx;
254+
inst.offset = addr_low;
255+
inst.src_reg = src_reg_idx;
256+
257+
return cmdq_pkt_append_command(pkt, inst);
258+
}
259+
EXPORT_SYMBOL(cmdq_pkt_write_s);
260+
261+
int cmdq_pkt_write_s_mask(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
262+
u16 addr_low, u16 src_reg_idx, u32 mask)
263+
{
264+
struct cmdq_instruction inst = {};
265+
int err;
266+
267+
inst.op = CMDQ_CODE_MASK;
268+
inst.mask = ~mask;
269+
err = cmdq_pkt_append_command(pkt, inst);
270+
if (err < 0)
271+
return err;
272+
273+
inst.mask = 0;
274+
inst.op = CMDQ_CODE_WRITE_S_MASK;
275+
inst.src_t = CMDQ_REG_TYPE;
276+
inst.sop = high_addr_reg_idx;
277+
inst.offset = addr_low;
278+
inst.src_reg = src_reg_idx;
279+
280+
return cmdq_pkt_append_command(pkt, inst);
281+
}
282+
EXPORT_SYMBOL(cmdq_pkt_write_s_mask);
283+
284+
int cmdq_pkt_write_s_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
285+
u16 addr_low, u32 value)
286+
{
287+
struct cmdq_instruction inst = {};
288+
289+
inst.op = CMDQ_CODE_WRITE_S;
290+
inst.sop = high_addr_reg_idx;
291+
inst.offset = addr_low;
292+
inst.value = value;
293+
294+
return cmdq_pkt_append_command(pkt, inst);
295+
}
296+
EXPORT_SYMBOL(cmdq_pkt_write_s_value);
297+
298+
int cmdq_pkt_write_s_mask_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
299+
u16 addr_low, u32 value, u32 mask)
300+
{
301+
struct cmdq_instruction inst = {};
302+
int err;
303+
304+
inst.op = CMDQ_CODE_MASK;
305+
inst.mask = ~mask;
306+
err = cmdq_pkt_append_command(pkt, inst);
307+
if (err < 0)
308+
return err;
309+
310+
inst.op = CMDQ_CODE_WRITE_S_MASK;
311+
inst.sop = high_addr_reg_idx;
312+
inst.offset = addr_low;
313+
inst.value = value;
314+
315+
return cmdq_pkt_append_command(pkt, inst);
316+
}
317+
EXPORT_SYMBOL(cmdq_pkt_write_s_mask_value);
318+
319+
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event, bool clear)
227320
{
228321
struct cmdq_instruction inst = { {0} };
322+
u32 clear_option = clear ? CMDQ_WFE_UPDATE : 0;
229323

230324
if (event >= CMDQ_MAX_EVENT)
231325
return -EINVAL;
232326

233327
inst.op = CMDQ_CODE_WFE;
234-
inst.value = CMDQ_WFE_OPTION;
328+
inst.value = CMDQ_WFE_OPTION | clear_option;
235329
inst.event = event;
236330

237331
return cmdq_pkt_append_command(pkt, inst);
@@ -315,6 +409,18 @@ int cmdq_pkt_assign(struct cmdq_pkt *pkt, u16 reg_idx, u32 value)
315409
}
316410
EXPORT_SYMBOL(cmdq_pkt_assign);
317411

412+
int cmdq_pkt_jump(struct cmdq_pkt *pkt, dma_addr_t addr)
413+
{
414+
struct cmdq_instruction inst = {};
415+
416+
inst.op = CMDQ_CODE_JUMP;
417+
inst.offset = CMDQ_JUMP_RELATIVE;
418+
inst.value = addr >>
419+
cmdq_get_shift_pa(((struct cmdq_client *)pkt->cl)->chan);
420+
return cmdq_pkt_append_command(pkt, inst);
421+
}
422+
EXPORT_SYMBOL(cmdq_pkt_jump);
423+
318424
int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
319425
{
320426
struct cmdq_instruction inst = { {0} };
@@ -329,7 +435,8 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
329435

330436
/* JUMP to end */
331437
inst.op = CMDQ_CODE_JUMP;
332-
inst.value = CMDQ_JUMP_PASS;
438+
inst.value = CMDQ_JUMP_PASS >>
439+
cmdq_get_shift_pa(((struct cmdq_client *)pkt->cl)->chan);
333440
err = cmdq_pkt_append_command(pkt, inst);
334441

335442
return err;

drivers/soc/mediatek/mtk-infracfg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/**
2121
* mtk_infracfg_set_bus_protection - enable bus protection
22-
* @regmap: The infracfg regmap
22+
* @infracfg: The infracfg regmap
2323
* @mask: The mask containing the protection bits to be enabled.
2424
* @reg_update: The boolean flag determines to set the protection bits
2525
* by regmap_update_bits with enable register(PROTECTEN) or
@@ -50,7 +50,7 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
5050

5151
/**
5252
* mtk_infracfg_clear_bus_protection - disable bus protection
53-
* @regmap: The infracfg regmap
53+
* @infracfg: The infracfg regmap
5454
* @mask: The mask containing the protection bits to be disabled.
5555
* @reg_update: The boolean flag determines to clear the protection bits
5656
* by regmap_update_bits with enable register(PROTECTEN) or

include/linux/mailbox/mtk-cmdq-mailbox.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
* bit 16-27: update value
2929
* bit 31: 1 - update, 0 - no update
3030
*/
31-
#define CMDQ_WFE_OPTION (CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | \
32-
CMDQ_WFE_WAIT_VALUE)
31+
#define CMDQ_WFE_OPTION (CMDQ_WFE_WAIT | CMDQ_WFE_WAIT_VALUE)
3332

3433
/** cmdq event maximum */
3534
#define CMDQ_MAX_EVENT 0x3ff
@@ -60,6 +59,9 @@ enum cmdq_code {
6059
CMDQ_CODE_JUMP = 0x10,
6160
CMDQ_CODE_WFE = 0x20,
6261
CMDQ_CODE_EOC = 0x40,
62+
CMDQ_CODE_READ_S = 0x80,
63+
CMDQ_CODE_WRITE_S = 0x90,
64+
CMDQ_CODE_WRITE_S_MASK = 0x91,
6365
CMDQ_CODE_LOGIC = 0xa0,
6466
};
6567

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

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <linux/timer.h>
1313

1414
#define CMDQ_NO_TIMEOUT 0xffffffffu
15+
#define CMDQ_ADDR_HIGH(addr) ((u32)(((addr) >> 16) & GENMASK(31, 0)))
16+
#define CMDQ_ADDR_LOW(addr) ((u16)(addr) | BIT(1))
1517

1618
struct cmdq_pkt;
1719

@@ -102,14 +104,90 @@ int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value);
102104
int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
103105
u16 offset, u32 value, u32 mask);
104106

107+
/*
108+
* cmdq_pkt_read_s() - append read_s command to the CMDQ packet
109+
* @pkt: the CMDQ packet
110+
* @high_addr_reg_idx: internal register ID which contains high address of pa
111+
* @addr_low: low address of pa
112+
* @reg_idx: the CMDQ internal register ID to cache read data
113+
*
114+
* Return: 0 for success; else the error code is returned
115+
*/
116+
int cmdq_pkt_read_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx, u16 addr_low,
117+
u16 reg_idx);
118+
119+
/**
120+
* cmdq_pkt_write_s() - append write_s command to the CMDQ packet
121+
* @pkt: the CMDQ packet
122+
* @high_addr_reg_idx: internal register ID which contains high address of pa
123+
* @addr_low: low address of pa
124+
* @src_reg_idx: the CMDQ internal register ID which cache source value
125+
*
126+
* Return: 0 for success; else the error code is returned
127+
*
128+
* Support write value to physical address without subsys. Use CMDQ_ADDR_HIGH()
129+
* to get high address and call cmdq_pkt_assign() to assign value into internal
130+
* reg. Also use CMDQ_ADDR_LOW() to get low address for addr_low parameter when
131+
* call to this function.
132+
*/
133+
int cmdq_pkt_write_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
134+
u16 addr_low, u16 src_reg_idx);
135+
136+
/**
137+
* cmdq_pkt_write_s_mask() - append write_s with mask command to the CMDQ packet
138+
* @pkt: the CMDQ packet
139+
* @high_addr_reg_idx: internal register ID which contains high address of pa
140+
* @addr_low: low address of pa
141+
* @src_reg_idx: the CMDQ internal register ID which cache source value
142+
* @mask: the specified target address mask, use U32_MAX if no need
143+
*
144+
* Return: 0 for success; else the error code is returned
145+
*
146+
* Support write value to physical address without subsys. Use CMDQ_ADDR_HIGH()
147+
* to get high address and call cmdq_pkt_assign() to assign value into internal
148+
* reg. Also use CMDQ_ADDR_LOW() to get low address for addr_low parameter when
149+
* call to this function.
150+
*/
151+
int cmdq_pkt_write_s_mask(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
152+
u16 addr_low, u16 src_reg_idx, u32 mask);
153+
154+
/**
155+
* cmdq_pkt_write_s_value() - append write_s command to the CMDQ packet which
156+
* write value to a physical address
157+
* @pkt: the CMDQ packet
158+
* @high_addr_reg_idx: internal register ID which contains high address of pa
159+
* @addr_low: low address of pa
160+
* @value: the specified target value
161+
*
162+
* Return: 0 for success; else the error code is returned
163+
*/
164+
int cmdq_pkt_write_s_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
165+
u16 addr_low, u32 value);
166+
167+
/**
168+
* cmdq_pkt_write_s_mask_value() - append write_s command with mask to the CMDQ
169+
* packet which write value to a physical
170+
* address
171+
* @pkt: the CMDQ packet
172+
* @high_addr_reg_idx: internal register ID which contains high address of pa
173+
* @addr_low: low address of pa
174+
* @value: the specified target value
175+
* @mask: the specified target mask
176+
*
177+
* Return: 0 for success; else the error code is returned
178+
*/
179+
int cmdq_pkt_write_s_mask_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
180+
u16 addr_low, u32 value, u32 mask);
181+
105182
/**
106183
* cmdq_pkt_wfe() - append wait for event command to the CMDQ packet
107184
* @pkt: the CMDQ packet
108-
* @event: the desired event type to "wait and CLEAR"
185+
* @event: the desired event type to wait
186+
* @clear: clear event or not after event arrive
109187
*
110188
* Return: 0 for success; else the error code is returned
111189
*/
112-
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event);
190+
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event, bool clear);
113191

114192
/**
115193
* cmdq_pkt_clear_event() - append clear event command to the CMDQ packet
@@ -175,6 +253,17 @@ int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
175253
*/
176254
int cmdq_pkt_assign(struct cmdq_pkt *pkt, u16 reg_idx, u32 value);
177255

256+
/**
257+
* cmdq_pkt_jump() - Append jump command to the CMDQ packet, ask GCE
258+
* to execute an instruction that change current thread PC to
259+
* a physical address which should contains more instruction.
260+
* @pkt: the CMDQ packet
261+
* @addr: physical address of target instruction buffer
262+
*
263+
* Return: 0 for success; else the error code is returned
264+
*/
265+
int cmdq_pkt_jump(struct cmdq_pkt *pkt, dma_addr_t addr);
266+
178267
/**
179268
* cmdq_pkt_finalize() - Append EOC and jump command to pkt.
180269
* @pkt: the CMDQ packet

0 commit comments

Comments
 (0)