Patchwork [3/9] isa: Add a way to query for a free interrupt

login
register
mail settings
Submitter Corey Minyard
Date July 9, 2012, 7:17 p.m.
Message ID <1341861429-6297-4-git-send-email-minyard@acm.org>
Download mbox | patch
Permalink /patch/169944/
State New
Headers show

Comments

Corey Minyard - July 9, 2012, 7:17 p.m.
From: Corey Minyard <cminyard@mvista.com>

This lets devices that don't care about their interrupt number, like
IPMI, just grab any unused interrupt.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
 hw/isa-bus.c |   13 +++++++++++++
 hw/isa.h     |    2 ++
 2 files changed, 15 insertions(+), 0 deletions(-)
Paolo Bonzini - July 10, 2012, 9:16 a.m.
Il 09/07/2012 21:17, minyard@acm.org ha scritto:
> From: Corey Minyard <cminyard@mvista.com>
> 
> This lets devices that don't care about their interrupt number, like
> IPMI, just grab any unused interrupt.

I would try to avoid this.  It is too dependent on the actual
initialization order and command line.  Just pick a reasonable value for
the interrupt (5?) and make it customizable.

I only gave a cursory look at the series, but it looks really well done
except for command-line parsing.  I'll reply to the patches individually.

Paolo

Patch

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 5a43f03..f561f21 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -71,6 +71,7 @@  qemu_irq isa_get_irq(ISADevice *dev, int isairq)
     if (isairq < 0 || isairq > 15) {
         hw_error("isa irq %d invalid", isairq);
     }
+    isabus->irq_inuse[isairq] = 1;
     return isabus->irqs[isairq];
 }
 
@@ -82,6 +83,18 @@  void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
     dev->nirqs++;
 }
 
+int isa_find_free_irq(ISABus *bus)
+{
+    unsigned int i;
+
+    /* 0 and 1 are called for, 2 is the chain interrupt */
+    for (i = 3; i < ISA_NUM_IRQS; i++) {
+	if (!bus->irq_inuse[i])
+	    return i;
+    }
+    return 0;
+}
+
 static inline void isa_init_ioport(ISADevice *dev, uint16_t ioport)
 {
     if (dev && (dev->ioport_id == 0 || ioport < dev->ioport_id)) {
diff --git a/hw/isa.h b/hw/isa.h
index f7bc4b5..9447296 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -28,6 +28,7 @@  struct ISABus {
     BusState qbus;
     MemoryRegion *address_space_io;
     qemu_irq *irqs;
+    int irq_inuse[ISA_NUM_IRQS];
 };
 
 struct ISADevice {
@@ -41,6 +42,7 @@  ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io);
 void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
 qemu_irq isa_get_irq(ISADevice *dev, int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
+int isa_find_free_irq(ISABus *bus);
 MemoryRegion *isa_address_space(ISADevice *dev);
 ISADevice *isa_create(ISABus *bus, const char *name);
 ISADevice *isa_try_create(ISABus *bus, const char *name);