1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include "gpu/gpu.h"
25 #include "base.h"
26 #include "libraries/utils/nvprintf.h"
27 
28 static bool g_libspdmAssertHit = false;
29 
30 /*
31  * Checking and clear libspdm assert status.
32  * Any assert in libspdm we need to return error and stop processing.
33  * Returns true if no assert detected, false if assert detected.
34  */
35 bool
nvspdm_check_and_clear_libspdm_assert(void)36 nvspdm_check_and_clear_libspdm_assert(void)
37 {
38     bool bAssertHit = g_libspdmAssertHit;
39 
40     // Clear assert status before returning.
41     g_libspdmAssertHit = false;
42 
43     // Function is successful on no assert, failing on assert.
44     return !bAssertHit;
45 }
46 
47 void
libspdm_debug_assert(const char * file_name,size_t line_number,const char * description)48 libspdm_debug_assert
49 (
50     const char *file_name,
51     size_t      line_number,
52     const char *description
53 )
54 {
55     NV_PRINTF (LEVEL_ERROR, "libspdm assertion hit!\n");
56     g_libspdmAssertHit = NV_TRUE;
57     DBG_BREAKPOINT();
58 }
59 
60 void
libspdm_debug_print(size_t error_level,const char * format,...)61 libspdm_debug_print
62 (
63     size_t      error_level,
64     const char *format,
65     ...
66 )
67 {
68     return;
69 }
70