[{"id":3684005,"web_url":"http://patchwork.ozlabs.org/comment/3684005/","msgid":"<afHrpQWu6mRkehxh@fedora>","list_archive_url":null,"date":"2026-04-29T11:29:41","subject":"Re: [PATCH 1/6] tests: Move TPM I2C bus read/write functions to\n common files","submitter":{"id":91136,"url":"http://patchwork.ozlabs.org/api/people/91136/","name":"Arun Menon","email":"armenon@redhat.com"},"content":"On Tue, Apr 28, 2026 at 01:07:13PM +0000, Stefan Berger wrote:\n> Move functions for reading from and writing to the Aspeed I2C device into\n> a file so they can be reused by other functions.\n> \n> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>\n> ---\n>  tests/qtest/meson.build        |  2 +-\n>  tests/qtest/tpm-tis-i2c-test.c | 50 +-------------------------\n>  tests/qtest/tpm-tis-i2c-util.c | 64 ++++++++++++++++++++++++++++++++++\n>  tests/qtest/tpm-tis-i2c-util.h | 30 ++++++++++++++++\n>  4 files changed, 96 insertions(+), 50 deletions(-)\n>  create mode 100644 tests/qtest/tpm-tis-i2c-util.c\n>  create mode 100644 tests/qtest/tpm-tis-i2c-util.h\n> \n> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build\n> index b735f55fc4..823be192e7 100644\n> --- a/tests/qtest/meson.build\n> +++ b/tests/qtest/meson.build\n> @@ -397,7 +397,7 @@ qtests = {\n>    'tpm-crb-test': [io, tpmemu_files],\n>    'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],\n>    'tpm-tis-test': [io, tpmemu_files, 'tpm-tis-util.c'],\n> -  'tpm-tis-i2c-test': [io, tpmemu_files, 'qtest_aspeed.c'],\n> +  'tpm-tis-i2c-test': [io, tpmemu_files, 'tpm-tis-i2c-util.c', 'qtest_aspeed.c'],\n>    'tpm-tis-device-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'],\n>    'tpm-tis-device-test': [io, tpmemu_files, 'tpm-tis-util.c'],\n>    'virtio-net-failover': test_migration_files,\n> diff --git a/tests/qtest/tpm-tis-i2c-test.c b/tests/qtest/tpm-tis-i2c-test.c\n> index 3a1af026f2..02ddf76c2c 100644\n> --- a/tests/qtest/tpm-tis-i2c-test.c\n> +++ b/tests/qtest/tpm-tis-i2c-test.c\n> @@ -20,6 +20,7 @@\n>  #include \"hw/pci/pci_ids.h\"\n>  #include \"qtest_aspeed.h\"\n>  #include \"tpm-emu.h\"\n> +#include \"tpm-tis-i2c-util.h\"\n>  \n>  #define DEBUG_TIS_TEST 0\n>  \n> @@ -36,58 +37,9 @@\n>  #define DPRINTF_STS \\\n>      DPRINTF(\"%s: %d: sts = 0x%08x\\n\", __func__, __LINE__, sts)\n>  \n> -#define I2C_SLAVE_ADDR   0x2e\n> -#define I2C_DEV_BUS_NUM  10\n> -\n>  static const uint8_t TPM_CMD[12] =\n>      \"\\x80\\x01\\x00\\x00\\x00\\x0c\\x00\\x00\\x01\\x44\\x00\\x00\";\n>  \n> -static uint32_t aspeed_bus_addr;\n> -\n> -static uint8_t cur_locty = 0xff;\n> -\n> -static void tpm_tis_i2c_set_locty(uint8_t locty)\n> -{\n> -    if (cur_locty != locty) {\n> -        cur_locty = locty;\n> -        aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR,\n> -                          TPM_I2C_REG_LOC_SEL, locty);\n> -    }\n> -}\n> -\n> -static uint8_t tpm_tis_i2c_readb(uint8_t locty, uint8_t reg)\n> -{\n> -    tpm_tis_i2c_set_locty(locty);\n> -    return aspeed_i2c_readb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);\n> -}\n> -\n> -static uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg)\n> -{\n> -    tpm_tis_i2c_set_locty(locty);\n> -    return aspeed_i2c_readw(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);\n> -}\n> -\n> -static uint32_t tpm_tis_i2c_readl(uint8_t locty, uint8_t reg)\n> -{\n> -    tpm_tis_i2c_set_locty(locty);\n> -    return aspeed_i2c_readl(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);\n> -}\n> -\n> -static void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v)\n> -{\n> -    if (reg != TPM_I2C_REG_LOC_SEL) {\n> -        tpm_tis_i2c_set_locty(locty);\n> -    }\n> -    aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);\n> -}\n> -\n> -static void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v)\n> -{\n> -    if (reg != TPM_I2C_REG_LOC_SEL) {\n> -        tpm_tis_i2c_set_locty(locty);\n> -    }\n> -    aspeed_i2c_writel(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);\n> -}\n>  \n>  static void tpm_tis_i2c_test_basic(const void *data)\n>  {\n> diff --git a/tests/qtest/tpm-tis-i2c-util.c b/tests/qtest/tpm-tis-i2c-util.c\n> new file mode 100644\n> index 0000000000..07b1eeba69\n> --- /dev/null\n> +++ b/tests/qtest/tpm-tis-i2c-util.c\n> @@ -0,0 +1,64 @@\n> +/*\n> + * SPDX-License-Identifier: GPL-2.0-or-later\n> + *\n> + * QTest utilities for TPM TIS over I2C\n> + *\n> + * Copyright (c) 2018, 2026 IBM Corporation\n> + *\n> + * Authors:\n> + *   Stefan Berger <stefanb@linux.ibm.com>\n> + *\n> + */\n> +\n> +#include \"qemu/osdep.h\"\n> +#include \"hw/acpi/tpm.h\"\n> +#include \"libqtest-single.h\"\n> +#include \"qtest_aspeed.h\"\n> +#include \"tpm-tis-i2c-util.h\"\n> +\n> +uint32_t aspeed_bus_addr;\n> +\n> +static uint8_t cur_locty = 0xff;\n> +\n> +static void tpm_tis_i2c_set_locty(uint8_t locty)\n> +{\n> +    if (cur_locty != locty) {\n> +        cur_locty = locty;\n> +        aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR,\n> +                          TPM_I2C_REG_LOC_SEL, locty);\n> +    }\n> +}\n> +\n> +uint8_t tpm_tis_i2c_readb(uint8_t locty, uint8_t reg)\n> +{\n> +    tpm_tis_i2c_set_locty(locty);\n> +    return aspeed_i2c_readb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);\n> +}\n> +\n> +uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg)\n> +{\n> +    tpm_tis_i2c_set_locty(locty);\n> +    return aspeed_i2c_readw(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);\n> +}\n> +\n> +uint32_t tpm_tis_i2c_readl(uint8_t locty, uint8_t reg)\n> +{\n> +    tpm_tis_i2c_set_locty(locty);\n> +    return aspeed_i2c_readl(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg);\n> +}\n> +\n> +void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v)\n> +{\n> +    if (reg != TPM_I2C_REG_LOC_SEL) {\n> +        tpm_tis_i2c_set_locty(locty);\n> +    }\n> +    aspeed_i2c_writeb(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);\n> +}\n> +\n> +void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v)\n> +{\n> +    if (reg != TPM_I2C_REG_LOC_SEL) {\n> +        tpm_tis_i2c_set_locty(locty);\n> +    }\n> +    aspeed_i2c_writel(global_qtest, aspeed_bus_addr, I2C_SLAVE_ADDR, reg, v);\n> +}\n> diff --git a/tests/qtest/tpm-tis-i2c-util.h b/tests/qtest/tpm-tis-i2c-util.h\n> new file mode 100644\n> index 0000000000..dfe626b43d\n> --- /dev/null\n> +++ b/tests/qtest/tpm-tis-i2c-util.h\n> @@ -0,0 +1,30 @@\n> +/*\n> + * SPDX-License-Identifier: GPL-2.0-or-later\n> + *\n> + * QTest TPM TIS I2C: Common test functions used for TPM I2C on Aspeed bus\n> + *\n> + * Copyright (c) 2026 IBM Corporation\n> + *\n> + * Authors:\n> + *   Stefan Berger <stefanb@linux.ibm.com>\n> + *\n> + */\n> +\n> +#ifndef TESTS_TPM_TIS_I2C_UTIL_H\n> +#define TESTS_TPM_TIS_I2C_UTIL_H\n> +\n> +#include \"qemu/osdep.h\"\n> +\n> +extern uint32_t aspeed_bus_addr;\n> +\n> +#define I2C_SLAVE_ADDR   0x2e\n> +#define I2C_DEV_BUS_NUM  10\n> +\n> +uint8_t tpm_tis_i2c_readb(uint8_t locty, uint8_t reg);\n> +uint16_t tpm_tis_i2c_readw(uint8_t locty, uint8_t reg);\n> +uint32_t tpm_tis_i2c_readl(uint8_t locty, uint8_t reg);\n> +\n> +void tpm_tis_i2c_writeb(uint8_t locty, uint8_t reg, uint8_t v);\n> +void tpm_tis_i2c_writel(uint8_t locty, uint8_t reg, uint32_t v);\n> +\n> +#endif /* TESTS_TPM_TIS_I2C_UTIL_H */\n> -- \n> 2.43.0\n> \n> \nLooks good to me.\n\nReviewed-by: Arun Menon <armenon@redhat.com>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=YPLTkgKq;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=MkvQDw8p;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g5FTP1b2Nz1yHX\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 21:30:01 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wI376-0002lI-2d; Wed, 29 Apr 2026 07:29:56 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <armenon@redhat.com>)\n id 1wI372-0002ke-Tq\n for qemu-devel@nongnu.org; Wed, 29 Apr 2026 07:29:53 -0400","from us-smtp-delivery-124.mimecast.com ([170.10.133.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <armenon@redhat.com>)\n id 1wI370-0007vf-3l\n for qemu-devel@nongnu.org; Wed, 29 Apr 2026 07:29:51 -0400","from mail-pj1-f71.google.com (mail-pj1-f71.google.com\n [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-196-00BrC_bfNtuq33c_N6A3Vw-1; Wed, 29 Apr 2026 07:29:47 -0400","by mail-pj1-f71.google.com with SMTP id\n 98e67ed59e1d1-35fbaada2f3so22945901a91.0\n for <qemu-devel@nongnu.org>; Wed, 29 Apr 2026 04:29:47 -0700 (PDT)","from fedora ([49.36.106.198]) by smtp.gmail.com with ESMTPSA id\n 41be03b00d2f7-c7fd65065e1sm2137088a12.22.2026.04.29.04.29.44\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 29 Apr 2026 04:29:45 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1777462189;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=FoopuS5uqwaLcywvhiReMZkk5JjheqUp793BySGQG5U=;\n b=YPLTkgKq74RrJW/0Exq4H3elCar3kP7UdBOzLC1hC0fONSR13AP55dOqfJlbJpqoDhya//\n rtn1lDBPZinISwuKX+F+W2edC1P4Ij4Tc7YEEmpk+iOzSEfTZnTWs+3CCn13bILB3l4gSM\n 4JejAcjwkfAqvPVFrlyUmHyDvRWKC3I=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1777462186; x=1778066986; darn=nongnu.org;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;\n bh=FoopuS5uqwaLcywvhiReMZkk5JjheqUp793BySGQG5U=;\n b=MkvQDw8pXc6Oqx3HJjM1weG2VJEdQPwOxEy+ju8slqvnssoJWhuVrnNLkxPpeMmBxt\n JS/YfM4105+ouG6KV7P2pOSfreL+ZNypCr42InxtmLAlOnCV3D3ljLufDeFJ/a3L1+Xk\n bbsUw1bOa7KrXGA3Cpfg6c6k8LnfeALV0BiuJzfoeu+3oxCyFg9YK1wP2qeQXLLJgv2D\n HtWnYTl6leYM4PITt8NyKCX4Zyn1iCei/kU+rLw21Dg19Imkhl+KOVu9cz7azXfRQ63V\n OcyWGegJjo/hzQltLoa/+QtMJZAhnNT31ggLPvWsYP2QnYIUZBWOXSHp6G2DFZYMCRSf\n idEg=="],"X-MC-Unique":"00BrC_bfNtuq33c_N6A3Vw-1","X-Mimecast-MFC-AGG-ID":"00BrC_bfNtuq33c_N6A3Vw_1777462187","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1777462186; x=1778066986;\n h=in-reply-to:content-disposition:mime-version:references:message-id\n :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=FoopuS5uqwaLcywvhiReMZkk5JjheqUp793BySGQG5U=;\n b=CgjtGN1jMRV+QFt5TyGAAvbjRcLswEesoek1kvHJq88yrqlIPZRMakMCppI6UQ2dGz\n jAX3pSzDLa0uPuWXWwcSAbfep3Qpf++h10lsFRory4v68ewnkq7L1FczkH4CbW5XISk2\n QUsQX65XF0rPWHGKIR3tbH9S8025yF6Y2b3dwXiERDAGo8kcYUHkyN8j/xWIzliMzaUg\n LKL5Q8IT2aageJAncLoYUisJkYXOHqlISPOVbn9HLnY2782btPudHgQyYgl5H2KuLWIG\n mWqQl4fAp9wXgL0E5wp9xQj/eI3z5cXiOt78I9I2qtDEywcany864xzFY6otpjshbHYK\n I8+w==","X-Gm-Message-State":"AOJu0Yz8HLD294CrB1MUR41EczH9hzW7FWt7WLUBSXE1KAVqY2VoSCz9\n w2+MnhGCZPAhPhAl72h1qbqCKju5uSZq0Fa7VbwABeqEvifEt9A9yRHDUbLrbvPmV+lUGRcLxPE\n Ow8xJpx9bLWKvG4K18R8FmYxvu5v7C9hoXF7lOM2fOPRjnXZX/UQRtYVo","X-Gm-Gg":"AeBDiesWEk3G21PvhCNqocRae8/aTvpSnEbEXwdhwaLpcg+8SVxAm2U4JJOqpQJCi00\n Z38XchVSvcHriWusb+46wdsL4iL6qlt5ZJ7T+Dnzy7W4PMByKyxHps3GHAy/YjH+IasA4sBLsOq\n S0YLmKzOc2Nalw8/44GNqbq35rUS+lc8/FUthHEIg7RbPJ+LoG50q8qyFuuiTf1nhxWOV2N8L/4\n 1N+EMVKlkE9mMfqHLar9+NeRZ63zHyCFAS87AalqXJbOS9GQiyEb2b8zM2ac9flEW8Pa96W0nt2\n ayiRe2h0PoiTMsQ1yBaTXaUhWlXelNL/q4eguX0npLFnY2zsAOwcj9n6tuqiAY5nqqeZTTORJSY\n 84StbJWtqQ+gD0Ty5hqpFY1c=","X-Received":["by 2002:a05:6a20:729b:b0:3a3:327:c5c9 with SMTP id\n adf61e73a8af0-3a39c214542mr8092258637.26.1777462186516;\n Wed, 29 Apr 2026 04:29:46 -0700 (PDT)","by 2002:a05:6a20:729b:b0:3a3:327:c5c9 with SMTP id\n adf61e73a8af0-3a39c214542mr8092214637.26.1777462185941;\n Wed, 29 Apr 2026 04:29:45 -0700 (PDT)"],"Date":"Wed, 29 Apr 2026 16:59:41 +0530","From":"Arun Menon <armenon@redhat.com>","To":"Stefan Berger <stefanb@linux.ibm.com>","Cc":"qemu-devel@nongnu.org, marcandre.lureau@redhat.com","Subject":"Re: [PATCH 1/6] tests: Move TPM I2C bus read/write functions to\n common files","Message-ID":"<afHrpQWu6mRkehxh@fedora>","References":"<20260428130718.1325177-1-stefanb@linux.ibm.com>\n <20260428130718.1325177-2-stefanb@linux.ibm.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20260428130718.1325177-2-stefanb@linux.ibm.com>","Received-SPF":"pass client-ip=170.10.133.124; envelope-from=armenon@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001,\n SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"}}]