All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Stefan Berger <stefanb@linux.ibm.com>,
	Arun Menon <armenon@redhat.com>
Subject: [PULL v1 01/16] tests: Move TPM I2C bus read/write functions to common files
Date: Mon,  1 Jun 2026 17:53:54 -0400	[thread overview]
Message-ID: <20260601215410.517009-2-stefanb@linux.ibm.com> (raw)
In-Reply-To: <20260601215410.517009-1-stefanb@linux.ibm.com>

Move functions for reading from and writing to the Aspeed I2C device into
a file so they can be reused by other functions.

Reviewed-by: Arun Menon <armenon@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260429121743.1346635-2-stefanb@linux.ibm.com
Signed-off-by: Stefan Berger <stefanb@linux.ibm.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 728dde54b3..57512c6e56 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -401,7 +401,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.54.0



  reply	other threads:[~2026-06-01 21:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 21:53 [PULL v1 00/16] Merge tpm 2026/06/01 v1 Stefan Berger
2026-06-01 21:53 ` Stefan Berger [this message]
2026-06-01 21:53 ` [PULL v1 02/16] tests: Have TPM I2C read/write functions take QTestState as first parameter Stefan Berger
2026-06-01 21:53 ` [PULL v1 03/16] tests: Convert string arrays to byte arrays Stefan Berger
2026-06-01 21:53 ` [PULL v1 04/16] tests: Rename id of tpmdev to tpm0 Stefan Berger
2026-06-01 21:53 ` [PULL v1 05/16] tests: Check whether the I2C master flag is set Stefan Berger
2026-06-01 21:53 ` [PULL v1 06/16] tests: Add a TPM TIS I2C swtpm test Stefan Berger
2026-06-01 21:54 ` [PULL v1 07/16] migration/vmstate: Add VMState support for GByteArray Stefan Berger
2026-06-01 21:54 ` [PULL v1 08/16] ui/vdagent: Use VMSTATE_GBYTEARRAY to safely migrate outbuf Stefan Berger
2026-06-01 21:54 ` [PULL v1 09/16] hw/tpm: Add TPM CRB chunking fields Stefan Berger
2026-06-01 21:54 ` [PULL v1 10/16] hw/tpm: Refactor CRB_CTRL_START register access Stefan Berger
2026-06-01 21:54 ` [PULL v1 11/16] hw/tpm: Add internal buffer state for chunking Stefan Berger
2026-06-01 21:54 ` [PULL v1 12/16] hw/tpm: Implement TPM CRB chunking logic Stefan Berger
2026-06-01 21:54 ` [PULL v1 13/16] test/qtest: Add test for tpm crb chunking Stefan Berger
2026-06-01 21:54 ` [PULL v1 14/16] hw/tpm: Add support for VM migration with TPM CRB chunking Stefan Berger
2026-06-01 21:54 ` [PULL v1 15/16] tpm_emulator: Reject a buffer size different than what was requested Stefan Berger
2026-06-01 21:54 ` [PULL v1 16/16] tpm_emulator: Disconnect if response exceeds negotiated buffer size Stefan Berger
2026-06-02 17:23 ` [PULL v1 00/16] Merge tpm 2026/06/01 v1 Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260601215410.517009-2-stefanb@linux.ibm.com \
    --to=stefanb@linux.ibm.com \
    --cc=armenon@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.