blob: ae42046bf372ed351d2193db4171d58cf8c2da67 [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}