Commit b81b2d55 authored by Chun-Kuang Hu's avatar Chun-Kuang Hu Committed by AngeloGioacchino Del Regno

soc: mediatek: cmdq: Refine cmdq_pkt_create() and cmdq_pkt_destroy()

cmdq_pkt_create() and cmdq_pkt_destroy() is not suitable for
client drivers so each client driver has implement its own
function. This refinement would pass struct cmdq_pkt pointer into
cmdq_pkt_create(). In addition, client driver has the struct
cmdq_client information, so it's not necessary to store this
information in struct cmdq_pkt. After this refinement, client
drivers could use these helper funciton instead of implementing
its own version.
Signed-off-by: default avatarChun-Kuang Hu <chunkuang.hu@kernel.org>
Link: https://lore.kernel.org/r/20240222154120.16959-8-chunkuang.hu@kernel.orgSigned-off-by: default avatarAngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
parent 9935af96
...@@ -106,22 +106,16 @@ void cmdq_mbox_destroy(struct cmdq_client *client) ...@@ -106,22 +106,16 @@ void cmdq_mbox_destroy(struct cmdq_client *client)
} }
EXPORT_SYMBOL(cmdq_mbox_destroy); EXPORT_SYMBOL(cmdq_mbox_destroy);
struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size) int cmdq_pkt_create(struct cmdq_client *client, struct cmdq_pkt *pkt, size_t size)
{ {
struct cmdq_pkt *pkt;
struct device *dev; struct device *dev;
dma_addr_t dma_addr; dma_addr_t dma_addr;
pkt = kzalloc(sizeof(*pkt), GFP_KERNEL);
if (!pkt)
return ERR_PTR(-ENOMEM);
pkt->va_base = kzalloc(size, GFP_KERNEL); pkt->va_base = kzalloc(size, GFP_KERNEL);
if (!pkt->va_base) { if (!pkt->va_base)
kfree(pkt); return -ENOMEM;
return ERR_PTR(-ENOMEM);
}
pkt->buf_size = size; pkt->buf_size = size;
pkt->cl = (void *)client;
dev = client->chan->mbox->dev; dev = client->chan->mbox->dev;
dma_addr = dma_map_single(dev, pkt->va_base, pkt->buf_size, dma_addr = dma_map_single(dev, pkt->va_base, pkt->buf_size,
...@@ -129,24 +123,20 @@ struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size) ...@@ -129,24 +123,20 @@ struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size)
if (dma_mapping_error(dev, dma_addr)) { if (dma_mapping_error(dev, dma_addr)) {
dev_err(dev, "dma map failed, size=%u\n", (u32)(u64)size); dev_err(dev, "dma map failed, size=%u\n", (u32)(u64)size);
kfree(pkt->va_base); kfree(pkt->va_base);
kfree(pkt); return -ENOMEM;
return ERR_PTR(-ENOMEM);
} }
pkt->pa_base = dma_addr; pkt->pa_base = dma_addr;
return pkt; return 0;
} }
EXPORT_SYMBOL(cmdq_pkt_create); EXPORT_SYMBOL(cmdq_pkt_create);
void cmdq_pkt_destroy(struct cmdq_pkt *pkt) void cmdq_pkt_destroy(struct cmdq_client *client, 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_unmap_single(client->chan->mbox->dev, pkt->pa_base, pkt->buf_size,
DMA_TO_DEVICE); DMA_TO_DEVICE);
kfree(pkt->va_base); kfree(pkt->va_base);
kfree(pkt);
} }
EXPORT_SYMBOL(cmdq_pkt_destroy); EXPORT_SYMBOL(cmdq_pkt_destroy);
......
...@@ -62,17 +62,19 @@ void cmdq_mbox_destroy(struct cmdq_client *client); ...@@ -62,17 +62,19 @@ void cmdq_mbox_destroy(struct cmdq_client *client);
/** /**
* cmdq_pkt_create() - create a CMDQ packet * cmdq_pkt_create() - create a CMDQ packet
* @client: the CMDQ mailbox client * @client: the CMDQ mailbox client
* @pkt: the CMDQ packet
* @size: required CMDQ buffer size * @size: required CMDQ buffer size
* *
* Return: CMDQ packet pointer * Return: 0 for success; else the error code is returned
*/ */
struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size); int cmdq_pkt_create(struct cmdq_client *client, struct cmdq_pkt *pkt, size_t size);
/** /**
* cmdq_pkt_destroy() - destroy the CMDQ packet * cmdq_pkt_destroy() - destroy the CMDQ packet
* @client: the CMDQ mailbox client
* @pkt: the CMDQ packet * @pkt: the CMDQ packet
*/ */
void cmdq_pkt_destroy(struct cmdq_pkt *pkt); void cmdq_pkt_destroy(struct cmdq_client *client, struct cmdq_pkt *pkt);
/** /**
* cmdq_pkt_write() - append write command to the CMDQ packet * cmdq_pkt_write() - append write command to the CMDQ packet
...@@ -318,12 +320,12 @@ static inline struct cmdq_client *cmdq_mbox_create(struct device *dev, int index ...@@ -318,12 +320,12 @@ 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 void cmdq_mbox_destroy(struct cmdq_client *client) { }
static inline struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size) static inline int cmdq_pkt_create(struct cmdq_client *client, struct cmdq_pkt *pkt, size_t size)
{ {
return ERR_PTR(-EINVAL); return -EINVAL;
} }
static inline void cmdq_pkt_destroy(struct cmdq_pkt *pkt) { } static inline void cmdq_pkt_destroy(struct cmdq_client *client, struct cmdq_pkt *pkt) { }
static inline int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value) static inline int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment