Skip to contentSkip to conversation

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

PATCH In review Gerd Hoffmann 3 participants 5 messages May 19, 2010 – May 26, 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.

[v2: code style fixes]

---
 hw/cirrus_vga.c |    4 ++++
 hw/vga-pci.c    |    4 ++++
 hw/vmware_vga.c |    4 ++++
 3 files changed, 12 insertions(+), 0 deletions(-)
hw/cirrus_vga.c +4 -0
index 9f61a01..977abd2 100644
@@ -3189,6 +3189,10 @@ 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 +4 -0
index c8d260c..9fa0bfb 100644
@@ -79,6 +79,10 @@ 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 +4 -0
index 4e7a75d..7a8cec0 100644
@@ -1232,6 +1232,10 @@ 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
In reply to Gerd Hoffmann
Quoted 1 line

+int is_ioport_assigned(pio_addr_t addr)

Shouldn't we move this into register_ioport_{read,write}, and have that fail if the port has already been assigned?

Paul

#3 lore raw
Quoted 4 lines · Paul Brook
Quoted 1 line

+int is_ioport_assigned(pio_addr_t addr)

Shouldn't we move this into register_ioport_{read,write}, and have that fail if the port has already been assigned?

It already checks and fails with hw_error(). Problem with that is that this kills qemu in case you try to pci hot-plug a vga card. So I've added a way to check before-hand, so we can fail gracefully in the few places where we need it (see second patch of the series).

cheers,
Gerd

#4 lore raw
Quoted 10 lines · Gerd Hoffmann
Quoted 4 lines · Paul Brook
Quoted 1 line

+int is_ioport_assigned(pio_addr_t addr)

Shouldn't we move this into register_ioport_{read,write}, and have that fail if the port has already been assigned?

It already checks and fails with hw_error(). Problem with that is that this kills qemu in case you try to pci hot-plug a vga card. So I've added a way to check before-hand, so we can fail gracefully in the few places where we need it (see second patch of the series).

If we needed in more than a few places, then a solution like the one we adopted for qdev_init() could make sense: have register_ioport_FOO() return an error, convert all users that don't want to check it to register_ioport_FOO_nofail(), which hw_error()s out.