1 /* 2 * Copyright (c) 2017-2018, 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.h 24 //! \brief Container for Linux/Android specific parameters shared across different GPU contexts of the same device instance 25 //! 26 27 #ifndef __MOS_CONTEXT_SPECIFIC_H__ 28 #define __MOS_CONTEXT_SPECIFIC_H__ 29 30 #include "mos_os_specific.h" 31 #include "mos_context.h" 32 #include "mos_auxtable_mgr.h" 33 34 class GraphicsResourceSpecific; 35 class CmdBufMgr; 36 class GpuContextMgr; 37 38 class OsContextSpecific : public OsContext 39 { 40 friend class GraphicsResourceSpecific; 41 42 //! 43 //! \brief SW semaphore key for share memory btw dual VDBox 44 //! 45 constexpr static uint32_t m_dualVdboxKey= ('D'<<24|'V'<<8|'X'<<0); 46 47 //! 48 //! \brief SW semaphore key for share memory to store SSEU configration 49 //! 50 constexpr static uint32_t m_sseuKey= ('S'<<24|'S'<<16|'E'<<8|'U'<<0); 51 52 //! 53 //! \brief shared memory size 54 //! 55 constexpr static uint32_t m_sseuShmSize = 256; 56 57 //! 58 //! \brief slice count value timeout critera in milliseconds 59 //! 60 constexpr static uint64_t m_sliceCountTimeoutMS = 1000; 61 62 #ifndef ANDROID 63 //! 64 //! \brief Initial share memory handle 65 //! 66 constexpr static void* MOS_LINUX_SHM_INVALID = (void *)nullptr; 67 68 //! 69 //! \brief Initial share memory ID 70 //! 71 constexpr static int32_t MOS_LINUX_IPC_INVALID_ID = -1; 72 73 //! 74 //! \brief maximum number to try to get a valid semaphore 75 //! 76 constexpr static uint32_t MOS_LINUX_SEM_MAX_TRIES = 10; 77 #endif 78 79 public: 80 //! 81 //! \brief Do not disable kmd watchdog, that is to say, pass 82 //! < 0: I915_EXEC_ENABLE_WATCHDOG flag to KMD; 83 //! < 1: Disable kmd watchdog; 84 //! that is to say, DO NOT pass I915_EXEC_ENABLE_WATCHDOG flag to KMD; 85 struct PerfInfo { 86 bool m_disableKmdWatchdog; 87 uint32_t m_enablePerfTag; 88 } ; 89 90 //! 91 //! \brief Constructor 92 //! 93 OsContextSpecific(); 94 95 //! 96 //! \brief Destructor 97 //! 98 ~OsContextSpecific(); 99 100 //! 101 //! \brief Initialize the MOS Context 102 //! \param [in] pOsDriverContext 103 //! ptr to MOS_CONTEXT created inside DDI 104 //! \return MOS_Success in pass case, MOS error status in fail cases 105 //! 106 MOS_STATUS Init(PMOS_CONTEXT osDriverContext); 107 108 //! 109 //! \brief Destroy the os specific MOS context 110 //! 111 void Destroy(); 112 113 //! 114 //! \brief Get the performance information 115 //! GetPerfInfo()116 struct PerfInfo GetPerfInfo() { return m_performanceInfo; } 117 118 //! 119 //! \brief Get the performance information 120 //! SetPerfInfo(const struct PerfInfo & performanceInfo)121 void SetPerfInfo(const struct PerfInfo &performanceInfo) 122 { 123 MOS_SecureMemcpy(&m_performanceInfo, sizeof(struct PerfInfo), &performanceInfo, sizeof(struct PerfInfo)); 124 } 125 126 //! 127 //! \brief Return whether we need 64bit relocation 128 //! Is64BitRelocUsed()129 bool Is64BitRelocUsed() { return m_use64BitRelocs; } 130 131 //! 132 //! \brief Return whether the KMD support the 2nd VCS 133 //! IsKmdWithVcs2()134 bool IsKmdWithVcs2() { return m_kmdHasVCS2; } 135 136 //! 137 //! \brief Return the semaphore ID we use to protect the IPC creation process 138 //! \return sem id 139 //! GetSemId()140 int32_t GetSemId() { return m_semId; } 141 142 //! 143 //! \brief Return the shm ID for the IPC 144 //! \return shm id GetShmId()145 int32_t GetShmId() { return m_shmId; } 146 147 //! 148 //! \brief Return the shm object for the IPC 149 //! \return shm id 150 //! GetShmPtr()151 void *GetShmPtr() { return m_shm; } 152 153 //! 154 //! \brief Return the function ptr for memory decompression function 155 //! GetpfnMemoryDecompaddr()156 void *GetpfnMemoryDecompaddr() { return (void *)m_memoryDecompress; } 157 GetDrmContext()158 MOS_LINUX_CONTEXT *GetDrmContext() { return m_intelContext; } 159 GetGpuContextHandle(MOS_GPU_CONTEXT GpuContext)160 GPU_CONTEXT_HANDLE GetGpuContextHandle(MOS_GPU_CONTEXT GpuContext) 161 { 162 return m_GpuContextHandle[GpuContext]; 163 } 164 SetGpuContextHandle(MOS_GPU_CONTEXT GpuContext,GPU_CONTEXT_HANDLE gpuContextHandle)165 void SetGpuContextHandle(MOS_GPU_CONTEXT GpuContext, GPU_CONTEXT_HANDLE gpuContextHandle) 166 { 167 m_GpuContextHandle[GpuContext] = gpuContextHandle; 168 } 169 GetGpuContextHandleByIndex(uint32_t index)170 GPU_CONTEXT_HANDLE GetGpuContextHandleByIndex(uint32_t index) 171 { 172 return (index < MOS_GPU_CONTEXT_MAX) ? m_GpuContextHandle[index] : MOS_GPU_CONTEXT_INVALID_HANDLE; 173 } 174 SetGpuContextHandleByIndex(uint32_t index,GPU_CONTEXT_HANDLE gpuContextHandle)175 void SetGpuContextHandleByIndex(uint32_t index, GPU_CONTEXT_HANDLE gpuContextHandle) 176 { 177 if (index < MOS_GPU_CONTEXT_MAX) 178 { 179 m_GpuContextHandle[index] = gpuContextHandle; 180 } 181 } 182 GetGpuContextMgr()183 GpuContextMgr *GetGpuContextMgr() { return m_gpuContextMgr; } 184 GetCmdBufMgr()185 CmdBufMgr* GetCmdBufMgr(){return m_cmdBufMgr;} 186 GetGmmClientContext()187 GMM_CLIENT_CONTEXT* GetGmmClientContext() { return m_pGmmClientContext; }; 188 GetAuxTableMgr()189 AuxTableMgr* GetAuxTableMgr() { return m_auxTableMgr; } 190 UseSwSwizzling()191 bool UseSwSwizzling() { return m_useSwSwizzling; } GetTileYFlag()192 bool GetTileYFlag() { return m_tileYFlag; } 193 194 #ifndef ANDROID 195 196 //! 197 //! \brief Set slice count to shared memory and KMD 198 //! \param [in,out] pSliceCount 199 //! Pointer to the slice count. Input the slice count for current 200 //! context, output the ruling slice count shared by all contexts. 201 //! 202 void SetSliceCount(uint32_t *pSliceCount); 203 204 #endif 205 //! 206 //! \brief Get the context priority from KMD 207 //! \param [in, out] pPriority 208 //! Pointer to the priority of current gpu context. 209 //! 210 void GetGpuPriority(int32_t *pPriority); 211 212 //! 213 //! \brief Get the context priority from KMD 214 //! \param [in] priority 215 //! the priority set to current gpu context. 216 //! 217 void SetGpuPriority(int32_t priority); 218 219 private: 220 #ifndef ANDROID 221 //! 222 //! \brief connect and create share memory for driver secure IPC 223 //! \param [in] key 224 //! used to generate key_value for share memory 225 //! \param [in] key 226 //! share memory size 227 //! \param [out] pShmid 228 //! ptr to int value for share memory id 229 //! \param [out] ppShm 230 //! ptr to ptr for share memory 231 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 232 //! 233 MOS_STATUS ConnectCreateShm(long key, uint32_t size, int32_t * pShmid, void* *ppShm); 234 235 //! 236 //! \brief destory the share memory 237 //! \param [in] pShmid 238 //! ptr to int value for share memory id 239 //! \param [in] ppShm 240 //! ptr to ptr for share memory 241 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 242 //! 243 MOS_STATUS DetachDestroyShm(int32_t shmid, void* pShm); 244 245 //! 246 //! \brief connect and create semaphore for driver secure IPC 247 //! \param [in] key 248 //! used to generate key_value for share memory 249 //! \param [out] pSemid 250 //! ptr to sem id created 251 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 252 //! 253 MOS_STATUS ConnectCreateSemaphore(long key, int32_t *pSemid); 254 255 //! 256 //! \brief create driver secure IPC 257 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 258 //! 259 MOS_STATUS CreateIPC(); 260 261 //! 262 //! \brief unlock the semaphore used in driver IPC 263 //! \param [in] semid 264 //! semaphore id to be unlocked 265 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 266 //! 267 MOS_STATUS UnLockSemaphore(int32_t semid); 268 269 //! 270 //! \brief lock the semaphore used in driver IPC 271 //! \param [in] semid 272 //! semaphore id to be locked 273 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 274 //! 275 MOS_STATUS LockSemaphore(int32_t semid); 276 277 //! 278 //! \brief destroy the IPC instance 279 //! 280 void DestroyIPC(); 281 282 //! 283 //! \brief attach to the share memory instance 284 //! \param shmid 285 //! [in] share memory id to be attached 286 //! \return share memory attached 287 //! 288 short ShmAttachedNumber(unsigned int shmid); 289 290 //! 291 //! \brief destroy the semaphore 292 //! \param shmid 293 //! [in] Semaphore id to be destoried 294 //! 295 MOS_STATUS DestroySemaphore(unsigned int semid); 296 297 //! 298 //! \brief create driver secure IPC for SSEU setting 299 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 300 //! 301 MOS_STATUS CreateSSEUIPC(); 302 303 //! 304 //! \brief destroy the SSEU IPC instance 305 //! 306 void DestroySSEUIPC(); 307 #endif // #ifndef ANDROID 308 309 //! 310 //! \brief Performance specific switch for debug purpose 311 //! 312 struct PerfInfo m_performanceInfo = {}; 313 314 //! 315 //! \brief Performance specific information for debug purpose 316 //! 317 PERF_DATA m_perfData = {}; 318 319 //! 320 //! \brief switch for 64bit KMD relocation 321 //! 322 bool m_use64BitRelocs = false; 323 324 //! 325 //! \brief tiling/untiling with CPU 326 //! 327 bool m_useSwSwizzling = false; 328 329 //! 330 //! \brief Sku tile Y flag 331 //! 332 bool m_tileYFlag = true; 333 334 //! 335 //! \brief flag to mark the existance of the second VDBox 336 //! 337 bool m_kmdHasVCS2 = false; 338 //! 339 //! \brief Semophore ID for secure IPC 340 //! 341 int32_t m_semId = 0; 342 //! 343 //! \brief Share memory ID for secure IPC 344 //! 345 int32_t m_shmId = 0; 346 //! 347 //! \brief Share memory ptr for secure IPC 348 //! 349 void* m_shm = nullptr; 350 //! 351 //! \brief Support slice count set in KMD 352 //! 353 bool m_sliceCountSetSupported = 0; 354 //! 355 //! \brief Enable/Disable dynamic slice shutdown and static slice config 356 //! -1 Use timer-based dynamic slice shutdown 357 //! 0 [default] Use default slices count 358 //! >0 Static slice shutdown, N for N slices 359 //! 360 int m_enableDymanicSliceShutdown = 0; 361 //! 362 //! \brief sseu for current context 363 //! 364 uint64_t m_sseu = 0; 365 //! 366 //! \brief Semophore ID for ruling SSEU configration 367 //! 368 int32_t m_sseuSemId = 0; 369 //! 370 //! \brief Share memory ID for ruling SSEU configration 371 //! 372 int32_t m_sseuShmId = 0; 373 //! 374 //! \brief Share memory ptr to the ruling SSEU configration 375 //! 376 void* m_sseuShm = nullptr; 377 //! 378 //! \brief Hybrid Decoder Multi-Threading Enable Flag 379 //! 380 bool m_hybridDecMultiThreadEnabled = false; 381 //! 382 //! \brief Flag to indicate if hybrid decoder is running 383 //! 384 bool m_hybridDecoderRunningFlag = false; 385 386 //! 387 //! \brief the function ptr for memory decompression function 388 //! 389 void (* m_memoryDecompress)( 390 PMOS_CONTEXT pOsContext, 391 PMOS_RESOURCE pOsResource) = nullptr; 392 393 //! 394 //! \brief the function ptr for surface copy function 395 //! 396 void (* m_mediaMemCopy )( 397 PMOS_CONTEXT pOsContext, 398 PMOS_RESOURCE pInputResource, 399 PMOS_RESOURCE pOutputResource, 400 bool bOutputCompressed) = nullptr; 401 402 //! 403 //! \brief the function ptr for Media Memory 2D copy function 404 //! 405 void (* m_mediaMemCopy2D)( 406 PMOS_CONTEXT pOsContext, 407 PMOS_RESOURCE pInputResource, 408 PMOS_RESOURCE pOutputResource, 409 uint32_t copyWidth, 410 uint32_t copyHeight, 411 uint32_t copyInputOffset, 412 uint32_t copyOutputOffset, 413 uint32_t bpp, 414 bool bOutputCompressed) = nullptr; 415 416 //! 417 //! \brief ptr to ptr of memory decompression state 418 //! 419 void* *m_mediaMemDecompState = nullptr; 420 421 //! 422 //! \brief ptr to mos context(kept for memory decompression function, to be cleaned up) 423 //! 424 PMOS_CONTEXT m_mosContext = nullptr; 425 426 //! 427 //! \brief the function ptr for memory decompression function 428 //! 429 uint32_t *m_transcryptedKernels = nullptr; 430 431 //! 432 //! \brief Size in bytes of the cached version of transcrypted and authenticated kernels 433 //! 434 uint32_t m_transcryptedKernelsSize = 0; 435 436 //! 437 //! \brief ptr to DRM bufmgr 438 //! 439 MOS_BUFMGR *m_bufmgr = nullptr; 440 441 //! 442 //! \brief ptr to intel context 443 //! 444 MOS_LINUX_CONTEXT *m_intelContext = nullptr; 445 446 //! 447 //! \brief drm device fd 448 //! 449 uint32_t m_fd = 0; 450 451 //! 452 //!UMD specific ClientContext object in GMM 453 //! 454 GMM_CLIENT_CONTEXT *m_pGmmClientContext = nullptr; 455 456 AuxTableMgr *m_auxTableMgr = nullptr; 457 458 GPU_CONTEXT_HANDLE m_GpuContextHandle[MOS_GPU_CONTEXT_MAX]; // Index to GPU Context (GpuContextHandles) 459 460 GpuContextMgr *m_gpuContextMgr = nullptr; 461 CmdBufMgr *m_cmdBufMgr = nullptr; 462 bool m_apoMosEnabled = false; 463 }; 464 #endif // #ifndef __MOS_CONTEXT_SPECIFIC_H__ 465