Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | |
2 | #include <linux/module.h> | |
3 | #include <linux/types.h> | |
4 | #include <linux/kthread.h> | |
5 | #include <linux/freezer.h> | |
6 | ||
7 | #include "trustzone/tz_cross/trustzone.h" | |
8 | #include "trustzone/tz_cross/ta_icnt.h" | |
9 | #include "trustzone/kree/system.h" | |
10 | #include "kree_int.h" | |
11 | #include "tz_counter.h" | |
12 | ||
13 | #ifdef ENABLE_INC_ONLY_COUNTER | |
14 | uint32_t TEECK_Icnt_Counter(KREE_SESSION_HANDLE session, uint32_t* a, uint32_t* b) | |
15 | { | |
16 | MTEEC_PARAM param[4]; | |
17 | uint32_t paramTypes; | |
18 | TZ_RESULT ret; | |
19 | ||
20 | paramTypes = TZ_ParamTypes2(TZPT_VALUE_OUTPUT, TZPT_VALUE_OUTPUT); | |
21 | ||
22 | ret = KREE_TeeServiceCall(session, TZCMD_ICNT_COUNT, | |
23 | paramTypes, param); | |
24 | if (ret != TZ_RESULT_SUCCESS) | |
25 | { | |
26 | printk("ServiceCall error %d\n", ret); | |
27 | } | |
28 | *a = param[0].value.a; | |
29 | *b = param[1].value.a; | |
30 | ||
31 | return ret; | |
32 | } | |
33 | ||
34 | uint32_t TEECK_Icnt_Rate(KREE_SESSION_HANDLE session, uint32_t* a) | |
35 | { | |
36 | MTEEC_PARAM param[4]; | |
37 | uint32_t paramTypes; | |
38 | TZ_RESULT ret; | |
39 | ||
40 | paramTypes = TZ_ParamTypes1(TZPT_VALUE_OUTPUT); | |
41 | ||
42 | ret = KREE_TeeServiceCall(session, TZCMD_ICNT_RATE, | |
43 | paramTypes, param); | |
44 | if (ret != TZ_RESULT_SUCCESS) | |
45 | { | |
46 | printk("ServiceCall error %d\n", ret); | |
47 | } | |
48 | *a = param[0].value.a; | |
49 | ||
50 | return ret; | |
51 | } | |
52 | #define THREAD_COUNT_FREQ 10 | |
53 | int update_counter_thread(void *data) | |
54 | { | |
55 | TZ_RESULT ret; | |
56 | KREE_SESSION_HANDLE icnt_session; | |
57 | uint32_t result; | |
58 | uint32_t a, b, rate; | |
59 | uint32_t nsec = THREAD_COUNT_FREQ; | |
60 | ||
61 | ret = KREE_CreateSession(TZ_TA_ICNT_UUID, &icnt_session); | |
62 | if (ret != TZ_RESULT_SUCCESS) | |
63 | { | |
64 | printk("CreateSession error %d\n", ret); | |
65 | return 1; | |
66 | } | |
67 | ||
68 | result = TEECK_Icnt_Rate(icnt_session, &rate); | |
69 | if (result == TZ_RESULT_SUCCESS) | |
70 | { | |
71 | //printk("(yjdbg) rate: %d\n", rate); | |
72 | nsec = (0xffffffff / rate); | |
73 | nsec -= 600; | |
74 | //printk("(yjdbg) rate: %d\n", nsec); | |
75 | } | |
76 | ||
77 | set_freezable(); | |
78 | ||
79 | for (;;) { | |
80 | if (kthread_should_stop()) | |
81 | break; | |
82 | ||
83 | if (try_to_freeze()) | |
84 | continue; | |
85 | ||
86 | result = TEECK_Icnt_Counter(icnt_session, &a, &b); | |
87 | if (result == TZ_RESULT_SUCCESS) | |
88 | { | |
89 | //printk("(yjdbg) tz_test TZCMD_ICNT_COUNT: 0x%x, 0x%x\n", a, b); | |
90 | } | |
91 | ||
92 | schedule_timeout_interruptible(HZ * nsec); | |
93 | } | |
94 | ||
95 | ret = KREE_CloseSession(icnt_session); | |
96 | if (ret != TZ_RESULT_SUCCESS) | |
97 | { | |
98 | printk("CloseSession error %d\n", ret); | |
99 | return 1; | |
100 | } | |
101 | ||
102 | return 0; | |
103 | } | |
104 | #endif | |
105 |