Skip to content

Commit 1c18748

Browse files
Jason-JH LinAngeloGioacchino Del Regno
authored andcommitted
mailbox: mtk-cmdq: Add mminfra_offset configuration for DRAM transaction
The GCE in MT8196 is placed in MMINFRA and requires all addresses in GCE instructions for DRAM transactions to be IOVA. Due to MMIO, if the GCE needs to access a hardware register at 0x1000_0000, but the SMMU is also mapping a DRAM block at 0x1000_0000, the MMINFRA will not know whether to write to the hardware register or the DRAM. To solve this, MMINFRA treats addresses greater than 2G as data paths and those less than 2G as config paths because the DRAM start address is currently at 2G (0x8000_0000). On the data path, MMINFRA remaps DRAM addresses by subtracting 2G, allowing SMMU to map DRAM addresses less than 2G. For example, if the DRAM start address 0x8000_0000 is mapped to IOVA=0x0, when GCE accesses IOVA=0x0, it must add a 2G offset to the address in the GCE instruction. MMINFRA will then see it as a data path (IOVA >= 2G) and subtract 2G, allowing GCE to access IOVA=0x0. Since the MMINFRA remap subtracting 2G is done in hardware and cannot be configured by software, the address of DRAM in GCE instruction must always add 2G to ensure proper access. After that, the shift functions do more than just shift addresses, so the APIs were renamed to cmdq_convert_gce_addr() and cmdq_revert_gce_addr(). This 2G adjustment is referred to as mminfra_offset in the CMDQ driver. CMDQ helper can get the mminfra_offset from the cmdq_mbox_priv of cmdq_pkt and add the mminfra_offset to the DRAM address in GCE instructions. Signed-off-by: Jason-JH Lin <jason-jh.lin@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Acked-by: Jassi Brar <jassisinghbrar@gmail.com> Acked-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
1 parent 7005b7c commit 1c18748

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

drivers/mailbox/mtk-cmdq-mailbox.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct cmdq {
9494
struct gce_plat {
9595
u32 thread_nr;
9696
u8 shift;
97+
dma_addr_t mminfra_offset;
9798
bool control_by_sw;
9899
bool sw_ddr_en;
99100
bool gce_vm;
@@ -103,20 +104,21 @@ struct gce_plat {
103104
static inline u32 cmdq_convert_gce_addr(dma_addr_t addr, const struct gce_plat *pdata)
104105
{
105106
/* Convert DMA addr (PA or IOVA) to GCE readable addr */
106-
return addr >> pdata->shift;
107+
return (addr + pdata->mminfra_offset) >> pdata->shift;
107108
}
108109

109110
static inline dma_addr_t cmdq_revert_gce_addr(u32 addr, const struct gce_plat *pdata)
110111
{
111112
/* Revert GCE readable addr to DMA addr (PA or IOVA) */
112-
return (dma_addr_t)addr << pdata->shift;
113+
return ((dma_addr_t)addr << pdata->shift) - pdata->mminfra_offset;
113114
}
114115

115116
void cmdq_get_mbox_priv(struct mbox_chan *chan, struct cmdq_mbox_priv *priv)
116117
{
117118
struct cmdq *cmdq = container_of(chan->mbox, struct cmdq, mbox);
118119

119120
priv->shift_pa = cmdq->pdata->shift;
121+
priv->mminfra_offset = cmdq->pdata->mminfra_offset;
120122
}
121123
EXPORT_SYMBOL(cmdq_get_mbox_priv);
122124

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct cmdq_cb_data {
7272

7373
struct cmdq_mbox_priv {
7474
u8 shift_pa;
75+
dma_addr_t mminfra_offset;
7576
};
7677

7778
struct cmdq_pkt {

0 commit comments

Comments
 (0)