| 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 mos_oca_specific.cpp |
| 24 |
//! \brief Linux specfic OCA class |
| 25 |
//! |
| 26 |
|
| 27 |
#include "mos_os.h" |
| 28 |
#include "mos_os_specific.h" |
| 29 |
#include "mos_oca_interface_specific.h" |
| 30 |
#include "mos_util_debug.h" |
| 31 |
#include "mos_utilities.h" |
| 32 |
#include <algorithm> |
| 33 |
|
| 34 |
//! |
| 35 |
//! \def MOS_OCA_CHK_NULL_RETURN(_ptr) |
| 36 |
//! Check if _ptr == nullptr. If so, assert, return an error and update LastErrorStatus. |
| 37 |
//! Should only be used by interface functions in MosOcaInterface. |
| 38 |
//! |
| 39 |
#define MOS_OCA_CHK_NULL_RETURN(mosCtx, _ptr, func, line) \ |
| 40 |
{ \ |
| 41 |
if ((_ptr) == nullptr) \ |
| 42 |
{ \ |
| 43 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, MOS_STATUS_NULL_POINTER, func, line); \ |
| 44 |
return MOS_STATUS_NULL_POINTER; \ |
| 45 |
} \ |
| 46 |
} |
| 47 |
|
| 48 |
//! |
| 49 |
//! \def MOS_OCA_CHK_STATUS_RETURN(_stmt) |
| 50 |
//! Check if MOS_STATUS_SUCCESS != _stmt. If so, assert, return an error and update LastErrorStatus. |
| 51 |
//! Should only be used by interface functions in MosOcaInterface. |
| 52 |
//! |
| 53 |
#define MOS_OCA_CHK_STATUS_RETURN(mosCtx, _stmt, func, line) \ |
| 54 |
{ \ |
| 55 |
MOS_STATUS stmtStatus = (MOS_STATUS)(_stmt); \ |
| 56 |
if (stmtStatus != MOS_STATUS_SUCCESS) \ |
| 57 |
{ \ |
| 58 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, stmtStatus, func, line); \ |
| 59 |
return stmtStatus; \ |
| 60 |
} \ |
| 61 |
} |
| 62 |
|
| 63 |
/****************************************************************************************************/ |
| 64 |
/* MosOcaInterfaceSpecific */ |
| 65 |
/****************************************************************************************************/ |
| 66 |
|
| 67 |
|
| 68 |
MOS_STATUS MosOcaInterfaceSpecific::s_ocaStatus = MOS_STATUS_SUCCESS; |
| 69 |
uint32_t MosOcaInterfaceSpecific::s_lineNumForOcaErr = 0; |
| 70 |
bool MosOcaInterfaceSpecific::s_bOcaStatusExistInReg = false; |
| 71 |
int32_t MosOcaInterfaceSpecific::s_refCount = 0; |
| 72 |
bool MosOcaInterfaceSpecific::s_isDestroyed = false; |
| 73 |
|
| 74 |
//! |
| 75 |
//! \brief Get the idle oca buffer, which is neither used by hw nor locked, and lock it for edit. |
| 76 |
//! \param [in] pMosContext |
| 77 |
//! pointer to MOS_INTERFACE |
| 78 |
//! \param [in] CurrentGpuContextHandle |
| 79 |
//! Gpu context handle |
| 80 |
//! \return MOS_OCA_BUFFER_HANDLE |
| 81 |
//! return the handle for oca buffer |
| 82 |
//! |
| 83 |
MOS_OCA_BUFFER_HANDLE MosOcaInterfaceSpecific::LockOcaBufAvailable(PMOS_CONTEXT pMosContext, uint32_t CurrentGpuContextHandle) |
| 84 |
{ |
| 85 |
if (nullptr == m_ocaMutex) |
| 86 |
{ |
| 87 |
MosOcaInterfaceSpecific::OnOcaError(pMosContext, MOS_STATUS_NULL_POINTER, __FUNCTION__, __LINE__); |
| 88 |
return MOS_OCA_INVALID_BUFFER_HANDLE; |
| 89 |
} |
| 90 |
|
| 91 |
MosOcaAutoLock autoLock(m_ocaMutex); |
| 92 |
for (int i = m_indexOfNextOcaBufContext; i < MAX_NUM_OF_OCA_BUF_CONTEXT; ++i) |
| 93 |
{ |
| 94 |
if (m_ocaBufContextList[i].inUse) |
| 95 |
{ |
| 96 |
continue; |
| 97 |
} |
| 98 |
m_ocaBufContextList[i].inUse = true; |
| 99 |
m_ocaBufContextList[i].logSection.resInfo.maxResInfoCount = m_config.maxResInfoCount; |
| 100 |
m_ocaBufContextList[i].logSection.resInfo.maxBufferResInfoCount = m_config.maxBufferResInfoCount; |
| 101 |
m_indexOfNextOcaBufContext = (i + 1) % MAX_NUM_OF_OCA_BUF_CONTEXT; |
| 102 |
return i; |
| 103 |
} |
| 104 |
|
| 105 |
for (int i = 0; i < m_indexOfNextOcaBufContext; ++i) |
| 106 |
{ |
| 107 |
if (m_ocaBufContextList[i].inUse) |
| 108 |
{ |
| 109 |
continue; |
| 110 |
} |
| 111 |
m_ocaBufContextList[i].inUse = true; |
| 112 |
m_ocaBufContextList[i].logSection.resInfo.maxResInfoCount = m_config.maxResInfoCount; |
| 113 |
m_ocaBufContextList[i].logSection.resInfo.maxBufferResInfoCount = m_config.maxBufferResInfoCount; |
| 114 |
m_indexOfNextOcaBufContext = (i + 1) % MAX_NUM_OF_OCA_BUF_CONTEXT; |
| 115 |
return i; |
| 116 |
} |
| 117 |
MosOcaInterfaceSpecific::OnOcaError(pMosContext, MOS_STATUS_INVALID_PARAMETER, __FUNCTION__, __LINE__); |
| 118 |
return MOS_OCA_INVALID_BUFFER_HANDLE; |
| 119 |
} |
| 120 |
|
| 121 |
//! |
| 122 |
//! \brief Unlock the oca buffer when edit complete. |
| 123 |
//! \param [in] ocaBufHandle |
| 124 |
//! Oca buffer handle. |
| 125 |
//! \return MOS_STATUS |
| 126 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 127 |
//! |
| 128 |
MOS_STATUS MosOcaInterfaceSpecific::UnlockOcaBuf(MOS_OCA_BUFFER_HANDLE ocaBufHandle) |
| 129 |
{ |
| 130 |
if (ocaBufHandle >= MAX_NUM_OF_OCA_BUF_CONTEXT) |
| 131 |
{ |
| 132 |
return MOS_STATUS_INVALID_PARAMETER; |
| 133 |
} |
| 134 |
m_ocaBufContextList[ocaBufHandle].logSection.offset = 0; |
| 135 |
m_ocaBufContextList[ocaBufHandle].logSection.base = nullptr; |
| 136 |
m_ocaBufContextList[ocaBufHandle].inUse = false; |
| 137 |
m_ocaBufContextList[ocaBufHandle].is1stLevelBBStarted = false; |
| 138 |
return MOS_STATUS_SUCCESS; |
| 139 |
} |
| 140 |
|
| 141 |
MOS_STATUS MosOcaInterfaceSpecific::UnlockOcaBufferWithDelay(MOS_OCA_BUFFER_HANDLE ocaBufHandle) |
| 142 |
{ |
| 143 |
if (ocaBufHandle >= MAX_NUM_OF_OCA_BUF_CONTEXT) |
| 144 |
{ |
| 145 |
return MOS_STATUS_INVALID_PARAMETER; |
| 146 |
} |
| 147 |
|
| 148 |
MosOcaAutoLock lock(m_mutexForOcaBufPool); |
| 149 |
m_PendingOcaBuffersToUnlock.push_back(ocaBufHandle); |
| 150 |
return MOS_STATUS_SUCCESS; |
| 151 |
} |
| 152 |
|
| 153 |
void MosOcaInterfaceSpecific::UnlockPendingOcaBuffers(PMOS_CONTEXT mosCtx, struct MOS_OCA_EXEC_LIST_INFO *info, int count) |
| 154 |
{ |
| 155 |
MosOcaAutoLock lock(m_mutexForOcaBufPool); |
| 156 |
if(m_PendingOcaBuffersToUnlock.size() > 1) |
| 157 |
{ |
| 158 |
MOS_OS_NORMALMESSAGE("size of pending oca buffer > 1"); |
| 159 |
} |
| 160 |
for (auto it = m_PendingOcaBuffersToUnlock.begin(); |
| 161 |
it != m_PendingOcaBuffersToUnlock.end(); ++it) |
| 162 |
{ |
| 163 |
// Other information to log section, which is only captured after BB end, can be added here. |
| 164 |
if(mosCtx != nullptr && info != nullptr && count > 0) |
| 165 |
{ |
| 166 |
AddExecListInfoToLogSection(*it, mosCtx, info, count); |
| 167 |
} |
| 168 |
UnlockOcaBuf(*it); |
| 169 |
} |
| 170 |
m_PendingOcaBuffersToUnlock.clear(); |
| 171 |
} |
| 172 |
|
| 173 |
//! |
| 174 |
//! \brief Oca operation which should be called at the beginning of 1st level batch buffer start. |
| 175 |
//! \param [out] gpuVaOcaBuffer |
| 176 |
//! The gfx virtual address of oca buffer, which should be set to GPR11 by LRI at the |
| 177 |
//! beginning of 1st level batch buffer no matter return value is MOS_STATUS_SUCCESS or not. |
| 178 |
//! \param [in] ocaBufHandle |
| 179 |
//! Oca buffer handle. |
| 180 |
//! \param [in] pMosContext |
| 181 |
//! Pointer to MOS_CONTEXT. |
| 182 |
//! \param [in] pMosResource |
| 183 |
//! Pointer to the MOS_RESOURCE. |
| 184 |
//! \param [in] offsetOf1stLevelBB |
| 185 |
//! Offset for current BB in pMosResource. |
| 186 |
//! \param [in] bUseSizeOfResource |
| 187 |
//! If true, use size of pMosResource for batch buffer, else use sizeOf1stLevelBB. |
| 188 |
//! \param [in] sizeOf1stLevelBB |
| 189 |
//! Size of BB. Ignore if bUseSizeOfResource == true. |
| 190 |
//! \return MOS_STATUS |
| 191 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 192 |
//! |
| 193 |
MOS_STATUS MosOcaInterfaceSpecific::On1stLevelBBStart(uint64_t &gpuVaOcaBuffer, MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT pMosContext, void *pMosResource, uint32_t offsetOf1stLevelBB, bool bUseSizeOfResource, uint32_t sizeOf1stLevelBB) |
| 194 |
{ |
| 195 |
// The GPR11 need to be reset to 0 to disable UMD_OCA for current workload if any error happened. |
| 196 |
gpuVaOcaBuffer = 0; |
| 197 |
if (!m_isOcaEnabled) |
| 198 |
{ |
| 199 |
return MOS_STATUS_SUCCESS; |
| 200 |
} |
| 201 |
|
| 202 |
PMOS_RESOURCE pOsResource = (PMOS_RESOURCE)pMosResource; |
| 203 |
if (ocaBufHandle >= MAX_NUM_OF_OCA_BUF_CONTEXT) |
| 204 |
{ |
| 205 |
MosOcaInterfaceSpecific::OnOcaError(pMosContext, MOS_STATUS_INVALID_PARAMETER, __FUNCTION__, __LINE__); |
| 206 |
return MOS_STATUS_INVALID_PARAMETER; |
| 207 |
} |
| 208 |
|
| 209 |
m_ocaBufContextList[ocaBufHandle].is1stLevelBBStarted = true; |
| 210 |
InitLogSection(ocaBufHandle, pOsResource); |
| 211 |
return MOS_STATUS_SUCCESS; |
| 212 |
} |
| 213 |
|
| 214 |
//! |
| 215 |
//! \brief Oca operation which should be called before adding batch buffer end command for 1st |
| 216 |
//! level batch buffer. |
| 217 |
//! \param [in] ocaBufHandle |
| 218 |
//! Oca buffer handle. |
| 219 |
//! \param [in] mosCtx |
| 220 |
//! DDI device context. |
| 221 |
//! \return MOS_STATUS |
| 222 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 223 |
//! |
| 224 |
MOS_STATUS MosOcaInterfaceSpecific::On1stLevelBBEnd(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx) |
| 225 |
{ |
| 226 |
if (!m_isOcaEnabled) |
| 227 |
{ |
| 228 |
return MOS_STATUS_SUCCESS; |
| 229 |
} |
| 230 |
if (ocaBufHandle >= MAX_NUM_OF_OCA_BUF_CONTEXT) |
| 231 |
{ |
| 232 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, MOS_STATUS_INVALID_PARAMETER, __FUNCTION__, __LINE__); |
| 233 |
return MOS_STATUS_INVALID_PARAMETER; |
| 234 |
} |
| 235 |
|
| 236 |
if (!m_ocaBufContextList[ocaBufHandle].is1stLevelBBStarted) |
| 237 |
{ |
| 238 |
MOS_OS_ASSERTMESSAGE("On1stLevelBBEnd is called without On1stLevelBBStart being called!"); |
| 239 |
return MOS_STATUS_INVALID_PARAMETER; |
| 240 |
} |
| 241 |
|
| 242 |
AddResourceInfoToLogSection(ocaBufHandle, mosCtx); |
| 243 |
|
| 244 |
return MOS_STATUS_SUCCESS; |
| 245 |
} |
| 246 |
|
| 247 |
//! |
| 248 |
//! \brief Oca operation which should be called before sending start sub level batch buffer command. |
| 249 |
//! \param [in] ocaBufHandle |
| 250 |
//! Oca buffer handle. |
| 251 |
//! \param [in] pMosContext |
| 252 |
//! Pointer to MOS_CONTEXT. |
| 253 |
//! \param [in] pMosResource |
| 254 |
//! Pointer to the MOS_RESOURCE. |
| 255 |
//! \param [in] offsetOfSubLevelBB |
| 256 |
//! Offset for current BB in pMosResource. |
| 257 |
//! \param [in] bUseSizeOfResource |
| 258 |
//! If true, use size of pMosResource for batch buffer, else use sizeOfSubLevelBB. |
| 259 |
//! \param [in] sizeOfSubLevelBB |
| 260 |
//! Size of BB. Ignore if bUseSizeOfResource == true. |
| 261 |
//! \return MOS_STATUS |
| 262 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 263 |
//! |
| 264 |
MOS_STATUS MosOcaInterfaceSpecific::OnSubLevelBBStart(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT pMosContext, void *pMosResource, uint32_t offsetOfSubLevelBB, bool bUseSizeOfResource, uint32_t sizeOfSubLevelBB) |
| 265 |
{ |
| 266 |
return MOS_STATUS_UNIMPLEMENTED; |
| 267 |
} |
| 268 |
|
| 269 |
//! |
| 270 |
//! \brief Oca operation which should be called when indirect states being added. |
| 271 |
//! \param [in] ocaBufHandle |
| 272 |
//! Oca buffer handle. |
| 273 |
//! \param [in] pMosContext |
| 274 |
//! Pointer to MOS_CONTEXT. |
| 275 |
//! \param [in] pMosResource |
| 276 |
//! Pointer to the MOS_RESOURCE. |
| 277 |
//! \param [in] offsetOfIndirectState |
| 278 |
//! Offset for current state in pMosResource. |
| 279 |
//! \param [in] bUseSizeOfResource |
| 280 |
//! If true, use size of pMosResource for indirect state, else use sizeOfIndirectState. |
| 281 |
//! \param [in] sizeOfIndirectState |
| 282 |
//! Size of indirect state. Ignore if bUseSizeOfResource == true. |
| 283 |
//! \return MOS_STATUS |
| 284 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 285 |
//! |
| 286 |
MOS_STATUS MosOcaInterfaceSpecific::OnIndirectState(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT pMosContext, void *pMosResource, uint32_t offsetOfIndirectState, bool bUseSizeOfResource, uint32_t sizeOfIndirectState) |
| 287 |
{ |
| 288 |
return MOS_STATUS_UNIMPLEMENTED; |
| 289 |
} |
| 290 |
|
| 291 |
//! |
| 292 |
//! \brief Oca operation which should be called before adding dispatch states, |
| 293 |
//! e.g. VEB_DI_IECP_STATE and MEDIA_OBJECT_WALKER. |
| 294 |
//! \param [out] offsetInIndirectStateHeap |
| 295 |
//! The start offset of current dispatch in indirect state heap, which should be set to low 32 bits |
| 296 |
//! of GPR12 by LRI before dispatch commands being added. |
| 297 |
//! OCA_HEAP_INVALID_OFFSET means no need to configure GPR12, otherwise the register need be configured |
| 298 |
//! no matter return value being MOS_STATUS_SUCCESS or not. |
| 299 |
//! \param [in] ocaBufHandle |
| 300 |
//! Oca buffer handle. |
| 301 |
//! \param [in] mosCtx |
| 302 |
//! DDI device context. |
| 303 |
//! \return MOS_STATUS |
| 304 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 305 |
//! |
| 306 |
MOS_STATUS MosOcaInterfaceSpecific::OnDispatch(uint32_t &offsetInIndirectStateHeap, MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx) |
| 307 |
{ |
| 308 |
return MOS_STATUS_UNIMPLEMENTED; |
| 309 |
} |
| 310 |
|
| 311 |
//! |
| 312 |
//! \brief Add string to oca log section |
| 313 |
//! \param [in] ocaBufHandle |
| 314 |
//! Oca buffer handle. |
| 315 |
//! \param [in] mosCtx |
| 316 |
//! DDI device context. |
| 317 |
//! \param [in] str |
| 318 |
//! string to be added. |
| 319 |
//! \param [in] maxCount |
| 320 |
//! size of the buffer pointed by str. |
| 321 |
//! \return MOS_STATUS |
| 322 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 323 |
//! |
| 324 |
MOS_STATUS MosOcaInterfaceSpecific::TraceMessage(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx, const char *str, uint32_t maxCount) |
| 325 |
{ |
| 326 |
if (!m_isOcaEnabled) |
| 327 |
{ |
| 328 |
return MOS_STATUS_SUCCESS; |
| 329 |
} |
| 330 |
if (nullptr == str || maxCount <= 0 || maxCount > MOS_OCA_MAX_STRING_LEN) |
| 331 |
{ |
| 332 |
return MOS_STATUS_INVALID_PARAMETER; |
| 333 |
} |
| 334 |
if (!IsLogSectionEnabled(ocaBufHandle)) |
| 335 |
{ |
| 336 |
return MOS_STATUS_SUCCESS; |
| 337 |
} |
| 338 |
|
| 339 |
uint32_t len = strnlen(str, maxCount); |
| 340 |
MOS_OCA_LOG_HEADER header = {MOS_OCA_LOG_TYPE_STRING, sizeof(MOS_OCA_LOG_HEADER), len}; |
| 341 |
|
| 342 |
return DumpDataBlock(ocaBufHandle, &header, (void *)str); |
| 343 |
} |
| 344 |
|
| 345 |
//! |
| 346 |
//! \brief Add resource to dump list. |
| 347 |
//! \param [in] ocaBufHandle |
| 348 |
//! Oca buffer handle. |
| 349 |
//! \param [in] mosCtx |
| 350 |
//! DDI device context. |
| 351 |
//! \param [in] resource |
| 352 |
//! Reference to MOS_RESOURCE. |
| 353 |
//! \param [in] hwCmdType |
| 354 |
//! Hw command Type. |
| 355 |
//! \param [in] locationInCmd |
| 356 |
//! Location in command. |
| 357 |
//! \param [in] offsetInRes |
| 358 |
//! Offset in resource. |
| 359 |
//! \return MOS_STATUS |
| 360 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 361 |
//! |
| 362 |
MOS_STATUS MosOcaInterfaceSpecific::AddResourceToDumpList(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx, MOS_RESOURCE &resource, MOS_HW_COMMAND hwCmdType, uint32_t locationInCmd, uint32_t offsetInRes) |
| 363 |
{ |
| 364 |
uint32_t i = 0; |
| 365 |
MOS_MEMCOMP_STATE resMmcMode = {}; |
| 366 |
if (!m_isOcaEnabled || !m_isInitialized) |
| 367 |
{ |
| 368 |
return MOS_STATUS_SUCCESS; |
| 369 |
} |
| 370 |
|
| 371 |
if (!m_ocaBufContextList[ocaBufHandle].is1stLevelBBStarted) |
| 372 |
{ |
| 373 |
MOS_OS_ASSERTMESSAGE("AddResourceToDumpList is called before oca buffer initialized!"); |
| 374 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, MOS_STATUS_UNINITIALIZED, __FUNCTION__, __LINE__); |
| 375 |
return MOS_STATUS_UNINITIALIZED; |
| 376 |
} |
| 377 |
|
| 378 |
if (nullptr == m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList) |
| 379 |
{ |
| 380 |
MOS_OS_NORMALMESSAGE("OCA resource info dump not enabled."); |
| 381 |
return MOS_STATUS_SUCCESS; |
| 382 |
} |
| 383 |
|
| 384 |
if (nullptr == resource.pGmmResInfo || Mos_ResourceIsNull(&resource)) |
| 385 |
{ |
| 386 |
return MOS_STATUS_SUCCESS; |
| 387 |
} |
| 388 |
|
| 389 |
if (hwCmdType >= MOS_HW_COMMAND_MAX || MOS_HW_COMMAND_MAX > 64) |
| 390 |
{ |
| 391 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, MOS_STATUS_UNINITIALIZED, __FUNCTION__, __LINE__); |
| 392 |
return MOS_STATUS_INVALID_PARAMETER; |
| 393 |
} |
| 394 |
|
| 395 |
for (i = 0; i < m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount; ++i) |
| 396 |
{ |
| 397 |
if (m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].allocationHandle == resource.bo->handle) |
| 398 |
{ |
| 399 |
if (offsetInRes > m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].offsetInRes) |
| 400 |
{ |
| 401 |
// Only update resource info for the largest offsetInRes case. |
| 402 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].hwCmdType = (uint32_t)hwCmdType; |
| 403 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].offsetInRes = offsetInRes; |
| 404 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].locationInCmd = locationInCmd; |
| 405 |
} |
| 406 |
return MOS_STATUS_SUCCESS; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
if (m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount >= m_ocaBufContextList[ocaBufHandle].logSection.resInfo.maxResInfoCount) |
| 411 |
{ |
| 412 |
// Not reture error but record the resource count skipped. |
| 413 |
++m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCountSkipped; |
| 414 |
MOS_OS_NORMALMESSAGE("The resource is skipped to be dumpped to oca buffer."); |
| 415 |
return MOS_STATUS_SUCCESS; |
| 416 |
} |
| 417 |
|
| 418 |
MosStreamState steamState = {}; |
| 419 |
steamState.osDeviceContext = mosCtx->m_osDeviceContext; |
| 420 |
if (MOS_FAILED(MosInterface::GetMemoryCompressionMode(&steamState, &resource, resMmcMode))) |
| 421 |
{ |
| 422 |
resMmcMode = MOS_MEMCOMP_DISABLED; |
| 423 |
} |
| 424 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].gfxAddress = resource.bo->offset64; |
| 425 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].sizeAllocation = resource.pGmmResInfo->GetSizeAllocation(); |
| 426 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].sizeSurface = resource.pGmmResInfo->GetSizeSurface(); |
| 427 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].sizeSurfacePhy = resource.pGmmResInfo->GetSizeSurface(); |
| 428 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].sizeMainSurface = resource.pGmmResInfo->GetSizeMainSurface(); |
| 429 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].allocationHandle = resource.bo->handle; |
| 430 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].hwCmdType = (uint32_t)hwCmdType; |
| 431 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].locationInCmd = locationInCmd; |
| 432 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].offsetInRes = offsetInRes; |
| 433 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].pitch = (uint32_t)resource.pGmmResInfo->GetRenderPitch(); |
| 434 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].width = (uint32_t)resource.pGmmResInfo->GetBaseWidth(); |
| 435 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].height = (uint32_t)resource.pGmmResInfo->GetBaseHeight(); |
| 436 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].format = (uint32_t)resource.Format; |
| 437 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].gmmFormat = (uint32_t)resource.pGmmResInfo->GetResourceFormat(); |
| 438 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].gmmTileMode = (uint32_t)resource.pGmmResInfo->GmmGetTileMode(); |
| 439 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].gmmClient = (uint32_t)resource.pGmmResInfo->GetClientType(); |
| 440 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].gmmResUsageType = (uint32_t)resource.pGmmResInfo->GetCachePolicyUsage(); |
| 441 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].mmcMode = (uint32_t)resMmcMode; |
| 442 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].mmcHint = (uint32_t)resource.pGmmResInfo->GetMmcHint(0); |
| 443 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].auxYOffset = resource.pGmmResInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_Y_CCS); |
| 444 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].auxUVOffset = resource.pGmmResInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_UV_CCS); |
| 445 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].auxCCSOffset = resource.pGmmResInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_CCS); |
| 446 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].auxCCOffset = resource.pGmmResInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_CC); |
| 447 |
|
| 448 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].flags.isLocalOnly = resource.pGmmResInfo->GetResFlags().Info.LocalOnly; |
| 449 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].flags.isNonLocalOnly = resource.pGmmResInfo->GetResFlags().Info.NonLocalOnly; |
| 450 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].flags.isNotLockable = resource.pGmmResInfo->GetResFlags().Info.NotLockable; |
| 451 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].flags.isShared = resource.pGmmResInfo->GetResFlags().Info.Shared; |
| 452 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].flags.isCameraCapture = resource.pGmmResInfo->GetResFlags().Gpu.CameraCapture; |
| 453 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList[i].flags.isRenderTarget = resource.pGmmResInfo->GetResFlags().Gpu.RenderTarget; |
| 454 |
|
| 455 |
++m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount; |
| 456 |
|
| 457 |
return MOS_STATUS_SUCCESS; |
| 458 |
} |
| 459 |
|
| 460 |
//! |
| 461 |
//! \brief Add buffer resource to dump list. |
| 462 |
//! \param [in] ocaBufHandle |
| 463 |
//! Oca buffer handle. |
| 464 |
//! \param [in] mosCtx |
| 465 |
//! DDI device context. |
| 466 |
//! \param [in] resource |
| 467 |
//! Reference to MOS_RESOURCE. |
| 468 |
//! \param [in] hwCmdType |
| 469 |
//! Hw command Type. |
| 470 |
//! \param [in] locationInCmd |
| 471 |
//! Location in command. |
| 472 |
//! \param [in] offsetInRes |
| 473 |
//! Offset in resource. |
| 474 |
//! \return MOS_STATUS |
| 475 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 476 |
//! |
| 477 |
MOS_STATUS MosOcaInterfaceSpecific::AddBufferResourceToDumpList(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx, MOS_RESOURCE &resource, MOS_HW_COMMAND hwCmdType, uint32_t locationInCmd, uint32_t offsetInRes) |
| 478 |
{ |
| 479 |
uint32_t i = 0; |
| 480 |
if (!m_isOcaEnabled || !m_isInitialized) |
| 481 |
{ |
| 482 |
return MOS_STATUS_SUCCESS; |
| 483 |
} |
| 484 |
|
| 485 |
if (!m_ocaBufContextList[ocaBufHandle].is1stLevelBBStarted) |
| 486 |
{ |
| 487 |
MOS_OS_ASSERTMESSAGE("AddBufferResourceToDumpList is called before oca buffer initialized!"); |
| 488 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, MOS_STATUS_UNINITIALIZED, __FUNCTION__, __LINE__); |
| 489 |
return MOS_STATUS_UNINITIALIZED; |
| 490 |
} |
| 491 |
|
| 492 |
if (nullptr == m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList) |
| 493 |
{ |
| 494 |
MOS_OS_NORMALMESSAGE("OCA resource info dump not enabled."); |
| 495 |
return MOS_STATUS_SUCCESS; |
| 496 |
} |
| 497 |
|
| 498 |
if (nullptr == resource.pGmmResInfo || Mos_ResourceIsNull(&resource)) |
| 499 |
{ |
| 500 |
return MOS_STATUS_SUCCESS; |
| 501 |
} |
| 502 |
|
| 503 |
if (hwCmdType >= MOS_HW_COMMAND_MAX || MOS_HW_COMMAND_MAX > 64) |
| 504 |
{ |
| 505 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, MOS_STATUS_UNINITIALIZED, __FUNCTION__, __LINE__); |
| 506 |
return MOS_STATUS_INVALID_PARAMETER; |
| 507 |
} |
| 508 |
|
| 509 |
for (i = 0; i < m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResCount; ++i) |
| 510 |
{ |
| 511 |
if (m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].allocationHandle == resource.bo->handle) |
| 512 |
{ |
| 513 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].hwCmdType = (uint32_t)hwCmdType; |
| 514 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].locationInCmd = locationInCmd; |
| 515 |
return MOS_STATUS_SUCCESS; |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
if (m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResCount >= m_ocaBufContextList[ocaBufHandle].logSection.resInfo.maxBufferResInfoCount) |
| 520 |
{ |
| 521 |
// Not reture error but record the resource count skipped. |
| 522 |
++m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCountSkipped; |
| 523 |
MOS_OS_NORMALMESSAGE("The resource is skipped to be dumpped to oca buffer."); |
| 524 |
return MOS_STATUS_SUCCESS; |
| 525 |
} |
| 526 |
|
| 527 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].gfxAddress = resource.bo->offset64; |
| 528 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].sizeAllocation = resource.pGmmResInfo->GetSizeAllocation(); |
| 529 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].allocationHandle = resource.bo->handle; |
| 530 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].hwCmdType = (uint32_t)hwCmdType; |
| 531 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].locationInCmd = locationInCmd; |
| 532 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].size = (uint32_t)resource.pGmmResInfo->GetBaseWidth(); |
| 533 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].gmmFormat = (uint32_t)resource.pGmmResInfo->GetResourceFormat(); |
| 534 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].gmmResUsageType = (uint32_t)resource.pGmmResInfo->GetCachePolicyUsage(); |
| 535 |
|
| 536 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].flags.isLocalOnly = resource.pGmmResInfo->GetResFlags().Info.LocalOnly; |
| 537 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].flags.isNonLocalOnly = resource.pGmmResInfo->GetResFlags().Info.NonLocalOnly; |
| 538 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].flags.isNotLockable = resource.pGmmResInfo->GetResFlags().Info.NotLockable; |
| 539 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList[i].flags.isRenderTarget = resource.pGmmResInfo->GetResFlags().Gpu.RenderTarget; |
| 540 |
|
| 541 |
++m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResCount; |
| 542 |
|
| 543 |
return MOS_STATUS_SUCCESS; |
| 544 |
} |
| 545 |
|
| 546 |
void MosOcaInterfaceSpecific::AddResourceInfoToLogSection(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx) |
| 547 |
{ |
| 548 |
if (!m_ocaBufContextList[ocaBufHandle].is1stLevelBBStarted) |
| 549 |
{ |
| 550 |
return; |
| 551 |
} |
| 552 |
if (0 == m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount) |
| 553 |
{ |
| 554 |
return; |
| 555 |
} |
| 556 |
if (!IsLogSectionEnabled(ocaBufHandle)) |
| 557 |
{ |
| 558 |
return; |
| 559 |
} |
| 560 |
|
| 561 |
MOS_OCA_LOG_HEADER_RESOURCE_INFO header = {}; |
| 562 |
header.header.type = MOS_OCA_LOG_TYPE_RESOURCE_INFO; |
| 563 |
header.header.headerSize = sizeof(MOS_OCA_LOG_HEADER_RESOURCE_INFO); |
| 564 |
header.header.dataSize = m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount * sizeof(MOS_OCA_RESOURCE_INFO); |
| 565 |
header.resCount = m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount; |
| 566 |
header.resCountSkipped = m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCountSkipped; |
| 567 |
|
| 568 |
MOS_STATUS status = DumpDataBlock(ocaBufHandle, (PMOS_OCA_LOG_HEADER)&header, m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resInfoList); |
| 569 |
if (MOS_FAILED(status)) |
| 570 |
{ |
| 571 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, status, __FUNCTION__, __LINE__); |
| 572 |
} |
| 573 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount = 0; |
| 574 |
|
| 575 |
if (m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResCount > 0) |
| 576 |
{ |
| 577 |
header = {}; |
| 578 |
header.header.type = MOS_OCA_LOG_TYPE_BUFFER_RESOURCE_INFO; |
| 579 |
header.header.headerSize = sizeof(MOS_OCA_LOG_HEADER_RESOURCE_INFO); |
| 580 |
header.header.dataSize = m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResCount * sizeof(MOS_OCA_BUFFER_RESOURCE_INFO); |
| 581 |
header.resCount = m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResCount; |
| 582 |
header.resCountSkipped = m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCountSkipped; |
| 583 |
|
| 584 |
status = DumpDataBlock(ocaBufHandle, (PMOS_OCA_LOG_HEADER)&header, m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResInfoList); |
| 585 |
if (MOS_FAILED(status)) |
| 586 |
{ |
| 587 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, status, __FUNCTION__, __LINE__); |
| 588 |
} |
| 589 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.bufferResCount = 0; |
| 590 |
} |
| 591 |
|
| 592 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCountSkipped = 0; |
| 593 |
return; |
| 594 |
} |
| 595 |
|
| 596 |
void MosOcaInterfaceSpecific::AddExecListInfoToLogSection(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx, struct MOS_OCA_EXEC_LIST_INFO *info, int count) |
| 597 |
{ |
| 598 |
if (!m_ocaBufContextList[ocaBufHandle].is1stLevelBBStarted) |
| 599 |
{ |
| 600 |
return; |
| 601 |
} |
| 602 |
if (info == nullptr || 0 == count) |
| 603 |
{ |
| 604 |
return; |
| 605 |
} |
| 606 |
if (!IsLogSectionEnabled(ocaBufHandle)) |
| 607 |
{ |
| 608 |
return; |
| 609 |
} |
| 610 |
|
| 611 |
MOS_OCA_LOG_HEADER_EXEC_LIST_INFO header = {}; |
| 612 |
header.header.type = MOS_OCA_LOG_TYPE_EXEC_LIST_INFO; |
| 613 |
header.header.headerSize = sizeof(MOS_OCA_LOG_HEADER_EXEC_LIST_INFO); |
| 614 |
header.header.dataSize = count * sizeof(struct MOS_OCA_EXEC_LIST_INFO); |
| 615 |
header.count = count; |
| 616 |
|
| 617 |
MOS_STATUS status = DumpDataBlock(ocaBufHandle, (PMOS_OCA_LOG_HEADER)&header, info); |
| 618 |
if (MOS_FAILED(status)) |
| 619 |
{ |
| 620 |
MosOcaInterfaceSpecific::OnOcaError(mosCtx, status, __FUNCTION__, __LINE__); |
| 621 |
} |
| 622 |
return; |
| 623 |
} |
| 624 |
|
| 625 |
//! |
| 626 |
//! \brief Add data block to oca log section. |
| 627 |
//! \param [in] ocaBufHandle |
| 628 |
//! Oca buffer handle. |
| 629 |
//! \param [in] mosCtx |
| 630 |
//! DDI device context. |
| 631 |
//! \param [in] pHeader |
| 632 |
//! Log header. It can be extended by user. The acutal size of header is pHeader->headerSize. |
| 633 |
//! \param [in] pData |
| 634 |
//! Data block without log header. The acutal size of data block is pHeader->dataSize. |
| 635 |
//! \return MOS_STATUS |
| 636 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 637 |
//! |
| 638 |
MOS_STATUS MosOcaInterfaceSpecific::DumpDataBlock(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_CONTEXT mosCtx, PMOS_OCA_LOG_HEADER pHeader, void *pData) |
| 639 |
{ |
| 640 |
if (!m_isOcaEnabled) |
| 641 |
{ |
| 642 |
return MOS_STATUS_SUCCESS; |
| 643 |
} |
| 644 |
if (ocaBufHandle >= MAX_NUM_OF_OCA_BUF_CONTEXT || nullptr == pHeader) |
| 645 |
{ |
| 646 |
return MOS_STATUS_INVALID_PARAMETER; |
| 647 |
} |
| 648 |
|
| 649 |
if (!IsLogSectionEnabled(ocaBufHandle)) |
| 650 |
{ |
| 651 |
return MOS_STATUS_SUCCESS; |
| 652 |
} |
| 653 |
|
| 654 |
MOS_OCA_CHK_STATUS_RETURN(mosCtx, DumpDataBlock(ocaBufHandle, pHeader, pData), __FUNCTION__, __LINE__); |
| 655 |
return MOS_STATUS_SUCCESS; |
| 656 |
} |
| 657 |
|
| 658 |
MOS_STATUS MosOcaInterfaceSpecific::DumpDataBlock(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_OCA_LOG_HEADER pHeader, void *pData) |
| 659 |
{ |
| 660 |
if (pHeader->headerSize < sizeof(MOS_OCA_LOG_HEADER) || |
| 661 |
pHeader->type >= MOS_OCA_LOG_TYPE_COUNT || pHeader->type <= MOS_OCA_LOG_TYPE_INVALID || |
| 662 |
(pHeader->dataSize > 0 && nullptr == pData) || (pHeader->dataSize == 0 && pData)) |
| 663 |
{ |
| 664 |
return MOS_STATUS_INVALID_PARAMETER; |
| 665 |
} |
| 666 |
|
| 667 |
uint32_t copySize = pHeader->headerSize + pHeader->dataSize; |
| 668 |
if (m_ocaBufContextList[ocaBufHandle].logSection.offset + copySize > m_ocaLogSectionSizeLimit) |
| 669 |
{ |
| 670 |
return MOS_STATUS_NOT_ENOUGH_BUFFER; |
| 671 |
} |
| 672 |
|
| 673 |
MOS_OS_CHK_STATUS_RETURN(InsertData(ocaBufHandle, (uint8_t *)pHeader, pHeader->headerSize)); |
| 674 |
if (pHeader->dataSize > 0) |
| 675 |
{ |
| 676 |
MOS_OS_CHK_STATUS_RETURN(InsertData(ocaBufHandle, (uint8_t *)pData, pHeader->dataSize)); |
| 677 |
} |
| 678 |
|
| 679 |
return MOS_STATUS_SUCCESS; |
| 680 |
} |
| 681 |
|
| 682 |
MOS_STATUS MosOcaInterfaceSpecific::InsertData(MOS_OCA_BUFFER_HANDLE ocaBufHandle, uint8_t *p, uint32_t size) |
| 683 |
{ |
| 684 |
if (nullptr == p || 0 == size) |
| 685 |
{ |
| 686 |
return MOS_STATUS_INVALID_PARAMETER; |
| 687 |
} |
| 688 |
|
| 689 |
uint32_t sizeCpy = std::min(m_ocaLogSectionSizeLimit - m_ocaBufContextList[ocaBufHandle].logSection.offset, size); |
| 690 |
MOS_OS_CHK_STATUS_RETURN(MOS_SecureMemcpy((uint8_t *)m_ocaBufContextList[ocaBufHandle].logSection.base + m_ocaBufContextList[ocaBufHandle].logSection.offset, sizeCpy, p, sizeCpy)); |
| 691 |
m_ocaBufContextList[ocaBufHandle].logSection.offset += sizeCpy; |
| 692 |
return MOS_STATUS_SUCCESS; |
| 693 |
} |
| 694 |
|
| 695 |
uint32_t MosOcaInterfaceSpecific::IncreaseSize(uint32_t cmdBufSize) |
| 696 |
{ |
| 697 |
return cmdBufSize + OCA_LOG_SECTION_SIZE_MAX; |
| 698 |
} |
| 699 |
|
| 700 |
void MosOcaInterfaceSpecific::InitOcaLogSection(MOS_LINUX_BO *bo) |
| 701 |
{ |
| 702 |
if (bo == nullptr || bo->virt == nullptr || bo->size <= OCA_LOG_SECTION_SIZE_MAX) |
| 703 |
{ |
| 704 |
return; |
| 705 |
} |
| 706 |
OCA_LOG_SECTION_HEADER *header = (OCA_LOG_SECTION_HEADER *)((uint64_t)bo->virt + bo->size - OCA_LOG_SECTION_SIZE_MAX); |
| 707 |
header->magicNum = OCA_LOG_SECTION_MAGIC_NUMBER; |
| 708 |
} |
| 709 |
|
| 710 |
void MosOcaInterfaceSpecific::InitLogSection(MOS_OCA_BUFFER_HANDLE ocaBufHandle, PMOS_RESOURCE resCmdBuf) |
| 711 |
{ |
| 712 |
if (resCmdBuf == nullptr || |
| 713 |
resCmdBuf->bo == nullptr || |
| 714 |
resCmdBuf->bo->virt == nullptr) |
| 715 |
{ |
| 716 |
return; |
| 717 |
} |
| 718 |
MOS_LINUX_BO *boCmdBuf = resCmdBuf->bo; |
| 719 |
if (boCmdBuf->size <= OCA_LOG_SECTION_SIZE_MAX) |
| 720 |
{ |
| 721 |
MOS_OS_NORMALMESSAGE("1st level BB size is not larger than OCA_LOG_SECTION_SIZE_MAX."); |
| 722 |
return; |
| 723 |
} |
| 724 |
|
| 725 |
uint64_t *logSectionBase = (uint64_t*)((char *)boCmdBuf->virt + boCmdBuf->size - OCA_LOG_SECTION_SIZE_MAX); |
| 726 |
OCA_LOG_SECTION_HEADER *header = (OCA_LOG_SECTION_HEADER *)logSectionBase; |
| 727 |
|
| 728 |
if (OCA_LOG_SECTION_MAGIC_NUMBER != header->magicNum) |
| 729 |
{ |
| 730 |
MOS_OS_NORMALMESSAGE("Log section not exists in current 1st level BB."); |
| 731 |
return; |
| 732 |
} |
| 733 |
|
| 734 |
m_ocaBufContextList[ocaBufHandle].logSection.base = logSectionBase; |
| 735 |
// Reserve an uint64 for magic number; |
| 736 |
m_ocaBufContextList[ocaBufHandle].logSection.offset = sizeof(OCA_LOG_SECTION_HEADER); |
| 737 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCount = 0; |
| 738 |
m_ocaBufContextList[ocaBufHandle].logSection.resInfo.resCountSkipped = 0; |
| 739 |
} |
| 740 |
|
| 741 |
bool MosOcaInterfaceSpecific::IsLogSectionEnabled(MOS_OCA_BUFFER_HANDLE ocaBufHandle) |
| 742 |
{ |
| 743 |
return nullptr != m_ocaBufContextList[ocaBufHandle].logSection.base; |
| 744 |
} |
| 745 |
|
| 746 |
//! |
| 747 |
//! \brief Oca Error Handler. |
| 748 |
//! \param [in] mosCtx |
| 749 |
//! DDI device context. |
| 750 |
//! \param [in] status |
| 751 |
//! status for error. |
| 752 |
//! \param [in] functionName |
| 753 |
//! The failure function name. |
| 754 |
//! \param [in] lineNumber |
| 755 |
//! The line number where the failure happened. |
| 756 |
//! |
| 757 |
void MosOcaInterfaceSpecific::OnOcaError(PMOS_CONTEXT mosCtx, MOS_STATUS status, const char *functionName, uint32_t lineNumber) |
| 758 |
{ |
| 759 |
if (MOS_SUCCEEDED(status)) |
| 760 |
{ |
| 761 |
return; |
| 762 |
} |
| 763 |
|
| 764 |
MOS_OS_ASSERTMESSAGE("%s failed at line %d with status = %d!", functionName, lineNumber, status); |
| 765 |
|
| 766 |
MOS_TraceEventExt(EVENT_OCA_ERROR, |
| 767 |
EVENT_TYPE_INFO, |
| 768 |
&status, |
| 769 |
sizeof(uint32_t), |
| 770 |
nullptr, |
| 771 |
0); |
| 772 |
|
| 773 |
if (MOS_SUCCEEDED(s_ocaStatus)) |
| 774 |
{ |
| 775 |
MediaUserSettingSharedPtr userSettingPtr = nullptr; |
| 776 |
|
| 777 |
s_ocaStatus = status; |
| 778 |
s_lineNumForOcaErr = lineNumber; |
| 779 |
|
| 780 |
userSettingPtr = MosInterface::MosGetUserSettingInstance(mosCtx); |
| 781 |
ReportUserSetting( |
| 782 |
userSettingPtr, |
| 783 |
__MEDIA_USER_FEATURE_VALUE_OCA_STATUS, |
| 784 |
status, |
| 785 |
MediaUserSetting::Group::Device); |
| 786 |
|
| 787 |
ReportUserSetting( |
| 788 |
userSettingPtr, |
| 789 |
__MEDIA_USER_FEATURE_VALUE_OCA_ERROR_HINT, |
| 790 |
lineNumber, |
| 791 |
MediaUserSetting::Group::Device); |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
//! |
| 796 |
//! \brief Initialize oca error handler related items. |
| 797 |
//! |
| 798 |
void MosOcaInterfaceSpecific::InitOcaErrorHandler(PMOS_CONTEXT mosCtx) |
| 799 |
{ |
| 800 |
if (!s_bOcaStatusExistInReg) |
| 801 |
{ |
| 802 |
s_bOcaStatusExistInReg = true; |
| 803 |
|
| 804 |
// "Oca Status" should already be added into reg for MOS_FAILED(s_ocaStatus) case by OnOcaError. |
| 805 |
if (MOS_SUCCEEDED(s_ocaStatus)) |
| 806 |
{ |
| 807 |
MediaUserSettingSharedPtr userSettingPtr = nullptr; |
| 808 |
userSettingPtr = MosInterface::MosGetUserSettingInstance(mosCtx); |
| 809 |
ReportUserSetting( |
| 810 |
userSettingPtr, |
| 811 |
__MEDIA_USER_FEATURE_VALUE_OCA_STATUS, |
| 812 |
s_ocaStatus, |
| 813 |
MediaUserSetting::Group::Device); |
| 814 |
} |
| 815 |
} |
| 816 |
} |
| 817 |
|
| 818 |
//! |
| 819 |
//! \brief Oca Interface Initialize. |
| 820 |
//! |
| 821 |
void MosOcaInterfaceSpecific::Initialize(PMOS_CONTEXT mosContext) |
| 822 |
{ |
| 823 |
MosOcaInterfaceSpecific::InitOcaErrorHandler(mosContext); |
| 824 |
if (m_isInitialized == false) |
| 825 |
{ |
| 826 |
MediaUserSettingSharedPtr userSettingPtr = MosInterface::MosGetUserSettingInstance(mosContext); |
| 827 |
// read isOcaEnabled from reg key |
| 828 |
int32_t value = 0; |
| 829 |
ReadUserSetting( |
| 830 |
userSettingPtr, |
| 831 |
value, |
| 832 |
__MEDIA_USER_FEATURE_VALUE_ENABLE_UMD_OCA, |
| 833 |
MediaUserSetting::Group::Device); |
| 834 |
|
| 835 |
m_isOcaEnabled = value; |
| 836 |
if (!m_isOcaEnabled) |
| 837 |
{ |
| 838 |
return; |
| 839 |
} |
| 840 |
char *user_ctx_env = getenv("INTEL_DISABLE_DUMP_EXEC_LIST_INFO"); |
| 841 |
if (nullptr != user_ctx_env) |
| 842 |
{ |
| 843 |
uint8_t user_ctx_env_value = (bool)atoi(user_ctx_env); |
| 844 |
if (user_ctx_env_value == 1) |
| 845 |
{ |
| 846 |
m_ocaDumpExecListInfoEnabled = false; |
| 847 |
} |
| 848 |
} |
| 849 |
|
| 850 |
m_config.maxResInfoCount = OCA_MAX_RESOURCE_INFO_COUNT_MAX; |
| 851 |
m_resInfoPool = MOS_NewArray(MOS_OCA_RESOURCE_INFO, m_config.maxResInfoCount * MAX_NUM_OF_OCA_BUF_CONTEXT); |
| 852 |
if (nullptr == m_resInfoPool) |
| 853 |
{ |
| 854 |
return; |
| 855 |
} |
| 856 |
MosUtilities::MosZeroMemory(m_resInfoPool, sizeof(MOS_OCA_RESOURCE_INFO)*m_config.maxResInfoCount * MAX_NUM_OF_OCA_BUF_CONTEXT); |
| 857 |
for (int i = 0; i < MAX_NUM_OF_OCA_BUF_CONTEXT; ++i) |
| 858 |
{ |
| 859 |
m_ocaBufContextList[i].logSection.resInfo.resInfoList = m_resInfoPool + i * m_config.maxResInfoCount; |
| 860 |
} |
| 861 |
|
| 862 |
m_config.maxBufferResInfoCount = OCA_MAX_BUFFER_RESOURCE_INFO_COUNT_MAX; |
| 863 |
m_bufferResInfoPool = MOS_NewArray(MOS_OCA_BUFFER_RESOURCE_INFO, m_config.maxBufferResInfoCount * MAX_NUM_OF_OCA_BUF_CONTEXT); |
| 864 |
if (nullptr == m_bufferResInfoPool) |
| 865 |
{ |
| 866 |
MOS_DeleteArray(m_resInfoPool); |
| 867 |
return; |
| 868 |
} |
| 869 |
MosUtilities::MosZeroMemory(m_bufferResInfoPool, sizeof(MOS_OCA_BUFFER_RESOURCE_INFO) * m_config.maxBufferResInfoCount * MAX_NUM_OF_OCA_BUF_CONTEXT); |
| 870 |
for (int i = 0; i < MAX_NUM_OF_OCA_BUF_CONTEXT; ++i) |
| 871 |
{ |
| 872 |
m_ocaBufContextList[i].logSection.resInfo.bufferResInfoList = m_bufferResInfoPool + i * m_config.maxBufferResInfoCount; |
| 873 |
} |
| 874 |
|
| 875 |
if (nullptr != m_ocaMutex) |
| 876 |
{ |
| 877 |
return; |
| 878 |
} |
| 879 |
|
| 880 |
m_ocaMutex = MosUtilities::MosCreateMutex(); |
| 881 |
if (nullptr == m_ocaMutex) |
| 882 |
{ |
| 883 |
MOS_DeleteArray(m_bufferResInfoPool); |
| 884 |
MOS_DeleteArray(m_resInfoPool); |
| 885 |
return; |
| 886 |
} |
| 887 |
|
| 888 |
m_mutexForOcaBufPool = MosUtilities::MosCreateMutex(); |
| 889 |
if (nullptr == m_mutexForOcaBufPool) |
| 890 |
{ |
| 891 |
MOS_DeleteArray(m_bufferResInfoPool); |
| 892 |
MOS_DeleteArray(m_resInfoPool); |
| 893 |
MosUtilities::MosDestroyMutex(m_ocaMutex); |
| 894 |
m_ocaMutex = nullptr; |
| 895 |
return; |
| 896 |
} |
| 897 |
|
| 898 |
m_isInitialized = true; |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
MosOcaInterface& MosOcaInterfaceSpecific::GetInstance() |
| 903 |
{ |
| 904 |
static MosOcaInterfaceSpecific instance; |
| 905 |
return instance; |
| 906 |
} |
| 907 |
|
| 908 |
MosOcaInterfaceSpecific::MosOcaInterfaceSpecific() |
| 909 |
{ |
| 910 |
} |
| 911 |
|
| 912 |
MosOcaInterfaceSpecific::MosOcaInterfaceSpecific(MosOcaInterfaceSpecific&) |
| 913 |
{ |
| 914 |
} |
| 915 |
|
| 916 |
MosOcaInterfaceSpecific& MosOcaInterfaceSpecific::operator= (MosOcaInterfaceSpecific&) |
| 917 |
{ |
| 918 |
return *this; |
| 919 |
} |
| 920 |
|
| 921 |
MosOcaInterfaceSpecific::~MosOcaInterfaceSpecific() |
| 922 |
{ |
| 923 |
Uninitialize(); |
| 924 |
s_isDestroyed = true; |
| 925 |
} |
| 926 |
|
| 927 |
//! |
| 928 |
//! \brief Oca Interface uninitialize. |
| 929 |
//! |
| 930 |
void MosOcaInterfaceSpecific::Uninitialize() |
| 931 |
{ |
| 932 |
if (m_isInitialized == true) |
| 933 |
{ |
| 934 |
if (m_PendingOcaBuffersToUnlock.size() > 0) |
| 935 |
{ |
| 936 |
MOS_OS_ASSERTMESSAGE("%d Oca Buffers in pending list!", m_PendingOcaBuffersToUnlock.size()); |
| 937 |
UnlockPendingOcaBuffers(nullptr, nullptr, 0); |
| 938 |
} |
| 939 |
if (nullptr != m_mutexForOcaBufPool) |
| 940 |
{ |
| 941 |
MosUtilities::MosDestroyMutex(m_mutexForOcaBufPool); |
| 942 |
m_mutexForOcaBufPool = nullptr; |
| 943 |
} |
| 944 |
if (nullptr != m_ocaMutex) |
| 945 |
{ |
| 946 |
MosUtilities::MosDestroyMutex(m_ocaMutex); |
| 947 |
m_ocaMutex = nullptr; |
| 948 |
} |
| 949 |
if (m_resInfoPool != nullptr) |
| 950 |
{ |
| 951 |
MOS_DeleteArray(m_resInfoPool); |
| 952 |
m_resInfoPool = nullptr; |
| 953 |
for (int i = 0; i < MAX_NUM_OF_OCA_BUF_CONTEXT; ++i) |
| 954 |
{ |
| 955 |
m_ocaBufContextList[i].logSection.resInfo.resInfoList = nullptr; |
| 956 |
} |
| 957 |
} |
| 958 |
if(m_bufferResInfoPool != nullptr) |
| 959 |
{ |
| 960 |
MOS_DeleteArray(m_bufferResInfoPool); |
| 961 |
m_bufferResInfoPool = nullptr; |
| 962 |
for (int i = 0; i < MAX_NUM_OF_OCA_BUF_CONTEXT; ++i) |
| 963 |
{ |
| 964 |
m_ocaBufContextList[i].logSection.resInfo.bufferResInfoList = nullptr; |
| 965 |
} |
| 966 |
} |
| 967 |
m_hOcaMap.clear(); |
| 968 |
m_isInitialized = false; |
| 969 |
s_bOcaStatusExistInReg = false; |
| 970 |
s_isDestroyed = false; |
| 971 |
m_ocaDumpExecListInfoEnabled = true; |
| 972 |
} |
| 973 |
} |
| 974 |
|
| 975 |
//! |
| 976 |
//! \brief Oca Interface Initialize. |
| 977 |
//! |
| 978 |
void MosOcaInterfaceSpecific::InitInterface(PMOS_CONTEXT mosContext) |
| 979 |
{ |
| 980 |
if (MosUtilities::MosAtomicIncrement(&s_refCount) == 1) |
| 981 |
{ |
| 982 |
MosOcaInterfaceSpecific &ins = (MosOcaInterfaceSpecific &)MosOcaInterfaceSpecific::GetInstance(); |
| 983 |
ins.Initialize(mosContext); |
| 984 |
} |
| 985 |
return; |
| 986 |
} |
| 987 |
|
| 988 |
//! |
| 989 |
//! \brief Oca Interface uninitialize. |
| 990 |
//! |
| 991 |
void MosOcaInterfaceSpecific::UninitInterface() |
| 992 |
{ |
| 993 |
if (MosUtilities::MosAtomicDecrement(&s_refCount) == 0) |
| 994 |
{ |
| 995 |
if(!s_isDestroyed) |
| 996 |
{ |
| 997 |
MosOcaInterfaceSpecific &ins = (MosOcaInterfaceSpecific &)MosOcaInterfaceSpecific::GetInstance(); |
| 998 |
ins.Uninitialize(); |
| 999 |
} |
| 1000 |
} |
| 1001 |
return; |
| 1002 |
} |
| 1003 |
|
| 1004 |
//! |
| 1005 |
//! \brief Insert OCA buffer handle into m_hOcaMap |
| 1006 |
//! \param [in] key |
| 1007 |
//! The key of m_hOcaMap. |
| 1008 |
//! \param [in] handle |
| 1009 |
//! Oca buffer handle. |
| 1010 |
//! \return MOS_STATUS |
| 1011 |
//! Return MOS_STATUS_SUCCESS if insert successfully, otherwise insert failed. |
| 1012 |
//! |
| 1013 |
MOS_STATUS MosOcaInterfaceSpecific::InsertOcaBufHandleMap(uint32_t *key, MOS_OCA_BUFFER_HANDLE handle) |
| 1014 |
{ |
| 1015 |
MOS_OS_CHK_NULL_RETURN(m_ocaMutex); |
| 1016 |
MOS_OS_CHK_NULL_RETURN(key); |
| 1017 |
|
| 1018 |
MosOcaAutoLock autoLock(m_ocaMutex); |
| 1019 |
auto success = m_hOcaMap.emplace(key, handle); |
| 1020 |
if (!success.second) |
| 1021 |
{ |
| 1022 |
// Should never come to here. |
| 1023 |
MOS_OS_ASSERTMESSAGE("OcaBufHandle has already been assigned to current cmdBuffer!"); |
| 1024 |
return MOS_STATUS_UNKNOWN; |
| 1025 |
} |
| 1026 |
return MOS_STATUS_SUCCESS; |
| 1027 |
} |
| 1028 |
|
| 1029 |
//! |
| 1030 |
//! \brief Remove OCA buffer handle from m_hOcaMap |
| 1031 |
//! \param [in] key |
| 1032 |
//! The key of m_hOcaMap. |
| 1033 |
//! \return MOS_STATUS |
| 1034 |
//! Return MOS_STATUS_SUCCESS if erase successfully, otherwise erase failed. |
| 1035 |
//! |
| 1036 |
MOS_STATUS MosOcaInterfaceSpecific::RemoveOcaBufHandleFromMap(uint32_t *key) |
| 1037 |
{ |
| 1038 |
MOS_OS_CHK_NULL_RETURN(m_ocaMutex); |
| 1039 |
|
| 1040 |
MosOcaAutoLock autoLock(m_ocaMutex); |
| 1041 |
auto it = m_hOcaMap.find(key); |
| 1042 |
if (it != m_hOcaMap.end()) |
| 1043 |
{ |
| 1044 |
m_hOcaMap.erase(it); |
| 1045 |
} |
| 1046 |
return MOS_STATUS_SUCCESS; |
| 1047 |
} |
| 1048 |
|
| 1049 |
//! |
| 1050 |
//! \brief Get OCA buffer handle from m_hOcaMap |
| 1051 |
//! \param [in] key |
| 1052 |
//! The key of m_hOcaMap. |
| 1053 |
//! \return MOS_OCA_BUFFER_HANDLE |
| 1054 |
//! Return oca buffer handle. |
| 1055 |
//! |
| 1056 |
MOS_OCA_BUFFER_HANDLE MosOcaInterfaceSpecific::GetOcaBufHandleFromMap(uint32_t *key) |
| 1057 |
{ |
| 1058 |
if (nullptr == m_ocaMutex) |
| 1059 |
{ |
| 1060 |
MOS_OS_ASSERTMESSAGE("m_ocaMutex is nullptr."); |
| 1061 |
return MOS_OCA_INVALID_BUFFER_HANDLE; |
| 1062 |
} |
| 1063 |
MosOcaAutoLock autoLock(m_ocaMutex); |
| 1064 |
auto it = m_hOcaMap.find(key); |
| 1065 |
if (it == m_hOcaMap.end()) |
| 1066 |
{ |
| 1067 |
// May come here for workloads not enabling UMD_OCA. |
| 1068 |
return MOS_OCA_INVALID_BUFFER_HANDLE; |
| 1069 |
} |
| 1070 |
if (it->second >= MAX_NUM_OF_OCA_BUF_CONTEXT) |
| 1071 |
{ |
| 1072 |
MOS_OS_ASSERTMESSAGE("Get invalid OcaBufHandle: %d!", it->second); |
| 1073 |
return MOS_OCA_INVALID_BUFFER_HANDLE; |
| 1074 |
} |
| 1075 |
|
| 1076 |
return it->second; |
| 1077 |
} |