firmware: mtk: add adsp ipc protocol for SOF
v7 cover firmware: mtk: add adsp ipc protocol for SOF
This patch provides mediatek adsp ipc support for SOF. ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.
This patch was tested and confirmed to with SOF fw on MT8195 cherry board.
Based on matthias.bgg/linux.git, v5.18-next/soc changes since v6:
- rebase to matthias.bgg/linux.git, v5.18-next/soc
- Prefer "GPL" over "GPL v2" for MODULE_LICENSE
changes since v5:
- fix WARNING: modpost: missing MODULE_LICENSE() in drivers/mailbox /mtk-adsp-mailbox.o. Add MODULE_LICENSE in the last line.
- Due to WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 in checkpatch, we don't remove SPDX-License in line 1.
changes since v4:
- add error message for wrong mbox chan
changes since v3:
- rebase on v5.16-rc8
- update reviewers
changes since v2:
- add out tag for two memory free phases
changes since v1:
- add comments for mtk_adsp_ipc_send and mtk_adsp_ipc_recv
- remove useless MODULE_LICENSE
- change label name to out_free
Allen-KH Cheng (1):
firmware: mediatek: add adsp ipc protocol interface
drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/mediatek/Kconfig | 9 + drivers/firmware/mediatek/Makefile | 2 + drivers/firmware/mediatek/mtk-adsp-ipc.c | 161 ++++++++++++++++++ .../linux/firmware/mediatek/mtk-adsp-ipc.h | 65 +++++++ 6 files changed, 239 insertions(+) create mode 100644 drivers/firmware/mediatek/Kconfig create mode 100644 drivers/firmware/mediatek/Makefile create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
Signature · 1 line
2.18.0
PATCH v7 1/1 firmware: mediatek: add adsp ipc protocol interface
From: Allen-KH Cheng <[email protected]>
Some of mediatek processors contain
the Tensilica HiFix DSP for audio processing.
The communication between Host CPU and DSP firmware is taking place using a shared memory area for message passing.
ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.
We use two mbox channels to implement a request-reply protocol.
--- drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/mediatek/Kconfig | 9 + drivers/firmware/mediatek/Makefile | 2 + drivers/firmware/mediatek/mtk-adsp-ipc.c | 161 ++++++++++++++++++ .../linux/firmware/mediatek/mtk-adsp-ipc.h | 65 +++++++ 6 files changed, 239 insertions(+) create mode 100644 drivers/firmware/mediatek/Kconfig create mode 100644 drivers/firmware/mediatek/Makefile create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
drivers/firmware/Kconfig +1 -0
@@ -300,6 +300,7 @@ source "drivers/firmware/cirrus/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" source "drivers/firmware/imx/Kconfig" +source "drivers/firmware/mediatek/Kconfig" source "drivers/firmware/meson/Kconfig" source "drivers/firmware/psci/Kconfig" source "drivers/firmware/smccc/Kconfig"
drivers/firmware/Makefile +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ obj-$(CONFIG_EFI) += efi/ obj-$(CONFIG_UEFI_CPER) += efi/ obj-y += imx/ +obj-y += mediatek/ obj-y += psci/ obj-y += smccc/ obj-y += tegra/
drivers/firmware/mediatek/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MTK_ADSP_IPC + tristate "MTK ADSP IPC Protocol driver" + depends on MTK_ADSP_MBOX + help + Say yes here to add support for the MediaTek ADSP IPC + between host AP (Linux) and the firmware running on ADSP. + ADSP exists on some mtk processors. + Client might use shared memory to exchange information with ADSP side.
drivers/firmware/mediatek/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_MTK_ADSP_IPC) += mtk-adsp-ipc.o
drivers/firmware/mediatek/mtk-adsp-ipc.c new file +161 -0
161 lines not on this page · raw message
include/linux/firmware/mediatek/mtk-adsp-ipc.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.18.0
Re: [PATCH v7 1/1] firmware: mediatek: add adsp ipc protocol interface
Hi Matthias,
Would you please take a look at it?
Thanks a lot,
Allen
Quoted 332 lines · Allen-KH Cheng
From: Allen-KH Cheng <[email protected]>
Some of mediatek processors contain
the Tensilica HiFix DSP for audio processing.The communication between Host CPU and DSP firmware is taking place using a shared memory area for message passing.
ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.
We use two mbox channels to implement a request-reply protocol.
Signed-off-by Allen-KH Cheng <[email protected]>Reviewed-by Pierre-Louis Bossart <Reviewed-by Curtis Malainey <[email protected]>Reviewed-by Tzung-Bi Shih <[email protected]>Reviewed-by YC Hung <[email protected]>Reviewed-by AngeloGioacchino Del Regno <--- drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/mediatek/Kconfig | 9 + drivers/firmware/mediatek/Makefile | 2 + drivers/firmware/mediatek/mtk-adsp-ipc.c | 161 ++++++++++++++++++ .../linux/firmware/mediatek/mtk-adsp-ipc.h | 65 +++++++ 6 files changed, 239 insertions(+) create mode 100644 drivers/firmware/mediatek/Kconfig create mode 100644 drivers/firmware/mediatek/Makefile create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.hdrivers/firmware/Kconfig +1
-0@@ -300,6 +300,7 @@ source "drivers/firmware/cirrus/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" source "drivers/firmware/imx/Kconfig" +source "drivers/firmware/mediatek/Kconfig" source "drivers/firmware/meson/Kconfig" source "drivers/firmware/psci/Kconfig" source "drivers/firmware/smccc/Kconfig"drivers/firmware/Makefile +1
-0@@ -34,6 +34,7 @@ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ obj-$(CONFIG_EFI) += efi/ obj-$(CONFIG_UEFI_CPER) += efi/ obj-y += imx/ +obj-y += mediatek/ obj-y += psci/ obj-y += smccc/ obj-y += tegra/drivers/firmware/mediatek/Kconfig new file +9
-0@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +config MTK_ADSP_IPC + tristate "MTK ADSP IPC Protocol driver" + depends on MTK_ADSP_MBOX + help + Say yes here to add support for the MediaTek ADSP IPC + between host AP (Linux) and the firmware running on ADSP. + ADSP exists on some mtk processors. + Client might use shared memory to exchange information withADSP side.
drivers/firmware/mediatek/Makefile new file +2
-0@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_MTK_ADSP_IPC) += mtk-adsp-ipc.odrivers/firmware/mediatek/mtk-adsp-ipc.c new file +25
-0@@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 MediaTek Corporation. All rights reserved. +* Author: Allen-KH Cheng <[email protected]> +*/ + +#include <linux/firmware/mediatek/mtk-adsp-ipc.h> +#include <linux/kernel.h> +#include <linux/mailbox_client.h> +#include <linux/module.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +/* +* mtk_adsp_ipc_send - send ipc cmd to MTK ADSP +* +* @ipc: ADSP IPC handle +* @idx: index of the mailbox channel +* @msg: IPC cmd (reply or request) +* +* Returns zero for success from mbox_send_message +* negative value for error +*/ +int mtk_adsp_ipc_send(struct mtk_adsp_ipc *ipc, unsigned int idx,
uint32_tmsg)drivers/firmware/mediatek/mtk-adsp-ipc.c new file +27
-0+{ +struct mtk_adsp_chan *adsp_chan; +int ret; + +if (idx >=MTK_ADSP_MBOX_NUM ) +return -EINVAL ; + + adsp_chan = &ipc->chans[idx]; + ret =mbox_send_message (adsp_chan->ch, &msg); +if (ret <0 ) +return ret; + +/* +* mbox_send_message returns non-negative value on success, +* return zero for success +*/ +return 0 ; +} +EXPORT_SYMBOL (mtk_adsp_ipc_send); + +/* +* mtk_adsp_ipc_recv - recv callback used by MTK ADSP mailbox +* +* @c: mbox client +* @msg: message received +* +* Users of ADSP IPC will need to privde handle_reply and
handle_request
+ * callbacks.
+ */drivers/firmware/mediatek/mtk-adsp-ipc.c new file +3
-0+static void mtk_adsp_ipc_recv (struct mbox_client *c,void *msg) +{ + struct mtk_adsp_chan *chan = container_of(c, struct
mtk_adsp_chan, cl);drivers/firmware/mediatek/mtk-adsp-ipc.c new file +49
-0+struct device *dev = c->dev; + +switch (chan->idx) { +case MTK_ADSP_MBOX_REPLY : + chan->ipc->ops->handle_reply (chan->ipc); +break ; +case MTK_ADSP_MBOX_REQUEST : + chan->ipc->ops->handle_request (chan->ipc); +break ; +default : +dev_err (dev,"wrong mbox chan %d\n" , chan->idx); +break ; + } +} + +static int mtk_adsp_ipc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct mtk_adsp_ipc *adsp_ipc; +struct mtk_adsp_chan *adsp_chan; +struct mbox_client *cl; +char *chan_name; +int ret; +int i, j; + +device_set_of_node_from_dev (&pdev->dev, pdev->dev.parent); + + adsp_ipc =devm_kzalloc (dev,sizeof (*adsp_ipc),GFP_KERNEL ); +if (!adsp_ipc) +return -ENOMEM ; + +for (i =0 ; i <MTK_ADSP_MBOX_NUM ; i++) { + chan_name =kasprintf (GFP_KERNEL ,"mbox%d" , i); +if (!chan_name) { + ret = -ENOMEM ; + goto out; + } + + adsp_chan = &adsp_ipc->chans[i]; + cl = &adsp_chan->cl; + cl->dev = dev->parent; + cl->tx_block = false; + cl->knows_txdone = false; + cl->tx_prepare =NULL ; + cl->rx_callback = mtk_adsp_ipc_recv; + + adsp_chan->ipc = adsp_ipc; + adsp_chan->idx = i; + adsp_chan->ch = mbox_request_channel_byname(cl,
chan_name);drivers/firmware/mediatek/mtk-adsp-ipc.c new file +4
-0+if (IS_ERR (adsp_chan->ch)) { + ret =PTR_ERR (adsp_chan->ch); +if (ret != -EPROBE_DEFER ) + dev_err(dev, "Failed to request mboxchan %d ret %d\n",
drivers/firmware/mediatek/mtk-adsp-ipc.c new file +51
-0+ i, ret); + goto out_free; + } + +dev_dbg (dev,"request mbox chan %s\n" , chan_name); +kfree (chan_name); + } + + adsp_ipc->dev = dev; +dev_set_drvdata (dev, adsp_ipc); +dev_dbg (dev,"MTK ADSP IPC initialized\n" ); + +return 0 ; + +out_free: +kfree (chan_name); +out: +for (j =0 ; j < i; j++) { + adsp_chan = &adsp_ipc->chans[j]; +mbox_free_channel (adsp_chan->ch); + } + +return ret; +} + +static int mtk_adsp_ipc_remove (struct platform_device *pdev) +{ +struct mtk_adsp_ipc *adsp_ipc =dev_get_drvdata (&pdev->dev); +struct mtk_adsp_chan *adsp_chan; +int i; + +for (i =0 ; i <MTK_ADSP_MBOX_NUM ; i++) { + adsp_chan = &adsp_ipc->chans[i]; +mbox_free_channel (adsp_chan->ch); + } + +return 0 ; +} + +static struct platform_driver mtk_adsp_ipc_driver = { + .driver = { + .name ="mtk-adsp-ipc" , + }, + .probe = mtk_adsp_ipc_probe, + .remove = mtk_adsp_ipc_remove, +}; +builtin_platform_driver (mtk_adsp_ipc_driver); + +MODULE_AUTHOR ("Allen-KH Cheng <[email protected]>" ); +MODULE_DESCRIPTION ("MTK ADSP IPC Driver" ); +MODULE_LICENSE ("GPL" );include/linux/firmware/mediatek/mtk-adsp-ipc.h new file +47
-0@@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2022 MediaTek Inc. +*/ + +#ifndef MTK_ADSP_IPC_H +#define MTK_ADSP_IPC_H + +#include <linux/device.h> +#include <linux/types.h> +#include <linux/mailbox_controller.h> +#include <linux/mailbox_client.h> + +#define MTK_ADSP_IPC_REQ 0 +#define MTK_ADSP_IPC_RSP 1 +#define MTK_ADSP_IPC_OP_REQ 0x1 +#define MTK_ADSP_IPC_OP_RSP 0x2 + +enum { +MTK_ADSP_MBOX_REPLY , +MTK_ADSP_MBOX_REQUEST , +MTK_ADSP_MBOX_NUM , +}; + +struct mtk_adsp_ipc ; + +struct mtk_adsp_ipc_ops { +void (*handle_reply)(struct mtk_adsp_ipc *ipc); +void (*handle_request)(struct mtk_adsp_ipc *ipc); +}; + +struct mtk_adsp_chan { +struct mtk_adsp_ipc *ipc; +struct mbox_client cl; +struct mbox_chan *ch; +char *name; +int idx; +}; + +struct mtk_adsp_ipc { +struct mtk_adsp_chan chans[MTK_ADSP_MBOX_NUM ]; +struct device *dev; +struct mtk_adsp_ipc_ops *ops; +void *private_data; +}; + +static inline void mtk_adsp_ipc_set_data(struct mtk_adsp_ipc *ipc,void *data)
include/linux/firmware/mediatek/mtk-adsp-ipc.h new file +16
-0+{ +if (!ipc) +return ; + + ipc->private_data = data; +} + +static inline void *mtk_adsp_ipc_get_data (struct mtk_adsp_ipc *ipc) +{ +if (!ipc) +return NULL ; + +return ipc->private_data; +} + +int mtk_adsp_ipc_send(struct mtk_adsp_ipc *ipc, unsigned int idx,
uint32_top);include/linux/firmware/mediatek/mtk-adsp-ipc.h new file +2
-0+ +#endif /* MTK_ADSP_IPC_H */
AngeloGioacchino Del Regno
maintainerRe: [PATCH v7 1/1] firmware: mediatek: add adsp ipc protocol interface
In reply to Allen-KH ChengIl 07/04/22 15:03, Allen-KH Cheng ha scritto:
Quoted 27 lines
From: Allen-KH Cheng <[email protected]>
Some of mediatek processors contain
the Tensilica HiFix DSP for audio processing.The communication between Host CPU and DSP firmware is taking place using a shared memory area for message passing.
ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.
We use two mbox channels to implement a request-reply protocol.
Signed-off-by Allen-KH Cheng <[email protected]>Reviewed-by Pierre-Louis Bossart <[email protected]>Reviewed-by Curtis Malainey <[email protected]>Reviewed-by Tzung-Bi Shih <[email protected]>Reviewed-by YC Hung <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>--- drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/mediatek/Kconfig | 9 + drivers/firmware/mediatek/Makefile | 2 + drivers/firmware/mediatek/mtk-adsp-ipc.c | 161 ++++++++++++++++++ .../linux/firmware/mediatek/mtk-adsp-ipc.h | 65 +++++++ 6 files changed, 239 insertions(+)
Quoted 5 lines
create mode 100644
drivers/firmware/mediatek/Kconfigcreate mode 100644drivers/firmware/mediatek/Makefilecreate mode 100644drivers/firmware/mediatek/mtk-adsp-ipc.ccreate mode 100644include/linux/firmware/mediatek/mtk-adsp-ipc.h
Gentle ping for this one, as it's getting stale... and it's ready.
To add context, this driver is *really* necessary, as support for it is added in the MT8195 ASoC SOF driver as a platform device [1], and the necessary memory regions are coming from the mediatek,mt8195-dsp [2] driver.
Cheers,
Angelo
AngeloGioacchino Del Regno
maintainerRe: [PATCH v7 1/1] firmware: mediatek: add adsp ipc protocol interface
Il 25/05/22 12:39, AngeloGioacchino Del Regno ha scritto:
Quoted 40 lines
Il 07/04/22 15:03, Allen-KH Cheng ha scritto:
Quoted 26 lines
From: Allen-KH Cheng <[email protected]>
Some of mediatek processors contain
the Tensilica HiFix DSP for audio processing.The communication between Host CPU and DSP firmware is taking place using a shared memory area for message passing.
ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.
We use two mbox channels to implement a request-reply protocol.
Signed-off-by Allen-KH Cheng <[email protected]>Reviewed-by Pierre-Louis Bossart <[email protected]>Reviewed-by Curtis Malainey <[email protected]>Reviewed-by Tzung-Bi Shih <[email protected]>Reviewed-by YC Hung <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>---
drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/mediatek/Kconfig | 9 + drivers/firmware/mediatek/Makefile | 2 + drivers/firmware/mediatek/mtk-adsp-ipc.c | 161 ++++++++++++++++++ .../linux/firmware/mediatek/mtk-adsp-ipc.h | 65 +++++++Quoted 6 lines
6 files changed, 239 insertions(+)create mode 100644
drivers/firmware/mediatek/Kconfigcreate mode 100644drivers/firmware/mediatek/Makefilecreate mode 100644drivers/firmware/mediatek/mtk-adsp-ipc.ccreate mode 100644include/linux/firmware/mediatek/mtk-adsp-ipc.hGentle ping for this one, as it's getting stale... and it's ready.
To add context, this driver is *really* necessary, as support for it is added in the MT8195 ASoC SOF driver as a platform device [1], and the necessary memory regions are coming from the mediatek,mt8195-dsp [2] driver.
Quoted 8 lines
Cheers,
Angelo
I'm sorry, ignore me, another version of this one was already merged.
Quoted 6 lines · Allen-KH Cheng
This patch provides mediatek adsp ipc support for SOF. ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.
This patch was tested and confirmed to with SOF fw on MT8195 cherry board.
... confirmed to **work** with ...
is probably what you meant to write here.
Quoted 31 lines
Based on matthias.bgg/linux.git, v5.18-next/soc changes since v6:
- rebase to matthias.bgg/linux.git, v5.18-next/soc
- Prefer "GPL" over "GPL v2" forMODULE_LICENSEchanges since v5:
- fix WARNING: modpost: missingMODULE_LICENSE()indrivers/mailbox/mtk-adsp-mailbox.o. AddMODULE_LICENSEin the last line.
- Due to WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 in checkpatch, we don't remove SPDX-License in line 1.changes since v4:
- add error message for wrong mbox chanchanges since v3:
- rebase on v5.16-rc8
- update reviewerschanges since v2:
- add out tag for two memory free phaseschanges since v1:
- add comments formtk_adsp_ipc_sendandmtk_adsp_ipc_recv
- remove uselessMODULE_LICENSE
- change label name toout_freeAllen-KH Cheng (1):
firmware: mediatek: add adsp ipc protocol interface
Quoted 15 lines
drivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/mediatek/Kconfig | 9 + drivers/firmware/mediatek/Makefile | 2 + drivers/firmware/mediatek/mtk-adsp-ipc.c | 161 ++++++++++++++++++ .../linux/firmware/mediatek/mtk-adsp-ipc.h | 65 +++++++ 6 files changed, 239 insertions(+) create mode 100644 drivers/firmware/mediatek/Kconfig create mode 100644 drivers/firmware/mediatek/Makefile create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.hSignature · 1 line
2.18.0
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Hi Daniel,
Quoted 5 lines · Daniel Golle
Quoted 4 lines · Allen-KH Cheng
This patch provides mediatek adsp ipc support for SOF. ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.
Quoted 7 lines
Quoted 2 lines
This patch was tested and confirmed to with SOF fw on MT8195 cherry board.
... confirmed to **work** with ...
is probably what you meant to write here.
Yes, thanks for your reminder.
It appears that for some reason I forgot to add this part.
We had tested ADSP IPC protocol with SOF in
github.com/thesofproject/sof/tree/mt8195/v0.4.
The other mailbox control is patchwork.kernel.org/patch/12728222/
Thanks,
Allen
Quoted 47 lines
Quoted 47 lines
Based on matthias.bgg/linux.git, v5.18-next/soc changes since v6:
- rebase to matthias.bgg/linux.git, v5.18-next/soc
- Prefer "GPL" over "GPL v2" forMODULE_LICENSEchanges since v5:
- fix WARNING: modpost: missingMODULE_LICENSE()indrivers/mailbox/mtk-adsp-mailbox.o. AddMODULE_LICENSEin the last line.
- Due to WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 in checkpatch, we don't remove SPDX-License in line 1.changes since v4:
- add error message for wrong mbox chanchanges since v3:
- rebase on v5.16-rc8
- update reviewerschanges since v2:
- add out tag for two memory free phaseschanges since v1:
- add comments formtk_adsp_ipc_sendandmtk_adsp_ipc_recv
- remove uselessMODULE_LICENSE
- change label name toout_freeAllen-KH Cheng (1):
firmware: mediatek: add adsp ipc protocol interfacedrivers/firmware/Kconfig | 1 + drivers/firmware/Makefile | 1 + drivers/firmware/mediatek/Kconfig | 9 + drivers/firmware/mediatek/Makefile | 2 + drivers/firmware/mediatek/mtk-adsp-ipc.c | 161 ++++++++++++++++++ .../linux/firmware/mediatek/mtk-adsp-ipc.h | 65 +++++++ 6 files changed, 239 insertions(+) create mode 100644 drivers/firmware/mediatek/Kconfig create mode 100644 drivers/firmware/mediatek/Makefile create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.hSignature · 1 line
2.18.0