All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Hervé Poussineau" <hpoussin@reactos.org>
To: qemu-devel@nongnu.org
Cc: "Aurelien Jarno" <aurelien@aurel32.net>,
	"Leon Alrae" <leon.alrae@imgtec.com>,
	"Hervé Poussineau" <hpoussin@reactos.org>
Subject: [Qemu-devel] [PATCH] gt64xxx: access right I/O port when activating byte swapping
Date: Fri, 20 May 2016 15:05:03 +0200	[thread overview]
Message-ID: <1463749503-27374-1-git-send-email-hpoussin@reactos.org> (raw)

Incidentally, this fixes YAMON on big endian guest.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/mips/gt64xxx_pci.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 3f4523d..c76ee88 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -177,6 +177,7 @@
 
 /* PCI Internal */
 #define GT_PCI0_CMD    		(0xc00 >> 2)
+#define   GT_CMD_MWORDSWAP      (1 << 10)
 #define GT_PCI0_TOR    		(0xc04 >> 2)
 #define GT_PCI0_BS_SCS10    	(0xc08 >> 2)
 #define GT_PCI0_BS_SCS32    	(0xc0c >> 2)
@@ -294,6 +295,62 @@ static void gt64120_isd_mapping(GT64120State *s)
     memory_region_add_subregion(get_system_memory(), s->ISD_start, &s->ISD_mem);
 }
 
+static uint64_t gt64120_pci_io_read(void *opaque, hwaddr addr,
+                                    unsigned int size)
+{
+    GT64120State *s = opaque;
+    uint8_t buf[4];
+
+    if (s->regs[GT_PCI0_CMD] & GT_CMD_MWORDSWAP) {
+        addr = (addr & ~3) + 4 - size - (addr & 3);
+    }
+
+    address_space_read(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
+                       buf, size);
+
+    if (size == 1) {
+        return buf[0];
+    } else if (size == 2) {
+        return lduw_le_p(buf);
+    } else if (size == 4) {
+        return ldl_le_p(buf);
+    } else {
+        g_assert_not_reached();
+    }
+}
+
+static void gt64120_pci_io_write(void *opaque, hwaddr addr, uint64_t data,
+                                 unsigned int size)
+{
+    GT64120State *s = opaque;
+    uint8_t buf[4];
+
+    if (s->regs[GT_PCI0_CMD] & GT_CMD_MWORDSWAP) {
+        addr = (addr & ~3) + 4 - size - (addr & 3);
+    }
+
+    if (size == 1) {
+        buf[0] = data;
+    } else if (size == 2) {
+        stw_le_p(buf, data);
+    } else if (size == 4) {
+        stl_le_p(buf, data);
+    } else {
+        g_assert_not_reached();
+    }
+
+    address_space_write(&address_space_io, addr, MEMTXATTRS_UNSPECIFIED,
+                        buf, size);
+}
+
+static const MemoryRegionOps gt64120_pci_io_ops = {
+    .read = gt64120_pci_io_read,
+    .write = gt64120_pci_io_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .impl.max_access_size = 4,
+    .valid.unaligned = true,
+};
+
 static void gt64120_pci_mapping(GT64120State *s)
 {
     /* Update PCI0IO mapping */
@@ -308,8 +365,9 @@ static void gt64120_pci_mapping(GT64120State *s)
         s->PCI0IO_length = ((s->regs[GT_PCI0IOHD] + 1) -
                             (s->regs[GT_PCI0IOLD] & 0x7f)) << 21;
         if (s->PCI0IO_length) {
-            memory_region_init_alias(&s->PCI0IO_mem, OBJECT(s), "pci0-io",
-                                     get_system_io(), 0, s->PCI0IO_length);
+            memory_region_init_io(&s->PCI0IO_mem, OBJECT(s),
+                                  &gt64120_pci_io_ops,
+                                  s, "pci0-io", s->PCI0IO_length);
             memory_region_add_subregion(get_system_memory(), s->PCI0IO_start,
                                         &s->PCI0IO_mem);
         }
-- 
2.1.4

             reply	other threads:[~2016-05-20 13:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20 13:05 Hervé Poussineau [this message]
2016-05-20 19:56 ` [Qemu-devel] [PATCH] gt64xxx: access right I/O port when activating byte swapping Aurelien Jarno
2016-06-18 20:48   ` Hervé Poussineau
2016-07-22 13:55     ` Aurelien Jarno
  -- strict thread matches above, loose matches on Subject: below --
2015-06-10 20:03 Hervé Poussineau

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=1463749503-27374-1-git-send-email-hpoussin@reactos.org \
    --to=hpoussin@reactos.org \
    --cc=aurelien@aurel32.net \
    --cc=leon.alrae@imgtec.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 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.