diff --git a/core/helpers/hw_helper.h b/core/helpers/hw_helper.h index b8845717a6..1d2f7ce712 100644 --- a/core/helpers/hw_helper.h +++ b/core/helpers/hw_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -37,7 +37,6 @@ class HwHelper { virtual void setupHardwareCapabilities(HardwareCapabilities *caps, const HardwareInfo &hwInfo) = 0; virtual bool isL3Configurable(const HardwareInfo &hwInfo) = 0; virtual SipKernelType getSipKernelType(bool debuggingActive) = 0; - virtual uint32_t getConfigureAddressSpaceMode() = 0; virtual bool isLocalMemoryEnabled(const HardwareInfo &hwInfo) const = 0; virtual bool isPageTableManagerSupported(const HardwareInfo &hwInfo) const = 0; virtual const AubMemDump::LrcaHelper &getCsTraits(aub_stream::EngineType engineType) const = 0; @@ -134,8 +133,6 @@ class HwHelperHw : public HwHelper { SipKernelType getSipKernelType(bool debuggingActive) override; - uint32_t getConfigureAddressSpaceMode() override; - bool isLocalMemoryEnabled(const HardwareInfo &hwInfo) const override; bool hvAlign4Required() const override; diff --git a/core/helpers/hw_helper_bdw_plus.inl b/core/helpers/hw_helper_bdw_plus.inl index dab7b9e63d..b7f393d433 100644 --- a/core/helpers/hw_helper_bdw_plus.inl +++ b/core/helpers/hw_helper_bdw_plus.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -25,11 +25,6 @@ void HwHelperHw::setCapabilityCoherencyFlag(const HardwareInfo *pHwIn coherencyFlag = true; } -template -uint32_t HwHelperHw::getConfigureAddressSpaceMode() { - return 0u; -} - template bool HwHelperHw::isLocalMemoryEnabled(const HardwareInfo &hwInfo) const { return false; diff --git a/runtime/gen12lp/hw_helper_gen12lp.cpp b/runtime/gen12lp/hw_helper_gen12lp.cpp index d3c9651b8c..620b26d353 100644 --- a/runtime/gen12lp/hw_helper_gen12lp.cpp +++ b/runtime/gen12lp/hw_helper_gen12lp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -45,11 +45,6 @@ uint32_t HwHelperHw::getComputeUnitsUsedForScratch(const HardwareInfo *p return pHwInfo->gtSystemInfo.MaxSubSlicesSupported * pHwInfo->gtSystemInfo.MaxEuPerSubSlice * 8; } -template <> -uint32_t HwHelperHw::getConfigureAddressSpaceMode() { - return 1u; -} - template <> bool HwHelperHw::isLocalMemoryEnabled(const HardwareInfo &hwInfo) const { return Gen12LPHelpers::isLocalMemoryEnabled(hwInfo); diff --git a/runtime/gmm_helper/gmm_memory_base.cpp b/runtime/gmm_helper/gmm_memory_base.cpp index dc1c8501be..ab0fda6162 100644 --- a/runtime/gmm_helper/gmm_memory_base.cpp +++ b/runtime/gmm_helper/gmm_memory_base.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -39,9 +39,22 @@ bool GmmMemoryBase::configureDevice(GMM_ESCAPE_HANDLE hAdapter, GMM_ESCAPE_FUNC_TYPE pfnEscape, GMM_GFX_SIZE_T SvmSize, BOOLEAN BDWL3Coherency, - GMM_GFX_PARTITIONING &gfxPartition, - uintptr_t &minAddress) { + uintptr_t &minAddress, + bool obtainMinAddress) { minAddress = windowsMinAddress; - return configureDeviceAddressSpace(hAdapter, hDevice, pfnEscape, SvmSize, BDWL3Coherency); + auto retVal = configureDeviceAddressSpace(hAdapter, hDevice, pfnEscape, SvmSize, BDWL3Coherency); + if (obtainMinAddress) { + minAddress = getInternalGpuVaRangeLimit(); + } + return retVal; +} +uintptr_t GmmMemoryBase::getInternalGpuVaRangeLimit() { + return static_cast(clientContext->GetInternalGpuVaRangeLimit()); +} + +bool GmmMemoryBase::setDeviceInfo(GMM_DEVICE_INFO *deviceInfo) { + auto status = clientContext->GmmSetDeviceInfo(deviceInfo); + DEBUG_BREAK_IF(status != GMM_SUCCESS); + return GMM_SUCCESS == status; } }; // namespace NEO diff --git a/runtime/gmm_helper/gmm_memory_base.h b/runtime/gmm_helper/gmm_memory_base.h index ea5001013d..6f98ae147b 100644 --- a/runtime/gmm_helper/gmm_memory_base.h +++ b/runtime/gmm_helper/gmm_memory_base.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,13 +21,17 @@ class GmmMemoryBase { GMM_GFX_SIZE_T SvmSize, BOOLEAN BDWL3Coherency); - virtual bool configureDevice(GMM_ESCAPE_HANDLE hAdapter, - GMM_ESCAPE_HANDLE hDevice, - GMM_ESCAPE_FUNC_TYPE pfnEscape, - GMM_GFX_SIZE_T SvmSize, - BOOLEAN BDWL3Coherency, - GMM_GFX_PARTITIONING &gfxPartition, - uintptr_t &minAddress); + bool configureDevice(GMM_ESCAPE_HANDLE hAdapter, + GMM_ESCAPE_HANDLE hDevice, + GMM_ESCAPE_FUNC_TYPE pfnEscape, + GMM_GFX_SIZE_T SvmSize, + BOOLEAN BDWL3Coherency, + uintptr_t &minAddress, + bool obtainMinAddress); + + MOCKABLE_VIRTUAL uintptr_t getInternalGpuVaRangeLimit(); + + MOCKABLE_VIRTUAL bool setDeviceInfo(GMM_DEVICE_INFO *deviceInfo); protected: GmmMemoryBase(); diff --git a/runtime/os_interface/windows/CMakeLists.txt b/runtime/os_interface/windows/CMakeLists.txt index 8631cd8c91..f5c714c027 100644 --- a/runtime/os_interface/windows/CMakeLists.txt +++ b/runtime/os_interface/windows/CMakeLists.txt @@ -52,7 +52,6 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.h - ${CMAKE_CURRENT_SOURCE_DIR}/wddm${BRANCH_DIR_SUFFIX}/wddm_configure_device.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_interface.cpp ) diff --git a/runtime/os_interface/windows/wddm/wddm.cpp b/runtime/os_interface/windows/wddm/wddm.cpp index 882319ee99..3f81680fd8 100644 --- a/runtime/os_interface/windows/wddm/wddm.cpp +++ b/runtime/os_interface/windows/wddm/wddm.cpp @@ -21,6 +21,7 @@ #include "core/utilities/stackvec.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/gmm_helper/gmm.h" +#include "runtime/helpers/windows/gmm_callbacks.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/hw_info_config.h" #include "runtime/os_interface/windows/gdi_interface.h" @@ -938,7 +939,37 @@ int Wddm::virtualFree(void *ptr, size_t size, unsigned long flags) { return virtualFreeFnc(ptr, size, flags); } -bool Wddm::configureDeviceAddressSpaceImpl() { +long __stdcall notifyAubCapture(void *csrHandle, uint64_t gfxAddress, size_t gfxSize, bool allocate) { + return notifyAubCaptureImpl(csrHandle, gfxAddress, gfxSize, allocate); +} +bool Wddm::configureDeviceAddressSpace() { + GMM_DEVICE_CALLBACKS_INT deviceCallbacks{}; + deviceCallbacks.Adapter.KmtHandle = adapter; + deviceCallbacks.hCsr = nullptr; + deviceCallbacks.hDevice.KmtHandle = device; + deviceCallbacks.PagingQueue = pagingQueue; + deviceCallbacks.PagingFence = pagingQueueSyncObject; + + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnAllocate = gdi->createAllocation; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnDeallocate = gdi->destroyAllocation; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnMapGPUVA = gdi->mapGpuVirtualAddress; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnMakeResident = gdi->makeResident; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnEvict = gdi->evict; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnReserveGPUVA = gdi->reserveGpuVirtualAddress; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnUpdateGPUVA = gdi->updateGpuVirtualAddress; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnWaitFromCpu = gdi->waitForSynchronizationObjectFromCpu; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnLock = gdi->lock2; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnUnLock = gdi->unlock2; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnEscape = gdi->escape; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnFreeGPUVA = gdi->freeGpuVirtualAddress; + deviceCallbacks.DevCbPtrs.KmtCbPtrs.pfnNotifyAubCapture = notifyAubCapture; + + GMM_DEVICE_INFO deviceInfo{}; + deviceInfo.pGfxPartition = &gfxPartition; + deviceInfo.pDeviceCb = &deviceCallbacks; + if (!gmmMemory->setDeviceInfo(&deviceInfo)) { + return false; + } SYSTEM_INFO sysInfo; Wddm::getSystemInfo(&sysInfo); maximumApplicationAddress = reinterpret_cast(sysInfo.lpMaximumApplicationAddress); @@ -950,7 +981,8 @@ bool Wddm::configureDeviceAddressSpaceImpl() { ? maximumApplicationAddress + 1u : 0u; - return gmmMemory->configureDevice(adapter, device, gdi->escape, svmSize, featureTable->ftrL3IACoherency, gfxPartition, minAddress); + bool obtainMinAddress = gfxPlatform->eRenderCoreFamily == IGFX_GEN12LP_CORE; + return gmmMemory->configureDevice(adapter, device, gdi->escape, svmSize, featureTable->ftrL3IACoherency, minAddress, obtainMinAddress); } void Wddm::waitOnPagingFenceFromCpu() { diff --git a/runtime/os_interface/windows/wddm/wddm.h b/runtime/os_interface/windows/wddm/wddm.h index fe228cc4fa..bd5c58c20e 100644 --- a/runtime/os_interface/windows/wddm/wddm.h +++ b/runtime/os_interface/windows/wddm/wddm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -195,7 +195,6 @@ class Wddm { bool closeAdapter(); void getDeviceState(); void handleCompletion(OsContextWin &osContext); - bool configureDeviceAddressSpaceImpl(); static CreateDXGIFactoryFcn createDxgiFactory; static GetSystemInfoFcn getSystemInfo; diff --git a/runtime/os_interface/windows/wddm/wddm_configure_device.cpp b/runtime/os_interface/windows/wddm/wddm_configure_device.cpp deleted file mode 100644 index adb19507a1..0000000000 --- a/runtime/os_interface/windows/wddm/wddm_configure_device.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "runtime/os_interface/windows/wddm/wddm.h" - -namespace NEO { -bool Wddm::configureDeviceAddressSpace() { - return configureDeviceAddressSpaceImpl(); -} - -} // namespace NEO diff --git a/unit_tests/gen11/hw_helper_tests_gen11.cpp b/unit_tests/gen11/hw_helper_tests_gen11.cpp index d2ee889cc2..bb6a2b7ade 100644 --- a/unit_tests/gen11/hw_helper_tests_gen11.cpp +++ b/unit_tests/gen11/hw_helper_tests_gen11.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -42,11 +42,6 @@ GEN11TEST_F(HwHelperTestGen11, givenGen11PlatformWhenSetupHardwareCapabilitiesIs testDefaultImplementationOfSetupHardwareCapabilities(helper, hardwareInfo); } -GEN11TEST_F(HwHelperTestGen11, whenGetConfigureAddressSpaceModeThenReturnZero) { - auto &helper = HwHelper::get(renderCoreFamily); - EXPECT_EQ(0u, helper.getConfigureAddressSpaceMode()); -} - GEN11TEST_F(HwHelperTestGen11, whenGetGpgpuEnginesThenReturnTwoRcsEngines) { whenGetGpgpuEnginesThenReturnTwoRcsEngines(); EXPECT_EQ(2u, pDevice->engines.size()); diff --git a/unit_tests/gen12lp/hw_helper_tests_gen12lp.inl b/unit_tests/gen12lp/hw_helper_tests_gen12lp.inl index 02b312fb2e..9a5a71362e 100644 --- a/unit_tests/gen12lp/hw_helper_tests_gen12lp.inl +++ b/unit_tests/gen12lp/hw_helper_tests_gen12lp.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -71,11 +71,6 @@ GEN12LPTEST_F(HwHelperTestGen12Lp, givenGen12LpPlatformWhenSetupHardwareCapabili } } -GEN12LPTEST_F(HwHelperTestGen12Lp, whenGetConfigureAddressSpaceModeThenReturnOne) { - auto &helper = HwHelper::get(renderCoreFamily); - EXPECT_EQ(1u, helper.getConfigureAddressSpaceMode()); -} - GEN12LPTEST_F(HwHelperTestGen12Lp, givenCompressionFtrEnabledWhenAskingForPageTableManagerThenReturnCorrectValue) { auto &helper = HwHelper::get(renderCoreFamily); diff --git a/unit_tests/gen12lp/windows/CMakeLists.txt b/unit_tests/gen12lp/windows/CMakeLists.txt index e19034b8f8..dd864b72f6 100644 --- a/unit_tests/gen12lp/windows/CMakeLists.txt +++ b/unit_tests/gen12lp/windows/CMakeLists.txt @@ -1,13 +1,14 @@ # -# Copyright (C) 2019 Intel Corporation +# Copyright (C) 2019-2020 Intel Corporation # # SPDX-License-Identifier: MIT # set(IGDRCL_SRCS_tests_gen12lp_windows ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests_gen12lp.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gmm_callbacks_tests_gen12lp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests_gen12lp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/wddm_tests_gen12lp.cpp ) if(WIN32) target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_gen12lp_windows}) diff --git a/unit_tests/gen12lp/windows/wddm_tests_gen12lp.cpp b/unit_tests/gen12lp/windows/wddm_tests_gen12lp.cpp new file mode 100644 index 0000000000..9b9be58a7a --- /dev/null +++ b/unit_tests/gen12lp/windows/wddm_tests_gen12lp.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2019-2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "core/command_stream/preemption.h" +#include "core/execution_environment/root_device_environment.h" +#include "runtime/os_interface/windows/gdi_interface.h" +#include "test.h" +#include "unit_tests/mocks/mock_execution_environment.h" +#include "unit_tests/mocks/mock_wddm.h" +#include "unit_tests/os_interface/windows/gdi_dll_fixture.h" + +#include "mock_gmm_memory.h" + +using namespace NEO; + +struct Gen12LpWddmTest : public GdiDllFixture, ::testing::Test { + void SetUp() override { + GdiDllFixture::SetUp(); + + executionEnvironment = std::make_unique(); + rootDeviceEnvironment = std::make_unique(*executionEnvironment); + wddm.reset(static_cast(Wddm::createWddm(*rootDeviceEnvironment))); + gmmMemory = new ::testing::NiceMock(); + wddm->gmmMemory.reset(gmmMemory); + } + + void TearDown() override { + GdiDllFixture::TearDown(); + } + + std::unique_ptr executionEnvironment; + std::unique_ptr rootDeviceEnvironment; + std::unique_ptr wddm; + GmockGmmMemory *gmmMemory = nullptr; +}; + +GEN12LPTEST_F(Gen12LpWddmTest, whenConfigureDeviceAddressSpaceThenObtainMinAddress) { + ON_CALL(*gmmMemory, configureDeviceAddressSpace(::testing::_, + ::testing::_, + ::testing::_, + ::testing::_, + ::testing::_)) + .WillByDefault(::testing::Return(true)); + + uintptr_t minAddress = 0x12345u; + + EXPECT_NE(NEO::windowsMinAddress, minAddress); + + EXPECT_CALL(*gmmMemory, + getInternalGpuVaRangeLimit()) + .Times(1) + .WillRepeatedly(::testing::Return(minAddress)); + + auto hwInfoMock = *platformDevices[0]; + wddm->init(hwInfoMock); + + EXPECT_EQ(minAddress, wddm->getWddmMinAddress()); +} diff --git a/unit_tests/gen8/hw_helper_tests_gen8.cpp b/unit_tests/gen8/hw_helper_tests_gen8.cpp index 6eca995b26..7c75dfbefc 100644 --- a/unit_tests/gen8/hw_helper_tests_gen8.cpp +++ b/unit_tests/gen8/hw_helper_tests_gen8.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -48,11 +48,6 @@ GEN8TEST_F(HwHelperTestGen8, givenGen8PlatformWhenSetupHardwareCapabilitiesIsCal EXPECT_FALSE(hwCaps.isStatelesToStatefullWithOffsetSupported); } -GEN8TEST_F(HwHelperTestGen8, whenGetConfigureAddressSpaceModeThenReturnZero) { - auto &helper = HwHelper::get(renderCoreFamily); - EXPECT_EQ(0u, helper.getConfigureAddressSpaceMode()); -} - GEN8TEST_F(HwHelperTestGen8, whenGetGpgpuEnginesThenReturnTwoRcsEngines) { whenGetGpgpuEnginesThenReturnTwoRcsEngines(); EXPECT_EQ(2u, pDevice->engines.size()); diff --git a/unit_tests/gen9/hw_helper_tests_gen9.cpp b/unit_tests/gen9/hw_helper_tests_gen9.cpp index 04e8bd38f1..1d5c65f908 100644 --- a/unit_tests/gen9/hw_helper_tests_gen9.cpp +++ b/unit_tests/gen9/hw_helper_tests_gen9.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -49,11 +49,6 @@ GEN9TEST_F(HwHelperTestGen9, givenDebuggingActiveWhenSipKernelTypeIsQueriedThenD EXPECT_EQ(SipKernelType::DbgCsrLocal, sipType); } -GEN9TEST_F(HwHelperTestGen9, whenGetConfigureAddressSpaceModeThenReturnZero) { - auto &helper = HwHelper::get(renderCoreFamily); - EXPECT_EQ(0u, helper.getConfigureAddressSpaceMode()); -} - GEN9TEST_F(HwHelperTestGen9, whenGetGpgpuEnginesThenReturnTwoRcsEngines) { whenGetGpgpuEnginesThenReturnTwoRcsEngines(); EXPECT_EQ(2u, pDevice->engines.size()); diff --git a/unit_tests/mocks/mock_gmm_memory_base.h b/unit_tests/mocks/mock_gmm_memory_base.h index 44fe352900..e6df5521f4 100644 --- a/unit_tests/mocks/mock_gmm_memory_base.h +++ b/unit_tests/mocks/mock_gmm_memory_base.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -26,13 +26,37 @@ class MockGmmMemoryBase : public GmmMemory { BOOLEAN BDWL3Coherency) override { return true; } + + uintptr_t getInternalGpuVaRangeLimit() override { + return NEO::windowsMinAddress; + } + + bool setDeviceInfo(GMM_DEVICE_INFO *deviceInfo) override { + partition = deviceInfo->pGfxPartition; + deviceCallbacks = *deviceInfo->pDeviceCb; + return setDeviceInfoValue; + } + + GMM_GFX_PARTITIONING *partition = nullptr; + bool setDeviceInfoValue = true; + GMM_DEVICE_CALLBACKS_INT deviceCallbacks{}; }; class GmockGmmMemoryBase : public GmmMemory { public: ~GmockGmmMemoryBase() = default; - GmockGmmMemoryBase() = default; + GmockGmmMemoryBase() { + ON_CALL(*this, getInternalGpuVaRangeLimit()) + .WillByDefault(::testing::Return(NEO::windowsMinAddress)); + + ON_CALL(*this, setDeviceInfo(::testing::_)) + .WillByDefault(::testing::Return(true)); + } + + MOCK_METHOD0(getInternalGpuVaRangeLimit, uintptr_t()); + + MOCK_METHOD1(setDeviceInfo, bool(GMM_DEVICE_INFO *)); MOCK_METHOD5(configureDeviceAddressSpace, bool(GMM_ESCAPE_HANDLE hAdapter, diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index 8b7c4175aa..903e30b211 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2017-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1136,3 +1136,80 @@ TEST_F(Wddm20WithMockGdiDllTests, WhenDestroyingSeparateMonitorFenceThenExpectGd EXPECT_EQ(monitorFence.fenceHandle, getDestroySynchronizationObjectDataFcn()->hSyncObject); } +namespace NEO { +long __stdcall notifyAubCapture(void *csrHandle, uint64_t gfxAddress, size_t gfxSize, bool allocate); +} + +TEST_F(Wddm20WithMockGdiDllTests, whenSetDeviceInfoSucceedsThenDeviceCallbacksArePassedToGmmMemory) { + GMM_DEVICE_CALLBACKS_INT expectedDeviceCb{}; + auto hwInfoMock = *platformDevices[0]; + wddm->init(hwInfoMock); + auto gdi = wddm->getGdi(); + auto gmmMemory = static_cast(wddm->getGmmMemory()); + + expectedDeviceCb.Adapter.KmtHandle = wddm->getAdapter(); + expectedDeviceCb.hDevice.KmtHandle = wddm->getDevice(); + expectedDeviceCb.hCsr = nullptr; + expectedDeviceCb.PagingQueue = wddm->getPagingQueue(); + expectedDeviceCb.PagingFence = wddm->getPagingQueueSyncObject(); + + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnAllocate = gdi->createAllocation; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnDeallocate = gdi->destroyAllocation; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnMapGPUVA = gdi->mapGpuVirtualAddress; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnMakeResident = gdi->makeResident; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnEvict = gdi->evict; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnReserveGPUVA = gdi->reserveGpuVirtualAddress; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnUpdateGPUVA = gdi->updateGpuVirtualAddress; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnWaitFromCpu = gdi->waitForSynchronizationObjectFromCpu; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnLock = gdi->lock2; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnUnLock = gdi->unlock2; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnEscape = gdi->escape; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnFreeGPUVA = gdi->freeGpuVirtualAddress; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnNotifyAubCapture = notifyAubCapture; + + EXPECT_TRUE(memcmp(&expectedDeviceCb, &gmmMemory->deviceCallbacks, sizeof(GMM_DEVICE_CALLBACKS_INT)) == 0); + EXPECT_TRUE(memcmp(&expectedDeviceCb.Adapter, &gmmMemory->deviceCallbacks.Adapter, sizeof(GMM_HANDLE_EXT)) == 0); + EXPECT_TRUE(memcmp(&expectedDeviceCb.hDevice, &gmmMemory->deviceCallbacks.hDevice, sizeof(GMM_HANDLE_EXT)) == 0); + EXPECT_TRUE(memcmp(&expectedDeviceCb.DevCbPtrs.KmtCbPtrs, &gmmMemory->deviceCallbacks.DevCbPtrs.KmtCbPtrs, sizeof(GMM_DEVICE_CB_PTRS::KmtCbPtrs)) == 0); +} + +TEST_F(Wddm20WithMockGdiDllTests, whenSetDeviceInfoFailsThenDeviceIsNotConfigured) { + + auto gmockGmmMemory = new ::testing::NiceMock(); + ON_CALL(*gmockGmmMemory, setDeviceInfo(::testing::_)) + .WillByDefault(::testing::Return(false)); + EXPECT_CALL(*gmockGmmMemory, configureDeviceAddressSpace(::testing::_, + ::testing::_, + ::testing::_, + ::testing::_, + ::testing::_)) + .Times(0); + + wddm->gmmMemory.reset(gmockGmmMemory); + + auto hwInfoMock = *platformDevices[0]; + wddm->init(hwInfoMock); +} + +HWTEST_F(Wddm20WithMockGdiDllTests, givenNonGen12LPPlatformWhenConfigureDeviceAddressSpaceThenDontObtainMinAddress) { + if (platformDevices[0]->platform.eRenderCoreFamily == IGFX_GEN12LP_CORE) { + GTEST_SKIP(); + } + auto gmmMemory = new ::testing::NiceMock(); + wddm->gmmMemory.reset(gmmMemory); + ON_CALL(*gmmMemory, configureDeviceAddressSpace(::testing::_, + ::testing::_, + ::testing::_, + ::testing::_, + ::testing::_)) + .WillByDefault(::testing::Return(true)); + + EXPECT_CALL(*gmmMemory, + getInternalGpuVaRangeLimit()) + .Times(0); + + auto hwInfoMock = *platformDevices[0]; + wddm->init(hwInfoMock); + + EXPECT_EQ(NEO::windowsMinAddress, wddm->getWddmMinAddress()); +}