ioport: add function to check whenever a port is assigned or not
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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
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
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
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.