1 /*
2  * Copyright (c) 2017, Linaro Limited
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef TEE_BENCH_H
29 #define TEE_BENCH_H
30 
31 #include <inttypes.h>
32 
33 #define PTA_BENCHMARK_UUID \
34 		{ 0x0b9a63b0, 0xb4c6, 0x4c85, \
35 			{ 0xa2, 0x84, 0xa2, 0x28, 0xef, 0x54, 0x7b, 0x4e } }
36 
37 #define BENCHMARK_CMD(id)	(0xFA190000 | ((id) & 0xFFFF))
38 #define BENCHMARK_CMD_REGISTER_MEMREF	BENCHMARK_CMD(1)
39 #define BENCHMARK_CMD_GET_MEMREF		BENCHMARK_CMD(2)
40 #define BENCHMARK_CMD_UNREGISTER		BENCHMARK_CMD(3)
41 
42 /*
43  * Cycle count divider is enabled (in PMCR),
44  * CCNT value is incremented every 64th clock cycle
45  */
46 #define TEE_BENCH_DIVIDER		64
47 /* max amount of timestamps per buffer */
48 #define TEE_BENCH_MAX_STAMPS	32
49 #define TEE_BENCH_MAX_MASK		(TEE_BENCH_MAX_STAMPS - 1)
50 
51 /* OP-TEE susbsystems ids */
52 #define TEE_BENCH_CLIENT	0x10000000
53 #define TEE_BENCH_KMOD		0x20000000
54 #define TEE_BENCH_CORE		0x30000000
55 #define TEE_BENCH_UTEE		0x40000000
56 #define TEE_BENCH_DUMB_TA	0xF0000001
57 
58 /* storing timestamp */
59 struct tee_time_st {
60 	uint64_t cnt;	/* stores value from CNTPCT register */
61 	uint64_t addr;	/* stores value from program counter register */
62 	uint64_t src;	/* OP-TEE subsystem id */
63 };
64 
65 /* per-cpu circular buffer for timestamps */
66 struct tee_ts_cpu_buf {
67 	uint64_t head;
68 	uint64_t tail;
69 	struct tee_time_st stamps[TEE_BENCH_MAX_STAMPS];
70 };
71 
72 /* memory layout for shared memory, where timestamps will be stored */
73 struct tee_ts_global {
74 	uint64_t cores;
75 	struct tee_ts_cpu_buf cpu_buf[];
76 };
77 #endif /* TEE_BENCH_H */
78