All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: Stefan Berger <stefanb@linux.vnet.ibm.com>
Cc: QEMU <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 4/4] tests: Tests more flags of the CRB interface
Date: Thu, 29 Mar 2018 14:30:20 +0200	[thread overview]
Message-ID: <CAJ+F1CKiR=NSaAX+FMDc8H_pJix4aazmnx94737+AKadwtEBCw@mail.gmail.com> (raw)
In-Reply-To: <1522270761-29646-5-git-send-email-stefanb@linux.vnet.ibm.com>

On Wed, Mar 28, 2018 at 10:59 PM, Stefan Berger
<stefanb@linux.vnet.ibm.com> wrote:
> Test and modify more flags of the CRB interface.
>
> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
> ---

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


>  tests/tpm-crb-test.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 72 insertions(+), 2 deletions(-)
>
> diff --git a/tests/tpm-crb-test.c b/tests/tpm-crb-test.c
> index e1513cb..d8f9569 100644
> --- a/tests/tpm-crb-test.c
> +++ b/tests/tpm-crb-test.c
> @@ -28,6 +28,10 @@ static void tpm_crb_test(const void *data)
>      uint64_t caddr = readq(TPM_CRB_ADDR_BASE + A_CRB_CTRL_CMD_LADDR);
>      uint32_t rsize = readl(TPM_CRB_ADDR_BASE + A_CRB_CTRL_RSP_SIZE);
>      uint64_t raddr = readq(TPM_CRB_ADDR_BASE + A_CRB_CTRL_RSP_ADDR);
> +    uint8_t locstate = readb(TPM_CRB_ADDR_BASE + A_CRB_LOC_STATE);
> +    uint32_t locctrl = readl(TPM_CRB_ADDR_BASE + A_CRB_LOC_CTRL);
> +    uint32_t locsts = readl(TPM_CRB_ADDR_BASE + A_CRB_LOC_STS);
> +    uint32_t sts = readl(TPM_CRB_ADDR_BASE + A_CRB_CTRL_STS);
>
>      g_assert_cmpint(FIELD_EX32(intfid, CRB_INTF_ID, InterfaceType), ==, 1);
>      g_assert_cmpint(FIELD_EX32(intfid, CRB_INTF_ID, InterfaceVersion), ==, 1);
> @@ -45,9 +49,47 @@ static void tpm_crb_test(const void *data)
>      g_assert_cmpint(caddr, >, TPM_CRB_ADDR_BASE);
>      g_assert_cmpint(raddr, >, TPM_CRB_ADDR_BASE);
>
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, tpmEstablished), ==, 1);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, locAssigned), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, activeLocality), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, reserved), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, tpmRegValidSts), ==, 1);
> +
> +    g_assert_cmpint(locctrl, ==, 0);
> +
> +    g_assert_cmpint(FIELD_EX32(locsts, CRB_LOC_STS, Granted), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locsts, CRB_LOC_STS, beenSeized), ==, 0);
> +
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmIdle), ==, 1);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmSts), ==, 0);
> +
> +    /* request access to locality 0 */
> +    writeb(TPM_CRB_ADDR_BASE + A_CRB_LOC_CTRL, 1);
> +
> +    /* granted bit must be set now */
> +    locsts = readl(TPM_CRB_ADDR_BASE + A_CRB_LOC_STS);
> +    g_assert_cmpint(FIELD_EX32(locsts, CRB_LOC_STS, Granted), ==, 1);
> +    g_assert_cmpint(FIELD_EX32(locsts, CRB_LOC_STS, beenSeized), ==, 0);
> +
> +    /* we must have an assigned locality */
> +    locstate = readb(TPM_CRB_ADDR_BASE + A_CRB_LOC_STATE);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, tpmEstablished), ==, 1);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, locAssigned), ==, 1);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, activeLocality), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, reserved), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, tpmRegValidSts), ==, 1);
> +
> +    /* set into ready state */
> +    writel(TPM_CRB_ADDR_BASE + A_CRB_CTRL_REQ, 1);
> +
> +    /* TPM must not be in the idle state */
> +    sts = readl(TPM_CRB_ADDR_BASE + A_CRB_CTRL_STS);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmIdle), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmSts), ==, 0);
> +
>      memwrite(caddr, TPM_CMD, sizeof(TPM_CMD));
>
> -    uint32_t sts, start = 1;
> +    uint32_t start = 1;
>      uint64_t end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND;
>      writel(TPM_CRB_ADDR_BASE + A_CRB_CTRL_START, start);
>      do {
> @@ -58,12 +100,40 @@ static void tpm_crb_test(const void *data)
>      } while (g_get_monotonic_time() < end_time);
>      start = readl(TPM_CRB_ADDR_BASE + A_CRB_CTRL_START);
>      g_assert_cmpint(start & 1, ==, 0);
> +
> +    /* TPM must still not be in the idle state */
>      sts = readl(TPM_CRB_ADDR_BASE + A_CRB_CTRL_STS);
> -    g_assert_cmpint(sts & 1, ==, 0);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmIdle), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmSts), ==, 0);
>
>      struct tpm_hdr tpm_msg;
>      memread(raddr, &tpm_msg, sizeof(tpm_msg));
>      g_assert_cmpmem(&tpm_msg, sizeof(tpm_msg), s->tpm_msg, sizeof(*s->tpm_msg));
> +
> +    /* set TPM into idle state */
> +    writel(TPM_CRB_ADDR_BASE + A_CRB_CTRL_REQ, 2);
> +
> +    /* idle state must be indicated now */
> +    sts = readl(TPM_CRB_ADDR_BASE + A_CRB_CTRL_STS);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmIdle), ==, 1);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_CTRL_STS, tpmSts), ==, 0);
> +
> +    /* relinquish locality */
> +    writel(TPM_CRB_ADDR_BASE + A_CRB_LOC_CTRL, 2);
> +
> +    /* Granted flag must be cleared */
> +    sts = readl(TPM_CRB_ADDR_BASE + A_CRB_LOC_STS);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_LOC_STS, Granted), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(sts, CRB_LOC_STS, beenSeized), ==, 0);
> +
> +    /* no locality may be assigned */
> +    locstate = readb(TPM_CRB_ADDR_BASE + A_CRB_LOC_STATE);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, tpmEstablished), ==, 1);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, locAssigned), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, activeLocality), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, reserved), ==, 0);
> +    g_assert_cmpint(FIELD_EX32(locstate, CRB_LOC_STATE, tpmRegValidSts), ==, 1);
> +
>  }
>
>  int main(int argc, char **argv)
> --
> 2.5.5
>
>



-- 
Marc-André Lureau

  reply	other threads:[~2018-03-29 12:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 20:59 [Qemu-devel] [PATCH 0/4] tpm: More improvements on CRB interface Stefan Berger
2018-03-28 20:59 ` [Qemu-devel] [PATCH 1/4] tpm: CRB: set the Idle flag by default Stefan Berger
2018-03-29 10:44   ` Marc-André Lureau
2018-03-28 20:59 ` [Qemu-devel] [PATCH 2/4] tpm: CRB: Reset Granted flag when relinquishing locality Stefan Berger
2018-03-29 10:43   ` Marc-André Lureau
2018-03-28 20:59 ` [Qemu-devel] [PATCH 3/4] tpm: CRB: Enforce locality is requested before processing buffer Stefan Berger
2018-03-29 10:45   ` Marc-André Lureau
2018-03-28 20:59 ` [Qemu-devel] [PATCH 4/4] tests: Tests more flags of the CRB interface Stefan Berger
2018-03-29 12:30   ` Marc-André Lureau [this message]
2018-03-29 10:21 ` [Qemu-devel] [PATCH 0/4] tpm: More improvements on " no-reply
2018-03-31  8:03 ` no-reply

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='CAJ+F1CKiR=NSaAX+FMDc8H_pJix4aazmnx94737+AKadwtEBCw@mail.gmail.com' \
    --to=marcandre.lureau@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.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 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.