refactor: Move all constants in sysman namespace

- Use inline constexpr for declaring global variables
- Avoid using Macros
- Use string_view type instead of std::string

Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma
2024-09-21 22:22:17 +00:00
committed by Compute-Runtime-Automation
parent 7f6b259f0e
commit 82eacc88bf
13 changed files with 91 additions and 85 deletions

View File

@@ -56,7 +56,7 @@ void OsFirmware::getSupportedFwTypes(std::vector<std::string> &supportedFwTypes,
void LinuxFirmwareImp::osGetFwProperties(zes_firmware_properties_t *pProperties) {
if (ZE_RESULT_SUCCESS != getFirmwareVersion(osFwType, pProperties)) {
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, unknown.c_str(), ZES_STRING_PROPERTY_SIZE - 1);
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, unknown.data(), ZES_STRING_PROPERTY_SIZE - 1);
}
pProperties->canControl = true; // Assuming that user has permission to flash the firmware
}

View File

@@ -27,7 +27,7 @@ ze_result_t WddmFirmwareImp::getFirmwareVersion(std::string fwType, zes_firmware
void WddmFirmwareImp::osGetFwProperties(zes_firmware_properties_t *pProperties) {
if (ZE_RESULT_SUCCESS != getFirmwareVersion(osFwType, pProperties)) {
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, unknown.c_str(), ZES_STRING_PROPERTY_SIZE);
strncpy_s(static_cast<char *>(pProperties->version), ZES_STRING_PROPERTY_SIZE, unknown.data(), ZES_STRING_PROPERTY_SIZE);
}
pProperties->canControl = true; // Assuming that user has permission to flash the firmware
}

View File

@@ -119,13 +119,13 @@ void LinuxGlobalOperationsImp::getBrandName(char (&brandName)[ZES_STRING_PROPERT
std::string strVal;
ze_result_t result = pSysfsAccess->read(subsystemVendorFile, strVal);
if (ZE_RESULT_SUCCESS != result) {
std::strncpy(brandName, unknown.c_str(), ZES_STRING_PROPERTY_SIZE);
std::strncpy(brandName, unknown.data(), ZES_STRING_PROPERTY_SIZE);
return;
}
if (strVal.compare(intelPciId) == 0) {
std::strncpy(brandName, vendorIntel.c_str(), ZES_STRING_PROPERTY_SIZE);
std::strncpy(brandName, vendorIntel.data(), ZES_STRING_PROPERTY_SIZE);
} else {
std::strncpy(brandName, unknown.c_str(), ZES_STRING_PROPERTY_SIZE);
std::strncpy(brandName, unknown.data(), ZES_STRING_PROPERTY_SIZE);
}
}
@@ -147,13 +147,13 @@ void LinuxGlobalOperationsImp::getVendorName(char (&vendorName)[ZES_STRING_PROPE
std::string strVal;
ze_result_t result = pSysfsAccess->read(vendorFile, strVal);
if (ZE_RESULT_SUCCESS != result) {
std::strncpy(vendorName, unknown.c_str(), ZES_STRING_PROPERTY_SIZE);
std::strncpy(vendorName, unknown.data(), ZES_STRING_PROPERTY_SIZE);
return;
}
if (strVal.compare(intelPciId) == 0) {
std::strncpy(vendorName, vendorIntel.c_str(), ZES_STRING_PROPERTY_SIZE);
std::strncpy(vendorName, vendorIntel.data(), ZES_STRING_PROPERTY_SIZE);
} else {
std::strncpy(vendorName, unknown.c_str(), ZES_STRING_PROPERTY_SIZE);
std::strncpy(vendorName, unknown.data(), ZES_STRING_PROPERTY_SIZE);
}
}

View File

@@ -118,11 +118,11 @@ ze_result_t GlobalOperationsImp::deviceGetProperties(zes_device_properties_t *pP
pOsGlobalOperations->getBrandName(pProperties->brandName);
memset(pProperties->boardNumber, 0, ZES_STRING_PROPERTY_SIZE);
if (!pOsGlobalOperations->getBoardNumber(pProperties->boardNumber)) {
memcpy_s(pProperties->boardNumber, ZES_STRING_PROPERTY_SIZE, unknown.c_str(), unknown.length() + 1);
memcpy_s(pProperties->boardNumber, ZES_STRING_PROPERTY_SIZE, unknown.data(), unknown.length() + 1);
}
memset(pProperties->serialNumber, 0, ZES_STRING_PROPERTY_SIZE);
if (!pOsGlobalOperations->getSerialNumber(pProperties->serialNumber)) {
memcpy_s(pProperties->serialNumber, ZES_STRING_PROPERTY_SIZE, unknown.c_str(), unknown.length() + 1);
memcpy_s(pProperties->serialNumber, ZES_STRING_PROPERTY_SIZE, unknown.data(), unknown.length() + 1);
}
return ZE_RESULT_SUCCESS;

View File

@@ -81,8 +81,8 @@ void LinuxPciImp::getMaxLinkCaps(double &maxLinkSpeed, int32_t &maxLinkWidth) {
}
uint16_t linkCaps = L0::Sysman::PciUtil::getWordFromConfig(linkCapPos, configMemory.data());
maxLinkSpeed = convertPciGenToLinkSpeed(BITS(linkCaps, 0, 4));
maxLinkWidth = BITS(linkCaps, 4, 6);
maxLinkSpeed = convertPciGenToLinkSpeed(bits(linkCaps, 0, 4));
maxLinkWidth = bits(linkCaps, 4, 6);
return;
}
@@ -189,7 +189,7 @@ uint16_t LinuxPciImp::getLinkCapabilityPos(uint8_t *configMem) {
id = L0::Sysman::PciUtil::getByteFromConfig(pos + PCI_CAP_LIST_ID, configMem);
if (id == PCI_CAP_ID_EXP) {
capRegister = L0::Sysman::PciUtil::getWordFromConfig(pos + PCI_CAP_FLAGS, configMem);
type = BITS(capRegister, 4, 4);
type = bits(capRegister, 4, 4);
// Root Complex Integrated end point and
// Root Complex Event collector will not implement link capabilities
@@ -258,11 +258,11 @@ bool LinuxPciImp::resizableBarEnabled(uint32_t barIndex) {
// Only first Control register(at offset 008h, as shown above), could tell about number of resizable Bars
controlRegister = L0::Sysman::PciUtil::getDwordFromConfig(rebarCapabilityPos + PCI_REBAR_CTRL, configMemory.data());
nBars = BITS(controlRegister, 5, 3); // control register's bits 5,6 and 7 contain number of resizable bars information
nBars = bits(controlRegister, 5, 3); // control register's bits 5,6 and 7 contain number of resizable bars information
for (auto barNumber = 0u; barNumber < nBars; barNumber++) {
uint32_t barId = 0;
controlRegister = L0::Sysman::PciUtil::getDwordFromConfig(rebarCapabilityPos + PCI_REBAR_CTRL, configMemory.data());
barId = BITS(controlRegister, 0, 3); // Control register's bit 0,1,2 tells the index of bar
barId = bits(controlRegister, 0, 3); // Control register's bit 0,1,2 tells the index of bar
if (barId == barIndex) {
isBarResizable = true;
break;
@@ -286,7 +286,7 @@ bool LinuxPciImp::resizableBarEnabled(uint32_t barIndex) {
// Control register's bit 8 to 13 indicates current BAR size in encoded form.
// Example, real value of current size could be 2^currentSize MB
auto currentSize = BITS(controlRegister, 8, 6);
auto currentSize = bits(controlRegister, 8, 6);
// If current size is equal to larget possible BAR size, it indicates resizable BAR is enabled.
return (currentSize == largestPossibleBarSize);