2 #include <linux/module.h>
3 #include <linux/types.h>
4 #include <linux/kthread.h>
5 #include <linux/freezer.h>
7 #include "trustzone/tz_cross/trustzone.h"
8 #include "trustzone/tz_cross/ta_icnt.h"
9 #include "trustzone/kree/system.h"
11 #include "tz_counter.h"
13 #ifdef ENABLE_INC_ONLY_COUNTER
14 uint32_t TEECK_Icnt_Counter(KREE_SESSION_HANDLE session
, uint32_t* a
, uint32_t* b
)
20 paramTypes
= TZ_ParamTypes2(TZPT_VALUE_OUTPUT
, TZPT_VALUE_OUTPUT
);
22 ret
= KREE_TeeServiceCall(session
, TZCMD_ICNT_COUNT
,
24 if (ret
!= TZ_RESULT_SUCCESS
)
26 printk("ServiceCall error %d\n", ret
);
28 *a
= param
[0].value
.a
;
29 *b
= param
[1].value
.a
;
34 uint32_t TEECK_Icnt_Rate(KREE_SESSION_HANDLE session
, uint32_t* a
)
40 paramTypes
= TZ_ParamTypes1(TZPT_VALUE_OUTPUT
);
42 ret
= KREE_TeeServiceCall(session
, TZCMD_ICNT_RATE
,
44 if (ret
!= TZ_RESULT_SUCCESS
)
46 printk("ServiceCall error %d\n", ret
);
48 *a
= param
[0].value
.a
;
52 #define THREAD_COUNT_FREQ 10
53 int update_counter_thread(void *data
)
56 KREE_SESSION_HANDLE icnt_session
;
59 uint32_t nsec
= THREAD_COUNT_FREQ
;
61 ret
= KREE_CreateSession(TZ_TA_ICNT_UUID
, &icnt_session
);
62 if (ret
!= TZ_RESULT_SUCCESS
)
64 printk("CreateSession error %d\n", ret
);
68 result
= TEECK_Icnt_Rate(icnt_session
, &rate
);
69 if (result
== TZ_RESULT_SUCCESS
)
71 //printk("(yjdbg) rate: %d\n", rate);
72 nsec
= (0xffffffff / rate
);
74 //printk("(yjdbg) rate: %d\n", nsec);
80 if (kthread_should_stop())
86 result
= TEECK_Icnt_Counter(icnt_session
, &a
, &b
);
87 if (result
== TZ_RESULT_SUCCESS
)
89 //printk("(yjdbg) tz_test TZCMD_ICNT_COUNT: 0x%x, 0x%x\n", a, b);
92 schedule_timeout_interruptible(HZ
* nsec
);
95 ret
= KREE_CloseSession(icnt_session
);
96 if (ret
!= TZ_RESULT_SUCCESS
)
98 printk("CloseSession error %d\n", ret
);