From c54152bbbc367eaeaf7a7b3096ef672b40c5f6e9 Mon Sep 17 00:00:00 2001 From: Jitendra Sharma Date: Fri, 30 Jul 2021 13:33:54 +0000 Subject: [PATCH] Sysman: Add support to check whether resizable PCI BAR is enabled Related-To: LOCI-2414 Signed-off-by: Jitendra Sharma --- .../source/sysman/pci/linux/os_pci_imp.cpp | 82 +++++++++++++-- .../source/sysman/pci/linux/os_pci_imp.h | 3 +- level_zero/tools/source/sysman/pci/os_pci.h | 2 +- .../tools/source/sysman/pci/pci_imp.cpp | 19 ++-- level_zero/tools/source/sysman/pci/pci_imp.h | 1 - .../source/sysman/pci/windows/os_pci_imp.cpp | 2 +- .../source/sysman/pci/windows/os_pci_imp.h | 2 +- level_zero/tools/source/sysman/sysman_const.h | 3 +- .../test/black_box_tests/zello_sysman.cpp | 15 +-- .../sources/sysman/pci/linux/test_zes_pci.cpp | 99 ++++++++----------- .../sysman/pci/windows/test_zes_pci.cpp | 57 +++++------ 11 files changed, 168 insertions(+), 117 deletions(-) diff --git a/level_zero/tools/source/sysman/pci/linux/os_pci_imp.cpp b/level_zero/tools/source/sysman/pci/linux/os_pci_imp.cpp index 47929df0af..813c5aaec6 100644 --- a/level_zero/tools/source/sysman/pci/linux/os_pci_imp.cpp +++ b/level_zero/tools/source/sysman/pci/linux/os_pci_imp.cpp @@ -152,13 +152,12 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector 0) { if (PCI_EXT_CAP_ID(header) == PCI_EXT_CAP_ID_REBAR) { - return true; + return pos; } pos = PCI_EXT_CAP_NEXT(header); if (pos < PCI_CFG_SPACE_SIZE) { - return false; + return 0; } header = getDwordFromConfig(pos); } - return false; + return 0; } -bool LinuxPciImp::resizableBarEnabled() { - return false; +// Parse PCIe configuration space to see if resizable Bar is supported +bool LinuxPciImp::resizableBarSupported() { + return (getRebarCapabilityPos() > 0); +} + +bool LinuxPciImp::resizableBarEnabled(uint32_t barIndex) { + bool isBarResizable = false; + uint32_t capabilityRegister = 0, controlRegister = 0; + uint32_t nBars = 1; + auto rebarCapabilityPos = getRebarCapabilityPos(); + + // If resizable Bar is not supported then return false. + if (!rebarCapabilityPos) { + return false; + } + + // As per PCI spec, resizable BAR's capability structure's 52 byte length could be represented as: + // -------------------------------------------------------------- + // | byte offset | Description of register | + // -------------------------------------------------------------| + // | +000h | PCI Express Extended Capability Header | + // -------------------------------------------------------------| + // | +004h | Resizable BAR Capability Register (0) | + // -------------------------------------------------------------| + // | +008h | Resizable BAR Control Register (0) | + // -------------------------------------------------------------| + // | +00Ch | Resizable BAR Capability Register (1) | + // -------------------------------------------------------------| + // | +010h | Resizable BAR Control Register (1) | + // -------------------------------------------------------------| + // | +014h | --- | + // -------------------------------------------------------------| + + // Only first Control register(at offset 008h, as shown above), could tell about number of resizable Bars + controlRegister = getDwordFromConfig(rebarCapabilityPos + PCI_REBAR_CTRL); + 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 = getDwordFromConfig(rebarCapabilityPos + PCI_REBAR_CTRL); + barId = BITS(controlRegister, 0, 3); // Control register's bit 0,1,2 tells the index of bar + if (barId == barIndex) { + isBarResizable = true; + break; + } + rebarCapabilityPos += 8; + } + + if (isBarResizable == false) { + return false; + } + + capabilityRegister = getDwordFromConfig(rebarCapabilityPos + PCI_REBAR_CAP); + // Capability register's bit 4 to 31 indicates supported Bar sizes. + // In possibleBarSizes, position of each set bit indicates supported bar size. Example, if set bit + // position of possibleBarSizes is from 0 to n, then this indicates BAR size from 2^0 MB to 2^n MB + auto possibleBarSizes = (capabilityRegister & PCI_REBAR_CAP_SIZES) >> 4; // First 4 bits are reserved + uint32_t largestPossibleBarSize = 0; + while (possibleBarSizes >>= 1) { // most significant set bit position of possibleBarSizes would tell larget possible bar size + largestPossibleBarSize++; + } + + // 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); + + // If current size is equal to larget possible BAR size, it indicates resizable BAR is enabled. + return (currentSize == largestPossibleBarSize); } ze_result_t LinuxPciImp::getState(zes_pci_state_t *state) { diff --git a/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h b/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h index cd15e581ef..d07cbc7c48 100644 --- a/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h +++ b/level_zero/tools/source/sysman/pci/linux/os_pci_imp.h @@ -25,7 +25,7 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass { ze_result_t getState(zes_pci_state_t *state) override; ze_result_t getProperties(zes_pci_properties_t *properties) override; bool resizableBarSupported() override; - bool resizableBarEnabled() override; + bool resizableBarEnabled(uint32_t barIndex) override; ze_result_t initializeBarProperties(std::vector &pBarProperties) override; LinuxPciImp() = default; LinuxPciImp(OsSysman *pOsSysman); @@ -51,6 +51,7 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass { return configMemory[pos] | (configMemory[pos + 1] << 8) | (configMemory[pos + 2] << 16) | (configMemory[pos + 3] << 24); } + uint32_t getRebarCapabilityPos(); }; } // namespace L0 diff --git a/level_zero/tools/source/sysman/pci/os_pci.h b/level_zero/tools/source/sysman/pci/os_pci.h index 20b3fecc4e..2da1c8c08c 100644 --- a/level_zero/tools/source/sysman/pci/os_pci.h +++ b/level_zero/tools/source/sysman/pci/os_pci.h @@ -25,7 +25,7 @@ class OsPci { virtual ze_result_t getState(zes_pci_state_t *state) = 0; virtual ze_result_t getProperties(zes_pci_properties_t *properties) = 0; virtual bool resizableBarSupported() = 0; - virtual bool resizableBarEnabled() = 0; + virtual bool resizableBarEnabled(uint32_t barIndex) = 0; virtual ze_result_t initializeBarProperties(std::vector &pBarProperties) = 0; static OsPci *create(OsSysman *pOsSysman); virtual ~OsPci() = default; diff --git a/level_zero/tools/source/sysman/pci/pci_imp.cpp b/level_zero/tools/source/sysman/pci/pci_imp.cpp index d38f3e4af8..1ae9224418 100644 --- a/level_zero/tools/source/sysman/pci/pci_imp.cpp +++ b/level_zero/tools/source/sysman/pci/pci_imp.cpp @@ -99,15 +99,17 @@ ze_result_t PciImp::pciGetInitializedBars(uint32_t *pCount, zes_pci_bar_properti pProperties[i].size = pciBarProperties[i]->size; pProperties[i].type = pciBarProperties[i]->type; - if (pProperties[i].pNext != nullptr && pProperties[i].stype == zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2) { + if (pProperties[i].pNext != nullptr) { zes_pci_bar_properties_1_2_t *pBarPropsExt = static_cast(pProperties[i].pNext); - // base, index, size and type are the same as the non 1.2 struct. - pBarPropsExt->base = pciBarProperties[i]->base; - pBarPropsExt->index = pciBarProperties[i]->index; - pBarPropsExt->size = pciBarProperties[i]->size; - pBarPropsExt->type = pciBarProperties[i]->type; - pBarPropsExt->resizableBarEnabled = static_cast(resizableBarEnabled); - pBarPropsExt->resizableBarSupported = static_cast(resizableBarSupported); + if (pBarPropsExt->stype == zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2) { + // base, index, size and type are the same as the non 1.2 struct. + pBarPropsExt->base = pciBarProperties[i]->base; + pBarPropsExt->index = pciBarProperties[i]->index; + pBarPropsExt->size = pciBarProperties[i]->size; + pBarPropsExt->type = pciBarProperties[i]->type; + pBarPropsExt->resizableBarSupported = static_cast(resizableBarSupported); + pBarPropsExt->resizableBarEnabled = static_cast(pOsPci->resizableBarEnabled(pBarPropsExt->index)); + } } } } @@ -120,7 +122,6 @@ ze_result_t PciImp::pciGetState(zes_pci_state_t *pState) { void PciImp::pciGetStaticFields() { pOsPci->getProperties(&pciProperties); - resizableBarEnabled = pOsPci->resizableBarEnabled(); resizableBarSupported = pOsPci->resizableBarSupported(); std::string bdf; pOsPci->getPciBdf(bdf); diff --git a/level_zero/tools/source/sysman/pci/pci_imp.h b/level_zero/tools/source/sysman/pci/pci_imp.h index 0ad42d5382..dd531cbd30 100644 --- a/level_zero/tools/source/sysman/pci/pci_imp.h +++ b/level_zero/tools/source/sysman/pci/pci_imp.h @@ -35,7 +35,6 @@ class PciImp : public Pci, NEO::NonCopyableOrMovableClass { private: OsSysman *pOsSysman = nullptr; bool resizableBarSupported = false; - bool resizableBarEnabled = false; zes_pci_properties_t pciProperties = {}; std::vector pciBarProperties = {}; }; diff --git a/level_zero/tools/source/sysman/pci/windows/os_pci_imp.cpp b/level_zero/tools/source/sysman/pci/windows/os_pci_imp.cpp index cc3b2891f9..b6ea82d5e7 100644 --- a/level_zero/tools/source/sysman/pci/windows/os_pci_imp.cpp +++ b/level_zero/tools/source/sysman/pci/windows/os_pci_imp.cpp @@ -190,7 +190,7 @@ bool WddmPciImp::resizableBarSupported() { return supported; } -bool WddmPciImp::resizableBarEnabled() { +bool WddmPciImp::resizableBarEnabled(uint32_t barIndex) { uint32_t valueSmall = 0; bool enabled = false; KmdSysman::RequestProperty request; diff --git a/level_zero/tools/source/sysman/pci/windows/os_pci_imp.h b/level_zero/tools/source/sysman/pci/windows/os_pci_imp.h index 75f6de2708..6aef8207b7 100644 --- a/level_zero/tools/source/sysman/pci/windows/os_pci_imp.h +++ b/level_zero/tools/source/sysman/pci/windows/os_pci_imp.h @@ -21,7 +21,7 @@ class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass { ze_result_t getState(zes_pci_state_t *state) override; ze_result_t getProperties(zes_pci_properties_t *properties) override; bool resizableBarSupported() override; - bool resizableBarEnabled() override; + bool resizableBarEnabled(uint32_t barIndex) override; ze_result_t initializeBarProperties(std::vector &pBarProperties) override; WddmPciImp(OsSysman *pOsSysman); WddmPciImp() = default; diff --git a/level_zero/tools/source/sysman/sysman_const.h b/level_zero/tools/source/sysman/sysman_const.h index 6917813b90..7b863c96df 100644 --- a/level_zero/tools/source/sysman/sysman_const.h +++ b/level_zero/tools/source/sysman/sysman_const.h @@ -59,4 +59,5 @@ constexpr uint32_t microFacor = milliFactor * milliFactor; constexpr uint64_t gigaUnitTransferToUnitTransfer = 1000 * 1000 * 1000; constexpr int32_t memoryBusWidth = 128; // bus width in bits -constexpr int32_t numMemoryChannels = 8; \ No newline at end of file +constexpr int32_t numMemoryChannels = 8; +#define BITS(x, at, width) (((x) >> (at)) & ((1 << (width)) - 1)) \ No newline at end of file diff --git a/level_zero/tools/test/black_box_tests/zello_sysman.cpp b/level_zero/tools/test/black_box_tests/zello_sysman.cpp index 0f26478ca9..2efef7cde6 100644 --- a/level_zero/tools/test/black_box_tests/zello_sysman.cpp +++ b/level_zero/tools/test/black_box_tests/zello_sysman.cpp @@ -301,13 +301,16 @@ void testSysmanPci(ze_device_handle_t &device) { if (verbose) { std::cout << "Bar count = " << count << std::endl; } + std::vector pciBarProps(count); - zes_pci_bar_properties_1_2_t props1_2 = {}; - memset(&props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t)); + std::vector pciBarExtProps(count); for (uint32_t i = 0; i < count; i++) { - pciBarProps[i].pNext = static_cast(&props1_2); - pciBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + pciBarExtProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + pciBarExtProps[i].pNext = nullptr; + pciBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES; + pciBarProps[i].pNext = static_cast(&pciBarExtProps[i]); } + VALIDATECALL(zesDevicePciGetBars(device, &count, pciBarProps.data())); if (verbose) { for (uint32_t i = 0; i < count; i++) { @@ -315,8 +318,8 @@ void testSysmanPci(ze_device_handle_t &device) { std::cout << "pciBarProps.index = " << std::hex << pciBarProps[i].index << std::endl; std::cout << "pciBarProps.base = " << std::hex << pciBarProps[i].base << std::endl; std::cout << "pciBarProps.size = " << std::hex << pciBarProps[i].size << std::endl; - std::cout << "pci_bar_properties_1_2_t.resizableBarSupported = " << static_cast(props1_2.resizableBarSupported) << std::endl; - std::cout << "pci_bar_properties_1_2_t.resizableBarEnabled = " << static_cast(props1_2.resizableBarEnabled) << std::endl; + std::cout << "pci_bar_properties_1_2_t.resizableBarSupported = " << static_cast(pciBarExtProps[i].resizableBarSupported) << std::endl; + std::cout << "pci_bar_properties_1_2_t.resizableBarEnabled = " << static_cast(pciBarExtProps[i].resizableBarEnabled) << std::endl; } } } diff --git a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp index 708277d91c..dfa8c36c6e 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp @@ -62,6 +62,10 @@ ssize_t preadMock(int fd, void *buf, size_t count, off_t offset) { mockBuf[0x420] = 0x15; mockBuf[0x422] = 0x01; mockBuf[0x423] = 0x22; + mockBuf[0x425] = 0xf0; + mockBuf[0x426] = 0x3f; + mockBuf[0x428] = 0x22; + mockBuf[0x429] = 0x11; mockBuf[0x220] = 0x24; mockBuf[0x222] = 0x01; mockBuf[0x223] = 0x32; @@ -318,6 +322,8 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigOpenF pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); pPciImp->pciGetStaticFields(); EXPECT_FALSE(pPciImp->pOsPci->resizableBarSupported()); + uint32_t barIndex = 2u; + EXPECT_FALSE(pPciImp->pOsPci->resizableBarEnabled(barIndex)); delete pLinuxPciImpTemp; pPciImp->pOsPci = pOsPciOriginal; } @@ -333,6 +339,8 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenInitializingPciAndPciConfigReadF pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); pPciImp->pciGetStaticFields(); EXPECT_FALSE(pPciImp->pOsPci->resizableBarSupported()); + uint32_t barIndex = 2u; + EXPECT_FALSE(pPciImp->pOsPci->resizableBarEnabled(barIndex)); delete pLinuxPciImpTemp; pPciImp->pOsPci = pOsPciOriginal; } @@ -348,6 +356,8 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndHeaderF pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); pPciImp->pciGetStaticFields(); EXPECT_FALSE(pPciImp->pOsPci->resizableBarSupported()); + uint32_t barIndex = 2u; + EXPECT_FALSE(pPciImp->pOsPci->resizableBarEnabled(barIndex)); delete pLinuxPciImpTemp; pPciImp->pOsPci = pOsPciOriginal; } @@ -363,6 +373,8 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndCapabil pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); pPciImp->pciGetStaticFields(); EXPECT_FALSE(pPciImp->pOsPci->resizableBarSupported()); + uint32_t barIndex = 2u; + EXPECT_FALSE(pPciImp->pOsPci->resizableBarEnabled(barIndex)); delete pLinuxPciImpTemp; pPciImp->pOsPci = pOsPciOriginal; } @@ -378,6 +390,8 @@ TEST_F(ZesPciFixture, GivenSysmanHandleWhenCheckForResizableBarSupportAndIfRebar pPciImp->pOsPci = static_cast(pLinuxPciImpTemp); pPciImp->pciGetStaticFields(); EXPECT_FALSE(pPciImp->pOsPci->resizableBarSupported()); + uint32_t barIndex = 2u; + EXPECT_FALSE(pPciImp->pOsPci->resizableBarEnabled(barIndex)); delete pLinuxPciImpTemp; pPciImp->pOsPci = pOsPciOriginal; } @@ -387,32 +401,33 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr)); EXPECT_NE(count, 0u); - zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count]; - zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t; - memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t)); - + std::vector pBarProps(count); + std::vector props1_2(count); for (uint32_t i = 0; i < count; i++) { - pBarProps[i].pNext = static_cast(props1_2); - pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + props1_2[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + props1_2[i].pNext = nullptr; + pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES; + pBarProps[i].pNext = static_cast(&props1_2[i]); } - EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps.data())); for (uint32_t i = 0; i < count; i++) { - EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2); + EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES); EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM); EXPECT_NE(pBarProps[i].base, 0u); EXPECT_NE(pBarProps[i].size, 0u); + EXPECT_EQ(props1_2[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2); + EXPECT_EQ(props1_2[i].resizableBarSupported, true); + if (props1_2[i].index == 2) { + EXPECT_EQ(props1_2[i].resizableBarEnabled, true); + } else { + EXPECT_EQ(props1_2[i].resizableBarEnabled, false); + } + EXPECT_LE(props1_2[i].type, ZES_PCI_BAR_TYPE_MEM); + EXPECT_NE(props1_2[i].base, 0u); + EXPECT_NE(props1_2[i].size, 0u); } - - EXPECT_EQ(props1_2->resizableBarSupported, true); - EXPECT_EQ(props1_2->resizableBarEnabled, false); - EXPECT_LE(props1_2->type, ZES_PCI_BAR_TYPE_MEM); - EXPECT_NE(props1_2->base, 0u); - EXPECT_NE(props1_2->size, 0u); - - delete[] pBarProps; - delete props1_2; } TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWrongType) { @@ -420,31 +435,24 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr)); EXPECT_NE(count, 0u); - zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count]; - zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t; - memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t)); - + std::vector pBarProps(count); + std::vector props1_2(count); for (uint32_t i = 0; i < count; i++) { - pBarProps[i].pNext = static_cast(props1_2); - pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE; + props1_2[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE; + props1_2[i].pNext = nullptr; + pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES; + pBarProps[i].pNext = static_cast(&props1_2[i]); } - EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps.data())); for (uint32_t i = 0; i < count; i++) { + EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES); EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM); EXPECT_NE(pBarProps[i].base, 0u); EXPECT_NE(pBarProps[i].size, 0u); + EXPECT_EQ(props1_2[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_STATE); } - - EXPECT_EQ(props1_2->resizableBarSupported, false); - EXPECT_EQ(props1_2->resizableBarEnabled, false); - EXPECT_EQ(props1_2->type, ZES_PCI_BAR_TYPE_MMIO); - EXPECT_EQ(props1_2->base, 0u); - EXPECT_EQ(props1_2->size, 0u); - - delete[] pBarProps; - delete props1_2; } TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithNullPtr) { @@ -456,30 +464,7 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe for (uint32_t i = 0; i < count; i++) { pBarProps[i].pNext = nullptr; - pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; - } - - EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); - - for (uint32_t i = 0; i < count; i++) { - EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM); - EXPECT_NE(pBarProps[i].base, 0u); - EXPECT_NE(pBarProps[i].size, 0u); - } - - delete[] pBarProps; -} - -TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyApiCallSucceedsWith1_2ExtensionWithWrongtypeNullPtr) { - uint32_t count = 0; - EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr)); - EXPECT_NE(count, 0u); - - zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count]; - - for (uint32_t i = 0; i < count; i++) { - pBarProps[i].pNext = nullptr; - pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE; + pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES; } EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/test_zes_pci.cpp b/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/test_zes_pci.cpp index d38176c6b5..4d62cd8cf0 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/test_zes_pci.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/test_zes_pci.cpp @@ -117,27 +117,26 @@ TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetB EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr)); EXPECT_NE(count, 0u); - zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count]; - zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t; - memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t)); - + std::vector pBarProps(count); + std::vector props1_2(count); for (uint32_t i = 0; i < count; i++) { - pBarProps[i].pNext = static_cast(props1_2); - pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + props1_2[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + props1_2[i].pNext = nullptr; + pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES; + pBarProps[i].pNext = static_cast(&props1_2[i]); } - EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps.data())); - EXPECT_EQ(props1_2->resizableBarSupported, true); - EXPECT_EQ(props1_2->resizableBarEnabled, true); - - delete[] pBarProps; - pBarProps = nullptr; - delete props1_2; - props1_2 = nullptr; + for (uint32_t i = 0; i < count; i++) { + EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES); + EXPECT_EQ(props1_2[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2); + EXPECT_EQ(props1_2[i].resizableBarSupported, true); + EXPECT_EQ(props1_2[i].resizableBarEnabled, true); + } } -TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithNullPtr) { +TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingPciGetBarsThenVerifyAPICallSucceedsWith1_2ExtensionWithNullPtr) { uint32_t count = 0; EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr)); EXPECT_NE(count, 0u); @@ -146,7 +145,7 @@ TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetB for (uint32_t i = 0; i < count; i++) { pBarProps[i].pNext = nullptr; - pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES; } EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); @@ -160,24 +159,22 @@ TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetB EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr)); EXPECT_NE(count, 0u); - zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count]; - zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t; - memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t)); - + std::vector pBarProps(count); + std::vector props1_2(count); for (uint32_t i = 0; i < count; i++) { - pBarProps[i].pNext = static_cast(props1_2); - pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE; + props1_2[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE; + props1_2[i].pNext = nullptr; + pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES; + pBarProps[i].pNext = static_cast(&props1_2[i]); } - EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps.data())); - EXPECT_EQ(props1_2->resizableBarSupported, false); - EXPECT_EQ(props1_2->resizableBarEnabled, false); - - delete[] pBarProps; - pBarProps = nullptr; - delete props1_2; - props1_2 = nullptr; + for (uint32_t i = 0; i < count; i++) { + EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES); + EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM); + EXPECT_EQ(props1_2[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_STATE); + } } TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStatsWithLocalMemoryThenVerifyzetSysmanPciGetBarsCallSucceeds) {