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

Add upstream OP-TEE patches #56

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
223f3ad
tee: add tee_param_is_memref() for driver use
jenswi-linaro Dec 23, 2016
21ff86d
tee: add TEE_IOCTL_PARAM_ATTR_META
jenswi-linaro Dec 23, 2016
5684aa9
optee: support asynchronous supplicant requests
jenswi-linaro Dec 23, 2016
3c03a9f
tee: flexible shared memory pool creation
jenswi-linaro Nov 29, 2017
4dcb5ae
tee: add register user memory
jenswi-linaro Nov 29, 2017
bc210c4
tee: optee: Update protocol definitions
lorc Nov 29, 2017
8146ea9
tee: optee: add page list manipulation functions
lorc Nov 29, 2017
71b92e3
tee: optee: add shared buffer registration functions
lorc Nov 29, 2017
e447773
tee: optee: add registered shared parameters handling
lorc Nov 29, 2017
f460ff8
tee: optee: add registered buffers handling into RPC calls
lorc Nov 29, 2017
e387297
tee: optee: store OP-TEE capabilities in private data
lorc Nov 29, 2017
fe854e5
tee: optee: add optee-specific shared pool implementation
lorc Nov 29, 2017
d66f0f4
tee: optee: enable dynamic SHM support
lorc Nov 29, 2017
f2b44c4
tee: use reference counting for tee_context
lorc Nov 29, 2017
c25f313
tee: shm: inline tee_shm_get_id()
lorc Nov 29, 2017
5d4d6a7
tee: optee: fix header dependencies
arndb Dec 21, 2017
62646f2
tee: add start argument to shm_register callback
jenswi-linaro Dec 28, 2017
5a5146d
tee: optee: check type of registered shared memory
jenswi-linaro Dec 28, 2017
aa174da
tee: shm: make function __tee_shm_alloc static
Dec 22, 2017
0d73d48
tee: shm: don't put_page on null shm->pages
Dec 22, 2017
f68b673
tee: shm: Potential NULL dereference calling tee_shm_register()
Jan 6, 2018
6c2b003
tee: correct max value for id allocation
MrVan Jan 15, 2018
1741e1e
tee: optee: GET_OS_REVISION: document a2 as a build identifier
jforissier Nov 24, 2017
44ea6b8
tee: optee: report OP-TEE revision information
jforissier Nov 24, 2017
08c3281
tee: replace getnstimeofday64() with ktime_get_real_ts64()
arndb Jun 18, 2018
646ac9a
tee: optee: making OPTEE_SHM_NUM_PRIV_PAGES configurable via Kconfig
sahilnxp Jun 8, 2018
d52afc5
tee: add kernel internal client interface
jenswi-linaro Nov 19, 2015
9961318
tee: new ioctl to a register tee_shm from a dmabuf file descriptor
etienne-lms Oct 27, 2016
ffb1c43
OP-TEE Benchmark **not for mainline**
Oct 25, 2016
f7bb55d
tee: optee: optee_bench.h: remove useless include **not for mainline**
jforissier May 31, 2017
54889fd
tee: optee: log message if dynamic shm is enabled
Apr 11, 2018
697f03e
tee: fix unbalanced context refcount in register shm from fd
etienne-lms Apr 16, 2018
b45e06e
tee: support of allocating DMA shared buffers **not for mainline**
Feb 5, 2018
9f23ee3
tee: support of allocating DMA shared buffers **not for mainline**
Jun 19, 2018
cbc7443
tee: optee: take DT status property into account
Aug 1, 2018
6ec3fb7
optee: allow to work without static shared memory
lorc Jun 15, 2018
8baf857
tee: shm: add accessors for buffer size and page offset
lorc Nov 29, 2017
5c1da24
tee: shm: add page accessor functions
lorc Nov 29, 2017
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
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