ioapic/abi: Save IRQ to GSI mapping
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 18 Mar 2011 05:59:50 +0000 (13:59 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Fri, 18 Mar 2011 07:31:43 +0000 (15:31 +0800)
sys/platform/pc32/apic/ioapic_abi.c
sys/platform/pc32/apic/ioapic_abi.h
sys/platform/pc32/apic/mpapic.c
sys/platform/pc64/apic/ioapic_abi.c
sys/platform/pc64/apic/ioapic_abi.h
sys/platform/pc64/apic/mpapic.c

index 8aa26a0..ef6f42a 100644 (file)
@@ -56,6 +56,7 @@
 
 #include <sys/thread2.h>
 
+#include <machine_base/apic/ioapic_abi.h>
 #include <machine_base/apic/ioapic_ipl.h>
 
 #ifdef SMP /* APIC-IO */
@@ -728,4 +729,49 @@ ioapic_initmap(void)
        ioapic_irqmaps[IOAPIC_HWI_SYSCALL].im_type = IOAPIC_IMT_SYSCALL;
 }
 
+void
+ioapic_abi_set_irqmap(int irq, int gsi, enum intr_trigger trig,
+    enum intr_polarity pola)
+{
+       struct apic_intmapinfo *info;
+       struct ioapic_irqmap *map;
+       void *ioaddr;
+       int pin;
+
+       KKASSERT(trig == INTR_TRIGGER_EDGE || trig == INTR_TRIGGER_LEVEL);
+       KKASSERT(pola == INTR_POLARITY_HIGH || pola == INTR_POLARITY_LOW);
+       KKASSERT((trig == INTR_TRIGGER_EDGE && pola == INTR_POLARITY_HIGH) ||
+                (trig == INTR_TRIGGER_LEVEL && pola == INTR_POLARITY_LOW));
+
+       KKASSERT(irq >= 0 && irq < IOAPIC_HWI_VECTORS);
+       map = &ioapic_irqmaps[irq];
+
+       KKASSERT(map->im_type == IOAPIC_IMT_UNUSED);
+       map->im_type = IOAPIC_IMT_LINE;
+
+       map->im_gsi = gsi;
+       map->im_trig = trig;
+       map->im_pola = pola;
+
+       if (bootverbose) {
+               kprintf("IOAPIC: irq %d -> gsi %d %c\n", irq, map->im_gsi,
+                       trig == INTR_TRIGGER_LEVEL ? 'L' : 'E');
+       }
+
+       pin = ioapic_gsi_pin(gsi);
+       ioaddr = ioapic_gsi_ioaddr(gsi);
+
+       info = &int_to_apicintpin[irq];
+
+       info->ioapic = 0; /* XXX unused */
+       info->int_pin = pin;
+       info->apic_address = ioaddr;
+       info->redirindex = IOAPIC_REDTBL + (2 * pin);
+       info->flags = IOAPIC_IM_FLAG_MASKED;
+       if (trig == INTR_TRIGGER_LEVEL)
+               info->flags |= IOAPIC_IM_FLAG_LEVEL;
+
+       /* TODO setup pin */
+}
+
 #endif /* SMP */
index 0000189..b43c46e 100644 (file)
 #ifndef _ARCH_APIC_IOAPIC_ABI_H_
 #define _ARCH_APIC_IOAPIC_ABI_H_
 
+#ifndef _SYS_BUS_H_
+#include <sys/bus.h>
+#endif
+
 #ifdef SMP     /* APIC_IO */
+
 extern struct machintr_abi MachIntrABI_IOAPIC;
-#endif
+
+void   ioapic_abi_set_irqmap(int, int, enum intr_trigger, enum intr_polarity);
+
+#endif /* SMP */
 
 #endif /* !_ARCH_APIC_IOAPIC_ABI_H_ */
index 708bf85..c4e9e40 100644 (file)
@@ -35,6 +35,7 @@
 #include <machine/md_var.h>
 #include <machine/pmap.h>
 #include <machine_base/apic/mpapic.h>
+#include <machine_base/apic/ioapic_abi.h>
 #include <machine/segments.h>
 #include <sys/thread2.h>
 
@@ -1263,9 +1264,7 @@ ioapic_gsi_setup(int gsi)
                irq = gsi;
        }
 
-#if 0
        ioapic_abi_set_irqmap(irq, gsi, trig, pola);
-#endif
 }
 
 void *
index 3d80712..532a4ac 100644 (file)
@@ -56,6 +56,7 @@
 
 #include <sys/thread2.h>
 
+#include <machine_base/apic/ioapic_abi.h>
 #include <machine_base/apic/ioapic_ipl.h>
 
 #ifdef SMP /* APIC-IO */
@@ -721,4 +722,49 @@ ioapic_initmap(void)
        ioapic_irqmaps[IOAPIC_HWI_SYSCALL].im_type = IOAPIC_IMT_SYSCALL;
 }
 
+void
+ioapic_abi_set_irqmap(int irq, int gsi, enum intr_trigger trig,
+    enum intr_polarity pola)
+{
+       struct apic_intmapinfo *info;
+       struct ioapic_irqmap *map;
+       void *ioaddr;
+       int pin;
+
+       KKASSERT(trig == INTR_TRIGGER_EDGE || trig == INTR_TRIGGER_LEVEL);
+       KKASSERT(pola == INTR_POLARITY_HIGH || pola == INTR_POLARITY_LOW);
+       KKASSERT((trig == INTR_TRIGGER_EDGE && pola == INTR_POLARITY_HIGH) ||
+                (trig == INTR_TRIGGER_LEVEL && pola == INTR_POLARITY_LOW));
+
+       KKASSERT(irq >= 0 && irq < IOAPIC_HWI_VECTORS);
+       map = &ioapic_irqmaps[irq];
+
+       KKASSERT(map->im_type == IOAPIC_IMT_UNUSED);
+       map->im_type = IOAPIC_IMT_LINE;
+
+       map->im_gsi = gsi;
+       map->im_trig = trig;
+       map->im_pola = pola;
+
+       if (bootverbose) {
+               kprintf("IOAPIC: irq %d -> gsi %d %c\n", irq, map->im_gsi,
+                       trig == INTR_TRIGGER_LEVEL ? 'L' : 'E');
+       }
+
+       pin = ioapic_gsi_pin(gsi);
+       ioaddr = ioapic_gsi_ioaddr(gsi);
+
+       info = &int_to_apicintpin[irq];
+
+       info->ioapic = 0; /* XXX unused */
+       info->int_pin = pin;
+       info->apic_address = ioaddr;
+       info->redirindex = IOAPIC_REDTBL + (2 * pin);
+       info->flags = IOAPIC_IM_FLAG_MASKED;
+       if (trig == INTR_TRIGGER_LEVEL)
+               info->flags |= IOAPIC_IM_FLAG_LEVEL;
+
+       /* TODO setup pin */
+}
+
 #endif /* SMP */
index 0000189..b43c46e 100644 (file)
 #ifndef _ARCH_APIC_IOAPIC_ABI_H_
 #define _ARCH_APIC_IOAPIC_ABI_H_
 
+#ifndef _SYS_BUS_H_
+#include <sys/bus.h>
+#endif
+
 #ifdef SMP     /* APIC_IO */
+
 extern struct machintr_abi MachIntrABI_IOAPIC;
-#endif
+
+void   ioapic_abi_set_irqmap(int, int, enum intr_trigger, enum intr_polarity);
+
+#endif /* SMP */
 
 #endif /* !_ARCH_APIC_IOAPIC_ABI_H_ */
index cfef0ac..c2033e0 100644 (file)
@@ -34,6 +34,7 @@
 #include <machine/md_var.h>
 #include <machine/pmap.h>
 #include <machine_base/apic/mpapic.h>
+#include <machine_base/apic/ioapic_abi.h>
 #include <machine/segments.h>
 #include <sys/thread2.h>
 
@@ -1325,9 +1326,7 @@ ioapic_gsi_setup(int gsi)
                irq = gsi;
        }
 
-#if 0
        ioapic_abi_set_irqmap(irq, gsi, trig, pola);
-#endif
 }
 
 void *