1 /*
2 * Copyright (c) 2020, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file mos_os_mock_adaptor_specific.cpp
24 //! \brief Common interface and structure used in mock adaptor.
25 //!
26 #include "mos_os.h"
27 #include "mos_os_specific.h"
28 #include "mos_interface.h"
29 #include "skuwa_factory.h"
30 #include "hwinfo_linux.h"
31 #include "mos_os_mock_adaptor_specific.h"
32
33 typedef DeviceInfoFactory<struct GfxDeviceInfo> DeviceInfoFact;
34 typedef DeviceInfoFactory<struct LinuxDeviceInit> DeviceInitFact;
35
MosMockAdaptorSpecific()36 MosMockAdaptorSpecific::MosMockAdaptorSpecific()
37 {
38
39 }
40
~MosMockAdaptorSpecific()41 MosMockAdaptorSpecific::~MosMockAdaptorSpecific()
42 {
43
44 }
45
GetDeviceInfo(uint32_t devId)46 GfxDeviceInfo *MosMockAdaptorSpecific::GetDeviceInfo(uint32_t devId)
47 {
48 GfxDeviceInfo *devInfo = DeviceInfoFact::LookupDevice(devId);
49
50 return devInfo;
51 }
52
GetDeviceInit(uint32_t platKey)53 LinuxDeviceInit *MosMockAdaptorSpecific::GetDeviceInit(uint32_t platKey)
54 {
55 LinuxDeviceInit *devInfo = DeviceInitFact::LookupDevice(platKey);
56
57 return devInfo;
58 }
59
InitializeSkuWaTable(PMOS_CONTEXT context)60 MOS_STATUS MosMockAdaptorSpecific::InitializeSkuWaTable(PMOS_CONTEXT context)
61 {
62 MOS_OS_CHK_NULL_RETURN(context);
63 MOS_OS_CHK_NULL_RETURN(m_pPlatform);
64 auto userSettingPtr = MosInterface::MosGetUserSettingInstance(context);
65
66 LinuxDriverInfo drvInfo = {18, 3, 0, 23172, 3, 1, 0, 1, 0, 0, 1, 0};
67 if (mos_get_driver_info(context->bufmgr, &drvInfo))
68 {
69 return MOS_STATUS_INVALID_HANDLE;
70 }
71
72 drvInfo.devId = m_pPlatform->usDeviceID;
73 drvInfo.devRev = m_pPlatform->usRevId;
74
75 GfxDeviceInfo *devInfo = GetDeviceInfo(drvInfo.devId);
76 if (devInfo == nullptr)
77 {
78 MOS_OS_ASSERTMESSAGE("Failed to get the device info for Device id: %x\n", drvInfo.devId);
79 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
80 }
81 /* Initialize Platform Info */
82 m_pGtSystemInfo->SliceCount = devInfo->SliceCount;
83 m_pGtSystemInfo->SubSliceCount = devInfo->SubSliceCount;
84 m_pGtSystemInfo->EUCount = devInfo->EUCount;
85
86 if (devInfo->InitMediaSysInfo &&
87 devInfo->InitMediaSysInfo(devInfo, m_pGtSystemInfo))
88 {
89 MOS_OS_NORMALMESSAGE("Init Media SystemInfo\n");
90 }
91 else
92 {
93 MOS_OS_ASSERTMESSAGE("Failed to Init Gt System Info\n");
94 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
95 }
96
97 if (mos_query_sys_engines(context->bufmgr, m_pGtSystemInfo))
98 {
99 MOS_OS_ASSERTMESSAGE("Failed to Init Gt System Info\n");
100 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
101 }
102
103 uint32_t platformKey = devInfo->productFamily;
104 LinuxDeviceInit *devInit = GetDeviceInit(platformKey);
105
106 if (devInit && devInit->InitMediaFeature &&
107 devInit->InitMediaWa &&
108 devInit->InitMediaFeature(devInfo, m_pSkuTable, &drvInfo, userSettingPtr) &&
109 devInit->InitMediaWa(devInfo, m_pWaTable, &drvInfo))
110 {
111 MOS_OS_NORMALMESSAGE("Init Media SKU/WA info successfully\n");
112 }
113 else
114 {
115 MOS_OS_ASSERTMESSAGE("Failed to Init SKU/WA Info\n");
116 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
117 }
118
119 uint32_t devExtKey = platformKey + MEDIA_EXT_FLAG;
120 LinuxDeviceInit *devExtInit = GetDeviceInit(devExtKey);
121
122 /* The initializationof Ext SKU/WA is optional. So skip the check of return value */
123 if (devExtInit && devExtInit->InitMediaFeature &&
124 devExtInit->InitMediaWa &&
125 devExtInit->InitMediaFeature(devInfo, m_pSkuTable, &drvInfo, userSettingPtr) &&
126 devExtInit->InitMediaWa(devInfo, m_pWaTable, &drvInfo))
127 {
128 MOS_OS_NORMALMESSAGE("Init Media SystemInfo successfully\n");
129 }
130
131 /* disable it on Linux */
132 MEDIA_WR_SKU(m_pSkuTable, FtrPerCtxtPreemptionGranularityControl, 0);
133 MEDIA_WR_SKU(m_pSkuTable, FtrMediaThreadGroupLevelPreempt, 0);
134 MEDIA_WR_SKU(m_pSkuTable, FtrMediaMidBatchPreempt, 0);
135 MEDIA_WR_SKU(m_pSkuTable, FtrMediaMidThreadLevelPreempt, 0);
136 MEDIA_WR_SKU(m_pSkuTable, FtrGpGpuThreadGroupLevelPreempt, 0);
137 MEDIA_WR_SKU(m_pSkuTable, FtrGpGpuMidBatchPreempt, 0);
138 MEDIA_WR_SKU(m_pSkuTable, FtrGpGpuMidThreadLevelPreempt, 0);
139
140 return MOS_STATUS_SUCCESS;
141 }
142
UpdateUserFeatureKey(PMOS_CONTEXT osContext)143 MOS_STATUS MosMockAdaptorSpecific::UpdateUserFeatureKey(PMOS_CONTEXT osContext)
144 {
145 MOS_OS_CHK_NULL_RETURN(osContext);
146 MediaUserSettingSharedPtr userSettingPtr = MosInterface::MosGetUserSettingInstance(osContext);
147 PLATFORM platForm = osContext->m_platform;
148 int32_t iDeviceId = osContext->iDeviceId;
149 int32_t eProductFaimily = (int32_t)platForm.eProductFamily;
150
151 ReportUserSettingForDebug(userSettingPtr, __MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_PLATFORM,eProductFaimily,MediaUserSetting::Group::Device);
152 ReportUserSettingForDebug(userSettingPtr, __MEDIA_USER_FEATURE_VALUE_MOCKADAPTOR_DEVICE,iDeviceId,MediaUserSetting::Group::Device);
153
154 return MOS_STATUS_SUCCESS;
155 }
156