Skip to contentSkip to conversation

Resolve isabus global

PATCH In review Bernhard Beschow 5 participants 40 messages Jan 26, 2023 – Apr 22, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover Resolve isabus global

This series resolves the global "isabus" variable and is basically a v2 of [1]. Note that the majority of the work consists of fixing ISA API calls in PIIX IDE which implicitly rely on the usage of the isabus global.

Rather than adding an ISABus pointer in PCIIDEState as in [1] this series uses a qemu_irq array which is roughly the approach outlined in [2]. Moreover, this series considers backwards compatibility for user-created PIIX IDE "Frankensten" devices by fishing out TYPE_ISA_BUS from the QOM tree inside the PIIX IDE device model. This hack can be removed again once a deprecation period of user-createable PIIX IDE devices is over. This deprecation wasn't announced yet but now might be a good time.

This series is structured as follows: The first three patches massage the ISA code for patch 8. Patches 4-8 change the PIIX IDE device models to not use the isabus global implicitly. Finally, the last two patches clan up and remove the isabus singleton.

Based-on: <[email protected]>
'Consolidate PIIX south bridges'

v2:
- Big rework sticking closer to [1], giving it more credit and reusing one patch
- Add io port cleanup
- Rebase onto [4] so changes to PIIX could be done once and centrally

Testing done:
* make check
* ./qemu-system-x86_64 -M x-remote -device piix3-ide still fails gracefully with qemu-system-x86_64: -device piix3-ide: No ISA bus found while piix3-ide requires one
* qemu-system-x86_64 -M pc -m 2G -cdrom manjaro-kde-21.3.2-220704-linux515.iso
* `qemu-system-x86_64 -M q35 -m 2G -device piix4-ide -cdrom \
manjaro-kde-21.3.2-220704-linux515.iso`
* `qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda \
debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0"`

[1] https://patchew.org/QEMU/[email protected]/
[2] https://lists.nongnu.org/archive/html/qemu-devel/2020-03/msg01707.html
[3] https://people.debian.org/~aurel32/qemu/mips/
[4] https://patchew.org/QEMU/[email protected]/

Bernhard Beschow (9):
softmmu/ioport: Move portio_list_init() in front of portio_list_add() softmmu/ioport: Merge portio_list_add() into portio_list_init() softmmu/ioport: Remove unused functions
hw/ide/piix: Disuse isa_get_irq()
Revert "hw/ide: Fix crash when plugging a piix3-ide device into the
x-remote machine"
hw/ide/pci: Add PCIIDEState::isa_irqs[]
hw/ide/piix: Require an ISABus only for user-created instances hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of
ISADevice
hw/isa/isa-bus: Resolve isabus global

Philippe Mathieu-Daudé (1):
hw/isa: Remove use of global isa bus

 include/exec/ioport.h     |  8 ++---
 include/hw/ide/internal.h |  3 +-
 include/hw/ide/pci.h      |  2 ++
 include/hw/isa/isa.h      | 15 ++++----
 hw/audio/adlib.c          |  4 +--
 hw/display/qxl.c          |  5 ++-
 hw/display/vga.c          |  8 ++---
 hw/dma/i82374.c           |  6 ++--
 hw/ide/ioport.c           | 19 +++++-----
 hw/ide/isa.c              |  4 ++-
 hw/ide/piix.c             | 75 +++++++++++++++++++++++++++++++--------
 hw/isa/isa-bus.c          | 54 +++++++++++++++-------------
 hw/isa/piix.c             |  5 +++
 hw/watchdog/wdt_ib700.c   |  4 +--
 softmmu/ioport.c          | 70 +++++++++++-------------------------
 15 files changed, 149 insertions(+), 133 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH v2 1/10 softmmu/ioport: Move portio_list_init() in front of portio_list_add()

This is a preparation for the next patch to keep its diff smaller.

---
 softmmu/ioport.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)
softmmu/ioport.c +20 -21
index cb8adb0b93..215344467b 100644
@@ -113,27 +113,6 @@ uint32_t cpu_inl(uint32_t addr)
     return val;
 }
 
-void portio_list_init(PortioList *piolist,
-                      Object *owner,
-                      const MemoryRegionPortio *callbacks,
-                      void *opaque, const char *name)
-{
-    unsigned n = 0;
-
-    while (callbacks[n].size) {
-        ++n;
-    }
-
-    piolist->ports = callbacks;
-    piolist->nr = 0;
-    piolist->regions = g_new0(MemoryRegion *, n);
-    piolist->address_space = NULL;
-    piolist->opaque = opaque;
-    piolist->owner = owner;
-    piolist->name = name;
-    piolist->flush_coalesced_mmio = false;
-}
-
 void portio_list_set_flush_coalesced(PortioList *piolist)
 {
     piolist->flush_coalesced_mmio = true;
@@ -250,6 +229,26 @@ static void portio_list_add_1(PortioList *piolist,
     ++piolist->nr;
 }
 
+void portio_list_init(PortioList *piolist, Object *owner,
+                      const MemoryRegionPortio *callbacks,
+                      void *opaque, const char *name)
+{
+    unsigned n = 0;
+
+    while (callbacks[n].size) {
+        ++n;
+    }
+
+    piolist->ports = callbacks;
+    piolist->nr = 0;
+    piolist->regions = g_new0(MemoryRegion *, n);
+    piolist->address_space = NULL;
+    piolist->opaque = opaque;
+    piolist->owner = owner;
+    piolist->name = name;
+    piolist->flush_coalesced_mmio = false;
+}
+
 void portio_list_add(PortioList *piolist,
                      MemoryRegion *address_space,
                      uint32_t start)
Signature · 1 line
2.39.1
#2 lore raw

PATCH v2 2/10 softmmu/ioport: Merge portio_list_add() into portio_list_init()

In reply to Bernhard Beschow

Both functions are always used together and in the same order. Let's reflect this in the API.

'hw/isa: Extract bus part from isa_register_portio_list()'

---
 include/exec/ioport.h   |  6 ++----
 hw/audio/adlib.c        |  4 ++--
 hw/display/qxl.c        |  5 ++---
 hw/display/vga.c        |  8 ++++----
 hw/dma/i82374.c         |  6 ++----
 hw/isa/isa-bus.c        |  6 ++----
 hw/watchdog/wdt_ib700.c |  4 ++--
 softmmu/ioport.c        | 19 +++++++------------
 8 files changed, 23 insertions(+), 35 deletions(-)
include/exec/ioport.h +2 -4
index e34f668998..ec3e8e5942 100644
@@ -64,12 +64,10 @@ typedef struct PortioList {
 
 void portio_list_init(PortioList *piolist, Object *owner,
                       const struct MemoryRegionPortio *callbacks,
-                      void *opaque, const char *name);
+                      void *opaque, const char *name,
+                      MemoryRegion *address_space_io, uint16_t start);
 void portio_list_set_flush_coalesced(PortioList *piolist);
 void portio_list_destroy(PortioList *piolist);
-void portio_list_add(PortioList *piolist,
-                     struct MemoryRegion *address_space,
-                     uint32_t addr);
 void portio_list_del(PortioList *piolist);
 
 #endif /* IOPORT_H */
hw/audio/adlib.c +2 -2
index 5f979b1487..957abe3da7 100644
@@ -291,8 +291,8 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
 
     adlib_portio_list[0].offset = s->port;
     adlib_portio_list[1].offset = s->port + 8;
-    portio_list_init (&s->port_list, OBJECT(s), adlib_portio_list, s, "adlib");
-    portio_list_add (&s->port_list, isa_address_space_io(&s->parent_obj), 0);
+    portio_list_init(&s->port_list, OBJECT(s), adlib_portio_list, s, "adlib",
+                     isa_address_space_io(&s->parent_obj), 0);
 }
 
 static Property adlib_properties[] = {
hw/display/qxl.c +2 -3
index ec712d3ca2..6d5a931425 100644
@@ -2224,10 +2224,9 @@ static void qxl_realize_primary(PCIDevice *dev, Error **errp)
     }
     vga_init(vga, OBJECT(dev),
              pci_address_space(dev), pci_address_space_io(dev), false);
-    portio_list_init(&qxl->vga_port_list, OBJECT(dev), qxl_vga_portio_list,
-                     vga, "vga");
+    portio_list_init(&qxl->vga_port_list, OBJECT(dev), qxl_vga_portio_list, vga,
+                     "vga", pci_address_space_io(dev), 0x3b0);
     portio_list_set_flush_coalesced(&qxl->vga_port_list);
-    portio_list_add(&qxl->vga_port_list, pci_address_space_io(dev), 0x3b0);
     qxl->have_vga = true;
 
     vga->con = graphic_console_init(DEVICE(dev), 0, &qxl_ops, qxl);
hw/display/vga.c +4 -4
index 7a5fdff649..2b606a526c 100644
@@ -2309,12 +2309,12 @@ void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space,
                                         1);
     memory_region_set_coalescing(vga_io_memory);
     if (init_vga_ports) {
-        portio_list_init(&s->vga_port_list, obj, vga_ports, s, "vga");
+        portio_list_init(&s->vga_port_list, obj, vga_ports, s, "vga",
+                         address_space_io, 0x3b0);
         portio_list_set_flush_coalesced(&s->vga_port_list);
-        portio_list_add(&s->vga_port_list, address_space_io, 0x3b0);
     }
     if (vbe_ports) {
-        portio_list_init(&s->vbe_port_list, obj, vbe_ports, s, "vbe");
-        portio_list_add(&s->vbe_port_list, address_space_io, 0x1ce);
+        portio_list_init(&s->vbe_port_list, obj, vbe_ports, s, "vbe",
+                         address_space_io, 0x1ce);
     }
 }
hw/dma/i82374.c +2 -4
index 34c3aaf7d3..5914b34079 100644
@@ -131,10 +131,8 @@ static void i82374_realize(DeviceState *dev, Error **errp)
     }
     i8257_dma_init(isa_bus, true);
 
-    portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s,
-                     "i82374");
-    portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj),
-                    s->iobase);
+    portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s, "i82374",
+                     isa_address_space_io(&s->parent_obj), s->iobase);
 
     memset(s->commands, 0, sizeof(s->commands));
 }
hw/isa/isa-bus.c +2 -4
index 1bee1a47f1..b3497dad61 100644
@@ -124,8 +124,6 @@ int isa_register_portio_list(ISADevice *dev,
                              const MemoryRegionPortio *pio_start,
                              void *opaque, const char *name)
 {
-    assert(piolist && !piolist->owner);
-
     if (!isabus) {
         return -ENODEV;
     }
@@ -135,8 +133,8 @@ int isa_register_portio_list(ISADevice *dev,
        actually handled e.g. the FDC device.  */
     isa_init_ioport(dev, start);
 
-    portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name);
-    portio_list_add(piolist, isabus->address_space_io, start);
+    portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name,
+                     isabus->address_space_io, start);
 
     return 0;
 }
hw/watchdog/wdt_ib700.c +2 -2
index b116c3a3aa..e53e474b83 100644
@@ -115,8 +115,8 @@ static void wdt_ib700_realize(DeviceState *dev, Error **errp)
 
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ib700_timer_expired, s);
 
-    portio_list_init(&s->port_list, OBJECT(s), wdt_portio_list, s, "ib700");
-    portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj), 0);
+    portio_list_init(&s->port_list, OBJECT(s), wdt_portio_list, s, "ib700",
+                     isa_address_space_io(&s->parent_obj), 0);
 }
 
 static void wdt_ib700_reset(DeviceState *dev)
softmmu/ioport.c +7 -12
index 215344467b..c92e3cb27d 100644
@@ -231,8 +231,13 @@ static void portio_list_add_1(PortioList *piolist,
 
 void portio_list_init(PortioList *piolist, Object *owner,
                       const MemoryRegionPortio *callbacks,
-                      void *opaque, const char *name)
+                      void *opaque, const char *name,
+                      MemoryRegion *address_space_io, uint16_t start)
 {
+    assert(piolist && !piolist->owner);
+
+    const MemoryRegionPortio *pio, *pio_start = callbacks;
+    unsigned int off_low, off_high, off_last, count;
     unsigned n = 0;
 
     while (callbacks[n].size) {
@@ -242,21 +247,11 @@ void portio_list_init(PortioList *piolist, Object *owner,
     piolist->ports = callbacks;
     piolist->nr = 0;
     piolist->regions = g_new0(MemoryRegion *, n);
-    piolist->address_space = NULL;
+    piolist->address_space = address_space_io;
     piolist->opaque = opaque;
     piolist->owner = owner;
     piolist->name = name;
     piolist->flush_coalesced_mmio = false;
-}
-
-void portio_list_add(PortioList *piolist,
-                     MemoryRegion *address_space,
-                     uint32_t start)
-{
-    const MemoryRegionPortio *pio, *pio_start = piolist->ports;
-    unsigned int off_low, off_high, off_last, count;
-
-    piolist->address_space = address_space;
 
     /* Handle the first entry specially.  */
     off_last = off_low = pio_start->offset;
Signature · 1 line
2.39.1
#3 lore raw

Re: [PATCH v2 02/10] softmmu/ioport: Merge portio_list_add() into portio_list_init()

Quoted 177 lines · Bernhard Beschow

Both functions are always used together and in the same order. Let's reflect this in the API.

'hw/isa: Extract bus part from isa_register_portio_list()'

---
  include/exec/ioport.h   |  6 ++----
  hw/audio/adlib.c        |  4 ++--
  hw/display/qxl.c        |  5 ++---
  hw/display/vga.c        |  8 ++++----
  hw/dma/i82374.c         |  6 ++----
  hw/isa/isa-bus.c        |  6 ++----
  hw/watchdog/wdt_ib700.c |  4 ++--
  softmmu/ioport.c        | 19 +++++++------------
  8 files changed, 23 insertions(+), 35 deletions(-)
include/exec/ioport.h +2 -4
index e34f668998..ec3e8e5942 100644
@@ -64,12 +64,10 @@ typedef struct PortioList {
 
  void portio_list_init(PortioList *piolist, Object *owner,
                        const struct MemoryRegionPortio *callbacks,
-                      void *opaque, const char *name);
+                      void *opaque, const char *name,
+                      MemoryRegion *address_space_io, uint16_t start);
  void portio_list_set_flush_coalesced(PortioList *piolist);
  void portio_list_destroy(PortioList *piolist);
-void portio_list_add(PortioList *piolist,
-                     struct MemoryRegion *address_space,
-                     uint32_t addr);
  void portio_list_del(PortioList *piolist);
 
  #endif /* IOPORT_H */
hw/audio/adlib.c +2 -2
index 5f979b1487..957abe3da7 100644
@@ -291,8 +291,8 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
 
      adlib_portio_list[0].offset = s->port;
      adlib_portio_list[1].offset = s->port + 8;
-    portio_list_init (&s->port_list, OBJECT(s), adlib_portio_list, s, "adlib");
-    portio_list_add (&s->port_list, isa_address_space_io(&s->parent_obj), 0);
+    portio_list_init(&s->port_list, OBJECT(s), adlib_portio_list, s, "adlib",
+                     isa_address_space_io(&s->parent_obj), 0);
  }
 
  static Property adlib_properties[] = {
hw/display/qxl.c +2 -3
index ec712d3ca2..6d5a931425 100644
@@ -2224,10 +2224,9 @@ static void qxl_realize_primary(PCIDevice *dev, Error **errp)
      }
      vga_init(vga, OBJECT(dev),
               pci_address_space(dev), pci_address_space_io(dev), false);
-    portio_list_init(&qxl->vga_port_list, OBJECT(dev), qxl_vga_portio_list,
-                     vga, "vga");
+    portio_list_init(&qxl->vga_port_list, OBJECT(dev), qxl_vga_portio_list, vga,
+                     "vga", pci_address_space_io(dev), 0x3b0);
      portio_list_set_flush_coalesced(&qxl->vga_port_list);
-    portio_list_add(&qxl->vga_port_list, pci_address_space_io(dev), 0x3b0);
      qxl->have_vga = true;
 
      vga->con = graphic_console_init(DEVICE(dev), 0, &qxl_ops, qxl);
hw/display/vga.c +4 -4
index 7a5fdff649..2b606a526c 100644
@@ -2309,12 +2309,12 @@ void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space,
                                          1);
      memory_region_set_coalescing(vga_io_memory);
      if (init_vga_ports) {
-        portio_list_init(&s->vga_port_list, obj, vga_ports, s, "vga");
+        portio_list_init(&s->vga_port_list, obj, vga_ports, s, "vga",
+                         address_space_io, 0x3b0);
          portio_list_set_flush_coalesced(&s->vga_port_list);
-        portio_list_add(&s->vga_port_list, address_space_io, 0x3b0);
      }
      if (vbe_ports) {
-        portio_list_init(&s->vbe_port_list, obj, vbe_ports, s, "vbe");
-        portio_list_add(&s->vbe_port_list, address_space_io, 0x1ce);
+        portio_list_init(&s->vbe_port_list, obj, vbe_ports, s, "vbe",
+                         address_space_io, 0x1ce);
      }
  }
hw/dma/i82374.c +2 -4
index 34c3aaf7d3..5914b34079 100644
@@ -131,10 +131,8 @@ static void i82374_realize(DeviceState *dev, Error **errp)
      }
      i8257_dma_init(isa_bus, true);
 
-    portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s,
-                     "i82374");
-    portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj),
-                    s->iobase);
+    portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s, "i82374",
+                     isa_address_space_io(&s->parent_obj), s->iobase);
 
      memset(s->commands, 0, sizeof(s->commands));
  }
hw/isa/isa-bus.c +2 -4
index 1bee1a47f1..b3497dad61 100644
@@ -124,8 +124,6 @@ int isa_register_portio_list(ISADevice *dev,
                               const MemoryRegionPortio *pio_start,
                               void *opaque, const char *name)
  {
-    assert(piolist && !piolist->owner);
-
      if (!isabus) {
          return -ENODEV;
      }
@@ -135,8 +133,8 @@ int isa_register_portio_list(ISADevice *dev,
         actually handled e.g. the FDC device.  */
      isa_init_ioport(dev, start);
 
-    portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name);
-    portio_list_add(piolist, isabus->address_space_io, start);
+    portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name,
+                     isabus->address_space_io, start);
 
      return 0;
  }
hw/watchdog/wdt_ib700.c +2 -2
index b116c3a3aa..e53e474b83 100644
@@ -115,8 +115,8 @@ static void wdt_ib700_realize(DeviceState *dev, Error **errp)
 
      s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ib700_timer_expired, s);
 
-    portio_list_init(&s->port_list, OBJECT(s), wdt_portio_list, s, "ib700");
-    portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj), 0);
+    portio_list_init(&s->port_list, OBJECT(s), wdt_portio_list, s, "ib700",
+                     isa_address_space_io(&s->parent_obj), 0);
  }
 
  static void wdt_ib700_reset(DeviceState *dev)
softmmu/ioport.c +7 -5
index 215344467b..c92e3cb27d 100644
@@ -231,8 +231,13 @@ static void portio_list_add_1(PortioList *piolist,
 
  void portio_list_init(PortioList *piolist, Object *owner,
                        const MemoryRegionPortio *callbacks,
-                      void *opaque, const char *name)
+                      void *opaque, const char *name,
+                      MemoryRegion *address_space_io, uint16_t start)
  {
+    assert(piolist && !piolist->owner);
+
+    const MemoryRegionPortio *pio, *pio_start = callbacks;
+    unsigned int off_low, off_high, off_last, count;
      unsigned n = 0;
 
      while (callbacks[n].size) {
@@ -242,21 +247,11 @@ void portio_list_init(PortioList *piolist, Object *owner,
      piolist->ports = callbacks;
      piolist->nr = 0;
      piolist->regions = g_new0(MemoryRegion *, n);
-    piolist->address_space = NULL;
+    piolist->address_space = address_space_io;
      piolist->opaque = opaque;
      piolist->owner = owner;
      piolist->name = name;
      piolist->flush_coalesced_mmio = false;
-}
-
-void portio_list_add(PortioList *piolist,

softmmu/ioport.c void portio_list_init(PortioList *piolist, Object *owner, · line 257

Quoted 10 lines
softmmu/ioport.c +0 -7
-                     MemoryRegion *address_space,
-                     uint32_t start)
-{
-    const MemoryRegionPortio *pio, *pio_start = piolist->ports;
-    unsigned int off_low, off_high, off_last, count;
-
-    piolist->address_space = address_space;
 
      /* Handle the first entry specially.  */
      off_last = off_low = pio_start->offset;

As a general comment: is portio used outside of ISA bus devices at all? It seems to me that portio is really a wrapper around the the old x86 IO port functionality, and so I could see PortioList being moved exclusively to within ISADevice which could allow the address_space, opaque and owner to be resolved automatically with the PortioList being owned by ISADevice.

ATB,

Mark.

#4 lore raw

PATCH v2 3/10 softmmu/ioport: Remove unused functions

In reply to Bernhard Beschow
---
 include/exec/ioport.h |  2 --
 softmmu/ioport.c      | 24 ------------------------
 2 files changed, 26 deletions(-)
include/exec/ioport.h +0 -2
index ec3e8e5942..1ef5aebba3 100644
@@ -67,7 +67,5 @@ void portio_list_init(PortioList *piolist, Object *owner,
                       void *opaque, const char *name,
                       MemoryRegion *address_space_io, uint16_t start);
 void portio_list_set_flush_coalesced(PortioList *piolist);
-void portio_list_destroy(PortioList *piolist);
-void portio_list_del(PortioList *piolist);
 
 #endif /* IOPORT_H */
softmmu/ioport.c +0 -24
index c92e3cb27d..0a55d39196 100644
@@ -118,19 +118,6 @@ void portio_list_set_flush_coalesced(PortioList *piolist)
     piolist->flush_coalesced_mmio = true;
 }
 
-void portio_list_destroy(PortioList *piolist)
-{
-    MemoryRegionPortioList *mrpio;
-    unsigned i;
-
-    for (i = 0; i < piolist->nr; ++i) {
-        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        object_unparent(OBJECT(&mrpio->mr));
-        g_free(mrpio);
-    }
-    g_free(piolist->regions);
-}
-
 static const MemoryRegionPortio *find_portio(MemoryRegionPortioList *mrpio,
                                              uint64_t offset, unsigned size,
                                              bool write)
@@ -280,14 +267,3 @@ void portio_list_init(PortioList *piolist, Object *owner,
     /* There will always be an open sub-list.  */
     portio_list_add_1(piolist, pio_start, count, start, off_low, off_high);
 }
-
-void portio_list_del(PortioList *piolist)
-{
-    MemoryRegionPortioList *mrpio;
-    unsigned i;
-
-    for (i = 0; i < piolist->nr; ++i) {
-        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        memory_region_del_subregion(piolist->address_space, &mrpio->mr);
-    }
-}
Signature · 1 line
2.39.1
#5 lore raw

Re: [PATCH v2 03/10] softmmu/ioport: Remove unused functions

Quoted 47 lines · Bernhard Beschow
---
  include/exec/ioport.h |  2 --
  softmmu/ioport.c      | 24 ------------------------
  2 files changed, 26 deletions(-)
include/exec/ioport.h +0 -2
index ec3e8e5942..1ef5aebba3 100644
@@ -67,7 +67,5 @@ void portio_list_init(PortioList *piolist, Object *owner,
                        void *opaque, const char *name,
                        MemoryRegion *address_space_io, uint16_t start);
  void portio_list_set_flush_coalesced(PortioList *piolist);
-void portio_list_destroy(PortioList *piolist);
-void portio_list_del(PortioList *piolist);
 
  #endif /* IOPORT_H */
softmmu/ioport.c +0 -14
index c92e3cb27d..0a55d39196 100644
@@ -118,19 +118,6 @@ void portio_list_set_flush_coalesced(PortioList *piolist)
      piolist->flush_coalesced_mmio = true;
  }
 
-void portio_list_destroy(PortioList *piolist)
-{
-    MemoryRegionPortioList *mrpio;
-    unsigned i;
-
-    for (i = 0; i < piolist->nr; ++i) {
-        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        object_unparent(OBJECT(&mrpio->mr));
-        g_free(mrpio);
-    }
-    g_free(piolist->regions);
-}
-
  static const MemoryRegionPortio *find_portio(MemoryRegionPortioList *mrpio,
                                               uint64_t offset, unsigned size,
                                               bool write)
@@ -280,14 +267,3 @@ void portio_list_init(PortioList *piolist, Object *owner,
      /* There will always be an open sub-list.  */
      portio_list_add_1(piolist, pio_start, count, start, off_low, off_high);
  }
-

softmmu/ioport.c void portio_list_init(PortioList *piolist, Object *owner, · line 293

Quoted 10 lines
softmmu/ioport.c +0 -10
-void portio_list_del(PortioList *piolist)
-{
-    MemoryRegionPortioList *mrpio;
-    unsigned i;
-
-    for (i = 0; i < piolist->nr; ++i) {
-        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        memory_region_del_subregion(piolist->address_space, &mrpio->mr);
-    }
-}

I think it may be worth leaving these functions. There were previous discussions around the cmd646 and via PCI-IDE interfaces which have a bit in PCI configuration space that switches the chip between compatibility (ISA) mode and PCI mode. I could see that switching the device to PCI mode would require removal of the old ISA ports, for example, as in PCI mode the registers would be accessed exclusively via the PCI BAR.

ATB,

Mark.

#6 lore raw

Re: [PATCH v2 03/10] softmmu/ioport: Remove unused functions

Am 5. Februar 2023 21:37:01 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 51 lines · Bernhard Beschow
Quoted 50 lines
---
  include/exec/ioport.h |  2 --
  softmmu/ioport.c      | 24 ------------------------
  2 files changed, 26 deletions(-)
include/exec/ioport.h +0 -2
index ec3e8e5942..1ef5aebba3 100644
@@ -67,7 +67,5 @@ void portio_list_init(PortioList *piolist, Object *owner,
                        void *opaque, const char *name,
                        MemoryRegion *address_space_io, uint16_t start);
  void portio_list_set_flush_coalesced(PortioList *piolist);
-void portio_list_destroy(PortioList *piolist);
-void portio_list_del(PortioList *piolist);
    #endif /* IOPORT_H */
softmmu/ioport.c +0 -17
index c92e3cb27d..0a55d39196 100644
@@ -118,19 +118,6 @@ void portio_list_set_flush_coalesced(PortioList *piolist)
      piolist->flush_coalesced_mmio = true;
  }
  -void portio_list_destroy(PortioList *piolist)
-{
-    MemoryRegionPortioList *mrpio;
-    unsigned i;
-
-    for (i = 0; i < piolist->nr; ++i) {
-        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        object_unparent(OBJECT(&mrpio->mr));
-        g_free(mrpio);
-    }
-    g_free(piolist->regions);
-}
-
  static const MemoryRegionPortio *find_portio(MemoryRegionPortioList *mrpio,
                                               uint64_t offset, unsigned size,
                                               bool write)
@@ -280,14 +267,3 @@ void portio_list_init(PortioList *piolist, Object *owner,
      /* There will always be an open sub-list.  */
      portio_list_add_1(piolist, pio_start, count, start, off_low, off_high);
  }
-
-void portio_list_del(PortioList *piolist)
-{
-    MemoryRegionPortioList *mrpio;
-    unsigned i;
Quoted 8 lines

softmmu/ioport.c void portio_list_init(PortioList *piolist, Object *owner, · line 293

Quoted 6 lines
softmmu/ioport.c +0 -6
-
-    for (i = 0; i < piolist->nr; ++i) {
-        mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        memory_region_del_subregion(piolist->address_space, &mrpio->mr);
-    }
-}

I think it may be worth leaving these functions. There were previous discussions around the cmd646 and via PCI-IDE interfaces which have a bit in PCI configuration space that switches the chip between compatibility (ISA) mode and PCI mode. I could see that switching the device to PCI mode would require removal of the old ISA ports, for example, as in PCI mode the registers would be accessed exclusively via the PCI BAR.

Sure, I can skip this patch.

BR,
Bernhard

Quoted 5 lines

ATB,

Mark.

#7 lore raw

PATCH v2 4/10 hw/ide/piix: Disuse isa_get_irq()

In reply to Bernhard Beschow

isa_get_irq() asks for an ISADevice which piix-ide doesn't provide. Passing a NULL pointer works but causes the isabus global to be used then. By fishing out TYPE_ISA_BUS from the QOM tree it is possible to achieve the same as isa_get_irq().

This is an alternative solution to commit 9405d87be25d 'hw/ide: Fix crash when plugging a piix3-ide device into the x-remote machine' which allows for cleaning up the ISA API while keeping PIIX IDE functions user-createable.

---
 hw/ide/piix.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
hw/ide/piix.c +18 -3
index 267dbf37db..a6646d9657 100644
@@ -126,7 +126,7 @@ static void piix_ide_reset(DeviceState *dev)
     pci_set_byte(pci_conf + 0x20, 0x01);  /* BMIBA: 20-23h */
 }
 
-static int pci_piix_init_ports(PCIIDEState *d)
+static int pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
 {
     static const struct {
         int iobase;
@@ -145,7 +145,7 @@ static int pci_piix_init_ports(PCIIDEState *d)
         if (ret) {
             return ret;
         }
-        ide_init2(&d->bus[i], isa_get_irq(NULL, port_info[i].isairq));
+        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
 
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
         d->bmdma[i].bus = &d->bus[i];
@@ -159,6 +159,8 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
 {
     PCIIDEState *d = PCI_IDE(dev);
     uint8_t *pci_conf = dev->config;
+    ISABus *isa_bus;
+    bool ambiguous;
     int rc;
 
     pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
@@ -168,7 +170,20 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
 
     vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
 
-    rc = pci_piix_init_ports(d);
+    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
+    if (ambiguous) {
+        error_setg(errp,
+                   "More than one ISA bus found while %s supports only one",
+                   object_get_typename(OBJECT(dev)));
+        return;
+    }
+    if (!isa_bus) {
+        error_setg(errp, "No ISA bus found while %s requires one",
+                   object_get_typename(OBJECT(dev)));
+        return;
+    }
+
+    rc = pci_piix_init_ports(d, isa_bus);
     if (rc) {
         error_setg_errno(errp, -rc, "Failed to realize %s",
                          object_get_typename(OBJECT(dev)));
Signature · 1 line
2.39.1
#8 lore raw

Re: [PATCH v2 04/10] hw/ide/piix: Disuse isa_get_irq()

Quoted 58 lines · Bernhard Beschow

isa_get_irq() asks for an ISADevice which piix-ide doesn't provide. Passing a NULL pointer works but causes the isabus global to be used then. By fishing out TYPE_ISA_BUS from the QOM tree it is possible to achieve the same as isa_get_irq().

This is an alternative solution to commit 9405d87be25d 'hw/ide: Fix crash when plugging a piix3-ide device into the x-remote machine' which allows for cleaning up the ISA API while keeping PIIX IDE functions user-createable.

---
  hw/ide/piix.c | 21 ++++++++++++++++++---
  1 file changed, 18 insertions(+), 3 deletions(-)
hw/ide/piix.c +11 -3
index 267dbf37db..a6646d9657 100644
@@ -126,7 +126,7 @@ static void piix_ide_reset(DeviceState *dev)
      pci_set_byte(pci_conf + 0x20, 0x01);  /* BMIBA: 20-23h */
  }
 
-static int pci_piix_init_ports(PCIIDEState *d)
+static int pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
  {
      static const struct {
          int iobase;
@@ -145,7 +145,7 @@ static int pci_piix_init_ports(PCIIDEState *d)
          if (ret) {
              return ret;
          }
-        ide_init2(&d->bus[i], isa_get_irq(NULL, port_info[i].isairq));
+        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
 
          bmdma_init(&d->bus[i], &d->bmdma[i], d);
          d->bmdma[i].bus = &d->bus[i];
@@ -159,6 +159,8 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
  {
      PCIIDEState *d = PCI_IDE(dev);
      uint8_t *pci_conf = dev->config;
+    ISABus *isa_bus;
+    bool ambiguous;
      int rc;
 
      pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
@@ -168,7 +170,20 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
 
      vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
 
-    rc = pci_piix_init_ports(d);
+    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
+    if (ambiguous) {
+        error_setg(errp,
+                   "More than one ISA bus found while %s supports only one",
+                   object_get_typename(OBJECT(dev)));
+        return;
+    }

hw/ide/piix.c static void pci_piix_ide_realize(PCIDevice *dev, Error **errp) · line 189

Quoted 10 lines
hw/ide/piix.c +7 -0
+    if (!isa_bus) {
+        error_setg(errp, "No ISA bus found while %s requires one",
+                   object_get_typename(OBJECT(dev)));
+        return;
+    }
+
+    rc = pci_piix_init_ports(d, isa_bus);
      if (rc) {
          error_setg_errno(errp, -rc, "Failed to realize %s",
                           object_get_typename(OBJECT(dev)));

I think the approach here to allow the PCI-ISA bridge to locate the ISABus is a good one, but I think it's worth keeping isa_get_irq() to avoid exposing the internals to devices.

For me the problem here is that isa_get_irq() accepts a NULL argument for ISADevice. I'd expect the function to look something like isa_bus_get_irq(ISABus *isa_bus, unsigned isairq) and then it is the responsibility of the caller to locate and specify the correct ISABus to avoid falling back to the isabus global.

In particular I can see a PCIDevice should be able to attempt a pci_get_isa_bus() or similar which would locate the PCI-ISA bridge and return the child ISA bus, which again is related to the cmd646/via compatibility mode feature.

This is along the lines of the similar approach I discussed in https://lists.gnu.org/archive/html/qemu-devel/2022-12/msg01443.html which is an evolution of the ideas discussed in the original thread a couple of years earlier at https://lists.nongnu.org/archive/html/qemu-devel/2020-03/msg01707.html.

ATB,

Mark.

#9 lore raw

PATCH v2 5/10 Revert "hw/ide: Fix crash when plugging a piix3-ide device into the x-remote machine"

In reply to Bernhard Beschow

Now that the PIIX IDE device models check for presence of an ISABus before using it, this fix isn't needed any longer.

This reverts commit 9405d87be25db6dff4d7b5ab48a81bbf6d083e47.

---
 include/hw/ide/internal.h |  2 +-
 include/hw/isa/isa.h      | 13 +++++--------
 hw/ide/ioport.c           | 16 ++++++----------
 hw/ide/piix.c             | 20 +++++---------------
 hw/isa/isa-bus.c          | 14 ++++----------
 5 files changed, 21 insertions(+), 44 deletions(-)
include/hw/ide/internal.h +1 -1
index fc0aa81a88..42c49414f4 100644
@@ -628,7 +628,7 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
                    int chs_trans, Error **errp);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_exit(IDEState *s);
-int ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
+void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
 void ide_register_restart_cb(IDEBus *bus);
 
 void ide_exec_cmd(IDEBus *bus, uint32_t val);
include/hw/isa/isa.h +5 -8
index 6c8a8a92cb..8dd2953211 100644
@@ -114,15 +114,12 @@ void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
  * @portio: the ports, sorted by offset.
  * @opaque: passed into the portio callbacks.
  * @name: passed into memory_region_init_io.
- *
- * Returns: 0 on success, negative error code otherwise (e.g. if the
- *          ISA bus is not available)
  */
-int isa_register_portio_list(ISADevice *dev,
-                             PortioList *piolist,
-                             uint16_t start,
-                             const MemoryRegionPortio *portio,
-                             void *opaque, const char *name);
+void isa_register_portio_list(ISADevice *dev,
+                              PortioList *piolist,
+                              uint16_t start,
+                              const MemoryRegionPortio *portio,
+                              void *opaque, const char *name);
 
 static inline ISABus *isa_bus_from_device(ISADevice *d)
 {
hw/ide/ioport.c +6 -10
index e6caa537fa..b613ff3bba 100644
@@ -50,19 +50,15 @@ static const MemoryRegionPortio ide_portio2_list[] = {
     PORTIO_END_OF_LIST(),
 };
 
-int ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
+void ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
 {
-    int ret;
-
     /* ??? Assume only ISA and PCI configurations, and that the PCI-ISA
        bridge has been setup properly to always register with ISA.  */
-    ret = isa_register_portio_list(dev, &bus->portio_list,
-                                   iobase, ide_portio_list, bus, "ide");
+    isa_register_portio_list(dev, &bus->portio_list,
+                             iobase, ide_portio_list, bus, "ide");
 
-    if (ret == 0 && iobase2) {
-        ret = isa_register_portio_list(dev, &bus->portio2_list,
-                                       iobase2, ide_portio2_list, bus, "ide");
+    if (iobase2) {
+        isa_register_portio_list(dev, &bus->portio2_list,
+                                 iobase2, ide_portio2_list, bus, "ide");
     }
-
-    return ret;
 }
hw/ide/piix.c +5 -15
index a6646d9657..5980045db0 100644
@@ -126,7 +126,7 @@ static void piix_ide_reset(DeviceState *dev)
     pci_set_byte(pci_conf + 0x20, 0x01);  /* BMIBA: 20-23h */
 }
 
-static int pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
+static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
 {
     static const struct {
         int iobase;
@@ -136,23 +136,18 @@ static int pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
         {0x1f0, 0x3f6, 14},
         {0x170, 0x376, 15},
     };
-    int i, ret;
+    int i;
 
     for (i = 0; i < 2; i++) {
         ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
-        ret = ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
-                              port_info[i].iobase2);
-        if (ret) {
-            return ret;
-        }
+        ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
+                        port_info[i].iobase2);
         ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
 
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
         d->bmdma[i].bus = &d->bus[i];
         ide_register_restart_cb(&d->bus[i]);
     }
-
-    return 0;
 }
 
 static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
@@ -161,7 +156,6 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
     uint8_t *pci_conf = dev->config;
     ISABus *isa_bus;
     bool ambiguous;
-    int rc;
 
     pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
 
@@ -183,11 +177,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
         return;
     }
 
-    rc = pci_piix_init_ports(d, isa_bus);
-    if (rc) {
-        error_setg_errno(errp, -rc, "Failed to realize %s",
-                         object_get_typename(OBJECT(dev)));
-    }
+    pci_piix_init_ports(d, isa_bus);
 }
 
 static void pci_piix_ide_exitfn(PCIDevice *dev)
hw/isa/isa-bus.c +4 -10
index b3497dad61..d3e2d9de35 100644
@@ -119,15 +119,11 @@ void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start)
     isa_init_ioport(dev, start);
 }
 
-int isa_register_portio_list(ISADevice *dev,
-                             PortioList *piolist, uint16_t start,
-                             const MemoryRegionPortio *pio_start,
-                             void *opaque, const char *name)
+void isa_register_portio_list(ISADevice *dev,
+                              PortioList *piolist, uint16_t start,
+                              const MemoryRegionPortio *pio_start,
+                              void *opaque, const char *name)
 {
-    if (!isabus) {
-        return -ENODEV;
-    }
-
     /* START is how we should treat DEV, regardless of the actual
        contents of the portio array.  This is how the old code
        actually handled e.g. the FDC device.  */
@@ -135,8 +131,6 @@ int isa_register_portio_list(ISADevice *dev,
 
     portio_list_init(piolist, OBJECT(dev), pio_start, opaque, name,
                      isabus->address_space_io, start);
-
-    return 0;
 }
 
 ISADevice *isa_new(const char *name)
Signature · 1 line
2.39.1
#10 lore raw

PATCH v2 6/10 hw/ide/pci: Add PCIIDEState::isa_irqs[]

In reply to Bernhard Beschow

These legacy ISA IRQs allow the PIIX IDE functions to be wired up in their south bridges and the VIA IDE functions to disuse PCI_INTERRUPT_LINE as outlined in https://lists.nongnu.org/archive/html/
qemu-devel/2020-03/msg01707.html .

---
 include/hw/ide/pci.h | 1 +
 1 file changed, 1 insertion(+)
include/hw/ide/pci.h +1 -0
index 2a6284acac..24c0b7a2dd 100644
@@ -49,6 +49,7 @@ struct PCIIDEState {
 
     IDEBus bus[2];
     BMDMAState bmdma[2];
+    qemu_irq isa_irqs[2];
     uint32_t secondary; /* used only for cmd646 */
     MemoryRegion bmdma_bar;
     MemoryRegion cmd_bar[2];
Signature · 1 line
2.39.1
#11 lore raw

Re: [PATCH v2 06/10] hw/ide/pci: Add PCIIDEState::isa_irqs[]

Am 26. Januar 2023 21:17:36 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 5 lines

These legacy ISA IRQs allow the PIIX IDE functions to be wired up in their south bridges and the VIA IDE functions to disuse PCI_INTERRUPT_LINE as outlined in https://lists.nongnu.org/archive/html/
qemu-devel/2020-03/msg01707.html .

Quoted 17 lines

---
include/hw/ide/pci.h | 1 +

1 file changed, 1 insertion(+)
include/hw/ide/pci.h +1 -0
index 2a6284acac..24c0b7a2dd 100644
@@ -49,6 +49,7 @@ struct PCIIDEState {
 
    IDEBus bus[2];
    BMDMAState bmdma[2];
+    qemu_irq isa_irqs[2];
    uint32_t secondary; /* used only for cmd646 */
    MemoryRegion bmdma_bar;
    MemoryRegion cmd_bar[2];
#12 lore raw

Re: [PATCH v2 06/10] hw/ide/pci: Add PCIIDEState::isa_irqs[]

Quoted 15 lines · Bernhard Beschow

Am 26. Januar 2023 21:17:36 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 5 lines

These legacy ISA IRQs allow the PIIX IDE functions to be wired up in their south bridges and the VIA IDE functions to disuse PCI_INTERRUPT_LINE as outlined in https://lists.nongnu.org/archive/html/
qemu-devel/2020-03/msg01707.html .

Quoted 4 lines

---
include/hw/ide/pci.h | 1 +

1 file changed, 1 insertion(+)
#13 lore raw

PATCH v2 7/10 hw/ide/piix: Require an ISABus only for user-created instances

In reply to Bernhard Beschow

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
 include/hw/ide/pci.h |  1 +
 hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
 hw/isa/piix.c        |  5 ++++
 3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
     MemoryRegion bmdma_bar;
     MemoryRegion cmd_bar[2];
     MemoryRegion data_bar[2];
+    bool user_created;
 };
 
 static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +50 -14

125 lines not on this page · raw message

hw/isa/piix.c +5 -0
index 54a1246a9d..f9974c2a77 100644
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
 
     /* IDE */
     qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
     if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
         return;
     }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
 
     /* USB */
     if (d->has_usb) {
Signature · 1 line
2.39.1
#14 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 171 lines · Bernhard Beschow

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
  include/hw/ide/pci.h |  1 +
  hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
  hw/isa/piix.c        |  5 ++++
  3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
      MemoryRegion bmdma_bar;
      MemoryRegion cmd_bar[2];
      MemoryRegion data_bar[2];
+    bool user_created;
  };
 
  static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +50 -14
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
      }
  }
 
+static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
  static void piix_ide_reset(DeviceState *dev)
  {
      PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
      };
      int i;
 
+    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
      for (i = 0; i < 2; i++) {
          ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
          ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                          port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
 
          bmdma_init(&d->bus[i], &d->bmdma[i], d);
          d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
  {
      PCIIDEState *d = PCI_IDE(dev);
      uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
 
      pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
 
@@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
 
      vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
 
-    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one",
-                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
      }
 
      pci_piix_init_ports(d, isa_bus);
  }
 
+static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
  static void pci_piix_ide_exitfn(PCIDevice *dev)
  {
      PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
      }
  }
 
+static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
  /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
  static void piix3_ide_class_init(ObjectClass *klass, void *data)
  {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
      k->class_id = PCI_CLASS_STORAGE_IDE;
      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
      dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
 
  static const TypeInfo piix3_ide_info = {
      .name          = TYPE_PIIX3_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix3_ide_class_init,
  };
 
@@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
      k->class_id = PCI_CLASS_STORAGE_IDE;
      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
      dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
 
  static const TypeInfo piix4_ide_info = {
      .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init,
  };
 
hw/isa/piix.c +1 -0
index 54a1246a9d..f9974c2a77 100644
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
 
      /* IDE */
      qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 358

Quoted 10 lines
hw/isa/piix.c +4 -0
      if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
          return;
      }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
 
      /* USB */
      if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

ATB,

Mark.

#15 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 168 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
  include/hw/ide/pci.h |  1 +
  hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
  hw/isa/piix.c        |  5 ++++
  3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
      MemoryRegion bmdma_bar;
      MemoryRegion cmd_bar[2];
      MemoryRegion data_bar[2];
+    bool user_created;
  };
    static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
      }
  }
  +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
  static void piix_ide_reset(DeviceState *dev)
  {
      PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, 
 ISABus *isa_bus)
      };
      int i;
  +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
      for (i = 0; i < 2; i++) {
          ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
          ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                          port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
            bmdma_init(&d->bus[i], &d->bmdma[i], d);
          d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error 
 **errp)
  {
      PCIIDEState *d = PCI_IDE(dev);
      uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
        pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
  @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, 

Error **errp)

        vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

- isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
&ambiguous));

hw/ide/piix.c +0 -3
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only 

one",

hw/ide/piix.c +9 -7
-                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only 

one",

hw/ide/piix.c +21 -0
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
      }
        pci_piix_init_ports(d, isa_bus);
  }
  +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
  static void pci_piix_ide_exitfn(PCIDevice *dev)
  {
      PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
      }
  }
  +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
  /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
  static void piix3_ide_class_init(ObjectClass *klass, void *data)
  {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, 
 void *data)
      k->class_id = PCI_CLASS_STORAGE_IDE;
      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
      dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix3_ide_info = {
      .name          = TYPE_PIIX3_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix3_ide_class_init,
  };
  @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass 

*klass, void *data)

      k->class_id = PCI_CLASS_STORAGE_IDE;
      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
      dc->hotpluggable = false;
hw/ide/piix.c +2 -0
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = {
      .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init,
  };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c

index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +1 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const 
 char *uhci_type,
        /* IDE */
      qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
      if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
          return;
      }
Quoted 8 lines

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 358

Quoted 6 lines
hw/isa/piix.c +4 -0
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
        /* USB */
      if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

Regards,
BALATON Zoltan

#16 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 172 lines · BALATON Zoltan
Quoted 162 lines · Mark Cave-Ayland
Quoted 161 lines · Bernhard Beschow

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
  include/hw/ide/pci.h |  1 +
  hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++---------- hw/isa/piix.c        |  5 ++++

  3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
       MemoryRegion bmdma_bar;
       MemoryRegion cmd_bar[2];
       MemoryRegion data_bar[2];
+    bool user_created;
   };
     static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
       }
   }
   +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
   static void piix_ide_reset(DeviceState *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus 
 *isa_bus)
       };
       int i;
   +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
       for (i = 0; i < 2; i++) {
           ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
           ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                           port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
             bmdma_init(&d->bus[i], &d->bmdma[i], d);
           d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
   {
       PCIIDEState *d = PCI_IDE(dev);
       uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;

        pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
  @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp) vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous)); -    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +16 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }

      }
        pci_piix_init_ports(d, isa_bus);
  }
  +static void pci_piix_ide_init(Object *obj)

hw/ide/piix.c +6 -0
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+

  static void pci_piix_ide_exitfn(PCIDevice *dev)
  {
      PCIIDEState *d = PCI_IDE(dev);

hw/ide/piix.c +6 -0
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
       }
   }
   +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
   /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
   static void piix3_ide_class_init(ObjectClass *klass, void *data)
   {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void 
 *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;
       set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
       dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
   }
     static const TypeInfo piix3_ide_info = {
       .name          = TYPE_PIIX3_IDE,
       .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
       .class_init    = piix3_ide_class_init,
   };
   @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)

      k->class_id = PCI_CLASS_STORAGE_IDE; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties); }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init, .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +1 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char 
 *uhci_type,
         /* IDE */
       qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
       if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
           return;
       }
Quoted 8 lines

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 358

Quoted 6 lines
hw/isa/piix.c +4 -0
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
         /* USB */
       if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

ATB,

Mark.

#17 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 19 lines · Mark Cave-Ayland
Quoted 16 lines · BALATON Zoltan
Quoted 15 lines · Mark Cave-Ayland
Quoted 14 lines · Bernhard Beschow

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
  include/hw/ide/pci.h |  1 +
  hw/ide/piix.c        | 64
++++++++++++++++++++++++++++++++++----------
  hw/isa/piix.c        |  5 ++++

  3 files changed, 56 insertions(+), 14 deletions(-)
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

Orthogonal to this discussion, one problem I see here is a device exposing 2 interfaces: ISA and PCI. QOM does support interfaces, but ISA and PCI aren't QOM interfaces. The QOM cast macros are written as a QOM object can only inherit one parent. Should we stick to QDev and convert ISA/PCI as QOM interfaces? That could solve some QDev IDE limitations...

#18 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Mark Cave-Ayland
Quoted 16 lines · BALATON Zoltan
Quoted 14 lines · Mark Cave-Ayland
Quoted 13 lines · Bernhard Beschow

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
  include/hw/ide/pci.h |  1 +
  hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++---------- hw/isa/piix.c        |  5 ++++

  3 files changed, 56 insertions(+), 14 deletions(-)
Quoted 3 lines
Quoted 1 line

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Quoted 8 lines
Quoted 1 line

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

Orthogonal to this discussion, one problem I see here is a device exposing 2 interfaces: ISA and PCI. QOM does support interfaces, but ISA and PCI aren't QOM interfaces. The QOM cast macros are written as a QOM object can only inherit one parent. Should we stick to QDev and convert ISA/PCI as QOM interfaces? That could solve some QDev IDE limitations...

The normal approach to this is to encapsulate the chip functionality as a set of common functions, for example see esp.c and then have separate files such as esp-pci.c and esp-isa.c which can be compiled accordingly using Kconfig dependencies.

FWIW the ability to support a legacy mode is only something that would be present in the generation of mixed PCI/ISA motherboards, and so probably not something that is worth the effort of reworking separate PCI and ISA QOM interfaces.

ATB,

Mark.

#19 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

In reply to Mark Cave-Ayland

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 171 lines · BALATON Zoltan
Quoted 170 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow
Quoted 154 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
  include/hw/ide/pci.h |  1 +
  hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++---------- hw/isa/piix.c        |  5 ++++

  3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
       MemoryRegion bmdma_bar;
       MemoryRegion cmd_bar[2];
       MemoryRegion data_bar[2];
+    bool user_created;
   };
     static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
       }
   }
   +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
   static void piix_ide_reset(DeviceState *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
       };
       int i;
   +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
       for (i = 0; i < 2; i++) {
           ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
           ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                           port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
             bmdma_init(&d->bus[i], &d->bmdma[i], d);
           d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
   {
       PCIIDEState *d = PCI_IDE(dev);
       uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;

        pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
  @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp) vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);
  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous)); -    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +16 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }

      }
        pci_piix_init_ports(d, isa_bus);
  }
  +static void pci_piix_ide_init(Object *obj)

hw/ide/piix.c +6 -0
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+

  static void pci_piix_ide_exitfn(PCIDevice *dev)
  {
      PCIIDEState *d = PCI_IDE(dev);

hw/ide/piix.c +6 -0
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
       }
   }
   +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
   /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
   static void piix3_ide_class_init(ObjectClass *klass, void *data)
   {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;
       set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
       dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
   }
     static const TypeInfo piix3_ide_info = {
       .name          = TYPE_PIIX3_IDE,
       .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
       .class_init    = piix3_ide_class_init,
   };
   @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties); }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init, .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
         /* IDE */
       qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
       if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
           return;
       }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
         /* USB */
       if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 5 lines
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

Best regards,
Bernhard

Quoted 5 lines

ATB,

Mark.

#20 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 28 lines · Bernhard Beschow

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 17 lines · BALATON Zoltan
Quoted 15 lines · Mark Cave-Ayland
Quoted 14 lines · Bernhard Beschow
Quoted 13 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
   include/hw/ide/pci.h |  1 +
   hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
   hw/isa/piix.c        |  5 ++++
   3 files changed, 56 insertions(+), 14 deletions(-)
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

Quoted 7 lines

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

Yes :)

#21 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

In reply to Bernhard Beschow
Quoted 180 lines · Bernhard Beschow

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 171 lines · BALATON Zoltan
Quoted 170 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow
Quoted 154 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
   include/hw/ide/pci.h |  1 +
   hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
   hw/isa/piix.c        |  5 ++++
   3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
       MemoryRegion bmdma_bar;
       MemoryRegion cmd_bar[2];
       MemoryRegion data_bar[2];
+    bool user_created;
   };
     static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
       }
   }
   +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
   static void piix_ide_reset(DeviceState *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
       };
       int i;
   +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
       for (i = 0; i < 2; i++) {
           ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
           ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                           port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
             bmdma_init(&d->bus[i], &d->bmdma[i], d);
           d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
   {
       PCIIDEState *d = PCI_IDE(dev);
       uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
         pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
   @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
         vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +28 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
       }
         pci_piix_init_ports(d, isa_bus);
   }
   +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
   static void pci_piix_ide_exitfn(PCIDevice *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
       }
   }
   +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
   /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
   static void piix3_ide_class_init(ObjectClass *klass, void *data)
   {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;
       set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
       dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
   }
     static const TypeInfo piix3_ide_info = {
       .name          = TYPE_PIIX3_IDE,
       .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
       .class_init    = piix3_ide_class_init,
   };
   @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
         /* IDE */
       qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
       if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
           return;
       }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
         /* USB */
       if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 5 lines
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

Quoted 7 lines

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

The cmd646 datasheet section 1.4 has a fleeting mention of a document called "PCI IDE Controller Specification Revision 1.0" which if you can find it, may provide more information as to whether this ability is specific to the cmd646 or whether it is also relevant to generic PCI-IDE controllers such as the PIIX series too.

ATB,

Mark.

#22 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Am 7. Februar 2023 20:52:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 186 lines · Bernhard Beschow
Quoted 185 lines

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 171 lines · BALATON Zoltan
Quoted 170 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow
Quoted 154 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
   include/hw/ide/pci.h |  1 +
   hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
   hw/isa/piix.c        |  5 ++++
   3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
       MemoryRegion bmdma_bar;
       MemoryRegion cmd_bar[2];
       MemoryRegion data_bar[2];
+    bool user_created;
   };
     static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
       }
   }
   +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
   static void piix_ide_reset(DeviceState *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
       };
       int i;
   +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
       for (i = 0; i < 2; i++) {
           ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
           ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                           port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
             bmdma_init(&d->bus[i], &d->bmdma[i], d);
           d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
   {
       PCIIDEState *d = PCI_IDE(dev);
       uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
         pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
   @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
         vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +28 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
       }
         pci_piix_init_ports(d, isa_bus);
   }
   +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
   static void pci_piix_ide_exitfn(PCIDevice *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
       }
   }
   +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
   /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
   static void piix3_ide_class_init(ObjectClass *klass, void *data)
   {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;
       set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
       dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
   }
     static const TypeInfo piix3_ide_info = {
       .name          = TYPE_PIIX3_IDE,
       .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
       .class_init    = piix3_ide_class_init,
   };
   @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
         /* IDE */
       qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
       if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
           return;
       }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
         /* USB */
       if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 5 lines
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

Quoted 7 lines
Quoted 3 lines

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

PIIX4's description of PROG_IF (0x9):
"Programming Interface (PI). 80h=Capable of IDE bus master operation."

VT82C686B in comparison:
7 Master IDE Capability...........fixed at 1 (Supported)
3 Programmable Indicator - Secondary......fixed at 1 Supports both modes 1 Programmable Indicator - Primary..........fixed at 1 Supports both modes

So VT82C686B can switch modes while PIIX can't. Right?

Furthermore, from the PIIX4 documentation of bit 2 of the bus master status register BMISX (IO):

"IDE Interrupt Status (IDEINTS)—R/WC. This bit, when set to a 1, indicates when an IDE device has asserted its interrupt line. When bit 2=1, all read data from the IDE device has been transferred to main memory and all write data has been transferred to the IDE device. Software sets this bit to a 0 by writing a 1 to it. IRQ14 is used for the primary channel and IRQ15 is used for the secondary channel. Note that, if the interrupt status bit is set to a 0 by writing a 1 to this bit while the interrupt line is still at the active level, this bit remains 0 until another assertion edge is detected on the interrupt line."

So the legacy ISA IRQs seem to be used always.

The VIA documentation offers a control register where "native" or "legacy" mode interrupt routing can be selected. I haven't found a similar register for PIIX4.

So it seems to me that PIIX can't switch modes...

Quoted 2 lines

The cmd646 datasheet section 1.4 has a fleeting mention of a document called "PCI IDE Controller Specification Revision 1.0" which if you can find it, may provide more information as to whether this ability is specific to the cmd646 or whether it is also relevant to generic PCI-IDE controllers such as the PIIX series too.

I used VT82C686B above instead of cmd646 if that's okay. I'd need to read the IDE controller specification still. But perhaps we're already wiser?

Best regards,
Bernhard

Quoted 5 lines

ATB,

Mark.

#23 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 175 lines · Bernhard Beschow

Am 7. Februar 2023 20:52:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 174 lines · Bernhard Beschow
Quoted 173 lines

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 172 lines · BALATON Zoltan
Quoted 171 lines · Mark Cave-Ayland
Quoted 159 lines · Bernhard Beschow
Quoted 158 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
   include/hw/ide/pci.h |  1 +
   hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
   hw/isa/piix.c        |  5 ++++
   3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
       MemoryRegion bmdma_bar;
       MemoryRegion cmd_bar[2];
       MemoryRegion data_bar[2];
+    bool user_created;
   };
     static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
       }
   }
   +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
   static void piix_ide_reset(DeviceState *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
       };
       int i;
   +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
       for (i = 0; i < 2; i++) {
           ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
           ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                           port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
             bmdma_init(&d->bus[i], &d->bmdma[i], d);
           d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
   {
       PCIIDEState *d = PCI_IDE(dev);
       uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
         pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
   @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
         vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +28 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
       }
         pci_piix_init_ports(d, isa_bus);
   }
   +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
   static void pci_piix_ide_exitfn(PCIDevice *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
       }
   }
   +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
   /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
   static void piix3_ide_class_init(ObjectClass *klass, void *data)
   {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;
       set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
       dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
   }
     static const TypeInfo piix3_ide_info = {
       .name          = TYPE_PIIX3_IDE,
       .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
       .class_init    = piix3_ide_class_init,
   };
   @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +1 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
         /* IDE */
       qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
       if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
           return;
       }
Quoted 8 lines

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 6 lines
hw/isa/piix.c +4 -0
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
         /* USB */
       if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently

(such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

Quoted 22 lines
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

Quoted 7 lines
Quoted 3 lines

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

PIIX4's description of PROG_IF (0x9):
"Programming Interface (PI). 80h=Capable of IDE bus master operation."

Quoted 6 lines

VT82C686B in comparison:
7 Master IDE Capability...........fixed at 1 (Supported)
3 Programmable Indicator - Secondary......fixed at 1 Supports both modes 1 Programmable Indicator - Primary..........fixed at 1 Supports both modes

So VT82C686B can switch modes while PIIX can't. Right?

Unless there's some other bit somewhere... These all-in-one chips can be confusing.

Quoted 7 lines

Furthermore, from the PIIX4 documentation of bit 2 of the bus master status register BMISX (IO):

"IDE Interrupt Status (IDEINTS)—R/WC. This bit, when set to a 1, indicates when an IDE device has asserted its interrupt line. When bit 2=1, all read data from the IDE device has been transferred to main memory and all write data has been transferred to the IDE device. Software sets this bit to a 0 by writing a 1 to it. IRQ14 is used for the primary channel and IRQ15 is used for the secondary channel. Note that, if the interrupt status bit is set to a 0 by writing a 1 to this bit while the interrupt line is still at the active level, this bit remains 0 until another assertion edge is detected on the interrupt line."

So the legacy ISA IRQs seem to be used always.

The VIA documentation offers a control register where "native" or "legacy" mode interrupt routing can be selected. I haven't found a similar register for PIIX4.

While from the docs it looks like that we have found before that on some machines this does not work and even after writing some value the control reg irqs remain set to legacy and software expects that. This is the case on pegasos2 where the firmware does write the reg but then OSes still use IRQ 14/15 for ide. Not sure about the fuloong2e but I think different Linux kernels did different things on that machine. We have spent a lot of time with this back then and I think found that just strapping the IRQ to legacy and setting the regs on reset as we set now works for all guests we tried so I'd be wary to touch this again. Out cuttent model may be incomplete only modeling one mode of the chip but this mode is what's used so I don't think it's worth trying to umplement an unused state that will be reset by the firmware anyway so nothing will use that.

(We're spamming a lot of people with this, maybe you could prune the cc if this is not any more relevant to the original patch.)

Regards,
BALATON Zoltan

Quoted 17 lines

So it seems to me that PIIX can't switch modes...

Quoted 2 lines

The cmd646 datasheet section 1.4 has a fleeting mention of a document called "PCI IDE Controller Specification Revision 1.0" which if you can find it, may provide more information as to whether this ability is specific to the cmd646 or whether it is also relevant to generic PCI-IDE controllers such as the PIIX series too.

I used VT82C686B above instead of cmd646 if that's okay. I'd need to read the IDE controller specification still. But perhaps we're already wiser?

Best regards,
Bernhard

Quoted 5 lines

ATB,

Mark.

#24 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 44 lines · BALATON Zoltan
Quoted 43 lines · Bernhard Beschow

Am 7. Februar 2023 20:52:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 42 lines · Bernhard Beschow
Quoted 41 lines

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 40 lines · BALATON Zoltan
Quoted 39 lines · Mark Cave-Ayland
Quoted 37 lines · Bernhard Beschow
Quoted 24 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
   include/hw/ide/pci.h |  1 +
   hw/ide/piix.c        | 64
++++++++++++++++++++++++++++++++++----------
   hw/isa/piix.c        |  5 ++++

   3 files changed, 56 insertions(+), 14 deletions(-)

   diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice 
 *dev, const char *uhci_type,
          /* IDE */
        qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice · line 357

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
        if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
            return;
        }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
          /* USB */
        if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently

 (such as we do things differently now compared to what we did years
ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon.

Indeed we don't want (and have the time) to model features we don't need or will never use. However taking the time to correctly understand these devices help us to correctly model them. In particular when design flaws have been identified in some models.

Quoted 1 line

But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

We certainly want to keep what we currently have working :)

Quoted 34 lines
Quoted 21 lines
Quoted 10 lines
Quoted 10 lines
Quoted 3 lines

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

   "Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

Quoted 7 lines
Quoted 3 lines

   "PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

PIIX4's description of PROG_IF (0x9):
 "Programming Interface (PI). 80h=Capable of IDE bus master operation."

Quoted 6 lines

VT82C686B in comparison:
 7 Master IDE Capability...........fixed at 1 (Supported)
 3 Programmable Indicator - Secondary......fixed at 1 Supports both modes 1 Programmable Indicator - Primary..........fixed at 1 Supports both modes

So VT82C686B can switch modes while PIIX can't. Right?

Unless there's some other bit somewhere... These all-in-one chips can be confusing.

Quoted 4 lines

Furthermore, from the PIIX4 documentation of bit 2 of the bus master status register BMISX (IO):

 "IDE Interrupt Status (IDEINTS)—R/WC. This bit, when set to a 1, indicates when an IDE device has asserted its interrupt line. When bit 2=1, all read data from the IDE device has been transferred to main memory and all write data has been transferred to the IDE device. Software sets this bit to a 0 by writing a 1 to it. IRQ14 is used for the primary channel and IRQ15 is used for the secondary channel. Note that, if the interrupt status bit is set to a 0 by writing a 1 to this bit while the interrupt line is still at the active level, this bit remains 0 until another assertion edge is detected on the interrupt line."

Quoted 7 lines
Quoted 3 lines

So the legacy ISA IRQs seem to be used always.

The VIA documentation offers a control register where "native" or "legacy" mode interrupt routing can be selected. I haven't found a similar register for PIIX4.

While from the docs it looks like that we have found before that on some machines this does not work and even after writing some value the control reg irqs remain set to legacy and software expects that. This is the case on pegasos2 where the firmware does write the reg but then OSes still use IRQ 14/15 for ide. Not sure about the fuloong2e but I think different Linux kernels did different things on that machine. We have spent a lot of time with this back then and I think found that just strapping the IRQ to legacy and setting the regs on reset as we set now works for all guests we tried so I'd be wary to touch this again. Out cuttent model may be incomplete only modeling one mode of the chip but this mode is what's used so I don't think it's worth trying to umplement an unused state that will be reset by the firmware anyway so nothing will use that.

(We're spamming a lot of people with this, maybe you could prune the cc if this is not any more relevant to the original patch.)

Don't worry too much about that, it is easier to filter out message than figuring you are interested and try to filter in everything. Better safe than sorry!

Quoted 17 lines
Quoted 17 lines

So it seems to me that PIIX can't switch modes...

Quoted 2 lines

The cmd646 datasheet section 1.4 has a fleeting mention of a document called "PCI IDE Controller Specification Revision 1.0" which if you can find it, may provide more information as to whether this ability is specific to the cmd646 or whether it is also relevant to generic PCI-IDE controllers such as the PIIX series too.

I used VT82C686B above instead of cmd646 if that's okay. I'd need to read the IDE controller specification still. But perhaps we're already wiser?

Best regards,
Bernhard

Quoted 5 lines

ATB,

Mark.

#25 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

In reply to Bernhard Beschow
Quoted 205 lines · Bernhard Beschow

Am 7. Februar 2023 20:52:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 186 lines · Bernhard Beschow
Quoted 185 lines

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 171 lines · BALATON Zoltan
Quoted 170 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow
Quoted 154 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
    include/hw/ide/pci.h |  1 +
    hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
    hw/isa/piix.c        |  5 ++++
    3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
        MemoryRegion bmdma_bar;
        MemoryRegion cmd_bar[2];
        MemoryRegion data_bar[2];
+    bool user_created;
    };
      static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
        }
    }
    +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
    static void piix_ide_reset(DeviceState *dev)
    {
        PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
        };
        int i;
    +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
        for (i = 0; i < 2; i++) {
            ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
            ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                            port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
              bmdma_init(&d->bus[i], &d->bmdma[i], d);
            d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
    {
        PCIIDEState *d = PCI_IDE(dev);
        uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
          pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
    @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
          vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +28 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
        }
          pci_piix_init_ports(d, isa_bus);
    }
    +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
    static void pci_piix_ide_exitfn(PCIDevice *dev)
    {
        PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
        }
    }
    +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
    /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
    static void piix3_ide_class_init(ObjectClass *klass, void *data)
    {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
        k->class_id = PCI_CLASS_STORAGE_IDE;
        set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
        dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
    }
      static const TypeInfo piix3_ide_info = {
        .name          = TYPE_PIIX3_IDE,
        .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
        .class_init    = piix3_ide_class_init,
    };
    @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
        k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
          /* IDE */
        qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
        if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
            return;
        }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
          /* USB */
        if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 5 lines
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

Quoted 7 lines
Quoted 3 lines

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

PIIX4's description of PROG_IF (0x9):
"Programming Interface (PI). 80h=Capable of IDE bus master operation."

VT82C686B in comparison:
7 Master IDE Capability...........fixed at 1 (Supported)
3 Programmable Indicator - Secondary......fixed at 1 Supports both modes 1 Programmable Indicator - Primary..........fixed at 1 Supports both modes

Quoted 7 lines

So VT82C686B can switch modes while PIIX can't. Right?

Furthermore, from the PIIX4 documentation of bit 2 of the bus master status register BMISX (IO):

"IDE Interrupt Status (IDEINTS)—R/WC. This bit, when set to a 1, indicates when an IDE device has asserted its interrupt line. When bit 2=1, all read data from the IDE device has been transferred to main memory and all write data has been transferred to the IDE device. Software sets this bit to a 0 by writing a 1 to it. IRQ14 is used for the primary channel and IRQ15 is used for the secondary channel. Note that, if the interrupt status bit is set to a 0 by writing a 1 to this bit while the interrupt line is still at the active level, this bit remains 0 until another assertion edge is detected on the interrupt line."

So the legacy ISA IRQs seem to be used always.

See also:

11.3.4. DEVICE LOCATION ON PCI BUS OR ISA BUS

Most of the peripheral devices have the capability to exist on the PCI Bus or the ISA/EIO Bus. However, PIIX4 does not support RTC or Keyboard Controller to be resided on the PCI Bus. The Device Activity Monitor is watching cycles on the PCI bus to generate activity events. The device monitors also can be enabled to forward cycles to the device’s enabled addresses to the ISA bus. Devices that reside on the ISA Bus must have both address ranges selected and enabled AND the ISA/EIO forwarding enabled. [...]

#26 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

In reply to Mark Cave-Ayland

Am 7. Februar 2023 20:52:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 186 lines · Bernhard Beschow
Quoted 185 lines

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 171 lines · BALATON Zoltan
Quoted 170 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow
Quoted 154 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
   include/hw/ide/pci.h |  1 +
   hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
   hw/isa/piix.c        |  5 ++++
   3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
       MemoryRegion bmdma_bar;
       MemoryRegion cmd_bar[2];
       MemoryRegion data_bar[2];
+    bool user_created;
   };
     static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
       }
   }
   +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
   static void piix_ide_reset(DeviceState *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
       };
       int i;
   +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
       for (i = 0; i < 2; i++) {
           ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
           ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                           port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
             bmdma_init(&d->bus[i], &d->bmdma[i], d);
           d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
   {
       PCIIDEState *d = PCI_IDE(dev);
       uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
         pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
   @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
         vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +28 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
       }
         pci_piix_init_ports(d, isa_bus);
   }
   +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
   static void pci_piix_ide_exitfn(PCIDevice *dev)
   {
       PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
       }
   }
   +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
   /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
   static void piix3_ide_class_init(ObjectClass *klass, void *data)
   {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;
       set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
       dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
   }
     static const TypeInfo piix3_ide_info = {
       .name          = TYPE_PIIX3_IDE,
       .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
       .class_init    = piix3_ide_class_init,
   };
   @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
       k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
         /* IDE */
       qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
       if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
           return;
       }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
         /* USB */
       if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 5 lines
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

Quoted 7 lines
Quoted 3 lines

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

A switch is definitely impossible: The PIIX IDE function has the 0x3c (interrupt line) and 0x3d (interrupt pin) registers reserved. It's fixed in legacy mode (prog-if is 0x80).

Best regards,
Bernhard

Quoted 7 lines

The cmd646 datasheet section 1.4 has a fleeting mention of a document called "PCI IDE Controller Specification Revision 1.0" which if you can find it, may provide more information as to whether this ability is specific to the cmd646 or whether it is also relevant to generic PCI-IDE controllers such as the PIIX series too.

ATB,

Mark.

#27 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Quoted 193 lines · Bernhard Beschow

Am 7. Februar 2023 20:52:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 190 lines · Bernhard Beschow
Quoted 188 lines

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 171 lines · BALATON Zoltan
Quoted 170 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow
Quoted 154 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
    include/hw/ide/pci.h |  1 +
    hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
    hw/isa/piix.c        |  5 ++++
    3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
        MemoryRegion bmdma_bar;
        MemoryRegion cmd_bar[2];
        MemoryRegion data_bar[2];
+    bool user_created;
    };
      static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
        }
    }
    +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
    static void piix_ide_reset(DeviceState *dev)
    {
        PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
        };
        int i;
    +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
        for (i = 0; i < 2; i++) {
            ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
            ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                            port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
              bmdma_init(&d->bus[i], &d->bmdma[i], d);
            d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
    {
        PCIIDEState *d = PCI_IDE(dev);
        uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
          pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
    @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
          vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +28 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
        }
          pci_piix_init_ports(d, isa_bus);
    }
    +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
    static void pci_piix_ide_exitfn(PCIDevice *dev)
    {
        PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
        }
    }
    +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
    /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
    static void piix3_ide_class_init(ObjectClass *klass, void *data)
    {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
        k->class_id = PCI_CLASS_STORAGE_IDE;
        set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
        dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
    }
      static const TypeInfo piix3_ide_info = {
        .name          = TYPE_PIIX3_IDE,
        .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
        .class_init    = piix3_ide_class_init,
    };
    @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
        k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
          /* IDE */
        qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
        if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
            return;
        }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
          /* USB */
        if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 5 lines
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

Quoted 8 lines
Quoted 3 lines

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

A switch is definitely impossible: The PIIX IDE function has the 0x3c (interrupt line) and 0x3d (interrupt pin) registers reserved. It's fixed in legacy mode (prog-if is 0x80).

Best regards,
Bernhard

Thanks for checking this. If you have any upcoming patches that touch this file, it's worth adding a comment explaining this with a reference to the relevant part of the datasheet, and also update wmask accordingly.

ATB,

Mark.

#28 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

Am 1. März 2023 16:42:16 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 196 lines · Bernhard Beschow
Quoted 195 lines

Am 7. Februar 2023 20:52:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 192 lines · Bernhard Beschow
Quoted 181 lines

Am 5. Februar 2023 22:32:03 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 171 lines · BALATON Zoltan
Quoted 170 lines · Mark Cave-Ayland
Quoted 167 lines · Bernhard Beschow
Quoted 154 lines

Internal instances now defer interrupt wiring to the caller which decouples them from the ISABus. User-created devices still fish out the ISABus from the QOM tree and the interrupt wiring remains in PIIX IDE. The latter mechanism is considered a workaround and intended to be removed once a deprecation period for user-created PIIX IDE devices is over.

---
    include/hw/ide/pci.h |  1 +
    hw/ide/piix.c        | 64 ++++++++++++++++++++++++++++++++++----------
    hw/isa/piix.c        |  5 ++++
    3 files changed, 56 insertions(+), 14 deletions(-)
include/hw/ide/pci.h +1 -0
index 24c0b7a2dd..ee2c8781b7 100644
@@ -54,6 +54,7 @@ struct PCIIDEState {
        MemoryRegion bmdma_bar;
        MemoryRegion cmd_bar[2];
        MemoryRegion data_bar[2];
+    bool user_created;
    };
      static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
hw/ide/piix.c +14 -3
index 5980045db0..f0d95761ac 100644
@@ -108,6 +108,13 @@ static void bmdma_setup_bar(PCIIDEState *d)
        }
    }
    +static void piix_ide_set_irq(void *opaque, int n, int level)
+{
+    PCIIDEState *d = opaque;
+
+    qemu_set_irq(d->isa_irqs[n], level);
+}
+
    static void piix_ide_reset(DeviceState *dev)
    {
        PCIIDEState *d = PCI_IDE(dev);
@@ -138,11 +145,18 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
        };
        int i;
    +    if (isa_bus) {
+        d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
+        d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
+    } else {
+        qdev_init_gpio_out(DEVICE(d), d->isa_irqs, 2);
+    }
+
        for (i = 0; i < 2; i++) {
            ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
            ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
                            port_info[i].iobase2);
-        ide_init2(&d->bus[i], isa_bus->irqs[port_info[i].isairq]);
+        ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
              bmdma_init(&d->bus[i], &d->bmdma[i], d);
            d->bmdma[i].bus = &d->bus[i];
@@ -154,8 +168,7 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
    {
        PCIIDEState *d = PCI_IDE(dev);
        uint8_t *pci_conf = dev->config;
-    ISABus *isa_bus;
-    bool ambiguous;
+    ISABus *isa_bus = NULL;
          pci_conf[PCI_CLASS_PROG] = 0x80; // legacy ATA mode
    @@ -164,22 +177,36 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp)
          vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_pci, d);

  -    isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous));
-    if (ambiguous) {
-        error_setg(errp,
-                   "More than one ISA bus found while %s supports only one", -                   object_get_typename(OBJECT(dev)));
-        return;
-    }
-    if (!isa_bus) {
-        error_setg(errp, "No ISA bus found while %s requires one",
-                   object_get_typename(OBJECT(dev)));
-        return;
+    if (d->user_created) {
+        bool ambiguous;

hw/ide/piix.c +28 -0
+
+        isa_bus = ISA_BUS(object_resolve_path_type("", TYPE_ISA_BUS,
+                                                   &ambiguous));
+
+        if (ambiguous) {
+            error_setg(errp,
+                       "More than one ISA bus found while %s supports only one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
+
+        if (!isa_bus) {
+            error_setg(errp, "No ISA bus found while %s requires one",
+                       object_get_typename(OBJECT(dev)));
+            return;
+        }
        }
          pci_piix_init_ports(d, isa_bus);
    }
    +static void pci_piix_ide_init(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    qdev_init_gpio_in(dev, piix_ide_set_irq, 2);
+}
+
    static void pci_piix_ide_exitfn(PCIDevice *dev)
    {
        PCIIDEState *d = PCI_IDE(dev);
@@ -191,6 +218,11 @@ static void pci_piix_ide_exitfn(PCIDevice *dev)
        }
    }
    +static Property piix_ide_properties[] = {
+    DEFINE_PROP_BOOL("user-created", PCIIDEState, user_created, true),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
    /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
    static void piix3_ide_class_init(ObjectClass *klass, void *data)
    {
@@ -205,11 +237,13 @@ static void piix3_ide_class_init(ObjectClass *klass, void *data)
        k->class_id = PCI_CLASS_STORAGE_IDE;
        set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
        dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
    }
      static const TypeInfo piix3_ide_info = {
        .name          = TYPE_PIIX3_IDE,
        .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
        .class_init    = piix3_ide_class_init,
    };
    @@ -227,11 +261,13 @@ static void piix4_ide_class_init(ObjectClass *klass, void *data)
        k->class_id = PCI_CLASS_STORAGE_IDE;

      set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->hotpluggable = false;
+    device_class_set_props(dc, piix_ide_properties);
  }
    static const TypeInfo piix4_ide_info = { .name          = TYPE_PIIX4_IDE,
      .parent        = TYPE_PCI_IDE,
+    .instance_init = pci_piix_ide_init,
      .class_init    = piix4_ide_class_init, };
  diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 54a1246a9d..f9974c2a77 100644

hw/isa/piix.c +0 -0
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
          /* IDE */
        qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
        if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
            return;
        }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
          /* USB */
        if (d->has_usb) {

I haven't checked the datasheet, but I suspect this will be similar to the cmd646/via PCI-IDE interfaces in that there will be a PCI configuration register that will switch between ISA compatibility mode (and ISA irqs) and PCI mode (with PCI IRQs). So it would be the device configuration that would specify PCI or ISA mode, rather than the presence of an ISABus.

Quoted 5 lines
Quoted 1 line

I forgot about this topic already and haven't follwed this series either so what I say may not fully make sense but I think CMD646 and via-ide are different. CMD646 is a PCI device and should use PCI interrupts while via-ide is part of a southbridge/superio complex and connected to the ISA PICs within that southbride, so I think via-ide always uses ISA IRQs and the ISA btidge within the same chip may convert that to PCI IRQs or not (that part is where I'm lost also because we may not actually model it that way). After a long debate we managed to find a solution back then that works for every guest we use it for now so I think we don't want to touch it now until some real need arises. It does not worth the trouble and added complexity to model something that is not used just for the sake of correctness. By the time we find a use for that, the ISA emulation may evolve so it's easier to implement the missing switching between isa and native mode or we may want to do it differently (such as we do things differently now compared to what we did years ago). So I think it does not worth keeping the ISA model from being simplified for some theoretical uses in the future which we may not actually do any time soon. But I don't want to get into this again so just shared my thoughts and feel free to ignore it. I don't care where these patches go as long as the VIA model keeps working for me.

I have a vague memory that ISA compatibility mode was part of the original PCI-BMDMA specification, but it has been a while since I last looked.

Bernhard, is there any mention of this in the PIIX datasheet(s)? For reference the cmd646 datasheet specifies that ISA mode or PCI mode is determined by register PROG_IF (0x9) in PCI configuration space.

I've found the following:

Quoted 7 lines

"Only PCI masters have access to the IDE port. ISA Bus masters cannot access the IDE I/O port addresses. Memory targeted by the IDE interface acting as a PCI Bus master on behalf of IDE DMA slaves must reside on PCI, usually main memory implemented by the host-to-PCI bridge."

And:

"PIIX4 can act as a PCI Bus master on behalf of an IDE slave device."

Does this perhaps mean that piix-ide does indeed have no ISA bus?

I'd be amazed if that were the case: certainly when the first motherboards came out with PCI and ISA slots, I'd expect the IDE legacy mode to be enabled by default since BIOSes and OSs such as DOS wouldn't have been PCI aware and would access the ISA ioports directly. From memory the OF PCI specification has mention of workarounds such as mapping the old VGA memory to PCI MMIO space for compatibility reasons, so I'd be surprised if there wasn't something similar for IDE.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

The wording above is a bit ambiguous because I can see the above statements would be true if the PCI-IDE device were already switched to PCI mode, and what we're looking for is whether a switch between the two is supported or possible.

A switch is definitely impossible: The PIIX IDE function has the 0x3c (interrupt line) and 0x3d (interrupt pin) registers reserved. It's fixed in legacy mode (prog-if is 0x80).

Best regards,
Bernhard

Thanks for checking this.

Thanks for the valuable pointer... interesting and very comprehensive read!

Quoted 1 line

If you have any upcoming patches that touch this file, it's worth adding a comment explaining this with a reference to the relevant part of the datasheet, and also update wmask accordingly.

Will do -- if I ever get to it...

Phil, you have an alternate series. Would you be able to do this, too?

Thanks,
Bernhard

Quoted 5 lines

ATB,

Mark.

#29 lore raw

Re: [PATCH v2 07/10] hw/ide/piix: Require an ISABus only for user-created instances

In reply to Bernhard Beschow
Quoted 7 lines · Bernhard Beschow
hw/isa/piix.c +0 -0
index 54a1246a9d..f9974c2a77 100644
@@ -345,9 +345,14 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
 
     /* IDE */

hw/isa/piix.c static void pci_piix_realize(PCIDevice *dev, const char *uhci_type, · line 356

Quoted 10 lines
hw/isa/piix.c +5 -0
     qdev_prop_set_int32(DEVICE(&d->ide), "addr", dev->devfn + 1);
+    qdev_prop_set_bit(DEVICE(&d->ide), "user-created", false);
     if (!qdev_realize(DEVICE(&d->ide), BUS(pci_bus), errp)) {
         return;
     }
+    qdev_connect_gpio_out(DEVICE(&d->ide), 0,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 14));
+    qdev_connect_gpio_out(DEVICE(&d->ide), 1,
+                          qdev_get_gpio_in(DEVICE(&d->pic), 15));
 

OK, but I think we should prefix this with "x-" so we don't commit to this as a stable API.

Quoted 4 lines
hw/isa/piix.c +0 -0
     /* USB */
     if (d->has_usb) {
Signature · 1 line
2.39.1
#30 lore raw

PATCH v2 8/10 hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of ISADevice

In reply to Bernhard Beschow

Both callers to ide_init_ioport() have access to the I/O memory region of the ISA bus, so can pass it directly. This allows ide_init_ioport() to directly call portio_list_init().

Note, now the callers become the owner of the PortioList.

'hw/ide: Let ide_init_ioport() take an ISA bus argument instead of device'

---
 include/hw/ide/internal.h |  3 ++-
 hw/ide/ioport.c           | 15 ++++++++-------
 hw/ide/isa.c              |  4 +++-
 hw/ide/piix.c             |  8 ++++++--
 4 files changed, 19 insertions(+), 11 deletions(-)
include/hw/ide/internal.h +2 -1
index 42c49414f4..c3e4d192fa 100644
@@ -628,7 +628,8 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
                    int chs_trans, Error **errp);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_exit(IDEState *s);
-void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2);
 void ide_register_restart_cb(IDEBus *bus);
 
 void ide_exec_cmd(IDEBus *bus, uint32_t val);
hw/ide/ioport.c +8 -7
index b613ff3bba..00e9baf0d1 100644
@@ -50,15 +50,16 @@ static const MemoryRegionPortio ide_portio2_list[] = {
     PORTIO_END_OF_LIST(),
 };
 
-void ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2)
 {
-    /* ??? Assume only ISA and PCI configurations, and that the PCI-ISA
-       bridge has been setup properly to always register with ISA.  */
-    isa_register_portio_list(dev, &bus->portio_list,
-                             iobase, ide_portio_list, bus, "ide");
+    assert(address_space_io);
+
+    portio_list_init(&bus->portio_list, owner, ide_portio_list, bus, "ide",
+                     address_space_io, iobase);
 
     if (iobase2) {
-        isa_register_portio_list(dev, &bus->portio2_list,
-                                 iobase2, ide_portio2_list, bus, "ide");
+        portio_list_init(&bus->portio2_list, owner, ide_portio2_list, bus,
+                         "ide", address_space_io, iobase2);
     }
 }
hw/ide/isa.c +3 -1
index 8bedbd13f1..cab5d0a07a 100644
@@ -72,9 +72,11 @@ static void isa_ide_realizefn(DeviceState *dev, Error **errp)
 {
     ISADevice *isadev = ISA_DEVICE(dev);
     ISAIDEState *s = ISA_IDE(dev);
+    ISABus *isabus = isa_bus_from_device(isadev);
 
     ide_bus_init(&s->bus, sizeof(s->bus), dev, 0, 2);
-    ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
+    ide_init_ioport(&s->bus, isabus->address_space_io, OBJECT(dev),
+                    s->iobase, s->iobase2);
     s->irq = isa_get_irq(isadev, s->isairq);
     ide_init2(&s->bus, s->irq);
     vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_isa, s);
hw/ide/piix.c +6 -2
index f0d95761ac..236b5b7416 100644
@@ -29,6 +29,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "migration/vmstate.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
@@ -143,8 +144,11 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
         {0x1f0, 0x3f6, 14},
         {0x170, 0x376, 15},
     };
+    PCIBus *pci_bus = pci_get_bus(&d->parent_obj);
     int i;
 
+    assert(pci_bus);
+
     if (isa_bus) {
         d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
         d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
@@ -154,8 +158,8 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
 
     for (i = 0; i < 2; i++) {
         ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
-        ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
-                        port_info[i].iobase2);
+        ide_init_ioport(&d->bus[i], pci_bus->address_space_io, OBJECT(d),
+                        port_info[i].iobase, port_info[i].iobase2);
         ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
 
         bmdma_init(&d->bus[i], &d->bmdma[i], d);
Signature · 1 line
2.39.1
Reviewed-by on v2 8/10
#31 lore raw

Re: [PATCH v2 08/10] hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of ISADevice

Quoted 35 lines · Bernhard Beschow

Both callers to ide_init_ioport() have access to the I/O memory region of the ISA bus, so can pass it directly. This allows ide_init_ioport() to directly call portio_list_init().

Note, now the callers become the owner of the PortioList.

'hw/ide: Let ide_init_ioport() take an ISA bus argument instead of device'

---
  include/hw/ide/internal.h |  3 ++-
  hw/ide/ioport.c           | 15 ++++++++-------
  hw/ide/isa.c              |  4 +++-
  hw/ide/piix.c             |  8 ++++++--
  4 files changed, 19 insertions(+), 11 deletions(-)
include/hw/ide/internal.h +2 -1
index 42c49414f4..c3e4d192fa 100644
@@ -628,7 +628,8 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
                     int chs_trans, Error **errp);
  void ide_init2(IDEBus *bus, qemu_irq irq);
  void ide_exit(IDEState *s);
-void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2);
  void ide_register_restart_cb(IDEBus *bus);
 
  void ide_exec_cmd(IDEBus *bus, uint32_t val);
hw/ide/ioport.c +0 -0
index b613ff3bba..00e9baf0d1 100644

hw/ide/ioport.c static const MemoryRegionPortio ide_portio2_list[] = { · line 55

Quoted 7 lines
hw/ide/ioport.c +2 -1
@@ -50,15 +50,16 @@ static const MemoryRegionPortio ide_portio2_list[] = {
      PORTIO_END_OF_LIST(),
  };
 
-void ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2)
  {

Eh I have almost the same change locally :)

$ git diff d2968dc5d0940799~..629b479f0b8f082688
hw/ide/ioport.c +2 -1
index fcfaa00cb9..f82e00076a 100644
@@ -50,20 +50,21 @@ static const MemoryRegionPortio ide_portio2_list[] = {
     PORTIO_END_OF_LIST(),
 };
 
-int ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
+int ide_init_ioport(IDEBus *bus, Object *owner, ISADevice *dev,
+                    MemoryRegion *isa_io, int iobase, int iobase2)
 
#32 lore raw

Re: [PATCH v2 08/10] hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of ISADevice

In reply to Bernhard Beschow
Quoted 100 lines · Bernhard Beschow

Both callers to ide_init_ioport() have access to the I/O memory region of the ISA bus, so can pass it directly. This allows ide_init_ioport() to directly call portio_list_init().

Note, now the callers become the owner of the PortioList.

'hw/ide: Let ide_init_ioport() take an ISA bus argument instead of device'

---
  include/hw/ide/internal.h |  3 ++-
  hw/ide/ioport.c           | 15 ++++++++-------
  hw/ide/isa.c              |  4 +++-
  hw/ide/piix.c             |  8 ++++++--
  4 files changed, 19 insertions(+), 11 deletions(-)
include/hw/ide/internal.h +2 -1
index 42c49414f4..c3e4d192fa 100644
@@ -628,7 +628,8 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
                     int chs_trans, Error **errp);
  void ide_init2(IDEBus *bus, qemu_irq irq);
  void ide_exit(IDEState *s);
-void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2);
  void ide_register_restart_cb(IDEBus *bus);
 
  void ide_exec_cmd(IDEBus *bus, uint32_t val);
hw/ide/ioport.c +8 -7
index b613ff3bba..00e9baf0d1 100644
@@ -50,15 +50,16 @@ static const MemoryRegionPortio ide_portio2_list[] = {
      PORTIO_END_OF_LIST(),
  };
 
-void ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2)
  {
-    /* ??? Assume only ISA and PCI configurations, and that the PCI-ISA
-       bridge has been setup properly to always register with ISA.  */
-    isa_register_portio_list(dev, &bus->portio_list,
-                             iobase, ide_portio_list, bus, "ide");
+    assert(address_space_io);
+
+    portio_list_init(&bus->portio_list, owner, ide_portio_list, bus, "ide",
+                     address_space_io, iobase);
 
      if (iobase2) {
-        isa_register_portio_list(dev, &bus->portio2_list,
-                                 iobase2, ide_portio2_list, bus, "ide");
+        portio_list_init(&bus->portio2_list, owner, ide_portio2_list, bus,
+                         "ide", address_space_io, iobase2);
      }
  }
hw/ide/isa.c +3 -1
index 8bedbd13f1..cab5d0a07a 100644
@@ -72,9 +72,11 @@ static void isa_ide_realizefn(DeviceState *dev, Error **errp)
  {
      ISADevice *isadev = ISA_DEVICE(dev);
      ISAIDEState *s = ISA_IDE(dev);
+    ISABus *isabus = isa_bus_from_device(isadev);
 
      ide_bus_init(&s->bus, sizeof(s->bus), dev, 0, 2);
-    ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
+    ide_init_ioport(&s->bus, isabus->address_space_io, OBJECT(dev),
+                    s->iobase, s->iobase2);
      s->irq = isa_get_irq(isadev, s->isairq);
      ide_init2(&s->bus, s->irq);
      vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_isa, s);
hw/ide/piix.c +4 -0
index f0d95761ac..236b5b7416 100644
@@ -29,6 +29,7 @@
 
  #include "qemu/osdep.h"
  #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
  #include "migration/vmstate.h"
  #include "qapi/error.h"
  #include "qemu/module.h"
@@ -143,8 +144,11 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
          {0x1f0, 0x3f6, 14},
          {0x170, 0x376, 15},
      };
+    PCIBus *pci_bus = pci_get_bus(&d->parent_obj);
      int i;
 
+    assert(pci_bus);
+
      if (isa_bus) {
          d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
          d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];

hw/ide/piix.c static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus) · line 165

Quoted 10 lines
hw/ide/piix.c +2 -2
@@ -154,8 +158,8 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
 
      for (i = 0; i < 2; i++) {
          ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
-        ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
-                        port_info[i].iobase2);
+        ide_init_ioport(&d->bus[i], pci_bus->address_space_io, OBJECT(d),
+                        port_info[i].iobase, port_info[i].iobase2);
          ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
 
          bmdma_init(&d->bus[i], &d->bmdma[i], d);

Again, given that I suspect ioports are specific to x86 I'd be inclined to leave this as a reference to ISA. I could see there being a function that exists such as isa_get_address_space_io(ISADevice *isa) in the same way as pci_address_space_io(), for example.

ATB,

Mark.

#33 lore raw

Re: [PATCH v2 08/10] hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of ISADevice

Am 5. Februar 2023 22:02:02 UTC schrieb Mark Cave-Ayland <[email protected]>:

Quoted 98 lines · Bernhard Beschow
Quoted 97 lines

Both callers to ide_init_ioport() have access to the I/O memory region of the ISA bus, so can pass it directly. This allows ide_init_ioport() to directly call portio_list_init().

Note, now the callers become the owner of the PortioList.

'hw/ide: Let ide_init_ioport() take an ISA bus argument instead of device'

---
  include/hw/ide/internal.h |  3 ++-
  hw/ide/ioport.c           | 15 ++++++++-------
  hw/ide/isa.c              |  4 +++-
  hw/ide/piix.c             |  8 ++++++--
  4 files changed, 19 insertions(+), 11 deletions(-)
include/hw/ide/internal.h +2 -1
index 42c49414f4..c3e4d192fa 100644
@@ -628,7 +628,8 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
                     int chs_trans, Error **errp);
  void ide_init2(IDEBus *bus, qemu_irq irq);
  void ide_exit(IDEState *s);
-void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2);
  void ide_register_restart_cb(IDEBus *bus);
    void ide_exec_cmd(IDEBus *bus, uint32_t val);
hw/ide/ioport.c +8 -6
index b613ff3bba..00e9baf0d1 100644
@@ -50,15 +50,16 @@ static const MemoryRegionPortio ide_portio2_list[] = {
      PORTIO_END_OF_LIST(),
  };
  -void ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
+void ide_init_ioport(IDEBus *bus, MemoryRegion *address_space_io, Object *owner,
+                     int iobase, int iobase2)
  {
-    /* ??? Assume only ISA and PCI configurations, and that the PCI-ISA
-       bridge has been setup properly to always register with ISA.  */
-    isa_register_portio_list(dev, &bus->portio_list,
-                             iobase, ide_portio_list, bus, "ide");
+    assert(address_space_io);
+
+    portio_list_init(&bus->portio_list, owner, ide_portio_list, bus, "ide",
+                     address_space_io, iobase);
        if (iobase2) {
-        isa_register_portio_list(dev, &bus->portio2_list,
-                                 iobase2, ide_portio2_list, bus, "ide");
+        portio_list_init(&bus->portio2_list, owner, ide_portio2_list, bus,
+                         "ide", address_space_io, iobase2);
      }
  }
hw/ide/isa.c +3 -1
index 8bedbd13f1..cab5d0a07a 100644
@@ -72,9 +72,11 @@ static void isa_ide_realizefn(DeviceState *dev, Error **errp)
  {
      ISADevice *isadev = ISA_DEVICE(dev);
      ISAIDEState *s = ISA_IDE(dev);
+    ISABus *isabus = isa_bus_from_device(isadev);
        ide_bus_init(&s->bus, sizeof(s->bus), dev, 0, 2);
-    ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
+    ide_init_ioport(&s->bus, isabus->address_space_io, OBJECT(dev),
+                    s->iobase, s->iobase2);
      s->irq = isa_get_irq(isadev, s->isairq);
      ide_init2(&s->bus, s->irq);
      vmstate_register(VMSTATE_IF(dev), 0, &vmstate_ide_isa, s);
hw/ide/piix.c +3 -0
index f0d95761ac..236b5b7416 100644
@@ -29,6 +29,7 @@
    #include "qemu/osdep.h"
  #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
  #include "migration/vmstate.h"
  #include "qapi/error.h"
  #include "qemu/module.h"
@@ -143,8 +144,11 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
          {0x1f0, 0x3f6, 14},
          {0x170, 0x376, 15},
      };
+    PCIBus *pci_bus = pci_get_bus(&d->parent_obj);
      int i;
  +    assert(pci_bus);
+
      if (isa_bus) {
          d->isa_irqs[0] = isa_bus->irqs[port_info[0].isairq];
          d->isa_irqs[1] = isa_bus->irqs[port_info[1].isairq];
@@ -154,8 +158,8 @@ static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus)
        for (i = 0; i < 2; i++) {
          ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
Quoted 8 lines

hw/ide/piix.c static void pci_piix_init_ports(PCIIDEState *d, ISABus *isa_bus) · line 165

Quoted 6 lines
hw/ide/piix.c +2 -2
-        ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
-                        port_info[i].iobase2);
+        ide_init_ioport(&d->bus[i], pci_bus->address_space_io, OBJECT(d),
+                        port_info[i].iobase, port_info[i].iobase2);
          ide_init2(&d->bus[i], qdev_get_gpio_in(DEVICE(d), i));
            bmdma_init(&d->bus[i], &d->bmdma[i], d);

Again, given that I suspect ioports are specific to x86 I'd be inclined to leave this as a reference to ISA. I could see there being a function that exists such as isa_get_address_space_io(ISADevice *isa) in the same way as pci_address_space_io(), for example.

Hi Mark,

I've just posted a series resolving the same problem in a different way.

For some reason I thought you were the maintainer of cmd646. So I was surprised not to see you in the recipients list there...

Best regards,
Bernhard

Quoted 5 lines

ATB,

Mark.

#34 lore raw

PATCH v2 9/10 hw/isa: Remove use of global isa bus

In reply to Bernhard Beschow

From: Philippe Mathieu-Daudé <[email protected]>

In the previous commits we removed all calls to these functions passing a NULL ISADevice argument. We can simplify and remove the use of the global isabus object.

Message-Id: <[email protected]>

---
 include/hw/isa/isa.h |  2 +-
 hw/isa/isa-bus.c     | 30 +++++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 8 deletions(-)
include/hw/isa/isa.h +1 -1
index 8dd2953211..486851e7cb 100644
@@ -108,7 +108,7 @@ void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
  * function makes it easy to create multiple MemoryRegions for a single
  * device and use the legacy portio routines.
  *
- * @dev: the ISADevice against which these are registered; may be NULL.
+ * @dev: the ISADevice against which these are registered
  * @piolist: the PortioList associated with the io ports
  * @start: the base I/O port against which the portio->offset is applied.
  * @portio: the ports, sorted by offset.
hw/isa/isa-bus.c +23 -7
index d3e2d9de35..8bae5cc473 100644
@@ -81,8 +81,12 @@ void isa_bus_irqs(ISABus *bus, qemu_irq *irqs)
  */
 qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq)
 {
-    assert(!dev || ISA_BUS(qdev_get_parent_bus(DEVICE(dev))) == isabus);
+    ISABus *isabus;
+
+    assert(dev);
     assert(isairq < ISA_NUM_IRQS);
+    isabus = isa_bus_from_device(dev);
+
     return isabus->irqs[isairq];
 }
 
@@ -115,6 +119,11 @@ static inline void isa_init_ioport(ISADevice *dev, uint16_t ioport)
 
 void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start)
 {
+    ISABus *isabus;
+
+    assert(dev);
+    isabus = isa_bus_from_device(dev);
+
     memory_region_add_subregion(isabus->address_space_io, start, io);
     isa_init_ioport(dev, start);
 }
@@ -124,6 +133,11 @@ void isa_register_portio_list(ISADevice *dev,
                               const MemoryRegionPortio *pio_start,
                               void *opaque, const char *name)
 {
+    ISABus *isabus;
+
+    assert(dev);
+    isabus = isa_bus_from_device(dev);
+
     /* START is how we should treat DEV, regardless of the actual
        contents of the portio array.  This is how the old code
        actually handled e.g. the FDC device.  */
@@ -243,18 +257,20 @@ static char *isabus_get_fw_dev_path(DeviceState *dev)
 
 MemoryRegion *isa_address_space(ISADevice *dev)
 {
-    if (dev) {
-        return isa_bus_from_device(dev)->address_space;
-    }
+    ISABus *isabus;
+
+    assert(dev);
+    isabus = isa_bus_from_device(dev);
 
     return isabus->address_space;
 }
 
 MemoryRegion *isa_address_space_io(ISADevice *dev)
 {
-    if (dev) {
-        return isa_bus_from_device(dev)->address_space_io;
-    }
+    ISABus *isabus;
+
+    assert(dev);
+    isabus = isa_bus_from_device(dev);
 
     return isabus->address_space_io;
 }
Signature · 1 line
2.39.1
#35 lore raw

PATCH v2 10/10 hw/isa/isa-bus: Resolve isabus global

In reply to Bernhard Beschow

Now that only isa_bus_new() accesses the isabus global it can be removed assuming that all call sites take care of not passing the same address spaces to different isa_bus_new() invocations.

---
 hw/isa/isa-bus.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
hw/isa/isa-bus.c +2 -6
index 8bae5cc473..b8c89a1e65 100644
@@ -26,8 +26,6 @@
 #include "hw/isa/isa.h"
 #include "hw/acpi/acpi_aml_interface.h"
 
-static ISABus *isabus;
-
 static char *isabus_get_fw_dev_path(DeviceState *dev);
 
 static void isa_bus_class_init(ObjectClass *klass, void *data)
@@ -53,10 +51,8 @@ static const TypeInfo isa_bus_info = {
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
                     MemoryRegion *address_space_io, Error **errp)
 {
-    if (isabus) {
-        error_setg(errp, "Can't create a second ISA bus");
-        return NULL;
-    }
+    ISABus *isabus;
+
     if (!dev) {
         dev = qdev_new("isabus-bridge");
         sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
Signature · 1 line
2.39.1
#36 lore raw
In reply to Bernhard Beschow

+ Mark whom I've discussed "multiple ISA buses" before

Am 26. Januar 2023 21:17:30 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 151 lines

This series resolves the global "isabus" variable and is basically a v2 of [1].

Note that the majority of the work consists of fixing ISA API calls in PIIX IDE

which implicitly rely on the usage of the isabus global.

Rather than adding an ISABus pointer in PCIIDEState as in [1] this series uses

a qemu_irq array which is roughly the approach outlined in [2]. Moreover, this

series considers backwards compatibility for user-created PIIX IDE

"Frankensten" devices by fishing out TYPE_ISA_BUS from the QOM tree inside

the PIIX IDE device model. This hack can be removed again once a deprecation

period of user-createable PIIX IDE devices is over. This deprecation wasn't

announced yet but now might be a good time.

This series is structured as follows: The first three patches massage the ISA

code for patch 8. Patches 4-8 change the PIIX IDE device models to not use the

isabus global implicitly. Finally, the last two patches clan up and remove the

isabus singleton.

Based-on: <[email protected]>

'Consolidate PIIX south bridges'

v2:

- Big rework sticking closer to [1], giving it more credit and reusing one patch

- Add io port cleanup

- Rebase onto [4] so changes to PIIX could be done once and centrally

Testing done:

* make check

* ./qemu-system-x86_64 -M x-remote -device piix3-ide still fails gracefully with

qemu-system-x86_64: -device piix3-ide: No ISA bus found while piix3-ide requires one

* qemu-system-x86_64 -M pc -m 2G -cdrom manjaro-kde-21.3.2-220704-linux515.iso

* `qemu-system-x86_64 -M q35 -m 2G -device piix4-ide -cdrom \

manjaro-kde-21.3.2-220704-linux515.iso`

* `qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda \

debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0"`

[1] https://patchew.org/QEMU/[email protected]/

[2] https://lists.nongnu.org/archive/html/qemu-devel/2020-03/msg01707.html

[3] https://people.debian.org/~aurel32/qemu/mips/

[4] https://patchew.org/QEMU/[email protected]/

Bernhard Beschow (9):

softmmu/ioport: Move portio_list_init() in front of portio_list_add()

softmmu/ioport: Merge portio_list_add() into portio_list_init()

softmmu/ioport: Remove unused functions

hw/ide/piix: Disuse isa_get_irq()

Revert "hw/ide: Fix crash when plugging a piix3-ide device into the

x-remote machine"

hw/ide/pci: Add PCIIDEState::isa_irqs[]

hw/ide/piix: Require an ISABus only for user-created instances

hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of

ISADevice

hw/isa/isa-bus: Resolve isabus global

Philippe Mathieu-Daudé (1):

hw/isa: Remove use of global isa bus

include/exec/ioport.h | 8 ++---

include/hw/ide/internal.h | 3 +-

include/hw/ide/pci.h | 2 ++

include/hw/isa/isa.h | 15 ++++----

hw/audio/adlib.c | 4 +--

hw/display/qxl.c | 5 ++-

hw/display/vga.c | 8 ++---

hw/dma/i82374.c | 6 ++--

hw/ide/ioport.c | 19 +++++-----

hw/ide/isa.c | 4 ++-

hw/ide/piix.c | 75 +++++++++++++++++++++++++++++++--------

hw/isa/isa-bus.c | 54 +++++++++++++++-------------

hw/isa/piix.c | 5 +++

hw/watchdog/wdt_ib700.c | 4 +--

softmmu/ioport.c | 70 +++++++++++-------------------------

15 files changed, 149 insertions(+), 133 deletions(-)

-- >
2.39.1

#37 lore raw
In reply to Bernhard Beschow
Quoted 12 lines · Bernhard Beschow

This series resolves the global "isabus" variable and is basically a v2 of [1]. Note that the majority of the work consists of fixing ISA API calls in PIIX IDE which implicitly rely on the usage of the isabus global.

Rather than adding an ISABus pointer in PCIIDEState as in [1] this series uses a qemu_irq array which is roughly the approach outlined in [2]. Moreover, this series considers backwards compatibility for user-created PIIX IDE "Frankensten" devices by fishing out TYPE_ISA_BUS from the QOM tree inside the PIIX IDE device model. This hack can be removed again once a deprecation period of user-createable PIIX IDE devices is over. This deprecation wasn't announced yet but now might be a good time.

Quoted 4 lines

This series is structured as follows: The first three patches massage the ISA code for patch 8. Patches 4-8 change the PIIX IDE device models to not use the isabus global implicitly. Finally, the last two patches clan up and remove the isabus singleton.

I expect there will be a v3 of this, right?

Quoted 59 lines

Based-on: <[email protected]>
'Consolidate PIIX south bridges'

v2:
- Big rework sticking closer to [1], giving it more credit and reusing one patch
- Add io port cleanup
- Rebase onto [4] so changes to PIIX could be done once and centrally

Testing done:
* make check
* ./qemu-system-x86_64 -M x-remote -device piix3-ide still fails gracefully with qemu-system-x86_64: -device piix3-ide: No ISA bus found while piix3-ide requires one
* qemu-system-x86_64 -M pc -m 2G -cdrom manjaro-kde-21.3.2-220704-linux515.iso

* `qemu-system-x86_64 -M q35 -m 2G -device piix4-ide -cdrom \
   manjaro-kde-21.3.2-220704-linux515.iso`

* `qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda \
debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0"`

[1] https://patchew.org/QEMU/[email protected]/
[2] https://lists.nongnu.org/archive/html/qemu-devel/2020-03/msg01707.html
[3] https://people.debian.org/~aurel32/qemu/mips/
[4] https://patchew.org/QEMU/[email protected]/

Bernhard Beschow (9):
softmmu/ioport: Move portio_list_init() in front of portio_list_add() softmmu/ioport: Merge portio_list_add() into portio_list_init() softmmu/ioport: Remove unused functions
hw/ide/piix: Disuse isa_get_irq()
Revert "hw/ide: Fix crash when plugging a piix3-ide device into the
x-remote machine"
hw/ide/pci: Add PCIIDEState::isa_irqs[]
hw/ide/piix: Require an ISABus only for user-created instances hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of
ISADevice
hw/isa/isa-bus: Resolve isabus global

Philippe Mathieu-Daudé (1):
hw/isa: Remove use of global isa bus

 include/exec/ioport.h     |  8 ++---
 include/hw/ide/internal.h |  3 +-
 include/hw/ide/pci.h      |  2 ++
 include/hw/isa/isa.h      | 15 ++++----
 hw/audio/adlib.c          |  4 +--
 hw/display/qxl.c          |  5 ++-
 hw/display/vga.c          |  8 ++---
 hw/dma/i82374.c           |  6 ++--
 hw/ide/ioport.c           | 19 +++++-----
 hw/ide/isa.c              |  4 ++-
 hw/ide/piix.c             | 75 +++++++++++++++++++++++++++++++--------
 hw/isa/isa-bus.c          | 54 +++++++++++++++-------------
 hw/isa/piix.c             |  5 +++
 hw/watchdog/wdt_ib700.c   |  4 +--
 softmmu/ioport.c          | 70 +++++++++++-------------------------
 15 files changed, 149 insertions(+), 133 deletions(-)
Signature · 1 line
2.39.1
#38 lore raw

Am 24. Februar 2023 16:22:48 UTC schrieb "Michael S. Tsirkin" <[email protected]>:

Quoted 13 lines · Bernhard Beschow
Quoted 12 lines

This series resolves the global "isabus" variable and is basically a v2 of [1]. Note that the majority of the work consists of fixing ISA API calls in PIIX IDE which implicitly rely on the usage of the isabus global.

Rather than adding an ISABus pointer in PCIIDEState as in [1] this series uses a qemu_irq array which is roughly the approach outlined in [2]. Moreover, this series considers backwards compatibility for user-created PIIX IDE "Frankensten" devices by fishing out TYPE_ISA_BUS from the QOM tree inside the PIIX IDE device model. This hack can be removed again once a deprecation period of user-createable PIIX IDE devices is over. This deprecation wasn't announced yet but now might be a good time.

Quoted 6 lines
Quoted 4 lines

This series is structured as follows: The first three patches massage the ISA code for patch 8. Patches 4-8 change the PIIX IDE device models to not use the isabus global implicitly. Finally, the last two patches clan up and remove the isabus singleton.

I expect there will be a v3 of this, right?

I would do it and I could rebase onto master if necessary. However, another series unrelated to this one but doing essentially the same thing with less backwards promises went through various iterations in the meantime. I don't know what the plan is.

Best regards,
Bernhard

Quoted 62 lines
Quoted 61 lines

Based-on: <[email protected]>
'Consolidate PIIX south bridges'

v2:
- Big rework sticking closer to [1], giving it more credit and reusing one patch
- Add io port cleanup
- Rebase onto [4] so changes to PIIX could be done once and centrally

Testing done:
* make check
* ./qemu-system-x86_64 -M x-remote -device piix3-ide still fails gracefully with qemu-system-x86_64: -device piix3-ide: No ISA bus found while piix3-ide requires one
* qemu-system-x86_64 -M pc -m 2G -cdrom manjaro-kde-21.3.2-220704-linux515.iso

* `qemu-system-x86_64 -M q35 -m 2G -device piix4-ide -cdrom \
   manjaro-kde-21.3.2-220704-linux515.iso`

* `qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda \
debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0"`

[1] https://patchew.org/QEMU/[email protected]/
[2] https://lists.nongnu.org/archive/html/qemu-devel/2020-03/msg01707.html
[3] https://people.debian.org/~aurel32/qemu/mips/
[4] https://patchew.org/QEMU/[email protected]/

Bernhard Beschow (9):
softmmu/ioport: Move portio_list_init() in front of portio_list_add() softmmu/ioport: Merge portio_list_add() into portio_list_init() softmmu/ioport: Remove unused functions
hw/ide/piix: Disuse isa_get_irq()
Revert "hw/ide: Fix crash when plugging a piix3-ide device into the
x-remote machine"
hw/ide/pci: Add PCIIDEState::isa_irqs[]
hw/ide/piix: Require an ISABus only for user-created instances hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of
ISADevice
hw/isa/isa-bus: Resolve isabus global

Philippe Mathieu-Daudé (1):
hw/isa: Remove use of global isa bus

 include/exec/ioport.h     |  8 ++---
 include/hw/ide/internal.h |  3 +-
 include/hw/ide/pci.h      |  2 ++
 include/hw/isa/isa.h      | 15 ++++----
 hw/audio/adlib.c          |  4 +--
 hw/display/qxl.c          |  5 ++-
 hw/display/vga.c          |  8 ++---
 hw/dma/i82374.c           |  6 ++--
 hw/ide/ioport.c           | 19 +++++-----
 hw/ide/isa.c              |  4 ++-
 hw/ide/piix.c             | 75 +++++++++++++++++++++++++++++++--------
 hw/isa/isa-bus.c          | 54 +++++++++++++++-------------
 hw/isa/piix.c             |  5 +++
 hw/watchdog/wdt_ib700.c   |  4 +--
 softmmu/ioport.c          | 70 +++++++++++-------------------------
 15 files changed, 149 insertions(+), 133 deletions(-)
Signature · 1 line
2.39.1
#39 lore raw

Am 26. Februar 2023 20:38:24 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 16 lines

Am 24. Februar 2023 16:22:48 UTC schrieb "Michael S. Tsirkin" <[email protected]>:

Quoted 13 lines · Bernhard Beschow
Quoted 12 lines

This series resolves the global "isabus" variable and is basically a v2 of [1]. Note that the majority of the work consists of fixing ISA API calls in PIIX IDE which implicitly rely on the usage of the isabus global.

Rather than adding an ISABus pointer in PCIIDEState as in [1] this series uses a qemu_irq array which is roughly the approach outlined in [2]. Moreover, this series considers backwards compatibility for user-created PIIX IDE "Frankensten" devices by fishing out TYPE_ISA_BUS from the QOM tree inside the PIIX IDE device model. This hack can be removed again once a deprecation period of user-createable PIIX IDE devices is over. This deprecation wasn't announced yet but now might be a good time.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This series is structured as follows: The first three patches massage the ISA code for patch 8. Patches 4-8 change the PIIX IDE device models to not use the isabus global implicitly. Finally, the last two patches clan up and remove the isabus singleton.

I expect there will be a v3 of this, right?

I would do it and I could rebase onto master if necessary. However, another series unrelated to this one but doing essentially the same thing with less backwards promises went through various iterations in the meantime. I don't know what the plan is.

Phil, how shall we proceed? What's holding back the PIIX consolidation? It was fully reviewed at the beginning of the development window. Now the freeze is just a couple of days ahead.

Best regards,
Bernhard

Quoted 66 lines

Best regards,
Bernhard

Quoted 62 lines
Quoted 61 lines

Based-on: <[email protected]>
'Consolidate PIIX south bridges'

v2:
- Big rework sticking closer to [1], giving it more credit and reusing one patch
- Add io port cleanup
- Rebase onto [4] so changes to PIIX could be done once and centrally

Testing done:
* make check
* ./qemu-system-x86_64 -M x-remote -device piix3-ide still fails gracefully with qemu-system-x86_64: -device piix3-ide: No ISA bus found while piix3-ide requires one
* qemu-system-x86_64 -M pc -m 2G -cdrom manjaro-kde-21.3.2-220704-linux515.iso

* `qemu-system-x86_64 -M q35 -m 2G -device piix4-ide -cdrom \
   manjaro-kde-21.3.2-220704-linux515.iso`

* `qemu-system-mips64el -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda \
debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=ttyS0"`

[1] https://patchew.org/QEMU/[email protected]/
[2] https://lists.nongnu.org/archive/html/qemu-devel/2020-03/msg01707.html
[3] https://people.debian.org/~aurel32/qemu/mips/
[4] https://patchew.org/QEMU/[email protected]/

Bernhard Beschow (9):
softmmu/ioport: Move portio_list_init() in front of portio_list_add() softmmu/ioport: Merge portio_list_add() into portio_list_init() softmmu/ioport: Remove unused functions
hw/ide/piix: Disuse isa_get_irq()
Revert "hw/ide: Fix crash when plugging a piix3-ide device into the
x-remote machine"
hw/ide/pci: Add PCIIDEState::isa_irqs[]
hw/ide/piix: Require an ISABus only for user-created instances hw/ide: Let ide_init_ioport() take a MemoryRegion argument instead of
ISADevice
hw/isa/isa-bus: Resolve isabus global

Philippe Mathieu-Daudé (1):
hw/isa: Remove use of global isa bus

 include/exec/ioport.h     |  8 ++---
 include/hw/ide/internal.h |  3 +-
 include/hw/ide/pci.h      |  2 ++
 include/hw/isa/isa.h      | 15 ++++----
 hw/audio/adlib.c          |  4 +--
 hw/display/qxl.c          |  5 ++-
 hw/display/vga.c          |  8 ++---
 hw/dma/i82374.c           |  6 ++--
 hw/ide/ioport.c           | 19 +++++-----
 hw/ide/isa.c              |  4 ++-
 hw/ide/piix.c             | 75 +++++++++++++++++++++++++++++++--------
 hw/isa/isa-bus.c          | 54 +++++++++++++++-------------
 hw/isa/piix.c             |  5 +++
 hw/watchdog/wdt_ib700.c   |  4 +--
 softmmu/ioport.c          | 70 +++++++++++-------------------------
 15 files changed, 149 insertions(+), 133 deletions(-)
Signature · 1 line
2.39.1