diff mbox

[8/9] isa: refine irq reservations

Message ID 1252943364-32705-9-git-send-email-kraxel@redhat.com
State Superseded
Headers show

Commit Message

Gerd Hoffmann Sept. 14, 2009, 3:49 p.m. UTC
There are a few cases where IRQ sharing on the ISA bus is used and
possible.  In general only devices of the same kind can do that.
A few use cases:

  * serial lines 1+3 share irq 4
  * serial lines 2+4 share irq 3
  * parallel ports share irq 7
  * ppc/prep: ide ports share irq 13

This patch refines the irq reservation mechanism for the isa bus to
handle those cases.  It keeps track of the driver which owns the IRQ in
question and allows irq sharing for devices handled by the same driver.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/isa-bus.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

Comments

Blue Swirl Sept. 14, 2009, 4:55 p.m. UTC | #1
On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> There are a few cases where IRQ sharing on the ISA bus is used and
> possible.  In general only devices of the same kind can do that.
> A few use cases:
>
>  * serial lines 1+3 share irq 4
>  * serial lines 2+4 share irq 3
>  * parallel ports share irq 7
>  * ppc/prep: ide ports share irq 13

There is another ppc/prep case where RTC and m48t59 share irq 8. The
attached patch converts m48t59 to ISA and makes this more visible.

Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge
triggered and so IRQ sharing was a bit unreliable (but not completely
broken) also on real HW?
Markus Armbruster Sept. 14, 2009, 8:09 p.m. UTC | #2
Blue Swirl <blauwirbel@gmail.com> writes:

> On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:
>> There are a few cases where IRQ sharing on the ISA bus is used and
>> possible.  In general only devices of the same kind can do that.
>> A few use cases:
>>
>>  * serial lines 1+3 share irq 4
>>  * serial lines 2+4 share irq 3
>>  * parallel ports share irq 7
>>  * ppc/prep: ide ports share irq 13
>
> There is another ppc/prep case where RTC and m48t59 share irq 8. The
> attached patch converts m48t59 to ISA and makes this more visible.
>
> Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge
> triggered and so IRQ sharing was a bit unreliable (but not completely
> broken) also on real HW?

If I remember correctly (and that's a considerable if), sufficiently
well-behaved hardware with sufficiently smart drivers could share IRQs.
Gerd Hoffmann Sept. 15, 2009, 7:23 a.m. UTC | #3
On 09/14/09 18:55, Blue Swirl wrote:
> On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>> There are a few cases where IRQ sharing on the ISA bus is used and
>> possible.  In general only devices of the same kind can do that.
>> A few use cases:
>>
>>   * serial lines 1+3 share irq 4
>>   * serial lines 2+4 share irq 3
>>   * parallel ports share irq 7
>>   * ppc/prep: ide ports share irq 13
>
> There is another ppc/prep case where RTC and m48t59 share irq 8. The
> attached patch converts m48t59 to ISA and makes this more visible.

Hmm, ok.  So scratch this and maybe use a 'sharing the irq is is fine 
with me' flag instead?

> Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge
> triggered and so IRQ sharing was a bit unreliable (but not completely
> broken) also on real HW?

Well, the fundamental problem is that (1) the drivers must be prepared 
to handle that and (b) the hardware must be designed sanely.  There are 
cases where it works fine (see the list above).  It isn't true in 
general though.  You can't configure two random devices (say sb16 + 
ne2k) to share the same irq and expect everything to work fine.

cheers,
   Gerd
Blue Swirl Sept. 15, 2009, 7:08 p.m. UTC | #4
On Tue, Sep 15, 2009 at 10:23 AM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> On 09/14/09 18:55, Blue Swirl wrote:
>>
>> On Mon, Sep 14, 2009 at 6:49 PM, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>>>
>>> There are a few cases where IRQ sharing on the ISA bus is used and
>>> possible.  In general only devices of the same kind can do that.
>>> A few use cases:
>>>
>>>  * serial lines 1+3 share irq 4
>>>  * serial lines 2+4 share irq 3
>>>  * parallel ports share irq 7
>>>  * ppc/prep: ide ports share irq 13
>>
>> There is another ppc/prep case where RTC and m48t59 share irq 8. The
>> attached patch converts m48t59 to ISA and makes this more visible.
>
> Hmm, ok.  So scratch this and maybe use a 'sharing the irq is is fine with
> me' flag instead?
>
>> Does sharing of IRQs really have to be fatal? Wasn't ISA bus edge
>> triggered and so IRQ sharing was a bit unreliable (but not completely
>> broken) also on real HW?
>
> Well, the fundamental problem is that (1) the drivers must be prepared to
> handle that and (b) the hardware must be designed sanely.  There are cases
> where it works fine (see the list above).  It isn't true in general though.
>  You can't configure two random devices (say sb16 + ne2k) to share the same
> irq and expect everything to work fine.

I wonder if the PREP machine is emulated correctly. I couldn't find
docs about PREP NVRAM or RTC.
diff mbox

Patch

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 4ecc0f8..1d2ca90 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -26,6 +26,7 @@  struct ISABus {
     BusState qbus;
     qemu_irq *irqs;
     uint32_t assigned;
+    DeviceInfo *irq_owner[16];
 };
 static ISABus *isabus;
 
@@ -71,7 +72,9 @@  qemu_irq isa_reserve_irq(int isairq)
         exit(1);
     }
     if (isabus->assigned & (1 << isairq)) {
-        fprintf(stderr, "isa irq %d already assigned\n", isairq);
+        DeviceInfo *owner = isabus->irq_owner[isairq];
+        fprintf(stderr, "isa irq %d already assigned (%s)\n",
+                isairq, owner ? owner->name : "unknown");
         exit(1);
     }
     isabus->assigned |= (1 << isairq);
@@ -82,10 +85,17 @@  void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
 {
     assert(dev->nirqs < ARRAY_SIZE(dev->isairq));
     if (isabus->assigned & (1 << isairq)) {
-        fprintf(stderr, "isa irq %d already assigned\n", isairq);
-        exit(1);
+        DeviceInfo *owner = isabus->irq_owner[isairq];
+        if (owner == dev->qdev.info) {
+            /* irq sharing is ok in case the same driver handles both */;
+        } else {
+            fprintf(stderr, "isa irq %d already assigned (%s)\n",
+                    isairq, owner ? owner->name : "unknown");
+            exit(1);
+        }
     }
     isabus->assigned |= (1 << isairq);
+    isabus->irq_owner[isairq] = dev->qdev.info;
     dev->isairq[dev->nirqs] = isairq;
     *p = isabus->irqs[isairq];
     dev->nirqs++;