Skip to contentSkip to conversation

Add baseline PIC tests.

PATCH New Steve Rutherford 1 participant 1 message Sep 2, 2015 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add baseline PIC tests.

Tests basic interrupt functionality of the PIC. Relies on the QEMU test device to raise and lower irq lines leading into the PIC.

---
 config/config-x86-common.mak |   3 +
 config/config-x86_64.mak     |   2 +-
 lib/x86/apic.c               |  20 ++-
 lib/x86/apic.h               |   3 +
 lib/x86/pic.c                |  80 +++++++++++
 lib/x86/pic.h                |  20 +++
 x86/ioapic.c                 |  11 --
 x86/pic.c                    | 330 +++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 452 insertions(+), 17 deletions(-)
 create mode 100644 lib/x86/pic.c
 create mode 100644 lib/x86/pic.h
 create mode 100644 x86/pic.c
config/config-x86-common.mak +3 -0
index c2f9908..a7aa17a 100644
@@ -7,6 +7,7 @@ cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
 cflatobjs += lib/x86/fwcfg.o
 cflatobjs += lib/x86/apic.o
+cflatobjs += lib/x86/pic.o
 cflatobjs += lib/x86/atomic.o
 cflatobjs += lib/x86/desc.o
 cflatobjs += lib/x86/isr.o
@@ -70,6 +71,8 @@ $(TEST_DIR)/apic.elf: $(cstart.o) $(TEST_DIR)/apic.o
 
 $(TEST_DIR)/ioapic.elf: $(cstart.o) $(TEST_DIR)/ioapic.o
 
+$(TEST_DIR)/pic.elf: $(cstart.o) $(TEST_DIR)/pic.o
+
 $(TEST_DIR)/tscdeadline_latency.elf: $(cstart.o) $(TEST_DIR)/tscdeadline_latency.o
 
 $(TEST_DIR)/init.elf: $(cstart.o) $(TEST_DIR)/init.o
config/config-x86_64.mak +1 -1
index 7d4eb34..0f2c47a 100644
@@ -7,7 +7,7 @@ tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \
 	  $(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \
 	  $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat \
 	  $(TEST_DIR)/pcid.flat $(TEST_DIR)/debug.flat \
-	  $(TEST_DIR)/ioapic.flat
+	  $(TEST_DIR)/ioapic.flat $(TEST_DIR)/pic.flat
 tests += $(TEST_DIR)/svm.flat
 tests += $(TEST_DIR)/vmx.flat
 tests += $(TEST_DIR)/tscdeadline_latency.flat
lib/x86/apic.c +15 -5
index 80b96d8..2e8e466 100644
@@ -1,6 +1,8 @@
 #include "libcflat.h"
 #include "apic.h"
+#include "io.h"
 #include "msr.h"
+#include "pic.h"
 
 static void *g_apic = (void *)0xfee00000;
 static void *g_ioapic = (void *)0xfec00000;
@@ -12,9 +14,15 @@ struct apic_ops {
     u32 (*id)(void);
 };
 
-static void outb(unsigned char data, unsigned short port)
+void set_irq_line(unsigned line, int val)
 {
-    asm volatile ("out %0, %1" : : "a"(data), "d"(port));
+    outb(val, 0x2000 + line);
+}
+
+void toggle_irq_line(unsigned line)
+{
+    set_irq_line(line, 1);
+    set_irq_line(line, 0);
 }
 
 void eoi(void)
@@ -164,8 +172,10 @@ void enable_apic(void)
     xapic_write(0xf0, 0x1ff); /* spurious vector register */
 }
 
-void mask_pic_interrupts(void)
+void unmask_lvt0(void)
 {
-    outb(0xff, 0x21);
-    outb(0xff, 0xa1);
+    int lvt0 = apic_read(APIC_LVT0);
+    lvt0 &= ~APIC_LVT_MASKED;
+    lvt0 = SET_APIC_DELIVERY_MODE(lvt0, APIC_MODE_EXTINT);
+    apic_write(APIC_LVT0, lvt0);
 }
lib/x86/apic.h +3 -0
index 216b98d..a5b19c0 100644
@@ -20,6 +20,8 @@ typedef struct {
 
 void mask_pic_interrupts(void);
 
+void set_irq_line(unsigned line, int val);
+void toggle_irq_line(unsigned line);
 void eoi(void);
 
 void ioapic_write_redir(unsigned line, ioapic_redir_entry_t e);
@@ -37,4 +39,5 @@ uint32_t apic_id(void);
 
 int enable_x2apic(void);
 
+void unmask_lvt0(void);
 #endif
lib/x86/pic.c new file +80 -0

80 lines not on this page · raw message

lib/x86/pic.h new file +20 -0
new file mode 100644
index 0000000..61e72ff
@@ -0,0 +1,20 @@
+#ifndef CFLAT_PIC_H
+#define CFLAT_PIC_H
+
+#define PIC_MASTER false
+#define PIC_SLAVE true
+
+void set_pic_mask(unsigned char master, unsigned char slave);
+void mask_pic_interrupts(void);
+void unmask_pic_interrupts(void);
+
+void pic_write_data(unsigned char value, int slave);
+unsigned char pic_read_data(int slave);
+
+void pic_write_command(unsigned char value, int slave);
+unsigned char pic_read_command(int slave);
+
+void pic_eoi(unsigned char irq);
+void pic_nonspecific_eoi(unsigned char irq);
+
+#endif  /* CFLAT_PIC_H */
x86/ioapic.c +0 -11
index 1fe1ccc..d91aa23 100644
@@ -19,17 +19,6 @@ static void set_ioapic_redir(unsigned line, unsigned vec, unsigned trig_mode)
 	ioapic_write_redir(line, e);
 }
 
-static void set_irq_line(unsigned line, int val)
-{
-	asm volatile("out %0, %1" : : "a"((u8)val), "d"((u16)(0x2000 + line)));
-}
-
-static void toggle_irq_line(unsigned line)
-{
-	set_irq_line(line, 1);
-	set_irq_line(line, 0);
-}
-
 static void ioapic_reg_version(void)
 {
 	u8 version_offset;
x86/pic.c new file +330 -0

330 lines not on this page · raw message

Signature · 1 line
2.5.0.457.gab17608