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 14556d5581..0f0163418e 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 @@ -125,6 +125,7 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vectorindex = i; pBarProp->base = baseAddr; pBarProp->size = barSize; @@ -149,6 +150,14 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector &pBarProperties) override; LinuxPciImp() = default; LinuxPciImp(OsSysman *pOsSysman); diff --git a/level_zero/tools/source/sysman/pci/os_pci.h b/level_zero/tools/source/sysman/pci/os_pci.h index 6682a75f4f..20b3fecc4e 100644 --- a/level_zero/tools/source/sysman/pci/os_pci.h +++ b/level_zero/tools/source/sysman/pci/os_pci.h @@ -24,6 +24,8 @@ class OsPci { virtual ze_result_t getMaxLinkWidth(int32_t &maxLinkWidth) = 0; 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 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 8ba18b40fc..4cfcc4c40a 100644 --- a/level_zero/tools/source/sysman/pci/pci_imp.cpp +++ b/level_zero/tools/source/sysman/pci/pci_imp.cpp @@ -94,7 +94,21 @@ ze_result_t PciImp::pciGetInitializedBars(uint32_t *pCount, zes_pci_bar_properti } if (nullptr != pProperties) { for (uint32_t i = 0; i < numToCopy; i++) { - pProperties[i] = *pciBarProperties[i]; + pProperties[i].base = pciBarProperties[i]->base; + pProperties[i].index = pciBarProperties[i]->index; + 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) { + 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 = resizableBarEnabled; + pBarPropsExt->resizableBarSupported = resizableBarSupported; + } } } return ZE_RESULT_SUCCESS; @@ -109,6 +123,8 @@ void PciImp::init() { } UNRECOVERABLE_IF(nullptr == pOsPci); pOsPci->getProperties(&pciProperties); + resizableBarEnabled = pOsPci->resizableBarEnabled(); + resizableBarSupported = pOsPci->resizableBarSupported(); std::string bdf; pOsPci->getPciBdf(bdf); if (bdf.empty()) { diff --git a/level_zero/tools/source/sysman/pci/pci_imp.h b/level_zero/tools/source/sysman/pci/pci_imp.h index 8f180c56f2..d98dff7ee4 100644 --- a/level_zero/tools/source/sysman/pci/pci_imp.h +++ b/level_zero/tools/source/sysman/pci/pci_imp.h @@ -33,6 +33,8 @@ 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 ab68ced3e5..cc3b2891f9 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 @@ -171,8 +171,49 @@ ze_result_t WddmPciImp::getState(zes_pci_state_t *state) { return status; } +bool WddmPciImp::resizableBarSupported() { + uint32_t valueSmall = 0; + bool supported = false; + KmdSysman::RequestProperty request; + KmdSysman::ResponseProperty response; + + request.commandId = KmdSysman::Command::Get; + request.componentId = KmdSysman::Component::PciComponent; + request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice; + request.requestId = KmdSysman::Requests::Pci::ResizableBarSupported; + + if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) { + memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t)); + supported = static_cast(valueSmall); + } + + return supported; +} + +bool WddmPciImp::resizableBarEnabled() { + uint32_t valueSmall = 0; + bool enabled = false; + KmdSysman::RequestProperty request; + KmdSysman::ResponseProperty response; + + request.commandId = KmdSysman::Command::Get; + request.componentId = KmdSysman::Component::PciComponent; + request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice; + request.requestId = KmdSysman::Requests::Pci::ResizableBarEnabled; + + if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) { + memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t)); + enabled = static_cast(valueSmall); + } + + return enabled; +} + ze_result_t WddmPciImp::initializeBarProperties(std::vector &pBarProperties) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; + zes_pci_bar_properties_t *pBarProp = new zes_pci_bar_properties_t; + memset(pBarProp, 0, sizeof(zes_pci_bar_properties_t)); + pBarProperties.push_back(pBarProp); + return ZE_RESULT_SUCCESS; } WddmPciImp::WddmPciImp(OsSysman *pOsSysman) { 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 68b1a155f8..75f6de2708 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,6 +20,8 @@ class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass { ze_result_t getMaxLinkWidth(int32_t &maxLinkwidth) override; 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; ze_result_t initializeBarProperties(std::vector &pBarProperties) override; WddmPciImp(OsSysman *pOsSysman); WddmPciImp() = default; diff --git a/level_zero/tools/source/sysman/windows/kmd_sys.h b/level_zero/tools/source/sysman/windows/kmd_sys.h index c7995449db..7e3883a1f1 100644 --- a/level_zero/tools/source/sysman/windows/kmd_sys.h +++ b/level_zero/tools/source/sysman/windows/kmd_sys.h @@ -303,6 +303,10 @@ enum Pci { CurrentLinkRxCounter, CurrentLinkTxCounter, + // resizable bar + ResizableBarSupported, + ResizableBarEnabled, + MaxPciRequests, }; 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 ca8633cbb2..855ab81b5a 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 @@ -211,6 +211,117 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe } } +TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2Extension) { + 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]; + 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)); + + 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; + } + + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + + 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_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->resizableBarSupported, false); + 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) { + 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]; + 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)); + + for (uint32_t i = 0; i < count; i++) { + pBarProps[i].pNext = static_cast(props1_2); + pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE; + } + + 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); + } + + 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) { + 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_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, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_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; + } + + 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, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStateThenVerifyzetSysmanPciGetStateCallReturnNotSupported) { zes_pci_state_t state; EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDevicePciGetState(device, &state)); diff --git a/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/mock_pci.h b/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/mock_pci.h index 68c3b0cd47..d01c6c673d 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/mock_pci.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/pci/windows/mock_pci.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -32,6 +32,8 @@ struct Mock : public PciKmdSysManager { uint32_t mockMaxLinkWidth[3] = {1, 0, 8}; uint32_t mockCurrentLinkSpeed[3] = {1, 0, 3}; uint32_t mockCurrentLinkWidth[3] = {1, 0, 1}; + uint32_t mockResizableBarSupported[3] = {1, 1, 1}; + uint32_t mockResizableBarEnabled[3] = {1, 1, 1}; void getPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override { uint8_t *pBuffer = reinterpret_cast(pResponse); @@ -88,6 +90,18 @@ struct Mock : public PciKmdSysManager { pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess; pResponse->outDataSize = sizeof(uint32_t); } break; + case KmdSysman::Requests::Pci::ResizableBarSupported: { + uint32_t *pValue = reinterpret_cast(pBuffer); + *pValue = mockResizableBarSupported[domain]; + pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess; + pResponse->outDataSize = sizeof(uint32_t); + } break; + case KmdSysman::Requests::Pci::ResizableBarEnabled: { + uint32_t *pValue = reinterpret_cast(pBuffer); + *pValue = mockResizableBarEnabled[domain]; + pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess; + pResponse->outDataSize = sizeof(uint32_t); + } break; default: { pResponse->outDataSize = 0; pResponse->outReturnCode = KmdSysman::KmdSysmanFail; 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 322fabf821..d38176c6b5 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 @@ -112,6 +112,74 @@ TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetB EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr)); } +TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2Extension) { + 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]; + 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)); + + 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; + } + + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + + EXPECT_EQ(props1_2->resizableBarSupported, true); + EXPECT_EQ(props1_2->resizableBarEnabled, true); + + delete[] pBarProps; + pBarProps = nullptr; + delete props1_2; + props1_2 = nullptr; +} + +TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithNullPtr) { + 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_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2; + } + + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + + delete[] pBarProps; + pBarProps = nullptr; +} + +TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWrongType) { + 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]; + 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)); + + for (uint32_t i = 0; i < count; i++) { + pBarProps[i].pNext = static_cast(props1_2); + pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE; + } + + EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps)); + + EXPECT_EQ(props1_2->resizableBarSupported, false); + EXPECT_EQ(props1_2->resizableBarEnabled, false); + + delete[] pBarProps; + pBarProps = nullptr; + delete props1_2; + props1_2 = nullptr; +} + TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStatsWithLocalMemoryThenVerifyzetSysmanPciGetBarsCallSucceeds) { setLocalMemorySupportedAndReinit(true);