qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Peter Crosthwaite <peter.crosthwaite@xilinx.com>,
	Stefan Berger <stefanb@linux.vnet.ibm.com>,
	Max Reitz <mreitz@redhat.com>,
	Anthony Liguori <aliguori@amazon.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PULL v3 03/26] tpm: Allow 32 & 16 bit accesses to the registers
Date: Mon, 2 Mar 2015 11:58:28 +0100	[thread overview]
Message-ID: <1425293287-4426-4-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1425293287-4426-1-git-send-email-mst@redhat.com>

From: Stefan Berger <stefanb@linux.vnet.ibm.com>

Improve the access to the registers with 32 and 16 bit reads and writes.
Also enable access to a non-base register address, such as reads of the
2nd byte of a register. Map the FIFO byte access to any byte within
its 4 byte register (following specs).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/tpm/tpm_tis.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index c0e7cd7..6170693 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -427,6 +427,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
     uint32_t val = 0xffffffff;
     uint8_t locty = tpm_tis_locality_from_addr(addr);
     uint32_t avail;
+    uint8_t v;
 
     if (tpm_backend_had_startup_error(s->be_driver)) {
         return val;
@@ -476,14 +477,26 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
         break;
     case TPM_TIS_REG_DATA_FIFO:
         if (tis->active_locty == locty) {
-            switch (tis->loc[locty].state) {
-            case TPM_TIS_STATE_COMPLETION:
-                val = tpm_tis_data_read(s, locty);
-                break;
-            default:
-                val = TPM_TIS_NO_DATA_BYTE;
-                break;
+            if (size > 4 - (addr & 0x3)) {
+                /* prevent access beyond FIFO */
+                size = 4 - (addr & 0x3);
+            }
+            val = 0;
+            shift = 0;
+            while (size > 0) {
+                switch (tis->loc[locty].state) {
+                case TPM_TIS_STATE_COMPLETION:
+                    v = tpm_tis_data_read(s, locty);
+                    break;
+                default:
+                    v = TPM_TIS_NO_DATA_BYTE;
+                    break;
+                }
+                val |= (v << shift);
+                shift += 8;
+                size--;
             }
+            shift = 0; /* no more adjustments */
         }
         break;
     case TPM_TIS_REG_DID_VID:
@@ -518,11 +531,13 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr,
 {
     TPMState *s = opaque;
     TPMTISEmuState *tis = &s->s.tis;
-    uint16_t off = addr & 0xfff;
+    uint16_t off = addr & 0xffc;
+    uint8_t shift = (addr & 0x3) * 8;
     uint8_t locty = tpm_tis_locality_from_addr(addr);
     uint8_t active_locty, l;
     int c, set_new_locty = 1;
     uint16_t len;
+    uint32_t mask = (size == 1) ? 0xff : ((size == 2) ? 0xffff : ~0);
 
     DPRINTF("tpm_tis: write.%u(%08x) = %08x\n", size, (int)addr, (uint32_t)val);
 
@@ -535,6 +550,15 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr,
         return;
     }
 
+    val &= mask;
+
+    if (shift) {
+        val <<= shift;
+        mask <<= shift;
+    }
+
+    mask ^= 0xffffffff;
+
     switch (off) {
     case TPM_TIS_REG_ACCESS:
 
@@ -646,9 +670,10 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr,
             break;
         }
 
-        tis->loc[locty].inte = (val & (TPM_TIS_INT_ENABLED |
-                                       TPM_TIS_INT_POLARITY_MASK |
-                                       TPM_TIS_INTERRUPTS_SUPPORTED));
+        tis->loc[locty].inte &= mask;
+        tis->loc[locty].inte |= (val & (TPM_TIS_INT_ENABLED |
+                                        TPM_TIS_INT_POLARITY_MASK |
+                                        TPM_TIS_INTERRUPTS_SUPPORTED));
         break;
     case TPM_TIS_REG_INT_VECTOR:
         /* hard wired -- ignore */
@@ -747,16 +772,25 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr addr,
             tis->loc[locty].state == TPM_TIS_STATE_COMPLETION) {
             /* drop the byte */
         } else {
-            DPRINTF("tpm_tis: Byte to send to TPM: %02x\n", (uint8_t)val);
+            DPRINTF("tpm_tis: Data to send to TPM: %08x (size=%d)\n",
+                    val, size);
             if (tis->loc[locty].state == TPM_TIS_STATE_READY) {
                 tis->loc[locty].state = TPM_TIS_STATE_RECEPTION;
                 tis->loc[locty].sts = TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID;
             }
 
-            if ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) {
+            val >>= shift;
+            if (size > 4 - (addr & 0x3)) {
+                /* prevent access beyond FIFO */
+                size = 4 - (addr & 0x3);
+            }
+
+            while ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) {
                 if (tis->loc[locty].w_offset < tis->loc[locty].w_buffer.size) {
                     tis->loc[locty].w_buffer.
                         buffer[tis->loc[locty].w_offset++] = (uint8_t)val;
+                    val >>= 8;
+                    size--;
                 } else {
                     tis->loc[locty].sts = TPM_TIS_STS_VALID;
                 }
-- 
MST

  parent reply	other threads:[~2015-03-02 10:58 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 10:58 [Qemu-devel] [PULL v3 00/26] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
2015-03-02 10:58 ` [Qemu-devel] [PULL v3 01/26] balloon: call qdev_alias_all_properties for proxy dev in balloon class init Michael S. Tsirkin
2015-03-02 10:58 ` [Qemu-devel] [PULL v3 02/26] tpm: Extend sts register to 32 bit Michael S. Tsirkin
2015-03-02 10:58 ` Michael S. Tsirkin [this message]
2015-03-02 10:58 ` [Qemu-devel] [PULL v3 04/26] tpm: Support for XFIFO register Michael S. Tsirkin
2015-03-02 10:58 ` [Qemu-devel] [PULL v3 05/26] tpm: Support for TIS selftest done flag Michael S. Tsirkin
2015-03-02 10:58 ` [Qemu-devel] [PULL v3 06/26] tpm: Support for capability flags of TIS 1.3 Michael S. Tsirkin
2015-03-02 10:58 ` [Qemu-devel] [PULL v3 07/26] pc: acpi-build: create PCI0._CRS dynamically Michael S. Tsirkin
2015-03-02 10:58 ` [Qemu-devel] [PULL v3 08/26] pc: acpi: drop manual hole punching for PCI hotplug resources Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 09/26] pc: acpi: drop manual hole punching for CPU " Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 10/26] pc: acpi: drop manual hole punching for GPE0 resources Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 11/26] pc: acpi-build: drop remaining ssdt_misc template Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 12/26] acpi: add acpi_irq_no_flags() term Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 13/26] pc: export applesmc IO port/len Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 14/26] pc: acpi-build: drop template patching and create Device(SMC) dynamically Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 15/26] tests: ACPI test blobs update due to PCI0._CRS changes Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 16/26] tests: bios-tables-test: add support for testing bridges Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 17/26] tests: add ACPI blobs for qemu with bridge cases Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 18/26] pc: acpi-build: simplify PCI bus tree generation Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 19/26] tests: ACPI: update pc/SSDT.bridge due to new alg of PCI tree creation Michael S. Tsirkin
2015-03-02 10:59 ` [Qemu-devel] [PULL v3 20/26] pc: acpi-build: drop template patching and create PCI bus tree dynamically Michael S. Tsirkin
2015-03-02 11:00 ` [Qemu-devel] [PULL v3 21/26] pc: acpi: remove not used anymore ssdt-[misc|pcihp].hex.generated blobs Michael S. Tsirkin
2015-03-02 11:00 ` [Qemu-devel] [PULL v3 22/26] acpi: make build_*() routines static to aml-build.c Michael S. Tsirkin
2015-03-02 11:00 ` [Qemu-devel] [PULL v3 23/26] pci: Give a few helpers internal linkage Michael S. Tsirkin
2015-03-02 11:00 ` [Qemu-devel] [PULL v3 24/26] pci-hotplug-old: Has been dead for five major releases, bury Michael S. Tsirkin
2015-03-02 11:00 ` [Qemu-devel] [PULL v3 25/26] acpi, mem-hotplug: use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb() Michael S. Tsirkin
2015-03-02 11:00 ` [Qemu-devel] [PULL v3 26/26] acpi-test-data: update after pci rewrite Michael S. Tsirkin
2015-03-02 14:32 ` [Qemu-devel] [PULL v3 00/26] pci, pc, virtio fixes and cleanups Michael S. Tsirkin
2015-03-02 19:03   ` Michael S. Tsirkin

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=1425293287-4426-4-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --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 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).