]> xenbits.xensource.com Git - xtf.git/commitdiff
Introduce some basic IO-APIC infrastructure
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 13 Apr 2018 13:41:21 +0000 (13:41 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 13 Apr 2018 16:45:21 +0000 (17:45 +0100)
Replace some opencoded IOAPIC_DEFAULT_BASE constants.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/include/arch/io-apic.h [new file with mode: 0644]
arch/x86/include/arch/xtf.h
arch/x86/io-apic.c [new file with mode: 0644]
build/files.mk
tests/selftest/main.c
tests/xsa-239/main.c

diff --git a/arch/x86/include/arch/io-apic.h b/arch/x86/include/arch/io-apic.h
new file mode 100644 (file)
index 0000000..ec88865
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * @file arch/x86/include/arch/io-apic.h
+ *
+ * %x86 IO-APIC register definitions and utility functions.
+ *
+ * The IO-APIC MMIO window is expected to be in its default location for the
+ * benefit of unpaged environments.
+ */
+
+#ifndef XTF_X86_IO_APIC_H
+#define XTF_X86_IO_APIC_H
+
+#include <xtf/numbers.h>
+#include <xtf/types.h>
+
+/* MMIO window registers. */
+#define IOAPIC_REGSEL             0x00
+#define IOAPIC_IOWIN              0x10
+
+/* IO-APIC registers. */
+#define IOAPIC_ID                 0x0
+
+
+#define IOAPIC_DEFAULT_BASE       0xfec00000
+
+/**
+ * Discover and initialise the IO-APIC.  May fail if there is no IO-APIC.
+ */
+int ioapic_init(void);
+
+static inline uint32_t ioapic_read32(unsigned int reg)
+{
+    *(volatile uint32_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_REGSEL) = reg;
+
+    return *(volatile uint32_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_IOWIN);
+}
+
+static inline uint64_t ioapic_read64(unsigned int reg)
+{
+    *(volatile uint64_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_REGSEL) = reg;
+
+    return *(volatile uint64_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_IOWIN);
+}
+
+static inline void ioapic_write32(unsigned int reg, uint32_t val)
+{
+    *(volatile uint32_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_REGSEL) = reg;
+    *(volatile uint32_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_IOWIN) = val;
+}
+
+static inline void ioapic_write64(unsigned int reg, uint64_t val)
+{
+    *(volatile uint64_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_REGSEL) = reg;
+    *(volatile uint64_t *)_p(IOAPIC_DEFAULT_BASE + IOAPIC_IOWIN) = val;
+}
+
+#endif /* !XTF_X86_IO_APIC_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index deaed1707ab0ae2d1b5cb20c437f39661ab6d45f..3609d5d90876076f3c4584a2e0da31499daa2609 100644 (file)
@@ -6,6 +6,7 @@
 #include <arch/exinfo.h>
 #include <arch/hpet.h>
 #include <arch/idt.h>
+#include <arch/io-apic.h>
 #include <arch/lib.h>
 #include <arch/mm.h>
 #include <arch/msr.h>
diff --git a/arch/x86/io-apic.c b/arch/x86/io-apic.c
new file mode 100644 (file)
index 0000000..05aea34
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * @file arch/x86/io-apic.c
+ *
+ * Basic x86 IO-APIC driver.
+ */
+
+#include <xtf/lib.h>
+
+#include <xen/errno.h>
+
+#include <arch/io-apic.h>
+
+int ioapic_init(void)
+{
+    uint32_t id = ioapic_read32(IOAPIC_ID);
+
+    /* Bare MMIO? */
+    if ( id == ~0u )
+        return -ENODEV;
+
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index 3000239487bc589d8b22122e16ade51409f56bc2..dfa27e481102bb637ce1fe999627ba86d3dd1ebf 100644 (file)
@@ -32,6 +32,7 @@ obj-hvm += $(ROOT)/arch/x86/apic.o
 obj-hvm += $(ROOT)/arch/x86/hpet.o
 obj-hvm += $(ROOT)/arch/x86/hvm/pagetables.o
 obj-hvm += $(ROOT)/arch/x86/hvm/traps.o
+obj-hvm += $(ROOT)/arch/x86/io-apic.o
 
 # Arguably common objects, but PV guests will have no interest in them.
 obj-hvm += $(ROOT)/arch/x86/vmx.o
index 51196b4916fcc8404fda47949edd48676b8f6154..430975587d0de0a0e1ab0d0e7e72e8939da501dd 100644 (file)
@@ -326,6 +326,10 @@ static void test_driver_init(void)
         rc = hpet_init();
         if ( rc && rc != -ENODEV )
             xtf_failure("Fail: hpet_init() returned %d\n", rc);
+
+        rc = ioapic_init();
+        if ( rc && rc != -ENODEV )
+            xtf_failure("Fail: ioapic_init() returned %d\n", rc);
     }
 
     rc = xenstore_init();
index 1035089f128407f85f779eb8c9d5299cf5e3451f..79f68100b6c2f05d52cc37f69b426824482ccdfa 100644 (file)
@@ -21,8 +21,8 @@ const char test_title[] = "XSA-239 PoC";
 
 void test_main(void)
 {
-    uint32_t *io_apic_32 = _p(0xfec00000);
-    uint8_t  *io_apic_8 =  _p(0xfec00000);
+    uint32_t *io_apic_32 = _p(IOAPIC_DEFAULT_BASE);
+    uint8_t  *io_apic_8 =  _p(IOAPIC_DEFAULT_BASE);
     unsigned int i;
 
     /*