All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Add Amlogic secure monitor driver
@ 2016-05-18 14:56 ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Carlo Caione

From: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>

In the Amlogic SoCs the secure monitor calls are used for a lot of reasons:
interact with the NVMEM (efuses), check the reboot reason, set USB boot, ...

This driver defines a generic interface towards the secure monitor that can be
used by more specialized drivers to interact with the secure monitor itself
without worrying about bounce buffers managing.

Changelog:

v2:
  * All the SMC function identifiers are now in a SoC-specific header file to
    be included by the DTS files so the SMC commands are now defined in the DT
    instead to be hardcoded into the driver
  * Patchset is no longer an RFC
  * Better error management and boundary checking
  * s/unsigned int/u32/
  * SMC call not only on CPU 0
  * Fix memory leaking
  * s/amlogic/meson/ in the directory names

Carlo Caione (4):
  soc: Amlogic: Add secure monitor driver
  soc: dt-bindings: Add secure monitor header file for GXBB
  ARM64: dts: amlogic: gxbb: Enable secure monitor
  documentation: Add secure monitor binding documentation

 .../devicetree/bindings/soc/meson/meson_sm.txt     |  45 ++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |   7 +
 drivers/soc/Kconfig                                |   1 +
 drivers/soc/Makefile                               |   1 +
 drivers/soc/meson/Kconfig                          |   8 ++
 drivers/soc/meson/Makefile                         |   1 +
 drivers/soc/meson/meson_sm.c                       | 155 +++++++++++++++++++++
 include/dt-bindings/soc/meson-gxbb-sm.h            |  44 ++++++
 include/linux/soc/meson/meson_sm.h                 |  22 +++
 9 files changed, 284 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt
 create mode 100644 drivers/soc/meson/Kconfig
 create mode 100644 drivers/soc/meson/Makefile
 create mode 100644 drivers/soc/meson/meson_sm.c
 create mode 100644 include/dt-bindings/soc/meson-gxbb-sm.h
 create mode 100644 include/linux/soc/meson/meson_sm.h

-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 0/4] Add Amlogic secure monitor driver
@ 2016-05-18 14:56 ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Carlo Caione <carlo@endlessm.com>

In the Amlogic SoCs the secure monitor calls are used for a lot of reasons:
interact with the NVMEM (efuses), check the reboot reason, set USB boot, ...

This driver defines a generic interface towards the secure monitor that can be
used by more specialized drivers to interact with the secure monitor itself
without worrying about bounce buffers managing.

Changelog:

v2:
  * All the SMC function identifiers are now in a SoC-specific header file to
    be included by the DTS files so the SMC commands are now defined in the DT
    instead to be hardcoded into the driver
  * Patchset is no longer an RFC
  * Better error management and boundary checking
  * s/unsigned int/u32/
  * SMC call not only on CPU 0
  * Fix memory leaking
  * s/amlogic/meson/ in the directory names

Carlo Caione (4):
  soc: Amlogic: Add secure monitor driver
  soc: dt-bindings: Add secure monitor header file for GXBB
  ARM64: dts: amlogic: gxbb: Enable secure monitor
  documentation: Add secure monitor binding documentation

 .../devicetree/bindings/soc/meson/meson_sm.txt     |  45 ++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |   7 +
 drivers/soc/Kconfig                                |   1 +
 drivers/soc/Makefile                               |   1 +
 drivers/soc/meson/Kconfig                          |   8 ++
 drivers/soc/meson/Makefile                         |   1 +
 drivers/soc/meson/meson_sm.c                       | 155 +++++++++++++++++++++
 include/dt-bindings/soc/meson-gxbb-sm.h            |  44 ++++++
 include/linux/soc/meson/meson_sm.h                 |  22 +++
 9 files changed, 284 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt
 create mode 100644 drivers/soc/meson/Kconfig
 create mode 100644 drivers/soc/meson/Makefile
 create mode 100644 drivers/soc/meson/meson_sm.c
 create mode 100644 include/dt-bindings/soc/meson-gxbb-sm.h
 create mode 100644 include/linux/soc/meson/meson_sm.h

-- 
2.7.4

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 0/4] Add Amlogic secure monitor driver
@ 2016-05-18 14:56 ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linus-amlogic

From: Carlo Caione <carlo@endlessm.com>

In the Amlogic SoCs the secure monitor calls are used for a lot of reasons:
interact with the NVMEM (efuses), check the reboot reason, set USB boot, ...

This driver defines a generic interface towards the secure monitor that can be
used by more specialized drivers to interact with the secure monitor itself
without worrying about bounce buffers managing.

Changelog:

v2:
  * All the SMC function identifiers are now in a SoC-specific header file to
    be included by the DTS files so the SMC commands are now defined in the DT
    instead to be hardcoded into the driver
  * Patchset is no longer an RFC
  * Better error management and boundary checking
  * s/unsigned int/u32/
  * SMC call not only on CPU 0
  * Fix memory leaking
  * s/amlogic/meson/ in the directory names

Carlo Caione (4):
  soc: Amlogic: Add secure monitor driver
  soc: dt-bindings: Add secure monitor header file for GXBB
  ARM64: dts: amlogic: gxbb: Enable secure monitor
  documentation: Add secure monitor binding documentation

 .../devicetree/bindings/soc/meson/meson_sm.txt     |  45 ++++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |   7 +
 drivers/soc/Kconfig                                |   1 +
 drivers/soc/Makefile                               |   1 +
 drivers/soc/meson/Kconfig                          |   8 ++
 drivers/soc/meson/Makefile                         |   1 +
 drivers/soc/meson/meson_sm.c                       | 155 +++++++++++++++++++++
 include/dt-bindings/soc/meson-gxbb-sm.h            |  44 ++++++
 include/linux/soc/meson/meson_sm.h                 |  22 +++
 9 files changed, 284 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt
 create mode 100644 drivers/soc/meson/Kconfig
 create mode 100644 drivers/soc/meson/Makefile
 create mode 100644 drivers/soc/meson/meson_sm.c
 create mode 100644 include/dt-bindings/soc/meson-gxbb-sm.h
 create mode 100644 include/linux/soc/meson/meson_sm.h

-- 
2.7.4

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
  2016-05-18 14:56 ` Carlo Caione
  (?)
@ 2016-05-18 14:56     ` Carlo Caione
  -1 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Carlo Caione

From: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>

Introduce a driver to provide calls into secure monitor mode.

In the Amlogic SoCs these calls are used for multiple reasons: access to
NVMEM, set USB boot, enable JTAG, etc...

Signed-off-by: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
---
 drivers/soc/Kconfig                |   1 +
 drivers/soc/Makefile               |   1 +
 drivers/soc/meson/Kconfig          |   8 ++
 drivers/soc/meson/Makefile         |   1 +
 drivers/soc/meson/meson_sm.c       | 155 +++++++++++++++++++++++++++++++++++++
 include/linux/soc/meson/meson_sm.h |  22 ++++++
 6 files changed, 188 insertions(+)
 create mode 100644 drivers/soc/meson/Kconfig
 create mode 100644 drivers/soc/meson/Makefile
 create mode 100644 drivers/soc/meson/meson_sm.c
 create mode 100644 include/linux/soc/meson/meson_sm.h

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index cb58ef0..7e70b52 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -4,6 +4,7 @@ source "drivers/soc/bcm/Kconfig"
 source "drivers/soc/brcmstb/Kconfig"
 source "drivers/soc/fsl/qe/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
+source "drivers/soc/meson/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
 source "drivers/soc/samsung/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 5ade713..9024d2b 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_DOVE)		+= dove/
 obj-$(CONFIG_MACH_DOVE)		+= dove/
 obj-y				+= fsl/
 obj-$(CONFIG_ARCH_MEDIATEK)	+= mediatek/
+obj-$(CONFIG_ARCH_MESON)	+= meson/
 obj-$(CONFIG_ARCH_QCOM)		+= qcom/
 obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
 obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
diff --git a/drivers/soc/meson/Kconfig b/drivers/soc/meson/Kconfig
new file mode 100644
index 0000000..fff11a3
--- /dev/null
+++ b/drivers/soc/meson/Kconfig
@@ -0,0 +1,8 @@
+#
+# Amlogic Secure Monitor driver
+#
+config MESON_SM
+	bool
+	default ARCH_MESON
+	help
+	  Say y here to enable the Amlogic secure monitor driver
diff --git a/drivers/soc/meson/Makefile b/drivers/soc/meson/Makefile
new file mode 100644
index 0000000..9ab3884
--- /dev/null
+++ b/drivers/soc/meson/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MESON_SM) +=	meson_sm.o
diff --git a/drivers/soc/meson/meson_sm.c b/drivers/soc/meson/meson_sm.c
new file mode 100644
index 0000000..16f7e32
--- /dev/null
+++ b/drivers/soc/meson/meson_sm.c
@@ -0,0 +1,155 @@
+/*
+ * Amlogic Secure Monitor driver
+ *
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdarg.h>
+#include <asm/cacheflush.h>
+#include <asm/compiler.h>
+#include <linux/arm-smccc.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/smp.h>
+
+#include <linux/soc/meson/meson_sm.h>
+
+#define SM_MEM_SIZE	0x1000
+
+/*
+ * To read from / write to the secure monitor we use two bounce buffers. The
+ * physical addresses of the two buffers are obtained by querying the secure
+ * monitor itself.
+ */
+
+static u32 sm_phy_in_base;
+static u32 sm_phy_out_base;
+
+static void __iomem *sm_sharemem_in_base;
+static void __iomem *sm_sharemem_out_base;
+
+struct meson_sm_data {
+	u32 cmd;
+	u32 arg0;
+	u32 arg1;
+	u32 arg2;
+	u32 arg3;
+	u32 arg4;
+	u32 ret;
+};
+
+static void __meson_sm_call(void *info)
+{
+	struct meson_sm_data *data = info;
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(data->cmd,
+		      data->arg0, data->arg1, data->arg2,
+		      data->arg3, data->arg4, 0, 0, &res);
+	data->ret = res.a0;
+}
+
+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	struct meson_sm_data data;
+
+	data.cmd = cmd;
+	data.arg0 = arg0;
+	data.arg1 = arg1;
+	data.arg2 = arg2;
+	data.arg3 = arg3;
+	data.arg4 = arg4;
+	data.ret = 0;
+
+	__meson_sm_call(&data);
+
+	return data.ret;
+}
+
+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;
+
+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
+
+	if (!size || size > SM_MEM_SIZE)
+		return -EINVAL;
+
+	memcpy(buffer, sm_sharemem_out_base, size);
+	return size;
+}
+
+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
+			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;
+
+	if (b_size > SM_MEM_SIZE)
+		return -EINVAL;
+
+	memcpy(sm_sharemem_in_base, buffer, b_size);
+
+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
+
+	if (!size)
+		return -EINVAL;
+
+	return size;
+}
+
+static int meson_sm_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	int cmd_in, cmd_out;
+
+	if (of_property_read_u32(np, "amlogic,sm_cmd_input_base", &cmd_in))
+		return -EINVAL;
+
+	if (of_property_read_u32(np, "amlogic,sm_cmd_output_base", &cmd_out))
+		return -EINVAL;
+
+	sm_phy_in_base = meson_sm_call(cmd_in, 0, 0, 0, 0, 0);
+	sm_sharemem_in_base = ioremap_cache(sm_phy_in_base, SM_MEM_SIZE);
+	if (!sm_sharemem_in_base)
+		return -EINVAL;
+
+	sm_phy_out_base = meson_sm_call(cmd_out, 0, 0, 0, 0, 0);
+	sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE);
+	if (!sm_sharemem_out_base) {
+		iounmap(sm_sharemem_in_base);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id meson_sm_ids[] = {
+	{ .compatible = "amlogic,meson-sm" },
+	{ /* sentinel */},
+};
+MODULE_DEVICE_TABLE(of, meson_sm_ids);
+
+static struct platform_driver meson_sm_platform_driver = {
+	.probe	= meson_sm_probe,
+	.driver	= {
+		.name		= "secmon",
+		.of_match_table	= meson_sm_ids,
+	},
+};
+module_platform_driver(meson_sm_platform_driver);
+
+MODULE_AUTHOR("Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>");
+MODULE_DESCRIPTION("Amlogic secure monitor driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/soc/meson/meson_sm.h b/include/linux/soc/meson/meson_sm.h
new file mode 100644
index 0000000..6ff8317
--- /dev/null
+++ b/include/linux/soc/meson/meson_sm.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_H_
+#define _MESON_SM_H_
+
+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, u32 arg2,
+		       u32 arg3, u32 arg4);
+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
+			u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+
+#endif /* _MESON_SM_H_ */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Carlo Caione <carlo@endlessm.com>

Introduce a driver to provide calls into secure monitor mode.

In the Amlogic SoCs these calls are used for multiple reasons: access to
NVMEM, set USB boot, enable JTAG, etc...

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 drivers/soc/Kconfig                |   1 +
 drivers/soc/Makefile               |   1 +
 drivers/soc/meson/Kconfig          |   8 ++
 drivers/soc/meson/Makefile         |   1 +
 drivers/soc/meson/meson_sm.c       | 155 +++++++++++++++++++++++++++++++++++++
 include/linux/soc/meson/meson_sm.h |  22 ++++++
 6 files changed, 188 insertions(+)
 create mode 100644 drivers/soc/meson/Kconfig
 create mode 100644 drivers/soc/meson/Makefile
 create mode 100644 drivers/soc/meson/meson_sm.c
 create mode 100644 include/linux/soc/meson/meson_sm.h

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index cb58ef0..7e70b52 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -4,6 +4,7 @@ source "drivers/soc/bcm/Kconfig"
 source "drivers/soc/brcmstb/Kconfig"
 source "drivers/soc/fsl/qe/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
+source "drivers/soc/meson/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
 source "drivers/soc/samsung/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 5ade713..9024d2b 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_DOVE)		+= dove/
 obj-$(CONFIG_MACH_DOVE)		+= dove/
 obj-y				+= fsl/
 obj-$(CONFIG_ARCH_MEDIATEK)	+= mediatek/
+obj-$(CONFIG_ARCH_MESON)	+= meson/
 obj-$(CONFIG_ARCH_QCOM)		+= qcom/
 obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
 obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
diff --git a/drivers/soc/meson/Kconfig b/drivers/soc/meson/Kconfig
new file mode 100644
index 0000000..fff11a3
--- /dev/null
+++ b/drivers/soc/meson/Kconfig
@@ -0,0 +1,8 @@
+#
+# Amlogic Secure Monitor driver
+#
+config MESON_SM
+	bool
+	default ARCH_MESON
+	help
+	  Say y here to enable the Amlogic secure monitor driver
diff --git a/drivers/soc/meson/Makefile b/drivers/soc/meson/Makefile
new file mode 100644
index 0000000..9ab3884
--- /dev/null
+++ b/drivers/soc/meson/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MESON_SM) +=	meson_sm.o
diff --git a/drivers/soc/meson/meson_sm.c b/drivers/soc/meson/meson_sm.c
new file mode 100644
index 0000000..16f7e32
--- /dev/null
+++ b/drivers/soc/meson/meson_sm.c
@@ -0,0 +1,155 @@
+/*
+ * Amlogic Secure Monitor driver
+ *
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo@endlessm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdarg.h>
+#include <asm/cacheflush.h>
+#include <asm/compiler.h>
+#include <linux/arm-smccc.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/smp.h>
+
+#include <linux/soc/meson/meson_sm.h>
+
+#define SM_MEM_SIZE	0x1000
+
+/*
+ * To read from / write to the secure monitor we use two bounce buffers. The
+ * physical addresses of the two buffers are obtained by querying the secure
+ * monitor itself.
+ */
+
+static u32 sm_phy_in_base;
+static u32 sm_phy_out_base;
+
+static void __iomem *sm_sharemem_in_base;
+static void __iomem *sm_sharemem_out_base;
+
+struct meson_sm_data {
+	u32 cmd;
+	u32 arg0;
+	u32 arg1;
+	u32 arg2;
+	u32 arg3;
+	u32 arg4;
+	u32 ret;
+};
+
+static void __meson_sm_call(void *info)
+{
+	struct meson_sm_data *data = info;
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(data->cmd,
+		      data->arg0, data->arg1, data->arg2,
+		      data->arg3, data->arg4, 0, 0, &res);
+	data->ret = res.a0;
+}
+
+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	struct meson_sm_data data;
+
+	data.cmd = cmd;
+	data.arg0 = arg0;
+	data.arg1 = arg1;
+	data.arg2 = arg2;
+	data.arg3 = arg3;
+	data.arg4 = arg4;
+	data.ret = 0;
+
+	__meson_sm_call(&data);
+
+	return data.ret;
+}
+
+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;
+
+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
+
+	if (!size || size > SM_MEM_SIZE)
+		return -EINVAL;
+
+	memcpy(buffer, sm_sharemem_out_base, size);
+	return size;
+}
+
+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
+			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;
+
+	if (b_size > SM_MEM_SIZE)
+		return -EINVAL;
+
+	memcpy(sm_sharemem_in_base, buffer, b_size);
+
+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
+
+	if (!size)
+		return -EINVAL;
+
+	return size;
+}
+
+static int meson_sm_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	int cmd_in, cmd_out;
+
+	if (of_property_read_u32(np, "amlogic,sm_cmd_input_base", &cmd_in))
+		return -EINVAL;
+
+	if (of_property_read_u32(np, "amlogic,sm_cmd_output_base", &cmd_out))
+		return -EINVAL;
+
+	sm_phy_in_base = meson_sm_call(cmd_in, 0, 0, 0, 0, 0);
+	sm_sharemem_in_base = ioremap_cache(sm_phy_in_base, SM_MEM_SIZE);
+	if (!sm_sharemem_in_base)
+		return -EINVAL;
+
+	sm_phy_out_base = meson_sm_call(cmd_out, 0, 0, 0, 0, 0);
+	sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE);
+	if (!sm_sharemem_out_base) {
+		iounmap(sm_sharemem_in_base);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id meson_sm_ids[] = {
+	{ .compatible = "amlogic,meson-sm" },
+	{ /* sentinel */},
+};
+MODULE_DEVICE_TABLE(of, meson_sm_ids);
+
+static struct platform_driver meson_sm_platform_driver = {
+	.probe	= meson_sm_probe,
+	.driver	= {
+		.name		= "secmon",
+		.of_match_table	= meson_sm_ids,
+	},
+};
+module_platform_driver(meson_sm_platform_driver);
+
+MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
+MODULE_DESCRIPTION("Amlogic secure monitor driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/soc/meson/meson_sm.h b/include/linux/soc/meson/meson_sm.h
new file mode 100644
index 0000000..6ff8317
--- /dev/null
+++ b/include/linux/soc/meson/meson_sm.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo@endlessm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_H_
+#define _MESON_SM_H_
+
+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, u32 arg2,
+		       u32 arg3, u32 arg4);
+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
+			u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+
+#endif /* _MESON_SM_H_ */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linus-amlogic

From: Carlo Caione <carlo@endlessm.com>

Introduce a driver to provide calls into secure monitor mode.

In the Amlogic SoCs these calls are used for multiple reasons: access to
NVMEM, set USB boot, enable JTAG, etc...

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 drivers/soc/Kconfig                |   1 +
 drivers/soc/Makefile               |   1 +
 drivers/soc/meson/Kconfig          |   8 ++
 drivers/soc/meson/Makefile         |   1 +
 drivers/soc/meson/meson_sm.c       | 155 +++++++++++++++++++++++++++++++++++++
 include/linux/soc/meson/meson_sm.h |  22 ++++++
 6 files changed, 188 insertions(+)
 create mode 100644 drivers/soc/meson/Kconfig
 create mode 100644 drivers/soc/meson/Makefile
 create mode 100644 drivers/soc/meson/meson_sm.c
 create mode 100644 include/linux/soc/meson/meson_sm.h

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index cb58ef0..7e70b52 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -4,6 +4,7 @@ source "drivers/soc/bcm/Kconfig"
 source "drivers/soc/brcmstb/Kconfig"
 source "drivers/soc/fsl/qe/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
+source "drivers/soc/meson/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
 source "drivers/soc/samsung/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 5ade713..9024d2b 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_DOVE)		+= dove/
 obj-$(CONFIG_MACH_DOVE)		+= dove/
 obj-y				+= fsl/
 obj-$(CONFIG_ARCH_MEDIATEK)	+= mediatek/
+obj-$(CONFIG_ARCH_MESON)	+= meson/
 obj-$(CONFIG_ARCH_QCOM)		+= qcom/
 obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
 obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
diff --git a/drivers/soc/meson/Kconfig b/drivers/soc/meson/Kconfig
new file mode 100644
index 0000000..fff11a3
--- /dev/null
+++ b/drivers/soc/meson/Kconfig
@@ -0,0 +1,8 @@
+#
+# Amlogic Secure Monitor driver
+#
+config MESON_SM
+	bool
+	default ARCH_MESON
+	help
+	  Say y here to enable the Amlogic secure monitor driver
diff --git a/drivers/soc/meson/Makefile b/drivers/soc/meson/Makefile
new file mode 100644
index 0000000..9ab3884
--- /dev/null
+++ b/drivers/soc/meson/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_MESON_SM) +=	meson_sm.o
diff --git a/drivers/soc/meson/meson_sm.c b/drivers/soc/meson/meson_sm.c
new file mode 100644
index 0000000..16f7e32
--- /dev/null
+++ b/drivers/soc/meson/meson_sm.c
@@ -0,0 +1,155 @@
+/*
+ * Amlogic Secure Monitor driver
+ *
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo@endlessm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdarg.h>
+#include <asm/cacheflush.h>
+#include <asm/compiler.h>
+#include <linux/arm-smccc.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/smp.h>
+
+#include <linux/soc/meson/meson_sm.h>
+
+#define SM_MEM_SIZE	0x1000
+
+/*
+ * To read from / write to the secure monitor we use two bounce buffers. The
+ * physical addresses of the two buffers are obtained by querying the secure
+ * monitor itself.
+ */
+
+static u32 sm_phy_in_base;
+static u32 sm_phy_out_base;
+
+static void __iomem *sm_sharemem_in_base;
+static void __iomem *sm_sharemem_out_base;
+
+struct meson_sm_data {
+	u32 cmd;
+	u32 arg0;
+	u32 arg1;
+	u32 arg2;
+	u32 arg3;
+	u32 arg4;
+	u32 ret;
+};
+
+static void __meson_sm_call(void *info)
+{
+	struct meson_sm_data *data = info;
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(data->cmd,
+		      data->arg0, data->arg1, data->arg2,
+		      data->arg3, data->arg4, 0, 0, &res);
+	data->ret = res.a0;
+}
+
+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	struct meson_sm_data data;
+
+	data.cmd = cmd;
+	data.arg0 = arg0;
+	data.arg1 = arg1;
+	data.arg2 = arg2;
+	data.arg3 = arg3;
+	data.arg4 = arg4;
+	data.ret = 0;
+
+	__meson_sm_call(&data);
+
+	return data.ret;
+}
+
+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;
+
+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
+
+	if (!size || size > SM_MEM_SIZE)
+		return -EINVAL;
+
+	memcpy(buffer, sm_sharemem_out_base, size);
+	return size;
+}
+
+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
+			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
+{
+	u32 size;
+
+	if (b_size > SM_MEM_SIZE)
+		return -EINVAL;
+
+	memcpy(sm_sharemem_in_base, buffer, b_size);
+
+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
+
+	if (!size)
+		return -EINVAL;
+
+	return size;
+}
+
+static int meson_sm_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	int cmd_in, cmd_out;
+
+	if (of_property_read_u32(np, "amlogic,sm_cmd_input_base", &cmd_in))
+		return -EINVAL;
+
+	if (of_property_read_u32(np, "amlogic,sm_cmd_output_base", &cmd_out))
+		return -EINVAL;
+
+	sm_phy_in_base = meson_sm_call(cmd_in, 0, 0, 0, 0, 0);
+	sm_sharemem_in_base = ioremap_cache(sm_phy_in_base, SM_MEM_SIZE);
+	if (!sm_sharemem_in_base)
+		return -EINVAL;
+
+	sm_phy_out_base = meson_sm_call(cmd_out, 0, 0, 0, 0, 0);
+	sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE);
+	if (!sm_sharemem_out_base) {
+		iounmap(sm_sharemem_in_base);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id meson_sm_ids[] = {
+	{ .compatible = "amlogic,meson-sm" },
+	{ /* sentinel */},
+};
+MODULE_DEVICE_TABLE(of, meson_sm_ids);
+
+static struct platform_driver meson_sm_platform_driver = {
+	.probe	= meson_sm_probe,
+	.driver	= {
+		.name		= "secmon",
+		.of_match_table	= meson_sm_ids,
+	},
+};
+module_platform_driver(meson_sm_platform_driver);
+
+MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
+MODULE_DESCRIPTION("Amlogic secure monitor driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/soc/meson/meson_sm.h b/include/linux/soc/meson/meson_sm.h
new file mode 100644
index 0000000..6ff8317
--- /dev/null
+++ b/include/linux/soc/meson/meson_sm.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo@endlessm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_H_
+#define _MESON_SM_H_
+
+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, u32 arg2,
+		       u32 arg3, u32 arg4);
+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
+			u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+
+#endif /* _MESON_SM_H_ */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 2/4] soc: dt-bindings: Add secure monitor header file for GXBB
  2016-05-18 14:56 ` Carlo Caione
  (?)
@ 2016-05-18 14:56     ` Carlo Caione
  -1 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Carlo Caione

From: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>

This patch adds the header file describing all the SMC function
identifiers for the Amlogic Meson GXBB SoC.

Signed-off-by: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
---
 include/dt-bindings/soc/meson-gxbb-sm.h | 44 +++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 include/dt-bindings/soc/meson-gxbb-sm.h

diff --git a/include/dt-bindings/soc/meson-gxbb-sm.h b/include/dt-bindings/soc/meson-gxbb-sm.h
new file mode 100644
index 0000000..b7d02df
--- /dev/null
+++ b/include/dt-bindings/soc/meson-gxbb-sm.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_GXBB_H_
+#define _MESON_SM_GXBB_H_
+
+#define SM_GET_SHARE_MEM_INPUT_BASE		0x82000020
+#define SM_GET_SHARE_MEM_OUTPUT_BASE		0x82000021
+#define SM_GET_REBOOT_REASON			0x82000022
+#define SM_GET_SHARE_STORAGE_IN_BASE		0x82000023
+#define SM_GET_SHARE_STORAGE_OUT_BASE		0x82000024
+#define SM_GET_SHARE_STORAGE_BLOCK_BASE		0x82000025
+#define SM_GET_SHARE_STORAGE_MESSAGE_BASE	0x82000026
+#define SM_GET_SHARE_STORAGE_BLOCK_SIZE		0x82000027
+#define SM_EFUSE_READ				0x82000030
+#define SM_EFUSE_WRITE				0x82000031
+#define SM_EFUSE_WRITE_PATTERN			0x82000032
+#define SM_EFUSE_USER_MAX			0x82000033
+#define SM_JTAG_ON				0x82000040
+#define SM_JTAG_OFF				0x82000041
+#define SM_SET_USB_BOOT_FUNC			0x82000043
+#define SM_SECURITY_KEY_QUERY			0x82000060
+#define SM_SECURITY_KEY_READ			0x82000061
+#define SM_SECURITY_KEY_WRITE			0x82000062
+#define SM_SECURITY_KEY_TELL			0x82000063
+#define SM_SECURITY_KEY_VERIFY			0x82000064
+#define SM_SECURITY_KEY_STATUS			0x82000065
+#define SM_SECURITY_KEY_NOTIFY			0x82000066
+#define SM_SECURITY_KEY_LIST			0x82000067
+#define SM_SECURITY_KEY_REMOVE			0x82000068
+#define SM_DEBUG_EFUSE_WRITE_PATTERN		0x820000F0
+#define SM_DEBUG_EFUSE_READ_PATTERN		0x820000F1
+#define SM_AML_DATA_PROCESS			0x820000FF
+
+#endif /* _MESON_SM_GXBB_H_ */
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 2/4] soc: dt-bindings: Add secure monitor header file for GXBB
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Carlo Caione <carlo@endlessm.com>

This patch adds the header file describing all the SMC function
identifiers for the Amlogic Meson GXBB SoC.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 include/dt-bindings/soc/meson-gxbb-sm.h | 44 +++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 include/dt-bindings/soc/meson-gxbb-sm.h

diff --git a/include/dt-bindings/soc/meson-gxbb-sm.h b/include/dt-bindings/soc/meson-gxbb-sm.h
new file mode 100644
index 0000000..b7d02df
--- /dev/null
+++ b/include/dt-bindings/soc/meson-gxbb-sm.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo@endlessm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_GXBB_H_
+#define _MESON_SM_GXBB_H_
+
+#define SM_GET_SHARE_MEM_INPUT_BASE		0x82000020
+#define SM_GET_SHARE_MEM_OUTPUT_BASE		0x82000021
+#define SM_GET_REBOOT_REASON			0x82000022
+#define SM_GET_SHARE_STORAGE_IN_BASE		0x82000023
+#define SM_GET_SHARE_STORAGE_OUT_BASE		0x82000024
+#define SM_GET_SHARE_STORAGE_BLOCK_BASE		0x82000025
+#define SM_GET_SHARE_STORAGE_MESSAGE_BASE	0x82000026
+#define SM_GET_SHARE_STORAGE_BLOCK_SIZE		0x82000027
+#define SM_EFUSE_READ				0x82000030
+#define SM_EFUSE_WRITE				0x82000031
+#define SM_EFUSE_WRITE_PATTERN			0x82000032
+#define SM_EFUSE_USER_MAX			0x82000033
+#define SM_JTAG_ON				0x82000040
+#define SM_JTAG_OFF				0x82000041
+#define SM_SET_USB_BOOT_FUNC			0x82000043
+#define SM_SECURITY_KEY_QUERY			0x82000060
+#define SM_SECURITY_KEY_READ			0x82000061
+#define SM_SECURITY_KEY_WRITE			0x82000062
+#define SM_SECURITY_KEY_TELL			0x82000063
+#define SM_SECURITY_KEY_VERIFY			0x82000064
+#define SM_SECURITY_KEY_STATUS			0x82000065
+#define SM_SECURITY_KEY_NOTIFY			0x82000066
+#define SM_SECURITY_KEY_LIST			0x82000067
+#define SM_SECURITY_KEY_REMOVE			0x82000068
+#define SM_DEBUG_EFUSE_WRITE_PATTERN		0x820000F0
+#define SM_DEBUG_EFUSE_READ_PATTERN		0x820000F1
+#define SM_AML_DATA_PROCESS			0x820000FF
+
+#endif /* _MESON_SM_GXBB_H_ */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 2/4] soc: dt-bindings: Add secure monitor header file for GXBB
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linus-amlogic

From: Carlo Caione <carlo@endlessm.com>

This patch adds the header file describing all the SMC function
identifiers for the Amlogic Meson GXBB SoC.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 include/dt-bindings/soc/meson-gxbb-sm.h | 44 +++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 include/dt-bindings/soc/meson-gxbb-sm.h

diff --git a/include/dt-bindings/soc/meson-gxbb-sm.h b/include/dt-bindings/soc/meson-gxbb-sm.h
new file mode 100644
index 0000000..b7d02df
--- /dev/null
+++ b/include/dt-bindings/soc/meson-gxbb-sm.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <carlo@endlessm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MESON_SM_GXBB_H_
+#define _MESON_SM_GXBB_H_
+
+#define SM_GET_SHARE_MEM_INPUT_BASE		0x82000020
+#define SM_GET_SHARE_MEM_OUTPUT_BASE		0x82000021
+#define SM_GET_REBOOT_REASON			0x82000022
+#define SM_GET_SHARE_STORAGE_IN_BASE		0x82000023
+#define SM_GET_SHARE_STORAGE_OUT_BASE		0x82000024
+#define SM_GET_SHARE_STORAGE_BLOCK_BASE		0x82000025
+#define SM_GET_SHARE_STORAGE_MESSAGE_BASE	0x82000026
+#define SM_GET_SHARE_STORAGE_BLOCK_SIZE		0x82000027
+#define SM_EFUSE_READ				0x82000030
+#define SM_EFUSE_WRITE				0x82000031
+#define SM_EFUSE_WRITE_PATTERN			0x82000032
+#define SM_EFUSE_USER_MAX			0x82000033
+#define SM_JTAG_ON				0x82000040
+#define SM_JTAG_OFF				0x82000041
+#define SM_SET_USB_BOOT_FUNC			0x82000043
+#define SM_SECURITY_KEY_QUERY			0x82000060
+#define SM_SECURITY_KEY_READ			0x82000061
+#define SM_SECURITY_KEY_WRITE			0x82000062
+#define SM_SECURITY_KEY_TELL			0x82000063
+#define SM_SECURITY_KEY_VERIFY			0x82000064
+#define SM_SECURITY_KEY_STATUS			0x82000065
+#define SM_SECURITY_KEY_NOTIFY			0x82000066
+#define SM_SECURITY_KEY_LIST			0x82000067
+#define SM_SECURITY_KEY_REMOVE			0x82000068
+#define SM_DEBUG_EFUSE_WRITE_PATTERN		0x820000F0
+#define SM_DEBUG_EFUSE_READ_PATTERN		0x820000F1
+#define SM_AML_DATA_PROCESS			0x820000FF
+
+#endif /* _MESON_SM_GXBB_H_ */
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 3/4] ARM64: dts: amlogic: gxbb: Enable secure monitor
  2016-05-18 14:56 ` Carlo Caione
  (?)
@ 2016-05-18 14:56     ` Carlo Caione
  -1 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Carlo Caione

From: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>

Add the secure monitor node in the Amlogic Meson GXBB DTSI file to
enable it.

Signed-off-by: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
index 76b3b6d..003e298 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
@@ -44,6 +44,7 @@
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/gpio/meson-gxbb-gpio.h>
+#include <dt-bindings/soc/meson-gxbb-sm.h>
 
 / {
 	compatible = "amlogic,meson-gxbb";
@@ -98,6 +99,12 @@
 		method = "smc";
 	};
 
+	sm {
+		compatible = "amlogic,meson-sm";
+		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
+		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 3/4] ARM64: dts: amlogic: gxbb: Enable secure monitor
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Carlo Caione <carlo@endlessm.com>

Add the secure monitor node in the Amlogic Meson GXBB DTSI file to
enable it.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
index 76b3b6d..003e298 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
@@ -44,6 +44,7 @@
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/gpio/meson-gxbb-gpio.h>
+#include <dt-bindings/soc/meson-gxbb-sm.h>
 
 / {
 	compatible = "amlogic,meson-gxbb";
@@ -98,6 +99,12 @@
 		method = "smc";
 	};
 
+	sm {
+		compatible = "amlogic,meson-sm";
+		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
+		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 3/4] ARM64: dts: amlogic: gxbb: Enable secure monitor
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linus-amlogic

From: Carlo Caione <carlo@endlessm.com>

Add the secure monitor node in the Amlogic Meson GXBB DTSI file to
enable it.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
index 76b3b6d..003e298 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
@@ -44,6 +44,7 @@
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/gpio/meson-gxbb-gpio.h>
+#include <dt-bindings/soc/meson-gxbb-sm.h>
 
 / {
 	compatible = "amlogic,meson-gxbb";
@@ -98,6 +99,12 @@
 		method = "smc";
 	};
 
+	sm {
+		compatible = "amlogic,meson-sm";
+		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
+		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 4/4] documentation: Add secure monitor binding documentation
  2016-05-18 14:56 ` Carlo Caione
  (?)
@ 2016-05-18 14:56     ` Carlo Caione
  -1 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Carlo Caione

From: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>

Add the binding documentation for the Amlogic secure monitor driver.

Signed-off-by: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
---
 .../devicetree/bindings/soc/meson/meson_sm.txt     | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt

diff --git a/Documentation/devicetree/bindings/soc/meson/meson_sm.txt b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
new file mode 100644
index 0000000..f59c732
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
@@ -0,0 +1,45 @@
+* Amlogic Secure Monitor
+
+In the Amlogic SoCs the Secure Monitor code is used to provide access to the
+NVMEM, enable JTAG, set USB boot, etc...
+
+Required properties for the secure monitor node:
+- compatible: Should be "amlogic,meson-sm"
+- amlogic,sm_cmd_input_base: SMC32 function identifier to read the physical
+                             address of the input buffer
+- amlogic,sm_cmd_output_base: SMC32 function identifier to read the physical
+                              address of the output buffer
+
+Example:
+
+	#include <dt-bindings/soc/meson-gxbb-sm.h>
+
+	...
+
+	sm {
+		compatible = "amlogic,meson-sm";
+		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
+		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
+	};
+
+Node of a device using the secure monitor must have a custom property to
+specify the SMC32 function the driver is going to use. The values of all the
+SMC function identifiers are listed in a SoC-specific header file:
+
+"include/dt-bindings/soc/meson-gxbb-sm.h" - for the Meson GXBB secure monitor.
+
+Example of the node using the secure monitor:
+
+	#include <dt-bindings/soc/meson-gxbb-sm.h>
+
+	...
+
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		amlogic,sm_cmd_read_efuse = <SM_EFUSE_READ>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		...
+	};
+
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 4/4] documentation: Add secure monitor binding documentation
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linux-arm-kernel

From: Carlo Caione <carlo@endlessm.com>

Add the binding documentation for the Amlogic secure monitor driver.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 .../devicetree/bindings/soc/meson/meson_sm.txt     | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt

diff --git a/Documentation/devicetree/bindings/soc/meson/meson_sm.txt b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
new file mode 100644
index 0000000..f59c732
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
@@ -0,0 +1,45 @@
+* Amlogic Secure Monitor
+
+In the Amlogic SoCs the Secure Monitor code is used to provide access to the
+NVMEM, enable JTAG, set USB boot, etc...
+
+Required properties for the secure monitor node:
+- compatible: Should be "amlogic,meson-sm"
+- amlogic,sm_cmd_input_base: SMC32 function identifier to read the physical
+                             address of the input buffer
+- amlogic,sm_cmd_output_base: SMC32 function identifier to read the physical
+                              address of the output buffer
+
+Example:
+
+	#include <dt-bindings/soc/meson-gxbb-sm.h>
+
+	...
+
+	sm {
+		compatible = "amlogic,meson-sm";
+		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
+		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
+	};
+
+Node of a device using the secure monitor must have a custom property to
+specify the SMC32 function the driver is going to use. The values of all the
+SMC function identifiers are listed in a SoC-specific header file:
+
+"include/dt-bindings/soc/meson-gxbb-sm.h" - for the Meson GXBB secure monitor.
+
+Example of the node using the secure monitor:
+
+	#include <dt-bindings/soc/meson-gxbb-sm.h>
+
+	...
+
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		amlogic,sm_cmd_read_efuse = <SM_EFUSE_READ>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		...
+	};
+
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 4/4] documentation: Add secure monitor binding documentation
@ 2016-05-18 14:56     ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-18 14:56 UTC (permalink / raw)
  To: linus-amlogic

From: Carlo Caione <carlo@endlessm.com>

Add the binding documentation for the Amlogic secure monitor driver.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 .../devicetree/bindings/soc/meson/meson_sm.txt     | 45 ++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt

diff --git a/Documentation/devicetree/bindings/soc/meson/meson_sm.txt b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
new file mode 100644
index 0000000..f59c732
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
@@ -0,0 +1,45 @@
+* Amlogic Secure Monitor
+
+In the Amlogic SoCs the Secure Monitor code is used to provide access to the
+NVMEM, enable JTAG, set USB boot, etc...
+
+Required properties for the secure monitor node:
+- compatible: Should be "amlogic,meson-sm"
+- amlogic,sm_cmd_input_base: SMC32 function identifier to read the physical
+                             address of the input buffer
+- amlogic,sm_cmd_output_base: SMC32 function identifier to read the physical
+                              address of the output buffer
+
+Example:
+
+	#include <dt-bindings/soc/meson-gxbb-sm.h>
+
+	...
+
+	sm {
+		compatible = "amlogic,meson-sm";
+		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
+		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
+	};
+
+Node of a device using the secure monitor must have a custom property to
+specify the SMC32 function the driver is going to use. The values of all the
+SMC function identifiers are listed in a SoC-specific header file:
+
+"include/dt-bindings/soc/meson-gxbb-sm.h" - for the Meson GXBB secure monitor.
+
+Example of the node using the secure monitor:
+
+	#include <dt-bindings/soc/meson-gxbb-sm.h>
+
+	...
+
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		amlogic,sm_cmd_read_efuse = <SM_EFUSE_READ>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		...
+	};
+
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 4/4] documentation: Add secure monitor binding documentation
  2016-05-18 14:56     ` Carlo Caione
  (?)
@ 2016-05-18 23:35         ` Rob Herring
  -1 siblings, 0 replies; 24+ messages in thread
From: Rob Herring @ 2016-05-18 23:35 UTC (permalink / raw)
  To: Carlo Caione
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, Carlo Caione

On Wed, May 18, 2016 at 04:56:22PM +0200, Carlo Caione wrote:
> From: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
> 
> Add the binding documentation for the Amlogic secure monitor driver.
> 
> Signed-off-by: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
> ---
>  .../devicetree/bindings/soc/meson/meson_sm.txt     | 45 ++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt
> 
> diff --git a/Documentation/devicetree/bindings/soc/meson/meson_sm.txt b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
> new file mode 100644
> index 0000000..f59c732
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt

bindings/firmware/

> @@ -0,0 +1,45 @@
> +* Amlogic Secure Monitor
> +
> +In the Amlogic SoCs the Secure Monitor code is used to provide access to the
> +NVMEM, enable JTAG, set USB boot, etc...
> +
> +Required properties for the secure monitor node:
> +- compatible: Should be "amlogic,meson-sm"
> +- amlogic,sm_cmd_input_base: SMC32 function identifier to read the physical
> +                             address of the input buffer
> +- amlogic,sm_cmd_output_base: SMC32 function identifier to read the physical
> +                              address of the output buffer

Use '-' rather than '_'.

> +
> +Example:
> +
> +	#include <dt-bindings/soc/meson-gxbb-sm.h>
> +
> +	...
> +
> +	sm {

Put this under a /firmware node.

> +		compatible = "amlogic,meson-sm";
> +		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
> +		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
> +	};
> +
> +Node of a device using the secure monitor must have a custom property to
> +specify the SMC32 function the driver is going to use. The values of all the
> +SMC function identifiers are listed in a SoC-specific header file:
> +
> +"include/dt-bindings/soc/meson-gxbb-sm.h" - for the Meson GXBB secure monitor.
> +
> +Example of the node using the secure monitor:
> +
> +	#include <dt-bindings/soc/meson-gxbb-sm.h>
> +
> +	...
> +
> +	efuse: efuse {
> +		compatible = "amlogic,meson-gxbb-efuse";
> +		amlogic,sm_cmd_read_efuse = <SM_EFUSE_READ>;
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +
> +		...
> +	};
> +
> -- 
> 2.7.4
> 
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 4/4] documentation: Add secure monitor binding documentation
@ 2016-05-18 23:35         ` Rob Herring
  0 siblings, 0 replies; 24+ messages in thread
From: Rob Herring @ 2016-05-18 23:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, May 18, 2016 at 04:56:22PM +0200, Carlo Caione wrote:
> From: Carlo Caione <carlo@endlessm.com>
> 
> Add the binding documentation for the Amlogic secure monitor driver.
> 
> Signed-off-by: Carlo Caione <carlo@endlessm.com>
> ---
>  .../devicetree/bindings/soc/meson/meson_sm.txt     | 45 ++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt
> 
> diff --git a/Documentation/devicetree/bindings/soc/meson/meson_sm.txt b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
> new file mode 100644
> index 0000000..f59c732
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt

bindings/firmware/

> @@ -0,0 +1,45 @@
> +* Amlogic Secure Monitor
> +
> +In the Amlogic SoCs the Secure Monitor code is used to provide access to the
> +NVMEM, enable JTAG, set USB boot, etc...
> +
> +Required properties for the secure monitor node:
> +- compatible: Should be "amlogic,meson-sm"
> +- amlogic,sm_cmd_input_base: SMC32 function identifier to read the physical
> +                             address of the input buffer
> +- amlogic,sm_cmd_output_base: SMC32 function identifier to read the physical
> +                              address of the output buffer

Use '-' rather than '_'.

> +
> +Example:
> +
> +	#include <dt-bindings/soc/meson-gxbb-sm.h>
> +
> +	...
> +
> +	sm {

Put this under a /firmware node.

> +		compatible = "amlogic,meson-sm";
> +		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
> +		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
> +	};
> +
> +Node of a device using the secure monitor must have a custom property to
> +specify the SMC32 function the driver is going to use. The values of all the
> +SMC function identifiers are listed in a SoC-specific header file:
> +
> +"include/dt-bindings/soc/meson-gxbb-sm.h" - for the Meson GXBB secure monitor.
> +
> +Example of the node using the secure monitor:
> +
> +	#include <dt-bindings/soc/meson-gxbb-sm.h>
> +
> +	...
> +
> +	efuse: efuse {
> +		compatible = "amlogic,meson-gxbb-efuse";
> +		amlogic,sm_cmd_read_efuse = <SM_EFUSE_READ>;
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +
> +		...
> +	};
> +
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 4/4] documentation: Add secure monitor binding documentation
@ 2016-05-18 23:35         ` Rob Herring
  0 siblings, 0 replies; 24+ messages in thread
From: Rob Herring @ 2016-05-18 23:35 UTC (permalink / raw)
  To: linus-amlogic

On Wed, May 18, 2016 at 04:56:22PM +0200, Carlo Caione wrote:
> From: Carlo Caione <carlo@endlessm.com>
> 
> Add the binding documentation for the Amlogic secure monitor driver.
> 
> Signed-off-by: Carlo Caione <carlo@endlessm.com>
> ---
>  .../devicetree/bindings/soc/meson/meson_sm.txt     | 45 ++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/soc/meson/meson_sm.txt
> 
> diff --git a/Documentation/devicetree/bindings/soc/meson/meson_sm.txt b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt
> new file mode 100644
> index 0000000..f59c732
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/meson/meson_sm.txt

bindings/firmware/

> @@ -0,0 +1,45 @@
> +* Amlogic Secure Monitor
> +
> +In the Amlogic SoCs the Secure Monitor code is used to provide access to the
> +NVMEM, enable JTAG, set USB boot, etc...
> +
> +Required properties for the secure monitor node:
> +- compatible: Should be "amlogic,meson-sm"
> +- amlogic,sm_cmd_input_base: SMC32 function identifier to read the physical
> +                             address of the input buffer
> +- amlogic,sm_cmd_output_base: SMC32 function identifier to read the physical
> +                              address of the output buffer

Use '-' rather than '_'.

> +
> +Example:
> +
> +	#include <dt-bindings/soc/meson-gxbb-sm.h>
> +
> +	...
> +
> +	sm {

Put this under a /firmware node.

> +		compatible = "amlogic,meson-sm";
> +		amlogic,sm_cmd_input_base = <SM_GET_SHARE_MEM_INPUT_BASE>;
> +		amlogic,sm_cmd_output_base = <SM_GET_SHARE_MEM_OUTPUT_BASE>;
> +	};
> +
> +Node of a device using the secure monitor must have a custom property to
> +specify the SMC32 function the driver is going to use. The values of all the
> +SMC function identifiers are listed in a SoC-specific header file:
> +
> +"include/dt-bindings/soc/meson-gxbb-sm.h" - for the Meson GXBB secure monitor.
> +
> +Example of the node using the secure monitor:
> +
> +	#include <dt-bindings/soc/meson-gxbb-sm.h>
> +
> +	...
> +
> +	efuse: efuse {
> +		compatible = "amlogic,meson-gxbb-efuse";
> +		amlogic,sm_cmd_read_efuse = <SM_EFUSE_READ>;
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +
> +		...
> +	};
> +
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
  2016-05-18 14:56     ` Carlo Caione
  (?)
@ 2016-05-23 11:38         ` Matthias Brugger
  -1 siblings, 0 replies; 24+ messages in thread
From: Matthias Brugger @ 2016-05-23 11:38 UTC (permalink / raw)
  To: Carlo Caione, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: Carlo Caione



On 18/05/16 16:56, Carlo Caione wrote:
> From: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
>
> Introduce a driver to provide calls into secure monitor mode.
>
> In the Amlogic SoCs these calls are used for multiple reasons: access to
> NVMEM, set USB boot, enable JTAG, etc...
>
> Signed-off-by: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
> ---
>   drivers/soc/Kconfig                |   1 +
>   drivers/soc/Makefile               |   1 +
>   drivers/soc/meson/Kconfig          |   8 ++
>   drivers/soc/meson/Makefile         |   1 +
>   drivers/soc/meson/meson_sm.c       | 155 +++++++++++++++++++++++++++++++++++++
>   include/linux/soc/meson/meson_sm.h |  22 ++++++
>   6 files changed, 188 insertions(+)
>   create mode 100644 drivers/soc/meson/Kconfig
>   create mode 100644 drivers/soc/meson/Makefile
>   create mode 100644 drivers/soc/meson/meson_sm.c
>   create mode 100644 include/linux/soc/meson/meson_sm.h
>
> diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
> index cb58ef0..7e70b52 100644
> --- a/drivers/soc/Kconfig
> +++ b/drivers/soc/Kconfig
> @@ -4,6 +4,7 @@ source "drivers/soc/bcm/Kconfig"
>   source "drivers/soc/brcmstb/Kconfig"
>   source "drivers/soc/fsl/qe/Kconfig"
>   source "drivers/soc/mediatek/Kconfig"
> +source "drivers/soc/meson/Kconfig"
>   source "drivers/soc/qcom/Kconfig"
>   source "drivers/soc/rockchip/Kconfig"
>   source "drivers/soc/samsung/Kconfig"
> diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
> index 5ade713..9024d2b 100644
> --- a/drivers/soc/Makefile
> +++ b/drivers/soc/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_DOVE)		+= dove/
>   obj-$(CONFIG_MACH_DOVE)		+= dove/
>   obj-y				+= fsl/
>   obj-$(CONFIG_ARCH_MEDIATEK)	+= mediatek/
> +obj-$(CONFIG_ARCH_MESON)	+= meson/
>   obj-$(CONFIG_ARCH_QCOM)		+= qcom/
>   obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
>   obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
> diff --git a/drivers/soc/meson/Kconfig b/drivers/soc/meson/Kconfig
> new file mode 100644
> index 0000000..fff11a3
> --- /dev/null
> +++ b/drivers/soc/meson/Kconfig
> @@ -0,0 +1,8 @@
> +#
> +# Amlogic Secure Monitor driver
> +#
> +config MESON_SM
> +	bool
> +	default ARCH_MESON
> +	help
> +	  Say y here to enable the Amlogic secure monitor driver
> diff --git a/drivers/soc/meson/Makefile b/drivers/soc/meson/Makefile
> new file mode 100644
> index 0000000..9ab3884
> --- /dev/null
> +++ b/drivers/soc/meson/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_MESON_SM) +=	meson_sm.o
> diff --git a/drivers/soc/meson/meson_sm.c b/drivers/soc/meson/meson_sm.c
> new file mode 100644
> index 0000000..16f7e32
> --- /dev/null
> +++ b/drivers/soc/meson/meson_sm.c
> @@ -0,0 +1,155 @@
> +/*
> + * Amlogic Secure Monitor driver
> + *
> + * Copyright (C) 2016 Endless Mobile, Inc.
> + * Author: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <stdarg.h>
> +#include <asm/cacheflush.h>
> +#include <asm/compiler.h>
> +#include <linux/arm-smccc.h>
> +#include <linux/io.h>
> +#include <linux/ioport.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/smp.h>
> +
> +#include <linux/soc/meson/meson_sm.h>
> +
> +#define SM_MEM_SIZE	0x1000
> +
> +/*
> + * To read from / write to the secure monitor we use two bounce buffers. The
> + * physical addresses of the two buffers are obtained by querying the secure
> + * monitor itself.
> + */
> +
> +static u32 sm_phy_in_base;
> +static u32 sm_phy_out_base;

You can put this two variable in meson_sm_probe, right?

> +
> +static void __iomem *sm_sharemem_in_base;
> +static void __iomem *sm_sharemem_out_base;
> +
> +struct meson_sm_data {
> +	u32 cmd;
> +	u32 arg0;
> +	u32 arg1;
> +	u32 arg2;
> +	u32 arg3;
> +	u32 arg4;
> +	u32 ret;
> +};
> +
> +static void __meson_sm_call(void *info)
> +{
> +	struct meson_sm_data *data = info;
> +	struct arm_smccc_res res;
> +
> +	arm_smccc_smc(data->cmd,
> +		      data->arg0, data->arg1, data->arg2,
> +		      data->arg3, data->arg4, 0, 0, &res);
> +	data->ret = res.a0;
> +}
> +
> +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)

Can the function be static or will it be called from another driver?

> +{
> +	struct meson_sm_data data;
> +
> +	data.cmd = cmd;
> +	data.arg0 = arg0;
> +	data.arg1 = arg1;
> +	data.arg2 = arg2;
> +	data.arg3 = arg3;
> +	data.arg4 = arg4;
> +	data.ret = 0;
> +
> +	__meson_sm_call(&data);
> +
> +	return data.ret;
> +}
> +
> +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
> +		       u32 arg2, u32 arg3, u32 arg4)
> +{
> +	u32 size;
> +
> +	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> +
> +	if (!size || size > SM_MEM_SIZE)
> +		return -EINVAL;
> +
> +	memcpy(buffer, sm_sharemem_out_base, size);
> +	return size;
> +}

This function will be needed to be exported to be callable from modules.

> +
> +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> +			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> +{
> +	u32 size;
> +
> +	if (b_size > SM_MEM_SIZE)
> +		return -EINVAL;
> +
> +	memcpy(sm_sharemem_in_base, buffer, b_size);
> +
> +	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> +
> +	if (!size)
> +		return -EINVAL;
> +
> +	return size;
> +}
> +

Same here.

Regards,
Matthias

> +static int meson_sm_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	int cmd_in, cmd_out;
> +
> +	if (of_property_read_u32(np, "amlogic,sm_cmd_input_base", &cmd_in))
> +		return -EINVAL;
> +
> +	if (of_property_read_u32(np, "amlogic,sm_cmd_output_base", &cmd_out))
> +		return -EINVAL;
> +
> +	sm_phy_in_base = meson_sm_call(cmd_in, 0, 0, 0, 0, 0);
> +	sm_sharemem_in_base = ioremap_cache(sm_phy_in_base, SM_MEM_SIZE);
> +	if (!sm_sharemem_in_base)
> +		return -EINVAL;
> +
> +	sm_phy_out_base = meson_sm_call(cmd_out, 0, 0, 0, 0, 0);
> +	sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE);
> +	if (!sm_sharemem_out_base) {
> +		iounmap(sm_sharemem_in_base);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id meson_sm_ids[] = {
> +	{ .compatible = "amlogic,meson-sm" },
> +	{ /* sentinel */},
> +};
> +MODULE_DEVICE_TABLE(of, meson_sm_ids);
> +
> +static struct platform_driver meson_sm_platform_driver = {
> +	.probe	= meson_sm_probe,
> +	.driver	= {
> +		.name		= "secmon",
> +		.of_match_table	= meson_sm_ids,
> +	},
> +};
> +module_platform_driver(meson_sm_platform_driver);
> +
> +MODULE_AUTHOR("Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>");
> +MODULE_DESCRIPTION("Amlogic secure monitor driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/soc/meson/meson_sm.h b/include/linux/soc/meson/meson_sm.h
> new file mode 100644
> index 0000000..6ff8317
> --- /dev/null
> +++ b/include/linux/soc/meson/meson_sm.h
> @@ -0,0 +1,22 @@
> +/*
> + * Copyright (C) 2016 Endless Mobile, Inc.
> + * Author: Carlo Caione <carlo-6IF/jdPJHihWk0Htik3J/w@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef _MESON_SM_H_
> +#define _MESON_SM_H_
> +
> +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
> +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, u32 arg2,
> +		       u32 arg3, u32 arg4);
> +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> +			u32 arg1, u32 arg2, u32 arg3, u32 arg4);
> +
> +#endif /* _MESON_SM_H_ */
>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
@ 2016-05-23 11:38         ` Matthias Brugger
  0 siblings, 0 replies; 24+ messages in thread
From: Matthias Brugger @ 2016-05-23 11:38 UTC (permalink / raw)
  To: linux-arm-kernel



On 18/05/16 16:56, Carlo Caione wrote:
> From: Carlo Caione <carlo@endlessm.com>
>
> Introduce a driver to provide calls into secure monitor mode.
>
> In the Amlogic SoCs these calls are used for multiple reasons: access to
> NVMEM, set USB boot, enable JTAG, etc...
>
> Signed-off-by: Carlo Caione <carlo@endlessm.com>
> ---
>   drivers/soc/Kconfig                |   1 +
>   drivers/soc/Makefile               |   1 +
>   drivers/soc/meson/Kconfig          |   8 ++
>   drivers/soc/meson/Makefile         |   1 +
>   drivers/soc/meson/meson_sm.c       | 155 +++++++++++++++++++++++++++++++++++++
>   include/linux/soc/meson/meson_sm.h |  22 ++++++
>   6 files changed, 188 insertions(+)
>   create mode 100644 drivers/soc/meson/Kconfig
>   create mode 100644 drivers/soc/meson/Makefile
>   create mode 100644 drivers/soc/meson/meson_sm.c
>   create mode 100644 include/linux/soc/meson/meson_sm.h
>
> diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
> index cb58ef0..7e70b52 100644
> --- a/drivers/soc/Kconfig
> +++ b/drivers/soc/Kconfig
> @@ -4,6 +4,7 @@ source "drivers/soc/bcm/Kconfig"
>   source "drivers/soc/brcmstb/Kconfig"
>   source "drivers/soc/fsl/qe/Kconfig"
>   source "drivers/soc/mediatek/Kconfig"
> +source "drivers/soc/meson/Kconfig"
>   source "drivers/soc/qcom/Kconfig"
>   source "drivers/soc/rockchip/Kconfig"
>   source "drivers/soc/samsung/Kconfig"
> diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
> index 5ade713..9024d2b 100644
> --- a/drivers/soc/Makefile
> +++ b/drivers/soc/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_DOVE)		+= dove/
>   obj-$(CONFIG_MACH_DOVE)		+= dove/
>   obj-y				+= fsl/
>   obj-$(CONFIG_ARCH_MEDIATEK)	+= mediatek/
> +obj-$(CONFIG_ARCH_MESON)	+= meson/
>   obj-$(CONFIG_ARCH_QCOM)		+= qcom/
>   obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
>   obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
> diff --git a/drivers/soc/meson/Kconfig b/drivers/soc/meson/Kconfig
> new file mode 100644
> index 0000000..fff11a3
> --- /dev/null
> +++ b/drivers/soc/meson/Kconfig
> @@ -0,0 +1,8 @@
> +#
> +# Amlogic Secure Monitor driver
> +#
> +config MESON_SM
> +	bool
> +	default ARCH_MESON
> +	help
> +	  Say y here to enable the Amlogic secure monitor driver
> diff --git a/drivers/soc/meson/Makefile b/drivers/soc/meson/Makefile
> new file mode 100644
> index 0000000..9ab3884
> --- /dev/null
> +++ b/drivers/soc/meson/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_MESON_SM) +=	meson_sm.o
> diff --git a/drivers/soc/meson/meson_sm.c b/drivers/soc/meson/meson_sm.c
> new file mode 100644
> index 0000000..16f7e32
> --- /dev/null
> +++ b/drivers/soc/meson/meson_sm.c
> @@ -0,0 +1,155 @@
> +/*
> + * Amlogic Secure Monitor driver
> + *
> + * Copyright (C) 2016 Endless Mobile, Inc.
> + * Author: Carlo Caione <carlo@endlessm.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <stdarg.h>
> +#include <asm/cacheflush.h>
> +#include <asm/compiler.h>
> +#include <linux/arm-smccc.h>
> +#include <linux/io.h>
> +#include <linux/ioport.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/smp.h>
> +
> +#include <linux/soc/meson/meson_sm.h>
> +
> +#define SM_MEM_SIZE	0x1000
> +
> +/*
> + * To read from / write to the secure monitor we use two bounce buffers. The
> + * physical addresses of the two buffers are obtained by querying the secure
> + * monitor itself.
> + */
> +
> +static u32 sm_phy_in_base;
> +static u32 sm_phy_out_base;

You can put this two variable in meson_sm_probe, right?

> +
> +static void __iomem *sm_sharemem_in_base;
> +static void __iomem *sm_sharemem_out_base;
> +
> +struct meson_sm_data {
> +	u32 cmd;
> +	u32 arg0;
> +	u32 arg1;
> +	u32 arg2;
> +	u32 arg3;
> +	u32 arg4;
> +	u32 ret;
> +};
> +
> +static void __meson_sm_call(void *info)
> +{
> +	struct meson_sm_data *data = info;
> +	struct arm_smccc_res res;
> +
> +	arm_smccc_smc(data->cmd,
> +		      data->arg0, data->arg1, data->arg2,
> +		      data->arg3, data->arg4, 0, 0, &res);
> +	data->ret = res.a0;
> +}
> +
> +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)

Can the function be static or will it be called from another driver?

> +{
> +	struct meson_sm_data data;
> +
> +	data.cmd = cmd;
> +	data.arg0 = arg0;
> +	data.arg1 = arg1;
> +	data.arg2 = arg2;
> +	data.arg3 = arg3;
> +	data.arg4 = arg4;
> +	data.ret = 0;
> +
> +	__meson_sm_call(&data);
> +
> +	return data.ret;
> +}
> +
> +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
> +		       u32 arg2, u32 arg3, u32 arg4)
> +{
> +	u32 size;
> +
> +	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> +
> +	if (!size || size > SM_MEM_SIZE)
> +		return -EINVAL;
> +
> +	memcpy(buffer, sm_sharemem_out_base, size);
> +	return size;
> +}

This function will be needed to be exported to be callable from modules.

> +
> +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> +			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> +{
> +	u32 size;
> +
> +	if (b_size > SM_MEM_SIZE)
> +		return -EINVAL;
> +
> +	memcpy(sm_sharemem_in_base, buffer, b_size);
> +
> +	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> +
> +	if (!size)
> +		return -EINVAL;
> +
> +	return size;
> +}
> +

Same here.

Regards,
Matthias

> +static int meson_sm_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	int cmd_in, cmd_out;
> +
> +	if (of_property_read_u32(np, "amlogic,sm_cmd_input_base", &cmd_in))
> +		return -EINVAL;
> +
> +	if (of_property_read_u32(np, "amlogic,sm_cmd_output_base", &cmd_out))
> +		return -EINVAL;
> +
> +	sm_phy_in_base = meson_sm_call(cmd_in, 0, 0, 0, 0, 0);
> +	sm_sharemem_in_base = ioremap_cache(sm_phy_in_base, SM_MEM_SIZE);
> +	if (!sm_sharemem_in_base)
> +		return -EINVAL;
> +
> +	sm_phy_out_base = meson_sm_call(cmd_out, 0, 0, 0, 0, 0);
> +	sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE);
> +	if (!sm_sharemem_out_base) {
> +		iounmap(sm_sharemem_in_base);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id meson_sm_ids[] = {
> +	{ .compatible = "amlogic,meson-sm" },
> +	{ /* sentinel */},
> +};
> +MODULE_DEVICE_TABLE(of, meson_sm_ids);
> +
> +static struct platform_driver meson_sm_platform_driver = {
> +	.probe	= meson_sm_probe,
> +	.driver	= {
> +		.name		= "secmon",
> +		.of_match_table	= meson_sm_ids,
> +	},
> +};
> +module_platform_driver(meson_sm_platform_driver);
> +
> +MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
> +MODULE_DESCRIPTION("Amlogic secure monitor driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/soc/meson/meson_sm.h b/include/linux/soc/meson/meson_sm.h
> new file mode 100644
> index 0000000..6ff8317
> --- /dev/null
> +++ b/include/linux/soc/meson/meson_sm.h
> @@ -0,0 +1,22 @@
> +/*
> + * Copyright (C) 2016 Endless Mobile, Inc.
> + * Author: Carlo Caione <carlo@endlessm.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef _MESON_SM_H_
> +#define _MESON_SM_H_
> +
> +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
> +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, u32 arg2,
> +		       u32 arg3, u32 arg4);
> +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> +			u32 arg1, u32 arg2, u32 arg3, u32 arg4);
> +
> +#endif /* _MESON_SM_H_ */
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
@ 2016-05-23 11:38         ` Matthias Brugger
  0 siblings, 0 replies; 24+ messages in thread
From: Matthias Brugger @ 2016-05-23 11:38 UTC (permalink / raw)
  To: linus-amlogic



On 18/05/16 16:56, Carlo Caione wrote:
> From: Carlo Caione <carlo@endlessm.com>
>
> Introduce a driver to provide calls into secure monitor mode.
>
> In the Amlogic SoCs these calls are used for multiple reasons: access to
> NVMEM, set USB boot, enable JTAG, etc...
>
> Signed-off-by: Carlo Caione <carlo@endlessm.com>
> ---
>   drivers/soc/Kconfig                |   1 +
>   drivers/soc/Makefile               |   1 +
>   drivers/soc/meson/Kconfig          |   8 ++
>   drivers/soc/meson/Makefile         |   1 +
>   drivers/soc/meson/meson_sm.c       | 155 +++++++++++++++++++++++++++++++++++++
>   include/linux/soc/meson/meson_sm.h |  22 ++++++
>   6 files changed, 188 insertions(+)
>   create mode 100644 drivers/soc/meson/Kconfig
>   create mode 100644 drivers/soc/meson/Makefile
>   create mode 100644 drivers/soc/meson/meson_sm.c
>   create mode 100644 include/linux/soc/meson/meson_sm.h
>
> diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
> index cb58ef0..7e70b52 100644
> --- a/drivers/soc/Kconfig
> +++ b/drivers/soc/Kconfig
> @@ -4,6 +4,7 @@ source "drivers/soc/bcm/Kconfig"
>   source "drivers/soc/brcmstb/Kconfig"
>   source "drivers/soc/fsl/qe/Kconfig"
>   source "drivers/soc/mediatek/Kconfig"
> +source "drivers/soc/meson/Kconfig"
>   source "drivers/soc/qcom/Kconfig"
>   source "drivers/soc/rockchip/Kconfig"
>   source "drivers/soc/samsung/Kconfig"
> diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
> index 5ade713..9024d2b 100644
> --- a/drivers/soc/Makefile
> +++ b/drivers/soc/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_DOVE)		+= dove/
>   obj-$(CONFIG_MACH_DOVE)		+= dove/
>   obj-y				+= fsl/
>   obj-$(CONFIG_ARCH_MEDIATEK)	+= mediatek/
> +obj-$(CONFIG_ARCH_MESON)	+= meson/
>   obj-$(CONFIG_ARCH_QCOM)		+= qcom/
>   obj-$(CONFIG_ARCH_ROCKCHIP)		+= rockchip/
>   obj-$(CONFIG_SOC_SAMSUNG)	+= samsung/
> diff --git a/drivers/soc/meson/Kconfig b/drivers/soc/meson/Kconfig
> new file mode 100644
> index 0000000..fff11a3
> --- /dev/null
> +++ b/drivers/soc/meson/Kconfig
> @@ -0,0 +1,8 @@
> +#
> +# Amlogic Secure Monitor driver
> +#
> +config MESON_SM
> +	bool
> +	default ARCH_MESON
> +	help
> +	  Say y here to enable the Amlogic secure monitor driver
> diff --git a/drivers/soc/meson/Makefile b/drivers/soc/meson/Makefile
> new file mode 100644
> index 0000000..9ab3884
> --- /dev/null
> +++ b/drivers/soc/meson/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_MESON_SM) +=	meson_sm.o
> diff --git a/drivers/soc/meson/meson_sm.c b/drivers/soc/meson/meson_sm.c
> new file mode 100644
> index 0000000..16f7e32
> --- /dev/null
> +++ b/drivers/soc/meson/meson_sm.c
> @@ -0,0 +1,155 @@
> +/*
> + * Amlogic Secure Monitor driver
> + *
> + * Copyright (C) 2016 Endless Mobile, Inc.
> + * Author: Carlo Caione <carlo@endlessm.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <stdarg.h>
> +#include <asm/cacheflush.h>
> +#include <asm/compiler.h>
> +#include <linux/arm-smccc.h>
> +#include <linux/io.h>
> +#include <linux/ioport.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/smp.h>
> +
> +#include <linux/soc/meson/meson_sm.h>
> +
> +#define SM_MEM_SIZE	0x1000
> +
> +/*
> + * To read from / write to the secure monitor we use two bounce buffers. The
> + * physical addresses of the two buffers are obtained by querying the secure
> + * monitor itself.
> + */
> +
> +static u32 sm_phy_in_base;
> +static u32 sm_phy_out_base;

You can put this two variable in meson_sm_probe, right?

> +
> +static void __iomem *sm_sharemem_in_base;
> +static void __iomem *sm_sharemem_out_base;
> +
> +struct meson_sm_data {
> +	u32 cmd;
> +	u32 arg0;
> +	u32 arg1;
> +	u32 arg2;
> +	u32 arg3;
> +	u32 arg4;
> +	u32 ret;
> +};
> +
> +static void __meson_sm_call(void *info)
> +{
> +	struct meson_sm_data *data = info;
> +	struct arm_smccc_res res;
> +
> +	arm_smccc_smc(data->cmd,
> +		      data->arg0, data->arg1, data->arg2,
> +		      data->arg3, data->arg4, 0, 0, &res);
> +	data->ret = res.a0;
> +}
> +
> +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)

Can the function be static or will it be called from another driver?

> +{
> +	struct meson_sm_data data;
> +
> +	data.cmd = cmd;
> +	data.arg0 = arg0;
> +	data.arg1 = arg1;
> +	data.arg2 = arg2;
> +	data.arg3 = arg3;
> +	data.arg4 = arg4;
> +	data.ret = 0;
> +
> +	__meson_sm_call(&data);
> +
> +	return data.ret;
> +}
> +
> +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
> +		       u32 arg2, u32 arg3, u32 arg4)
> +{
> +	u32 size;
> +
> +	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> +
> +	if (!size || size > SM_MEM_SIZE)
> +		return -EINVAL;
> +
> +	memcpy(buffer, sm_sharemem_out_base, size);
> +	return size;
> +}

This function will be needed to be exported to be callable from modules.

> +
> +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> +			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> +{
> +	u32 size;
> +
> +	if (b_size > SM_MEM_SIZE)
> +		return -EINVAL;
> +
> +	memcpy(sm_sharemem_in_base, buffer, b_size);
> +
> +	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> +
> +	if (!size)
> +		return -EINVAL;
> +
> +	return size;
> +}
> +

Same here.

Regards,
Matthias

> +static int meson_sm_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	int cmd_in, cmd_out;
> +
> +	if (of_property_read_u32(np, "amlogic,sm_cmd_input_base", &cmd_in))
> +		return -EINVAL;
> +
> +	if (of_property_read_u32(np, "amlogic,sm_cmd_output_base", &cmd_out))
> +		return -EINVAL;
> +
> +	sm_phy_in_base = meson_sm_call(cmd_in, 0, 0, 0, 0, 0);
> +	sm_sharemem_in_base = ioremap_cache(sm_phy_in_base, SM_MEM_SIZE);
> +	if (!sm_sharemem_in_base)
> +		return -EINVAL;
> +
> +	sm_phy_out_base = meson_sm_call(cmd_out, 0, 0, 0, 0, 0);
> +	sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE);
> +	if (!sm_sharemem_out_base) {
> +		iounmap(sm_sharemem_in_base);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id meson_sm_ids[] = {
> +	{ .compatible = "amlogic,meson-sm" },
> +	{ /* sentinel */},
> +};
> +MODULE_DEVICE_TABLE(of, meson_sm_ids);
> +
> +static struct platform_driver meson_sm_platform_driver = {
> +	.probe	= meson_sm_probe,
> +	.driver	= {
> +		.name		= "secmon",
> +		.of_match_table	= meson_sm_ids,
> +	},
> +};
> +module_platform_driver(meson_sm_platform_driver);
> +
> +MODULE_AUTHOR("Carlo Caione <carlo@endlessm.com>");
> +MODULE_DESCRIPTION("Amlogic secure monitor driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/soc/meson/meson_sm.h b/include/linux/soc/meson/meson_sm.h
> new file mode 100644
> index 0000000..6ff8317
> --- /dev/null
> +++ b/include/linux/soc/meson/meson_sm.h
> @@ -0,0 +1,22 @@
> +/*
> + * Copyright (C) 2016 Endless Mobile, Inc.
> + * Author: Carlo Caione <carlo@endlessm.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef _MESON_SM_H_
> +#define _MESON_SM_H_
> +
> +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
> +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, u32 arg2,
> +		       u32 arg3, u32 arg4);
> +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> +			u32 arg1, u32 arg2, u32 arg3, u32 arg4);
> +
> +#endif /* _MESON_SM_H_ */
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
  2016-05-23 11:38         ` Matthias Brugger
  (?)
@ 2016-05-23 11:43             ` Carlo Caione
  -1 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-23 11:43 UTC (permalink / raw)
  To: Matthias Brugger
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-amlogic-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-6IF/jdPJHihWk0Htik3J/w, devicetree-u79uwXL29TY76Z2rM5mHXA,
	khilman-rdvid1DuHRBWk0Htik3J/w, afaerber-l3A5Bk7waGM,
	arnd-r2nGTMty4D4, jens.wiklander-QSEj5FYQhm4dnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, robh+dt-DgEjT+Ai2ygdnm+yROfE0A

On 23/05/16 13:38, Matthias Brugger wrote:
> 

[...]
> >+#include <stdarg.h>
> >+#include <asm/cacheflush.h>
> >+#include <asm/compiler.h>
> >+#include <linux/arm-smccc.h>
> >+#include <linux/io.h>
> >+#include <linux/ioport.h>
> >+#include <linux/module.h>
> >+#include <linux/platform_device.h>
> >+#include <linux/of.h>
> >+#include <linux/smp.h>
> >+
> >+#include <linux/soc/meson/meson_sm.h>
> >+
> >+#define SM_MEM_SIZE	0x1000
> >+
> >+/*
> >+ * To read from / write to the secure monitor we use two bounce buffers. The
> >+ * physical addresses of the two buffers are obtained by querying the secure
> >+ * monitor itself.
> >+ */
> >+
> >+static u32 sm_phy_in_base;
> >+static u32 sm_phy_out_base;
> 
> You can put this two variable in meson_sm_probe, right?

Yeah, actually no need to be there.

> >+
> >+static void __iomem *sm_sharemem_in_base;
> >+static void __iomem *sm_sharemem_out_base;
> >+
> >+struct meson_sm_data {
> >+	u32 cmd;
> >+	u32 arg0;
> >+	u32 arg1;
> >+	u32 arg2;
> >+	u32 arg3;
> >+	u32 arg4;
> >+	u32 ret;
> >+};
> >+
> >+static void __meson_sm_call(void *info)
> >+{
> >+	struct meson_sm_data *data = info;
> >+	struct arm_smccc_res res;
> >+
> >+	arm_smccc_smc(data->cmd,
> >+		      data->arg0, data->arg1, data->arg2,
> >+		      data->arg3, data->arg4, 0, 0, &res);
> >+	data->ret = res.a0;
> >+}
> >+
> >+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> 
> Can the function be static or will it be called from another driver?

It _can_ be called from another driver. It depends on the SMC used, so
better making it available.

> 
> >+{
> >+	struct meson_sm_data data;
> >+
> >+	data.cmd = cmd;
> >+	data.arg0 = arg0;
> >+	data.arg1 = arg1;
> >+	data.arg2 = arg2;
> >+	data.arg3 = arg3;
> >+	data.arg4 = arg4;
> >+	data.ret = 0;
> >+
> >+	__meson_sm_call(&data);
> >+
> >+	return data.ret;
> >+}
> >+
> >+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
> >+		       u32 arg2, u32 arg3, u32 arg4)
> >+{
> >+	u32 size;
> >+
> >+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> >+
> >+	if (!size || size > SM_MEM_SIZE)
> >+		return -EINVAL;
> >+
> >+	memcpy(buffer, sm_sharemem_out_base, size);
> >+	return size;
> >+}
> 
> This function will be needed to be exported to be callable from modules.

Fix in v3.

> >+
> >+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> >+			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> >+{
> >+	u32 size;
> >+
> >+	if (b_size > SM_MEM_SIZE)
> >+		return -EINVAL;
> >+
> >+	memcpy(sm_sharemem_in_base, buffer, b_size);
> >+
> >+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> >+
> >+	if (!size)
> >+		return -EINVAL;
> >+
> >+	return size;
> >+}
> >+
> 
> Same here.

Thanks.

Cheers,

-- 
Carlo Caione
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
@ 2016-05-23 11:43             ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-23 11:43 UTC (permalink / raw)
  To: linux-arm-kernel

On 23/05/16 13:38, Matthias Brugger wrote:
> 

[...]
> >+#include <stdarg.h>
> >+#include <asm/cacheflush.h>
> >+#include <asm/compiler.h>
> >+#include <linux/arm-smccc.h>
> >+#include <linux/io.h>
> >+#include <linux/ioport.h>
> >+#include <linux/module.h>
> >+#include <linux/platform_device.h>
> >+#include <linux/of.h>
> >+#include <linux/smp.h>
> >+
> >+#include <linux/soc/meson/meson_sm.h>
> >+
> >+#define SM_MEM_SIZE	0x1000
> >+
> >+/*
> >+ * To read from / write to the secure monitor we use two bounce buffers. The
> >+ * physical addresses of the two buffers are obtained by querying the secure
> >+ * monitor itself.
> >+ */
> >+
> >+static u32 sm_phy_in_base;
> >+static u32 sm_phy_out_base;
> 
> You can put this two variable in meson_sm_probe, right?

Yeah, actually no need to be there.

> >+
> >+static void __iomem *sm_sharemem_in_base;
> >+static void __iomem *sm_sharemem_out_base;
> >+
> >+struct meson_sm_data {
> >+	u32 cmd;
> >+	u32 arg0;
> >+	u32 arg1;
> >+	u32 arg2;
> >+	u32 arg3;
> >+	u32 arg4;
> >+	u32 ret;
> >+};
> >+
> >+static void __meson_sm_call(void *info)
> >+{
> >+	struct meson_sm_data *data = info;
> >+	struct arm_smccc_res res;
> >+
> >+	arm_smccc_smc(data->cmd,
> >+		      data->arg0, data->arg1, data->arg2,
> >+		      data->arg3, data->arg4, 0, 0, &res);
> >+	data->ret = res.a0;
> >+}
> >+
> >+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> 
> Can the function be static or will it be called from another driver?

It _can_ be called from another driver. It depends on the SMC used, so
better making it available.

> 
> >+{
> >+	struct meson_sm_data data;
> >+
> >+	data.cmd = cmd;
> >+	data.arg0 = arg0;
> >+	data.arg1 = arg1;
> >+	data.arg2 = arg2;
> >+	data.arg3 = arg3;
> >+	data.arg4 = arg4;
> >+	data.ret = 0;
> >+
> >+	__meson_sm_call(&data);
> >+
> >+	return data.ret;
> >+}
> >+
> >+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
> >+		       u32 arg2, u32 arg3, u32 arg4)
> >+{
> >+	u32 size;
> >+
> >+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> >+
> >+	if (!size || size > SM_MEM_SIZE)
> >+		return -EINVAL;
> >+
> >+	memcpy(buffer, sm_sharemem_out_base, size);
> >+	return size;
> >+}
> 
> This function will be needed to be exported to be callable from modules.

Fix in v3.

> >+
> >+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> >+			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> >+{
> >+	u32 size;
> >+
> >+	if (b_size > SM_MEM_SIZE)
> >+		return -EINVAL;
> >+
> >+	memcpy(sm_sharemem_in_base, buffer, b_size);
> >+
> >+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> >+
> >+	if (!size)
> >+		return -EINVAL;
> >+
> >+	return size;
> >+}
> >+
> 
> Same here.

Thanks.

Cheers,

-- 
Carlo Caione

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver
@ 2016-05-23 11:43             ` Carlo Caione
  0 siblings, 0 replies; 24+ messages in thread
From: Carlo Caione @ 2016-05-23 11:43 UTC (permalink / raw)
  To: linus-amlogic

On 23/05/16 13:38, Matthias Brugger wrote:
> 

[...]
> >+#include <stdarg.h>
> >+#include <asm/cacheflush.h>
> >+#include <asm/compiler.h>
> >+#include <linux/arm-smccc.h>
> >+#include <linux/io.h>
> >+#include <linux/ioport.h>
> >+#include <linux/module.h>
> >+#include <linux/platform_device.h>
> >+#include <linux/of.h>
> >+#include <linux/smp.h>
> >+
> >+#include <linux/soc/meson/meson_sm.h>
> >+
> >+#define SM_MEM_SIZE	0x1000
> >+
> >+/*
> >+ * To read from / write to the secure monitor we use two bounce buffers. The
> >+ * physical addresses of the two buffers are obtained by querying the secure
> >+ * monitor itself.
> >+ */
> >+
> >+static u32 sm_phy_in_base;
> >+static u32 sm_phy_out_base;
> 
> You can put this two variable in meson_sm_probe, right?

Yeah, actually no need to be there.

> >+
> >+static void __iomem *sm_sharemem_in_base;
> >+static void __iomem *sm_sharemem_out_base;
> >+
> >+struct meson_sm_data {
> >+	u32 cmd;
> >+	u32 arg0;
> >+	u32 arg1;
> >+	u32 arg2;
> >+	u32 arg3;
> >+	u32 arg4;
> >+	u32 ret;
> >+};
> >+
> >+static void __meson_sm_call(void *info)
> >+{
> >+	struct meson_sm_data *data = info;
> >+	struct arm_smccc_res res;
> >+
> >+	arm_smccc_smc(data->cmd,
> >+		      data->arg0, data->arg1, data->arg2,
> >+		      data->arg3, data->arg4, 0, 0, &res);
> >+	data->ret = res.a0;
> >+}
> >+
> >+u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> 
> Can the function be static or will it be called from another driver?

It _can_ be called from another driver. It depends on the SMC used, so
better making it available.

> 
> >+{
> >+	struct meson_sm_data data;
> >+
> >+	data.cmd = cmd;
> >+	data.arg0 = arg0;
> >+	data.arg1 = arg1;
> >+	data.arg2 = arg2;
> >+	data.arg3 = arg3;
> >+	data.arg4 = arg4;
> >+	data.ret = 0;
> >+
> >+	__meson_sm_call(&data);
> >+
> >+	return data.ret;
> >+}
> >+
> >+u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1,
> >+		       u32 arg2, u32 arg3, u32 arg4)
> >+{
> >+	u32 size;
> >+
> >+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> >+
> >+	if (!size || size > SM_MEM_SIZE)
> >+		return -EINVAL;
> >+
> >+	memcpy(buffer, sm_sharemem_out_base, size);
> >+	return size;
> >+}
> 
> This function will be needed to be exported to be callable from modules.

Fix in v3.

> >+
> >+u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0,
> >+			u32 arg1, u32 arg2, u32 arg3, u32 arg4)
> >+{
> >+	u32 size;
> >+
> >+	if (b_size > SM_MEM_SIZE)
> >+		return -EINVAL;
> >+
> >+	memcpy(sm_sharemem_in_base, buffer, b_size);
> >+
> >+	size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4);
> >+
> >+	if (!size)
> >+		return -EINVAL;
> >+
> >+	return size;
> >+}
> >+
> 
> Same here.

Thanks.

Cheers,

-- 
Carlo Caione

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2016-05-23 11:43 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-18 14:56 [PATCH v2 0/4] Add Amlogic secure monitor driver Carlo Caione
2016-05-18 14:56 ` Carlo Caione
2016-05-18 14:56 ` Carlo Caione
     [not found] ` <1463583382-15614-1-git-send-email-carlo-KA+7E9HrN00dnm+yROfE0A@public.gmane.org>
2016-05-18 14:56   ` [PATCH v2 1/4] soc: Amlogic: Add " Carlo Caione
2016-05-18 14:56     ` Carlo Caione
2016-05-18 14:56     ` Carlo Caione
     [not found]     ` <1463583382-15614-2-git-send-email-carlo-KA+7E9HrN00dnm+yROfE0A@public.gmane.org>
2016-05-23 11:38       ` Matthias Brugger
2016-05-23 11:38         ` Matthias Brugger
2016-05-23 11:38         ` Matthias Brugger
     [not found]         ` <5742EBC4.3050704-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-05-23 11:43           ` Carlo Caione
2016-05-23 11:43             ` Carlo Caione
2016-05-23 11:43             ` Carlo Caione
2016-05-18 14:56   ` [PATCH v2 2/4] soc: dt-bindings: Add secure monitor header file for GXBB Carlo Caione
2016-05-18 14:56     ` Carlo Caione
2016-05-18 14:56     ` Carlo Caione
2016-05-18 14:56   ` [PATCH v2 3/4] ARM64: dts: amlogic: gxbb: Enable secure monitor Carlo Caione
2016-05-18 14:56     ` Carlo Caione
2016-05-18 14:56     ` Carlo Caione
2016-05-18 14:56   ` [PATCH v2 4/4] documentation: Add secure monitor binding documentation Carlo Caione
2016-05-18 14:56     ` Carlo Caione
2016-05-18 14:56     ` Carlo Caione
     [not found]     ` <1463583382-15614-5-git-send-email-carlo-KA+7E9HrN00dnm+yROfE0A@public.gmane.org>
2016-05-18 23:35       ` Rob Herring
2016-05-18 23:35         ` Rob Herring
2016-05-18 23:35         ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.