blob: cafcb7a8d32d994d799df36413770660d51215ed [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Boyan Karatotev794b0ac2025-06-20 13:13:29 +01002 * Copyright (c) 2018-2025, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02008#include <debug.h>
Antonio Nino Diaz09a00ef2019-01-11 13:12:58 +00009#include <drivers/arm/arm_gic.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010#include <irq.h>
11#include <platform.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020012#include <tftf_lib.h>
13
14/*
15 * The 2 following global variables are used by the SGI handler to return
16 * information to the main test function.
17 */
Boyan Karatotev794b0ac2025-06-20 13:13:29 +010018static unsigned int sgi_data;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020019
20/* Flag to indicate whether the SGI has been handled */
21static volatile unsigned int sgi_handled;
22
23static int sgi_handler(void *data)
24{
25 /* Save SGI data */
Boyan Karatotev794b0ac2025-06-20 13:13:29 +010026 sgi_data = *(unsigned int *) data;
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020027 sgi_handled = 1;
28
29 /* Return value doesn't matter */
30 return 0;
31}
32
33/*
34 * @Test_Aim@ Test SGI support on lead CPU
35 *
36 * 1) Register a local IRQ handler for SGI 0.
37 * 2) Send SGI 0 to the calling core, i.e. the lead CPU.
38 * 3) Check the correctness of the data received in the IRQ handler.
39 *
40 * TODO: Improve this test by sending SGIs to all cores in the system.
41 * This will ensure that IRQs are correctly configured on all cores.
42 */
43test_result_t test_validation_sgi(void)
44{
45 unsigned int mpid = read_mpidr_el1();
46 unsigned int core_pos = platform_get_core_pos(mpid);
47 const unsigned int sgi_id = IRQ_NS_SGI_0;
Boyan Karatotev6d144db2025-06-23 15:04:53 +010048 const unsigned int sgi_irq = tftf_irq_get_my_sgi_num(sgi_id);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020049 test_result_t test_res = TEST_RESULT_SUCCESS;
50 int ret;
51
52 /* Register the local IRQ handler for the SGI */
Boyan Karatotev6d144db2025-06-23 15:04:53 +010053 ret = tftf_irq_register_handler_sgi(sgi_id, sgi_handler);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020054 if (ret != 0) {
55 tftf_testcase_printf("Failed to register IRQ %u (%d)",
56 sgi_id, ret);
57 return TEST_RESULT_FAIL;
58 }
Boyan Karatotev6d144db2025-06-23 15:04:53 +010059 tftf_irq_enable_sgi(sgi_id, GIC_HIGHEST_NS_PRIORITY);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020060
61 /* Send the SGI to the lead CPU */
62 tftf_send_sgi(sgi_id, core_pos);
63
64 /*
65 * Wait for the SGI to be handled.
66 * The SGI handler will update a global variable to reflect that.
67 */
68 while (sgi_handled == 0)
69 continue;
70
71 /* Verify the data received in the SGI handler */
Boyan Karatotev6d144db2025-06-23 15:04:53 +010072 if (sgi_data != sgi_irq) {
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020073 tftf_testcase_printf("Wrong IRQ ID, expected %u, got %u\n",
Boyan Karatotev6d144db2025-06-23 15:04:53 +010074 sgi_irq, sgi_data);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020075 test_res = TEST_RESULT_FAIL;
76 }
77
Boyan Karatotev6d144db2025-06-23 15:04:53 +010078 tftf_irq_disable_sgi(sgi_id);
79 tftf_irq_unregister_handler_sgi(sgi_id);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020080
81 return test_res;
82}