tests: Have TPM I2C read/write functions take QTestState as first parameter
Pass the QTestState as first parameter to the TPM I2C functions. Use global_qtest in existing test cases. Reviewed-by: Arun Menon <armenon@redhat.com> Link: https://lore.kernel.org/qemu-devel/20260429121743.1346635-3-stefanb@linux.ibm.com Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger committed
Apr 29, 2026 at 12:17 UTC
8c55f44b3c07d3f0a3fc918f43a309a3c0ee92d3
3 files changed
+110
-103
tests/qtest/tpm-tis-i2c-test.c
+89
-82
@@ -50,62 +50,64 @@ static void tpm_tis_i2c_test_basic(const void *data)
50
* All register accesses below must work without locality 0 being the
51
* active locality. Therefore, ensure access is released.
52
*/
53
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS,
53
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
54
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
55
- access = tpm_tis_i2c_readb(0, TPM_I2C_REG_ACCESS);
55
+ access = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_ACCESS);
56
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
57
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
58
59
/* read interrupt capability -- none are supported */
60
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_INT_CAPABILITY);
60
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_INT_CAPABILITY);
61
g_assert_cmpint(v, ==, 0);
62
63
/* try to enable all interrupts */
64
- tpm_tis_i2c_writel(0, TPM_I2C_REG_INT_ENABLE, 0xffffffff);
65
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_INT_ENABLE);
64
+ tpm_tis_i2c_writel(global_qtest, 0, TPM_I2C_REG_INT_ENABLE, 0xffffffff);
65
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_INT_ENABLE);
66
/* none could be enabled */
67
g_assert_cmpint(v, ==, 0);
68
69
/* enable csum */
70
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_CSUM_ENABLE, TPM_DATA_CSUM_ENABLED);
70
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE,
71
+ TPM_DATA_CSUM_ENABLED);
72
/* check csum enable register has bit 0 set */
72
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
73
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
74
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
75
/* reading it as 32bit register returns same result */
75
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
76
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
77
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
78
79
/* disable csum */
79
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_CSUM_ENABLE, 0);
80
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE, 0);
81
/* check csum enable register has bit 0 clear */
81
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
82
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
83
g_assert_cmpint(v, ==, 0);
84
85
/* write to unsupported register '1' */
85
- tpm_tis_i2c_writel(0, 1, 0x12345678);
86
- v = tpm_tis_i2c_readl(0, 1);
86
+ tpm_tis_i2c_writel(global_qtest, 0, 1, 0x12345678);
87
+ v = tpm_tis_i2c_readl(global_qtest, 0, 1);
88
g_assert_cmpint(v, ==, 0xffffffff);
89
90
/* request use of locality */
90
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
91
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
92
+ TPM_TIS_ACCESS_REQUEST_USE);
93
94
/* read byte from STS + 3 */
93
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_STS + 3);
95
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_STS + 3);
96
g_assert_cmpint(v, ==, 0);
97
98
/* check STS after writing to STS + 3 */
97
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
98
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_STS + 3, 0xf);
99
- v2 = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
99
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
100
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_STS + 3, 0xf);
101
+ v2 = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
102
g_assert_cmpint(v, ==, v2);
103
104
/* release access */
103
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS,
105
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
106
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
107
108
/* select locality 5 -- must not be possible */
107
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_LOC_SEL, 5);
108
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_LOC_SEL);
109
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_LOC_SEL, 5);
110
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_LOC_SEL);
111
g_assert_cmpint(v, ==, 0);
112
}
113
@@ -118,11 +120,12 @@ static void tpm_tis_i2c_test_check_localities(const void *data)
120
uint32_t rid;
121
122
for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES; locty++) {
121
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
123
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
124
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
125
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
126
125
- capability = tpm_tis_i2c_readl(locty, TPM_I2C_REG_INTF_CAPABILITY);
127
+ capability = tpm_tis_i2c_readl(global_qtest, locty,
128
+ TPM_I2C_REG_INTF_CAPABILITY);
129
i2c_cap = (TPM_I2C_CAP_INTERFACE_TYPE |
130
TPM_I2C_CAP_INTERFACE_VER |
131
TPM_I2C_CAP_TPM2_FAMILY |
@@ -131,15 +134,15 @@ static void tpm_tis_i2c_test_check_localities(const void *data)
134
TPM_I2C_CAP_DEV_ADDR_CHANGE);
135
g_assert_cmpint(capability, ==, i2c_cap);
136
134
- didvid = tpm_tis_i2c_readl(locty, TPM_I2C_REG_DID_VID);
137
+ didvid = tpm_tis_i2c_readl(global_qtest, locty, TPM_I2C_REG_DID_VID);
138
g_assert_cmpint(didvid, ==, (1 << 16) | PCI_VENDOR_ID_IBM);
139
137
- rid = tpm_tis_i2c_readl(locty, TPM_I2C_REG_RID);
140
+ rid = tpm_tis_i2c_readl(global_qtest, locty, TPM_I2C_REG_RID);
141
g_assert_cmpint(rid, !=, 0);
142
g_assert_cmpint(rid, !=, 0xffffffff);
143
144
/* locality selection must be at locty */
142
- l = tpm_tis_i2c_readb(locty, TPM_I2C_REG_LOC_SEL);
145
+ l = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_LOC_SEL);
146
g_assert_cmpint(l, ==, locty);
147
}
148
}
@@ -151,23 +154,23 @@ static void tpm_tis_i2c_test_check_access_reg(const void *data)
154
155
/* do not test locality 4 (hw only) */
156
for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
154
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
157
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
158
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
159
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
160
161
/* request use of locality */
159
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
162
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
163
TPM_TIS_ACCESS_REQUEST_USE);
164
162
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
165
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
166
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
167
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
168
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
169
170
/* release access */
168
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
171
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
172
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
170
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
173
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
174
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
175
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
176
}
@@ -186,14 +189,14 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
189
for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
190
pending_request_flag = 0;
191
189
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
192
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
193
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
194
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
195
196
/* request use of locality */
194
- tpm_tis_i2c_writeb(locty,
197
+ tpm_tis_i2c_writeb(global_qtest, locty,
198
TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
196
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
199
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
200
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
201
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
202
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -201,14 +204,14 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
204
/* lower localities cannot seize access */
205
for (l = 0; l < locty; l++) {
206
/* lower locality is not active */
204
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
207
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
208
DPRINTF_ACCESS;
209
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
210
pending_request_flag |
211
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
212
213
/* try to request use from 'l' */
211
- tpm_tis_i2c_writeb(l,
214
+ tpm_tis_i2c_writeb(global_qtest, l,
215
TPM_I2C_REG_ACCESS,
216
TPM_TIS_ACCESS_REQUEST_USE);
217
@@ -216,7 +219,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
219
* requesting use from 'l' was not possible;
220
* we must see REQUEST_USE and possibly PENDING_REQUEST
221
*/
219
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
222
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
223
DPRINTF_ACCESS;
224
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
225
TPM_TIS_ACCESS_REQUEST_USE |
@@ -227,17 +230,17 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
230
* locality 'locty' must be unchanged;
231
* we must see PENDING_REQUEST
232
*/
230
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
233
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
234
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
235
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
236
TPM_TIS_ACCESS_PENDING_REQUEST |
237
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
238
239
/* try to seize from 'l' */
237
- tpm_tis_i2c_writeb(l,
240
+ tpm_tis_i2c_writeb(global_qtest, l,
241
TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_SEIZE);
242
/* seize from 'l' was not possible */
240
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
243
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
244
DPRINTF_ACCESS;
245
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
246
TPM_TIS_ACCESS_REQUEST_USE |
@@ -245,7 +248,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
248
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
249
250
/* locality 'locty' must be unchanged */
248
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
251
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
252
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
253
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
254
TPM_TIS_ACCESS_PENDING_REQUEST |
@@ -264,14 +267,14 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
267
*/
268
for (l = locty + 1; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
269
/* try to 'request use' from 'l' */
267
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
270
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
271
TPM_TIS_ACCESS_REQUEST_USE);
272
273
/*
274
* requesting use from 'l' was not possible; we should see
275
* REQUEST_USE and may see PENDING_REQUEST
276
*/
274
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
277
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
278
DPRINTF_ACCESS;
279
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
280
TPM_TIS_ACCESS_REQUEST_USE |
@@ -282,7 +285,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
285
* locality 'l-1' must be unchanged; we should always
286
* see PENDING_REQUEST from 'l' requesting access
287
*/
285
- access = tpm_tis_i2c_readb(l - 1, TPM_I2C_REG_ACCESS);
288
+ access = tpm_tis_i2c_readb(global_qtest, l - 1, TPM_I2C_REG_ACCESS);
289
DPRINTF_ACCESS;
290
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
291
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
@@ -290,10 +293,11 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
293
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
294
295
/* try to seize from 'l' */
293
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_SEIZE);
296
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
297
+ TPM_TIS_ACCESS_SEIZE);
298
299
/* seize from 'l' was possible */
296
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
300
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
301
DPRINTF_ACCESS;
302
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
303
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
@@ -301,7 +305,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
305
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
306
307
/* l - 1 should show that it has BEEN_SEIZED */
304
- access = tpm_tis_i2c_readb(l - 1, TPM_I2C_REG_ACCESS);
308
+ access = tpm_tis_i2c_readb(global_qtest, l - 1, TPM_I2C_REG_ACCESS);
309
DPRINTF_ACCESS;
310
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
311
TPM_TIS_ACCESS_BEEN_SEIZED |
@@ -309,10 +313,10 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
313
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
314
315
/* clear the BEEN_SEIZED flag and make sure it's gone */
312
- tpm_tis_i2c_writeb(l - 1, TPM_I2C_REG_ACCESS,
316
+ tpm_tis_i2c_writeb(global_qtest, l - 1, TPM_I2C_REG_ACCESS,
317
TPM_TIS_ACCESS_BEEN_SEIZED);
318
315
- access = tpm_tis_i2c_readb(l - 1, TPM_I2C_REG_ACCESS);
319
+ access = tpm_tis_i2c_readb(global_qtest, l - 1, TPM_I2C_REG_ACCESS);
320
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
321
pending_request_flag |
322
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -330,22 +334,22 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
334
/* release access from l - 1; this activates locty - 1 */
335
l--;
336
333
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
337
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
338
DPRINTF_ACCESS;
339
340
DPRINTF("%s: %d: relinquishing control on l = %d\n",
341
__func__, __LINE__, l);
338
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
342
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
343
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
344
341
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
345
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
346
DPRINTF_ACCESS;
347
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
348
pending_request_flag |
349
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
350
351
for (l = locty - 1; l >= 0; l--) {
348
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
352
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
353
DPRINTF_ACCESS;
354
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
355
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
@@ -353,7 +357,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
357
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
358
359
/* release this locality */
356
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
360
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
361
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
362
363
if (l == 1) {
@@ -363,7 +367,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
367
368
/* no locality may be active now */
369
for (l = 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
366
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
370
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
371
DPRINTF_ACCESS;
372
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
373
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -384,14 +388,14 @@ static void tpm_tis_i2c_test_check_access_reg_release(const void *data)
388
for (locty = TPM_TIS_NUM_LOCALITIES - 2; locty >= 0; locty--) {
389
pending_request_flag = 0;
390
387
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
391
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
392
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
393
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
394
395
/* request use of locality */
392
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
396
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
397
TPM_TIS_ACCESS_REQUEST_USE);
394
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
398
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
399
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
400
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
401
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -405,9 +409,9 @@ static void tpm_tis_i2c_test_check_access_reg_release(const void *data)
409
* request use of locality 'l' -- we MUST see REQUEST USE and
410
* may see PENDING_REQUEST
411
*/
408
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
412
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
413
TPM_TIS_ACCESS_REQUEST_USE);
410
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
414
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
415
DPRINTF_ACCESS;
416
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
417
TPM_TIS_ACCESS_REQUEST_USE |
@@ -416,7 +420,7 @@ static void tpm_tis_i2c_test_check_access_reg_release(const void *data)
420
pending_request_flag = TPM_TIS_ACCESS_PENDING_REQUEST;
421
}
422
/* release locality 'locty' */
419
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
423
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
424
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
425
/*
426
* highest locality should now be active; release it and make sure the
@@ -427,16 +431,16 @@ static void tpm_tis_i2c_test_check_access_reg_release(const void *data)
431
continue;
432
}
433
/* 'l' should be active now */
430
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
434
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
435
DPRINTF_ACCESS;
436
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
437
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
438
pending_request_flag |
439
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
440
/* 'l' relinquishes access */
437
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
441
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
442
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
439
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
443
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
444
DPRINTF_ACCESS;
445
if (l == 1 || (locty <= 1 && l == 2)) {
446
pending_request_flag = 0;
@@ -460,22 +464,24 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
464
size_t i;
465
466
/* enable csum */
463
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_CSUM_ENABLE, TPM_DATA_CSUM_ENABLED);
467
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE,
468
+ TPM_DATA_CSUM_ENABLED);
469
/* check csum enable register has bit 0 set */
465
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
470
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
471
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
472
/* reading it as 32bit register returns same result */
468
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
473
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
474
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
475
476
/* request use of locality 0 */
472
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
473
- access = tpm_tis_i2c_readb(0, TPM_I2C_REG_ACCESS);
477
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
478
+ TPM_TIS_ACCESS_REQUEST_USE);
479
+ access = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_ACCESS);
480
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
481
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
482
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
483
478
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
484
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
485
DPRINTF_STS;
486
487
g_assert_cmpint(sts & 0xff, ==, 0);
@@ -484,21 +490,22 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
490
g_assert_cmpint(bcount, >=, 128);
491
492
/* read bcount from STS + 1 must work also */
487
- bcount2 = tpm_tis_i2c_readw(0, TPM_I2C_REG_STS + 1);
493
+ bcount2 = tpm_tis_i2c_readw(global_qtest, 0, TPM_I2C_REG_STS + 1);
494
g_assert_cmpint(bcount, ==, bcount2);
495
496
/* ic2 must have bits 26-31 zero */
497
g_assert_cmpint(sts & (0x1f << 26), ==, 0);
498
493
- tpm_tis_i2c_writel(0, TPM_I2C_REG_STS, TPM_TIS_STS_COMMAND_READY);
494
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
499
+ tpm_tis_i2c_writel(global_qtest, 0, TPM_I2C_REG_STS,
500
+ TPM_TIS_STS_COMMAND_READY);
501
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
502
DPRINTF_STS;
503
g_assert_cmpint(sts & 0xff, ==, TPM_TIS_STS_COMMAND_READY);
504
505
/* transmit command */
506
for (i = 0; i < sizeof(TPM_CMD); i++) {
500
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_FIFO, TPM_CMD[i]);
501
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
507
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_FIFO, TPM_CMD[i]);
508
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
509
DPRINTF_STS;
510
if (i < sizeof(TPM_CMD) - 1) {
511
g_assert_cmpint(sts & 0xff, ==,
@@ -509,21 +516,21 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
516
g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
517
}
518
/* read the checksum */
512
- csum = tpm_tis_i2c_readw(0, TPM_I2C_REG_DATA_CSUM_GET);
519
+ csum = tpm_tis_i2c_readw(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_GET);
520
g_assert_cmpint(csum, ==, 0x6733);
521
522
/* start processing */
516
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_STS, TPM_TIS_STS_TPM_GO);
523
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_STS, TPM_TIS_STS_TPM_GO);
524
525
uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
526
do {
520
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
527
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
528
if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
529
break;
530
}
531
} while (g_get_monotonic_time() < end_time);
532
526
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
533
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
534
DPRINTF_STS;
535
g_assert_cmpint(sts & 0xff, == ,
536
TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE);
@@ -534,8 +541,8 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
541
g_assert_cmpint(sizeof(tpm_msg), ==, bcount);
542
543
for (i = 0; i < sizeof(tpm_msg); i++) {
537
- tpm_msg[i] = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_FIFO);
538
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
544
+ tpm_msg[i] = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_FIFO);
545
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
546
DPRINTF_STS;
547
if (sts & TPM_TIS_STS_DATA_AVAILABLE) {
548
g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
@@ -544,9 +551,9 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
551
g_assert_cmpmem(tpm_msg, sizeof(tpm_msg), s->tpm_msg, sizeof(*s->tpm_msg));
552
553
/* relinquish use of locality 0 */
547
- tpm_tis_i2c_writeb(0,
554
+ tpm_tis_i2c_writeb(global_qtest, 0,
555
TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_ACTIVE_LOCALITY);
549
- access = tpm_tis_i2c_readb(0, TPM_I2C_REG_ACCESS);
556
+ access = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_ACCESS);
557
}
558
559
int main(int argc, char **argv)
tests/qtest/tpm-tis-i2c-util.c
+16
-16
@@ -20,45 +20,45 @@ uint32_t aspeed_bus_addr;
20
21
static uint8_t cur_locty = 0xff;
22
23
-static void tpm_tis_i2c_set_locty(uint8_t locty)
23
+static void tpm_tis_i2c_set_locty(QTestState *s, uint8_t locty)
24
{
25
if (cur_locty != locty) {
26
cur_locty = locty;
27
- aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR,
27
+ aspeed_i2c_writeb(s, aspeed_bus_addr, I2C_SLAVE_ADDR,
28
TPM_I2C_REG_LOC_SEL, locty);
29
}
30
}
31
32
-uint8_t tpm_tis_i2c_readb(uint8_t locty, uint8_t reg)
32
+uint8_t tpm_tis_i2c_readb(QTestState *s, uint8_t locty, uint8_t reg)
33
{
34
- tpm_tis_i2c_set_locty(locty);
35
- return aspeed_i2c_readb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
34
+ tpm_tis_i2c_set_locty(s, locty);
35
+ return aspeed_i2c_readb(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
36
}
37
38
-uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg)
38
+uint16_t tpm_tis_i2c_readw(QTestState *s, uint8_t locty, uint8_t reg)
39
{
40
- tpm_tis_i2c_set_locty(locty);
40
+ tpm_tis_i2c_set_locty(s, locty);
41
return aspeed_i2c_readw(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
42
}
43
44
-uint32_t tpm_tis_i2c_readl(uint8_t locty, uint8_t reg)
44
+uint32_t tpm_tis_i2c_readl(QTestState *s, uint8_t locty, uint8_t reg)
45
{
46
- tpm_tis_i2c_set_locty(locty);
47
- return aspeed_i2c_readl(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
46
+ tpm_tis_i2c_set_locty(s, locty);
47
+ return aspeed_i2c_readl(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
48
}
49
50
-void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v)
50
+void tpm_tis_i2c_writeb(QTestState *s, uint8_t locty, uint8_t reg, uint8_t v)
51
{
52
if (reg != TPM_I2C_REG_LOC_SEL) {
53
- tpm_tis_i2c_set_locty(locty);
53
+ tpm_tis_i2c_set_locty(s, locty);
54
}
55
- aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
55
+ aspeed_i2c_writeb(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
56
}
57
58
-void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v)
58
+void tpm_tis_i2c_writel(QTestState *s, uint8_t locty, uint8_t reg, uint32_t v)
59
{
60
if (reg != TPM_I2C_REG_LOC_SEL) {
61
- tpm_tis_i2c_set_locty(locty);
61
+ tpm_tis_i2c_set_locty(s, locty);
62
}
63
- aspeed_i2c_writel(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
63
+ aspeed_i2c_writel(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
64
}
tests/qtest/tpm-tis-i2c-util.h
+5
-5
@@ -20,11 +20,11 @@ extern uint32_t aspeed_bus_addr;
20
#define I2C_SLAVE_ADDR 0x2e
21
#define I2C_DEV_BUS_NUM 10
22
23
-uint8_t tpm_tis_i2c_readb(uint8_t locty, uint8_t reg);
24
-uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg);
25
-uint32_t tpm_tis_i2c_readl(uint8_t locty, uint8_t reg);
23
+uint8_t tpm_tis_i2c_readb(QTestState *s, uint8_t locty, uint8_t reg);
24
+uint16_t tpm_tis_i2c_readw(QTestState *s, uint8_t locty, uint8_t reg);
25
+uint32_t tpm_tis_i2c_readl(QTestState *s, uint8_t locty, uint8_t reg);
26
27
-void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v);
28
-void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v);
27
+void tpm_tis_i2c_writeb(QTestState *s, uint8_t locty, uint8_t reg, uint8_t v);
28
+void tpm_tis_i2c_writel(QTestState *s, uint8_t locty, uint8_t reg, uint32_t v);
29
30
#endif /* TESTS_TPM_TIS_I2C_UTIL_H */