1 /*
2  * Copyright (c) 2024, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 
9 #include "fatal_error.h"
10 
11 #include "device_definition.h"
12 
13 static bool prevent_recursion = false;
14 
log_error_permissions_check(uint32_t err,bool is_fatal)15 bool log_error_permissions_check(uint32_t err, bool is_fatal)
16 {
17     enum lcm_tp_mode_t tp_mode = LCM_TP_MODE_PCI;
18     enum lcm_lcs_t lcs = LCM_LCS_SE;
19     enum lcm_bool_t sp_enabled = LCM_TRUE;
20 
21     /* Avoid issues where one of the following functions also throws a fatal
22      * error.
23      */
24     if (prevent_recursion) {
25         return false;
26     }
27 
28     prevent_recursion = true;
29 
30     if (lcm_get_tp_mode(&LCM_DEV_S, &tp_mode) != LCM_ERROR_NONE) {
31         goto out;
32     }
33     if (lcm_get_lcs(&LCM_DEV_S, &lcs) != LCM_ERROR_NONE) {
34         goto out;
35     }
36     if (lcm_get_sp_enabled(&LCM_DEV_S, &sp_enabled) != LCM_ERROR_NONE) {
37         goto out;
38     }
39 
40     if (tp_mode == LCM_TP_MODE_TCI || (lcs != LCM_LCS_SE && sp_enabled != LCM_TRUE)) {
41         prevent_recursion = false;
42         return true;
43     }
44 out:
45     prevent_recursion = false;
46 
47     return false;
48 }
49