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

login
register
mail settings
Submitter Gerd Hoffmann
Date May 19, 2010, 9:54 a.m.
Message ID <1274262857-31964-1-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/52969/
State New
Headers show

Comments

Gerd Hoffmann - May 19, 2010, 9:54 a.m.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ioport.c |    5 +++++
 ioport.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
Paul Brook - May 24, 2010, 12:32 p.m.
> +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
Gerd Hoffmann - May 25, 2010, 9:41 a.m.
On 05/24/10 14:32, Paul Brook wrote:
>> +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
Markus Armbruster - May 26, 2010, 7:05 a.m.
Gerd Hoffmann <kraxel@redhat.com> writes:

> On 05/24/10 14:32, Paul Brook wrote:
>>> +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.

Patch

diff --git a/ioport.c b/ioport.c
index 53dd87a..b718047 100644
--- a/ioport.c
+++ b/ioport.c
@@ -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)
diff --git a/ioport.h b/ioport.h
index 3d3c8a3..46fbfa8 100644
--- a/ioport.h
+++ b/ioport.h
@@ -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);