qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ninad Palsule <ninad@linux.vnet.ibm.com>
To: Stefan Berger <stefanb@linux.ibm.com>, qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, clg@kaod.org, ninad@linux.ibm.com,
	joel@jms.id.au, andrew@aj.id.au
Subject: Re: [PATCH 2/3] qtest: Move tpm_util_tis_transmit() into tpm-tis-utils.c and rename it
Date: Tue, 28 Mar 2023 08:31:42 -0500	[thread overview]
Message-ID: <44e66316-f562-d9a9-6f0f-b6cd394468f3@linux.vnet.ibm.com> (raw)
In-Reply-To: <20230327202416.3617162-3-stefanb@linux.ibm.com>


On 3/27/23 3:24 PM, Stefan Berger wrote:
> To be able to remove tpm_tis_base_addr from test cases that do not really
> need it move the tpm_util_tis_transmit() function into tpm-tis-utils.c and
> rename it to tpm_tis_transmit().
>
> Fix a locality parameter in a test case on the way.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Ninad Palsule <ninad@linux.ibm.com>
> ---
>   tests/qtest/tpm-crb-swtpm-test.c        |  3 --
>   tests/qtest/tpm-crb-test.c              |  3 --
>   tests/qtest/tpm-tis-device-swtpm-test.c |  5 +--
>   tests/qtest/tpm-tis-swtpm-test.c        |  5 +--
>   tests/qtest/tpm-tis-util.c              | 47 ++++++++++++++++++++++++-
>   tests/qtest/tpm-tis-util.h              |  4 +++
>   tests/qtest/tpm-util.c                  | 45 -----------------------
>   tests/qtest/tpm-util.h                  |  3 --
>   8 files changed, 56 insertions(+), 59 deletions(-)
>
> diff --git a/tests/qtest/tpm-crb-swtpm-test.c b/tests/qtest/tpm-crb-swtpm-test.c
> index 40254f762f..ffeb1c396b 100644
> --- a/tests/qtest/tpm-crb-swtpm-test.c
> +++ b/tests/qtest/tpm-crb-swtpm-test.c
> @@ -19,9 +19,6 @@
>   #include "tpm-tests.h"
>   #include "hw/acpi/tpm.h"
>   
> -/* Not used but needed for linking */
> -uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
> -
>   typedef struct TestState {
>       char *src_tpm_path;
>       char *dst_tpm_path;
> diff --git a/tests/qtest/tpm-crb-test.c b/tests/qtest/tpm-crb-test.c
> index 7b94453390..396ae3f91c 100644
> --- a/tests/qtest/tpm-crb-test.c
> +++ b/tests/qtest/tpm-crb-test.c
> @@ -19,9 +19,6 @@
>   #include "qemu/module.h"
>   #include "tpm-emu.h"
>   
> -/* Not used but needed for linking */
> -uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
> -
>   #define TPM_CMD "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00"
>   
>   static void tpm_crb_test(const void *data)
> diff --git a/tests/qtest/tpm-tis-device-swtpm-test.c b/tests/qtest/tpm-tis-device-swtpm-test.c
> index 8c067fddd4..517a077005 100644
> --- a/tests/qtest/tpm-tis-device-swtpm-test.c
> +++ b/tests/qtest/tpm-tis-device-swtpm-test.c
> @@ -18,6 +18,7 @@
>   #include "libqtest.h"
>   #include "qemu/module.h"
>   #include "tpm-tests.h"
> +#include "tpm-tis-util.h"
>   #include "hw/acpi/tpm.h"
>   
>   uint64_t tpm_tis_base_addr = 0xc000000;
> @@ -33,7 +34,7 @@ static void tpm_tis_swtpm_test(const void *data)
>   {
>       const TestState *ts = data;
>   
> -    tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer,
> +    tpm_test_swtpm_test(ts->src_tpm_path, tpm_tis_transfer,
>                           "tpm-tis-device", MACHINE_OPTIONS);
>   }
>   
> @@ -42,7 +43,7 @@ static void tpm_tis_swtpm_migration_test(const void *data)
>       const TestState *ts = data;
>   
>       tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
> -                                  tpm_util_tis_transfer, "tpm-tis-device",
> +                                  tpm_tis_transfer, "tpm-tis-device",
>                                     MACHINE_OPTIONS);
>   }
>   
> diff --git a/tests/qtest/tpm-tis-swtpm-test.c b/tests/qtest/tpm-tis-swtpm-test.c
> index 11539c0a52..105e42e21d 100644
> --- a/tests/qtest/tpm-tis-swtpm-test.c
> +++ b/tests/qtest/tpm-tis-swtpm-test.c
> @@ -17,6 +17,7 @@
>   #include "libqtest.h"
>   #include "qemu/module.h"
>   #include "tpm-tests.h"
> +#include "tpm-tis-util.h"
>   #include "hw/acpi/tpm.h"
>   
>   uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
> @@ -31,7 +32,7 @@ static void tpm_tis_swtpm_test(const void *data)
>   {
>       const TestState *ts = data;
>   
> -    tpm_test_swtpm_test(ts->src_tpm_path, tpm_util_tis_transfer,
> +    tpm_test_swtpm_test(ts->src_tpm_path, tpm_tis_transfer,
>                           "tpm-tis", NULL);
>   }
>   
> @@ -40,7 +41,7 @@ static void tpm_tis_swtpm_migration_test(const void *data)
>       const TestState *ts = data;
>   
>       tpm_test_swtpm_migration_test(ts->src_tpm_path, ts->dst_tpm_path, ts->uri,
> -                                  tpm_util_tis_transfer, "tpm-tis", NULL);
> +                                  tpm_tis_transfer, "tpm-tis", NULL);
>   }
>   
>   int main(int argc, char **argv)
> diff --git a/tests/qtest/tpm-tis-util.c b/tests/qtest/tpm-tis-util.c
> index 939893bf01..728cd3e065 100644
> --- a/tests/qtest/tpm-tis-util.c
> +++ b/tests/qtest/tpm-tis-util.c
> @@ -52,7 +52,7 @@ void tpm_tis_test_check_localities(const void *data)
>       uint32_t rid;
>   
>       for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES; locty++) {
> -        access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
> +        access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
>           g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
>                                       TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
>   
> @@ -449,3 +449,48 @@ void tpm_tis_test_check_transmit(const void *data)
>       writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_ACTIVE_LOCALITY);
>       access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
>   }
> +
> +void tpm_tis_transfer(QTestState *s,
> +                      const unsigned char *req, size_t req_size,
> +                      unsigned char *rsp, size_t rsp_size)
> +{
> +    uint32_t sts;
> +    uint16_t bcount;
> +    size_t i;
> +
> +    /* request use of locality 0 */
> +    qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
> +    qtest_writel(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY);
> +
> +    sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> +    bcount = (sts >> 8) & 0xffff;
> +    g_assert_cmpint(bcount, >=, req_size);
> +
> +    /* transmit command */
> +    for (i = 0; i < req_size; i++) {
> +        qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO), req[i]);
> +    }
> +
> +    /* start processing */
> +    qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO);
> +
> +    uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
> +    do {
> +        sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> +        if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
> +            break;
> +        }
> +    } while (g_get_monotonic_time() < end_time);
> +
> +    sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> +    bcount = (sts >> 8) & 0xffff;
> +
> +    memset(rsp, 0, rsp_size);
> +    for (i = 0; i < bcount; i++) {
> +        rsp[i] = qtest_readb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO));
> +    }
> +
> +    /* relinquish use of locality 0 */
> +    qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS),
> +                 TPM_TIS_ACCESS_ACTIVE_LOCALITY);
> +}
> diff --git a/tests/qtest/tpm-tis-util.h b/tests/qtest/tpm-tis-util.h
> index d10efe86ae..03910a7ba7 100644
> --- a/tests/qtest/tpm-tis-util.h
> +++ b/tests/qtest/tpm-tis-util.h
> @@ -20,4 +20,8 @@ void tpm_tis_test_check_access_reg_seize(const void *data);
>   void tpm_tis_test_check_access_reg_release(const void *data);
>   void tpm_tis_test_check_transmit(const void *data);
>   
> +void tpm_tis_transfer(QTestState *s,
> +                      const unsigned char *req, size_t req_size,
> +                      unsigned char *rsp, size_t rsp_size);
> +
>   #endif /* TESTS_TPM_TIS_UTIL_H */
> diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
> index a7efe2d0d2..1c0319e6e7 100644
> --- a/tests/qtest/tpm-util.c
> +++ b/tests/qtest/tpm-util.c
> @@ -51,51 +51,6 @@ void tpm_util_crb_transfer(QTestState *s,
>       qtest_memread(s, raddr, rsp, rsp_size);
>   }
>   
> -void tpm_util_tis_transfer(QTestState *s,
> -                           const unsigned char *req, size_t req_size,
> -                           unsigned char *rsp, size_t rsp_size)
> -{
> -    uint32_t sts;
> -    uint16_t bcount;
> -    size_t i;
> -
> -    /* request use of locality 0 */
> -    qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
> -    qtest_writel(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY);
> -
> -    sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> -    bcount = (sts >> 8) & 0xffff;
> -    g_assert_cmpint(bcount, >=, req_size);
> -
> -    /* transmit command */
> -    for (i = 0; i < req_size; i++) {
> -        qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO), req[i]);
> -    }
> -
> -    /* start processing */
> -    qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO);
> -
> -    uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
> -    do {
> -        sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> -        if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
> -            break;
> -        }
> -    } while (g_get_monotonic_time() < end_time);
> -
> -    sts = qtest_readl(s, TIS_REG(0, TPM_TIS_REG_STS));
> -    bcount = (sts >> 8) & 0xffff;
> -
> -    memset(rsp, 0, rsp_size);
> -    for (i = 0; i < bcount; i++) {
> -        rsp[i] = qtest_readb(s, TIS_REG(0, TPM_TIS_REG_DATA_FIFO));
> -    }
> -
> -    /* relinquish use of locality 0 */
> -    qtest_writeb(s, TIS_REG(0, TPM_TIS_REG_ACCESS),
> -                 TPM_TIS_ACCESS_ACTIVE_LOCALITY);
> -}
> -
>   void tpm_util_startup(QTestState *s, tx_func *tx)
>   {
>       unsigned char buffer[1024];
> diff --git a/tests/qtest/tpm-util.h b/tests/qtest/tpm-util.h
> index 80720afac0..0cb28dd6e5 100644
> --- a/tests/qtest/tpm-util.h
> +++ b/tests/qtest/tpm-util.h
> @@ -27,9 +27,6 @@ typedef void (tx_func)(QTestState *s,
>   void tpm_util_crb_transfer(QTestState *s,
>                              const unsigned char *req, size_t req_size,
>                              unsigned char *rsp, size_t rsp_size);
> -void tpm_util_tis_transfer(QTestState *s,
> -                           const unsigned char *req, size_t req_size,
> -                           unsigned char *rsp, size_t rsp_size);
>   
>   void tpm_util_startup(QTestState *s, tx_func *tx);
>   void tpm_util_pcrextend(QTestState *s, tx_func *tx);


  reply	other threads:[~2023-03-28 13:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-27 20:24 [PATCH 0/3] qtests: tpm: Add test cases for TPM TIS I2C device emulation Stefan Berger
2023-03-27 20:24 ` [PATCH 1/3] qtest: Add functions for accessing devices on Aspeed I2C controller Stefan Berger
2023-03-28  6:39   ` Cédric Le Goater
2023-03-28 12:26     ` Stefan Berger
2023-03-28 13:10       ` Cédric Le Goater
2023-03-28 13:26   ` Ninad Palsule
2023-03-27 20:24 ` [PATCH 2/3] qtest: Move tpm_util_tis_transmit() into tpm-tis-utils.c and rename it Stefan Berger
2023-03-28 13:31   ` Ninad Palsule [this message]
2023-03-27 20:24 ` [PATCH 3/3] qtest: Add a test case for TPM TIS I2C connected to Aspeed I2C controller Stefan Berger
2023-03-28  6:44   ` Cédric Le Goater
2023-03-28  9:17   ` Cédric Le Goater
2023-03-28 11:31     ` Stefan Berger
2023-03-28 11:52       ` Cédric Le Goater
2023-03-28 14:10   ` Ninad Palsule

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=44e66316-f562-d9a9-6f0f-b6cd394468f3@linux.vnet.ibm.com \
    --to=ninad@linux.vnet.ibm.com \
    --cc=andrew@aj.id.au \
    --cc=clg@kaod.org \
    --cc=joel@jms.id.au \
    --cc=marcandre.lureau@redhat.com \
    --cc=ninad@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.ibm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).