Split out generic interrupt helpers from GICv3 code.
This lets us remove the dependency of other tests on GICv3.
Change-Id: I34d546fca4726372564307333ddf5c8a65f3513a
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 88f2c18..3475316 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -16,7 +16,9 @@
"offsets.h": "c",
"barriers.h": "c",
"spci.h": "c",
- "spci_internal.h": "c"
+ "spci_internal.h": "c",
+ "interrupts_gicv3.h": "c",
+ "interrupts.h": "c"
},
"C_Cpp.errorSquiggles": "Disabled"
}
diff --git a/inc/hf/arch/cpu.h b/inc/hf/arch/cpu.h
index ae0d08f..c26cb8c 100644
--- a/inc/hf/arch/cpu.h
+++ b/inc/hf/arch/cpu.h
@@ -27,7 +27,7 @@
#include "vmapi/hf/spci.h"
/**
- * Disables interrutps.
+ * Disables interrupts.
*/
void arch_irq_disable(void);
diff --git a/project/reference b/project/reference
index d35cafd..3eeaa40 160000
--- a/project/reference
+++ b/project/reference
@@ -1 +1 @@
-Subproject commit d35cafd3b2f0d758c753c7058bed3daabd40b909
+Subproject commit 3eeaa4002c7ab8dc0ed02b0dadfa8ba7ab3ad76f
diff --git a/src/arch/aarch64/hftest/BUILD.gn b/src/arch/aarch64/hftest/BUILD.gn
index 78d89c7..044c874 100644
--- a/src/arch/aarch64/hftest/BUILD.gn
+++ b/src/arch/aarch64/hftest/BUILD.gn
@@ -42,13 +42,22 @@
]
}
-# Exception handlers for interrupts and GICv3 el1 driver.
-source_set("interrupts_gicv3") {
+# Exception handlers for interrupts.
+source_set("interrupts") {
testonly = true
public_configs = [ "//src/arch/aarch64:config" ]
sources = [
"events.c",
"exceptions.S",
+ "interrupts.c",
+ ]
+}
+
+# GICv3 EL1 driver.
+source_set("interrupts_gicv3") {
+ testonly = true
+ public_configs = [ "//src/arch/aarch64:config" ]
+ sources = [
"interrupts_gicv3.c",
]
}
diff --git a/src/arch/aarch64/hftest/interrupts.c b/src/arch/aarch64/hftest/interrupts.c
new file mode 100644
index 0000000..507552f
--- /dev/null
+++ b/src/arch/aarch64/hftest/interrupts.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018 The Hafnium Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "hf/arch/vm/interrupts.h"
+
+#include <stdint.h>
+
+#include "hf/dlog.h"
+
+#include "msr.h"
+
+extern uint8_t vector_table_el1;
+static void (*irq_callback)(void);
+
+void irq_current(void)
+{
+ if (irq_callback != NULL) {
+ irq_callback();
+ }
+}
+
+void exception_setup(void (*irq)(void))
+{
+ irq_callback = irq;
+
+ /* Set exception vector table. */
+ write_msr(VBAR_EL1, &vector_table_el1);
+}
+
+void sync_current_exception(uintreg_t esr, uintreg_t elr)
+{
+ switch (esr >> 26) {
+ case 0x25: /* EC = 100101, Data abort. */
+ dlog("Data abort: pc=%#x, esr=%#x, ec=%#x", elr, esr,
+ esr >> 26);
+ if (!(esr & (1U << 10))) { /* Check FnV bit. */
+ dlog(", far=%#x", read_msr(far_el1));
+ } else {
+ dlog(", far=invalid");
+ }
+
+ dlog("\n");
+ break;
+
+ default:
+ dlog("Unknown current sync exception pc=%#x, esr=%#x, "
+ "ec=%#x\n",
+ elr, esr, esr >> 26);
+ }
+
+ for (;;) {
+ /* do nothing */
+ }
+}
+
+void interrupt_wait(void)
+{
+ __asm__ volatile("wfi");
+}
diff --git a/src/arch/aarch64/hftest/interrupts_gicv3.c b/src/arch/aarch64/hftest/interrupts_gicv3.c
index a5df6ff..9010ce1 100644
--- a/src/arch/aarch64/hftest/interrupts_gicv3.c
+++ b/src/arch/aarch64/hftest/interrupts_gicv3.c
@@ -19,30 +19,10 @@
#include <stdbool.h>
#include <stdint.h>
-#include "hf/arch/cpu.h"
-
#include "hf/dlog.h"
#include "msr.h"
-extern uint8_t vector_table_el1;
-static void (*irq_callback)(void);
-
-void irq_current(void)
-{
- if (irq_callback != NULL) {
- irq_callback();
- }
-}
-
-void exception_setup(void (*irq)(void))
-{
- irq_callback = irq;
-
- /* Set exception vector table. */
- write_msr(VBAR_EL1, &vector_table_el1);
-}
-
void interrupt_gic_setup(void)
{
uint32_t ctlr = 1U << 4 /* Enable affinity routing. */
@@ -159,34 +139,3 @@
{
write_msr(ICC_EOIR1_EL1, intid);
}
-
-void sync_current_exception(uintreg_t esr, uintreg_t elr)
-{
- switch (esr >> 26) {
- case 0x25: /* EC = 100101, Data abort. */
- dlog("Data abort: pc=%#x, esr=%#x, ec=%#x", elr, esr,
- esr >> 26);
- if (!(esr & (1U << 10))) { /* Check FnV bit. */
- dlog(", far=%#x", read_msr(far_el1));
- } else {
- dlog(", far=invalid");
- }
-
- dlog("\n");
- break;
-
- default:
- dlog("Unknown current sync exception pc=%#x, esr=%#x, "
- "ec=%#x\n",
- elr, esr, esr >> 26);
- }
-
- for (;;) {
- /* do nothing */
- }
-}
-
-void interrupt_wait(void)
-{
- __asm__ volatile("wfi");
-}
diff --git a/src/arch/aarch64/inc/hf/arch/vm/interrupts.h b/src/arch/aarch64/inc/hf/arch/vm/interrupts.h
new file mode 100644
index 0000000..fa0ba2a
--- /dev/null
+++ b/src/arch/aarch64/inc/hf/arch/vm/interrupts.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2019 The Hafnium Authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+void exception_setup(void (*irq)(void));
+void interrupt_wait(void);
diff --git a/src/arch/aarch64/inc/hf/arch/vm/interrupts_gicv3.h b/src/arch/aarch64/inc/hf/arch/vm/interrupts_gicv3.h
index 5ebf6ac..b98c304 100644
--- a/src/arch/aarch64/inc/hf/arch/vm/interrupts_gicv3.h
+++ b/src/arch/aarch64/inc/hf/arch/vm/interrupts_gicv3.h
@@ -51,7 +51,6 @@
/* clang-format on */
-void exception_setup(void (*irq)(void));
void interrupt_gic_setup(void);
void interrupt_enable(uint32_t intid, bool enable);
void interrupt_enable_all(bool enable);
@@ -63,4 +62,3 @@
uint16_t target_list);
uint32_t interrupt_get_and_acknowledge(void);
void interrupt_end(uint32_t intid);
-void interrupt_wait(void);
diff --git a/test/vmapi/arch/aarch64/gicv3/BUILD.gn b/test/vmapi/arch/aarch64/gicv3/BUILD.gn
index 43a7fea..83cb1d4 100644
--- a/test/vmapi/arch/aarch64/gicv3/BUILD.gn
+++ b/test/vmapi/arch/aarch64/gicv3/BUILD.gn
@@ -33,6 +33,7 @@
deps = [
"//src/arch/aarch64:arch",
+ "//src/arch/aarch64/hftest:interrupts",
"//src/arch/aarch64/hftest:interrupts_gicv3",
"//test/hftest:hftest_primary_vm",
]
diff --git a/test/vmapi/arch/aarch64/gicv3/gicv3.c b/test/vmapi/arch/aarch64/gicv3/gicv3.c
index 71c3994..a96f55a 100644
--- a/test/vmapi/arch/aarch64/gicv3/gicv3.c
+++ b/test/vmapi/arch/aarch64/gicv3/gicv3.c
@@ -17,6 +17,7 @@
#include "gicv3.h"
#include "hf/arch/cpu.h"
+#include "hf/arch/vm/interrupts.h"
#include "hf/arch/vm/interrupts_gicv3.h"
#include "hf/dlog.h"
diff --git a/test/vmapi/arch/aarch64/gicv3/services/BUILD.gn b/test/vmapi/arch/aarch64/gicv3/services/BUILD.gn
index 89786b1..8ba8436 100644
--- a/test/vmapi/arch/aarch64/gicv3/services/BUILD.gn
+++ b/test/vmapi/arch/aarch64/gicv3/services/BUILD.gn
@@ -33,7 +33,6 @@
deps = [
":common",
- "//src/arch/aarch64/hftest:interrupts_gicv3",
]
}
@@ -49,6 +48,7 @@
deps = [
":common",
"//src/arch/aarch64:arch",
+ "//src/arch/aarch64/hftest:interrupts",
"//src/arch/aarch64/hftest:interrupts_gicv3",
]
}
@@ -65,7 +65,6 @@
deps = [
":common",
"//src/arch/aarch64:arch",
- "//src/arch/aarch64/hftest:interrupts_gicv3",
]
}
diff --git a/test/vmapi/arch/aarch64/gicv3/services/timer.c b/test/vmapi/arch/aarch64/gicv3/services/timer.c
index 4b9cfd1..96bf367 100644
--- a/test/vmapi/arch/aarch64/gicv3/services/timer.c
+++ b/test/vmapi/arch/aarch64/gicv3/services/timer.c
@@ -18,6 +18,7 @@
#include "hf/arch/cpu.h"
#include "hf/arch/vm/events.h"
+#include "hf/arch/vm/interrupts.h"
#include "hf/arch/vm/interrupts_gicv3.h"
#include "hf/dlog.h"
diff --git a/test/vmapi/primary_with_secondaries/services/BUILD.gn b/test/vmapi/primary_with_secondaries/services/BUILD.gn
index 4dbe074..a735b81 100644
--- a/test/vmapi/primary_with_secondaries/services/BUILD.gn
+++ b/test/vmapi/primary_with_secondaries/services/BUILD.gn
@@ -68,7 +68,7 @@
]
deps = [
- "//src/arch/aarch64/hftest:interrupts_gicv3",
+ "//src/arch/aarch64/hftest:interrupts",
]
}
@@ -136,7 +136,7 @@
]
deps = [
- "//src/arch/aarch64/hftest:interrupts_gicv3",
+ "//src/arch/aarch64/hftest:interrupts",
]
}
@@ -153,6 +153,7 @@
]
deps = [
"//src/arch/aarch64:arch",
+ "//src/arch/aarch64/hftest:interrupts",
"//test/vmapi/primary_with_secondaries:util",
]
}
@@ -189,6 +190,9 @@
sources = [
"wfi.c",
]
+ deps = [
+ "//src/arch/aarch64/hftest:interrupts",
+ ]
}
# Service to receive messages in a secondary VM and ensure that the header fields are correctly set.
diff --git a/test/vmapi/primary_with_secondaries/services/echo_with_notification.c b/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
index a4954d9..fb27e24 100644
--- a/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
+++ b/test/vmapi/primary_with_secondaries/services/echo_with_notification.c
@@ -15,7 +15,7 @@
*/
#include "hf/arch/cpu.h"
-#include "hf/arch/vm/interrupts_gicv3.h"
+#include "hf/arch/vm/interrupts.h"
#include "hf/spci.h"
#include "hf/std.h"
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible.c b/test/vmapi/primary_with_secondaries/services/interruptible.c
index 3b86122..be0249e 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible.c
@@ -15,7 +15,7 @@
*/
#include "hf/arch/cpu.h"
-#include "hf/arch/vm/interrupts_gicv3.h"
+#include "hf/arch/vm/interrupts.h"
#include "hf/dlog.h"
#include "hf/std.h"
diff --git a/test/vmapi/primary_with_secondaries/services/interruptible_echo.c b/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
index e370aea..7574ac6 100644
--- a/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
+++ b/test/vmapi/primary_with_secondaries/services/interruptible_echo.c
@@ -15,7 +15,7 @@
*/
#include "hf/arch/cpu.h"
-#include "hf/arch/vm/interrupts_gicv3.h"
+#include "hf/arch/vm/interrupts.h"
#include "hf/dlog.h"
#include "hf/std.h"
diff --git a/test/vmapi/primary_with_secondaries/services/receive_block.c b/test/vmapi/primary_with_secondaries/services/receive_block.c
index c8c4de2..29ec406 100644
--- a/test/vmapi/primary_with_secondaries/services/receive_block.c
+++ b/test/vmapi/primary_with_secondaries/services/receive_block.c
@@ -15,7 +15,7 @@
*/
#include "hf/arch/cpu.h"
-#include "hf/arch/vm/interrupts_gicv3.h"
+#include "hf/arch/vm/interrupts.h"
#include "hf/dlog.h"
#include "hf/spci.h"
diff --git a/test/vmapi/primary_with_secondaries/services/wfi.c b/test/vmapi/primary_with_secondaries/services/wfi.c
index 7dbd372..e45f511 100644
--- a/test/vmapi/primary_with_secondaries/services/wfi.c
+++ b/test/vmapi/primary_with_secondaries/services/wfi.c
@@ -15,7 +15,7 @@
*/
#include "hf/arch/cpu.h"
-#include "hf/arch/vm/interrupts_gicv3.h"
+#include "hf/arch/vm/interrupts.h"
#include "hf/dlog.h"