diff options
author | Richard Zhu <hongxing.zhu@nxp.com> | 2017-03-09 17:12:15 +0800 |
---|---|---|
committer | Jason Liu <jason.hui.liu@nxp.com> | 2019-02-12 10:25:57 +0800 |
commit | 85aef431ff7a26313efa3b11228888d227c7177c (patch) | |
tree | a13d8ec6abc2add93d0fce1bfe51c6128861d2bc | |
parent | 5b7f13911785d66e1d8eead7d3e0fe4572bc0fa8 (diff) |
MLK-14439-3 rpmsg: imx: setup the imx rpmsg driver
- move imx_rpmsg from arch/arm/ to drivers/rpmsg.
- use the new MU generic APIs in the rpmsg implementation.
- Validated the pingpong test on both imx6sx and imx7d sdb boards.
Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
-rw-r--r-- | Documentation/devicetree/bindings/rpmsg/imx-rpmsg.txt | 19 | ||||
-rw-r--r-- | arch/arm/mach-imx/Makefile | 1 | ||||
-rw-r--r-- | arch/arm/mach-imx/mu.c | 96 | ||||
-rw-r--r-- | drivers/rpmsg/Kconfig | 5 | ||||
-rw-r--r-- | drivers/rpmsg/Makefile | 1 | ||||
-rw-r--r-- | drivers/rpmsg/imx_rpmsg.c (renamed from arch/arm/mach-imx/imx_rpmsg.c) | 185 | ||||
-rw-r--r-- | drivers/soc/imx/Kconfig | 7 | ||||
-rw-r--r-- | drivers/soc/imx/Makefile | 2 | ||||
-rw-r--r-- | include/linux/imx_rpmsg.h | 1 |
9 files changed, 209 insertions, 108 deletions
diff --git a/Documentation/devicetree/bindings/rpmsg/imx-rpmsg.txt b/Documentation/devicetree/bindings/rpmsg/imx-rpmsg.txt new file mode 100644 index 000000000000..27d710274ec3 --- /dev/null +++ b/Documentation/devicetree/bindings/rpmsg/imx-rpmsg.txt @@ -0,0 +1,19 @@ +i.MX RPMSG platform implementations + +Required properties: +- compatible : "fsl,imx7d-rpmsg", "fsl,imx6sx-rpmsg" +- vdev-nums : The number of the remote virtual devices. +- reg : The reserved DDR phisical memory used to store + vring descriptors. + +Example: +rpmsg: rpmsg{ + compatible = "fsl,imx6sx-rpmsg"; + status = "disabled"; +}; + +&rpmsg{ + vdev-nums = <1>; + reg = <0xbfff0000 0x10000>; + status = "okay"; +}; diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index e6eb59c7aefd..4e806170fe3c 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -84,7 +84,6 @@ obj-$(CONFIG_HAVE_IMX_MMDC) += mmdc.o obj-$(CONFIG_HAVE_IMX_DDRC) += ddrc.o obj-$(CONFIG_HAVE_IMX_SRC) += src.o obj-$(CONFIG_HAVE_IMX_MU) += mu.o -obj-$(CONFIG_HAVE_IMX_RPMSG) += imx_rpmsg.o ifneq ($(CONFIG_SOC_IMX6)$(CONFIG_SOC_IMX7)$(CONFIG_SOC_LS1021A),) AFLAGS_headsmp.o :=-Wa,-march=armv7-a obj-$(CONFIG_SMP) += headsmp.o platsmp.o diff --git a/arch/arm/mach-imx/mu.c b/arch/arm/mach-imx/mu.c index c2cca7e06c66..f8786c2c37b0 100644 --- a/arch/arm/mach-imx/mu.c +++ b/arch/arm/mach-imx/mu.c @@ -52,21 +52,12 @@ #define MU_LPM_M4_WAIT_MODE 0x5A5A0002 #define MU_LPM_M4_STOP_MODE 0x5A5A0003 -#define MAX_NUM 10 /* enlarge it if overflow happen */ +#define MAX_NUM 10 /* enlarge it if overflow happen */ -struct imx_mu_rpmsg_box { - const char *name; - struct blocking_notifier_head notifier; -}; - -static struct imx_mu_rpmsg_box mu_rpmsg_box = { - .name = "m4", -}; - -void __iomem *mu_base; +static void __iomem *mu_base; static u32 m4_message[MAX_NUM]; static u32 in_idx, out_idx; -static struct delayed_work mu_work, rpmsg_work; +static struct delayed_work mu_work; static u32 m4_wake_irqs[4]; static bool m4_freq_low; struct irq_domain *domain; @@ -276,11 +267,6 @@ static void mu_work_handler(struct work_struct *work) mu_base + MU_ACR); } -int imx_mu_rpmsg_send(unsigned int rpmsg) -{ - return imx_mu_send_message(MU_RPMSG_HANDSHAKE_INDEX, rpmsg); -} - int imx_mu_lpm_ready(bool ready) { u32 val; @@ -301,54 +287,6 @@ int imx_mu_lpm_ready(bool ready) return 0; } -int imx_mu_rpmsg_register_nb(const char *name, struct notifier_block *nb) -{ - if ((name == NULL) || (nb == NULL)) - return -EINVAL; - - if (!strcmp(mu_rpmsg_box.name, name)) - blocking_notifier_chain_register(&(mu_rpmsg_box.notifier), nb); - else - return -ENOENT; - - return 0; -} - -int imx_mu_rpmsg_unregister_nb(const char *name, struct notifier_block *nb) -{ - if ((name == NULL) || (nb == NULL)) - return -EINVAL; - - if (!strcmp(mu_rpmsg_box.name, name)) - blocking_notifier_chain_unregister(&(mu_rpmsg_box.notifier), - nb); - else - return -ENOENT; - - return 0; -} - -static void rpmsg_work_handler(struct work_struct *work) -{ - u32 message; - unsigned long flags; - - spin_lock_irqsave(&mu_lock, flags); - /* handle all incoming mu message */ - while (in_idx != out_idx) { - message = m4_message[out_idx % MAX_NUM]; - spin_unlock_irqrestore(&mu_lock, flags); - - blocking_notifier_call_chain(&(mu_rpmsg_box.notifier), 4, - (void *)message); - - spin_lock_irqsave(&mu_lock, flags); - m4_message[out_idx % MAX_NUM] = 0; - out_idx++; - } - spin_unlock_irqrestore(&mu_lock, flags); -} - static irqreturn_t imx_mu_isr(int irq, void *param) { u32 irqs; @@ -359,30 +297,6 @@ static irqreturn_t imx_mu_isr(int irq, void *param) else irqs = readl_relaxed(mu_base + MU_ASR); - /* RPMSG */ - if (irqs & (1 << 26)) { - spin_lock_irqsave(&mu_lock, flags); - /* get message from receive buffer */ - if (cpu_is_imx7ulp()) - m4_message[in_idx % MAX_NUM] = readl_relaxed(mu_base + - MX7ULP_MU_RR1); - else - m4_message[in_idx % MAX_NUM] = readl_relaxed(mu_base + - MU_ARR1_OFFSET); - in_idx++; - /* - * Too many mu message not be handled in timely, can enlarge - * MAX_NUM */ - if (in_idx == out_idx) { - spin_unlock_irqrestore(&mu_lock, flags); - pr_err("MU overflow!\n"); - return IRQ_HANDLED; - } - spin_unlock_irqrestore(&mu_lock, flags); - - schedule_delayed_work(&rpmsg_work, 0); - } - if (irqs & (1 << 27)) { spin_lock_irqsave(&mu_lock, flags); /* get message from receive buffer */ @@ -429,7 +343,7 @@ static int imx_mu_probe(struct platform_device *pdev) else irq = platform_get_irq(pdev, 0); ret = request_irq(irq, imx_mu_isr, - IRQF_EARLY_RESUME, "imx-mu", &mu_rpmsg_box); + IRQF_EARLY_RESUME | IRQF_SHARED, "imx-mu", NULL); if (ret) { pr_err("%s: register interrupt %d failed, rc %d\n", __func__, irq, ret); @@ -461,7 +375,6 @@ static int imx_mu_probe(struct platform_device *pdev) } INIT_DELAYED_WORK(&mu_work, mu_work_handler); - INIT_DELAYED_WORK(&rpmsg_work, rpmsg_work_handler); /* bit0 of MX7ULP_MU_CR used to let m4 to know MU is ready now */ if (cpu_is_imx7ulp()) writel_relaxed(readl_relaxed(mu_base + MX7ULP_MU_CR) | @@ -469,7 +382,6 @@ static int imx_mu_probe(struct platform_device *pdev) else writel_relaxed(readl_relaxed(mu_base + MU_ACR) | BIT(26) | BIT(27), mu_base + MU_ACR); - BLOCKING_INIT_NOTIFIER_HEAD(&(mu_rpmsg_box.notifier)); pr_info("MU is ready for cross core communication!\n"); diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index f35b33a519aa..3979e01368f6 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -51,6 +51,11 @@ config RPMSG_VIRTIO select RPMSG select VIRTIO +config HAVE_IMX_RPMSG + bool "IMX RPMSG driver on the AMP SOCs" + select RPMSG + select RPMSG_VIRTIO + config IMX_RPMSG_PINGPONG tristate "IMX RPMSG pingpong driver -- loadable modules only" default m diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile index 07f5a48cf58f..3a1f0e97e3c0 100644 --- a/drivers/rpmsg/Makefile +++ b/drivers/rpmsg/Makefile @@ -6,5 +6,6 @@ obj-$(CONFIG_RPMSG_QCOM_GLINK_NATIVE) += qcom_glink_native.o obj-$(CONFIG_RPMSG_QCOM_GLINK_SMEM) += qcom_glink_smem.o obj-$(CONFIG_RPMSG_QCOM_SMD) += qcom_smd.o obj-$(CONFIG_RPMSG_VIRTIO) += virtio_rpmsg_bus.o +obj-$(CONFIG_HAVE_IMX_RPMSG) += imx_rpmsg.o obj-$(CONFIG_IMX_RPMSG_PINGPONG) += imx_rpmsg_pingpong.o obj-$(CONFIG_IMX_RPMSG_TTY) += imx_rpmsg_tty.o diff --git a/arch/arm/mach-imx/imx_rpmsg.c b/drivers/rpmsg/imx_rpmsg.c index bb03605e1d79..ba548989de34 100644 --- a/arch/arm/mach-imx/imx_rpmsg.c +++ b/drivers/rpmsg/imx_rpmsg.c @@ -12,12 +12,16 @@ * http://www.gnu.org/copyleft/gpl.html */ +#include <linux/clk.h> #include <linux/err.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/module.h> #include <linux/notifier.h> #include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_device.h> +#include <linux/of_irq.h> #include <linux/platform_device.h> #include <linux/rpmsg.h> #include <linux/slab.h> @@ -26,6 +30,14 @@ #include <linux/virtio_ids.h> #include <linux/virtio_ring.h> #include <linux/imx_rpmsg.h> +#include <linux/mx8_mu.h> + +enum imx_rpmsg_variants { + IMX6SX, + IMX7D, + IMX7ULP, +}; +static enum imx_rpmsg_variants variant; struct imx_virdev { struct virtio_device vdev; @@ -44,6 +56,23 @@ struct imx_rpmsg_vproc { struct imx_virdev ivdev[MAX_VDEV_NUMS]; }; +struct imx_mu_rpmsg_box { + const char *name; + struct blocking_notifier_head notifier; +}; + +static struct imx_mu_rpmsg_box mu_rpmsg_box = { + .name = "m4", +}; + +#define MAX_NUM 10 /* enlarge it if overflow happen */ + +static void __iomem *mu_base; +static u32 m4_message[MAX_NUM]; +static u32 in_idx, out_idx; +static DEFINE_SPINLOCK(mu_lock); +static struct delayed_work rpmsg_work; + /* * For now, allocate 256 buffers of 512 bytes for each side. each buffer * will then have 16B for the msg header and 496B for the payload. @@ -92,19 +121,14 @@ static int imx_rpmsg_finalize_features(struct virtio_device *vdev) /* kick the remote processor, and let it know which virtqueue to poke at */ static bool imx_rpmsg_notify(struct virtqueue *vq) { - int ret; unsigned int mu_rpmsg = 0; struct imx_rpmsg_vq_info *rpvq = vq->priv; mu_rpmsg = rpvq->vq_id << 16; mutex_lock(&rpvq->rpdev->lock); /* send the index of the triggered virtqueue as the mu payload */ - ret = imx_mu_rpmsg_send(mu_rpmsg); + MU_SendMessage(mu_base, 1, mu_rpmsg); mutex_unlock(&rpvq->rpdev->lock); - if (ret) { - pr_err("ugh, imx_mu_rpmsg_send() failed: %d\n", ret); - return false; - } return true; } @@ -112,13 +136,12 @@ static bool imx_rpmsg_notify(struct virtqueue *vq) static int imx_mu_rpmsg_callback(struct notifier_block *this, unsigned long index, void *data) { - u32 mu_msg = (u32) data; + u32 mu_msg = (phys_addr_t) data; struct imx_virdev *virdev; virdev = container_of(this, struct imx_virdev, nb); pr_debug("%s mu_msg: 0x%x\n", __func__, mu_msg); - /* ignore vq indices which are clearly not for us */ mu_msg = mu_msg >> 16; if (mu_msg < virdev->base_vq_id || mu_msg > virdev->base_vq_id + 1) { @@ -140,8 +163,35 @@ static int imx_mu_rpmsg_callback(struct notifier_block *this, return NOTIFY_DONE; } +int imx_mu_rpmsg_register_nb(const char *name, struct notifier_block *nb) +{ + if ((name == NULL) || (nb == NULL)) + return -EINVAL; + + if (!strcmp(mu_rpmsg_box.name, name)) + blocking_notifier_chain_register(&(mu_rpmsg_box.notifier), nb); + else + return -ENOENT; + + return 0; +} + +int imx_mu_rpmsg_unregister_nb(const char *name, struct notifier_block *nb) +{ + if ((name == NULL) || (nb == NULL)) + return -EINVAL; + + if (!strcmp(mu_rpmsg_box.name, name)) + blocking_notifier_chain_unregister(&(mu_rpmsg_box.notifier), + nb); + else + return -ENOENT; + + return 0; +} + static struct virtqueue *rp_find_vq(struct virtio_device *vdev, - unsigned index, + unsigned int index, void (*callback)(struct virtqueue *vq), const char *name, bool ctx) @@ -167,8 +217,8 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, memset(rpvq->addr, 0, RPMSG_RING_SIZE); - pr_debug("vring%d: phys 0x%x, virt 0x%x\n", index, virdev->vring[index], - (unsigned int) rpvq->addr); + pr_debug("vring%d: phys 0x%x, virt 0x%p\n", index, virdev->vring[index], + rpvq->addr); vq = vring_new_virtqueue(index, RPMSG_NUM_BUFS / 2, RPMSG_VRING_ALIGN, vdev, true, ctx, @@ -207,6 +257,7 @@ static void imx_rpmsg_del_vqs(struct virtio_device *vdev) list_for_each_entry_safe(vq, n, &vdev->vqs, list) { struct imx_rpmsg_vq_info *rpvq = vq->priv; + iounmap(rpvq->addr); vring_del_virtqueue(vq); kfree(rpvq); @@ -217,7 +268,7 @@ static void imx_rpmsg_del_vqs(struct virtio_device *vdev) &virdev->nb); } -static int imx_rpmsg_find_vqs(struct virtio_device *vdev, unsigned nvqs, +static int imx_rpmsg_find_vqs(struct virtio_device *vdev, unsigned int nvqs, struct virtqueue *vqs[], vq_callback_t *callbacks[], const char * const names[], @@ -317,7 +368,8 @@ static int set_vring_phy_buf(struct platform_device *pdev, 0x8000; start += 0x10000; if (start > end) { - pr_err("Too small memory size %x!\n", size); + pr_err("Too small memory size %x!\n", + (u32)size); ret = -EINVAL; break; } @@ -329,11 +381,118 @@ static int set_vring_phy_buf(struct platform_device *pdev, return ret; } +static void rpmsg_work_handler(struct work_struct *work) +{ + u32 message; + unsigned long flags; + + spin_lock_irqsave(&mu_lock, flags); + /* handle all incoming mu message */ + while (in_idx != out_idx) { + message = m4_message[out_idx % MAX_NUM]; + spin_unlock_irqrestore(&mu_lock, flags); + + blocking_notifier_call_chain(&(mu_rpmsg_box.notifier), 4, + (void *)(phys_addr_t)message); + + spin_lock_irqsave(&mu_lock, flags); + m4_message[out_idx % MAX_NUM] = 0; + out_idx++; + } + spin_unlock_irqrestore(&mu_lock, flags); +} + +static irqreturn_t imx_mu_rpmsg_isr(int irq, void *param) +{ + u32 irqs, message; + unsigned long flags; + + irqs = MU_ReadStatus(mu_base); + + /* RPMSG */ + if (irqs & (1 << 26)) { + spin_lock_irqsave(&mu_lock, flags); + /* get message from receive buffer */ + MU_ReceiveMsg(mu_base, 1, &message); + m4_message[in_idx % MAX_NUM] = message; + in_idx++; + /* + * Too many mu message not be handled in timely, can enlarge + * MAX_NUM + */ + if (in_idx == out_idx) { + spin_unlock_irqrestore(&mu_lock, flags); + pr_err("MU overflow!\n"); + return IRQ_HANDLED; + } + spin_unlock_irqrestore(&mu_lock, flags); + + schedule_delayed_work(&rpmsg_work, 0); + } + + return IRQ_HANDLED; +} + static int imx_rpmsg_probe(struct platform_device *pdev) { int i, j, ret = 0; + u32 irq; + struct clk *clk; + struct device_node *np_mu; + struct device *dev = &pdev->dev; struct device_node *np = pdev->dev.of_node; + variant = (enum imx_rpmsg_variants)of_device_get_match_data(dev); + + /* Initialize the mu unit used by rpmsg */ + np_mu = of_find_compatible_node(NULL, NULL, "fsl,imx6sx-mu"); + if (!np_mu) + pr_info("Cannot find MU-RPMSG entry in device tree\n"); + mu_base = of_iomap(np_mu, 0); + WARN_ON(!mu_base); + + if (variant == IMX7ULP) + irq = of_irq_get(np_mu, 1); + else + irq = of_irq_get(np_mu, 0); + + ret = request_irq(irq, imx_mu_rpmsg_isr, + IRQF_EARLY_RESUME | IRQF_SHARED, + "imx-mu-rpmsg", &mu_rpmsg_box); + if (ret) { + pr_err("%s: register interrupt %d failed, rc %d\n", + __func__, irq, ret); + return ret; + } + + if (variant == IMX7D) { + clk = of_clk_get(np_mu, 0); + if (IS_ERR(clk)) { + pr_err("mu clock source missing or invalid\n"); + return PTR_ERR(clk); + } + ret = clk_prepare_enable(clk); + if (ret) { + pr_err("unable to enable mu clock\n"); + return ret; + } + } + + INIT_DELAYED_WORK(&rpmsg_work, rpmsg_work_handler); + /* + * bit26 is used by rpmsg channels. + * bit0 of MX7ULP_MU_CR used to let m4 to know MU is ready now + */ + if (variant == IMX7ULP) { + MU_EnableRxFullInt(mu_base, 1); + MU_SetFn(mu_base, 1); + } else { + MU_EnableRxFullInt(mu_base, 1); + } + BLOCKING_INIT_NOTIFIER_HEAD(&(mu_rpmsg_box.notifier)); + + pr_info("MU is ready for cross core communication!\n"); + for (i = 0; i < ARRAY_SIZE(imx_rpmsg_vprocs); i++) { struct imx_rpmsg_vproc *rpdev = &imx_rpmsg_vprocs[i]; diff --git a/drivers/soc/imx/Kconfig b/drivers/soc/imx/Kconfig index 68cbe4ccd934..3daacb6ef728 100644 --- a/drivers/soc/imx/Kconfig +++ b/drivers/soc/imx/Kconfig @@ -32,4 +32,11 @@ config IMX7_PM_DOMAINS select PM_GENERIC_DOMAINS default y if SOC_IMX7D +config HAVE_IMX_MU + bool + +config HAVE_IMX_RPMSG + select RPMSG_VIRTIO + select RPMSG + bool endmenu diff --git a/drivers/soc/imx/Makefile b/drivers/soc/imx/Makefile index 8dc698b5bd51..b949b5a2bbe3 100644 --- a/drivers/soc/imx/Makefile +++ b/drivers/soc/imx/Makefile @@ -1,5 +1,5 @@ obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o obj-$(CONFIG_IMX7_PM_DOMAINS) += gpcv2.o -obj-$(CONFIG_ARCH_FSL_IMX8QM) += mu/ +obj-$(CONFIG_HAVE_IMX_MU) += mu/ obj-$(CONFIG_ARCH_FSL_IMX8QM) += sc/ obj-$(CONFIG_ARCH_FSL_IMX8QM) += pm-domains.o soc-imx8.o diff --git a/include/linux/imx_rpmsg.h b/include/linux/imx_rpmsg.h index 2c3458056d47..1299774cf5c1 100644 --- a/include/linux/imx_rpmsg.h +++ b/include/linux/imx_rpmsg.h @@ -39,7 +39,6 @@ struct imx_rpmsg_head { u8 reserved[5]; } __attribute__ ((packed)); -int imx_mu_rpmsg_send(unsigned int vq_id); int imx_mu_rpmsg_register_nb(const char *name, struct notifier_block *nb); int imx_mu_rpmsg_unregister_nb(const char *name, struct notifier_block *nb); #endif /* __LINUX_IMX_RPMSG_H__ */ |