Debian Codegraph @

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