From: Stefan Berger <stefanb@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Stefan Berger <stefanb@linux.ibm.com>,
Arun Menon <armenon@redhat.com>
Subject: [PULL v1 02/16] tests: Have TPM I2C read/write functions take QTestState as first parameter
Date: Mon, 1 Jun 2026 17:53:55 -0400 [thread overview]
Message-ID: <20260601215410.517009-3-stefanb@linux.ibm.com> (raw)
In-Reply-To: <20260601215410.517009-1-stefanb@linux.ibm.com>
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>
---
tests/qtest/tpm-tis-i2c-test.c | 171 +++++++++++++++++----------------
tests/qtest/tpm-tis-i2c-util.c | 32 +++---
tests/qtest/tpm-tis-i2c-util.h | 10 +-
3 files changed, 110 insertions(+), 103 deletions(-)
diff --git a/tests/qtest/tpm-tis-i2c-test.c b/tests/qtest/tpm-tis-i2c-test.c
index 02ddf76c2c..f614f888f3 100644
--- a/tests/qtest/tpm-tis-i2c-test.c
+++ b/tests/qtest/tpm-tis-i2c-test.c
@@ -50,62 +50,64 @@ static void tpm_tis_i2c_test_basic(const void *data)
* All register accesses below must work without locality 0 being the
* active locality. Therefore, ensure access is released.
*/
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = tpm_tis_i2c_readb(0, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* read interrupt capability -- none are supported */
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_INT_CAPABILITY);
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_INT_CAPABILITY);
g_assert_cmpint(v, ==, 0);
/* try to enable all interrupts */
- tpm_tis_i2c_writel(0, TPM_I2C_REG_INT_ENABLE, 0xffffffff);
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_INT_ENABLE);
+ tpm_tis_i2c_writel(global_qtest, 0, TPM_I2C_REG_INT_ENABLE, 0xffffffff);
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_INT_ENABLE);
/* none could be enabled */
g_assert_cmpint(v, ==, 0);
/* enable csum */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_CSUM_ENABLE, TPM_DATA_CSUM_ENABLED);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE,
+ TPM_DATA_CSUM_ENABLED);
/* check csum enable register has bit 0 set */
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
/* reading it as 32bit register returns same result */
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
/* disable csum */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_CSUM_ENABLE, 0);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE, 0);
/* check csum enable register has bit 0 clear */
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
g_assert_cmpint(v, ==, 0);
/* write to unsupported register '1' */
- tpm_tis_i2c_writel(0, 1, 0x12345678);
- v = tpm_tis_i2c_readl(0, 1);
+ tpm_tis_i2c_writel(global_qtest, 0, 1, 0x12345678);
+ v = tpm_tis_i2c_readl(global_qtest, 0, 1);
g_assert_cmpint(v, ==, 0xffffffff);
/* request use of locality */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
+ TPM_TIS_ACCESS_REQUEST_USE);
/* read byte from STS + 3 */
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_STS + 3);
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_STS + 3);
g_assert_cmpint(v, ==, 0);
/* check STS after writing to STS + 3 */
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_STS + 3, 0xf);
- v2 = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_STS + 3, 0xf);
+ v2 = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
g_assert_cmpint(v, ==, v2);
/* release access */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
/* select locality 5 -- must not be possible */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_LOC_SEL, 5);
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_LOC_SEL);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_LOC_SEL, 5);
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_LOC_SEL);
g_assert_cmpint(v, ==, 0);
}
@@ -118,11 +120,12 @@ static void tpm_tis_i2c_test_check_localities(const void *data)
uint32_t rid;
for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES; locty++) {
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- capability = tpm_tis_i2c_readl(locty, TPM_I2C_REG_INTF_CAPABILITY);
+ capability = tpm_tis_i2c_readl(global_qtest, locty,
+ TPM_I2C_REG_INTF_CAPABILITY);
i2c_cap = (TPM_I2C_CAP_INTERFACE_TYPE |
TPM_I2C_CAP_INTERFACE_VER |
TPM_I2C_CAP_TPM2_FAMILY |
@@ -131,15 +134,15 @@ static void tpm_tis_i2c_test_check_localities(const void *data)
TPM_I2C_CAP_DEV_ADDR_CHANGE);
g_assert_cmpint(capability, ==, i2c_cap);
- didvid = tpm_tis_i2c_readl(locty, TPM_I2C_REG_DID_VID);
+ didvid = tpm_tis_i2c_readl(global_qtest, locty, TPM_I2C_REG_DID_VID);
g_assert_cmpint(didvid, ==, (1 << 16) | PCI_VENDOR_ID_IBM);
- rid = tpm_tis_i2c_readl(locty, TPM_I2C_REG_RID);
+ rid = tpm_tis_i2c_readl(global_qtest, locty, TPM_I2C_REG_RID);
g_assert_cmpint(rid, !=, 0);
g_assert_cmpint(rid, !=, 0xffffffff);
/* locality selection must be at locty */
- l = tpm_tis_i2c_readb(locty, TPM_I2C_REG_LOC_SEL);
+ l = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_LOC_SEL);
g_assert_cmpint(l, ==, locty);
}
}
@@ -151,23 +154,23 @@ static void tpm_tis_i2c_test_check_access_reg(const void *data)
/* do not test locality 4 (hw only) */
for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* request use of locality */
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_REQUEST_USE);
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* release access */
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
}
@@ -186,14 +189,14 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
pending_request_flag = 0;
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* request use of locality */
- tpm_tis_i2c_writeb(locty,
+ tpm_tis_i2c_writeb(global_qtest, locty,
TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -201,14 +204,14 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
/* lower localities cannot seize access */
for (l = 0; l < locty; l++) {
/* lower locality is not active */
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
pending_request_flag |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* try to request use from 'l' */
- tpm_tis_i2c_writeb(l,
+ tpm_tis_i2c_writeb(global_qtest, l,
TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_REQUEST_USE);
@@ -216,7 +219,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
* requesting use from 'l' was not possible;
* we must see REQUEST_USE and possibly PENDING_REQUEST
*/
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_REQUEST_USE |
@@ -227,17 +230,17 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
* locality 'locty' must be unchanged;
* we must see PENDING_REQUEST
*/
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
TPM_TIS_ACCESS_PENDING_REQUEST |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* try to seize from 'l' */
- tpm_tis_i2c_writeb(l,
+ tpm_tis_i2c_writeb(global_qtest, l,
TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_SEIZE);
/* seize from 'l' was not possible */
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_REQUEST_USE |
@@ -245,7 +248,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* locality 'locty' must be unchanged */
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
TPM_TIS_ACCESS_PENDING_REQUEST |
@@ -264,14 +267,14 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
*/
for (l = locty + 1; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
/* try to 'request use' from 'l' */
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_REQUEST_USE);
/*
* requesting use from 'l' was not possible; we should see
* REQUEST_USE and may see PENDING_REQUEST
*/
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_REQUEST_USE |
@@ -282,7 +285,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
* locality 'l-1' must be unchanged; we should always
* see PENDING_REQUEST from 'l' requesting access
*/
- access = tpm_tis_i2c_readb(l - 1, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l - 1, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
@@ -290,10 +293,11 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* try to seize from 'l' */
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_SEIZE);
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
+ TPM_TIS_ACCESS_SEIZE);
/* seize from 'l' was possible */
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
@@ -301,7 +305,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* l - 1 should show that it has BEEN_SEIZED */
- access = tpm_tis_i2c_readb(l - 1, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l - 1, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_BEEN_SEIZED |
@@ -309,10 +313,10 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* clear the BEEN_SEIZED flag and make sure it's gone */
- tpm_tis_i2c_writeb(l - 1, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, l - 1, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_BEEN_SEIZED);
- access = tpm_tis_i2c_readb(l - 1, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l - 1, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
pending_request_flag |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -330,22 +334,22 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
/* release access from l - 1; this activates locty - 1 */
l--;
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
DPRINTF("%s: %d: relinquishing control on l = %d\n",
__func__, __LINE__, l);
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
pending_request_flag |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
for (l = locty - 1; l >= 0; l--) {
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
@@ -353,7 +357,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* release this locality */
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
if (l == 1) {
@@ -363,7 +367,7 @@ static void tpm_tis_i2c_test_check_access_reg_seize(const void *data)
/* no locality may be active now */
for (l = 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -384,14 +388,14 @@ static void tpm_tis_i2c_test_check_access_reg_release(const void *data)
for (locty = TPM_TIS_NUM_LOCALITIES - 2; locty >= 0; locty--) {
pending_request_flag = 0;
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* request use of locality */
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_REQUEST_USE);
- access = tpm_tis_i2c_readb(locty, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, locty, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
@@ -405,9 +409,9 @@ static void tpm_tis_i2c_test_check_access_reg_release(const void *data)
* request use of locality 'l' -- we MUST see REQUEST USE and
* may see PENDING_REQUEST
*/
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_REQUEST_USE);
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_REQUEST_USE |
@@ -416,7 +420,7 @@ static void tpm_tis_i2c_test_check_access_reg_release(const void *data)
pending_request_flag = TPM_TIS_ACCESS_PENDING_REQUEST;
}
/* release locality 'locty' */
- tpm_tis_i2c_writeb(locty, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, locty, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
/*
* 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)
continue;
}
/* 'l' should be active now */
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
pending_request_flag |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
/* 'l' relinquishes access */
- tpm_tis_i2c_writeb(l, TPM_I2C_REG_ACCESS,
+ tpm_tis_i2c_writeb(global_qtest, l, TPM_I2C_REG_ACCESS,
TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = tpm_tis_i2c_readb(l, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, l, TPM_I2C_REG_ACCESS);
DPRINTF_ACCESS;
if (l == 1 || (locty <= 1 && l == 2)) {
pending_request_flag = 0;
@@ -460,22 +464,24 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
size_t i;
/* enable csum */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_CSUM_ENABLE, TPM_DATA_CSUM_ENABLED);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE,
+ TPM_DATA_CSUM_ENABLED);
/* check csum enable register has bit 0 set */
- v = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
+ v = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
/* reading it as 32bit register returns same result */
- v = tpm_tis_i2c_readl(0, TPM_I2C_REG_DATA_CSUM_ENABLE);
+ v = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_ENABLE);
g_assert_cmpint(v, ==, TPM_DATA_CSUM_ENABLED);
/* request use of locality 0 */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
- access = tpm_tis_i2c_readb(0, TPM_I2C_REG_ACCESS);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_ACCESS,
+ TPM_TIS_ACCESS_REQUEST_USE);
+ access = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_ACCESS);
g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
TPM_TIS_ACCESS_ACTIVE_LOCALITY |
TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
DPRINTF_STS;
g_assert_cmpint(sts & 0xff, ==, 0);
@@ -484,21 +490,22 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
g_assert_cmpint(bcount, >=, 128);
/* read bcount from STS + 1 must work also */
- bcount2 = tpm_tis_i2c_readw(0, TPM_I2C_REG_STS + 1);
+ bcount2 = tpm_tis_i2c_readw(global_qtest, 0, TPM_I2C_REG_STS + 1);
g_assert_cmpint(bcount, ==, bcount2);
/* ic2 must have bits 26-31 zero */
g_assert_cmpint(sts & (0x1f << 26), ==, 0);
- tpm_tis_i2c_writel(0, TPM_I2C_REG_STS, TPM_TIS_STS_COMMAND_READY);
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
+ tpm_tis_i2c_writel(global_qtest, 0, TPM_I2C_REG_STS,
+ TPM_TIS_STS_COMMAND_READY);
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
DPRINTF_STS;
g_assert_cmpint(sts & 0xff, ==, TPM_TIS_STS_COMMAND_READY);
/* transmit command */
for (i = 0; i < sizeof(TPM_CMD); i++) {
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_DATA_FIFO, TPM_CMD[i]);
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_DATA_FIFO, TPM_CMD[i]);
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
DPRINTF_STS;
if (i < sizeof(TPM_CMD) - 1) {
g_assert_cmpint(sts & 0xff, ==,
@@ -509,21 +516,21 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
}
/* read the checksum */
- csum = tpm_tis_i2c_readw(0, TPM_I2C_REG_DATA_CSUM_GET);
+ csum = tpm_tis_i2c_readw(global_qtest, 0, TPM_I2C_REG_DATA_CSUM_GET);
g_assert_cmpint(csum, ==, 0x6733);
/* start processing */
- tpm_tis_i2c_writeb(0, TPM_I2C_REG_STS, TPM_TIS_STS_TPM_GO);
+ tpm_tis_i2c_writeb(global_qtest, 0, TPM_I2C_REG_STS, TPM_TIS_STS_TPM_GO);
uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
do {
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
break;
}
} while (g_get_monotonic_time() < end_time);
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
DPRINTF_STS;
g_assert_cmpint(sts & 0xff, == ,
TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE);
@@ -534,8 +541,8 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
g_assert_cmpint(sizeof(tpm_msg), ==, bcount);
for (i = 0; i < sizeof(tpm_msg); i++) {
- tpm_msg[i] = tpm_tis_i2c_readb(0, TPM_I2C_REG_DATA_FIFO);
- sts = tpm_tis_i2c_readl(0, TPM_I2C_REG_STS);
+ tpm_msg[i] = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_DATA_FIFO);
+ sts = tpm_tis_i2c_readl(global_qtest, 0, TPM_I2C_REG_STS);
DPRINTF_STS;
if (sts & TPM_TIS_STS_DATA_AVAILABLE) {
g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
@@ -544,9 +551,9 @@ static void tpm_tis_i2c_test_check_transmit(const void *data)
g_assert_cmpmem(tpm_msg, sizeof(tpm_msg), s->tpm_msg, sizeof(*s->tpm_msg));
/* relinquish use of locality 0 */
- tpm_tis_i2c_writeb(0,
+ tpm_tis_i2c_writeb(global_qtest, 0,
TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = tpm_tis_i2c_readb(0, TPM_I2C_REG_ACCESS);
+ access = tpm_tis_i2c_readb(global_qtest, 0, TPM_I2C_REG_ACCESS);
}
int main(int argc, char **argv)
diff --git a/tests/qtest/tpm-tis-i2c-util.c b/tests/qtest/tpm-tis-i2c-util.c
index 07b1eeba69..6e724a4a47 100644
--- a/tests/qtest/tpm-tis-i2c-util.c
+++ b/tests/qtest/tpm-tis-i2c-util.c
@@ -20,45 +20,45 @@ uint32_t aspeed_bus_addr;
static uint8_t cur_locty = 0xff;
-static void tpm_tis_i2c_set_locty(uint8_t locty)
+static void tpm_tis_i2c_set_locty(QTestState *s, uint8_t locty)
{
if (cur_locty != locty) {
cur_locty = locty;
- aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR,
+ aspeed_i2c_writeb(s, aspeed_bus_addr, I2C_SLAVE_ADDR,
TPM_I2C_REG_LOC_SEL, locty);
}
}
-uint8_t tpm_tis_i2c_readb(uint8_t locty, uint8_t reg)
+uint8_t tpm_tis_i2c_readb(QTestState *s, uint8_t locty, uint8_t reg)
{
- tpm_tis_i2c_set_locty(locty);
- return aspeed_i2c_readb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
+ tpm_tis_i2c_set_locty(s, locty);
+ return aspeed_i2c_readb(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
}
-uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg)
+uint16_t tpm_tis_i2c_readw(QTestState *s, uint8_t locty, uint8_t reg)
{
- tpm_tis_i2c_set_locty(locty);
+ tpm_tis_i2c_set_locty(s, locty);
return aspeed_i2c_readw(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
}
-uint32_t tpm_tis_i2c_readl(uint8_t locty, uint8_t reg)
+uint32_t tpm_tis_i2c_readl(QTestState *s, uint8_t locty, uint8_t reg)
{
- tpm_tis_i2c_set_locty(locty);
- return aspeed_i2c_readl(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
+ tpm_tis_i2c_set_locty(s, locty);
+ return aspeed_i2c_readl(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
}
-void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v)
+void tpm_tis_i2c_writeb(QTestState *s, uint8_t locty, uint8_t reg, uint8_t v)
{
if (reg != TPM_I2C_REG_LOC_SEL) {
- tpm_tis_i2c_set_locty(locty);
+ tpm_tis_i2c_set_locty(s, locty);
}
- aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
+ aspeed_i2c_writeb(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
}
-void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v)
+void tpm_tis_i2c_writel(QTestState *s, uint8_t locty, uint8_t reg, uint32_t v)
{
if (reg != TPM_I2C_REG_LOC_SEL) {
- tpm_tis_i2c_set_locty(locty);
+ tpm_tis_i2c_set_locty(s, locty);
}
- aspeed_i2c_writel(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
+ aspeed_i2c_writel(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
}
diff --git a/tests/qtest/tpm-tis-i2c-util.h b/tests/qtest/tpm-tis-i2c-util.h
index dfe626b43d..3289545f61 100644
--- a/tests/qtest/tpm-tis-i2c-util.h
+++ b/tests/qtest/tpm-tis-i2c-util.h
@@ -20,11 +20,11 @@ extern uint32_t aspeed_bus_addr;
#define I2C_SLAVE_ADDR 0x2e
#define I2C_DEV_BUS_NUM 10
-uint8_t tpm_tis_i2c_readb(uint8_t locty, uint8_t reg);
-uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg);
-uint32_t tpm_tis_i2c_readl(uint8_t locty, uint8_t reg);
+uint8_t tpm_tis_i2c_readb(QTestState *s, uint8_t locty, uint8_t reg);
+uint16_t tpm_tis_i2c_readw(QTestState *s, uint8_t locty, uint8_t reg);
+uint32_t tpm_tis_i2c_readl(QTestState *s, uint8_t locty, uint8_t reg);
-void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v);
-void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v);
+void tpm_tis_i2c_writeb(QTestState *s, uint8_t locty, uint8_t reg, uint8_t v);
+void tpm_tis_i2c_writel(QTestState *s, uint8_t locty, uint8_t reg, uint32_t v);
#endif /* TESTS_TPM_TIS_I2C_UTIL_H */
--
2.54.0
next prev parent reply other threads:[~2026-06-01 21:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 21:53 [PULL v1 00/16] Merge tpm 2026/06/01 v1 Stefan Berger
2026-06-01 21:53 ` [PULL v1 01/16] tests: Move TPM I2C bus read/write functions to common files Stefan Berger
2026-06-01 21:53 ` Stefan Berger [this message]
2026-06-01 21:53 ` [PULL v1 03/16] tests: Convert string arrays to byte arrays Stefan Berger
2026-06-01 21:53 ` [PULL v1 04/16] tests: Rename id of tpmdev to tpm0 Stefan Berger
2026-06-01 21:53 ` [PULL v1 05/16] tests: Check whether the I2C master flag is set Stefan Berger
2026-06-01 21:53 ` [PULL v1 06/16] tests: Add a TPM TIS I2C swtpm test Stefan Berger
2026-06-01 21:54 ` [PULL v1 07/16] migration/vmstate: Add VMState support for GByteArray Stefan Berger
2026-06-01 21:54 ` [PULL v1 08/16] ui/vdagent: Use VMSTATE_GBYTEARRAY to safely migrate outbuf Stefan Berger
2026-06-01 21:54 ` [PULL v1 09/16] hw/tpm: Add TPM CRB chunking fields Stefan Berger
2026-06-01 21:54 ` [PULL v1 10/16] hw/tpm: Refactor CRB_CTRL_START register access Stefan Berger
2026-06-01 21:54 ` [PULL v1 11/16] hw/tpm: Add internal buffer state for chunking Stefan Berger
2026-06-01 21:54 ` [PULL v1 12/16] hw/tpm: Implement TPM CRB chunking logic Stefan Berger
2026-06-01 21:54 ` [PULL v1 13/16] test/qtest: Add test for tpm crb chunking Stefan Berger
2026-06-01 21:54 ` [PULL v1 14/16] hw/tpm: Add support for VM migration with TPM CRB chunking Stefan Berger
2026-06-01 21:54 ` [PULL v1 15/16] tpm_emulator: Reject a buffer size different than what was requested Stefan Berger
2026-06-01 21:54 ` [PULL v1 16/16] tpm_emulator: Disconnect if response exceeds negotiated buffer size Stefan Berger
2026-06-02 17:23 ` [PULL v1 00/16] Merge tpm 2026/06/01 v1 Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260601215410.517009-3-stefanb@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=armenon@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.