1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
/*
* Copyright (C) 2022-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/shared/firmware_util/sysman_firmware_util_imp.h"
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/debug_helpers.h"
#include <map>
namespace L0 {
namespace Sysman {
static const std::map<std::string, csc_late_binding_type> lateBindingTypeToEnumMap = {
{"FanTable", CSC_LATE_BINDING_TYPE_FAN_TABLE},
{"VRConfig", CSC_LATE_BINDING_TYPE_VR_CONFIG},
};
const std::string fwDeviceInitByDevice = "igsc_device_init_by_device_info";
const std::string fwDeviceGetDeviceInfo = "igsc_device_get_device_info";
const std::string fwDeviceFwVersion = "igsc_device_fw_version";
const std::string fwDeviceFwDataVersion = "igsc_device_fwdata_version";
const std::string fwDeviceIteratorCreate = "igsc_device_iterator_create";
const std::string fwDeviceIteratorNext = "igsc_device_iterator_next";
const std::string fwDeviceIteratorDestroy = "igsc_device_iterator_destroy";
const std::string fwDeviceFwUpdate = "igsc_device_fw_update";
const std::string fwDeviceFwDataUpdate = "igsc_device_fwdata_update";
const std::string fwImageOpromInit = "igsc_image_oprom_init";
const std::string fwImageOpromType = "igsc_image_oprom_type";
const std::string fwDeviceOpromUpdate = "igsc_device_oprom_update";
const std::string fwDeviceOpromVersion = "igsc_device_oprom_version";
const std::string fwDevicePscVersion = "igsc_device_psc_version";
const std::string fwDeviceClose = "igsc_device_close";
const std::string fwDeviceUpdateLateBindingConfig = "igsc_device_update_late_binding_config";
pIgscDeviceInitByDevice deviceInitByDevice;
pIgscDeviceGetDeviceInfo deviceGetDeviceInfo;
pIgscDeviceFwVersion deviceGetFwVersion;
pIgscDeviceFwDataVersion deviceGetFwDataVersion;
pIgscDeviceIteratorCreate deviceIteratorCreate;
pIgscDeviceIteratorNext deviceItreatorNext;
pIgscDeviceIteratorDestroy deviceItreatorDestroy;
pIgscDeviceFwUpdate deviceFwUpdate;
pIgscDeviceFwDataUpdate deviceFwDataUpdate;
pIgscImageOpromInit imageOpromInit;
pIgscImageOpromType imageOpromType;
pIgscDeviceOpromUpdate deviceOpromUpdate;
pIgscDeviceOpromVersion deviceOpromVersion;
pIgscDevicePscVersion deviceGetPscVersion;
pIgscDeviceClose deviceClose;
pIgscDeviceUpdateLateBindingConfig deviceUpdateLateBindingConfig;
bool FirmwareUtilImp::loadEntryPoints() {
bool ok = getSymbolAddr(fwDeviceInitByDevice, deviceInitByDevice);
ok = ok && getSymbolAddr(fwDeviceGetDeviceInfo, deviceGetDeviceInfo);
ok = ok && getSymbolAddr(fwDeviceFwVersion, deviceGetFwVersion);
ok = ok && getSymbolAddr(fwDeviceFwDataVersion, deviceGetFwDataVersion);
ok = ok && getSymbolAddr(fwDeviceIteratorCreate, deviceIteratorCreate);
ok = ok && getSymbolAddr(fwDeviceIteratorNext, deviceItreatorNext);
ok = ok && getSymbolAddr(fwDeviceIteratorDestroy, deviceItreatorDestroy);
ok = ok && getSymbolAddr(fwDeviceFwUpdate, deviceFwUpdate);
ok = ok && getSymbolAddr(fwDeviceFwDataUpdate, deviceFwDataUpdate);
ok = ok && getSymbolAddr(fwImageOpromInit, imageOpromInit);
ok = ok && getSymbolAddr(fwImageOpromType, imageOpromType);
ok = ok && getSymbolAddr(fwDeviceOpromUpdate, deviceOpromUpdate);
ok = ok && getSymbolAddr(fwDeviceOpromVersion, deviceOpromVersion);
ok = ok && getSymbolAddr(fwDevicePscVersion, deviceGetPscVersion);
ok = ok && getSymbolAddr(fwDeviceClose, deviceClose);
ok = ok && getSymbolAddr(fwDeviceUpdateLateBindingConfig, deviceUpdateLateBindingConfig);
ok = ok && loadEntryPointsExt();
return ok;
}
void firmwareFlashProgressFunc(uint32_t done, uint32_t total, void *ctx) {
if (ctx != nullptr) {
uint32_t percent = (done * 100) / total;
FirmwareUtilImp *pFirmwareUtilImp = static_cast<FirmwareUtilImp *>(ctx);
pFirmwareUtilImp->updateFirmwareFlashProgress(percent);
PRINT_DEBUG_STRING(NEO::debugManager.flags.PrintDebugMessages.get(), stdout, "Progress: %d/%d:%d/%\n", done, total, percent);
}
}
void FirmwareUtilImp::updateFirmwareFlashProgress(uint32_t percent) {
const std::lock_guard<std::mutex> lock(flashProgress.fwProgressLock);
flashProgress.completionPercent = percent;
}
ze_result_t FirmwareUtilImp::getFlashFirmwareProgress(uint32_t *pCompletionPercent) {
const std::lock_guard<std::mutex> lock(flashProgress.fwProgressLock);
*pCompletionPercent = flashProgress.completionPercent;
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::getFirstDevice(IgscDeviceInfo *info) {
igsc_device_iterator *iter;
int ret = deviceIteratorCreate(&iter);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
info->name[0] = '\0';
do {
ret = deviceItreatorNext(iter, info);
if (ret != IGSC_SUCCESS) {
deviceItreatorDestroy(iter);
return ZE_RESULT_ERROR_UNINITIALIZED;
}
if (info->domain == domain &&
info->bus == bus &&
info->dev == device &&
info->func == function) {
fwDevicePath.assign(info->name);
break;
}
} while (1);
deviceItreatorDestroy(iter);
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::fwDeviceInit() {
int ret;
IgscDeviceInfo info;
ze_result_t result = getFirstDevice(&info);
if (result != ZE_RESULT_SUCCESS) {
return result;
}
ret = deviceInitByDevice(&fwDeviceHandle, fwDevicePath.c_str());
if (ret != 0) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::fwGetVersion(std::string &fwVersion) {
const std::lock_guard<std::mutex> lock(this->fwLock);
igsc_fw_version deviceFwVersion;
memset(&deviceFwVersion, 0, sizeof(deviceFwVersion));
int ret = deviceGetFwVersion(&fwDeviceHandle, &deviceFwVersion);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
fwVersion.append(deviceFwVersion.project);
fwVersion.append("_");
fwVersion.append(std::to_string(deviceFwVersion.hotfix));
fwVersion.append(".");
fwVersion.append(std::to_string(deviceFwVersion.build));
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::fwDataGetVersion(std::string &fwDataVersion) {
const std::lock_guard<std::mutex> lock(this->fwLock);
igsc_fwdata_version deviceFwDataVersion;
memset(&deviceFwDataVersion, 0, sizeof(deviceFwDataVersion));
int ret = deviceGetFwDataVersion(&fwDeviceHandle, &deviceFwDataVersion);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
fwDataVersion.append("Major : ");
fwDataVersion.append(std::to_string(deviceFwDataVersion.major_version));
fwDataVersion.append(", OEM Manufacturing Data : ");
fwDataVersion.append(std::to_string(deviceFwDataVersion.oem_manuf_data_version));
fwDataVersion.append(", Major VCN : ");
fwDataVersion.append(std::to_string(deviceFwDataVersion.major_vcn));
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::opromGetVersion(std::string &fwVersion) {
const std::lock_guard<std::mutex> lock(this->fwLock);
igsc_oprom_version opromVersion;
memset(&opromVersion, 0, sizeof(opromVersion));
int ret = deviceOpromVersion(&fwDeviceHandle, IGSC_OPROM_CODE, &opromVersion);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
fwVersion.append("OPROM CODE VERSION:");
for (int i = 0; i < IGSC_OPROM_VER_SIZE; i++) {
fwVersion.append(std::to_string(static_cast<unsigned int>(opromVersion.version[i])));
}
fwVersion.append("_");
memset(&opromVersion, 0, sizeof(opromVersion));
ret = deviceOpromVersion(&fwDeviceHandle, IGSC_OPROM_DATA, &opromVersion);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
fwVersion.append("OPROM DATA VERSION:");
for (int i = 0; i < IGSC_OPROM_VER_SIZE; i++) {
fwVersion.append(std::to_string(static_cast<unsigned int>(opromVersion.version[i])));
}
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::fwFlashGSC(void *pImage, uint32_t size) {
const std::lock_guard<std::mutex> lock(this->fwLock);
int ret = deviceFwUpdate(&fwDeviceHandle, static_cast<const uint8_t *>(pImage), size, firmwareFlashProgressFunc, this);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::fwFlashGfxData(void *pImage, uint32_t size) {
const std::lock_guard<std::mutex> lock(this->fwLock);
int ret = deviceFwDataUpdate(&fwDeviceHandle, static_cast<const uint8_t *>(pImage), size, firmwareFlashProgressFunc, this);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::fwFlashOprom(void *pImage, uint32_t size) {
const std::lock_guard<std::mutex> lock(this->fwLock);
struct igsc_oprom_image *opromImg = nullptr;
uint32_t opromImgType = 0;
int retData = 0, retCode = 0;
int ret = imageOpromInit(&opromImg, static_cast<const uint8_t *>(pImage), size);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
ret = imageOpromType(opromImg, &opromImgType);
if (ret != IGSC_SUCCESS) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
if (opromImgType & IGSC_OPROM_DATA) {
retData = deviceOpromUpdate(&fwDeviceHandle, IGSC_OPROM_DATA, opromImg, firmwareFlashProgressFunc, this);
}
if (opromImgType & IGSC_OPROM_CODE) {
retCode = deviceOpromUpdate(&fwDeviceHandle, IGSC_OPROM_CODE, opromImg, firmwareFlashProgressFunc, this);
}
if ((retData != IGSC_SUCCESS) && (retCode != IGSC_SUCCESS)) {
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return ZE_RESULT_SUCCESS;
}
ze_result_t FirmwareUtilImp::fwFlashLateBinding(void *pImage, uint32_t size, std::string fwType) {
const std::lock_guard<std::mutex> lock(this->fwLock);
uint32_t lateBindingFlashStatus = 0;
int ret = deviceUpdateLateBindingConfig(&fwDeviceHandle, lateBindingTypeToEnumMap.at(fwType), CSC_LATE_BINDING_FLAGS_IS_PERSISTENT_MASK, static_cast<uint8_t *>(pImage), static_cast<size_t>(size), &lateBindingFlashStatus);
if (ret != IGSC_SUCCESS || lateBindingFlashStatus != CSC_LATE_BINDING_STATUS_SUCCESS) {
if (ret == IGSC_ERROR_BUSY) {
return ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE;
}
return ZE_RESULT_ERROR_UNINITIALIZED;
}
return ZE_RESULT_SUCCESS;
}
FirmwareUtilImp::FirmwareUtilImp(uint16_t domain, uint8_t bus, uint8_t device, uint8_t function) : domain(domain), bus(bus), device(device), function(function) {
}
FirmwareUtilImp::~FirmwareUtilImp() {
const std::lock_guard<std::mutex> lock(this->fwLock);
if (nullptr != libraryHandle) {
deviceClose(&fwDeviceHandle);
delete libraryHandle;
libraryHandle = nullptr;
}
};
FirmwareUtil *FirmwareUtil::create(uint16_t domain, uint8_t bus, uint8_t device, uint8_t function) {
FirmwareUtilImp *pFwUtilImp = new FirmwareUtilImp(domain, bus, device, function);
UNRECOVERABLE_IF(nullptr == pFwUtilImp);
NEO::OsLibraryCreateProperties properties(FirmwareUtilImp::fwUtilLibraryName);
properties.customLoadFlags = &FirmwareUtilImp::fwUtilLoadFlags;
pFwUtilImp->libraryHandle = NEO::OsLibrary::loadFunc(properties);
if (pFwUtilImp->libraryHandle == nullptr || pFwUtilImp->loadEntryPoints() == false || pFwUtilImp->fwDeviceInit() != ZE_RESULT_SUCCESS) {
if (nullptr != pFwUtilImp->libraryHandle) {
delete pFwUtilImp->libraryHandle;
pFwUtilImp->libraryHandle = nullptr;
}
delete pFwUtilImp;
return nullptr;
}
return static_cast<FirmwareUtil *>(pFwUtilImp);
}
} // namespace Sysman
} // namespace L0
|