Skip to contentSkip to conversation

Add Amlogic secure monitor and NVMEM drivers

PATCH Superseded Carlo Caione 3 participants 11 messages Aug 27, 2016 – Sep 1, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Add Amlogic secure monitor and NVMEM drivers

From: Carlo Caione <[email protected]>

I decided to respin again the secure monitor driver this time with the NVMEM driver in the same patchset to have a clear view on how a generic driver can use the monitor.

The latest patchset for the secure monitor with the Changelog is here [1].

[1] http://www.spinics.net/lists/arm-kernel/msg510441.html

Changelog:
v3:
- Add missing ACKs
- s/0x1000/SZ_4K/
v2:
- nvmem driver not using regmap anymore
- headers list cleanup
- disable sm driver for !4K kernels
- removed meson_sm_get_fw()
- better debug printing
- general cleanup

Carlo Caione (6):
firmware: Amlogic: Add secure monitor driver
documentation: Add secure monitor bindings documentation
ARM64: dts: amlogic: gxbb: Enable secure monitor
nvmem: amlogic: Add Amlogic Meson EFUSE driver
documentation: Add nvmem bindings documentation
ARM64: dts: amlogic: gxbb: Enable NVMEM

 .../bindings/firmware/meson/meson_sm.txt           |  15 ++
 .../devicetree/bindings/nvmem/amlogic-efuse.txt    |  39 ++++
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi        |  24 ++
 drivers/firmware/Kconfig                           |   1 +
 drivers/firmware/Makefile                          |   1 +
 drivers/firmware/meson/Kconfig                     |   9 +
 drivers/firmware/meson/Makefile                    |   1 +
 drivers/firmware/meson/meson_sm.c                  | 248 +++++++++++++++++++++
 drivers/nvmem/Kconfig                              |  10 +
 drivers/nvmem/Makefile                             |   2 +
 drivers/nvmem/meson-efuse.c                        |  93 ++++++++
 include/linux/firmware/meson/meson_sm.h            |  31 +++
 12 files changed, 474 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt
 create mode 100644 Documentation/devicetree/bindings/nvmem/amlogic-efuse.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 drivers/nvmem/meson-efuse.c
 create mode 100644 include/linux/firmware/meson/meson_sm.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 1/6 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          |   9 ++
 drivers/firmware/meson/Makefile         |   1 +
 drivers/firmware/meson/meson_sm.c       | 247 ++++++++++++++++++++++++++++++++
 include/linux/firmware/meson/meson_sm.h |  31 ++++
 6 files changed, 290 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/linux/firmware/meson/meson_sm.h
drivers/firmware/Kconfig +1 -0
index 0e22f24..bca172d 100644
@@ -209,5 +209,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 44a59dc..898ac41 100644
@@ -22,6 +22,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 +9 -0
new file mode 100644
index 0000000..170d7e8
@@ -0,0 +1,9 @@
+#
+# Amlogic Secure Monitor driver
+#
+config MESON_SM
+	bool
+	default ARCH_MESON
+	depends on ARM64_4K_PAGES
+	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 +247 -0

247 lines not on this page · raw message

include/linux/firmware/meson/meson_sm.h new file +31 -0
new file mode 100644
index 0000000..8e953c6
@@ -0,0 +1,31 @@
+/*
+ * 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_SM_FW_H_
+#define _MESON_SM_FW_H_
+
+enum {
+	SM_EFUSE_READ,
+	SM_EFUSE_WRITE,
+	SM_EFUSE_USER_MAX,
+};
+
+struct meson_sm_firmware;
+
+int meson_sm_call(unsigned int cmd_index, u32 *ret, u32 arg0, u32 arg1,
+		  u32 arg2, u32 arg3, u32 arg4);
+int meson_sm_call_write(void *buffer, unsigned int b_size, unsigned int cmd_index,
+			u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+int meson_sm_call_read(void *buffer, unsigned int cmd_index, u32 arg0, u32 arg1,
+		       u32 arg2, u32 arg3, u32 arg4);
+
+#endif /* _MESON_SM_FW_H_ */
Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 2/6 documentation: Add secure monitor bindings documentation

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add the binding documentation for the Amlogic secure monitor driver.

---
 .../devicetree/bindings/firmware/meson/meson_sm.txt       | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/firmware/meson/meson_sm.txt
Documentation/devicetree/bindings/firmware/meson/meson_sm.txt new file +15 -0
new file mode 100644
index 0000000..c248cd4
@@ -0,0 +1,15 @@
+* 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:
+
+	firmware {
+		sm: secure-monitor {
+			compatible = "amlogic,meson-gxbb-sm";
+		};
+	};
Signature · 1 line
2.7.4
#3 lore raw

PATCH v3 3/6 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 | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +6 -0
index e502c24..ca428e8 100644
@@ -99,6 +99,12 @@
 		method = "smc";
 	};
 
+	firmware {
+		sm: secure-monitor {
+			compatible = "amlogic,meson-gxbb-sm";
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
Signature · 1 line
2.7.4
#4 lore raw

PATCH v3 4/6 nvmem: amlogic: Add Amlogic Meson EFUSE driver

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add Amlogic EFUSE driver to access hardware data like ethernet address, serial number or IDs.

---
 drivers/nvmem/Kconfig       | 10 +++++
 drivers/nvmem/Makefile      |  2 +
 drivers/nvmem/meson-efuse.c | 93 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+)
 create mode 100644 drivers/nvmem/meson-efuse.c
drivers/nvmem/Kconfig +10 -0
index f550c45..ba140ea 100644
@@ -101,4 +101,14 @@ config NVMEM_VF610_OCOTP
 	  This driver can also be build as a module. If so, the module will
 	  be called nvmem-vf610-ocotp.
 
+config MESON_EFUSE
+	tristate "Amlogic eFuse Support"
+	depends on (ARCH_MESON || COMPILE_TEST) && MESON_SM
+	help
+	  This is a driver to retrieve specific values from the eFuse found on
+	  the Amlogic Meson SoCs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called nvmem_meson_efuse.
+
 endif
drivers/nvmem/Makefile +2 -0
index 45ab1ae..8f942a0 100644
@@ -22,3 +22,5 @@ obj-$(CONFIG_NVMEM_SUNXI_SID)	+= nvmem_sunxi_sid.o
 nvmem_sunxi_sid-y		:= sunxi_sid.o
 obj-$(CONFIG_NVMEM_VF610_OCOTP)	+= nvmem-vf610-ocotp.o
 nvmem-vf610-ocotp-y		:= vf610-ocotp.o
+obj-$(CONFIG_MESON_EFUSE)	+= nvmem_meson_efuse.o
+nvmem_meson_efuse-y		:= meson-efuse.o
drivers/nvmem/meson-efuse.c new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.7.4
#5 lore raw

PATCH v3 5/6 documentation: Add nvmem bindings documentation

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

This patch add the bindings document of Amlogic eFuse driver.

---
 .../devicetree/bindings/nvmem/amlogic-efuse.txt    | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt
Documentation/devicetree/bindings/nvmem/amlogic-efuse.txt new file +39 -0
new file mode 100644
index 0000000..fafd85b
@@ -0,0 +1,39 @@
+= Amlogic eFuse device tree bindings =
+
+Required properties:
+- compatible: should be "amlogic,meson-gxbb-efuse"
+
+= Data cells =
+Are child nodes of eFuse, bindings of which as described in
+bindings/nvmem/nvmem.txt
+
+Example:
+
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		sn: sn at 14 {
+			reg = <0x14 0x10>;
+		};
+
+		eth_mac: eth_mac at 34 {
+			reg = <0x34 0x10>;
+		};
+
+		bid: bid at 46 {
+			reg = <0x46 0x30>;
+		};
+	};
+
+= Data consumers =
+Are device nodes which consume nvmem data cells.
+
+For example:
+
+	eth_mac {
+		...
+		nvmem-cells = <&eth_mac>;
+		nvmem-cell-names = "eth_mac";
+	};
Signature · 1 line
2.7.4
#6 lore raw

PATCH v3 6/6 ARM64: dts: amlogic: gxbb: Enable NVMEM

In reply to Carlo Caione

From: Carlo Caione <[email protected]>

Add the NVMEM device node in the DTSI.

---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 18 ++++++++++++++++++
 drivers/firmware/meson/meson_sm.c           |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +18 -0
index ca428e8..aea8fd6 100644
@@ -105,6 +105,24 @@
 		};
 	};
 
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		sn: sn at 14 {
+			reg = <0x14 0x10>;
+		};
+
+		eth_mac: eth_mac at 34 {
+			reg = <0x34 0x10>;
+		};
+
+		bid: bid at 46 {
+			reg = <0x46 0x30>;
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
drivers/firmware/meson/meson_sm.c +2 -1
index bba594e..b0d2549 100644
@@ -21,6 +21,7 @@
 #include <linux/of_device.h>
 #include <linux/printk.h>
 #include <linux/types.h>
+#include <linux/sizes.h>
 
 #include <linux/firmware/meson/meson_sm.h>
 
@@ -38,7 +39,7 @@ struct meson_sm_chip {
 };
 
 struct meson_sm_chip gxbb_chip = {
-	.shmem_size		= 0x1000,
+	.shmem_size		= SZ_4K,
 	.cmd_shmem_in_base	= 0x82000020,
 	.cmd_shmem_out_base	= 0x82000021,
 	.cmd = {
Signature · 1 line
2.7.4
maintainer
#7 lore raw

PATCH v3 6/6 ARM64: dts: amlogic: gxbb: Enable NVMEM

Hi Carlo,

Quoted 52 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Add the NVMEM device node in the DTSI.

---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 18 ++++++++++++++++++
 drivers/firmware/meson/meson_sm.c           |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +18 -0
index ca428e8..aea8fd6 100644
@@ -105,6 +105,24 @@
 		};
 	};
 
+	efuse: efuse {
+		compatible = "amlogic,meson-gxbb-efuse";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		sn: sn at 14 {
+			reg = <0x14 0x10>;
+		};
+
+		eth_mac: eth_mac at 34 {
+			reg = <0x34 0x10>;
+		};
+
+		bid: bid at 46 {
+			reg = <0x46 0x30>;
+		};
+	};
+
 	timer {
 		compatible = "arm,armv8-timer";
 		interrupts = <GIC_PPI 13
drivers/firmware/meson/meson_sm.c +1 -0
index bba594e..b0d2549 100644
@@ -21,6 +21,7 @@
 #include <linux/of_device.h>
 #include <linux/printk.h>
 #include <linux/types.h>
+#include <linux/sizes.h>
 
 #include <linux/firmware/meson/meson_sm.h>
 

drivers/firmware/meson/meson_sm.c struct meson_sm_chip { · line 45

Quoted 8 lines
drivers/firmware/meson/meson_sm.c +1 -1
@@ -38,7 +39,7 @@ struct meson_sm_chip {
 };
 
 struct meson_sm_chip gxbb_chip = {
-	.shmem_size		= 0x1000,
+	.shmem_size		= SZ_4K,
 	.cmd_shmem_in_base	= 0x82000020,
 	.cmd_shmem_out_base	= 0x82000021,
 	.cmd = {

This change doesn't reallly belong in this patch, and driver changes in DT patches makes it hard to keep the DT changes separate from driver changes, which is how we like to manage things in arm-soc.

I've dropped it from this patch, and folded it into PATCH 1/6.

Thanks,

Kevin

#8 lore raw

PATCH v3 6/6 ARM64: dts: amlogic: gxbb: Enable NVMEM

Quoted 58 lines · Kevin Hilman

Hi Carlo,

Quoted 54 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Add the NVMEM device node in the DTSI.

---
 arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 18 ++++++++++++++++++
 drivers/firmware/meson/meson_sm.c           |  3 ++-
 2 files changed, 20 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +18 -0
index ca428e8..aea8fd6 100644
@@ -105,6 +105,24 @@
              };
      };
 
+     efuse: efuse {
+             compatible = "amlogic,meson-gxbb-efuse";
+             #address-cells = <1>;
+             #size-cells = <1>;
+
+             sn: sn at 14 {
+                     reg = <0x14 0x10>;
+             };
+
+             eth_mac: eth_mac at 34 {
+                     reg = <0x34 0x10>;
+             };
+
+             bid: bid at 46 {
+                     reg = <0x46 0x30>;
+             };
+     };
+
      timer {
              compatible = "arm,armv8-timer";
              interrupts = <GIC_PPI 13
drivers/firmware/meson/meson_sm.c +1 -0
index bba594e..b0d2549 100644
@@ -21,6 +21,7 @@
 #include <linux/of_device.h>
 #include <linux/printk.h>
 #include <linux/types.h>
+#include <linux/sizes.h>
 
 #include <linux/firmware/meson/meson_sm.h>
 
@@ -38,7 +39,7 @@ struct meson_sm_chip {
 };
 
Quoted 10 lines

drivers/firmware/meson/meson_sm.c struct meson_sm_chip { · line 45

Quoted 6 lines
drivers/firmware/meson/meson_sm.c +1 -1
 struct meson_sm_chip gxbb_chip = {
-     .shmem_size             = 0x1000,
+     .shmem_size             = SZ_4K,
      .cmd_shmem_in_base      = 0x82000020,
      .cmd_shmem_out_base     = 0x82000021,
      .cmd = {

This change doesn't reallly belong in this patch, and driver changes in DT patches makes it hard to keep the DT changes separate from driver changes, which is how we like to manage things in arm-soc.

Damn. Sorry, probably amended the wrong patch when trying to address mark's comments.

Quoted 1 line

I've dropped it from this patch, and folded it into PATCH 1/6.

Where it belongs.

Thank you,

Signature · 1 line
Carlo Caione  |  +39.340.80.30.096  |  Endless
#9 lore raw

v3 cover Add Amlogic secure monitor and NVMEM drivers

In reply to Carlo Caione
Quoted 5 lines · Carlo Caione

From: Carlo Caione <[email protected]>

I decided to respin again the secure monitor driver this time with the NVMEM driver in the same patchset to have a clear view on how a generic driver can use the monitor.

Kevin,
finally I found the time to respin this patchset for the last time. Since we have now all the ACKs we need, could you please take all the 6 patches in your tree?

Thanks,

Signature · 1 line
Carlo Caione
maintainer
#10 lore raw

v3 cover Add Amlogic secure monitor and NVMEM drivers

Quoted 11 lines · Carlo Caione
Quoted 5 lines · Carlo Caione

From: Carlo Caione <[email protected]>

I decided to respin again the secure monitor driver this time with the NVMEM driver in the same patchset to have a clear view on how a generic driver can use the monitor.

Kevin,
finally I found the time to respin this patchset for the last time. Since we have now all the ACKs we need, could you please take all the 6 patches in your tree?

Patches 1, 4 applied to drivers branch. The rest applied to dt64 branch.

Thanks,

Kevin