[PATCH 3/3] mailbox: sophgo: add mailbox driver for cv18x SoCs
Yuntao Dai
d1581209858 at live.com
Sun Jul 14 09:09:57 PDT 2024
Hi Junhui,
On Tue, Jul 2, 2024 at 11:08 PM, Junhui Liu <liujh2818 at gmail.com> wrote:
> Hi Yuntao,
>
> On 2024/6/18 23:12, Yuntao Dai wrote:
>> Add mailbox controller driver for cv18x SoCs, tested on mailbox-test
>> client.
>>
>> Signed-off-by: Yuntao Dai <d1581209858 at live.com>
>> ---
>> drivers/mailbox/Kconfig | 11 ++
>> drivers/mailbox/Makefile | 2 +
>> drivers/mailbox/cv1800b-mailbox.c | 181
>> ++++++++++++++++++++++++++++++
>> 3 files changed, 194 insertions(+)
>> create mode 100644 drivers/mailbox/cv1800b-mailbox.c
>>
>> diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
>> index 3b8842c4a..4e5593861 100644
>> --- a/drivers/mailbox/Kconfig
>> +++ b/drivers/mailbox/Kconfig
>> @@ -286,4 +286,15 @@ config QCOM_IPCC
>> acts as an interrupt controller for receiving interrupts from
>> clients.
>> Say Y here if you want to build this driver.
>> +config CV1800B_MBOX
>> + tristate "cv1800b mailbox"
>> + depends on OF
>> + depends on ARCH_SOPHGO || COMPILE_TEST
>> + help
>> + Mailbox driver implementation for Sophgo cv180x SoCs. This driver
>> + can be used to send message between different processors in SoC.
>> Any
>> + processer can write data in a channel, and set co-responding
>> register
>> + to raise interrupt to notice another processor, and it is
>> allowed to
>> + send data to itself.
>> +
>> endif
>> diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
>> index 5cf2f54de..71f0f746e 100644
>> --- a/drivers/mailbox/Makefile
>> +++ b/drivers/mailbox/Makefile
>> @@ -62,3 +62,5 @@ obj-$(CONFIG_SUN6I_MSGBOX) += sun6i-msgbox.o
>> obj-$(CONFIG_SPRD_MBOX) += sprd-mailbox.o
>> better
>> obj-$(CONFIG_QCOM_IPCC) += qcom-ipcc.o
>> +
>> +obj-$(CONFIG_CV1800B_MBOX) += cv1800b-mailbox.o
>> \ No newline at end of file
>> diff --git a/drivers/mailbox/cv1800b-mailbox.c
>> b/drivers/mailbox/cv1800b-mailbox.c
>> new file mode 100644
>> index 000000000..8ef2a5492
>> --- /dev/null
>> +++ b/drivers/mailbox/cv1800b-mailbox.c
>> @@ -0,0 +1,181 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +
>> +#include <linux/device.h>
>> +#include <linux/err.h>
>> +#include <linux/interrupt.h>
>> +#include <linux/io.h>
>> +#include <linux/kfifo.h>
>> +#include <linux/mailbox_controller.h>
>> +#include <linux/mailbox_client.h>
>> +#include <linux/module.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/slab.h>
>> +
>> +#define MAILBOX_MAX_CHAN 0x0008
>> +#define MAILBOX_DONE_OFFSET 0x0002
>> +#define MAILBOX_CONTEXT_SIZE 0x0040
>> +#define MAILBOX_CONTEXT_OFFSET 0x0400
>> +
>> +#define MBOX_EN_REG(cpu) (cpu << 2)
>> +#define MBOX_DONE_REG(cpu) ((cpu << 2) + MAILBOX_DONE_OFFSET)
>> +
>> +#define MBOX_SET_CLR_REG(cpu) (0x10 + (cpu << 4))
>> +#define MBOX_SET_INT_REG(cpu) (0x18 + (cpu << 4))
>> +
>> +#define MBOX_SET_REG 0x60
>> +
>> +struct cv1800b_mbox {
>> + struct mbox_controller mbox;
>> + struct mbox_chan chans[MAILBOX_MAX_CHAN];
>> + u64 *content[MAILBOX_MAX_CHAN];
>> + void __iomem *mbox_base;
>> + int sendto;
>> + int recvid;
>> +};
>> +
>> +static irqreturn_t cv1800b_mbox_isr(int irq, void *dev_id)
>> +{
>> + struct cv1800b_mbox *mbox = (struct cv1800b_mbox *)dev_id;
>> + size_t i;
>> +
>> + for (i = 0; i < MAILBOX_MAX_CHAN; i++) {
>> + if (mbox->content[i]) {
>> + mbox_chan_received_data(&mbox->chans[i],
>> + mbox->content[i]);
> I tested this driver but met "NULL pointer dereference" Oops here
> when I sent message from the c906l core without binding clients.
>
> I think maybe it's better to add a check here, like:
>
> struct mbox_chan *chan = &mbox->chans[i];
> if (chan->cl) {
> mbox_chan_received_data(chan, mbox->content[i]);
> }
>
> Best,
> Junhui Liu
Thanks for your addvice, I will take it. On the other side, I am not
sure weather mailbox driver can work without register mailbox client
correctly?
Best regards,
Yuntao
More information about the linux-riscv
mailing list