[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c87af05e-9017-4806-88b1-7aa65f2b7070@collabora.com>
Date: Thu, 15 Feb 2024 11:40:35 +0100
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>
To: Chun-Kuang Hu <chunkuang.hu@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
linux-arm-kernel@...ts.infradead.org, linux-mediatek@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-media@...r.kernel.org
Subject: Re: [PATCH 1/9] soc: mediatek: cmdq: Remove unused helper funciton
Il 15/02/24 01:49, Chun-Kuang Hu ha scritto:
> cmdq_pkt_create(), cmdq_pkt_destroy(), and cmdq_pkt_flush_async()
> are not used by all client drivers (MediaTek drm driver and
> MediaTek mdp3 driver),
>
Hello CK,
We can technically force the hand to say that this is true - but only because
these two functions are copy-pasted in both mediatek-drm and MDP3 drivers with
no meaningful changes, as in, the only change is that `pkt` is supposed to be
preallocated in both of the variants, while the one in mtk-cmdq-helper allocates
it on its own.
Code duplication is something that we want to avoid, not something that we want
to embrace: removing those functions from cmdq-helper with the plan to keep
duplicating them in each MediaTek driver that uses CMDQ packets is plain wrong.
This - especially because I'm sure that we will see yet another copy-paste of
those two functions in a future ISP driver, bringing the duplication count to
3 (or actually, 3 by 2 functions = 6 times).
On the other hand, removing the cmdq_pkt_flush_async() function is something
that I *do* support, as it's only doing two simple calls that are not even
specific to cmdq, but more like "generic stuff".
In short, as it is right now, this is a NACK - but if you change this commit to
remove only cmdq_pkt_flush_async() I would agree.
The right thing to do is to remove the duplicated functions:
- mtk_drm_cmdq_pkt_create()
- mtk_drm_cmdq_pkt_destroy()
- mdp_cmdq_pkt_create()
- mdp_cmdq_pkt_destroy()
..and migrate both drivers to use the common cmdq helper code instea, but that's
something that can come later.
For now, you can simply perform the ->cl removal on all duplicated functions, then
we can migrate them all to the common helper, removing duplication all along.
Regards,
Angelo
> Signed-off-by: Chun-Kuang Hu <chunkuang.hu@...nel.org>
> ---
> drivers/soc/mediatek/mtk-cmdq-helper.c | 59 --------------------------
> include/linux/soc/mediatek/mtk-cmdq.h | 40 -----------------
> 2 files changed, 99 deletions(-)
>
> diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c
> index b0cd071c4719..67e17974d1e6 100644
> --- a/drivers/soc/mediatek/mtk-cmdq-helper.c
> +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c
> @@ -105,50 +105,6 @@ void cmdq_mbox_destroy(struct cmdq_client *client)
> }
> EXPORT_SYMBOL(cmdq_mbox_destroy);
>
> -struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size)
> -{
> - struct cmdq_pkt *pkt;
> - struct device *dev;
> - dma_addr_t dma_addr;
> -
> - pkt = kzalloc(sizeof(*pkt), GFP_KERNEL);
> - if (!pkt)
> - return ERR_PTR(-ENOMEM);
> - pkt->va_base = kzalloc(size, GFP_KERNEL);
> - if (!pkt->va_base) {
> - kfree(pkt);
> - return ERR_PTR(-ENOMEM);
> - }
> - pkt->buf_size = size;
> - pkt->cl = (void *)client;
> -
> - dev = client->chan->mbox->dev;
> - dma_addr = dma_map_single(dev, pkt->va_base, pkt->buf_size,
> - DMA_TO_DEVICE);
> - if (dma_mapping_error(dev, dma_addr)) {
> - dev_err(dev, "dma map failed, size=%u\n", (u32)(u64)size);
> - kfree(pkt->va_base);
> - kfree(pkt);
> - return ERR_PTR(-ENOMEM);
> - }
> -
> - pkt->pa_base = dma_addr;
> -
> - return pkt;
> -}
> -EXPORT_SYMBOL(cmdq_pkt_create);
> -
> -void cmdq_pkt_destroy(struct cmdq_pkt *pkt)
> -{
> - struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
> -
> - dma_unmap_single(client->chan->mbox->dev, pkt->pa_base, pkt->buf_size,
> - DMA_TO_DEVICE);
> - kfree(pkt->va_base);
> - kfree(pkt);
> -}
> -EXPORT_SYMBOL(cmdq_pkt_destroy);
> -
> static int cmdq_pkt_append_command(struct cmdq_pkt *pkt,
> struct cmdq_instruction inst)
> {
> @@ -426,19 +382,4 @@ int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
> }
> EXPORT_SYMBOL(cmdq_pkt_finalize);
>
> -int cmdq_pkt_flush_async(struct cmdq_pkt *pkt)
> -{
> - int err;
> - struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
> -
> - err = mbox_send_message(client->chan, pkt);
> - if (err < 0)
> - return err;
> - /* We can send next packet immediately, so just call txdone. */
> - mbox_client_txdone(client->chan, 0);
> -
> - return 0;
> -}
> -EXPORT_SYMBOL(cmdq_pkt_flush_async);
> -
> MODULE_LICENSE("GPL v2");
> diff --git a/include/linux/soc/mediatek/mtk-cmdq.h b/include/linux/soc/mediatek/mtk-cmdq.h
> index 649955d2cf5c..6c42d817d368 100644
> --- a/include/linux/soc/mediatek/mtk-cmdq.h
> +++ b/include/linux/soc/mediatek/mtk-cmdq.h
> @@ -59,21 +59,6 @@ struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
> */
> void cmdq_mbox_destroy(struct cmdq_client *client);
>
> -/**
> - * cmdq_pkt_create() - create a CMDQ packet
> - * @client: the CMDQ mailbox client
> - * @size: required CMDQ buffer size
> - *
> - * Return: CMDQ packet pointer
> - */
> -struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size);
> -
> -/**
> - * cmdq_pkt_destroy() - destroy the CMDQ packet
> - * @pkt: the CMDQ packet
> - */
> -void cmdq_pkt_destroy(struct cmdq_pkt *pkt);
> -
> /**
> * cmdq_pkt_write() - append write command to the CMDQ packet
> * @pkt: the CMDQ packet
> @@ -266,19 +251,6 @@ int cmdq_pkt_jump(struct cmdq_pkt *pkt, dma_addr_t addr);
> */
> int cmdq_pkt_finalize(struct cmdq_pkt *pkt);
>
> -/**
> - * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
> - * packet and call back at the end of done packet
> - * @pkt: the CMDQ packet
> - *
> - * Return: 0 for success; else the error code is returned
> - *
> - * Trigger CMDQ to asynchronously execute the CMDQ packet and call back
> - * at the end of done packet. Note that this is an ASYNC function. When the
> - * function returned, it may or may not be finished.
> - */
> -int cmdq_pkt_flush_async(struct cmdq_pkt *pkt);
> -
> #else /* IS_ENABLED(CONFIG_MTK_CMDQ) */
>
> static inline int cmdq_dev_get_client_reg(struct device *dev,
> @@ -294,13 +266,6 @@ static inline struct cmdq_client *cmdq_mbox_create(struct device *dev, int index
>
> static inline void cmdq_mbox_destroy(struct cmdq_client *client) { }
>
> -static inline struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size)
> -{
> - return ERR_PTR(-EINVAL);
> -}
> -
> -static inline void cmdq_pkt_destroy(struct cmdq_pkt *pkt) { }
> -
> static inline int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value)
> {
> return -ENOENT;
> @@ -384,11 +349,6 @@ static inline int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
> return -EINVAL;
> }
>
> -static inline int cmdq_pkt_flush_async(struct cmdq_pkt *pkt)
> -{
> - return -EINVAL;
> -}
> -
> #endif /* IS_ENABLED(CONFIG_MTK_CMDQ) */
>
> #endif /* __MTK_CMDQ_H__ */
Powered by blists - more mailing lists