diff mbox series

[2/2] hw/pci-host/bonito: Map PCI IRQs in board code

Message ID 20230105154440.259361-3-shentey@gmail.com (mailing list archive)
State New, archived
Headers show
Series Move Fuloong2e PCI IRQ mapping to board code | expand

Commit Message

Bernhard Beschow Jan. 5, 2023, 3:44 p.m. UTC
PCI IRQ mapping is board specific, as could be seen by
pci_bonito_map_irq(). So move it to board code and rename it.

Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
 include/hw/pci-host/bonito.h |  2 ++
 hw/mips/fuloong2e.c          | 22 ++++++++++++++++++++++
 hw/pci-host/bonito.c         | 24 ------------------------
 3 files changed, 24 insertions(+), 24 deletions(-)
diff mbox series

Patch

diff --git a/include/hw/pci-host/bonito.h b/include/hw/pci-host/bonito.h
index b8ecf7870a..5ed0b48d51 100644
--- a/include/hw/pci-host/bonito.h
+++ b/include/hw/pci-host/bonito.h
@@ -12,6 +12,8 @@ 
 
 #include "qom/object.h"
 
+#define BONITO_IRQ_BASE 32
+
 #define TYPE_BONITO_PCI_HOST_BRIDGE "Bonito-pcihost"
 OBJECT_DECLARE_SIMPLE_TYPE(BonitoState, BONITO_PCI_HOST_BRIDGE)
 
diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
index f41e19dc3f..7ac5940741 100644
--- a/hw/mips/fuloong2e.c
+++ b/hw/mips/fuloong2e.c
@@ -200,6 +200,27 @@  static void main_cpu_reset(void *opaque)
     }
 }
 
+/* Map the original irq (0~3) to bonito irq (16~47, but 16~31 are unused) */
+static int pci_fuloong2e_map_irq(PCIDevice *pci_dev, int irq_num)
+{
+    int slot;
+
+    slot = PCI_SLOT(pci_dev->devfn);
+
+    switch (slot) {
+    case 5:   /* FULOONG2E_VIA_SLOT, SouthBridge, IDE, USB, ACPI, AC97, MC97 */
+        return irq_num % 4 + BONITO_IRQ_BASE;
+    case 6:   /* FULOONG2E_ATI_SLOT, VGA */
+        return 4 + BONITO_IRQ_BASE;
+    case 7:   /* FULOONG2E_RTL_SLOT, RTL8139 */
+        return 5 + BONITO_IRQ_BASE;
+    case 8 ... 12: /* PCI slot 1 to 4 */
+        return (slot - 8 + irq_num) + 6 + BONITO_IRQ_BASE;
+    default:  /* Unknown device, don't do any translation */
+        return irq_num;
+    }
+}
+
 /* Network support */
 static void network_init(PCIBus *pci_bus)
 {
@@ -297,6 +318,7 @@  static void mips_fuloong2e_init(MachineState *machine)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, env->irq[2]);
     pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci"));
+    pci_bus_map_irqs(pci_bus, pci_fuloong2e_map_irq);
 
     /* South bridge -> IP5 */
     pci_dev = pci_create_simple_multifunction(pci_bus,
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index 0ec437a623..ad1ca7e454 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -548,8 +548,6 @@  static const MemoryRegionOps bonito_spciconf_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-#define BONITO_IRQ_BASE 32
-
 static void pci_bonito_set_irq(void *opaque, int irq_num, int level)
 {
     BonitoState *s = opaque;
@@ -567,27 +565,6 @@  static void pci_bonito_set_irq(void *opaque, int irq_num, int level)
     }
 }
 
-/* map the original irq (0~3) to bonito irq (16~47, but 16~31 are unused) */
-static int pci_bonito_map_irq(PCIDevice *pci_dev, int irq_num)
-{
-    int slot;
-
-    slot = PCI_SLOT(pci_dev->devfn);
-
-    switch (slot) {
-    case 5:   /* FULOONG2E_VIA_SLOT, SouthBridge, IDE, USB, ACPI, AC97, MC97 */
-        return irq_num % 4 + BONITO_IRQ_BASE;
-    case 6:   /* FULOONG2E_ATI_SLOT, VGA */
-        return 4 + BONITO_IRQ_BASE;
-    case 7:   /* FULOONG2E_RTL_SLOT, RTL8139 */
-        return 5 + BONITO_IRQ_BASE;
-    case 8 ... 12: /* PCI slot 1 to 4 */
-        return (slot - 8 + irq_num) + 6 + BONITO_IRQ_BASE;
-    default:  /* Unknown device, don't do any translation */
-        return irq_num;
-    }
-}
-
 static void bonito_reset_hold(Object *obj)
 {
     PCIBonitoState *s = PCI_BONITO(obj);
@@ -635,7 +612,6 @@  static void bonito_host_realize(DeviceState *dev, Error **errp)
     phb->bus = pci_root_bus_new(dev, "pci", &bs->pci_mem, get_system_io(),
                                 PCI_DEVFN(5, 0), TYPE_PCI_BUS);
     pci_bus_irqs(phb->bus, pci_bonito_set_irq, dev, 32);
-    pci_bus_map_irqs(phb->bus, pci_bonito_map_irq);
 
     for (size_t i = 0; i < 3; i++) {
         char *name = g_strdup_printf("pci.lomem%zu", i);