qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
Cc: blauwirbel@gmail.com, aurelien@aurel32.net, mst@redhat.com
Subject: [Qemu-devel] [PATCH 01/10] PPC: Uninorth config space accessor
Date: Tue,  9 Feb 2010 17:37:01 +0100	[thread overview]
Message-ID: <1265733430-9656-2-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1265733430-9656-1-git-send-email-agraf@suse.de>

The Uninorth PCI bridge requires different layouts in its PCI config space
accessors.

This patch introduces a conversion function that makes it compatible with
the way Linux accesses it.

I also kept an OpenBIOS compatibility hack in. I think it'd be better to
take small steps here and do the config space access rework in OpenBIOS
later on. When that's done we can remove that hack.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/unin_pci.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 1 deletions(-)

diff --git a/hw/unin_pci.c b/hw/unin_pci.c
index 19eb5e0..0fbef1e 100644
--- a/hw/unin_pci.c
+++ b/hw/unin_pci.c
@@ -39,6 +39,7 @@
 typedef struct UNINState {
     SysBusDevice busdev;
     PCIHostState host_state;
+    ReadWriteHandler data_handler;
 } UNINState;
 
 /* Don't know if this matches real hardware, but it agrees with OHW.  */
@@ -75,6 +76,68 @@ static void pci_unin_reset(void *opaque)
 {
 }
 
+static uint32_t unin_get_config_reg(uint32_t reg, uint32_t addr)
+{
+    uint32_t retval;
+
+    if (reg & (1u << 31)) {
+        /* XXX OpenBIOS compatibility hack */
+        retval = reg | (addr & 3);
+    } else if (reg & 1) {
+        /* CFA1 style */
+        retval = (reg & ~7u) | (addr & 7);
+    } else {
+        uint32_t slot, func;
+
+        /* Grab CFA0 style values */
+        slot = ffs(reg & 0xfffff800) - 1;
+        func = (reg >> 8) & 7;
+
+        /* ... and then convert them to x86 format */
+        /* config pointer */
+        retval = (reg & (0xff - 7)) | (addr & 7);
+        /* slot */
+        retval |= slot << 11;
+        /* fn */
+        retval |= func << 8;
+    }
+
+
+    UNIN_DPRINTF("Converted config space accessor %08x/%08x -> %08x\n",
+                 reg, addr, retval);
+
+    return retval;
+}
+
+static void unin_data_write(ReadWriteHandler *handler,
+                            uint64_t addr, uint32_t val, int len)
+{
+    UNINState *s = container_of(handler, UNINState, data_handler);
+#ifdef TARGET_WORDS_BIGENDIAN
+    val = qemu_bswap_len(val, len);
+#endif
+    UNIN_DPRINTF("write addr %" PRIx64 " len %d val %x\n", addr, len, val);
+    pci_data_write(s->host_state.bus,
+                   unin_get_config_reg(s->host_state.config_reg, addr),
+                   val, len);
+}
+
+static uint32_t unin_data_read(ReadWriteHandler *handler,
+                               uint64_t addr, int len)
+{
+    UNINState *s = container_of(handler, UNINState, data_handler);
+    uint32_t val;
+
+    val = pci_data_read(s->host_state.bus,
+                        unin_get_config_reg(s->host_state.config_reg, addr),
+                        len);
+    UNIN_DPRINTF("read addr %" PRIx64 " len %d val %x\n", addr, len, val);
+#ifdef TARGET_WORDS_BIGENDIAN
+    val = qemu_bswap_len(val, len);
+#endif
+    return val;
+}
+
 static int pci_unin_main_init_device(SysBusDevice *dev)
 {
     UNINState *s;
@@ -85,7 +148,9 @@ static int pci_unin_main_init_device(SysBusDevice *dev)
     s = FROM_SYSBUS(UNINState, dev);
 
     pci_mem_config = pci_host_conf_register_mmio(&s->host_state);
-    pci_mem_data = pci_host_data_register_mmio(&s->host_state);
+    s->data_handler.read = unin_data_read;
+    s->data_handler.write = unin_data_write;
+    pci_mem_data = cpu_register_io_memory_simple(&s->data_handler);
     sysbus_init_mmio(dev, 0x1000, pci_mem_config);
     sysbus_init_mmio(dev, 0x1000, pci_mem_data);
 
-- 
1.6.0.2

  reply	other threads:[~2010-02-09 16:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-09 16:37 [Qemu-devel] [PATCH 00/10] PPC NewWorld fixery v4 Alexander Graf
2010-02-09 16:37 ` Alexander Graf [this message]
2010-02-09 16:37 ` [Qemu-devel] [PATCH 02/10] PPC: Use Mac99_U3 type on ppc64 Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 03/10] PPC: Include dump of lspci -nn on real G5 Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 04/10] PPC: Make interrupts work Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 05/10] PPC: tell the guest about the time base frequency Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 06/10] PPC: Use macio IDE controller for Newworld Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 07/10] PPC: Get rid of segfaults in DBDMA emulation Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 08/10] PPC: Add USB per default on U3 Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 09/10] PPC: Fix large pages Alexander Graf
2010-02-09 16:37 ` [Qemu-devel] [PATCH 10/10] PPC: Add timer when running KVM Alexander Graf
2010-02-09 17:01 ` [Qemu-devel] Re: [PATCH 00/10] PPC NewWorld fixery v4 Michael S. Tsirkin
2010-02-09 18:26   ` Alexander Graf
2010-02-09 20:30     ` Michael S. Tsirkin
2010-02-09 20:37       ` aurelien
2010-02-09 20:39         ` Michael S. Tsirkin
2010-02-09 21:24           ` Alexander Graf
2010-02-09 21:31             ` Michael S. Tsirkin
2010-02-09 21:43 ` 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=1265733430-9656-2-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=aurelien@aurel32.net \
    --cc=blauwirbel@gmail.com \
    --cc=mst@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).