qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org, marcandre.lureau@redhat.com
Cc: amarnath.valluri@intel.com, Stefan Berger <stefanb@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH] tpm: Add a caching layer for the TPM Established flag
Date: Wed,  8 Nov 2017 14:45:56 -0500	[thread overview]
Message-ID: <1510170356-16953-1-git-send-email-stefanb@linux.vnet.ibm.com> (raw)

Add a caching layer for the TPM established flag so that we don't
need to go to the backend every time the flag is read by accessing
the REG_ACCESS register.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
 hw/tpm/tpm_tis.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 7402528..6b81bbf 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -95,6 +95,9 @@ struct TPMState {
     char *backend;
     TPMBackend *be_driver;
     TPMVersion be_tpm_version;
+
+    unsigned int established_flag:1;
+    unsigned int established_flag_cached:1;
 };
 
 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)
@@ -529,6 +532,26 @@ static void tpm_tis_dump_state(void *opaque, hwaddr addr)
 }
 #endif
 
+static void tpm_tis_reset_tpm_established_flag(TPMState *s,
+                                               uint8_t locty)
+{
+    s->established_flag_cached = 0;
+
+    tpm_backend_reset_tpm_established_flag(s->be_driver, locty);
+}
+
+static unsigned int tpm_tis_get_tpm_established_flag(TPMState *s)
+{
+    if (s->established_flag_cached) {
+        return s->established_flag;
+    }
+
+    s->established_flag = !tpm_backend_get_tpm_established_flag(s->be_driver);
+    s->established_flag_cached = 1;
+
+    return s->established_flag;
+}
+
 /*
  * Read a register of the TIS interface
  * See specs pages 33-63 for description of the registers
@@ -556,7 +579,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
         if (tpm_tis_check_request_use_except(s, locty)) {
             val |= TPM_TIS_ACCESS_PENDING_REQUEST;
         }
-        val |= !tpm_backend_get_tpm_established_flag(s->be_driver);
+        val |= tpm_tis_get_tpm_established_flag(s);
         break;
     case TPM_TIS_REG_INT_ENABLE:
         val = s->loc[locty].inte;
@@ -840,7 +863,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
 
             if (val & TPM_TIS_STS_RESET_ESTABLISHMENT_BIT) {
                 if (locty == 3 || locty == 4) {
-                    tpm_backend_reset_tpm_established_flag(s->be_driver, locty);
+                    tpm_tis_reset_tpm_established_flag(s, locty);
                 }
             }
         }
-- 
2.5.5

             reply	other threads:[~2017-11-08 19:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08 19:45 Stefan Berger [this message]
2017-11-08 20:38 ` [Qemu-devel] [PATCH] tpm: Add a caching layer for the TPM Established flag Stefan Berger

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=1510170356-16953-1-git-send-email-stefanb@linux.vnet.ibm.com \
    --to=stefanb@linux.vnet.ibm.com \
    --cc=amarnath.valluri@intel.com \
    --cc=marcandre.lureau@redhat.com \
    --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 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).