generic TEE subsystem
Subsystems (7)
v6 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.
At last Linaro Connect, SFO15, I got some additional feedback on this patch set:
* As each TEE driver has their own tee-supplicant (if any) we need an automated way of starting the correct tee-supplicant
- Addressed with exposing implementation id of a TEE driver in sysfs
* Relying on using only contiguous physical memory when communicating with secure world is too constrained
- Partially addressed with an updated OP-TEE message protocol in the OP-TEE driver
- The main concerns are to avoid incompatible user space API changes and also avoid fundamental incompatible changes to the TEE subsystem or driver when adding support for physically fragmented memory later on.
v6:
* Rebased on v4.3-rc7
* Changed smccc interface to let the compiler marshal most of the parameters
* Added ARCH64 capability for smccc interface
* Changed the PSCI firmware calls (both arm and arm64) to use the new generic smccc interface instead instead of own assembly functions.
* Move optee DT bindings to below arm/firmware
* Defines method for OP-TEE driver to call secure world in DT, smc or hvc
* Exposes implementation id of a TEE driver in sysfs
to easily spawn corresponding tee-supplicant when device is ready
* Update OP-TEE Message Protocol to better cope with fragmented physical memory
* Read time directly from OP-TEE driver instead of forwarding the RPC request to tee-supplicant
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 (6):
arm/arm64: add smccc
drivers: psci: replace psci firmware calls
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 + .../bindings/arm/firmware/optee,optee-tz.txt | 29 + .../devicetree/bindings/vendor-prefixes.txt | 1 + Documentation/ioctl/ioctl-number.txt | 1 + Documentation/tee.txt | 117 +++ MAINTAINERS | 13 + arch/arm/Kconfig | 4 + arch/arm/kernel/Makefile | 3 +- arch/arm/kernel/psci-call.S | 31 - arch/arm/kernel/smccc-call.S | 49 ++ arch/arm/kernel/smccc.c | 18 + arch/arm64/Kconfig | 4 + arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/psci-call.S | 28 - arch/arm64/kernel/smccc-call.S | 43 + arch/arm64/kernel/smccc.c | 18 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/firmware/psci.c | 21 +- drivers/tee/Kconfig | 18 + drivers/tee/Makefile | 4 + drivers/tee/optee/Kconfig | 8 + drivers/tee/optee/Makefile | 5 + drivers/tee/optee/call.c | 400 ++++++++++ drivers/tee/optee/core.c | 502 ++++++++++++ drivers/tee/optee/optee_msg.h | 423 ++++++++++ drivers/tee/optee/optee_private.h | 146 ++++ drivers/tee/optee/optee_smc.h | 418 ++++++++++ drivers/tee/optee/rpc.c | 322 ++++++++ drivers/tee/optee/supp.c | 212 +++++ drivers/tee/tee.c | 873 +++++++++++++++++++++ drivers/tee/tee_private.h | 80 ++ drivers/tee/tee_shm.c | 324 ++++++++ drivers/tee/tee_shm_pool.c | 133 ++++ include/linux/arm-smccc.h | 98 +++ include/linux/tee_drv.h | 300 +++++++ include/uapi/linux/tee.h | 383 +++++++++ 37 files changed, 4974 insertions(+), 63 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt create mode 100644 Documentation/tee.txt delete mode 100644 arch/arm/kernel/psci-call.S create mode 100644 arch/arm/kernel/smccc-call.S create mode 100644 arch/arm/kernel/smccc.c delete mode 100644 arch/arm64/kernel/psci-call.S 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
PATCH v6 1/6 arm/arm64: add smccc
Adds helpers to do SMC and HVC based on ARM SMC Calling Convention. CONFIG_HAVE_SMCCC is enabled for architectures that may support the SMC or HVC 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 | 49 +++++++++++++++++++++ arch/arm/kernel/smccc.c | 18 ++++++++ arch/arm64/Kconfig | 4 ++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/smccc-call.S | 43 ++++++++++++++++++ arch/arm64/kernel/smccc.c | 18 ++++++++ include/linux/arm-smccc.h | 98 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 237 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
@@ -226,6 +226,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
@@ -325,6 +328,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
@@ -92,4 +92,6 @@ obj-y += 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 +49 -0
49 lines not on this page · raw message
arch/arm/kernel/smccc.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* 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_smc); +EXPORT_SYMBOL_GPL (smccc_hvc);
arch/arm64/Kconfig +4 -0
@@ -89,6 +89,7 @@ config ARM64 select SPARSE_IRQ select SYSCTL_EXCEPTION_TRACE select HAVE_CONTEXT_TRACKING + select HAVE_SMCCC help ARM 64-bit (AArch64) Linux support.
@@ -167,6 +168,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
@@ -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 +43 -0
43 lines not on this page · raw message
arch/arm64/kernel/smccc.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* 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_smc); +EXPORT_SYMBOL_GPL (smccc_hvc);
include/linux/arm-smccc.h new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v6 1/6] arm/arm64: add smccc
Hi Jens,
Quoted 6 lines · Jens Wiklander
Adds helpers to do SMC and HVC based on ARM SMC Calling Convention.
CONFIG_HAVE_SMCCCis enabled for architectures that may support the SMC or HVC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.Signed-off-by Jens Wiklander <[email protected]>
Quoted 10 lines
--- arch/arm/Kconfig | 4 ++ arch/arm/kernel/Makefile | 2 + arch/arm/kernel/smccc-call.S | 49 +++++++++++++++++++++ arch/arm/kernel/smccc.c | 18 ++++++++ arch/arm64/Kconfig | 4 ++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/smccc-call.S | 43 ++++++++++++++++++ arch/arm64/kernel/smccc.c | 18 ++++++++ include/linux/arm-smccc.h | 98 ++++++++++++++++++++++++++++++++++++++++++
This should probably be split so that the arm and arm64 patches can be merged separately.
Quoted 6 lines
9 files changed, 237 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 config NEED_RET_TO_USER · line 230
Quoted 10 lines
arch/arm/Kconfig +2
-0@@ -226,6 +226,9 @@ config NEED_RET_TO_USER config ARCH_MTD_XIP bool +config HAVE_SMCCC + bool
If you want this to be selectable by multiple arches, wouldn't it be better to define it out in a common Kconfig file? Maybe HAVE_ARM_SMCCC too, for some better namespacing.
An alternative is just making your TEE driver depend on ARM || ARM64 and providing dummy smc wrappers that return an error code for cores older than ARMv7.
Quoted 13 lines
arch/arm64/kernel/smccc-call.S new file +7
-0@@ -0,0 +1,43 @@ +/* + * 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. + *
arch/arm64/kernel/smccc-call.S line 17
Quoted 10 lines
arch/arm64/kernel/smccc-call.S new file +10
-0+ * 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_RES_X0_OFFS 0 +#define SMC_RES_X2_OFFS 16
These should be generates in asm-offsets.c
Quoted 16 lines
arch/arm64/kernel/smccc-call.S new file +16
-0+ +/* + * void smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2, + * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct smccc_res *res) + */ +ENTRY(smccc_smc) + smc #0 + ldr x4, [sp] + stp x0, x1, [x4, #SMC_RES_X0_OFFS] + stp x2, x3, [x4, #SMC_RES_X2_OFFS] + ret +ENDPROC(smccc_smc) + +/* + * void smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a2,
arch/arm64/kernel/smccc-call.S line 43
Quoted 10 lines
arch/arm64/kernel/smccc-call.S new file +10
-0+ * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct smccc_res *res) + */ +ENTRY(smccc_hvc) + hvc #0 + ldr x4, [sp] + stp x0, x1, [x4, #SMC_RES_X0_OFFS] + stp x2, x3, [x4, #SMC_RES_X2_OFFS] + ret +ENDPROC(smccc_hvc)
Maybe you could generate both of these from an asm macro that takes the first instruction as a parameter?
Quoted 14 lines
arch/arm64/kernel/smccc.c new file +8
-0@@ -0,0 +1,18 @@ +/* +* 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,
arch/arm64/kernel/smccc.c line 18
Quoted 10 lines
arch/arm64/kernel/smccc.c new file +10
-0+* 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_smc); +EXPORT_SYMBOL_GPL (smccc_hvc);
Again, I think you want an arm_ prefix for some better namespacing.
Quoted 1 line
include/linux/arm-smccc.h +0
-0
[...]
Quoted 31 lines
include/linux/arm-smccc.h +31
-0+#define SMCCC_SMC_32 (0 << 30) +#define SMCCC_SMC_64 (1 << 30) +#define SMCCC_FAST_CALL (1 << 31) +#define SMCCC_STD_CALL (0 << 31) + +#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 +
include/linux/arm-smccc.h line 66
Quoted 10 lines
include/linux/arm-smccc.h +10
-0+/** +* struct smccc_res - Result from SMC/HVC call +* @a0-a3 result values from registers 0 to 3 +*/ +struct smccc_res { +unsigned long a0; +unsigned long a1; +unsigned long a2; +unsigned long a3; +};
Are there any endianness considerations for this structure?
Will
Re: [PATCH v6 1/6] arm/arm64: add smccc
Quoted 20 lines · Will Deacon
Hi Jens,
Quoted 6 lines · Jens Wiklander
Adds helpers to do SMC and HVC based on ARM SMC Calling Convention.
CONFIG_HAVE_SMCCCis enabled for architectures that may support the SMC or HVC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform.Signed-off-by Jens Wiklander <[email protected]>Quoted 10 lines
--- arch/arm/Kconfig | 4 ++ arch/arm/kernel/Makefile | 2 + arch/arm/kernel/smccc-call.S | 49 +++++++++++++++++++++ arch/arm/kernel/smccc.c | 18 ++++++++ arch/arm64/Kconfig | 4 ++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/smccc-call.S | 43 ++++++++++++++++++ arch/arm64/kernel/smccc.c | 18 ++++++++ include/linux/arm-smccc.h | 98 ++++++++++++++++++++++++++++++++++++++++++
Quoted 2 lines
This should probably be split so that the arm and arm64 patches can be merged separately.
OK, what's preferable two or three patches?
Quoted 18 lines
Quoted 7 lines
9 files changed, 237 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[...]
Quoted 8 lines
arch/arm/Kconfig +0
-0@@ -226,6 +226,9 @@ config NEED_RET_TO_USER config ARCH_MTD_XIP bool
Quoted 6 lines
arch/arm/Kconfig config NEED_RET_TO_USER · line 230
Quoted 2 lines
arch/arm/Kconfig +2
-0+config HAVE_SMCCC + boolIf you want this to be selectable by multiple arches, wouldn't it be better to define it out in a common
Kconfigfile? MaybeHAVE_ARM_SMCCCtoo, for some better namespacing.
What's a good place, init/Kconfig?
Quoted 4 lines
An alternative is just making your TEE driver depend on ARM || ARM64 and providing dummy smc wrappers that return an error code for cores older than ARMv7.
It's tempting, but it would mean adding this dummy function for all architectures as it need to be exported to be usable from a load module.
Quoted 18 lines
Quoted 18 lines
arch/arm64/kernel/smccc-call.S new file +11
-0@@ -0,0 +1,43 @@ +/* + * 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.
Quoted 8 lines
arch/arm64/kernel/smccc-call.S line 17
Quoted 6 lines
arch/arm64/kernel/smccc-call.S new file +6
-0+ * + */ +#include <linux/linkage.h> + +#define SMC_RES_X0_OFFS 0 +#define SMC_RES_X2_OFFS 16These should be generates in
asm-offsets.c
OK
Quoted 22 lines
Quoted 22 lines
arch/arm64/kernel/smccc-call.S new file +21
-0+ +/* + * void smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2, + * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct smccc_res *res) + */ +ENTRY(smccc_smc) + smc #0 + ldr x4, [sp] + stp x0, x1, [x4, #SMC_RES_X0_OFFS] + stp x2, x3, [x4, #SMC_RES_X2_OFFS] + ret +ENDPROC(smccc_smc) + +/* + * void smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a2, + * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct smccc_res *res) + */ +ENTRY(smccc_hvc) + hvc #0
Quoted 8 lines
arch/arm64/kernel/smccc-call.S line 43
Quoted 5 lines
arch/arm64/kernel/smccc-call.S new file +5
-0+ ldr x4, [sp] + stp x0, x1, [x4, #SMC_RES_X0_OFFS] + stp x2, x3, [x4, #SMC_RES_X2_OFFS] + ret +ENDPROC(smccc_hvc)Maybe you could generate both of these from an asm macro that takes the first instruction as a parameter?
OK
Quoted 19 lines
Quoted 19 lines
arch/arm64/kernel/smccc.c new file +12
-0@@ -0,0 +1,18 @@ +/* +* 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. +*
Quoted 8 lines
arch/arm64/kernel/smccc.c line 18
Quoted 6 lines
arch/arm64/kernel/smccc.c new file +6
-0+*/ +#include <linux/export.h> +#include <linux/arm-smccc.h> + +EXPORT_SYMBOL_GPL (smccc_smc); +EXPORT_SYMBOL_GPL (smccc_hvc);Again, I think you want an
arm_prefix for some better namespacing.
Agree
Quoted 40 lines
Quoted 2 lines
include/linux/arm-smccc.h +0
-0[...]
Quoted 35 lines
include/linux/arm-smccc.h +35
-0+#define SMCCC_SMC_32 (0 << 30) +#define SMCCC_SMC_64 (1 << 30) +#define SMCCC_FAST_CALL (1 << 31) +#define SMCCC_STD_CALL (0 << 31) + +#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_res - Result from SMC/HVC call +* @a0-a3 result values from registers 0 to 3 +*/
Quoted 8 lines
include/linux/arm-smccc.h line 66
Quoted 6 lines
include/linux/arm-smccc.h +6
-0+struct smccc_res { +unsigned long a0; +unsigned long a1; +unsigned long a2; +unsigned long a3; +};Are there any endianness considerations for this structure?
No, I can't find anything in the ARM SMC Calling Convention document indicating that.
Thanks,
Jens
Mark Rutland
maintainerRe: [PATCH v6 1/6] arm/arm64: add smccc
Quoted 39 lines
Quoted 26 lines
Quoted 25 lines
arch/arm64/kernel/smccc-call.S new file +24
-0+/* + * void smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2, + * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct smccc_res *res) + */ +ENTRY(smccc_smc) + smc #0 + ldr x4, [sp] + stp x0, x1, [x4, #SMC_RES_X0_OFFS] + stp x2, x3, [x4, #SMC_RES_X2_OFFS] + ret +ENDPROC(smccc_smc) +/* + * void smccc_hvc(unsigned long a0, unsigned long a1, unsigned long a2, + * unsigned long a3, unsigned long a4, unsigned long a5, + * unsigned long a6, unsigned long a7, struct smccc_res *res) + */ +ENTRY(smccc_hvc) + hvc #0 + ldr x4, [sp] + stp x0, x1, [x4, #SMC_RES_X0_OFFS] + stp x2, x3, [x4, #SMC_RES_X2_OFFS] + ret +ENDPROC(smccc_hvc)Quoted 12 lines
include/linux/arm-smccc.h line 66
Quoted 10 lines
include/linux/arm-smccc.h new file +10
-0+/** +* struct smccc_res - Result from SMC/HVC call +* @a0-a3 result values from registers 0 to 3 +*/ +struct smccc_res { +unsigned long a0; +unsigned long a1; +unsigned long a2; +unsigned long a3; +};Are there any endianness considerations for this structure?
Quoted 2 lines
No, I can't find anything in the ARM SMC Calling Convention document indicating that.
The calling conventions have no bearing on the structure, which is our invention.
We stash register values (which don't have endianness) returned by the firmeware into the structure in the sequences above (which appear endian-clean to me).
Thanks,
Mark.
Re: [PATCH v6 1/6] arm/arm64: add smccc
Quoted 16 lines · Mark Rutland
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
+/**
+ * structsmccc_res- Result from SMC/HVC call
+ * @a0-a3 result values from registers 0 to 3
+ */Quoted 8 lines
include/linux/arm-smccc.h line 66
Quoted 6 lines
include/linux/arm-smccc.h new file +6
-0+struct smccc_res { +unsigned long a0; +unsigned long a1; +unsigned long a2; +unsigned long a3; +};Are there any endianness considerations for this structure?
Quoted 2 lines
No, I can't find anything in the ARM SMC Calling Convention document indicating that.
Quoted 6 lines
The calling conventions have no bearing on the structure, which is our invention.
We stash register values (which don't have endianness) returned by the firmeware into the structure in the sequences above (which appear endian-clean to me).
Ah yes, the structure is populated by the kernel not the firmware, so there's nothing to worry about. Thanks for the explanation.
Will
PATCH v6 2/6 drivers: psci: replace psci firmware calls
In reply to Jens WiklanderSwitch to use a generic interface for issuing SMC/HVC based on ARM SMC Calling Convention. Removes now the now unused psci-call.S.
--- arch/arm/kernel/Makefile | 1 - arch/arm/kernel/psci-call.S | 31 ------------------------------- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/psci-call.S | 28 ---------------------------- drivers/firmware/psci.c | 21 +++++++++++++++++++-- 5 files changed, 20 insertions(+), 63 deletions(-) delete mode 100644 arch/arm/kernel/psci-call.S delete mode 100644 arch/arm64/kernel/psci-call.S
arch/arm/kernel/Makefile +0 -1
@@ -88,7 +88,6 @@ obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-$(CONFIG_ARM_VIRT_EXT) += hyp-stub.o ifeq ($(CONFIG_ARM_PSCI),y) -obj-y += psci-call.o obj-$(CONFIG_SMP) += psci_smp.o endif
arch/arm/kernel/psci-call.S deleted +0 -31
@@ -1,31 +0,0 @@ -/* - * 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. - * - * Copyright (C) 2015 ARM Limited - * - * Author: Mark Rutland <[email protected]> - */ - -#include <linux/linkage.h> - -#include <asm/opcodes-sec.h> -#include <asm/opcodes-virt.h> - -/* int __invoke_psci_fn_hvc(u32 function_id, u32 arg0, u32 arg1, u32 arg2) */ -ENTRY(__invoke_psci_fn_hvc) - __HVC(0) - bx lr -ENDPROC(__invoke_psci_fn_hvc) - -/* int __invoke_psci_fn_smc(u32 function_id, u32 arg0, u32 arg1, u32 arg2) */ -ENTRY(__invoke_psci_fn_smc) - __SMC(0) - bx lr -ENDPROC(__invoke_psci_fn_smc)
arch/arm64/kernel/Makefile +1 -1
@@ -15,7 +15,7 @@ CFLAGS_REMOVE_return_address.o = -pg arm64-obj-y := debug-monitors.o entry.o irq.o fpsimd.o \ entry-fpsimd.o process.o ptrace.o setup.o signal.o \ sys.o stacktrace.o time.o traps.o io.o vdso.o \ - hyp-stub.o psci.o psci-call.o cpu_ops.o insn.o \ + hyp-stub.o psci.o cpu_ops.o insn.o \ return_address.o cpuinfo.o cpu_errata.o \ cpufeature.o alternative.o cacheinfo.o \ smp.o smp_spin_table.o topology.o
arch/arm64/kernel/psci-call.S deleted +0 -28
@@ -1,28 +0,0 @@ -/* - * 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. - * - * Copyright (C) 2015 ARM Limited - * - * Author: Will Deacon <[email protected]> - */ - -#include <linux/linkage.h> - -/* int __invoke_psci_fn_hvc(u64 function_id, u64 arg0, u64 arg1, u64 arg2) */ -ENTRY(__invoke_psci_fn_hvc) - hvc #0 - ret -ENDPROC(__invoke_psci_fn_hvc) - -/* int __invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1, u64 arg2) */ -ENTRY(__invoke_psci_fn_smc) - smc #0 - ret -ENDPROC(__invoke_psci_fn_smc)
drivers/firmware/psci.c +19 -2
@@ -19,6 +19,7 @@#include <linux/pm.h> #include <linux/printk.h> #include <linux/psci.h> +#include <linux/arm-smccc.h> #include <linux/reboot.h> #include <uapi/linux/psci.h>
@@ -56,8 +57,6 @@ struct psci_operations psci_ops;typedef unsigned long (psci_fn )(unsigned long ,unsigned long ,unsigned long ,unsigned long ); -asmlinkage psci_fn __invoke_psci_fn_hvc; -asmlinkage psci_fn __invoke_psci_fn_smc;static psci_fn *invoke_psci_fn;enum psci_function {
@@ -70,6 +69,24 @@ enum psci_function {static u32 psci_function_id[PSCI_FN_MAX ]; +static unsigned long __invoke_psci_fn_hvc (unsigned long a0,unsigned long a1, +unsigned long a2,unsigned long a3) +{ +struct smccc_res res; + +smccc_hvc (a0, a1, a2, a3,0 ,0 ,0 ,0 , &res); +return res.a0; +} + +static unsigned long __invoke_psci_fn_smc (unsigned long a0,unsigned long a1, +unsigned long a2,unsigned long a3) +{ +struct smccc_res res; + +smccc_smc (a0, a1, a2, a3,0 ,0 ,0 ,0 , &res); +return res.a0; +} +static int psci_to_linux_errno (int errno) {switch (errno) {
Signature · 1 line
1.9.1
Re: [PATCH v6 2/6] drivers: psci: replace psci firmware calls
Quoted 13 lines · Jens Wiklander
Switch to use a generic interface for issuing SMC/HVC based on ARM SMC Calling Convention. Removes now the now unused
psci-call.S.Signed-off-by Jens Wiklander <[email protected]>--- arch/arm/kernel/Makefile | 1 - arch/arm/kernel/psci-call.S | 31 ------------------------------- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/psci-call.S | 28 ---------------------------- drivers/firmware/psci.c | 21 +++++++++++++++++++-- 5 files changed, 20 insertions(+), 63 deletions(-) delete mode 100644 arch/arm/kernel/psci-call.S delete mode 100644 arch/arm64/kernel/psci-call.S
[...]
Quoted 22 lines
drivers/firmware/psci.c +1
-2@@ -19,6 +19,7 @@#include <linux/pm.h> #include <linux/printk.h> #include <linux/psci.h> +#include <linux/arm-smccc.h> #include <linux/reboot.h> #include <uapi/linux/psci.h> @@ -56,8 +57,6 @@ struct psci_operations psci_ops;typedef unsigned long (psci_fn )(unsigned long ,unsigned long ,unsigned long ,unsigned long ); -asmlinkage psci_fn __invoke_psci_fn_hvc; -asmlinkage psci_fn __invoke_psci_fn_smc;static psci_fn *invoke_psci_fn;enum psci_function {
drivers/firmware/psci.c enum psci_function { · line 73
Quoted 5 lines
drivers/firmware/psci.c +2
-0@@ -70,6 +69,24 @@ enum psci_function {static u32 psci_function_id[PSCI_FN_MAX ]; +static unsigned long __invoke_psci_fn_hvc (unsigned long a0,unsigned long a1, +unsigned long a2,unsigned long a3)
Minor comment, but could we keep these argument names the same as before please?
drivers/firmware/psci.c enum psci_function { · line 77
Quoted 4 lines
drivers/firmware/psci.c +4
-0+{ +struct smccc_res res; + +smccc_hvc (a0, a1, a2, a3,0 ,0 ,0 ,0 , &res);
It's slightly tempting to use varargs instead of the '0' argument padding, but that will probably make the asm code unmanageable.
Will
Re: [PATCH v6 2/6] drivers: psci: replace psci firmware calls
Quoted 40 lines · Will Deacon
Quoted 13 lines · Jens Wiklander
Switch to use a generic interface for issuing SMC/HVC based on ARM SMC Calling Convention. Removes now the now unused
psci-call.S.Signed-off-by Jens Wiklander <[email protected]>--- arch/arm/kernel/Makefile | 1 - arch/arm/kernel/psci-call.S | 31 ------------------------------- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/psci-call.S | 28 ---------------------------- drivers/firmware/psci.c | 21 +++++++++++++++++++-- 5 files changed, 20 insertions(+), 63 deletions(-) delete mode 100644 arch/arm/kernel/psci-call.S delete mode 100644 arch/arm64/kernel/psci-call.S[...]
Quoted 23 lines
drivers/firmware/psci.c +1
-2@@ -19,6 +19,7 @@#include <linux/pm.h> #include <linux/printk.h> #include <linux/psci.h> +#include <linux/arm-smccc.h> #include <linux/reboot.h> #include <uapi/linux/psci.h> @@ -56,8 +57,6 @@ struct psci_operations psci_ops;typedef unsigned long (psci_fn )(unsigned long ,unsigned long ,unsigned long ,unsigned long ); -asmlinkage psci_fn __invoke_psci_fn_hvc; -asmlinkage psci_fn __invoke_psci_fn_smc;static psci_fn *invoke_psci_fn;enum psci_function {@@ -70,6 +69,24 @@ enum psci_function {
Quoted 7 lines
drivers/firmware/psci.c enum psci_function { · line 73
Quoted 4 lines
drivers/firmware/psci.c +2
-0static u32 psci_function_id[PSCI_FN_MAX ]; +static unsigned long __invoke_psci_fn_hvc (unsigned long a0,unsigned long a1, +unsigned long a2,unsigned long a3)Minor comment, but could we keep these argument names the same as before please?
You mean function_id, arg0, arg1... instead? I guess I should update arm-smccc.h also then.
Quoted 8 lines
drivers/firmware/psci.c enum psci_function { · line 77
Quoted 5 lines
drivers/firmware/psci.c +4
-0+{ +struct smccc_res res; + +smccc_hvc (a0, a1, a2, a3,0 ,0 ,0 ,0 , &res);It's slightly tempting to use varargs instead of the '0' argument padding, but that will probably make the asm code unmanageable.
Agree.
Thanks,
Jens
Re: [PATCH v6 2/6] drivers: psci: replace psci firmware calls
Quoted 43 lines · Jens Wiklander
Quoted 42 lines · Will Deacon
Quoted 13 lines · Jens Wiklander
Switch to use a generic interface for issuing SMC/HVC based on ARM SMC Calling Convention. Removes now the now unused
psci-call.S.Signed-off-by Jens Wiklander <[email protected]>--- arch/arm/kernel/Makefile | 1 - arch/arm/kernel/psci-call.S | 31 ------------------------------- arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/psci-call.S | 28 ---------------------------- drivers/firmware/psci.c | 21 +++++++++++++++++++-- 5 files changed, 20 insertions(+), 63 deletions(-) delete mode 100644 arch/arm/kernel/psci-call.S delete mode 100644 arch/arm64/kernel/psci-call.S[...]
Quoted 25 lines
drivers/firmware/psci.c +1
-2@@ -19,6 +19,7 @@#include <linux/pm.h> #include <linux/printk.h> #include <linux/psci.h> +#include <linux/arm-smccc.h> #include <linux/reboot.h> #include <uapi/linux/psci.h> @@ -56,8 +57,6 @@ struct psci_operations psci_ops;typedef unsigned long (psci_fn )(unsigned long ,unsigned long ,unsigned long ,unsigned long ); -asmlinkage psci_fn __invoke_psci_fn_hvc; -asmlinkage psci_fn __invoke_psci_fn_smc;static psci_fn *invoke_psci_fn;enum psci_function {@@ -70,6 +69,24 @@ enum psci_function {static u32 psci_function_id[PSCI_FN_MAX ];
Quoted 8 lines
Quoted 5 lines
drivers/firmware/psci.c enum psci_function { · line 73
Quoted 2 lines
drivers/firmware/psci.c +2
-0+static unsigned long __invoke_psci_fn_hvc (unsigned long a0,unsigned long a1, +unsigned long a2,unsigned long a3)Minor comment, but could we keep these argument names the same as before please?
You mean
function_id, arg0, arg1... instead? I guess I should updatearm-smccc.halso then.
No; I think just updating the psci caller to use those, but leave the SMCCC low-level details as they are. The latter is just pushing data, whilst the former has some (albeit limited) knowledge of what those values represent.
Will
PATCH v6 3/6 dt/bindings: add bindings for optee
In reply to Jens WiklanderIntroduces optee prefix and adds bindings for ARM TrustZone based OP-TEE implementation.
--- .../bindings/arm/firmware/optee,optee-tz.txt | 29 ++++++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.txt | 1 + 2 files changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +29 -0
@@ -0,0 +1,29 @@ +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 : should contain "optee,optee-tz" + +- method : The method of calling the OP-TEE Trusted OS. Permitted + values are: + + "smc" : SMC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + "hvc" : HVC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + + +Example: + optee { + compatible = "optee,optee-tz"; + method = "smc"; + };
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
@@ -159,6 +159,7 @@ nxp NXP Semiconductors okaya Okaya Electric America, Inc. onnn ON Semiconductor Corp. opencores OpenCores.org +optee OP-TEE, Open Portable Trusted Execution Environment option Option NV ortustech Ortus Technology Co., Ltd. ovti OmniVision Technologies
Signature · 1 line
1.9.1
Rob Herring
maintainerRe: [PATCH v6 3/6] dt/bindings: add bindings for optee
Quoted 18 lines · Jens Wiklander
Introduces optee prefix and adds bindings for ARM TrustZone based OP-TEE implementation.
Signed-off-by Jens Wiklander <[email protected]>--- .../bindings/arm/firmware/optee,optee-tz.txt | 29 ++++++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.txt | 1 + 2 files changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txtDocumentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +2
-0@@ -0,0 +1,29 @@ +OP-TEE Device Tree Bindings +
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt line 12
Quoted 10 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +10
-0+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 : should contain "optee,optee-tz"
I would leave off optee as a vendor. Different implementations by vendors should then add their vendor prefix as they all have the chance to screw-up something. I suppose we could do "linaro" as the reference implementation.
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt line 21
Quoted 9 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +9
-0+ +- method : The method of calling the OP-TEE Trusted OS. Permitted + values are: + + "smc" : SMC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + "hvc" : HVC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h
The use here would be a guest VM calling thru to hypervisor and then hypervisor calling optee?
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt line 26
Quoted 5 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +5
-0+ + + +Example: + optee {
This should go under a /firmware node similar to Documentation/devicetree/bindings/arm/firmware/tlm,trusted-foundations.txt.
Rob
Re: [PATCH v6 3/6] dt/bindings: add bindings for optee
Quoted 26 lines · Rob Herring
Quoted 25 lines · Jens Wiklander
Introduces optee prefix and adds bindings for ARM TrustZone based OP-TEE implementation.
Signed-off-by Jens Wiklander <[email protected]>--- .../bindings/arm/firmware/optee,optee-tz.txt | 29 ++++++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.txt | 1 + 2 files changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txtDocumentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +9
-0@@ -0,0 +1,29 @@ +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. +
Quoted 8 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt line 12
Quoted 3 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +3
-0+* OP-TEE based on ARM TrustZone required properties: + +- compatible : should contain "optee,optee-tz"I would leave off optee as a vendor. Different implementations by vendors should then add their vendor prefix as they all have the chance to screw-up something. I suppose we could do "linaro" as the reference implementation.
OK, I'll use "linaro" then.
Quoted 13 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt line 21
Quoted 10 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +9
-0+ +- method : The method of calling the OP-TEE Trusted OS. Permitted + values are: + + "smc" : SMC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + "hvc" : HVC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.hThe use here would be a guest VM calling thru to hypervisor and then hypervisor calling optee?
Yes, the hypervisor needs to be involved (translating IPA to PA etc) when invoking secure world.
Quoted 9 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt line 26
Quoted 6 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +5
-0+ + + +Example: + optee {This should go under a /firmware node similar to
Documentation/devicetree/bindings/arm/firmware/tlm,trusted-foundations.txt.
I tried that and discovered that a
compatible = "simple-bus";
is needed for the firmware node for optee to get probed. Is it OK to write the example as:
firmware {
compatible = "simple-bus";
optee {...
Thanks,
Jens
Rob Herring
maintainerRe: [PATCH v6 3/6] dt/bindings: add bindings for optee
Quoted 26 lines · Jens Wiklander
Quoted 25 lines · Rob Herring
Quoted 24 lines · Jens Wiklander
Introduces optee prefix and adds bindings for ARM TrustZone based OP-TEE implementation.
Signed-off-by Jens Wiklander <[email protected]>--- .../bindings/arm/firmware/optee,optee-tz.txt | 29 ++++++++++++++++++++++ .../devicetree/bindings/vendor-prefixes.txt | 1 + 2 files changed, 30 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txtDocumentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +8
-0@@ -0,0 +1,29 @@ +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.
[...]
Quoted 11 lines
Quoted 5 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt line 26
Quoted 2 lines
Documentation/devicetree/bindings/arm/firmware/optee,optee-tz.txt new file +2
-0+Example: + optee {This should go under a /firmware node similar to
Documentation/devicetree/bindings/arm/firmware/tlm,trusted-foundations.txt.I tried that and discovered that a
compatible = "simple-bus";
is needed for the firmware node for optee to get probed. Is it OK to write the example as:
Quoted 4 lines
firmware {
compatible = "simple-bus";
optee {That would needlessly create devices for any other child nodes and it is not a bus. Just find the node and call of_platform_device_create for that node in an initcall.
Rob
PATCH v6 4/6 tee: generic TEE subsystem
In reply to Jens WiklanderInitial 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.
* Sysfs implementation_id of TEE driver
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 | 7 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/tee/Kconfig | 8 + drivers/tee/Makefile | 3 + drivers/tee/tee.c | 873 +++++++++++++++++++++++++++++++++++ drivers/tee/tee_private.h | 80 ++++ drivers/tee/tee_shm.c | 324 +++++++++++++ drivers/tee/tee_shm_pool.c | 133 ++++++ include/linux/tee_drv.h | 300 ++++++++++++ include/uapi/linux/tee.h | 383 +++++++++++++++ 12 files changed, 2115 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
@@ -303,6 +303,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 0xAA 00-3F linux/uapi/linux/userfaultfd.h 0xAB 00-1F linux/nbd.h 0xAC 00-1F linux/raw.h
MAINTAINERS +7 -0
@@ -9133,6 +9133,13 @@ S: Maintained F: include/linux/mmc/dw_mmc.h F: drivers/mmc/host/dw_mmc* +TEE SUBSYSTEM +M: Jens Wiklander <[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
@@ -188,4 +188,6 @@ source "drivers/nvdimm/Kconfig" source "drivers/nvmem/Kconfig" +source "drivers/tee/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -167,3 +167,4 @@ obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ obj-$(CONFIG_CORESIGHT) += hwtracing/coresight/ obj-$(CONFIG_ANDROID) += android/ obj-$(CONFIG_NVMEM) += nvmem/ +obj-$(CONFIG_TEE) += tee/
drivers/tee/Kconfig new file +8 -0
@@ -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
@@ -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 +873 -0
873 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 +300 -0
300 lines not on this page · raw message
include/uapi/linux/tee.h new file +383 -0
383 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v6 5/6 tee: add OP-TEE driver
In reply to Jens WiklanderAdds 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 | 400 ++++++++++++++++++++++++++++++ drivers/tee/optee/core.c | 502 ++++++++++++++++++++++++++++++++++++++ drivers/tee/optee/optee_msg.h | 423 ++++++++++++++++++++++++++++++++ drivers/tee/optee/optee_private.h | 146 +++++++++++ drivers/tee/optee/optee_smc.h | 418 +++++++++++++++++++++++++++++++ drivers/tee/optee/rpc.c | 322 ++++++++++++++++++++++++ drivers/tee/optee/supp.c | 212 ++++++++++++++++ 12 files changed, 2452 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
@@ -7777,6 +7777,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
@@ -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
@@ -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
@@ -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
@@ -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 +400 -0
400 lines not on this page · raw message
drivers/tee/optee/core.c new file +502 -0
502 lines not on this page · raw message
drivers/tee/optee/optee_msg.h new file +423 -0
423 lines not on this page · raw message
drivers/tee/optee/optee_private.h new file +146 -0
146 lines not on this page · raw message
drivers/tee/optee/optee_smc.h new file +418 -0
418 lines not on this page · raw message
drivers/tee/optee/rpc.c new file +322 -0
322 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
PATCH v6 6/6 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
@@ -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
@@ -9144,6 +9144,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