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 private: 207 #ifndef ANDROID 208 //! 209 //! \brief connect and create share memory for driver secure IPC 210 //! \param [in] key 211 //! used to generate key_value for share memory 212 //! \param [in] key 213 //! share memory size 214 //! \param [out] pShmid 215 //! ptr to int value for share memory id 216 //! \param [out] ppShm 217 //! ptr to ptr for share memory 218 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 219 //! 220 MOS_STATUS ConnectCreateShm(long key, uint32_t size, int32_t * pShmid, void* *ppShm); 221 222 //! 223 //! \brief destory the share memory 224 //! \param [in] pShmid 225 //! ptr to int value for share memory id 226 //! \param [in] ppShm 227 //! ptr to ptr for share memory 228 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 229 //! 230 MOS_STATUS DetachDestroyShm(int32_t shmid, void* pShm); 231 232 //! 233 //! \brief connect and create semaphore for driver secure IPC 234 //! \param [in] key 235 //! used to generate key_value for share memory 236 //! \param [out] pSemid 237 //! ptr to sem id created 238 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 239 //! 240 MOS_STATUS ConnectCreateSemaphore(long key, int32_t *pSemid); 241 242 //! 243 //! \brief create driver secure IPC 244 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 245 //! 246 MOS_STATUS CreateIPC(); 247 248 //! 249 //! \brief unlock the semaphore used in driver IPC 250 //! \param [in] semid 251 //! semaphore id to be unlocked 252 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 253 //! 254 MOS_STATUS UnLockSemaphore(int32_t semid); 255 256 //! 257 //! \brief lock the semaphore used in driver IPC 258 //! \param [in] semid 259 //! semaphore id to be locked 260 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 261 //! 262 MOS_STATUS LockSemaphore(int32_t semid); 263 264 //! 265 //! \brief destroy the IPC instance 266 //! 267 void DestroyIPC(); 268 269 //! 270 //! \brief attach to the share memory instance 271 //! \param shmid 272 //! [in] share memory id to be attached 273 //! \return share memory attached 274 //! 275 short ShmAttachedNumber(unsigned int shmid); 276 277 //! 278 //! \brief destroy the semaphore 279 //! \param shmid 280 //! [in] Semaphore id to be destoried 281 //! 282 MOS_STATUS DestroySemaphore(unsigned int semid); 283 284 //! 285 //! \brief create driver secure IPC for SSEU setting 286 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 287 //! 288 MOS_STATUS CreateSSEUIPC(); 289 290 //! 291 //! \brief destroy the SSEU IPC instance 292 //! 293 void DestroySSEUIPC(); 294 #endif // #ifndef ANDROID 295 296 //! 297 //! \brief Performance specific switch for debug purpose 298 //! 299 struct PerfInfo m_performanceInfo = {}; 300 301 //! 302 //! \brief Performance specific information for debug purpose 303 //! 304 PERF_DATA m_perfData = {}; 305 306 //! 307 //! \brief switch for 64bit KMD relocation 308 //! 309 bool m_use64BitRelocs = false; 310 311 //! 312 //! \brief tiling/untiling with CPU 313 //! 314 bool m_useSwSwizzling = false; 315 316 //! 317 //! \brief Sku tile Y flag 318 //! 319 bool m_tileYFlag = true; 320 321 //! 322 //! \brief flag to mark the existance of the second VDBox 323 //! 324 bool m_kmdHasVCS2 = false; 325 //! 326 //! \brief Semophore ID for secure IPC 327 //! 328 int32_t m_semId = 0; 329 //! 330 //! \brief Share memory ID for secure IPC 331 //! 332 int32_t m_shmId = 0; 333 //! 334 //! \brief Share memory ptr for secure IPC 335 //! 336 void* m_shm = nullptr; 337 //! 338 //! \brief Support slice count set in KMD 339 //! 340 bool m_sliceCountSetSupported = 0; 341 //! 342 //! \brief Enable/Disable dynamic slice shutdown and static slice config 343 //! -1 Use timer-based dynamic slice shutdown 344 //! 0 [default] Use default slices count 345 //! >0 Static slice shutdown, N for N slices 346 //! 347 int m_enableDymanicSliceShutdown = 0; 348 //! 349 //! \brief sseu for current context 350 //! 351 uint64_t m_sseu = 0; 352 //! 353 //! \brief Semophore ID for ruling SSEU configration 354 //! 355 int32_t m_sseuSemId = 0; 356 //! 357 //! \brief Share memory ID for ruling SSEU configration 358 //! 359 int32_t m_sseuShmId = 0; 360 //! 361 //! \brief Share memory ptr to the ruling SSEU configration 362 //! 363 void* m_sseuShm = nullptr; 364 //! 365 //! \brief Hybrid Decoder Multi-Threading Enable Flag 366 //! 367 bool m_hybridDecMultiThreadEnabled = false; 368 //! 369 //! \brief Flag to indicate if hybrid decoder is running 370 //! 371 bool m_hybridDecoderRunningFlag = false; 372 373 //! 374 //! \brief the function ptr for memory decompression function 375 //! 376 void (* m_memoryDecompress)( 377 PMOS_CONTEXT pOsContext, 378 PMOS_RESOURCE pOsResource) = nullptr; 379 380 //! 381 //! \brief the function ptr for surface copy function 382 //! 383 void (* m_mediaMemCopy )( 384 PMOS_CONTEXT pOsContext, 385 PMOS_RESOURCE pInputResource, 386 PMOS_RESOURCE pOutputResource, 387 bool bOutputCompressed) = nullptr; 388 389 //! 390 //! \brief the function ptr for Media Memory 2D copy function 391 //! 392 void (* m_mediaMemCopy2D)( 393 PMOS_CONTEXT pOsContext, 394 PMOS_RESOURCE pInputResource, 395 PMOS_RESOURCE pOutputResource, 396 uint32_t copyWidth, 397 uint32_t copyHeight, 398 uint32_t copyInputOffset, 399 uint32_t copyOutputOffset, 400 bool bOutputCompressed) = nullptr; 401 402 //! 403 //! \brief ptr to ptr of memory decompression state 404 //! 405 void* *m_mediaMemDecompState = nullptr; 406 407 //! 408 //! \brief ptr to mos context(kept for memory decompression function, to be cleaned up) 409 //! 410 PMOS_CONTEXT m_mosContext = nullptr; 411 412 //! 413 //! \brief the function ptr for memory decompression function 414 //! 415 uint32_t *m_transcryptedKernels = nullptr; 416 417 //! 418 //! \brief Size in bytes of the cached version of transcrypted and authenticated kernels 419 //! 420 uint32_t m_transcryptedKernelsSize = 0; 421 422 //! 423 //! \brief ptr to DRM bufmgr 424 //! 425 MOS_BUFMGR *m_bufmgr = nullptr; 426 427 //! 428 //! \brief ptr to intel context 429 //! 430 MOS_LINUX_CONTEXT *m_intelContext = nullptr; 431 432 //! 433 //! \brief drm device fd 434 //! 435 uint32_t m_fd = 0; 436 437 //! 438 //!UMD specific ClientContext object in GMM 439 //! 440 GMM_CLIENT_CONTEXT *m_pGmmClientContext = nullptr; 441 442 AuxTableMgr *m_auxTableMgr = nullptr; 443 444 GPU_CONTEXT_HANDLE m_GpuContextHandle[MOS_GPU_CONTEXT_MAX]; // Index to GPU Context (GpuContextHandles) 445 446 GpuContextMgr *m_gpuContextMgr = nullptr; 447 CmdBufMgr *m_cmdBufMgr = nullptr; 448 }; 449 #endif // #ifndef __MOS_CONTEXT_SPECIFIC_H__ 450