blob: cafcb7a8d32d994d799df36413770660d51215ed [file] [log] [blame]
/*
* Copyright (c) 2018-2025, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <arch_helpers.h>
#include <debug.h>
#include <drivers/arm/arm_gic.h>
#include <irq.h>
#include <platform.h>
#include <tftf_lib.h>
/*
* The 2 following global variables are used by the SGI handler to return
* information to the main test function.
*/
static unsigned int sgi_data;
/* Flag to indicate whether the SGI has been handled */
static volatile unsigned int sgi_handled;
static int sgi_handler(void *data)
{
/* Save SGI data */
sgi_data = *(unsigned int *) data;
sgi_handled = 1;
/* Return value doesn't matter */
return 0;
}
/*
* @Test_Aim@ Test SGI support on lead CPU
*
* 1) Register a local IRQ handler for SGI 0.
* 2) Send SGI 0 to the calling core, i.e. the lead CPU.
* 3) Check the correctness of the data received in the IRQ handler.
*
* TODO: Improve this test by sending SGIs to all cores in the system.
* This will ensure that IRQs are correctly configured on all cores.
*/
test_result_t test_validation_sgi(void)
{
unsigned int mpid = read_mpidr_el1();
unsigned int core_pos = platform_get_core_pos(mpid);
const unsigned int sgi_id = IRQ_NS_SGI_0;
const unsigned int sgi_irq = tftf_irq_get_my_sgi_num(sgi_id);
test_result_t test_res = TEST_RESULT_SUCCESS;
int ret;
/* Register the local IRQ handler for the SGI */
ret = tftf_irq_register_handler_sgi(sgi_id, sgi_handler);
if (ret != 0) {
tftf_testcase_printf("Failed to register IRQ %u (%d)",
sgi_id, ret);
return TEST_RESULT_FAIL;
}
tftf_irq_enable_sgi(sgi_id, GIC_HIGHEST_NS_PRIORITY);
/* Send the SGI to the lead CPU */
tftf_send_sgi(sgi_id, core_pos);
/*
* Wait for the SGI to be handled.
* The SGI handler will update a global variable to reflect that.
*/
while (sgi_handled == 0)
continue;
/* Verify the data received in the SGI handler */
if (sgi_data != sgi_irq) {
tftf_testcase_printf("Wrong IRQ ID, expected %u, got %u\n",
sgi_irq, sgi_data);
test_res = TEST_RESULT_FAIL;
}
tftf_irq_disable_sgi(sgi_id);
tftf_irq_unregister_handler_sgi(sgi_id);
return test_res;
}