* [PATCH v2 0/6] Add test case for TPM over I2C with swtpm
@ 2026-04-29 12:17 Stefan Berger
2026-04-29 12:17 ` [PATCH v2 1/6] tests: Move TPM I2C bus read/write functions to common files Stefan Berger
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Stefan Berger @ 2026-04-29 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, armenon, Stefan Berger
This series adds a test case for TPM over I2C with external swtpm. It is
based on existing test cases for the TPM TIS and CRB. The first patches
refactor and fix some issues in exising code to prepare it for reuse by
the new test case.
Stefan
v2: Addressed some issues pointed out by Arun
Stefan Berger (6):
tests: Move TPM I2C bus read/write functions to common files
tests: Have TPM I2C read/write functions take QTestState as first
parameter
tests: Convert string arrays to byte arrays
tests: Rename id of tpmdev to tpm0
tests: Check whether the I2C master flag is set
tests: Add a TPM TIS I2C swtpm test
tests/qtest/meson.build | 7 +-
tests/qtest/qtest_aspeed.c | 9 +-
tests/qtest/tpm-tests.c | 34 +++--
tests/qtest/tpm-tis-i2c-swtpm-test.c | 82 ++++++++++
tests/qtest/tpm-tis-i2c-test.c | 221 +++++++++++----------------
tests/qtest/tpm-tis-i2c-util.c | 102 +++++++++++++
tests/qtest/tpm-tis-i2c-util.h | 34 +++++
tests/qtest/tpm-util.c | 53 ++++---
8 files changed, 373 insertions(+), 169 deletions(-)
create mode 100644 tests/qtest/tpm-tis-i2c-swtpm-test.c
create mode 100644 tests/qtest/tpm-tis-i2c-util.c
create mode 100644 tests/qtest/tpm-tis-i2c-util.h
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/6] tests: Move TPM I2C bus read/write functions to common files
2026-04-29 12:17 [PATCH v2 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
@ 2026-04-29 12:17 ` Stefan Berger
2026-04-29 12:17 ` [PATCH v2 2/6] tests: Have TPM I2C read/write functions take QTestState as first parameter Stefan Berger
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Stefan Berger @ 2026-04-29 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, armenon, Stefan Berger
Move functions for reading from and writing to the Aspeed I2C device into
a file so they can be reused by other functions.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Arun Menon <armenon@redhat.com>
---
tests/qtest/meson.build | 2 +-
tests/qtest/tpm-tis-i2c-test.c | 50 +-------------------------
tests/qtest/tpm-tis-i2c-util.c | 64 ++++++++++++++++++++++++++++++++++
tests/qtest/tpm-tis-i2c-util.h | 30 ++++++++++++++++
4 files changed, 96 insertions(+), 50 deletions(-)
create mode 100644 tests/qtest/tpm-tis-i2c-util.c
create mode 100644 tests/qtest/tpm-tis-i2c-util.h
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index b735f55fc4..823be192e7 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -397,7 +397,7 @@ qtests = {
'tpm-crb-test': [io, tpmemu_files],
'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-test': [io, tpmemu_files, 'tpm-tis-util.c'],
- 'tpm-tis-i2c-test': [io, tpmemu_files, 'qtest_aspeed.c'],
+ 'tpm-tis-i2c-test': [io, tpmemu_files, 'tpm-tis-i2c-util.c', 'qtest_aspeed.c'],
'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'virtio-net-failover': test_migration_files,
diff --git a/tests/qtest/tpm-tis-i2c-test.c b/tests/qtest/tpm-tis-i2c-test.c
index 3a1af026f2..02ddf76c2c 100644
--- a/tests/qtest/tpm-tis-i2c-test.c
+++ b/tests/qtest/tpm-tis-i2c-test.c
@@ -20,6 +20,7 @@
#include "hw/pci/pci_ids.h"
#include "qtest_aspeed.h"
#include "tpm-emu.h"
+#include "tpm-tis-i2c-util.h"
#define DEBUG_TIS_TEST 0
@@ -36,58 +37,9 @@
#define DPRINTF_STS \
DPRINTF("%s: %d: sts = 0x%08x\n", __func__, __LINE__, sts)
-#define I2C_SLAVE_ADDR 0x2e
-#define I2C_DEV_BUS_NUM 10
-
static const uint8_t TPM_CMD[12] =
"\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
-static uint32_t aspeed_bus_addr;
-
-static uint8_t cur_locty = 0xff;
-
-static void tpm_tis_i2c_set_locty(uint8_t locty)
-{
- if (cur_locty != locty) {
- cur_locty = locty;
- aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR,
- TPM_I2C_REG_LOC_SEL, locty);
- }
-}
-
-static uint8_t tpm_tis_i2c_readb(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);
-}
-
-static uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg)
-{
- tpm_tis_i2c_set_locty(locty);
- return aspeed_i2c_readw(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
-}
-
-static uint32_t tpm_tis_i2c_readl(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);
-}
-
-static void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v)
-{
- if (reg != TPM_I2C_REG_LOC_SEL) {
- tpm_tis_i2c_set_locty(locty);
- }
- aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
-}
-
-static void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v)
-{
- if (reg != TPM_I2C_REG_LOC_SEL) {
- tpm_tis_i2c_set_locty(locty);
- }
- aspeed_i2c_writel(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
-}
static void tpm_tis_i2c_test_basic(const void *data)
{
diff --git a/tests/qtest/tpm-tis-i2c-util.c b/tests/qtest/tpm-tis-i2c-util.c
new file mode 100644
index 0000000000..07b1eeba69
--- /dev/null
+++ b/tests/qtest/tpm-tis-i2c-util.c
@@ -0,0 +1,64 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * QTest utilities for TPM TIS over I2C
+ *
+ * Copyright (c) 2018, 2026 IBM Corporation
+ *
+ * Authors:
+ * Stefan Berger <stefanb@linux.ibm.com>
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "hw/acpi/tpm.h"
+#include "libqtest-single.h"
+#include "qtest_aspeed.h"
+#include "tpm-tis-i2c-util.h"
+
+uint32_t aspeed_bus_addr;
+
+static uint8_t cur_locty = 0xff;
+
+static void tpm_tis_i2c_set_locty(uint8_t locty)
+{
+ if (cur_locty != locty) {
+ cur_locty = locty;
+ aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR,
+ TPM_I2C_REG_LOC_SEL, locty);
+ }
+}
+
+uint8_t tpm_tis_i2c_readb(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);
+}
+
+uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg)
+{
+ tpm_tis_i2c_set_locty(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)
+{
+ tpm_tis_i2c_set_locty(locty);
+ return aspeed_i2c_readl(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);
+}
+
+void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v)
+{
+ if (reg != TPM_I2C_REG_LOC_SEL) {
+ tpm_tis_i2c_set_locty(locty);
+ }
+ aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
+}
+
+void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v)
+{
+ if (reg != TPM_I2C_REG_LOC_SEL) {
+ tpm_tis_i2c_set_locty(locty);
+ }
+ aspeed_i2c_writel(global_qtest, 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
new file mode 100644
index 0000000000..dfe626b43d
--- /dev/null
+++ b/tests/qtest/tpm-tis-i2c-util.h
@@ -0,0 +1,30 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * QTest TPM TIS I2C: Common test functions used for TPM I2C on Aspeed bus
+ *
+ * Copyright (c) 2026 IBM Corporation
+ *
+ * Authors:
+ * Stefan Berger <stefanb@linux.ibm.com>
+ *
+ */
+
+#ifndef TESTS_TPM_TIS_I2C_UTIL_H
+#define TESTS_TPM_TIS_I2C_UTIL_H
+
+#include "qemu/osdep.h"
+
+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);
+
+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);
+
+#endif /* TESTS_TPM_TIS_I2C_UTIL_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/6] tests: Have TPM I2C read/write functions take QTestState as first parameter
2026-04-29 12:17 [PATCH v2 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
2026-04-29 12:17 ` [PATCH v2 1/6] tests: Move TPM I2C bus read/write functions to common files Stefan Berger
@ 2026-04-29 12:17 ` Stefan Berger
2026-04-29 12:17 ` [PATCH v2 3/6] tests: Convert string arrays to byte arrays Stefan Berger
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Stefan Berger @ 2026-04-29 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, armenon, Stefan Berger
Pass the QTestState as first parameter to the TPM I2C functions. Use
global_qtest in existing test cases.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Arun Menon <armenon@redhat.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.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/6] tests: Convert string arrays to byte arrays
2026-04-29 12:17 [PATCH v2 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
2026-04-29 12:17 ` [PATCH v2 1/6] tests: Move TPM I2C bus read/write functions to common files Stefan Berger
2026-04-29 12:17 ` [PATCH v2 2/6] tests: Have TPM I2C read/write functions take QTestState as first parameter Stefan Berger
@ 2026-04-29 12:17 ` Stefan Berger
2026-04-29 13:12 ` Arun Menon
2026-04-29 12:17 ` [PATCH v2 4/6] tests: Rename id of tpmdev to tpm0 Stefan Berger
` (2 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Stefan Berger @ 2026-04-29 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, armenon, Stefan Berger
Convert the TPM command and response string arrays to byte arrays.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
tests/qtest/tpm-tests.c | 30 ++++++++++++++++++---------
tests/qtest/tpm-util.c | 45 ++++++++++++++++++++++++++---------------
2 files changed, 49 insertions(+), 26 deletions(-)
diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index 197714f8d9..8bd3288f80 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -59,11 +59,16 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
tpm_util_startup(s, tx);
tpm_util_pcrextend(s, tx);
- static const unsigned char tpm_pcrread_resp[] =
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
+ static const unsigned char tpm_pcrread_resp[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
+ 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
+ 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
+ 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
+ 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde
+ };
tpm_util_pcrread(s, tx, tpm_pcrread_resp,
sizeof(tpm_pcrread_resp));
@@ -105,11 +110,16 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
tpm_util_startup(src_qemu, tx);
tpm_util_pcrextend(src_qemu, tx);
- static const unsigned char tpm_pcrread_resp[] =
- "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
- "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
- "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
- "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
+ static const unsigned char tpm_pcrread_resp[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
+ 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
+ 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
+ 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
+ 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde,
+ };
tpm_util_pcrread(src_qemu, tx, tpm_pcrread_resp,
sizeof(tpm_pcrread_resp));
diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
index 2cb2dd4796..63cd5b69db 100644
--- a/tests/qtest/tpm-util.c
+++ b/tests/qtest/tpm-util.c
@@ -54,10 +54,14 @@ void tpm_util_crb_transfer(QTestState *s,
void tpm_util_startup(QTestState *s, tx_func *tx)
{
unsigned char buffer[1024];
- static const unsigned char tpm_startup[] =
- "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
- static const unsigned char tpm_startup_resp[] =
- "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
+ static const unsigned char tpm_startup[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
+ 0x01, 0x44, 0x00, 0x00
+ };
+ static const unsigned char tpm_startup_resp[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
+ 0x00, 0x00
+ };
tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
@@ -68,16 +72,23 @@ void tpm_util_startup(QTestState *s, tx_func *tx)
void tpm_util_pcrextend(QTestState *s, tx_func *tx)
{
unsigned char buffer[1024];
- static const unsigned char tpm_pcrextend[] =
- "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
- "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
- "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x00";
+ static const unsigned char tpm_pcrextend[] = {
+ 0x80, 0x02, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
+ 0x01, 0x82, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
+ 0x00, 0x09, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
+ 0x0b, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00
+ };
- static const unsigned char tpm_pcrextend_resp[] =
- "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
- "\x01\x00\x00";
+ static const unsigned char tpm_pcrextend_resp[] = {
+ 0x80, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00
+ };
tx(s, tpm_pcrextend, sizeof(tpm_pcrextend), buffer, sizeof(buffer));
@@ -89,9 +100,11 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
const unsigned char *exp_resp, size_t exp_resp_size)
{
unsigned char buffer[1024];
- static const unsigned char tpm_pcrread[] =
- "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
- "\x03\x00\x04\x00";
+ static const unsigned char tpm_pcrread[] = {
+ 0x80, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
+ 0x01, 0x7e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b,
+ 0x03, 0x00, 0x04, 0x00
+ };
tx(s, tpm_pcrread, sizeof(tpm_pcrread), buffer, sizeof(buffer));
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/6] tests: Rename id of tpmdev to tpm0
2026-04-29 12:17 [PATCH v2 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
` (2 preceding siblings ...)
2026-04-29 12:17 ` [PATCH v2 3/6] tests: Convert string arrays to byte arrays Stefan Berger
@ 2026-04-29 12:17 ` Stefan Berger
2026-04-29 12:17 ` [PATCH v2 5/6] tests: Check whether the I2C master flag is set Stefan Berger
2026-04-29 12:17 ` [PATCH v2 6/6] tests: Add a TPM TIS I2C swtpm test Stefan Berger
5 siblings, 0 replies; 9+ messages in thread
From: Stefan Berger @ 2026-04-29 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, armenon, Stefan Berger
Rename the id of the tpmdev from dev to tpm0 because this 'dev' cannot
be used when the tpm-tis-i2c device is used.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Arun Menon <armenon@redhat.com>
---
tests/qtest/tpm-tests.c | 4 ++--
tests/qtest/tpm-util.c | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index 8bd3288f80..1b4f932b0c 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -49,8 +49,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
args = g_strdup_printf(
"%s "
"-chardev socket,id=chr,path=%s "
- "-tpmdev emulator,id=dev,chardev=chr "
- "-device %s,tpmdev=dev",
+ "-tpmdev emulator,id=tpm0,chardev=chr "
+ "-device %s,tpmdev=tpm0",
machine_options ? : "", addr->u.q_unix.path, ifmodel);
s = qtest_start(args);
diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
index 63cd5b69db..0f9bef8971 100644
--- a/tests/qtest/tpm-util.c
+++ b/tests/qtest/tpm-util.c
@@ -240,8 +240,8 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
src_qemu_args = g_strdup_printf(
"%s "
"-chardev socket,id=chr,path=%s "
- "-tpmdev emulator,id=dev,chardev=chr "
- "-device %s,tpmdev=dev ",
+ "-tpmdev emulator,id=tpm0,chardev=chr "
+ "-device %s,tpmdev=tpm0 ",
machine_options ? : "", src_tpm_addr->u.q_unix.path, ifmodel);
*src_qemu = qtest_init(src_qemu_args);
@@ -249,8 +249,8 @@ void tpm_util_migration_start_qemu(QTestState **src_qemu,
dst_qemu_args = g_strdup_printf(
"%s "
"-chardev socket,id=chr,path=%s "
- "-tpmdev emulator,id=dev,chardev=chr "
- "-device %s,tpmdev=dev "
+ "-tpmdev emulator,id=tpm0,chardev=chr "
+ "-device %s,tpmdev=tpm0 "
"-incoming %s",
machine_options ? : "",
dst_tpm_addr->u.q_unix.path,
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 5/6] tests: Check whether the I2C master flag is set
2026-04-29 12:17 [PATCH v2 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
` (3 preceding siblings ...)
2026-04-29 12:17 ` [PATCH v2 4/6] tests: Rename id of tpmdev to tpm0 Stefan Berger
@ 2026-04-29 12:17 ` Stefan Berger
2026-04-29 13:13 ` Arun Menon
2026-04-29 12:17 ` [PATCH v2 6/6] tests: Add a TPM TIS I2C swtpm test Stefan Berger
5 siblings, 1 reply; 9+ messages in thread
From: Stefan Berger @ 2026-04-29 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, armenon, Stefan Berger
Replace the 'once' variable with a check for whether the master flag is
set so that the flag can be set when needed.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
tests/qtest/qtest_aspeed.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/tests/qtest/qtest_aspeed.c b/tests/qtest/qtest_aspeed.c
index f6da9adea9..7bf5abb9be 100644
--- a/tests/qtest/qtest_aspeed.c
+++ b/tests/qtest/qtest_aspeed.c
@@ -15,18 +15,21 @@
#include "qtest_aspeed.h"
#include "hw/i2c/aspeed_i2c.h"
+static bool aspeed_i2c_is_master_enabled(QTestState *s, uint32_t baseaddr)
+{
+ return qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL) & A_I2CD_MASTER_EN;
+}
+
static void aspeed_i2c_startup(QTestState *s, uint32_t baseaddr,
uint8_t slave_addr, uint8_t reg)
{
uint32_t v;
- static int once;
- if (!once) {
+ if (!aspeed_i2c_is_master_enabled(s, baseaddr)) {
/* one time: enable master */
qtest_writel(s, baseaddr + A_I2CC_FUN_CTRL, 0);
v = qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL) | A_I2CD_MASTER_EN;
qtest_writel(s, baseaddr + A_I2CC_FUN_CTRL, v);
- once = 1;
}
/* select device */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 6/6] tests: Add a TPM TIS I2C swtpm test
2026-04-29 12:17 [PATCH v2 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
` (4 preceding siblings ...)
2026-04-29 12:17 ` [PATCH v2 5/6] tests: Check whether the I2C master flag is set Stefan Berger
@ 2026-04-29 12:17 ` Stefan Berger
5 siblings, 0 replies; 9+ messages in thread
From: Stefan Berger @ 2026-04-29 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, armenon, Stefan Berger
Add a test case testing the TPM TIS over I2C with swtpm.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Arun Menon <armenon@redhat.com>
---
tests/qtest/meson.build | 5 +-
tests/qtest/tpm-tis-i2c-swtpm-test.c | 82 ++++++++++++++++++++++++++++
tests/qtest/tpm-tis-i2c-util.c | 38 +++++++++++++
tests/qtest/tpm-tis-i2c-util.h | 4 ++
4 files changed, 127 insertions(+), 2 deletions(-)
create mode 100644 tests/qtest/tpm-tis-i2c-swtpm-test.c
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 823be192e7..1a94f20f7f 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -241,7 +241,7 @@ qtests_arm = \
(config_all_devices.has_key('CONFIG_ASPEED_SOC') ? qtests_aspeed : []) + \
(config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \
(config_all_devices.has_key('CONFIG_GENERIC_LOADER') ? ['hexloader-test'] : []) + \
- (config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \
+ (config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test', 'tpm-tis-i2c-swtpm-test'] : []) + \
(config_all_devices.has_key('CONFIG_VEXPRESS') ? ['test-arm-mptimer'] : []) + \
(config_all_devices.has_key('CONFIG_MICROBIT') ? ['microbit-test'] : []) + \
(config_all_devices.has_key('CONFIG_STM32L4X5_SOC') ? qtests_stm32l4x5 : []) + \
@@ -260,7 +260,7 @@ qtests_aarch64 = \
(config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test', 'xlnx-versal-trng-test'] : []) + \
(config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test', 'bcm2835-i2c-test'] : []) + \
(config_all_accel.has_key('CONFIG_TCG') and \
- config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test'] : []) + \
+ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test', 'tpm-tis-i2c-swtpm-test'] : []) + \
(config_all_devices.has_key('CONFIG_ASPEED_SOC') ? qtests_aspeed64 : []) + \
(config_all_devices.has_key('CONFIG_NPCM8XX') ? qtests_npcm8xx : []) + \
(config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
@@ -398,6 +398,7 @@ qtests = {
'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-i2c-test': [io, tpmemu_files, 'tpm-tis-i2c-util.c', 'qtest_aspeed.c'],
+ 'tpm-tis-i2c-swtpm-test': [io, tpmemu_files, 'tpm-tis-i2c-util.c', 'qtest_aspeed.c'],
'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],
'virtio-net-failover': test_migration_files,
diff --git a/tests/qtest/tpm-tis-i2c-swtpm-test.c b/tests/qtest/tpm-tis-i2c-swtpm-test.c
new file mode 100644
index 0000000000..50d32a960b
--- /dev/null
+++ b/tests/qtest/tpm-tis-i2c-swtpm-test.c
@@ -0,0 +1,82 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * QTest testcase for TPM TIS over I2C talking to external swtpm
+ *
+ * Copyright (c) 2018, 2026 IBM Corporation
+ * with parts borrowed from migration-test.c that is:
+ * Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+ *
+ * Authors:
+ * Stefan Berger <stefanb@linux.ibm.com>
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "libqtest.h"
+#include "qemu/module.h"
+#include "tpm-tests.h"
+#include "tpm-tis-i2c-util.h"
+#include "qtest_aspeed.h"
+
+typedef struct TestState {
+ char *src_tpm_path;
+ char *dst_tpm_path;
+ char *uri;
+ const char *machine_options;
+ char *ifmodel;
+} TestState;
+
+static void tpm_tis_i2c_swtpm_test(const void *data)
+{
+ const TestState *ts = data;
+
+ tpm_test_swtpm_test(ts->src_tpm_path, tpm_tis_i2c_transfer,
+ ts->ifmodel, ts->machine_options);
+}
+
+static void tpm_tis_swtpm_migration_test(const void *data)
+{
+ const TestState *ts = data;
+
+ tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path,
+ ts->uri, tpm_tis_i2c_transfer,
+ ts->ifmodel, ts->machine_options);
+}
+
+
+int main(int argc, char **argv)
+{
+ int ret;
+ TestState ts;
+
+ ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-i2c-swtpm-test.XXXXXX",
+ NULL);
+ ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-i2c-swtpm-test.XXXXXX",
+ NULL);
+ ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);
+ ts.machine_options = "-machine rainier-bmc -accel tcg";
+ ts.ifmodel = g_strdup_printf(
+ "tpm-tis-i2c,bus=aspeed.i2c.bus.%d,address=0x%x",
+ I2C_DEV_BUS_NUM, I2C_SLAVE_ADDR);
+
+ module_call_init(MODULE_INIT_QOM);
+ g_test_init(&argc, &argv, NULL);
+
+ aspeed_bus_addr = ast2600_i2c_calc_bus_addr(I2C_DEV_BUS_NUM);
+
+ qtest_add_data_func("/tpm/tis-i2c-swtpm/test", &ts, tpm_tis_i2c_swtpm_test);
+ qtest_add_data_func("/tpm/tis-i2c-swtpm-migration/test", &ts,
+ tpm_tis_swtpm_migration_test);
+ ret = g_test_run();
+
+ tpm_util_rmdir(ts.dst_tpm_path);
+ g_free(ts.dst_tpm_path);
+ tpm_util_rmdir(ts.src_tpm_path);
+ g_free(ts.src_tpm_path);
+ g_free(ts.uri);
+ g_free(ts.ifmodel);
+
+ return ret;
+}
diff --git a/tests/qtest/tpm-tis-i2c-util.c b/tests/qtest/tpm-tis-i2c-util.c
index 6e724a4a47..c73420ec5b 100644
--- a/tests/qtest/tpm-tis-i2c-util.c
+++ b/tests/qtest/tpm-tis-i2c-util.c
@@ -15,6 +15,7 @@
#include "libqtest-single.h"
#include "qtest_aspeed.h"
#include "tpm-tis-i2c-util.h"
+#include "tpm-emu.h"
uint32_t aspeed_bus_addr;
@@ -62,3 +63,40 @@ void tpm_tis_i2c_writel(QTestState *s, uint8_t locty, uint8_t reg, uint32_t v)
}
aspeed_i2c_writel(s, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);
}
+
+void tpm_tis_i2c_transfer(QTestState *s,
+ const unsigned char *req, size_t req_size,
+ unsigned char *rsp, size_t rsp_size)
+{
+ uint32_t sts;
+ size_t i;
+
+ /* request use of locality 0 */
+ tpm_tis_i2c_writeb(s, 0, TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_REQUEST_USE);
+
+ tpm_tis_i2c_writel(s, 0, TPM_I2C_REG_STS, TPM_TIS_STS_COMMAND_READY);
+
+ /* transmit command */
+ for (i = 0; i < req_size; i++) {
+ tpm_tis_i2c_writeb(s, 0, TPM_I2C_REG_DATA_FIFO, req[i]);
+ }
+
+ /* start processing */
+ tpm_tis_i2c_writeb(s, 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(s, 0, TPM_I2C_REG_STS);
+ if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
+ break;
+ }
+ } while (g_get_monotonic_time() < end_time);
+
+ /* read response */
+ for (i = 0; i < rsp_size; i++) {
+ rsp[i] = tpm_tis_i2c_readb(s, 0, TPM_I2C_REG_DATA_FIFO);
+ }
+ /* relinquish use of locality 0 */
+ tpm_tis_i2c_writeb(s, 0,
+ TPM_I2C_REG_ACCESS, TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+}
diff --git a/tests/qtest/tpm-tis-i2c-util.h b/tests/qtest/tpm-tis-i2c-util.h
index 3289545f61..499bf4964a 100644
--- a/tests/qtest/tpm-tis-i2c-util.h
+++ b/tests/qtest/tpm-tis-i2c-util.h
@@ -27,4 +27,8 @@ uint32_t tpm_tis_i2c_readl(QTestState *s, uint8_t locty, uint8_t reg);
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);
+void tpm_tis_i2c_transfer(QTestState *s,
+ const unsigned char *req, size_t req_size,
+ unsigned char *rsp, size_t rsp_size);
+
#endif /* TESTS_TPM_TIS_I2C_UTIL_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/6] tests: Convert string arrays to byte arrays
2026-04-29 12:17 ` [PATCH v2 3/6] tests: Convert string arrays to byte arrays Stefan Berger
@ 2026-04-29 13:12 ` Arun Menon
0 siblings, 0 replies; 9+ messages in thread
From: Arun Menon @ 2026-04-29 13:12 UTC (permalink / raw)
To: Stefan Berger; +Cc: qemu-devel, marcandre.lureau
Hi,
On Wed, Apr 29, 2026 at 12:17:40PM +0000, Stefan Berger wrote:
> Convert the TPM command and response string arrays to byte arrays.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> tests/qtest/tpm-tests.c | 30 ++++++++++++++++++---------
> tests/qtest/tpm-util.c | 45 ++++++++++++++++++++++++++---------------
> 2 files changed, 49 insertions(+), 26 deletions(-)
>
> diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
> index 197714f8d9..8bd3288f80 100644
> --- a/tests/qtest/tpm-tests.c
> +++ b/tests/qtest/tpm-tests.c
> @@ -59,11 +59,16 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
> tpm_util_startup(s, tx);
> tpm_util_pcrextend(s, tx);
>
> - static const unsigned char tpm_pcrread_resp[] =
> - "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> - "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> - "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> - "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
> + static const unsigned char tpm_pcrread_resp[] = {
> + 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
> + 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
> + 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
> + 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
> + 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
> + 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
> + 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde
> + };
> tpm_util_pcrread(s, tx, tpm_pcrread_resp,
> sizeof(tpm_pcrread_resp));
>
> @@ -105,11 +110,16 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
> tpm_util_startup(src_qemu, tx);
> tpm_util_pcrextend(src_qemu, tx);
>
> - static const unsigned char tpm_pcrread_resp[] =
> - "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> - "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> - "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> - "\xa4\x2f\x9a\xae\xa8\xc7\xb7\xaa\x79\xa8\x62\x56\xc1\xde";
> + static const unsigned char tpm_pcrread_resp[] = {
> + 0x80, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00,
> + 0x00, 0x01, 0x00, 0x0b, 0x03, 0x00, 0x04, 0x00,
> + 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0xf6, 0x85,
> + 0x98, 0xe5, 0x86, 0x8d, 0xe6, 0x8b, 0x97, 0x29,
> + 0x99, 0x60, 0xf2, 0x71, 0x7d, 0x17, 0x67, 0x89,
> + 0xa4, 0x2f, 0x9a, 0xae, 0xa8, 0xc7, 0xb7, 0xaa,
> + 0x79, 0xa8, 0x62, 0x56, 0xc1, 0xde,
> + };
> tpm_util_pcrread(src_qemu, tx, tpm_pcrread_resp,
> sizeof(tpm_pcrread_resp));
>
> diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
> index 2cb2dd4796..63cd5b69db 100644
> --- a/tests/qtest/tpm-util.c
> +++ b/tests/qtest/tpm-util.c
> @@ -54,10 +54,14 @@ void tpm_util_crb_transfer(QTestState *s,
> void tpm_util_startup(QTestState *s, tx_func *tx)
> {
> unsigned char buffer[1024];
> - static const unsigned char tpm_startup[] =
> - "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
> - static const unsigned char tpm_startup_resp[] =
> - "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
> + static const unsigned char tpm_startup[] = {
> + 0x80, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00,
> + 0x01, 0x44, 0x00, 0x00
> + };
> + static const unsigned char tpm_startup_resp[] = {
> + 0x80, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
> + 0x00, 0x00
> + };
>
> tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
>
> @@ -68,16 +72,23 @@ void tpm_util_startup(QTestState *s, tx_func *tx)
> void tpm_util_pcrextend(QTestState *s, tx_func *tx)
> {
> unsigned char buffer[1024];
> - static const unsigned char tpm_pcrextend[] =
> - "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
> - "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
> - "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
> - "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
> - "\x00";
> + static const unsigned char tpm_pcrextend[] = {
> + 0x80, 0x02, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
> + 0x01, 0x82, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00,
> + 0x00, 0x09, 0x40, 0x00, 0x00, 0x09, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
> + 0x0b, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00
> + };
>
> - static const unsigned char tpm_pcrextend_resp[] =
> - "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
> - "\x01\x00\x00";
> + static const unsigned char tpm_pcrextend_resp[] = {
> + 0x80, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x01, 0x00, 0x00
> + };
>
> tx(s, tpm_pcrextend, sizeof(tpm_pcrextend), buffer, sizeof(buffer));
>
> @@ -89,9 +100,11 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
> const unsigned char *exp_resp, size_t exp_resp_size)
> {
> unsigned char buffer[1024];
> - static const unsigned char tpm_pcrread[] =
> - "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
> - "\x03\x00\x04\x00";
> + static const unsigned char tpm_pcrread[] = {
> + 0x80, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
> + 0x01, 0x7e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0b,
> + 0x03, 0x00, 0x04, 0x00
> + };
>
> tx(s, tpm_pcrread, sizeof(tpm_pcrread), buffer, sizeof(buffer));
>
> --
> 2.43.0
>
Reviewed-by: Arun Menon <armenon@redhat.com>
Regards,
Arun Menon
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 5/6] tests: Check whether the I2C master flag is set
2026-04-29 12:17 ` [PATCH v2 5/6] tests: Check whether the I2C master flag is set Stefan Berger
@ 2026-04-29 13:13 ` Arun Menon
0 siblings, 0 replies; 9+ messages in thread
From: Arun Menon @ 2026-04-29 13:13 UTC (permalink / raw)
To: Stefan Berger; +Cc: qemu-devel, marcandre.lureau
Hi,
On Wed, Apr 29, 2026 at 12:17:42PM +0000, Stefan Berger wrote:
> Replace the 'once' variable with a check for whether the master flag is
> set so that the flag can be set when needed.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> tests/qtest/qtest_aspeed.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/tests/qtest/qtest_aspeed.c b/tests/qtest/qtest_aspeed.c
> index f6da9adea9..7bf5abb9be 100644
> --- a/tests/qtest/qtest_aspeed.c
> +++ b/tests/qtest/qtest_aspeed.c
> @@ -15,18 +15,21 @@
> #include "qtest_aspeed.h"
> #include "hw/i2c/aspeed_i2c.h"
>
> +static bool aspeed_i2c_is_master_enabled(QTestState *s, uint32_t baseaddr)
> +{
> + return qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL) & A_I2CD_MASTER_EN;
> +}
> +
> static void aspeed_i2c_startup(QTestState *s, uint32_t baseaddr,
> uint8_t slave_addr, uint8_t reg)
> {
> uint32_t v;
> - static int once;
>
> - if (!once) {
> + if (!aspeed_i2c_is_master_enabled(s, baseaddr)) {
> /* one time: enable master */
> qtest_writel(s, baseaddr + A_I2CC_FUN_CTRL, 0);
> v = qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL) | A_I2CD_MASTER_EN;
> qtest_writel(s, baseaddr + A_I2CC_FUN_CTRL, v);
> - once = 1;
> }
>
> /* select device */
> --
> 2.43.0
>
Reviewed-by: Arun Menon <armenon@redhat.com>
Regards,
Arun Menon
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-04-29 13:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-29 12:17 [PATCH v2 0/6] Add test case for TPM over I2C with swtpm Stefan Berger
2026-04-29 12:17 ` [PATCH v2 1/6] tests: Move TPM I2C bus read/write functions to common files Stefan Berger
2026-04-29 12:17 ` [PATCH v2 2/6] tests: Have TPM I2C read/write functions take QTestState as first parameter Stefan Berger
2026-04-29 12:17 ` [PATCH v2 3/6] tests: Convert string arrays to byte arrays Stefan Berger
2026-04-29 13:12 ` Arun Menon
2026-04-29 12:17 ` [PATCH v2 4/6] tests: Rename id of tpmdev to tpm0 Stefan Berger
2026-04-29 12:17 ` [PATCH v2 5/6] tests: Check whether the I2C master flag is set Stefan Berger
2026-04-29 13:13 ` Arun Menon
2026-04-29 12:17 ` [PATCH v2 6/6] tests: Add a TPM TIS I2C swtpm test Stefan Berger
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.