1 /*
2 * Copyright (c) 2017-2023, 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 hwinfo_linux.c
24 //! \brief The purpose of the file is to get the sku/wa table according to platform information.
25 //!
26
27 #include "hwinfo_linux.h"
28 #include "mos_utilities.h"
29 #include "mos_util_debug.h"
30 #include "skuwa_factory.h"
31 #include "linux_system_info.h"
32 #include "linux_shadow_skuwa.h"
33 #include "mos_solo_generic.h"
34 #include "media_user_setting_specific.h"
35
36 typedef DeviceInfoFactory<struct GfxDeviceInfo> DeviceInfoFact;
37 typedef DeviceInfoFactory<struct LinuxDeviceInit> DeviceInitFact;
38
getDeviceInfo(uint32_t devId)39 static GfxDeviceInfo *getDeviceInfo(uint32_t devId)
40 {
41 GfxDeviceInfo *devInfo = DeviceInfoFact::LookupDevice(devId);
42
43 return devInfo;
44 }
45
getDeviceInit(uint32_t platKey)46 static LinuxDeviceInit *getDeviceInit(uint32_t platKey)
47 {
48 LinuxDeviceInit *devInfo = DeviceInitFact::LookupDevice(platKey);
49
50 return devInfo;
51 }
52
53 /*****************************************************************************\
54 Description:
55 Get ProductFamily according to input device FD
56
57 Input:
58 fd - file descriptor to the /dev/dri/cardX
59 Output:
60 eProductFamily - describing current platform product family
61 \*****************************************************************************/
HWInfo_GetGfxProductFamily(int32_t fd,PRODUCT_FAMILY & eProductFamily)62 MOS_STATUS HWInfo_GetGfxProductFamily(int32_t fd, PRODUCT_FAMILY &eProductFamily)
63 {
64 if (fd < 0)
65 {
66 MOS_OS_ASSERTMESSAGE("Invalid parameter \n");
67 return MOS_STATUS_INVALID_PARAMETER;
68 }
69 uint32_t devId = 23172;
70 if (mos_get_device_id(fd, &devId))
71 {
72 MOS_OS_ASSERTMESSAGE("Failed to get the chipset id\n");
73 return MOS_STATUS_INVALID_HANDLE;
74 }
75 GfxDeviceInfo *devInfo = getDeviceInfo(devId);
76 if (devInfo == nullptr)
77 {
78 MOS_OS_ASSERTMESSAGE("Failed to get the device info for Device id: %x\n", devId);
79 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
80 }
81 eProductFamily = (PRODUCT_FAMILY)devInfo->productFamily;
82 return MOS_STATUS_SUCCESS;
83 }
84
85
86 /*****************************************************************************\
87 Description:
88 Get Sku/Wa tables and platform information according to input device FD
89
90 Input:
91 fd - file descriptor to the /dev/dri/cardX
92 Output:
93 gfxPlatform - describing current platform. is it mobile, desk,
94 server? Sku/Wa must know.
95 skuTable - describing SKU
96 waTable - the constraints list
97 gtSystemInfo - describing current system information
98 userSettingPtr - shared pointer to user setting instance
99 \*****************************************************************************/
HWInfo_GetGfxInfo(int32_t fd,MOS_BUFMGR * pDrmBufMgr,PLATFORM * gfxPlatform,MEDIA_FEATURE_TABLE * skuTable,MEDIA_WA_TABLE * waTable,MEDIA_SYSTEM_INFO * gtSystemInfo,MediaUserSettingSharedPtr userSettingPtr)100 MOS_STATUS HWInfo_GetGfxInfo(int32_t fd,
101 MOS_BUFMGR *pDrmBufMgr,
102 PLATFORM *gfxPlatform,
103 MEDIA_FEATURE_TABLE *skuTable,
104 MEDIA_WA_TABLE *waTable,
105 MEDIA_SYSTEM_INFO *gtSystemInfo,
106 MediaUserSettingSharedPtr userSettingPtr)
107 {
108 if ((fd < 0) ||
109 (pDrmBufMgr == nullptr) ||
110 (gfxPlatform == nullptr) ||
111 (skuTable == nullptr) ||
112 (waTable == nullptr) ||
113 (gtSystemInfo == nullptr))
114 {
115 MOS_OS_ASSERTMESSAGE("Invalid parameter \n");
116 return MOS_STATUS_INVALID_PARAMETER;
117 }
118
119 #if (_DEBUG || _RELEASE_INTERNAL)
120 MOS_USER_FEATURE_VALUE_DATA UserFeatureData;
121 #endif
122
123 LinuxDriverInfo drvInfo = {18, 3, 0, 23172, 3, 1, 0, 1, 0, 0, 1, 0, 0};
124 if (!Mos_Solo_IsEnabled(nullptr) && mos_get_driver_info(pDrmBufMgr, &drvInfo))
125 {
126 MOS_OS_ASSERTMESSAGE("Failed to get the chipset id\n");
127 return MOS_STATUS_INVALID_HANDLE;
128 }
129
130 GfxDeviceInfo *devInfo = getDeviceInfo(drvInfo.devId);
131 if (devInfo == nullptr)
132 {
133 MOS_OS_ASSERTMESSAGE("Failed to get the device info for Device id: %x\n", drvInfo.devId);
134 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
135 }
136 /* Initialize Platform Info */
137 gfxPlatform->ePlatformType = (PLATFORM_TYPE)devInfo->platformType;
138 gfxPlatform->eProductFamily = (PRODUCT_FAMILY)devInfo->productFamily;
139 gfxPlatform->ePCHProductFamily = PCH_UNKNOWN;
140 gfxPlatform->eDisplayCoreFamily = (GFXCORE_FAMILY)devInfo->displayFamily;
141 gfxPlatform->eRenderCoreFamily = (GFXCORE_FAMILY)devInfo->renderFamily;
142 gfxPlatform->eGTType = (GTTYPE)devInfo->eGTType;
143 gfxPlatform->usDeviceID = drvInfo.devId;
144 gfxPlatform->usRevId = drvInfo.devRev;
145
146 if (mos_query_device_blob(pDrmBufMgr, gtSystemInfo) == 0)
147 {
148 gtSystemInfo->EUCount = gtSystemInfo->SubSliceCount * gtSystemInfo->MaxEuPerSubSlice;
149 gtSystemInfo->ThreadCount = gtSystemInfo->EUCount * gtSystemInfo->NumThreadsPerEu;
150 gtSystemInfo->VEBoxInfo.IsValid = true;
151 gtSystemInfo->VDBoxInfo.IsValid = true;
152 }
153 else
154 {
155 MOS_OS_NORMALMESSAGE("Device blob query is not supported yet.\n");
156 gtSystemInfo->SliceCount = drvInfo.sliceCount;
157 gtSystemInfo->SubSliceCount = drvInfo.subSliceCount;
158 gtSystemInfo->EUCount = drvInfo.euCount;
159
160 if (devInfo->InitMediaSysInfo &&
161 devInfo->InitMediaSysInfo(devInfo, gtSystemInfo))
162 {
163 MOS_OS_NORMALMESSAGE("Init Media SystemInfo\n");
164 }
165 else
166 {
167 MOS_OS_ASSERTMESSAGE("Failed to Init Gt System Info\n");
168 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
169 }
170 }
171
172 if (mos_query_sys_engines(pDrmBufMgr, gtSystemInfo))
173 {
174 MOS_OS_ASSERTMESSAGE("Failed to Init Gt System Info\n");
175 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
176 }
177
178 uint32_t platformKey = devInfo->productFamily;
179 LinuxDeviceInit *devInit = getDeviceInit(platformKey);
180
181 if (devInit && devInit->InitMediaFeature &&
182 devInit->InitMediaWa &&
183 devInit->InitMediaFeature(devInfo, skuTable, &drvInfo, userSettingPtr) &&
184 devInit->InitMediaWa(devInfo, waTable, &drvInfo))
185 {
186 #ifdef _MEDIA_RESERVED
187 MOS_OS_NORMALMESSAGE("Init Media SKU/WA info successfully\n");
188 if (MEDIA_IS_SKU(skuTable, FtrMediaIPSeparation))
189 {
190 gfxPlatform->eMediaCoreFamily = (GFXCORE_FAMILY)devInfo->mediaFamily;
191
192 if (0 == gfxPlatform->sMediaBlockID.Value)
193 {
194 if (mos_query_hw_ip_version(pDrmBufMgr, DRM_ENGINE_CLASS_VIDEO_DECODE, (void *)&(gfxPlatform->sMediaBlockID)))
195 {
196 MOS_OS_ASSERTMESSAGE("Failed to query vdbox engine GmdID\n");
197 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
198 }
199 else
200 {
201 MOS_OS_NORMALMESSAGE("Media mediaRevID arch:%d, release:%d, RevisionID:%d\n", gfxPlatform->sMediaBlockID.GmdID.GMDArch,
202 gfxPlatform->sMediaBlockID.GmdID.GMDRelease, gfxPlatform->sMediaBlockID.GmdID.RevisionID);
203 }
204 }
205
206 if (0 == gfxPlatform->sRenderBlockID.Value)
207 {
208 if (mos_query_hw_ip_version(pDrmBufMgr, DRM_ENGINE_CLASS_RENDER, (void *)&(gfxPlatform->sRenderBlockID)))
209 {
210 MOS_OS_ASSERTMESSAGE("Failed to query render GmdID\n");
211 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
212 }
213
214 else
215 {
216 MOS_OS_NORMALMESSAGE("Media sRenderBlockID arch:%d, release:%d, RevisionID:%d\n", gfxPlatform->sRenderBlockID.GmdID.GMDArch,
217 gfxPlatform->sRenderBlockID.GmdID.GMDRelease, gfxPlatform->sRenderBlockID.GmdID.RevisionID);
218 }
219 }
220 }
221 #endif
222 }
223 else
224 {
225 MOS_OS_ASSERTMESSAGE("Failed to Init SKU/WA Info\n");
226 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
227 }
228
229 uint32_t devExtKey = platformKey + MEDIA_EXT_FLAG;
230 LinuxDeviceInit *devExtInit = getDeviceInit(devExtKey);
231
232 /* The initializationof Ext SKU/WA is optional. So skip the check of return value */
233 if (devExtInit && devExtInit->InitMediaFeature &&
234 devExtInit->InitMediaWa &&
235 devExtInit->InitMediaFeature(devInfo, skuTable, &drvInfo, userSettingPtr) &&
236 devExtInit->InitMediaWa(devInfo, waTable, &drvInfo))
237 {
238 MOS_OS_NORMALMESSAGE("Init Media SystemInfo successfully\n");
239 }
240 if (drvInfo.isServer)
241 {
242 mos_set_platform_information(pDrmBufMgr, PLATFORM_INFORMATION_IS_SERVER);
243 }
244
245 /* disable it on Linux */
246 MEDIA_WR_SKU(skuTable, FtrPerCtxtPreemptionGranularityControl, 0);
247 MEDIA_WR_SKU(skuTable, FtrMediaThreadGroupLevelPreempt, 0);
248 MEDIA_WR_SKU(skuTable, FtrMediaMidBatchPreempt, 0);
249 MEDIA_WR_SKU(skuTable, FtrMediaMidThreadLevelPreempt, 0);
250 MEDIA_WR_SKU(skuTable, FtrGpGpuThreadGroupLevelPreempt, 0);
251 MEDIA_WR_SKU(skuTable, FtrGpGpuMidBatchPreempt, 0);
252 MEDIA_WR_SKU(skuTable, FtrGpGpuMidThreadLevelPreempt, 0);
253
254 #if (_DEBUG || _RELEASE_INTERNAL)
255 // User feature read to detect if simulation environment (MediaSolo) is enabled
256 MOS_ZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
257 MOS_UserFeature_ReadValue_ID(
258 nullptr,
259 __MEDIA_USER_FEATURE_VALUE_MEDIASOLO_ENABLE_ID,
260 &UserFeatureData,
261 (MOS_CONTEXT_HANDLE)nullptr);
262 //Disable plarform checks to support pre-si features (e.g., MMCD) on MediaSolo
263 MEDIA_WR_WA(waTable, WaDisregardPlatformChecks, (UserFeatureData.i32Data) ? true : false);
264 #endif
265
266 return MOS_STATUS_SUCCESS;
267 }
268
269 /*****************************************************************************\
270 Description:
271 Get the required Sku/Wa tables for GMM and platform information based on device Fd
272
273 Input:
274 fd - file descriptor to the /dev/dri/cardX
275 Output:
276 SHADOW_MEDIA_FEATURE_TABLE *shadowSkuTable
277 SHADOW_MEDIA_WA_TABLE *shadowWaTable,
278 MEDIA_SYSTEM_INFO *systemInfo
279 \*****************************************************************************/
HWInfo_GetGmmInfo(MOS_BUFMGR * pDrmBufMgr,SHADOW_MEDIA_FEATURE_TABLE * shadowSkuTable,SHADOW_MEDIA_WA_TABLE * shadowWaTable,MEDIA_SYSTEM_INFO * systemInfo)280 MOS_STATUS HWInfo_GetGmmInfo(MOS_BUFMGR *pDrmBufMgr,
281 SHADOW_MEDIA_FEATURE_TABLE *shadowSkuTable,
282 SHADOW_MEDIA_WA_TABLE *shadowWaTable,
283 MEDIA_SYSTEM_INFO *systemInfo)
284 {
285 if ((pDrmBufMgr == nullptr) ||
286 (shadowSkuTable == nullptr) ||
287 (shadowWaTable == nullptr) ||
288 (systemInfo == nullptr))
289 {
290 MOS_OS_ASSERTMESSAGE("Invalid parameter \n");
291 return MOS_STATUS_INVALID_PARAMETER;
292 }
293
294 LinuxDriverInfo drvInfo = {18, 3, 0, 23172, 3, 1, 0, 1, 0, 0, 1, 0};
295
296 if (!Mos_Solo_IsEnabled(nullptr) && mos_get_driver_info(pDrmBufMgr, &drvInfo))
297 {
298 MOS_OS_ASSERTMESSAGE("Failed to get the chipset id\n");
299 return MOS_STATUS_INVALID_HANDLE;
300 }
301
302 GfxDeviceInfo *devInfo = getDeviceInfo(drvInfo.devId);
303 if (devInfo == nullptr)
304 {
305 MOS_OS_ASSERTMESSAGE("Failed to get the device info for Device id: %x\n", drvInfo.devId);
306 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
307 }
308
309 if (devInfo->InitMediaSysInfo &&
310 devInfo->InitShadowSku &&
311 devInfo->InitShadowWa &&
312 devInfo->InitMediaSysInfo(devInfo, systemInfo) &&
313 devInfo->InitShadowSku(devInfo, shadowSkuTable, &drvInfo) &&
314 devInfo->InitShadowWa(devInfo, shadowWaTable, &drvInfo))
315 {
316 MOS_OS_NORMALMESSAGE("Init Media SystemInfo successfully\n");
317 }
318 else
319 {
320 MOS_OS_ASSERTMESSAGE("Failed to Init Media System Info\n");
321 return MOS_STATUS_PLATFORM_NOT_SUPPORTED;
322 }
323
324 return MOS_STATUS_SUCCESS;
325 }
326
327