1 /*
2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef _CC_PAL_PERF_H_
8 #define _CC_PAL_PERF_H_
9
10 #include <string.h>
11
12 #ifdef LIB_PERF
13 #include "cc_pal_perf_plat.h"
14 #endif
15
16 typedef enum
17 {
18 PERF_TEST_TYPE_AES_INIT,
19 PERF_TEST_TYPE_AES_SET_KEY,
20 PERF_TEST_TYPE_AES_BLOCK,
21 PERF_TEST_TYPE_AES_FIN,
22 PERF_TEST_TYPE_CC_AES_INIT,
23 PERF_TEST_TYPE_CC_AES_BLOCK,
24 PERF_TEST_TYPE_CC_AES_FIN,
25 PERF_TEST_TYPE_HW_CMPLT ,
26 PERF_TEST_TYPE_PAL_MAP,
27 PERF_TEST_TYPE_PAL_UNMAP,
28 PERF_TEST_TYPE_MLLI_BUILD,
29 PERF_TEST_TYPE_SYM_DRV_INIT,
30 PERF_TEST_TYPE_SYM_DRV_PROC,
31 PERF_TEST_TYPE_SYM_DRV_FIN,
32 PERF_TEST_TYPE_CC_HASH_INIT,
33 PERF_TEST_TYPE_CC_HASH_UPDATE,
34 PERF_TEST_TYPE_CC_HASH_FIN,
35 PERF_TEST_TYPE_CC_HMAC_INIT,
36 PERF_TEST_TYPE_CC_HMAC_UPDATE,
37 PERF_TEST_TYPE_CC_HMAC_FIN,
38 PERF_TEST_TYPE_CMPLT_SLEEP,
39 PERF_TEST_TYPE_CC_ECDSA_SIGN_INIT,
40 PERF_TEST_TYPE_CC_ECDSA_SIGN_UPDATE,
41 PERF_TEST_TYPE_CC_ECDSA_SIGN_FINISH,
42 PERF_TEST_TYPE_CC_ECDSA_VERIFY_INIT,
43 PERF_TEST_TYPE_CC_ECDSA_VERIFY_UPDATE,
44 PERF_TEST_TYPE_CC_ECDSA_VERIFY_FINISH,
45 PERF_TEST_TYPE_PKA_EC_WRST_SCALAR_MULT,
46 PERF_TEST_TYPE_CALC_SIGNATURE,
47 PERF_TEST_TYPE_PKA_SCALAR_MULT_AFF,
48 PERF_TEST_TYPE_PKA_SCALAR_MULT_SCA,
49 PERF_TEST_TYPE_PKA_ECDSA_VERIFY,
50 PERF_TEST_TYPE_PKA_ModExp = 0x30,
51 PERF_TEST_TYPE_TEST_BASE = 0x100,
52 PERF_TEST_TYPE_MAX,
53 PERF_TEST_TYPE_RESERVE32 = 0x7FFFFFFF
54 } CCPalPerfType_t;
55
56 #ifdef LIB_PERF
57
CC_PalPerfTypeStr(CCPalPerfType_t type,char * pStr,uint32_t buffLen)58 static char* CC_PalPerfTypeStr(CCPalPerfType_t type, char* pStr, uint32_t buffLen)
59 {
60 #define CCPalPerfTypeStr_str(a) case a: strncpy(pStr, #a + strlen("PERF_TEST_TYPE_"), buffLen); break;
61
62 switch (type)
63 {
64 CCPalPerfTypeStr_str(PERF_TEST_TYPE_AES_INIT);
65 CCPalPerfTypeStr_str(PERF_TEST_TYPE_AES_SET_KEY);
66 CCPalPerfTypeStr_str(PERF_TEST_TYPE_AES_BLOCK);
67 CCPalPerfTypeStr_str(PERF_TEST_TYPE_AES_FIN);
68 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_AES_INIT);
69 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_AES_BLOCK);
70 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_AES_FIN);
71 CCPalPerfTypeStr_str(PERF_TEST_TYPE_HW_CMPLT );
72 CCPalPerfTypeStr_str(PERF_TEST_TYPE_PAL_MAP);
73 CCPalPerfTypeStr_str(PERF_TEST_TYPE_PAL_UNMAP);
74 CCPalPerfTypeStr_str(PERF_TEST_TYPE_MLLI_BUILD);
75 CCPalPerfTypeStr_str(PERF_TEST_TYPE_SYM_DRV_INIT);
76 CCPalPerfTypeStr_str(PERF_TEST_TYPE_SYM_DRV_PROC);
77 CCPalPerfTypeStr_str(PERF_TEST_TYPE_SYM_DRV_FIN);
78 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_HASH_INIT);
79 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_HASH_UPDATE);
80 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_HASH_FIN);
81 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_HMAC_INIT);
82 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_HMAC_UPDATE);
83 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_HMAC_FIN);
84 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CMPLT_SLEEP);
85 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_ECDSA_SIGN_INIT);
86 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_ECDSA_SIGN_UPDATE);
87 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_ECDSA_SIGN_FINISH);
88 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_ECDSA_VERIFY_INIT);
89 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_ECDSA_VERIFY_UPDATE);
90 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CC_ECDSA_VERIFY_FINISH);
91 CCPalPerfTypeStr_str(PERF_TEST_TYPE_PKA_EC_WRST_SCALAR_MULT);
92 CCPalPerfTypeStr_str(PERF_TEST_TYPE_CALC_SIGNATURE);
93 CCPalPerfTypeStr_str(PERF_TEST_TYPE_PKA_SCALAR_MULT_AFF);
94 CCPalPerfTypeStr_str(PERF_TEST_TYPE_PKA_SCALAR_MULT_SCA);
95 CCPalPerfTypeStr_str(PERF_TEST_TYPE_PKA_ECDSA_VERIFY);
96 CCPalPerfTypeStr_str(PERF_TEST_TYPE_PKA_ModExp);
97 CCPalPerfTypeStr_str(PERF_TEST_TYPE_TEST_BASE);
98 default: strncpy(pStr, "PERF_TEST_TYPE_UNKNOWN", buffLen);
99 }
100
101 return pStr;
102 }
103
104 #define CC_PAL_PERF_INIT CC_PalPerfInit
105 #define CC_PAL_PERF_OPEN_NEW_ENTRY(num, type) num = CC_PalPerfOpenNewEntry(type)
106 #define CC_PAL_PERF_CLOSE_ENTRY(num, type) CC_PalPerfCloseEntry(num, type)
107 #define CC_PAL_PERF_DUMP CC_PalPerfDump
108 #define CC_PAL_PERF_FIN CC_PalPerfFin
109
110 /**
111 * @brief initialize performance test mechanism
112 *
113 * @param[in]
114 * *
115 * @return None
116 */
117 void CC_PalPerfInit(void);
118
119
120 /**
121 * @brief opens new entry in perf buffer to record new entry
122 *
123 * @param[in] entryType - entry type (defined in cc_pal_perf.h) to be recorded in buffer
124 *
125 * @return A non-zero value in case of failure.
126 */
127 CCPalPerfData_t CC_PalPerfOpenNewEntry(CCPalPerfType_t entryType);
128
129
130 /**
131 * @brief closes entry in perf buffer previously opened by CC_PalPerfOpenNewEntry
132 *
133 * @param[in] idx - index of the entry to be closed, the return value of CC_PalPerfOpenNewEntry
134 * @param[in] entryType - entry type (defined in cc_pal_perf.h) to be recorded in buffer
135 *
136 * @return A non-zero value in case of failure.
137 */
138 void CC_PalPerfCloseEntry(CCPalPerfData_t idx, CCPalPerfType_t entryType);
139
140
141 /**
142 * @brief dumps the performance buffer
143 *
144 * @param[in] None
145 *
146 * @return None
147 */
148 void CC_PalPerfDump(void);
149
150
151 /**
152 * @brief terminates resources used for performance tests
153 *
154 * @param[in]
155 * *
156 * @return None
157 */
158 void CC_PalPerfFin(void);
159
160 #else //LIB_PERF
161 #define CC_PAL_PERF_INIT()
162 #define CC_PAL_PERF_OPEN_NEW_ENTRY(num, type) (num=num)
163 #define CC_PAL_PERF_CLOSE_ENTRY(num, type)
164 #define CC_PAL_PERF_DUMP()
165 #define CC_PAL_PERF_FIN()
166
167
168 typedef unsigned int CCPalPerfData_t;
169
170 #endif //LIB_PERF
171
172
173 #endif /*_CC_PAL_PERF_H__*/
174
175