Add test case for TPM over I2C with swtpm
Subsystems (2)
cover Add test case for TPM over I2C with swtpm
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
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: Set sizes for arrays of expected TPM responses and requests
tests: Rename id of tpmdev to tpm0
tests: Implement aspeed_i2c_restart to reenable selection of master
tests: Add a TPM TIS I2C swtpm test
tests/qtest/meson.build | 7 +- tests/qtest/qtest_aspeed.c | 8 +- tests/qtest/qtest_aspeed.h | 2 + tests/qtest/tpm-tests.c | 8 +- tests/qtest/tpm-tis-i2c-swtpm-test.c | 86 +++++++++++ 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 | 18 +-- 9 files changed, 338 insertions(+), 148 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
Signature · 1 line
2.43.0
PATCH 1/6 tests: Move TPM I2C bus read/write functions to common files
Move functions for reading from and writing to the Aspeed I2C device into a file so they can be reused by other functions.
--- 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
tests/qtest/meson.build +1 -1
@@ -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,
tests/qtest/tpm-tis-i2c-test.c +1 -49
65 lines not on this page · raw message
tests/qtest/tpm-tis-i2c-util.c new file +64 -0
64 lines not on this page · raw message
tests/qtest/tpm-tis-i2c-util.h new file +30 -0
@@ -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 <[email protected]> +* +*/ + +#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 */
Signature · 1 line
2.43.0
Re: [PATCH 1/6] tests: Move TPM I2C bus read/write functions to common files
Quoted 207 lines · 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 <[email protected]>--- 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.htests/qtest/meson.build +1
-1@@ -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,tests/qtest/tpm-tis-i2c-test.c +1
-49@@ -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) {tests/qtest/tpm-tis-i2c-util.c new file +64
-0@@ -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 <[email protected]> +* +*/ + +#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); +}tests/qtest/tpm-tis-i2c-util.h new file +30
-0@@ -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 <[email protected]> +* +*/ + +#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 */ Signature · 1 line
2.43.0
Looks good to me.
PATCH 2/6 tests: Have TPM I2C read/write functions take QTestState as first parameter
In reply to Stefan BergerPass the QTestState as first parameter to the TPM I2C functions. Use global_qtest in existing test cases.
--- 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(-)
tests/qtest/tpm-tis-i2c-test.c +89 -82
@@ -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)
tests/qtest/tpm-tis-i2c-util.c +16 -16
@@ -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); }
tests/qtest/tpm-tis-i2c-util.h +5 -5
@@ -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 */
Signature · 1 line
2.43.0
Re: [PATCH 2/6] tests: Have TPM I2C read/write functions take QTestState as first parameter
Hi,
Quoted 600 lines · Stefan Berger
Pass the QTestState as first parameter to the TPM I2C functions. Use
global_qtestin existing test cases.Signed-off-by Stefan Berger <[email protected]>--- 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(-)tests/qtest/tpm-tis-i2c-test.c +89
-82@@ -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)tests/qtest/tpm-tis-i2c-util.c +16
-16@@ -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); }tests/qtest/tpm-tis-i2c-util.h +5
-5@@ -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 */ Signature · 1 line
2.43.0
Regards,
Arun Menon
PATCH 3/6 tests: Set sizes for arrays of expected TPM responses and requests
In reply to Stefan BergerSet the sizes of byte arrays holding TPM requests and responses to avoid a terminating NUL byte to be added and to only compare the expected part of responses.
--- tests/qtest/tpm-tests.c | 4 ++-- tests/qtest/tpm-util.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-)
tests/qtest/tpm-tests.c +2 -2
@@ -59,7 +59,7 @@ 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[] = +static const unsigned char tpm_pcrread_resp[62 ] ="\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"
@@ -105,7 +105,7 @@ 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[] = +static const unsigned char tpm_pcrread_resp[62 ] ="\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"
tests/qtest/tpm-util.c +5 -5
@@ -54,9 +54,9 @@ 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[] = +static const unsigned char tpm_startup[12 ] ="\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00" ; -static const unsigned char tpm_startup_resp[] = +static const unsigned char tpm_startup_resp[10 ] ="\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00" ;tx (s, tpm_startup,sizeof (tpm_startup), buffer,sizeof (buffer));
@@ -68,14 +68,14 @@ 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[] = +static const unsigned char tpm_pcrextend[65 ] ="\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_resp[] = +static const unsigned char tpm_pcrextend_resp[19 ] ="\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x01\x00\x00" ;
@@ -89,7 +89,7 @@ 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[] = +static const unsigned char tpm_pcrread[20 ] ="\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b" "\x03\x00\x04\x00" ;
Signature · 1 line
2.43.0
Re: [PATCH 3/6] tests: Set sizes for arrays of expected TPM responses and requests
Hi,
Quoted 15 lines · Stefan Berger
Set the sizes of byte arrays holding TPM requests and responses to avoid a terminating NUL byte to be added and to only compare the expected part of responses.
Signed-off-by Stefan Berger <[email protected]>--- tests/qtest/tpm-tests.c | 4 ++-- tests/qtest/tpm-util.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-)tests/qtest/tpm-tests.c +0
-0
tests/qtest/tpm-tests.c void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx, · line 65
Quoted 8 lines
tests/qtest/tpm-tests.c +1
-1@@ -59,7 +59,7 @@ 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[] = +static const unsigned char tpm_pcrread_resp[62 ] ="\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"
Can we define it as an initializer list instead of a string literal like below?
static const unsigned char tpm_pcrread_resp[] = {0x80, 0x01, 0x00, 0x00,...};
This one avoids the null terminator.
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};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[] =
{0x80,0x02,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00};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};Quoted 54 lines
tests/qtest/tpm-tests.c +1
-1@@ -105,7 +105,7 @@ 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[] = +static const unsigned char tpm_pcrread_resp[62 ] ="\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" tests/qtest/tpm-util.c +5
-5@@ -54,9 +54,9 @@ 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[] = +static const unsigned char tpm_startup[12 ] ="\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00" ; -static const unsigned char tpm_startup_resp[] = +static const unsigned char tpm_startup_resp[10 ] ="\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00" ;tx (s, tpm_startup,sizeof (tpm_startup), buffer,sizeof (buffer));@@ -68,14 +68,14 @@ 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[] = +static const unsigned char tpm_pcrextend[65 ] ="\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_resp[] = +static const unsigned char tpm_pcrextend_resp[19 ] ="\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x01\x00\x00" ;@@ -89,7 +89,7 @@ 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[] = +static const unsigned char tpm_pcrread[20 ] ="\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b" "\x03\x00\x04\x00" ;Signature · 1 line
2.43.0
Regards,
Arun Menon
PATCH 4/6 tests: Rename id of tpmdev to tpm0
In reply to Stefan BergerRename the id of the tpmdev from dev to tpm0 because this 'dev' cannot be used when the tpm-tis-i2c device is used.
--- tests/qtest/tpm-tests.c | 4 ++-- tests/qtest/tpm-util.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)
tests/qtest/tpm-tests.c +2 -2
@@ -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);
tests/qtest/tpm-util.c +4 -4
@@ -227,8 +227,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);
@@ -236,8 +236,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,
Signature · 1 line
2.43.0
Re: [PATCH 4/6] tests: Rename id of tpmdev to tpm0
Hi,
Quoted 54 lines · 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 <[email protected]>--- tests/qtest/tpm-tests.c | 4 ++-- tests/qtest/tpm-util.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-)tests/qtest/tpm-tests.c +2
-2@@ -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);tests/qtest/tpm-util.c +4
-4@@ -227,8 +227,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);@@ -236,8 +236,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,Signature · 1 line
2.43.0
Regards,
Arun Menon
PATCH 5/6 tests: Implement aspeed_i2c_restart to reenable selection of master
In reply to Stefan BergerFor some TPM I2C tests it is important to be able to reenable the selection of the master. Implement aspeed_i2c_restart to enable this.
--- tests/qtest/qtest_aspeed.c | 8 +++++++- tests/qtest/qtest_aspeed.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-)
tests/qtest/qtest_aspeed.c +7 -1
@@ -15,11 +15,17 @@#include "qtest_aspeed.h" #include "hw/i2c/aspeed_i2c.h" +static int once; + +void aspeed_i2c_restart (void ) +{ + once = false; +} +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) {/* one time: enable master */
tests/qtest/qtest_aspeed.h +2 -0
@@ -23,6 +23,8 @@ static inline uint32_t ast2600_i2c_calc_bus_addr(uint8_t bus_num)return AST2600_ASPEED_I2C_BASE_ADDR +0x80 + bus_num *0x80 ; } +void aspeed_i2c_restart (void ); +uint8_t aspeed_i2c_readb (QTestState *s,uint32_t baseaddr,uint8_t slave_addr,uint8_t reg); uint16_t aspeed_i2c_readw(QTestState *s,
Signature · 1 line
2.43.0
Re: [PATCH 5/6] tests: Implement aspeed_i2c_restart to reenable selection of master
Hi,
Quoted 14 lines · Stefan Berger
For some TPM I2C tests it is important to be able to reenable the selection of the master. Implement
aspeed_i2c_restartto enable this.Signed-off-by Stefan Berger <[email protected]>--- tests/qtest/qtest_aspeed.c | 8 +++++++- tests/qtest/qtest_aspeed.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-)tests/qtest/qtest_aspeed.c +0
-0
tests/qtest/qtest_aspeed.c line 18
Quoted 4 lines
tests/qtest/qtest_aspeed.c +1
-0@@ -15,11 +15,17 @@#include "qtest_aspeed.h" #include "hw/i2c/aspeed_i2c.h" +static int once;
can we make this a boolean?
tests/qtest/qtest_aspeed.c line 22
Quoted 11 lines
tests/qtest/qtest_aspeed.c +6
-1+ +void aspeed_i2c_restart (void ) +{ + once = false; +} +static void aspeed_i2c_startup (QTestState *s,uint32_t baseaddr,uint8_t slave_addr,uint8_t reg) {uint32_t v; -static int once;
Can we check if the A_I2CD_MASTER_EN bit is set directly without having the need to store a global static variable? For example:
static bool is_aspeed_i2c_master_enabled(QTestState *s, uint32_t baseaddr)
{
uint32_t reg_val;
return ((qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL)
& A_I2CD_MASTER_EN) != 0);
}Quoted 1 line
and use it here:
Quoted 1 line
if (!once) {if (!is_aspeed_i2c_master_enabled(s, baseaddr)) {
for restarts, we can directly write to the register
qtest_writel(s, bus_addr + A_I2CC_FUN_CTRL, 0);
and the subsequent call to aspeed_i2c_startup() will handle the init properly.
Quoted 17 lines
/* one time: enable master */tests/qtest/qtest_aspeed.h +2
-0@@ -23,6 +23,8 @@ static inline uint32_t ast2600_i2c_calc_bus_addr(uint8_t bus_num)return AST2600_ASPEED_I2C_BASE_ADDR +0x80 + bus_num *0x80 ; } +void aspeed_i2c_restart (void ); +uint8_t aspeed_i2c_readb (QTestState *s,uint32_t baseaddr,uint8_t slave_addr,uint8_t reg); uint16_t aspeed_i2c_readw(QTestState *s,Signature · 1 line
2.43.0
Regards,
Arun Menon
Re: [PATCH 5/6] tests: Implement aspeed_i2c_restart to reenable selection of master
Quoted 47 lines · Arun Menon
Hi,
Quoted 14 lines · Stefan Berger
For some TPM I2C tests it is important to be able to reenable the selection of the master. Implement
aspeed_i2c_restartto enable this.Signed-off-by Stefan Berger <[email protected]>--- tests/qtest/qtest_aspeed.c | 8 +++++++- tests/qtest/qtest_aspeed.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-)tests/qtest/qtest_aspeed.c +0
-0tests/qtest/qtest_aspeed.c line 18
Quoted 4 lines
tests/qtest/qtest_aspeed.c +1
-0@@ -15,11 +15,17 @@#include "qtest_aspeed.h" #include "hw/i2c/aspeed_i2c.h" +static int once;can we make this a boolean?
tests/qtest/qtest_aspeed.c line 22
Quoted 11 lines
tests/qtest/qtest_aspeed.c +6
-1+ +void aspeed_i2c_restart (void ) +{ + once = false; +} +static void aspeed_i2c_startup (QTestState *s,uint32_t baseaddr,uint8_t slave_addr,uint8_t reg) {uint32_t v; -static int once;Can we check if the
A_I2CD_MASTER_ENbit is set directly without having the need to store a global static variable? For example:static bool
is_aspeed_i2c_master_enabled(QTestState *s, uint32_t baseaddr){ uint32_t reg_val; return ((qtest_readl(s, baseaddr + A_I2CC_FUN_CTRL) & A_I2CD_MASTER_EN) != 0); }Quoted 1 line
Quoted 8 lines
and use it here:
Quoted 1 line
if (!once) {if (!is_aspeed_i2c_master_enabled(s, baseaddr)) {
for restarts, we can directly write to the register
qtest_writel(s, bus_addr + A_I2CC_FUN_CTRL, 0);
and the subsequent call toaspeed_i2c_startup()will handle the init properly.
Yes, that's better. Thanks.
Quoted 1 line
PATCH 6/6 tests: Add a TPM TIS I2C swtpm test
In reply to Stefan BergerAdd a test case testing the TPM TIS over I2C with swtpm.
--- tests/qtest/meson.build | 5 +- tests/qtest/tpm-tis-i2c-swtpm-test.c | 86 ++++++++++++++++++++++++++++ tests/qtest/tpm-tis-i2c-util.c | 38 ++++++++++++ tests/qtest/tpm-tis-i2c-util.h | 4 ++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/tpm-tis-i2c-swtpm-test.c
tests/qtest/meson.build +3 -2
@@ -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,
tests/qtest/tpm-tis-i2c-swtpm-test.c new file +86 -0
86 lines not on this page · raw message
tests/qtest/tpm-tis-i2c-util.c +38 -0
@@ -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 ); +}
tests/qtest/tpm-tis-i2c-util.h +4 -0
@@ -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 */
Signature · 1 line
2.43.0
Re: [PATCH 6/6] tests: Add a TPM TIS I2C swtpm test
Quoted 202 lines · Stefan Berger
Add a test case testing the TPM TIS over I2C with swtpm.
Signed-off-by Stefan Berger <[email protected]>--- tests/qtest/meson.build | 5 +- tests/qtest/tpm-tis-i2c-swtpm-test.c | 86 ++++++++++++++++++++++++++++ tests/qtest/tpm-tis-i2c-util.c | 38 ++++++++++++ tests/qtest/tpm-tis-i2c-util.h | 4 ++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 tests/qtest/tpm-tis-i2c-swtpm-test.ctests/qtest/meson.build +3
-2@@ -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,tests/qtest/tpm-tis-i2c-swtpm-test.c new file +86
-0@@ -0,0 +1,86 @@ +/* +* 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 <[email protected]> +* +*/ + +#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; + +aspeed_i2c_restart (); + +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; + +aspeed_i2c_restart (); + +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; +}tests/qtest/tpm-tis-i2c-util.c +38
-0@@ -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 ); +}tests/qtest/tpm-tis-i2c-util.h +4
-0@@ -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 */ Signature · 1 line
2.43.0
Regards,
Arun Menon