diff --git a/shared/source/os_interface/linux/drm_wrappers.cpp b/shared/source/os_interface/linux/drm_wrappers.cpp index 72d9bd1d90..24e73362c4 100644 --- a/shared/source/os_interface/linux/drm_wrappers.cpp +++ b/shared/source/os_interface/linux/drm_wrappers.cpp @@ -173,24 +173,30 @@ static_assert(offsetof(DrmVersion, descLen) == offsetof(drm_version, desc_len)); static_assert(offsetof(DrmVersion, desc) == offsetof(drm_version, desc)); unsigned int getIoctlRequestValue(DrmIoctl ioctlRequest, IoctlHelper *ioctlHelper) { + if (ioctlHelper) { + return ioctlHelper->getIoctlRequestValue(ioctlRequest); + } switch (ioctlRequest) { case DrmIoctl::Getparam: return DRM_IOCTL_I915_GETPARAM; default: - UNRECOVERABLE_IF(!ioctlHelper); - return ioctlHelper->getIoctlRequestValue(ioctlRequest); + UNRECOVERABLE_IF(true); + return 0; } } int getDrmParamValue(DrmParam drmParam, IoctlHelper *ioctlHelper) { + if (ioctlHelper) { + return ioctlHelper->getDrmParamValue(drmParam); + } switch (drmParam) { case DrmParam::ParamChipsetId: return I915_PARAM_CHIPSET_ID; case DrmParam::ParamRevision: return I915_PARAM_REVISION; default: - UNRECOVERABLE_IF(!ioctlHelper); - return ioctlHelper->getDrmParamValue(drmParam); + UNRECOVERABLE_IF(true); + return 0; } } } // namespace NEO diff --git a/shared/source/os_interface/linux/ioctl_helper.cpp b/shared/source/os_interface/linux/ioctl_helper.cpp index e145c5a149..385935e33f 100644 --- a/shared/source/os_interface/linux/ioctl_helper.cpp +++ b/shared/source/os_interface/linux/ioctl_helper.cpp @@ -134,6 +134,8 @@ std::vector IoctlHelper::translateToMemoryRegions(const std::vecto unsigned int IoctlHelper::getIoctlRequestValueBase(DrmIoctl ioctlRequest) const { switch (ioctlRequest) { + case DrmIoctl::Getparam: + return DRM_IOCTL_I915_GETPARAM; case DrmIoctl::GemExecbuffer2: return DRM_IOCTL_I915_GEM_EXECBUFFER2; case DrmIoctl::GemWait: @@ -196,6 +198,10 @@ int IoctlHelper::getDrmParamValueBase(DrmParam drmParam) const { return I915_ENGINE_CLASS_INVALID; case DrmParam::EngineClassInvalidNone: return I915_ENGINE_CLASS_INVALID_NONE; + case DrmParam::ParamChipsetId: + return I915_PARAM_CHIPSET_ID; + case DrmParam::ParamRevision: + return I915_PARAM_REVISION; case DrmParam::ParamHasExecSoftpin: return I915_PARAM_HAS_EXEC_SOFTPIN; case DrmParam::ParamHasPooledEu: diff --git a/shared/test/unit_test/os_interface/linux/drm_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_tests.cpp index bf77aded2d..fe10c18639 100644 --- a/shared/test/unit_test/os_interface/linux/drm_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_tests.cpp @@ -1174,6 +1174,29 @@ TEST(DrmWrapperTest, WhenGettingRevisionParamValueThenIoctlHelperIsNotNeeded) { EXPECT_EQ(getDrmParamValue(DrmParam::ParamRevision, nullptr), static_cast(I915_PARAM_REVISION)); } +class MockIoctlHelper : public IoctlHelperPrelim20 { + public: + unsigned int getIoctlRequestValue(DrmIoctl ioctlRequest) const override { + return ioctlRequestValue; + }; + + int getDrmParamValue(DrmParam drmParam) const override { + return drmParamValue; + } + + unsigned int ioctlRequestValue = 1234u; + int drmParamValue = 1234; +}; + +TEST(DrmWrapperTest, whenGettingDrmParamOrIoctlRequestValueThenUseIoctlHelperWhenAvailable) { + MockIoctlHelper ioctlHelper{}; + EXPECT_EQ(getIoctlRequestValue(DrmIoctl::Getparam, &ioctlHelper), ioctlHelper.ioctlRequestValue); + EXPECT_NE(getIoctlRequestValue(DrmIoctl::Getparam, nullptr), getIoctlRequestValue(DrmIoctl::Getparam, &ioctlHelper)); + + EXPECT_EQ(getDrmParamValue(DrmParam::ParamChipsetId, &ioctlHelper), ioctlHelper.drmParamValue); + EXPECT_NE(getDrmParamValue(DrmParam::ParamChipsetId, nullptr), getDrmParamValue(DrmParam::ParamChipsetId, &ioctlHelper)); +} + TEST(DrmWrapperTest, WhenGettingIoctlStringValueThenProperStringIsReturned) { std::map ioctlCodeStringMap = { {DrmIoctl::GemClose, "DRM_IOCTL_GEM_CLOSE"}, diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp index b17837eb84..5eda267502 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_dg1.cpp @@ -100,6 +100,7 @@ DG1TEST_F(IoctlHelperTestsDg1, whenGettingIoctlRequestValueThenPropertValueIsRet auto executionEnvironment = std::make_unique(); auto drm = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); auto &ioctlHelper = *drm->getIoctlHelper(); + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::Getparam), static_cast(DRM_IOCTL_I915_GETPARAM)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemExecbuffer2), static_cast(DRM_IOCTL_I915_GEM_EXECBUFFER2)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemWait), static_cast(DRM_IOCTL_I915_GEM_WAIT)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemClose), static_cast(DRM_IOCTL_GEM_CLOSE)); @@ -124,6 +125,4 @@ DG1TEST_F(IoctlHelperTestsDg1, whenGettingIoctlRequestValueThenPropertValueIsRet EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::DG1GemCreateExt), static_cast(DRM_IOCTL_I915_GEM_CREATE_EXT)); EXPECT_NE(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemCreateExt), static_cast(DRM_IOCTL_I915_GEM_CREATE_EXT)); - - EXPECT_THROW(ioctlHelper.getIoctlRequestValue(DrmIoctl::Getparam), std::runtime_error); } diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp index d3c3770e1c..82ed6cfbfb 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp @@ -22,6 +22,7 @@ struct IoctlPrelimHelperTests : ::testing::Test { }; TEST_F(IoctlPrelimHelperTests, whenGettingIoctlRequestValueThenPropertValueIsReturned) { + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::Getparam), static_cast(DRM_IOCTL_I915_GETPARAM)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemExecbuffer2), static_cast(DRM_IOCTL_I915_GEM_EXECBUFFER2)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemWait), static_cast(DRM_IOCTL_I915_GEM_WAIT)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemClose), static_cast(DRM_IOCTL_GEM_CLOSE)); @@ -56,12 +57,19 @@ TEST_F(IoctlPrelimHelperTests, whenGettingIoctlRequestValueThenPropertValueIsRet EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemVmCreate), static_cast(DRM_IOCTL_I915_GEM_VM_CREATE)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemVmDestroy), static_cast(DRM_IOCTL_I915_GEM_VM_DESTROY)); - EXPECT_THROW(ioctlHelper.getIoctlRequestValue(DrmIoctl::Getparam), std::runtime_error); EXPECT_THROW(ioctlHelper.getIoctlRequestValue(DrmIoctl::DG1GemCreateExt), std::runtime_error); } TEST_F(IoctlPrelimHelperTests, whenGettingDrmParamValueThenPropertValueIsReturned) { EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassCompute), static_cast(PRELIM_I915_ENGINE_CLASS_COMPUTE)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassRender), static_cast(I915_ENGINE_CLASS_RENDER)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassCopy), static_cast(I915_ENGINE_CLASS_COPY)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassVideo), static_cast(I915_ENGINE_CLASS_VIDEO)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassVideoEnhance), static_cast(I915_ENGINE_CLASS_VIDEO_ENHANCE)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassInvalid), static_cast(I915_ENGINE_CLASS_INVALID)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassInvalidNone), static_cast(I915_ENGINE_CLASS_INVALID_NONE)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamChipsetId), static_cast(I915_PARAM_CHIPSET_ID)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamRevision), static_cast(I915_PARAM_REVISION)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamHasExecSoftpin), static_cast(I915_PARAM_HAS_EXEC_SOFTPIN)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamHasPooledEu), static_cast(I915_PARAM_HAS_POOLED_EU)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamHasScheduler), static_cast(I915_PARAM_HAS_SCHEDULER)); diff --git a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp index 4fff7fbf7a..75df6b9c0c 100644 --- a/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp +++ b/shared/test/unit_test/os_interface/linux/ioctl_helper_tests_upstream.cpp @@ -23,6 +23,7 @@ TEST(IoctlHelperUpstreamTest, whenGettingVmBindAvailabilityThenFalseIsReturned) TEST(IoctlHelperUpstreamTest, whenGettingIoctlRequestValueThenPropertValueIsReturned) { IoctlHelperUpstream ioctlHelper{}; + EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::Getparam), static_cast(DRM_IOCTL_I915_GETPARAM)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemExecbuffer2), static_cast(DRM_IOCTL_I915_GEM_EXECBUFFER2)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemWait), static_cast(DRM_IOCTL_I915_GEM_WAIT)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemClose), static_cast(DRM_IOCTL_GEM_CLOSE)); @@ -46,13 +47,20 @@ TEST(IoctlHelperUpstreamTest, whenGettingIoctlRequestValueThenPropertValueIsRetu EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemVmCreate), static_cast(DRM_IOCTL_I915_GEM_VM_CREATE)); EXPECT_EQ(ioctlHelper.getIoctlRequestValue(DrmIoctl::GemVmDestroy), static_cast(DRM_IOCTL_I915_GEM_VM_DESTROY)); - EXPECT_THROW(ioctlHelper.getIoctlRequestValue(DrmIoctl::Getparam), std::runtime_error); EXPECT_THROW(ioctlHelper.getIoctlRequestValue(DrmIoctl::DG1GemCreateExt), std::runtime_error); } TEST(IoctlHelperUpstreamTest, whenGettingDrmParamValueThenPropertValueIsReturned) { IoctlHelperUpstream ioctlHelper{}; EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassCompute), 4); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassRender), static_cast(I915_ENGINE_CLASS_RENDER)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassCopy), static_cast(I915_ENGINE_CLASS_COPY)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassVideo), static_cast(I915_ENGINE_CLASS_VIDEO)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassVideoEnhance), static_cast(I915_ENGINE_CLASS_VIDEO_ENHANCE)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassInvalid), static_cast(I915_ENGINE_CLASS_INVALID)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::EngineClassInvalidNone), static_cast(I915_ENGINE_CLASS_INVALID_NONE)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamChipsetId), static_cast(I915_PARAM_CHIPSET_ID)); + EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamRevision), static_cast(I915_PARAM_REVISION)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamHasExecSoftpin), static_cast(I915_PARAM_HAS_EXEC_SOFTPIN)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamHasPooledEu), static_cast(I915_PARAM_HAS_POOLED_EU)); EXPECT_EQ(ioctlHelper.getDrmParamValue(DrmParam::ParamHasScheduler), static_cast(I915_PARAM_HAS_SCHEDULER));