Patchwork msix: allow byte and word reading from mmio

login
register
mail settings
Submitter Bernhard Kohl
Date May 5, 2010, 4:19 p.m.
Message ID <4BE19A74.4090300@nsn.com>
Download mbox | patch
Permalink /patch/51774/
State New
Headers show

Comments

Bernhard Kohl - May 5, 2010, 4:19 p.m.
It's legal that the guest reads a single byte or word from mmio.

Signed-off-by: Bernhard Kohl <bernhard.kohl@nsn.com>
---
  hw/msix.c |   20 ++++++++++++++++----
  1 files changed, 16 insertions(+), 4 deletions(-)


  static uint8_t msix_pending_mask(int vector)
@@ -215,7 +227,7 @@ static CPUWriteMemoryFunc * const msix_mmio_write[] = {
  };

  static CPUReadMemoryFunc * const msix_mmio_read[] = {
-    msix_mmio_read_unallowed, msix_mmio_read_unallowed, msix_mmio_readl
+    msix_mmio_readb, msix_mmio_readw, msix_mmio_readl
  };

  /* Should be called from device's map method. */

Patch

diff --git a/hw/msix.c b/hw/msix.c
index 2ca0900..773bbbd 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -117,10 +117,22 @@  static uint32_t msix_mmio_readl(void *opaque, 
target_phys_addr_t addr)
      return pci_get_long(page + offset);
  }

-static uint32_t msix_mmio_read_unallowed(void *opaque, 
target_phys_addr_t addr)
+static uint32_t msix_mmio_readw(void *opaque, target_phys_addr_t addr)
  {
-    fprintf(stderr, "MSI-X: only dword read is allowed!\n");
-    return 0;
+    PCIDevice *dev = opaque;
+    unsigned int offset = addr & (MSIX_PAGE_SIZE - 1) & ~0x1;
+    void *page = dev->msix_table_page;
+
+    return pci_get_word(page + offset);
+}
+
+static uint32_t msix_mmio_readb(void *opaque, target_phys_addr_t addr)
+{
+    PCIDevice *dev = opaque;
+    unsigned int offset = addr & (MSIX_PAGE_SIZE - 1);
+    void *page = dev->msix_table_page;
+
+    return pci_get_byte(page + offset);
  }