Skip to contentSkip to conversation

generic TEE subsystem

PATCH Superseded Jens Wiklander 6 participants 20 messages Aug 19, 2015 – Sep 16, 2015

Subsystems (7)

v5 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v5 cover generic TEE subsystem

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc.

Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include:
- Secure key handling where the OS may or may not have direct access to key material.
- E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment.
- Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc.
- Secure boot to ensure that loaded binaries haven?t been tampered with. It?s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot.
- Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution.

A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that you also could do by leveraging a TEE.

Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key.

Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor.

To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://github.com/OP-TEE/optee_os) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also.

"tee: generic TEE subsystem" brings in the generic TEE subsystem which helps when writing a driver for a specific TEE, for example, OP-TEE.

"tee: add OP-TEE driver" is an OP-TEE driver which uses the subsystem to do its work.

This patch set has been prepared in cooperation with Javier Gonz?lez who proposed "Generic TrustZone Driver in Linux Kernel" patches 28 Nov 2014,
https://lwn.net/Articles/623380/ . We've since then changed the scope to TEE instead of TrustZone.

We have discussed the design on tee-dev at lists.linaro.org (archive at
https://lists.linaro.org/pipermail/tee-dev/) with people from other companies, including Valentin Manea <[email protected]>, Emmanuel MICHEL <[email protected]>,
Jean-michel DELORME <[email protected]>,
and Joakim Bech <[email protected]>. Our main concern has been to agree on something that is generic enough to support many different TEEs while still keeping the interface together.

v5:
* Replaced kref reference counting for the device with a size_t instead as the counter is always protected by a mutex

v4:
* Rebased on 4.1
* Redesigned the synchronization around entry exit of normal SMC
* Replaced rwsem on the driver instance with kref and completion since rwsem wasn't intended to be used in this way
* Expanded the TEE_IOCTL_PARAM_ATTR_TYPE_MASK to make room for future additional parameter types
* Documents TEE subsystem and OP-TEE driver
* Replaced TEE_IOC_CMD with TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE, TEE_IOC_CANCEL and TEE_IOC_CLOSE_SESSION
* DT bindings in a separate patch
* Assembly parts moved to arch/arm and arch/arm64 respectively, in a separate patch
* Redefined/clarified the meaning of OPTEE_SMC_SHM_CACHED
* Removed CMA usage to limit the scope of the patch set

v3:
* Rebased on 4.1-rc3 (dma_buf_export() API change)
* A couple of small sparse fixes
* Documents bindings for OP-TEE driver
* Updated MAINTAINERS

v2:
* Replaced the stubbed OP-TEE driver with a real OP-TEE driver
* Removed most APIs not needed by OP-TEE in current state
* Update Documentation/ioctl/ioctl-number.txt with correct path to tee.h
* Rename tee_shm_pool_alloc_cma() to tee_shm_pool_alloc()
* Moved tee.h into include/uapi/linux/
* Redefined tee.h IOCTL macros to be directly based on _IOR and friends
* Removed version info on the API to user space, a data blob which can contain an UUID is left for user space to be able to tell which protocol to use in TEE_IOC_CMD
* Changed user space exposed structures to only have types with __ prefix
* Dropped THIS_MODULE from tee_fops
* Reworked how the driver is registered and ref counted:
- moved from using an embedded struct miscdevice to an embedded struct device.
- uses an struct rw_semaphore as synchronization for driver detachment
- uses alloc/register pattern from TPM

Thanks,
Jens

Jens Wiklander (5):
arm/arm64: add smccc ARCH32
dt/bindings: add bindings for optee
tee: generic TEE subsystem
tee: add OP-TEE driver
Documentation: tee subsystem and op-tee driver

 Documentation/00-INDEX                             |   2 +
 Documentation/devicetree/bindings/optee/optee.txt  |  17 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 Documentation/ioctl/ioctl-number.txt               |   1 +
 Documentation/tee.txt                              | 117 +++
 MAINTAINERS                                        |  14 +
 arch/arm/Kconfig                                   |   4 +
 arch/arm/kernel/Makefile                           |   2 +
 arch/arm/kernel/smccc-call.S                       |  26 +
 arch/arm/kernel/smccc.c                            |  17 +
 arch/arm64/Kconfig                                 |   4 +
 arch/arm64/kernel/Makefile                         |   1 +
 arch/arm64/kernel/smccc-call.S                     |  34 +
 arch/arm64/kernel/smccc.c                          |  17 +
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/tee/Kconfig                                |  18 +
 drivers/tee/Makefile                               |   4 +
 drivers/tee/optee/Kconfig                          |   8 +
 drivers/tee/optee/Makefile                         |   5 +
 drivers/tee/optee/call.c                           | 390 ++++++++++
 drivers/tee/optee/core.c                           | 453 +++++++++++
 drivers/tee/optee/optee_msg.h                      | 334 +++++++++
 drivers/tee/optee/optee_private.h                  | 129 ++++
 drivers/tee/optee/optee_smc.h                      | 466 ++++++++++++
 drivers/tee/optee/rpc.c                            | 248 ++++++
 drivers/tee/optee/supp.c                           | 212 ++++++
 drivers/tee/tee.c                                  | 834 +++++++++++++++++++++
 drivers/tee/tee_private.h                          |  80 ++
 drivers/tee/tee_shm.c                              | 324 ++++++++
 drivers/tee/tee_shm_pool.c                         | 133 ++++
 include/linux/arm-smccc.h                          |  79 ++
 include/linux/tee_drv.h                            | 306 ++++++++
 include/uapi/linux/tee.h                           | 376 ++++++++++
 34 files changed, 4659 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/optee/optee.txt
 create mode 100644 Documentation/tee.txt
 create mode 100644 arch/arm/kernel/smccc-call.S
 create mode 100644 arch/arm/kernel/smccc.c
 create mode 100644 arch/arm64/kernel/smccc-call.S
 create mode 100644 arch/arm64/kernel/smccc.c
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c
 create mode 100644 drivers/tee/tee.c
 create mode 100644 drivers/tee/tee_private.h
 create mode 100644 drivers/tee/tee_shm.c
 create mode 100644 drivers/tee/tee_shm_pool.c
 create mode 100644 include/linux/arm-smccc.h
 create mode 100644 include/linux/tee_drv.h
 create mode 100644 include/uapi/linux/tee.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v5 1/5 arm/arm64: add smccc ARCH32

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

---
 arch/arm/Kconfig               |  4 +++
 arch/arm/kernel/Makefile       |  2 ++
 arch/arm/kernel/smccc-call.S   | 26 ++++++++++++++
 arch/arm/kernel/smccc.c        | 17 +++++++++
 arch/arm64/Kconfig             |  4 +++
 arch/arm64/kernel/Makefile     |  1 +
 arch/arm64/kernel/smccc-call.S | 34 ++++++++++++++++++
 arch/arm64/kernel/smccc.c      | 17 +++++++++
 include/linux/arm-smccc.h      | 79 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 184 insertions(+)
 create mode 100644 arch/arm/kernel/smccc-call.S
 create mode 100644 arch/arm/kernel/smccc.c
 create mode 100644 arch/arm64/kernel/smccc-call.S
 create mode 100644 arch/arm64/kernel/smccc.c
 create mode 100644 include/linux/arm-smccc.h
arch/arm/Kconfig +4 -0
index 45df48b..75e4da3 100644
@@ -221,6 +221,9 @@ config NEED_RET_TO_USER
 config ARCH_MTD_XIP
 	bool
 
+config HAVE_SMCCC
+	bool
+
 config VECTORS_BASE
 	hex
 	default 0xffff0000 if MMU || CPU_HIGH_VECTOR
@@ -324,6 +327,7 @@ config ARCH_MULTIPLATFORM
 	select CLKSRC_OF
 	select COMMON_CLK
 	select GENERIC_CLOCKEVENTS
+	select HAVE_SMCCC if CPU_V7
 	select MIGHT_HAVE_PCI
 	select MULTI_IRQ_HANDLER
 	select SPARSE_IRQ
arch/arm/kernel/Makefile +2 -0
index 752725d..8cdd25b 100644
@@ -90,4 +90,6 @@ obj-y				+= psci.o psci-call.o
 obj-$(CONFIG_SMP)		+= psci_smp.o
 endif
 
+obj-$(CONFIG_HAVE_SMCCC)	+= smccc-call.o smccc.o
+
 extra-y := $(head-y) vmlinux.lds
arch/arm/kernel/smccc-call.S new file +26 -0
new file mode 100644
index 0000000..05bc554
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#include <asm/opcodes-sec.h>
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+	push	{r4-r8, lr}
+	mov	r8, r0
+	ldm	r8, {r0-r7}
+	__SMC(0)
+	stm	r8, {r0-r7}
+	pop	{r4-r8, pc}
+ENDPROC(smccc_call32)
arch/arm/kernel/smccc.c new file +17 -0
new file mode 100644
index 0000000..ba4039e
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/export.h>
+#include <linux/arm-smccc.h>
+
+EXPORT_SYMBOL_GPL(smccc_call32);
arch/arm64/Kconfig +4 -0
index 7796af4..b3ea778 100644
@@ -83,6 +83,7 @@ config ARM64
 	select SPARSE_IRQ
 	select SYSCTL_EXCEPTION_TRACE
 	select HAVE_CONTEXT_TRACKING
+	select HAVE_SMCCC
 	help
 	  ARM 64-bit (AArch64) Linux support.
 
@@ -146,6 +147,9 @@ config KERNEL_MODE_NEON
 config FIX_EARLYCON_MEM
 	def_bool y
 
+config HAVE_SMCCC
+	bool
+
 config PGTABLE_LEVELS
 	int
 	default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42
arch/arm64/kernel/Makefile +1 -0
index 426d076..f7804f7 100644
@@ -36,6 +36,7 @@ arm64-obj-$(CONFIG_EFI)			+= efi.o efi-stub.o efi-entry.o
 arm64-obj-$(CONFIG_PCI)			+= pci.o
 arm64-obj-$(CONFIG_ARMV8_DEPRECATED)	+= armv8_deprecated.o
 arm64-obj-$(CONFIG_ACPI)		+= acpi.o
+arm64-obj-$(CONFIG_HAVE_SMCCC)		+= smccc-call.o smccc.o
 
 obj-y					+= $(arm64-obj-y) vdso/
 obj-m					+= $(arm64-obj-m)
arch/arm64/kernel/smccc-call.S new file +34 -0
new file mode 100644
index 0000000..3ce7fe8
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS	0
+#define SMC_PARAM_W2_OFFS	8
+#define SMC_PARAM_W4_OFFS	16
+#define SMC_PARAM_W6_OFFS	24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+	stp	x28, x30, [sp, #-16]!
+	mov	x28, x0
+	ldp	w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+	ldp	w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+	ldp	w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+	ldp	w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+	smc	#0
+	stp	w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+	stp	w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+	ldp	x28, x30, [sp], #16
+	ret
+ENDPROC(smccc_call32)
arch/arm64/kernel/smccc.c new file +17 -0
new file mode 100644
index 0000000..ba4039e
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/export.h>
+#include <linux/arm-smccc.h>
+
+EXPORT_SYMBOL_GPL(smccc_call32);
include/linux/arm-smccc.h new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 7 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

Quoted 10 lines
---
 arch/arm/Kconfig               |  4 +++
 arch/arm/kernel/Makefile       |  2 ++
 arch/arm/kernel/smccc-call.S   | 26 ++++++++++++++
 arch/arm/kernel/smccc.c        | 17 +++++++++
 arch/arm64/Kconfig             |  4 +++
 arch/arm64/kernel/Makefile     |  1 +
 arch/arm64/kernel/smccc-call.S | 34 ++++++++++++++++++
 arch/arm64/kernel/smccc.c      | 17 +++++++++
 include/linux/arm-smccc.h      | 79 

++++++++++++++++++++++++++++++++++++++++++

arch/arm64/kernel/Makefile arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o

Quoted 122 lines
 9 files changed, 184 insertions(+)
 create mode 100644 arch/arm/kernel/smccc-call.S
 create mode 100644 arch/arm/kernel/smccc.c
 create mode 100644 arch/arm64/kernel/smccc-call.S
 create mode 100644 arch/arm64/kernel/smccc.c
 create mode 100644 include/linux/arm-smccc.h
arch/arm/Kconfig +4 -0
index 45df48b..75e4da3 100644
@@ -221,6 +221,9 @@ config NEED_RET_TO_USER
 config ARCH_MTD_XIP
 	bool
 
+config HAVE_SMCCC
+	bool
+
 config VECTORS_BASE
 	hex
 	default 0xffff0000 if MMU || CPU_HIGH_VECTOR
@@ -324,6 +327,7 @@ config ARCH_MULTIPLATFORM
 	select CLKSRC_OF
 	select COMMON_CLK
 	select GENERIC_CLOCKEVENTS
+	select HAVE_SMCCC if CPU_V7
 	select MIGHT_HAVE_PCI
 	select MULTI_IRQ_HANDLER
 	select SPARSE_IRQ
arch/arm/kernel/Makefile +2 -0
index 752725d..8cdd25b 100644
@@ -90,4 +90,6 @@ obj-y				+= psci.o psci-call.o
 obj-$(CONFIG_SMP)		+= psci_smp.o
 endif
 
+obj-$(CONFIG_HAVE_SMCCC)	+= smccc-call.o smccc.o
+
 extra-y := $(head-y) vmlinux.lds
arch/arm/kernel/smccc-call.S new file +26 -0
new file mode 100644
index 0000000..05bc554
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#include <asm/opcodes-sec.h>
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+	push	{r4-r8, lr}
+	mov	r8, r0
+	ldm	r8, {r0-r7}
+	__SMC(0)
+	stm	r8, {r0-r7}
+	pop	{r4-r8, pc}
+ENDPROC(smccc_call32)
arch/arm/kernel/smccc.c new file +17 -0
new file mode 100644
index 0000000..ba4039e
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/export.h>
+#include <linux/arm-smccc.h>
+
+EXPORT_SYMBOL_GPL(smccc_call32);
arch/arm64/Kconfig +4 -0
index 7796af4..b3ea778 100644
@@ -83,6 +83,7 @@ config ARM64
 	select SPARSE_IRQ
 	select SYSCTL_EXCEPTION_TRACE
 	select HAVE_CONTEXT_TRACKING
+	select HAVE_SMCCC
 	help
 	  ARM 64-bit (AArch64) Linux support.
 
@@ -146,6 +147,9 @@ config KERNEL_MODE_NEON
 config FIX_EARLYCON_MEM
 	def_bool y
 
+config HAVE_SMCCC
+	bool
+
 config PGTABLE_LEVELS
 	int
 	default 2 if ARM64_64K_PAGES && ARM64_VA_BITS_42
arch/arm64/kernel/Makefile +0 -0
index 426d076..f7804f7 100644
@@ -36,6 +36,7 @@ arm64-obj-$(CONFIG_EFI)			+= efi.o efi-stub.o 

efi-entry.o

Review

Quoted 8 lines
arch/arm64/kernel/Makefile +1 -0
 arm64-obj-$(CONFIG_PCI)			+= pci.o
 arm64-obj-$(CONFIG_ARMV8_DEPRECATED)	+= armv8_deprecated.o
 arm64-obj-$(CONFIG_ACPI)		+= acpi.o
+arm64-obj-$(CONFIG_HAVE_SMCCC)		+= smccc-call.o smccc.o
 
 obj-y					+= $(arm64-obj-y) vdso/
 obj-m					+= $(arm64-obj-m)
(quoted diff) +0 -0

b/arch/arm64/kernel/smccc-call.S

Quoted 78 lines

new file mode 100644
index 0000000..3ce7fe8

arch/arm64/kernel/smccc-call.S new file +34 -0
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS	0
+#define SMC_PARAM_W2_OFFS	8
+#define SMC_PARAM_W4_OFFS	16
+#define SMC_PARAM_W6_OFFS	24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+	stp	x28, x30, [sp, #-16]!
+	mov	x28, x0
+	ldp	w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+	ldp	w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+	ldp	w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+	ldp	w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+	smc	#0
+	stp	w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+	stp	w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+	ldp	x28, x30, [sp], #16
+	ret
+ENDPROC(smccc_call32)
arch/arm64/kernel/smccc.c new file +17 -0
new file mode 100644
index 0000000..ba4039e
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/export.h>
+#include <linux/arm-smccc.h>
+
+EXPORT_SYMBOL_GPL(smccc_call32);
include/linux/arm-smccc.h new file +10 -0
new file mode 100644
index 0000000..9b8d775
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

include/linux/arm-smccc.h line 20

Quoted 10 lines
include/linux/arm-smccc.h new file +10 -0
+ * GNU General Public License for more details.
+ *
+ */
+#ifndef __LINUX_ARM_SMCCC_H
+#define __LINUX_ARM_SMCCC_H
+
+#include <linux/types.h>
+
+/*
+ * This file provideds defines common defines for ARM SMC Calling

typos here?

include/linux/arm-smccc.h line 25

Quoted 5 lines
include/linux/arm-smccc.h new file +5 -0
+ * Convention as specified in
+ * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
+ */
+
+#define SMCCC_SMC_32			(0 << 30)

0 << 30 is just 0, and so meaningless.
It's better to introduce SMCCC_IS_32() macro instead.

include/linux/arm-smccc.h line 28

Quoted 3 lines
include/linux/arm-smccc.h new file +3 -0
+#define SMCCC_SMC_64			(1 << 30)
+#define SMCCC_FAST_CALL			(1 << 31)
+#define SMCCC_STD_CALL			(0 << 31)

The same

Quoted 33 lines
include/linux/arm-smccc.h new file +33 -0
+
+#define SMCCC_OWNER_MASK		0x3F
+#define SMCCC_OWNER_SHIFT		24
+
+#define SMCCC_FUNC_MASK			0xFFFF
+
+#define SMCCC_IS_FAST_CALL(smc_val)	((smc_val) & SMCCC_FAST_CALL)
+#define SMCCC_IS_64(smc_val)		((smc_val) & SMCCC_SMC_64)
+#define SMCCC_FUNC_NUM(smc_val)		((smc_val) & SMCCC_FUNC_MASK)
+#define SMCCC_OWNER_NUM(smc_val) \
+	(((smc_val) >> SMCCC_OWNER_SHIFT) & SMCCC_OWNER_MASK)
+
+#define SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
+			((type) | (calling_convention) | \
+			(((owner) & SMCCC_OWNER_MASK) << SMCCC_OWNER_SHIFT) | \
+			((func_num) & SMCCC_FUNC_MASK))
+
+#define SMCCC_OWNER_ARCH		0
+#define SMCCC_OWNER_CPU			1
+#define SMCCC_OWNER_SIP			2
+#define SMCCC_OWNER_OEM			3
+#define SMCCC_OWNER_STANDARD		4
+#define SMCCC_OWNER_TRUSTED_APP		48
+#define SMCCC_OWNER_TRUSTED_APP_END	49
+#define SMCCC_OWNER_TRUSTED_OS		50
+#define SMCCC_OWNER_TRUSTED_OS_END	63
+
+struct smccc_param32 {
+	u32 a0;
+	u32 a1;
+	u32 a2;
+	u32 a3;
+	u32 a4;

include/linux/arm-smccc.h

Quoted 10 lines
include/linux/arm-smccc.h new file +10 -0
+	u32 a5;
+	u32 a6;
+	u32 a7;
+};
+
+/**
+ * smccc_call32() - make ARCH32 SMC calls
+ * @param: values to pass in registers 0 to 7
+ *
+ * This function is used to make SMC calls following SMC Calling 

Convention

include/linux/arm-smccc.h line 73

Quoted 2 lines
include/linux/arm-smccc.h new file +2 -0
+ * for ARCH32 calls. The content of the supplied param are copied to
+ * registers 0 to 7 prior to the SMC instruction. Values a0..a3 are 

updated

Quoted 14 lines
include/linux/arm-smccc.h new file +6 -1
+ * with the content from register 0 to 3 on return from the SMC
+ * instruction.
+ */
+void smccc_call32(struct smccc_param32 *param);
+
+#endif /*__LINUX_ARM_SMCCC_H*/
--

1.9.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

On Wed, Aug 19, 2015 at 01:56:39PM +0300, Yury wrote:
[...]

Quoted 16 lines
Quoted 16 lines

+++ b/include/linux/arm-smccc.h

include/linux/arm-smccc.h new file +14 -0
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#ifndef __LINUX_ARM_SMCCC_H
Quoted 8 lines

include/linux/arm-smccc.h line 20

Quoted 6 lines
include/linux/arm-smccc.h new file +6 -0
+#define __LINUX_ARM_SMCCC_H
+
+#include <linux/types.h>
+
+/*
+ * This file provideds defines common defines for ARM SMC Calling

typos here?

Thanks

Quoted 9 lines

include/linux/arm-smccc.h line 25

Quoted 6 lines
include/linux/arm-smccc.h new file +5 -0
+ * Convention as specified in
+ * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
+ */
+
+#define SMCCC_SMC_32			(0 << 30)

0 << 30 is just 0, and so meaningless.
It's better to introduce SMCCC_IS_32() macro instead.

SMCCC_SMC_32 is used as an argument for SMCCC_CALL_VAL (example in "[PATCH v5 4/5] tee: add OP-TEE driver" drivers/tee/optee/optee_smc.h). Shifting 0 here is still 0 as you point out, but it connects it with the other define SMCCC_SMC_64.

Quoted 64 lines

include/linux/arm-smccc.h line 28

Quoted 4 lines
include/linux/arm-smccc.h new file +3 -0
+#define SMCCC_SMC_64			(1 << 30)
+#define SMCCC_FAST_CALL			(1 << 31)
+#define SMCCC_STD_CALL			(0 << 31)

The same

Quoted 33 lines
include/linux/arm-smccc.h new file +33 -0
+
+#define SMCCC_OWNER_MASK		0x3F
+#define SMCCC_OWNER_SHIFT		24
+
+#define SMCCC_FUNC_MASK			0xFFFF
+
+#define SMCCC_IS_FAST_CALL(smc_val)	((smc_val) & SMCCC_FAST_CALL)
+#define SMCCC_IS_64(smc_val)		((smc_val) & SMCCC_SMC_64)
+#define SMCCC_FUNC_NUM(smc_val)		((smc_val) & SMCCC_FUNC_MASK)
+#define SMCCC_OWNER_NUM(smc_val) \
+	(((smc_val) >> SMCCC_OWNER_SHIFT) & SMCCC_OWNER_MASK)
+
+#define SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
+			((type) | (calling_convention) | \
+			(((owner) & SMCCC_OWNER_MASK) << SMCCC_OWNER_SHIFT) | \
+			((func_num) & SMCCC_FUNC_MASK))
+
+#define SMCCC_OWNER_ARCH		0
+#define SMCCC_OWNER_CPU			1
+#define SMCCC_OWNER_SIP			2
+#define SMCCC_OWNER_OEM			3
+#define SMCCC_OWNER_STANDARD		4
+#define SMCCC_OWNER_TRUSTED_APP		48
+#define SMCCC_OWNER_TRUSTED_APP_END	49
+#define SMCCC_OWNER_TRUSTED_OS		50
+#define SMCCC_OWNER_TRUSTED_OS_END	63
+
+struct smccc_param32 {
+	u32 a0;
+	u32 a1;
+	u32 a2;
+	u32 a3;
+	u32 a4;

include/linux/arm-smccc.h

Quoted 10 lines
include/linux/arm-smccc.h new file +10 -0
+	u32 a5;
+	u32 a6;
+	u32 a7;
+};
+
+/**
+ * smccc_call32() - make ARCH32 SMC calls
+ * @param: values to pass in registers 0 to 7
+ *
+ * This function is used to make SMC calls following SMC Calling

Convention

Review line 73

Quoted 2 lines
(quoted diff) +2 -0
+ * for ARCH32 calls. The content of the supplied param are copied to
+ * registers 0 to 7 prior to the SMC instruction. Values a0..a3

are updated

Quoted 10 lines
include/linux/arm-smccc.h new file +6 -1
+ * with the content from register 0 to 3 on return from the SMC
+ * instruction.
+ */
+void smccc_call32(struct smccc_param32 *param);
+
+#endif /*__LINUX_ARM_SMCCC_H*/
--

1.9.1

Quoted 4 lines
Quoted 4 lines

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

--
Thanks,
Jens

#4 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

In reply to Jens Wiklander
Quoted 4 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

[...]

Quoted 19 lines
arch/arm64/kernel/smccc-call.S new file +13 -0
new file mode 100644
index 0000000..3ce7fe8
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

arch/arm64/kernel/smccc-call.S line 23

Quoted 10 lines
arch/arm64/kernel/smccc-call.S new file +10 -0
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS      0
+#define SMC_PARAM_W2_OFFS      8
+#define SMC_PARAM_W4_OFFS      16
+#define SMC_PARAM_W6_OFFS      24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+       stp     x28, x30, [sp, #-16]!

Why are you saving lr?

arch/arm64/kernel/smccc-call.S line 34

Quoted 11 lines
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

Will

#5 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 51 lines · Will Deacon
Quoted 4 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

[...]

Quoted 19 lines
arch/arm64/kernel/smccc-call.S new file +13 -0
new file mode 100644
index 0000000..3ce7fe8
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */

arch/arm64/kernel/smccc-call.S line 23

Quoted 10 lines
arch/arm64/kernel/smccc-call.S new file +10 -0
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS      0
+#define SMC_PARAM_W2_OFFS      8
+#define SMC_PARAM_W4_OFFS      16
+#define SMC_PARAM_W6_OFFS      24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+       stp     x28, x30, [sp, #-16]!

Why are you saving lr?

arch/arm64/kernel/smccc-call.S line 34

Quoted 11 lines
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)
Quoted 3 lines

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

I think that make sense to make smc, hvc calling more generic. Remove psci name from __invoke_psci_fn_smc and just use it in other drivers.

Thanks,
Michal

#6 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

In reply to Will Deacon
Quoted 30 lines · Will Deacon
Quoted 4 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

[...]

Quoted 23 lines
arch/arm64/kernel/smccc-call.S new file +17 -0
new file mode 100644
index 0000000..3ce7fe8
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS      0
+#define SMC_PARAM_W2_OFFS      8
Quoted 8 lines

arch/arm64/kernel/smccc-call.S line 23

Quoted 6 lines
arch/arm64/kernel/smccc-call.S new file +6 -0
+#define SMC_PARAM_W4_OFFS      16
+#define SMC_PARAM_W6_OFFS      24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+       stp     x28, x30, [sp, #-16]!

Why are you saving lr?

Agree, no point in saving lr, but I still need to decrease sp with 16 to maintain correct alignment. I'll do it with an str instruction instead.

Quoted 13 lines

arch/arm64/kernel/smccc-call.S line 34

Quoted 12 lines
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)
Quoted 3 lines

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

I assume you're referring to when to use "hvc" and "smc".

I would rather consider smccc_call32() a primitive function that a driver may use if it's configured to do so, for instance via DT. When an "hvc" should be used instead of an "smc" up to the driver to decide based how it's configured.

When merging psci-call.S and smccc-call.S into fw-call.S, what should I do about smccc.c? I need to export the smccc_call32 function somewhere as it could be used from a loadable module.

--
Thanks,
Jens

maintainer
#7 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 6 lines · Jens Wiklander
Quoted 5 lines · Will Deacon
Quoted 4 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

[...]

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)
Quoted 5 lines
Quoted 3 lines

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

I assume you're referring to when to use "hvc" and "smc".

I assume he's on about passing the values in registers rather than a struct.

Quoted 1 line

From the looks of the SMC Calling Convention documentation, it's valid to have

return values in registers r0-r3, which necessitates the use of a struct (at least for the return values).

Thanks,
Mark.

#8 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

In reply to Jens Wiklander
Quoted 40 lines · Jens Wiklander
Quoted 30 lines · Will Deacon
Quoted 4 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

[...]

Quoted 23 lines
arch/arm64/kernel/smccc-call.S new file +17 -0
new file mode 100644
index 0000000..3ce7fe8
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS      0
+#define SMC_PARAM_W2_OFFS      8
Quoted 8 lines

arch/arm64/kernel/smccc-call.S line 23

Quoted 6 lines
arch/arm64/kernel/smccc-call.S new file +6 -0
+#define SMC_PARAM_W4_OFFS      16
+#define SMC_PARAM_W6_OFFS      24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+       stp     x28, x30, [sp, #-16]!

Why are you saving lr?

Quoted 2 lines

Agree, no point in saving lr, but I still need to decrease sp with 16 to maintain correct alignment. I'll do it with an str instruction instead.

That or pad out with xzr

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)
Quoted 5 lines
Quoted 3 lines

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

I assume you're referring to when to use "hvc" and "smc".

No, I mean use a C prototype to avoid marshalling the parameters in assembly like this. As Rutland pointed out, the return value is a bit messy, but the arguments align nicely with the PCS afaict.

Will

#9 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 63 lines · Will Deacon
Quoted 40 lines · Jens Wiklander
Quoted 30 lines · Will Deacon
Quoted 4 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

[...]

Quoted 23 lines
arch/arm64/kernel/smccc-call.S new file +17 -0
new file mode 100644
index 0000000..3ce7fe8
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS      0
+#define SMC_PARAM_W2_OFFS      8
Quoted 8 lines

arch/arm64/kernel/smccc-call.S line 23

Quoted 6 lines
arch/arm64/kernel/smccc-call.S new file +6 -0
+#define SMC_PARAM_W4_OFFS      16
+#define SMC_PARAM_W6_OFFS      24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+       stp     x28, x30, [sp, #-16]!

Why are you saving lr?

Quoted 2 lines

Agree, no point in saving lr, but I still need to decrease sp with 16 to maintain correct alignment. I'll do it with an str instruction instead.

That or pad out with xzr

Quoted 17 lines
Quoted 16 lines

arch/arm64/kernel/smccc-call.S line 34

Quoted 12 lines
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

Quoted 5 lines
Quoted 1 line

I assume you're referring to when to use "hvc" and "smc".

No, I mean use a C prototype to avoid marshalling the parameters in assembly like this. As Rutland pointed out, the return value is a bit messy, but the arguments align nicely with the PCS afaict.

If possible I'd like the function to have the same prototype for both arm and arm64. For arm it's not possible to supply more than 4 parameters. To fully support SMC Calling Convention we need to be able to pass 8 parameters and have 4 return values. The OP-TEE driver in this patch set depends on this. I don't see how we can avoid the marshalling here.

We could have two versions of the SMCCC functions, one simplified which only uses registers and one complete like this one with marshalling.

Thanks,
Jens

#10 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 77 lines · Jens Wiklander
Quoted 63 lines · Will Deacon
Quoted 40 lines · Jens Wiklander
Quoted 30 lines · Will Deacon
Quoted 4 lines · Jens Wiklander

Adds helpers to do SMC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.

[...]

Quoted 23 lines
arch/arm64/kernel/smccc-call.S new file +17 -0
new file mode 100644
index 0000000..3ce7fe8
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015, Linaro Limited
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/linkage.h>
+
+#define SMC_PARAM_W0_OFFS      0
+#define SMC_PARAM_W2_OFFS      8
Quoted 8 lines

arch/arm64/kernel/smccc-call.S line 23

Quoted 6 lines
arch/arm64/kernel/smccc-call.S new file +6 -0
+#define SMC_PARAM_W4_OFFS      16
+#define SMC_PARAM_W6_OFFS      24
+
+/* void smccc_call32(struct smccc_param32 *param) */
+ENTRY(smccc_call32)
+       stp     x28, x30, [sp, #-16]!

Why are you saving lr?

Quoted 2 lines

Agree, no point in saving lr, but I still need to decrease sp with 16 to maintain correct alignment. I'll do it with an str instruction instead.

That or pad out with xzr

Quoted 17 lines
Quoted 16 lines

arch/arm64/kernel/smccc-call.S line 34

Quoted 12 lines
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

Quoted 5 lines
Quoted 1 line

I assume you're referring to when to use "hvc" and "smc".

No, I mean use a C prototype to avoid marshalling the parameters in assembly like this. As Rutland pointed out, the return value is a bit messy, but the arguments align nicely with the PCS afaict.

If possible I'd like the function to have the same prototype for both arm and arm64. For arm it's not possible to supply more than 4 parameters. To fully support SMC Calling Convention we need to be able to pass 8 parameters and have 4 return values. The OP-TEE driver in this patch set depends on this. I don't see how we can avoid the marshalling here.

Quoted 2 lines

We could have two versions of the SMCCC functions, one simplified which only uses registers and one complete like this one with marshalling.

Will, what do think about this?

Thanks,
Jens

#11 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 34 lines · Jens Wiklander
Quoted 33 lines · Jens Wiklander
Quoted 19 lines · Will Deacon
Quoted 18 lines · Jens Wiklander
Quoted 16 lines · Will Deacon

arch/arm64/kernel/smccc-call.S line 34

Quoted 11 lines · Jens Wiklander
arch/arm64/kernel/smccc-call.S new file +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

Quoted 5 lines
Quoted 1 line

I assume you're referring to when to use "hvc" and "smc".

No, I mean use a C prototype to avoid marshalling the parameters in assembly like this. As Rutland pointed out, the return value is a bit messy, but the arguments align nicely with the PCS afaict.

If possible I'd like the function to have the same prototype for both arm and arm64. For arm it's not possible to supply more than 4 parameters. To fully support SMC Calling Convention we need to be able to pass 8 parameters and have 4 return values. The OP-TEE driver in this patch set depends on this. I don't see how we can avoid the marshalling here.

Quoted 4 lines
Quoted 2 lines

We could have two versions of the SMCCC functions, one simplified which only uses registers and one complete like this one with marshalling.

Will, what do think about this?

I still think you should make use of a C prototype to avoid explicit parameter marshalling in assembly. If you want to maintain a compatible API between arm and arm64, then you can easily have an intermediate function in arm64 that sits between the API entry point and the assembly.

Will

#12 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 38 lines · Will Deacon
Quoted 37 lines · Jens Wiklander
Quoted 35 lines · Jens Wiklander
Quoted 19 lines · Will Deacon
Quoted 18 lines · Jens Wiklander
Quoted 16 lines · Will Deacon

Review

Quoted 11 lines · Jens Wiklander
(quoted diff) +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

Quoted 5 lines
Quoted 1 line

I assume you're referring to when to use "hvc" and "smc".

No, I mean use a C prototype to avoid marshalling the parameters in assembly like this. As Rutland pointed out, the return value is a bit messy, but the arguments align nicely with the PCS afaict.

If possible I'd like the function to have the same prototype for both arm and arm64. For arm it's not possible to supply more than 4 parameters. To fully support SMC Calling Convention we need to be able to pass 8 parameters and have 4 return values. The OP-TEE driver in this patch set depends on this. I don't see how we can avoid the marshalling here.

We could have two versions of the SMCCC functions, one simplified which only uses registers and one complete like this one with marshalling.

Quoted 6 lines
Quoted 1 line

Will, what do think about this?

I still think you should make use of a C prototype to avoid explicit parameter marshalling in assembly. If you want to maintain a compatible API between arm and arm64, then you can easily have an intermediate function in arm64 that sits between the API entry point and the assembly.

Yes, I see how that's convenient for passing argument values in registers, but that doesn't help with storing the returned values in x0..x3 into something accessible in C. Am I missing something?

Thanks,
Jens

#13 lore raw

Re: [PATCH v5 1/5] arm/arm64: add smccc ARCH32

Quoted 41 lines · Jens Wiklander
Quoted 40 lines · Will Deacon
Quoted 38 lines · Jens Wiklander
Quoted 33 lines · Jens Wiklander
Quoted 19 lines · Will Deacon
Quoted 18 lines · Jens Wiklander
Quoted 16 lines · Will Deacon

Review

Quoted 11 lines · Jens Wiklander
(quoted diff) +11 -0
+       mov     x28, x0
+       ldp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       ldp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     w4, w5, [x28, #SMC_PARAM_W4_OFFS]
+       ldp     w6, w7, [x28, #SMC_PARAM_W6_OFFS]
+       smc     #0
+       stp     w0, w1, [x28, #SMC_PARAM_W0_OFFS]
+       stp     w2, w3, [x28, #SMC_PARAM_W2_OFFS]
+       ldp     x28, x30, [sp], #16
+       ret
+ENDPROC(smccc_call32)

Could we deal with this like we do for PSCI instead? (see __invoke_psci_fn_smc). We could also then rename psci-call.S to fw-call.S and stick this in there too.

Quoted 5 lines
Quoted 1 line

I assume you're referring to when to use "hvc" and "smc".

No, I mean use a C prototype to avoid marshalling the parameters in assembly like this. As Rutland pointed out, the return value is a bit messy, but the arguments align nicely with the PCS afaict.

If possible I'd like the function to have the same prototype for both arm and arm64. For arm it's not possible to supply more than 4 parameters. To fully support SMC Calling Convention we need to be able to pass 8 parameters and have 4 return values. The OP-TEE driver in this patch set depends on this. I don't see how we can avoid the marshalling here.

Quoted 2 lines

We could have two versions of the SMCCC functions, one simplified which only uses registers and one complete like this one with marshalling.

Will, what do think about this?

Quoted 8 lines
Quoted 4 lines

I still think you should make use of a C prototype to avoid explicit parameter marshalling in assembly. If you want to maintain a compatible API between arm and arm64, then you can easily have an intermediate function in arm64 that sits between the API entry point and the assembly.

Yes, I see how that's convenient for passing argument values in registers, but that doesn't help with storing the returned values in x0..x3 into something accessible in C. Am I missing something?

Your approach using a struct looked fine to me, just place it after the parameters and use it only for the return values. Then __invoke_psci* can wrap this and unpack r0/x0 from the structure.

Will

#14 lore raw

PATCH v5 2/5 dt/bindings: add bindings for optee

In reply to Jens Wiklander

Introduces optee prefix and adds bindings for ARM TrustZone based OP-TEE implementation.

---
 Documentation/devicetree/bindings/optee/optee.txt     | 17 +++++++++++++++++
 Documentation/devicetree/bindings/vendor-prefixes.txt |  1 +
 2 files changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/optee/optee.txt
Documentation/devicetree/bindings/optee/optee.txt new file +17 -0
new file mode 100644
index 0000000..4a6ff10
@@ -0,0 +1,17 @@
+OP-TEE Device Tree Bindings
+
+OP-TEE is a piece of software using hardware features to provide a Trusted
+Execution Environment. The security can be provided with ARM TrustZone, but
+also by virtualization or a separate chip. As there's no single OP-TEE
+vendor we're using "optee" as the first part of compatible property,
+indicating the OP-TEE protocol is used when communicating with the secure
+world.
+
+* OP-TEE based on ARM TrustZone required properties:
+
+- compatible="optee,optee-tz"
+
+Example:
+	optee {
+		compatible="optee,optee-tz";
+	};
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index 8033919..17c2a7e 100644
@@ -141,6 +141,7 @@ nvidia	NVIDIA
 nxp	NXP Semiconductors
 onnn	ON Semiconductor Corp.
 opencores	OpenCores.org
+optee	OP-TEE, Open Portable Trusted Execution Environment
 ortustech	Ortus Technology Co., Ltd.
 ovti	OmniVision Technologies
 panasonic	Panasonic Corporation
Signature · 1 line
1.9.1
maintainer
#15 lore raw

Re: [PATCH v5 2/5] dt/bindings: add bindings for optee

Quoted 6 lines · Jens Wiklander

Introduces optee prefix and adds bindings for ARM TrustZone based OP-TEE implementation.

---
 Documentation/devicetree/bindings/optee/optee.txt     | 17 +++++++++++++++++

How about bindings/arm/firmware/... where the *other* TZ binding is located.

Quoted 10 lines
 Documentation/devicetree/bindings/vendor-prefixes.txt |  1 +
 2 files changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/optee/optee.txt
Documentation/devicetree/bindings/optee/optee.txt new file +0 -0
new file mode 100644
index 0000000..4a6ff10

Documentation/devicetree/bindings/optee/optee.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/optee/optee.txt new file +5 -0
@@ -0,0 +1,17 @@
+OP-TEE Device Tree Bindings
+
+OP-TEE is a piece of software using hardware features to provide a Trusted
+Execution Environment. The security can be provided with ARM TrustZone, but
+also by virtualization or a separate chip. As there's no single OP-TEE

I don't see how the Linux side would not need to know what the communication channel is whether it is smc, hvc, or something else.

Quoted 25 lines
Documentation/devicetree/bindings/optee/optee.txt new file +12 -0
+vendor we're using "optee" as the first part of compatible property,
+indicating the OP-TEE protocol is used when communicating with the secure
+world.
+
+* OP-TEE based on ARM TrustZone required properties:
+
+- compatible="optee,optee-tz"
+
+Example:
+	optee {
+		compatible="optee,optee-tz";
+	};
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index 8033919..17c2a7e 100644
@@ -141,6 +141,7 @@ nvidia	NVIDIA
 nxp	NXP Semiconductors
 onnn	ON Semiconductor Corp.
 opencores	OpenCores.org
+optee	OP-TEE, Open Portable Trusted Execution Environment
 ortustech	Ortus Technology Co., Ltd.
 ovti	OmniVision Technologies
 panasonic	Panasonic Corporation
#16 lore raw

Re: [PATCH v5 2/5] dt/bindings: add bindings for optee

Quoted 9 lines · Rob Herring
Quoted 6 lines · Jens Wiklander

Introduces optee prefix and adds bindings for ARM TrustZone based OP-TEE implementation.

---
 Documentation/devicetree/bindings/optee/optee.txt     | 17 +++++++++++++++++

How about bindings/arm/firmware/... where the *other* TZ binding is located.

OK, I'll move it.

Quoted 5 lines
Quoted 5 lines
 Documentation/devicetree/bindings/vendor-prefixes.txt |  1 +
 2 files changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/optee/optee.txt
Quoted 14 lines

Documentation/devicetree/bindings/optee/optee.txt line 5

Quoted 11 lines
Documentation/devicetree/bindings/optee/optee.txt new file +5 -0
new file mode 100644
index 0000000..4a6ff10
@@ -0,0 +1,17 @@
+OP-TEE Device Tree Bindings
+
+OP-TEE is a piece of software using hardware features to provide a Trusted
+Execution Environment. The security can be provided with ARM TrustZone, but
+also by virtualization or a separate chip. As there's no single OP-TEE

I don't see how the Linux side would not need to know what the communication channel is whether it is smc, hvc, or something else.

I assume you're missing something similar to the "method" property defined for PSCI. I'll add that.

Quoted 18 lines
Quoted 18 lines
Documentation/devicetree/bindings/optee/optee.txt new file +12 -0
+vendor we're using "optee" as the first part of compatible property,
+indicating the OP-TEE protocol is used when communicating with the secure
+world.
+
+* OP-TEE based on ARM TrustZone required properties:
+
+- compatible="optee,optee-tz"
+
+Example:
+	optee {
+		compatible="optee,optee-tz";
+	};
Documentation/devicetree/bindings/vendor-prefixes.txt +0 -0
index 8033919..17c2a7e 100644
@@ -141,6 +141,7 @@ nvidia	NVIDIA
Quoted 9 lines

Documentation/devicetree/bindings/vendor-prefixes.txt nvidia NVIDIA · line 147

Quoted 8 lines
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
 nxp	NXP Semiconductors
 onnn	ON Semiconductor Corp.
 opencores	OpenCores.org
+optee	OP-TEE, Open Portable Trusted Execution Environment
 ortustech	Ortus Technology Co., Ltd.
 ovti	OmniVision Technologies
 panasonic	Panasonic Corporation

Thanks,
Jens

#17 lore raw

PATCH v5 3/5 tee: generic TEE subsystem

In reply to Jens Wiklander

Initial patch for generic TEE subsystem.
This subsystem provides:
* Registration/un-registration of TEE drivers.
* Shared memory between normal world and secure world.
* Ioctl interface for interaction with user space.

A TEE (Trusted Execution Environment) driver is a driver that interfaces with a trusted OS running in some secure environment, for example, TrustZone on ARM cpus, or a separate secure co-processor etc.

The TEE subsystem can serve a TEE driver for a Global Platform compliant TEE, but it's not limited to only Global Platform TEEs.

This patch builds on other similar implementations trying to solve the same problem:
* "optee_linuxdriver" by among others
Jean-michel DELORME<[email protected]> and Emmanuel MICHEL <[email protected]>
* "Generic TrustZone Driver" by Javier Gonz?lez <[email protected]>

---
 Documentation/ioctl/ioctl-number.txt |   1 +
 MAINTAINERS                          |   8 +
 drivers/Kconfig                      |   2 +
 drivers/Makefile                     |   1 +
 drivers/tee/Kconfig                  |   8 +
 drivers/tee/Makefile                 |   3 +
 drivers/tee/tee.c                    | 834 +++++++++++++++++++++++++++++++++++
 drivers/tee/tee_private.h            |  80 ++++
 drivers/tee/tee_shm.c                | 324 ++++++++++++++
 drivers/tee/tee_shm_pool.c           | 133 ++++++
 include/linux/tee_drv.h              | 306 +++++++++++++
 include/uapi/linux/tee.h             | 376 ++++++++++++++++
 12 files changed, 2076 insertions(+)
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/tee.c
 create mode 100644 drivers/tee/tee_private.h
 create mode 100644 drivers/tee/tee_shm.c
 create mode 100644 drivers/tee/tee_shm_pool.c
 create mode 100644 include/linux/tee_drv.h
 create mode 100644 include/uapi/linux/tee.h
Documentation/ioctl/ioctl-number.txt +1 -0
index 51f4221..f54dfc02 100644
@@ -301,6 +301,7 @@ Code  Seq#(hex)	Include File		Comments
 0xA3	80-8F	Port ACL		in development:
 					<mailto:[email protected]>
 0xA3	90-9F	linux/dtlk.h
+0xA4	00-1F	uapi/linux/tee.h	Generic TEE subsystem
 0xAB	00-1F	linux/nbd.h
 0xAC	00-1F	linux/raw.h
 0xAD	00	Netfilter device	in development:
MAINTAINERS +8 -0
index d8afd29..869635f 100644
@@ -8634,6 +8634,14 @@ S:	Maintained
 F:	include/linux/mmc/dw_mmc.h
 F:	drivers/mmc/host/dw_mmc*
 
+TEE SUBSYSTEM
+M:	Jens Wiklander <[email protected]>
+M:	Javier Gonz?lez <[email protected]>
+S:	Maintained
+F:	include/linux/tee_drv.h
+F:	include/uapi/linux/tee.h
+F:	drivers/tee/
+
 THUNDERBOLT DRIVER
 M:	Andreas Noever <[email protected]>
 S:	Maintained
drivers/Kconfig +2 -0
index c0cc96b..7510f69 100644
@@ -182,4 +182,6 @@ source "drivers/thunderbolt/Kconfig"
 
 source "drivers/android/Kconfig"
 
+source "drivers/tee/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index 46d2554..852f0af 100644
@@ -165,3 +165,4 @@ obj-$(CONFIG_RAS)		+= ras/
 obj-$(CONFIG_THUNDERBOLT)	+= thunderbolt/
 obj-$(CONFIG_CORESIGHT)		+= hwtracing/coresight/
 obj-$(CONFIG_ANDROID)		+= android/
+obj-$(CONFIG_TEE)		+= tee/
drivers/tee/Kconfig new file +8 -0
new file mode 100644
index 0000000..64a8cd7
@@ -0,0 +1,8 @@
+# Generic Trusted Execution Environment Configuration
+config TEE
+	bool "Trusted Execution Environment support"
+	default n
+	select DMA_SHARED_BUFFER
+	help
+	  This implements a generic interface towards a Trusted Execution
+	  Environment (TEE).
drivers/tee/Makefile new file +3 -0
new file mode 100644
index 0000000..60d2dab
@@ -0,0 +1,3 @@
+obj-y += tee.o
+obj-y += tee_shm.o
+obj-y += tee_shm_pool.o
drivers/tee/tee.c new file +834 -0

834 lines not on this page · raw message

drivers/tee/tee_private.h new file +80 -0

80 lines not on this page · raw message

drivers/tee/tee_shm.c new file +324 -0

324 lines not on this page · raw message

drivers/tee/tee_shm_pool.c new file +133 -0

133 lines not on this page · raw message

include/linux/tee_drv.h new file +306 -0

306 lines not on this page · raw message

include/uapi/linux/tee.h new file +376 -0

376 lines not on this page · raw message

Signature · 1 line
1.9.1
#18 lore raw

PATCH v5 4/5 tee: add OP-TEE driver

In reply to Jens Wiklander

Adds a OP-TEE driver which also can be compiled as a loadable module.

* Targets ARM and ARM64
* Supports using reserved memory from OP-TEE as shared memory
* Probes OP-TEE version using SMCs
* Accepts requests on privileged and unprivileged device
* Uses OPTEE message protocol version 2 to communicate with secure world

---
 MAINTAINERS                       |   5 +
 drivers/tee/Kconfig               |  10 +
 drivers/tee/Makefile              |   1 +
 drivers/tee/optee/Kconfig         |   8 +
 drivers/tee/optee/Makefile        |   5 +
 drivers/tee/optee/call.c          | 390 +++++++++++++++++++++++++++++++
 drivers/tee/optee/core.c          | 453 ++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/optee_msg.h     | 334 +++++++++++++++++++++++++++
 drivers/tee/optee/optee_private.h | 129 +++++++++++
 drivers/tee/optee/optee_smc.h     | 466 ++++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c           | 248 ++++++++++++++++++++
 drivers/tee/optee/supp.c          | 212 +++++++++++++++++
 12 files changed, 2261 insertions(+)
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c
MAINTAINERS +5 -0
index 869635f..2df3f03 100644
@@ -7314,6 +7314,11 @@ F:	arch/*/oprofile/
 F:	drivers/oprofile/
 F:	include/linux/oprofile.h
 
+OP-TEE DRIVER
+M:	Jens Wiklander <[email protected]>
+S:	Maintained
+F:	drivers/tee/optee/
+
 ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
 M:	Mark Fasheh <[email protected]>
 M:	Joel Becker <[email protected]>
drivers/tee/Kconfig +10 -0
index 64a8cd7..b269276 100644
@@ -6,3 +6,13 @@ config TEE
 	help
 	  This implements a generic interface towards a Trusted Execution
 	  Environment (TEE).
+
+if TEE
+
+menu "TEE drivers"
+
+source "drivers/tee/optee/Kconfig"
+
+endmenu
+
+endif
drivers/tee/Makefile +1 -0
index 60d2dab..53f3c76 100644
@@ -1,3 +1,4 @@
 obj-y += tee.o
 obj-y += tee_shm.o
 obj-y += tee_shm_pool.o
+obj-$(CONFIG_OPTEE) += optee/
drivers/tee/optee/Kconfig new file +8 -0
new file mode 100644
index 0000000..b550b18
@@ -0,0 +1,8 @@
+# OP-TEE Trusted Execution Environment Configuration
+config OPTEE
+	tristate "OP-TEE"
+	default n
+	depends on HAVE_SMCCC
+	help
+	  This implements the OP-TEE Trusted Execution Environment (TEE)
+	  driver.
drivers/tee/optee/Makefile new file +5 -0
new file mode 100644
index 0000000..92fe578
@@ -0,0 +1,5 @@
+obj-$(CONFIG_OPTEE) += optee.o
+optee-objs += core.o
+optee-objs += call.o
+optee-objs += rpc.o
+optee-objs += supp.o
drivers/tee/optee/call.c new file +390 -0

390 lines not on this page · raw message

drivers/tee/optee/core.c new file +453 -0

453 lines not on this page · raw message

drivers/tee/optee/optee_msg.h new file +334 -0

334 lines not on this page · raw message

drivers/tee/optee/optee_private.h new file +129 -0

129 lines not on this page · raw message

drivers/tee/optee/optee_smc.h new file +466 -0

466 lines not on this page · raw message

drivers/tee/optee/rpc.c new file +248 -0

248 lines not on this page · raw message

drivers/tee/optee/supp.c new file +212 -0

212 lines not on this page · raw message

Signature · 1 line
1.9.1
#19 lore raw

PATCH v5 5/5 Documentation: tee subsystem and op-tee driver

In reply to Jens Wiklander
---
 Documentation/00-INDEX |   2 +
 Documentation/tee.txt  | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS            |   1 +
 3 files changed, 120 insertions(+)
 create mode 100644 Documentation/tee.txt
Documentation/00-INDEX +2 -0
index cd077ca..bd3f803 100644
@@ -435,6 +435,8 @@ sysrq.txt
 	- info on the magic SysRq key.
 target/
 	- directory with info on generating TCM v4 fabric .ko modules
+tee.txt
+	- info on the TEE subsystem and drivers
 this_cpu_ops.txt
 	- List rationale behind and the way to use this_cpu operations.
 thermal/
Documentation/tee.txt new file +117 -0

117 lines not on this page · raw message

MAINTAINERS +1 -0
index 2df3f03..a48d718 100644
@@ -8646,6 +8646,7 @@ S:	Maintained
 F:	include/linux/tee_drv.h
 F:	include/uapi/linux/tee.h
 F:	drivers/tee/
+F:	Documentation/tee.txt
 
 THUNDERBOLT DRIVER
 M:	Andreas Noever <[email protected]>
Signature · 1 line
1.9.1