Debian Codegraph @

media_driver/media_interface/media_interfaces_m9_kbl/media_interfaces_g9_kbl.cpp

raw
1 /*
2 * Copyright (c) 2017-2019, 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 media_interfaces_g9_kbl.cpp
24 //! \brief Helps with KBL factory creation.
25 //!
26
27 #include "media_interfaces_g9_kbl.h"
28 #if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE)
29 #include "igcodeckrn_g9.h"
30 #endif
31
32 extern template class MediaFactory<uint32_t, MhwInterfaces>;
33 extern template class MediaFactory<uint32_t, MmdDevice>;
34 extern template class MediaFactory<uint32_t, CodechalDevice>;
35 extern template class MediaFactory<uint32_t, CMHalDevice>;
36 extern template class MediaFactory<uint32_t, VphalDevice>;
37 extern template class MediaFactory<uint32_t, RenderHalDevice>;
38 extern template class MediaFactory<uint32_t, Nv12ToP010Device>;
39 extern template class MediaFactory<uint32_t, DecodeHistogramDevice>;
40
41 static bool kblRegisteredVphal =
42 MediaFactory<uint32_t, VphalDevice>::
43 Register<VphalInterfacesG9Kbl>((uint32_t)IGFX_KABYLAKE);
44
45 MOS_STATUS VphalInterfacesG9Kbl::Initialize(
46 PMOS_INTERFACE osInterface,
47 bool bInitVphalState,
48 MOS_STATUS *eStatus,
49 bool clearViewMode)
50 {
51 m_vpBase = MOS_New(
52 VphalState,
53 osInterface,
54 eStatus);
55
56 return *eStatus;
57 }
58
59 static bool kblRegisteredMhw =
60 MediaFactory<uint32_t, MhwInterfaces>::
61 Register<MhwInterfacesG9Kbl>((uint32_t)IGFX_KABYLAKE);
62
63 #define PLATFORM_INTEL_KBL 11
64 #define GENX_SKL 5
65
66 MOS_STATUS MhwInterfacesG9Kbl::Initialize(
67 CreateParams params,
68 PMOS_INTERFACE osInterface)
69 {
70 if (osInterface == nullptr)
71 {
72 MHW_ASSERTMESSAGE("The OS interface is not valid!");
73 return MOS_STATUS_INVALID_PARAMETER;
74 }
75
76 auto gtSystemInfo = osInterface->pfnGetGtSystemInfo(osInterface);
77 if (gtSystemInfo == nullptr)
78 {
79 MHW_ASSERTMESSAGE("The OS interface is not valid!");
80 return MOS_STATUS_INVALID_PARAMETER;
81 }
82
83 if ((params.m_isCp == false) && (params.Flags.m_value == 0))
84 {
85 MHW_ASSERTMESSAGE("No MHW interfaces were requested for creation.");
86 return MOS_STATUS_INVALID_PARAMETER;
87 }
88
89 // MHW_CP and MHW_MI must always be created
90 MOS_STATUS status;
91 m_cpInterface = osInterface->pfnCreateMhwCpInterface(osInterface);
92 m_miInterface = MOS_New(Mi, m_cpInterface, osInterface);
93
94 if (params.Flags.m_render)
95 {
96 m_renderInterface =
97 MOS_New(Render, m_miInterface, osInterface, gtSystemInfo, params.m_heapMode);
98 }
99 if (params.Flags.m_stateHeap)
100 {
101 m_stateHeapInterface =
102 MOS_New(StateHeap, osInterface, params.m_heapMode);
103 }
104 if (params.Flags.m_sfc)
105 {
106 m_sfcInterface = MOS_New(Sfc, osInterface);
107 }
108 if (params.Flags.m_vebox)
109 {
110 m_veboxInterface = MOS_New(Vebox, osInterface);
111 }
112
113 if (params.Flags.m_vdboxAll || params.Flags.m_mfx)
114 {
115 m_mfxInterface =
116 MOS_New(Mfx, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
117 }
118 if (params.Flags.m_vdboxAll || params.Flags.m_hcp)
119 {
120 m_hcpInterface =
121 MOS_New(Hcp, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
122 }
123 if (params.Flags.m_vdboxAll || params.Flags.m_huc)
124 {
125 m_hucInterface = MOS_New(Huc, osInterface, m_miInterface, m_cpInterface);
126 }
127 if (params.Flags.m_vdboxAll || params.Flags.m_vdenc)
128 {
129 m_vdencInterface = MOS_New(Vdenc, osInterface);
130 }
131
132 return MOS_STATUS_SUCCESS;
133 }
134 #if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE)
135 static bool kblRegisteredMmd =
136 MediaFactory<uint32_t, MmdDevice>::
137 Register<MmdDeviceG9Kbl>((uint32_t)IGFX_KABYLAKE);
138
139 MOS_STATUS MmdDeviceG9Kbl::Initialize(
140 PMOS_INTERFACE osInterface,
141 MhwInterfaces *mhwInterfaces)
142 {
143 #define MMD_FAILURE() \
144 { \
145 if (device != nullptr) \
146 { \
147 MOS_Delete(device); \
148 } \
149 return MOS_STATUS_NO_SPACE; \
150 }
151 MHW_FUNCTION_ENTER;
152
153 MhwMiInterface *miInterface = nullptr;
154 MhwRenderInterface *renderInterface = nullptr;
155 Mmd *device = nullptr;
156
157 if (mhwInterfaces->m_miInterface == nullptr)
158 {
159 MMD_FAILURE();
160 }
161 miInterface = mhwInterfaces->m_miInterface;
162
163 if (mhwInterfaces->m_renderInterface == nullptr)
164 {
165 MMD_FAILURE();
166 }
167 renderInterface = mhwInterfaces->m_renderInterface;
168
169 device = MOS_New(Mmd);
170
171 if (device == nullptr)
172 {
173 MMD_FAILURE();
174 }
175
176 if (device->Initialize(
177 osInterface,
178 mhwInterfaces->m_cpInterface,
179 miInterface,
180 renderInterface) != MOS_STATUS_SUCCESS)
181 {
182 MMD_FAILURE();
183 }
184
185 m_mmdDevice = device;
186
187 return MOS_STATUS_SUCCESS;
188 }
189 #endif
190 static bool kblRegisteredNv12ToP010 =
191 MediaFactory<uint32_t, Nv12ToP010Device>::
192 Register<Nv12ToP010DeviceG9Kbl>((uint32_t)IGFX_KABYLAKE);
193
194 MOS_STATUS Nv12ToP010DeviceG9Kbl::Initialize(
195 PMOS_INTERFACE osInterface)
196 {
197 m_nv12ToP010device = MOS_New(Nv12ToP010, osInterface);
198
199 if (m_nv12ToP010device == nullptr)
200 {
201 MHW_ASSERTMESSAGE("Create Nv12 to P010 interfaces failed.")
202 return MOS_STATUS_NO_SPACE;
203 }
204
205 return MOS_STATUS_SUCCESS;
206 }
207
208 static bool kblRegisteredCodecHal =
209 MediaFactory<uint32_t, CodechalDevice>::
210 Register<CodechalInterfacesG9Kbl>((uint32_t)IGFX_KABYLAKE);
211
212 MOS_STATUS CodechalInterfacesG9Kbl::Initialize(
213 void *standardInfo,
214 void *settings,
215 MhwInterfaces *mhwInterfaces,
216 PMOS_INTERFACE osInterface)
217 {
218 if (standardInfo == nullptr ||
219 mhwInterfaces == nullptr ||
220 osInterface == nullptr)
221 {
222 CODECHAL_PUBLIC_ASSERTMESSAGE("CodecHal device is not valid!");
223 return MOS_STATUS_INVALID_PARAMETER;
224 }
225 PCODECHAL_STANDARD_INFO info = ((PCODECHAL_STANDARD_INFO)standardInfo);
226 CODECHAL_FUNCTION CodecFunction = info->CodecFunction;
227
228 CodechalHwInterface *hwInterface = MOS_New(Hw, osInterface, CodecFunction, mhwInterfaces);
229
230 if (hwInterface == nullptr)
231 {
232 CODECHAL_PUBLIC_ASSERTMESSAGE("hwInterface is not valid!");
233 return MOS_STATUS_NO_SPACE;
234 }
235 #if USE_CODECHAL_DEBUG_TOOL
236 CodechalDebugInterface *debugInterface = MOS_New(CodechalDebugInterface);
237 if (debugInterface == nullptr)
238 {
239 MOS_Delete(hwInterface);
240 mhwInterfaces->SetDestroyState(true);
241 CODECHAL_PUBLIC_ASSERTMESSAGE("debugInterface is not valid!");
242 return MOS_STATUS_NO_SPACE;
243 }
244 if (debugInterface->Initialize(hwInterface, CodecFunction) != MOS_STATUS_SUCCESS)
245 {
246 MOS_Delete(hwInterface);
247 mhwInterfaces->SetDestroyState(true);
248 MOS_Delete(debugInterface);
249 CODECHAL_PUBLIC_ASSERTMESSAGE("Debug interface creation failed!");
250 return MOS_STATUS_INVALID_PARAMETER;
251 }
252 #else
253 CodechalDebugInterface *debugInterface = nullptr;
254 #endif // USE_CODECHAL_DEBUG_TOOL
255
256 if (CodecHalIsDecode(CodecFunction))
257 {
258 #ifdef _MPEG2_DECODE_SUPPORTED
259 if (info->Mode == CODECHAL_DECODE_MODE_MPEG2IDCT ||
260 info->Mode == CODECHAL_DECODE_MODE_MPEG2VLD)
261 {
262 m_codechalDevice = MOS_New(Decode::Mpeg2, hwInterface, debugInterface, info);
263 }
264 else
265 #endif
266 #ifdef _VC1_DECODE_SUPPORTED
267 if (info->Mode == CODECHAL_DECODE_MODE_VC1IT ||
268 info->Mode == CODECHAL_DECODE_MODE_VC1VLD)
269 {
270 m_codechalDevice = MOS_New(Decode::Vc1, hwInterface, debugInterface, info);
271 }
272 else
273 #endif
274 #ifdef _AVC_DECODE_SUPPORTED
275 if (info->Mode == CODECHAL_DECODE_MODE_AVCVLD)
276 {
277 m_codechalDevice = MOS_New(Decode::Avc, hwInterface, debugInterface, info);
278
279 if (m_codechalDevice == nullptr)
280 {
281 CODECHAL_PUBLIC_ASSERTMESSAGE("Failed to create decode device!");
282 return MOS_STATUS_NO_SPACE;
283 }
284 #ifdef _DECODE_PROCESSING_SUPPORTED
285 if (settings != nullptr && ((CodechalSetting *)settings)->downsamplingHinted)
286 {
287 CodechalDecode *decoder = dynamic_cast<CodechalDecode *>(m_codechalDevice);
288 if (decoder == nullptr)
289 {
290 CODECHAL_PUBLIC_ASSERTMESSAGE("Failed to create decode device!");
291 return MOS_STATUS_NO_SPACE;
292 }
293 FieldScalingInterface *fieldScalingInterface =
294 MOS_New(Decode::FieldScaling, hwInterface);
295 if (fieldScalingInterface == nullptr)
296 {
297 CODECHAL_PUBLIC_ASSERTMESSAGE("Failed to create field scaling interface!");
298 return MOS_STATUS_NO_SPACE;
299 }
300 decoder->m_fieldScalingInterface = fieldScalingInterface;
301 }
302 #endif
303 }
304 else
305 #endif
306 #ifdef _JPEG_DECODE_SUPPORTED
307 if (info->Mode == CODECHAL_DECODE_MODE_JPEG)
308 {
309 m_codechalDevice = MOS_New(Decode::Jpeg, hwInterface, debugInterface, info);
310 }
311 else
312 #endif
313 #ifdef _VP8_DECODE_SUPPORTED
314 if (info->Mode == CODECHAL_DECODE_MODE_VP8VLD)
315 {
316 m_codechalDevice = MOS_New(Decode::Vp8, hwInterface, debugInterface, info);
317 }
318 else
319 #endif
320 #ifdef _HEVC_DECODE_SUPPORTED
321 if (info->Mode == CODECHAL_DECODE_MODE_HEVCVLD)
322 {
323 m_codechalDevice = MOS_New(Decode::Hevc, hwInterface, debugInterface, info);
324 }
325 else
326 #endif
327 #ifdef _VP9_DECODE_SUPPORTED
328 if (info->Mode == CODECHAL_DECODE_MODE_VP9VLD)
329 {
330 m_codechalDevice = MOS_New(Decode::Vp9, hwInterface, debugInterface, info);
331 }
332 else
333 #endif
334 {
335 CODECHAL_PUBLIC_ASSERTMESSAGE("Decode mode requested invalid!");
336 return MOS_STATUS_INVALID_PARAMETER;
337 }
338
339 if (m_codechalDevice == nullptr)
340 {
341 MOS_Delete(hwInterface);
342 mhwInterfaces->SetDestroyState(true);
343 #if USE_CODECHAL_DEBUG_TOOL
344 MOS_Delete(debugInterface);
345 #endif
346 CODECHAL_PUBLIC_ASSERTMESSAGE("Decoder device creation failed!");
347 return MOS_STATUS_NO_SPACE;
348 }
349 }
350 else if (CodecHalIsEncode(CodecFunction))
351 {
352 CodechalEncoderState* encoder = nullptr;
353 #ifdef _MPEG2_ENCODE_VME_SUPPORTED
354 if (info->Mode == CODECHAL_ENCODE_MODE_MPEG2)
355 {
356 // Setup encode interface functions
357 encoder = MOS_New(Encode::Mpeg2, hwInterface, debugInterface, info);
358 if (encoder == nullptr)
359 {
360 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode allocation failed!");
361 return MOS_STATUS_INVALID_PARAMETER;
362 }
363 else
364 {
365 m_codechalDevice = encoder;
366 }
367
368 encoder->m_kernelBase = (uint8_t*)IGCODECKRN_G9;
369 }
370 else
371 #endif
372 #ifdef _JPEG_ENCODE_SUPPORTED
373 if (info->Mode == CODECHAL_ENCODE_MODE_JPEG)
374 {
375 encoder = MOS_New(Encode::Jpeg, hwInterface, debugInterface, info);
376 if (encoder == nullptr)
377 {
378 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
379 return MOS_STATUS_INVALID_PARAMETER;
380 }
381 else
382 {
383 m_codechalDevice = encoder;
384 }
385 encoder->m_needCheckCpEnabled = true;
386 }
387 else
388 #endif
389 #ifdef _HEVC_ENCODE_VME_SUPPORTED
390 if (info->Mode == CODECHAL_ENCODE_MODE_HEVC)
391 {
392 encoder = MOS_New(Encode::HevcEnc, hwInterface, debugInterface, info);
393 if (encoder == nullptr)
394 {
395 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
396 return MOS_STATUS_INVALID_PARAMETER;
397 }
398 else
399 {
400 m_codechalDevice = encoder;
401 }
402
403 encoder->m_kernelBase = (uint8_t*)IGCODECKRN_G9;
404 }
405 else
406 #endif
407 #if defined (_AVC_ENCODE_VME_SUPPORTED) || defined (_AVC_ENCODE_VDENC_SUPPORTED)
408 if (info->Mode == CODECHAL_ENCODE_MODE_AVC)
409 {
410 if (CodecHalUsesVdencEngine(info->CodecFunction))
411 {
412 #ifdef _AVC_ENCODE_VDENC_SUPPORTED
413 encoder = MOS_New(Encode::AvcVdenc, hwInterface, debugInterface, info);
414 #endif
415 }
416 else
417 {
418 #ifdef _AVC_ENCODE_VME_SUPPORTED
419 encoder = MOS_New(Encode::AvcEnc, hwInterface, debugInterface, info);
420 #endif
421 }
422 if (encoder == nullptr)
423 {
424 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
425 return MOS_STATUS_INVALID_PARAMETER;
426 }
427 else
428 {
429 m_codechalDevice = encoder;
430 }
431 }
432 else
433 #endif
434 #ifdef _VP8_ENCODE_SUPPORTED
435 if (info->Mode == CODECHAL_ENCODE_MODE_VP8)
436 {
437 // Setup encode interface functions
438 encoder = MOS_New(Encode::Vp8, hwInterface, debugInterface, info);
439 if (encoder == nullptr)
440 {
441 CODECHAL_PUBLIC_ASSERTMESSAGE("VP8 Encode allocation failed!");
442 return MOS_STATUS_INVALID_PARAMETER;
443 }
444 else
445 {
446 m_codechalDevice = encoder;
447 }
448 }
449 else
450 #endif
451 {
452 CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported encode function requested.");
453 return MOS_STATUS_INVALID_PARAMETER;
454 }
455 #if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE)
456 if (info->Mode != CODECHAL_ENCODE_MODE_JPEG)
457 {
458 // Create CSC and Downscaling interface
459 if ((encoder->m_cscDsState = MOS_New(Encode::CscDs, encoder)) == nullptr)
460 {
461 return MOS_STATUS_INVALID_PARAMETER;
462 }
463 }
464 #endif
465 }
466 else
467 {
468 CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported codec function requested.");
469 return MOS_STATUS_INVALID_PARAMETER;
470 }
471
472 return MOS_STATUS_SUCCESS;
473 }
474
475 static bool kblRegisteredCMHal =
476 MediaFactory<uint32_t, CMHalDevice>::
477 Register<CMHalInterfacesG9Kbl>((uint32_t)IGFX_KABYLAKE);
478
479 MOS_STATUS CMHalInterfacesG9Kbl::Initialize(CM_HAL_STATE *pCmState)
480 {
481 if (pCmState == nullptr)
482 {
483 MHW_ASSERTMESSAGE("pCmState is nullptr.")
484 return MOS_STATUS_INVALID_PARAMETER;
485 }
486
487 m_cmhalDevice = MOS_New(CMHal, pCmState);
488 if (m_cmhalDevice == nullptr)
489 {
490 MHW_ASSERTMESSAGE("Create CM Hal interfaces failed.")
491 return MOS_STATUS_NO_SPACE;
492 }
493
494 int gengt = PLATFORM_INTEL_GT2;
495 if (MEDIA_IS_SKU(pCmState->skuTable, FtrGT1))
496 {
497 gengt = PLATFORM_INTEL_GT1;
498 }
499 else if (MEDIA_IS_SKU(pCmState->skuTable, FtrGT1_5))
500 {
501 gengt = PLATFORM_INTEL_GT1_5;
502 }
503 else if (MEDIA_IS_SKU(pCmState->skuTable, FtrGT2))
504 {
505 gengt = PLATFORM_INTEL_GT2;
506 }
507 else if (MEDIA_IS_SKU(pCmState->skuTable, FtrGT3))
508 {
509 gengt = PLATFORM_INTEL_GT3;
510 }
511 else if (MEDIA_IS_SKU(pCmState->skuTable, FtrGT4))
512 {
513 gengt = PLATFORM_INTEL_GT4;
514 }
515
516 m_cmhalDevice->SetGenPlatformInfo(PLATFORM_INTEL_KBL, gengt, "SKL");
517 uint32_t cisaID = GENX_SKL;
518 m_cmhalDevice->AddSupportedCisaIDs(&cisaID);
519
520 CM_HAL_G9_X *pGen9Device = static_cast<CM_HAL_G9_X *>(m_cmhalDevice);
521 const char *CmSteppingInfo_KBL[] = { "A0", "B0", "C0", "D0", "E0" };
522 pGen9Device->OverwriteSteppingTable(CmSteppingInfo_KBL, sizeof(CmSteppingInfo_KBL)/sizeof(const char *));
523 return MOS_STATUS_SUCCESS;
524 }
525
526 static bool kblRegisteredRenderHal =
527 MediaFactory<uint32_t, RenderHalDevice>::
528 Register<RenderHalInterfacesG9Kbl>((uint32_t)IGFX_KABYLAKE);
529
530 MOS_STATUS RenderHalInterfacesG9Kbl::Initialize()
531 {
532 m_renderhalDevice = MOS_New(XRenderHal);
533 if (m_renderhalDevice == nullptr)
534 {
535 MHW_ASSERTMESSAGE("Create Render Hal interfaces failed.")
536 return MOS_STATUS_NO_SPACE;
537 }
538 return MOS_STATUS_SUCCESS;
539 }
540
541 static bool kblRegisteredDecodeHistogram =
542 MediaFactory<uint32_t, DecodeHistogramDevice>::
543 Register<DecodeHistogramDeviceG9Kbl>((uint32_t)IGFX_KABYLAKE);
544
545 MOS_STATUS DecodeHistogramDeviceG9Kbl::Initialize(
546 CodechalHwInterface *hwInterface,
547 PMOS_INTERFACE osInterface)
548 {
549 m_decodeHistogramDevice = MOS_New(DecodeHistogramVebox, hwInterface, osInterface);
550
551 if (m_decodeHistogramDevice == nullptr)
552 {
553 MHW_ASSERTMESSAGE("Create vebox decode histogram interfaces failed.")
554 return MOS_STATUS_NO_SPACE;
555 }
556
557 return MOS_STATUS_SUCCESS;
558 }
559
560 #define IP_VERSION_M9_0 0x0900
561 static bool kblRegisteredHwInfo =
562 MediaFactory<uint32_t, MediaInterfacesHwInfoDevice>::Register<MediaInterfacesHwInfoDeviceG9Kbl>((uint32_t)IGFX_KABYLAKE);
563
564 MOS_STATUS MediaInterfacesHwInfoDeviceG9Kbl::Initialize(PLATFORM platform)
565 {
566 m_hwInfo.SetDeviceInfo(IP_VERSION_M9_0, platform.usRevId);
567 return MOS_STATUS_SUCCESS;
568 }