From: Jason-jh Lin The subsys ID of a GCE client stands for bits [31:16] of its register address, and the write instruction carries the low 16 bits as the offset. cmdq_dev_get_client_reg() parses both from the DT: the subsys ID, and the low 16 bits into client_reg->offset, which clients add their register offset to before they call pkt_write(). A client without a subsys ID in the DT falls back to cmdq_pkt_write_pa() and cmdq_pkt_write_mask_pa(), which need GCEv3. They split the address the same way: pa_base[31:16] is loaded into an SPR, which the WRITE_S instruction uses as the high address, and offset gives the low 16 bits. But the no-subsys path of cmdq_dev_get_client_reg() leaves client_reg->offset at 0, so a client that passes client_reg->offset + reg_offset like it does with a subsys loses the low 16 bits of its base. When the base isn't 64K aligned, as the OVLSYS display components of some SoCs, the packet writes to (base & ~0xffff) + reg_offset and still runs to EOC without error. Set client_reg->offset to the low 16 bits of the base there, which is what the DT holds for a subsys, so that clients can use both paths the same way. Document pa_base and offset of the _pa helpers and of struct cmdq_client_reg accordingly. Fixes: 4bf783d8415c ("soc: mediatek: mtk-cmdq: Add pa_base parsing for hardware without subsys ID support") Cc: stable@vger.kernel.org Signed-off-by: Jason-jh Lin Reviewed-by: Roman Vivchar --- Changes in v3: - Say in the commit message that pa_base[31:16] is loaded into an SPR, which WRITE_S uses as the high address, instead of pa_base replacing the subsys ID, and that the PA write helpers need GCEv3. - Note in the struct cmdq_client_reg kernel-doc that pa_base is only used by the PA write helpers, for a client without a subsys ID. - Make the high/low 16-bit split explicit in the kernel-doc of cmdq_pkt_write_pa() and cmdq_pkt_write_mask_pa(). - Add Reviewed-by from Roman. v2: https://lore.kernel.org/all/20261202151352.1541964-1-jason-jh.lin@mediatek.com/ Changes in v2: - Drop the fold of pa_base + offset in cmdq_pkt_write_pa() and cmdq_pkt_write_mask_pa(), which would break callers that already pass the low 16 bits of the address in offset. Fix the cause in cmdq_dev_get_client_reg() instead, so the title changes as well. - Drop the Reviewed-by tags of v1, as the patch is different. v1: https://lore.kernel.org/all/20261201112523.643035-1-jason-jh.lin@mediatek.com/ drivers/soc/mediatek/mtk-cmdq-helper.c | 7 +++++++ include/linux/soc/mediatek/mtk-cmdq.h | 22 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c index fb82f2a85a21..22f179b37b6b 100644 --- a/drivers/soc/mediatek/mtk-cmdq-helper.c +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #define CMDQ_WRITE_ENABLE_MASK BIT(0) @@ -104,6 +105,12 @@ int cmdq_dev_get_client_reg(struct device *dev, client_reg->pkt_write = cmdq_pkt_write_pa; client_reg->pkt_write_mask = cmdq_pkt_write_mask_pa; + /* + * Keep the low 16 bits of the base, as the DT does for a + * subsys, because the base isn't always 64K aligned. + */ + client_reg->offset = lower_16_bits(res.start); + return 0; } diff --git a/include/linux/soc/mediatek/mtk-cmdq.h b/include/linux/soc/mediatek/mtk-cmdq.h index 03bb85462566..2271425541bb 100644 --- a/include/linux/soc/mediatek/mtk-cmdq.h +++ b/include/linux/soc/mediatek/mtk-cmdq.h @@ -52,6 +52,18 @@ struct cmdq_operand { }; }; +/** + * struct cmdq_client_reg - GCE client register information from the DT + * @subsys: the CMDQ sub system code, CMDQ_SUBSYS_INVALID if there is none + * @pa_base: the physical address of the client registers, only used by + * the PA write helpers for a client without a subsys ID. Only + * bits [31:16] are used, bits [15:0] are in @offset + * @offset: the low 16 bits of @pa_base. Add the register offset to it to + * get the offset argument of @pkt_write and @pkt_write_mask + * @size: the size of the client registers + * @pkt_write: cmdq_pkt_write_subsys() or cmdq_pkt_write_pa() + * @pkt_write_mask: cmdq_pkt_write_mask_subsys() or cmdq_pkt_write_mask_pa() + */ struct cmdq_client_reg { u8 subsys; phys_addr_t pa_base; @@ -139,8 +151,9 @@ int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value); * cmdq_pkt_write_pa() - append write command to the CMDQ packet with pa_base * @pkt: the CMDQ packet * @subsys: unused parameter - * @pa_base: the physical address base of the hardware register - * @offset: register offset from CMDQ sub system + * @pa_base: the physical address of the hardware register, only bits [31:16] + * are used, while bits [15:0] must be supplied in @offset + * @offset: the low 16 bits of the register address * @value: the specified target register value * * Return: 0 for success; else the error code is returned @@ -178,8 +191,9 @@ int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys, * cmdq_pkt_write_mask_pa() - append write command with mask to the CMDQ packet with pa * @pkt: the CMDQ packet * @subsys: unused parameter - * @pa_base: the physical address base of the hardware register - * @offset: register offset from CMDQ sub system + * @pa_base: the physical address of the hardware register, only bits [31:16] + * are used, while bits [15:0] must be supplied in @offset + * @offset: the low 16 bits of the register address * @value: the specified target register value * @mask: the specified target register mask * -- 2.43.0