From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 05/22] Add initial mailbox support
Date: Thu, 3 Aug 2023 12:49:46 +0200 [thread overview]
Message-ID: <20230803105003.4088205-6-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230803105003.4088205-1-s.hauer@pengutronix.de>
This adds a minimum mailbox support. The code is based on the
corresponding U-Boot code. It's currently enough to bring up
the communication with the SCI on TI K3 SoCs.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/Kconfig | 1 +
drivers/Makefile | 1 +
drivers/mailbox/Kconfig | 10 +++++
drivers/mailbox/Makefile | 1 +
drivers/mailbox/mailbox.c | 92 +++++++++++++++++++++++++++++++++++++++
include/mailbox.h | 36 +++++++++++++++
6 files changed, 141 insertions(+)
create mode 100644 drivers/mailbox/Kconfig
create mode 100644 drivers/mailbox/Makefile
create mode 100644 drivers/mailbox/mailbox.c
create mode 100644 include/mailbox.h
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 2636eed1a3..d9c0320556 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -46,5 +46,6 @@ source "drivers/nvme/Kconfig"
source "drivers/ddr/Kconfig"
source "drivers/power/Kconfig"
source "drivers/virtio/Kconfig"
+source "drivers/mailbox/Kconfig"
endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index fa899a2ab8..3f60e1b9c7 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -48,3 +48,4 @@ obj-y += power/
obj-$(CONFIG_SOUND) += sound/
obj-y += virtio/
obj-$(CONFIG_HAVE_OPTEE) += tee/optee/of.o
+obj-y += mailbox/
diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
new file mode 100644
index 0000000000..7839a44729
--- /dev/null
+++ b/drivers/mailbox/Kconfig
@@ -0,0 +1,10 @@
+menuconfig MAILBOX
+ bool "Mailbox Hardware Support"
+ help
+ Mailbox is a framework to control hardware communication between
+ on-chip processors through queued messages and interrupt driven
+ signals. Say Y if your platform supports hardware mailboxes.
+
+if MAILBOX
+
+endif
diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
new file mode 100644
index 0000000000..9dec4e3b3b
--- /dev/null
+++ b/drivers/mailbox/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MAILBOX) += mailbox.o
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
new file mode 100644
index 0000000000..edf9481aca
--- /dev/null
+++ b/drivers/mailbox/mailbox.c
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2016, NVIDIA CORPORATION.
+ */
+
+#define LOG_CATEGORY UCLASS_MAILBOX
+
+#include <common.h>
+#include <mailbox.h>
+#include <deep-probe.h>
+
+int mbox_send(struct mbox_chan *chan, const void *data)
+{
+ const struct mbox_chan_ops *ops = chan->mbox->ops;
+
+ return ops->send(chan, data);
+}
+
+int mbox_recv(struct mbox_chan *chan, void *data, unsigned long timeout_us)
+{
+ const struct mbox_chan_ops *ops = chan->mbox->ops;
+ u64 start;
+ int ret;
+
+ start = get_time_ns();
+
+ for (;;) {
+ ret = ops->recv(chan, data);
+ if (ret != -ENODATA)
+ return ret;
+ if (is_timeout(start, timeout_us * 1000))
+ return -ETIMEDOUT;
+ }
+}
+
+static LIST_HEAD(mbox_cons);
+
+int mbox_controller_register(struct mbox_controller *mbox)
+{
+ list_add_tail(&mbox->node, &mbox_cons);
+
+ return 0;
+}
+
+
+struct mbox_chan *mbox_request_channel(struct device *dev, int index)
+{
+ struct of_phandle_args spec;
+ struct mbox_controller *mbox;
+ struct mbox_chan *chan = ERR_PTR(-ENODEV);
+
+ if (of_parse_phandle_with_args(dev->of_node, "mboxes",
+ "#mbox-cells", index, &spec)) {
+ return ERR_PTR(-ENODEV);
+ }
+
+ of_device_ensure_probed(spec.np);
+
+ list_for_each_entry(mbox, &mbox_cons, node) {
+ if (mbox->dev->of_node != spec.np)
+ continue;
+
+ chan = mbox->of_xlate(mbox, &spec);
+ if (!IS_ERR(chan))
+ break;
+ }
+
+ return chan;
+}
+
+struct mbox_chan *mbox_request_channel_byname(struct device *dev, const char *name)
+{
+ struct device_node *np = dev->of_node;
+ struct property *prop;
+ const char *mbox_name;
+ int index = 0;
+
+ if (!np)
+ return ERR_PTR(-EINVAL);
+
+ if (!of_get_property(np, "mbox-names", NULL)) {
+ return ERR_PTR(-EINVAL);
+ }
+
+ of_property_for_each_string(np, "mbox-names", prop, mbox_name) {
+ if (!strncmp(name, mbox_name, strlen(name)))
+ return mbox_request_channel(dev, index);
+ index++;
+ }
+
+ return ERR_PTR(-ENODEV);
+}
diff --git a/include/mailbox.h b/include/mailbox.h
new file mode 100644
index 0000000000..3be58ec103
--- /dev/null
+++ b/include/mailbox.h
@@ -0,0 +1,36 @@
+#ifndef __MAILBOX_H
+#define __MAILBOX_H
+
+struct mbox_chan {
+ struct mbox_controller *mbox;
+ struct device *dev;
+ void *con_priv;
+};
+
+/**
+ * struct mbox_ops - The functions that a mailbox driver must implement.
+ */
+struct mbox_chan_ops {
+ int (*request)(struct mbox_chan *chan);
+ int (*rfree)(struct mbox_chan *chan);
+ int (*send)(struct mbox_chan *chan, const void *data);
+ int (*recv)(struct mbox_chan *chan, void *data);
+};
+
+struct mbox_controller {
+ struct device *dev;
+ const struct mbox_chan_ops *ops;
+ struct mbox_chan *chans;
+ int num_chans;
+ struct mbox_chan *(*of_xlate)(struct mbox_controller *mbox,
+ const struct of_phandle_args *sp);
+ struct list_head node;
+};
+
+int mbox_controller_register(struct mbox_controller *mbox);
+struct mbox_chan *mbox_request_channel(struct device *dev, int index);
+struct mbox_chan *mbox_request_channel_byname(struct device *dev, const char *name);
+int mbox_send(struct mbox_chan *chan, const void *data);
+int mbox_recv(struct mbox_chan *chan, void *data, unsigned long timeout_us);
+
+#endif /* __MAILBOX_H */
--
2.39.2
next prev parent reply other threads:[~2023-08-03 10:51 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 10:49 [PATCH 00/22] Add initial Texas Instruments K3 support Sascha Hauer
2023-08-03 10:49 ` [PATCH 01/22] pm_domain: Add onecell support Sascha Hauer
2023-08-03 10:49 ` [PATCH 02/22] gpio: davinci: Redesign driver to accommodate ngpios in one gpio chip Sascha Hauer
2023-08-03 10:49 ` [PATCH 03/22] gpio: davinci: Add support for GPIO controllers on TI K3 SoCs Sascha Hauer
2023-08-03 10:49 ` [PATCH 04/22] ARM64: Add support for debug_ll on TI AM62x SoCs Sascha Hauer
2023-08-03 10:49 ` Sascha Hauer [this message]
2023-08-03 10:49 ` [PATCH 06/22] mailbox: Add TI K3 Secure Proxy Driver Sascha Hauer
2023-08-03 10:49 ` [PATCH 07/22] serial: ns16550: Add support for UARTs on K3 SoCs Sascha Hauer
2023-08-03 10:49 ` [PATCH 08/22] firmware: Add basic support for TI System Control Interface (TI SCI) protocol Sascha Hauer
2023-08-03 10:49 ` [PATCH 09/22] lib: Add generic binary search function Sascha Hauer
2023-08-03 10:49 ` [PATCH 10/22] clk: Add K3 SCI clock driver Sascha Hauer
2023-08-03 10:49 ` [PATCH 11/22] soc: ti: Add ti_sci_pm_domains driver Sascha Hauer
2023-08-03 10:49 ` [PATCH 12/22] mci: fix define Sascha Hauer
2023-08-03 10:49 ` [PATCH 13/22] mci: make debugging output more useful Sascha Hauer
2023-08-03 10:49 ` [PATCH 14/22] mci: sdhci: Add common wait for idle function Sascha Hauer
2023-08-03 10:49 ` [PATCH 15/22] mci: sdhci: wait for idle before stopping clock Sascha Hauer
2023-08-03 10:49 ` [PATCH 16/22] mci: Add am654 SDHCI driver Sascha Hauer
2023-08-03 10:49 ` [PATCH 17/22] ARM: Add Texas Instruments K3 architecture Sascha Hauer
2023-08-03 10:49 ` [PATCH 18/22] ARM: k3: Add initial BeaglePlay board support Sascha Hauer
2023-08-03 10:50 ` [PATCH 19/22] ARM: k3: BeaglePlay: Work around non working SD card Sascha Hauer
2023-08-03 10:50 ` [PATCH 20/22] ARM: k3: BeaglePlay: generate FIT image Sascha Hauer
2023-08-03 10:50 ` [PATCH 21/22] doc: K3: Add documentation Sascha Hauer
2023-08-03 10:50 ` [PATCH 22/22] ARM: multi_v8_defconfig: Enable K3 SoCs Sascha Hauer
2023-11-02 14:12 ` [PATCH 00/22] Add initial Texas Instruments K3 support Ahmad Fatoum
2023-11-03 7:36 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230803105003.4088205-6-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox