Skip to contentSkip to conversation

Add Amlogic secure monitor driver

PATCH Superseded Carlo Caione 2 participants 7 messages May 25, 2016 – May 26, 2016

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add Amlogic secure monitor driver

From: Carlo Caione <[email protected]>

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:

v4:
* Changed patches order
* Removed now useless PATCH 2/4
* Changed compatible to be SoC-specific
* In the DT now we use SoC-agnostic IDs for the SMC functions. These IDs are traslated into SoC specific function IDs inside the driver
* Added error checking on meson_sm_call() to retrieve the base address
* Improved printing on errors

v3:
* Moved driver to drivers/firmware
* Added EXPORT_SYMBOL macros
* Changed '_' in '-'
* Introduced 'struct meson_sm_firmware' and 'meson_sm_get_fw()' to be used by drivers using the secure-monitor to enforce probe ordering

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 (3):
firmware: Amlogic: Add secure monitor driver
documentation: Add secure monitor binding documentation
ARM64: dts: amlogic: gxbb: Enable secure monitor

 .../bindings/firmware/meson/meson_sm.txt           |  42 +++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |   9 +
 drivers/firmware/Kconfig                           |   1 +
 drivers/firmware/Makefile                          |   1 +
 drivers/firmware/meson/Kconfig                     |   8 +
 drivers/firmware/meson/Makefile                    |   1 +
 drivers/firmware/meson/meson_sm.c                  | 193 +++++++++++++++++++++
 include/dt-bindings/firmware/meson-sm.h            |  20 +++
 include/linux/firmware/meson/meson-sm.h            |  49 ++++++
 9 files changed, 324 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt
 create mode 100644 drivers/firmware/meson/Kconfig
 create mode 100644 drivers/firmware/meson/Makefile
 create mode 100644 drivers/firmware/meson/meson_sm.c
 create mode 100644 include/dt-bindings/firmware/meson-sm.h
 create mode 100644 include/linux/firmware/meson/meson-sm.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v4 1/3 firmware: Amlogic: Add secure monitor driver

From: Carlo Caione <[email protected]>

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...

---
 drivers/firmware/Kconfig                |   1 +
 drivers/firmware/Makefile               |   1 +
 drivers/firmware/meson/Kconfig          |   8 ++
 drivers/firmware/meson/Makefile         |   1 +
 drivers/firmware/meson/meson_sm.c       | 193 ++++++++++++++++++++++++++++++++
 include/dt-bindings/firmware/meson-sm.h |  20 ++++
 include/linux/firmware/meson/meson-sm.h |  49 ++++++++
 7 files changed, 273 insertions(+)
 create mode 100644 drivers/firmware/meson/Kconfig
 create mode 100644 drivers/firmware/meson/Makefile
 create mode 100644 drivers/firmware/meson/meson_sm.c
 create mode 100644 include/dt-bindings/firmware/meson-sm.h
 create mode 100644 include/linux/firmware/meson/meson-sm.h
drivers/firmware/Kconfig +1 -0
index 6664f11..686e395 100644
@@ -199,5 +199,6 @@ config HAVE_ARM_SMCCC
 source "drivers/firmware/broadcom/Kconfig"
 source "drivers/firmware/google/Kconfig"
 source "drivers/firmware/efi/Kconfig"
+source "drivers/firmware/meson/Kconfig"
 
 endmenu
drivers/firmware/Makefile +1 -0
index 474bada..fc4bb09 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_QCOM_SCM_32)	+= qcom_scm-32.o
 CFLAGS_qcom_scm-32.o :=$(call as-instr,.arch armv7-a\n.arch_extension sec,-DREQUIRES_SEC=1) -march=armv7-a
 
 obj-y				+= broadcom/
+obj-y				+= meson/
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
 obj-$(CONFIG_UEFI_CPER)		+= efi/
drivers/firmware/meson/Kconfig new file +8 -0
new file mode 100644
index 0000000..fff11a3
@@ -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
drivers/firmware/meson/Makefile new file +1 -0
new file mode 100644
index 0000000..9ab3884
@@ -0,0 +1 @@
+obj-$(CONFIG_MESON_SM) +=	meson_sm.o
drivers/firmware/meson/meson_sm.c new file +193 -0

193 lines not on this page · raw message

include/dt-bindings/firmware/meson-sm.h new file +20 -0
new file mode 100644
index 0000000..3a52a13
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * 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_DT_H_
+#define _MESON_DT_H_
+
+#define SM_EFUSE_READ		0
+#define SM_EFUSE_WRITE		1
+#define SM_EFUSE_USER_MAX	2
+
+#endif /* _MESON_DT_H_ */
include/linux/firmware/meson/meson-sm.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH v4 1/3 firmware: Amlogic: Add secure monitor driver

Hi Carlo,

Quoted 16 lines · Carlo Caione
include/dt-bindings/firmware/meson-sm.h new file +10 -0
new file mode 100644
index 0000000..3a52a13
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * 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/dt-bindings/firmware/meson-sm.h line 20

Quoted 10 lines
include/dt-bindings/firmware/meson-sm.h new file +10 -0
+ */
+
+#ifndef _MESON_DT_H_
+#define _MESON_DT_H_
+
+#define SM_EFUSE_READ		0
+#define SM_EFUSE_WRITE		1
+#define SM_EFUSE_USER_MAX	2
+
+#endif /* _MESON_DT_H_ */

Now this has been refactored, I don't see the point of this dt-bindings header ?

These defines should take place in linux/firmware/meson/meson-sm.h

Neil

#3 lore raw

PATCH v4 1/3 firmware: Amlogic: Add secure monitor driver

Quoted 1 line · Neil Armstrong

Hi Carlo,

Hi Neil,

Quoted 30 lines · Carlo Caione
Quoted 16 lines
include/dt-bindings/firmware/meson-sm.h new file +10 -0
new file mode 100644
index 0000000..3a52a13
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2016 Endless Mobile, Inc.
+ * Author: Carlo Caione <[email protected]>
+ *
+ * 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/dt-bindings/firmware/meson-sm.h line 20

Quoted 10 lines
include/dt-bindings/firmware/meson-sm.h new file +10 -0
+ */
+
+#ifndef _MESON_DT_H_
+#define _MESON_DT_H_
+
+#define SM_EFUSE_READ		0
+#define SM_EFUSE_WRITE		1
+#define SM_EFUSE_USER_MAX	2
+
+#endif /* _MESON_DT_H_ */

Now this has been refactored, I don't see the point of this dt-bindings header ?

Quoted 1 line

These defines should take place in linux/firmware/meson/meson-sm.h

Yes, that is a possibility I considered before submitting this version and now it also seems probably the best way to do it. I'll change it in the next revision.

Thanks,

Signature · 1 line
Carlo Caione
#4 lore raw

PATCH v4 2/3 documentation: Add secure monitor binding documentation

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add the binding documentation for the Amlogic secure monitor driver.

---
 .../bindings/firmware/meson/meson_sm.txt           | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt
Documentation/devicetree/bindings/firmware/meson/meson_sm.txt new file +42 -0
new file mode 100644
index 0000000..896758d
@@ -0,0 +1,42 @@
+* 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-gxbb-sm"
+
+Example:
+
+	#include <dt-bindings/firmware/meson-sm.h>
+
+	...
+
+	firmware {
+		compatible = "simple-bus";
+
+		sm: secure-monitor {
+			compatible = "amlogic,meson-gxbb-sm";
+		};
+	};
+
+Node of a device using the secure monitor must have a custom property to
+specify the SMC32 function ID the driver is going to use.
+
+Example of the node using the secure monitor:
+
+	#include <dt-bindings/firmware/meson-sm.h>
+
+	...
+
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		secure-monitor = <&sm>;
+		amlogic,sm-cmd-read-efuse = <SM_EFUSE_READ>;
+		amlogic,sm-cmd-max-efuse = <SM_EFUSE_USER_MAX>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		...
+	};
+
Signature · 1 line
2.7.4
#5 lore raw

PATCH v4 2/3 documentation: Add secure monitor binding documentation

Hi Carlo,

Quoted 42 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Add the binding documentation for the Amlogic secure monitor driver.

---
 .../bindings/firmware/meson/meson_sm.txt           | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt
Documentation/devicetree/bindings/firmware/meson/meson_sm.txt new file +26 -0
new file mode 100644
index 0000000..896758d
@@ -0,0 +1,42 @@
+* 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-gxbb-sm"
+
+Example:
+
+	#include <dt-bindings/firmware/meson-sm.h>
+
+	...
+
+	firmware {
+		compatible = "simple-bus";
+
+		sm: secure-monitor {
+			compatible = "amlogic,meson-gxbb-sm";
+		};
+	};
+
+Node of a device using the secure monitor must have a custom property to
+specify the SMC32 function ID the driver is going to use.
+
+Example of the node using the secure monitor:

Documentation/devicetree/bindings/firmware/meson/meson_sm.txt line 36

Quoted 10 lines
Documentation/devicetree/bindings/firmware/meson/meson_sm.txt new file +10 -0
+
+	#include <dt-bindings/firmware/meson-sm.h>
+
+	...
+
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		secure-monitor = <&sm>;
+		amlogic,sm-cmd-read-efuse = <SM_EFUSE_READ>;
+		amlogic,sm-cmd-max-efuse = <SM_EFUSE_USER_MAX>;

Same here, since the compatible is "gxbb" specific, there is no need for these properties, and so no need for the dt-bindings header.

Quoted 7 lines
Documentation/devicetree/bindings/firmware/meson/meson_sm.txt new file +6 -0
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		...
+	};
+
#6 lore raw

PATCH v4 3/3 ARM64: dts: amlogic: gxbb: Enable secure monitor

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

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

---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +9 -0
index 76b3b6d..735a751 100644
@@ -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/firmware/meson-sm.h>
 
 / {
 	compatible = "amlogic,meson-gxbb";
@@ -98,6 +99,14 @@
 		method = "smc";
 	};
 
+	firmware {
+		compatible = "simple-bus";
+
+		sm: secure-monitor {
+			compatible = "amlogic,meson-gxbb-sm";
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
Signature · 1 line
2.7.4