• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stefanberger / libtpms / #2063

11 Feb 2026 02:58PM UTC coverage: 77.18% (-0.02%) from 77.195%
#2063

push

travis-ci

web-flow
Merge c175b6f1e into c2a8109f8

1174 of 1370 new or added lines in 95 files covered. (85.69%)

2190 existing lines in 89 files now uncovered.

36347 of 47094 relevant lines covered (77.18%)

125164.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.29
/src/tpm2/TPMCmd/Platform/src/PlatformACT.c
1
// SPDX-License-Identifier: BSD-2-Clause
2

3
//** Includes
4
#include "Platform.h"
5

6
//** Functions
7

8
#if ACT_SUPPORT
9

10
//*** ActSignal()
11
// Function called when there is an ACT event to signal or unsignal
12
#ifndef __ACT_DISABLED        // libtpms added
13
static void ActSignal(P_ACT_DATA actData, int on)
14
{
15
    if(actData == NULL)
16
        return;
17
    // If this is to turn a signal on, don't do anything if it is already on. If this
18
    // is to turn the signal off, do it anyway because this might be for
19
    // initialization.
20
    if(on && (actData->signaled == TRUE))
21
        return;
22
    actData->signaled = (uint8_t)on;
23

24
    // If there is an action, then replace the "Do something" with the correct action.
25
    // It should test 'on' to see if it is turning the signal on or off.
26
    switch(actData->number)
27
    {
28
#  if RH_ACT_0
29
        case 0:  // Do something
30
            return;
31
#  endif
32
#  if RH_ACT_1
33
        case 1:  // Do something
34
            return;
35
#  endif
36
#  if RH_ACT_2
37
        case 2:  // Do something
38
            return;
39
#  endif
40
#  if RH_ACT_3
41
        case 3:  // Do something
42
            return;
43
#  endif
44
#  if RH_ACT_4
45
        case 4:  // Do something
46
            return;
47
#  endif
48
#  if RH_ACT_5
49
        case 5:  // Do something
50
            return;
51
#  endif
52
#  if RH_ACT_6
53
        case 6:  // Do something
54
            return;
55
#  endif
56
#  if RH_ACT_7
57
        case 7:  // Do something
58
            return;
59
#  endif
60
#  if RH_ACT_8
61
        case 8:  // Do something
62
            return;
63
#  endif
64
#  if RH_ACT_9
65
        case 9:  // Do something
66
            return;
67
#  endif
68
#  if RH_ACT_A
69
        case 0xA:  // Do something
70
            return;
71
#  endif
72
#  if RH_ACT_B
73
        case 0xB:
74
            // Do something
75
            return;
76
#  endif
77
#  if RH_ACT_C
78
        case 0xC:  // Do something
79
            return;
80
#  endif
81
#  if RH_ACT_D
82
        case 0xD:  // Do something
83
            return;
84
#  endif
85
#  if RH_ACT_E
86
        case 0xE:  // Do something
87
            return;
88
#  endif
89
#  if RH_ACT_F
90
        case 0xF:  // Do something
91
            return;
92
#  endif
93
        default:
94
            return;
95
    }
96
}
97
#endif                // libtpms added
98

99
//*** ActGetDataPointer()
100
static P_ACT_DATA ActGetDataPointer(uint32_t act)
101
{
102

103
#  define RETURN_ACT_POINTER(N) \
104
      if(0x##N == act)          \
105
          return &ACT_##N;
106

107
    FOR_EACH_ACT(RETURN_ACT_POINTER)
108

109
    return (P_ACT_DATA)NULL;
110
}
111

112
//*** _plat__ACT_GetImplemented()
113
// This function tests to see if an ACT is implemented. It is a belt and suspenders
114
// function because the TPM should not be calling to manipulate an ACT that is not
115
// implemented. However, this could help the simulator code which doesn't necessarily
116
// know if an ACT is implemented or not.
UNCOV
117
LIB_EXPORT int _plat__ACT_GetImplemented(uint32_t act)
×
118
{
UNCOV
119
    return (ActGetDataPointer(act) != NULL);
×
120
}
121

122
//*** _plat__ACT_GetRemaining()
123
// This function returns the remaining time. If an update is pending, 'newValue' is
124
// returned. Otherwise, the current counter value is returned. Note that since the
125
// timers keep running, the returned value can get stale immediately. The actual count
126
// value will be no greater than the returned value.
UNCOV
127
LIB_EXPORT uint32_t _plat__ACT_GetRemaining(uint32_t act  //IN: the ACT selector
×
128
)
129
{
UNCOV
130
    P_ACT_DATA actData = ActGetDataPointer(act);
×
UNCOV
131
    uint32_t   remain;
×
132
    //
UNCOV
133
    if(actData == NULL)
×
UNCOV
134
        return 0;
×
135
    remain = actData->remaining;
136
    if(actData->pending)
137
        remain = actData->newValue;
138
    return remain;
139
}
140

141
//*** _plat__ACT_GetSignaled()
UNCOV
142
LIB_EXPORT int _plat__ACT_GetSignaled(uint32_t act  //IN: number of ACT to check
×
143
)
144
{
UNCOV
145
    P_ACT_DATA actData = ActGetDataPointer(act);
×
146
    //
UNCOV
147
    if(actData == NULL)
×
UNCOV
148
        return 0;
×
149
    return (int)actData->signaled;
150
}
151

152
#ifndef __ACT_DISABLED        // libtpms added
153
//*** _plat__ACT_SetSignaled()
154
LIB_EXPORT void _plat__ACT_SetSignaled(uint32_t act, int on)
155
{
156
    ActSignal(ActGetDataPointer(act), on);
157
}
158

159
//*** _plat__ACT_GetPending()
160
LIB_EXPORT int _plat__ACT_GetPending(uint32_t act  //IN: number of ACT to check
161
)
162
{
163
    P_ACT_DATA actData = ActGetDataPointer(act);
164
    //
165
    if(actData == NULL)
166
        return 0;
167
    return (int)actData->pending;
168
}
169

170
//*** _plat__ACT_UpdateCounter()
171
// This function is used to write the newValue for the counter. If an update is
172
// pending, then no update occurs and the function returns FALSE. If 'setSignaled'
173
// is TRUE, then the ACT signaled state is SET and if 'newValue' is 0, nothing
174
// is posted.
175
LIB_EXPORT int _plat__ACT_UpdateCounter(uint32_t act,      // IN: ACT to update
176
                                        uint32_t newValue  // IN: the value to post
177
)
178
{
179
    P_ACT_DATA actData = ActGetDataPointer(act);
180
    //
181
    if(actData == NULL)
182
        // actData doesn't exist but pretend update is pending rather than indicate
183
        // that a retry is necessary.
184
        return TRUE;
185
    // if an update is pending then return FALSE so that there will be a retry
186
    if(actData->pending != 0)
187
        return FALSE;
188
    actData->newValue = newValue;
189
    actData->pending  = TRUE;
190

191
    return TRUE;
192
}
193
#endif                // libtpms added
194

195
//***_plat__ACT_EnableTicks()
196
// This enables and disables the processing of the once-per-second ticks. This should
197
// be turned off ('enable' = FALSE) by _TPM_Init and turned on ('enable' = TRUE) by
198
// TPM2_Startup() after all the initializations have completed.
199
LIB_EXPORT void _plat__ACT_EnableTicks(int enable)
20,956✔
200
{
201
    actTicksAllowed = enable;
20,956✔
202
}
20,956✔
203

204
#ifndef __ACT_DISABLED        // libtpms added
205
//*** ActDecrement()
206
// If 'newValue' is non-zero it is copied to 'remaining' and then 'newValue' is
207
// set to zero. Then 'remaining' is decremented by one if it is not already zero. If
208
// the value is decremented to zero, then the associated event is signaled. If setting
209
// 'remaining' causes it to be greater than 1, then the signal associated with the ACT
210
// is turned off.
211
static void ActDecrement(P_ACT_DATA actData)
212
{
213
    // Check to see if there is an update pending
214
    if(actData->pending)
215
    {
216
        // If this update will cause the count to go from non-zero to zero, set
217
        // the newValue to 1 so that it will timeout when decremented below.
218
        if((actData->newValue == 0) && (actData->remaining != 0))
219
            actData->newValue = 1;
220
        actData->remaining = actData->newValue;
221

222
        // Update processed
223
        actData->pending = 0;
224
    }
225
    // no update so countdown if the count is non-zero but not max
226
    if((actData->remaining != 0) && (actData->remaining != UINT32_MAX))
227
    {
228
        // If this countdown causes the count to go to zero, then turn the signal for
229
        // the ACT on.
230
        if((actData->remaining -= 1) == 0)
231
            ActSignal(actData, TRUE);
232
    }
233
    // If the current value of the counter is non-zero, then the signal should be
234
    // off.
235
    if(actData->signaled && (actData->remaining > 0))
236
        ActSignal(actData, FALSE);
237
}
238

239
//*** _plat__ACT_Tick()
240
// This processes the once-per-second clock tick from the hardware. This is set up
241
// for the simulator to use the control interface to send ticks to the TPM. These
242
// ticks do not have to be on a per second basis. They can be as slow or as fast as
243
// desired so that the simulation can be tested.
244
LIB_EXPORT void _plat__ACT_Tick(void)
245
{
246
    // Ticks processing is turned off at certain times just to make sure that nothing
247
    // strange is happening before pointers and things are
248
    if(actTicksAllowed)
249
    {
250
        // Handle the update for each counter.
251
#  define DECREMENT_COUNT(N) ActDecrement(&ACT_##N);
252

253
        FOR_EACH_ACT(DECREMENT_COUNT)
254
    }
255
}
256

257
//*** ActZero()
258
// This function initializes a single ACT
259
static void ActZero(uint32_t act, P_ACT_DATA actData)
260
{
261
    actData->remaining = 0;
262
    actData->newValue  = 0;
263
    actData->pending   = 0;
264
    actData->number    = (uint8_t)act;
265
    ActSignal(actData, FALSE);
266
}
267
#endif                        // libtpms added
268

269
//***_plat__ACT_Initialize()
270
// This function initializes the ACT hardware and data structures
271
LIB_EXPORT int _plat__ACT_Initialize(void)
4,251✔
272
{
273
    actTicksAllowed = 0;
4,251✔
274
#  define ZERO_ACT(N) ActZero(0x##N, &ACT_##N);
275
    FOR_EACH_ACT(ZERO_ACT)
276

277
    return TRUE;
4,251✔
278
}
279

280
#endif  // ACT_SUPPORT
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc