blob: 1b0350660ab1ed612d94a229c657f730ef056dde [file] [log] [blame]
/*
* 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.
*/
#include "hf/arch/cpu.h"
#include "hf/arch/vm/interrupts_gicv3.h"
#include "hf/dlog.h"
#include "hf/spci.h"
#include "vmapi/hf/call.h"
#include "hftest.h"
#include "primary_with_secondary.h"
/*
* Secondary VM that enables an interrupt, disables interrupts globally, and
* calls hf_mailbox_receive with block=true but expects it to fail.
*/
static void irq(void)
{
uint32_t interrupt_id = hf_interrupt_get();
FAIL("Unexpected secondary IRQ %d from current", interrupt_id);
}
TEST_SERVICE(receive_block)
{
int32_t i;
const char message[] = "Done waiting";
exception_setup(irq);
arch_irq_disable();
hf_interrupt_enable(EXTERNAL_INTERRUPT_ID_A, true);
for (i = 0; i < 10; ++i) {
int32_t res = spci_msg_wait();
EXPECT_EQ(res, SPCI_INTERRUPTED);
}
memcpy_s(SERVICE_SEND_BUFFER()->payload, SPCI_MSG_PAYLOAD_MAX, message,
sizeof(message));
spci_message_init(SERVICE_SEND_BUFFER(), sizeof(message),
HF_PRIMARY_VM_ID, hf_vm_get_id());
spci_msg_send(0);
}