Skip to contentSkip to conversation

Add MHU and RPMSG driver for cs1k

PATCH Applied [email protected] 2 participants 6 messages Sep 22, 2022 – Sep 29, 2022

lore
Share & tools
lore
#0 lore raw

cover Add MHU and RPMSG driver for cs1k

From: Emekcan <[email protected]>

The host uses MHUs to send/receive data from the external system in corstone1000. These commits add MHU mailbox device tree bindings and rpmsg mailbox driver. The host can now use the driver under /dev/rpmsg0_ctrl0 to communicate with external system.

Emekcan (2):
arm-bsp/u-boot: Add external system MHUs to u-boot device tree arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000

 ...d-rpmsg-client-to-u-boot-device-tree.patch |  81 +++++++
 .../recipes-bsp/u-boot/u-boot_%.bbappend      |   1 +
 ...03-Add-rpsmg-driver-for-corstone1000.patch | 222 ++++++++++++++++++
 .../linux/files/corstone1000/defconfig        |   7 +-
 .../linux/linux-arm-platforms.inc             |   1 +
 5 files changed, 311 insertions(+), 1 deletion(-)
 create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/corstone1000/0027-Add-mhu-and-rpmsg-client-to-u-boot-device-tree.patch
 create mode 100644 meta-arm-bsp/recipes-kernel/linux/files/corstone1000/0003-Add-rpsmg-driver-for-corstone1000.patch
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 arm-bsp/u-boot: Add external system MHUs to u-boot device tree

From: Emekcan <[email protected]>

The host uses MHUs to send/receive data from the external system in corstone1000. This commit adds MHU mailbox bindings into the u-boot device tree to enable data communication between the host and external system.

---
 ...d-rpmsg-client-to-u-boot-device-tree.patch | 81 +++++++++++++++++++
 .../recipes-bsp/u-boot/u-boot_%.bbappend      |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 meta-arm-bsp/recipes-bsp/u-boot/u-boot/corstone1000/0027-Add-mhu-and-rpmsg-client-to-u-boot-device-tree.patch
meta-arm-bsp/recipes-bsp/u-boot/u-boot/corstone1000/0027-Add-mhu-and-rpmsg-client-to-u-boot-device-tree.patch new file +81 -0
new file mode 100644
index 00000000..cd01732d
@@ -0,0 +1,81 @@
+Upstream-Status: Pending [Not submitted to upstream yet]
+Signed-off-by: Emekcan Aras <[email protected]>
+
+From a1b8b91a43cfa9dbaa2d907a6d9629da6f93fa3e Mon Sep 17 00:00:00 2001
+From: Emekcan <[email protected]>
+Date: Mon, 12 Sep 2022 15:47:06 +0100
+Subject: [PATCH] Add mhu and rpmsg client to u-boot device tree
+
+Adds external system controller and mhu driver to u-boot
+device tree. This enables communication between host and
+the external system.
+
+Signed-off-by: Emekcan Aras <[email protected]>
+---
+ arch/arm/dts/corstone1000.dtsi | 50 ++++++++++++++++++++++++++++++++
+ 1 file changed, 50 insertions(+)
+
+diff --git a/arch/arm/dts/corstone1000.dtsi b/arch/arm/dts/corstone1000.dtsi
+index 19b6e3ea72..61dd6c432c 100644
+--- a/arch/arm/dts/corstone1000.dtsi
++++ b/arch/arm/dts/corstone1000.dtsi
+@@ -161,6 +161,56 @@
+ 			status = "disabled";
+ 		};
+ 
++		mbox_es0mhu0_tx: mhu@1b000000 {
++			compatible = "arm,mhuv2-tx","arm,primecell";
++			reg = <0x1b000000 0x1000>;
++			clocks = <&refclk100mhz>;
++			clock-names = "apb_pclk";
++			interrupts = <GIC_SPI 11 IRQ_TYPE_LEVEL_HIGH>;
++			#mbox-cells = <2>;
++			arm,mhuv2-protocols = <1 1>;
++			mbox-name = "arm-es0-mhu0_tx";
++		};
++
++		mbox_es0mhu0_rx: mhu@1b010000 {
++			compatible = "arm,mhuv2-rx","arm,primecell";
++			reg = <0x1b010000 0x1000>;
++			clocks = <&refclk100mhz>;
++			clock-names = "apb_pclk";
++			interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>;
++			#mbox-cells = <2>;
++			arm,mhuv2-protocols = <1 1>;
++			mbox-name = "arm-es0-mhu0_rx";
++		};
++
++		mbox_es0mhu1_tx: mhu@1b020000 {
++			compatible = "arm,mhuv2-tx","arm,primecell";
++			reg = <0x1b020000 0x1000>;
++			clocks = <&refclk100mhz>;
++			clock-names = "apb_pclk";
++			interrupts = <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;
++			#mbox-cells = <2>;
++			arm,mhuv2-protocols = <1 1>;
++			mbox-name = "arm-es0-mhu1_tx";
++		};
++
++		mbox_es0mhu1_rx: mhu@1b030000 {
++			compatible = "arm,mhuv2-rx","arm,primecell";
++			reg = <0x1b030000 0x1000>;
++			clocks = <&refclk100mhz>;
++			clock-names = "apb_pclk";
++			interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>;
++			#mbox-cells = <2>;
++			arm,mhuv2-protocols = <1 1>;
++			mbox-name = "arm-es0-mhu1_rx";
++		};
++
++		client {
++			compatible = "arm,client";
++			mboxes = <&mbox_es0mhu0_tx 0 0>, <&mbox_es0mhu1_tx 0 0>, <&mbox_es0mhu0_rx 0 0>, <&mbox_es0mhu1_rx 0 0>;
++			mbox-names = "es0mhu0_tx", "es0mhu1_tx", "es0mhu0_rx", "es0mhu1_rx";
++		};
++
+ 		extsys0: extsys@1A010310 {
+ 			compatible = "arm,extsys_ctrl";
+ 			reg = <0x1A010310 0x4>,
+-- 
+2.17.1
+
meta-arm-bsp/recipes-bsp/u-boot/u-boot_%.bbappend +1 -0
index 3c316f30..08d4a8e1 100644
@@ -44,6 +44,7 @@ SRC_URI:append:corstone1000 = " \
         file://0024-arm-corstone1000-add-mmc-for-fvp.patch \
         file://0025-corstone1000-use-a-compressed-kernel.patch \
         file://0026-Introduce-external-sys-driver-to-device-tree.patch \
+        file://0027-Add-mhu-and-rpmsg-client-to-u-boot-device-tree.patch \
       "
 
 #
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000

In reply to [email protected]

From: Emekcan <[email protected]>

Adds out-of-tree rpmsg_arm_mailbox driver patches into linux kernel to communicate with external system using MHUs in corstone1000 platform. The host can communicate with external system using the driver under /dev/rpmsg0_ctrl0.

---
 ...03-Add-rpsmg-driver-for-corstone1000.patch | 222 ++++++++++++++++++
 .../linux/files/corstone1000/defconfig        |   7 +-
 .../linux/linux-arm-platforms.inc             |   1 +
 3 files changed, 229 insertions(+), 1 deletion(-)
 create mode 100644 meta-arm-bsp/recipes-kernel/linux/files/corstone1000/0003-Add-rpsmg-driver-for-corstone1000.patch
meta-arm-bsp/recipes-kernel/linux/files/corstone1000/0003-Add-rpsmg-driver-for-corstone1000.patch new file +222 -0
new file mode 100644
index 00000000..d88acfc0
@@ -0,0 +1,222 @@
+Upstream-Status: Pending [Not submitted to upstream yet]
+Signed-off-by: Emekcan Aras <[email protected]>
+
+From e683c37ee51717e625c8a598056cf4bb1bdadcbc Mon Sep 17 00:00:00 2001
+From: Emekcan <[email protected]>
+Date: Wed, 17 Aug 2022 14:21:42 +0100
+Subject: [PATCH] Add rpsmg driver for corstone1000
+
+Adds rpsmg driver to communicate with external
+system in corstone1000 platform.
+
+Signed-off-by: Emekcan Aras <[email protected]>
+---
+ drivers/rpmsg/Kconfig             |  10 ++
+ drivers/rpmsg/Makefile            |   1 +
+ drivers/rpmsg/rpmsg_arm_mailbox.c | 164 ++++++++++++++++++++++
+ 3 files changed, 175 insertions(+)
+ create mode 100644 drivers/rpmsg/rpmsg_arm_mailbox.c
+
+diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig
+index 0b4407abdf13..c276bd17bffe 100644
+--- a/drivers/rpmsg/Kconfig
++++ b/drivers/rpmsg/Kconfig
+@@ -73,4 +73,14 @@ config RPMSG_VIRTIO
+ 	select RPMSG_NS
+ 	select VIRTIO
+ 
++config RPMSG_ARM
++	tristate "ARM RPMSG driver"
++	select     RPMSG
++	depends on HAS_IOMEM
++	depends on MAILBOX
++	help
++	  Say y here to enable support for rpmsg lient driver which is built
++	  around mailbox client using Arm MHUv2.1 as physical medium.This
++	  driver enables communication which remote processor using MHU.
++
+ endmenu
+diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile
+index 8d452656f0ee..34e9c146cd64 100644
+--- a/drivers/rpmsg/Makefile
++++ b/drivers/rpmsg/Makefile
+@@ -1,5 +1,6 @@
+ # SPDX-License-Identifier: GPL-2.0
+ obj-$(CONFIG_RPMSG)		+= rpmsg_core.o
++obj-$(CONFIG_RPMSG_ARM)		+= rpmsg_arm_mailbox.o
+ obj-$(CONFIG_RPMSG_CHAR)	+= rpmsg_char.o
+ obj-$(CONFIG_RPMSG_NS)		+= rpmsg_ns.o
+ obj-$(CONFIG_RPMSG_MTK_SCP)	+= mtk_rpmsg.o
+diff --git a/drivers/rpmsg/rpmsg_arm_mailbox.c b/drivers/rpmsg/rpmsg_arm_mailbox.c
+new file mode 100644
+index 000000000000..4a80102669f6
+--- /dev/null
++++ b/drivers/rpmsg/rpmsg_arm_mailbox.c
+@@ -0,0 +1,164 @@
++// SPDX-License-Identifier: GPL-2.0
++/*
++ * rpmsg client driver using mailbox client interface
++ *
++ * Copyright (C) 2019 ARM Ltd.
++ *
++ */
++
++#include <linux/bitmap.h>
++#include <linux/export.h>
++#include <linux/io.h>
++#include <linux/kernel.h>
++#include <linux/ktime.h>
++#include <linux/mailbox_client.h>
++#include <linux/module.h>
++#include <linux/of_address.h>
++#include <linux/of_device.h>
++#include <linux/processor.h>
++#include <linux/semaphore.h>
++#include <linux/slab.h>
++#include <linux/rpmsg.h>
++#include "rpmsg_internal.h"
++#include <linux/mailbox/arm_mhuv2_message.h>
++
++#define RPMSG_NAME	"arm_rpmsg"
++#define RPMSG_ADDR_ANY	0xFFFFFFFF
++
++struct arm_channel {
++	struct rpmsg_endpoint ept;
++	struct mbox_client cl;
++	struct mbox_chan *mbox;
++};
++
++#define arm_channel_from_rpmsg(_ept) container_of(_ept, struct arm_channel, ept)
++#define arm_channel_from_mbox(_ept) container_of(_ept, struct arm_channel, cl)
++
++
++static void arm_msg_rx_handler(struct mbox_client *cl, void *mssg)
++{
++	struct arm_mhuv2_mbox_msg *msg = mssg;
++	struct arm_channel* channel = arm_channel_from_mbox(cl);
++	int err = channel->ept.cb(channel->ept.rpdev, msg->data, 4, channel->ept.priv, RPMSG_ADDR_ANY);
++	if(err) {
++		printk("ARM Mailbox: Endpoint callback failed with error: %d", err);
++	}
++}
++
++
++static void arm_destroy_ept(struct rpmsg_endpoint *ept)
++{
++	struct arm_channel *channel = arm_channel_from_rpmsg(ept);
++	mbox_free_channel(channel->mbox);
++	kfree(channel);
++}
++
++static int arm_send(struct rpmsg_endpoint *ept, void *data, int len)
++{
++	struct arm_channel *channel = arm_channel_from_rpmsg(ept);
++
++	mbox_send_message(channel->mbox, data);
++	return 0;
++}
++
++static int arm_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dest)
++{
++	struct arm_mhuv2_mbox_msg msg;
++	struct arm_channel *channel = arm_channel_from_rpmsg(ept);
++	msg.data = data;
++	msg.len = len;
++	mbox_send_message(channel->mbox, &msg);
++	return 0;
++}
++
++
++static const struct rpmsg_endpoint_ops arm_endpoint_ops = {
++	.destroy_ept = arm_destroy_ept,
++	.send = arm_send,
++	.sendto = arm_sendto,
++};
++
++
++static struct rpmsg_endpoint *arm_create_ept(struct rpmsg_device *rpdev,
++		rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo)
++{
++	struct arm_channel *channel;
++
++	channel = kzalloc(sizeof(*channel), GFP_KERNEL);
++
++	// Initialize rpmsg endpoint
++	kref_init(&channel->ept.refcount);
++	channel->ept.rpdev = rpdev;
++	channel->ept.cb = cb;
++	channel->ept.priv = priv;
++	channel->ept.ops = &arm_endpoint_ops;
++
++	// Initialize mailbox client
++	channel->cl.dev = rpdev->dev.parent;
++	channel->cl.rx_callback = arm_msg_rx_handler;
++	channel->cl.tx_done = NULL; /* operate in blocking mode */
++	channel->cl.tx_block = true;
++	channel->cl.tx_tout = 500; /* by half a second */
++	channel->cl.knows_txdone = false; /* depending upon protocol */
++
++	channel->mbox = mbox_request_channel_byname(&channel->cl, chinfo.name);
++	if (IS_ERR_OR_NULL(channel->mbox)) {
++		printk("RPMsg ARM: Cannot get channel by name: '%s'\n", chinfo.name);
++		return -1;
++	}
++
++	return &channel->ept;
++}
++
++static const struct rpmsg_device_ops arm_device_ops = {
++	.create_ept = arm_create_ept,
++};
++
++
++static void arm_release_device(struct device *dev)
++{
++	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
++
++	kfree(rpdev);
++}
++
++
++static int client_probe(struct platform_device *pdev)
++{
++	struct device *dev = &pdev->dev;
++	struct rpmsg_device *rpdev;
++
++	rpdev = kzalloc(sizeof(*rpdev), GFP_KERNEL);
++	if (!rpdev)
++		return -ENOMEM;
++
++	/* Assign callbacks for rpmsg_device */
++	rpdev->ops = &arm_device_ops;
++
++	/* Assign public information to the rpmsg_device */
++	memcpy(rpdev->id.name, RPMSG_NAME, strlen(RPMSG_NAME));
++
++	rpdev->dev.parent = dev;
++	rpdev->dev.release = arm_release_device;
++
++	return rpmsg_chrdev_register_device(rpdev);
++}
++
++static const struct of_device_id client_of_match[] = {
++	{ .compatible = "arm,client", .data = NULL },
++	{ /* Sentinel */ },
++};
++
++static struct platform_driver client_driver = {
++	.driver = {
++		.name = "arm-mhu-client",
++		.of_match_table = client_of_match,
++	},
++	.probe = client_probe,
++};
++
++module_platform_driver(client_driver);
++
++MODULE_LICENSE("GPL v2");
++MODULE_DESCRIPTION("ARM RPMSG Driver");
++MODULE_AUTHOR("Tushar Khandelwal <[email protected]>");
+-- 
+2.17.1
+
meta-arm-bsp/recipes-kernel/linux/files/corstone1000/defconfig +6 -1
index 095cc257..0cdd3fa4 100644
@@ -92,4 +92,9 @@ CONFIG_LIBCRC32C=y
 CONFIG_DEBUG_FS=y
 CONFIG_PANIC_TIMEOUT=5
 CONFIG_STACKTRACE=y
-CONFIG_EXTSYS_CTRL=y
\ No newline at end of file
+CONFIG_EXTSYS_CTRL=y
+CONFIG_MAILBOX=y
+CONFIG_ARM_MHU_V2=y
+CONFIG_RPMSG=y
+CONFIG_RPMSG_CHAR=y
+CONFIG_RPMSG_ARM=y
meta-arm-bsp/recipes-kernel/linux/linux-arm-platforms.inc +1 -0
index c44d5883..4a6cc438 100644
@@ -42,6 +42,7 @@ SRC_URI:append:corstone1000 = " \
            file://defconfig  \
            file://0001-UPSTREAM-firmware-arm_ffa-Handle-compatibility-with-.patch  \
            file://0002-Add-external-system-driver.patch \
+           file://0003-Add-rpsmg-driver-for-corstone1000.patch \
         "
 
 SRC_URI:append:corstone1000 = " ${@bb.utils.contains('MACHINE_FEATURES', \
Signature · 1 line
2.17.1
Applied
#3 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, 22 Sep 2022 15:59:54 +0100, [email protected] wrote:

The host uses MHUs to send/receive data from the external system in corstone1000. These commits add MHU mailbox device tree bindings and rpmsg mailbox driver. The host can now use the driver under /dev/rpmsg0_ctrl0 to communicate with external system.

Emekcan (2):
arm-bsp/u-boot: Add external system MHUs to u-boot device tree arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000

[...]

Applied, thanks!

[1/2] arm-bsp/u-boot: Add external system MHUs to u-boot device tree

      commit: b573b29b766f231b6d3a21b21426738b2ce9d69a
[2/2] arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000
      commit: be8890bb034cb7d850e975041baba04cca2fb93e

Best regards,

Signature · 1 line
Jon Mason <[email protected]>
Applied
#4 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, 22 Sep 2022 15:59:54 +0100, [email protected] wrote:

The host uses MHUs to send/receive data from the external system in corstone1000. These commits add MHU mailbox device tree bindings and rpmsg mailbox driver. The host can now use the driver under /dev/rpmsg0_ctrl0 to communicate with external system.

Emekcan (2):
arm-bsp/u-boot: Add external system MHUs to u-boot device tree arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000

[...]

Applied, thanks!

[1/2] arm-bsp/u-boot: Add external system MHUs to u-boot device tree

      commit: b573b29b766f231b6d3a21b21426738b2ce9d69a
[2/2] arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000
      commit: be8890bb034cb7d850e975041baba04cca2fb93e

Best regards,

Signature · 1 line
Jon Mason <[email protected]>
Applied
#5 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, 22 Sep 2022 15:59:54 +0100, [email protected] wrote:

The host uses MHUs to send/receive data from the external system in corstone1000. These commits add MHU mailbox device tree bindings and rpmsg mailbox driver. The host can now use the driver under /dev/rpmsg0_ctrl0 to communicate with external system.

Emekcan (2):
arm-bsp/u-boot: Add external system MHUs to u-boot device tree arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000

[...]

Applied, thanks!

[1/2] arm-bsp/u-boot: Add external system MHUs to u-boot device tree

      commit: b573b29b766f231b6d3a21b21426738b2ce9d69a
[2/2] arm-bsp/kernel: Add rpmsg_arm_mailbox to corstone1000
      commit: be8890bb034cb7d850e975041baba04cca2fb93e

Best regards,

Signature · 1 line
Jon Mason <[email protected]>