| 1 |
/* |
| 2 |
* Copyright (c) 2019-2024, 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_context_specific_next.cpp |
| 24 |
//! \brief Container for Linux/Android specific parameters shared across different GPU contexts of the same device instance |
| 25 |
//! |
| 26 |
|
| 27 |
#include "mos_os.h" |
| 28 |
#include "mos_util_debug.h" |
| 29 |
#include "mos_resource_defs.h" |
| 30 |
#include <unistd.h> |
| 31 |
#include <dlfcn.h> |
| 32 |
#include "hwinfo_linux.h" |
| 33 |
#include "mos_interface.h" |
| 34 |
#include <stdlib.h> |
| 35 |
|
| 36 |
#include <sys/ipc.h> |
| 37 |
#include <sys/shm.h> |
| 38 |
#include <sys/sem.h> |
| 39 |
#include <sys/types.h> |
| 40 |
#include <time.h> |
| 41 |
|
| 42 |
#if MOS_MEDIASOLO_SUPPORTED |
| 43 |
#include "mos_os_solo.h" |
| 44 |
#endif // MOS_MEDIASOLO_SUPPORTED |
| 45 |
#include "mos_solo_generic.h" |
| 46 |
#include "mos_context_specific_next.h" |
| 47 |
#include "mos_gpucontextmgr_next.h" |
| 48 |
#include "mos_cmdbufmgr_next.h" |
| 49 |
#include "mos_oca_rtlog_mgr.h" |
| 50 |
#include "mos_oca_interface_specific.h" |
| 51 |
#define BATCH_BUFFER_SIZE 0x80000 |
| 52 |
|
| 53 |
OsContextSpecificNext::OsContextSpecificNext() |
| 54 |
{ |
| 55 |
MOS_OS_FUNCTION_ENTER; |
| 56 |
} |
| 57 |
|
| 58 |
OsContextSpecificNext::~OsContextSpecificNext() |
| 59 |
{ |
| 60 |
MOS_OS_FUNCTION_ENTER; |
| 61 |
} |
| 62 |
|
| 63 |
MOS_STATUS OsContextSpecificNext::Init(DDI_DEVICE_CONTEXT ddiDriverContext) |
| 64 |
{ |
| 65 |
uint32_t iDeviceId = 0; |
| 66 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 67 |
uint32_t value = 0; |
| 68 |
uint32_t mode = 0; |
| 69 |
MediaUserSettingSharedPtr userSettingPtr = nullptr; |
| 70 |
|
| 71 |
MOS_OS_FUNCTION_ENTER; |
| 72 |
|
| 73 |
eStatus = MOS_STATUS_SUCCESS; |
| 74 |
|
| 75 |
PMOS_CONTEXT osDriverContext = (PMOS_CONTEXT)ddiDriverContext; |
| 76 |
|
| 77 |
if (GetOsContextValid() == false) |
| 78 |
{ |
| 79 |
uint32_t commandBufferSize = 0; |
| 80 |
m_skuTable.reset(); |
| 81 |
m_waTable.reset(); |
| 82 |
MosUtilities::MosZeroMemory(&m_platformInfo, sizeof(m_platformInfo)); |
| 83 |
MosUtilities::MosZeroMemory(&m_gtSystemInfo, sizeof(m_gtSystemInfo)); |
| 84 |
|
| 85 |
if( nullptr == osDriverContext || |
| 86 |
0 > osDriverContext->fd ) |
| 87 |
{ |
| 88 |
MOS_OS_ASSERT(false); |
| 89 |
return MOS_STATUS_INVALID_HANDLE; |
| 90 |
} |
| 91 |
m_fd = osDriverContext->fd; |
| 92 |
|
| 93 |
userSettingPtr = MosInterface::MosGetUserSettingInstance(osDriverContext); |
| 94 |
|
| 95 |
m_bufmgr = mos_bufmgr_gem_init(m_fd, BATCH_BUFFER_SIZE, &m_deviceType); |
| 96 |
if (nullptr == m_bufmgr) |
| 97 |
{ |
| 98 |
MOS_OS_ASSERTMESSAGE("Not able to allocate buffer manager, fd=0x%d", m_fd); |
| 99 |
return MOS_STATUS_INVALID_PARAMETER; |
| 100 |
} |
| 101 |
mos_bufmgr_enable_reuse(m_bufmgr); |
| 102 |
|
| 103 |
osDriverContext->bufmgr = m_bufmgr; |
| 104 |
|
| 105 |
//Latency reducation:replace HWGetDeviceID to get device using ioctl from drm. |
| 106 |
iDeviceId = mos_bufmgr_get_devid(m_bufmgr); |
| 107 |
m_isAtomSOC = IS_ATOMSOC(iDeviceId); |
| 108 |
|
| 109 |
eStatus = NullHwInit((MOS_CONTEXT_HANDLE)osDriverContext); |
| 110 |
if (!GetNullHwIsEnabled()) |
| 111 |
{ |
| 112 |
eStatus = HWInfo_GetGfxInfo(m_fd, m_bufmgr, &m_platformInfo, &m_skuTable, &m_waTable, &m_gtSystemInfo, userSettingPtr); |
| 113 |
} |
| 114 |
else |
| 115 |
{ |
| 116 |
m_platformInfo = osDriverContext->m_platform; |
| 117 |
m_skuTable = osDriverContext->m_skuTable; |
| 118 |
m_waTable = osDriverContext->m_waTable; |
| 119 |
m_gtSystemInfo = osDriverContext->m_gtSystemInfo; |
| 120 |
iDeviceId = osDriverContext->iDeviceId; |
| 121 |
} |
| 122 |
|
| 123 |
// replace platform/sku/wa/gtsysinfo for os context |
| 124 |
if (Mos_Solo_IsEnabled(nullptr)) |
| 125 |
{ |
| 126 |
m_skuTable.reset(); |
| 127 |
m_waTable.reset(); |
| 128 |
Mos_Solo_SetPlatform(&m_platformInfo, (PMOS_CONTEXT)osDriverContext); |
| 129 |
Mos_Solo_SetSkuwaGtInfo((PMOS_CONTEXT)osDriverContext, m_platformInfo, m_skuTable, m_waTable, m_gtSystemInfo, iDeviceId); |
| 130 |
} |
| 131 |
|
| 132 |
if (eStatus != MOS_STATUS_SUCCESS) |
| 133 |
{ |
| 134 |
MOS_OS_ASSERTMESSAGE("Fatal error - unsuccesfull Sku/Wa/GtSystemInfo initialization"); |
| 135 |
return eStatus; |
| 136 |
} |
| 137 |
|
| 138 |
if (m_platformInfo.eProductFamily == IGFX_METEORLAKE || |
| 139 |
m_platformInfo.eProductFamily == IGFX_ARROWLAKE || |
| 140 |
m_platformInfo.eProductFamily == IGFX_LUNARLAKE) |
| 141 |
{ |
| 142 |
ReadUserSetting( |
| 143 |
userSettingPtr, |
| 144 |
value, |
| 145 |
"INTEL MEDIA ALLOC MODE", |
| 146 |
MediaUserSetting::Group::Device); |
| 147 |
|
| 148 |
if (value) |
| 149 |
{ |
| 150 |
mode = (value & 0x000000ff); |
| 151 |
} |
| 152 |
|
| 153 |
// Realloc cache only if it's not mode 0 |
| 154 |
if (mode) |
| 155 |
{ |
| 156 |
mos_bufmgr_realloc_cache(m_bufmgr, mode); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
ReadUserSetting( |
| 161 |
userSettingPtr, |
| 162 |
value, |
| 163 |
__MEDIA_USER_FEATURE_VALUE_ENABLE_SOFTPIN, |
| 164 |
MediaUserSetting::Group::Device); |
| 165 |
|
| 166 |
if (value) |
| 167 |
{ |
| 168 |
bool softpin_va1Malign = false; |
| 169 |
if (MEDIA_IS_SKU(&m_skuTable, Ftr1MGranularAuxTable)) |
| 170 |
{ |
| 171 |
softpin_va1Malign = true; |
| 172 |
} |
| 173 |
|
| 174 |
mos_bufmgr_enable_softpin(m_bufmgr, softpin_va1Malign); |
| 175 |
|
| 176 |
ReadUserSetting( |
| 177 |
userSettingPtr, |
| 178 |
value, |
| 179 |
__MEDIA_USER_FEATURE_VALUE_ENABLE_VM_BIND, |
| 180 |
MediaUserSetting::Group::Device); |
| 181 |
|
| 182 |
if (value) |
| 183 |
{ |
| 184 |
mos_bufmgr_enable_vmbind(m_bufmgr); |
| 185 |
MOS_OS_NORMALMESSAGE("mos_bufmg_enable_vmbind"); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
uint64_t isRecoverableContextEnabled = 0; |
| 190 |
MOS_LINUX_CONTEXT *intel_context = mos_context_create_ext(m_bufmgr, 0, false); |
| 191 |
int ret = mos_get_context_param(intel_context, 0, DRM_CONTEXT_PARAM_RECOVERABLE, &isRecoverableContextEnabled); |
| 192 |
if (ret == -EINVAL) |
| 193 |
{ |
| 194 |
isRecoverableContextEnabled = 1; |
| 195 |
} |
| 196 |
if (intel_context) |
| 197 |
{ |
| 198 |
mos_context_destroy(intel_context); |
| 199 |
} |
| 200 |
// set recoverablecontext disabled if want disable object capture |
| 201 |
if (MEDIA_IS_WA(&m_waTable, WaDisableSetObjectCapture) && isRecoverableContextEnabled) |
| 202 |
{ |
| 203 |
mos_bufmgr_disable_object_capture(m_bufmgr); |
| 204 |
} |
| 205 |
|
| 206 |
if (MEDIA_IS_SKU(&m_skuTable, FtrEnableMediaKernels) == 0) |
| 207 |
{ |
| 208 |
MEDIA_WR_WA(&m_waTable, WaHucStreamoutOnlyDisable, 0); |
| 209 |
} |
| 210 |
|
| 211 |
MosUtilities::MosTraceSetupInfo( |
| 212 |
(VA_MAJOR_VERSION << 16) | VA_MINOR_VERSION, |
| 213 |
m_platformInfo.eProductFamily, |
| 214 |
m_platformInfo.eRenderCoreFamily, |
| 215 |
(m_platformInfo.usRevId << 16) | m_platformInfo.usDeviceID); |
| 216 |
|
| 217 |
GMM_SKU_FEATURE_TABLE gmmSkuTable = {}; |
| 218 |
GMM_WA_TABLE gmmWaTable = {}; |
| 219 |
GMM_GT_SYSTEM_INFO gmmGtInfo = {}; |
| 220 |
GMM_ADAPTER_BDF gmmAdapterBDF = {}; |
| 221 |
eStatus = HWInfo_GetGmmInfo(m_bufmgr, &gmmSkuTable, &gmmWaTable, &gmmGtInfo); |
| 222 |
if (MOS_STATUS_SUCCESS != eStatus) |
| 223 |
{ |
| 224 |
MOS_OS_ASSERTMESSAGE("Fatal error - unsuccesfull Gmm Sku/Wa/GtSystemInfo initialization"); |
| 225 |
return eStatus; |
| 226 |
} |
| 227 |
|
| 228 |
eStatus = MosInterface::GetAdapterBDF(osDriverContext, &gmmAdapterBDF); |
| 229 |
if (MOS_STATUS_SUCCESS != eStatus) |
| 230 |
{ |
| 231 |
MOS_OS_ASSERTMESSAGE("Fatal error - unsuccesfull Gmm Adapter BDF initialization"); |
| 232 |
return eStatus; |
| 233 |
} |
| 234 |
|
| 235 |
// Initialize Gmm context |
| 236 |
GMM_INIT_IN_ARGS gmmInitAgrs = {}; |
| 237 |
GMM_INIT_OUT_ARGS gmmOutArgs = {}; |
| 238 |
gmmInitAgrs.Platform = m_platformInfo; |
| 239 |
gmmInitAgrs.pSkuTable = &gmmSkuTable; |
| 240 |
gmmInitAgrs.pWaTable = &gmmWaTable; |
| 241 |
gmmInitAgrs.pGtSysInfo = &gmmGtInfo; |
| 242 |
gmmInitAgrs.FileDescriptor = gmmAdapterBDF.Data; |
| 243 |
gmmInitAgrs.ClientType = (GMM_CLIENT)GMM_LIBVA_LINUX; |
| 244 |
|
| 245 |
// replace sku/wa/gtsysinfo for gmm client context |
| 246 |
if (Mos_Solo_IsEnabled(nullptr)) |
| 247 |
{ |
| 248 |
gmmInitAgrs.pSkuTable = &m_skuTable; |
| 249 |
gmmInitAgrs.pWaTable = &m_waTable; |
| 250 |
gmmInitAgrs.pGtSysInfo = &m_gtSystemInfo; |
| 251 |
} |
| 252 |
|
| 253 |
GMM_STATUS status = InitializeGmm(&gmmInitAgrs, &gmmOutArgs); |
| 254 |
if (status != GMM_SUCCESS) |
| 255 |
{ |
| 256 |
MOS_OS_ASSERTMESSAGE("Fatal error - InitializeGmm fail."); |
| 257 |
return MOS_STATUS_INVALID_PARAMETER; |
| 258 |
} |
| 259 |
m_gmmClientContext = gmmOutArgs.pGmmClientContext; |
| 260 |
|
| 261 |
m_auxTableMgr = AuxTableMgr::CreateAuxTableMgr(m_bufmgr, &m_skuTable, m_gmmClientContext); |
| 262 |
|
| 263 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 264 |
ReadUserSettingForDebug( |
| 265 |
userSettingPtr, |
| 266 |
osDriverContext->bSimIsActive, |
| 267 |
__MEDIA_USER_FEATURE_VALUE_SIM_ENABLE, |
| 268 |
MediaUserSetting::Group::Device); |
| 269 |
#endif |
| 270 |
|
| 271 |
m_useSwSwizzling = osDriverContext->bSimIsActive || MEDIA_IS_SKU(&m_skuTable, FtrUseSwSwizzling); |
| 272 |
|
| 273 |
m_tileYFlag = MEDIA_IS_SKU(&m_skuTable, FtrTileY); |
| 274 |
|
| 275 |
m_use64BitRelocs = true; |
| 276 |
|
| 277 |
if (!GetNullHwIsEnabled()) |
| 278 |
{ |
| 279 |
osDriverContext->iDeviceId = iDeviceId; |
| 280 |
osDriverContext->m_skuTable = m_skuTable; |
| 281 |
osDriverContext->m_waTable = m_waTable; |
| 282 |
osDriverContext->m_gtSystemInfo = m_gtSystemInfo; |
| 283 |
osDriverContext->m_platform = m_platformInfo; |
| 284 |
} |
| 285 |
osDriverContext->pGmmClientContext = m_gmmClientContext; |
| 286 |
osDriverContext->m_auxTableMgr = m_auxTableMgr; |
| 287 |
osDriverContext->bUseSwSwizzling = m_useSwSwizzling; |
| 288 |
osDriverContext->bTileYFlag = m_tileYFlag; |
| 289 |
osDriverContext->bIsAtomSOC = m_isAtomSOC; |
| 290 |
osDriverContext->m_osDeviceContext = this; |
| 291 |
|
| 292 |
m_usesPatchList = true; |
| 293 |
m_usesGfxAddress = false; |
| 294 |
|
| 295 |
SetOsContextValid(true); |
| 296 |
// Prepare the command buffer manager |
| 297 |
if (m_ocaLogSectionSupported) |
| 298 |
{ |
| 299 |
// increase size for oca log section |
| 300 |
commandBufferSize = MosOcaInterfaceSpecific::IncreaseSize(COMMAND_BUFFER_SIZE); |
| 301 |
} |
| 302 |
else |
| 303 |
{ |
| 304 |
commandBufferSize = COMMAND_BUFFER_SIZE; |
| 305 |
} |
| 306 |
m_cmdBufMgr = CmdBufMgrNext::GetObject(); |
| 307 |
MOS_OS_CHK_NULL_RETURN(m_cmdBufMgr); |
| 308 |
MOS_OS_CHK_STATUS_RETURN(m_cmdBufMgr->Initialize(this, commandBufferSize)); |
| 309 |
|
| 310 |
// Prepare the gpu Context manager |
| 311 |
m_gpuContextMgr = GpuContextMgrNext::GetObject(this); |
| 312 |
MOS_OS_CHK_NULL_RETURN(m_gpuContextMgr); |
| 313 |
|
| 314 |
m_perfData = (PERF_DATA*)MOS_AllocAndZeroMemory(sizeof(PERF_DATA)); |
| 315 |
MOS_OS_CHK_NULL_RETURN(m_perfData); |
| 316 |
osDriverContext->pPerfData = m_perfData; |
| 317 |
|
| 318 |
//It must be done with m_gpuContextMgr ready. Insides it will create gpu context. |
| 319 |
|
| 320 |
m_mosDecompression = MOS_New(MosDecompression, osDriverContext); |
| 321 |
MOS_OS_CHK_NULL_RETURN(m_mosDecompression); |
| 322 |
osDriverContext->ppMediaMemDecompState = m_mosDecompression->GetMediaMemDecompState(); |
| 323 |
MOS_OS_CHK_NULL_RETURN(osDriverContext->ppMediaMemDecompState); |
| 324 |
if (*osDriverContext->ppMediaMemDecompState == nullptr) |
| 325 |
{ |
| 326 |
MOS_OS_NORMALMESSAGE("Decomp state creation failed"); |
| 327 |
} |
| 328 |
|
| 329 |
m_mosMediaCopy = MOS_New(MosMediaCopy, osDriverContext); |
| 330 |
if (nullptr == m_mosMediaCopy) |
| 331 |
{ |
| 332 |
MOS_OS_NORMALMESSAGE("m_mosMediaCopy creation failed"); |
| 333 |
} |
| 334 |
else |
| 335 |
{ |
| 336 |
osDriverContext->ppMediaCopyState = (void **)m_mosMediaCopy->GetMediaCopyState(); |
| 337 |
if ((nullptr == osDriverContext->ppMediaCopyState) || (nullptr == *osDriverContext->ppMediaCopyState)) |
| 338 |
{ |
| 339 |
MOS_OS_NORMALMESSAGE("Media Copy state creation failed"); |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
MosOcaRTLogMgr::RegisterContext(this, osDriverContext); |
| 344 |
return eStatus; |
| 345 |
} |
| 346 |
|
| 347 |
void OsContextSpecificNext::Destroy() |
| 348 |
{ |
| 349 |
MOS_OS_FUNCTION_ENTER; |
| 350 |
|
| 351 |
if (GetOsContextValid() == true) |
| 352 |
{ |
| 353 |
if (m_auxTableMgr != nullptr) |
| 354 |
{ |
| 355 |
MOS_Delete(m_auxTableMgr); |
| 356 |
m_auxTableMgr = nullptr; |
| 357 |
} |
| 358 |
|
| 359 |
m_skuTable.reset(); |
| 360 |
m_waTable.reset(); |
| 361 |
|
| 362 |
mos_bufmgr_destroy(m_bufmgr); |
| 363 |
|
| 364 |
// Delete Gmm context |
| 365 |
GMM_INIT_OUT_ARGS gmmOutArgs = {}; |
| 366 |
gmmOutArgs.pGmmClientContext = m_gmmClientContext; |
| 367 |
GmmAdapterDestroy(&gmmOutArgs); |
| 368 |
m_gmmClientContext = nullptr; |
| 369 |
|
| 370 |
SetOsContextValid(false); |
| 371 |
|
| 372 |
if (m_perfData != nullptr) |
| 373 |
{ |
| 374 |
MOS_FreeMemory(m_perfData); |
| 375 |
m_perfData = nullptr; |
| 376 |
} |
| 377 |
|
| 378 |
if (m_mosMediaCopy != nullptr) |
| 379 |
{ |
| 380 |
MOS_Delete(m_mosMediaCopy); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
} |
| 385 |
|