1 /*
2 * Copyright 2019 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/irq.h"
10 #include "hf/arch/types.h"
11 #include "hf/arch/vm/interrupts.h"
12
13 #include "hf/dlog.h"
14
15 #include "vmapi/hf/call.h"
16
17 #include "primary_with_secondary.h"
18 #include "test/hftest.h"
19
20 /*
21 * Secondary VM that enables an interrupt, disables interrupts globally, and
22 * calls WFI.
23 */
24
irq(void)25 static void irq(void)
26 {
27 uint32_t interrupt_id = hf_interrupt_get();
28 FAIL("Unexpected secondary IRQ %d from current", interrupt_id);
29 }
30
TEST_SERVICE(wfi)31 TEST_SERVICE(wfi)
32 {
33 int32_t i;
34 const char message[] = "Done waiting";
35
36 exception_setup(irq, NULL);
37 arch_irq_disable();
38 hf_interrupt_enable(EXTERNAL_INTERRUPT_ID_A, true, INTERRUPT_TYPE_IRQ);
39
40 for (i = 0; i < 10; ++i) {
41 interrupt_wait();
42 }
43
44 memcpy_s(SERVICE_SEND_BUFFER(), FFA_MSG_PAYLOAD_MAX, message,
45 sizeof(message));
46
47 ffa_msg_send(hf_vm_get_id(), HF_PRIMARY_VM_ID, sizeof(message), 0);
48 }
49