Commit 40b561e5 authored by Arnd Bergmann's avatar Arnd Bergmann

Merge tag 'tee-ts-for-v6.10' of...

Merge tag 'tee-ts-for-v6.10' of https://git.linaro.org/people/jens.wiklander/linux-tee into soc/drivers

TEE driver for Trusted Services

This introduces a TEE driver for Trusted Services [1].

Trusted Services is a TrustedFirmware.org project that provides a
framework for developing and deploying device Root of Trust services in
FF-A [2] Secure Partitions. The project hosts the reference
implementation of Arm Platform Security Architecture [3] for Arm
A-profile devices.

The FF-A Secure Partitions are accessible through the FF-A driver in
Linux. However, the FF-A driver doesn't have a user space interface so
user space clients currently cannot access Trusted Services. The goal of
this TEE driver is to bridge this gap and make Trusted Services
functionality accessible from user space.

[1] https://www.trustedfirmware.org/projects/trusted-services/
[2] https://developer.arm.com/documentation/den0077/
[3] https://www.arm.com/architecture/security-features/platform-security

* tag 'tee-ts-for-v6.10' of https://git.linaro.org/people/jens.wiklander/linux-tee:
  MAINTAINERS: tee: tstee: Add entry
  Documentation: tee: Add TS-TEE driver
  tee: tstee: Add Trusted Services TEE driver
  tee: optee: Move pool_op helper functions
  tee: Refactor TEE subsystem header files

Link: https://lore.kernel.org/r/20240425073119.GA3261080@raydenSigned-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parents d9f843fb 31611cc8
...@@ -10,6 +10,7 @@ TEE Subsystem ...@@ -10,6 +10,7 @@ TEE Subsystem
tee tee
op-tee op-tee
amd-tee amd-tee
ts-tee
.. only:: subproject and html .. only:: subproject and html
......
.. SPDX-License-Identifier: GPL-2.0
=================================
TS-TEE (Trusted Services project)
=================================
This driver provides access to secure services implemented by Trusted Services.
Trusted Services [1] is a TrustedFirmware.org project that provides a framework
for developing and deploying device Root of Trust services in FF-A [2] S-EL0
Secure Partitions. The project hosts the reference implementation of the Arm
Platform Security Architecture [3] for Arm A-profile devices.
The FF-A Secure Partitions (SP) are accessible through the FF-A driver [4] which
provides the low level communication for this driver. On top of that the Trusted
Services RPC protocol is used [5]. To use the driver from user space a reference
implementation is provided at [6], which is part of the Trusted Services client
library called libts [7].
All Trusted Services (TS) SPs have the same FF-A UUID; it identifies the TS RPC
protocol. A TS SP can host one or more services (e.g. PSA Crypto, PSA ITS, etc).
A service is identified by its service UUID; the same type of service cannot be
present twice in the same SP. During SP boot each service in the SP is assigned
an "interface ID". This is just a short ID to simplify message addressing.
The generic TEE design is to share memory at once with the Trusted OS, which can
then be reused to communicate with multiple applications running on the Trusted
OS. However, in case of FF-A, memory sharing works on an endpoint level, i.e.
memory is shared with a specific SP. User space has to be able to separately
share memory with each SP based on its endpoint ID; therefore a separate TEE
device is registered for each discovered TS SP. Opening the SP corresponds to
opening the TEE device and creating a TEE context. A TS SP hosts one or more
services. Opening a service corresponds to opening a session in the given
tee_context.
Overview of a system with Trusted Services components::
User space Kernel space Secure world
~~~~~~~~~~ ~~~~~~~~~~~~ ~~~~~~~~~~~~
+--------+ +-------------+
| Client | | Trusted |
+--------+ | Services SP |
/\ +-------------+
|| /\
|| ||
|| ||
\/ \/
+-------+ +----------+--------+ +-------------+
| libts | | TEE | TS-TEE | | FF-A SPMC |
| | | subsys | driver | | + SPMD |
+-------+----------------+----+-----+--------+-----------+-------------+
| Generic TEE API | | FF-A | TS RPC protocol |
| IOCTL (TEE_IOC_*) | | driver | over FF-A |
+-----------------------------+ +--------+-------------------------+
References
==========
[1] https://www.trustedfirmware.org/projects/trusted-services/
[2] https://developer.arm.com/documentation/den0077/
[3] https://www.arm.com/architecture/security-features/platform-security
[4] drivers/firmware/arm_ffa/
[5] https://trusted-services.readthedocs.io/en/v1.0.0/developer/service-access-protocols.html#abi
[6] https://git.trustedfirmware.org/TS/trusted-services.git/tree/components/rpc/ts_rpc/caller/linux/ts_rpc_caller_linux.c?h=v1.0.0
[7] https://git.trustedfirmware.org/TS/trusted-services.git/tree/deployments/libts/arm-linux/CMakeLists.txt?h=v1.0.0
...@@ -21753,6 +21753,7 @@ F: Documentation/driver-api/tee.rst ...@@ -21753,6 +21753,7 @@ F: Documentation/driver-api/tee.rst
F: Documentation/tee/ F: Documentation/tee/
F: Documentation/userspace-api/tee.rst F: Documentation/userspace-api/tee.rst
F: drivers/tee/ F: drivers/tee/
F: include/linux/tee_core.h
F: include/linux/tee_drv.h F: include/linux/tee_drv.h
F: include/uapi/linux/tee.h F: include/uapi/linux/tee.h
...@@ -22546,6 +22547,15 @@ F: Documentation/ABI/testing/configfs-tsm ...@@ -22546,6 +22547,15 @@ F: Documentation/ABI/testing/configfs-tsm
F: drivers/virt/coco/tsm.c F: drivers/virt/coco/tsm.c
F: include/linux/tsm.h F: include/linux/tsm.h
TRUSTED SERVICES TEE DRIVER
M: Balint Dobszay <balint.dobszay@arm.com>
M: Sudeep Holla <sudeep.holla@arm.com>
L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
L: trusted-services@lists.trustedfirmware.org
S: Maintained
F: Documentation/tee/ts-tee.rst
F: drivers/tee/tstee/
TTY LAYER AND SERIAL DRIVERS TTY LAYER AND SERIAL DRIVERS
M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
M: Jiri Slaby <jirislaby@kernel.org> M: Jiri Slaby <jirislaby@kernel.org>
......
...@@ -15,5 +15,6 @@ if TEE ...@@ -15,5 +15,6 @@ if TEE
source "drivers/tee/optee/Kconfig" source "drivers/tee/optee/Kconfig"
source "drivers/tee/amdtee/Kconfig" source "drivers/tee/amdtee/Kconfig"
source "drivers/tee/tstee/Kconfig"
endif endif
...@@ -5,3 +5,4 @@ tee-objs += tee_shm.o ...@@ -5,3 +5,4 @@ tee-objs += tee_shm.o
tee-objs += tee_shm_pool.o tee-objs += tee_shm_pool.o
obj-$(CONFIG_OPTEE) += optee/ obj-$(CONFIG_OPTEE) += optee/
obj-$(CONFIG_AMDTEE) += amdtee/ obj-$(CONFIG_AMDTEE) += amdtee/
obj-$(CONFIG_ARM_TSTEE) += tstee/
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/types.h> #include <linux/types.h>
#include "amdtee_if.h" #include "amdtee_if.h"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/tee.h> #include <linux/tee.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/psp-tee.h> #include <linux/psp-tee.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/psp.h> #include <linux/psp.h>
......
...@@ -9,13 +9,12 @@ ...@@ -9,13 +9,12 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/firmware.h> #include <linux/firmware.h>
#include "amdtee_private.h" #include "amdtee_private.h"
#include "../tee_private.h"
#include <linux/psp-tee.h> #include <linux/psp-tee.h>
static struct amdtee_driver_data *drv_data; static struct amdtee_driver_data *drv_data;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
*/ */
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/psp.h> #include <linux/psp.h>
#include "amdtee_private.h" #include "amdtee_private.h"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/types.h> #include <linux/types.h>
#include "optee_private.h" #include "optee_private.h"
......
...@@ -9,77 +9,13 @@ ...@@ -9,77 +9,13 @@
#include <linux/crash_dump.h> #include <linux/crash_dump.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/mm.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/types.h> #include <linux/types.h>
#include "optee_private.h" #include "optee_private.h"
int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
size_t size, size_t align,
int (*shm_register)(struct tee_context *ctx,
struct tee_shm *shm,
struct page **pages,
size_t num_pages,
unsigned long start))
{
size_t nr_pages = roundup(size, PAGE_SIZE) / PAGE_SIZE;
struct page **pages;
unsigned int i;
int rc = 0;
/*
* Ignore alignment since this is already going to be page aligned
* and there's no need for any larger alignment.
*/
shm->kaddr = alloc_pages_exact(nr_pages * PAGE_SIZE,
GFP_KERNEL | __GFP_ZERO);
if (!shm->kaddr)
return -ENOMEM;
shm->paddr = virt_to_phys(shm->kaddr);
shm->size = nr_pages * PAGE_SIZE;
pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
if (!pages) {
rc = -ENOMEM;
goto err;
}
for (i = 0; i < nr_pages; i++)
pages[i] = virt_to_page((u8 *)shm->kaddr + i * PAGE_SIZE);
shm->pages = pages;
shm->num_pages = nr_pages;
if (shm_register) {
rc = shm_register(shm->ctx, shm, pages, nr_pages,
(unsigned long)shm->kaddr);
if (rc)
goto err;
}
return 0;
err:
free_pages_exact(shm->kaddr, shm->size);
shm->kaddr = NULL;
return rc;
}
void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
int (*shm_unregister)(struct tee_context *ctx,
struct tee_shm *shm))
{
if (shm_unregister)
shm_unregister(shm->ctx, shm);
free_pages_exact(shm->kaddr, shm->size);
shm->kaddr = NULL;
kfree(shm->pages);
shm->pages = NULL;
}
static void optee_bus_scan(struct work_struct *work) static void optee_bus_scan(struct work_struct *work)
{ {
WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP)); WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/uuid.h> #include <linux/uuid.h>
#include "optee_private.h" #include "optee_private.h"
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/types.h> #include <linux/types.h>
#include "optee_private.h" #include "optee_private.h"
#include "optee_ffa.h" #include "optee_ffa.h"
...@@ -374,14 +374,14 @@ static int optee_ffa_shm_unregister_supp(struct tee_context *ctx, ...@@ -374,14 +374,14 @@ static int optee_ffa_shm_unregister_supp(struct tee_context *ctx,
static int pool_ffa_op_alloc(struct tee_shm_pool *pool, static int pool_ffa_op_alloc(struct tee_shm_pool *pool,
struct tee_shm *shm, size_t size, size_t align) struct tee_shm *shm, size_t size, size_t align)
{ {
return optee_pool_op_alloc_helper(pool, shm, size, align, return tee_dyn_shm_alloc_helper(shm, size, align,
optee_ffa_shm_register); optee_ffa_shm_register);
} }
static void pool_ffa_op_free(struct tee_shm_pool *pool, static void pool_ffa_op_free(struct tee_shm_pool *pool,
struct tee_shm *shm) struct tee_shm *shm)
{ {
optee_pool_op_free_helper(pool, shm, optee_ffa_shm_unregister); tee_dyn_shm_free_helper(shm, optee_ffa_shm_unregister);
} }
static void pool_ffa_op_destroy_pool(struct tee_shm_pool *pool) static void pool_ffa_op_destroy_pool(struct tee_shm_pool *pool)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include "optee_private.h" #include "optee_private.h"
struct notif_entry { struct notif_entry {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <linux/arm-smccc.h> #include <linux/arm-smccc.h>
#include <linux/rhashtable.h> #include <linux/rhashtable.h>
#include <linux/semaphore.h> #include <linux/semaphore.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/types.h> #include <linux/types.h>
#include "optee_msg.h" #include "optee_msg.h"
...@@ -283,18 +283,6 @@ int optee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session); ...@@ -283,18 +283,6 @@ int optee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session);
int optee_enumerate_devices(u32 func); int optee_enumerate_devices(u32 func);
void optee_unregister_devices(void); void optee_unregister_devices(void);
int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
size_t size, size_t align,
int (*shm_register)(struct tee_context *ctx,
struct tee_shm *shm,
struct page **pages,
size_t num_pages,
unsigned long start));
void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
int (*shm_unregister)(struct tee_context *ctx,
struct tee_shm *shm));
void optee_remove_common(struct optee *optee); void optee_remove_common(struct optee *optee);
int optee_open(struct tee_context *ctx, bool cap_memref_null); int optee_open(struct tee_context *ctx, bool cap_memref_null);
void optee_release(struct tee_context *ctx); void optee_release(struct tee_context *ctx);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include "optee_private.h" #include "optee_private.h"
#include "optee_rpc_cmd.h" #include "optee_rpc_cmd.h"
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include "optee_private.h" #include "optee_private.h"
...@@ -592,19 +592,18 @@ static int pool_op_alloc(struct tee_shm_pool *pool, ...@@ -592,19 +592,18 @@ static int pool_op_alloc(struct tee_shm_pool *pool,
* to be registered with OP-TEE. * to be registered with OP-TEE.
*/ */
if (shm->flags & TEE_SHM_PRIV) if (shm->flags & TEE_SHM_PRIV)
return optee_pool_op_alloc_helper(pool, shm, size, align, NULL); return tee_dyn_shm_alloc_helper(shm, size, align, NULL);
return optee_pool_op_alloc_helper(pool, shm, size, align, return tee_dyn_shm_alloc_helper(shm, size, align, optee_shm_register);
optee_shm_register);
} }
static void pool_op_free(struct tee_shm_pool *pool, static void pool_op_free(struct tee_shm_pool *pool,
struct tee_shm *shm) struct tee_shm *shm)
{ {
if (!(shm->flags & TEE_SHM_PRIV)) if (!(shm->flags & TEE_SHM_PRIV))
optee_pool_op_free_helper(pool, shm, optee_shm_unregister); tee_dyn_shm_free_helper(shm, optee_shm_unregister);
else else
optee_pool_op_free_helper(pool, shm, NULL); tee_dyn_shm_free_helper(shm, NULL);
} }
static void pool_op_destroy_pool(struct tee_shm_pool *pool) static void pool_op_destroy_pool(struct tee_shm_pool *pool)
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <crypto/hash.h> #include <crypto/hash.h>
#include <crypto/sha1.h> #include <crypto/sha1.h>
......
...@@ -12,41 +12,6 @@ ...@@ -12,41 +12,6 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/types.h> #include <linux/types.h>
#define TEE_DEVICE_FLAG_REGISTERED 0x1
#define TEE_MAX_DEV_NAME_LEN 32
/**
* struct tee_device - TEE Device representation
* @name: name of device
* @desc: description of device
* @id: unique id of device
* @flags: represented by TEE_DEVICE_FLAG_REGISTERED above
* @dev: embedded basic device structure
* @cdev: embedded cdev
* @num_users: number of active users of this device
* @c_no_user: completion used when unregistering the device
* @mutex: mutex protecting @num_users and @idr
* @idr: register of user space shared memory objects allocated or
* registered on this device
* @pool: shared memory pool
*/
struct tee_device {
char name[TEE_MAX_DEV_NAME_LEN];
const struct tee_desc *desc;
int id;
unsigned int flags;
struct device dev;
struct cdev cdev;
size_t num_users;
struct completion c_no_users;
struct mutex mutex; /* protects num_users and idr */
struct idr idr;
struct tee_shm_pool *pool;
};
int tee_shm_get_fd(struct tee_shm *shm); int tee_shm_get_fd(struct tee_shm *shm);
bool tee_device_get(struct tee_device *teedev); bool tee_device_get(struct tee_device *teedev);
......
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
#include <linux/anon_inodes.h> #include <linux/anon_inodes.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/io.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/uio.h> #include <linux/uio.h>
#include <linux/highmem.h> #include <linux/highmem.h>
...@@ -202,6 +203,70 @@ struct tee_shm *tee_shm_alloc_priv_buf(struct tee_context *ctx, size_t size) ...@@ -202,6 +203,70 @@ struct tee_shm *tee_shm_alloc_priv_buf(struct tee_context *ctx, size_t size)
} }
EXPORT_SYMBOL_GPL(tee_shm_alloc_priv_buf); EXPORT_SYMBOL_GPL(tee_shm_alloc_priv_buf);
int tee_dyn_shm_alloc_helper(struct tee_shm *shm, size_t size, size_t align,
int (*shm_register)(struct tee_context *ctx,
struct tee_shm *shm,
struct page **pages,
size_t num_pages,
unsigned long start))
{
size_t nr_pages = roundup(size, PAGE_SIZE) / PAGE_SIZE;
struct page **pages;
unsigned int i;
int rc = 0;
/*
* Ignore alignment since this is already going to be page aligned
* and there's no need for any larger alignment.
*/
shm->kaddr = alloc_pages_exact(nr_pages * PAGE_SIZE,
GFP_KERNEL | __GFP_ZERO);
if (!shm->kaddr)
return -ENOMEM;
shm->paddr = virt_to_phys(shm->kaddr);
shm->size = nr_pages * PAGE_SIZE;
pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
if (!pages) {
rc = -ENOMEM;
goto err;
}
for (i = 0; i < nr_pages; i++)
pages[i] = virt_to_page((u8 *)shm->kaddr + i * PAGE_SIZE);
shm->pages = pages;
shm->num_pages = nr_pages;
if (shm_register) {
rc = shm_register(shm->ctx, shm, pages, nr_pages,
(unsigned long)shm->kaddr);
if (rc)
goto err;
}
return 0;
err:
free_pages_exact(shm->kaddr, shm->size);
shm->kaddr = NULL;
return rc;
}
EXPORT_SYMBOL_GPL(tee_dyn_shm_alloc_helper);
void tee_dyn_shm_free_helper(struct tee_shm *shm,
int (*shm_unregister)(struct tee_context *ctx,
struct tee_shm *shm))
{
if (shm_unregister)
shm_unregister(shm->ctx, shm);
free_pages_exact(shm->kaddr, shm->size);
shm->kaddr = NULL;
kfree(shm->pages);
shm->pages = NULL;
}
EXPORT_SYMBOL_GPL(tee_dyn_shm_free_helper);
static struct tee_shm * static struct tee_shm *
register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags, register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags,
int id) int id)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
#include <linux/genalloc.h> #include <linux/genalloc.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tee_drv.h> #include <linux/tee_core.h>
#include "tee_private.h" #include "tee_private.h"
static int pool_op_gen_alloc(struct tee_shm_pool *pool, struct tee_shm *shm, static int pool_op_gen_alloc(struct tee_shm_pool *pool, struct tee_shm *shm,
......
# SPDX-License-Identifier: GPL-2.0-only
config ARM_TSTEE
tristate "Arm Trusted Services TEE driver"
depends on ARM_FFA_TRANSPORT
default n
help
The Trusted Services project provides a framework for developing and
deploying device Root of Trust services in FF-A Secure Partitions.
This driver provides an interface to make Trusted Services Secure
Partitions accessible for user space clients, since the FF-A driver
doesn't implement a user space interface directly.
# SPDX-License-Identifier: GPL-2.0-only
arm-tstee-objs := core.o
obj-$(CONFIG_ARM_TSTEE) = arm-tstee.o
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2023, Arm Limited
*/
#ifndef TSTEE_PRIVATE_H
#define TSTEE_PRIVATE_H
#include <linux/arm_ffa.h>
#include <linux/bitops.h>
#include <linux/tee_core.h>
#include <linux/types.h>
#include <linux/uuid.h>
#include <linux/xarray.h>
/*
* The description of the ABI implemented in this file is available at
* https://trusted-services.readthedocs.io/en/v1.0.0/developer/service-access-protocols.html#abi
*/
/* UUID of this protocol */
#define TS_RPC_UUID UUID_INIT(0xbdcd76d7, 0x825e, 0x4751, \
0x96, 0x3b, 0x86, 0xd4, 0xf8, 0x49, 0x43, 0xac)
/* Protocol version*/
#define TS_RPC_PROTOCOL_VERSION (1)
/* Status codes */
#define TS_RPC_OK (0)
/* RPC control register */
#define TS_RPC_CTRL_REG (0)
#define OPCODE_MASK GENMASK(15, 0)
#define IFACE_ID_MASK GENMASK(23, 16)
#define TS_RPC_CTRL_OPCODE(x) ((u16)(FIELD_GET(OPCODE_MASK, (x))))
#define TS_RPC_CTRL_IFACE_ID(x) ((u8)(FIELD_GET(IFACE_ID_MASK, (x))))
#define TS_RPC_CTRL_PACK_IFACE_OPCODE(i, o) \
(FIELD_PREP(IFACE_ID_MASK, (i)) | FIELD_PREP(OPCODE_MASK, (o)))
#define TS_RPC_CTRL_SAP_RC BIT(30)
#define TS_RPC_CTRL_SAP_ERR BIT(31)
/* Interface ID for RPC management operations */
#define TS_RPC_MGMT_IFACE_ID (0xff)
/* Management calls */
#define TS_RPC_OP_GET_VERSION (0x0000)
#define TS_RPC_GET_VERSION_RESP (1)
#define TS_RPC_OP_RETRIEVE_MEM (0x0001)
#define TS_RPC_RETRIEVE_MEM_HANDLE_LSW (1)
#define TS_RPC_RETRIEVE_MEM_HANDLE_MSW (2)
#define TS_RPC_RETRIEVE_MEM_TAG_LSW (3)
#define TS_RPC_RETRIEVE_MEM_TAG_MSW (4)
#define TS_RPC_RETRIEVE_MEM_RPC_STATUS (1)
#define TS_RPC_OP_RELINQ_MEM (0x0002)
#define TS_RPC_RELINQ_MEM_HANDLE_LSW (1)
#define TS_RPC_RELINQ_MEM_HANDLE_MSW (2)
#define TS_RPC_RELINQ_MEM_RPC_STATUS (1)
#define TS_RPC_OP_SERVICE_INFO (0x0003)
#define TS_RPC_SERVICE_INFO_UUID0 (1)
#define TS_RPC_SERVICE_INFO_UUID1 (2)
#define TS_RPC_SERVICE_INFO_UUID2 (3)
#define TS_RPC_SERVICE_INFO_UUID3 (4)
#define TS_RPC_SERVICE_INFO_RPC_STATUS (1)
#define TS_RPC_SERVICE_INFO_IFACE (2)
/* Service call */
#define TS_RPC_SERVICE_MEM_HANDLE_LSW (1)
#define TS_RPC_SERVICE_MEM_HANDLE_MSW (2)
#define TS_RPC_SERVICE_REQ_LEN (3)
#define TS_RPC_SERVICE_CLIENT_ID (4)
#define TS_RPC_SERVICE_RPC_STATUS (1)
#define TS_RPC_SERVICE_STATUS (2)
#define TS_RPC_SERVICE_RESP_LEN (3)
struct tstee {
struct ffa_device *ffa_dev;
struct tee_device *teedev;
struct tee_shm_pool *pool;
};
struct ts_session {
u8 iface_id;
};
struct ts_context_data {
struct xarray sess_list;
};
#endif /* TSTEE_PRIVATE_H */
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2024 Linaro Limited
*/
#ifndef __TEE_CORE_H
#define __TEE_CORE_H
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/idr.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/tee.h>
#include <linux/tee_drv.h>
#include <linux/types.h>
#include <linux/uuid.h>
/*
* The file describes the API provided by the generic TEE driver to the
* specific TEE driver.
*/
#define TEE_SHM_DYNAMIC BIT(0) /* Dynamic shared memory registered */
/* in secure world */
#define TEE_SHM_USER_MAPPED BIT(1) /* Memory mapped in user space */
#define TEE_SHM_POOL BIT(2) /* Memory allocated from pool */
#define TEE_SHM_PRIV BIT(3) /* Memory private to TEE driver */
#define TEE_DEVICE_FLAG_REGISTERED 0x1
#define TEE_MAX_DEV_NAME_LEN 32
/**
* struct tee_device - TEE Device representation
* @name: name of device
* @desc: description of device
* @id: unique id of device
* @flags: represented by TEE_DEVICE_FLAG_REGISTERED above
* @dev: embedded basic device structure
* @cdev: embedded cdev
* @num_users: number of active users of this device
* @c_no_user: completion used when unregistering the device
* @mutex: mutex protecting @num_users and @idr
* @idr: register of user space shared memory objects allocated or
* registered on this device
* @pool: shared memory pool
*/
struct tee_device {
char name[TEE_MAX_DEV_NAME_LEN];
const struct tee_desc *desc;
int id;
unsigned int flags;
struct device dev;
struct cdev cdev;
size_t num_users;
struct completion c_no_users;
struct mutex mutex; /* protects num_users and idr */
struct idr idr;
struct tee_shm_pool *pool;
};
/**
* struct tee_driver_ops - driver operations vtable
* @get_version: returns version of driver
* @open: called when the device file is opened
* @release: release this open file
* @open_session: open a new session
* @close_session: close a session
* @system_session: declare session as a system session
* @invoke_func: invoke a trusted function
* @cancel_req: request cancel of an ongoing invoke or open
* @supp_recv: called for supplicant to get a command
* @supp_send: called for supplicant to send a response
* @shm_register: register shared memory buffer in TEE
* @shm_unregister: unregister shared memory buffer in TEE
*/
struct tee_driver_ops {
void (*get_version)(struct tee_device *teedev,
struct tee_ioctl_version_data *vers);
int (*open)(struct tee_context *ctx);
void (*release)(struct tee_context *ctx);
int (*open_session)(struct tee_context *ctx,
struct tee_ioctl_open_session_arg *arg,
struct tee_param *param);
int (*close_session)(struct tee_context *ctx, u32 session);
int (*system_session)(struct tee_context *ctx, u32 session);
int (*invoke_func)(struct tee_context *ctx,
struct tee_ioctl_invoke_arg *arg,
struct tee_param *param);
int (*cancel_req)(struct tee_context *ctx, u32 cancel_id, u32 session);
int (*supp_recv)(struct tee_context *ctx, u32 *func, u32 *num_params,
struct tee_param *param);
int (*supp_send)(struct tee_context *ctx, u32 ret, u32 num_params,
struct tee_param *param);
int (*shm_register)(struct tee_context *ctx, struct tee_shm *shm,
struct page **pages, size_t num_pages,
unsigned long start);
int (*shm_unregister)(struct tee_context *ctx, struct tee_shm *shm);
};
/**
* struct tee_desc - Describes the TEE driver to the subsystem
* @name: name of driver
* @ops: driver operations vtable
* @owner: module providing the driver
* @flags: Extra properties of driver, defined by TEE_DESC_* below
*/
#define TEE_DESC_PRIVILEGED 0x1
struct tee_desc {
const char *name;
const struct tee_driver_ops *ops;
struct module *owner;
u32 flags;
};
/**
* tee_device_alloc() - Allocate a new struct tee_device instance
* @teedesc: Descriptor for this driver
* @dev: Parent device for this device
* @pool: Shared memory pool, NULL if not used
* @driver_data: Private driver data for this device
*
* Allocates a new struct tee_device instance. The device is
* removed by tee_device_unregister().
*
* @returns a pointer to a 'struct tee_device' or an ERR_PTR on failure
*/
struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
struct device *dev,
struct tee_shm_pool *pool,
void *driver_data);
/**
* tee_device_register() - Registers a TEE device
* @teedev: Device to register
*
* tee_device_unregister() need to be called to remove the @teedev if
* this function fails.
*
* @returns < 0 on failure
*/
int tee_device_register(struct tee_device *teedev);
/**
* tee_device_unregister() - Removes a TEE device
* @teedev: Device to unregister
*
* This function should be called to remove the @teedev even if
* tee_device_register() hasn't been called yet. Does nothing if
* @teedev is NULL.
*/
void tee_device_unregister(struct tee_device *teedev);
/**
* tee_session_calc_client_uuid() - Calculates client UUID for session
* @uuid: Resulting UUID
* @connection_method: Connection method for session (TEE_IOCTL_LOGIN_*)
* @connectuon_data: Connection data for opening session
*
* Based on connection method calculates UUIDv5 based client UUID.
*
* For group based logins verifies that calling process has specified
* credentials.
*
* @return < 0 on failure
*/
int tee_session_calc_client_uuid(uuid_t *uuid, u32 connection_method,
const u8 connection_data[TEE_IOCTL_UUID_LEN]);
/**
* struct tee_shm_pool - shared memory pool
* @ops: operations
* @private_data: private data for the shared memory manager
*/
struct tee_shm_pool {
const struct tee_shm_pool_ops *ops;
void *private_data;
};
/**
* struct tee_shm_pool_ops - shared memory pool operations
* @alloc: called when allocating shared memory
* @free: called when freeing shared memory
* @destroy_pool: called when destroying the pool
*/
struct tee_shm_pool_ops {
int (*alloc)(struct tee_shm_pool *pool, struct tee_shm *shm,
size_t size, size_t align);
void (*free)(struct tee_shm_pool *pool, struct tee_shm *shm);
void (*destroy_pool)(struct tee_shm_pool *pool);
};
/*
* tee_shm_pool_alloc_res_mem() - Create a shm manager for reserved memory
* @vaddr: Virtual address of start of pool
* @paddr: Physical address of start of pool
* @size: Size in bytes of the pool
*
* @returns pointer to a 'struct tee_shm_pool' or an ERR_PTR on failure.
*/
struct tee_shm_pool *tee_shm_pool_alloc_res_mem(unsigned long vaddr,
phys_addr_t paddr, size_t size,
int min_alloc_order);
/**
* tee_shm_pool_free() - Free a shared memory pool
* @pool: The shared memory pool to free
*
* The must be no remaining shared memory allocated from this pool when
* this function is called.
*/
static inline void tee_shm_pool_free(struct tee_shm_pool *pool)
{
pool->ops->destroy_pool(pool);
}
/**
* tee_get_drvdata() - Return driver_data pointer
* @returns the driver_data pointer supplied to tee_register().
*/
void *tee_get_drvdata(struct tee_device *teedev);
/**
* tee_shm_alloc_priv_buf() - Allocate shared memory for private use by specific
* TEE driver
* @ctx: The TEE context for shared memory allocation
* @size: Shared memory allocation size
* @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure
*/
struct tee_shm *tee_shm_alloc_priv_buf(struct tee_context *ctx, size_t size);
int tee_dyn_shm_alloc_helper(struct tee_shm *shm, size_t size, size_t align,
int (*shm_register)(struct tee_context *ctx,
struct tee_shm *shm,
struct page **pages,
size_t num_pages,
unsigned long start));
void tee_dyn_shm_free_helper(struct tee_shm *shm,
int (*shm_unregister)(struct tee_context *ctx,
struct tee_shm *shm));
/**
* tee_shm_is_dynamic() - Check if shared memory object is of the dynamic kind
* @shm: Shared memory handle
* @returns true if object is dynamic shared memory
*/
static inline bool tee_shm_is_dynamic(struct tee_shm *shm)
{
return shm && (shm->flags & TEE_SHM_DYNAMIC);
}
/**
* tee_shm_put() - Decrease reference count on a shared memory handle
* @shm: Shared memory handle
*/
void tee_shm_put(struct tee_shm *shm);
/**
* tee_shm_get_id() - Get id of a shared memory object
* @shm: Shared memory handle
* @returns id
*/
static inline int tee_shm_get_id(struct tee_shm *shm)
{
return shm->id;
}
/**
* tee_shm_get_from_id() - Find shared memory object and increase reference
* count
* @ctx: Context owning the shared memory
* @id: Id of shared memory object
* @returns a pointer to 'struct tee_shm' on success or an ERR_PTR on failure
*/
struct tee_shm *tee_shm_get_from_id(struct tee_context *ctx, int id);
static inline bool tee_param_is_memref(struct tee_param *param)
{
switch (param->attr & TEE_IOCTL_PARAM_ATTR_TYPE_MASK) {
case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT:
case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT:
case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT:
return true;
default:
return false;
}
}
/**
* teedev_open() - Open a struct tee_device
* @teedev: Device to open
*
* @return a pointer to struct tee_context on success or an ERR_PTR on failure.
*/
struct tee_context *teedev_open(struct tee_device *teedev);
/**
* teedev_close_context() - closes a struct tee_context
* @ctx: The struct tee_context to close
*/
void teedev_close_context(struct tee_context *ctx);
#endif /*__TEE_CORE_H*/
This diff is collapsed.
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
*/ */
#define TEE_IMPL_ID_OPTEE 1 #define TEE_IMPL_ID_OPTEE 1
#define TEE_IMPL_ID_AMDTEE 2 #define TEE_IMPL_ID_AMDTEE 2
#define TEE_IMPL_ID_TSTEE 3
/* /*
* OP-TEE specific capabilities * OP-TEE specific capabilities
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment