linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniele Alessandrelli <daniele.alessandrelli@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	Daniele Alessandrelli <daniele.alessandrelli@intel.com>,
	Paul J Murphy <paul.j.murphy@intel.com>
Subject: [PATCH 1/1] soc: keembay: Add Keem Bay IMR driver
Date: Tue, 21 Apr 2020 17:36:18 +0100	[thread overview]
Message-ID: <13ca92165fab2827b6d439661e75f5b91ef083c2.1587485099.git.daniele.alessandrelli@intel.com> (raw)
In-Reply-To: <cover.1587485099.git.daniele.alessandrelli@intel.com>

From: Daniele Alessandrelli <daniele.alessandrelli@intel.com>

Keem Bay bootloader sets up a temporary Isolated Memory Region (IMR) to
protect itself during pre-Linux boot.

This temporary IMR remains active even when control is passed to the
Linux Kernel. It is Kernel responsibility to remove such an IMR during
initialization.

This driver adds such functionality.

The driver is loaded during `early_init`, which should ensure that the
IMR is removed before devices that may try to access the IMR are
initialized.

Signed-off-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
---
 MAINTAINERS                       |  5 ++++
 drivers/soc/Kconfig               |  1 +
 drivers/soc/Makefile              |  1 +
 drivers/soc/keembay/Kconfig       | 22 +++++++++++++++++
 drivers/soc/keembay/Makefile      |  5 ++++
 drivers/soc/keembay/keembay-imr.c | 40 +++++++++++++++++++++++++++++++
 6 files changed, 74 insertions(+)
 create mode 100644 drivers/soc/keembay/Kconfig
 create mode 100644 drivers/soc/keembay/Makefile
 create mode 100644 drivers/soc/keembay/keembay-imr.c

diff --git a/MAINTAINERS b/MAINTAINERS
index b816a453b10e..59f1923a0f25 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9194,6 +9194,11 @@ S:	Maintained
 W:	http://lse.sourceforge.net/kdump/
 F:	Documentation/admin-guide/kdump/
 
+KEEMBAY IMR
+M:	Daniele Alessandrelli <daniele.alessandrelli@intel.com>
+S:	Maintained
+F:	drivers/soc/keembay/keembay-imr.c
+
 KEENE FM RADIO TRANSMITTER DRIVER
 M:	Hans Verkuil <hverkuil@xs4all.nl>
 L:	linux-media@vger.kernel.org
diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 425ab6f7e375..eeeba3ef7338 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -9,6 +9,7 @@ source "drivers/soc/bcm/Kconfig"
 source "drivers/soc/fsl/Kconfig"
 source "drivers/soc/imx/Kconfig"
 source "drivers/soc/ixp4xx/Kconfig"
+source "drivers/soc/keembay/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/renesas/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 36452bed86ef..65c981207283 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -13,6 +13,7 @@ obj-y				+= fsl/
 obj-$(CONFIG_ARCH_GEMINI)	+= gemini/
 obj-y				+= imx/
 obj-$(CONFIG_ARCH_IXP4XX)	+= ixp4xx/
+obj-y				+= keembay/
 obj-$(CONFIG_SOC_XWAY)		+= lantiq/
 obj-y				+= mediatek/
 obj-y				+= amlogic/
diff --git a/drivers/soc/keembay/Kconfig b/drivers/soc/keembay/Kconfig
new file mode 100644
index 000000000000..2161bce131b3
--- /dev/null
+++ b/drivers/soc/keembay/Kconfig
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Keem Bay SoC drivers.
+#
+
+menu "Keem Bay SoC drivers"
+
+config KEEMBAY_IMR
+	bool "Clean-up Keem Bay bootloader IMR at boot"
+	depends on ARM64
+	help
+	  This option makes the Kernel clean up the Isolated Memory Region
+	  (IMR) set up by Keem Bay bootloader (U-boot) to protect itself during
+	  early boot.
+
+	  The IMR number to be cleaned up is taken from the device tree
+	  (property 'u-boot-imr' of the 'chosen' node).
+
+	  If you are compiling the Kernel for a Keem Bay SoC select Y,
+	  otherwise select N.
+
+endmenu
diff --git a/drivers/soc/keembay/Makefile b/drivers/soc/keembay/Makefile
new file mode 100644
index 000000000000..dacfdb9f5fc1
--- /dev/null
+++ b/drivers/soc/keembay/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for Keem Bay SoC drivers.
+#
+obj-$(CONFIG_KEEMBAY_IMR) += keembay-imr.o
diff --git a/drivers/soc/keembay/keembay-imr.c b/drivers/soc/keembay/keembay-imr.c
new file mode 100644
index 000000000000..eabbdd6e69a7
--- /dev/null
+++ b/drivers/soc/keembay/keembay-imr.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2019-2020 Intel Corporation
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/arm-smccc.h>
+#include <linux/init.h>
+#include <linux/of.h>
+#include <linux/printk.h>
+#include <linux/types.h>
+
+/* Keem Bay SiP SVC for clearing an IMR. */
+#define KMB_SIP_SVC_IMR_CLEAR	0x8200ff13
+
+static int __init clear_imr(u64 imr)
+{
+	struct arm_smccc_res res = { 0 };
+
+	arm_smccc_smc(KMB_SIP_SVC_IMR_CLEAR, imr, 0, 0, 0, 0, 0, 0, &res);
+
+	return res.a0;
+}
+
+static int __init kmb_imr_init(void)
+{
+	u32 imr;
+	int rc;
+
+	rc = of_property_read_u32(of_chosen, "u-boot-imr", &imr);
+	if (rc) {
+		pr_warn("Skipping IMR clean-up: No U-Boot IMR defined in device tree\n");
+		return 0;
+	}
+	pr_info("Disabling Keem Bay U-boot IMR: %u\n", imr);
+
+	return clear_imr(imr);
+}
+early_initcall(kmb_imr_init);
-- 
2.21.1


  reply	other threads:[~2020-04-21 16:36 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 16:36 [PATCH 0/1] Add IMR driver for Keem Bay Daniele Alessandrelli
2020-04-21 16:36 ` Daniele Alessandrelli [this message]
2020-05-01  8:10   ` [PATCH 1/1] soc: keembay: Add Keem Bay IMR driver Greg Kroah-Hartman
2020-05-01 11:50     ` Daniele Alessandrelli
2020-05-01 11:59       ` Greg Kroah-Hartman
2020-05-24 21:28       ` Pavel Machek
2020-05-25  8:18         ` Arnd Bergmann
2020-05-27 13:31           ` Alessandrelli, Daniele
2020-05-27 14:33             ` Arnd Bergmann
2020-05-27 17:43               ` Daniele Alessandrelli
2020-05-27 18:59                 ` Arnd Bergmann
2020-05-28 12:27                   ` Daniele Alessandrelli
2020-05-28 11:22             ` Pavel Machek
2020-05-28 13:00               ` Daniele Alessandrelli
2020-05-07 17:44   ` Pavel Machek
2020-04-30 19:49 ` [PATCH 0/1] Add IMR driver for Keem Bay Alessandrelli, Daniele
2020-05-01  7:09   ` gregkh
2020-05-01  7:53     ` Daniele Alessandrelli
2020-05-01  8:04       ` gregkh

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=13ca92165fab2827b6d439661e75f5b91ef083c2.1587485099.git.daniele.alessandrelli@intel.com \
    --to=daniele.alessandrelli@linux.intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=daniele.alessandrelli@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.j.murphy@intel.com \
    --cc=robh@kernel.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;
as well as URLs for NNTP newsgroup(s).