diff mbox series

[v2,02/12] x86: rewrite gsi_handler()

Message ID 20201105133923.23821-3-kraxel@redhat.com
State Accepted
Commit ceea95cd88c8f90ad93a83bbad4a077590316342
Headers show
Series microvm: add second ioapic | expand

Commit Message

Gerd Hoffmann Nov. 5, 2020, 1:39 p.m. UTC
Rewrite function to use switch() for IRQ number mapping.
Check i8259_irq exists before raising it so the function
also works in case no i8259 (aka pic) is present.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/i386/x86.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Igor Mammedov Nov. 11, 2020, 12:15 p.m. UTC | #1
On Thu,  5 Nov 2020 14:39:13 +0100
Gerd Hoffmann <kraxel@redhat.com> wrote:

> Rewrite function to use switch() for IRQ number mapping.

> Check i8259_irq exists before raising it so the function

> also works in case no i8259 (aka pic) is present.

> 

> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>


Reviewed-by: Igor Mammedov <imammedo@redhat.com>


> ---

>  hw/i386/x86.c | 14 ++++++++++----

>  1 file changed, 10 insertions(+), 4 deletions(-)

> 

> diff --git a/hw/i386/x86.c b/hw/i386/x86.c

> index 5944fc44edca..b67e7b789f89 100644

> --- a/hw/i386/x86.c

> +++ b/hw/i386/x86.c

> @@ -588,11 +588,17 @@ void gsi_handler(void *opaque, int n, int level)

>      GSIState *s = opaque;

>  

>      trace_x86_gsi_interrupt(n, level);

> -    if (n < ISA_NUM_IRQS) {

> -        /* Under KVM, Kernel will forward to both PIC and IOAPIC */

> -        qemu_set_irq(s->i8259_irq[n], level);

> +    switch (n) {

> +    case 0 ... ISA_NUM_IRQS - 1:

> +        if (s->i8259_irq[n]) {

> +            /* Under KVM, Kernel will forward to both PIC and IOAPIC */

> +            qemu_set_irq(s->i8259_irq[n], level);

> +        }

> +        /* fall through */

> +    case ISA_NUM_IRQS ... IOAPIC_NUM_PINS - 1:

> +        qemu_set_irq(s->ioapic_irq[n], level);

> +        break;

>      }

> -    qemu_set_irq(s->ioapic_irq[n], level);

>  }

>  

>  void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)
diff mbox series

Patch

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 5944fc44edca..b67e7b789f89 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -588,11 +588,17 @@  void gsi_handler(void *opaque, int n, int level)
     GSIState *s = opaque;
 
     trace_x86_gsi_interrupt(n, level);
-    if (n < ISA_NUM_IRQS) {
-        /* Under KVM, Kernel will forward to both PIC and IOAPIC */
-        qemu_set_irq(s->i8259_irq[n], level);
+    switch (n) {
+    case 0 ... ISA_NUM_IRQS - 1:
+        if (s->i8259_irq[n]) {
+            /* Under KVM, Kernel will forward to both PIC and IOAPIC */
+            qemu_set_irq(s->i8259_irq[n], level);
+        }
+        /* fall through */
+    case ISA_NUM_IRQS ... IOAPIC_NUM_PINS - 1:
+        qemu_set_irq(s->ioapic_irq[n], level);
+        break;
     }
-    qemu_set_irq(s->ioapic_irq[n], level);
 }
 
 void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name)