blob: 5c944d15754947b001b8649d9c6eba935e63c055 [file] [log] [blame]
Madhukar Pappireddy81237692024-01-04 17:32:23 -06001/*
2 * Copyright 2024 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 "vmapi/hf/call.h"
10
11#include "primary_with_secondary.h"
12#include "test/hftest.h"
13
14/*
15 * Test secure interrupt handling while the Secure Partition runs in FFA_RUN
16 * partition runtime model with virtual interrupts potentially masked. This
17 * test helps to validate the functionality of the SPMC, which is to:
18 * - Intercept a FFA_MSG_WAIT invocation by the current SP in FFA_RUN partition
19 * runtime model, if there are pending virtual secure interrupts.
20 * - Resume the SP to handle the pending secure virtual interrupt.
21 *
22 * For orchestrating the above scenario, we leverage indirect messaging
23 * interface and allocate CPU cycles to the Secure Partition through FFA_RUN
24 * interface.
25 */
26TEST_PRECONDITION(secure_interrupts, preempted_by_secure_interrupt,
27 service1_is_not_vm)
28{
29 struct ffa_value ret;
30 struct mailbox_buffers mb = set_up_mailbox();
31 const uint32_t delay = 100;
32 const uint32_t echo_payload;
33 ffa_id_t echo_sender;
34 ffa_id_t own_id = hf_vm_get_id();
35 struct ffa_partition_info *service1_info = service1(mb.recv);
36
37 SERVICE_SELECT(service1_info->vm_id, "sec_interrupt_preempt_msg",
38 mb.send);
39
40 /*
41 * Send an indirect message to convey the Secure Watchdog timer delay
42 * which serves as the source of the secure interrupt.
43 */
44 ret = send_indirect_message(own_id, service1_info->vm_id, mb.send,
45 &delay, sizeof(delay), 0);
46 EXPECT_EQ(ret.func, FFA_SUCCESS_32);
47
48 /* Schedule message receiver through FFA_RUN interface. */
49 ret = ffa_run(service1_info->vm_id, 0);
50 EXPECT_EQ(ret.func, FFA_MSG_WAIT_32);
51
52 receive_indirect_message((void *)&echo_payload, sizeof(echo_payload),
53 mb.recv, &echo_sender);
54
55 HFTEST_LOG("Message echoed back: %#x", echo_payload);
56 EXPECT_EQ(echo_payload, delay);
57 EXPECT_EQ(echo_sender, service1_info->vm_id);
58}
J-Alves3e9f6052024-07-23 13:41:56 +010059
60/**
61 * This test expects SP1 to have pended an interrupt for SP2, before SP2 has
62 * booted, following the boot protocol.
63 *
64 * TODO: Make this test applicable to S-EL0 and S-EL1 UP partitions.
65 */
66TEST_PRECONDITION(secure_interrupts, handle_interrupt_rtm_init,
67 service2_is_mp_sp)
68{
69 struct ffa_value ret;
70 struct mailbox_buffers mb = set_up_mailbox();
71 struct ffa_partition_info *service2_info = service2(mb.recv);
72
73 SERVICE_SELECT(service2_info->vm_id, "check_interrupt_rtm_init_handled",
74 mb.send);
75
76 /* Schedule message receiver through FFA_RUN interface. */
77 ret = ffa_run(service2_info->vm_id, 0);
78 EXPECT_EQ(ret.func, FFA_YIELD_32);
79}