1 /*
2 * Copyright (c) 2021, 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 codechal_common.cpp
24 //! \brief Impelements the public interface for CodecHal.
25 //! \details
26 //!
27
28 #include "codechal_common.h"
29 #include "codec_hw_next.h"
30 #include "codechal_debug.h"
31 #include "mos_solo_generic.h"
32 #include "codechal_setting.h"
33
Codechal(CodechalHwInterfaceNext * hwInterface,CodechalDebugInterface * debugInterface)34 Codechal::Codechal(
35 CodechalHwInterfaceNext *hwInterface,
36 CodechalDebugInterface *debugInterface)
37 {
38 CODECHAL_PUBLIC_FUNCTION_ENTER;
39 if (hwInterface)
40 {
41 CODECHAL_PUBLIC_CHK_NULL_NO_STATUS_RETURN(hwInterface->GetOsInterface());
42 MOS_UNUSED(debugInterface);
43
44 m_hwInterface = hwInterface;
45 m_osInterface = hwInterface->GetOsInterface();
46
47 m_userSettingPtr = m_osInterface->pfnGetUserSettingInstance(m_osInterface);
48 ;
49 }
50 #if USE_CODECHAL_DEBUG_TOOL
51 CODECHAL_PUBLIC_CHK_NULL_NO_STATUS_RETURN(debugInterface);
52 m_debugInterface = debugInterface;
53 #endif // USE_CODECHAL_DEBUG_TOOL
54
55
56 }
57
~Codechal()58 Codechal::~Codechal()
59 {
60 CODECHAL_PUBLIC_FUNCTION_ENTER;
61
62 MOS_TraceEvent(EVENT_CODECHAL_DESTROY, EVENT_TYPE_START, nullptr, 0, nullptr, 0);
63
64 #if USE_CODECHAL_DEBUG_TOOL
65 if (m_debugInterface != nullptr)
66 {
67 MOS_Delete(m_debugInterface);
68 m_debugInterface = nullptr;
69 }
70
71 if (m_statusReportDebugInterface != nullptr)
72 {
73 MOS_Delete(m_statusReportDebugInterface);
74 m_statusReportDebugInterface = nullptr;
75 }
76 #endif // USE_CODECHAL_DEBUG_TOOL
77
78 // Destroy HW interface objects (GSH, SSH, etc)
79 if (m_hwInterface != nullptr)
80 {
81 MOS_Delete(m_hwInterface);
82 m_hwInterface = nullptr;
83 }
84
85 // Destroy OS interface objects (CBs, etc)
86 if (m_osInterface != nullptr)
87 {
88 m_osInterface->pfnDestroy(m_osInterface, false);
89
90 // Deallocate OS interface structure (except if externally provided)
91 if (m_osInterface->bDeallocateOnExit)
92 {
93 MOS_FreeMemory(m_osInterface);
94 }
95 }
96
97 MOS_TraceEvent(EVENT_CODECHAL_DESTROY, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
98 }
99
Allocate(CodechalSetting * codecHalSettings)100 MOS_STATUS Codechal::Allocate(CodechalSetting *codecHalSettings)
101 {
102 CODECHAL_PUBLIC_FUNCTION_ENTER;
103
104 CODECHAL_PUBLIC_CHK_NULL_RETURN(codecHalSettings);
105 CODECHAL_PUBLIC_CHK_NULL_RETURN(m_hwInterface);
106 CODECHAL_PUBLIC_CHK_NULL_RETURN(m_osInterface);
107
108 MOS_TraceEvent(EVENT_CODECHAL_CREATE,
109 EVENT_TYPE_INFO,
110 &codecHalSettings->codecFunction,
111 sizeof(uint32_t),
112 nullptr,
113 0);
114
115 CODECHAL_PUBLIC_CHK_STATUS_RETURN(m_hwInterface->Initialize(codecHalSettings));
116
117 MOS_NULL_RENDERING_FLAGS nullHWAccelerationEnable;
118 nullHWAccelerationEnable.Value = 0;
119
120 #if (_DEBUG || _RELEASE_INTERNAL)
121 if (!m_statusReportDebugInterface)
122 {
123 m_statusReportDebugInterface = MOS_New(CodechalDebugInterface);
124 CODECHAL_PUBLIC_CHK_NULL_RETURN(m_statusReportDebugInterface);
125 CODECHAL_PUBLIC_CHK_STATUS_RETURN(
126 m_statusReportDebugInterface->Initialize(m_hwInterface, codecHalSettings->codecFunction));
127 }
128
129 ReadUserSettingForDebug(
130 m_userSettingPtr,
131 nullHWAccelerationEnable.Value,
132 __MEDIA_USER_FEATURE_VALUE_NULL_HW_ACCELERATION_ENABLE,
133 MediaUserSetting::Group::Device);
134
135 m_useNullHw[MOS_GPU_CONTEXT_VIDEO] =
136 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVideo);
137 m_useNullHw[MOS_GPU_CONTEXT_VIDEO2] =
138 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVideo2);
139 m_useNullHw[MOS_GPU_CONTEXT_VIDEO3] =
140 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVideo3);
141 m_useNullHw[MOS_GPU_CONTEXT_VDBOX2_VIDEO] =
142 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVDBox2Video);
143 m_useNullHw[MOS_GPU_CONTEXT_VDBOX2_VIDEO2] =
144 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVDBox2Video2);
145 m_useNullHw[MOS_GPU_CONTEXT_VDBOX2_VIDEO3] =
146 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxVDBox2Video3);
147 m_useNullHw[MOS_GPU_CONTEXT_RENDER] =
148 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxRender);
149 m_useNullHw[MOS_GPU_CONTEXT_RENDER2] =
150 (nullHWAccelerationEnable.CodecGlobal || nullHWAccelerationEnable.CtxRender2);
151 #endif // _DEBUG || _RELEASE_INTERNAL
152
153 return MOS_STATUS_SUCCESS;
154 }
155
BeginFrame()156 MOS_STATUS Codechal::BeginFrame()
157 {
158 CODECHAL_PUBLIC_FUNCTION_ENTER;
159 return MOS_STATUS_SUCCESS;
160 }
161
EndFrame()162 MOS_STATUS Codechal::EndFrame()
163 {
164 CODECHAL_PUBLIC_FUNCTION_ENTER;
165 return MOS_STATUS_SUCCESS;
166 }
167
Reformat()168 MOS_STATUS Codechal::Reformat()
169 {
170 CODECHAL_PUBLIC_FUNCTION_ENTER;
171 return MOS_STATUS_SUCCESS;
172 }
173
Execute(void * params)174 MOS_STATUS Codechal::Execute(void *params)
175 {
176 CODECHAL_PUBLIC_FUNCTION_ENTER;
177
178 CODECHAL_PUBLIC_CHK_NULL_RETURN(params);
179
180 CODECHAL_DEBUG_TOOL(
181 CODECHAL_PUBLIC_CHK_NULL_RETURN(m_osInterface);
182 CODECHAL_PUBLIC_CHK_NULL_RETURN(m_debugInterface);
183
184 CODECHAL_PUBLIC_CHK_STATUS_RETURN(Mos_Solo_ForceDumps(
185 m_debugInterface->m_bufferDumpFrameNum,
186 m_osInterface));)
187
188 return MOS_STATUS_SUCCESS;
189 }
190
GetStatusReport(void * status,uint16_t numStatus)191 MOS_STATUS Codechal::GetStatusReport(
192 void *status,
193 uint16_t numStatus)
194 {
195 CODECHAL_PUBLIC_FUNCTION_ENTER;
196 MOS_UNUSED(status);
197 MOS_UNUSED(numStatus);
198 CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported codec function requested.");
199 return MOS_STATUS_UNKNOWN;
200 }
201
Destroy()202 void Codechal::Destroy()
203 {
204 CODECHAL_PUBLIC_FUNCTION_ENTER;
205 }
206
ResolveMetaData(PMOS_RESOURCE pInput,PMOS_RESOURCE pOutput)207 MOS_STATUS Codechal::ResolveMetaData(PMOS_RESOURCE pInput, PMOS_RESOURCE pOutput)
208 {
209 return MOS_STATUS_SUCCESS;
210 }
211
ReportErrorFlag(PMOS_RESOURCE pMetadataBuffer,uint32_t size,uint32_t offset,uint32_t flag)212 MOS_STATUS Codechal::ReportErrorFlag(PMOS_RESOURCE pMetadataBuffer, uint32_t size,
213 uint32_t offset, uint32_t flag)
214 {
215 return MOS_STATUS_SUCCESS;
216 }
217