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 v3 07/13] tpm_tis: merge r/w_offset into rw_offset
Date: Fri, 10 Nov 2017 09:11:46 -0500	[thread overview]
Message-ID: <1510323112-2207-8-git-send-email-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1510323112-2207-1-git-send-email-stefanb@linux.vnet.ibm.com>

We can now merge the r_offset and w_offset into a single rw_offset.
This is possible since when the offset is used for writing in
RECEPTION state then reads are ignore. Conversly, when the offset
is used for reading when in COMPLETION state, then writes are
ignored.

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

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index dfdddd3..7d7e2cd 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -68,8 +68,7 @@ typedef struct TPMState {
     MemoryRegion mmio;
 
     unsigned char buffer[TPM_TIS_BUFFER_MAX];
-    uint16_t w_offset;
-    uint16_t r_offset;
+    uint16_t rw_offset;
 
     uint8_t active_locty;
     uint8_t aborting_locty;
@@ -257,7 +256,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty)
                         "tpm_tis: To TPM");
 
     /*
-     * w_offset serves as length indicator for length of data;
+     * rw_offset serves as length indicator for length of data;
      * it's reset when the response comes back
      */
     s->loc[locty].state = TPM_TIS_STATE_EXECUTION;
@@ -265,7 +264,7 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty)
     s->cmd = (TPMBackendCmd) {
         .locty = locty,
         .in = s->buffer,
-        .in_len = s->w_offset,
+        .in_len = s->rw_offset,
         .out = s->buffer,
         .out_len = s->be_buffer_size,
     };
@@ -347,8 +346,7 @@ static void tpm_tis_new_active_locality(TPMState *s, uint8_t new_active_locty)
 /* abort -- this function switches the locality */
 static void tpm_tis_abort(TPMState *s, uint8_t locty)
 {
-    s->r_offset = 0;
-    s->w_offset = 0;
+    s->rw_offset = 0;
 
     DPRINTF("tpm_tis: tis_abort: new active locality is %d\n", s->next_locty);
 
@@ -415,8 +413,7 @@ static void tpm_tis_request_completed(TPMIf *ti)
     tpm_tis_sts_set(&s->loc[locty],
                     TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE);
     s->loc[locty].state = TPM_TIS_STATE_COMPLETION;
-    s->r_offset = 0;
-    s->w_offset = 0;
+    s->rw_offset = 0;
 
     tpm_tis_show_buffer(s->buffer, s->be_buffer_size,
                         "tpm_tis: From TPM");
@@ -441,14 +438,14 @@ static uint32_t tpm_tis_data_read(TPMState *s, uint8_t locty)
         len = MIN(tpm_cmd_get_size(&s->buffer),
                   s->be_buffer_size);
 
-        ret = s->buffer[s->r_offset++];
-        if (s->r_offset >= len) {
+        ret = s->buffer[s->rw_offset++];
+        if (s->rw_offset >= len) {
             /* got last byte */
             tpm_tis_sts_set(&s->loc[locty], TPM_TIS_STS_VALID);
             tpm_tis_raise_irq(s, locty, TPM_TIS_INT_STS_VALID);
         }
         DPRINTF("tpm_tis: tpm_tis_data_read byte 0x%02x   [%d]\n",
-                ret, s->r_offset - 1);
+                ret, s->rw_offset - 1);
     }
 
     return ret;
@@ -483,26 +480,14 @@ static void tpm_tis_dump_state(void *opaque, hwaddr addr)
                 (int)tpm_tis_mmio_read(opaque, base + regs[idx], 4));
     }
 
-    DPRINTF("tpm_tis: read offset   : %d\n"
+    DPRINTF("tpm_tis: r/w offset    : %d\n"
             "tpm_tis: result buffer : ",
-            s->r_offset);
+            s->rw_offset);
     for (idx = 0;
          idx < MIN(tpm_cmd_get_size(&s->buffer), s->be_buffer_size);
          idx++) {
         DPRINTF("%c%02x%s",
-                s->r_offset == idx ? '>' : ' ',
-                s->buffer[idx],
-                ((idx & 0xf) == 0xf) ? "\ntpm_tis:                 " : "");
-    }
-    DPRINTF("\n"
-            "tpm_tis: write offset  : %d\n"
-            "tpm_tis: request buffer: ",
-            s->w_offset);
-    for (idx = 0;
-         idx < MIN(tpm_cmd_get_size(s->buffer), s->be_buffer_size);
-         idx++) {
-        DPRINTF("%c%02x%s",
-                s->w_offset == idx ? '>' : ' ',
+                s->rw_offset == idx ? '>' : ' ',
                 s->buffer[idx],
                 ((idx & 0xf) == 0xf) ? "\ntpm_tis:                 " : "");
     }
@@ -567,9 +552,9 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
                 val = TPM_TIS_BURST_COUNT(
                        MIN(tpm_cmd_get_size(&s->buffer),
                            s->be_buffer_size)
-                       - s->r_offset) | s->loc[locty].sts;
+                       - s->rw_offset) | s->loc[locty].sts;
             } else {
-                avail = s->be_buffer_size - s->w_offset;
+                avail = s->be_buffer_size - s->rw_offset;
                 /*
                  * byte-sized reads should not return 0x00 for 0x100
                  * available bytes.
@@ -833,8 +818,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
             switch (s->loc[locty].state) {
 
             case TPM_TIS_STATE_READY:
-                s->w_offset = 0;
-                s->r_offset = 0;
+                s->rw_offset = 0;
             break;
 
             case TPM_TIS_STATE_IDLE:
@@ -852,8 +836,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
             break;
 
             case TPM_TIS_STATE_COMPLETION:
-                s->w_offset = 0;
-                s->r_offset = 0;
+                s->rw_offset = 0;
                 /* shortcut to ready state with C/R set */
                 s->loc[locty].state = TPM_TIS_STATE_READY;
                 if (!(s->loc[locty].sts & TPM_TIS_STS_COMMAND_READY)) {
@@ -879,7 +862,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
         } else if (val == TPM_TIS_STS_RESPONSE_RETRY) {
             switch (s->loc[locty].state) {
             case TPM_TIS_STATE_COMPLETION:
-                s->r_offset = 0;
+                s->rw_offset = 0;
                 tpm_tis_sts_set(&s->loc[locty],
                                 TPM_TIS_STS_VALID|
                                 TPM_TIS_STS_DATA_AVAILABLE);
@@ -917,8 +900,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
             }
 
             while ((s->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) {
-                if (s->w_offset < s->be_buffer_size) {
-                    s->buffer[s->w_offset++] =
+                if (s->rw_offset < s->be_buffer_size) {
+                    s->buffer[s->rw_offset++] =
                         (uint8_t)val;
                     val >>= 8;
                     size--;
@@ -928,13 +911,13 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
             }
 
             /* check for complete packet */
-            if (s->w_offset > 5 &&
+            if (s->rw_offset > 5 &&
                 (s->loc[locty].sts & TPM_TIS_STS_EXPECT)) {
                 /* we have a packet length - see if we have all of it */
                 bool need_irq = !(s->loc[locty].sts & TPM_TIS_STS_VALID);
 
                 len = tpm_cmd_get_size(&s->buffer);
-                if (len > s->w_offset) {
+                if (len > s->rw_offset) {
                     tpm_tis_sts_set(&s->loc[locty],
                                     TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID);
                 } else {
@@ -1019,8 +1002,7 @@ static void tpm_tis_reset(DeviceState *dev)
         s->loc[c].ints = 0;
         s->loc[c].state = TPM_TIS_STATE_IDLE;
 
-        s->w_offset = 0;
-        s->r_offset = 0;
+        s->rw_offset = 0;
     }
 
     tpm_tis_do_startup_tpm(s, s->be_buffer_size);
-- 
2.5.5

  parent reply	other threads:[~2017-11-10 14:12 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 14:11 [Qemu-devel] [PATCH v3 00/13] tpm: Extend TPM with state migration support (not 2.11) Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 01/13] tpm_tis: convert uint32_t to size_t Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 02/13] tpm_tis: limit size of buffer from backend Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 03/13] tpm_tis: remove TPMSizeBuffer usage Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 04/13] tpm_tis: move buffers from localities into common location Stefan Berger
2017-12-21 14:11   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 05/13] tpm_tis: merge read and write buffer into single buffer Stefan Berger
2017-12-21 14:41   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 06/13] tpm_tis: move r/w_offsets to TPMState Stefan Berger
2017-12-21 14:41   ` Marc-André Lureau
2017-12-21 14:44     ` Stefan Berger
2017-11-10 14:11 ` Stefan Berger [this message]
2017-12-21 14:41   ` [Qemu-devel] [PATCH v3 07/13] tpm_tis: merge r/w_offset into rw_offset Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 08/13] tpm: Implement tpm_sized_buffer_reset Stefan Berger
2017-12-21 14:44   ` Marc-André Lureau
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 09/13] tpm: Introduce condition to notify waiters of completed command Stefan Berger
2017-12-22 13:24   ` Marc-André Lureau
2017-12-27 14:17     ` Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 10/13] tpm: Introduce condition in TPM backend for notification Stefan Berger
2017-12-27 14:19   ` Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 11/13] tpm: implement tpm_backend_wait_cmd_completed Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 12/13] tpm: extend TPM emulator with state migration support Stefan Berger
2017-11-10 14:11 ` [Qemu-devel] [PATCH v3 13/13] tpm_tis: extend TPM TIS " Stefan Berger
2017-12-22 12:49 ` [Qemu-devel] [PATCH v3 00/13] tpm: Extend TPM with state migration support (not 2.11) Marc-André Lureau
2017-12-22 15:59   ` Stefan Berger
2017-12-22 16:13     ` Marc-André Lureau
2017-12-22 17:47       ` Stefan Berger
2017-12-22 17:52         ` Marc-André Lureau
2017-12-22 19:18           ` Stefan Berger
2017-12-27 15:00       ` 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=1510323112-2207-8-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).