Patchwork [2/6] Add config space conversion function for uni_north

login
register
mail settings
Submitter Alexander Graf
Date Jan. 4, 2010, 7:32 a.m.
Message ID <1262590375-11431-3-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/42049/
State New
Headers show

Comments

Alexander Graf - Jan. 4, 2010, 7:32 a.m.
As stated in the previous patch, 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>
CC: Michael S. Tsirkin <mst@redhat.com>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>

---

v1 -> v2:

  - convert Uninorth to use config space decoder

---
 hw/unin_pci.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/unin_pci.c b/hw/unin_pci.c
index fdb9401..5e69725 100644
--- a/hw/unin_pci.c
+++ b/hw/unin_pci.c
@@ -75,6 +75,36 @@  static void pci_unin_reset(void *opaque)
 {
 }
 
+static void unin_decode_config_reg(PCIHostState *s, uint32_t config_reg,
+                                   PCIConfigAddress *decoded)
+{
+    decoded->addr.domain = s->bus;
+    decoded->addr_mask = 7;
+    decoded->offset = config_reg & 0xfc;
+    decoded->addr.fn = (config_reg >> 8) & 0x7;
+
+    if (config_reg & (1u << 31)) {
+        /* XXX OpenBIOS compatibility hack */
+        pci_host_decode_config_reg(s, config_reg, decoded);
+    } else if (config_reg & 1) {
+        /* CFA1 style values */
+
+        decoded->valid = (config_reg & 1) ? true : false;
+        decoded->addr.bus = (config_reg >> 16) & 0xff;
+        decoded->addr.slot = (config_reg >> 11) & 0x1f;
+    } else {
+        /* CFA0 style values */
+
+        decoded->valid = true;
+        decoded->addr.bus = 0;
+        decoded->addr.slot = ffs(config_reg & 0xfffff800) - 1;
+    }
+
+    UNIN_DPRINTF("Converted config space accessor %08x -> %02x %02x %x\n",
+                 config_reg, decoded->addr.bus, decoded->addr.slot,
+                 decoded->addr.fn);
+}
+
 static int pci_unin_main_init_device(SysBusDevice *dev)
 {
     UNINState *s;
@@ -85,6 +115,7 @@  static int pci_unin_main_init_device(SysBusDevice *dev)
     s = FROM_SYSBUS(UNINState, dev);
 
     pci_host_init(&s->host_state);
+    s->host_state.decode_config_reg = unin_decode_config_reg;
     pci_mem_config = pci_host_conf_register_mmio(&s->host_state);
     pci_mem_data = pci_host_data_register_mmio(&s->host_state);
     sysbus_init_mmio(dev, 0x1000, pci_mem_config);