Skip to contentSkip to conversation

ioport: add function to check whenever a port is assigned or not

PATCH In review Gerd Hoffmann 3 participants 6 messages May 11, 2010 – May 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ioport: add function to check whenever a port is assigned or not

---
 ioport.c |    5 +++++
 ioport.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
ioport.c +5 -0
index 53dd87a..b718047 100644
@@ -190,6 +190,11 @@ void isa_unassign_ioport(pio_addr_t start, int length)
     }
 }
 
+int is_ioport_assigned(pio_addr_t addr)
+{
+    return ioport_opaque[addr] != NULL;
+}
+
 /***********************************************************/
 
 void cpu_outb(pio_addr_t addr, uint8_t val)
ioport.h +1 -0
index 3d3c8a3..46fbfa8 100644
@@ -41,6 +41,7 @@ int register_ioport_read(pio_addr_t start, int length, int size,
 int register_ioport_write(pio_addr_t start, int length, int size,
                           IOPortWriteFunc *func, void *opaque);
 void isa_unassign_ioport(pio_addr_t start, int length);
+int is_ioport_assigned(pio_addr_t addr);
 
 
 void cpu_outb(pio_addr_t addr, uint8_t val);
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 2/2 all vga: fail graicefully when vga ports are taken

Try to pci hotplug a vga card, watch qemu die with hw_error(). This patch fixes it.

---
 hw/cirrus_vga.c |    3 +++
 hw/vga-pci.c    |    3 +++
 hw/vmware_vga.c |    3 +++
 3 files changed, 9 insertions(+), 0 deletions(-)
hw/cirrus_vga.c +3 -0
index 9f61a01..2f50e86 100644
@@ -3189,6 +3189,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
      uint8_t *pci_conf = d->dev.config;
      int device_id = CIRRUS_ID_CLGD5446;
 
+     if (is_ioport_assigned(0x3c0))
+         return -1;
+
      /* setup VGA */
      vga_common_init(&s->vga, VGA_RAM_SIZE);
      cirrus_init_common(s, device_id, 1);
hw/vga-pci.c +3 -0
index c8d260c..2ef3278 100644
@@ -79,6 +79,9 @@ static int pci_vga_initfn(PCIDevice *dev)
      VGACommonState *s = &d->vga;
      uint8_t *pci_conf = d->dev.config;
 
+     if (is_ioport_assigned(0x3c0))
+         return -1;
+
      // vga + console init
      vga_common_init(s, VGA_RAM_SIZE);
      vga_init(s);
hw/vmware_vga.c +3 -0
index 4e7a75d..cd0eb57 100644
@@ -1232,6 +1232,9 @@ static int pci_vmsvga_initfn(PCIDevice *dev)
     struct pci_vmsvga_state_s *s =
         DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
 
+    if (is_ioport_assigned(0x3c0))
+        return -1;
+
     pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
     pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
     s->card.config[PCI_COMMAND]	= PCI_COMMAND_IO |
Signature · 1 line
1.6.6.1
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] all vga: fail graicefully when vga ports are taken

Quoted 15 lines · Gerd Hoffmann

Try to pci hotplug a vga card, watch qemu die with hw_error().
This patch fixes it.

---

  hw/cirrus_vga.c |    3 +++
  hw/vga-pci.c    |    3 +++
  hw/vmware_vga.c |    3 +++
  3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 9f61a01..2f50e86 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -3189,6 +3189,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)

Quoted 6 lines
      uint8_t *pci_conf = d->dev.config;
      int device_id = CIRRUS_ID_CLGD5446;

+ if (is_ioport_assigned(0x3c0))
+ return -1;
+

-ECODING_STYLE.

Quoted 37 lines
      /* setup VGA */
      vga_common_init(&s->vga, VGA_RAM_SIZE);
      cirrus_init_common(s, device_id, 1);
 diff --git a/hw/vga-pci.c b/hw/vga-pci.c
 index c8d260c..2ef3278 100644
 --- a/hw/vga-pci.c
 +++ b/hw/vga-pci.c
 @@ -79,6 +79,9 @@ static int pci_vga_initfn(PCIDevice *dev)
      VGACommonState *s = &d->vga;
      uint8_t *pci_conf = d->dev.config;

+ if (is_ioport_assigned(0x3c0))
+ return -1;
+

      // vga + console init
      vga_common_init(s, VGA_RAM_SIZE);
      vga_init(s);

diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index 4e7a75d..cd0eb57 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1232,6 +1232,9 @@ static int pci_vmsvga_initfn(PCIDevice *dev)
struct pci_vmsvga_state_s *s =
DO_UPCAST(struct pci_vmsvga_state_s, card, dev);

+ if (is_ioport_assigned(0x3c0))
+ return -1;
+

     pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
     pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
     s->card.config[PCI_COMMAND]        = PCI_COMMAND_IO |

--
1.6.6.1

#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] all vga: fail graicefully when vga ports are taken

In reply to Gerd Hoffmann
Quoted 2 lines · Gerd Hoffmann

Try to pci hotplug a vga card, watch qemu die with hw_error(). This patch fixes it.

Looks good.

Are there any other hot-pluggable devices that acquire single-use resources such as fixed I/O ports?

#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] all vga: fail graicefully when vga ports are taken

Quoted 9 lines · Markus Armbruster
Quoted 2 lines · Gerd Hoffmann

Try to pci hotplug a vga card, watch qemu die with hw_error(). This patch fixes it.

Looks good.

Are there any other hot-pluggable devices that acquire single-use resources such as fixed I/O ports?

Any PCI device doing ISA compatibility stuff I'd guess, which makes IDE a candidate. Checking ...

Yes (hw/ide/piix.c):

    ide_init_ioport(&d->bus[0], 0x1f0, 0x3f6);
    ide_init_ioport(&d->bus[1], 0x170, 0x376);

Those are tagged with "no-user" though due to being hard-coded in pc.c, so any attempt to hot-plug one of those should fail way before it attempts to grab the I/O ports.

cheers,
Gerd

#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] all vga: fail graicefully when vga ports are taken

Quoted 14 lines · Gerd Hoffmann
Quoted 9 lines · Markus Armbruster
Quoted 2 lines · Gerd Hoffmann

Try to pci hotplug a vga card, watch qemu die with hw_error(). This patch fixes it.

Looks good.

Are there any other hot-pluggable devices that acquire single-use resources such as fixed I/O ports?

Any PCI device doing ISA compatibility stuff I'd guess, which makes IDE a candidate. Checking ...

Quoted 8 lines

Yes (hw/ide/piix.c):

    ide_init_ioport(&d->bus[0], 0x1f0, 0x3f6);
    ide_init_ioport(&d->bus[1], 0x170, 0x376);

Those are tagged with "no-user" though due to being hard-coded in pc.c, so any attempt to hot-plug one of those should fail way before it attempts to grab the I/O ports.

So a more general mechanism than you ad hoc is_ioport_assigned() check doesn't seem to be justified.