Skip to contentSkip to conversation

mbox: add polarfire soc system controller mailbox

PATCH Superseded [email protected] 2 participants 2 messages Mar 11, 2021 – Mar 31, 2021

Subsystems (3)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH v4 1/5 mbox: add polarfire soc system controller mailbox

From: Conor Dooley <[email protected]>

This driver adds support for the single mailbox channel of the MSS system controller on the Microchip PolarFire SoC.

---
 drivers/mailbox/Kconfig        |  12 ++
 drivers/mailbox/Makefile       |   2 +
 drivers/mailbox/mailbox-mpfs.c | 277 +++++++++++++++++++++++++++++++++
 include/soc/microchip/mpfs.h   |  57 +++++++
 4 files changed, 348 insertions(+)
 create mode 100644 drivers/mailbox/mailbox-mpfs.c
 create mode 100644 include/soc/microchip/mpfs.h
drivers/mailbox/Kconfig +12 -0
index f4abe3529acd..b37268bd5004 100644
@@ -160,6 +160,18 @@ config MAILBOX_TEST
 	  Test client to help with testing new Controller driver
 	  implementations.
 
+config POLARFIRE_SOC_MAILBOX
+	tristate "PolarFire SoC (MPFS) Mailbox"
+	depends on HAS_IOMEM
+	depends on SOC_MICROCHIP_POLARFIRE || COMPILE_TEST
+	help
+	  This driver adds support for the PolarFire SoC (MPFS) mailbox controller.
+
+	  To compile this driver as a module, choose M here. the
+	  module will be called mailbox-mpfs.
+
+	  If unsure, say N.
+
 config QCOM_APCS_IPC
 	tristate "Qualcomm APCS IPC driver"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/mailbox/Makefile +2 -0
index 7194fa92c787..c2089f04887e 100644
@@ -41,6 +41,8 @@ obj-$(CONFIG_BCM_PDC_MBOX)	+= bcm-pdc-mailbox.o
 
 obj-$(CONFIG_BCM_FLEXRM_MBOX)	+= bcm-flexrm-mailbox.o
 
+obj-$(CONFIG_POLARFIRE_SOC_MAILBOX)	+= mailbox-mpfs.o
+
 obj-$(CONFIG_QCOM_APCS_IPC)	+= qcom-apcs-ipc-mailbox.o
 
 obj-$(CONFIG_TEGRA_HSP_MBOX)	+= tegra-hsp.o
drivers/mailbox/mailbox-mpfs.c new file +277 -0

277 lines not on this page · raw message

include/soc/microchip/mpfs.h new file +57 -0

57 lines not on this page · raw message

Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
maintainer
#1 lore raw
Quoted 56 lines · On Thu, Mar 11, 2021 at 5:34 AM <[email protected]> wrote:
drivers/mailbox/mailbox-mpfs.c new file +50 -0
new file mode 100644
index 000000000000..7aa6c8c87ea0
@@ -0,0 +1,277 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Microchip PolarFire SoC (MPFS) system controller/mailbox controller driver
+ *
+ * Copyright (c) 2020 Microchip Corporation. All rights reserved.
+ *
+ * Author: Conor Dooley <[email protected]>
+ *
+ */
+
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/mailbox_controller.h>
+#include <soc/microchip/mpfs.h>
+
+#define SERVICES_CR_OFFSET             0x50u
+#define SERVICES_SR_OFFSET             0x54u
+#define MAILBOX_REG_OFFSET             0x800u
+#define MSS_SYS_MAILBOX_DATA_OFFSET    0u
+#define SCB_MASK_WIDTH                 16u
+
+/* SCBCTRL service control register */
+
+#define SCB_CTRL_REQ (0)
+#define SCB_CTRL_REQ_MASK BIT(SCB_CTRL_REQ)
+
+#define SCB_CTRL_BUSY (1)
+#define SCB_CTRL_BUSY_MASK BIT(SCB_CTRL_BUSY)
+
+#define SCB_CTRL_ABORT (2)
+#define SCB_CTRL_ABORT_MASK BIT(SCB_CTRL_ABORT)
+
+#define SCB_CTRL_NOTIFY (3)
+#define SCB_CTRL_NOTIFY_MASK BIT(SCB_CTRL_NOTIFY)
+
+#define SCB_CTRL_POS (16)
+#define SCB_CTRL_MASK GENMASK(SCB_CTRL_POS + SCB_MASK_WIDTH, SCB_CTRL_POS)
+
+/* SCBCTRL service status register */
+
+#define SCB_STATUS_REQ (0)
+#define SCB_STATUS_REQ_MASK BIT(SCB_STATUS_REQ)
+
+#define SCB_STATUS_BUSY (1)
+#define SCB_STATUS_BUSY_MASK BIT(SCB_STATUS_BUSY)

drivers/mailbox/mailbox-mpfs.c line 60

Quoted 10 lines
drivers/mailbox/mailbox-mpfs.c new file +10 -0
+
+#define SCB_STATUS_ABORT (2)
+#define SCB_STATUS_ABORT_MASK BIT(SCB_STATUS_ABORT)
+
+#define SCB_STATUS_NOTIFY (3)
+#define SCB_STATUS_NOTIFY_MASK BIT(SCB_STATUS_NOTIFY)
+
+#define SCB_STATUS_POS (16)
+#define SCB_STATUS_MASK GENMASK(SCB_STATUS_POS + SCB_MASK_WIDTH, SCB_STATUS_POS)
+

Please run checkpatch with strict option on the patchset.

drivers/mailbox/mailbox-mpfs.c line 93

Quoted 7 lines
drivers/mailbox/mailbox-mpfs.c new file +6 -0
+
+static int mpfs_mbox_send_data(struct mbox_chan *chan, void *data)
+{
+       u32 mailbox_val = 0u;
+       u16 options_select;
+       u32 tx_trigger;

just a nit... here and elsewhere, can the variables be lesser verbose?

Quoted 7 lines
drivers/mailbox/mailbox-mpfs.c new file +7 -0
+
+static void mpfs_mbox_rx_data(struct mbox_chan *chan)
+{
+       struct mpfs_mbox *mbox = mbox_chan_to_mpfs_mbox(chan);
+       u32 i;
+       u16 num_words = ALIGN((mbox->response_size), (4)) / 4U; //TODO better way?
+       struct mpfs_mss_response *response;

drivers/mailbox/mailbox-mpfs.c line 161

Quoted 10 lines
drivers/mailbox/mailbox-mpfs.c new file +10 -0
+
+       response = kmalloc(sizeof(*response), GFP_ATOMIC);
+       response->response_size = mbox->response_size;
+       response->response_msg = kcalloc(num_words, sizeof(response->response_msg), GFP_ATOMIC);
+
+       if (!response->response_msg) {
+               dev_err(mbox->dev, "failed to assign memory for response %d\n", -ENOMEM);
+               return;
+       }
+

response_size is provided by the client driver.
So why not simply get the buffer from the client and just fill it here? That is simpler and better (avoid alloc in isr) and the right thing to do.

Quoted 4 lines
drivers/mailbox/mailbox-mpfs.c new file +3 -0
+
+static int mpfs_mbox_probe(struct platform_device *pdev)
+{

drivers/mailbox/mailbox-mpfs.c line 225

Quoted 10 lines
drivers/mailbox/mailbox-mpfs.c new file +10 -0
+       struct mpfs_mbox *mbox;
+       struct resource *regs;
+       struct mbox_chan *chans;
+       int ret;
+
+       mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL);
+       if (!mbox)
+               return -ENOMEM;
+
+       chans = devm_kzalloc(&pdev->dev, sizeof(*chans), GFP_KERNEL);

You may simply embed the mbox_chan in mpfs_mbox.

cheers.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv