Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-tee patch set: Enable OP-TEE #59

Merged
merged 39 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a923a67
tee: add tee_param_is_memref() for driver use
jenswi-linaro Dec 23, 2016
86cdfd8
tee: add TEE_IOCTL_PARAM_ATTR_META
jenswi-linaro Dec 23, 2016
92cad26
optee: support asynchronous supplicant requests
jenswi-linaro Dec 23, 2016
bce7309
tee: flexible shared memory pool creation
jenswi-linaro Nov 29, 2017
3429728
tee: add register user memory
jenswi-linaro Nov 29, 2017
3f432fc
tee: optee: Update protocol definitions
lorc Nov 29, 2017
3498607
tee: optee: add page list manipulation functions
lorc Nov 29, 2017
4d7edbb
tee: optee: add shared buffer registration functions
lorc Nov 29, 2017
571bdf5
tee: optee: add registered shared parameters handling
lorc Nov 29, 2017
afce837
tee: optee: add registered buffers handling into RPC calls
lorc Nov 29, 2017
06d1e9d
tee: optee: store OP-TEE capabilities in private data
lorc Nov 29, 2017
766785e
tee: optee: add optee-specific shared pool implementation
lorc Nov 29, 2017
6b9b620
tee: optee: enable dynamic SHM support
lorc Nov 29, 2017
ed51d34
tee: use reference counting for tee_context
lorc Nov 29, 2017
12be3ab
tee: shm: inline tee_shm_get_id()
lorc Nov 29, 2017
29606f8
tee: optee: fix header dependencies
arndb Dec 21, 2017
1195147
tee: add start argument to shm_register callback
jenswi-linaro Dec 28, 2017
0bf130e
tee: optee: check type of registered shared memory
jenswi-linaro Dec 28, 2017
197ba29
tee: shm: make function __tee_shm_alloc static
Dec 22, 2017
af7d81f
tee: shm: don't put_page on null shm->pages
Dec 22, 2017
953ac5a
tee: shm: Potential NULL dereference calling tee_shm_register()
Jan 6, 2018
6146841
tee: correct max value for id allocation
MrVan Jan 15, 2018
6bdcba5
tee: optee: GET_OS_REVISION: document a2 as a build identifier
jforissier Nov 24, 2017
ff233e2
tee: optee: report OP-TEE revision information
jforissier Nov 24, 2017
14afe9d
tee: replace getnstimeofday64() with ktime_get_real_ts64()
arndb Jun 18, 2018
ceca19b
tee: optee: making OPTEE_SHM_NUM_PRIV_PAGES configurable via Kconfig
sahilnxp Jun 8, 2018
48f9299
tee: add kernel internal client interface
jenswi-linaro Nov 19, 2015
ed650ee
tee: new ioctl to a register tee_shm from a dmabuf file descriptor
etienne-lms Oct 27, 2016
a263d93
OP-TEE Benchmark **not for mainline**
Oct 25, 2016
492695f
tee: optee: optee_bench.h: remove useless include **not for mainline**
jforissier May 31, 2017
801bae5
tee: optee: log message if dynamic shm is enabled
Apr 11, 2018
0e55bbd
tee: fix unbalanced context refcount in register shm from fd
etienne-lms Apr 16, 2018
963b363
tee: support of allocating DMA shared buffers **not for mainline**
Feb 5, 2018
8740656
tee: support of allocating DMA shared buffers **not for mainline**
Jun 19, 2018
4a7d2fb
tee: optee: take DT status property into account
Aug 1, 2018
a5f3696
optee: allow to work without static shared memory
lorc Jun 15, 2018
7a42d92
tee: shm: add accessors for buffer size and page offset
lorc Nov 29, 2017
0bbcff2
tee: shm: add page accessor functions
lorc Nov 29, 2017
a2098ed
Enable OP-TEE
rshym Feb 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions arch/arm64/configs/android_xenvm_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,5 @@ CONFIG_CRYPTO_AES_ARM64_CE_BLK=y
CONFIG_CRYPTO_AES_ARM64_NEON_BLK=y
CONFIG_CMA_ALIGNMENT=9
CONFIG_XT_CMA_HELPER=y
CONFIG_TEE=y
CONFIG_OPTEE=y
15 changes: 15 additions & 0 deletions drivers/tee/optee/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ config OPTEE
help
This implements the OP-TEE Trusted Execution Environment (TEE)
driver.

config OPTEE_SHM_NUM_PRIV_PAGES
int "Private Shared Memory Pages"
default 1
depends on OPTEE
help
This sets the number of private shared memory pages to be
used by OP-TEE TEE driver.

config OPTEE_BENCHMARK
bool "OP-TEE Benchmark (EXPERIMENTAL)"
depends on OPTEE
help
This enables benchmarking feature in the OP-TEE Trusted
Execution Environment (TEE) driver.
2 changes: 2 additions & 0 deletions drivers/tee/optee/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ optee-objs += core.o
optee-objs += call.o
optee-objs += rpc.o
optee-objs += supp.o
optee-objs += shm_pool.o
optee-objs += bench.o
157 changes: 157 additions & 0 deletions drivers/tee/optee/bench.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* Copyright (c) 2017, 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/smp.h>
#include "optee_bench.h"

/*
* Specific defines for ARM performance timers
*/
/* aarch32 */
#define OPTEE_BENCH_DEF_OPTS (1 | 16)
#define OPTEE_BENCH_DEF_OVER 0x8000000f
/* enable 64 divider for CCNT */
#define OPTEE_BENCH_DIVIDER_OPTS (OPTEE_BENCH_DEF_OPTS | 8)

/* aarch64 */
#define OPTEE_BENCH_ARMV8_PMCR_MASK 0x3f
#define OPTEE_BENCH_ARMV8_PMCR_E (1 << 0) /* Enable all counters */
#define OPTEE_BENCH_ARMV8_PMCR_P (1 << 1) /* Reset all counters */
#define OPTEE_BENCH_ARMV8_PMCR_C (1 << 2) /* Cycle counter reset */
#define OPTEE_BENCH_ARMV8_PMCR_D (1 << 3) /* 64 divider */

#define OPTEE_BENCH_ARMV8_PMUSERENR_EL0 (1 << 0) /* EL0 access enable */
#define OPTEE_BENCH_ARMV8_PMUSERENR_CR (1 << 2) /* CCNT read enable */

struct optee_ts_global *optee_bench_ts_global;
struct rw_semaphore optee_bench_ts_rwsem;

#ifdef CONFIG_OPTEE_BENCHMARK
static inline u32 armv8pmu_pmcr_read(void)
{
u32 val = 0;

asm volatile("mrs %0, pmcr_el0" : "=r"(val));

return (u32)val;
}

static inline void armv8pmu_pmcr_write(u32 val)
{
val &= OPTEE_BENCH_ARMV8_PMCR_MASK;
asm volatile("msr pmcr_el0, %0" :: "r"((u64)val));
}

static inline u64 read_ccounter(void)
{
u64 ccounter;

#ifdef __aarch64__
asm volatile("mrs %0, PMCCNTR_EL0" : "=r"(ccounter));
#else
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(ccounter));
#endif

return ccounter * OPTEE_BENCH_DIVIDER;
}

static void optee_pmu_setup(void *data)
{
#ifdef __aarch64__
/* Enable EL0 access to PMU counters. */
asm volatile("msr pmuserenr_el0, %0" :: "r"((u64)
OPTEE_BENCH_ARMV8_PMUSERENR_EL0 |
OPTEE_BENCH_ARMV8_PMUSERENR_CR));
/* Enable PMU counters */
armv8pmu_pmcr_write(OPTEE_BENCH_ARMV8_PMCR_P |
OPTEE_BENCH_ARMV8_PMCR_C |
OPTEE_BENCH_ARMV8_PMCR_D);
asm volatile("msr pmcntenset_el0, %0" :: "r"((u64)(1 << 31)));
armv8pmu_pmcr_write(armv8pmu_pmcr_read() |
OPTEE_BENCH_ARMV8_PMCR_E);
#else
/* Enable EL0 access to PMU counters */
asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(1));
/* Enable all PMU counters */
asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"
(OPTEE_BENCH_DIVIDER_OPTS));
/* Disable counter overflow interrupts */
asm volatile("mcr p15, 0, %0, c9, c12, 1" :: "r"(OPTEE_BENCH_DEF_OVER));
#endif
}

static void optee_pmu_disable(void *data)
{
#ifdef __aarch64__
/* Disable EL0 access */
asm volatile("msr pmuserenr_el0, %0" :: "r"((u64)0));
/* Disable PMU counters */
armv8pmu_pmcr_write(armv8pmu_pmcr_read() | ~OPTEE_BENCH_ARMV8_PMCR_E);
#else
/* Disable all PMU counters */
asm volatile("mcr p15, 0, %0, c9, c12, 0" :: "r"(0));
/* Enable counter overflow interrupts */
asm volatile("mcr p15, 0, %0, c9, c12, 2" :: "r"(OPTEE_BENCH_DEF_OVER));
/* Disable EL0 access to PMU counters. */
asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(0));
#endif
}

void optee_bm_enable(void)
{
on_each_cpu(optee_pmu_setup, NULL, 1);
}

void optee_bm_disable(void)
{
on_each_cpu(optee_pmu_disable, NULL, 1);
}

void optee_bm_timestamp(void)
{
struct optee_ts_cpu_buf *cpu_buf;
struct optee_time_st ts_data;
uint64_t ts_i;
void *ret_addr;
int cur_cpu = 0;
int ret;

down_read(&optee_bench_ts_rwsem);

if (!optee_bench_ts_global) {
up_read(&optee_bench_ts_rwsem);
return;
}

cur_cpu = get_cpu();

if (cur_cpu >= optee_bench_ts_global->cores) {
put_cpu();
up_read(&optee_bench_ts_rwsem);
return;
}

ret_addr = __builtin_return_address(0);

cpu_buf = &optee_bench_ts_global->cpu_buf[cur_cpu];
ts_i = __sync_fetch_and_add(&cpu_buf->head, 1);
ts_data.cnt = read_ccounter();
ts_data.addr = (uintptr_t)ret_addr;
ts_data.src = OPTEE_BENCH_KMOD;
cpu_buf->stamps[ts_i & OPTEE_BENCH_MAX_MASK] = ts_data;

up_read(&optee_bench_ts_rwsem);

put_cpu();
}
#endif /* CONFIG_OPTEE_BENCHMARK */
Loading