From: Lokesh Vutla <lokeshvutla@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 21/25] remoteproc: Introduce K3 system controller
Date: Tue, 21 Aug 2018 20:01:59 +0530 [thread overview]
Message-ID: <20180821143203.29142-22-lokeshvutla@ti.com> (raw)
In-Reply-To: <20180821143203.29142-1-lokeshvutla@ti.com>
K3 specific SoCs have a dedicated microcontroller for doing
resource management. Any HLOS/firmware on compute clusters should
load a firmware to this microcontroller before accessing any resource.
Adding support for loading this firmware.
After the K3 system controller got loaded with firmware and started
up it sends out a boot notification message through the secure proxy
facility using the TI SCI protocol. Intercept and receive this message
through the rproc start operation which will need to get invoked
explicitly after the firmware got loaded.
Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
---
.../remoteproc/k3-system-controller.txt | 24 ++
drivers/remoteproc/Kconfig | 9 +
drivers/remoteproc/Makefile | 1 +
drivers/remoteproc/k3_system_controller.c | 323 ++++++++++++++++++
4 files changed, 357 insertions(+)
create mode 100644 doc/device-tree-bindings/remoteproc/k3-system-controller.txt
create mode 100644 drivers/remoteproc/k3_system_controller.c
diff --git a/doc/device-tree-bindings/remoteproc/k3-system-controller.txt b/doc/device-tree-bindings/remoteproc/k3-system-controller.txt
new file mode 100644
index 0000000000..32f4720b0d
--- /dev/null
+++ b/doc/device-tree-bindings/remoteproc/k3-system-controller.txt
@@ -0,0 +1,24 @@
+Texas Instruments' K3 System Controller
+=========================================
+
+K3 specific SoCs have a dedicated microcontroller for doing
+resource management. Any HLOS/firmware on compute clusters should
+load a firmware to this microcontroller before accessing any resource.
+This driver communicates with ROM for loading this firmware.
+
+Required properties:
+--------------------
+- compatible: Shall be: "ti,am654-system-controller"
+- mbox-names: "tx" for Transfer channel
+ "rx" for Receive channel
+- mboxes: Corresponding phandles to mailbox channels.
+
+
+Example:
+--------
+
+system-controller: system-controller {
+ compatible = "ti,am654-system-controller";
+ mboxes= <&secproxy 4>, <&secproxy 5>;
+ mbox-names = "tx", "rx";
+};
diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index becae5f85d..812d30153b 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -13,6 +13,15 @@ config REMOTEPROC
depends on DM
# Please keep the configuration alphabetically sorted.
+config K3_SYSTEM_CONTROLLER
+ bool "Support for TI' K3 System Controller"
+ select REMOTEPROC
+ depends on DM
+ depends on ARCH_K3
+ depends on OF_CONTROL
+ help
+ Say 'y' here to add support for TI' K3 System Controller.
+
config REMOTEPROC_SANDBOX
bool "Support for Test processor for Sandbox"
select REMOTEPROC
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index bda995e21b..bfd02ad52d 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -7,5 +7,6 @@
obj-$(CONFIG_REMOTEPROC) += rproc-uclass.o
# Remote proc drivers - Please keep this list alphabetically sorted.
+obj-$(CONFIG_K3_SYSTEM_CONTROLLER) += k3_system_controller.o
obj-$(CONFIG_REMOTEPROC_SANDBOX) += sandbox_testproc.o
obj-$(CONFIG_REMOTEPROC_TI_POWER) += ti_power_proc.o
diff --git a/drivers/remoteproc/k3_system_controller.c b/drivers/remoteproc/k3_system_controller.c
new file mode 100644
index 0000000000..3c316a1234
--- /dev/null
+++ b/drivers/remoteproc/k3_system_controller.c
@@ -0,0 +1,323 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments' K3 System Controller Driver
+ *
+ * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
+ * Lokesh Vutla <lokeshvutla@ti.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <remoteproc.h>
+#include <errno.h>
+#include <mailbox.h>
+#include <linux/soc/ti/k3-sec-proxy.h>
+
+#define K3_MSG_R5_TO_M3_M3FW 0x8105
+#define K3_MSG_M3_TO_R5_CERT_RESULT 0x8805
+#define K3_MSG_M3_TO_R5_BOOT_NOTIFICATION 0x000A
+
+#define K3_FLAGS_MSG_CERT_AUTH_PASS 0x555555
+#define K3_FLAGS_MSG_CERT_AUTH_FAIL 0xffffff
+
+/**
+ * struct k3_sysctrler_msg_hdr - Generic Header for Messages and responses.
+ * @cmd_id: Message ID. One of K3_MSG_*
+ * @host_id: Host ID of the message
+ * @seq_ne: Message identifier indicating a transfer sequence.
+ * @flags: Flags for the message.
+ */
+struct k3_sysctrler_msg_hdr {
+ u16 cmd_id;
+ u8 host_id;
+ u8 seq_nr;
+ u32 flags;
+} __attribute__ ((__packed__));
+
+/**
+ * struct k3_sysctrler_load_msg - Message format for Firmware loading
+ * @hdr: Generic message hdr
+ * @buffer_address: Address at which firmware is located.
+ * @buffer_size: Size of the firmware.
+ */
+struct k3_sysctrler_load_msg {
+ struct k3_sysctrler_msg_hdr hdr;
+ u32 buffer_address;
+ u32 buffer_size;
+} __attribute__ ((__packed__));
+
+/**
+ * struct k3_sysctrler_boot_notification_msg - Message format for boot
+ * notification
+ * @checksum: Checksum for the entire message
+ * @reserved: Reserved for future use.
+ * @hdr: Generic message hdr
+ */
+struct k3_sysctrler_boot_notification_msg {
+ u16 checksum;
+ u16 reserved;
+ struct k3_sysctrler_msg_hdr hdr;
+} __attribute__ ((__packed__));
+
+/**
+ * struct k3_sysctrler_desc - Description of SoC integration.
+ * @host_id: Host identifier representing the compute entity
+ * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds)
+ * @max_msg_size: Maximum size of data per message that can be handled.
+ */
+struct k3_sysctrler_desc {
+ u8 host_id;
+ int max_rx_timeout_us;
+ int max_msg_size;
+};
+
+/**
+ * struct k3_sysctrler_privdata - Structure representing System Controller data.
+ * @chan_tx: Transmit mailbox channel
+ * @chan_rx: Receive mailbox channel
+ * @desc: SoC description for this instance
+ * @seq_nr: Counter for number of messages sent.
+ */
+struct k3_sysctrler_privdata {
+ struct mbox_chan chan_tx;
+ struct mbox_chan chan_rx;
+ struct k3_sysctrler_desc *desc;
+ u32 seq_nr;
+};
+
+static inline
+void k3_sysctrler_load_msg_setup(struct k3_sysctrler_load_msg *fw,
+ struct k3_sysctrler_privdata *priv,
+ ulong addr, ulong size)
+{
+ fw->hdr.cmd_id = K3_MSG_R5_TO_M3_M3FW;
+ fw->hdr.host_id = priv->desc->host_id;
+ fw->hdr.seq_nr = priv->seq_nr++;
+ fw->hdr.flags = 0x0;
+ fw->buffer_address = addr;
+ fw->buffer_size = size;
+}
+
+static int k3_sysctrler_load_response(u32 *buf)
+{
+ struct k3_sysctrler_load_msg *fw;
+
+ fw = (struct k3_sysctrler_load_msg *)buf;
+
+ /* Check for proper response ID */
+ if (fw->hdr.cmd_id != K3_MSG_M3_TO_R5_CERT_RESULT) {
+ dev_err(dev, "%s: Command expected 0x%x, but received 0x%x\n",
+ __func__, K3_MSG_M3_TO_R5_CERT_RESULT, fw->hdr.cmd_id);
+ return -EINVAL;
+ }
+
+ /* Check for certificate authentication result */
+ if (fw->hdr.flags == K3_FLAGS_MSG_CERT_AUTH_FAIL) {
+ dev_err(dev, "%s: Firmware certificate authentication failed\n",
+ __func__);
+ return -EINVAL;
+ } else if (fw->hdr.flags != K3_FLAGS_MSG_CERT_AUTH_PASS) {
+ dev_err(dev, "%s: Firmware Load response Invalid %d\n",
+ __func__, fw->hdr.flags);
+ return -EINVAL;
+ }
+
+ debug("%s: Firmware authentication passed\n", __func__);
+
+ return 0;
+}
+
+static int k3_sysctrler_boot_notification_response(u32 *buf)
+{
+ struct k3_sysctrler_boot_notification_msg *boot;
+
+ boot = (struct k3_sysctrler_boot_notification_msg *)buf;
+
+ /* ToDo: Verify checksum */
+
+ /* Check for proper response ID */
+ if (boot->hdr.cmd_id != K3_MSG_M3_TO_R5_BOOT_NOTIFICATION) {
+ dev_err(dev, "%s: Command expected 0x%x, but received 0x%x\n",
+ __func__, K3_MSG_M3_TO_R5_BOOT_NOTIFICATION,
+ boot->hdr.cmd_id);
+ return -EINVAL;
+ }
+
+ debug("%s: Boot notification received\n", __func__);
+
+ return 0;
+}
+
+/**
+ * k3_sysctrler_load() - Loadup the K3 remote processor
+ * @dev: corresponding K3 remote processor device
+ * @addr: Address in memory where image binary is stored
+ * @size: Size in bytes of the image binary
+ *
+ * Return: 0 if all goes good, else appropriate error message.
+ */
+static int k3_sysctrler_load(struct udevice *dev, ulong addr, ulong size)
+{
+ struct k3_sysctrler_privdata *priv = dev_get_priv(dev);
+ struct k3_sysctrler_load_msg firmware;
+ struct k3_sec_proxy_msg msg;
+ int ret;
+
+ debug("%s: Loading binary from 0x%08lX, size 0x%08lX\n",
+ __func__, addr, size);
+
+ memset(&firmware, 0, sizeof(firmware));
+ memset(&msg, 0, sizeof(msg));
+
+ /* Setup the message */
+ k3_sysctrler_load_msg_setup(&firmware, priv, addr, size);
+ msg.len = sizeof(firmware);
+ msg.buf = (u32 *)&firmware;
+
+ /* Send the message */
+ ret = mbox_send(&priv->chan_tx, &msg);
+ if (ret) {
+ dev_err(dev, "%s: Firmware Loading failed. ret = %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ /* Receive the response */
+ ret = mbox_recv(&priv->chan_rx, &msg, priv->desc->max_rx_timeout_us);
+ if (ret) {
+ dev_err(dev, "%s: Firmware Load response failed. ret = %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ /* Process the response */
+ ret = k3_sysctrler_load_response(msg.buf);
+ if (ret)
+ return ret;
+
+ debug("%s: Firmware Loaded successfully on dev %s\n",
+ __func__, dev->name);
+
+ return 0;
+}
+
+/**
+ * k3_sysctrler_start() - Start the remote processor
+ * Note that while technically the K3 system controller starts up
+ * automatically after its firmware got loaded we still want to
+ * utilize the rproc start operation for other startup-related
+ * tasks.
+ * @dev: device to operate upon
+ *
+ * Return: 0 if all went ok, else return appropriate error
+ */
+static int k3_sysctrler_start(struct udevice *dev)
+{
+ struct k3_sysctrler_privdata *priv = dev_get_priv(dev);
+ struct k3_sec_proxy_msg msg;
+ int ret;
+
+ debug("%s(dev=%p)\n", __func__, dev);
+
+ /* Receive the boot notification. Note that it is sent only once. */
+ ret = mbox_recv(&priv->chan_rx, &msg, priv->desc->max_rx_timeout_us);
+ if (ret) {
+ dev_err(dev, "%s: Boot Notification response failed. ret = %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ /* Process the response */
+ ret = k3_sysctrler_boot_notification_response(msg.buf);
+ if (ret)
+ return ret;
+
+ debug("%s: Boot notification received successfully on dev %s\n",
+ __func__, dev->name);
+
+ return 0;
+}
+
+static const struct dm_rproc_ops k3_sysctrler_ops = {
+ .load = k3_sysctrler_load,
+ .start = k3_sysctrler_start,
+};
+
+/**
+ * k3_of_to_priv() - generate private data from device tree
+ * @dev: corresponding k3 remote processor device
+ * @priv: pointer to driver specific private data
+ *
+ * Return: 0 if all goes good, else appropriate error message.
+ */
+static int k3_of_to_priv(struct udevice *dev,
+ struct k3_sysctrler_privdata *priv)
+{
+ int ret;
+
+ ret = mbox_get_by_name(dev, "tx", &priv->chan_tx);
+ if (ret) {
+ dev_err(dev, "%s: Acquiring Tx channel failed. ret = %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ ret = mbox_get_by_name(dev, "rx", &priv->chan_rx);
+ if (ret) {
+ dev_err(dev, "%s: Acquiring Rx channel failed. ret = %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/**
+ * k3_sysctrler_probe() - Basic probe
+ * @dev: corresponding k3 remote processor device
+ *
+ * Return: 0 if all goes good, else appropriate error message.
+ */
+static int k3_sysctrler_probe(struct udevice *dev)
+{
+ struct k3_sysctrler_privdata *priv;
+ int ret;
+
+ debug("%s(dev=%p)\n", __func__, dev);
+
+ priv = dev_get_priv(dev);
+
+ ret = k3_of_to_priv(dev, priv);
+ if (ret) {
+ dev_err(dev, "%s: Probe failed with error %d\n", __func__, ret);
+ return ret;
+ }
+
+ priv->desc = (void *)dev_get_driver_data(dev);
+ priv->seq_nr = 0;
+
+ return 0;
+}
+
+static const struct k3_sysctrler_desc k3_sysctrler_am654_desc = {
+ .host_id = 4, /* HOST_ID_R5_1 */
+ .max_rx_timeout_us = 400000,
+ .max_msg_size = 60,
+};
+
+static const struct udevice_id k3_sysctrler_ids[] = {
+ {
+ .compatible = "ti,am654-system-controller",
+ .data = (ulong)&k3_sysctrler_am654_desc,
+ },
+ {}
+};
+
+U_BOOT_DRIVER(k3_sysctrler) = {
+ .name = "k3_system_controller",
+ .of_match = k3_sysctrler_ids,
+ .id = UCLASS_REMOTEPROC,
+ .ops = &k3_sysctrler_ops,
+ .probe = k3_sysctrler_probe,
+ .priv_auto_alloc_size = sizeof(struct k3_sysctrler_privdata),
+};
--
2.18.0
next prev parent reply other threads:[~2018-08-21 14:31 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 14:31 [U-Boot] [PATCH 00/25] [2/3] Initial support Texas Instrument's AM654 Platform Lokesh Vutla
2018-08-21 14:31 ` [U-Boot] [PATCH 01/25] firmware: Add basic support for TI System Control Interface (TI SCI) protocol Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-24 15:00 ` Lokesh Vutla
2018-08-21 14:31 ` [U-Boot] [PATCH 02/25] firmware: ti_sci: Add support for board configuration Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 03/25] firmware: ti_sci: Add support for device control Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 04/25] firmware: ti_sci: Add support for clock control Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 05/25] firmware: ti_sci: Add support for reboot core service Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 06/25] firmware: ti_sci: Add support for processor control services Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 07/25] dm: firmware: Automatically bind child devices Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 08/25] dm: reset: Update uclass to allow querying reset status Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 09/25] reset: Extend reset control with an optional data field Lokesh Vutla
2018-08-24 14:11 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 10/25] reset: Introduce TI System Control Interface (TI SCI) reset driver Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 11/25] clk: Allow clock defaults to be set also during re-reloc state Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-24 14:42 ` Dr. Philipp Tomsich
2018-08-24 15:54 ` Andreas Dannenberg
2018-08-24 16:00 ` Dr. Philipp Tomsich
2018-08-24 16:28 ` Andreas Dannenberg
2018-08-27 3:26 ` Kever Yang
2018-08-27 16:06 ` Andreas Dannenberg
2018-08-28 9:12 ` Lokesh Vutla
2018-08-27 6:02 ` Lokesh Vutla
2018-08-21 14:31 ` [U-Boot] [PATCH 12/25] clk: Extend clock control with an optional data field Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 13/25] clk: Introduce TI System Control Interface (TI SCI) clock driver Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 14/25] power domain: Add support for multiple powerdomains per device Lokesh Vutla
2018-08-22 9:21 ` Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 15/25] power domain: Introduce TI System Control Interface (TI SCI) power domain driver Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 16/25] sysreset: Add TI System Control Interface (TI SCI) sysreset driver Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 17/25] mailbox: Allow attaching private data for mbox_chan Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 18/25] mailbox: Introduce K3 Secure Proxy Driver Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 19/25] spl: Allow mailbox drivers to be used within SPL Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` [U-Boot] [PATCH 20/25] remoteproc: Allow for individual remoteproc initialization Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:31 ` Lokesh Vutla [this message]
2018-08-24 14:12 ` [U-Boot] [PATCH 21/25] remoteproc: Introduce K3 system controller Tom Rini
2018-08-24 15:02 ` Lokesh Vutla
2018-08-21 14:32 ` [U-Boot] [PATCH 22/25] remoteproc: Introduce K3 remoteproc driver Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:32 ` [U-Boot] [PATCH 23/25] spl: Allow remoteproc drivers to be used within SPL Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:32 ` [U-Boot] [PATCH 24/25] mmc: k3_arasan: Add sdhci driver support for K3 family SoCs Lokesh Vutla
2018-08-24 14:12 ` Tom Rini
2018-08-21 14:32 ` [U-Boot] [PATCH 25/25] gpio: do not include <asm/arch/gpio.h> for ARCH_K3 Lokesh Vutla
2018-08-24 14:13 ` Tom Rini
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=20180821143203.29142-22-lokeshvutla@ti.com \
--to=lokeshvutla@ti.com \
--cc=u-boot@lists.denx.de \
/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