1 /*
2  * Copyright 2022 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #include "hf/arch/vm/interrupts.h"
10 #include "hf/arch/vm/interrupts_gicv3.h"
11 
12 #include "hf/dlog.h"
13 #include "hf/mm.h"
14 
15 #include "test/hftest.h"
16 
17 volatile uint32_t last_interrupt_id = 0;
18 
irq(void)19 static void irq(void)
20 {
21 	uint32_t interrupt_id = interrupt_get_and_acknowledge();
22 	HFTEST_LOG("primary IRQ %d from current\n", interrupt_id);
23 	last_interrupt_id = interrupt_id;
24 	interrupt_end(interrupt_id);
25 	HFTEST_LOG("primary IRQ %d ended\n", interrupt_id);
26 }
27 
gicv3_system_setup()28 void gicv3_system_setup()
29 {
30 	const uint32_t mode = MM_MODE_R | MM_MODE_W | MM_MODE_D;
31 	hftest_mm_identity_map((void *)GICD_BASE, PAGE_SIZE, mode);
32 	hftest_mm_identity_map((void *)GICR_BASE, PAGE_SIZE, mode);
33 	hftest_mm_identity_map((void *)IO32_C(SGI_BASE).ptr, PAGE_SIZE, mode);
34 
35 	exception_setup(irq, NULL);
36 	interrupt_gic_setup();
37 }
38