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 #ifndef LIBSPDM_INCLUDES_H 25 #define LIBSPDM_INCLUDES_H 26 27 // 28 // Dedicated header file to centralize all libspdm-related includes and defines. 29 // This allows us to minimize the amount of headers (and sources) that have direct 30 // libspdm dependency, and allowing shared macros & types for dependent source. 31 // 32 33 /* ------------------------ Includes --------------------------------------- */ 34 #include "internal/libspdm_common_lib.h" 35 #include "internal/libspdm_secured_message_lib.h" 36 #include "library/spdm_requester_lib.h" 37 38 /* ------------------------ Macros and Defines ----------------------------- */ 39 // 40 // As libspdm has its own RETURN_STATUS define, we need to ensure we do not 41 // accidentally compare it against NV_STATUS. Use macro for consistent libspdm 42 // error handling. 43 // 44 #define CHECK_SPDM_STATUS(expr) do { \ 45 libspdm_return_t __spdmStatus; \ 46 __spdmStatus = (expr); \ 47 if (LIBSPDM_STATUS_IS_ERROR(__spdmStatus)) \ 48 { \ 49 NV_PRINTF(LEVEL_ERROR, "SPDM failed with status 0x%0x\n", \ 50 __spdmStatus); \ 51 status = NV_ERR_GENERIC; \ 52 goto ErrorExit; \ 53 } \ 54 } while (NV_FALSE) 55 56 // Check for any critical issues caused by data size mismatches. 57 ct_assert(sizeof(NvU8) == sizeof(uint8_t)); 58 ct_assert(sizeof(NvU16) == sizeof(uint16_t)); 59 ct_assert(sizeof(NvU32) == sizeof(uint32_t)); 60 ct_assert(sizeof(NvU64) == sizeof(uint64_t)); 61 62 typedef struct _SPDM_ALGO_CHECK_ENTRY 63 { 64 libspdm_data_type_t dataType; 65 uint32_t expectedAlgo; 66 } SPDM_ALGO_CHECK_ENTRY, *PSPDM_ALGO_CHECK_ENTRY; 67 68 // 69 // Check for assert in libspdm code, indicating a fatal condition. 70 // Returns false if assert was hit. 71 // 72 bool nvspdm_check_and_clear_libspdm_assert(void); 73 74 #endif // LIBSPDM_INCLUDES_H 75