1 /*
2 * Copyright (c) 2009-2023, 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_os_specific.c
24 //! \brief Common interface used in MOS LINUX OS
25 //! \details Common interface used in MOS LINUX OS
26 //!
27 #include <unistd.h>
28 #include <dlfcn.h>
29 #include <stdlib.h>
30
31 #include "mos_os.h"
32 #include "mos_os_cp_interface_specific.h"
33 #include "mos_util_debug.h"
34 #include "mos_resource_defs.h"
35 #include "hwinfo_linux.h"
36 #include "mos_graphicsresource.h"
37 #include "mos_context_specific.h"
38 #include "mos_gpucontext_specific.h"
39 #include "mos_gpucontextmgr.h"
40
41 #include "mos_graphicsresource_next.h"
42 #include "mos_context_specific_next.h"
43 #include "mos_gpucontext_specific_next.h"
44 #include "mos_gpucontextmgr_next.h"
45 #include "mos_interface.h"
46
47 #if MOS_MEDIASOLO_SUPPORTED
48 #include "mos_os_solo.h"
49 #endif // MOS_MEDIASOLO_SUPPORTED
50 #include "mos_solo_generic.h"
51
52 #ifndef ANDROID
53 #include <sys/ipc.h>
54 #include <sys/shm.h>
55 #include <sys/sem.h>
56 #include <sys/types.h>
57 #endif
58
59 #include "mos_os_virtualengine.h"
60 #include "mos_util_user_interface.h"
61
62 #include "mos_os_virtualengine_singlepipe_next.h"
63 #include "mos_os_virtualengine_scalability_next.h"
64
65 #include "memory_policy_manager.h"
66 #include "mos_oca_interface_specific.h"
67 #include "mos_os_next.h"
68
69 extern int32_t CreateCmDevice(MOS_CONTEXT *mosContext,
70 CMRT_UMD::CmDevice* &device,
71 uint32_t devCreateOption,
72 uint8_t priority);
73
74 extern int32_t DestroyCmDevice(CMRT_UMD::CmDevice* &device);
75
76 extern MOS_STATUS InitCmOsDDIInterface(PCM_HAL_STATE cmState);
77
78 //!
79 //! \brief DRM VMAP patch
80 //!
81 #define Y_TILE_WIDTH 128
82 #define Y_TILE_HEIGHT 32
83 #define X_TILE_WIDTH 512
84 #define X_TILE_HEIGHT 8
85
86 #define MI_BATCHBUFFER_END 0x05000000
87
88 //!
89 //! \brief Two VDBOX shared memory key
90 //!
91 #define DUAL_VDBOX_KEY ('D'<<24|'V'<<8|'X'<<0)
92
93 //============= PRIVATE FUNCTIONS <BEGIN>=========================================
94
SetupMediaSoloSwitch()95 bool SetupMediaSoloSwitch()
96 {
97 bool mediaSoloEnabled = false;
98 MosUtilities::MosReadMediaSoloEnabledUserFeature(mediaSoloEnabled);
99 return mediaSoloEnabled;
100 }
101
SetupApoDdiSwitch(int32_t fd,MediaUserSettingSharedPtr userSettingPtr)102 bool SetupApoDdiSwitch(int32_t fd, MediaUserSettingSharedPtr userSettingPtr)
103 {
104 if (fd < 0)
105 {
106 return false;
107 }
108
109 //Read user feature to determine if apg mos is enabled.
110 uint32_t userfeatureValue = 0;
111 MOS_STATUS estatus = MosUtilities::MosReadApoDdiEnabledUserFeature(userfeatureValue, nullptr, userSettingPtr);
112
113 return (userfeatureValue != 0);
114 }
115
SetupApoMosSwitch(int32_t fd,MediaUserSettingSharedPtr userSettingPtr)116 bool SetupApoMosSwitch(int32_t fd, MediaUserSettingSharedPtr userSettingPtr)
117 {
118 if (fd < 0)
119 {
120 return false;
121 }
122
123 //Read user feature to determine if apg mos is enabled.
124 uint32_t userfeatureValue = 0;
125 MOS_STATUS estatus = MosUtilities::MosReadApoMosEnabledUserFeature(userfeatureValue, nullptr, userSettingPtr);
126
127 if(estatus == MOS_STATUS_SUCCESS)
128 {
129 return (userfeatureValue != 0);
130 }
131 PRODUCT_FAMILY eProductFamily = IGFX_UNKNOWN;
132 HWInfo_GetGfxProductFamily(fd, eProductFamily);
133
134 if (eProductFamily >= IGFX_TIGERLAKE_LP)
135 {
136 return true;
137 }
138
139 return false;
140 }
141
142
143 //!
144 //! \brief Clear Gpu Context
145 //! \details OS GPU context clear
146 //! \param PMOS_RESOURCE pContext
147 //! [in] Pointer to OS context
148 //! \return void
149 //! Return NONE
150 //!
Mos_Specific_ClearGpuContext(MOS_CONTEXT * pContext)151 void Mos_Specific_ClearGpuContext(MOS_CONTEXT *pContext)
152 {
153 int32_t iLoop = 0;
154
155 MOS_OS_FUNCTION_ENTER;
156
157 if (nullptr == pContext)
158 {
159 MOS_OS_ASSERTMESSAGE("Input mos context is null");
160 return;
161 }
162
163 for (iLoop = 0; iLoop < MOS_GPU_CONTEXT_MAX; iLoop++)
164 {
165 if (pContext->OsGpuContext[iLoop].pCB != nullptr)
166 {
167 MOS_FreeMemory(pContext->OsGpuContext[iLoop].pCB);
168 pContext->OsGpuContext[iLoop].pCB = nullptr;
169 }
170
171 if (pContext->OsGpuContext[iLoop].pAllocationList != nullptr)
172 {
173 MOS_FreeMemory(pContext->OsGpuContext[iLoop].pAllocationList);
174 pContext->OsGpuContext[iLoop].pAllocationList = nullptr;
175 }
176
177 if (pContext->OsGpuContext[iLoop].pPatchLocationList)
178 {
179 MOS_FreeMemory(pContext->OsGpuContext[iLoop].pPatchLocationList);
180 pContext->OsGpuContext[iLoop].pPatchLocationList = nullptr;
181 }
182
183 if (pContext->OsGpuContext[iLoop].pResources != nullptr)
184 {
185 MOS_FreeMemory(pContext->OsGpuContext[iLoop].pResources);
186 pContext->OsGpuContext[iLoop].pResources = nullptr;
187 }
188
189 if (pContext->OsGpuContext[iLoop].pbWriteMode != nullptr)
190 {
191 MOS_FreeMemory(pContext->OsGpuContext[iLoop].pbWriteMode);
192 pContext->OsGpuContext[iLoop].pbWriteMode = nullptr;
193 }
194
195 pContext->OsGpuContext[iLoop].uiMaxNumAllocations = 0;
196 pContext->OsGpuContext[iLoop].uiMaxPatchLocationsize = 0;
197 }
198 }
199
200 //!
201 //! \brief Unified OS get command buffer
202 //! \details Return the pointer to the next available space in Cmd Buffer
203 //! \param PMOS_CONTEXT pOsContext
204 //! [in] Pointer to OS Context
205 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
206 //! [out] Pointer to Command Buffer
207 //! \param int32_t iSize
208 //! [out] Size of command in bytes
209 //! \return int32_t
210 //! Return true is there is space
211 //!
Linux_GetCommandBuffer(PMOS_CONTEXT pOsContext,PMOS_COMMAND_BUFFER pCmdBuffer,int32_t iSize)212 int32_t Linux_GetCommandBuffer(
213 PMOS_CONTEXT pOsContext,
214 PMOS_COMMAND_BUFFER pCmdBuffer,
215 int32_t iSize)
216 {
217 int32_t bResult = false;
218 MOS_LINUX_BO *cmd_bo = nullptr;
219 struct mos_drm_bo_alloc alloc;
220
221 if ( pOsContext == nullptr ||
222 pCmdBuffer == nullptr)
223 {
224 bResult = false;
225 MOS_OS_ASSERTMESSAGE("Linux_GetCommandBuffer:pOsContext == nullptr || pCmdBuffer == NULL");
226 goto finish;
227 }
228
229 // Allocate the command buffer from GEM
230 alloc.name = "MOS CmdBuf";
231 alloc.size = iSize;
232 alloc.alignment = 4096;
233 alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
234 cmd_bo = mos_bo_alloc(pOsContext->bufmgr, &alloc); // Align to page boundary
235 if (cmd_bo == nullptr)
236 {
237 MOS_OS_ASSERTMESSAGE("Allocation of command buffer failed.");
238 bResult = false;
239 goto finish;
240 }
241 //MOS_OS_NORMALMESSAGE("alloc CMB, bo is 0x%x.", cmd_bo);
242
243 // Map command buffer to user virtual address
244 if (mos_bo_map(cmd_bo,1) != 0) // Write enable set
245 {
246 MOS_OS_ASSERTMESSAGE("Mapping of command buffer failed.");
247 bResult = false;
248 goto finish;
249 }
250
251 Mos_ResetResource(&pCmdBuffer->OsResource);
252
253 // Fill in resource information
254 pCmdBuffer->OsResource.Format = Format_Buffer;
255 pCmdBuffer->OsResource.iWidth = cmd_bo->size;
256 pCmdBuffer->OsResource.iHeight = 1;
257 pCmdBuffer->OsResource.iPitch = cmd_bo->size;
258 pCmdBuffer->OsResource.iSize = pCmdBuffer->OsResource.iPitch * pCmdBuffer->OsResource.iHeight;
259 pCmdBuffer->OsResource.iCount = 1;
260 pCmdBuffer->OsResource.pData = (uint8_t*)cmd_bo->virt;
261 pCmdBuffer->OsResource.TileType = MOS_TILE_LINEAR;
262 pCmdBuffer->OsResource.bo = cmd_bo;
263 pCmdBuffer->OsResource.bMapped = true;
264
265 // for MOS wrapper to avoid memory leak
266 pCmdBuffer->OsResource.bConvertedFromDDIResource = true;
267
268 pCmdBuffer->pCmdBase = (uint32_t*)cmd_bo->virt;
269 pCmdBuffer->pCmdPtr = (uint32_t*)cmd_bo->virt;
270 pCmdBuffer->iOffset = 0;
271 pCmdBuffer->iRemaining = cmd_bo->size;
272 pCmdBuffer->iCmdIndex = -1;
273 pCmdBuffer->iVdboxNodeIndex = MOS_VDBOX_NODE_INVALID;
274 pCmdBuffer->iVeboxNodeIndex = MOS_VEBOX_NODE_INVALID;
275 pCmdBuffer->is1stLvlBB = true;
276 MOS_ZeroMemory(pCmdBuffer->pCmdBase, cmd_bo->size);
277 pCmdBuffer->iSubmissionType = SUBMISSION_TYPE_SINGLE_PIPE;
278 MOS_ZeroMemory(&pCmdBuffer->Attributes, sizeof(pCmdBuffer->Attributes));
279 bResult = true;
280
281 finish:
282 if ((false == bResult)&&(nullptr != cmd_bo)){
283 //need to unreference command buffer allocated.
284 mos_bo_unreference(cmd_bo);
285 }
286 return bResult;
287 }
288
289 //!
290 //! \brief Get unused command buffer space
291 //! \details Return unused command buffer space
292 //! \param PMOS_CONTEXT pOsContext
293 //! [in] Pointer to OS Context
294 //! \param MOS_GPU_CONTEXT GpuContext
295 //! [in] GPU context
296 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
297 //! [out] Pointer to Command buffer
298 //! \return void
299 //!
Linux_ReturnCommandBuffer(PMOS_CONTEXT pOsContext,MOS_GPU_CONTEXT GpuContext,PMOS_COMMAND_BUFFER pCmdBuffer)300 void Linux_ReturnCommandBuffer(
301 PMOS_CONTEXT pOsContext,
302 MOS_GPU_CONTEXT GpuContext,
303 PMOS_COMMAND_BUFFER pCmdBuffer)
304 {
305 MOS_OS_GPU_CONTEXT *pOsGpuContext;
306
307 if (pOsContext == nullptr || pCmdBuffer == nullptr ||
308 Mos_ResourceIsNull(&(pCmdBuffer->OsResource)))
309 {
310 MOS_OS_ASSERTMESSAGE("Invalid input parameter pOsContext or pCmdBuffer.");
311 goto finish;
312 }
313
314 if (GpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
315 {
316 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
317 goto finish;
318 }
319
320 pOsGpuContext = &pOsContext->OsGpuContext[GpuContext];
321 if (pOsContext == nullptr)
322 {
323 MOS_OS_ASSERTMESSAGE("Os gpucontext is null.");
324 goto finish;
325 }
326
327 pOsGpuContext->pCB->iOffset = pCmdBuffer->iOffset ;
328 pOsGpuContext->pCB->iRemaining = pCmdBuffer->iRemaining;
329 pOsGpuContext->pCB->pCmdPtr = pCmdBuffer->pCmdPtr;
330 pOsGpuContext->pCB->iVdboxNodeIndex = pCmdBuffer->iVdboxNodeIndex;
331 pOsGpuContext->pCB->iVeboxNodeIndex = pCmdBuffer->iVeboxNodeIndex;
332 pOsGpuContext->pCB->is1stLvlBB = pCmdBuffer->is1stLvlBB;
333
334 finish:
335 return;
336 }
337
338 //!
339 //! \brief Flush Command Buffer
340 //! \details Flush Command Buffer space
341 //! \param PMOS_CONTEXT pOsContext
342 //! [in] Pointer to OS Context
343 //! \param MOS_GPU_CONTEXT GpuContext
344 //! [in] GPU context
345 //! \return int32_t
346 //! true if succeeded, false if failed or invalid parameters
347 //!
Linux_FlushCommandBuffer(PMOS_CONTEXT pOsContext,MOS_GPU_CONTEXT GpuContext)348 int32_t Linux_FlushCommandBuffer(
349 PMOS_CONTEXT pOsContext,
350 MOS_GPU_CONTEXT GpuContext)
351 {
352 PCOMMAND_BUFFER pCurrCB;
353 int32_t bResult = false;
354 PMOS_OS_GPU_CONTEXT pOsGpuContext;
355
356 if (pOsContext == nullptr)
357 {
358 MOS_OS_ASSERTMESSAGE("Invalid input parameter pOsContext.")
359 goto finish;
360 }
361
362 if (GpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
363 {
364 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
365 goto finish;
366 }
367
368 pOsGpuContext = &pOsContext->OsGpuContext[GpuContext];
369 if (pOsGpuContext == nullptr)
370 {
371 MOS_OS_ASSERTMESSAGE("Invalid OsGpuContext");
372 goto finish;
373 }
374
375 // Refresh command buffer usage
376 pOsContext->pfnRefresh(pOsContext);
377
378 pOsGpuContext->uiCurrentNumPatchLocations = 0;
379
380 // CB already active
381 pCurrCB = pOsGpuContext->pCurrentCB;
382 if (pCurrCB == nullptr)
383 {
384 MOS_OS_ASSERTMESSAGE("Invalid current CB in OsGpuContext.");
385 goto finish;
386 }
387
388 if (pCurrCB->bActive)
389 {
390 goto finish;
391 }
392
393 pCurrCB->bActive = true;
394 bResult = true;
395
396 finish:
397 return bResult;
398 }
399
400 //!
401 //! \brief Init command buffer pool
402 //! \details Initilize the command buffer pool
403 //! \param PMOS_CONTEXT pOsContext
404 //! [in] Pointer to OS Context
405 //! \return void
406 //!
Linux_InitCmdBufferPool(PMOS_CONTEXT pOsContext)407 void Linux_InitCmdBufferPool(
408 PMOS_CONTEXT pOsContext)
409 {
410 MOS_OS_FUNCTION_ENTER;
411
412 MOS_ZeroMemory(&pOsContext->CmdBufferPool, sizeof(CMD_BUFFER_BO_POOL));
413 pOsContext->CmdBufferPool.iFetch = 0;
414 }
415
416 //!
417 //! \brief Wait and release command buffer
418 //! \details Command buffer Wait and release
419 //! \param PMOS_CONTEXT pOsContext
420 //! [in] Pointer to OS context structure
421 //! \param int32_t index
422 //! [in] Command buffer's index in Command buffer pool
423 //! \return MOS_STATUS
424 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
425 //!
Linux_WaitAndReleaseCmdBuffer(PMOS_CONTEXT pOsContext,int32_t index)426 MOS_STATUS Linux_WaitAndReleaseCmdBuffer(
427 PMOS_CONTEXT pOsContext,
428 int32_t index)
429 {
430 MOS_LINUX_BO *cmd_bo;
431 MOS_STATUS eStatus;
432
433 MOS_OS_FUNCTION_ENTER;
434
435 eStatus = MOS_STATUS_SUCCESS;
436
437 MOS_OS_CHK_NULL(pOsContext);
438
439 if (index < 0 || index >= MAX_CMD_BUF_NUM)
440 {
441 eStatus = MOS_STATUS_INVALID_PARAMETER;
442 goto finish;
443 }
444
445 // According to the logic of CmdBufferPool now, the command buffer is used in a circular way.
446 // The input index always points to the next(oldest) buffer after the latest(newest) buffer.
447 // If the next buffer is not empty (!= nullptr), all the buffers in the pool will also be not empty.
448 // So it's not necessary to check all buffers to see whether there's empty buffer.
449 cmd_bo = pOsContext->CmdBufferPool.pCmd_bo[index];
450 if (cmd_bo != nullptr)
451 {
452 mos_bo_wait_rendering(cmd_bo);
453 mos_bo_unreference(cmd_bo);
454 pOsContext->CmdBufferPool.pCmd_bo[index] = nullptr;
455 }
456
457 finish:
458 return eStatus;
459 }
460
461 //!
462 //! \brief Release command buffer pool
463 //! \details Release command buffer pool until all of commands are finished.
464 //! \param PMOS_CONTEXT pOsContext
465 //! [in] Pointer to OS context structure
466 //! \return MOS_STATUS
467 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
468 //!
Linux_ReleaseCmdBufferPool(PMOS_CONTEXT pOsContext)469 MOS_STATUS Linux_ReleaseCmdBufferPool(PMOS_CONTEXT pOsContext)
470 {
471 int32_t i;
472 MOS_STATUS eStatus;
473
474 MOS_OS_FUNCTION_ENTER;
475
476 eStatus = MOS_STATUS_SUCCESS;
477
478 MOS_OS_CHK_NULL(pOsContext);
479
480 for (i = 0; i < MAX_CMD_BUF_NUM; i++)
481 {
482 MOS_OS_CHK_STATUS(Linux_WaitAndReleaseCmdBuffer(pOsContext, i));
483 }
484
485 finish:
486 return eStatus;
487 }
488
489 //!
490 //! \brief Wait for the fetch command
491 //! \details Wait for the fetch command bo until it is available
492 //! \param PMOS_CONTEXT pOsContext
493 //! [in] Pointer to OS context structure
494 //! \return MOS_STATUS
495 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
496 //!
Linux_WaitForAvailableCmdBo(PMOS_CONTEXT pOsContext)497 MOS_STATUS Linux_WaitForAvailableCmdBo(
498 PMOS_CONTEXT pOsContext)
499 {
500 int32_t index;
501 MOS_STATUS eStatus;
502
503 MOS_OS_FUNCTION_ENTER;
504
505 eStatus = MOS_STATUS_SUCCESS;
506
507 MOS_OS_CHK_NULL(pOsContext);
508
509 index = pOsContext->CmdBufferPool.iFetch;
510 MOS_OS_CHK_STATUS(Linux_WaitAndReleaseCmdBuffer(pOsContext, index));
511
512 finish:
513 return eStatus;
514 }
515
516 //!
517 //! \brief Insert command buffer
518 //! \details Insert command buffer into pool
519 //! \param PMOS_CONTEXT pOsContext
520 //! [in] Pointer to OS context structure
521 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
522 //! [in] Pointer to command buffer struct
523 //! \return MOS_STATUS
524 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
525 //!
Linux_InsertCmdBufferToPool(PMOS_CONTEXT pOsContext,PMOS_COMMAND_BUFFER pCmdBuffer)526 MOS_STATUS Linux_InsertCmdBufferToPool(
527 PMOS_CONTEXT pOsContext,
528 PMOS_COMMAND_BUFFER pCmdBuffer)
529 {
530 int32_t index = 0;
531 MOS_STATUS eStatus;
532
533 MOS_OS_FUNCTION_ENTER;
534
535 eStatus = MOS_STATUS_SUCCESS;
536
537 MOS_OS_CHK_NULL(pOsContext);
538 MOS_OS_CHK_NULL(pCmdBuffer);
539 MOS_OS_CHK_STATUS(Linux_WaitForAvailableCmdBo(pOsContext));
540
541 index = pOsContext->CmdBufferPool.iFetch;
542
543 pOsContext->CmdBufferPool.pCmd_bo[index] = pCmdBuffer->OsResource.bo;
544 pCmdBuffer->iCmdIndex = index;
545
546 pOsContext->CmdBufferPool.iFetch++;
547 if (pOsContext->CmdBufferPool.iFetch >= MAX_CMD_BUF_NUM)
548 {
549 pOsContext->CmdBufferPool.iFetch = 0;
550 }
551
552 finish:
553 return eStatus;
554 }
555
556 //!
557 //! \brief Linux Refresh
558 //! \details Linux Refresh
559 //! \param MOS_CONTEXT * pOsContext
560 //! [in] Pointer to OS context structure
561 //! \return int32_t
562 //! true always
563 //!
Linux_Refresh(MOS_CONTEXT * pOsContext)564 int32_t Linux_Refresh(MOS_CONTEXT *pOsContext)
565 {
566 MOS_UNUSED(pOsContext);
567 return true;
568 }
569
570 #ifndef ANDROID
571
572 #define MOS_LINUX_IPC_INVALID_ID -1
573 #define MOS_LINUX_SHM_INVALID (void *)-1
574 #define MOS_LINUX_SEM_MAX_TRIES 10
575
DetachDestroyShm(int32_t shmid,void * pShm)576 static MOS_STATUS DetachDestroyShm(int32_t shmid, void *pShm)
577 {
578 struct shmid_ds buf;
579 MOS_ZeroMemory(&buf, sizeof(buf));
580
581 if (shmid < 0)
582 {
583 return MOS_STATUS_UNKNOWN;
584 }
585
586 if ((pShm != MOS_LINUX_SHM_INVALID) && (pShm != nullptr) && shmdt(pShm) < 0)
587 {
588 return MOS_STATUS_UNKNOWN;
589 }
590
591 if (shmctl(shmid, IPC_STAT, &buf) < 0)
592 {
593 return MOS_STATUS_UNKNOWN;
594 }
595
596 if (buf.shm_nattch == 0)
597 {
598 if (shmctl(shmid, IPC_RMID, nullptr) < 0)
599 {
600 return MOS_STATUS_UNKNOWN;
601 }
602 }
603 return MOS_STATUS_SUCCESS;
604 }
605
ConnectCreateShm(long key,uint32_t size,int32_t * pShmid,void ** ppShm)606 static MOS_STATUS ConnectCreateShm(long key, uint32_t size, int32_t *pShmid, void **ppShm)
607 {
608 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
609 MOS_OS_CHK_NULL_RETURN(pShmid);
610 MOS_OS_CHK_NULL_RETURN(ppShm);
611
612 struct shmid_ds buf;
613 int32_t shmid = -1;
614 key_t key_value = (key_t)key;
615 void * shmptr = nullptr;
616 MOS_ZeroMemory(&buf, sizeof(buf));
617
618 shmid = shmget(key_value, size, IPC_CREAT | 0666);
619 if (shmid < 0)
620 {
621 return MOS_STATUS_UNKNOWN;
622 }
623
624 shmptr = shmat(shmid, 0, 0);
625 if (shmptr == MOS_LINUX_SHM_INVALID)
626 {
627 DetachDestroyShm(shmid, shmptr);
628 return MOS_STATUS_UNKNOWN;
629 }
630
631 if (shmctl(shmid, IPC_STAT, &buf) < 0)
632 {
633 // can't get any status info
634 DetachDestroyShm(shmid, shmptr);
635 return MOS_STATUS_UNKNOWN;
636 }
637
638 *ppShm = shmptr;
639 *pShmid = shmid;
640
641 return MOS_STATUS_SUCCESS;
642 }
643
ConnectCreateSemaphore(long key,int32_t * pSemid)644 static MOS_STATUS ConnectCreateSemaphore(long key, int32_t *pSemid)
645 {
646 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
647 MOS_OS_CHK_NULL_RETURN(pSemid);
648 int32_t semid = -1;
649 struct sembuf sop;
650 struct semid_ds buf;
651 uint32_t i = 0;
652 key_t key_value = (key_t)key;
653 int32_t val = 0;
654 MOS_ZeroMemory(&sop, sizeof(sop));
655 MOS_ZeroMemory(&buf, sizeof(buf));
656
657 semid = semget(key, 1, IPC_CREAT | IPC_EXCL | 0666);
658
659 if (semid != MOS_LINUX_IPC_INVALID_ID)
660 {
661 // initialize it to 0
662 if (semctl(semid, 0, SETVAL, val) == -1)
663 {
664 return MOS_STATUS_UNKNOWN;
665 }
666
667 // Perform a "no-op" semaphore operation - changes sem_otime
668 // so other processes can see we've initialized the set.
669 sop.sem_num = 0;
670 sop.sem_op = 0; //Wait for value to equal 0
671 sop.sem_flg = 0;
672 if (semop(semid, &sop, 1) == -1)
673 {
674 return MOS_STATUS_UNKNOWN;
675 }
676
677 }
678 else
679 {
680 // errno EEXIST
681 semid = semget(key, 1, 0666);
682 if (semid == MOS_LINUX_IPC_INVALID_ID)
683 {
684 return MOS_STATUS_UNKNOWN;
685 }
686 }
687
688 *pSemid = semid;
689
690 return MOS_STATUS_SUCCESS;
691 }
692
DestroySemaphore(int32_t semid)693 static MOS_STATUS DestroySemaphore(int32_t semid)
694 {
695 int32_t nwait = -1;
696
697 if (semid < 0)
698 {
699 return MOS_STATUS_UNKNOWN;
700 }
701
702 nwait = semctl(semid, 0, GETZCNT, 0);
703
704 if (nwait > 0)
705 {
706 return MOS_STATUS_SUCCESS;
707 }
708
709 if (semctl(semid, 0, IPC_RMID, nullptr) < 0)
710 {
711 return MOS_STATUS_UNKNOWN;
712 }
713
714 return MOS_STATUS_SUCCESS;
715 }
716
ShmAttachedNumber(int32_t shmid)717 static int16_t ShmAttachedNumber(int32_t shmid)
718 {
719 struct shmid_ds buf;
720 MOS_ZeroMemory(&buf, sizeof(buf));
721
722 if (shmctl(shmid, IPC_STAT, &buf) < 0)
723 {
724 return -1;
725 }
726
727 return buf.shm_nattch;
728 }
729
LockSemaphore(int32_t semid)730 static MOS_STATUS LockSemaphore(int32_t semid)
731 {
732 struct sembuf op[2] = {};
733 op[0].sem_num = 0; // wait for [0] to be 0
734 op[0].sem_op = 0;
735 op[0].sem_flg = 0;
736 op[1].sem_num = 0;
737 op[1].sem_op = 1; // increment
738 op[1].sem_flg = SEM_UNDO;
739
740 if (semid < 0)
741 {
742 return MOS_STATUS_UNKNOWN;
743 }
744
745 if (semop(semid, op, 2) < 0)
746 {
747 return MOS_STATUS_UNKNOWN;
748 }
749
750 return MOS_STATUS_SUCCESS;
751 }
752
UnLockSemaphore(int32_t semid)753 static MOS_STATUS UnLockSemaphore(int32_t semid)
754 {
755 struct sembuf op;
756 op.sem_num = 0;
757 op.sem_op = -1; // decrement back to 0
758 op.sem_flg = SEM_UNDO;
759
760 if (semid < 0)
761 {
762 return MOS_STATUS_UNKNOWN;
763 }
764
765 if (semop(semid, &op, 1) < 0)
766 {
767 return MOS_STATUS_UNKNOWN;
768 }
769
770 return MOS_STATUS_SUCCESS;
771 }
772
DestroyIPC(PMOS_CONTEXT pOsContext)773 void DestroyIPC(PMOS_CONTEXT pOsContext)
774 {
775 if (MOS_LINUX_IPC_INVALID_ID != pOsContext->semid)
776 {
777 int16_t iAttachedNum = 0;
778
779 if (MOS_LINUX_IPC_INVALID_ID != pOsContext->shmid)
780 {
781 LockSemaphore(pOsContext->semid);
782 iAttachedNum = ShmAttachedNumber(pOsContext->shmid);
783
784 DetachDestroyShm(pOsContext->shmid, pOsContext->pShm);
785 pOsContext->shmid = MOS_LINUX_IPC_INVALID_ID;
786 pOsContext->pShm = MOS_LINUX_SHM_INVALID;
787
788 if (iAttachedNum) --iAttachedNum;
789 UnLockSemaphore(pOsContext->semid);
790 }
791 }
792 }
793
CreateIPC(PMOS_CONTEXT pOsContext)794 MOS_STATUS CreateIPC(PMOS_CONTEXT pOsContext)
795 {
796 MOS_STATUS eStatus;
797
798 MOS_OS_CHK_NULL(pOsContext);
799 pOsContext->semid = MOS_LINUX_IPC_INVALID_ID;
800 pOsContext->shmid = MOS_LINUX_IPC_INVALID_ID;
801 pOsContext->pShm = MOS_LINUX_SHM_INVALID;
802
803 struct semid_ds buf;
804 MOS_ZeroMemory(&buf, sizeof(buf));
805
806 //wait and retry untill to get a valid semaphore
807 for (int i = 0; i < MOS_LINUX_SEM_MAX_TRIES; i ++)
808 {
809 ConnectCreateSemaphore(DUAL_VDBOX_KEY, &pOsContext->semid);
810
811 //check whether the semid is initialized or not
812 if (semctl(pOsContext->semid, 0, IPC_STAT, &buf) == -1)
813 {
814 return MOS_STATUS_UNKNOWN;
815 }
816 if (buf.sem_otime != 0)
817 {
818 break;
819 }
820
821 MosUtilities::MosSleep(1); //wait and retry
822 }
823
824 LockSemaphore(pOsContext->semid);
825 eStatus = ConnectCreateShm(DUAL_VDBOX_KEY, sizeof(VDBOX_WORKLOAD), &pOsContext->shmid, &pOsContext->pShm);
826 UnLockSemaphore(pOsContext->semid);
827 MOS_CHK_STATUS_SAFE(eStatus);
828
829 finish:
830 return eStatus;
831 }
832 #endif
833
Linux_GetGpuContext(PMOS_INTERFACE pOsInterface,uint32_t gpuContextHandle)834 GpuContextSpecific* Linux_GetGpuContext(PMOS_INTERFACE pOsInterface, uint32_t gpuContextHandle)
835 {
836 MOS_OS_FUNCTION_ENTER;
837
838 if (pOsInterface == nullptr || pOsInterface->osContextPtr == nullptr)
839 {
840 MOS_OS_ASSERTMESSAGE("invalid input parameters!");
841 return nullptr;
842 }
843
844 auto osCxtSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
845
846 auto gpuContextMgr = osCxtSpecific->GetGpuContextMgr();
847 if (gpuContextMgr == nullptr)
848 {
849 MOS_OS_ASSERTMESSAGE("m_gpuContextMgr cannot be nullptr");
850 return nullptr;
851 }
852
853 auto gpuContext = gpuContextMgr->GetGpuContext(gpuContextHandle);
854 if (gpuContext == nullptr)
855 {
856 MOS_OS_ASSERTMESSAGE("cannot find the gpuContext corresponding to the active gpuContextHandle");
857 return nullptr;
858 }
859
860 auto gpuContextSpecific = static_cast<GpuContextSpecific *>(gpuContext);
861
862 return gpuContextSpecific;
863 }
864
865 //!
866 //! \brief Initialize the GPU Status Buffer
867 //! \details Initialize the GPU Status Buffer
868 //! \param MOS_CONTEXT * pOsContext
869 //! [in, out] Pointer to OS context structure
870 //! \return MOS_STATUS
871 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
872 //!
Linux_InitGPUStatus(PMOS_CONTEXT pOsContext)873 MOS_STATUS Linux_InitGPUStatus(
874 PMOS_CONTEXT pOsContext)
875 {
876 MOS_LINUX_BO *bo = nullptr;
877 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
878 struct mos_drm_bo_alloc alloc;
879
880 if (pOsContext == nullptr)
881 {
882 MOS_OS_ASSERTMESSAGE("Linux_InitGPUStatus:pOsContext == NULL");
883 eStatus = MOS_STATUS_NULL_POINTER;
884 goto finish;
885 }
886
887 pOsContext->pGPUStatusBuffer =
888 (MOS_RESOURCE*)MOS_AllocAndZeroMemory(sizeof(MOS_RESOURCE) * MOS_GPU_CONTEXT_MAX);
889 if (nullptr == pOsContext->pGPUStatusBuffer)
890 {
891 MOS_OS_ASSERTMESSAGE("pContext->pGPUStatusBuffer malloc failed.");
892 eStatus = MOS_STATUS_NO_SPACE;
893 goto finish;
894 }
895
896 // Allocate the command buffer from GEM
897 alloc.name = "GPU Status Buffer";
898 alloc.size = sizeof(MOS_GPU_STATUS_DATA) * MOS_GPU_CONTEXT_MAX;
899 alloc.alignment = 4096;
900 alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
901 bo = mos_bo_alloc(pOsContext->bufmgr, &alloc); // Align to page boundary
902 if (bo == nullptr)
903 {
904 MOS_OS_ASSERTMESSAGE("Allocation of GPU Status Buffer failed.");
905 eStatus = MOS_STATUS_NO_SPACE;
906 goto finish;
907 }
908
909 // Map command buffer to user virtual address
910 if (mos_bo_map(bo, 1) != 0) // Write enable set
911 {
912 MOS_OS_ASSERTMESSAGE("Mapping of GPU Status Buffer failed.");
913 eStatus = MOS_STATUS_INVALID_HANDLE;
914 goto finish;
915 }
916
917 Mos_ResetResource(pOsContext->pGPUStatusBuffer);
918
919 // Fill in resource information
920 pOsContext->pGPUStatusBuffer->Format = Format_Buffer;
921 pOsContext->pGPUStatusBuffer->iWidth = bo->size;
922 pOsContext->pGPUStatusBuffer->iHeight = 1;
923 pOsContext->pGPUStatusBuffer->iPitch = bo->size;
924 pOsContext->pGPUStatusBuffer->iCount = 1;
925 pOsContext->pGPUStatusBuffer->pData = (uint8_t*)bo->virt;
926 pOsContext->pGPUStatusBuffer->TileType = MOS_TILE_LINEAR;
927 pOsContext->pGPUStatusBuffer->bo = bo;
928 pOsContext->pGPUStatusBuffer->bMapped = true;
929
930 MOS_ZeroMemory(pOsContext->pGPUStatusBuffer->pData, bo->size);
931
932 finish:
933 return eStatus;
934 }
935
936 //!
937 //! \brief Release the GPU Status Buffer
938 //! \details Release the GPU Status Buffer
939 //! \param MOS_CONTEXT * pOsContext
940 //! [in, out] Pointer to OS context structure
941 //! \return void
942 //!
Linux_ReleaseGPUStatus(PMOS_CONTEXT pOsContext)943 void Linux_ReleaseGPUStatus(
944 PMOS_CONTEXT pOsContext)
945 {
946 MOS_LINUX_BO *bo = nullptr;
947
948 if ( pOsContext == nullptr || pOsContext->pGPUStatusBuffer == nullptr)
949 {
950 return;
951 }
952
953 bo = pOsContext->pGPUStatusBuffer->bo;
954 if (bo != nullptr)
955 {
956 mos_bo_unmap(bo);
957 mos_bo_wait_rendering(bo);
958 mos_bo_unreference(bo);
959 }
960 pOsContext->pGPUStatusBuffer->bo = nullptr;
961
962 MOS_FreeMemAndSetNull(pOsContext->pGPUStatusBuffer);
963 }
964
965 //!
966 //! \brief Get GPU status tag for the given GPU context
967 //! \details Get GPU status tag for the given GPU context
968 //! \param MOS_CONTEXT * pOsContext
969 //! [in] Pointer to OS context structure
970 //! \param MOS_GPU_CONTEXT GpuContext
971 //! [in, out] GPU Context
972 //! \return uint32_t
973 //! GPU status tag
974 //!
Linux_GetGpuCtxBufferTag(PMOS_CONTEXT pOsContext,MOS_GPU_CONTEXT GpuContext)975 uint32_t Linux_GetGpuCtxBufferTag(
976 PMOS_CONTEXT pOsContext,
977 MOS_GPU_CONTEXT GpuContext)
978 {
979 if ( pOsContext == nullptr)
980 {
981 MOS_OS_ASSERTMESSAGE("Invalid pOsContext.");
982 return 0;
983 }
984
985 if (GpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
986 {
987 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
988 return 0;
989 }
990
991 return pOsContext->OsGpuContext[GpuContext].uiGPUStatusTag;
992 }
993
994 //!
995 //! \brief Increment GPU status tag for the given GPU context
996 //! \details Increment GPU status tag for the given GPU context
997 //! \param MOS_CONTEXT * pOsContext
998 //! [in] Pointer to OS context structure
999 //! \param MOS_GPU_CONTEXT GpuContext
1000 //! [in] GPU Context
1001 //! \return void
1002 //!
Linux_IncGpuCtxBufferTag(PMOS_CONTEXT pOsContext,MOS_GPU_CONTEXT GpuContext)1003 void Linux_IncGpuCtxBufferTag(
1004 PMOS_CONTEXT pOsContext,
1005 MOS_GPU_CONTEXT GpuContext)
1006 {
1007 uint32_t uiGPUStatusTag;
1008
1009 if ( pOsContext == nullptr)
1010 {
1011 MOS_OS_ASSERTMESSAGE("Invalid pOsContext.");
1012 return;
1013 }
1014
1015 if (GpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
1016 {
1017 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
1018 return;
1019 }
1020
1021 uiGPUStatusTag = pOsContext->OsGpuContext[GpuContext].uiGPUStatusTag;
1022
1023 pOsContext->OsGpuContext[GpuContext].uiGPUStatusTag = uiGPUStatusTag % UINT_MAX + 1;
1024 if(pOsContext->OsGpuContext[GpuContext].uiGPUStatusTag == 0)
1025 {
1026 pOsContext->OsGpuContext[GpuContext].uiGPUStatusTag = 1;
1027 }
1028 }
1029
Linux_GetGmmClientContext(PMOS_CONTEXT pOsContext)1030 GMM_CLIENT_CONTEXT* Linux_GetGmmClientContext(PMOS_CONTEXT pOsContext)
1031 {
1032 if (pOsContext == nullptr)
1033 {
1034 return nullptr;
1035 }
1036 return pOsContext->pGmmClientContext;
1037 }
1038
1039 //!
1040 //! \brief Get GPU tag for the given GPU context from the status buffer
1041 //! \details Get GPU tag for the given GPU context from the status buffer
1042 //! \param MOS_CONTEXT * pOsContext
1043 //! [in] Pointer to OS context structure
1044 //! \param MOS_GPU_CONTEXT GpuContext
1045 //! [in] GPU Context
1046 //! \return uint32_t
1047 //! GPU tag
1048 //!
Linux_GetGPUTag(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT mosGpuCtx)1049 uint32_t Linux_GetGPUTag(
1050 PMOS_INTERFACE pOsInterface,
1051 MOS_GPU_CONTEXT mosGpuCtx)
1052 {
1053 MOS_OS_FUNCTION_ENTER;
1054
1055 if (pOsInterface == nullptr)
1056 {
1057 MOS_OS_ASSERTMESSAGE("invalid input parameters!");
1058 return 0;
1059 }
1060
1061 if (mosGpuCtx == MOS_GPU_CONTEXT_INVALID_HANDLE)
1062 {
1063 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
1064 return 0;
1065 }
1066
1067 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
1068 {
1069 if (pOsInterface->osContextPtr == nullptr)
1070 {
1071 MOS_OS_ASSERTMESSAGE("invalid input parameters!");
1072 return 0;
1073 }
1074
1075 auto osCxtSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
1076
1077 auto handle = osCxtSpecific->GetGpuContextHandle(mosGpuCtx);
1078
1079 if (pOsInterface->apoMosEnabled)
1080 {
1081 PMOS_RESOURCE gpuStatusResource = nullptr;
1082 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetGpuStatusBufferResource(pOsInterface->osStreamState, gpuStatusResource, handle));
1083 MOS_OS_CHK_NULL_RETURN(gpuStatusResource);
1084 auto gpuStatusData = (MOS_GPU_STATUS_DATA *)gpuStatusResource->pData;
1085 if (gpuStatusData == nullptr)
1086 {
1087 MOS_OS_ASSERTMESSAGE("cannot find ");
1088 return 0;
1089 }
1090 return gpuStatusData->GPUTag;
1091 }
1092
1093 auto gpuContext = Linux_GetGpuContext(pOsInterface, handle);
1094
1095 if (gpuContext == nullptr)
1096 {
1097 MOS_OS_ASSERTMESSAGE("cannot get corresponding gpu context!");
1098 return 0;
1099 }
1100
1101 auto resource = gpuContext->GetStatusBufferResource();
1102
1103 if (resource == nullptr)
1104 {
1105 MOS_OS_ASSERTMESSAGE("cannot find the gpuContext corresponding to the active resource.");
1106 return 0;
1107 }
1108
1109 MOS_RESOURCE gpuStatusResource;
1110 MOS_OS_CHK_STATUS_RETURN(resource->ConvertToMosResource(&gpuStatusResource));
1111 auto gpuStatusData = (MOS_GPU_STATUS_DATA *)gpuStatusResource.pData;
1112 if (gpuStatusData == nullptr)
1113 {
1114 MOS_OS_ASSERTMESSAGE("cannot find ");
1115 return 0;
1116 }
1117 return gpuStatusData->GPUTag;
1118 }
1119
1120 MOS_GPU_STATUS_DATA *pGPUStatusData = nullptr;
1121
1122 if ( pOsInterface->pOsContext == nullptr ||
1123 pOsInterface->pOsContext->pGPUStatusBuffer == nullptr ||
1124 pOsInterface->pOsContext->pGPUStatusBuffer->pData == nullptr)
1125 {
1126 return 0;
1127 }
1128
1129 pGPUStatusData = (MOS_GPU_STATUS_DATA *)(pOsInterface->pOsContext->pGPUStatusBuffer->pData + (sizeof(MOS_GPU_STATUS_DATA) * mosGpuCtx));
1130 if (pGPUStatusData == nullptr)
1131 {
1132 MOS_OS_ASSERTMESSAGE("cannot find the gpuContext corresponding to the active resource");
1133 return 0;
1134 }
1135 return pGPUStatusData->GPUTag;
1136 }
1137
1138 //!
1139 //! \brief Destroy Linux context
1140 //! \details Destroy Linux context
1141 //! \param PMOS_CONTEXT pOsContext
1142 //! [in] Pointer to OS context structure
1143 //! \return void
1144 //!
Linux_Destroy(PMOS_CONTEXT pOsContext,int32_t MODSEnabled,int32_t modularizedGpuCtxEnabled)1145 void Linux_Destroy(
1146 PMOS_CONTEXT pOsContext,
1147 int32_t MODSEnabled,
1148 int32_t modularizedGpuCtxEnabled)
1149 {
1150 PCOMMAND_BUFFER pCurrCB = nullptr;
1151 PCOMMAND_BUFFER pNextCB = nullptr;
1152 int32_t iSize = 0;
1153 int i = 0;
1154 if (pOsContext == nullptr)
1155 {
1156 MOS_OS_ASSERTMESSAGE("OsContext is null.");
1157 return;
1158 }
1159
1160 #ifndef ANDROID
1161 if (pOsContext->bKMDHasVCS2)
1162 {
1163 DestroyIPC(pOsContext);
1164 }
1165 #endif
1166
1167 if (!modularizedGpuCtxEnabled)
1168 {
1169 Linux_ReleaseCmdBufferPool(pOsContext);
1170
1171 for (i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
1172 {
1173 MOS_FreeMemAndSetNull(pOsContext->OsGpuContext[i].pCB);
1174
1175 pCurrCB = pOsContext->OsGpuContext[i].pStartCB;
1176 for (; (pCurrCB); pCurrCB = pNextCB)
1177 {
1178 pNextCB = pCurrCB->pNext;
1179 MOS_FreeMemAndSetNull(pCurrCB);
1180 }
1181 }
1182
1183 Linux_ReleaseGPUStatus(pOsContext);
1184 }
1185
1186 if (pOsContext->contextOffsetList.size())
1187 {
1188 pOsContext->contextOffsetList.clear();
1189 pOsContext->contextOffsetList.shrink_to_fit();
1190 }
1191
1192 if (!MODSEnabled && (pOsContext->intel_context))
1193 {
1194 if (pOsContext->intel_context->vm_id != INVALID_VM)
1195 {
1196 mos_vm_destroy(pOsContext->intel_context->bufmgr,pOsContext->intel_context->vm_id);
1197 pOsContext->intel_context->vm_id = INVALID_VM;
1198 }
1199 mos_context_destroy(pOsContext->intel_context);
1200 }
1201
1202 MOS_Delete(pOsContext);
1203 }
1204
1205 //!
1206 //! \brief Get DMA Buffer ID
1207 //! \details Get the DMA perf Buffer ID
1208 //! \param PMOS_CONTEXT pOsContext
1209 //! [in] Pointer to OS context structure
1210 //! \return uint32_t
1211 //! Return the buffer ID
1212 //!
Linux_GetDmaBufID(PMOS_CONTEXT pOsContext)1213 uint32_t Linux_GetDmaBufID (PMOS_CONTEXT pOsContext )
1214 {
1215 if (pOsContext == nullptr)
1216 {
1217 MOS_OS_ASSERTMESSAGE("OsContext is null.");
1218 return 0;
1219 }
1220
1221 uint32_t dmaBufID = 0;
1222 if (pOsContext->pPerfData != nullptr)
1223 {
1224 dmaBufID = pOsContext->pPerfData->dmaBufID;
1225 }
1226 return dmaBufID;
1227 }
1228
1229 //!
1230 //! \brief Get Buffer Type
1231 //! \details Returns the type of buffer, 1D, 2D or volume
1232 //! \param PMOS_RESOURCE pOsResource
1233 //! [in] Pointer to OS Resource
1234 //! \return GFX resource Type
1235 //!
GetResType(PMOS_RESOURCE pOsResource)1236 MOS_GFXRES_TYPE GetResType(PMOS_RESOURCE pOsResource)
1237 {
1238 GMM_RESOURCE_INFO *pGmmResourceInfo = nullptr;
1239 MOS_GFXRES_TYPE ResType = MOS_GFXRES_INVALID;
1240 GMM_RESOURCE_TYPE GMMResType = RESOURCE_INVALID;
1241
1242 if (pOsResource == nullptr)
1243 {
1244 MOS_OS_ASSERTMESSAGE("OsContext is null.");
1245 return MOS_GFXRES_INVALID;
1246 }
1247
1248 pGmmResourceInfo = (GMM_RESOURCE_INFO *)pOsResource->pGmmResInfo;
1249 GMMResType = pGmmResourceInfo->GetResourceType();
1250
1251 switch (GMMResType)
1252 {
1253 case RESOURCE_BUFFER:
1254 ResType = MOS_GFXRES_BUFFER;
1255 break;
1256 case RESOURCE_3D:
1257 ResType = MOS_GFXRES_VOLUME;
1258 break;
1259 case RESOURCE_2D:
1260 ResType = MOS_GFXRES_2D;
1261 break;
1262 default:
1263 break;
1264 }
1265 return ResType;
1266 }
1267 //!
1268 //! \brief Set the DMA Buffer ID
1269 //! \details Sets the buffer ID in perf data
1270 //! \param PMOS_CONTEXT pOsContext
1271 //! [in] Pointer to OS context structure
1272 //! \param uint32_t dwDmaBufID
1273 //! [in] Buffer ID to be set
1274 //! \return void
1275 //!
Linux_SetDmaBufID(PMOS_CONTEXT pOsContext,uint32_t dwDmaBufID)1276 void Linux_SetDmaBufID ( PMOS_CONTEXT pOsContext, uint32_t dwDmaBufID )
1277 {
1278 if (pOsContext == nullptr)
1279 {
1280 MOS_OS_ASSERTMESSAGE("OsContext is null.");
1281 return;
1282 }
1283
1284 if (pOsContext->pPerfData != nullptr)
1285 {
1286 pOsContext->pPerfData->dmaBufID = dwDmaBufID;
1287 }
1288 }
1289
1290 //!
1291 //! \brief Set the DMA Kernel ID
1292 //! \details Sets the Kernel ID in perf data
1293 //! \param PMOS_CONTEXT pOsContext
1294 //! [in] Pointer to OS context structure
1295 //! \param uint32_t KernelID
1296 //! [in] Buffer ID to be set
1297 //! \return void
1298 //!
Linux_SetPerfHybridKernelID(PMOS_CONTEXT pOsContext,uint32_t KernelID)1299 void Linux_SetPerfHybridKernelID ( PMOS_CONTEXT pOsContext, uint32_t KernelID)
1300 {
1301 if (pOsContext == nullptr)
1302 {
1303 MOS_OS_ASSERTMESSAGE("OsContext is null.");
1304 return;
1305 }
1306
1307 if (pOsContext->pPerfData != nullptr)
1308 {
1309 pOsContext->pPerfData->dmaBufID = (pOsContext->pPerfData->dmaBufID & 0xF0FF) | ((KernelID <<8) & 0x0F00);
1310 }
1311 }
1312
1313 //!
1314 //! \brief Init Linux context
1315 //! \details Initialize the linux context
1316 //! \param MOS_OS_CONTEXT * pContext
1317 //! [in] Pointer to OS context structure
1318 //! \param PMOS_CONTEXT pOsDriverContext
1319 //! [in] Pointer to OS Driver context
1320 //! \return MOS_STATUS
1321 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1322 //!
Linux_InitContext(MOS_OS_CONTEXT * pContext,PMOS_CONTEXT pOsDriverContext,int32_t MODSEnabled,int32_t modularizedGpuCtxEnabled)1323 MOS_STATUS Linux_InitContext(
1324 MOS_OS_CONTEXT *pContext,
1325 PMOS_CONTEXT pOsDriverContext,
1326 int32_t MODSEnabled,
1327 int32_t modularizedGpuCtxEnabled)
1328 {
1329 int32_t iDeviceId = -1;
1330 MOS_STATUS eStatus;
1331 int32_t i = -1;
1332
1333 MOS_OS_FUNCTION_ENTER;
1334
1335 eStatus = MOS_STATUS_SUCCESS;
1336
1337 if (nullptr == pContext ||
1338 nullptr == pOsDriverContext ||
1339 nullptr == pOsDriverContext->bufmgr ||
1340 (nullptr == pOsDriverContext->m_gpuContextMgr && modularizedGpuCtxEnabled && !pOsDriverContext->m_apoMosEnabled) ||
1341 (nullptr == pOsDriverContext->m_cmdBufMgr && modularizedGpuCtxEnabled && !pOsDriverContext->m_apoMosEnabled) ||
1342 0 >= pOsDriverContext->fd)
1343 {
1344 MOS_OS_ASSERT(false);
1345 return MOS_STATUS_INVALID_HANDLE;
1346 }
1347 pContext->bufmgr = pOsDriverContext->bufmgr;
1348 pContext->m_gpuContextMgr = pOsDriverContext->m_gpuContextMgr;
1349 pContext->m_cmdBufMgr = pOsDriverContext->m_cmdBufMgr;
1350 pContext->fd = pOsDriverContext->fd;
1351 pContext->pPerfData = pOsDriverContext->pPerfData;
1352 pContext->m_auxTableMgr = pOsDriverContext->m_auxTableMgr;
1353 pContext->m_userSettingPtr = pOsDriverContext->m_userSettingPtr;
1354
1355 mos_bufmgr_enable_reuse(pOsDriverContext->bufmgr);
1356
1357 // DDI layer can pass over the DeviceID.
1358 iDeviceId = pOsDriverContext->iDeviceId;
1359 if (0 == iDeviceId)
1360 {
1361 //Such as CP, it calls InitMosInterface() dretly without creating MediaContext.
1362 iDeviceId = mos_bufmgr_get_devid(pOsDriverContext->bufmgr);
1363 pOsDriverContext->iDeviceId = iDeviceId;
1364
1365 MOS_OS_CHK_STATUS_MESSAGE(
1366 HWInfo_GetGfxInfo(pOsDriverContext->fd, pOsDriverContext->bufmgr, &pContext->m_platform, &pContext->m_skuTable, &pContext->m_waTable, &pContext->m_gtSystemInfo, pOsDriverContext->m_userSettingPtr),
1367 "Fatal error - unsuccesfull Sku/Wa/GtSystemInfo initialization");
1368
1369 pOsDriverContext->m_skuTable = pContext->m_skuTable;
1370 pOsDriverContext->m_waTable = pContext->m_waTable;
1371 pOsDriverContext->m_gtSystemInfo = pContext->m_gtSystemInfo;
1372 pOsDriverContext->m_platform = pContext->m_platform;
1373 MOS_OS_NORMALMESSAGE("DeviceID was created DeviceID = %d, platform product %d", iDeviceId, pContext->m_platform.eProductFamily);
1374 }
1375 else
1376 {
1377 // pOsDriverContext's parameters were passed by CmCreateDevice.
1378 // Get SkuTable/WaTable/systemInfo/platform from OSDriver directly.
1379 pContext->m_skuTable = pOsDriverContext->m_skuTable;
1380 pContext->m_waTable = pOsDriverContext->m_waTable;
1381 pContext->m_gtSystemInfo = pOsDriverContext->m_gtSystemInfo;
1382 pContext->m_platform = pOsDriverContext->m_platform;
1383 }
1384
1385 pContext->bUse64BitRelocs = true;
1386 pContext->bUseSwSwizzling = pContext->bSimIsActive || MEDIA_IS_SKU(&pContext->m_skuTable, FtrUseSwSwizzling);
1387 pContext->bTileYFlag = MEDIA_IS_SKU(&pContext->m_skuTable, FtrTileY);
1388 // when MODS enabled, intel_context will be created by pOsContextSpecific, should not recreate it here, or will cause memory leak.
1389 if (!MODSEnabled)
1390 {
1391 pContext->intel_context = mos_context_create_ext(pOsDriverContext->bufmgr, 0, pOsDriverContext->m_protectedGEMContext);
1392 if (!Mos_Solo_IsEnabled(nullptr) && pContext->intel_context)
1393 {
1394 pContext->intel_context->vm_id = mos_vm_create(pOsDriverContext->bufmgr);
1395 if (pContext->intel_context->vm_id == INVALID_VM)
1396 {
1397 MOS_OS_ASSERTMESSAGE("Failed to create vm.\n");
1398 return MOS_STATUS_UNKNOWN;
1399 }
1400 }
1401 else //try legacy context create ioctl if DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT is not supported
1402 {
1403 pContext->intel_context = mos_context_create(pOsDriverContext->bufmgr);
1404 if (pContext->intel_context)
1405 {
1406 pContext->intel_context->vm_id = INVALID_VM;
1407 }
1408 }
1409
1410 if (pContext->intel_context == nullptr)
1411 {
1412 MOS_OS_ASSERTMESSAGE("Failed to create drm intel context");
1413 return MOS_STATUS_UNKNOWN;
1414 }
1415 }
1416
1417 pContext->intel_context->pOsContext = pContext;
1418
1419 pContext->bIsAtomSOC = IS_ATOMSOC(iDeviceId);
1420
1421 if(!modularizedGpuCtxEnabled)
1422 {
1423 Linux_InitCmdBufferPool(pContext);
1424
1425 // Initialize GPU Status Buffer
1426 eStatus = Linux_InitGPUStatus(pContext);
1427 if (MOS_STATUS_SUCCESS != eStatus)
1428 {
1429 goto finish;
1430 }
1431
1432 for (i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
1433 {
1434 pContext->OsGpuContext[i].pStartCB = nullptr;
1435 pContext->OsGpuContext[i].pCurrentCB = nullptr;
1436 pContext->OsGpuContext[i].bCBFlushed = true;
1437 pContext->OsGpuContext[i].uiCommandBufferSize = COMMAND_BUFFER_SIZE;
1438 pContext->OsGpuContext[i].pCB =
1439 (PMOS_COMMAND_BUFFER)MOS_AllocAndZeroMemory(sizeof(MOS_COMMAND_BUFFER));
1440
1441 if (nullptr == pContext->OsGpuContext[i].pCB)
1442 {
1443 MOS_OS_ASSERTMESSAGE("No More Avaliable Memory");
1444 eStatus = MOS_STATUS_NO_SPACE;
1445 goto finish;
1446 }
1447
1448 // each thread has its own GPU context, so do not need any lock as guarder here
1449 pContext->OsGpuContext[i].pAllocationList =
1450 (ALLOCATION_LIST*)MOS_AllocAndZeroMemory(sizeof(ALLOCATION_LIST) * ALLOCATIONLIST_SIZE);
1451 if (nullptr == pContext->OsGpuContext[i].pAllocationList)
1452 {
1453 MOS_OS_ASSERTMESSAGE("pContext->OsGpuContext[%d].pAllocationList malloc failed.", i);
1454 eStatus = MOS_STATUS_NO_SPACE;
1455 goto finish;
1456 }
1457 pContext->OsGpuContext[i].uiMaxNumAllocations = ALLOCATIONLIST_SIZE;
1458
1459 pContext->OsGpuContext[i].pPatchLocationList =
1460 (PATCHLOCATIONLIST*)MOS_AllocAndZeroMemory(sizeof(PATCHLOCATIONLIST) * PATCHLOCATIONLIST_SIZE);
1461 if (nullptr == pContext->OsGpuContext[i].pPatchLocationList)
1462 {
1463 MOS_OS_ASSERTMESSAGE("pContext->OsGpuContext[%d].pPatchLocationList malloc failed.", i);
1464 eStatus = MOS_STATUS_NO_SPACE;
1465 goto finish;
1466 }
1467 pContext->OsGpuContext[i].uiMaxPatchLocationsize = PATCHLOCATIONLIST_SIZE;
1468
1469 pContext->OsGpuContext[i].pResources =
1470 (PMOS_RESOURCE)MOS_AllocAndZeroMemory(sizeof(MOS_RESOURCE) * ALLOCATIONLIST_SIZE);
1471 if (nullptr == pContext->OsGpuContext[i].pResources)
1472 {
1473 MOS_OS_ASSERTMESSAGE("pContext->OsGpuContext[%d].pResources malloc failed.", i);
1474 eStatus = MOS_STATUS_NO_SPACE;
1475 goto finish;
1476 }
1477
1478 pContext->OsGpuContext[i].pbWriteMode =
1479 (int32_t*)MOS_AllocAndZeroMemory(sizeof(int32_t) * ALLOCATIONLIST_SIZE);
1480 if (nullptr == pContext->OsGpuContext[i].pbWriteMode)
1481 {
1482 MOS_OS_ASSERTMESSAGE("pContext->OsGpuContext[%d].pbWriteMode malloc failed.", i);
1483 eStatus = MOS_STATUS_NO_SPACE;
1484 goto finish;
1485 }
1486
1487 pContext->OsGpuContext[i].uiGPUStatusTag = 1;
1488 }
1489 }
1490
1491 #ifndef ANDROID
1492 {
1493 pContext->bKMDHasVCS2 = mos_has_bsd2(pContext->bufmgr);
1494 }
1495 if (pContext->bKMDHasVCS2)
1496 {
1497 eStatus = CreateIPC(pContext);
1498 MOS_CHK_STATUS_SAFE(eStatus);
1499 }
1500 #endif
1501
1502 pContext->pTranscryptedKernels = nullptr;
1503 pContext->uiTranscryptedKernelsSize = 0;
1504
1505 // For Media Memory compression
1506 pContext->ppMediaMemDecompState = pOsDriverContext->ppMediaMemDecompState;
1507 pContext->pfnMemoryDecompress = pOsDriverContext->pfnMemoryDecompress;
1508 pContext->pfnMediaMemoryCopy = pOsDriverContext->pfnMediaMemoryCopy;
1509 pContext->pfnMediaMemoryCopy2D = pOsDriverContext->pfnMediaMemoryCopy2D;
1510
1511 // Set interface functions
1512 pContext->pfnDestroy = Linux_Destroy;
1513 pContext->pfnGetCommandBuffer = Linux_GetCommandBuffer;
1514 pContext->pfnReturnCommandBuffer = Linux_ReturnCommandBuffer;
1515 pContext->pfnFlushCommandBuffer = Linux_FlushCommandBuffer;
1516 pContext->pfnInsertCmdBufferToPool = Linux_InsertCmdBufferToPool;
1517 pContext->pfnWaitAndReleaseCmdBuffer = Linux_WaitAndReleaseCmdBuffer;
1518 pContext->pfnRefresh = Linux_Refresh;
1519 pContext->GetDmaBufID = Linux_GetDmaBufID;
1520 pContext->SetDmaBufID = Linux_SetDmaBufID;
1521 pContext->SetPerfHybridKernelID = Linux_SetPerfHybridKernelID;
1522 pContext->pfnGetGpuCtxBufferTag = Linux_GetGpuCtxBufferTag;
1523 pContext->pfnIncGpuCtxBufferTag = Linux_IncGpuCtxBufferTag;
1524 pContext->GetGPUTag = Linux_GetGPUTag;
1525 pContext->GetGmmClientContext = Linux_GetGmmClientContext;
1526
1527 finish:
1528 if (!modularizedGpuCtxEnabled)
1529 {
1530 // init context failed, roll back
1531 if (eStatus != MOS_STATUS_SUCCESS)
1532 Mos_Specific_ClearGpuContext(pContext);
1533 }
1534
1535 return eStatus;
1536 }
1537 //============= PRIVATE FUNCTIONS <END>=========================================
1538
1539 //!
1540 //! \brief Set GPU context
1541 //! \details Set GPU context for the following rendering operations
1542 //! \param MOS_OS_CONTEXT * pContext
1543 //! [in] Pointer to OS context structure
1544 //! \param MOS_GPU_CONTEXT GpuContext
1545 //! [in] GPU Context
1546 //! \return MOS_STATUS
1547 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1548 //!
Mos_Specific_SetGpuContext(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT GpuContext)1549 MOS_STATUS Mos_Specific_SetGpuContext(
1550 PMOS_INTERFACE pOsInterface,
1551 MOS_GPU_CONTEXT GpuContext)
1552 {
1553 MOS_OS_FUNCTION_ENTER;
1554
1555 MOS_OS_CHK_NULL_RETURN(pOsInterface);
1556
1557 if (GpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
1558 {
1559 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
1560 return MOS_STATUS_INVALID_PARAMETER;
1561 }
1562
1563 // Set GPU context handle
1564 pOsInterface->CurrentGpuContextOrdinal = GpuContext;
1565
1566 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
1567 {
1568 MOS_OS_CHK_NULL_RETURN(pOsInterface->osContextPtr);
1569
1570 auto pOsContextSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
1571 MOS_OS_CHK_NULL_RETURN(pOsContextSpecific);
1572
1573 // Set GPU context handle
1574 pOsInterface->CurrentGpuContextHandle = pOsContextSpecific->GetGpuContextHandle(GpuContext);
1575
1576 if (pOsInterface->apoMosEnabled)
1577 {
1578 if(MEDIA_IS_SKU(&pOsInterface->pOsContext->m_skuTable, FtrProtectedGEMContextPatch))
1579 {
1580 GpuContextSpecificNext* GpuCtxSpecific = MosInterface::GetGpuContext(pOsInterface->osStreamState, pOsInterface->CurrentGpuContextHandle);
1581 MOS_OS_CHK_STATUS_RETURN(GpuCtxSpecific->PatchGPUContextProtection(pOsInterface->osStreamState));
1582 }
1583 MOS_OS_CHK_STATUS_RETURN(MosInterface::SetGpuContext(
1584 pOsInterface->osStreamState,
1585 pOsContextSpecific->GetGpuContextHandle(GpuContext)));
1586 }
1587 }
1588
1589 return MOS_STATUS_SUCCESS;
1590 }
1591
Mos_Specific_SetGpuContextFromHandle(MOS_INTERFACE * osInterface,MOS_GPU_CONTEXT contextName,GPU_CONTEXT_HANDLE contextHandle)1592 MOS_STATUS Mos_Specific_SetGpuContextFromHandle(MOS_INTERFACE *osInterface,
1593 MOS_GPU_CONTEXT contextName,
1594 GPU_CONTEXT_HANDLE contextHandle)
1595 {
1596 MOS_OS_FUNCTION_ENTER;
1597 MOS_OS_CHK_NULL_RETURN(osInterface);
1598
1599 if (MOS_GPU_CONTEXT_INVALID_HANDLE == contextName)
1600 {
1601 MOS_OS_ASSERTMESSAGE("Invalid input parameter contextName.");
1602 return MOS_STATUS_INVALID_PARAMETER;
1603 }
1604
1605 // Set GPU context handle
1606 osInterface->CurrentGpuContextOrdinal = contextName;
1607
1608 if (osInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
1609 {
1610 MOS_OS_CHK_NULL_RETURN(osInterface->osContextPtr);
1611
1612 auto os_context_specific
1613 = static_cast<OsContextSpecific*>(osInterface->osContextPtr);
1614 MOS_OS_CHK_NULL_RETURN(os_context_specific);
1615
1616 // Set GPU context handle
1617 osInterface->CurrentGpuContextHandle = contextHandle;
1618
1619 if (osInterface->apoMosEnabled)
1620 {
1621 MOS_OS_CHK_STATUS_RETURN(
1622 MosInterface::SetGpuContext(osInterface->osStreamState,
1623 contextHandle));
1624 }
1625 }
1626
1627 return MOS_STATUS_SUCCESS;
1628 }
1629
1630 //!
1631 //! \brief Get current GPU context
1632 //! \details Get current GPU context for the following rendering operations
1633 //! \param PMOS_INTERFACE pOsInterface
1634 //! [in] Pointer to OS Interface
1635 //! \return MOS_GPU_CONTEXT
1636 //! Return current GPU context
1637 //!
Mos_Specific_GetGpuContext(PMOS_INTERFACE pOsInterface)1638 MOS_GPU_CONTEXT Mos_Specific_GetGpuContext(
1639 PMOS_INTERFACE pOsInterface)
1640 {
1641 if (pOsInterface == nullptr)
1642 {
1643 MOS_OS_ASSERTMESSAGE("OsInterface is null.");
1644 return MOS_GPU_CONTEXT_INVALID_HANDLE;
1645 }
1646
1647 return pOsInterface->CurrentGpuContextOrdinal;
1648 }
1649
1650 //!
1651 //! \brief Set GPU context Handle
1652 //! \details Set GPU context handle for the following rendering operations
1653 //! \param PMOS_INTERFACE pOsInterface
1654 //! [in] Pointer to OS Interface
1655 //! \param GPU_CONTEXT_HANDLE gpuContextHandle
1656 //! [in] GPU Context Handle
1657 //! \param MOS_GPU_CONTEXT GpuContext
1658 //! [in] GPU Context
1659 //! \return MOS_STATUS
1660 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1661 //!
Mos_Specific_SetGpuContextHandle(PMOS_INTERFACE pOsInterface,GPU_CONTEXT_HANDLE gpuContextHandle,MOS_GPU_CONTEXT GpuContext)1662 MOS_STATUS Mos_Specific_SetGpuContextHandle(
1663 PMOS_INTERFACE pOsInterface,
1664 GPU_CONTEXT_HANDLE gpuContextHandle,
1665 MOS_GPU_CONTEXT GpuContext)
1666 {
1667 MOS_OS_FUNCTION_ENTER;
1668
1669 if (Mos_Solo_IsEnabled(nullptr)) return MOS_STATUS_SUCCESS;
1670
1671 MOS_OS_CHK_NULL_RETURN(pOsInterface);
1672 MOS_OS_CHK_NULL_RETURN(pOsInterface->osContextPtr);
1673
1674 auto pOsContextSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
1675 MOS_OS_CHK_NULL_RETURN(pOsContextSpecific);
1676
1677 pOsContextSpecific->SetGpuContextHandle(GpuContext, gpuContextHandle);
1678
1679 return MOS_STATUS_SUCCESS;
1680 }
1681
1682 //!
1683 //! \brief Get GPU context pointer
1684 //! \details Get GPU context pointer
1685 //! \param PMOS_INTERFACE pOsInterface
1686 //! [in] Pointer to OS Interface
1687 //! \param GPU_CONTEXT_HANDLE gpuContextHandle
1688 //! [in] GPU Context Handle
1689 //! \return void *
1690 //! a pointer to a gpu context
1691 //!
Mos_Specific_GetGpuContextbyHandle(PMOS_INTERFACE pOsInterface,GPU_CONTEXT_HANDLE gpuContextHandle)1692 void *Mos_Specific_GetGpuContextbyHandle(
1693 PMOS_INTERFACE pOsInterface,
1694 GPU_CONTEXT_HANDLE gpuContextHandle)
1695 {
1696 MOS_OS_FUNCTION_ENTER;
1697
1698 if (!pOsInterface)
1699 {
1700 MOS_OS_ASSERTMESSAGE("Invalid nullptr");
1701 return nullptr;
1702 }
1703
1704 if (pOsInterface->apoMosEnabled)
1705 {
1706 return MosInterface::GetGpuContext(pOsInterface->osStreamState, gpuContextHandle);
1707 }
1708
1709 OsContextSpecific *pOsContextSpecific = static_cast<OsContextSpecific *>(pOsInterface->osContextPtr);
1710 if(!pOsContextSpecific)
1711 {
1712 MOS_OS_ASSERTMESSAGE("Invalid nullptr");
1713 return nullptr;
1714 }
1715
1716 GpuContextMgr *gpuContextMgr = pOsContextSpecific->GetGpuContextMgr();
1717 if (!gpuContextMgr)
1718 {
1719 MOS_OS_ASSERTMESSAGE("Invalid nullptr");
1720 return nullptr;
1721 }
1722
1723 GpuContext *gpuContext = gpuContextMgr->GetGpuContext(gpuContextHandle);
1724 if (!gpuContext)
1725 {
1726 MOS_OS_ASSERTMESSAGE("Invalid nullptr");
1727 return nullptr;
1728 }
1729
1730 return (void *)gpuContext;
1731 }
1732
1733 //!
1734 //! \brief Get current GMM client context
1735 //! \details Get current GMM client context
1736 //! \param PMOS_INTERFACE pOsInterface
1737 //! [in] Pointer to OS Interface
1738 //! \return GMM_CLIENT_CONTEXT
1739 //! Return current GMM client context
1740 //!
Mos_Specific_GetGmmClientContext(PMOS_INTERFACE pOsInterface)1741 GMM_CLIENT_CONTEXT *Mos_Specific_GetGmmClientContext(
1742 PMOS_INTERFACE pOsInterface)
1743 {
1744 if (pOsInterface == nullptr)
1745 {
1746 MOS_OS_ASSERTMESSAGE("OsInterface is null.");
1747 return nullptr;
1748 }
1749
1750 if (pOsInterface->apoMosEnabled)
1751 {
1752 return MosInterface::GetGmmClientContext(pOsInterface->osStreamState);
1753 }
1754
1755 if (pOsInterface->modulizedMosEnabled && !Mos_Solo_IsEnabled(nullptr))
1756 {
1757 OsContextSpecific *pOsContextSpecific = static_cast<OsContextSpecific *>(pOsInterface->osContextPtr);
1758 if (pOsContextSpecific)
1759 {
1760 return pOsContextSpecific->GetGmmClientContext();
1761 }
1762 }
1763 else
1764 {
1765 if (pOsInterface->pOsContext)
1766 {
1767 return pOsInterface->pOsContext->GetGmmClientContext(pOsInterface->pOsContext);
1768 }
1769 }
1770 return nullptr;
1771 }
1772
1773 //!
1774 //! \brief Get Platform
1775 //! \details Get platform info
1776 //! \param PMOS_INTERFACE pOsInterface
1777 //! [in] Pointer to OS Interface
1778 //! \param PLATFORM pPlatform
1779 //! [out] Pointer to platform
1780 //! \return MOS_STATUS
1781 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1782 //!
Mos_Specific_GetPlatform(PMOS_INTERFACE pOsInterface,PLATFORM * pPlatform)1783 void Mos_Specific_GetPlatform(
1784 PMOS_INTERFACE pOsInterface,
1785 PLATFORM *pPlatform)
1786 {
1787 MOS_STATUS eStatus;
1788
1789 eStatus = MOS_STATUS_SUCCESS;
1790
1791 MOS_OS_CHK_NULL(pOsInterface);
1792 MOS_OS_CHK_NULL(pOsInterface->pOsContext);
1793 MOS_OS_CHK_NULL(pPlatform);
1794
1795 if (pOsInterface->apoMosEnabled)
1796 {
1797 // apo wrapper
1798 auto platform = MosInterface::GetPlatform(pOsInterface->osStreamState);
1799 if (platform)
1800 {
1801 *pPlatform = *platform;
1802 }
1803 return;
1804 }
1805
1806 *pPlatform = pOsInterface->pOsContext->m_platform;
1807
1808 finish:
1809 return;
1810 }
1811
Mos_DestroyInterface(PMOS_INTERFACE pOsInterface)1812 MOS_STATUS Mos_DestroyInterface(PMOS_INTERFACE pOsInterface)
1813 {
1814 MOS_OS_CHK_NULL_RETURN(pOsInterface);
1815
1816 MOS_STREAM_HANDLE streamState = pOsInterface->osStreamState;
1817 MOS_OS_CHK_NULL_RETURN(streamState);
1818
1819 auto deviceContext = streamState->osDeviceContext;
1820 MOS_OS_CHK_NULL_RETURN(deviceContext);
1821
1822 if (!Mos_Solo_IsEnabled((PMOS_CONTEXT)streamState->perStreamParameters))
1823 {
1824 OsContext *pOsContext = pOsInterface->osContextPtr;
1825 MOS_OS_CHK_NULL_RETURN(pOsContext);
1826 // APO MOS destory GPU contexts here instead of inside osContextPtr
1827 OsContextSpecific *pOsContextSpecific = static_cast<OsContextSpecific *>(pOsContext);
1828
1829 auto gpuContextMgr = deviceContext->GetGpuContextMgr();
1830 for (uint32_t i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
1831 {
1832 if (pOsContextSpecific->GetGpuContextHandleByIndex(i) != MOS_GPU_CONTEXT_INVALID_HANDLE)
1833 {
1834 if (gpuContextMgr == nullptr)
1835 {
1836 MOS_OS_ASSERTMESSAGE("GpuContextMgr is null when destroy GpuContext");
1837 break;
1838 }
1839 auto gpuContext = gpuContextMgr->GetGpuContext(pOsContextSpecific->GetGpuContextHandleByIndex(i));
1840 if (gpuContext == nullptr)
1841 {
1842 MOS_OS_ASSERTMESSAGE("cannot find the gpuContext corresponding to the active gpuContextHandle");
1843 continue;
1844 }
1845 gpuContextMgr->DestroyGpuContext(gpuContext);
1846 pOsContextSpecific->SetGpuContextHandleByIndex(i, MOS_GPU_CONTEXT_INVALID_HANDLE);
1847 }
1848 }
1849
1850 pOsContext->CleanUp();
1851
1852 MOS_Delete(pOsContext);
1853 pOsInterface->osContextPtr = nullptr;
1854 }
1855
1856 if (pOsInterface->osCpInterface)
1857 {
1858 Delete_MosCpInterface(pOsInterface->osCpInterface);
1859 pOsInterface->osCpInterface = NULL;
1860 }
1861
1862 PMOS_CONTEXT perStreamParameters = (PMOS_CONTEXT)streamState->perStreamParameters;
1863
1864 if (perStreamParameters && perStreamParameters->bFreeContext)
1865 {
1866 perStreamParameters->m_skuTable.reset();
1867 perStreamParameters->m_waTable.reset();
1868 Mos_Specific_ClearGpuContext(perStreamParameters);
1869
1870 if (perStreamParameters->contextOffsetList.size())
1871 {
1872 perStreamParameters->contextOffsetList.clear();
1873 perStreamParameters->contextOffsetList.shrink_to_fit();
1874 }
1875
1876 if(Mos_Solo_IsEnabled(perStreamParameters))
1877 {
1878 Linux_ReleaseCmdBufferPool(perStreamParameters);
1879 PCOMMAND_BUFFER pCurrCB = nullptr;
1880 PCOMMAND_BUFFER pNextCB = nullptr;
1881 for (uint32_t i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
1882 {
1883 MOS_FreeMemAndSetNull(perStreamParameters->OsGpuContext[i].pCB);
1884
1885 pCurrCB = perStreamParameters->OsGpuContext[i].pStartCB;
1886 for (; (pCurrCB); pCurrCB = pNextCB)
1887 {
1888 pNextCB = pCurrCB->pNext;
1889 MOS_FreeMemAndSetNull(pCurrCB);
1890 }
1891 }
1892 Linux_ReleaseGPUStatus(perStreamParameters);
1893 }
1894 if (perStreamParameters->intel_context)
1895 {
1896 if (perStreamParameters->intel_context->vm_id != INVALID_VM)
1897 {
1898 mos_vm_destroy(perStreamParameters->intel_context->bufmgr, perStreamParameters->intel_context->vm_id);
1899 perStreamParameters->intel_context->vm_id = INVALID_VM;
1900 }
1901 mos_context_destroy(perStreamParameters->intel_context);
1902 perStreamParameters->intel_context = nullptr;
1903 }
1904 MOS_Delete(perStreamParameters);
1905 streamState->perStreamParameters = nullptr;
1906 }
1907
1908 MosInterface::DestroyVirtualEngineState(streamState);
1909 MOS_FreeMemAndSetNull(pOsInterface->pVEInterf);
1910
1911 MOS_OS_CHK_STATUS_RETURN(MosInterface::DestroyOsStreamState(streamState));
1912 pOsInterface->osStreamState = nullptr;
1913 return MOS_STATUS_SUCCESS;
1914 }
1915 //!
1916 //! \brief Destroys OS specific allocations
1917 //! \details Destroys OS specific allocations including destroying OS context
1918 //! \param PMOS_INTERFACE pOsInterface
1919 //! [in] Pointer to OS Interface
1920 //! \param int32_t bDestroyVscVppDeviceTag
1921 //! [in] Destroy VscVppDeviceTagId Flag, no use in Linux
1922 //! \return void
1923 //!
Mos_Specific_Destroy(PMOS_INTERFACE pOsInterface,int32_t bDestroyVscVppDeviceTag)1924 void Mos_Specific_Destroy(
1925 PMOS_INTERFACE pOsInterface,
1926 int32_t bDestroyVscVppDeviceTag)
1927 {
1928 MOS_UNUSED(bDestroyVscVppDeviceTag);
1929
1930 if (nullptr == pOsInterface)
1931 {
1932 MOS_OS_ASSERTMESSAGE("input parameter, pOsInterface is NULL.");
1933 return;
1934 }
1935
1936 if (pOsInterface->apoMosEnabled)
1937 {
1938 MOS_STATUS status = Mos_DestroyInterface(pOsInterface);
1939 if (status != MOS_STATUS_SUCCESS)
1940 {
1941 MOS_OS_ASSERTMESSAGE("Mos Destroy Interface failed.");
1942 }
1943 return;
1944 }
1945
1946 if (pOsInterface->modulizedMosEnabled && !Mos_Solo_IsEnabled(nullptr))
1947 {
1948 OsContext* pOsContext = pOsInterface->osContextPtr;
1949 if (pOsContext == nullptr)
1950 {
1951 MOS_OS_ASSERTMESSAGE("Unable to get the active OS context.");
1952 return;
1953 }
1954
1955 // APO MOS destory GPU contexts here instead of inside osContextPtr
1956 if (pOsInterface->apoMosEnabled)
1957 {
1958 OsContextSpecific* pOsContextSpecific = static_cast<OsContextSpecific*>(pOsContext);
1959 if (pOsInterface->osStreamState == nullptr)
1960 {
1961 MOS_OS_ASSERTMESSAGE("osStreamState is null when destroy GpuContext");
1962 return;
1963 }
1964 if (pOsInterface->osStreamState->osDeviceContext == nullptr)
1965 {
1966 MOS_OS_ASSERTMESSAGE("osDeviceContext is null when destroy GpuContext");
1967 return;
1968 }
1969 auto gpuContextMgr = pOsInterface->osStreamState->osDeviceContext->GetGpuContextMgr();
1970 for (uint32_t i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
1971 {
1972 if (pOsContextSpecific->GetGpuContextHandleByIndex(i) != MOS_GPU_CONTEXT_INVALID_HANDLE)
1973 {
1974 if (gpuContextMgr == nullptr)
1975 {
1976 MOS_OS_ASSERTMESSAGE("GpuContextMgr is null when destroy GpuContext");
1977 break;
1978 }
1979 auto gpuContext = gpuContextMgr->GetGpuContext(pOsContextSpecific->GetGpuContextHandleByIndex(i));
1980 if (gpuContext == nullptr)
1981 {
1982 MOS_OS_ASSERTMESSAGE("cannot find the gpuContext corresponding to the active gpuContextHandle");
1983 continue;
1984 }
1985 gpuContextMgr->DestroyGpuContext(gpuContext);
1986 pOsContextSpecific->SetGpuContextHandleByIndex(i, MOS_GPU_CONTEXT_INVALID_HANDLE);
1987 }
1988 }
1989 }
1990 pOsContext->CleanUp();
1991
1992 MOS_Delete(pOsContext);
1993 pOsInterface->osContextPtr = nullptr;
1994 }
1995
1996 if (pOsInterface->osCpInterface)
1997 {
1998 Delete_MosCpInterface(pOsInterface->osCpInterface);
1999 pOsInterface->osCpInterface = NULL;
2000 }
2001
2002 if (pOsInterface &&
2003 pOsInterface->pOsContext &&
2004 pOsInterface->pOsContext->bFreeContext)
2005 {
2006 pOsInterface->pOsContext->m_skuTable.reset();
2007 pOsInterface->pOsContext->m_waTable.reset();
2008 Mos_Specific_ClearGpuContext(pOsInterface->pOsContext);
2009 bool modularizedGpuCtxEnabled = pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr);
2010 pOsInterface->pOsContext->pfnDestroy(pOsInterface->pOsContext, pOsInterface->modulizedMosEnabled, modularizedGpuCtxEnabled);
2011 pOsInterface->pOsContext = nullptr;
2012 }
2013 if (pOsInterface->pVEInterf)
2014 {
2015 if (pOsInterface->apoMosEnabled && pOsInterface->pVEInterf->veInterface)
2016 {
2017 pOsInterface->pVEInterf->veInterface->Destroy();
2018 MOS_Delete(pOsInterface->pVEInterf->veInterface);
2019 }
2020 MOS_FreeMemAndSetNull(pOsInterface->pVEInterf);
2021 }
2022
2023 if (pOsInterface->apoMosEnabled)
2024 {
2025 auto status = MosInterface::DestroyOsStreamState(pOsInterface->osStreamState);
2026 if (status != MOS_STATUS_SUCCESS)
2027 {
2028 MOS_OS_ASSERTMESSAGE("Failed to destroy stream state.");
2029 return;
2030 }
2031 }
2032 }
2033
2034 //!
2035 //! \brief Gets the SKU table
2036 //! \details Gets the SKU table for the platform
2037 //! \param PMOS_INTERFACE pOsInterface
2038 //! [in] Pointer to OS Interface
2039 //! \return MEDIA_FEATURE_TABLE *
2040 //! Returns the pointer to sku table
2041 //!
Mos_Specific_GetSkuTable(PMOS_INTERFACE pOsInterface)2042 MEDIA_FEATURE_TABLE *Mos_Specific_GetSkuTable(
2043 PMOS_INTERFACE pOsInterface)
2044 {
2045 if (pOsInterface && pOsInterface->apoMosEnabled)
2046 {
2047 // apo wrapper
2048 return MosInterface::GetSkuTable(pOsInterface->osStreamState);
2049 }
2050
2051 if (pOsInterface && pOsInterface->pOsContext)
2052 {
2053 return &pOsInterface->pOsContext->m_skuTable;
2054 }
2055 return nullptr;
2056 }
2057
2058 //!
2059 //! \brief Gets the WA table
2060 //! \details Gets the WA table for the platform
2061 //! \param PMOS_INTERFACE pOsInterface
2062 //! [in] Pointer to OS Interface
2063 //! \return MEDIA_WA_TABLE *
2064 //! Returns the pointer to WA table
2065 //!
Mos_Specific_GetWaTable(PMOS_INTERFACE pOsInterface)2066 MEDIA_WA_TABLE *Mos_Specific_GetWaTable(
2067 PMOS_INTERFACE pOsInterface)
2068 {
2069 if (pOsInterface && pOsInterface->apoMosEnabled)
2070 {
2071 // apo wrapper
2072 return MosInterface::GetWaTable(pOsInterface->osStreamState);
2073 }
2074
2075 if (pOsInterface && pOsInterface->pOsContext)
2076 {
2077 return &pOsInterface->pOsContext->m_waTable;
2078 }
2079 return nullptr;
2080 }
2081
2082 //!
2083 //! \brief Gets the GT System Info
2084 //! \details Gets the GT System Info
2085 //! \param PMOS_INTERFACE pOsInterface
2086 //! [in] OS Interface
2087 //! \return MEDIA_SYSTEM_INFO *
2088 //! pointer to the GT System Info
2089 //!
Mos_Specific_GetGtSystemInfo(PMOS_INTERFACE pOsInterface)2090 MEDIA_SYSTEM_INFO *Mos_Specific_GetGtSystemInfo(
2091 PMOS_INTERFACE pOsInterface)
2092 {
2093 if( nullptr == pOsInterface)
2094 {
2095 MOS_OS_ASSERTMESSAGE("input parameter pOsInterface is NULL.");
2096 return nullptr;
2097 }
2098
2099 if (pOsInterface->apoMosEnabled)
2100 {
2101 // apo wrapper
2102 return MosInterface::GetGtSystemInfo(pOsInterface->osStreamState);
2103 }
2104
2105 if( nullptr == pOsInterface->pOsContext)
2106 {
2107 MOS_OS_ASSERTMESSAGE("pOsContext is NULL.");
2108 return nullptr;
2109 }
2110
2111 return &pOsInterface->pOsContext->m_gtSystemInfo;
2112 }
2113
Mos_Specific_GetMediaEngineInfo(PMOS_INTERFACE pOsInterface,MEDIA_ENGINE_INFO & info)2114 MOS_STATUS Mos_Specific_GetMediaEngineInfo(
2115 PMOS_INTERFACE pOsInterface, MEDIA_ENGINE_INFO &info)
2116 {
2117 if (pOsInterface == nullptr)
2118 {
2119 MOS_OS_ASSERTMESSAGE("Invalid pointer!");
2120 return MOS_STATUS_INVALID_PARAMETER;
2121 }
2122
2123 if (pOsInterface->apoMosEnabled)
2124 {
2125 // apo wrapper
2126 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetMediaEngineInfo(pOsInterface->osStreamState, info));
2127 return MOS_STATUS_SUCCESS;
2128 }
2129
2130 auto systemInfo = pOsInterface->pfnGetGtSystemInfo(pOsInterface);
2131 MOS_OS_CHK_NULL_RETURN(systemInfo);
2132 MosUtilities::MosZeroMemory(&info, sizeof(info));
2133 info.VDBoxInfo = systemInfo->VDBoxInfo;
2134 info.VEBoxInfo = systemInfo->VEBoxInfo;
2135
2136 return MOS_STATUS_SUCCESS;
2137 }
2138
2139 //!
2140 //! \brief Resets OS States
2141 //! \details Resets OS States for linux
2142 //! \param PMOS_INTERFACE pOsInterface
2143 //! [in] Pointer to OS Interface
2144 //! \return void
2145 //!
Mos_Specific_ResetOsStates(PMOS_INTERFACE pOsInterface)2146 void Mos_Specific_ResetOsStates(
2147 PMOS_INTERFACE pOsInterface) // [in] OS Interface
2148 {
2149 MOS_OS_FUNCTION_ENTER;
2150
2151 PMOS_OS_CONTEXT pOsContext;
2152 PMOS_OS_GPU_CONTEXT pOsGpuContext;
2153
2154 if (pOsInterface == nullptr ||
2155 pOsInterface->pOsContext == nullptr)
2156 {
2157 return;
2158 }
2159
2160 if (pOsInterface->apoMosEnabled)
2161 {
2162 auto status = MosInterface::ResetCommandBuffer(pOsInterface->osStreamState, 0);
2163 if (MOS_FAILED(status))
2164 {
2165 MOS_OS_ASSERTMESSAGE("ResetCommandBuffer failed.");
2166 }
2167 return;
2168 }
2169
2170 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
2171 {
2172 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
2173 if (gpuContext == nullptr)
2174 {
2175 MOS_OS_ASSERTMESSAGE("GPU Context pointer is nullptr!");
2176 return;
2177 }
2178
2179 gpuContext->ResetGpuContextStatus();
2180 return;
2181 }
2182
2183 pOsContext = pOsInterface->pOsContext;
2184 pOsGpuContext = &pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
2185 // Reset resource allocation
2186 pOsGpuContext->uiNumAllocations = 0;
2187 MOS_ZeroMemory(pOsGpuContext->pAllocationList, sizeof(ALLOCATION_LIST) * pOsGpuContext->uiMaxNumAllocations);
2188 pOsGpuContext->uiCurrentNumPatchLocations = 0;
2189 MOS_ZeroMemory(pOsGpuContext->pPatchLocationList, sizeof(PATCHLOCATIONLIST) * pOsGpuContext->uiMaxPatchLocationsize);
2190 pOsGpuContext->uiResCount = 0;
2191
2192 MOS_ZeroMemory(pOsGpuContext->pResources, sizeof(MOS_RESOURCE) * pOsGpuContext->uiMaxNumAllocations);
2193 MOS_ZeroMemory(pOsGpuContext->pbWriteMode, sizeof(int32_t) * pOsGpuContext->uiMaxNumAllocations);
2194
2195 if((pOsGpuContext->bCBFlushed == true) && pOsGpuContext->pCB->OsResource.bo)
2196 {
2197 pOsGpuContext->pCB->OsResource.bo = nullptr;
2198 }
2199
2200 }
2201
2202 //!
2203 //! \brief Allocate resource
2204 //! \details To Allocate Buffer, pass Format as Format_Buffer and set the iWidth as size of the buffer.
2205 //! \param PMOS_INTERFACE pOsInterface
2206 //! [in] Pointer to OS Interface
2207 //! \param PMOS_ALLOC_GFXRES_PARAMS pParams
2208 //! [in] Pointer to resource params
2209 //! \param PMOS_RESOURCE pOsResource
2210 //! [in/out] Pointer to OS resource
2211 //! \return MOS_STATUS
2212 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2213 //!
Mos_Specific_AllocateResource(PMOS_INTERFACE pOsInterface,PMOS_ALLOC_GFXRES_PARAMS pParams,PCCHAR functionName,PCCHAR filename,int32_t line,PMOS_RESOURCE pOsResource)2214 MOS_STATUS Mos_Specific_AllocateResource(
2215 PMOS_INTERFACE pOsInterface,
2216 PMOS_ALLOC_GFXRES_PARAMS pParams,
2217 #if MOS_MESSAGES_ENABLED
2218 PCCHAR functionName,
2219 PCCHAR filename,
2220 int32_t line,
2221 #endif // MOS_MESSAGES_ENABLED
2222 PMOS_RESOURCE pOsResource)
2223 {
2224 void * caller = nullptr;
2225 const char * bufname;
2226 void * ptr;
2227 int32_t iSize = 0;
2228 int32_t iPitch = 0;
2229 MOS_STATUS eStatus;
2230 MOS_LINUX_BO * bo = nullptr;
2231 MOS_TILE_TYPE tileformat;
2232 uint32_t tileformat_linux = 0;
2233 int32_t iHeight = 0;
2234 int32_t iAlignedHeight = 0;
2235 GMM_RESCREATE_PARAMS GmmParams;
2236 GMM_RESOURCE_INFO * pGmmResourceInfo = nullptr;
2237 GMM_RESOURCE_TYPE resourceType = RESOURCE_INVALID;
2238 int mem_type = MOS_MEMPOOL_VIDEOMEMORY;
2239
2240 MOS_OS_FUNCTION_ENTER;
2241
2242 MOS_ZeroMemory(&GmmParams, sizeof(GmmParams));
2243
2244 if( nullptr == pOsResource)
2245 {
2246 MOS_OS_ASSERTMESSAGE("input parameter pOSResource is NULL.");
2247 return MOS_STATUS_INVALID_PARAMETER;
2248 }
2249
2250 if( nullptr == pOsInterface)
2251 {
2252 MOS_OS_ASSERTMESSAGE("input parameter pOsInterface is NULL.");
2253 return MOS_STATUS_INVALID_PARAMETER;
2254 }
2255
2256 bufname = pParams->pBufName;
2257 pOsResource->bConvertedFromDDIResource = false;
2258
2259 bool osContextValid = false;
2260 if (pOsInterface->osContextPtr != nullptr)
2261 {
2262 if (pOsInterface->osContextPtr->GetOsContextValid() == true)
2263 {
2264 osContextValid = true;
2265 }
2266 }
2267
2268 if (pOsInterface->apoMosEnabled)
2269 {
2270 pParams->bBypassMODImpl = !((pOsInterface->modulizedMosEnabled) && (!Mos_Solo_IsEnabled(nullptr)) && (osContextValid == true));
2271
2272 MOS_OS_CHK_NULL_RETURN(pOsInterface->osStreamState);
2273
2274 pOsInterface->osStreamState->component = pOsInterface->Component;
2275
2276 eStatus = MosInterface::AllocateResource(
2277 pOsInterface->osStreamState,
2278 pParams,
2279 pOsResource
2280 #if MOS_MESSAGES_ENABLED
2281 ,
2282 functionName,
2283 filename,
2284 line
2285 #endif // MOS_MESSAGES_ENABLED
2286 );
2287
2288 return eStatus;
2289 }
2290
2291 if ((pOsInterface->modulizedMosEnabled) && (!Mos_Solo_IsEnabled(nullptr)) && (osContextValid == true))
2292 {
2293 pOsResource->pGfxResource = GraphicsResource::CreateGraphicResource(GraphicsResource::osSpecificResource);
2294 if (pOsResource->pGfxResource == nullptr)
2295 {
2296 MOS_OS_ASSERTMESSAGE("input nullptr returned by GraphicsResource::CreateGraphicResource.");
2297 return MOS_STATUS_INVALID_HANDLE;
2298 }
2299
2300 if (pOsInterface->osContextPtr == nullptr)
2301 {
2302 MOS_OS_ASSERTMESSAGE("invalid osContextPtr.");
2303 return MOS_STATUS_INVALID_HANDLE;
2304 }
2305 if (MosUtilities::m_mosMemAllocCounterGfx != nullptr)
2306 {
2307 GraphicsResource::SetMemAllocCounterGfx(*MosUtilities::m_mosMemAllocCounterGfx);
2308 }
2309 GraphicsResource::CreateParams params(pParams);
2310 eStatus = pOsResource->pGfxResource->Allocate(pOsInterface->osContextPtr, params);
2311 if (eStatus != MOS_STATUS_SUCCESS)
2312 {
2313 MOS_OS_ASSERTMESSAGE("Allocate graphic resource failed");
2314 return MOS_STATUS_INVALID_HANDLE;
2315 }
2316
2317 eStatus = pOsResource->pGfxResource->ConvertToMosResource(pOsResource);
2318 if (eStatus != MOS_STATUS_SUCCESS)
2319 {
2320 MOS_OS_ASSERTMESSAGE("Convert graphic resource failed");
2321 return MOS_STATUS_INVALID_HANDLE;
2322 }
2323 if (MosUtilities::m_mosMemAllocCounterGfx != nullptr)
2324 {
2325 *MosUtilities::m_mosMemAllocCounterGfx = GraphicsResource::GetMemAllocCounterGfx();
2326 }
2327 MOS_OS_CHK_NULL(pOsResource->pGmmResInfo);
2328 MOS_MEMNINJA_GFX_ALLOC_MESSAGE(pOsResource->pGmmResInfo, bufname, pOsInterface->Component,
2329 (uint32_t)pOsResource->pGmmResInfo->GetSizeSurface(), pParams->dwArraySize, functionName, filename, line);
2330
2331 return eStatus;
2332 }
2333
2334 caller = nullptr;
2335 tileformat_linux = TILING_NONE;
2336 iAlignedHeight = iHeight = pParams->dwHeight;
2337 eStatus = MOS_STATUS_SUCCESS;
2338 resourceType = RESOURCE_2D;
2339 tileformat = pParams->TileType;
2340
2341 MOS_ZeroMemory(&GmmParams, sizeof(GmmParams));
2342
2343 if( nullptr == pOsInterface->pOsContext )
2344 {
2345 MOS_OS_ASSERTMESSAGE("input parameter pOsInterface is NULL.");
2346 return MOS_STATUS_INVALID_PARAMETER;
2347 }
2348 switch (pParams->Format)
2349 {
2350 case Format_Buffer:
2351 case Format_RAW:
2352 resourceType = RESOURCE_BUFFER;
2353 iAlignedHeight = 1;
2354 //indicate buffer Restriction is Vertex.
2355 GmmParams.Flags.Gpu.State = true;
2356 break;
2357 case Format_L8:
2358 case Format_L16:
2359 case Format_STMM:
2360 case Format_AI44:
2361 case Format_IA44:
2362 case Format_R5G6B5:
2363 case Format_R8G8B8:
2364 case Format_X8R8G8B8:
2365 case Format_A8R8G8B8:
2366 case Format_X8B8G8R8:
2367 case Format_A8B8G8R8:
2368 case Format_R32S:
2369 case Format_R32F:
2370 case Format_V8U8:
2371 case Format_YUY2:
2372 case Format_UYVY:
2373 case Format_P8:
2374 case Format_A8:
2375 case Format_AYUV:
2376 case Format_NV12:
2377 case Format_NV21:
2378 case Format_YV12:
2379 case Format_Buffer_2D:
2380 case Format_R32U:
2381 case Format_444P:
2382 case Format_422H:
2383 case Format_422V:
2384 case Format_IMC3:
2385 case Format_411P:
2386 case Format_411R:
2387 case Format_RGBP:
2388 case Format_BGRP:
2389 case Format_R16U:
2390 case Format_R8U:
2391 case Format_R8UN:
2392 case Format_P010:
2393 case Format_P016:
2394 case Format_Y216:
2395 case Format_Y416:
2396 case Format_P208:
2397 case Format_Y210:
2398 case Format_Y410:
2399 case Format_R16F:
2400 resourceType = RESOURCE_2D;
2401 //indicate buffer Restriction is Planar surface restrictions.
2402 GmmParams.Flags.Gpu.Video = true;
2403 break;
2404 default:
2405 MOS_OS_ASSERTMESSAGE("Unsupported format");
2406 eStatus = MOS_STATUS_UNIMPLEMENTED;
2407 goto finish;
2408 }
2409
2410 // Create GmmResourceInfo
2411 GmmParams.BaseWidth = pParams->dwWidth;
2412 GmmParams.BaseHeight = iAlignedHeight;
2413 GmmParams.ArraySize = 1;
2414 GmmParams.Type = resourceType;
2415 GmmParams.Format = MosInterface::MosFmtToGmmFmt(pParams->Format);
2416
2417 MOS_OS_CHECK_CONDITION(GmmParams.Format == GMM_FORMAT_INVALID,
2418 "Unsupported format",
2419 MOS_STATUS_UNKNOWN);
2420
2421 switch(tileformat)
2422 {
2423 case MOS_TILE_Y:
2424 tileformat_linux = TILING_Y;
2425 if (pParams->bIsCompressible &&
2426 MEDIA_IS_SKU(&pOsInterface->pOsContext->m_skuTable, FtrE2ECompression) &&
2427 MEDIA_IS_SKU(&pOsInterface->pOsContext->m_skuTable, FtrCompressibleSurfaceDefault))
2428 {
2429 GmmParams.Flags.Gpu.MMC = true;
2430 GmmParams.Flags.Info.MediaCompressed = 1;
2431 GmmParams.Flags.Gpu.CCS = 1;
2432 GmmParams.Flags.Gpu.RenderTarget = 1;
2433 GmmParams.Flags.Gpu.UnifiedAuxSurface = 1;
2434
2435 if (pParams->CompressionMode == MOS_MMC_RC)
2436 {
2437 GmmParams.Flags.Info.MediaCompressed = 0;
2438 GmmParams.Flags.Info.RenderCompressed = 1;
2439 }
2440 else
2441 {
2442 GmmParams.Flags.Info.MediaCompressed = 1;
2443 GmmParams.Flags.Info.RenderCompressed = 0;
2444 }
2445
2446 if(MEDIA_IS_SKU(&pOsInterface->pOsContext->m_skuTable, FtrFlatPhysCCS))
2447 {
2448 GmmParams.Flags.Gpu.UnifiedAuxSurface = 0;
2449 }
2450 }
2451 break;
2452 case MOS_TILE_X:
2453 GmmParams.Flags.Info.TiledX = true;
2454 tileformat_linux = TILING_X;
2455 break;
2456 default:
2457 GmmParams.Flags.Info.Linear = true;
2458 tileformat_linux = TILING_NONE;
2459 }
2460 GmmParams.Flags.Info.LocalOnly = MEDIA_IS_SKU(&pOsInterface->pOsContext->m_skuTable, FtrLocalMemory);
2461
2462 pOsResource->pGmmResInfo = pGmmResourceInfo = pOsInterface->pOsContext->pGmmClientContext->CreateResInfoObject(&GmmParams);
2463
2464 MOS_OS_CHK_NULL(pGmmResourceInfo);
2465
2466 switch (pGmmResourceInfo->GetTileType())
2467 {
2468 case GMM_TILED_X:
2469 tileformat = MOS_TILE_X;
2470 tileformat_linux = TILING_X;
2471 break;
2472 case GMM_TILED_Y:
2473 tileformat = MOS_TILE_Y;
2474 tileformat_linux = TILING_Y;
2475 break;
2476 case GMM_NOT_TILED:
2477 tileformat = MOS_TILE_LINEAR;
2478 tileformat_linux = TILING_NONE;
2479 break;
2480 default:
2481 tileformat = MOS_TILE_Y;
2482 tileformat_linux = TILING_Y;
2483 break;
2484 }
2485
2486 if (pParams->TileType == MOS_TILE_Y)
2487 {
2488 pGmmResourceInfo->SetMmcMode((GMM_RESOURCE_MMC_INFO)pParams->CompressionMode, 0);
2489 }
2490
2491 iPitch = GFX_ULONG_CAST(pGmmResourceInfo->GetRenderPitch());
2492 iSize = GFX_ULONG_CAST(pGmmResourceInfo->GetSizeSurface());
2493 iHeight = pGmmResourceInfo->GetBaseHeight();
2494
2495 MemoryPolicyParameter memPolicyPar;
2496 MOS_ZeroMemory(&memPolicyPar, sizeof(MemoryPolicyParameter));
2497
2498 memPolicyPar.skuTable = &pOsInterface->pOsContext->m_skuTable;
2499 memPolicyPar.waTable = &pOsInterface->pOsContext->m_waTable;
2500 memPolicyPar.resInfo = pGmmResourceInfo;
2501 memPolicyPar.resName = pParams->pBufName;
2502 memPolicyPar.preferredMemType = pParams->dwMemType;
2503
2504 mem_type = MemoryPolicyManager::UpdateMemoryPolicy(&memPolicyPar);
2505
2506 // Only Linear and Y TILE supported
2507 if( tileformat_linux == TILING_NONE )
2508 {
2509 struct mos_drm_bo_alloc alloc;
2510 alloc.name = bufname;
2511 alloc.size = iSize;
2512 alloc.alignment = 4096;
2513 alloc.ext.mem_type = mem_type;
2514 bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, &alloc);
2515 }
2516 else
2517 {
2518 struct mos_drm_bo_alloc_tiled alloc_tiled;
2519 alloc_tiled.name = bufname;
2520 alloc_tiled.x = iPitch;
2521 alloc_tiled.y = iSize/iPitch;
2522 alloc_tiled.cpp = 1;
2523 alloc_tiled.ext.tiling_mode = tileformat_linux;
2524 alloc_tiled.ext.mem_type = mem_type;
2525
2526 bo = mos_bo_alloc_tiled(pOsInterface->pOsContext->bufmgr, &alloc_tiled);
2527 iPitch = (int32_t)alloc_tiled.pitch;;
2528 }
2529
2530 pOsResource->bMapped = false;
2531 if (bo)
2532 {
2533 pOsResource->Format = pParams->Format;
2534 pOsResource->iWidth = pParams->dwWidth;
2535 pOsResource->iHeight = iHeight;
2536 pOsResource->iPitch = iPitch;
2537 pOsResource->iCount = 0;
2538 pOsResource->bufname = bufname;
2539 pOsResource->bo = bo;
2540 pOsResource->TileType = tileformat;
2541 pOsResource->TileModeGMM = (MOS_TILE_MODE_GMM)pGmmResourceInfo->GetTileModeSurfaceState();
2542 pOsResource->bGMMTileEnabled = true;
2543 pOsResource->pData = (uint8_t *)bo->virt; //It is useful for batch buffer to fill commands
2544 if (pParams->ResUsageType == MOS_CODEC_RESOURCE_USAGE_BEGIN_CODEC ||
2545 pParams->ResUsageType >= MOS_HW_RESOURCE_USAGE_MEDIA_BATCH_BUFFERS)
2546 {
2547 pOsResource->memObjCtrlState = MosInterface::GetCachePolicyMemoryObject(pOsInterface->pOsContext->pGmmClientContext, MOS_MP_RESOURCE_USAGE_DEFAULT);
2548 pOsResource->mocsMosResUsageType = MOS_MP_RESOURCE_USAGE_DEFAULT;
2549 }
2550 else
2551 {
2552 pOsResource->memObjCtrlState = MosInterface::GetCachePolicyMemoryObject(pOsInterface->pOsContext->pGmmClientContext, pParams->ResUsageType);
2553 pOsResource->mocsMosResUsageType = pParams->ResUsageType;
2554 }
2555
2556 MOS_OS_VERBOSEMESSAGE("Alloc %7d bytes (%d x %d resource).",iSize, pParams->dwWidth, iHeight);
2557 }
2558 else
2559 {
2560 MOS_OS_ASSERTMESSAGE("Fail to Alloc %7d bytes (%d x %d resource).",iSize, pParams->dwWidth, pParams->dwHeight);
2561 eStatus = MOS_STATUS_NO_SPACE;
2562 }
2563
2564 MosUtilities::MosAtomicIncrement(MosUtilities::m_mosMemAllocCounterGfx);
2565 MOS_MEMNINJA_GFX_ALLOC_MESSAGE(pOsResource->pGmmResInfo, bufname, pOsInterface->Component,
2566 (uint32_t)pOsResource->pGmmResInfo->GetSizeSurface(), pParams->dwArraySize, functionName, filename, line);
2567
2568 finish:
2569 return eStatus;
2570 }
2571
2572 //!
2573 //! \brief Get Resource Information
2574 //! \details Linux get resource info
2575 //! \param PMOS_INTERFACE pOsInterface
2576 //! [in] Pointer to OS interface structure
2577 //! \param PMOS_RESOURCE pOsResource
2578 //! [in] Pointer to input OS resource
2579 //! \param PMOS_SURFACE pResDetails
2580 //! [out] Pointer to output resource information details
2581 //! \return MOS_STATUS
2582 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2583 //!
Mos_Specific_GetResourceInfo(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,PMOS_SURFACE pResDetails)2584 MOS_STATUS Mos_Specific_GetResourceInfo(
2585 PMOS_INTERFACE pOsInterface,
2586 PMOS_RESOURCE pOsResource,
2587 PMOS_SURFACE pResDetails)
2588 {
2589 GMM_RESOURCE_INFO * pGmmResourceInfo = nullptr;
2590 GMM_DISPLAY_FRAME gmmChannel = GMM_DISPLAY_FRAME_MAX;
2591 GMM_REQ_OFFSET_INFO reqInfo[3] = {};
2592 GMM_RESOURCE_FLAG GmmFlags = {};
2593 MOS_STATUS eStatus;
2594
2595 MOS_OS_FUNCTION_ENTER;
2596
2597 eStatus = MOS_STATUS_SUCCESS;
2598
2599 MOS_OS_CHK_NULL(pOsInterface);
2600 MOS_OS_CHK_NULL(pOsResource);
2601 MOS_OS_CHK_NULL(pResDetails);
2602
2603 if (pOsInterface->apoMosEnabled)
2604 {
2605 return MosInterface::GetResourceInfo(pOsInterface->osStreamState, pOsResource, *pResDetails);
2606 }
2607
2608 // Get Gmm resource info
2609 pGmmResourceInfo = (GMM_RESOURCE_INFO*)pOsResource->pGmmResInfo;
2610 MOS_OS_CHK_NULL(pGmmResourceInfo);
2611
2612 GmmFlags = pGmmResourceInfo->GetResFlags();
2613
2614 pResDetails->dwWidth = GFX_ULONG_CAST(pGmmResourceInfo->GetBaseWidth());
2615 pResDetails->dwHeight = pGmmResourceInfo->GetBaseHeight();
2616 pResDetails->dwPitch = GFX_ULONG_CAST(pGmmResourceInfo->GetRenderPitch());
2617 pResDetails->dwSize = GFX_ULONG_CAST(pGmmResourceInfo->GetSizeSurface());
2618 pResDetails->dwDepth = MOS_MAX(1, pGmmResourceInfo->GetBaseDepth());
2619 pResDetails->dwLockPitch = GFX_ULONG_CAST(pGmmResourceInfo->GetRenderPitch());
2620 if (GFX_GET_CURRENT_RENDERCORE(pOsInterface->pfnGetGmmClientContext(pOsInterface)->GetPlatformInfo().Platform) < IGFX_GEN8_CORE)
2621 {
2622 pResDetails->bArraySpacing = pGmmResourceInfo->IsArraySpacingSingleLod();
2623 }
2624 if (GFX_GET_CURRENT_RENDERCORE(pOsInterface->pfnGetGmmClientContext(pOsInterface)->GetPlatformInfo().Platform) >= IGFX_GEN9_CORE)
2625 {
2626 pResDetails->dwQPitch = pGmmResourceInfo->GetQPitch();
2627 }
2628
2629 pResDetails->bCompressible = GmmFlags.Gpu.MMC ?
2630 (pGmmResourceInfo->GetMmcHint(0) == GMM_MMC_HINT_ON) : false;
2631 pResDetails->bIsCompressed = pGmmResourceInfo->IsMediaMemoryCompressed(0);
2632 pResDetails->CompressionMode = (MOS_RESOURCE_MMC_MODE)pGmmResourceInfo->GetMmcMode(0);
2633
2634 if (0 == pResDetails->dwPitch)
2635 {
2636 MOS_OS_ASSERTMESSAGE("Pitch from GmmResource is 0, unexpected.");
2637 return MOS_STATUS_INVALID_PARAMETER;
2638 }
2639 // check resource's tile type
2640 pResDetails->TileModeGMM = (MOS_TILE_MODE_GMM)pGmmResourceInfo->GetTileModeSurfaceState();
2641 pResDetails->bGMMTileEnabled = true;
2642 switch (pGmmResourceInfo->GetTileType())
2643 {
2644 case GMM_TILED_Y:
2645 if (GmmFlags.Info.TiledYf)
2646 {
2647 pResDetails->TileType = MOS_TILE_YF;
2648 }
2649 else if (GmmFlags.Info.TiledYs)
2650 {
2651 pResDetails->TileType = MOS_TILE_YS;
2652 }
2653 else
2654 {
2655 pResDetails->TileType = MOS_TILE_Y;
2656 }
2657 break;
2658 case GMM_TILED_X:
2659 pResDetails->TileType = MOS_TILE_X;
2660 break;
2661 case GMM_NOT_TILED:
2662 pResDetails->TileType = MOS_TILE_LINEAR;
2663 break;
2664 default:
2665 pResDetails->TileType = MOS_TILE_Y;
2666 break;
2667 }
2668 pResDetails->Format = pOsResource->Format;
2669
2670 MOS_ZeroMemory(reqInfo, sizeof(reqInfo));
2671 gmmChannel = GMM_DISPLAY_BASE;
2672 // Get the base offset of the surface (plane Y)
2673 reqInfo[2].ReqRender = true;
2674 reqInfo[2].Plane = GMM_PLANE_Y;
2675 reqInfo[2].Frame = gmmChannel;
2676 reqInfo[2].CubeFace = __GMM_NO_CUBE_MAP;
2677 reqInfo[2].ArrayIndex = 0;
2678 pGmmResourceInfo->GetOffset(reqInfo[2]);
2679 pResDetails->RenderOffset.YUV.Y.BaseOffset = reqInfo[2].Render.Offset;
2680
2681 // Get U/UV plane information (plane offset, X/Y offset)
2682 reqInfo[0].ReqRender = true;
2683 reqInfo[0].Plane = GMM_PLANE_U;
2684 reqInfo[0].Frame = gmmChannel;
2685 reqInfo[0].CubeFace = __GMM_NO_CUBE_MAP;
2686 reqInfo[0].ArrayIndex = 0;
2687 pGmmResourceInfo->GetOffset(reqInfo[0]);
2688
2689 pResDetails->RenderOffset.YUV.U.BaseOffset = reqInfo[0].Render.Offset;
2690 pResDetails->RenderOffset.YUV.U.XOffset = reqInfo[0].Render.XOffset;
2691 pResDetails->RenderOffset.YUV.U.YOffset = reqInfo[0].Render.YOffset;
2692
2693 // Get V plane information (plane offset, X/Y offset)
2694 reqInfo[1].ReqRender = true;
2695 reqInfo[1].Plane = GMM_PLANE_V;
2696 reqInfo[1].Frame = gmmChannel;
2697 reqInfo[1].CubeFace = __GMM_NO_CUBE_MAP;
2698 reqInfo[1].ArrayIndex = 0;
2699 pGmmResourceInfo->GetOffset(reqInfo[1]);
2700
2701 pResDetails->RenderOffset.YUV.V.BaseOffset = reqInfo[1].Render.Offset;
2702 pResDetails->RenderOffset.YUV.V.XOffset = reqInfo[1].Render.XOffset;
2703 pResDetails->RenderOffset.YUV.V.YOffset = reqInfo[1].Render.YOffset;
2704
2705 finish:
2706 return eStatus;
2707 }
2708
2709 //!
2710 //! \brief Free the resource
2711 //! \details Free the allocated resource
2712 //! \param PMOS_INTERFACE pOsInterface
2713 //! [in] Pointer to OS interface structure
2714 //! \param PMOS_RESOURCE pOsResource
2715 //! [in] Pointer to input OS resource
2716 //! \return void
2717 //!
Mos_Specific_FreeResource(PMOS_INTERFACE pOsInterface,PCCHAR functionName,PCCHAR filename,int32_t line,PMOS_RESOURCE pOsResource)2718 void Mos_Specific_FreeResource(
2719 PMOS_INTERFACE pOsInterface,
2720 #if MOS_MESSAGES_ENABLED
2721 PCCHAR functionName,
2722 PCCHAR filename,
2723 int32_t line,
2724 #endif // MOS_MESSAGES_ENABLED
2725 PMOS_RESOURCE pOsResource)
2726 {
2727 MOS_OS_FUNCTION_ENTER;
2728
2729 if( nullptr == pOsInterface )
2730 {
2731 MOS_OS_ASSERTMESSAGE("input parameter pOsInterface is NULL.");
2732 return;
2733 }
2734
2735 if( nullptr == pOsResource )
2736 {
2737 MOS_OS_ASSERTMESSAGE("input parameter pOsResource is NULL.");
2738 return;
2739 }
2740
2741 bool osContextValid = false;
2742 if (pOsInterface->osContextPtr != nullptr)
2743 {
2744 if (pOsInterface->osContextPtr->GetOsContextValid() == true)
2745 {
2746 osContextValid = true;
2747 }
2748 }
2749
2750 if (pOsInterface->apoMosEnabled)
2751 {
2752 MosInterface::FreeResource(
2753 pOsInterface->osStreamState,
2754 pOsResource,
2755 0
2756 #if MOS_MESSAGES_ENABLED
2757 ,
2758 functionName,
2759 filename,
2760 line
2761 #endif
2762 );
2763
2764 return;
2765 }
2766
2767 if ((pOsInterface->modulizedMosEnabled)
2768 && (!pOsResource->bConvertedFromDDIResource)
2769 && (osContextValid == true)
2770 && (!Mos_Solo_IsEnabled(nullptr))
2771 && (pOsResource->pGfxResource))
2772 {
2773 if (pOsInterface->osContextPtr == nullptr)
2774 {
2775 MOS_OS_ASSERTMESSAGE("invalid osContextPtr.");
2776 return;
2777 }
2778 if (MosUtilities::m_mosMemAllocCounterGfx != nullptr)
2779 {
2780 GraphicsResource::SetMemAllocCounterGfx(*MosUtilities::m_mosMemAllocCounterGfx);
2781 }
2782 if (pOsResource && pOsResource->pGfxResource)
2783 {
2784 pOsResource->pGfxResource->Free(pOsInterface->osContextPtr);
2785 }
2786 else
2787 {
2788 MOS_OS_VERBOSEMESSAGE("Received an empty Graphics Resource, skip free");
2789 }
2790 MOS_Delete(pOsResource->pGfxResource);
2791 pOsResource->pGfxResource = nullptr;
2792 if (MosUtilities::m_mosMemAllocCounterGfx != nullptr)
2793 {
2794 *MosUtilities::m_mosMemAllocCounterGfx = GraphicsResource::GetMemAllocCounterGfx();
2795 }
2796 MOS_MEMNINJA_GFX_FREE_MESSAGE(pOsResource->pGmmResInfo, functionName, filename, line);
2797 MOS_ZeroMemory(pOsResource, sizeof(*pOsResource));
2798 return;
2799 }
2800
2801 if (pOsResource && pOsResource->bo)
2802 {
2803 OsContextSpecific *osCtx = static_cast<OsContextSpecific *>(pOsInterface->osContextPtr);
2804 if(osCtx == nullptr)
2805 {
2806 MOS_OS_ASSERTMESSAGE("osCtx is nullptr!");
2807 return;
2808 }
2809 else
2810 {
2811 AuxTableMgr *auxTableMgr = osCtx->GetAuxTableMgr();
2812
2813 // Unmap Resource from Aux Table
2814 if (auxTableMgr)
2815 {
2816 auxTableMgr->UnmapResource(pOsResource->pGmmResInfo, pOsResource->bo);
2817 }
2818 }
2819
2820 mos_bo_unreference((MOS_LINUX_BO *)(pOsResource->bo));
2821
2822 if ( pOsInterface->pOsContext != nullptr && pOsInterface->pOsContext->contextOffsetList.size())
2823 {
2824 MOS_CONTEXT *pOsCtx = pOsInterface->pOsContext;
2825 auto item_ctx = pOsCtx->contextOffsetList.begin();
2826
2827 for (;item_ctx != pOsCtx->contextOffsetList.end();)
2828 {
2829 if (item_ctx->target_bo == pOsResource->bo)
2830 {
2831 item_ctx = pOsCtx->contextOffsetList.erase(item_ctx);
2832 }
2833 else
2834 {
2835 item_ctx++;
2836 }
2837 }
2838 }
2839
2840 pOsResource->bo = nullptr;
2841 if (pOsResource->pGmmResInfo != nullptr &&
2842 pOsInterface->pOsContext != nullptr &&
2843 pOsInterface->pOsContext->pGmmClientContext != nullptr)
2844 {
2845 MosUtilities::MosAtomicDecrement(MosUtilities::m_mosMemAllocCounterGfx);
2846 MOS_MEMNINJA_GFX_FREE_MESSAGE(pOsResource->pGmmResInfo, functionName, filename, line);
2847
2848 pOsInterface->pOsContext->pGmmClientContext->DestroyResInfoObject(pOsResource->pGmmResInfo);
2849 pOsResource->pGmmResInfo = nullptr;
2850 }
2851 }
2852
2853 }
2854
2855 //!
2856 //! \brief Free OS resource
2857 //! \details Free OS resource
2858 //! \param PMOS_INTERFACE pOsInterface
2859 //! [in] OS Interface
2860 //! \param PMOS_RESOURCE pOsResource
2861 //! [in/out] OS Resource to be freed
2862 //! \param uint32_t uiFlag
2863 //! [in] Flag to free resources. This one is useless on Linux, just for compatibility.
2864 //! \return void
2865 //!
Mos_Specific_FreeResourceWithFlag(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,PCCHAR functionName,PCCHAR filename,int32_t line,uint32_t uiFlag)2866 void Mos_Specific_FreeResourceWithFlag(
2867 PMOS_INTERFACE pOsInterface,
2868 PMOS_RESOURCE pOsResource,
2869 #if MOS_MESSAGES_ENABLED
2870 PCCHAR functionName,
2871 PCCHAR filename,
2872 int32_t line,
2873 #endif // MOS_MESSAGES_ENABLED
2874 uint32_t uiFlag)
2875 {
2876 MOS_UNUSED(uiFlag);
2877
2878 if (pOsInterface == nullptr ||
2879 pOsResource == nullptr)
2880 {
2881 return;
2882 }
2883
2884 #if MOS_MESSAGES_ENABLED
2885 Mos_Specific_FreeResource(pOsInterface, functionName, filename, line, pOsResource);
2886 #else
2887 Mos_Specific_FreeResource(pOsInterface, pOsResource);
2888 #endif // MOS_MESSAGES_ENABLED
2889 }
2890
2891 //!
2892 //! \brief Locks Resource request
2893 //! \details Locks Resource request
2894 //! \param PMOS_INTERFACE pOsInterface
2895 //! [in] pointer to OS Interface structure
2896 //! \param PMOS_RESOURCE pOsResource
2897 //! [in/out] Resource object
2898 //! \param PMOS_LOCK_PARAMS pLockFlags
2899 //! [in] Lock Flags
2900 //! \return MOS_STATUS
2901 //! MOS_STATUS_SUCCESS if successful
2902 //!
Mos_Specific_LockSyncRequest(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,PMOS_LOCK_PARAMS pLockFlags)2903 MOS_STATUS Mos_Specific_LockSyncRequest(
2904 PMOS_INTERFACE pOsInterface,
2905 PMOS_RESOURCE pOsResource,
2906 PMOS_LOCK_PARAMS pLockFlags)
2907 {
2908 MOS_UNUSED(pOsInterface);
2909 MOS_UNUSED(pOsInterface);
2910 MOS_UNUSED(pOsInterface);
2911
2912 return MOS_STATUS_SUCCESS;
2913 }
2914
2915 //!
2916 //! \brief Lock resource
2917 //! \details Lock allocated resource
2918 //! \param PMOS_INTERFACE pOsInterface
2919 //! [in] Pointer to OS interface structure
2920 //! \param PMOS_RESOURCE pOsResource
2921 //! [in] Pointer to input OS resource
2922 //! \param PMOS_LOCK_PARAMS pLockFlags
2923 //! [in] Lock Flags - MOS_LOCKFLAG_* flags
2924 //! \return void *
2925 //!
Mos_Specific_LockResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,PMOS_LOCK_PARAMS pLockFlags)2926 void *Mos_Specific_LockResource(
2927 PMOS_INTERFACE pOsInterface,
2928 PMOS_RESOURCE pOsResource,
2929 PMOS_LOCK_PARAMS pLockFlags)
2930 {
2931 void *pData = nullptr;
2932 MOS_OS_CONTEXT *pContext = nullptr;
2933
2934 MOS_OS_FUNCTION_ENTER;
2935
2936 MOS_OS_ASSERT(pOsInterface);
2937 MOS_OS_ASSERT(pOsResource);
2938 MOS_OS_ASSERT(pOsInterface->pOsContext);
2939
2940 if( nullptr == pOsInterface )
2941 {
2942 MOS_OS_ASSERTMESSAGE("input parameter pOsInterface is NULL.");
2943 return nullptr;
2944 }
2945
2946 if( nullptr == pOsResource)
2947 {
2948 MOS_OS_ASSERTMESSAGE("input parameter pOsInterface is NULL.");
2949 return nullptr;
2950 }
2951
2952 bool osContextValid = false;
2953 if (pOsInterface->osContextPtr != nullptr)
2954 {
2955 if (pOsInterface->osContextPtr->GetOsContextValid() == true)
2956 {
2957 osContextValid = true;
2958 }
2959 }
2960
2961 if (pOsInterface->apoMosEnabled)
2962 {
2963 return MosInterface::LockMosResource(pOsInterface->osStreamState, pOsResource, pLockFlags);
2964 }
2965
2966 if ((pOsInterface->modulizedMosEnabled)
2967 && (!pOsResource->bConvertedFromDDIResource)
2968 && (osContextValid == true)
2969 && (!Mos_Solo_IsEnabled(nullptr))
2970 && (pOsResource->pGfxResource))
2971 {
2972 if (nullptr == pOsInterface->osContextPtr)
2973 {
2974 MOS_OS_ASSERTMESSAGE("invalid osContextPtr, skip lock");
2975 }
2976
2977 if (pOsResource->pGfxResource)
2978 {
2979 GraphicsResource::LockParams params(pLockFlags);
2980 pData = pOsResource->pGfxResource->Lock(pOsInterface->osContextPtr, params);
2981 }
2982 else
2983 {
2984 MOS_OS_ASSERTMESSAGE("Received an empty Graphics Resource, skip lock");
2985 }
2986 return pData;
2987 }
2988
2989 pContext = pOsInterface->pOsContext;
2990 if (pOsResource && pOsResource->bo && pOsResource->pGmmResInfo)
2991 {
2992 MOS_LINUX_BO *bo = pOsResource->bo;
2993 GMM_RESOURCE_FLAG GmmFlags;
2994
2995 MOS_ZeroMemory(&GmmFlags, sizeof(GmmFlags));
2996 GmmFlags = pOsResource->pGmmResInfo->GetResFlags();
2997
2998 // Do decompression for a compressed surface before lock
2999 if (!pLockFlags->NoDecompress &&
3000 (((GmmFlags.Gpu.MMC || GmmFlags.Gpu.CCS) && GmmFlags.Gpu.UnifiedAuxSurface)||
3001 pOsResource->pGmmResInfo->IsMediaMemoryCompressed(0)))
3002 {
3003 PMOS_CONTEXT pOsContext = pOsInterface->pOsContext;
3004
3005 MOS_OS_ASSERT(pOsContext);
3006 MOS_OS_ASSERT(pOsContext->ppMediaMemDecompState);
3007 MOS_OS_ASSERT(pOsContext->pfnMemoryDecompress);
3008 pOsContext->pfnMemoryDecompress(pOsContext, pOsResource);
3009 }
3010
3011 if(false == pOsResource->bMapped)
3012 {
3013 if (pContext->bIsAtomSOC)
3014 {
3015 mos_bo_map_gtt(bo);
3016 }
3017 else
3018 {
3019 if (pOsResource->TileType != MOS_TILE_LINEAR && !pLockFlags->TiledAsTiled)
3020 {
3021 if (pContext->bUseSwSwizzling)
3022 {
3023 mos_bo_map(bo, (OSKM_LOCKFLAG_WRITEONLY&pLockFlags->WriteOnly));
3024 pOsResource->MmapOperation = MOS_MMAP_OPERATION_MMAP;
3025 if (pOsResource->pSystemShadow == nullptr)
3026 {
3027 pOsResource->pSystemShadow = (uint8_t *)MOS_AllocMemory(bo->size);
3028 MOS_OS_CHECK_CONDITION((pOsResource->pSystemShadow == nullptr), "Failed to allocate shadow surface", nullptr);
3029 }
3030 if (pOsResource->pSystemShadow)
3031 {
3032 int32_t flags = pContext->bTileYFlag ? 0 : 1;
3033 MOS_OS_CHECK_CONDITION((pOsResource->TileType != MOS_TILE_Y), "Unsupported tile type", nullptr);
3034 MOS_OS_CHECK_CONDITION((bo->size <= 0 || pOsResource->iPitch <= 0), "Invalid BO size or pitch", nullptr);
3035 Mos_SwizzleData((uint8_t*)bo->virt, pOsResource->pSystemShadow,
3036 MOS_TILE_Y, MOS_TILE_LINEAR, bo->size / pOsResource->iPitch, pOsResource->iPitch, flags);
3037 }
3038 }
3039 else
3040 {
3041 mos_bo_map_gtt(bo);
3042 pOsResource->MmapOperation = MOS_MMAP_OPERATION_MMAP_GTT;
3043 }
3044 }
3045 else if (pLockFlags->Uncached)
3046 {
3047 mos_bo_map_wc(bo);
3048 pOsResource->MmapOperation = MOS_MMAP_OPERATION_MMAP_WC;
3049 }
3050 else
3051 {
3052 mos_bo_map(bo, (OSKM_LOCKFLAG_WRITEONLY&pLockFlags->WriteOnly));
3053 pOsResource->MmapOperation = MOS_MMAP_OPERATION_MMAP;
3054 }
3055 }
3056 pOsResource->pData = pOsResource->pSystemShadow ? pOsResource->pSystemShadow : (uint8_t*)bo->virt;
3057 pOsResource->bMapped = true;
3058 }
3059
3060 pData = pOsResource->pData;
3061
3062 }
3063
3064 finish:
3065 MOS_OS_ASSERT(pData);
3066 return pData;
3067 }
3068
3069 //!
3070 //! \brief Unlock resource
3071 //! \details Unlock the locked resource
3072 //! \param PMOS_INTERFACE pOsInterface
3073 //! [in] Pointer to OS interface structure
3074 //! \param PMOS_RESOURCE pOsResource
3075 //! [in] Pointer to input OS resource
3076 //! \return MOS_STATUS
3077 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3078 //!
Mos_Specific_UnlockResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource)3079 MOS_STATUS Mos_Specific_UnlockResource(
3080 PMOS_INTERFACE pOsInterface,
3081 PMOS_RESOURCE pOsResource)
3082 {
3083 MOS_STATUS eStatus;
3084
3085 eStatus = MOS_STATUS_SUCCESS;
3086
3087 MOS_OS_CONTEXT *pContext = nullptr;
3088
3089 MOS_OS_FUNCTION_ENTER;
3090
3091 MOS_OS_CHK_NULL(pOsInterface);
3092 MOS_OS_CHK_NULL(pOsResource);
3093 MOS_OS_CHK_NULL(pOsInterface->pOsContext);
3094
3095 if (pOsInterface->apoMosEnabled)
3096 {
3097 return MosInterface::UnlockMosResource(pOsInterface->osStreamState, pOsResource);
3098 }
3099
3100 bool osContextValid;
3101 osContextValid = false;
3102 if (pOsInterface->osContextPtr != nullptr)
3103 {
3104 if (pOsInterface->osContextPtr->GetOsContextValid() == true)
3105 {
3106 osContextValid = true;
3107 }
3108 }
3109
3110 if ((pOsInterface->modulizedMosEnabled)
3111 && (!pOsResource->bConvertedFromDDIResource)
3112 && (osContextValid == true)
3113 && (!Mos_Solo_IsEnabled(nullptr))
3114 && (pOsResource->pGfxResource))
3115 {
3116 if (nullptr == pOsInterface->osContextPtr)
3117 {
3118 MOS_OS_ASSERTMESSAGE("invalid osContextPtr, skip lock");
3119 }
3120
3121 if (pOsResource->pGfxResource)
3122 {
3123 eStatus = pOsResource->pGfxResource->Unlock(pOsInterface->osContextPtr);
3124 }
3125 else
3126 {
3127 MOS_OS_VERBOSEMESSAGE("Received an empty Graphics Resource, skip unlock");
3128 }
3129 return eStatus;
3130 }
3131
3132 pContext = pOsInterface->pOsContext;
3133
3134 if(pOsResource->bo)
3135 {
3136 if(true == pOsResource->bMapped)
3137 {
3138 if (pContext->bIsAtomSOC)
3139 {
3140 mos_bo_unmap_gtt(pOsResource->bo);
3141 }
3142 else
3143 {
3144 if (pOsResource->pSystemShadow)
3145 {
3146 int32_t flags = pContext->bTileYFlag ? 0 : 1;
3147 Mos_SwizzleData(pOsResource->pSystemShadow, (uint8_t*)pOsResource->bo->virt,
3148 MOS_TILE_LINEAR, MOS_TILE_Y, pOsResource->bo->size / pOsResource->iPitch, pOsResource->iPitch, flags);
3149 MOS_FreeMemory(pOsResource->pSystemShadow);
3150 pOsResource->pSystemShadow = nullptr;
3151 }
3152
3153 switch(pOsResource->MmapOperation)
3154 {
3155 case MOS_MMAP_OPERATION_MMAP_GTT:
3156 mos_bo_unmap_gtt(pOsResource->bo);
3157 break;
3158 case MOS_MMAP_OPERATION_MMAP_WC:
3159 mos_bo_unmap_wc(pOsResource->bo);
3160 break;
3161 case MOS_MMAP_OPERATION_MMAP:
3162 mos_bo_unmap(pOsResource->bo);
3163 break;
3164 default:
3165 MOS_OS_ASSERTMESSAGE("Invalid mmap operation type");
3166 break;
3167 }
3168 }
3169 pOsResource->bo->virt = nullptr;
3170 pOsResource->bMapped = false;
3171 }
3172 pOsResource->pData = nullptr;
3173 }
3174
3175 finish:
3176 return eStatus;
3177 }
3178
3179 //!
3180 //! \brief Decompress Resource
3181 //! \details Decompress Resource
3182 //! \param PMOS_INTERFACE pOsInterface
3183 //! [in] pointer to OS Interface structure
3184 //! \param PMOS_RESOURCE pOsResource
3185 //! [in/out] Resource object
3186 //! \return MOS_STATUS
3187 //! MOS_STATUS_SUCCESS if successful
3188 //!
Mos_Specific_DecompResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource)3189 MOS_STATUS Mos_Specific_DecompResource(
3190 PMOS_INTERFACE pOsInterface,
3191 PMOS_RESOURCE pOsResource)
3192 {
3193 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
3194 MOS_OS_CONTEXT *pContext = nullptr;
3195
3196 //---------------------------------------
3197 MOS_OS_CHK_NULL(pOsInterface);
3198 MOS_OS_CHK_NULL(pOsResource);
3199 MOS_OS_CHK_NULL(pOsInterface->pOsContext);
3200 //---------------------------------------
3201
3202 if (pOsInterface->apoMosEnabled)
3203 {
3204 return MosInterface::DecompResource(pOsInterface->osStreamState, pOsResource);
3205 }
3206
3207 pContext = pOsInterface->pOsContext;
3208
3209 if (pOsResource && pOsResource->bo && pOsResource->pGmmResInfo)
3210 {
3211 MOS_LINUX_BO *bo = pOsResource->bo;
3212 if (pOsResource->pGmmResInfo->IsMediaMemoryCompressed(0))
3213 {
3214 PMOS_CONTEXT pOsContext = pOsInterface->pOsContext;
3215
3216 MOS_OS_CHK_NULL(pOsContext);
3217 MOS_OS_CHK_NULL(pOsContext->ppMediaMemDecompState);
3218 MOS_OS_CHK_NULL(pOsContext->pfnMemoryDecompress);
3219 pOsContext->pfnMemoryDecompress(pOsContext, pOsResource);
3220 }
3221 }
3222
3223 eStatus = MOS_STATUS_SUCCESS;
3224
3225 finish:
3226 return eStatus;
3227 }
3228
3229 //!
3230 //! \brief Set auxiliary sync resource
3231 //! \details Set auxiliary resource to sync with decompression
3232 //! \param PMOS_INTERFACE pOsInterface
3233 //! [in] pointer to OS Interface structure
3234 //! \param PMOS_RESOURCE pOsResource
3235 //! [in/out] Resource object
3236 //! \return MOS_STATUS
3237 //! MOS_STATUS_SUCCESS if successful
3238 //!
Mos_Specific_SetDecompSyncRes(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE syncResource)3239 MOS_STATUS Mos_Specific_SetDecompSyncRes(
3240 PMOS_INTERFACE pOsInterface,
3241 PMOS_RESOURCE syncResource)
3242 {
3243 return MOS_STATUS_SUCCESS;
3244 }
3245
3246 //!
3247 //! \brief Decompress and Copy Resource to Another Buffer
3248 //! \details Decompress and Copy Resource to Another Buffer
3249 //! \param PMOS_INTERFACE pOsInterface
3250 //! [in] pointer to OS Interface structure
3251 //! \param PMOS_RESOURCE inputOsResource
3252 //! [in] Input Resource object
3253 //! \param PMOS_RESOURCE outputOsResource
3254 //! [out] output Resource object
3255 //! \param [in] bOutputCompressed
3256 //! true means apply compression on output surface, else output uncompressed surface
3257 //! \return MOS_STATUS
3258 //! MOS_STATUS_SUCCESS if successful
3259 //!
Mos_Specific_DoubleBufferCopyResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE inputOsResource,PMOS_RESOURCE outputOsResource,bool bOutputCompressed)3260 MOS_STATUS Mos_Specific_DoubleBufferCopyResource(
3261 PMOS_INTERFACE osInterface,
3262 PMOS_RESOURCE inputOsResource,
3263 PMOS_RESOURCE outputOsResource,
3264 bool bOutputCompressed)
3265 {
3266 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
3267 MOS_OS_CONTEXT *pContext = nullptr;
3268
3269 //---------------------------------------
3270 MOS_OS_CHK_NULL(osInterface);
3271 MOS_OS_CHK_NULL(inputOsResource);
3272 MOS_OS_CHK_NULL(outputOsResource);
3273 //---------------------------------------
3274
3275 if (osInterface->apoMosEnabled)
3276 {
3277 return MosInterface::DoubleBufferCopyResource(osInterface->osStreamState, inputOsResource, outputOsResource, bOutputCompressed);
3278 }
3279
3280 pContext = osInterface->pOsContext;
3281
3282 if (inputOsResource && inputOsResource->bo && inputOsResource->pGmmResInfo &&
3283 outputOsResource && outputOsResource->bo && outputOsResource->pGmmResInfo)
3284 {
3285 // Double Buffer Copy can support any tile status surface with/without compression
3286 pContext->pfnMediaMemoryCopy(pContext, inputOsResource, outputOsResource, bOutputCompressed);
3287 }
3288
3289 eStatus = MOS_STATUS_SUCCESS;
3290
3291 finish:
3292 return eStatus;
3293 }
3294
3295 //!
3296 //! \brief Decompress and Copy Resource to Another Buffer
3297 //! \details Decompress and Copy Resource to Another Buffer
3298 //! \param PMOS_INTERFACE pOsInterface
3299 //! [in] pointer to OS Interface structure
3300 //! \param PMOS_RESOURCE inputOsResource
3301 //! [in] Input Resource object
3302 //! \param PMOS_RESOURCE outputOsResource
3303 //! [out] output Resource object
3304 //! \param [in] copyWidth
3305 //! The 2D surface Width
3306 //! \param [in] copyHeight
3307 //! The 2D surface height
3308 //! \param [in] copyInputOffset
3309 //! The offset of copied surface from
3310 //! \param [in] copyOutputOffset
3311 //! The offset of copied to
3312 //! \param [in] bOutputCompressed
3313 //! true means apply compression on output surface, else output uncompressed surface
3314 //! \return MOS_STATUS
3315 //! MOS_STATUS_SUCCESS if successful
3316 //!
Mos_Specific_MediaCopyResource2D(PMOS_INTERFACE osInterface,PMOS_RESOURCE inputOsResource,PMOS_RESOURCE outputOsResource,uint32_t copyWidth,uint32_t copyHeight,uint32_t bpp,bool bOutputCompressed)3317 MOS_STATUS Mos_Specific_MediaCopyResource2D(
3318 PMOS_INTERFACE osInterface,
3319 PMOS_RESOURCE inputOsResource,
3320 PMOS_RESOURCE outputOsResource,
3321 uint32_t copyWidth,
3322 uint32_t copyHeight,
3323 uint32_t bpp,
3324 bool bOutputCompressed)
3325 {
3326 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
3327 MOS_OS_CONTEXT *pContext = nullptr;
3328
3329 //---------------------------------------
3330 MOS_OS_CHK_NULL(osInterface);
3331 MOS_OS_CHK_NULL(inputOsResource);
3332 MOS_OS_CHK_NULL(outputOsResource);
3333 //---------------------------------------
3334
3335 if (osInterface->apoMosEnabled)
3336 {
3337 return MosInterface::MediaCopyResource2D(osInterface->osStreamState, inputOsResource, outputOsResource,
3338 copyWidth, copyHeight, bpp, bOutputCompressed);
3339 }
3340
3341 pContext = osInterface->pOsContext;
3342
3343 if (inputOsResource && inputOsResource->bo && inputOsResource->pGmmResInfo &&
3344 outputOsResource && outputOsResource->bo && outputOsResource->pGmmResInfo)
3345 {
3346 // Double Buffer Copy can support any tile status surface with/without compression
3347 pContext->pfnMediaMemoryCopy2D(pContext, inputOsResource, outputOsResource, copyWidth, copyHeight, 0, 0, bpp, bOutputCompressed);
3348 }
3349
3350 eStatus = MOS_STATUS_SUCCESS;
3351
3352 finish:
3353 return eStatus;
3354 }
3355
3356 //!
3357 //! \brief Copy mono picture
3358 //! \details This is the copy function dedicated to mono picture copy
3359 //! \param PMOS_INTERFACE pOsInterface
3360 //! [in] pointer to OS Interface structure
3361 //! \param PMOS_RESOURCE inputOsResource
3362 //! [in] Input Resource object
3363 //! \param PMOS_RESOURCE outputOsResource
3364 //! [out] output Resource object
3365 //! \param [in] copyWidth
3366 //! The 2D surface Width
3367 //! \param [in] copyHeight
3368 //! The 2D surface height
3369 //! \param [in] copyInputOffset
3370 //! The offset of copied surface from
3371 //! \param [in] copyOutputOffset
3372 //! The offset of copied to
3373 //! \param [in] bOutputCompressed
3374 //! true means apply compression on output surface, else output uncompressed surface
3375 //! \return MOS_STATUS
3376 //! MOS_STATUS_SUCCESS if successful
3377 //!
Mos_Specific_MonoSurfaceCopy(PMOS_INTERFACE osInterface,PMOS_RESOURCE inputOsResource,PMOS_RESOURCE outputOsResource,uint32_t copyWidth,uint32_t copyHeight,uint32_t copyInputOffset,uint32_t copyOutputOffset,bool bOutputCompressed)3378 MOS_STATUS Mos_Specific_MonoSurfaceCopy(
3379 PMOS_INTERFACE osInterface,
3380 PMOS_RESOURCE inputOsResource,
3381 PMOS_RESOURCE outputOsResource,
3382 uint32_t copyWidth,
3383 uint32_t copyHeight,
3384 uint32_t copyInputOffset,
3385 uint32_t copyOutputOffset,
3386 bool bOutputCompressed)
3387 {
3388 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
3389 MOS_OS_CONTEXT *pContext = nullptr;
3390
3391 //---------------------------------------
3392 MOS_OS_CHK_NULL_RETURN(osInterface);
3393 MOS_OS_CHK_NULL_RETURN(inputOsResource);
3394 MOS_OS_CHK_NULL_RETURN(outputOsResource);
3395 //---------------------------------------
3396
3397 if (osInterface->apoMosEnabled)
3398 {
3399 return MosInterface::MonoSurfaceCopy(osInterface->osStreamState, inputOsResource, outputOsResource, copyWidth, copyHeight, copyInputOffset, copyOutputOffset, bOutputCompressed);
3400 }
3401
3402 pContext = osInterface->pOsContext;
3403
3404 if (inputOsResource && inputOsResource->bo && inputOsResource->pGmmResInfo &&
3405 outputOsResource && outputOsResource->bo && outputOsResource->pGmmResInfo)
3406 {
3407 // Double Buffer Copy can support any tile status surface with/without compression
3408 pContext->pfnMediaMemoryCopy2D(pContext, inputOsResource, outputOsResource, copyWidth, copyHeight, 0, 0, 16, bOutputCompressed);
3409 }
3410
3411 eStatus = MOS_STATUS_SUCCESS;
3412
3413 return eStatus;
3414 }
3415
3416 //!
3417 //! \brief Get Mos Context
3418 //! \details Get Mos Context info
3419 //! \param PMOS_INTERFACE pOsInterface
3420 //! [in] Pointer to OS interface structure
3421 //! \param mosContext void **
3422 //! [out] pointer of mos_context
3423 //! \return MOS_STATUS
3424 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3425 //!
Mos_Specific_GetMosContext(PMOS_INTERFACE osInterface,PMOS_CONTEXT * mosContext)3426 MOS_STATUS Mos_Specific_GetMosContext(
3427 PMOS_INTERFACE osInterface,
3428 PMOS_CONTEXT* mosContext)
3429 {
3430 MOS_OS_CHK_NULL_RETURN(osInterface);
3431 if (osInterface->apoMosEnabled)
3432 {
3433 void *apo_mos_context = nullptr;
3434 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetperStreamParameters(osInterface->osStreamState, &apo_mos_context));
3435 *mosContext = (PMOS_CONTEXT)apo_mos_context;
3436 }
3437 else
3438 {
3439 *mosContext = (PMOS_CONTEXT)osInterface->pOsContext;
3440 }
3441
3442 return MOS_STATUS_SUCCESS;
3443 }
3444
3445 //!
3446 //! \brief Set patch entry
3447 //! \details Sets the patch entry in MS's patch list
3448 //! \param PMOS_INTERFACE pOsInterface
3449 //! [in] Pointer to OS interface structure
3450 //! \param PMOS_PATCH_ENTRY_PARAMS pParams
3451 //! [in] patch entry params
3452 //! \return MOS_STATUS
3453 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3454 //!
Mos_Specific_SetPatchEntry(PMOS_INTERFACE pOsInterface,PMOS_PATCH_ENTRY_PARAMS pParams)3455 MOS_STATUS Mos_Specific_SetPatchEntry(
3456 PMOS_INTERFACE pOsInterface,
3457 PMOS_PATCH_ENTRY_PARAMS pParams)
3458 {
3459 MOS_OS_FUNCTION_ENTER;
3460
3461 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3462 MOS_OS_CHK_NULL_RETURN(pParams);
3463
3464 #if (_DEBUG || _RELEASE_INTERNAL)
3465 if (!pParams->bUpperBoundPatch && pParams->presResource)
3466 {
3467 uint32_t handle = pParams->presResource->bo?pParams->presResource->bo->handle:0;
3468 uint32_t eventData[] = {handle, pParams->uiResourceOffset,
3469 pParams->uiPatchOffset, pParams->bWrite,
3470 pParams->HwCommandType, pParams->forceDwordOffset,
3471 pParams->patchType};
3472 MOS_TraceEventExt(EVENT_RESOURCE_PATCH, EVENT_TYPE_INFO2,
3473 &eventData, sizeof(eventData),
3474 nullptr, 0);
3475 }
3476 #endif
3477 if (pOsInterface->apoMosEnabled)
3478 {
3479 return MosInterface::SetPatchEntry(pOsInterface->osStreamState, pParams);
3480 }
3481
3482 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
3483 {
3484 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
3485 MOS_OS_CHK_NULL_RETURN(gpuContext);
3486
3487 return (gpuContext->SetPatchEntry(pOsInterface, pParams));
3488 }
3489
3490 PMOS_OS_CONTEXT pOsContext;
3491 MOS_OS_GPU_CONTEXT *pOsGpuContext;
3492 PPATCHLOCATIONLIST pPatchList;
3493 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3494
3495 pOsContext = pOsInterface->pOsContext;
3496 pOsGpuContext = &pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
3497 pPatchList = pOsGpuContext->pPatchLocationList;
3498
3499 pPatchList[pOsGpuContext->uiCurrentNumPatchLocations].AllocationIndex = pParams->uiAllocationIndex;
3500 pPatchList[pOsGpuContext->uiCurrentNumPatchLocations].AllocationOffset = pParams->uiResourceOffset;
3501 pPatchList[pOsGpuContext->uiCurrentNumPatchLocations].PatchOffset = pParams->uiPatchOffset;
3502 pPatchList[pOsGpuContext->uiCurrentNumPatchLocations].uiWriteOperation = pParams->bWrite ? true : false;
3503
3504 if (pOsInterface->osCpInterface &&
3505 pOsInterface->osCpInterface->IsHMEnabled())
3506 {
3507 pOsInterface->osCpInterface->RegisterPatchForHM(
3508 (uint32_t*)(pParams->cmdBufBase + pParams->uiPatchOffset),
3509 pParams->bWrite,
3510 pParams->HwCommandType,
3511 pParams->forceDwordOffset,
3512 pParams->presResource,
3513 &pPatchList[pOsGpuContext->uiCurrentNumPatchLocations]);
3514 }
3515
3516 pOsGpuContext->uiCurrentNumPatchLocations++;
3517
3518 return eStatus;
3519 }
3520
3521 //!
3522 //! \brief Update resource usage type
3523 //! \details update the resource usage for cache policy
3524 //! \param PMOS_RESOURCE pOsResource
3525 //! [in/out] Pointer to OS Resource
3526 //! \param MOS_HW_RESOURCE_DEF resUsageType
3527 //! [in] resosuce usage type
3528 //! \return MOS_STATUS
3529 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3530 //!
Mos_Specific_UpdateResourceUsageType(PMOS_RESOURCE pOsResource,MOS_HW_RESOURCE_DEF resUsageType)3531 MOS_STATUS Mos_Specific_UpdateResourceUsageType(
3532 PMOS_RESOURCE pOsResource,
3533 MOS_HW_RESOURCE_DEF resUsageType)
3534 {
3535 return MosInterface::UpdateResourceUsageType(pOsResource, resUsageType);
3536 }
3537
3538 //!
3539 //! \brief Registers Resource
3540 //! \details Set the Allocation Index in OS resource structure
3541 //! \param PMOS_INTERFACE pOsInterface
3542 //! [in] Pointer to OS Interface
3543 //! \param PMOS_RESOURCE pOsResource
3544 //! [in/out] Pointer to OS Resource
3545 //! \param int32_t bWrite
3546 //! [in] Write Flag
3547 //! \param int32_t bWritebSetResourceSyncTag
3548 //! [in] Resource registration Flag, no use for Linux
3549 //! \return MOS_STATUS
3550 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3551 //!
Mos_Specific_RegisterResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,int32_t bWrite,int32_t bWritebSetResourceSyncTag)3552 MOS_STATUS Mos_Specific_RegisterResource (
3553 PMOS_INTERFACE pOsInterface,
3554 PMOS_RESOURCE pOsResource,
3555 int32_t bWrite,
3556 int32_t bWritebSetResourceSyncTag)
3557 {
3558 MOS_OS_FUNCTION_ENTER;
3559
3560 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3561 MOS_OS_CHK_NULL_RETURN(pOsResource);
3562
3563 if (pOsInterface->apoMosEnabled)
3564 {
3565 #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
3566 GpuCmdResInfoDumpNext::GetInstance(pOsInterface->pOsContext)->StoreCmdResPtr(pOsInterface, (const void *)pOsResource);
3567 #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
3568
3569 return MosInterface::RegisterResource(
3570 pOsInterface->osStreamState,
3571 pOsResource,
3572 bWrite);
3573 }
3574
3575 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
3576 {
3577 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
3578 MOS_OS_CHK_NULL_RETURN(gpuContext);
3579
3580 #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
3581 GpuCmdResInfoDump::GetInstance(pOsInterface->pOsContext)->StoreCmdResPtr(pOsInterface, (const void *)pOsResource);
3582 #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
3583
3584 return (gpuContext->RegisterResource(pOsResource, bWrite));
3585 }
3586
3587 PMOS_OS_CONTEXT pOsContext = nullptr;
3588 PMOS_RESOURCE pResources = nullptr;
3589 uint32_t uiAllocation = 0;
3590 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3591 MOS_OS_GPU_CONTEXT *pOsGpuContext = nullptr;
3592 MOS_UNUSED(bWritebSetResourceSyncTag);
3593
3594 MOS_OS_ASSERT(pOsInterface);
3595 MOS_OS_ASSERT(pOsInterface->pOsContext);
3596
3597 pOsContext = pOsInterface->pOsContext;
3598
3599 if (pOsInterface->CurrentGpuContextOrdinal == MOS_GPU_CONTEXT_INVALID_HANDLE)
3600 {
3601 MOS_OS_ASSERTMESSAGE("CurrentGpuContextOrdinal exceed max.");
3602 return MOS_STATUS_INVALID_PARAMETER;
3603 }
3604 pOsGpuContext = &pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
3605
3606 // Find previous registration
3607 pResources = pOsGpuContext->pResources;
3608 if( nullptr == pResources)
3609 {
3610 MOS_OS_ASSERTMESSAGE("pResource is NULL.");
3611 return MOS_STATUS_SUCCESS;
3612 }
3613 for (uiAllocation = 0;
3614 uiAllocation < pOsGpuContext->uiResCount;
3615 uiAllocation++, pResources++)
3616 {
3617 if (pOsResource->bo == pResources->bo) break;
3618 }
3619 // Allocation list to be updated
3620 if (uiAllocation < pOsGpuContext->uiMaxNumAllocations)
3621 {
3622 // New buffer
3623 if (uiAllocation == pOsGpuContext->uiResCount)
3624 {
3625 pOsGpuContext->uiResCount++;
3626 }
3627
3628 // Set allocation
3629 pOsResource->iAllocationIndex[pOsInterface->CurrentGpuContextOrdinal] = uiAllocation;
3630 pOsGpuContext->pResources[uiAllocation] = *pOsResource;
3631 pOsGpuContext->pbWriteMode[uiAllocation] |= bWrite;
3632 pOsGpuContext->pAllocationList[uiAllocation].hAllocation = &pOsGpuContext->pResources[uiAllocation];
3633 pOsGpuContext->pAllocationList[uiAllocation].WriteOperation|= bWrite;
3634 pOsGpuContext->uiNumAllocations = pOsGpuContext->uiResCount;
3635 }
3636 else
3637 {
3638 MOS_OS_ASSERTMESSAGE("Reached max # registrations.");
3639 eStatus = MOS_STATUS_UNKNOWN;
3640 }
3641 return eStatus;
3642 }
3643
3644 //!
3645 //! \brief Verify command buffer size
3646 //! \details Verifys the buffer to be used for rendering GPU commands is large enough
3647 //! \param PMOS_INTERFACE pOsInterface
3648 //! [in] Pointer to OS interface structure
3649 //! \param uint32_t dwRequestedSize
3650 //! [in] Buffer size requested
3651 //! \return MOS_STATUS
3652 //! Return MOS_STATUS_SUCCESS if successful (command buffer will be large enough to hold dwMaxSize)
3653 //! otherwise failed
3654 //!
Mos_Specific_VerifyCommandBufferSize(PMOS_INTERFACE pOsInterface,uint32_t dwRequestedSize,uint32_t dwFlags)3655 MOS_STATUS Mos_Specific_VerifyCommandBufferSize(
3656 PMOS_INTERFACE pOsInterface,
3657 uint32_t dwRequestedSize,
3658 uint32_t dwFlags)
3659 {
3660 MOS_OS_FUNCTION_ENTER;
3661
3662 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3663
3664 if (pOsInterface->apoMosEnabled)
3665 {
3666 return MosInterface::VerifyCommandBufferSize(pOsInterface->osStreamState, 0, dwRequestedSize, dwFlags);
3667 }
3668
3669 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
3670 {
3671 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
3672 MOS_OS_CHK_NULL_RETURN(gpuContext);
3673
3674 return (gpuContext->VerifyCommandBufferSize(dwRequestedSize));
3675 }
3676
3677 PMOS_OS_CONTEXT pOsContext = nullptr;
3678 MOS_OS_GPU_CONTEXT OsGpuContext;
3679
3680 //---------------------------------------
3681 MOS_UNUSED(dwFlags);
3682 MOS_OS_ASSERT(pOsInterface);
3683 MOS_OS_ASSERT(pOsInterface->pOsContext);
3684 //---------------------------------------
3685
3686 if (pOsInterface->CurrentGpuContextOrdinal == MOS_GPU_CONTEXT_INVALID_HANDLE)
3687 {
3688 MOS_OS_ASSERTMESSAGE("CurrentGpuContextOrdinal exceed max.");
3689 return MOS_STATUS_INVALID_PARAMETER;
3690 }
3691
3692 pOsContext = pOsInterface->pOsContext;
3693 OsGpuContext = pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
3694
3695 if (OsGpuContext.uiCommandBufferSize < dwRequestedSize)
3696 {
3697 return MOS_STATUS_UNKNOWN;
3698 }
3699
3700 return MOS_STATUS_SUCCESS;
3701 }
3702
3703 //!
3704 //! \brief Resets Resource Allocation
3705 //! \details Resets Resource Allocation
3706 //! \param PMOS_INTERFACE pOsInterface
3707 //! [in] Pointer to OS interface structure
3708 //! \param PMOS_RESOURCE pOsResource
3709 //! [in] Pointer to input OS resource
3710 //! \return void
3711 //!
Mos_Specific_ResetResourceAllocationIndex(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource)3712 void Mos_Specific_ResetResourceAllocationIndex (
3713 PMOS_INTERFACE pOsInterface,
3714 PMOS_RESOURCE pOsResource)
3715 {
3716 int32_t i;
3717 MOS_UNUSED(pOsInterface);
3718
3719 if( nullptr == pOsResource)
3720 {
3721 MOS_OS_ASSERTMESSAGE("pOsResource is NULL.");
3722 return;
3723 }
3724
3725 for (i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
3726 {
3727 pOsResource->iAllocationIndex[i] = MOS_INVALID_ALLOC_INDEX;
3728 }
3729 }
3730
3731 //!
3732 //! \brief Get command buffer
3733 //! \details Retrieves buffer to be used for rendering GPU commands
3734 //! \param PMOS_INTERFACE pOsInterface
3735 //! [in] Pointer to OS interface structure
3736 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
3737 //! [out] Pointer to Command Buffer control structure
3738 //! \return MOS_STATUS
3739 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3740 //!
Mos_Specific_GetCommandBuffer(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer,uint32_t dwFlags)3741 MOS_STATUS Mos_Specific_GetCommandBuffer(
3742 PMOS_INTERFACE pOsInterface,
3743 PMOS_COMMAND_BUFFER pCmdBuffer,
3744 uint32_t dwFlags)
3745 {
3746 MOS_OS_FUNCTION_ENTER;
3747
3748 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3749 MOS_OS_CHK_NULL_RETURN(pCmdBuffer);
3750
3751 if (pOsInterface->apoMosEnabled)
3752 {
3753 return MosInterface::GetCommandBuffer(pOsInterface->osStreamState, pCmdBuffer, dwFlags);
3754 }
3755
3756 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
3757 {
3758 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
3759 MOS_OS_CHK_NULL_RETURN(gpuContext);
3760
3761 return (gpuContext->GetCommandBuffer(pCmdBuffer, dwFlags));
3762 }
3763
3764 PMOS_OS_CONTEXT pOsContext = nullptr;
3765 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3766 PMOS_OS_GPU_CONTEXT pOsGpuContext = nullptr;
3767 uint32_t uiCommandBufferSize = 0;
3768
3769 MOS_UNUSED(dwFlags);
3770 MOS_OS_CHK_NULL(pOsInterface);
3771 MOS_OS_CHK_NULL(pOsInterface->pOsContext);
3772 MOS_OS_CHK_NULL(pCmdBuffer);
3773
3774 if (pOsInterface->CurrentGpuContextOrdinal == MOS_GPU_CONTEXT_INVALID_HANDLE)
3775 {
3776 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
3777 eStatus = MOS_STATUS_INVALID_PARAMETER;
3778 goto finish;
3779 }
3780
3781 // Activate software context
3782 pOsContext = pOsInterface->pOsContext;
3783 pOsGpuContext = &pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
3784 uiCommandBufferSize = pOsGpuContext->uiCommandBufferSize;
3785
3786 if(pOsGpuContext->bCBFlushed == true)
3787 {
3788 if (pOsContext->pfnGetCommandBuffer(pOsContext,
3789 pCmdBuffer,
3790 uiCommandBufferSize))
3791 {
3792 MOS_OS_CHK_STATUS(pOsContext->pfnInsertCmdBufferToPool(pOsContext, pCmdBuffer));
3793 pOsGpuContext->bCBFlushed = false;
3794 eStatus = MOS_SecureMemcpy(pOsGpuContext->pCB, sizeof(MOS_COMMAND_BUFFER), pCmdBuffer, sizeof(MOS_COMMAND_BUFFER));
3795 MOS_OS_CHECK_CONDITION((eStatus != MOS_STATUS_SUCCESS), "Failed to copy command buffer", eStatus);
3796 }
3797 else
3798 {
3799 MOS_OS_ASSERTMESSAGE("Failed to activate command buffer.");
3800 eStatus = MOS_STATUS_UNKNOWN;
3801 goto finish;
3802 }
3803 }
3804
3805 MOS_OS_CHK_STATUS(pOsInterface->pfnRegisterResource(pOsInterface, &(pOsGpuContext->pCB->OsResource), false, false));
3806 eStatus = MOS_SecureMemcpy(pCmdBuffer, sizeof(MOS_COMMAND_BUFFER), pOsGpuContext->pCB, sizeof(MOS_COMMAND_BUFFER));
3807 MOS_OS_CHECK_CONDITION((eStatus != MOS_STATUS_SUCCESS), "Failed to copy command buffer", eStatus);
3808
3809 finish:
3810 return eStatus;
3811 }
3812
3813 //!
3814 //! \brief Set indirect state size
3815 //! \details Sets indirect state size to be used for rendering purposes
3816 //! \param PMOS_INTERFACE pOsInterface
3817 //! [in] Pointer to OS interface structure
3818 //! \param uint32_t uSize
3819 //! [in] State size
3820 //! \return MOS_STATUS
3821 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3822 //!
Mos_Specific_SetIndirectStateSize(PMOS_INTERFACE pOsInterface,uint32_t uSize)3823 MOS_STATUS Mos_Specific_SetIndirectStateSize(
3824 PMOS_INTERFACE pOsInterface,
3825 uint32_t uSize)
3826 {
3827 MOS_OS_FUNCTION_ENTER;
3828
3829 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3830
3831 if (pOsInterface->apoMosEnabled)
3832 {
3833 return MosInterface::SetupIndirectState(pOsInterface->osStreamState, uSize);
3834 }
3835
3836 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
3837 {
3838 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
3839 MOS_OS_CHK_NULL_RETURN(gpuContext);
3840
3841 MOS_OS_CHK_STATUS_RETURN(gpuContext->SetIndirectStateSize(uSize));
3842 }
3843
3844 PMOS_CONTEXT pOsContext = nullptr;
3845 MOS_STATUS eStatus;
3846
3847 MOS_OS_CHK_NULL(pOsInterface);
3848
3849 eStatus = MOS_STATUS_SUCCESS;
3850
3851 pOsContext = pOsInterface->pOsContext;
3852 MOS_OS_CHK_NULL(pOsContext);
3853
3854 pOsContext->uIndirectStateSize = uSize;
3855
3856 finish:
3857 return eStatus;
3858 }
3859
3860 //!
3861 //! \brief Set indirect state size
3862 //! \details Retrieves indirect state to be used for rendering purposes
3863 //! \param PMOS_INTERFACE pOsInterface
3864 //! [in] Pointer to OS interface structure
3865 //! \param uint32_t *puOffset
3866 //! [out] Pointer to indirect buffer offset
3867 //! \param uint32_t *puSize
3868 //! [out] Pointer to indirect buffer size
3869 //! \return MOS_STATUS
3870 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3871 //!
Mos_Specific_GetIndirectState(PMOS_INTERFACE pOsInterface,uint32_t * puOffset,uint32_t * puSize)3872 MOS_STATUS Mos_Specific_GetIndirectState(
3873 PMOS_INTERFACE pOsInterface,
3874 uint32_t *puOffset,
3875 uint32_t *puSize)
3876 {
3877 MOS_OS_FUNCTION_ENTER;
3878
3879 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3880 MOS_OS_CHK_NULL_RETURN(puOffset);
3881 MOS_OS_CHK_NULL_RETURN(puSize);
3882
3883 if (pOsInterface->apoMosEnabled)
3884 {
3885 uint32_t offset = 0;
3886 uint32_t size = 0;
3887 auto eStatus = MosInterface::GetIndirectState(pOsInterface->osStreamState, nullptr, offset, size);
3888 *puOffset = offset;
3889 *puSize = size;
3890 return eStatus;
3891 }
3892
3893 if (pOsInterface->CurrentGpuContextHandle == MOS_GPU_CONTEXT_INVALID_HANDLE)
3894 {
3895 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
3896 return MOS_STATUS_INVALID_PARAMETER;
3897 }
3898
3899 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
3900 {
3901 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
3902 MOS_OS_CHK_NULL_RETURN(gpuContext);
3903
3904 return (gpuContext->GetIndirectState(puOffset, puSize));
3905 }
3906
3907 PMOS_CONTEXT pOsContext = nullptr;
3908 MOS_OS_GPU_CONTEXT OsGpuContext;
3909
3910 pOsContext = pOsInterface->pOsContext;
3911 if (pOsContext)
3912 {
3913 OsGpuContext = pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
3914
3915 if (puOffset)
3916 {
3917 *puOffset = OsGpuContext.uiCommandBufferSize - pOsContext->uIndirectStateSize;
3918 }
3919
3920 if (puSize)
3921 {
3922 *puSize = pOsContext->uIndirectStateSize;
3923 }
3924 }
3925 return MOS_STATUS_SUCCESS;
3926 }
3927
3928 //!
3929 //! \brief Get Resource Allocation Index
3930 //! \details Get Resource Allocation Index
3931 //! \param PMOS_INTERFACE pOsInterface
3932 //! [in] Pointer to OS interface structure
3933 //! \param PMOS_RESOURCE pResource
3934 //! [in] Pointer to input OS resource
3935 //! \return int32_t
3936 //! return the allocation index
3937 //!
Mos_Specific_GetResourceAllocationIndex(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pResource)3938 int32_t Mos_Specific_GetResourceAllocationIndex(
3939 PMOS_INTERFACE pOsInterface,
3940 PMOS_RESOURCE pResource)
3941 {
3942 MOS_OS_FUNCTION_ENTER;
3943
3944 if (pResource && pOsInterface)
3945 {
3946
3947 if (pOsInterface->CurrentGpuContextHandle == MOS_GPU_CONTEXT_INVALID_HANDLE)
3948 {
3949 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
3950 return MOS_STATUS_INVALID_PARAMETER;
3951 }
3952
3953 return(pResource->iAllocationIndex[pOsInterface->CurrentGpuContextOrdinal]);
3954 }
3955
3956 return MOS_INVALID_ALLOC_INDEX;
3957
3958 }
3959
3960 //!
3961 //! \brief Get Indirect State Pointer
3962 //! \details Get Indirect State Pointer
3963 //! \param PMOS_INTERFACE pOsInterface
3964 //! [in] Pointer to OS interface structure
3965 //! \param uint8_t **pIndirectState
3966 //! [out] Pointer to Indirect State Buffer
3967 //! \return MOS_STATUS
3968 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3969 //!
Mos_Specific_GetIndirectStatePointer(PMOS_INTERFACE pOsInterface,uint8_t ** pIndirectState)3970 MOS_STATUS Mos_Specific_GetIndirectStatePointer(
3971 PMOS_INTERFACE pOsInterface,
3972 uint8_t **pIndirectState)
3973 {
3974 PMOS_OS_CONTEXT pOsContext = nullptr;
3975 MOS_OS_GPU_CONTEXT OsGpuContext = {};
3976 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3977
3978 MOS_OS_FUNCTION_ENTER;
3979
3980 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3981 MOS_OS_CHK_NULL_RETURN(pIndirectState);
3982
3983 if (pOsInterface->apoMosEnabled)
3984 {
3985 uint32_t offset = 0;
3986 uint32_t size = 0;
3987 return MosInterface::GetIndirectState(pOsInterface->osStreamState, pIndirectState, offset, size);
3988 }
3989
3990 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
3991 {
3992 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
3993 MOS_OS_CHK_NULL_RETURN(gpuContext);
3994
3995 return (gpuContext->GetIndirectStatePointer(pIndirectState));
3996 }
3997
3998 eStatus = MOS_STATUS_UNKNOWN;
3999
4000 pOsContext = (pOsInterface) ? pOsInterface->pOsContext : nullptr;
4001
4002 if (pOsContext)
4003 {
4004 if (pOsInterface->CurrentGpuContextHandle == MOS_GPU_CONTEXT_INVALID_HANDLE)
4005 {
4006 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
4007 return MOS_STATUS_INVALID_PARAMETER;
4008 }
4009
4010 OsGpuContext = pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
4011
4012 if (OsGpuContext.pCB && OsGpuContext.pCB->pCmdBase)
4013 {
4014 *pIndirectState =
4015 (uint8_t*)OsGpuContext.pCB->pCmdBase +
4016 OsGpuContext.uiCommandBufferSize -
4017 pOsContext->uIndirectStateSize;
4018
4019 eStatus = MOS_STATUS_SUCCESS;
4020 }
4021 }
4022
4023 return eStatus;
4024 }
4025
4026 //!
4027 //! \brief Return command buffer space
4028 //! \details Return unused command buffer space
4029 //! \param PMOS_INTERFACE pOsInterface
4030 //! [in] Pointer to OS interface structure
4031 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
4032 //! [out] Pointer to Command Buffer control structure
4033 //! \return void
4034 //!
Mos_Specific_ReturnCommandBuffer(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer,uint32_t dwFlags)4035 void Mos_Specific_ReturnCommandBuffer(
4036 PMOS_INTERFACE pOsInterface,
4037 PMOS_COMMAND_BUFFER pCmdBuffer,
4038 uint32_t dwFlags)
4039 {
4040 MOS_OS_FUNCTION_ENTER;
4041
4042 if (pOsInterface == nullptr || pCmdBuffer == nullptr)
4043 {
4044 MOS_OS_ASSERTMESSAGE("Invalid parameters.");
4045 return;
4046 }
4047
4048 // Need to ensure 4K extra padding for HW requirement.
4049 if (pCmdBuffer && pCmdBuffer->iRemaining < EXTRA_PADDING_NEEDED)
4050 {
4051 MOS_OS_ASSERTMESSAGE("Need to ensure 4K extra padding for HW requirement.");
4052 }
4053
4054 if (pOsInterface->apoMosEnabled)
4055 {
4056 auto status = MosInterface::ReturnCommandBuffer(pOsInterface->osStreamState, pCmdBuffer, dwFlags);
4057 if (MOS_FAILED(status))
4058 {
4059 MOS_OS_ASSERTMESSAGE("ReturnCommandBuffer failed.");
4060 }
4061 return;
4062 }
4063
4064 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
4065 {
4066 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
4067
4068 if (gpuContext)
4069 {
4070 gpuContext->ReturnCommandBuffer(pCmdBuffer, dwFlags);
4071 }
4072 else
4073 {
4074 MOS_OS_ASSERTMESSAGE("Cannot get valid Gpu context!");
4075 }
4076
4077 return;
4078 }
4079
4080 PMOS_OS_CONTEXT pOsContext = nullptr;
4081 int32_t bResult;
4082
4083 MOS_UNUSED(dwFlags);
4084
4085 bResult = false;
4086
4087 // Validate parameters
4088 pOsContext = (pOsInterface) ? pOsInterface->pOsContext : nullptr;
4089 if (pOsContext == nullptr || pCmdBuffer == nullptr)
4090 {
4091 MOS_OS_ASSERTMESSAGE("Invalid parameters.");
4092 goto finish;
4093 }
4094
4095 pOsContext->pfnReturnCommandBuffer(pOsContext,pOsInterface->CurrentGpuContextOrdinal, pCmdBuffer);
4096
4097 finish:
4098 return;
4099 }
4100 #if (_DEBUG || _RELEASE_INTERNAL)
Mos_GetNopCommandBuffer_Linux(PMOS_INTERFACE pOsInterface)4101 MOS_LINUX_BO * Mos_GetNopCommandBuffer_Linux(
4102 PMOS_INTERFACE pOsInterface)
4103 {
4104 int j;
4105 uint32_t *buf = nullptr;
4106 MOS_LINUX_BO* bo = nullptr;
4107
4108 j = 0;
4109
4110 if(pOsInterface == nullptr || pOsInterface->pOsContext == nullptr)
4111 {
4112 return nullptr;
4113 }
4114
4115 struct mos_drm_bo_alloc alloc;
4116 alloc.name = "NOP_CMD_BO";
4117 alloc.size = 4096;
4118 alloc.alignment = 4096;
4119 alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
4120 bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, &alloc);
4121 if(bo == nullptr)
4122 {
4123 return nullptr;
4124 }
4125
4126 mos_bo_map(bo, 1);
4127 buf = (uint32_t*)bo->virt;
4128 if(buf == nullptr)
4129 {
4130 mos_bo_unreference(bo);
4131 return nullptr;
4132 }
4133
4134 buf[j++] = 0x05000000; // MI_BATCH_BUFFER_END
4135
4136 mos_bo_unmap(bo);
4137
4138 return bo;
4139 }
4140
Mos_GetBadCommandBuffer_Linux(PMOS_INTERFACE pOsInterface)4141 MOS_LINUX_BO * Mos_GetBadCommandBuffer_Linux(
4142 PMOS_INTERFACE pOsInterface)
4143 {
4144 int j;
4145 uint32_t *buf = nullptr;
4146 MOS_LINUX_BO* bo = nullptr;
4147
4148 j = 0;
4149
4150 if(pOsInterface == nullptr || pOsInterface->pOsContext == nullptr)
4151 {
4152 return nullptr;
4153 }
4154
4155 struct mos_drm_bo_alloc alloc;
4156 alloc.name = "BAD_CMD_BO";
4157 alloc.size = 4096;
4158 alloc.alignment = 4096;
4159 alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
4160 bo = mos_bo_alloc(pOsInterface->pOsContext->bufmgr, &alloc);
4161 if(bo == nullptr)
4162 {
4163 return nullptr;
4164 }
4165
4166 mos_bo_map(bo, 1);
4167 buf = (uint32_t*)bo->virt;
4168 if(buf == nullptr)
4169 {
4170 mos_bo_unreference(bo);
4171 return nullptr;
4172 }
4173
4174 /* Hanging batch buffer */
4175 // Semaphore setup:
4176 // Set up GTT buffer, polling mode with
4177 // comparison: address > op data (0xffffffff),
4178 // which should never resolve since nothing
4179 // is bigger than 0xffffffff. This semaphore
4180 // should result in a hang that TDR will have
4181 // to handle.
4182 //
4183 // 31:29 = 0
4184 // 28:23 = 0x1c
4185 // ---> 31:24 = 0x0e, 23=0x0
4186 // 22:22 = 0x1 (GTT, must be secure batch)
4187 // 21:16 = 0x0
4188 // ---> 23:20 = 0x4, 19:16=0x0
4189 // 15:15 = 0x1 (polling mode)
4190 // 14:12 = 0x0: memory data > op data (set op data = 0xffffffff and we should never have a match... if the comparison is unsigned)
4191 // ---> 15:12 = 0x8
4192 // 11:08 = 0x0
4193 // 07:00 = 0x2
4194 // ---> 07:04 = 0x0, 03:00 = 0x2
4195 // 31:0 = 0xffffffff
4196 //
4197 buf[j++] = 0x0e008002;
4198
4199 // semaphore data
4200 //
4201 buf[j++] = 0xffffffff;
4202
4203 // semaphore address
4204 //
4205 buf[j++] = 0x0;
4206 buf[j++] = 0x0;
4207
4208 buf[j++] = 0x0; /* MI_NOOP */
4209 buf[j++] = 0x05000000; // MI_BATCH_BUFFER_END
4210
4211 mos_bo_unmap(bo);
4212
4213 return bo;
4214 }
4215 #endif // _DEBUG || _RELEASE_INTERNAL
4216
Mos_Specific_GetVcsExecFlag(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer,MOS_GPU_NODE GpuNode)4217 uint32_t Mos_Specific_GetVcsExecFlag(PMOS_INTERFACE pOsInterface,
4218 PMOS_COMMAND_BUFFER pCmdBuffer,
4219 MOS_GPU_NODE GpuNode)
4220 {
4221 MOS_OS_ASSERT(pOsInterface);
4222 MOS_OS_ASSERT(pCmdBuffer);
4223 uint32_t VcsExecFlag = I915_EXEC_BSD | I915_EXEC_BSD_RING1;
4224
4225 if (MOS_VDBOX_NODE_INVALID == pCmdBuffer->iVdboxNodeIndex)
4226 {
4227 // That's those case when BB did not have any VDBOX# specific commands.
4228 // Thus, we need to select VDBOX# here. Alternatively we can rely on KMD
4229 // to make balancing for us, i.e. rely on Virtual Engine support.
4230 pCmdBuffer->iVdboxNodeIndex = pOsInterface->pfnGetVdboxNodeId(pOsInterface, pCmdBuffer);
4231 if (MOS_VDBOX_NODE_INVALID == pCmdBuffer->iVdboxNodeIndex)
4232 {
4233 pCmdBuffer->iVdboxNodeIndex = (GpuNode == MOS_GPU_NODE_VIDEO)?
4234 MOS_VDBOX_NODE_1: MOS_VDBOX_NODE_2;
4235 }
4236 }
4237
4238 if (MOS_VDBOX_NODE_1 == pCmdBuffer->iVdboxNodeIndex)
4239 {
4240 VcsExecFlag = I915_EXEC_BSD | I915_EXEC_BSD_RING1;
4241 }
4242 else if (MOS_VDBOX_NODE_2 == pCmdBuffer->iVdboxNodeIndex)
4243 {
4244 VcsExecFlag = I915_EXEC_BSD | I915_EXEC_BSD_RING2;
4245 }
4246
4247 return VcsExecFlag;
4248 }
4249
4250 //!
4251 //! \brief Submit command buffer
4252 //! \details Submit the command buffer
4253 //! \param PMOS_INTERFACE pOsInterface
4254 //! [in] Pointer to OS interface structure
4255 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
4256 //! [in] Pointer to Command Buffer control structure
4257 //! \param int32_t bNullRendering
4258 //! [in] boolean null rendering
4259 //! \return MOS_STATUS
4260 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
4261 //!
Mos_Specific_SubmitCommandBuffer(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer,int32_t bNullRendering)4262 MOS_STATUS Mos_Specific_SubmitCommandBuffer(
4263 PMOS_INTERFACE pOsInterface,
4264 PMOS_COMMAND_BUFFER pCmdBuffer,
4265 int32_t bNullRendering)
4266 {
4267 MOS_OS_FUNCTION_ENTER;
4268
4269 MOS_OS_CHK_NULL_RETURN(pOsInterface);
4270 MOS_OS_CHK_NULL_RETURN(pCmdBuffer);
4271
4272 if (pOsInterface->apoMosEnabled)
4273 {
4274 return MosInterface::SubmitCommandBuffer(pOsInterface->osStreamState, pCmdBuffer, bNullRendering);
4275 }
4276
4277 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
4278 {
4279 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
4280 MOS_OS_CHK_NULL_RETURN(gpuContext);
4281
4282 #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
4283 GpuCmdResInfoDump::GetInstance(pOsInterface->pOsContext)->Dump(pOsInterface);
4284 GpuCmdResInfoDump::GetInstance(pOsInterface->pOsContext)->ClearCmdResPtrs(pOsInterface);
4285 #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
4286
4287 return (gpuContext->SubmitCommandBuffer(pOsInterface, pCmdBuffer, bNullRendering));
4288 }
4289 MOS_OS_ASSERTMESSAGE("Not support this path");
4290 return MOS_STATUS_UNIMPLEMENTED;
4291 }
4292
4293 //!
4294 //! \brief Wait and release command buffer
4295 //! \details Wait and release command buffer
4296 //! \param PMOS_INTERFACE pOsInterface
4297 //! [in] Pointer to OS interface structure
4298 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
4299 //! [in] Pointer to Command Buffer control structure
4300 //! \return MOS_STATUS
4301 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
4302 //!
Mos_Specific_WaitAndReleaseCmdBuffer(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer)4303 MOS_STATUS Mos_Specific_WaitAndReleaseCmdBuffer(
4304 PMOS_INTERFACE pOsInterface,
4305 PMOS_COMMAND_BUFFER pCmdBuffer)
4306 {
4307 MOS_OS_CHK_NULL_RETURN(pOsInterface);
4308 MOS_OS_CHK_NULL_RETURN(pCmdBuffer);
4309 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
4310 {
4311 auto cmd_bo = pCmdBuffer->OsResource.bo;
4312 MOS_OS_CHK_NULL_RETURN(cmd_bo);
4313
4314 // only wait rendering here, release will covered by gpucontext
4315 mos_bo_wait_rendering(cmd_bo);
4316
4317 return MOS_STATUS_SUCCESS;
4318 }
4319
4320 PMOS_CONTEXT pOsContext;
4321 MOS_STATUS eStatus;
4322
4323 eStatus = MOS_STATUS_SUCCESS;
4324
4325 MOS_OS_CHK_NULL(pOsInterface);
4326 MOS_OS_CHK_NULL(pCmdBuffer);
4327
4328 pOsContext = pOsInterface->pOsContext;
4329 MOS_OS_CHK_NULL(pOsContext);
4330
4331 MOS_OS_CHK_STATUS(pOsContext->pfnWaitAndReleaseCmdBuffer(pOsContext, pCmdBuffer->iCmdIndex));
4332
4333 finish:
4334 return eStatus;
4335 }
4336
4337 //!
4338 //! \brief Get resource gfx address
4339 //! \details Get resource gfx address
4340 //! \param PMOS_INTERFACE pOsInterface
4341 //! [in] Pointer to OS interface structure
4342 //! \param PMOS_RESOURCE pResource
4343 //! [in] Pointer to resource
4344 //! \return uint64_t
4345 //! Return resource gfx address
4346 //!
Mos_Specific_GetResourceGfxAddress(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pResource)4347 uint64_t Mos_Specific_GetResourceGfxAddress(
4348 PMOS_INTERFACE pOsInterface,
4349 PMOS_RESOURCE pResource)
4350 {
4351 MOS_OS_CHK_NULL_RETURN(pOsInterface);
4352 MOS_OS_CHK_NULL_RETURN(pResource);
4353
4354 if (pOsInterface->apoMosEnabled)
4355 {
4356 return MosInterface::GetResourceGfxAddress(pOsInterface->osStreamState, pResource);
4357 }
4358
4359 if (!mos_bo_is_softpin(pResource->bo))
4360 {
4361 mos_bo_set_softpin(pResource->bo);
4362 }
4363 return pResource->bo->offset64;
4364 }
4365
4366 //!
4367 //! \brief Get Clear Color Address
4368 //! \details The clear color address
4369 //! \param PMOS_INTERFACE pOsInterface
4370 //! [in] OS Interface
4371 //! \param PMOS_RESOURCE pResource
4372 //! [in] OS resource structure
4373 //! \return uint64_t
4374 //! The clear color address
4375 //!
Mos_Specific_GetResourceClearAddress(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pResource)4376 uint64_t Mos_Specific_GetResourceClearAddress(
4377 PMOS_INTERFACE pOsInterface,
4378 PMOS_RESOURCE pResource)
4379 {
4380 uint64_t ui64ClearColorAddress = 0;
4381 return ui64ClearColorAddress;
4382 }
4383
4384 //!
4385 //! \brief Resizes the buffer to be used for rendering GPU commands
4386 //! \details return true if succeeded - command buffer will be large enough to hold dwMaxSize
4387 //! return false if failed or invalid parameters
4388 //! \param PMOS_INTERFACE pOsInterface
4389 //! [in] Pointer to OS interface structure
4390 //! \param uint32_t dwRequestedCommandBufferSize
4391 //! [in] requested command buffer size
4392 //! \param uint32_t dwRequestedPatchListSize
4393 //! [in] requested patch list size
4394 //! \return MOS_STATUS
4395 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
4396 //!
Mos_Specific_ResizeCommandBufferAndPatchList(PMOS_INTERFACE pOsInterface,uint32_t dwRequestedCommandBufferSize,uint32_t dwRequestedPatchListSize,uint32_t dwFlags)4397 MOS_STATUS Mos_Specific_ResizeCommandBufferAndPatchList(
4398 PMOS_INTERFACE pOsInterface,
4399 uint32_t dwRequestedCommandBufferSize,
4400 uint32_t dwRequestedPatchListSize,
4401 uint32_t dwFlags)
4402 {
4403 MOS_OS_FUNCTION_ENTER;
4404
4405 MOS_OS_CHK_NULL_RETURN(pOsInterface);
4406
4407 if (pOsInterface->apoMosEnabled)
4408 {
4409 return MosInterface::ResizeCommandBufferAndPatchList(pOsInterface->osStreamState, 0, dwRequestedCommandBufferSize, dwRequestedPatchListSize, dwFlags);
4410 }
4411
4412 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
4413 {
4414 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
4415 MOS_OS_CHK_NULL_RETURN(gpuContext);
4416
4417 return (gpuContext->ResizeCommandBufferAndPatchList(dwRequestedCommandBufferSize, dwRequestedPatchListSize, dwFlags));
4418 }
4419
4420 PMOS_CONTEXT pOsContext;
4421 PMOS_OS_GPU_CONTEXT pOsGpuContext;
4422 PPATCHLOCATIONLIST pNewPatchList;
4423 MOS_STATUS eStatus;
4424
4425 MOS_OS_FUNCTION_ENTER;
4426
4427 //---------------------------------------
4428 MOS_UNUSED(dwFlags);
4429 MOS_OS_ASSERT(pOsInterface);
4430 MOS_OS_ASSERT(pOsInterface->pOsContext);
4431 //---------------------------------------
4432
4433 eStatus = MOS_STATUS_SUCCESS;
4434
4435 pOsContext = pOsInterface->pOsContext;
4436 pOsGpuContext = &(pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal]);
4437
4438 // uiCommandBufferSize is used for allocate command buffer and submit command buffer, in this moment, command buffer has not allocated yet.
4439 // Linux KMD requires command buffer size align to 8 bytes, or it will not execute the commands.
4440 pOsGpuContext->uiCommandBufferSize = MOS_ALIGN_CEIL(dwRequestedCommandBufferSize, 8);
4441
4442 if (dwRequestedPatchListSize > pOsGpuContext->uiMaxPatchLocationsize)
4443 {
4444 pNewPatchList = (PPATCHLOCATIONLIST)realloc(
4445 pOsGpuContext->pPatchLocationList,
4446 sizeof(PATCHLOCATIONLIST) * dwRequestedPatchListSize);
4447 if (nullptr == pNewPatchList)
4448 {
4449 MOS_OS_ASSERTMESSAGE("pOsGpuContext->pPatchLocationList realloc failed.");
4450 eStatus = MOS_STATUS_NO_SPACE;
4451 goto finish;
4452 }
4453
4454 pOsGpuContext->pPatchLocationList = pNewPatchList;
4455
4456 // now zero the extended portion
4457 MOS_ZeroMemory(
4458 (pOsGpuContext->pPatchLocationList + pOsGpuContext->uiMaxPatchLocationsize),
4459 sizeof(PATCHLOCATIONLIST) * (dwRequestedPatchListSize - pOsGpuContext->uiMaxPatchLocationsize));
4460 pOsGpuContext->uiMaxPatchLocationsize = dwRequestedPatchListSize;
4461 }
4462
4463 finish:
4464 return eStatus;
4465 }
4466
4467 //!
4468 //! \brief Create GPU context
4469 //! \details Create GPU context
4470 //! \param PMOS_INTERFACE pOsInterface
4471 //! [in] Pointer to OS interface structure
4472 //! \param MOS_GPU_CONTEXT GpuContext
4473 //! [in] GPU Context
4474 //! \param MOS_GPU_NODE GpuNode
4475 //! [in] GPU Node
4476 //! \return MOS_STATUS
4477 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
4478 //!
Mos_Specific_CreateGpuContext(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT mosGpuCxt,MOS_GPU_NODE GpuNode,PMOS_GPUCTX_CREATOPTIONS createOption)4479 MOS_STATUS Mos_Specific_CreateGpuContext(
4480 PMOS_INTERFACE pOsInterface,
4481 MOS_GPU_CONTEXT mosGpuCxt,
4482 MOS_GPU_NODE GpuNode,
4483 PMOS_GPUCTX_CREATOPTIONS createOption)
4484 {
4485 MOS_OS_FUNCTION_ENTER;
4486
4487 MOS_OS_CHK_NULL_RETURN(pOsInterface);
4488
4489 if (mosGpuCxt == MOS_GPU_CONTEXT_INVALID_HANDLE)
4490 {
4491 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
4492 return MOS_STATUS_INVALID_PARAMETER;
4493 }
4494
4495 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
4496 {
4497 MOS_OS_CHK_NULL_RETURN(pOsInterface->osContextPtr);
4498
4499 auto pOsContextSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
4500 MOS_OS_CHK_NULL_RETURN(pOsContextSpecific);
4501
4502 auto gpuContextMgr = pOsContextSpecific->GetGpuContextMgr();
4503 if (!pOsInterface->apoMosEnabled)
4504 {
4505 MOS_OS_CHK_NULL_RETURN(gpuContextMgr);
4506 }
4507
4508 auto cmdBufMgr = pOsContextSpecific->GetCmdBufMgr();
4509 if (!pOsInterface->apoMosEnabled)
4510 {
4511 MOS_OS_CHK_NULL_RETURN(cmdBufMgr);
4512 }
4513
4514 MOS_OS_CHK_NULL_RETURN(createOption);
4515 if (GpuNode == MOS_GPU_NODE_3D && createOption->SSEUValue != 0)
4516 {
4517 struct drm_i915_gem_context_param_sseu sseu;
4518 MOS_ZeroMemory(&sseu, sizeof(sseu));
4519 sseu.engine.engine_class = I915_ENGINE_CLASS_RENDER;
4520 sseu.engine.engine_instance = 0;
4521
4522 if (mos_get_context_param_sseu(pOsInterface->pOsContext->intel_context, &sseu))
4523 {
4524 MOS_OS_ASSERTMESSAGE("Failed to get sseu configuration.");
4525 return MOS_STATUS_UNKNOWN;
4526 };
4527
4528 if (mos_hweight8(pOsInterface->pOsContext->intel_context, sseu.subslice_mask) > createOption->packed.SubSliceCount)
4529 {
4530 sseu.subslice_mask = mos_switch_off_n_bits(pOsInterface->pOsContext->intel_context, sseu.subslice_mask,
4531 mos_hweight8(pOsInterface->pOsContext->intel_context, sseu.subslice_mask)-createOption->packed.SubSliceCount);
4532 }
4533
4534 if (mos_set_context_param_sseu(pOsInterface->pOsContext->intel_context, sseu))
4535 {
4536 MOS_OS_ASSERTMESSAGE("Failed to set sseu configuration.");
4537 return MOS_STATUS_UNKNOWN;
4538 };
4539 }
4540
4541 createOption->gpuNode = GpuNode;
4542 if (pOsInterface->apoMosEnabled)
4543 {
4544 MOS_OS_CHK_NULL_RETURN(pOsInterface->osStreamState);
4545 // Update ctxBasedScheduling from legacy OsInterface
4546 pOsInterface->osStreamState->ctxBasedScheduling = pOsInterface->ctxBasedScheduling;
4547 if (pOsContextSpecific->GetGpuContextHandle(mosGpuCxt) == MOS_GPU_CONTEXT_INVALID_HANDLE)
4548 {
4549 auto osDeviceContext = pOsInterface->osStreamState->osDeviceContext;
4550 MOS_OS_CHK_NULL_RETURN(osDeviceContext);
4551 auto gpuContextMgr = osDeviceContext->GetGpuContextMgr();
4552 MOS_OS_CHK_NULL_RETURN(gpuContextMgr);
4553 auto cmdBufMgr = osDeviceContext->GetCmdBufferMgr();
4554 MOS_OS_CHK_NULL_RETURN(cmdBufMgr);
4555
4556 auto gpuContext = gpuContextMgr->CreateGpuContext(GpuNode, cmdBufMgr);
4557 MOS_OS_CHK_NULL_RETURN(gpuContext);
4558
4559 auto gpuContextSpecific = static_cast<GpuContextSpecificNext *>(gpuContext);
4560 MOS_OS_CHK_NULL_RETURN(gpuContextSpecific);
4561
4562 MOS_OS_CHK_STATUS_RETURN(gpuContextSpecific->Init(gpuContextMgr->GetOsContext(), pOsInterface->osStreamState, createOption));
4563 gpuContextSpecific->SetGpuContext(mosGpuCxt);
4564
4565 pOsContextSpecific->SetGpuContextHandle(mosGpuCxt, gpuContextSpecific->GetGpuContextHandle());
4566 }
4567
4568 return MOS_STATUS_SUCCESS;
4569 }
4570
4571 if (pOsContextSpecific->GetGpuContextHandle(mosGpuCxt) == MOS_GPU_CONTEXT_INVALID_HANDLE)
4572 {
4573 auto gpuContext = gpuContextMgr->CreateGpuContext(GpuNode, cmdBufMgr, mosGpuCxt);
4574 MOS_OS_CHK_NULL_RETURN(gpuContext);
4575
4576 auto gpuContextSpecific = static_cast<GpuContextSpecific *>(gpuContext);
4577 MOS_OS_CHK_NULL_RETURN(gpuContextSpecific);
4578
4579 MOS_OS_CHK_STATUS_RETURN(gpuContextSpecific->Init(gpuContextMgr->GetOsContext(), pOsInterface, GpuNode, createOption));
4580
4581 pOsContextSpecific->SetGpuContextHandle(mosGpuCxt, gpuContextSpecific->GetGpuContextHandle());
4582 }
4583
4584 return MOS_STATUS_SUCCESS;
4585 }
4586
4587 MOS_UNUSED(pOsInterface);
4588 MOS_UNUSED(mosGpuCxt);
4589 MOS_UNUSED(GpuNode);
4590 MOS_UNUSED(createOption);
4591 return MOS_STATUS_SUCCESS;
4592 }
4593
4594 GPU_CONTEXT_HANDLE
Mos_Specific_CreateGpuComputeContext(MOS_INTERFACE * osInterface,MOS_GPU_CONTEXT contextName,MOS_GPUCTX_CREATOPTIONS * createOption)4595 Mos_Specific_CreateGpuComputeContext(MOS_INTERFACE *osInterface,
4596 MOS_GPU_CONTEXT contextName,
4597 MOS_GPUCTX_CREATOPTIONS *createOption)
4598 {
4599 MOS_OS_FUNCTION_ENTER;
4600 MOS_OS_CHK_NULL_RETURN(osInterface);
4601
4602 if (MOS_GPU_CONTEXT_CM_COMPUTE != contextName
4603 && MOS_GPU_CONTEXT_COMPUTE != contextName)
4604 {
4605 MOS_OS_ASSERTMESSAGE("Invalid input parameter contextName.");
4606 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4607 }
4608
4609 if (osInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
4610 {
4611 if (nullptr == createOption)
4612 {
4613 MOS_OS_ASSERTMESSAGE("Invalid pointer (nullptr).");
4614 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4615 }
4616
4617 if (osInterface->apoMosEnabled)
4618 {
4619 if (nullptr == osInterface->osStreamState)
4620 {
4621 MOS_OS_ASSERTMESSAGE("Invalid pointer (nullptr).");
4622 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4623 }
4624
4625 // Update ctxBasedScheduling from legacy OsInterface
4626 osInterface->osStreamState->ctxBasedScheduling
4627 = osInterface->ctxBasedScheduling;
4628
4629 // Only wrapper will contain re-creation check based on stream Index and MOS_GPU_CONTEXT
4630 createOption->gpuNode = MOS_GPU_NODE_COMPUTE;
4631 GPU_CONTEXT_HANDLE context_handle = MOS_GPU_CONTEXT_INVALID_HANDLE;
4632 MOS_STATUS status
4633 = MosInterface::CreateGpuContext(osInterface->osStreamState,
4634 *createOption, context_handle);
4635 if (MOS_FAILED(status))
4636 {
4637 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4638 }
4639
4640 auto os_device_context = osInterface->osStreamState->osDeviceContext;
4641 auto gpu_context_mgr = os_device_context->GetGpuContextMgr();
4642 if (nullptr == gpu_context_mgr)
4643 {
4644 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4645 }
4646 GpuContextNext *context_next
4647 = gpu_context_mgr->GetGpuContext(context_handle);
4648 auto context_specific_next
4649 = static_cast<GpuContextSpecificNext*>(context_next);
4650 if (nullptr == context_specific_next)
4651 {
4652 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4653 }
4654 context_specific_next->SetGpuContext(contextName);
4655 return context_handle;
4656 }
4657 else
4658 {
4659 auto os_context_specific
4660 = static_cast<OsContextSpecific*>(osInterface->osContextPtr);
4661 if (nullptr == os_context_specific)
4662 {
4663 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4664 }
4665 auto gpu_context_mgr = os_context_specific->GetGpuContextMgr();
4666 if (nullptr == gpu_context_mgr)
4667 {
4668 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4669 }
4670 auto cmd_buffer_mgr = os_context_specific->GetCmdBufMgr();
4671 if (nullptr == cmd_buffer_mgr)
4672 {
4673 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4674 }
4675
4676 GpuContext *gpu_context
4677 = gpu_context_mgr->CreateGpuContext(MOS_GPU_NODE_COMPUTE,
4678 cmd_buffer_mgr,
4679 contextName);
4680 auto *context_specific = static_cast<GpuContextSpecific*>(gpu_context);
4681 if (nullptr == context_specific)
4682 {
4683 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4684 }
4685 MOS_STATUS status
4686 = context_specific->Init(gpu_context_mgr->GetOsContext(),
4687 osInterface, MOS_GPU_NODE_COMPUTE,
4688 createOption);
4689 if (MOS_STATUS_SUCCESS != status)
4690 {
4691 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4692 }
4693 return context_specific->GetGpuContextHandle();
4694 }
4695 }
4696 return MOS_GPU_CONTEXT_INVALID_HANDLE;
4697 }
4698
4699 //!
4700 //! \brief Destroy GPU context
4701 //! \details Destroy GPU context
4702 //! [in] Pointer to OS interface structure
4703 //! \param MOS_GPU_CONTEXT GpuContext
4704 //! [in] GPU Context
4705 //! \return MOS_STATUS
4706 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
4707 //!
Mos_Specific_DestroyGpuContext(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT mosGpuCxt)4708 MOS_STATUS Mos_Specific_DestroyGpuContext(
4709 PMOS_INTERFACE pOsInterface,
4710 MOS_GPU_CONTEXT mosGpuCxt)
4711 {
4712 MOS_OS_FUNCTION_ENTER;
4713
4714 MOS_OS_CHK_NULL_RETURN(pOsInterface);
4715
4716 if (mosGpuCxt == MOS_GPU_CONTEXT_INVALID_HANDLE)
4717 {
4718 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
4719 return MOS_STATUS_INVALID_PARAMETER;
4720 }
4721
4722 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
4723 {
4724 MOS_OS_CHK_NULL_RETURN(pOsInterface->osContextPtr);
4725
4726 OsContextSpecific *pOsContextSpecific = static_cast<OsContextSpecific *>(pOsInterface->osContextPtr);
4727 MOS_OS_CHK_NULL_RETURN(pOsContextSpecific);
4728
4729 GPU_CONTEXT_HANDLE gpuContextHandle = pOsContextSpecific->GetGpuContextHandle(mosGpuCxt);
4730
4731 if (pOsInterface->apoMosEnabled)
4732 {
4733 return MosInterface::DestroyGpuContext(pOsInterface->osStreamState, gpuContextHandle);
4734 }
4735
4736 GpuContextMgr *gpuContextMgr = pOsContextSpecific->GetGpuContextMgr();
4737 MOS_OS_CHK_NULL_RETURN(gpuContextMgr);
4738 GpuContext *gpuContext = gpuContextMgr->GetGpuContext(gpuContextHandle);
4739 MOS_OS_CHK_NULL_RETURN(gpuContext);
4740
4741 gpuContextMgr->DestroyGpuContext(gpuContext);
4742 return MOS_STATUS_SUCCESS;
4743 }
4744
4745 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
4746 MOS_UNUSED(pOsInterface);
4747 MOS_UNUSED(mosGpuCxt);
4748 return eStatus;
4749 }
4750
4751 //!
4752 //! \brief Get GPU context Manager
4753 //! \param PMOS_INTERFACE pOsInterface
4754 //! [in] Pointer to OS Interface
4755 //! \return GpuContextMgr
4756 //! GPU context Manager got from Os interface
4757 //!
Mos_Specific_GetGpuContextMgr(PMOS_INTERFACE pOsInterface)4758 GpuContextMgr *Mos_Specific_GetGpuContextMgr(
4759 PMOS_INTERFACE pOsInterface)
4760 {
4761 MOS_OS_FUNCTION_ENTER;
4762
4763 if (pOsInterface && pOsInterface->osContextPtr)
4764 {
4765 auto pOsContextSpecific = static_cast<OsContextSpecific *>(pOsInterface->osContextPtr);
4766 return pOsContextSpecific->GetGpuContextMgr();
4767 }
4768 else
4769 {
4770 return nullptr;
4771 }
4772 }
4773
4774 //!
4775 //! \brief Destroy GPU context by handle
4776 //! \details Destroy GPU context by handle for legacy
4777 //! \param PMOS_INTERFACE pOsInterface
4778 //! [in] Pointer to OS interface structure
4779 //! \param GPU_CONTEXT_HANDLE gpuContextHandle
4780 //! [in] GPU Context handle
4781 //! \return MOS_STATUS
4782 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
4783 //!
Mos_Specific_DestroyGpuContextByHandle(PMOS_INTERFACE pOsInterface,GPU_CONTEXT_HANDLE gpuContextHandle)4784 MOS_STATUS Mos_Specific_DestroyGpuContextByHandle(
4785 PMOS_INTERFACE pOsInterface,
4786 GPU_CONTEXT_HANDLE gpuContextHandle)
4787 {
4788 if (Mos_Solo_IsEnabled(nullptr)) return MOS_STATUS_SUCCESS;
4789 if (pOsInterface && pOsInterface->apoMosEnabled)
4790 {
4791 return MosInterface::DestroyGpuContext(pOsInterface->osStreamState, gpuContextHandle);
4792 }
4793
4794 auto gpuContextMgr = Mos_Specific_GetGpuContextMgr(pOsInterface);
4795
4796 if (gpuContextMgr == nullptr)
4797 {
4798 //No need to destory GPU context when adv_gpucontext not enabled in Os context
4799 MOS_OS_NORMALMESSAGE("There is no Gpu context manager, adv gpu context not enabled, no need to destory GPU contexts.");
4800 return MOS_STATUS_NULL_POINTER;
4801 }
4802 else
4803 {
4804 auto gpuContext = gpuContextMgr->GetGpuContext(gpuContextHandle);
4805 if (gpuContext != nullptr)
4806 {
4807 gpuContextMgr->DestroyGpuContext(gpuContext);
4808 }
4809 else
4810 {
4811 MOS_OS_ASSERTMESSAGE("Not found gpu Context to destory, something must be wrong");
4812 return MOS_STATUS_NULL_POINTER;
4813 }
4814 }
4815 return MOS_STATUS_SUCCESS;
4816 }
4817
4818 //!
4819 //! \brief Destroy Compute GPU context
4820 //! \details Destroy Compute GPU context
4821 //! [in] Pointer to OS interface structure
4822 //! \param GPU_CONTEXT_HANDLE gpuContextHandle
4823 //! [in] GPU Context handle
4824 //! \return MOS_STATUS
4825 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
4826 //!
Mos_Specific_DestroyGpuComputeContext(PMOS_INTERFACE osInterface,GPU_CONTEXT_HANDLE gpuContextHandle)4827 MOS_STATUS Mos_Specific_DestroyGpuComputeContext(
4828 PMOS_INTERFACE osInterface,
4829 GPU_CONTEXT_HANDLE gpuContextHandle)
4830 {
4831 MOS_OS_FUNCTION_ENTER;
4832
4833 MOS_OS_CHK_NULL_RETURN(osInterface);
4834 if(MOS_GPU_CONTEXT_INVALID_HANDLE == gpuContextHandle)
4835 {
4836 MOS_OS_ASSERTMESSAGE("Invalid compute gpu context handle.");
4837 return MOS_STATUS_INVALID_HANDLE;
4838 }
4839 if (!osInterface->modularizedGpuCtxEnabled || Mos_Solo_IsEnabled(nullptr))
4840 {
4841 return MOS_STATUS_SUCCESS;
4842 }
4843
4844 OsContextSpecific *pOsContextSpecific = static_cast<OsContextSpecific *>(osInterface->osContextPtr);
4845 MOS_OS_CHK_NULL_RETURN(pOsContextSpecific);
4846
4847 GPU_CONTEXT_HANDLE iGpuContextHandle = pOsContextSpecific->GetGpuContextHandle(MOS_GPU_CONTEXT_CM_COMPUTE);
4848 if(iGpuContextHandle == gpuContextHandle)
4849 {
4850 MOS_OS_ASSERTMESSAGE("It will be destroyed in osInterface destroy.");
4851 return MOS_STATUS_SUCCESS;
4852 }
4853
4854 iGpuContextHandle = pOsContextSpecific->GetGpuContextHandle(MOS_GPU_CONTEXT_COMPUTE);
4855 if(iGpuContextHandle == gpuContextHandle)
4856 {
4857 MOS_OS_ASSERTMESSAGE("It will be destroyed in osInterface destroy.");
4858 return MOS_STATUS_SUCCESS;
4859 }
4860
4861 if (osInterface->apoMosEnabled)
4862 {
4863 auto gpuContext = MosInterface::GetGpuContext(osInterface->osStreamState, gpuContextHandle);
4864 MOS_OS_CHK_NULL_RETURN(gpuContext);
4865
4866 MOS_GPU_CONTEXT gpuContextName = gpuContext->GetCpuContextID();
4867 if(gpuContextName != MOS_GPU_CONTEXT_CM_COMPUTE && gpuContextName != MOS_GPU_CONTEXT_COMPUTE)
4868 {
4869 MOS_OS_ASSERTMESSAGE("It is not compute gpu context and it will be destroyed in osInterface destroy.");
4870 return MOS_STATUS_SUCCESS;
4871 }
4872 return MosInterface::DestroyGpuContext(osInterface->osStreamState, gpuContextHandle);
4873 }
4874
4875 GpuContextMgr *gpuContextMgr = pOsContextSpecific->GetGpuContextMgr();
4876 MOS_OS_CHK_NULL_RETURN(gpuContextMgr);
4877 GpuContext *gpuContext = gpuContextMgr->GetGpuContext(gpuContextHandle);
4878 MOS_OS_CHK_NULL_RETURN(gpuContext);
4879
4880 MOS_GPU_CONTEXT gpuContextName = gpuContext->GetCpuContextID();
4881 if(gpuContextName != MOS_GPU_CONTEXT_CM_COMPUTE && gpuContextName != MOS_GPU_CONTEXT_COMPUTE)
4882 {
4883 MOS_OS_ASSERTMESSAGE("It is not compute gpu context and it will be destroyed in osInterface destroy.");
4884 return MOS_STATUS_SUCCESS;
4885 }
4886
4887 gpuContextMgr->DestroyGpuContext(gpuContext);
4888 return MOS_STATUS_SUCCESS;
4889 }
4890
4891 //!
4892 //! \brief Sets the perf tag
4893 //! \details Sets the perf tag
4894 //! \param PMOS_INTERFACE pOsInterface
4895 //! [in] Pointer to OS interface structure
4896 //! \param uint32_t PerfTag
4897 //! [in] Perf tag
4898 //! \return void
4899 //!
Mos_Specific_SetPerfTag(PMOS_INTERFACE pOsInterface,uint32_t PerfTag)4900 void Mos_Specific_SetPerfTag(
4901 PMOS_INTERFACE pOsInterface,
4902 uint32_t PerfTag)
4903 {
4904 uint32_t ComponentTag;
4905
4906 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface);
4907
4908 if (pOsInterface->apoMosEnabled)
4909 {
4910 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface->osStreamState);
4911 pOsInterface->osStreamState->component = pOsInterface->Component;
4912 return MosInterface::SetPerfTag(pOsInterface->osStreamState, PerfTag);
4913 }
4914
4915 PMOS_CONTEXT pOsContext =(PMOS_CONTEXT)pOsInterface->pOsContext;
4916
4917 if(pOsContext)
4918 {
4919 switch (pOsInterface->Component)
4920 {
4921 case COMPONENT_VPreP:
4922 case COMPONENT_VPCommon:
4923 ComponentTag = PERFTAG_VPREP;
4924 break;
4925
4926 case COMPONENT_LibVA:
4927 ComponentTag = PERFTAG_LIBVA;
4928 break;
4929
4930 case COMPONENT_CM:
4931 ComponentTag = PERFTAG_CM;
4932 break;
4933
4934 case COMPONENT_Decode:
4935 ComponentTag = PERFTAG_DECODE;
4936 break;
4937
4938 case COMPONENT_Encode:
4939 ComponentTag = PERFTAG_ENCODE;
4940 break;
4941
4942 default:
4943 ComponentTag = 0xF000 & pOsContext->GetDmaBufID(pOsContext);
4944 break;
4945 }
4946
4947 pOsContext->SetDmaBufID(pOsContext, ComponentTag | (PerfTag&0x0fff));
4948 }
4949
4950 }
4951
4952 //!
4953 //! \brief Resets the perf tag
4954 //! \details Resets the perf tag
4955 //! \param PMOS_INTERFACE pOsInterface
4956 //! [in] Pointer to OS interface structure
4957 //! \return void
4958 //!
Mos_Specific_ResetPerfBufferID(PMOS_INTERFACE pOsInterface)4959 void Mos_Specific_ResetPerfBufferID(
4960 PMOS_INTERFACE pOsInterface)
4961 {
4962 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface);
4963
4964 if (pOsInterface->apoMosEnabled)
4965 {
4966 return MosInterface::ResetPerfBufferID(pOsInterface->osStreamState);
4967 }
4968
4969 PMOS_CONTEXT pOsContext = (PMOS_CONTEXT)pOsInterface->pOsContext;
4970 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsContext);
4971 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsContext->pPerfData);
4972 pOsContext->pPerfData->bufferID = 0;
4973 return;
4974 }
4975
4976 //!
4977 //! \brief Increment the perf tag for buffer ID
4978 //! \details Increment the perf tag for buffer ID
4979 //! \param PMOS_INTERFACE pOsInterface
4980 //! [in] Pointer to OS interface structure
4981 //! \return void
4982 //!
Mos_Specific_IncPerfBufferID(PMOS_INTERFACE pOsInterface)4983 void Mos_Specific_IncPerfBufferID(
4984 PMOS_INTERFACE pOsInterface)
4985 {
4986 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface);
4987
4988 if (pOsInterface->apoMosEnabled)
4989 {
4990 return MosInterface::IncPerfBufferID(pOsInterface->osStreamState);
4991 }
4992
4993 PMOS_CONTEXT pOsContext = (PMOS_CONTEXT)pOsInterface->pOsContext;
4994
4995 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsContext);
4996 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsContext->pPerfData);
4997
4998 pOsContext->pPerfData->bufferID++;
4999 return;
5000 }
5001
5002 //!
5003 //! \brief Increment the perf tag for Frame ID
5004 //! \details Increment the perf tag for frame ID
5005 //! \param PMOS_INTERFACE pOsInterface
5006 //! [in] Pointer to OS interface structure
5007 //! \return void
5008 //!
Mos_Specific_IncPerfFrameID(PMOS_INTERFACE pOsInterface)5009 void Mos_Specific_IncPerfFrameID(
5010 PMOS_INTERFACE pOsInterface)
5011 {
5012 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface);
5013
5014 if (pOsInterface->apoMosEnabled)
5015 {
5016 return MosInterface::IncPerfFrameID(pOsInterface->osStreamState);
5017 }
5018
5019 PMOS_CONTEXT pOsContext = (PMOS_CONTEXT)pOsInterface->pOsContext;
5020
5021 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsContext);
5022 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsContext->pPerfData);
5023
5024 pOsContext->pPerfData->frameID++;
5025
5026 }
5027
5028 //!
5029 //! \brief Gets the perf tag
5030 //! \details Gets the perf tag
5031 //! \param PMOS_INTERFACE pOsInterface
5032 //! [in] Pointer to OS interface structure
5033 //! \return uint32_t
5034 //! Return perf tag
5035 //!
Mos_Specific_GetPerfTag(PMOS_INTERFACE pOsInterface)5036 uint32_t Mos_Specific_GetPerfTag(
5037 PMOS_INTERFACE pOsInterface)
5038 {
5039 uint32_t perfTag;
5040
5041 if (pOsInterface == nullptr)
5042 {
5043 MOS_OS_ASSERTMESSAGE("pOsInterface invalid nullptr");
5044 return 0;
5045 }
5046
5047 if (pOsInterface->apoMosEnabled)
5048 {
5049 return MosInterface::GetPerfTag(pOsInterface->osStreamState);
5050 }
5051
5052 PMOS_CONTEXT osContext = (PMOS_CONTEXT)pOsInterface->pOsContext;
5053
5054 if (osContext == nullptr)
5055 {
5056 return 0;
5057 }
5058
5059 perfTag = *(uint32_t *)(osContext->pPerfData);
5060 return perfTag;
5061 }
5062
5063 //!
5064 //! \brief Set Hybrid Kernel ID
5065 //! \details Set Hybrid Kernel ID
5066 //! \param PMOS_INTERFACE pOsInterface
5067 //! [in] OS Interface
5068 //! \param uint32_t KernelID
5069 //! [in] Hybrid Decoder Kernel ID
5070 //! \return void
5071 //!
Mos_Specific_SetPerfHybridKernelID(PMOS_INTERFACE pOsInterface,uint32_t KernelID)5072 void Mos_Specific_SetPerfHybridKernelID(
5073 PMOS_INTERFACE pOsInterface,
5074 uint32_t KernelID)
5075 {
5076 PMOS_CONTEXT pOsContext;
5077
5078 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface);
5079
5080 if (pOsInterface->apoMosEnabled)
5081 {
5082 return MosInterface::SetPerfHybridKernelID(pOsInterface->osStreamState, KernelID);
5083 }
5084
5085 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface->pOsContext);
5086
5087 pOsContext = (PMOS_CONTEXT)pOsInterface->pOsContext;
5088 pOsContext->SetPerfHybridKernelID(pOsContext,KernelID);
5089 }
5090
5091 //!
5092 //! \brief Check if Perf Tag is already set
5093 //! \details Check if Perf Tag is already set
5094 //! \param PMOS_INTERFACE pOsInterface
5095 //! [in] OS Interface
5096 //! \return int32_t
5097 //!
Mos_Specific_IsPerfTagSet(PMOS_INTERFACE pOsInterface)5098 int32_t Mos_Specific_IsPerfTagSet(
5099 PMOS_INTERFACE pOsInterface)
5100 {
5101 uint32_t ComponentTag;
5102 int32_t bRet = false;
5103 PMOS_CONTEXT pOsContext;
5104
5105 if(pOsInterface == nullptr)
5106 {
5107 MOS_OS_ASSERTMESSAGE("pOsInterface invalid nullptr");
5108 return bRet;
5109 }
5110
5111 if (pOsInterface->apoMosEnabled)
5112 {
5113 return MosInterface::IsPerfTagSet(pOsInterface->osStreamState);
5114 }
5115
5116 MOS_OS_ASSERT(pOsInterface->pOsContext);
5117
5118 pOsContext = (pOsInterface) ? (PMOS_CONTEXT)pOsInterface->pOsContext : nullptr;
5119 bRet = false;
5120
5121 if (pOsContext)
5122 {
5123 ComponentTag = 0xF000 & pOsContext->GetDmaBufID(pOsContext);
5124
5125 switch (ComponentTag)
5126 {
5127 case PERFTAG_ENCODE:
5128 case PERFTAG_DECODE:
5129 bRet = true;
5130 break;
5131
5132 default:
5133 bRet = false;
5134 break;
5135 }
5136 }
5137
5138 return bRet;
5139 }
5140
5141 //!
5142 //! \brief Check for GPU context valid
5143 //! \details Always returns MOS_STATUS_SUCCESS on Linux.
5144 // This interface is implemented for compatibility.
5145 //! \param PMOS_INTERFACE pOsInterface
5146 //! [in] pointer to Os interface structure
5147 //! \param MOS_GPU_CONTEXT GpuContext
5148 //! [in] Gpu Context
5149 //! \return MOS_STATUS
5150 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
5151 //!
Mos_Specific_IsGpuContextValid(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT GpuContext)5152 MOS_STATUS Mos_Specific_IsGpuContextValid(
5153 PMOS_INTERFACE pOsInterface,
5154 MOS_GPU_CONTEXT GpuContext)
5155 {
5156 MOS_UNUSED(pOsInterface);
5157 MOS_UNUSED(GpuContext);
5158 return MOS_STATUS_SUCCESS;
5159 }
5160
5161 //!
5162 //! \brief Unified OS Resources sync
5163 //! \details Tag based synchronization at the resource level
5164 //! \param PMOS_INTERFACE pOsInterface
5165 //! [in] Pointer to OS Interface
5166 //! \param PMOS_RESOURCE pOsResource
5167 //! [in] Pointer to OS Resource
5168 //! \param MOS_GPU_CONTEXT requestorGPUCtx
5169 //! [in] GPU Context
5170 //! \param int32_t bWriteOperation
5171 //! [in] true if write operation
5172 //! \return void
5173 //!
Mos_Specific_SyncOnResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,MOS_GPU_CONTEXT requestorGPUCtx,int32_t bWriteOperation)5174 void Mos_Specific_SyncOnResource(
5175 PMOS_INTERFACE pOsInterface,
5176 PMOS_RESOURCE pOsResource,
5177 MOS_GPU_CONTEXT requestorGPUCtx,
5178 int32_t bWriteOperation)
5179 {
5180 MOS_UNUSED(pOsInterface);
5181 MOS_UNUSED(pOsResource);
5182 MOS_UNUSED(requestorGPUCtx);
5183 MOS_UNUSED(bWriteOperation);
5184 }
5185
5186 //!
5187 //! \brief Synchronize GPU context
5188 //! \details Synchronize GPU context
5189 //! \param PMOS_INTERFACE pOsInterface
5190 //! [in] OS Interface
5191 //! \param MOS_GPU_CONTEXT busyGPUCtx
5192 //! [in] Busy context id being requested to sync with
5193 //! \param MOS_GPU_CONTEXT requestorGPUCtx
5194 //! [in] Requestor context id
5195 //! \return void
5196 //!
Mos_Specific_SyncGpuContext(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT busyGPUCtx,MOS_GPU_CONTEXT requestorGPUCtx)5197 void Mos_Specific_SyncGpuContext(
5198 PMOS_INTERFACE pOsInterface,
5199 MOS_GPU_CONTEXT busyGPUCtx,
5200 MOS_GPU_CONTEXT requestorGPUCtx)
5201 {
5202 MOS_UNUSED(pOsInterface);
5203 MOS_UNUSED(busyGPUCtx);
5204 MOS_UNUSED(requestorGPUCtx);
5205 }
5206
5207 //!
5208 //! \brief Checks for HW enabled
5209 //! \details Checks for HW enabled
5210 //! \param PMOS_INTERFACE pOsInterface
5211 //! [in] pointer to Os interface structure
5212 //! \return int32_t
5213 //! Returns true id HW enabled if CP mode
5214 //!
Mos_Specific_IsNullHWEnabled(PMOS_INTERFACE pOsInterface)5215 int32_t Mos_Specific_IsNullHWEnabled(
5216 PMOS_INTERFACE pOsInterface)
5217 {
5218 MOS_UNUSED(pOsInterface);
5219 return false;
5220 }
5221
5222 //!
5223 //! \brief Get GPU status buffer
5224 //! \details Gets the status buffer for the resource
5225 //! \param PMOS_INTERFACE pOsInterface
5226 //! [in] Pointer to OS Interface
5227 //! \param PMOS_RESOURCE pOsResource
5228 //! [out] Pointer to OS Resource
5229 //! \return MOS_STATUS
5230 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
5231 //!
Mos_Specific_GetGpuStatusBufferResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE & pOsResource)5232 MOS_STATUS Mos_Specific_GetGpuStatusBufferResource(
5233 PMOS_INTERFACE pOsInterface,
5234 PMOS_RESOURCE &pOsResource)
5235 {
5236 MOS_OS_FUNCTION_ENTER;
5237
5238 MOS_OS_CHK_NULL_RETURN(pOsInterface);
5239
5240 if (pOsInterface->apoMosEnabled)
5241 {
5242 return MosInterface::GetGpuStatusBufferResource(pOsInterface->osStreamState, pOsResource, pOsInterface->osStreamState->currentGpuContextHandle);
5243 }
5244
5245 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
5246 {
5247 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
5248 MOS_OS_CHK_NULL_RETURN(gpuContext);
5249
5250 auto resource = gpuContext->GetStatusBufferResource();
5251 MOS_OS_CHK_NULL_RETURN(resource);
5252
5253 pOsResource = gpuContext->GetStatusBufferMosResource();
5254 MOS_OS_CHK_NULL_RETURN(pOsResource);
5255 MOS_ZeroMemory(pOsResource, sizeof(MOS_RESOURCE));
5256
5257 MOS_OS_CHK_STATUS_RETURN(resource->ConvertToMosResource(pOsResource));
5258
5259 return MOS_STATUS_SUCCESS;
5260 }
5261
5262 PMOS_CONTEXT pOsContext;
5263
5264 MOS_OS_ASSERT(pOsInterface);
5265 MOS_OS_ASSERT(pOsInterface->pOsContext);
5266
5267 pOsContext = pOsInterface->pOsContext;
5268
5269 pOsResource = pOsContext->pGPUStatusBuffer;
5270 return MOS_STATUS_SUCCESS;
5271 }
5272
5273 //!
5274 //! \brief Get GPU status tag offset
5275 //! \details Gets the status tag offset
5276 //! \param PMOS_INTERFACE pOsInterface
5277 //! [in] Pointer to OS Interface
5278 //! \param MOS_GPU_CONTEXT GpuContext
5279 //! [in] GPU Context
5280 //! \return uint32_t
5281 //! Returns the tag offset
5282 //!
Mos_Specific_GetGpuStatusTagOffset(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT GpuContext)5283 uint32_t Mos_Specific_GetGpuStatusTagOffset(
5284 PMOS_INTERFACE pOsInterface,
5285 MOS_GPU_CONTEXT GpuContext)
5286 {
5287 MOS_OS_FUNCTION_ENTER;
5288
5289 MOS_OS_CHK_NULL_RETURN(pOsInterface);
5290
5291 uint32_t offset = 0;
5292
5293 if (pOsInterface->apoMosEnabled)
5294 {
5295 // always 0 in apo
5296 return 0;
5297 }
5298 // A gobal status buffer for all GPU contexts is no longer used when modulized GPU context enabled,
5299 // replace with separate buffer corresponding to each GPU context and the offset will be 0
5300 if (!pOsInterface->modularizedGpuCtxEnabled || Mos_Solo_IsEnabled(nullptr))
5301 {
5302 offset = sizeof(MOS_GPU_STATUS_DATA) * GpuContext;
5303 }
5304
5305 return offset;
5306 }
5307
5308 //!
5309 //! \brief Get GPU status tag
5310 //! \details Gets the status tag
5311 //! \param PMOS_INTERFACE pOsInterface
5312 //! [in] Pointer to OS Interface
5313 //! \param MOS_GPU_CONTEXT GpuContext
5314 //! [in] GPU Context
5315 //! \return uint32_t
5316 //! Returns the tag
5317 //!
Mos_Specific_GetGpuStatusTag(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT mosGpuCtx)5318 uint32_t Mos_Specific_GetGpuStatusTag(
5319 PMOS_INTERFACE pOsInterface,
5320 MOS_GPU_CONTEXT mosGpuCtx)
5321 {
5322 MOS_OS_FUNCTION_ENTER;
5323
5324 MOS_OS_ASSERT(pOsInterface);
5325
5326 if (mosGpuCtx == MOS_GPU_CONTEXT_INVALID_HANDLE)
5327 {
5328 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
5329 return -1;
5330 }
5331
5332 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
5333 {
5334 if (pOsInterface->osContextPtr == nullptr)
5335 {
5336 MOS_OS_ASSERTMESSAGE("invalid input parameters!");
5337 return 0;
5338 }
5339
5340 auto osCxtSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
5341
5342 auto handle = osCxtSpecific->GetGpuContextHandle(mosGpuCtx);
5343
5344 if (pOsInterface->apoMosEnabled)
5345 {
5346 return MosInterface::GetGpuStatusTag(pOsInterface->osStreamState, handle);
5347 }
5348
5349 auto gpuContext = Linux_GetGpuContext(pOsInterface, handle);
5350 MOS_OS_CHK_NULL_RETURN(gpuContext);
5351
5352 return gpuContext->GetGpuStatusTag();
5353 }
5354
5355 PMOS_CONTEXT pOsContext;
5356
5357 MOS_OS_ASSERT(pOsInterface->pOsContext);
5358 //------------------------------------
5359
5360 pOsContext = pOsInterface->pOsContext;
5361
5362 return pOsContext->pfnGetGpuCtxBufferTag(pOsContext, mosGpuCtx);
5363 }
5364
5365 //!
5366 //! \brief Increment GPU status tag
5367 //! \details Increment the status tag
5368 //! \param PMOS_INTERFACE pOsInterface
5369 //! [in] Pointer to OS Interface
5370 //! \param MOS_GPU_CONTEXT GpuContext
5371 //! [in] GPU Context
5372 //! \return void
5373 //!
Mos_Specific_IncrementGpuStatusTag(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT mosGpuCtx)5374 void Mos_Specific_IncrementGpuStatusTag(
5375 PMOS_INTERFACE pOsInterface,
5376 MOS_GPU_CONTEXT mosGpuCtx)
5377 {
5378 MOS_OS_FUNCTION_ENTER;
5379
5380 MOS_OS_ASSERT(pOsInterface);
5381
5382 if (mosGpuCtx == MOS_GPU_CONTEXT_INVALID_HANDLE)
5383 {
5384 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
5385 return;
5386 }
5387
5388 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
5389 {
5390 if (pOsInterface->osContextPtr == nullptr)
5391 {
5392 MOS_OS_ASSERTMESSAGE("invalid input parameters!");
5393 return;
5394 }
5395
5396 auto osCxtSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
5397
5398 auto handle = osCxtSpecific->GetGpuContextHandle(mosGpuCtx);
5399
5400 if (pOsInterface->apoMosEnabled)
5401 {
5402 MosInterface::IncrementGpuStatusTag(pOsInterface->osStreamState, handle);
5403 return;
5404 }
5405
5406 auto gpuContext = Linux_GetGpuContext(pOsInterface, handle);
5407
5408 if (gpuContext)
5409 {
5410 gpuContext->IncrementGpuStatusTag();
5411 }
5412 else
5413 {
5414 MOS_OS_ASSERTMESSAGE("Cannot get valid Gpu context!");
5415 }
5416 }
5417
5418 PMOS_CONTEXT pOsContext;
5419
5420 //------------------------------------
5421 MOS_OS_ASSERT(pOsInterface);
5422 MOS_OS_ASSERT(pOsInterface->pOsContext);
5423 //------------------------------------
5424
5425 pOsContext = pOsInterface->pOsContext;
5426
5427 pOsContext->pfnIncGpuCtxBufferTag(pOsContext, mosGpuCtx);
5428 }
5429
5430 //!
5431 //! \brief Get GPU status Sync tag
5432 //! \details This function will return the GPU status tag which is updated when corresponding
5433 //! GPU packet is done. User can use this flag to check if some GPU packet is done.
5434 //! \param PMOS_INTERFACE pOsInterface
5435 //! [in] Pointer to OS Interface
5436 //! \param MOS_GPU_CONTEXT GpuContext
5437 //! [in] GPU Context
5438 //! \return uint32_t
5439 //! Returns the tag
5440 //!
Mos_Specific_GetGpuStatusSyncTag(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT gpuContext)5441 uint32_t Mos_Specific_GetGpuStatusSyncTag(
5442 PMOS_INTERFACE pOsInterface,
5443 MOS_GPU_CONTEXT gpuContext)
5444 {
5445 MOS_OS_FUNCTION_ENTER;
5446 PMOS_CONTEXT pOsContext = nullptr;
5447
5448 if(!pOsInterface || !pOsInterface->pOsContext)
5449 {
5450 MOS_OS_ASSERTMESSAGE("Invalid nullptr");
5451 return 0;
5452 }
5453 pOsContext = pOsInterface->pOsContext;
5454
5455 return pOsContext->GetGPUTag(pOsInterface, gpuContext);
5456 }
5457
5458 //!
5459 //! \brief Sets the resource sync tag
5460 //! \details Dummy implementation on Linux for compatibility.
5461 //! \param PMOS_INTERFACE pOsInterface
5462 //! [in] Pointer to OS Interface
5463 //! \param PMOS_SYNC_PARAMS pParams
5464 //! [in] Pointer to sync params
5465 //! \return void
5466 //!
Mos_Specific_SetResourceSyncTag(PMOS_INTERFACE pOsInterface,PMOS_SYNC_PARAMS pParams)5467 void Mos_Specific_SetResourceSyncTag(
5468 PMOS_INTERFACE pOsInterface,
5469 PMOS_SYNC_PARAMS pParams)
5470 {
5471 MOS_UNUSED(pOsInterface);
5472 MOS_UNUSED(pParams);
5473 return ;
5474 }
5475
5476 //!
5477 //! \brief Perform overlay sync
5478 //! \details Dummy implementation on Linux for compatibility.
5479 //! \param PMOS_INTERFACE pOsInterface
5480 //! [in] Pointer to OS Interface
5481 //! \param PMOS_SYNC_PARAMS pParams
5482 //! [in] Pointer to sync params
5483 //! \return MOS_STATUS
5484 //! Return MOS_STATUS_SUCCESS
5485 //!
Mos_Specific_PerformOverlaySync(PMOS_INTERFACE pOsInterface,PMOS_SYNC_PARAMS pParams)5486 MOS_STATUS Mos_Specific_PerformOverlaySync(
5487 PMOS_INTERFACE pOsInterface,
5488 PMOS_SYNC_PARAMS pParams)
5489 {
5490 MOS_UNUSED(pOsInterface);
5491 MOS_UNUSED(pParams);
5492 return MOS_STATUS_SUCCESS;
5493 }
5494
5495 //!
5496 //! \brief Signal OS Engine
5497 //! \details Dummy implementation on Linux for compatibility.
5498 //! \param PMOS_INTERFACE pOsInterface
5499 //! [in] Pointer to OS Interface
5500 //! \param PMOS_SYNC_PARAMS pParams
5501 //! [in] Pointer to sync params
5502 //! \return MOS_STATUS
5503 //! Return MOS_STATUS_SUCCESS
5504 //!
Mos_Specific_EngineSignal(PMOS_INTERFACE pOsInterface,PMOS_SYNC_PARAMS pParams)5505 MOS_STATUS Mos_Specific_EngineSignal(
5506 PMOS_INTERFACE pOsInterface,
5507 PMOS_SYNC_PARAMS pParams)
5508 {
5509 MOS_UNUSED(pOsInterface);
5510 MOS_UNUSED(pParams);
5511 return MOS_STATUS_SUCCESS;
5512 }
5513
5514 //!
5515 //! \brief Wait on sync
5516 //! \details Dummy implementation on Linux for compatibility.
5517 //! \param PMOS_INTERFACE pOsInterface
5518 //! [in] Pointer to OS Interface
5519 //! \param PMOS_SYNC_PARAMS pParams
5520 //! [in] Pointer to sync params
5521 //! \return MOS_STATUS
5522 //! Return MOS_STATUS_SUCCESS
5523 //!
Mos_Specific_EngineWait(PMOS_INTERFACE pOsInterface,PMOS_SYNC_PARAMS pParams)5524 MOS_STATUS Mos_Specific_EngineWait(
5525 PMOS_INTERFACE pOsInterface,
5526 PMOS_SYNC_PARAMS pParams)
5527 {
5528 MOS_UNUSED(pOsInterface);
5529 MOS_UNUSED(pParams);
5530 return MOS_STATUS_SUCCESS;
5531 }
5532
5533 //!
5534 //! \brief Signal on resource
5535 //! \details Dummy implementation on Linux for compatibility.
5536 //! \param PMOS_INTERFACE pOsInterface
5537 //! [in] Pointer to OS Interface
5538 //! \param PMOS_SYNC_PARAMS pParams
5539 //! [in] Pointer to sync params
5540 //! \return MOS_STATUS
5541 //! Return MOS_STATUS_SUCCESS
5542 //!
Mos_Specific_ResourceSignal(PMOS_INTERFACE pOsInterface,PMOS_SYNC_PARAMS pParams)5543 MOS_STATUS Mos_Specific_ResourceSignal(
5544 PMOS_INTERFACE pOsInterface,
5545 PMOS_SYNC_PARAMS pParams)
5546 {
5547 MOS_UNUSED(pOsInterface);
5548 MOS_UNUSED(pParams);
5549 return MOS_STATUS_SUCCESS;
5550 }
5551
5552 //!
5553 //! \brief Wait on resource
5554 //! \details Dummy implementation on Linux for compatibility.
5555 //! \param PMOS_INTERFACE pOsInterface
5556 //! [in] Pointer to OS Interface
5557 //! \param PMOS_SYNC_PARAMS pParams
5558 //! [in] Pointer to sync params
5559 //! \return MOS_STATUS
5560 //! Return MOS_STATUS_SUCCESS
5561 //!
Mos_Specific_ResourceWait(PMOS_INTERFACE pOsInterface,PMOS_SYNC_PARAMS pParams)5562 MOS_STATUS Mos_Specific_ResourceWait(
5563 PMOS_INTERFACE pOsInterface,
5564 PMOS_SYNC_PARAMS pParams)
5565 {
5566 MOS_UNUSED(pOsInterface);
5567 MOS_UNUSED(pParams);
5568 return MOS_STATUS_SUCCESS;
5569 }
5570
5571 //!
5572 //! \brief Create Sync Resource
5573 //! \details Dummy implementation on Linux for compatibility.
5574 //! \param PMOS_INTERFACE pOsInterface
5575 //! [in] Pointer to OS Interface
5576 //! \param PMOS_RESOURCE pOsResource
5577 //! [in] Pointer to OS resource
5578 //! \return MOS_STATUS
5579 //! Return MOS_STATUS_SUCCESS
5580 //!
Mos_Specific_CreateSyncResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource)5581 MOS_STATUS Mos_Specific_CreateSyncResource(
5582 PMOS_INTERFACE pOsInterface,
5583 PMOS_RESOURCE pOsResource)
5584 {
5585 MOS_UNUSED(pOsInterface);
5586 MOS_UNUSED(pOsResource);
5587 return MOS_STATUS_SUCCESS;
5588 }
5589
5590 //!
5591 //! \brief Destroy Sync resource
5592 //! \details Dummy implementation on Linux for compatibility.
5593 //! \param PMOS_INTERFACE pOsInterface
5594 //! [in] Pointer to OS Interface
5595 //! \param PMOS_RESOURCE pOsResource
5596 //! [in] Pointer to OS resource
5597 //! \return MOS_STATUS
5598 //! Return MOS_STATUS_SUCCESS
5599 //!
Mos_Specific_DestroySyncResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource)5600 MOS_STATUS Mos_Specific_DestroySyncResource(
5601 PMOS_INTERFACE pOsInterface,
5602 PMOS_RESOURCE pOsResource)
5603 {
5604 MOS_UNUSED(pOsInterface);
5605 MOS_UNUSED(pOsResource);
5606 return MOS_STATUS_SUCCESS;
5607 }
5608
5609 //!
5610 //! \brief Initializes the tags for Hybrid Decode multi-threading sync
5611 //! \details Initializes the tags for Hybrid Decode multi-threading sync
5612 //! \param PMOS_INTERFACE pOsInterface
5613 //! [in] OS Interface
5614 //! \param PMOS_RESOURCE pOsResource
5615 //! [in] Pointer to OS resource
5616 //! \param uint8_t ucRenderTargetIndex
5617 //! [in] Index of render target in pSemHandleList for pOsResource
5618 //! \param PMOS_SEMAPHORE *pCurFrmSem
5619 //! [in] List of semaphore handles used for current frame sync
5620 //! \param PMOS_SEMAPHORE *pRefFrmSem
5621 //! [in] List of semaphore handles used for reference frame sync
5622 //! \param PMOS_MUTEX *pFrmMutex
5623 //! [in] List of mutex handles of frame lock mutex
5624 //! \return MOS_STATUS
5625 //!
Mos_Specific_InitializeMultiThreadingSyncTags(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,uint8_t ucRenderTargetIndex,PMOS_SEMAPHORE * pCurFrmSem,PMOS_SEMAPHORE * pRefFrmSem,PMOS_MUTEX * pFrmMutex)5626 MOS_STATUS Mos_Specific_InitializeMultiThreadingSyncTags(
5627 PMOS_INTERFACE pOsInterface,
5628 PMOS_RESOURCE pOsResource,
5629 uint8_t ucRenderTargetIndex,
5630 PMOS_SEMAPHORE *pCurFrmSem,
5631 PMOS_SEMAPHORE *pRefFrmSem,
5632 PMOS_MUTEX *pFrmMutex)
5633 {
5634 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
5635
5636 MOS_OS_CHK_NULL(pOsInterface);
5637 MOS_OS_CHK_NULL(pOsResource);
5638 MOS_OS_CHK_NULL(pCurFrmSem);
5639 MOS_OS_CHK_NULL(pRefFrmSem);
5640
5641 if(*pOsResource->ppReferenceFrameSemaphore == nullptr)
5642 {
5643 *pOsResource->ppReferenceFrameSemaphore = MosUtilities::MosCreateSemaphore(1, 1);
5644 }
5645
5646 if(*pOsResource->ppCurrentFrameSemaphore == nullptr)
5647 {
5648 *pOsResource->ppCurrentFrameSemaphore = MosUtilities::MosCreateSemaphore(1, 1);
5649 }
5650
5651 if((*pOsResource->ppReferenceFrameSemaphore != nullptr) && (*pOsResource->ppCurrentFrameSemaphore != nullptr))
5652 {
5653 pCurFrmSem[ucRenderTargetIndex] = *pOsResource->ppCurrentFrameSemaphore;
5654 pRefFrmSem[ucRenderTargetIndex] = *pOsResource->ppReferenceFrameSemaphore;
5655 pFrmMutex[ucRenderTargetIndex] = nullptr;
5656 }
5657
5658 finish:
5659 return eStatus;
5660 }
5661
5662 //!
5663 //! \brief Wait current frame's semaphore for Hybrid Decode multi-threading sync
5664 //! \details Wait current frame's semaphore for Hybrid Decode multi-threading sync
5665 //! \param PMOS_RESOURCE pOsResource
5666 //! [in] Pointer to OS resource
5667 //! \return MOS_STATUS
5668 //!
Mos_Specific_MultiThreadingWaitCurrentFrame(PMOS_RESOURCE pOsResource)5669 MOS_STATUS Mos_Specific_MultiThreadingWaitCurrentFrame(
5670 PMOS_RESOURCE pOsResource)
5671 {
5672 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
5673
5674 MOS_OS_CHK_NULL(pOsResource);
5675
5676 MOS_OS_CHK_STATUS(MosUtilities::MosWaitSemaphore(*pOsResource->ppCurrentFrameSemaphore, INFINITE));
5677
5678 finish:
5679 return eStatus;
5680 }
5681
5682 //!
5683 //! \brief Post current frame's semaphore for Hybrid Decode multi-threading sync
5684 //! \details Post current frame's semaphore for Hybrid Decode multi-threading sync
5685 //! \param PMOS_RESOURCE pOsResource
5686 //! [in] Pointer to OS resource
5687 //! \return MOS_STATUS
5688 //!
Mos_Specific_MultiThreadingPostCurrentFrame(PMOS_RESOURCE pOsResource)5689 MOS_STATUS Mos_Specific_MultiThreadingPostCurrentFrame(
5690 PMOS_RESOURCE pOsResource)
5691 {
5692 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
5693
5694 MOS_OS_CHK_NULL(pOsResource);
5695
5696 MOS_OS_CHK_STATUS(MosUtilities::MosPostSemaphore(*pOsResource->ppCurrentFrameSemaphore, 1));
5697
5698 finish:
5699 return eStatus;
5700 }
5701
5702 //!
5703 //! \brief Sets hybrid decoder running flag
5704 //! \details Sets hybrid decoder running flag to indicate there is a hybrid decoder
5705 //! is running
5706 //! \param PMOS_INTERFACE pOsInterface
5707 //! [in] OS Interface
5708 //! \param int32_t bFlag
5709 //! [in] hybrid decoder (HEVC or VP9) running flag
5710 //! \return MOS_STATUS
5711 //!
Mos_Specific_SetHybridDecoderRunningFlag(PMOS_INTERFACE pOsInterface,int32_t bFlag)5712 MOS_STATUS Mos_Specific_SetHybridDecoderRunningFlag(
5713 PMOS_INTERFACE pOsInterface,
5714 int32_t bFlag)
5715 {
5716 PMOS_CONTEXT pOsContext;
5717 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
5718
5719 MOS_OS_CHK_NULL(pOsInterface);
5720 MOS_OS_CHK_NULL(pOsInterface->pOsContext);
5721
5722 pOsContext = pOsInterface->pOsContext;
5723 pOsContext->bHybridDecoderRunningFlag = bFlag;
5724
5725 finish:
5726 return eStatus;
5727 }
5728
5729 //!
5730 //! \brief Gets hybrid decoder running flag
5731 //! \details Gets hybrid decoder running flag to decide if hybrid decoder is being used
5732 //! \param PMOS_INTERFACE pOsInterface
5733 //! [in] OS Interface
5734 //! \param int32_t bFlag
5735 //! [in] hybrid decoder (HEVC or VP9) running flag
5736 //! \return MOS_STATUS
5737 //!
Mos_Specific_GetHybridDecoderRunningFlag(PMOS_INTERFACE pOsInterface,int32_t * pFlag)5738 MOS_STATUS Mos_Specific_GetHybridDecoderRunningFlag(
5739 PMOS_INTERFACE pOsInterface,
5740 int32_t *pFlag)
5741 {
5742 PMOS_CONTEXT pOsContext;
5743 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
5744
5745 MOS_OS_CHK_NULL(pFlag);
5746 *pFlag = false;
5747
5748 MOS_OS_CHK_NULL(pOsInterface);
5749 MOS_OS_CHK_NULL(pOsInterface->pOsContext);
5750
5751 pOsContext = pOsInterface->pOsContext;
5752 *pFlag = pOsContext->bHybridDecoderRunningFlag;
5753
5754 finish:
5755 return eStatus;
5756 }
5757
5758 //!
5759 //! \brief Multi thread resource sync method
5760 //! \details Dummy implementation on Linux for compatibility.
5761 //! \param PMOS_INTERFACE pOsInterface
5762 //! [in] OS Interface
5763 //! \param PMOS_RESOURCE pOsResource
5764 //! [in] Pointer to OS resource
5765 //! \return MOS_STATUS
5766 //!
Mos_Specific_MultiThreadResourceSync(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource)5767 MOS_STATUS Mos_Specific_MultiThreadResourceSync(
5768 PMOS_INTERFACE pOsInterface,
5769 PMOS_RESOURCE pOsResource)
5770 {
5771 MOS_UNUSED(pOsInterface);
5772 MOS_UNUSED(pOsResource);
5773 return MOS_STATUS_SUCCESS;
5774 }
5775
5776 //!
5777 //! \brief Registers a complete notification event
5778 //! \details Registers a complete notification event
5779 //! \param PMOS_INTERFACE pOsInterface
5780 //! [in] Pointer to OS Interface
5781 //! \param MOS_GPU_CONTEXT GpuContext
5782 //! [in] GPU Context
5783 //! \return MOS_STATUS
5784 //! Return MOS_STATUS_SUCCESS
5785 //!
Mos_Specific_RegisterBBCompleteNotifyEvent(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT GpuContext)5786 MOS_STATUS Mos_Specific_RegisterBBCompleteNotifyEvent(
5787 PMOS_INTERFACE pOsInterface,
5788 MOS_GPU_CONTEXT GpuContext)
5789 {
5790 MOS_UNUSED(pOsInterface);
5791 MOS_UNUSED(GpuContext);
5792 return MOS_STATUS_SUCCESS;
5793 }
5794
5795 //!
5796 //! \brief Waits on a complete notification event
5797 //! \details Waits on a complete notification event
5798 //! \param PMOS_INTERFACE pOsInterface
5799 //! [in] Pointer to OS Interface
5800 //! \param uint32_t uiTimeOut
5801 //! [in] Time to wait (ms)
5802 //! \return MOS_STATUS
5803 //! Return MOS_STATUS_SUCCESS
5804 //!
Mos_Specific_WaitForBBCompleteNotifyEvent(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT GpuContext,uint32_t uiTimeOut)5805 MOS_STATUS Mos_Specific_WaitForBBCompleteNotifyEvent(
5806 PMOS_INTERFACE pOsInterface,
5807 MOS_GPU_CONTEXT GpuContext,
5808 uint32_t uiTimeOut)
5809 {
5810 MOS_UNUSED(pOsInterface);
5811 MOS_UNUSED(GpuContext);
5812 usleep(1000 * uiTimeOut);
5813
5814 return MOS_STATUS_SUCCESS;
5815 }
5816
Mos_Specific_WaitAllCmdCompletion_Os(PMOS_INTERFACE pOsInterface)5817 MOS_STATUS Mos_Specific_WaitAllCmdCompletion_Os(
5818 PMOS_INTERFACE pOsInterface)
5819 {
5820 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
5821
5822 return eStatus;
5823 }
5824
5825 //!
5826 //! \brief Get interface version
5827 //! \details Get interface version
5828 //!
5829 //! \param PMOS_INTERFACE pOsInterface
5830 //! [in] OS Interface
5831 //!
5832 //! \return uint32_t
5833 //! Read-only OS runtime interface version, it's meaning diff from OS and API
5834 //!
Mos_Specific_GetInterfaceVersion(PMOS_INTERFACE pOsInterface)5835 uint32_t Mos_Specific_GetInterfaceVersion(
5836 PMOS_INTERFACE pOsInterface)
5837 {
5838 MOS_UNUSED(pOsInterface);
5839 return 0;
5840 }
5841
5842 //!
5843 //! \brief Sets the flags to skip the sync on a particular resource
5844 //! \details This is required to avoid updating resource tags/masks for a given resource
5845 //! This way we dont end up putting unnecessary sync points by syncing on this particular resource
5846 //! \param PMOS_ALLOC_GFXRES_PARAMS pAllocParams
5847 //! [in] allocation parameters
5848 //! \return MOS_STATUS
5849 //! Return MOS_STATUS_SUCCESS if success else failure reason
5850 //!
Mos_Specific_SkipResourceSync(PMOS_RESOURCE pOsResource)5851 MOS_STATUS Mos_Specific_SkipResourceSync(
5852 PMOS_RESOURCE pOsResource)
5853 {
5854 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
5855
5856 //---------------------------------------
5857 MOS_OS_CHK_NULL(pOsResource);
5858 //---------------------------------------
5859
5860 mos_bo_set_object_async(pOsResource->bo);
5861
5862 finish:
5863 return eStatus;
5864 }
5865
5866 //!
5867 //! \brief Gets the HW rendering flags
5868 //! \details Gets the HW rendering flags
5869 //! \param PMOS_INTERFACE pOsInterface
5870 //! [in] Pointer to OS Interface
5871 //! \return MOS_NULL_RENDERING_FLAGS
5872 //! Returns the null rendering flags
5873 //!
Mos_Specific_GetNullHWRenderFlags(PMOS_INTERFACE pOsInterface)5874 MOS_NULL_RENDERING_FLAGS Mos_Specific_GetNullHWRenderFlags(
5875 PMOS_INTERFACE pOsInterface)
5876 {
5877 return pOsInterface->NullHWAccelerationEnable;
5878 }
5879
5880 //!
5881 //! \brief Debug hook to note type of surface state or sampler state being
5882 //! used.
5883 //! \details Sets the Command buffer debug info
5884 //! \param PMOS_INTERFACE pOsInterface
5885 //! [in] Pointer to OS Interface
5886 //! \param int32_t bSamplerState
5887 //! [in] Sampler state
5888 //! \param int32_t bSurfaceState
5889 //! [in] Surface state
5890 //! \param uint32_t dwStateIndex
5891 //! [in] State index
5892 //! \param uint32_t dwType
5893 //! [in] dword type
5894 //! \return MOS_STATUS
5895 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
5896 //!
Mos_Specific_SetCmdBufferDebugInfo(PMOS_INTERFACE pOsInterface,int32_t bSamplerState,int32_t bSurfaceState,uint32_t dwStateIndex,uint32_t dwType)5897 MOS_STATUS Mos_Specific_SetCmdBufferDebugInfo(
5898 PMOS_INTERFACE pOsInterface,
5899 int32_t bSamplerState,
5900 int32_t bSurfaceState,
5901 uint32_t dwStateIndex,
5902 uint32_t dwType)
5903 {
5904 MOS_UNUSED(pOsInterface);
5905 MOS_UNUSED(bSamplerState);
5906 MOS_UNUSED(bSurfaceState);
5907 MOS_UNUSED(dwStateIndex);
5908 MOS_UNUSED(dwType);
5909 // stub function. implemented for simulation but not driver.
5910 return MOS_STATUS_SUCCESS;
5911 }
5912
5913 //!
5914 //! \brief Command buffer debug
5915 //! \details Debug hook to get type of surface state or sampler state being
5916 //! used.
5917 //! \param PMOS_INTERFACE pOsInterface
5918 //! \param int32_t bSamplerState
5919 //! \param int32_t bSurfaceState
5920 //! \param uint32_t dwStateIndex
5921 //! \return uint32_t
5922 //!
Mos_Specific_GetCmdBufferDebugInfo(PMOS_INTERFACE pOsInterface,int32_t bSamplerState,int32_t bSurfaceState,uint32_t dwStateIndex)5923 uint32_t Mos_Specific_GetCmdBufferDebugInfo(
5924 PMOS_INTERFACE pOsInterface,
5925 int32_t bSamplerState,
5926 int32_t bSurfaceState,
5927 uint32_t dwStateIndex)
5928 {
5929 MOS_UNUSED(pOsInterface);
5930 MOS_UNUSED(bSamplerState);
5931 MOS_UNUSED(bSurfaceState);
5932 MOS_UNUSED(dwStateIndex);
5933 // stub function. implemented for simulation but not driver.
5934 return 0;
5935 }
5936
5937 //!
5938 //! \brief Set PAK/MFX context for Encoder which can be used for Synchronization
5939 //! \details On Linux, the synchronization is handled in KMD, no job in UMD
5940 //! \param PMOS_INTERFACE pOsInterface
5941 //! [in] pointer to OS interface structure
5942 //! \param MOS_GPU_CONTEXT GpuContext
5943 //! [in] GPU context
5944 //! \return MOS_STATUS
5945 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
5946 //!
Mos_Specific_SetEncodePakContext(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT GpuContext)5947 void Mos_Specific_SetEncodePakContext(
5948 PMOS_INTERFACE pOsInterface,
5949 MOS_GPU_CONTEXT GpuContext)
5950 {
5951 MOS_UNUSED(pOsInterface);
5952 MOS_UNUSED(GpuContext);
5953 return;
5954 }
5955
5956 //!
5957 //! \brief Set VME/ENC context for Encoder which can be used for Synchronization
5958 //! \details On Linux, the synchronization is handled in KMD, no job in UMD
5959 //! \param PMOS_INTERFACE pOsInterface
5960 //! [in] pointer to OS interface structure
5961 //! \param MOS_GPU_CONTEXT GpuContext
5962 //! [in] GPU context
5963 //! \return MOS_STATUS
5964 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
5965 //!
Mos_Specific_SetEncodeEncContext(PMOS_INTERFACE pOsInterface,MOS_GPU_CONTEXT GpuContext)5966 void Mos_Specific_SetEncodeEncContext(
5967 PMOS_INTERFACE pOsInterface,
5968 MOS_GPU_CONTEXT GpuContext)
5969 {
5970 MOS_UNUSED(pOsInterface);
5971 MOS_UNUSED(GpuContext);
5972 return;
5973 }
5974
5975 //!
5976 //! \brief Verifys the patch list to be used for rendering GPU commands is large enough
5977 //! \details
5978 //! \param PMOS_INTERFACE pOsInterface
5979 //! [in] pointer to OS interface structure
5980 //! \param uint32_t dwRequestedSize
5981 //! [in] patch list size to be verified
5982 //! \return MOS_STATUS
5983 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
5984 //!
Mos_Specific_VerifyPatchListSize(PMOS_INTERFACE pOsInterface,uint32_t dwRequestedSize)5985 MOS_STATUS Mos_Specific_VerifyPatchListSize(
5986 PMOS_INTERFACE pOsInterface,
5987 uint32_t dwRequestedSize)
5988 {
5989 MOS_OS_FUNCTION_ENTER;
5990
5991 MOS_OS_CHK_NULL_RETURN(pOsInterface);
5992
5993 if (pOsInterface->apoMosEnabled)
5994 {
5995 // No APO MOS interface support for this func, implement in wrapper
5996 auto streamState = pOsInterface->osStreamState;
5997
5998 MOS_OS_CHK_NULL_RETURN(streamState);
5999 MOS_OS_CHK_NULL_RETURN(streamState->osDeviceContext);
6000
6001 auto osDeviceContext = streamState->osDeviceContext;
6002
6003 auto gpuContextMgr = osDeviceContext->GetGpuContextMgr();
6004 if (gpuContextMgr)
6005 {
6006 auto gpuCtx = gpuContextMgr->GetGpuContext(streamState->currentGpuContextHandle);
6007
6008 auto gpuCtxSpecific = static_cast<GpuContextSpecificNext *>(gpuCtx);
6009 MOS_OS_CHK_NULL_RETURN(gpuCtxSpecific);
6010 return (gpuCtxSpecific->VerifyPatchListSize(dwRequestedSize));
6011 }
6012 }
6013 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
6014 {
6015 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
6016 MOS_OS_CHK_NULL_RETURN(gpuContext);
6017
6018 return (gpuContext->VerifyPatchListSize(dwRequestedSize));
6019 }
6020
6021 MOS_STATUS eStatus;
6022 PMOS_OS_CONTEXT pOsContext;
6023 PMOS_OS_GPU_CONTEXT pOsGpuContext;
6024
6025 MOS_OS_CHK_NULL(pOsInterface);
6026
6027 eStatus = MOS_STATUS_SUCCESS;
6028
6029 pOsContext = pOsInterface->pOsContext;
6030 MOS_OS_CHK_NULL(pOsContext);
6031
6032 pOsGpuContext = &(pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal]);
6033 if (dwRequestedSize > pOsGpuContext->uiMaxPatchLocationsize)
6034 {
6035 eStatus = MOS_STATUS_UNKNOWN;
6036 }
6037
6038 finish:
6039 return eStatus;
6040 }
6041
6042 //!
6043 //! \brief reset command buffer space
6044 //! \details resets the command buffer space
6045 //! \param PMOS_INTERFACE pOsInterface
6046 //! [in] pointer to OS interface structure
6047 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
6048 //! [in] pointer to command buffer structure
6049 //! \return MOS_STATUS
6050 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
6051 //!
Mos_Specific_ResetCommandBuffer(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer)6052 MOS_STATUS Mos_Specific_ResetCommandBuffer(
6053 PMOS_INTERFACE pOsInterface,
6054 PMOS_COMMAND_BUFFER pCmdBuffer)
6055 {
6056 PMOS_OS_CONTEXT pOsContext;
6057 PMOS_OS_GPU_CONTEXT pOsGpuContext;
6058 MOS_UNUSED(pCmdBuffer);
6059 MOS_OS_FUNCTION_ENTER;
6060
6061 MOS_OS_CHK_NULL_RETURN(pOsInterface);
6062 MOS_OS_CHK_NULL_RETURN(pCmdBuffer);
6063
6064 if (pOsInterface->apoMosEnabled)
6065 {
6066 return MosInterface::ResetCommandBuffer(pOsInterface->osStreamState, pCmdBuffer);
6067 }
6068
6069 if (pOsInterface->CurrentGpuContextOrdinal == MOS_GPU_CONTEXT_INVALID_HANDLE)
6070 {
6071 MOS_OS_ASSERTMESSAGE("Invalid input parameter GpuContext.");
6072 return MOS_STATUS_INVALID_PARAMETER;
6073 }
6074
6075 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
6076 {
6077 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
6078 MOS_OS_CHK_NULL_RETURN(gpuContext);
6079
6080 return gpuContext->ResetCommandBuffer();
6081 }
6082
6083 pOsContext = pOsInterface->pOsContext;
6084 pOsGpuContext = &pOsContext->OsGpuContext[pOsInterface->CurrentGpuContextOrdinal];
6085
6086 pOsGpuContext->bCBFlushed = true;
6087
6088 finish:
6089 return MOS_STATUS_SUCCESS;
6090 }
6091
6092 //!
6093 //! \brief Get the memory compression mode
6094 //! \details Gets the memory compression mode from GMM
6095 //! \param PMOS_INTERFACE pOsInterface
6096 //! [in] pointer to OS interface structure
6097 //! \param PMOS_RESOURCE pOsResource
6098 //! [in] pointer to input OS resource
6099 //! \param PMOS_MEMCOMP_STATE pResMmcMode
6100 //! [out] the memory compression mode gotten from OS resource
6101 //! \return MOS_STATUS
6102 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
6103 //!
Mos_Specific_GetMemoryCompressionMode(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,PMOS_MEMCOMP_STATE pResMmcMode)6104 MOS_STATUS Mos_Specific_GetMemoryCompressionMode(
6105 PMOS_INTERFACE pOsInterface,
6106 PMOS_RESOURCE pOsResource,
6107 PMOS_MEMCOMP_STATE pResMmcMode)
6108 {
6109 PGMM_RESOURCE_INFO pGmmResourceInfo;
6110 GMM_RESOURCE_FLAG flags;
6111 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
6112 MOS_OS_FUNCTION_ENTER;
6113
6114 MOS_OS_CHK_NULL_RETURN(pOsResource);
6115 MOS_OS_CHK_NULL_RETURN(pResMmcMode);
6116 MOS_OS_CHK_NULL_RETURN(pOsInterface);
6117
6118 MediaFeatureTable* skuTable = nullptr;
6119 skuTable = pOsInterface->pfnGetSkuTable(pOsInterface);
6120 MOS_OS_CHK_NULL_RETURN(skuTable);
6121
6122 if (pOsInterface->apoMosEnabled)
6123 {
6124 return MosInterface::GetMemoryCompressionMode(pOsInterface->osStreamState, pOsResource, *pResMmcMode);
6125 }
6126
6127 // Get Gmm resource info
6128 pGmmResourceInfo = (GMM_RESOURCE_INFO*)pOsResource->pGmmResInfo;
6129 MOS_OS_CHK_NULL_RETURN(pGmmResourceInfo);
6130
6131 flags = pOsResource->pGmmResInfo->GetResFlags();
6132
6133 if (!flags.Gpu.MMC || !flags.Gpu.CCS)
6134 {
6135 *pResMmcMode = MOS_MEMCOMP_DISABLED;
6136 return MOS_STATUS_SUCCESS;
6137 }
6138
6139 if (flags.Info.MediaCompressed || flags.Info.RenderCompressed)
6140 {
6141 *pResMmcMode = flags.Info.RenderCompressed ? MOS_MEMCOMP_RC : MOS_MEMCOMP_MC;
6142 }
6143 else
6144 {
6145 switch (pGmmResourceInfo->GetMmcMode(0))
6146 {
6147 case GMM_MMC_HORIZONTAL:
6148 *pResMmcMode = MOS_MEMCOMP_HORIZONTAL;
6149 break;
6150 case GMM_MMC_VERTICAL:
6151 *pResMmcMode = MOS_MEMCOMP_VERTICAL;
6152 break;
6153 case GMM_MMC_DISABLED:
6154 default:
6155 *pResMmcMode = MOS_MEMCOMP_DISABLED;
6156 break;
6157 }
6158 }
6159
6160 uint32_t MmcFormat = 0;
6161 GMM_RESOURCE_FORMAT gmmResFmt;
6162
6163 gmmResFmt = pGmmResourceInfo->GetResourceFormat();
6164
6165 if (*pResMmcMode == MOS_MEMCOMP_MC &&
6166 (!MEDIA_IS_SKU(skuTable, FtrFlatPhysCCS)))
6167 {
6168 MmcFormat = static_cast<uint32_t>(pOsInterface->pfnGetGmmClientContext(pOsInterface)->GetMediaSurfaceStateCompressionFormat(gmmResFmt));
6169 *pResMmcMode = (MmcFormat != 0) ? *pResMmcMode : MOS_MEMCOMP_DISABLED;
6170 }
6171
6172 eStatus = MOS_STATUS_SUCCESS;
6173
6174
6175 finish:
6176 return eStatus;
6177 }
6178
6179 //!
6180 //! \brief Set the memory compression mode in GMM
6181 //! \details Set the memory compression mode
6182 //! \param PMOS_INTERFACE pOsInterface
6183 //! [in] pointer to OS interface structure
6184 //! \param PMOS_RESOURCE pOsResource
6185 //! [in] pointer to input OS resource
6186 //! \param MOS_MEMCOMP_STATE ResMmcMode
6187 //! [in] the memory compression mode to be set into OS resource
6188 //! \return MOS_STATUS
6189 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
6190 //!
Mos_Specific_SetMemoryCompressionMode(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,MOS_MEMCOMP_STATE ResMmcMode)6191 MOS_STATUS Mos_Specific_SetMemoryCompressionMode(
6192 PMOS_INTERFACE pOsInterface,
6193 PMOS_RESOURCE pOsResource,
6194 MOS_MEMCOMP_STATE ResMmcMode)
6195 {
6196 PGMM_RESOURCE_INFO pGmmResourceInfo = nullptr;
6197 GMM_RESOURCE_MMC_INFO GmmResMmcMode = GMM_MMC_DISABLED;
6198 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
6199 MOS_OS_FUNCTION_ENTER;
6200 MOS_OS_CHK_NULL(pOsResource);
6201 MOS_OS_CHK_NULL(pOsInterface);
6202
6203 if (pOsInterface->apoMosEnabled)
6204 {
6205 return MosInterface::SetMemoryCompressionMode(pOsInterface->osStreamState, pOsResource, ResMmcMode);
6206 }
6207
6208 // Get Gmm resource info
6209 pGmmResourceInfo = (GMM_RESOURCE_INFO*)pOsResource->pGmmResInfo;
6210 MOS_OS_CHK_NULL(pGmmResourceInfo);
6211
6212 switch (ResMmcMode)
6213 {
6214 case MOS_MEMCOMP_HORIZONTAL:
6215 GmmResMmcMode = GMM_MMC_HORIZONTAL;
6216 break;
6217 case MOS_MEMCOMP_VERTICAL:
6218 GmmResMmcMode = GMM_MMC_VERTICAL;
6219 break;
6220 case MOS_MEMCOMP_DISABLED:
6221 default:
6222 GmmResMmcMode = GMM_MMC_DISABLED;
6223 break;
6224 }
6225
6226 pGmmResourceInfo->SetMmcMode(GmmResMmcMode, 0);
6227
6228 eStatus = MOS_STATUS_SUCCESS;
6229
6230 finish:
6231 return eStatus;
6232 }
6233
6234 //!
6235 //! \brief Set the memory compression hint in GMM on Linux or Gralloc on Android
6236 //! \details Indicate if the surface is compressible
6237 //! \param PMOS_INTERFACE pOsInterface
6238 //! [in] pointer to OS interface structure
6239 //! \param PMOS_RESOURCE pOsResource
6240 //! [in] pointer to input OS resource
6241 //! \param int32_t bHintOn
6242 //! [in] the memory compression hint to be set
6243 //! \return MOS_STATUS
6244 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
6245 //!
Mos_Specific_SetMemoryCompressionHint(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,int32_t bHintOn)6246 MOS_STATUS Mos_Specific_SetMemoryCompressionHint(
6247 PMOS_INTERFACE pOsInterface,
6248 PMOS_RESOURCE pOsResource,
6249 int32_t bHintOn)
6250 {
6251 PGMM_RESOURCE_INFO pGmmResourceInfo = nullptr;
6252 uint32_t uiArrayIndex = 0;
6253 MOS_STATUS eStatus;
6254 MOS_OS_FUNCTION_ENTER;
6255 eStatus = MOS_STATUS_UNKNOWN;
6256 MOS_OS_CHK_NULL(pOsResource);
6257 MOS_OS_CHK_NULL(pOsInterface);
6258
6259 if (pOsInterface->apoMosEnabled)
6260 {
6261 return MosInterface::SetMemoryCompressionHint(pOsInterface->osStreamState, pOsResource, bHintOn);
6262 }
6263
6264 // Get Gmm resource info
6265 pGmmResourceInfo = (GMM_RESOURCE_INFO*)pOsResource->pGmmResInfo;
6266 MOS_OS_CHK_NULL(pGmmResourceInfo);
6267
6268 pGmmResourceInfo->SetMmcHint(bHintOn ? GMM_MMC_HINT_ON : GMM_MMC_HINT_OFF, uiArrayIndex);
6269
6270 eStatus = MOS_STATUS_SUCCESS;
6271
6272 finish:
6273 return eStatus;
6274 }
6275
6276 //!
6277 //! \brief Get the memory compression format
6278 //! \details Gets the memory compression format from GMM
6279 //! \param PMOS_INTERFACE pOsInterface
6280 //! [in] pointer to OS interface structure
6281 //! \param PMOS_RESOURCE pOsResource
6282 //! [in] pointer to input OS resource
6283 //! \param uint32_t *pResMmcFormat
6284 //! [out] the memory compression format gotten from GMM resource
6285 //! \return MOS_STATUS
6286 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
6287 //!
Mos_Specific_GetMemoryCompressionFormat(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,uint32_t * pResMmcFormat)6288 MOS_STATUS Mos_Specific_GetMemoryCompressionFormat(
6289 PMOS_INTERFACE pOsInterface,
6290 PMOS_RESOURCE pOsResource,
6291 uint32_t *pResMmcFormat)
6292 {
6293
6294 PGMM_RESOURCE_INFO pGmmResourceInfo;
6295 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
6296 MOS_OS_FUNCTION_ENTER;
6297 MOS_OS_CHK_NULL(pOsResource);
6298 MOS_OS_CHK_NULL(pOsInterface);
6299 MOS_OS_CHK_NULL(pResMmcFormat);
6300
6301 if (pOsInterface->apoMosEnabled)
6302 {
6303 return MosInterface::GetMemoryCompressionFormat(pOsInterface->osStreamState, pOsResource, pResMmcFormat);
6304 }
6305
6306 // Get Gmm resource info
6307 pGmmResourceInfo = (GMM_RESOURCE_INFO*)pOsResource->pGmmResInfo;
6308 MOS_OS_CHK_NULL(pGmmResourceInfo);
6309
6310 MOS_OS_CHK_NULL(pOsInterface->pfnGetGmmClientContext(pOsInterface));
6311 // Get compression format from GMM RESOURCE FORMAT
6312 GMM_RESOURCE_FORMAT gmmResFmt;
6313 gmmResFmt = pGmmResourceInfo->GetResourceFormat();
6314 MOS_MEMCOMP_STATE MmcMode;
6315 uint32_t MmcFormat;
6316 Mos_Specific_GetMemoryCompressionMode(pOsInterface, pOsResource, &MmcMode);
6317 switch (MmcMode)
6318 {
6319 case MOS_MEMCOMP_MC:
6320 MmcFormat = static_cast<uint32_t>(pOsInterface->pfnGetGmmClientContext(pOsInterface)->GetMediaSurfaceStateCompressionFormat(gmmResFmt));
6321 break;
6322 case MOS_MEMCOMP_RC:
6323 MmcFormat = static_cast<uint32_t>(pOsInterface->pfnGetGmmClientContext(pOsInterface)->GetSurfaceStateCompressionFormat(gmmResFmt));
6324 break;
6325 default:
6326 MmcFormat = 0;
6327 }
6328
6329 if (MmcFormat > 0x1F)
6330 {
6331 MOS_OS_ASSERTMESSAGE("Get a incorrect Compression format(%d) from GMM", MmcFormat);
6332 }
6333 else
6334 {
6335 *pResMmcFormat = MmcFormat;
6336 MOS_OS_VERBOSEMESSAGE("GMM compression mode %d, compression format %d", MmcMode, MmcFormat);
6337 }
6338
6339 eStatus = MOS_STATUS_SUCCESS;
6340
6341 finish:
6342 return eStatus;
6343
6344 }
6345
6346 #ifdef ANDROID
6347 //!
6348 //! \brief Create GPU node association.
6349 //! \details Create GPU node association.
6350 //! \param PMOS_INTERFACE pOsInterface
6351 //! [in] OS Interface
6352 //! \param MOS_MEDIA_OPERATION MediaOperation
6353 //! [in] Media operation
6354 //! \param MOS_GPU_NODE *pVideoNodeOrdinal
6355 //! [out] VCS node ordinal
6356 //! \return MOS_STATUS
6357 //! MOS_STATUS_SUCCESS if success, otherwise error code
6358 //!
Mos_Specific_CreateVideoNodeAssociation(PMOS_INTERFACE pOsInterface,int32_t bSetVideoNode,MOS_GPU_NODE * pVideoNodeOrdinal)6359 MOS_STATUS Mos_Specific_CreateVideoNodeAssociation(
6360 PMOS_INTERFACE pOsInterface,
6361 int32_t bSetVideoNode,
6362 MOS_GPU_NODE *pVideoNodeOrdinal)
6363 {
6364 MOS_UNUSED(pOsInterface);
6365 MOS_UNUSED(bSetVideoNode);
6366 MOS_OS_ASSERT(pVideoNodeOrdinal);
6367
6368 // return VDBox #1 for now.
6369 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO;
6370
6371 return MOS_STATUS_SUCCESS;
6372 }
6373
6374 //!
6375 //! \brief Destroy GPU node association.
6376 //! \details Destroy GPU node association.
6377 //! \param PMOS_INTERFACE pOsInterface
6378 //! [in] OS Interface
6379 //! \param MOS_GPU_NODE VideoNodeOrdinal
6380 //! [in] VCS node ordinal
6381 //! \return MOS_STATUS
6382 //! MOS_STATUS_SUCCESS if success, otherwise error code
6383 //!
Mos_Specific_DestroyVideoNodeAssociation(PMOS_INTERFACE pOsInterface,MOS_GPU_NODE VideoNodeOrdinal)6384 MOS_STATUS Mos_Specific_DestroyVideoNodeAssociation(
6385 PMOS_INTERFACE pOsInterface,
6386 MOS_GPU_NODE VideoNodeOrdinal)
6387 {
6388 MOS_UNUSED(pOsInterface);
6389 MOS_UNUSED(VideoNodeOrdinal);
6390 return MOS_STATUS_SUCCESS;
6391 }
6392
6393 #else
6394
6395 //!
6396 //! \brief Create GPU node association.
6397 //! \details Create GPU node association.
6398 //! \param PMOS_INTERFACE pOsInterface
6399 //! [in] OS Interface
6400 //! \param MOS_MEDIA_OPERATION MediaOperation
6401 //! [in] Media operation
6402 //! \param MOS_GPU_NODE *pVideoNodeOrdinal
6403 //! [out] VCS node ordinal
6404 //! \return MOS_STATUS
6405 //! MOS_STATUS_SUCCESS if success, otherwise error code
6406 //!
Mos_Specific_CreateVideoNodeAssociation(PMOS_INTERFACE pOsInterface,int32_t bSetVideoNode,MOS_GPU_NODE * pVideoNodeOrdinal)6407 MOS_STATUS Mos_Specific_CreateVideoNodeAssociation(
6408 PMOS_INTERFACE pOsInterface,
6409 int32_t bSetVideoNode,
6410 MOS_GPU_NODE *pVideoNodeOrdinal)
6411 {
6412 PMOS_OS_CONTEXT pOsContext;
6413 PVDBOX_WORKLOAD pVDBoxWorkLoad = nullptr;
6414 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
6415
6416 MOS_OS_FUNCTION_ENTER;
6417
6418 MOS_OS_ASSERT(pOsInterface);
6419 MOS_OS_ASSERT(pVideoNodeOrdinal);
6420
6421 pOsContext = pOsInterface->pOsContext;
6422
6423 if (false == pOsContext->bKMDHasVCS2)
6424 {
6425 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO;
6426 goto finish;
6427 }
6428
6429 // If node selection is forced or we have only one VDBox, turn balancing off.
6430 // After that check debug flags.
6431 if (pOsInterface->bEnableVdboxBalancing)
6432 {
6433 pOsContext->bPerCmdBufferBalancing = !bSetVideoNode && pOsContext->bKMDHasVCS2 && pOsInterface->pfnGetVdboxNodeId;
6434 }
6435 else
6436 {
6437 pOsContext->bPerCmdBufferBalancing = 0;
6438 }
6439
6440 #if (_DEBUG || _RELEASE_INTERNAL)
6441 if (pOsInterface->eForceVdbox == MOS_FORCE_VDBOX_1)
6442 {
6443 bSetVideoNode = true;
6444 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO;
6445 pOsContext->bPerCmdBufferBalancing = 0;
6446 }
6447 else if (pOsInterface->eForceVdbox == MOS_FORCE_VDBOX_2)
6448 {
6449 bSetVideoNode = true;
6450 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO2;
6451 pOsContext->bPerCmdBufferBalancing = 0;
6452 }
6453 #endif // _DEBUG || _RELEASE_INTERNAL
6454
6455 if (pOsContext->semid == MOS_LINUX_IPC_INVALID_ID)
6456 {
6457 MOS_OS_ASSERTMESSAGE("Invalid semid in OsContext.");
6458 eStatus = MOS_STATUS_UNKNOWN;
6459 goto finish;
6460 }
6461
6462 LockSemaphore(pOsContext->semid);
6463
6464 pVDBoxWorkLoad = (PVDBOX_WORKLOAD)pOsContext->pShm;
6465 MOS_OS_ASSERT(pVDBoxWorkLoad);
6466
6467 if (bSetVideoNode)
6468 {
6469 if (*pVideoNodeOrdinal == MOS_GPU_NODE_VIDEO)
6470 {
6471 pVDBoxWorkLoad->uiVDBoxCount[0]++;
6472 }
6473 else if (*pVideoNodeOrdinal == MOS_GPU_NODE_VIDEO2)
6474 {
6475 pVDBoxWorkLoad->uiVDBoxCount[1]++;
6476 }
6477 else
6478 {
6479 MOS_OS_ASSERTMESSAGE("VDBoxWorkLoad not set.");
6480 }
6481 }
6482 else
6483 {
6484 if (pVDBoxWorkLoad->uiVDBoxCount[0] < pVDBoxWorkLoad->uiVDBoxCount[1])
6485 {
6486 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO;
6487 pVDBoxWorkLoad->uiVDBoxCount[0]++;
6488 }
6489 else if (pVDBoxWorkLoad->uiVDBoxCount[0] == pVDBoxWorkLoad->uiVDBoxCount[1])
6490 {
6491 // this ping-pong method improves much performance for multi-session HD to HD xcode
6492 if (pVDBoxWorkLoad->uiRingIndex == 0)
6493 {
6494 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO;
6495 pVDBoxWorkLoad->uiVDBoxCount[0]++;
6496 pVDBoxWorkLoad->uiRingIndex = 1;
6497 }
6498 else
6499 {
6500 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO2;
6501 pVDBoxWorkLoad->uiVDBoxCount[1]++;
6502 pVDBoxWorkLoad->uiRingIndex = 0;
6503 }
6504 }
6505 else
6506 {
6507 *pVideoNodeOrdinal = MOS_GPU_NODE_VIDEO2;
6508 pVDBoxWorkLoad->uiVDBoxCount[1]++;
6509 }
6510 }
6511
6512 UnLockSemaphore(pOsContext->semid);
6513
6514 finish:
6515 return eStatus;
6516 }
6517
6518 //!
6519 //! \brief Destroy GPU node association.
6520 //! \details Destroy GPU node association.
6521 //! \param PMOS_INTERFACE pOsInterface
6522 //! [in] OS Interface
6523 //! \param MOS_GPU_NODE VideoNodeOrdinal
6524 //! [in] VCS node ordinal
6525 //! \return MOS_STATUS
6526 //! MOS_STATUS_SUCCESS if success, otherwise error code
6527 //!
Mos_Specific_DestroyVideoNodeAssociation(PMOS_INTERFACE pOsInterface,MOS_GPU_NODE VideoNodeOrdinal)6528 MOS_STATUS Mos_Specific_DestroyVideoNodeAssociation(
6529 PMOS_INTERFACE pOsInterface,
6530 MOS_GPU_NODE VideoNodeOrdinal)
6531 {
6532 PMOS_OS_CONTEXT pOsContext = nullptr;
6533 PVDBOX_WORKLOAD pVDBoxWorkLoad = nullptr;
6534
6535 MOS_OS_FUNCTION_ENTER;
6536 MOS_OS_CHK_NULL_RETURN(pOsInterface);
6537 MOS_OS_CHK_NULL_RETURN(pOsInterface->pOsContext);
6538 pOsContext = pOsInterface->pOsContext;
6539
6540 // not do workload balancing in UMD just return;
6541 if (pOsContext->bKMDHasVCS2 == false)
6542 {
6543 return MOS_STATUS_SUCCESS;
6544 }
6545
6546 if (pOsContext->semid == MOS_LINUX_IPC_INVALID_ID)
6547 {
6548 MOS_OS_ASSERTMESSAGE("Invalid semid in OsContext.");
6549 return MOS_STATUS_UNKNOWN;
6550 }
6551
6552 LockSemaphore(pOsContext->semid);
6553
6554 pVDBoxWorkLoad = (PVDBOX_WORKLOAD)pOsContext->pShm;
6555 MOS_OS_ASSERT(pVDBoxWorkLoad);
6556
6557 if (VideoNodeOrdinal == MOS_GPU_NODE_VIDEO)
6558 {
6559 pVDBoxWorkLoad->uiVDBoxCount[0]--;
6560 }
6561 else
6562 {
6563 pVDBoxWorkLoad->uiVDBoxCount[1]--;
6564 }
6565
6566 UnLockSemaphore(pOsContext->semid);
6567
6568 return MOS_STATUS_SUCCESS;
6569 }
6570 #endif
6571
Mos_Specific_GetVdboxNodeId(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer)6572 MOS_VDBOX_NODE_IND Mos_Specific_GetVdboxNodeId(
6573 PMOS_INTERFACE pOsInterface,
6574 PMOS_COMMAND_BUFFER pCmdBuffer)
6575 {
6576 MOS_VDBOX_NODE_IND idx = MOS_VDBOX_NODE_INVALID;
6577
6578 MOS_OS_CHK_NULL_NO_STATUS(pCmdBuffer);
6579 MOS_OS_CHK_NULL_NO_STATUS(pOsInterface);
6580 MOS_OS_CHK_NULL_NO_STATUS(pOsInterface->pOsContext);
6581
6582 // If we have assigned vdbox index for the given cmdbuf, return it immediately
6583 if (MOS_VDBOX_NODE_INVALID != pCmdBuffer->iVdboxNodeIndex) {
6584 idx = pCmdBuffer->iVdboxNodeIndex;
6585 return idx;
6586 }
6587
6588 finish:
6589 return idx;
6590 }
6591
6592 //!
6593 //! \brief Get the memory object
6594 //! \details Get the memory object for cache policy
6595 //! \param MOS_HW_RESOURCE_DEF MosUsage
6596 //! [in] HW resource
6597 //! [in] Gmm client context
6598 //! \return MEMORY_OBJECT_CONTROL_STATE
6599 //! Return the memory object
6600 //!
Mos_Specific_CachePolicyGetMemoryObject(MOS_HW_RESOURCE_DEF MosUsage,GMM_CLIENT_CONTEXT * pGmmClientContext)6601 MEMORY_OBJECT_CONTROL_STATE Mos_Specific_CachePolicyGetMemoryObject(
6602 MOS_HW_RESOURCE_DEF MosUsage,
6603 GMM_CLIENT_CONTEXT *pGmmClientContext)
6604 {
6605 // Force convert to stream handle for wrapper
6606 return MosInterface::GetCachePolicyMemoryObject(pGmmClientContext, MosUsage);
6607 }
6608
6609 //!
6610 //! \brief Get the L1 config
6611 //! \details Get the L1 config for cache policy
6612 //! \param MOS_HW_RESOURCE_DEF MosUsage
6613 //! [in] HW resource
6614 //! [in] Gmm client context
6615 //! \return uint8_t
6616 //! L1_CACHE_CONTROL
6617 //!
Mos_Specific_CachePolicyGetL1Config(MOS_HW_RESOURCE_DEF MosUsage,GMM_CLIENT_CONTEXT * pGmmClientContext)6618 uint8_t Mos_Specific_CachePolicyGetL1Config(
6619 MOS_HW_RESOURCE_DEF MosUsage,
6620 GMM_CLIENT_CONTEXT *pGmmClientContext)
6621 {
6622 return 0;
6623 }
6624
6625
6626 //*-----------------------------------------------------------------------------
6627 //| Purpose : Loads library
6628 //| Returns : Instance to handle
6629 //*-----------------------------------------------------------------------------
6630 //!
6631 //! \brief
6632 //! \details
6633 //! \param const char *pFileName
6634 //! \return HINSTANCE
6635 //!
Mos_Specific_LoadLibrary(PMOS_INTERFACE pOsInterface,PCCHAR pFileName,void ** ppvModule)6636 MOS_STATUS Mos_Specific_LoadLibrary(
6637 PMOS_INTERFACE pOsInterface,
6638 PCCHAR pFileName,
6639 void **ppvModule)
6640 {
6641 char *error;
6642 MOS_UNUSED(pOsInterface);
6643 //---------------------------------
6644 MOS_OS_ASSERT(pFileName);
6645 //---------------------------------
6646
6647 return MosInterface::MosLoadLibrary(nullptr, pFileName, ppvModule);
6648 }
6649
6650 //*-----------------------------------------------------------------------------
6651 //| Purpose : Frees library
6652 //| Returns : Result of the operation
6653 //*-----------------------------------------------------------------------------
6654 //!
6655 //! \brief
6656 //! \details
6657 //! \param HINSTANCE hInstance
6658 //! \return MOS_STATUS
6659 //!
Mos_Specific_FreeLibrary(void * hInstance)6660 MOS_STATUS Mos_Specific_FreeLibrary(
6661 void *hInstance)
6662 {
6663 int32_t bStatus;
6664
6665 //---------------------------------
6666 MOS_OS_ASSERT(hInstance);
6667 //---------------------------------
6668
6669 return MosInterface::MosFreeLibrary(hInstance);
6670 }
6671
6672 //!
6673 //! \brief Determines if the GPU Hung
6674 //! \param PMOS_INTERFACE pOsInterface
6675 //! [in] Pointer to OS Interface
6676 //! \return int32_t
6677 //! Return if the GPU Hung
6678 //!
Mos_Specific_IsGPUHung(PMOS_INTERFACE pOsInterface)6679 int32_t Mos_Specific_IsGPUHung(
6680 PMOS_INTERFACE pOsInterface)
6681 {
6682 uint32_t dwResetCount = 0;
6683 uint32_t dwActiveBatch = 0;
6684 uint32_t dwPendingBatch = 0;
6685 int32_t bResult = false;
6686 int32_t ret = 0;
6687
6688 if (pOsInterface == nullptr)
6689 {
6690 MOS_OS_ASSERTMESSAGE("Mos_Specific_IsGPUHung: pOsInterface == NULL");
6691 return false;
6692 }
6693
6694 if (pOsInterface->apoMosEnabled)
6695 {
6696 return MosInterface::IsGPUHung(pOsInterface->osStreamState);
6697 }
6698
6699 MOS_LINUX_CONTEXT *intel_i915_ctx = pOsInterface->pOsContext->intel_context;
6700 if (pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(nullptr))
6701 {
6702 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
6703 if(gpuContext != nullptr && gpuContext->GetI915Context(0) != nullptr)
6704 {
6705 intel_i915_ctx = gpuContext->GetI915Context(0);
6706 }
6707 }
6708
6709 dwResetCount = dwActiveBatch = dwPendingBatch = 0;
6710
6711 ret = mos_get_reset_stats(intel_i915_ctx, &dwResetCount,
6712 &dwActiveBatch, &dwPendingBatch);
6713 if (ret)
6714 {
6715 MOS_OS_NORMALMESSAGE("mos_get_reset_stats return error(%d)\n", ret);
6716 goto finish;
6717 }
6718
6719 //Chip reset will count this value, but maybe caused by ctx in other process.
6720 //In this case, reset has no impact on current process
6721 if (dwResetCount != pOsInterface->dwGPUResetCount)
6722 {
6723 pOsInterface->dwGPUResetCount = dwResetCount;
6724 }
6725
6726 //Thses two values are ctx specific, it must reset in current process if either changes
6727 if (dwActiveBatch != pOsInterface->dwGPUActiveBatch ||
6728 dwPendingBatch != pOsInterface->dwGPUPendingBatch)
6729 {
6730 pOsInterface->dwGPUActiveBatch = dwActiveBatch;
6731 pOsInterface->dwGPUPendingBatch = dwPendingBatch;
6732 bResult = true;
6733 }
6734
6735 finish:
6736 return bResult;
6737 }
6738
Mos_Specific_GetAuxTableBaseAddr(PMOS_INTERFACE osInterface)6739 uint64_t Mos_Specific_GetAuxTableBaseAddr(
6740 PMOS_INTERFACE osInterface)
6741 {
6742 if (osInterface == nullptr)
6743 {
6744 MOS_OS_NORMALMESSAGE("Invalid osInterface");
6745 return 0;
6746 }
6747 if(osInterface->apoMosEnabled)
6748 {
6749 return MosInterface::GetAuxTableBaseAddr(osInterface->osStreamState);
6750 }
6751
6752 if (osInterface->osContextPtr == nullptr)
6753 {
6754 MOS_OS_NORMALMESSAGE("Invalid osInterface");
6755 return 0;
6756 }
6757 auto osCtx = static_cast<OsContextSpecific *>(osInterface->osContextPtr);
6758 AuxTableMgr *auxTableMgr = osCtx->GetAuxTableMgr();
6759
6760 return auxTableMgr ? auxTableMgr->GetAuxTableBase() : 0;
6761 }
6762
6763 //!
6764 //! \brief Get gpu context priority from KMD
6765 //! \param [in] pOsInterface
6766 //! Pointer to OS interface
6767 //! \param [out] pPriority
6768 //! the priority of the current context.
6769 //!
Mos_Specific_GetGpuPriority(PMOS_INTERFACE pOsInterface,int32_t * pPriority)6770 void Mos_Specific_GetGpuPriority(
6771 PMOS_INTERFACE pOsInterface,
6772 int32_t* pPriority)
6773 {
6774 MOS_OS_ASSERT(pOsInterface);
6775
6776 if (pOsInterface->apoMosEnabled)
6777 {
6778 return MosInterface::GetGpuPriority(pOsInterface->osStreamState, pPriority);
6779 }
6780
6781 if (pOsInterface->osContextPtr)
6782 {
6783 auto osCxtSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
6784 osCxtSpecific->GetGpuPriority(pPriority);
6785 }
6786 else
6787 {
6788 MOS_OS_ASSERTMESSAGE("OS context is nullptr.");
6789 }
6790 }
6791
6792 //!
6793 //! \brief Set gpu priority to KMD
6794 //! \param [in] pOsInterface
6795 //! Pointer to OS interface
6796 //! \param [in] priority
6797 //! the priority set to current context.
6798 //!
Mos_Specific_SetGpuPriority(PMOS_INTERFACE pOsInterface,int32_t priority)6799 void Mos_Specific_SetGpuPriority(
6800 PMOS_INTERFACE pOsInterface,
6801 int32_t priority)
6802 {
6803 MOS_OS_ASSERT(pOsInterface);
6804
6805 if (pOsInterface->apoMosEnabled)
6806 {
6807 return MosInterface::SetGpuPriority(pOsInterface->osStreamState, priority);
6808 }
6809
6810 if (pOsInterface->osContextPtr)
6811 {
6812 auto osCxtSpecific = static_cast<OsContextSpecific*>(pOsInterface->osContextPtr);
6813 osCxtSpecific->SetGpuPriority(priority);
6814 }
6815 else
6816 {
6817 MOS_OS_ASSERTMESSAGE("OS context is nullptr.");
6818 }
6819 }
6820
6821 //!
6822 //! \brief Set slice count to shared memory and KMD
6823 //! \param [in] pOsInterface
6824 //! Pointer to OS interface
6825 //! \param [in,out] pSliceCount
6826 //! Pointer to the slice count. Input the slice count for current
6827 //! context, output the ruling slice count shared by all contexts.
6828 //!
Mos_Specific_SetSliceCount(PMOS_INTERFACE pOsInterface,uint32_t * pSliceCount)6829 void Mos_Specific_SetSliceCount(
6830 PMOS_INTERFACE pOsInterface,
6831 uint32_t *pSliceCount)
6832 {
6833 MOS_OS_ASSERT(pOsInterface);
6834 MOS_OS_ASSERT(pSliceCount);
6835
6836 if (pOsInterface->osContextPtr)
6837 {
6838 pOsInterface->osContextPtr->SetSliceCount(pSliceCount);
6839 }
6840 else
6841 {
6842 MOS_OS_ASSERTMESSAGE("OS context is nullptr.");
6843 }
6844 }
6845
Mos_Specific_NotifyStreamIndexSharing(PMOS_INTERFACE pOsInterface)6846 void Mos_Specific_NotifyStreamIndexSharing(
6847 PMOS_INTERFACE pOsInterface)
6848 {
6849 MOS_UNUSED(pOsInterface);
6850 }
6851
Mos_Specific_CheckVirtualEngineSupported(PMOS_INTERFACE osInterface)6852 MOS_STATUS Mos_Specific_CheckVirtualEngineSupported(
6853 PMOS_INTERFACE osInterface)
6854 {
6855 MOS_OS_CHK_NULL_RETURN(osInterface);
6856
6857 auto skuTable = osInterface->pfnGetSkuTable(osInterface);
6858 MOS_OS_CHK_NULL_RETURN(skuTable);
6859 if (MEDIA_IS_SKU(skuTable, FtrContextBasedScheduling))
6860 {
6861 osInterface->bSupportVirtualEngine = true;
6862 }
6863 else
6864 {
6865 osInterface->bSupportVirtualEngine = false;
6866 }
6867
6868 return MOS_STATUS_SUCCESS;
6869 }
6870
Mos_Specific_GetUserSettingInstance(PMOS_INTERFACE osInterface)6871 MediaUserSettingSharedPtr Mos_Specific_GetUserSettingInstance(
6872 PMOS_INTERFACE osInterface)
6873 {
6874 MOS_OS_FUNCTION_ENTER;
6875 if (!osInterface)
6876 {
6877 MOS_OS_ASSERTMESSAGE("Invalid osInterface ptr");
6878 return nullptr;
6879 }
6880
6881 if (osInterface->apoMosEnabled)
6882 {
6883 return MosInterface::MosGetUserSettingInstance(osInterface->osStreamState);
6884 }
6885 return MosInterface::MosGetUserSettingInstance(osInterface->pOsContext);
6886 }
6887
Mos_Specific_InitInterface_Ve(PMOS_INTERFACE osInterface)6888 static MOS_STATUS Mos_Specific_InitInterface_Ve(
6889 PMOS_INTERFACE osInterface)
6890 {
6891 PLATFORM Platform;
6892 MOS_STATUS eStatus;
6893 MOS_STATUS eStatusUserFeature;
6894 uint32_t regValue = 0;
6895 MediaUserSettingSharedPtr userSettingPtr = nullptr;
6896
6897 MOS_OS_FUNCTION_ENTER;
6898
6899 eStatus = MOS_STATUS_SUCCESS;
6900 eStatusUserFeature = MOS_STATUS_SUCCESS;
6901
6902 MOS_OS_CHK_NULL_RETURN(osInterface);
6903 userSettingPtr = osInterface->pfnGetUserSettingInstance(osInterface);
6904
6905 // Get platform information
6906 memset(&Platform, 0, sizeof(PLATFORM));
6907 if (!Mos_Solo_IsEnabled(nullptr))
6908 {
6909 osInterface->pfnGetPlatform(osInterface, &Platform);
6910 }
6911
6912 if (GFX_IS_GEN_11_OR_LATER(Platform) || Mos_Solo_IsEnabled(nullptr))
6913 {
6914 //keep this as false until VE is enabled by all media components
6915 osInterface->bSupportVirtualEngine = false;
6916 osInterface->bUseHwSemaForResSyncInVE = false;
6917 osInterface->pVEInterf = nullptr;
6918 osInterface->VEEnable = false;
6919
6920 auto skuTable = osInterface->pfnGetSkuTable(osInterface);
6921 MOS_OS_CHK_NULL_RETURN(skuTable);
6922 if (MEDIA_IS_SKU(skuTable, FtrGucSubmission))
6923 {
6924 osInterface->bParallelSubmission = true;
6925 }
6926
6927 //Read Scalable/Legacy Decode mode on Gen11+
6928 //1:by default for scalable decode mode
6929 //0:for legacy decode mode
6930 regValue = 0;
6931 eStatusUserFeature = ReadUserSetting(
6932 userSettingPtr,
6933 regValue,
6934 __MEDIA_USER_FEATURE_VALUE_ENABLE_HCP_SCALABILITY_DECODE,
6935 MediaUserSetting::Group::Device);
6936
6937 osInterface->bHcpDecScalabilityMode = regValue ? MOS_SCALABILITY_ENABLE_MODE_DEFAULT : MOS_SCALABILITY_ENABLE_MODE_FALSE;
6938 if(osInterface->bHcpDecScalabilityMode
6939 && (eStatusUserFeature == MOS_STATUS_SUCCESS))
6940 {
6941 //user's value to enable scalability
6942 osInterface->bHcpDecScalabilityMode = MOS_SCALABILITY_ENABLE_MODE_USER_FORCE;
6943 }
6944
6945 #if (_DEBUG || _RELEASE_INTERNAL)
6946 osInterface->frameSplit = false;
6947 ReadUserSetting(
6948 userSettingPtr,
6949 osInterface->frameSplit,
6950 __MEDIA_USER_FEATURE_VALUE_ENABLE_LINUX_FRAME_SPLIT,
6951 MediaUserSetting::Group::Device);
6952
6953 regValue = 0;
6954 ReadUserSettingForDebug(
6955 userSettingPtr,
6956 regValue,
6957 __MEDIA_USER_FEATURE_VALUE_ENABLE_GUC_SUBMISSION,
6958 MediaUserSetting::Group::Device);
6959 osInterface->bParallelSubmission = osInterface->bParallelSubmission && regValue;
6960
6961 // read the "Force VEBOX" user feature key
6962 // 0: not force
6963 regValue = 0;
6964 ReadUserSettingForDebug(
6965 userSettingPtr,
6966 regValue,
6967 __MEDIA_USER_FEATURE_VALUE_FORCE_VEBOX,
6968 MediaUserSetting::Group::Device);
6969 osInterface->eForceVebox = (MOS_FORCE_VEBOX)regValue;
6970
6971 //KMD Virtual Engine DebugOverride
6972 // 0: not Override
6973 ReadUserSettingForDebug(
6974 userSettingPtr,
6975 osInterface->bEnableDbgOvrdInVE,
6976 __MEDIA_USER_FEATURE_VALUE_ENABLE_VE_DEBUG_OVERRIDE,
6977 MediaUserSetting::Group::Device);
6978 #endif
6979
6980 // UMD Vebox Virtual Engine Scalability Mode
6981 // 0: disable. can set to 1 only when KMD VE is enabled.
6982 regValue = 0;
6983 eStatusUserFeature = ReadUserSetting(
6984 userSettingPtr,
6985 regValue,
6986 __MEDIA_USER_FEATURE_VALUE_ENABLE_VEBOX_SCALABILITY_MODE,
6987 MediaUserSetting::Group::Device);
6988
6989 osInterface->bVeboxScalabilityMode = regValue ? MOS_SCALABILITY_ENABLE_MODE_DEFAULT : MOS_SCALABILITY_ENABLE_MODE_FALSE;
6990
6991 #if (_DEBUG || _RELEASE_INTERNAL)
6992 if(osInterface->bVeboxScalabilityMode
6993 && (eStatusUserFeature == MOS_STATUS_SUCCESS))
6994 {
6995 //user's value to enable scalability
6996 osInterface->bVeboxScalabilityMode = MOS_SCALABILITY_ENABLE_MODE_USER_FORCE;
6997
6998 if (osInterface->eForceVebox == MOS_FORCE_VEBOX_NONE)
6999 {
7000 osInterface->eForceVebox = MOS_FORCE_VEBOX_1_2;
7001 }
7002 }
7003 else if ((!osInterface->bVeboxScalabilityMode)
7004 && (eStatusUserFeature == MOS_STATUS_SUCCESS))
7005 {
7006 osInterface->eForceVebox = MOS_FORCE_VEBOX_NONE;
7007 }
7008
7009 // read the "Force VEBOX" user feature key
7010 // 0: not force
7011 regValue = 0;
7012 ReadUserSettingForDebug(
7013 userSettingPtr,
7014 regValue,
7015 __MEDIA_USER_FEATURE_VALUE_FORCE_VEBOX,
7016 MediaUserSetting::Group::Device);
7017 osInterface->eForceVebox = (MOS_FORCE_VEBOX)regValue;
7018 #endif
7019 }
7020
7021 return eStatus;
7022 }
7023
Mos_Specific_IsMismatchOrderProgrammingSupported()7024 bool Mos_Specific_IsMismatchOrderProgrammingSupported()
7025 {
7026 return MosInterface::IsMismatchOrderProgrammingSupported();
7027 }
7028
Mos_Specific_pfnIsMultipleCodecDevicesInUse(PMOS_INTERFACE pOsInterface)7029 bool Mos_Specific_pfnIsMultipleCodecDevicesInUse(
7030 PMOS_INTERFACE pOsInterface)
7031 {
7032 MOS_OS_FUNCTION_ENTER;
7033
7034 return false;
7035 }
7036
Mos_Specific_pfnSetMultiEngineEnabled(PMOS_INTERFACE pOsInterface,MOS_COMPONENT component,bool enabled)7037 MOS_STATUS Mos_Specific_pfnSetMultiEngineEnabled(
7038 PMOS_INTERFACE pOsInterface,
7039 MOS_COMPONENT component,
7040 bool enabled)
7041 {
7042 MOS_OS_FUNCTION_ENTER;
7043
7044 return MOS_STATUS_SUCCESS;
7045 }
7046
Mos_Specific_pfnGetMultiEngineStatus(PMOS_INTERFACE pOsInterface,PLATFORM * platform,MOS_COMPONENT component,bool & isMultiDevices,bool & isMultiEngine)7047 MOS_STATUS Mos_Specific_pfnGetMultiEngineStatus(
7048 PMOS_INTERFACE pOsInterface,
7049 PLATFORM *platform,
7050 MOS_COMPONENT component,
7051 bool &isMultiDevices,
7052 bool &isMultiEngine)
7053 {
7054 MOS_OS_FUNCTION_ENTER;
7055
7056 return MOS_STATUS_SUCCESS;
7057 }
7058
Mos_Specific_pfnGetLatestVirtualNode(PMOS_INTERFACE pOsInterface,MOS_COMPONENT component)7059 MOS_GPU_NODE Mos_Specific_pfnGetLatestVirtualNode(
7060 PMOS_INTERFACE pOsInterface,
7061 MOS_COMPONENT component)
7062 {
7063 MOS_OS_FUNCTION_ENTER;
7064
7065 return MOS_GPU_NODE_MAX;
7066 }
7067
Mos_Specific_pfnSetLatestVirtualNode(PMOS_INTERFACE pOsInterface,MOS_GPU_NODE node)7068 void Mos_Specific_pfnSetLatestVirtualNode(
7069 PMOS_INTERFACE pOsInterface,
7070 MOS_GPU_NODE node)
7071 {
7072 MOS_OS_FUNCTION_ENTER;
7073 }
7074
Mos_Specific_pfnGetDecoderVirtualNodePerStream(PMOS_INTERFACE pOsInterface)7075 MOS_GPU_NODE Mos_Specific_pfnGetDecoderVirtualNodePerStream(
7076 PMOS_INTERFACE pOsInterface)
7077 {
7078 MOS_OS_FUNCTION_ENTER;
7079
7080 return MOS_GPU_NODE_MAX;
7081 }
7082
Mos_Specific_pfnSetDecoderVirtualNodePerStream(PMOS_INTERFACE pOsInterface,MOS_GPU_NODE node)7083 void Mos_Specific_pfnSetDecoderVirtualNodePerStream(
7084 PMOS_INTERFACE pOsInterface,
7085 MOS_GPU_NODE node)
7086 {
7087 MOS_OS_FUNCTION_ENTER;
7088 }
7089
Mos_Specific_IsAsyncDevice(PMOS_INTERFACE pOsInterface)7090 bool Mos_Specific_IsAsyncDevice(PMOS_INTERFACE pOsInterface)
7091 {
7092 return false;
7093 }
7094
7095 //! \brief Unified OS Initializes OS Linux Interface
7096 //! \details Linux OS Interface initilization
7097 //! \param PMOS_INTERFACE pOsInterface
7098 //! [in] Pointer to OS Interface
7099 //! \param PMOS_CONTEXT pOsDriverContext
7100 //! [in] Pointer to Driver context
7101 //! \return MOS_STATUS
7102 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
7103 //!
Mos_Specific_InitInterface(PMOS_INTERFACE pOsInterface,PMOS_CONTEXT pOsDriverContext)7104 MOS_STATUS Mos_Specific_InitInterface(
7105 PMOS_INTERFACE pOsInterface,
7106 PMOS_CONTEXT pOsDriverContext)
7107 {
7108 PMOS_OS_CONTEXT pOsContext = nullptr;
7109 PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface = nullptr;
7110 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
7111 MediaFeatureTable *pSkuTable = nullptr;
7112 uint32_t dwResetCount = 0;
7113 int32_t ret = 0;
7114 bool modularizedGpuCtxEnabled = false;
7115 MediaUserSettingSharedPtr userSettingPtr = nullptr;
7116 bool bSimIsActive = false;
7117 bool useCustomerValue = false;
7118 uint32_t regValue = 0;
7119 char *pMediaWatchdog = nullptr;
7120 long int watchdog = 0;
7121
7122 MOS_OS_FUNCTION_ENTER;
7123
7124 MOS_OS_CHK_NULL(pOsInterface);
7125 MOS_OS_CHK_NULL(pOsDriverContext);
7126
7127 userSettingPtr = pOsDriverContext->m_userSettingPtr;
7128
7129 // Initialize OS interface functions
7130 pOsInterface->pfnSetGpuContext = Mos_Specific_SetGpuContext;
7131 pOsInterface->pfnSetGpuContextFromHandle = Mos_Specific_SetGpuContextFromHandle;
7132 pOsInterface->pfnGetGpuContext = Mos_Specific_GetGpuContext;
7133 pOsInterface->pfnSetEncodePakContext = Mos_Specific_SetEncodePakContext;
7134 pOsInterface->pfnSetEncodeEncContext = Mos_Specific_SetEncodeEncContext;
7135 pOsInterface->pfnGetGmmClientContext = Mos_Specific_GetGmmClientContext;
7136
7137 pOsInterface->pfnGetPlatform = Mos_Specific_GetPlatform;
7138 pOsInterface->pfnDestroy = Mos_Specific_Destroy;
7139 pOsInterface->pfnGetSkuTable = Mos_Specific_GetSkuTable;
7140 pOsInterface->pfnGetWaTable = Mos_Specific_GetWaTable;
7141 pOsInterface->pfnGetGtSystemInfo = Mos_Specific_GetGtSystemInfo;
7142 pOsInterface->pfnGetMediaEngineInfo = Mos_Specific_GetMediaEngineInfo;
7143 pOsInterface->pfnResetOsStates = Mos_Specific_ResetOsStates;
7144 pOsInterface->pfnAllocateResource = Mos_Specific_AllocateResource;
7145 pOsInterface->pfnGetResourceInfo = Mos_Specific_GetResourceInfo;
7146 pOsInterface->pfnFreeResource = Mos_Specific_FreeResource;
7147 pOsInterface->pfnFreeResourceWithFlag = Mos_Specific_FreeResourceWithFlag;
7148 pOsInterface->pfnLockSyncRequest = Mos_Specific_LockSyncRequest;
7149 pOsInterface->pfnLockResource = Mos_Specific_LockResource;
7150 pOsInterface->pfnUnlockResource = Mos_Specific_UnlockResource;
7151 pOsInterface->pfnDecompResource = Mos_Specific_DecompResource;
7152 pOsInterface->pfnSetDecompSyncRes = Mos_Specific_SetDecompSyncRes;
7153 pOsInterface->pfnDoubleBufferCopyResource = Mos_Specific_DoubleBufferCopyResource;
7154 pOsInterface->pfnMediaCopyResource2D = Mos_Specific_MediaCopyResource2D;
7155 pOsInterface->pfnMonoSurfaceCopy = Mos_Specific_MonoSurfaceCopy;
7156 pOsInterface->pfnGetMosContext = Mos_Specific_GetMosContext;
7157 pOsInterface->pfnUpdateResourceUsageType = Mos_Specific_UpdateResourceUsageType;
7158 pOsInterface->pfnRegisterResource = Mos_Specific_RegisterResource;
7159 pOsInterface->pfnResetResourceAllocationIndex = Mos_Specific_ResetResourceAllocationIndex;
7160 pOsInterface->pfnGetResourceAllocationIndex = Mos_Specific_GetResourceAllocationIndex;
7161 pOsInterface->pfnGetResourceGfxAddress = Mos_Specific_GetResourceGfxAddress;
7162 pOsInterface->pfnGetResourceClearAddress = Mos_Specific_GetResourceClearAddress;
7163 pOsInterface->pfnGetCommandBuffer = Mos_Specific_GetCommandBuffer;
7164 pOsInterface->pfnResetCommandBuffer = Mos_Specific_ResetCommandBuffer;
7165 pOsInterface->pfnReturnCommandBuffer = Mos_Specific_ReturnCommandBuffer;
7166 pOsInterface->pfnSubmitCommandBuffer = Mos_Specific_SubmitCommandBuffer;
7167 pOsInterface->pfnWaitAndReleaseCmdBuffer = Mos_Specific_WaitAndReleaseCmdBuffer;
7168 pOsInterface->pfnVerifyCommandBufferSize = Mos_Specific_VerifyCommandBufferSize;
7169 pOsInterface->pfnResizeCommandBufferAndPatchList = Mos_Specific_ResizeCommandBufferAndPatchList;
7170 pOsInterface->pfnSetPerfTag = Mos_Specific_SetPerfTag;
7171 pOsInterface->pfnResetPerfBufferID = Mos_Specific_ResetPerfBufferID;
7172 pOsInterface->pfnIncPerfFrameID = Mos_Specific_IncPerfFrameID;
7173 pOsInterface->pfnIncPerfBufferID = Mos_Specific_IncPerfBufferID;
7174 pOsInterface->pfnGetPerfTag = Mos_Specific_GetPerfTag;
7175 pOsInterface->pfnSetPerfHybridKernelID = Mos_Specific_SetPerfHybridKernelID;
7176 pOsInterface->pfnIsPerfTagSet = Mos_Specific_IsPerfTagSet;
7177 pOsInterface->pfnSetIndirectStateSize = Mos_Specific_SetIndirectStateSize;
7178 pOsInterface->pfnGetIndirectState = Mos_Specific_GetIndirectState;
7179 pOsInterface->pfnGetIndirectStatePointer = Mos_Specific_GetIndirectStatePointer;
7180 pOsInterface->pfnSetPatchEntry = Mos_Specific_SetPatchEntry;
7181 pOsInterface->pfnGetInterfaceVersion = Mos_Specific_GetInterfaceVersion;
7182
7183 pOsInterface->pfnLoadLibrary = Mos_Specific_LoadLibrary;
7184 pOsInterface->pfnFreeLibrary = Mos_Specific_FreeLibrary;
7185 pOsInterface->pfnCheckVirtualEngineSupported = Mos_Specific_CheckVirtualEngineSupported;
7186
7187 //GPU context and synchronization functions
7188 pOsInterface->pfnCreateGpuContext = Mos_Specific_CreateGpuContext;
7189 pOsInterface->pfnCreateGpuComputeContext = Mos_Specific_CreateGpuComputeContext;
7190 pOsInterface->pfnDestroyGpuContext = Mos_Specific_DestroyGpuContext;
7191 pOsInterface->pfnDestroyGpuContextByHandle = Mos_Specific_DestroyGpuContextByHandle;
7192 pOsInterface->pfnDestroyGpuComputeContext = Mos_Specific_DestroyGpuComputeContext;
7193 pOsInterface->pfnIsGpuContextValid = Mos_Specific_IsGpuContextValid;
7194 pOsInterface->pfnSyncOnResource = Mos_Specific_SyncOnResource;
7195 pOsInterface->pfnSyncGpuContext = Mos_Specific_SyncGpuContext;
7196 pOsInterface->pfnGetGpuStatusBufferResource = Mos_Specific_GetGpuStatusBufferResource;
7197 pOsInterface->pfnGetGpuStatusTagOffset = Mos_Specific_GetGpuStatusTagOffset;
7198 pOsInterface->pfnGetGpuStatusTag = Mos_Specific_GetGpuStatusTag;
7199 pOsInterface->pfnIncrementGpuStatusTag = Mos_Specific_IncrementGpuStatusTag;
7200 pOsInterface->pfnGetGpuStatusSyncTag = Mos_Specific_GetGpuStatusSyncTag;
7201 pOsInterface->pfnSetResourceSyncTag = Mos_Specific_SetResourceSyncTag;
7202 pOsInterface->pfnPerformOverlaySync = Mos_Specific_PerformOverlaySync;
7203 pOsInterface->pfnEngineSignal = Mos_Specific_EngineSignal;
7204 pOsInterface->pfnEngineWait = Mos_Specific_EngineWait;
7205 pOsInterface->pfnWaitAllCmdCompletion = Mos_Specific_WaitAllCmdCompletion_Os;
7206 pOsInterface->pfnResourceSignal = Mos_Specific_ResourceSignal;
7207 pOsInterface->pfnResourceWait = Mos_Specific_ResourceWait;
7208 pOsInterface->pfnCreateSyncResource = Mos_Specific_CreateSyncResource;
7209 pOsInterface->pfnDestroySyncResource = Mos_Specific_DestroySyncResource;
7210 pOsInterface->pfnInitializeMultiThreadingSyncTags = Mos_Specific_InitializeMultiThreadingSyncTags;
7211 pOsInterface->pfnMultiThreadingWaitCurrentFrame = Mos_Specific_MultiThreadingWaitCurrentFrame;
7212 pOsInterface->pfnMultiThreadingPostCurrentFrame = Mos_Specific_MultiThreadingPostCurrentFrame;
7213 pOsInterface->pfnSetHybridDecoderRunningFlag = Mos_Specific_SetHybridDecoderRunningFlag;
7214 pOsInterface->pfnGetHybridDecoderRunningFlag = Mos_Specific_GetHybridDecoderRunningFlag;
7215 pOsInterface->pfnMultiThreadResourceSync = Mos_Specific_MultiThreadResourceSync;
7216
7217 pOsInterface->pfnCachePolicyGetMemoryObject = Mos_Specific_CachePolicyGetMemoryObject;
7218 pOsInterface->pfnVerifyPatchListSize = Mos_Specific_VerifyPatchListSize;
7219 pOsInterface->pfnGetMemoryCompressionMode = Mos_Specific_GetMemoryCompressionMode;
7220 pOsInterface->pfnSetMemoryCompressionMode = Mos_Specific_SetMemoryCompressionMode;
7221 pOsInterface->pfnSetMemoryCompressionHint = Mos_Specific_SetMemoryCompressionHint;
7222 pOsInterface->pfnGetMemoryCompressionFormat = Mos_Specific_GetMemoryCompressionFormat;
7223 pOsInterface->pfnCreateVideoNodeAssociation = Mos_Specific_CreateVideoNodeAssociation;
7224 pOsInterface->pfnDestroyVideoNodeAssociation = Mos_Specific_DestroyVideoNodeAssociation;
7225 pOsInterface->pfnGetVdboxNodeId = Mos_Specific_GetVdboxNodeId;
7226
7227 pOsInterface->pfnGetNullHWRenderFlags = Mos_Specific_GetNullHWRenderFlags;
7228 pOsInterface->pfnSetCmdBufferDebugInfo = Mos_Specific_SetCmdBufferDebugInfo;
7229 pOsInterface->pfnGetCmdBufferDebugInfo = Mos_Specific_GetCmdBufferDebugInfo;
7230
7231 pOsInterface->pfnRegisterBBCompleteNotifyEvent = Mos_Specific_RegisterBBCompleteNotifyEvent;
7232 pOsInterface->pfnWaitForBBCompleteNotifyEvent = Mos_Specific_WaitForBBCompleteNotifyEvent;
7233 pOsInterface->pfnCachePolicyGetMemoryObject = Mos_Specific_CachePolicyGetMemoryObject;
7234 pOsInterface->pfnCachePolicyGetL1Config = Mos_Specific_CachePolicyGetL1Config;
7235 pOsInterface->pfnSkipResourceSync = Mos_Specific_SkipResourceSync;
7236 pOsInterface->pfnIsGPUHung = Mos_Specific_IsGPUHung;
7237 pOsInterface->pfnGetAuxTableBaseAddr = Mos_Specific_GetAuxTableBaseAddr;
7238 pOsInterface->pfnSetSliceCount = Mos_Specific_SetSliceCount;
7239 pOsInterface->pfnGetResourceIndex = Mos_Specific_GetResourceIndex;
7240 pOsInterface->pfnGetGpuPriority = Mos_Specific_GetGpuPriority;
7241 pOsInterface->pfnSetGpuPriority = Mos_Specific_SetGpuPriority;
7242 pOsInterface->pfnIsSetMarkerEnabled = Mos_Specific_IsSetMarkerEnabled;
7243 pOsInterface->pfnGetMarkerResource = Mos_Specific_GetMarkerResource;
7244 pOsInterface->pfnNotifyStreamIndexSharing = Mos_Specific_NotifyStreamIndexSharing;
7245
7246 pOsInterface->pfnSetGpuContextHandle = Mos_Specific_SetGpuContextHandle;
7247 pOsInterface->pfnGetGpuContextbyHandle = Mos_Specific_GetGpuContextbyHandle;
7248
7249 pOsInterface->pfnGetUserSettingInstance = Mos_Specific_GetUserSettingInstance;
7250
7251 pOsInterface->pfnIsMismatchOrderProgrammingSupported = Mos_Specific_IsMismatchOrderProgrammingSupported;
7252 pOsInterface->pfnIsMultipleCodecDevicesInUse = Mos_Specific_pfnIsMultipleCodecDevicesInUse;
7253 pOsInterface->pfnSetMultiEngineEnabled = Mos_Specific_pfnSetMultiEngineEnabled;
7254 pOsInterface->pfnGetMultiEngineStatus = Mos_Specific_pfnGetMultiEngineStatus;
7255 pOsInterface->pfnGetLatestVirtualNode = Mos_Specific_pfnGetLatestVirtualNode;
7256 pOsInterface->pfnSetLatestVirtualNode = Mos_Specific_pfnSetLatestVirtualNode;
7257 pOsInterface->pfnGetDecoderVirtualNodePerStream = Mos_Specific_pfnGetDecoderVirtualNodePerStream;
7258 pOsInterface->pfnSetDecoderVirtualNodePerStream = Mos_Specific_pfnSetDecoderVirtualNodePerStream;
7259
7260 pOsInterface->pfnGetResType = GetResType;
7261 pOsInterface->pfnGetTsFrequency = Mos_Specific_GetTsFrequency;
7262 pOsInterface->pfnSetHintParams = Mos_Specific_SetHintParams;
7263 pOsInterface->pfnIsResourceReleasable = Mos_Specific_IsResourceReleasable;
7264 pOsInterface->pfnVirtualEngineInit = Mos_Specific_Virtual_Engine_Init;
7265 pOsInterface->pfnDestroyVeInterface = Mos_Specific_DestroyVeInterface;
7266 pOsInterface->pfnVirtualEngineInterfaceInitialize = Mos_VirtualEngineInterface_Initialize;
7267
7268 pOsInterface->pfnCreateCmDevice = CreateCmDevice;
7269 pOsInterface->pfnDestroyCmDevice = DestroyCmDevice;
7270 pOsInterface->pfnInitCmInterface = InitCmOsDDIInterface;
7271
7272 pOsInterface->pfnIsAsynDevice = Mos_Specific_IsAsyncDevice;
7273
7274 #if (_DEBUG || _RELEASE_INTERNAL)
7275 pOsInterface->pfnGetEngineLogicId = Mos_Specific_GetEngineLogicId;
7276 #endif
7277 pOsContext = nullptr;
7278 pOsUserFeatureInterface = (PMOS_USER_FEATURE_INTERFACE)&pOsInterface->UserFeatureInterface;
7279
7280 MOS_OS_NORMALMESSAGE("mm:Mos_Specific_InitInterface called.");
7281
7282 pOsInterface->modularizedGpuCtxEnabled = true;
7283 pOsInterface->veDefaultEnable = true;
7284 pOsInterface->phasedSubmission = true;
7285
7286 pOsInterface->apoMosEnabled = pOsDriverContext->m_apoMosEnabled;
7287 if (pOsInterface->apoMosEnabled)
7288 {
7289 MOS_OS_CHK_NULL(pOsDriverContext->m_osDeviceContext);
7290 pOsInterface->bNullHwIsEnabled = pOsDriverContext->m_osDeviceContext->GetNullHwIsEnabled();
7291 pOsInterface->streamStateIniter = true;
7292 MOS_OS_CHK_STATUS(MosInterface::CreateOsStreamState(
7293 &pOsInterface->osStreamState,
7294 (MOS_DEVICE_HANDLE)pOsDriverContext->m_osDeviceContext,
7295 (MOS_INTERFACE_HANDLE)pOsInterface,
7296 pOsInterface->Component,
7297 pOsDriverContext));
7298
7299 // Set interface functions for legacy HAL
7300 pOsContext = (PMOS_OS_CONTEXT)pOsInterface->osStreamState->perStreamParameters;
7301 MOS_OS_CHK_NULL_RETURN(pOsContext);
7302
7303 pOsContext->GetGPUTag = Linux_GetGPUTag;
7304 }
7305 else
7306 {
7307 // Create Linux OS Context
7308 pOsContext = MOS_New(MOS_OS_CONTEXT);
7309 MOS_OS_CHK_NULL_RETURN(pOsContext);
7310 }
7311
7312 if (pOsInterface->modulizedMosEnabled && !Mos_Solo_IsEnabled(nullptr))
7313 {
7314 OsContext *osContextPtr = OsContext::GetOsContextObject();
7315 if (osContextPtr == nullptr)
7316 {
7317 MOS_OS_ASSERTMESSAGE("Unable to get the active OS context.");
7318 eStatus = MOS_STATUS_INVALID_PARAMETER;
7319 goto finish;
7320 }
7321
7322 pOsInterface->osContextPtr = osContextPtr;
7323
7324 if (pOsInterface->osContextPtr->GetOsContextValid() == false)
7325 {
7326 eStatus = pOsInterface->osContextPtr->Init(pOsDriverContext);
7327 if (MOS_STATUS_SUCCESS != eStatus)
7328 {
7329 MOS_OS_ASSERTMESSAGE("Unable to initialize MODS context.");
7330 eStatus = MOS_STATUS_INVALID_PARAMETER;
7331 goto finish;
7332 }
7333 }
7334
7335 //ApoMos do it in CreateOsStreamState
7336 if (!pOsInterface->apoMosEnabled)
7337 {
7338 OsContextSpecific *pOsContextSpecific = static_cast<OsContextSpecific *>(pOsInterface->osContextPtr);
7339 pOsContext->intel_context = pOsContextSpecific->GetDrmContext();
7340 pOsContext->pGmmClientContext = pOsDriverContext->pGmmClientContext;
7341 }
7342 }
7343 else
7344 {
7345 pOsContext->pGmmClientContext = pOsDriverContext->pGmmClientContext;
7346 }
7347
7348 #if MOS_MEDIASOLO_SUPPORTED
7349 if (pOsInterface->bSoloInUse)
7350 {
7351 bSimIsActive = pOsInterface->bSimIsActive;
7352 useCustomerValue = true;
7353 }
7354 #endif
7355 #if (_DEBUG || _RELEASE_INTERNAL)
7356 ReadUserSettingForDebug(
7357 userSettingPtr,
7358 pOsInterface->bSimIsActive,
7359 __MEDIA_USER_FEATURE_VALUE_SIM_ENABLE,
7360 MediaUserSetting::Group::Device,
7361 bSimIsActive,
7362 useCustomerValue);
7363 #endif
7364 if (!pOsInterface->apoMosEnabled)
7365 {
7366 pOsContext->bSimIsActive = pOsInterface->bSimIsActive;
7367 }
7368
7369 // Initialize
7370 if (!pOsInterface->apoMosEnabled)
7371 {
7372 modularizedGpuCtxEnabled = pOsInterface->modularizedGpuCtxEnabled && !Mos_Solo_IsEnabled(pOsContext);
7373 eStatus = Linux_InitContext(pOsContext, pOsDriverContext, pOsInterface->modulizedMosEnabled && !Mos_Solo_IsEnabled(pOsContext), modularizedGpuCtxEnabled);
7374 if( MOS_STATUS_SUCCESS != eStatus )
7375 {
7376 MOS_OS_ASSERTMESSAGE("Unable to initialize context.");
7377 goto finish;
7378 }
7379
7380 pOsContext->bFreeContext = true;
7381
7382 //Added by Ben for video memory allocation
7383 pOsContext->bufmgr = pOsDriverContext->bufmgr;
7384 mos_bufmgr_enable_reuse(pOsDriverContext->bufmgr);
7385 }
7386
7387 pOsInterface->pOsContext = pOsContext;
7388
7389 pOsInterface->bUsesPatchList = true;
7390 pOsInterface->bUsesGfxAddress = false;
7391 pOsInterface->bNoParsingAssistanceInKmd = true;
7392 pOsInterface->bUsesCmdBufHeaderInResize = false;
7393 pOsInterface->bUsesCmdBufHeader = false;
7394 pOsInterface->dwNumNalUnitBytesIncluded = MOS_NAL_UNIT_LENGTH - MOS_NAL_UNIT_STARTCODE_LENGTH;
7395
7396 pOsInterface->bInlineCodecStatusUpdate = true;
7397 pOsInterface->bAllowExtraPatchToSameLoc = false;
7398
7399 pOsUserFeatureInterface->bIsNotificationSupported = false;
7400 pOsUserFeatureInterface->pOsInterface = pOsInterface;
7401
7402 pOsUserFeatureInterface->pfnEnableNotification = MosUtilities::MosUserFeatureEnableNotification;
7403 pOsUserFeatureInterface->pfnDisableNotification = MosUtilities::MosUserFeatureDisableNotification;
7404 pOsUserFeatureInterface->pfnParsePath = MosUtilities::MosUserFeatureParsePath;
7405
7406 // Init reset count for the context
7407 ret = mos_get_reset_stats(pOsInterface->pOsContext->intel_context, &dwResetCount, nullptr, nullptr);
7408 if (ret)
7409 {
7410 MOS_OS_NORMALMESSAGE("mos_get_reset_stats return error(%d)\n", ret);
7411 dwResetCount = 0;
7412 }
7413 pOsInterface->dwGPUResetCount = dwResetCount;
7414 pOsInterface->dwGPUActiveBatch = 0;
7415 pOsInterface->dwGPUPendingBatch = 0;
7416
7417 // enable it on Linux
7418 pOsInterface->bMediaReset = true;
7419 pOsInterface->trinityPath = TRINITY_DISABLED;
7420 pOsInterface->umdMediaResetEnable = true;
7421
7422 pMediaWatchdog = getenv("INTEL_MEDIA_RESET_WATCHDOG");
7423 if (pMediaWatchdog != nullptr)
7424 {
7425 watchdog = strtol(pMediaWatchdog, nullptr, 0);
7426 if (watchdog == 0)
7427 {
7428 pOsInterface->bMediaReset = false;
7429 pOsInterface->umdMediaResetEnable = false;
7430 }
7431 }
7432
7433 // Check SKU table to detect if simulation environment (HAS) is enabled
7434 pSkuTable = pOsInterface->pfnGetSkuTable(pOsInterface);
7435 MOS_OS_CHK_NULL(pSkuTable);
7436
7437 // disable Media Reset for non-xe platform who has no media reset support on Linux
7438 if(!MEDIA_IS_SKU(pSkuTable, FtrSWMediaReset))
7439 {
7440 pOsInterface->bMediaReset = false;
7441 pOsInterface->umdMediaResetEnable = false;
7442 }
7443
7444 // initialize MOS_CP interface
7445 pOsInterface->osCpInterface = Create_MosCpInterface(pOsInterface);
7446 if (pOsInterface->osCpInterface == nullptr)
7447 {
7448 MOS_OS_ASSERTMESSAGE("fail to create osCpInterface.");
7449 return MOS_STATUS_UNKNOWN;
7450 }
7451
7452 #if (_DEBUG || _RELEASE_INTERNAL)
7453 // read the "Force VDBOX" user feature key
7454 // 0: not force
7455 ReadUserSettingForDebug(
7456 userSettingPtr,
7457 pOsInterface->eForceVdbox,
7458 __MEDIA_USER_FEATURE_VALUE_FORCE_VDBOX,
7459 MediaUserSetting::Group::Device);
7460
7461 // Force TileYf/Ys
7462 // 0: Tile Y 1: Tile Yf 2 Tile Ys
7463 ReadUserSettingForDebug(
7464 userSettingPtr,
7465 pOsInterface->dwForceTileYfYs,
7466 __MEDIA_USER_FEATURE_VALUE_FORCE_YFYS,
7467 MediaUserSetting::Group::Device);
7468
7469 // Null HW Driver
7470 // 0: Disable
7471 ReadUserSettingForDebug(
7472 userSettingPtr,
7473 pOsInterface->NullHWAccelerationEnable.Value,
7474 __MEDIA_USER_FEATURE_VALUE_NULL_HW_ACCELERATION_ENABLE,
7475 MediaUserSetting::Group::Device);
7476
7477 #endif // (_DEBUG || _RELEASE_INTERNAL)
7478
7479 #if MOS_MEDIASOLO_SUPPORTED
7480 Mos_Solo_Initialize(pOsInterface);
7481 #endif // MOS_MEDIASOLO_SUPPORTED
7482 if (!pOsInterface->apoMosEnabled)
7483 {
7484 #if (_DEBUG || _RELEASE_INTERNAL)
7485 // read the "Disable KMD Watchdog" user feature key
7486 regValue = 0;
7487 ReadUserSettingForDebug(
7488 userSettingPtr,
7489 regValue,
7490 __MEDIA_USER_FEATURE_VALUE_DISABLE_KMD_WATCHDOG,
7491 MediaUserSetting::Group::Device);
7492
7493 pOsContext->bDisableKmdWatchdog = regValue ? true : false;
7494
7495 // read "Linux PerformanceTag Enable" user feature key
7496 regValue = 0;
7497 ReadUserSettingForDebug(
7498 userSettingPtr,
7499 regValue,
7500 __MEDIA_USER_FEATURE_VALUE_LINUX_PERFORMANCETAG_ENABLE,
7501 MediaUserSetting::Group::Device);
7502
7503 pOsContext->uEnablePerfTag = regValue;
7504 #endif
7505 }
7506 eStatus = Mos_Specific_InitInterface_Ve(pOsInterface);
7507 if(eStatus != MOS_STATUS_SUCCESS)
7508 {
7509 goto finish;
7510 }
7511
7512 eStatus = MOS_STATUS_SUCCESS;
7513
7514 finish:
7515 if( MOS_STATUS_SUCCESS != eStatus && nullptr != pOsContext )
7516 {
7517 MOS_Delete(pOsContext);
7518 }
7519 return eStatus;
7520 }
7521
7522 //!
7523 //! \brief Convert to MOS tile type
7524 //! \details Convert from Linux to MOS tile type
7525 //! \param uint32_t type
7526 //! [in] tile type
7527 //! \return MOS_TILE_TYPE
7528 //! Return MOS tile type
7529 //!
LinuxToMosTileType(uint32_t type)7530 MOS_TILE_TYPE LinuxToMosTileType(uint32_t type)
7531 {
7532 switch (type) {
7533 case TILING_NONE:
7534 return MOS_TILE_LINEAR;
7535 case TILING_X:
7536 return MOS_TILE_X;
7537 case TILING_Y:
7538 return MOS_TILE_Y;
7539 default:
7540 return MOS_TILE_INVALID;
7541 }
7542 };
7543
7544 //!
7545 //! \brief Get resource index
7546 //! \details Get resource index of MOS_RESOURCE
7547 //! \param PMOS_RESOURCE osResource
7548 //! [in] Pointer to OS resource
7549 //! \return uint32_t
7550 //! Resource index
7551 //!
Mos_Specific_GetResourceIndex(PMOS_RESOURCE osResource)7552 uint32_t Mos_Specific_GetResourceIndex(
7553 PMOS_RESOURCE osResource)
7554 {
7555 return 0;
7556 }
7557
Mos_Specific_GetResourcePitch(PMOS_RESOURCE pOsResource)7558 uint32_t Mos_Specific_GetResourcePitch(
7559 PMOS_RESOURCE pOsResource)
7560 {
7561 MOS_OS_FUNCTION_ENTER;
7562
7563 MOS_OS_ASSERT(pOsResource);
7564
7565 return pOsResource->iPitch;
7566 }
7567
Mos_Specific_SetResourceWidth(PMOS_RESOURCE pOsResource,uint32_t dwWidth)7568 void Mos_Specific_SetResourceWidth(
7569 PMOS_RESOURCE pOsResource,
7570 uint32_t dwWidth)
7571 {
7572 MOS_OS_FUNCTION_ENTER;
7573
7574 MOS_OS_ASSERT(pOsResource);
7575
7576 pOsResource->iWidth = dwWidth;
7577 }
7578
Mos_Specific_SetResourceFormat(PMOS_RESOURCE pOsResource,MOS_FORMAT mosFormat)7579 void Mos_Specific_SetResourceFormat(
7580 PMOS_RESOURCE pOsResource,
7581 MOS_FORMAT mosFormat)
7582 {
7583 MOS_OS_FUNCTION_ENTER;
7584
7585 MOS_OS_ASSERT(pOsResource);
7586
7587 pOsResource->Format = mosFormat;
7588 }
7589
7590 //!
7591 //! \brief Get SetMarker enabled flag
7592 //! \details Get SetMarker enabled flag from OsInterface
7593 //! \param PMOS_INTERFACE pOsInterface
7594 //! [in] OS Interface
7595 //! \return bool
7596 //! SetMarker enabled flag
7597 //!
Mos_Specific_IsSetMarkerEnabled(PMOS_INTERFACE pOsInterface)7598 bool Mos_Specific_IsSetMarkerEnabled(
7599 PMOS_INTERFACE pOsInterface)
7600 {
7601 return false;
7602 }
7603
7604 //!
7605 //! \brief Get SetMarker resource address
7606 //! \details Get SetMarker resource address from OsInterface
7607 //! \param PMOS_INTERFACE pOsInterface
7608 //! [in] OS Interface
7609 //! \return PMOS_RESOURCE
7610 //! SetMarker resource address
7611 //!
Mos_Specific_GetMarkerResource(PMOS_INTERFACE pOsInterface)7612 PMOS_RESOURCE Mos_Specific_GetMarkerResource(
7613 PMOS_INTERFACE pOsInterface)
7614 {
7615 return 0;
7616 }
7617
7618 //!
7619 //! \brief Get TimeStamp frequency base
7620 //! \details Get TimeStamp frequency base from OsInterface
7621 //! \param PMOS_INTERFACE pOsInterface
7622 //! [in] OS Interface
7623 //! \return uint32_t
7624 //! time stamp frequency base
7625 //!
Mos_Specific_GetTsFrequency(PMOS_INTERFACE osInterface)7626 uint32_t Mos_Specific_GetTsFrequency(PMOS_INTERFACE osInterface)
7627 {
7628 uint32_t freq = 0;
7629 int ret = mos_get_ts_frequency(osInterface->pOsContext->bufmgr, &freq);
7630 if(ret == 0)
7631 {
7632 return freq;
7633 }
7634 else
7635 {
7636 // fail to query it from KMD
7637 return 0;
7638 }
7639 }
7640
7641 //!
7642 //! \brief Checks whether the requested resource is releasable
7643 //! \param PMOS_INTERFACE pOsInterface
7644 //! [in] OS Interface
7645 //! \param PMOS_RESOURCE pOsResource
7646 //! [in] Pointer to OS Resource
7647 //! \return MOS_STATUS
7648 //! MOS_STATUS_SUCCESS if requested can be released, otherwise MOS_STATUS_UNKNOWN
7649 //!
Mos_Specific_IsResourceReleasable(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource)7650 MOS_STATUS Mos_Specific_IsResourceReleasable(
7651 PMOS_INTERFACE pOsInterface,
7652 PMOS_RESOURCE pOsResource)
7653 {
7654 return MOS_STATUS_SUCCESS;
7655 }
7656
Mos_GetDeviceUfPathInfo(PMOS_CONTEXT mosContext)7657 MOS_USER_FEATURE_KEY_PATH_INFO *Mos_GetDeviceUfPathInfo(
7658 PMOS_CONTEXT mosContext)
7659 {
7660 MOS_UNUSED(mosContext);
7661 //NOT IMPLEMENTED
7662 return nullptr;
7663 }
7664
7665 #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
7666 struct GpuCmdResInfoDump::GpuCmdResInfo
7667 {
7668 int32_t iWidth;
7669 int32_t iHeight;
7670 int32_t iSize;
7671 int32_t iPitch;
7672 int32_t iDepth;
7673 MOS_FORMAT Format;
7674 int32_t iCount;
7675 int32_t iAllocationIndex[MOS_GPU_CONTEXT_MAX];
7676 uint32_t dwGfxAddress;
7677 const char *bufname;
7678 uint32_t isTiled;
7679 MOS_TILE_TYPE TileType;
7680 uint32_t bMapped;
7681 uint32_t name;
7682 uint64_t user_provided_va;
7683 bool bConvertedFromDDIResource;
7684 };
7685
StoreCmdResPtr(PMOS_INTERFACE pOsInterface,const void * pRes)7686 void GpuCmdResInfoDump::StoreCmdResPtr(PMOS_INTERFACE pOsInterface, const void *pRes) const
7687 {
7688 if (!m_dumpEnabled)
7689 {
7690 return;
7691 }
7692 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
7693 MOS_OS_ASSERT(gpuContext != nullptr);
7694
7695 auto pResTmp1 = (const MOS_RESOURCE *)(pRes);
7696 auto pResTmp2 = (GpuCmdResInfo *)MOS_AllocMemory(sizeof(GpuCmdResInfo));
7697
7698 pResTmp2->iWidth = pResTmp1->iWidth;
7699 pResTmp2->iHeight = pResTmp1->iHeight;
7700 pResTmp2->iSize = pResTmp1->iSize;
7701 pResTmp2->iPitch = pResTmp1->iPitch;
7702 pResTmp2->iDepth = pResTmp1->iDepth;
7703 pResTmp2->Format = pResTmp1->Format;
7704 pResTmp2->iCount = pResTmp1->iCount;
7705 for (auto i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
7706 {
7707 pResTmp2->iAllocationIndex[i] = pResTmp1->iAllocationIndex[i];
7708 }
7709 pResTmp2->dwGfxAddress = pResTmp1->dwGfxAddress;
7710 pResTmp2->bufname = pResTmp1->bufname;
7711 pResTmp2->isTiled = pResTmp1->isTiled;
7712 pResTmp2->TileType = pResTmp1->TileType;
7713 pResTmp2->bMapped = pResTmp1->bMapped;
7714 pResTmp2->name = pResTmp1->name;
7715 pResTmp2->user_provided_va = pResTmp1->user_provided_va;
7716 pResTmp2->bConvertedFromDDIResource = pResTmp1->bConvertedFromDDIResource;
7717
7718 gpuContext->PushCmdResPtr((const void *)pResTmp2);
7719 }
7720
ClearCmdResPtrs(PMOS_INTERFACE pOsInterface)7721 void GpuCmdResInfoDump::ClearCmdResPtrs(PMOS_INTERFACE pOsInterface) const
7722 {
7723 if (!m_dumpEnabled)
7724 {
7725 return;
7726 }
7727
7728 auto gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
7729 MOS_OS_ASSERT(gpuContext != nullptr);
7730
7731 auto &cmdResInfoPtrs = gpuContext->GetCmdResPtrs();
7732
7733 for (auto e : cmdResInfoPtrs)
7734 {
7735 MOS_FreeMemory((void *)e);
7736 }
7737
7738 gpuContext->ClearCmdResPtrs();
7739 }
7740
Dump(const void * cmdResInfoPtr,std::ofstream & outputFile)7741 void GpuCmdResInfoDump::Dump(const void *cmdResInfoPtr, std::ofstream &outputFile) const
7742 {
7743 using std::endl;
7744
7745 auto pRes = (const GpuCmdResInfo *)(cmdResInfoPtr);
7746
7747 outputFile << "Gpu Resource Pointer : " << pRes << endl;
7748 outputFile << "iWidth : " << pRes->iWidth << endl;
7749 outputFile << "iHeight : " << pRes->iHeight << endl;
7750 outputFile << "iSize : " << pRes->iSize << endl;
7751 outputFile << "iPitch : " << pRes->iPitch << endl;
7752 outputFile << "iDepth : " << pRes->iDepth << endl;
7753 outputFile << "Format : " << (int32_t)pRes->Format << endl;
7754 outputFile << "iCount : " << pRes->iCount << endl;
7755 outputFile << "iAllocationIndex : ";
7756 for (auto i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
7757 {
7758 outputFile << pRes->iAllocationIndex[i] << " ";
7759 }
7760 outputFile << endl;
7761 outputFile << "dwGfxAddress : " << pRes->dwGfxAddress << endl;
7762 outputFile << "bufname : " << pRes->bufname << endl;
7763 outputFile << "isTiled : " << pRes->isTiled << endl;
7764 outputFile << "TileType : " << GetTileType(pRes->TileType) << endl;
7765 outputFile << "bMapped : " << pRes->bMapped << endl;
7766 outputFile << "name : " << pRes->name << endl;
7767 outputFile << "user_provided_va : " << pRes->user_provided_va << endl;
7768 outputFile << "bConvertedFromDDIResource : " << pRes->bConvertedFromDDIResource << endl;
7769 outputFile << endl;
7770 }
7771
GetCmdResPtrs(PMOS_INTERFACE pOsInterface)7772 const std::vector<const void *> &GpuCmdResInfoDump::GetCmdResPtrs(PMOS_INTERFACE pOsInterface) const
7773 {
7774 const auto *gpuContext = Linux_GetGpuContext(pOsInterface, pOsInterface->CurrentGpuContextHandle);
7775 MOS_OS_ASSERT(gpuContext != nullptr);
7776
7777 return gpuContext->GetCmdResPtrs();
7778 }
7779 #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
7780
Mos_Specific_Virtual_Engine_Init(PMOS_INTERFACE pOsInterface,PMOS_VIRTUALENGINE_HINT_PARAMS * veHitParams,MOS_VIRTUALENGINE_INIT_PARAMS & veInParams)7781 MOS_STATUS Mos_Specific_Virtual_Engine_Init(
7782 PMOS_INTERFACE pOsInterface,
7783 PMOS_VIRTUALENGINE_HINT_PARAMS* veHitParams,
7784 MOS_VIRTUALENGINE_INIT_PARAMS& veInParams)
7785 {
7786 MOS_OS_CHK_NULL_RETURN(pOsInterface);
7787 if (pOsInterface->apoMosEnabled)
7788 {
7789 MOS_OS_CHK_NULL_RETURN(pOsInterface->osStreamState);
7790 MOS_VE_HANDLE veState = nullptr;
7791 MOS_OS_CHK_STATUS_RETURN(MosInterface::CreateVirtualEngineState(
7792 pOsInterface->osStreamState, &veInParams, veState));
7793
7794 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetVeHintParams(pOsInterface->osStreamState, veInParams.bScalabilitySupported, veHitParams));
7795 }
7796 else
7797 {
7798 MOS_OS_CHK_STATUS_RETURN(Mos_VirtualEngineInterface_Initialize(pOsInterface, &veInParams));
7799 PMOS_VIRTUALENGINE_INTERFACE veInterface = pOsInterface->pVEInterf;
7800 MOS_OS_CHK_NULL_RETURN(veInterface);
7801 if (veInterface->pfnVEGetHintParams)
7802 {
7803 MOS_OS_CHK_STATUS_RETURN(veInterface->pfnVEGetHintParams(veInterface, veInParams.bScalabilitySupported, veHitParams));
7804 }
7805 }
7806
7807 return MOS_STATUS_SUCCESS;
7808 }
7809
Mos_Specific_SetHintParams(PMOS_INTERFACE pOsInterface,PMOS_VIRTUALENGINE_SET_PARAMS veParams)7810 MOS_STATUS Mos_Specific_SetHintParams(
7811 PMOS_INTERFACE pOsInterface,
7812 PMOS_VIRTUALENGINE_SET_PARAMS veParams)
7813 {
7814 MOS_OS_FUNCTION_ENTER;
7815 MOS_OS_CHK_NULL_RETURN(pOsInterface);
7816 if (pOsInterface->apoMosEnabled)
7817 {
7818 MOS_OS_CHK_NULL_RETURN(pOsInterface->osStreamState);
7819 MOS_OS_CHK_STATUS_RETURN(MosInterface::SetVeHintParams(pOsInterface->osStreamState, veParams));
7820 }
7821 else
7822 {
7823 PMOS_VIRTUALENGINE_INTERFACE veInterface = pOsInterface->pVEInterf;
7824 MOS_OS_CHK_NULL_RETURN(veInterface);
7825 if (veInterface->pfnVESetHintParams)
7826 {
7827 MOS_OS_CHK_STATUS_RETURN(veInterface->pfnVESetHintParams(veInterface, veParams));
7828 }
7829 }
7830
7831 return MOS_STATUS_SUCCESS;
7832 }
7833
Mos_Specific_DestroyVeInterface(PMOS_VIRTUALENGINE_INTERFACE * veInterface)7834 MOS_STATUS Mos_Specific_DestroyVeInterface(
7835 PMOS_VIRTUALENGINE_INTERFACE *veInterface)
7836 {
7837 MOS_OS_FUNCTION_ENTER;
7838 if (*veInterface)
7839 {
7840 if ((*veInterface)->pfnVEDestroy)
7841 {
7842 (*veInterface)->pfnVEDestroy(*veInterface);
7843 }
7844 MOS_FreeMemAndSetNull(*veInterface);
7845 }
7846
7847 return MOS_STATUS_SUCCESS;
7848 }
7849
7850 #if (_DEBUG || _RELEASE_INTERNAL)
Mos_Specific_GetEngineLogicId(PMOS_INTERFACE pOsInterface,uint8_t & id)7851 MOS_STATUS Mos_Specific_GetEngineLogicId(
7852 PMOS_INTERFACE pOsInterface,
7853 uint8_t& id)
7854 {
7855 if (pOsInterface->apoMosEnabled)
7856 {
7857 if (MosInterface::GetVeEngineCount(pOsInterface->osStreamState) != 1)
7858 {
7859 MOS_OS_ASSERTMESSAGE("VeEngineCount is not equal to 1.");
7860 }
7861 id = MosInterface::GetEngineLogicId(pOsInterface->osStreamState, 0);
7862 }
7863 else
7864 {
7865 PMOS_VIRTUALENGINE_INTERFACE veInterface = pOsInterface->pVEInterf;
7866 if (veInterface->ucEngineCount != 1)
7867 {
7868 MOS_OS_ASSERTMESSAGE("ucEngineCount is not equal to 1.");
7869 }
7870 id = veInterface->EngineLogicId[0];
7871 }
7872
7873 return MOS_STATUS_SUCCESS;
7874 }
7875 #endif
7876