1 /* 2 * SPDX-FileCopyrightText: Copyright (c) 2019-2020 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 _INFOROM_NVSWITCH_H_ 25 #define _INFOROM_NVSWITCH_H_ 26 27 #include "inforom/ifrstruct.h" 28 #include "inforom/omsdef.h" 29 #include "nv_list.h" 30 #include "smbpbi_shared_nvswitch.h" 31 32 #define INFOROM_MAX_PACKED_SIZE (32*1024) 33 34 #define INFOROM_FS_FILE_SIZE(pPackedFile) \ 35 (((pPackedFile)[INFOROM_OBJECT_HEADER_V1_00_SIZE_OFFSET]) | \ 36 ((pPackedFile)[INFOROM_OBJECT_HEADER_V1_00_SIZE_OFFSET + 1] << 8)) 37 #define INFOROM_FS_FILE_NAMES_MATCH(fileName1, fileName2) \ 38 ((((NvU8)((fileName1)[0])) == ((NvU8)((fileName2)[0]))) && \ 39 (((NvU8)((fileName1)[1])) == ((NvU8)((fileName2)[1]))) && \ 40 (((NvU8)((fileName1)[2])) == ((NvU8)((fileName2)[2])))) 41 42 #define INFOROM_FS_COPY_FILE_NAME(destName, srcName) \ 43 { \ 44 (destName)[0] = (srcName)[0]; \ 45 (destName)[1] = (srcName)[1]; \ 46 (destName)[2] = (srcName)[2]; \ 47 } 48 49 #define m_inforom_nvl_get_new_errors_per_minute(value, pSum) \ 50 do \ 51 { \ 52 *pSum = (*pSum - (*pSum / 60)) + value; \ 53 } while (NV_FALSE) \ 54 55 // 56 // OS type defines. 57 // 58 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_TYPE_OTHER 0x0 59 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_TYPE_WIN9X 0x1 60 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_TYPE_WIN2K 0x2 61 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_TYPE_WIN 0x4 62 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_TYPE_UNIX 0x5 63 64 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_MAJOR 7:0 65 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_MINOR 15:8 66 #define INFOROM_BBX_OBJ_V1_00_SYSTEM_OS_BUILD 31:16 67 68 69 struct INFOROM_OBJECT_CACHE_ENTRY 70 { 71 INFOROM_OBJECT_HEADER_V1_00 header; 72 struct INFOROM_OBJECT_CACHE_ENTRY *pNext; 73 }; 74 75 struct inforom 76 { 77 // InfoROM Objects 78 // RO objects - statically allocated as the InfoROM should always contain 79 // these objects. 80 struct 81 { 82 NvBool bValid; 83 union { 84 NvU8 v1[INFOROM_OBD_OBJECT_V1_XX_PACKED_SIZE]; 85 NvU8 v2[INFOROM_OBD_OBJECT_V2_XX_PACKED_SIZE]; 86 } packedObject; 87 union { 88 INFOROM_OBJECT_HEADER_V1_00 header; 89 INFOROM_OBD_OBJECT_V1_XX v1; 90 INFOROM_OBD_OBJECT_V2_XX v2; 91 } object; 92 } OBD; 93 94 struct 95 { 96 NvBool bValid; 97 NvU8 packedObject[INFOROM_OEM_OBJECT_V1_00_PACKED_SIZE]; 98 INFOROM_OEM_OBJECT_V1_00 object; 99 } OEM; 100 101 struct 102 { 103 NvBool bValid; 104 NvU8 packedObject[INFOROM_IMG_OBJECT_V1_00_PACKED_SIZE]; 105 INFOROM_IMG_OBJECT_V1_00 object; 106 } IMG; 107 108 INFOROM_NVLINK_STATE *pNvlinkState; 109 INFOROM_ECC_STATE *pEccState; 110 INFOROM_OMS_STATE *pOmsState; 111 112 // 113 // descriptor cache for all the inforom objects. This is to handle inforom objects in a generic way. 114 // 115 struct INFOROM_OBJECT_CACHE_ENTRY *pObjectCache; 116 }; 117 118 // Generic InfoROM APIs 119 NvlStatus nvswitch_initialize_inforom(nvswitch_device *device); 120 NvlStatus nvswitch_inforom_read_object(nvswitch_device* device, 121 const char objectName[3], const char *pObjectFormat, 122 NvU8 *pPackedObject, void *pObject); 123 NvlStatus nvswitch_inforom_write_object(nvswitch_device* device, 124 const char objectName[3], const char *pObjectFormat, 125 void *pObject, NvU8 *pOldPackedObject); 126 void nvswitch_destroy_inforom(nvswitch_device *device); 127 NvlStatus nvswitch_inforom_add_object(struct inforom *pInforom, 128 INFOROM_OBJECT_HEADER_V1_00 *pHeader); 129 NvlStatus nvswitch_inforom_get_object_version_info(nvswitch_device *device, 130 const char objectName[3], NvU8 *pVersion, NvU8 *pSubVersion); 131 void *nvswitch_add_halinfo_node(NVListPtr head, int type, int size); 132 void *nvswitch_get_halinfo_node(NVListPtr head, int type); 133 void nvswitch_inforom_post_init(nvswitch_device *device); 134 NvlStatus nvswitch_initialize_inforom_objects(nvswitch_device *device); 135 void nvswitch_destroy_inforom_objects(nvswitch_device *device); 136 NvlStatus nvswitch_inforom_load_object(nvswitch_device* device, 137 struct inforom *pInforom, const char objectName[3], 138 const char *pObjectFormat, NvU8 *pPackedObject, void *pObject); 139 void nvswitch_inforom_read_static_data(nvswitch_device *device, 140 struct inforom *pInforom, RM_SOE_SMBPBI_INFOROM_DATA *pData); 141 void nvswitch_inforom_string_copy(inforom_U008 *pSrc, NvU8 *pDst, NvU32 size); 142 143 // InfoROM RO APIs 144 NvlStatus nvswitch_inforom_read_only_objects_load(nvswitch_device *device); 145 146 // InfoROM NVL APIs 147 NvlStatus nvswitch_inforom_nvlink_load(nvswitch_device *device); 148 void nvswitch_inforom_nvlink_unload(nvswitch_device *device); 149 NvlStatus nvswitch_inforom_nvlink_flush(nvswitch_device *device); 150 NvlStatus nvswitch_inforom_nvlink_get_minion_data(nvswitch_device *device, 151 NvU8 linkId, NvU32 *seedData); 152 NvlStatus nvswitch_inforom_nvlink_set_minion_data(nvswitch_device *device, 153 NvU8 linkId, NvU32 *seedData, NvU32 size); 154 NvlStatus nvswitch_inforom_nvlink_log_error_event(nvswitch_device *device, void *error_event); 155 NvlStatus nvswitch_inforom_nvlink_get_max_correctable_error_rate(nvswitch_device *device, 156 NVSWITCH_GET_NVLINK_MAX_CORRECTABLE_ERROR_RATES_PARAMS *params); 157 NvlStatus nvswitch_inforom_nvlink_get_errors(nvswitch_device *device, 158 NVSWITCH_GET_NVLINK_ERROR_COUNTS_PARAMS *params); 159 NvlStatus nvswitch_inforom_nvlink_setL1Threshold(nvswitch_device *device, NvU32 word1, NvU32 word2); 160 NvlStatus nvswitch_inforom_nvlink_getL1Threshold(nvswitch_device *device, NvU32 *word1, NvU32 *word2); 161 162 // InfoROM ECC APIs 163 NvlStatus nvswitch_inforom_ecc_load(nvswitch_device *device); 164 void nvswitch_inforom_ecc_unload(nvswitch_device *device); 165 NvlStatus nvswitch_inforom_ecc_flush(nvswitch_device *device); 166 NvlStatus nvswitch_inforom_ecc_log_err_event(nvswitch_device *device, 167 INFOROM_NVS_ECC_ERROR_EVENT *err_event); 168 NvlStatus nvswitch_inforom_ecc_get_errors(nvswitch_device *device, 169 NVSWITCH_GET_ECC_ERROR_COUNTS_PARAMS *params); 170 171 // InfoROM OMS APIs 172 NvlStatus nvswitch_inforom_oms_load(nvswitch_device *device); 173 void nvswitch_inforom_oms_unload(nvswitch_device *device); 174 NvlStatus nvswitch_inforom_oms_set_device_disable(nvswitch_device *device, 175 NvBool bDisable); 176 NvlStatus nvswitch_inforom_oms_get_device_disable(nvswitch_device *device, 177 NvBool *pBDisabled); 178 179 // InfoROM BBX APIs 180 NvlStatus nvswitch_inforom_bbx_load(nvswitch_device *device); 181 void nvswitch_inforom_bbx_unload(nvswitch_device * device); 182 NvlStatus nvswitch_inforom_bbx_add_sxid(nvswitch_device *device, 183 NvU32 exceptionType, NvU32 data0, 184 NvU32 data1, NvU32 data2); 185 NvlStatus nvswitch_inforom_bbx_get_sxid(nvswitch_device *device, 186 NVSWITCH_GET_SXIDS_PARAMS *params); 187 188 // InfoROM DEM APIs 189 NvlStatus nvswitch_inforom_dem_load(nvswitch_device *device); 190 void nvswitch_inforom_dem_unload(nvswitch_device * device); 191 #endif // _INFOROM_NVSWITCH_H_ 192