1 /*
2 * Copyright (c) 2022-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 <cstdlib>
29 #include <dlfcn.h>
30
31 #include "mos_os.h"
32 #include "mos_util_debug.h"
33 #include "mos_resource_defs.h"
34 #include "hwinfo_linux.h"
35
36 #include "mos_graphicsresource_next.h"
37 #include "mos_context_specific_next.h"
38 #include "mos_gpucontext_specific_next.h"
39 #include "mos_gpucontextmgr_next.h"
40 #include "mos_interface.h"
41
42 #if MOS_MEDIASOLO_SUPPORTED
43 #include "mos_os_solo.h"
44 #endif // MOS_MEDIASOLO_SUPPORTED
45 #include "mos_solo_generic.h"
46
47
48 #include "mos_os_virtualengine_singlepipe_next.h"
49 #include "mos_os_virtualengine_scalability_next.h"
50
51 #include "memory_policy_manager.h"
52 #include "mos_oca_interface_specific.h"
53 #include "mos_os_next.h"
54 #include "mos_os_cp_interface_specific.h"
55
56 //!
57 //! \brief DRM VMAP patch
58 //!
59 #define Y_TILE_WIDTH 128
60 #define Y_TILE_HEIGHT 32
61 #define X_TILE_WIDTH 512
62 #define X_TILE_HEIGHT 8
63
64 #define MI_BATCHBUFFER_END 0x05000000
65
66 //!
67 //! \brief Two VDBOX shared memory key
68 //!
69 #define DUAL_VDBOX_KEY ('D'<<24|'V'<<8|'X'<<0)
70
71 //============= PRIVATE FUNCTIONS <BEGIN>=========================================
72
SetupMediaSoloSwitch()73 bool SetupMediaSoloSwitch()
74 {
75 bool mediaSoloEnabled = false;
76 MosUtilities::MosReadMediaSoloEnabledUserFeature(mediaSoloEnabled);
77 return mediaSoloEnabled;
78 }
79
80 //!
81 //! \brief Clear Gpu Context
82 //! \details OS GPU context clear
83 //! \param PMOS_RESOURCE context
84 //! [in] Pointer to OS context
85 //! \return void
86 //! Return NONE
87 //!
Mos_Specific_ClearGpuContext(MOS_CONTEXT * context)88 void Mos_Specific_ClearGpuContext(MOS_CONTEXT *context)
89 {
90 int32_t iLoop = 0;
91
92 MOS_OS_FUNCTION_ENTER;
93
94 MOS_OS_CHK_NULL_NO_STATUS_RETURN(context);
95
96 for (iLoop = 0; iLoop < MOS_GPU_CONTEXT_MAX; iLoop++)
97 {
98 if (context->OsGpuContext[iLoop].pCB != nullptr)
99 {
100 MOS_FreeMemory(context->OsGpuContext[iLoop].pCB);
101 context->OsGpuContext[iLoop].pCB = nullptr;
102 }
103
104 if (context->OsGpuContext[iLoop].pAllocationList != nullptr)
105 {
106 MOS_FreeMemory(context->OsGpuContext[iLoop].pAllocationList);
107 context->OsGpuContext[iLoop].pAllocationList = nullptr;
108 }
109
110 if (context->OsGpuContext[iLoop].pPatchLocationList)
111 {
112 MOS_FreeMemory(context->OsGpuContext[iLoop].pPatchLocationList);
113 context->OsGpuContext[iLoop].pPatchLocationList = nullptr;
114 }
115
116 if (context->OsGpuContext[iLoop].pResources != nullptr)
117 {
118 MOS_FreeMemory(context->OsGpuContext[iLoop].pResources);
119 context->OsGpuContext[iLoop].pResources = nullptr;
120 }
121
122 if (context->OsGpuContext[iLoop].pbWriteMode != nullptr)
123 {
124 MOS_FreeMemory(context->OsGpuContext[iLoop].pbWriteMode);
125 context->OsGpuContext[iLoop].pbWriteMode = nullptr;
126 }
127
128 context->OsGpuContext[iLoop].uiMaxNumAllocations = 0;
129 context->OsGpuContext[iLoop].uiMaxPatchLocationsize = 0;
130 }
131 }
132
133 //!
134 //! \brief Unified OS get command buffer
135 //! \details Return the pointer to the next available space in Cmd Buffer
136 //! \param PMOS_CONTEXT osContext
137 //! [in] Pointer to OS Context
138 //! \param PMOS_COMMAND_BUFFER cmdBuffer
139 //! [out] Pointer to Command Buffer
140 //! \param int32_t iSize
141 //! [out] Size of command in bytes
142 //! \return int32_t
143 //! Return true is there is space
144 //!
Linux_GetCommandBuffer(PMOS_CONTEXT osContext,PMOS_COMMAND_BUFFER cmdBuffer,int32_t size)145 int32_t Linux_GetCommandBuffer(
146 PMOS_CONTEXT osContext,
147 PMOS_COMMAND_BUFFER cmdBuffer,
148 int32_t size)
149 {
150 MOS_LINUX_BO *cmd_bo = nullptr;
151
152 if ( osContext == nullptr ||
153 cmdBuffer == nullptr)
154 {
155 MOS_OS_ASSERTMESSAGE("Linux_GetCommandBuffer:osContext == nullptr || cmdBuffer == NULL");
156 return false;
157 }
158
159 // Allocate the command buffer from GEM
160 struct mos_drm_bo_alloc alloc;
161 alloc.name = "MOS CmdBuf";
162 alloc.size = size;
163 alloc.alignment = 4096;
164 alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
165 cmd_bo = mos_bo_alloc(osContext->bufmgr, &alloc); // Align to page boundary
166 MOS_OS_CHK_NULL_RETURN_VALUE(cmd_bo, false);
167
168 //MOS_OS_NORMALMESSAGE("alloc CMB, bo is 0x%x.", cmd_bo);
169
170 // Map command buffer to user virtual address
171 if (mos_bo_map(cmd_bo,1) != 0) // Write enable set
172 {
173 MOS_OS_ASSERTMESSAGE("Mapping of command buffer failed.");
174 mos_bo_unreference(cmd_bo);
175 return false;
176 }
177
178 Mos_ResetResource(&cmdBuffer->OsResource);
179
180 // Fill in resource information
181 cmdBuffer->OsResource.Format = Format_Buffer;
182 cmdBuffer->OsResource.iWidth = cmd_bo->size;
183 cmdBuffer->OsResource.iHeight = 1;
184 cmdBuffer->OsResource.iPitch = cmd_bo->size;
185 cmdBuffer->OsResource.iSize = cmdBuffer->OsResource.iPitch * cmdBuffer->OsResource.iHeight;
186 cmdBuffer->OsResource.iCount = 1;
187 cmdBuffer->OsResource.pData = (uint8_t*)cmd_bo->virt;
188 cmdBuffer->OsResource.TileType = MOS_TILE_LINEAR;
189 cmdBuffer->OsResource.bo = cmd_bo;
190 cmdBuffer->OsResource.bMapped = true;
191
192 // for MOS wrapper to avoid memory leak
193 cmdBuffer->OsResource.bConvertedFromDDIResource = true;
194
195 cmdBuffer->pCmdBase = (uint32_t*)cmd_bo->virt;
196 cmdBuffer->pCmdPtr = (uint32_t*)cmd_bo->virt;
197 cmdBuffer->iOffset = 0;
198 cmdBuffer->iRemaining = cmd_bo->size;
199 cmdBuffer->iCmdIndex = -1;
200 cmdBuffer->iVdboxNodeIndex = MOS_VDBOX_NODE_INVALID;
201 cmdBuffer->iVeboxNodeIndex = MOS_VEBOX_NODE_INVALID;
202 cmdBuffer->is1stLvlBB = true;
203 MOS_ZeroMemory(cmdBuffer->pCmdBase, cmd_bo->size);
204 cmdBuffer->iSubmissionType = SUBMISSION_TYPE_SINGLE_PIPE;
205 MOS_ZeroMemory(&cmdBuffer->Attributes, sizeof(cmdBuffer->Attributes));
206
207 return true;
208 }
209
210 //!
211 //! \brief Get unused command buffer space
212 //! \details Return unused command buffer space
213 //! \param PMOS_CONTEXT osContext
214 //! [in] Pointer to OS Context
215 //! \param MOS_GPU_CONTEXT gpuContext
216 //! [in] GPU context
217 //! \param PMOS_COMMAND_BUFFER cmdBuffer
218 //! [out] Pointer to Command buffer
219 //! \return void
220 //!
Linux_ReturnCommandBuffer(PMOS_CONTEXT osContext,MOS_GPU_CONTEXT gpuContext,PMOS_COMMAND_BUFFER cmdBuffer)221 void Linux_ReturnCommandBuffer(
222 PMOS_CONTEXT osContext,
223 MOS_GPU_CONTEXT gpuContext,
224 PMOS_COMMAND_BUFFER cmdBuffer)
225 {
226 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osContext);
227 MOS_OS_CHK_NULL_NO_STATUS_RETURN(cmdBuffer);
228
229 if (Mos_ResourceIsNull(&(cmdBuffer->OsResource)))
230 {
231 MOS_OS_ASSERTMESSAGE("Invalid input parameter osContext or cmdBuffer.");
232 return;
233 }
234
235 if (gpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
236 {
237 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
238 return;
239 }
240
241 MOS_OS_GPU_CONTEXT &osGpuContext = osContext->OsGpuContext[gpuContext];
242
243 osGpuContext.pCB->iOffset = cmdBuffer->iOffset;
244 osGpuContext.pCB->iRemaining = cmdBuffer->iRemaining;
245 osGpuContext.pCB->pCmdPtr = cmdBuffer->pCmdPtr;
246 osGpuContext.pCB->iVdboxNodeIndex = cmdBuffer->iVdboxNodeIndex;
247 osGpuContext.pCB->iVeboxNodeIndex = cmdBuffer->iVeboxNodeIndex;
248 osGpuContext.pCB->is1stLvlBB = cmdBuffer->is1stLvlBB;
249
250 return;
251 }
252
253 //!
254 //! \brief Flush Command Buffer
255 //! \details Flush Command Buffer space
256 //! \param PMOS_CONTEXT osContext
257 //! [in] Pointer to OS Context
258 //! \param MOS_GPU_CONTEXT gpucontext
259 //! [in] GPU context
260 //! \return int32_t
261 //! true if succeeded, false if failed or invalid parameters
262 //!
Linux_FlushCommandBuffer(PMOS_CONTEXT osContext,MOS_GPU_CONTEXT gpucontext)263 int32_t Linux_FlushCommandBuffer(
264 PMOS_CONTEXT osContext,
265 MOS_GPU_CONTEXT gpucontext)
266 {
267 PCOMMAND_BUFFER currCB;
268
269 MOS_OS_CHK_NULL_RETURN_VALUE(osContext, false);
270
271 if (gpucontext == MOS_GPU_CONTEXT_INVALID_HANDLE)
272 {
273 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpucontext.");
274 return false;
275 }
276
277 MOS_OS_GPU_CONTEXT &osGpuContext = osContext->OsGpuContext[gpucontext];
278
279 osGpuContext.uiCurrentNumPatchLocations = 0;
280
281 // CB already active
282 currCB = osGpuContext.pCurrentCB;
283 MOS_OS_CHK_NULL_RETURN_VALUE(currCB, false);
284
285 if (currCB->bActive)
286 {
287 return false;
288 }
289
290 currCB->bActive = true;
291 return true;
292 }
293
294 //!
295 //! \brief Init command buffer pool
296 //! \details Initilize the command buffer pool
297 //! \param PMOS_CONTEXT osContext
298 //! [in] Pointer to OS Context
299 //! \return void
300 //!
Linux_InitCmdBufferPool(PMOS_CONTEXT osContext)301 void Linux_InitCmdBufferPool(
302 PMOS_CONTEXT osContext)
303 {
304 MOS_OS_FUNCTION_ENTER;
305 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osContext);
306
307 MOS_ZeroMemory(&osContext->CmdBufferPool, sizeof(CMD_BUFFER_BO_POOL));
308 osContext->CmdBufferPool.iFetch = 0;
309 }
310
311 //!
312 //! \brief Wait and release command buffer
313 //! \details Command buffer Wait and release
314 //! \param PMOS_CONTEXT osContext
315 //! [in] Pointer to OS context structure
316 //! \param int32_t index
317 //! [in] Command buffer's index in Command buffer pool
318 //! \return MOS_STATUS
319 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
320 //!
Linux_WaitAndReleaseCmdBuffer(PMOS_CONTEXT osContext,int32_t index)321 MOS_STATUS Linux_WaitAndReleaseCmdBuffer(
322 PMOS_CONTEXT osContext,
323 int32_t index)
324 {
325 MOS_LINUX_BO *cmd_bo;
326
327 MOS_OS_FUNCTION_ENTER;
328
329 MOS_OS_CHK_NULL_RETURN(osContext);
330
331 if (index < 0 || index >= MAX_CMD_BUF_NUM)
332 {
333 return MOS_STATUS_INVALID_PARAMETER;
334 }
335
336 // According to the logic of CmdBufferPool now, the command buffer is used in a circular way.
337 // The input index always points to the next(oldest) buffer after the latest(newest) buffer.
338 // If the next buffer is not empty (!= nullptr), all the buffers in the pool will also be not empty.
339 // So it's not necessary to check all buffers to see whether there's empty buffer.
340 cmd_bo = osContext->CmdBufferPool.pCmd_bo[index];
341 if (cmd_bo != nullptr)
342 {
343 mos_bo_wait_rendering(cmd_bo);
344 mos_bo_unreference(cmd_bo);
345 osContext->CmdBufferPool.pCmd_bo[index] = nullptr;
346 }
347
348 return MOS_STATUS_SUCCESS;
349 }
350
351 //!
352 //! \brief Release command buffer pool
353 //! \details Release command buffer pool until all of commands are finished.
354 //! \param PMOS_CONTEXT osContext
355 //! [in] Pointer to OS context structure
356 //! \return MOS_STATUS
357 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
358 //!
Linux_ReleaseCmdBufferPool(PMOS_CONTEXT osContext)359 MOS_STATUS Linux_ReleaseCmdBufferPool(PMOS_CONTEXT osContext)
360 {
361 MOS_OS_FUNCTION_ENTER;
362
363 for (int32_t i = 0; i < MAX_CMD_BUF_NUM; i++)
364 {
365 MOS_OS_CHK_STATUS_RETURN(Linux_WaitAndReleaseCmdBuffer(osContext, i));
366 }
367 return MOS_STATUS_SUCCESS;
368 }
369
370 //!
371 //! \brief Wait for the fetch command
372 //! \details Wait for the fetch command bo until it is available
373 //! \param PMOS_CONTEXT osContext
374 //! [in] Pointer to OS context structure
375 //! \return MOS_STATUS
376 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
377 //!
Linux_WaitForAvailableCmdBo(PMOS_CONTEXT osContext)378 MOS_STATUS Linux_WaitForAvailableCmdBo(
379 PMOS_CONTEXT osContext)
380 {
381 int32_t index = 0;
382
383 MOS_OS_FUNCTION_ENTER;
384
385 MOS_OS_CHK_NULL_RETURN(osContext);
386
387 index = osContext->CmdBufferPool.iFetch;
388 MOS_OS_CHK_STATUS_RETURN(Linux_WaitAndReleaseCmdBuffer(osContext, index));
389
390 return MOS_STATUS_SUCCESS;
391 }
392
393 //!
394 //! \brief Insert command buffer
395 //! \details Insert command buffer into pool
396 //! \param PMOS_CONTEXT osContext
397 //! [in] Pointer to OS context structure
398 //! \param PMOS_COMMAND_BUFFER cmdBuffer
399 //! [in] Pointer to command buffer struct
400 //! \return MOS_STATUS
401 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
402 //!
Linux_InsertCmdBufferToPool(PMOS_CONTEXT osContext,PMOS_COMMAND_BUFFER cmdBuffer)403 MOS_STATUS Linux_InsertCmdBufferToPool(
404 PMOS_CONTEXT osContext,
405 PMOS_COMMAND_BUFFER cmdBuffer)
406 {
407 int32_t index = 0;
408
409 MOS_OS_FUNCTION_ENTER;
410
411 MOS_OS_CHK_NULL_RETURN(osContext);
412 MOS_OS_CHK_NULL_RETURN(cmdBuffer);
413 MOS_OS_CHK_STATUS_RETURN(Linux_WaitForAvailableCmdBo(osContext));
414
415 index = osContext->CmdBufferPool.iFetch;
416
417 osContext->CmdBufferPool.pCmd_bo[index] = cmdBuffer->OsResource.bo;
418 cmdBuffer->iCmdIndex = index;
419
420 osContext->CmdBufferPool.iFetch++;
421 if (osContext->CmdBufferPool.iFetch >= MAX_CMD_BUF_NUM)
422 {
423 osContext->CmdBufferPool.iFetch = 0;
424 }
425
426 return MOS_STATUS_SUCCESS;
427 }
428
429 //!
430 //! \brief Initialize the GPU Status Buffer
431 //! \details Initialize the GPU Status Buffer
432 //! \param MOS_CONTEXT * osContext
433 //! [in, out] Pointer to OS context structure
434 //! \return MOS_STATUS
435 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
436 //!
Linux_InitGPUStatus(PMOS_CONTEXT osContext)437 MOS_STATUS Linux_InitGPUStatus(
438 PMOS_CONTEXT osContext)
439 {
440 MOS_LINUX_BO *bo = nullptr;
441
442 MOS_OS_CHK_NULL_RETURN(osContext);
443
444 osContext->pGPUStatusBuffer =
445 (MOS_RESOURCE*)MOS_AllocAndZeroMemory(sizeof(MOS_RESOURCE) * MOS_GPU_CONTEXT_MAX);
446
447 MOS_OS_CHK_NULL_RETURN(osContext->pGPUStatusBuffer);
448
449 // Allocate the command buffer from GEM
450 struct mos_drm_bo_alloc alloc;
451 alloc.name = "GPU Status Buffer";
452 alloc.size = sizeof(MOS_GPU_STATUS_DATA) * MOS_GPU_CONTEXT_MAX;
453 alloc.alignment = 4096;
454 alloc.ext.mem_type = MOS_MEMPOOL_SYSTEMMEMORY;
455 bo = mos_bo_alloc(osContext->bufmgr, &alloc); // Align to page boundary
456 if (bo == nullptr)
457 {
458 MOS_OS_ASSERTMESSAGE("Allocation of GPU Status Buffer failed.");
459 MOS_FreeMemAndSetNull(osContext->pGPUStatusBuffer);
460 return MOS_STATUS_NO_SPACE;
461 }
462
463 // Map command buffer to user virtual address
464 if (mos_bo_map(bo, 1) != 0) // Write enable set
465 {
466 MOS_OS_ASSERTMESSAGE("Mapping of GPU Status Buffer failed.");
467 mos_bo_unreference(bo);
468 MOS_FreeMemAndSetNull(osContext->pGPUStatusBuffer);
469 return MOS_STATUS_INVALID_HANDLE;
470 }
471
472 Mos_ResetResource(osContext->pGPUStatusBuffer);
473
474 // Fill in resource information
475 osContext->pGPUStatusBuffer->Format = Format_Buffer;
476 osContext->pGPUStatusBuffer->iWidth = bo->size;
477 osContext->pGPUStatusBuffer->iHeight = 1;
478 osContext->pGPUStatusBuffer->iPitch = bo->size;
479 osContext->pGPUStatusBuffer->iCount = 1;
480 osContext->pGPUStatusBuffer->pData = (uint8_t*)bo->virt;
481 osContext->pGPUStatusBuffer->TileType = MOS_TILE_LINEAR;
482 osContext->pGPUStatusBuffer->bo = bo;
483 osContext->pGPUStatusBuffer->bMapped = true;
484
485 MOS_ZeroMemory(osContext->pGPUStatusBuffer->pData, bo->size);
486
487 return MOS_STATUS_SUCCESS;
488 }
489
490 //!
491 //! \brief Release the GPU Status Buffer
492 //! \details Release the GPU Status Buffer
493 //! \param MOS_CONTEXT * osContext
494 //! [in, out] Pointer to OS context structure
495 //! \return void
496 //!
Linux_ReleaseGPUStatus(PMOS_CONTEXT osContext)497 void Linux_ReleaseGPUStatus(
498 PMOS_CONTEXT osContext)
499 {
500 MOS_LINUX_BO *bo = nullptr;
501
502 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osContext);
503 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osContext->pGPUStatusBuffer);
504
505 bo = osContext->pGPUStatusBuffer->bo;
506 if (bo != nullptr)
507 {
508 mos_bo_unmap(bo);
509 mos_bo_wait_rendering(bo);
510 mos_bo_unreference(bo);
511 }
512 osContext->pGPUStatusBuffer->bo = nullptr;
513
514 MOS_FreeMemAndSetNull(osContext->pGPUStatusBuffer);
515 }
516
517 //!
518 //! \brief Get GPU status tag for the given GPU context
519 //! \details Get GPU status tag for the given GPU context
520 //! \param MOS_CONTEXT * osContext
521 //! [in] Pointer to OS context structure
522 //! \param MOS_GPU_CONTEXT gpuContext
523 //! [in, out] GPU Context
524 //! \return uint32_t
525 //! GPU status tag
526 //!
Linux_GetGpuCtxBufferTag(PMOS_CONTEXT osContext,MOS_GPU_CONTEXT gpuContext)527 uint32_t Linux_GetGpuCtxBufferTag(
528 PMOS_CONTEXT osContext,
529 MOS_GPU_CONTEXT gpuContext)
530 {
531 MOS_OS_CHK_NULL_RETURN_VALUE(osContext, 0);
532
533 if (gpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
534 {
535 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
536 return 0;
537 }
538
539 return osContext->OsGpuContext[gpuContext].uiGPUStatusTag;
540 }
541
542 //!
543 //! \brief Increment GPU status tag for the given GPU context
544 //! \details Increment GPU status tag for the given GPU context
545 //! \param MOS_CONTEXT * osContext
546 //! [in] Pointer to OS context structure
547 //! \param MOS_GPU_CONTEXT gpuContext
548 //! [in] GPU Context
549 //! \return void
550 //!
Linux_IncGpuCtxBufferTag(PMOS_CONTEXT osContext,MOS_GPU_CONTEXT gpuContext)551 void Linux_IncGpuCtxBufferTag(
552 PMOS_CONTEXT osContext,
553 MOS_GPU_CONTEXT gpuContext)
554 {
555 uint32_t uiGPUStatusTag;
556
557 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osContext);
558
559 if (gpuContext == MOS_GPU_CONTEXT_INVALID_HANDLE)
560 {
561 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
562 return;
563 }
564
565 uiGPUStatusTag = osContext->OsGpuContext[gpuContext].uiGPUStatusTag;
566
567 osContext->OsGpuContext[gpuContext].uiGPUStatusTag = uiGPUStatusTag % UINT_MAX + 1;
568 if (osContext->OsGpuContext[gpuContext].uiGPUStatusTag == 0)
569 {
570 osContext->OsGpuContext[gpuContext].uiGPUStatusTag = 1;
571 }
572 }
573
574 //!
575 //! \brief Get Buffer Type
576 //! \details Returns the type of buffer, 1D, 2D or volume
577 //! \param PMOS_RESOURCE osResource
578 //! [in] Pointer to OS Resource
579 //! \return GFX resource Type
580 //!
GetResType(PMOS_RESOURCE osResource)581 MOS_GFXRES_TYPE GetResType(PMOS_RESOURCE osResource)
582 {
583 GMM_RESOURCE_INFO *gmmResourceInfo = nullptr;
584 MOS_GFXRES_TYPE resType = MOS_GFXRES_INVALID;
585 GMM_RESOURCE_TYPE gmmResType = RESOURCE_INVALID;
586
587 MOS_OS_CHK_NULL_RETURN_VALUE(osResource, MOS_GFXRES_INVALID);
588
589 gmmResourceInfo = (GMM_RESOURCE_INFO *)osResource->pGmmResInfo;
590 MOS_OS_CHK_NULL_RETURN_VALUE(gmmResourceInfo, MOS_GFXRES_INVALID);
591 gmmResType = gmmResourceInfo->GetResourceType();
592
593 switch (gmmResType)
594 {
595 case RESOURCE_BUFFER:
596 resType = MOS_GFXRES_BUFFER;
597 break;
598 case RESOURCE_3D:
599 resType = MOS_GFXRES_VOLUME;
600 break;
601 case RESOURCE_2D:
602 resType = MOS_GFXRES_2D;
603 break;
604 default:
605 break;
606 }
607 return resType;
608 }
609
610 //!
611 //! \brief Init Linux context
612 //! \details Initialize the linux context
613 //! \param MOS_OS_CONTEXT * context
614 //! [in] Pointer to OS context structure
615 //! \param PMOS_CONTEXT osDriverContext
616 //! [in] Pointer to OS Driver context
617 //! \return MOS_STATUS
618 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
619 //!
Linux_InitContext(MOS_OS_CONTEXT * context,PMOS_CONTEXT osDriverContext)620 MOS_STATUS Linux_InitContext(
621 MOS_OS_CONTEXT *context,
622 PMOS_CONTEXT osDriverContext)
623 {
624 MOS_STATUS eStatus;
625 int32_t i = -1;
626
627 MOS_OS_FUNCTION_ENTER;
628
629 eStatus = MOS_STATUS_SUCCESS;
630
631 Linux_InitCmdBufferPool(context);
632
633 // Initialize GPU Status Buffer
634 eStatus = Linux_InitGPUStatus(context);
635 MOS_OS_CHK_STATUS_RETURN(eStatus);
636
637 for (i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
638 {
639 context->OsGpuContext[i].pStartCB = nullptr;
640 context->OsGpuContext[i].pCurrentCB = nullptr;
641 context->OsGpuContext[i].bCBFlushed = true;
642 context->OsGpuContext[i].uiCommandBufferSize = COMMAND_BUFFER_SIZE;
643 context->OsGpuContext[i].pCB =
644 (PMOS_COMMAND_BUFFER)MOS_AllocAndZeroMemory(sizeof(MOS_COMMAND_BUFFER));
645
646 if (nullptr == context->OsGpuContext[i].pCB)
647 {
648 MOS_OS_ASSERTMESSAGE("No More Avaliable Memory");
649 Mos_Specific_ClearGpuContext(context);
650 return MOS_STATUS_NO_SPACE;
651 }
652
653 // each thread has its own GPU context, so do not need any lock as guarder here
654 context->OsGpuContext[i].pAllocationList =
655 (ALLOCATION_LIST*)MOS_AllocAndZeroMemory(sizeof(ALLOCATION_LIST) * ALLOCATIONLIST_SIZE);
656 if (nullptr == context->OsGpuContext[i].pAllocationList)
657 {
658 MOS_OS_ASSERTMESSAGE("context->OsGpuContext[%d].pAllocationList malloc failed.", i);
659 Mos_Specific_ClearGpuContext(context);
660 return MOS_STATUS_NO_SPACE;
661 }
662 context->OsGpuContext[i].uiMaxNumAllocations = ALLOCATIONLIST_SIZE;
663
664 context->OsGpuContext[i].pPatchLocationList =
665 (PATCHLOCATIONLIST*)MOS_AllocAndZeroMemory(sizeof(PATCHLOCATIONLIST) * PATCHLOCATIONLIST_SIZE);
666 if (nullptr == context->OsGpuContext[i].pPatchLocationList)
667 {
668 MOS_OS_ASSERTMESSAGE("context->OsGpuContext[%d].pPatchLocationList malloc failed.", i);
669 Mos_Specific_ClearGpuContext(context);
670 return MOS_STATUS_NO_SPACE;
671 }
672 context->OsGpuContext[i].uiMaxPatchLocationsize = PATCHLOCATIONLIST_SIZE;
673
674 context->OsGpuContext[i].pResources =
675 (PMOS_RESOURCE)MOS_AllocAndZeroMemory(sizeof(MOS_RESOURCE) * ALLOCATIONLIST_SIZE);
676 if (nullptr == context->OsGpuContext[i].pResources)
677 {
678 MOS_OS_ASSERTMESSAGE("context->OsGpuContext[%d].pResources malloc failed.", i);
679 Mos_Specific_ClearGpuContext(context);
680 return MOS_STATUS_NO_SPACE;
681 }
682
683 context->OsGpuContext[i].pbWriteMode =
684 (int32_t*)MOS_AllocAndZeroMemory(sizeof(int32_t) * ALLOCATIONLIST_SIZE);
685 if (nullptr == context->OsGpuContext[i].pbWriteMode)
686 {
687 MOS_OS_ASSERTMESSAGE("context->OsGpuContext[%d].pbWriteMode malloc failed.", i);
688 Mos_Specific_ClearGpuContext(context);
689 return MOS_STATUS_NO_SPACE;
690 }
691
692 context->OsGpuContext[i].uiGPUStatusTag = 1;
693 }
694
695
696 context->pTranscryptedKernels = nullptr;
697 context->uiTranscryptedKernelsSize = 0;
698
699 // For Media Memory compression
700 context->ppMediaMemDecompState = osDriverContext->ppMediaMemDecompState;
701 context->pfnMemoryDecompress = osDriverContext->pfnMemoryDecompress;
702 context->pfnMediaMemoryCopy = osDriverContext->pfnMediaMemoryCopy;
703 context->pfnMediaMemoryCopy2D = osDriverContext->pfnMediaMemoryCopy2D;
704
705 // Set interface functions
706 return eStatus;
707 }
708
709 //============= PRIVATE FUNCTIONS <END>=========================================
710
711 //!
712 //! \brief Set GPU context
713 //! \details Set GPU context for the following rendering operations
714 //! \param PMOS_INTERFACE * osInterface
715 //! [in] Pointer to OS interface
716 //! \param MOS_GPU_CONTEXT gpuContext
717 //! [in] GPU Context
718 //! \return MOS_STATUS
719 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
720 //!
Mos_Specific_SetGpuContext(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext)721 MOS_STATUS Mos_Specific_SetGpuContext(
722 PMOS_INTERFACE osInterface,
723 MOS_GPU_CONTEXT gpuContext)
724 {
725 MOS_OS_FUNCTION_ENTER;
726
727 MOS_OS_CHK_NULL_RETURN(osInterface);
728
729 if (gpuContext >= MOS_GPU_CONTEXT_MAX)
730 {
731 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
732 return MOS_STATUS_INVALID_PARAMETER;
733 }
734
735 // Set GPU context handle
736 osInterface->CurrentGpuContextOrdinal = gpuContext;
737
738 if (Mos_Solo_IsEnabled(nullptr))
739 {
740 return MOS_STATUS_SUCCESS;
741 }
742
743 // Set GPU context handle
744 osInterface->CurrentGpuContextHandle = osInterface->m_GpuContextHandleMap[gpuContext];
745
746 MOS_OS_CHK_STATUS_RETURN(MosInterface::SetGpuContext(
747 osInterface->osStreamState,
748 osInterface->m_GpuContextHandleMap[gpuContext]));
749
750 return MOS_STATUS_SUCCESS;
751 }
752
Mos_Specific_SetGpuContextFromHandle(MOS_INTERFACE * osInterface,MOS_GPU_CONTEXT contextName,GPU_CONTEXT_HANDLE contextHandle)753 MOS_STATUS Mos_Specific_SetGpuContextFromHandle(MOS_INTERFACE *osInterface,
754 MOS_GPU_CONTEXT contextName,
755 GPU_CONTEXT_HANDLE contextHandle)
756 {
757 MOS_OS_FUNCTION_ENTER;
758 MOS_OS_CHK_NULL_RETURN(osInterface);
759
760 if (MOS_GPU_CONTEXT_INVALID_HANDLE == contextName)
761 {
762 MOS_OS_ASSERTMESSAGE("Invalid input parameter contextName.");
763 return MOS_STATUS_INVALID_PARAMETER;
764 }
765
766 // Set GPU context handle
767 osInterface->CurrentGpuContextOrdinal = contextName;
768
769 if (Mos_Solo_IsEnabled(nullptr))
770 {
771 return MOS_STATUS_SUCCESS;
772 }
773
774 // Set GPU context handle
775 osInterface->CurrentGpuContextHandle = contextHandle;
776
777 MOS_OS_CHK_STATUS_RETURN(
778 MosInterface::SetGpuContext(osInterface->osStreamState,
779 contextHandle));
780
781 return MOS_STATUS_SUCCESS;
782 }
783
784 //!
785 //! \brief Get current GPU context
786 //! \details Get current GPU context for the following rendering operations
787 //! \param PMOS_INTERFACE osInterface
788 //! [in] Pointer to OS Interface
789 //! \return MOS_GPU_CONTEXT
790 //! Return current GPU context
791 //!
Mos_Specific_GetGpuContext(PMOS_INTERFACE osInterface)792 MOS_GPU_CONTEXT Mos_Specific_GetGpuContext(
793 PMOS_INTERFACE osInterface)
794 {
795 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, MOS_GPU_CONTEXT_INVALID_HANDLE);
796
797 return osInterface->CurrentGpuContextOrdinal;
798 }
799
800 //!
801 //! \brief Set GPU context Handle
802 //! \details Set GPU context handle for the following rendering operations
803 //! \param PMOS_INTERFACE osInterface
804 //! [in] Pointer to OS Interface
805 //! \param GPU_CONTEXT_HANDLE gpuContextHandle
806 //! [in] GPU Context Handle
807 //! \param MOS_GPU_CONTEXT gpuContext
808 //! [in] GPU Context
809 //! \return MOS_STATUS
810 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
811 //!
Mos_Specific_SetGpuContextHandle(PMOS_INTERFACE osInterface,GPU_CONTEXT_HANDLE gpuContextHandle,MOS_GPU_CONTEXT gpuContext)812 MOS_STATUS Mos_Specific_SetGpuContextHandle(
813 PMOS_INTERFACE osInterface,
814 GPU_CONTEXT_HANDLE gpuContextHandle,
815 MOS_GPU_CONTEXT gpuContext)
816 {
817 MOS_OS_FUNCTION_ENTER;
818 MOS_OS_CHK_NULL_RETURN(osInterface);
819 if (gpuContext >= MOS_GPU_CONTEXT_MAX)
820 {
821 MOS_OS_ASSERTMESSAGE("gpuContext %x >= MOS_GPU_CONTEXT_MAX", gpuContext);
822 return MOS_STATUS_INVALID_PARAMETER;
823 }
824 osInterface->m_GpuContextHandleMap[gpuContext] = gpuContextHandle;
825 return MOS_STATUS_SUCCESS;
826 }
827
828 //!
829 //! \brief Get GPU context pointer
830 //! \details Get GPU context pointer
831 //! \param PMOS_INTERFACE osInterface
832 //! [in] Pointer to OS Interface
833 //! \param GPU_CONTEXT_HANDLE gpuContextHandle
834 //! [in] GPU Context Handle
835 //! \return void *
836 //! a pointer to a gpu context
837 //!
Mos_Specific_GetGpuContextbyHandle(PMOS_INTERFACE osInterface,GPU_CONTEXT_HANDLE gpuContextHandle)838 void *Mos_Specific_GetGpuContextbyHandle(
839 PMOS_INTERFACE osInterface,
840 GPU_CONTEXT_HANDLE gpuContextHandle)
841 {
842 MOS_OS_FUNCTION_ENTER;
843
844 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, nullptr);
845
846 return MosInterface::GetGpuContext(osInterface->osStreamState, gpuContextHandle);
847 }
848
849 //!
850 //! \brief Get current GMM client context
851 //! \details Get current GMM client context
852 //! \param PMOS_INTERFACE osInterface
853 //! [in] Pointer to OS Interface
854 //! \return GMM_CLIENT_CONTEXT
855 //! Return current GMM client context
856 //!
Mos_Specific_GetGmmClientContext(PMOS_INTERFACE osInterface)857 GMM_CLIENT_CONTEXT *Mos_Specific_GetGmmClientContext(
858 PMOS_INTERFACE osInterface)
859 {
860 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, nullptr);
861
862 return MosInterface::GetGmmClientContext(osInterface->osStreamState);
863 }
864
865 //!
866 //! \brief Get Platform
867 //! \details Get platform info
868 //! \param PMOS_INTERFACE osInterface
869 //! [in] Pointer to OS Interface
870 //! \param PLATFORM pPlatform
871 //! [out] Pointer to platform
872 //! \return MOS_STATUS
873 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
874 //!
Mos_Specific_GetPlatform(PMOS_INTERFACE osInterface,PLATFORM * pPlatform)875 void Mos_Specific_GetPlatform(
876 PMOS_INTERFACE osInterface,
877 PLATFORM *pPlatform)
878 {
879 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
880 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pPlatform);
881
882 auto platform = MosInterface::GetPlatform(osInterface->osStreamState);
883 MOS_OS_CHK_NULL_NO_STATUS_RETURN(platform);
884 *pPlatform = *platform;
885 return;
886 }
887
Mos_DestroyInterface(PMOS_INTERFACE osInterface)888 MOS_STATUS Mos_DestroyInterface(PMOS_INTERFACE osInterface)
889 {
890 MOS_OS_CHK_NULL_RETURN(osInterface);
891
892 MOS_STREAM_HANDLE streamState = osInterface->osStreamState;
893 MOS_OS_CHK_NULL_RETURN(streamState);
894
895 auto deviceContext = streamState->osDeviceContext;
896 MOS_OS_CHK_NULL_RETURN(deviceContext);
897 auto gpuContextMgr = deviceContext->GetGpuContextMgr();
898
899 if (!Mos_Solo_IsEnabled((PMOS_CONTEXT)streamState->perStreamParameters) && gpuContextMgr)
900 {
901 for (uint32_t i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
902 {
903 if (osInterface->m_GpuContextHandleMap[i] != MOS_GPU_CONTEXT_INVALID_HANDLE)
904 {
905 auto gpuContext = gpuContextMgr->GetGpuContext(osInterface->m_GpuContextHandleMap[i]);
906 if (gpuContext == nullptr)
907 {
908 MOS_OS_ASSERTMESSAGE("cannot find the gpuContext corresponding to the active gpuContextHandle");
909 continue;
910 }
911 gpuContextMgr->DestroyGpuContext(gpuContext);
912 osInterface->m_GpuContextHandleMap[i] = MOS_GPU_CONTEXT_INVALID_HANDLE;
913 }
914 }
915 }
916
917 if (osInterface->osCpInterface)
918 {
919 Delete_MosCpInterface(osInterface->osCpInterface);
920 osInterface->osCpInterface = nullptr;
921 }
922
923 PMOS_CONTEXT perStreamParameters = (PMOS_CONTEXT)streamState->perStreamParameters;
924
925 if (perStreamParameters && perStreamParameters->bFreeContext)
926 {
927 perStreamParameters->m_skuTable.reset();
928 perStreamParameters->m_waTable.reset();
929 Mos_Specific_ClearGpuContext(perStreamParameters);
930
931 if (perStreamParameters->contextOffsetList.size())
932 {
933 perStreamParameters->contextOffsetList.clear();
934 perStreamParameters->contextOffsetList.shrink_to_fit();
935 }
936
937 if(Mos_Solo_IsEnabled(perStreamParameters))
938 {
939 Linux_ReleaseCmdBufferPool(perStreamParameters);
940 PCOMMAND_BUFFER pCurrCB = nullptr;
941 PCOMMAND_BUFFER pNextCB = nullptr;
942 for (uint32_t i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
943 {
944 MOS_FreeMemAndSetNull(perStreamParameters->OsGpuContext[i].pCB);
945
946 pCurrCB = perStreamParameters->OsGpuContext[i].pStartCB;
947 for (; (pCurrCB); pCurrCB = pNextCB)
948 {
949 pNextCB = pCurrCB->pNext;
950 MOS_FreeMemAndSetNull(pCurrCB);
951 }
952 }
953 Linux_ReleaseGPUStatus(perStreamParameters);
954 }
955 if (perStreamParameters->intel_context)
956 {
957 if (perStreamParameters->intel_context->vm_id != INVALID_VM)
958 {
959 mos_vm_destroy(perStreamParameters->intel_context->bufmgr, perStreamParameters->intel_context->vm_id);
960 perStreamParameters->intel_context->vm_id = INVALID_VM;
961 }
962 mos_context_destroy(perStreamParameters->intel_context);
963 perStreamParameters->intel_context = nullptr;
964 }
965 MOS_Delete(perStreamParameters);
966 streamState->perStreamParameters = nullptr;
967 }
968
969 MosInterface::DestroyVirtualEngineState(streamState);
970 MOS_FreeMemAndSetNull(osInterface->pVEInterf);
971
972 MOS_OS_CHK_STATUS_RETURN(MosInterface::DestroyOsStreamState(streamState));
973 osInterface->osStreamState = nullptr;
974 return MOS_STATUS_SUCCESS;
975 }
976 //!
977 //! \brief Destroys OS specific allocations
978 //! \details Destroys OS specific allocations including destroying OS context
979 //! \param PMOS_INTERFACE osInterface
980 //! [in] Pointer to OS Interface
981 //! \param int32_t destroyVscVppDeviceTag
982 //! [in] Destroy VscVppDeviceTagId Flag, no use in Linux
983 //! \return void
984 //!
Mos_Specific_Destroy(PMOS_INTERFACE osInterface,int32_t destroyVscVppDeviceTag)985 void Mos_Specific_Destroy(
986 PMOS_INTERFACE osInterface,
987 int32_t destroyVscVppDeviceTag)
988 {
989 MOS_UNUSED(destroyVscVppDeviceTag);
990 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
991
992 MOS_STATUS status = Mos_DestroyInterface(osInterface);
993 if (status != MOS_STATUS_SUCCESS)
994 {
995 MOS_OS_ASSERTMESSAGE("Mos Destroy Interface failed.");
996 }
997 return;
998 }
999
1000 //!
1001 //! \brief Gets the SKU table
1002 //! \details Gets the SKU table for the platform
1003 //! \param PMOS_INTERFACE osInterface
1004 //! [in] Pointer to OS Interface
1005 //! \return MEDIA_FEATURE_TABLE *
1006 //! Returns the pointer to sku table
1007 //!
Mos_Specific_GetSkuTable(PMOS_INTERFACE osInterface)1008 MEDIA_FEATURE_TABLE *Mos_Specific_GetSkuTable(
1009 PMOS_INTERFACE osInterface)
1010 {
1011 if (osInterface == nullptr)
1012 {
1013 MOS_OS_ASSERTMESSAGE("osInterface found be nullptr.");
1014 return nullptr;
1015 }
1016 return MosInterface::GetSkuTable(osInterface->osStreamState);
1017 }
1018
1019 //!
1020 //! \brief Gets the WA table
1021 //! \details Gets the WA table for the platform
1022 //! \param PMOS_INTERFACE osInterface
1023 //! [in] Pointer to OS Interface
1024 //! \return MEDIA_WA_TABLE *
1025 //! Returns the pointer to WA table
1026 //!
Mos_Specific_GetWaTable(PMOS_INTERFACE osInterface)1027 MEDIA_WA_TABLE *Mos_Specific_GetWaTable(
1028 PMOS_INTERFACE osInterface)
1029 {
1030 if (osInterface == nullptr)
1031 {
1032 MOS_OS_ASSERTMESSAGE("osInterface found be nullptr.");
1033 return nullptr;
1034 }
1035 return MosInterface::GetWaTable(osInterface->osStreamState);
1036 }
1037
1038 //!
1039 //! \brief Gets the GT System Info
1040 //! \details Gets the GT System Info
1041 //! \param PMOS_INTERFACE osInterface
1042 //! [in] OS Interface
1043 //! \return MEDIA_SYSTEM_INFO *
1044 //! pointer to the GT System Info
1045 //!
Mos_Specific_GetGtSystemInfo(PMOS_INTERFACE osInterface)1046 MEDIA_SYSTEM_INFO *Mos_Specific_GetGtSystemInfo(
1047 PMOS_INTERFACE osInterface)
1048 {
1049 if (nullptr == osInterface)
1050 {
1051 MOS_OS_ASSERTMESSAGE("input parameter osInterface is NULL.");
1052 return nullptr;
1053 }
1054
1055 return MosInterface::GetGtSystemInfo(osInterface->osStreamState);
1056 }
1057
Mos_Specific_GetMediaEngineInfo(PMOS_INTERFACE osInterface,MEDIA_ENGINE_INFO & info)1058 MOS_STATUS Mos_Specific_GetMediaEngineInfo(
1059 PMOS_INTERFACE osInterface,
1060 MEDIA_ENGINE_INFO &info)
1061 {
1062 MOS_OS_CHK_NULL_RETURN(osInterface);
1063 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetMediaEngineInfo(osInterface->osStreamState, info));
1064 return MOS_STATUS_SUCCESS;
1065 }
1066
1067 //!
1068 //! \brief Resets OS States
1069 //! \details Resets OS States for linux
1070 //! \param PMOS_INTERFACE osInterface
1071 //! [in] Pointer to OS Interface
1072 //! \return void
1073 //!
Mos_Specific_ResetOsStates(PMOS_INTERFACE osInterface)1074 void Mos_Specific_ResetOsStates(
1075 PMOS_INTERFACE osInterface)
1076 {
1077 MOS_OS_FUNCTION_ENTER;
1078
1079 if (osInterface == nullptr)
1080 {
1081 return;
1082 }
1083 if (!Mos_Solo_IsEnabled(nullptr))
1084 {
1085 auto status = MosInterface::ResetCommandBuffer(osInterface->osStreamState, 0);
1086 if (MOS_FAILED(status))
1087 {
1088 MOS_OS_ASSERTMESSAGE("ResetCommandBuffer failed.");
1089 }
1090 return;
1091 }
1092
1093 PMOS_OS_CONTEXT osContext = osInterface->pOsContext;
1094 MOS_OS_GPU_CONTEXT &osGpuContext = osContext->OsGpuContext[osInterface->CurrentGpuContextOrdinal];
1095 // Reset resource allocation
1096 osGpuContext.uiNumAllocations = 0;
1097 MOS_ZeroMemory(osGpuContext.pAllocationList, sizeof(ALLOCATION_LIST) * osGpuContext.uiMaxNumAllocations);
1098 osGpuContext.uiCurrentNumPatchLocations = 0;
1099 MOS_ZeroMemory(osGpuContext.pPatchLocationList, sizeof(PATCHLOCATIONLIST) * osGpuContext.uiMaxPatchLocationsize);
1100 osGpuContext.uiResCount = 0;
1101
1102 MOS_ZeroMemory(osGpuContext.pResources, sizeof(MOS_RESOURCE) * osGpuContext.uiMaxNumAllocations);
1103 MOS_ZeroMemory(osGpuContext.pbWriteMode, sizeof(int32_t) * osGpuContext.uiMaxNumAllocations);
1104
1105 if ((osGpuContext.bCBFlushed == true) && osGpuContext.pCB->OsResource.bo)
1106 {
1107 osGpuContext.pCB->OsResource.bo = nullptr;
1108 }
1109
1110 return;
1111 }
1112
1113 //!
1114 //! \brief Allocate resource
1115 //! \details To Allocate Buffer, pass Format as Format_Buffer and set the iWidth as size of the buffer.
1116 //! \param PMOS_INTERFACE osInterface
1117 //! [in] Pointer to OS Interface
1118 //! \param PMOS_ALLOC_GFXRES_PARAMS params
1119 //! [in] Pointer to resource params
1120 //! \param PMOS_RESOURCE osResource
1121 //! [in/out] Pointer to OS resource
1122 //! \return MOS_STATUS
1123 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1124 //!
Mos_Specific_AllocateResource(PMOS_INTERFACE osInterface,PMOS_ALLOC_GFXRES_PARAMS params,PCCHAR functionName,PCCHAR filename,int32_t line,PMOS_RESOURCE osResource)1125 MOS_STATUS Mos_Specific_AllocateResource(
1126 PMOS_INTERFACE osInterface,
1127 PMOS_ALLOC_GFXRES_PARAMS params,
1128 #if MOS_MESSAGES_ENABLED
1129 PCCHAR functionName,
1130 PCCHAR filename,
1131 int32_t line,
1132 #endif // MOS_MESSAGES_ENABLED
1133 PMOS_RESOURCE osResource)
1134 {
1135 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
1136 bool osContextValid = false;
1137 MOS_OS_FUNCTION_ENTER;
1138
1139 MOS_OS_CHK_NULL_RETURN(osResource);
1140 MOS_OS_CHK_NULL_RETURN(osInterface);
1141 MOS_OS_CHK_NULL_RETURN(osInterface->osStreamState);
1142
1143 if(Mos_Solo_IsEnabled(nullptr))
1144 {
1145 MOS_OS_ASSERTMESSAGE("Mos_Solo_IsEnabled, Invalid resource allocation request");
1146 return MOS_STATUS_INVALID_PARAMETER;
1147 }
1148 osResource->bConvertedFromDDIResource = false;
1149 params->bBypassMODImpl = false;
1150 osInterface->osStreamState->component = osInterface->Component;
1151
1152 eStatus = MosInterface::AllocateResource(
1153 osInterface->osStreamState,
1154 params,
1155 osResource
1156 #if MOS_MESSAGES_ENABLED
1157 ,
1158 functionName,
1159 filename,
1160 line
1161 #endif // MOS_MESSAGES_ENABLED
1162 );
1163
1164 return eStatus;
1165 }
1166
1167 //!
1168 //! \brief Get Resource Information
1169 //! \details Linux get resource info
1170 //! \param PMOS_INTERFACE osInterface
1171 //! [in] Pointer to OS interface structure
1172 //! \param PMOS_RESOURCE osResource
1173 //! [in] Pointer to input OS resource
1174 //! \param PMOS_SURFACE pResDetails
1175 //! [out] Pointer to output resource information details
1176 //! \return MOS_STATUS
1177 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1178 //!
Mos_Specific_GetResourceInfo(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,PMOS_SURFACE resDetails)1179 MOS_STATUS Mos_Specific_GetResourceInfo(
1180 PMOS_INTERFACE osInterface,
1181 PMOS_RESOURCE osResource,
1182 PMOS_SURFACE resDetails)
1183 {
1184 MOS_OS_FUNCTION_ENTER;
1185
1186 MOS_OS_CHK_NULL_RETURN(osInterface);
1187 MOS_OS_CHK_NULL_RETURN(resDetails);
1188 return MosInterface::GetResourceInfo(osInterface->osStreamState, osResource, *resDetails);
1189 }
1190
1191 //!
1192 //! \brief Free the resource
1193 //! \details Free the allocated resource
1194 //! \param PMOS_INTERFACE osInterface
1195 //! [in] Pointer to OS interface structure
1196 //! \param PMOS_RESOURCE osResource
1197 //! [in] Pointer to input OS resource
1198 //! \return void
1199 //!
Mos_Specific_FreeResource(PMOS_INTERFACE osInterface,PCCHAR functionName,PCCHAR filename,int32_t line,PMOS_RESOURCE osResource)1200 void Mos_Specific_FreeResource(
1201 PMOS_INTERFACE osInterface,
1202 #if MOS_MESSAGES_ENABLED
1203 PCCHAR functionName,
1204 PCCHAR filename,
1205 int32_t line,
1206 #endif // MOS_MESSAGES_ENABLED
1207 PMOS_RESOURCE osResource)
1208 {
1209 MOS_OS_FUNCTION_ENTER;
1210 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
1211 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osResource);
1212
1213 MosInterface::FreeResource(
1214 osInterface->osStreamState,
1215 osResource,
1216 0
1217 #if MOS_MESSAGES_ENABLED
1218 ,
1219 functionName,
1220 filename,
1221 line
1222 #endif
1223 );
1224
1225 return;
1226 }
1227
1228 //!
1229 //! \brief Free OS resource
1230 //! \details Free OS resource
1231 //! \param PMOS_INTERFACE osInterface
1232 //! [in] OS Interface
1233 //! \param PMOS_RESOURCE osResource
1234 //! [in/out] OS Resource to be freed
1235 //! \param uint32_t uiFlag
1236 //! [in] Flag to free resources. This one is useless on Linux, just for compatibility.
1237 //! \return void
1238 //!
Mos_Specific_FreeResourceWithFlag(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,PCCHAR functionName,PCCHAR filename,int32_t line,uint32_t uiFlag)1239 void Mos_Specific_FreeResourceWithFlag(
1240 PMOS_INTERFACE osInterface,
1241 PMOS_RESOURCE osResource,
1242 #if MOS_MESSAGES_ENABLED
1243 PCCHAR functionName,
1244 PCCHAR filename,
1245 int32_t line,
1246 #endif // MOS_MESSAGES_ENABLED
1247 uint32_t uiFlag)
1248 {
1249 MOS_UNUSED(uiFlag);
1250
1251 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
1252 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osResource);
1253
1254 #if MOS_MESSAGES_ENABLED
1255 Mos_Specific_FreeResource(osInterface, functionName, filename, line, osResource);
1256 #else
1257 Mos_Specific_FreeResource(osInterface, osResource);
1258 #endif // MOS_MESSAGES_ENABLED
1259 }
1260
1261 //!
1262 //! \brief Locks Resource request
1263 //! \details Locks Resource request
1264 //! \param PMOS_INTERFACE osInterface
1265 //! [in] pointer to OS Interface structure
1266 //! \param PMOS_RESOURCE osResource
1267 //! [in/out] Resource object
1268 //! \param PMOS_LOCK_PARAMS lockFlags
1269 //! [in] Lock Flags
1270 //! \return MOS_STATUS
1271 //! MOS_STATUS_SUCCESS if successful
1272 //!
Mos_Specific_LockSyncRequest(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,PMOS_LOCK_PARAMS lockFlags)1273 MOS_STATUS Mos_Specific_LockSyncRequest(
1274 PMOS_INTERFACE osInterface,
1275 PMOS_RESOURCE osResource,
1276 PMOS_LOCK_PARAMS lockFlags)
1277 {
1278 MOS_UNUSED(osInterface);
1279 MOS_UNUSED(osResource);
1280 MOS_UNUSED(lockFlags);
1281
1282 return MOS_STATUS_SUCCESS;
1283 }
1284
1285 //!
1286 //! \brief Lock resource
1287 //! \details Lock allocated resource
1288 //! \param PMOS_INTERFACE osInterface
1289 //! [in] Pointer to OS interface structure
1290 //! \param PMOS_RESOURCE osResource
1291 //! [in] Pointer to input OS resource
1292 //! \param PMOS_LOCK_PARAMS lockFlags
1293 //! [in] Lock Flags - MOS_LOCKFLAG_* flags
1294 //! \return void *
1295 //!
Mos_Specific_LockResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,PMOS_LOCK_PARAMS lockFlags)1296 void *Mos_Specific_LockResource(
1297 PMOS_INTERFACE osInterface,
1298 PMOS_RESOURCE osResource,
1299 PMOS_LOCK_PARAMS lockFlags)
1300 {
1301 MOS_OS_CONTEXT *context = nullptr;
1302
1303 MOS_OS_FUNCTION_ENTER;
1304 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, nullptr);
1305 MOS_OS_CHK_NULL_RETURN_VALUE(osResource, nullptr);
1306 if(!Mos_Solo_IsEnabled(nullptr))
1307 {
1308 return MosInterface::LockMosResource(osInterface->osStreamState, osResource, lockFlags);
1309 }
1310
1311 context = osInterface->pOsContext;
1312 MOS_OS_CHK_NULL_RETURN_VALUE(context, nullptr);
1313 MOS_OS_CHK_NULL_RETURN_VALUE(osResource->bo, nullptr);
1314 MOS_OS_CHK_NULL_RETURN_VALUE(osResource->pGmmResInfo, nullptr);
1315
1316 {
1317 MOS_LINUX_BO *bo = osResource->bo;
1318 GMM_RESOURCE_FLAG gmmFlags = {};
1319
1320 gmmFlags = osResource->pGmmResInfo->GetResFlags();
1321
1322 // Do decompression for a compressed surface before lock
1323 if (!lockFlags->NoDecompress &&
1324 (((gmmFlags.Gpu.MMC || gmmFlags.Gpu.CCS) && gmmFlags.Gpu.UnifiedAuxSurface)||
1325 osResource->pGmmResInfo->IsMediaMemoryCompressed(0)))
1326 {
1327 if(context->pfnMemoryDecompress)
1328 {
1329 context->pfnMemoryDecompress(context, osResource);
1330 }
1331 }
1332 if(osResource->bMapped)
1333 {
1334 return osResource->pData;
1335 }
1336
1337 if (osResource->TileType != MOS_TILE_LINEAR && !lockFlags->TiledAsTiled)
1338 {
1339 if (context->bUseSwSwizzling)
1340 {
1341 mos_bo_map(bo, (OSKM_LOCKFLAG_WRITEONLY&lockFlags->WriteOnly));
1342 osResource->MmapOperation = MOS_MMAP_OPERATION_MMAP;
1343 if (osResource->pSystemShadow == nullptr)
1344 {
1345 osResource->pSystemShadow = (uint8_t *)MOS_AllocMemory(bo->size);
1346 MOS_OS_CHECK_CONDITION((osResource->pSystemShadow == nullptr), "Failed to allocate shadow surface", nullptr);
1347 }
1348 if (osResource->pSystemShadow)
1349 {
1350 int32_t flags = context->bTileYFlag ? 0 : 1;
1351 MOS_OS_CHECK_CONDITION((osResource->TileType != MOS_TILE_Y), "Unsupported tile type", nullptr);
1352 MOS_OS_CHECK_CONDITION((bo->size <= 0 || osResource->iPitch <= 0), "Invalid BO size or pitch", nullptr);
1353 Mos_SwizzleData((uint8_t*)bo->virt, osResource->pSystemShadow,
1354 MOS_TILE_Y, MOS_TILE_LINEAR, bo->size / osResource->iPitch, osResource->iPitch, flags);
1355 }
1356 }
1357 else
1358 {
1359 mos_bo_map_gtt(bo);
1360 osResource->MmapOperation = MOS_MMAP_OPERATION_MMAP_GTT;
1361 }
1362 }
1363 else if (lockFlags->Uncached)
1364 {
1365 mos_bo_map_wc(bo);
1366 osResource->MmapOperation = MOS_MMAP_OPERATION_MMAP_WC;
1367 }
1368 else
1369 {
1370 mos_bo_map(bo, (OSKM_LOCKFLAG_WRITEONLY&lockFlags->WriteOnly));
1371 osResource->MmapOperation = MOS_MMAP_OPERATION_MMAP;
1372 }
1373 osResource->pData = osResource->pSystemShadow ? osResource->pSystemShadow : (uint8_t*)bo->virt;
1374 osResource->bMapped = true;
1375 }
1376 return osResource->pData;
1377 }
1378
1379 //!
1380 //! \brief Unlock resource
1381 //! \details Unlock the locked resource
1382 //! \param PMOS_INTERFACE osInterface
1383 //! [in] Pointer to OS interface structure
1384 //! \param PMOS_RESOURCE osResource
1385 //! [in] Pointer to input OS resource
1386 //! \return MOS_STATUS
1387 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1388 //!
Mos_Specific_UnlockResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource)1389 MOS_STATUS Mos_Specific_UnlockResource(
1390 PMOS_INTERFACE osInterface,
1391 PMOS_RESOURCE osResource)
1392 {
1393 MOS_OS_FUNCTION_ENTER;
1394
1395 MOS_OS_CHK_NULL_RETURN(osInterface);
1396 if(!Mos_Solo_IsEnabled(nullptr))
1397 {
1398 return MosInterface::UnlockMosResource(osInterface->osStreamState, osResource);
1399 }
1400
1401 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
1402 if(false == osResource->bMapped)
1403 {
1404 osResource->pData = nullptr;
1405 return MOS_STATUS_SUCCESS;
1406 }
1407
1408 if(osResource->bo)
1409 {
1410 if (osResource->pSystemShadow)
1411 {
1412 int32_t flags = osInterface->pOsContext->bTileYFlag ? 0 : 1;
1413 Mos_SwizzleData(osResource->pSystemShadow, (uint8_t*)osResource->bo->virt,
1414 MOS_TILE_LINEAR, MOS_TILE_Y, osResource->bo->size / osResource->iPitch, osResource->iPitch, flags);
1415 MOS_FreeMemory(osResource->pSystemShadow);
1416 osResource->pSystemShadow = nullptr;
1417 }
1418
1419 switch(osResource->MmapOperation)
1420 {
1421 case MOS_MMAP_OPERATION_MMAP_GTT:
1422 mos_bo_unmap_gtt(osResource->bo);
1423 break;
1424 case MOS_MMAP_OPERATION_MMAP_WC:
1425 mos_bo_unmap_wc(osResource->bo);
1426 break;
1427 case MOS_MMAP_OPERATION_MMAP:
1428 mos_bo_unmap(osResource->bo);
1429 break;
1430 default:
1431 MOS_OS_ASSERTMESSAGE("Invalid mmap operation type");
1432 break;
1433 }
1434 osResource->bo->virt = nullptr;
1435 }
1436
1437 osResource->bMapped = false;
1438 osResource->pData = nullptr;
1439 return MOS_STATUS_SUCCESS;
1440 }
1441
1442 //!
1443 //! \brief Decompress Resource
1444 //! \details Decompress Resource
1445 //! \param PMOS_INTERFACE osInterface
1446 //! [in] pointer to OS Interface structure
1447 //! \param PMOS_RESOURCE osResource
1448 //! [in/out] Resource object
1449 //! \return MOS_STATUS
1450 //! MOS_STATUS_SUCCESS if successful
1451 //!
Mos_Specific_DecompResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource)1452 MOS_STATUS Mos_Specific_DecompResource(
1453 PMOS_INTERFACE osInterface,
1454 PMOS_RESOURCE osResource)
1455 {
1456 MOS_OS_CHK_NULL_RETURN(osInterface);
1457 return MosInterface::DecompResource(osInterface->osStreamState, osResource);
1458 }
1459
1460 //!
1461 //! \brief Decompress and Copy Resource to Another Buffer
1462 //! \details Decompress and Copy Resource to Another Buffer
1463 //! \param PMOS_INTERFACE osInterface
1464 //! [in] pointer to OS Interface structure
1465 //! \param PMOS_RESOURCE inputOsResource
1466 //! [in] Input Resource object
1467 //! \param PMOS_RESOURCE outputOsResource
1468 //! [out] output Resource object
1469 //! \param [in] outputCompressed
1470 //! true means apply compression on output surface, else output uncompressed surface
1471 //! \return MOS_STATUS
1472 //! MOS_STATUS_SUCCESS if successful
1473 //!
Mos_Specific_DoubleBufferCopyResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE inputOsResource,PMOS_RESOURCE outputOsResource,bool outputCompressed)1474 MOS_STATUS Mos_Specific_DoubleBufferCopyResource(
1475 PMOS_INTERFACE osInterface,
1476 PMOS_RESOURCE inputOsResource,
1477 PMOS_RESOURCE outputOsResource,
1478 bool outputCompressed)
1479 {
1480 MOS_OS_CHK_NULL_RETURN(osInterface);
1481
1482 return MosInterface::DoubleBufferCopyResource(osInterface->osStreamState, inputOsResource, outputOsResource, outputCompressed);
1483 }
1484
1485 //!
1486 //! \brief Decompress and Copy Resource to Another Buffer
1487 //! \details Decompress and Copy Resource to Another Buffer
1488 //! \param PMOS_INTERFACE osInterface
1489 //! [in] pointer to OS Interface structure
1490 //! \param PMOS_RESOURCE inputOsResource
1491 //! [in] Input Resource object
1492 //! \param PMOS_RESOURCE outputOsResource
1493 //! [out] output Resource object
1494 //! \param [in] copyWidth
1495 //! The 2D surface Width
1496 //! \param [in] copyHeight
1497 //! The 2D surface height
1498 //! \param [in] copyInputOffset
1499 //! The offset of copied surface from
1500 //! \param [in] copyOutputOffset
1501 //! The offset of copied to
1502 //! \param [in] bOutputCompressed
1503 //! true means apply compression on output surface, else output uncompressed surface
1504 //! \return MOS_STATUS
1505 //! MOS_STATUS_SUCCESS if successful
1506 //!
Mos_Specific_MediaCopyResource2D(PMOS_INTERFACE osInterface,PMOS_RESOURCE inputOsResource,PMOS_RESOURCE outputOsResource,uint32_t copyWidth,uint32_t copyHeight,uint32_t bpp,bool outputCompressed)1507 MOS_STATUS Mos_Specific_MediaCopyResource2D(
1508 PMOS_INTERFACE osInterface,
1509 PMOS_RESOURCE inputOsResource,
1510 PMOS_RESOURCE outputOsResource,
1511 uint32_t copyWidth,
1512 uint32_t copyHeight,
1513 uint32_t bpp,
1514 bool outputCompressed)
1515 {
1516 MOS_OS_CHK_NULL_RETURN(osInterface);
1517
1518 return MosInterface::MediaCopyResource2D(osInterface->osStreamState, inputOsResource, outputOsResource,
1519 copyWidth, copyHeight, bpp, outputCompressed);
1520 }
1521
1522 //!
1523 //! \brief Get Mos Context
1524 //! \details Get Mos Context info
1525 //! \param PMOS_INTERFACE osInterface
1526 //! [in] Pointer to OS interface structure
1527 //! \param mosContext void **
1528 //! [out] pointer of mos_context
1529 //! \return MOS_STATUS
1530 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1531 //!
Mos_Specific_GetMosContext(PMOS_INTERFACE osInterface,PMOS_CONTEXT * mosContext)1532 MOS_STATUS Mos_Specific_GetMosContext(
1533 PMOS_INTERFACE osInterface,
1534 PMOS_CONTEXT* mosContext)
1535 {
1536 MOS_OS_CHK_NULL_RETURN(osInterface);
1537 MOS_OS_CHK_NULL_RETURN(mosContext);
1538 void *apo_mos_context = nullptr;
1539 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetperStreamParameters(osInterface->osStreamState, &apo_mos_context));
1540 *mosContext = (PMOS_CONTEXT)apo_mos_context;
1541 return MOS_STATUS_SUCCESS;
1542 }
1543
1544 //!
1545 //! \brief Set patch entry
1546 //! \details Sets the patch entry in MS's patch list
1547 //! \param PMOS_INTERFACE osInterface
1548 //! [in] Pointer to OS interface structure
1549 //! \param PMOS_PATCH_ENTRY_PARAMS params
1550 //! [in] patch entry params
1551 //! \return MOS_STATUS
1552 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1553 //!
Mos_Specific_SetPatchEntry(PMOS_INTERFACE osInterface,PMOS_PATCH_ENTRY_PARAMS params)1554 MOS_STATUS Mos_Specific_SetPatchEntry(
1555 PMOS_INTERFACE osInterface,
1556 PMOS_PATCH_ENTRY_PARAMS params)
1557 {
1558 MOS_OS_FUNCTION_ENTER;
1559
1560 MOS_OS_CHK_NULL_RETURN(osInterface);
1561 MOS_OS_CHK_NULL_RETURN(params);
1562
1563 #if (_DEBUG || _RELEASE_INTERNAL)
1564 if (!params->bUpperBoundPatch && params->presResource)
1565 {
1566 uint32_t handle = params->presResource->bo?params->presResource->bo->handle:0;
1567 uint32_t eventData[] = {handle, params->uiResourceOffset,
1568 params->uiPatchOffset, params->bWrite,
1569 params->HwCommandType, params->forceDwordOffset,
1570 params->patchType};
1571 MOS_TraceEventExt(EVENT_RESOURCE_PATCH, EVENT_TYPE_INFO2,
1572 &eventData, sizeof(eventData),
1573 nullptr, 0);
1574 }
1575 #endif
1576 if (Mos_Solo_IsEnabled(nullptr))
1577 {
1578 MOS_OS_ASSERTMESSAGE("Invalid solo function call");
1579 return MOS_STATUS_INVALID_PARAMETER;
1580 }
1581 return MosInterface::SetPatchEntry(osInterface->osStreamState, params);
1582 }
1583
1584 //!
1585 //! \brief Update resource usage type
1586 //! \details update the resource usage for cache policy
1587 //! \param PMOS_RESOURCE osResource
1588 //! [in/out] Pointer to OS Resource
1589 //! \param MOS_HW_RESOURCE_DEF resUsageType
1590 //! [in] resosuce usage type
1591 //! \return MOS_STATUS
1592 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1593 //!
Mos_Specific_UpdateResourceUsageType(PMOS_RESOURCE osResource,MOS_HW_RESOURCE_DEF resUsageType)1594 MOS_STATUS Mos_Specific_UpdateResourceUsageType(
1595 PMOS_RESOURCE osResource,
1596 MOS_HW_RESOURCE_DEF resUsageType)
1597 {
1598 return MosInterface::UpdateResourceUsageType(osResource, resUsageType);
1599 }
1600
1601 //!
1602 //! \brief Registers Resource
1603 //! \details Set the Allocation Index in OS resource structure
1604 //! \param PMOS_INTERFACE osInterface
1605 //! [in] Pointer to OS Interface
1606 //! \param PMOS_RESOURCE osResource
1607 //! [in/out] Pointer to OS Resource
1608 //! \param int32_t bWrite
1609 //! [in] Write Flag
1610 //! \param int32_t bWritebSetResourceSyncTag
1611 //! [in] Resource registration Flag, no use for Linux
1612 //! \return MOS_STATUS
1613 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1614 //!
Mos_Specific_RegisterResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,int32_t write,int32_t writebSetResourceSyncTag)1615 MOS_STATUS Mos_Specific_RegisterResource (
1616 PMOS_INTERFACE osInterface,
1617 PMOS_RESOURCE osResource,
1618 int32_t write,
1619 int32_t writebSetResourceSyncTag)
1620 {
1621 MOS_OS_FUNCTION_ENTER;
1622
1623 MOS_OS_CHK_NULL_RETURN(osInterface);
1624
1625 if (Mos_Solo_IsEnabled(nullptr))
1626 {
1627 MOS_OS_ASSERTMESSAGE("Invalid solo function call");
1628 return MOS_STATUS_INVALID_PARAMETER;
1629 }
1630
1631 #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
1632 auto dumper = GpuCmdResInfoDumpNext::GetInstance(osInterface->pOsContext);
1633 if (dumper)
1634 {
1635 dumper->StoreCmdResPtr(osInterface, (const void *)osResource);
1636 }
1637 #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
1638
1639 return MosInterface::RegisterResource(
1640 osInterface->osStreamState,
1641 osResource,
1642 write);
1643 }
1644
1645 //!
1646 //! \brief Verify command buffer size
1647 //! \details Verifys the buffer to be used for rendering GPU commands is large enough
1648 //! \param PMOS_INTERFACE osInterface
1649 //! [in] Pointer to OS interface structure
1650 //! \param uint32_t dwRequestedSize
1651 //! [in] Buffer size requested
1652 //! \return MOS_STATUS
1653 //! Return MOS_STATUS_SUCCESS if successful (command buffer will be large enough to hold dwMaxSize)
1654 //! otherwise failed
1655 //!
Mos_Specific_VerifyCommandBufferSize(PMOS_INTERFACE osInterface,uint32_t requestedSize,uint32_t flags)1656 MOS_STATUS Mos_Specific_VerifyCommandBufferSize(
1657 PMOS_INTERFACE osInterface,
1658 uint32_t requestedSize,
1659 uint32_t flags)
1660 {
1661 MOS_OS_CHK_NULL_RETURN(osInterface);
1662
1663 if (!Mos_Solo_IsEnabled(nullptr))
1664 {
1665 return MosInterface::VerifyCommandBufferSize(osInterface->osStreamState, 0, requestedSize, flags);
1666 }
1667
1668 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
1669 if (osInterface->CurrentGpuContextOrdinal == MOS_GPU_CONTEXT_INVALID_HANDLE)
1670 {
1671 MOS_OS_ASSERTMESSAGE("CurrentGpuContextOrdinal exceed max.");
1672 return MOS_STATUS_INVALID_PARAMETER;
1673 }
1674
1675 MOS_OS_GPU_CONTEXT &osGpuContext = osInterface->pOsContext->OsGpuContext[osInterface->CurrentGpuContextOrdinal];
1676
1677 if (osGpuContext.uiCommandBufferSize < requestedSize)
1678 {
1679 return MOS_STATUS_UNKNOWN;
1680 }
1681
1682 return MOS_STATUS_SUCCESS;
1683 }
1684
1685 //!
1686 //! \brief Resets Resource Allocation
1687 //! \details Resets Resource Allocation
1688 //! \param PMOS_INTERFACE osInterface
1689 //! [in] Pointer to OS interface structure
1690 //! \param PMOS_RESOURCE osResource
1691 //! [in] Pointer to input OS resource
1692 //! \return void
1693 //!
Mos_Specific_ResetResourceAllocationIndex(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource)1694 void Mos_Specific_ResetResourceAllocationIndex (
1695 PMOS_INTERFACE osInterface,
1696 PMOS_RESOURCE osResource)
1697 {
1698 int32_t i = 0;
1699 MOS_UNUSED(osInterface);
1700 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osResource);
1701
1702 for (i = 0; i < MOS_GPU_CONTEXT_MAX; i++)
1703 {
1704 osResource->iAllocationIndex[i] = MOS_INVALID_ALLOC_INDEX;
1705 }
1706 }
1707
1708 //!
1709 //! \brief Get command buffer
1710 //! \details Retrieves buffer to be used for rendering GPU commands
1711 //! \param PMOS_INTERFACE osInterface
1712 //! [in] Pointer to OS interface structure
1713 //! \param PMOS_COMMAND_BUFFER cmdBuffer
1714 //! [out] Pointer to Command Buffer control structure
1715 //! \return MOS_STATUS
1716 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1717 //!
Mos_Specific_GetCommandBuffer(PMOS_INTERFACE osInterface,PMOS_COMMAND_BUFFER cmdBuffer,uint32_t flags)1718 MOS_STATUS Mos_Specific_GetCommandBuffer(
1719 PMOS_INTERFACE osInterface,
1720 PMOS_COMMAND_BUFFER cmdBuffer,
1721 uint32_t flags)
1722 {
1723 MOS_OS_CHK_NULL_RETURN(osInterface);
1724 if (!Mos_Solo_IsEnabled(nullptr))
1725 {
1726 return MosInterface::GetCommandBuffer(osInterface->osStreamState, cmdBuffer, flags);
1727 }
1728
1729 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
1730 uint32_t uiCommandBufferSize = 0;
1731
1732 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
1733 MOS_OS_CHK_NULL_RETURN(cmdBuffer);
1734
1735 if (osInterface->CurrentGpuContextOrdinal == MOS_GPU_CONTEXT_INVALID_HANDLE)
1736 {
1737 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
1738 return MOS_STATUS_INVALID_PARAMETER;
1739 }
1740
1741 // Activate software context
1742 MOS_OS_GPU_CONTEXT &osGpuContext = osInterface->pOsContext->OsGpuContext[osInterface->CurrentGpuContextOrdinal];
1743 uiCommandBufferSize = osGpuContext.uiCommandBufferSize;
1744
1745 if (osGpuContext.bCBFlushed == true)
1746 {
1747 if (Linux_GetCommandBuffer(osInterface->pOsContext,
1748 cmdBuffer,
1749 uiCommandBufferSize))
1750 {
1751 MOS_OS_CHK_STATUS_RETURN(Linux_InsertCmdBufferToPool(osInterface->pOsContext, cmdBuffer));
1752 osGpuContext.bCBFlushed = false;
1753 eStatus = MOS_SecureMemcpy(osGpuContext.pCB, sizeof(MOS_COMMAND_BUFFER), cmdBuffer, sizeof(MOS_COMMAND_BUFFER));
1754 MOS_OS_CHECK_CONDITION((eStatus != MOS_STATUS_SUCCESS), "Failed to copy command buffer", eStatus);
1755 }
1756 else
1757 {
1758 MOS_OS_ASSERTMESSAGE("Failed to activate command buffer.");
1759 return MOS_STATUS_UNKNOWN;
1760 }
1761 }
1762
1763 MOS_OS_CHK_STATUS_RETURN(osInterface->pfnRegisterResource(osInterface, &(osGpuContext.pCB->OsResource), false, false));
1764 eStatus = MOS_SecureMemcpy(cmdBuffer, sizeof(MOS_COMMAND_BUFFER), osGpuContext.pCB, sizeof(MOS_COMMAND_BUFFER));
1765 MOS_OS_CHECK_CONDITION((eStatus != MOS_STATUS_SUCCESS), "Failed to copy command buffer", eStatus);
1766 return MOS_STATUS_SUCCESS;
1767 }
1768
1769 //!
1770 //! \brief Set indirect state size
1771 //! \details Sets indirect state size to be used for rendering purposes
1772 //! \param PMOS_INTERFACE osInterface
1773 //! [in] Pointer to OS interface structure
1774 //! \param uint32_t uSize
1775 //! [in] State size
1776 //! \return MOS_STATUS
1777 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1778 //!
Mos_Specific_SetIndirectStateSize(PMOS_INTERFACE osInterface,uint32_t size)1779 MOS_STATUS Mos_Specific_SetIndirectStateSize(
1780 PMOS_INTERFACE osInterface,
1781 uint32_t size)
1782 {
1783 MOS_OS_CHK_NULL_RETURN(osInterface);
1784
1785 if (!Mos_Solo_IsEnabled(nullptr))
1786 {
1787 return MosInterface::SetupIndirectState(osInterface->osStreamState, size);
1788 }
1789
1790 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
1791
1792 osInterface->pOsContext->uIndirectStateSize = size;
1793
1794 return MOS_STATUS_SUCCESS;
1795 }
1796
1797 //!
1798 //! \brief Set indirect state size
1799 //! \details Retrieves indirect state to be used for rendering purposes
1800 //! \param PMOS_INTERFACE osInterface
1801 //! [in] Pointer to OS interface structure
1802 //! \param uint32_t *puOffset
1803 //! [out] Pointer to indirect buffer offset
1804 //! \param uint32_t *puSize
1805 //! [out] Pointer to indirect buffer size
1806 //! \return MOS_STATUS
1807 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1808 //!
Mos_Specific_GetIndirectState(PMOS_INTERFACE osInterface,uint32_t * puOffset,uint32_t * puSize)1809 MOS_STATUS Mos_Specific_GetIndirectState(
1810 PMOS_INTERFACE osInterface,
1811 uint32_t *puOffset,
1812 uint32_t *puSize)
1813 {
1814 MOS_OS_FUNCTION_ENTER;
1815
1816 MOS_OS_CHK_NULL_RETURN(osInterface);
1817 MOS_OS_CHK_NULL_RETURN(puOffset);
1818 MOS_OS_CHK_NULL_RETURN(puSize);
1819
1820 if (!Mos_Solo_IsEnabled(nullptr))
1821 {
1822 uint32_t offset = 0;
1823 uint32_t size = 0;
1824 auto eStatus = MosInterface::GetIndirectState(osInterface->osStreamState, nullptr, offset, size);
1825 *puOffset = offset;
1826 *puSize = size;
1827 return eStatus;
1828 }
1829
1830 if (osInterface->pOsContext)
1831 {
1832 MOS_OS_GPU_CONTEXT &osGpuContext = osInterface->pOsContext->OsGpuContext[osInterface->CurrentGpuContextOrdinal];
1833
1834 *puOffset = osGpuContext.uiCommandBufferSize - osInterface->pOsContext->uIndirectStateSize;
1835
1836 *puSize = osInterface->pOsContext->uIndirectStateSize;
1837 }
1838 return MOS_STATUS_SUCCESS;
1839
1840 }
1841
1842 //!
1843 //! \brief Get Resource Allocation Index
1844 //! \details Get Resource Allocation Index
1845 //! \param PMOS_INTERFACE osInterface
1846 //! [in] Pointer to OS interface structure
1847 //! \param PMOS_RESOURCE pResource
1848 //! [in] Pointer to input OS resource
1849 //! \return int32_t
1850 //! return the allocation index
1851 //!
Mos_Specific_GetResourceAllocationIndex(PMOS_INTERFACE osInterface,PMOS_RESOURCE resource)1852 int32_t Mos_Specific_GetResourceAllocationIndex(
1853 PMOS_INTERFACE osInterface,
1854 PMOS_RESOURCE resource)
1855 {
1856 MOS_OS_FUNCTION_ENTER;
1857
1858 if (!resource || !osInterface || osInterface->CurrentGpuContextHandle == MOS_GPU_CONTEXT_INVALID_HANDLE)
1859 {
1860 return MOS_INVALID_ALLOC_INDEX;
1861 }
1862
1863 return(resource->iAllocationIndex[osInterface->CurrentGpuContextOrdinal]);
1864 }
1865
1866 //!
1867 //! \brief Get Indirect State Pointer
1868 //! \details Get Indirect State Pointer
1869 //! \param PMOS_INTERFACE osInterface
1870 //! [in] Pointer to OS interface structure
1871 //! \param uint8_t **indirectState
1872 //! [out] Pointer to Indirect State Buffer
1873 //! \return MOS_STATUS
1874 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1875 //!
Mos_Specific_GetIndirectStatePointer(PMOS_INTERFACE osInterface,uint8_t ** indirectState)1876 MOS_STATUS Mos_Specific_GetIndirectStatePointer(
1877 PMOS_INTERFACE osInterface,
1878 uint8_t **indirectState)
1879 {
1880 MOS_OS_FUNCTION_ENTER;
1881 PMOS_OS_CONTEXT osContext = nullptr;
1882
1883 MOS_OS_CHK_NULL_RETURN(osInterface);
1884 MOS_OS_CHK_NULL_RETURN(indirectState);
1885
1886 uint32_t offset = 0;
1887 uint32_t size = 0;
1888 return MosInterface::GetIndirectState(osInterface->osStreamState, indirectState, offset, size);
1889 }
1890
1891 //!
1892 //! \brief Return command buffer space
1893 //! \details Return unused command buffer space
1894 //! \param PMOS_INTERFACE osInterface
1895 //! [in] Pointer to OS interface structure
1896 //! \param PMOS_COMMAND_BUFFER cmdBuffer
1897 //! [out] Pointer to Command Buffer control structure
1898 //! \return void
1899 //!
Mos_Specific_ReturnCommandBuffer(PMOS_INTERFACE osInterface,PMOS_COMMAND_BUFFER cmdBuffer,uint32_t flags)1900 void Mos_Specific_ReturnCommandBuffer(
1901 PMOS_INTERFACE osInterface,
1902 PMOS_COMMAND_BUFFER cmdBuffer,
1903 uint32_t flags)
1904 {
1905 MOS_OS_FUNCTION_ENTER;
1906 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
1907 MOS_OS_CHK_NULL_NO_STATUS_RETURN(cmdBuffer);
1908
1909 // Need to ensure 4K extra padding for HW requirement.
1910 if (cmdBuffer && cmdBuffer->iRemaining < EXTRA_PADDING_NEEDED)
1911 {
1912 MOS_OS_ASSERTMESSAGE("Need to ensure 4K extra padding for HW requirement.");
1913 }
1914
1915 if (!Mos_Solo_IsEnabled(nullptr))
1916 {
1917 auto status = MosInterface::ReturnCommandBuffer(osInterface->osStreamState, cmdBuffer, flags);
1918 if (MOS_FAILED(status))
1919 {
1920 MOS_OS_ASSERTMESSAGE("ReturnCommandBuffer failed.");
1921 }
1922 return;
1923 }
1924
1925 Linux_ReturnCommandBuffer(osInterface->pOsContext,osInterface->CurrentGpuContextOrdinal, cmdBuffer);
1926 return;
1927 }
1928
1929 //!
1930 //! \brief Submit command buffer
1931 //! \details Submit the command buffer
1932 //! \param PMOS_INTERFACE osInterface
1933 //! [in] Pointer to OS interface structure
1934 //! \param PMOS_COMMAND_BUFFER cmdBuffer
1935 //! [in] Pointer to Command Buffer control structure
1936 //! \param int32_t bNullRendering
1937 //! [in] boolean null rendering
1938 //! \return MOS_STATUS
1939 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1940 //!
Mos_Specific_SubmitCommandBuffer(PMOS_INTERFACE osInterface,PMOS_COMMAND_BUFFER cmdBuffer,int32_t bNullRendering)1941 MOS_STATUS Mos_Specific_SubmitCommandBuffer(
1942 PMOS_INTERFACE osInterface,
1943 PMOS_COMMAND_BUFFER cmdBuffer,
1944 int32_t bNullRendering)
1945 {
1946 MOS_OS_CHK_NULL_RETURN(osInterface);
1947 return MosInterface::SubmitCommandBuffer(osInterface->osStreamState, cmdBuffer, bNullRendering);
1948 }
1949
1950 //!
1951 //! \brief Get resource gfx address
1952 //! \details Get resource gfx address
1953 //! \param PMOS_INTERFACE osInterface
1954 //! [in] Pointer to OS interface structure
1955 //! \param PMOS_RESOURCE pResource
1956 //! [in] Pointer to resource
1957 //! \return uint64_t
1958 //! Return resource gfx address
1959 //!
Mos_Specific_GetResourceGfxAddress(PMOS_INTERFACE osInterface,PMOS_RESOURCE resource)1960 uint64_t Mos_Specific_GetResourceGfxAddress(
1961 PMOS_INTERFACE osInterface,
1962 PMOS_RESOURCE resource)
1963 {
1964 MOS_OS_CHK_NULL_RETURN(osInterface);
1965
1966 return MosInterface::GetResourceGfxAddress(osInterface->osStreamState, resource);
1967 }
1968
1969 //!
1970 //! \brief Get Clear Color Address
1971 //! \details The clear color address
1972 //! \param PMOS_INTERFACE pOsInterface
1973 //! [in] OS Interface
1974 //! \param PMOS_RESOURCE pResource
1975 //! [in] OS resource structure
1976 //! \return uint64_t
1977 //! The clear color address
1978 //!
Mos_Specific_GetResourceClearAddress(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pResource)1979 uint64_t Mos_Specific_GetResourceClearAddress(
1980 PMOS_INTERFACE pOsInterface,
1981 PMOS_RESOURCE pResource)
1982 {
1983 uint64_t ui64ClearColorAddress = 0;
1984 return ui64ClearColorAddress;
1985 }
1986
1987 //!
1988 //! \brief Resizes the buffer to be used for rendering GPU commands
1989 //! \details return true if succeeded - command buffer will be large enough to hold dwMaxSize
1990 //! return false if failed or invalid parameters
1991 //! \param PMOS_INTERFACE osInterface
1992 //! [in] Pointer to OS interface structure
1993 //! \param uint32_t dwRequestedCommandBufferSize
1994 //! [in] requested command buffer size
1995 //! \param uint32_t dwRequestedPatchListSize
1996 //! [in] requested patch list size
1997 //! \return MOS_STATUS
1998 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
1999 //!
Mos_Specific_ResizeCommandBufferAndPatchList(PMOS_INTERFACE osInterface,uint32_t dwRequestedCommandBufferSize,uint32_t dwRequestedPatchListSize,uint32_t dwFlags)2000 MOS_STATUS Mos_Specific_ResizeCommandBufferAndPatchList(
2001 PMOS_INTERFACE osInterface,
2002 uint32_t dwRequestedCommandBufferSize,
2003 uint32_t dwRequestedPatchListSize,
2004 uint32_t dwFlags)
2005 {
2006 MOS_OS_CHK_NULL_RETURN(osInterface);
2007 if (!Mos_Solo_IsEnabled(nullptr))
2008 {
2009 return MosInterface::ResizeCommandBufferAndPatchList(osInterface->osStreamState, 0, dwRequestedCommandBufferSize, dwRequestedPatchListSize, dwFlags);
2010 }
2011
2012 PMOS_CONTEXT osContext = osInterface->pOsContext;
2013 MOS_OS_CHK_NULL_RETURN(osContext);
2014
2015 MOS_OS_GPU_CONTEXT &osGpuContext = osContext->OsGpuContext[osInterface->CurrentGpuContextOrdinal];
2016
2017 // uiCommandBufferSize is used for allocate command buffer and submit command buffer, in this moment, command buffer has not allocated yet.
2018 // Linux KMD requires command buffer size align to 8 bytes, or it will not execute the commands.
2019 osGpuContext.uiCommandBufferSize = MOS_ALIGN_CEIL(dwRequestedCommandBufferSize, 8);
2020
2021 if (dwRequestedPatchListSize > osGpuContext.uiMaxPatchLocationsize)
2022 {
2023 PPATCHLOCATIONLIST pNewPatchList = (PPATCHLOCATIONLIST)realloc(
2024 osGpuContext.pPatchLocationList,
2025 sizeof(PATCHLOCATIONLIST) * dwRequestedPatchListSize);
2026 MOS_OS_CHK_NULL_RETURN(pNewPatchList);
2027
2028 osGpuContext.pPatchLocationList = pNewPatchList;
2029
2030 // now zero the extended portion
2031 MOS_ZeroMemory(
2032 (osGpuContext.pPatchLocationList + osGpuContext.uiMaxPatchLocationsize),
2033 sizeof(PATCHLOCATIONLIST) * (dwRequestedPatchListSize - osGpuContext.uiMaxPatchLocationsize));
2034 osGpuContext.uiMaxPatchLocationsize = dwRequestedPatchListSize;
2035 }
2036
2037 return MOS_STATUS_SUCCESS;
2038 }
2039
2040 //!
2041 //! \brief Create GPU context
2042 //! \details Create GPU context
2043 //! \param PMOS_INTERFACE osInterface
2044 //! [in] Pointer to OS interface structure
2045 //! \param MOS_GPU_CONTEXT gpuContext
2046 //! [in] GPU Context
2047 //! \param MOS_GPU_NODE GpuNode
2048 //! [in] GPU Node
2049 //! \return MOS_STATUS
2050 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2051 //!
Mos_Specific_CreateGpuContext(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT mosGpuCxt,MOS_GPU_NODE gpuNode,PMOS_GPUCTX_CREATOPTIONS createOption)2052 MOS_STATUS Mos_Specific_CreateGpuContext(
2053 PMOS_INTERFACE osInterface,
2054 MOS_GPU_CONTEXT mosGpuCxt,
2055 MOS_GPU_NODE gpuNode,
2056 PMOS_GPUCTX_CREATOPTIONS createOption)
2057 {
2058 MOS_OS_FUNCTION_ENTER;
2059
2060 MOS_OS_CHK_NULL_RETURN(osInterface);
2061
2062 if (mosGpuCxt >= MOS_GPU_CONTEXT_MAX)
2063 {
2064 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
2065 return MOS_STATUS_INVALID_PARAMETER;
2066 }
2067
2068 if (!Mos_Solo_IsEnabled(nullptr))
2069 {
2070 MOS_OS_CHK_NULL_RETURN(createOption);
2071 if (gpuNode == MOS_GPU_NODE_3D && createOption->SSEUValue != 0)
2072 {
2073 struct drm_i915_gem_context_param_sseu sseu;
2074 MOS_ZeroMemory(&sseu, sizeof(sseu));
2075 sseu.engine.engine_class = I915_ENGINE_CLASS_RENDER;
2076 sseu.engine.engine_instance = 0;
2077
2078 if (mos_get_context_param_sseu(osInterface->pOsContext->intel_context, &sseu))
2079 {
2080 MOS_OS_ASSERTMESSAGE("Failed to get sseu configuration.");
2081 return MOS_STATUS_UNKNOWN;
2082 };
2083
2084 if (mos_hweight8(osInterface->pOsContext->intel_context, sseu.subslice_mask) > createOption->packed.SubSliceCount)
2085 {
2086 sseu.subslice_mask = mos_switch_off_n_bits(osInterface->pOsContext->intel_context, sseu.subslice_mask,
2087 mos_hweight8(osInterface->pOsContext->intel_context, sseu.subslice_mask)-createOption->packed.SubSliceCount);
2088 }
2089
2090 if (mos_set_context_param_sseu(osInterface->pOsContext->intel_context, sseu))
2091 {
2092 MOS_OS_ASSERTMESSAGE("Failed to set sseu configuration.");
2093 return MOS_STATUS_UNKNOWN;
2094 }
2095 }
2096
2097 createOption->gpuNode = gpuNode;
2098 MOS_OS_CHK_NULL_RETURN(osInterface->osStreamState);
2099 // Update ctxBasedScheduling from legacy OsInterface
2100 osInterface->osStreamState->ctxBasedScheduling = osInterface->ctxBasedScheduling;
2101 if (osInterface->m_GpuContextHandleMap[mosGpuCxt] == MOS_GPU_CONTEXT_INVALID_HANDLE)
2102 {
2103 auto osDeviceContext = osInterface->osStreamState->osDeviceContext;
2104 MOS_OS_CHK_NULL_RETURN(osDeviceContext);
2105 auto gpuContextMgr = osDeviceContext->GetGpuContextMgr();
2106 MOS_OS_CHK_NULL_RETURN(gpuContextMgr);
2107 auto cmdBufMgr = osDeviceContext->GetCmdBufferMgr();
2108 MOS_OS_CHK_NULL_RETURN(cmdBufMgr);
2109
2110 auto gpuContext = gpuContextMgr->CreateGpuContext(gpuNode, cmdBufMgr);
2111 MOS_OS_CHK_NULL_RETURN(gpuContext);
2112
2113 auto gpuContextSpecific = static_cast<GpuContextSpecificNext *>(gpuContext);
2114 MOS_OS_CHK_NULL_RETURN(gpuContextSpecific);
2115
2116 MOS_OS_CHK_STATUS_RETURN(gpuContextSpecific->Init(gpuContextMgr->GetOsContext(), osInterface->osStreamState, createOption));
2117 gpuContextSpecific->SetGpuContext(mosGpuCxt);
2118 osInterface->m_GpuContextHandleMap[mosGpuCxt] = gpuContextSpecific->GetGpuContextHandle();
2119 }
2120
2121 return MOS_STATUS_SUCCESS;
2122
2123 }
2124
2125 MOS_UNUSED(osInterface);
2126 MOS_UNUSED(mosGpuCxt);
2127 MOS_UNUSED(gpuNode);
2128 MOS_UNUSED(createOption);
2129 return MOS_STATUS_SUCCESS;
2130 }
2131
2132 GPU_CONTEXT_HANDLE
Mos_Specific_CreateGpuComputeContext(MOS_INTERFACE * osInterface,MOS_GPU_CONTEXT contextName,MOS_GPUCTX_CREATOPTIONS * createOption)2133 Mos_Specific_CreateGpuComputeContext(MOS_INTERFACE *osInterface,
2134 MOS_GPU_CONTEXT contextName,
2135 MOS_GPUCTX_CREATOPTIONS *createOption)
2136 {
2137 MOS_OS_FUNCTION_ENTER;
2138 MOS_OS_CHK_NULL_RETURN(osInterface);
2139
2140 if (MOS_GPU_CONTEXT_CM_COMPUTE != contextName
2141 && MOS_GPU_CONTEXT_COMPUTE != contextName)
2142 {
2143 MOS_OS_ASSERTMESSAGE("Invalid input parameter contextName.");
2144 return MOS_GPU_CONTEXT_INVALID_HANDLE;
2145 }
2146
2147 if (!Mos_Solo_IsEnabled(nullptr))
2148 {
2149 if (nullptr == createOption)
2150 {
2151 MOS_OS_ASSERTMESSAGE("Invalid pointer (nullptr).");
2152 return MOS_GPU_CONTEXT_INVALID_HANDLE;
2153 }
2154
2155 if (nullptr == osInterface->osStreamState)
2156 {
2157 MOS_OS_ASSERTMESSAGE("Invalid pointer (nullptr).");
2158 return MOS_GPU_CONTEXT_INVALID_HANDLE;
2159 }
2160
2161 // Update ctxBasedScheduling from legacy OsInterface
2162 osInterface->osStreamState->ctxBasedScheduling
2163 = osInterface->ctxBasedScheduling;
2164
2165 // Only wrapper will contain re-creation check based on stream Index and MOS_GPU_CONTEXT
2166 createOption->gpuNode = MOS_GPU_NODE_COMPUTE;
2167 GPU_CONTEXT_HANDLE context_handle = MOS_GPU_CONTEXT_INVALID_HANDLE;
2168 MOS_STATUS status
2169 = MosInterface::CreateGpuContext(osInterface->osStreamState,
2170 *createOption, context_handle);
2171 if (MOS_FAILED(status))
2172 {
2173 return MOS_GPU_CONTEXT_INVALID_HANDLE;
2174 }
2175
2176 auto os_device_context = osInterface->osStreamState->osDeviceContext;
2177 auto gpu_context_mgr = os_device_context->GetGpuContextMgr();
2178 if (nullptr == gpu_context_mgr)
2179 {
2180 return MOS_GPU_CONTEXT_INVALID_HANDLE;
2181 }
2182 GpuContextNext *context_next
2183 = gpu_context_mgr->GetGpuContext(context_handle);
2184 auto context_specific_next
2185 = static_cast<GpuContextSpecificNext*>(context_next);
2186 if (nullptr == context_specific_next)
2187 {
2188 return MOS_GPU_CONTEXT_INVALID_HANDLE;
2189 }
2190 context_specific_next->SetGpuContext(contextName);
2191 return context_handle;
2192 }
2193 return MOS_GPU_CONTEXT_INVALID_HANDLE;
2194 }
2195
2196 //!
2197 //! \brief Destroy GPU context
2198 //! \details Destroy GPU context
2199 //! [in] Pointer to OS interface structure
2200 //! \param MOS_GPU_CONTEXT gpuContext
2201 //! [in] GPU Context
2202 //! \return MOS_STATUS
2203 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2204 //!
Mos_Specific_DestroyGpuContext(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT mosGpuCxt)2205 MOS_STATUS Mos_Specific_DestroyGpuContext(
2206 PMOS_INTERFACE osInterface,
2207 MOS_GPU_CONTEXT mosGpuCxt)
2208 {
2209 MOS_OS_FUNCTION_ENTER;
2210
2211 MOS_OS_CHK_NULL_RETURN(osInterface);
2212
2213 if (mosGpuCxt >= MOS_GPU_CONTEXT_MAX)
2214 {
2215 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
2216 return MOS_STATUS_INVALID_PARAMETER;
2217 }
2218
2219 if (!Mos_Solo_IsEnabled(nullptr))
2220 {
2221 auto status = MosInterface::DestroyGpuContext(osInterface->osStreamState, osInterface->m_GpuContextHandleMap[mosGpuCxt]);
2222 osInterface->m_GpuContextHandleMap[mosGpuCxt] = MOS_GPU_CONTEXT_INVALID_HANDLE;
2223 return status;
2224 }
2225
2226 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
2227 MOS_UNUSED(osInterface);
2228 MOS_UNUSED(mosGpuCxt);
2229 return eStatus;
2230 }
2231
2232 //!
2233 //! \brief Destroy Compute GPU context
2234 //! \details Destroy Compute GPU context
2235 //! [in] Pointer to OS interface structure
2236 //! \param GPU_CONTEXT_HANDLE gpuContextHandle
2237 //! [in] GPU Context handle
2238 //! \return MOS_STATUS
2239 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2240 //!
Mos_Specific_DestroyGpuComputeContext(PMOS_INTERFACE osInterface,GPU_CONTEXT_HANDLE gpuContextHandle)2241 MOS_STATUS Mos_Specific_DestroyGpuComputeContext(
2242 PMOS_INTERFACE osInterface,
2243 GPU_CONTEXT_HANDLE gpuContextHandle)
2244 {
2245 MOS_OS_FUNCTION_ENTER;
2246
2247 MOS_OS_CHK_NULL_RETURN(osInterface);
2248 if(MOS_GPU_CONTEXT_INVALID_HANDLE == gpuContextHandle)
2249 {
2250 MOS_OS_ASSERTMESSAGE("Invalid compute gpu context handle.");
2251 return MOS_STATUS_INVALID_HANDLE;
2252 }
2253 if (Mos_Solo_IsEnabled(nullptr))
2254 {
2255 return MOS_STATUS_SUCCESS;
2256 }
2257
2258 GPU_CONTEXT_HANDLE iGpuContextHandle = osInterface->m_GpuContextHandleMap[MOS_GPU_CONTEXT_CM_COMPUTE];
2259 if (iGpuContextHandle == gpuContextHandle)
2260 {
2261 MOS_OS_ASSERTMESSAGE("It will be destroyed in osInterface destroy.");
2262 return MOS_STATUS_SUCCESS;
2263 }
2264 auto gpuContext = MosInterface::GetGpuContext(osInterface->osStreamState, gpuContextHandle);
2265 MOS_OS_CHK_NULL_RETURN(gpuContext);
2266
2267 MOS_GPU_CONTEXT gpuContextName = gpuContext->GetCpuContextID();
2268 if(gpuContextName != MOS_GPU_CONTEXT_CM_COMPUTE && gpuContextName != MOS_GPU_CONTEXT_COMPUTE)
2269 {
2270 MOS_OS_ASSERTMESSAGE("It is not compute gpu context and it will be destroyed in osInterface destroy.");
2271 return MOS_STATUS_SUCCESS;
2272 }
2273 return MosInterface::DestroyGpuContext(osInterface->osStreamState, gpuContextHandle);
2274 }
2275
2276 //!
2277 //! \brief Sets the perf tag
2278 //! \details Sets the perf tag
2279 //! \param PMOS_INTERFACE osInterface
2280 //! [in] Pointer to OS interface structure
2281 //! \param uint32_t PerfTag
2282 //! [in] Perf tag
2283 //! \return void
2284 //!
Mos_Specific_SetPerfTag(PMOS_INTERFACE osInterface,uint32_t perfTag)2285 void Mos_Specific_SetPerfTag(
2286 PMOS_INTERFACE osInterface,
2287 uint32_t perfTag)
2288 {
2289 uint32_t componentTag = 0;
2290 PMOS_CONTEXT osContext = nullptr;
2291
2292 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
2293
2294 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface->osStreamState);
2295 osInterface->osStreamState->component = osInterface->Component;
2296 return MosInterface::SetPerfTag(osInterface->osStreamState, perfTag);
2297 }
2298
2299 //!
2300 //! \brief Resets the perf tag
2301 //! \details Resets the perf tag
2302 //! \param PMOS_INTERFACE osInterface
2303 //! [in] Pointer to OS interface structure
2304 //! \return void
2305 //!
Mos_Specific_ResetPerfBufferID(PMOS_INTERFACE osInterface)2306 void Mos_Specific_ResetPerfBufferID(
2307 PMOS_INTERFACE osInterface)
2308 {
2309 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
2310
2311 return MosInterface::ResetPerfBufferID(osInterface->osStreamState);
2312 }
2313
2314 //!
2315 //! \brief Increment the perf tag for buffer ID
2316 //! \details Increment the perf tag for buffer ID
2317 //! \param PMOS_INTERFACE osInterface
2318 //! [in] Pointer to OS interface structure
2319 //! \return void
2320 //!
Mos_Specific_IncPerfBufferID(PMOS_INTERFACE osInterface)2321 void Mos_Specific_IncPerfBufferID(
2322 PMOS_INTERFACE osInterface)
2323 {
2324 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
2325
2326 return MosInterface::IncPerfBufferID(osInterface->osStreamState);
2327 }
2328
2329 //!
2330 //! \brief Increment the perf tag for Frame ID
2331 //! \details Increment the perf tag for frame ID
2332 //! \param PMOS_INTERFACE osInterface
2333 //! [in] Pointer to OS interface structure
2334 //! \return void
2335 //!
Mos_Specific_IncPerfFrameID(PMOS_INTERFACE osInterface)2336 void Mos_Specific_IncPerfFrameID(
2337 PMOS_INTERFACE osInterface)
2338 {
2339 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
2340
2341 return MosInterface::IncPerfFrameID(osInterface->osStreamState);
2342 }
2343
2344 //!
2345 //! \brief Gets the perf tag
2346 //! \details Gets the perf tag
2347 //! \param PMOS_INTERFACE osInterface
2348 //! [in] Pointer to OS interface structure
2349 //! \return uint32_t
2350 //! Return perf tag
2351 //!
Mos_Specific_GetPerfTag(PMOS_INTERFACE osInterface)2352 uint32_t Mos_Specific_GetPerfTag(
2353 PMOS_INTERFACE osInterface)
2354 {
2355 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, 0);
2356
2357 return MosInterface::GetPerfTag(osInterface->osStreamState);
2358 }
2359
2360 //!
2361 //! \brief Check if Perf Tag is already set
2362 //! \details Check if Perf Tag is already set
2363 //! \param PMOS_INTERFACE osInterface
2364 //! [in] OS Interface
2365 //! \return int32_t
2366 //!
Mos_Specific_IsPerfTagSet(PMOS_INTERFACE osInterface)2367 int32_t Mos_Specific_IsPerfTagSet(
2368 PMOS_INTERFACE osInterface)
2369 {
2370 uint32_t ComponentTag;
2371 int32_t bRet = false;
2372 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, false);
2373 return MosInterface::IsPerfTagSet(osInterface->osStreamState);
2374 }
2375
2376 //!
2377 //! \brief Check for GPU context valid
2378 //! \details Always returns MOS_STATUS_SUCCESS on Linux.
2379 // This interface is implemented for compatibility.
2380 //! \param PMOS_INTERFACE osInterface
2381 //! [in] pointer to Os interface structure
2382 //! \param MOS_GPU_CONTEXT gpuContext
2383 //! [in] Gpu Context
2384 //! \return MOS_STATUS
2385 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2386 //!
Mos_Specific_IsGpuContextValid(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext)2387 MOS_STATUS Mos_Specific_IsGpuContextValid(
2388 PMOS_INTERFACE osInterface,
2389 MOS_GPU_CONTEXT gpuContext)
2390 {
2391 MOS_UNUSED(osInterface);
2392 MOS_UNUSED(gpuContext);
2393 return MOS_STATUS_SUCCESS;
2394 }
2395
2396 //!
2397 //! \brief Unified OS Resources sync
2398 //! \details Tag based synchronization at the resource level
2399 //! \param PMOS_INTERFACE osInterface
2400 //! [in] Pointer to OS Interface
2401 //! \param PMOS_RESOURCE osResource
2402 //! [in] Pointer to OS Resource
2403 //! \param MOS_GPU_CONTEXT requestorGPUCtx
2404 //! [in] GPU Context
2405 //! \param int32_t bWriteOperation
2406 //! [in] true if write operation
2407 //! \return void
2408 //!
Mos_Specific_SyncOnResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,MOS_GPU_CONTEXT requestorGPUCtx,int32_t bWriteOperation)2409 void Mos_Specific_SyncOnResource(
2410 PMOS_INTERFACE osInterface,
2411 PMOS_RESOURCE osResource,
2412 MOS_GPU_CONTEXT requestorGPUCtx,
2413 int32_t bWriteOperation)
2414 {
2415 MOS_UNUSED(osInterface);
2416 MOS_UNUSED(osResource);
2417 MOS_UNUSED(requestorGPUCtx);
2418 MOS_UNUSED(bWriteOperation);
2419 }
2420
2421 //!
2422 //! \brief Checks for HW enabled
2423 //! \details Checks for HW enabled
2424 //! \param PMOS_INTERFACE osInterface
2425 //! [in] pointer to Os interface structure
2426 //! \return int32_t
2427 //! Returns true id HW enabled if CP mode
2428 //!
Mos_Specific_IsNullHWEnabled(PMOS_INTERFACE osInterface)2429 int32_t Mos_Specific_IsNullHWEnabled(
2430 PMOS_INTERFACE osInterface)
2431 {
2432 MOS_UNUSED(osInterface);
2433 return false;
2434 }
2435
2436 //!
2437 //! \brief Get GPU status buffer
2438 //! \details Gets the status buffer for the resource
2439 //! \param PMOS_INTERFACE osInterface
2440 //! [in] Pointer to OS Interface
2441 //! \param PMOS_RESOURCE osResource
2442 //! [out] Pointer to OS Resource
2443 //! \return MOS_STATUS
2444 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2445 //!
Mos_Specific_GetGpuStatusBufferResource(PMOS_INTERFACE osInterface,PMOS_RESOURCE & osResource)2446 MOS_STATUS Mos_Specific_GetGpuStatusBufferResource(
2447 PMOS_INTERFACE osInterface,
2448 PMOS_RESOURCE &osResource)
2449 {
2450 MOS_OS_CHK_NULL_RETURN(osInterface);
2451 MOS_OS_CHK_NULL_RETURN(osInterface->osStreamState);
2452
2453 if(!Mos_Solo_IsEnabled(nullptr))
2454 {
2455 return MosInterface::GetGpuStatusBufferResource(osInterface->osStreamState, osResource, osInterface->osStreamState->currentGpuContextHandle);
2456 }
2457
2458 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
2459
2460 osResource = osInterface->pOsContext->pGPUStatusBuffer;
2461 return MOS_STATUS_SUCCESS;
2462
2463 }
2464
2465 //!
2466 //! \brief Get GPU status tag offset
2467 //! \details Gets the status tag offset
2468 //! \param PMOS_INTERFACE osInterface
2469 //! [in] Pointer to OS Interface
2470 //! \param MOS_GPU_CONTEXT gpuContext
2471 //! [in] GPU Context
2472 //! \return uint32_t
2473 //! Returns the tag offset
2474 //!
Mos_Specific_GetGpuStatusTagOffset(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext)2475 uint32_t Mos_Specific_GetGpuStatusTagOffset(
2476 PMOS_INTERFACE osInterface,
2477 MOS_GPU_CONTEXT gpuContext)
2478 {
2479 MOS_OS_FUNCTION_ENTER;
2480 if(Mos_Solo_IsEnabled(nullptr))
2481 {
2482 return sizeof(MOS_GPU_STATUS_DATA) * gpuContext;
2483 }
2484
2485 return 0;
2486 }
2487
2488 //!
2489 //! \brief Get GPU status tag
2490 //! \details Gets the status tag
2491 //! \param PMOS_INTERFACE osInterface
2492 //! [in] Pointer to OS Interface
2493 //! \param MOS_GPU_CONTEXT gpuContext
2494 //! [in] GPU Context
2495 //! \return uint32_t
2496 //! Returns the tag
2497 //!
Mos_Specific_GetGpuStatusTag(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT mosGpuCtx)2498 uint32_t Mos_Specific_GetGpuStatusTag(
2499 PMOS_INTERFACE osInterface,
2500 MOS_GPU_CONTEXT mosGpuCtx)
2501 {
2502 MOS_OS_FUNCTION_ENTER;
2503
2504 if (osInterface == nullptr)
2505 {
2506 MOS_OS_ASSERTMESSAGE("osInterface == nullptr");
2507 return -1;
2508 }
2509
2510 if (mosGpuCtx >= MOS_GPU_CONTEXT_MAX)
2511 {
2512 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
2513 return -1;
2514 }
2515
2516 if (!Mos_Solo_IsEnabled(nullptr))
2517 {
2518 auto handle = osInterface->m_GpuContextHandleMap[mosGpuCtx];
2519
2520 return MosInterface::GetGpuStatusTag(osInterface->osStreamState, handle);
2521 }
2522
2523 return Linux_GetGpuCtxBufferTag(osInterface->pOsContext, mosGpuCtx);
2524 }
2525
2526 //!
2527 //! \brief Increment GPU status tag
2528 //! \details Increment the status tag
2529 //! \param PMOS_INTERFACE osInterface
2530 //! [in] Pointer to OS Interface
2531 //! \param MOS_GPU_CONTEXT gpuContext
2532 //! [in] GPU Context
2533 //! \return void
2534 //!
Mos_Specific_IncrementGpuStatusTag(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT mosGpuCtx)2535 void Mos_Specific_IncrementGpuStatusTag(
2536 PMOS_INTERFACE osInterface,
2537 MOS_GPU_CONTEXT mosGpuCtx)
2538 {
2539 MOS_OS_FUNCTION_ENTER;
2540 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
2541
2542 if (mosGpuCtx >= MOS_GPU_CONTEXT_MAX)
2543 {
2544 MOS_OS_ASSERTMESSAGE("Invalid input parameter gpuContext.");
2545 return;
2546 }
2547
2548 if (!Mos_Solo_IsEnabled(nullptr))
2549 {
2550 auto handle = osInterface->m_GpuContextHandleMap[mosGpuCtx];
2551
2552 MosInterface::IncrementGpuStatusTag(osInterface->osStreamState, handle);
2553 return;
2554 }
2555
2556 return Linux_IncGpuCtxBufferTag(osInterface->pOsContext, mosGpuCtx);
2557 }
2558
2559 //!
2560 //! \brief Get GPU status Sync tag
2561 //! \details This function will return the GPU status tag which is updated when corresponding
2562 //! GPU packet is done. User can use this flag to check if some GPU packet is done.
2563 //! \param PMOS_INTERFACE osInterface
2564 //! [in] Pointer to OS Interface
2565 //! \param MOS_GPU_CONTEXT gpuContext
2566 //! [in] GPU Context
2567 //! \return uint32_t
2568 //! Returns the tag
2569 //!
Mos_Specific_GetGpuStatusSyncTag(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext)2570 uint32_t Mos_Specific_GetGpuStatusSyncTag(
2571 PMOS_INTERFACE osInterface,
2572 MOS_GPU_CONTEXT gpuContext)
2573 {
2574 MOS_OS_FUNCTION_ENTER;
2575 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, 0);
2576 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface->pOsContext, 0);
2577
2578 if (!Mos_Solo_IsEnabled(nullptr))
2579 {
2580 auto handle = osInterface->m_GpuContextHandleMap[gpuContext];
2581
2582 PMOS_RESOURCE gpuStatusResource = nullptr;
2583 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetGpuStatusBufferResource(osInterface->osStreamState, gpuStatusResource, handle));
2584 MOS_OS_CHK_NULL_RETURN(gpuStatusResource);
2585 auto gpuStatusData = (MOS_GPU_STATUS_DATA *)gpuStatusResource->pData;
2586 if (gpuStatusData == nullptr)
2587 {
2588 MOS_OS_ASSERTMESSAGE("cannot find ");
2589 return 0;
2590 }
2591 return gpuStatusData->GPUTag;
2592 }
2593 else
2594 {
2595 MOS_GPU_STATUS_DATA *pGPUStatusData = nullptr;
2596
2597 if ( osInterface->pOsContext->pGPUStatusBuffer == nullptr ||
2598 osInterface->pOsContext->pGPUStatusBuffer->pData == nullptr)
2599 {
2600 return 0;
2601 }
2602
2603 pGPUStatusData = (MOS_GPU_STATUS_DATA *)(osInterface->pOsContext->pGPUStatusBuffer->pData + (sizeof(MOS_GPU_STATUS_DATA) * gpuContext));
2604 if (pGPUStatusData == nullptr)
2605 {
2606 MOS_OS_ASSERTMESSAGE("cannot find the gpuContext corresponding to the active resource");
2607 return 0;
2608 }
2609 return pGPUStatusData->GPUTag;
2610 }
2611 }
2612
2613 //!
2614 //! \brief Sets the resource sync tag
2615 //! \details Dummy implementation on Linux for compatibility.
2616 //! \param PMOS_INTERFACE osInterface
2617 //! [in] Pointer to OS Interface
2618 //! \param PMOS_SYNC_PARAMS pParams
2619 //! [in] Pointer to sync params
2620 //! \return void
2621 //!
Mos_Specific_SetResourceSyncTag(PMOS_INTERFACE osInterface,PMOS_SYNC_PARAMS pParams)2622 void Mos_Specific_SetResourceSyncTag(
2623 PMOS_INTERFACE osInterface,
2624 PMOS_SYNC_PARAMS pParams)
2625 {
2626 MOS_UNUSED(osInterface);
2627 MOS_UNUSED(pParams);
2628 return ;
2629 }
2630
2631 //!
2632 //! \brief Perform overlay sync
2633 //! \details Dummy implementation on Linux for compatibility.
2634 //! \param PMOS_INTERFACE osInterface
2635 //! [in] Pointer to OS Interface
2636 //! \param PMOS_SYNC_PARAMS pParams
2637 //! [in] Pointer to sync params
2638 //! \return MOS_STATUS
2639 //! Return MOS_STATUS_SUCCESS
2640 //!
Mos_Specific_PerformOverlaySync(PMOS_INTERFACE osInterface,PMOS_SYNC_PARAMS pParams)2641 MOS_STATUS Mos_Specific_PerformOverlaySync(
2642 PMOS_INTERFACE osInterface,
2643 PMOS_SYNC_PARAMS pParams)
2644 {
2645 MOS_UNUSED(osInterface);
2646 MOS_UNUSED(pParams);
2647 return MOS_STATUS_SUCCESS;
2648 }
2649
2650 //!
2651 //! \brief Wait on resource
2652 //! \details Dummy implementation on Linux for compatibility.
2653 //! \param PMOS_INTERFACE osInterface
2654 //! [in] Pointer to OS Interface
2655 //! \param PMOS_SYNC_PARAMS pParams
2656 //! [in] Pointer to sync params
2657 //! \return MOS_STATUS
2658 //! Return MOS_STATUS_SUCCESS
2659 //!
Mos_Specific_ResourceWait(PMOS_INTERFACE osInterface,PMOS_SYNC_PARAMS pParams)2660 MOS_STATUS Mos_Specific_ResourceWait(
2661 PMOS_INTERFACE osInterface,
2662 PMOS_SYNC_PARAMS pParams)
2663 {
2664 MOS_UNUSED(osInterface);
2665 MOS_UNUSED(pParams);
2666 return MOS_STATUS_SUCCESS;
2667 }
2668
2669 //!
2670 //! \brief Registers a complete notification event
2671 //! \details Registers a complete notification event
2672 //! \param PMOS_INTERFACE osInterface
2673 //! [in] Pointer to OS Interface
2674 //! \param MOS_GPU_CONTEXT gpuContext
2675 //! [in] GPU Context
2676 //! \return MOS_STATUS
2677 //! Return MOS_STATUS_SUCCESS
2678 //!
Mos_Specific_RegisterBBCompleteNotifyEvent(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext)2679 MOS_STATUS Mos_Specific_RegisterBBCompleteNotifyEvent(
2680 PMOS_INTERFACE osInterface,
2681 MOS_GPU_CONTEXT gpuContext)
2682 {
2683 MOS_UNUSED(osInterface);
2684 MOS_UNUSED(gpuContext);
2685 return MOS_STATUS_SUCCESS;
2686 }
2687
2688 //!
2689 //! \brief Waits on a complete notification event
2690 //! \details Waits on a complete notification event
2691 //! \param PMOS_INTERFACE osInterface
2692 //! [in] Pointer to OS Interface
2693 //! \param uint32_t uiTimeOut
2694 //! [in] Time to wait (ms)
2695 //! \return MOS_STATUS
2696 //! Return MOS_STATUS_SUCCESS
2697 //!
Mos_Specific_WaitForBBCompleteNotifyEvent(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext,uint32_t uiTimeOut)2698 MOS_STATUS Mos_Specific_WaitForBBCompleteNotifyEvent(
2699 PMOS_INTERFACE osInterface,
2700 MOS_GPU_CONTEXT gpuContext,
2701 uint32_t uiTimeOut)
2702 {
2703 MOS_UNUSED(osInterface);
2704 MOS_UNUSED(gpuContext);
2705 usleep(1000 * uiTimeOut);
2706
2707 return MOS_STATUS_SUCCESS;
2708 }
2709
Mos_Specific_WaitAllCmdCompletion_Os(PMOS_INTERFACE osInterface)2710 MOS_STATUS Mos_Specific_WaitAllCmdCompletion_Os(
2711 PMOS_INTERFACE osInterface)
2712 {
2713 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
2714
2715 return eStatus;
2716 }
2717
2718 //!
2719 //! \brief Get interface version
2720 //! \details Get interface version
2721 //!
2722 //! \param PMOS_INTERFACE osInterface
2723 //! [in] OS Interface
2724 //!
2725 //! \return uint32_t
2726 //! Read-only OS runtime interface version, it's meaning diff from OS and API
2727 //!
Mos_Specific_GetInterfaceVersion(PMOS_INTERFACE osInterface)2728 uint32_t Mos_Specific_GetInterfaceVersion(
2729 PMOS_INTERFACE osInterface)
2730 {
2731 MOS_UNUSED(osInterface);
2732 return 0;
2733 }
2734
2735 //!
2736 //! \brief Sets the flags to skip the sync on a particular resource
2737 //! \details This is required to avoid updating resource tags/masks for a given resource
2738 //! This way we dont end up putting unnecessary sync points by syncing on this particular resource
2739 //! \param PMOS_ALLOC_GFXRES_PARAMS pAllocParams
2740 //! [in] allocation parameters
2741 //! \return MOS_STATUS
2742 //! Return MOS_STATUS_SUCCESS if success else failure reason
2743 //!
Mos_Specific_SkipResourceSync(PMOS_RESOURCE osResource)2744 MOS_STATUS Mos_Specific_SkipResourceSync(
2745 PMOS_RESOURCE osResource)
2746 {
2747 MOS_OS_CHK_NULL_RETURN(osResource);
2748
2749 mos_bo_set_object_async(osResource->bo);
2750
2751 return MOS_STATUS_SUCCESS;
2752 }
2753
2754 //!
2755 //! \brief Gets the HW rendering flags
2756 //! \details Gets the HW rendering flags
2757 //! \param PMOS_INTERFACE osInterface
2758 //! [in] Pointer to OS Interface
2759 //! \return MOS_NULL_RENDERING_FLAGS
2760 //! Returns the null rendering flags
2761 //!
Mos_Specific_GetNullHWRenderFlags(PMOS_INTERFACE osInterface)2762 MOS_NULL_RENDERING_FLAGS Mos_Specific_GetNullHWRenderFlags(
2763 PMOS_INTERFACE osInterface)
2764 {
2765 return osInterface->NullHWAccelerationEnable;
2766 }
2767
2768 //!
2769 //! \brief Debug hook to note type of surface state or sampler state being
2770 //! used.
2771 //! \details Sets the Command buffer debug info
2772 //! \param PMOS_INTERFACE osInterface
2773 //! [in] Pointer to OS Interface
2774 //! \param int32_t bSamplerState
2775 //! [in] Sampler state
2776 //! \param int32_t bSurfaceState
2777 //! [in] Surface state
2778 //! \param uint32_t dwStateIndex
2779 //! [in] State index
2780 //! \param uint32_t dwType
2781 //! [in] dword type
2782 //! \return MOS_STATUS
2783 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2784 //!
Mos_Specific_SetCmdBufferDebugInfo(PMOS_INTERFACE osInterface,int32_t bSamplerState,int32_t bSurfaceState,uint32_t dwStateIndex,uint32_t dwType)2785 MOS_STATUS Mos_Specific_SetCmdBufferDebugInfo(
2786 PMOS_INTERFACE osInterface,
2787 int32_t bSamplerState,
2788 int32_t bSurfaceState,
2789 uint32_t dwStateIndex,
2790 uint32_t dwType)
2791 {
2792 MOS_UNUSED(osInterface);
2793 MOS_UNUSED(bSamplerState);
2794 MOS_UNUSED(bSurfaceState);
2795 MOS_UNUSED(dwStateIndex);
2796 MOS_UNUSED(dwType);
2797 // stub function. implemented for simulation but not driver.
2798 return MOS_STATUS_SUCCESS;
2799 }
2800
2801 //!
2802 //! \brief Command buffer debug
2803 //! \details Debug hook to get type of surface state or sampler state being
2804 //! used.
2805 //! \param PMOS_INTERFACE osInterface
2806 //! \param int32_t bSamplerState
2807 //! \param int32_t bSurfaceState
2808 //! \param uint32_t dwStateIndex
2809 //! \return uint32_t
2810 //!
Mos_Specific_GetCmdBufferDebugInfo(PMOS_INTERFACE osInterface,int32_t bSamplerState,int32_t bSurfaceState,uint32_t dwStateIndex)2811 uint32_t Mos_Specific_GetCmdBufferDebugInfo(
2812 PMOS_INTERFACE osInterface,
2813 int32_t bSamplerState,
2814 int32_t bSurfaceState,
2815 uint32_t dwStateIndex)
2816 {
2817 MOS_UNUSED(osInterface);
2818 MOS_UNUSED(bSamplerState);
2819 MOS_UNUSED(bSurfaceState);
2820 MOS_UNUSED(dwStateIndex);
2821 // stub function. implemented for simulation but not driver.
2822 return 0;
2823 }
2824
2825 //!
2826 //! \brief Set PAK/MFX context for Encoder which can be used for Synchronization
2827 //! \details On Linux, the synchronization is handled in KMD, no job in UMD
2828 //! \param PMOS_INTERFACE osInterface
2829 //! [in] pointer to OS interface structure
2830 //! \param MOS_GPU_CONTEXT gpuContext
2831 //! [in] GPU context
2832 //! \return MOS_STATUS
2833 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2834 //!
Mos_Specific_SetEncodePakContext(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext)2835 void Mos_Specific_SetEncodePakContext(
2836 PMOS_INTERFACE osInterface,
2837 MOS_GPU_CONTEXT gpuContext)
2838 {
2839 MOS_UNUSED(osInterface);
2840 MOS_UNUSED(gpuContext);
2841 return;
2842 }
2843
2844 //!
2845 //! \brief Set VME/ENC context for Encoder which can be used for Synchronization
2846 //! \details On Linux, the synchronization is handled in KMD, no job in UMD
2847 //! \param PMOS_INTERFACE osInterface
2848 //! [in] pointer to OS interface structure
2849 //! \param MOS_GPU_CONTEXT gpuContext
2850 //! [in] GPU context
2851 //! \return MOS_STATUS
2852 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2853 //!
Mos_Specific_SetEncodeEncContext(PMOS_INTERFACE osInterface,MOS_GPU_CONTEXT gpuContext)2854 void Mos_Specific_SetEncodeEncContext(
2855 PMOS_INTERFACE osInterface,
2856 MOS_GPU_CONTEXT gpuContext)
2857 {
2858 MOS_UNUSED(osInterface);
2859 MOS_UNUSED(gpuContext);
2860 return;
2861 }
2862
2863 //!
2864 //! \brief Verifys the patch list to be used for rendering GPU commands is large enough
2865 //! \details
2866 //! \param PMOS_INTERFACE osInterface
2867 //! [in] pointer to OS interface structure
2868 //! \param uint32_t dwRequestedSize
2869 //! [in] patch list size to be verified
2870 //! \return MOS_STATUS
2871 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2872 //!
Mos_Specific_VerifyPatchListSize(PMOS_INTERFACE osInterface,uint32_t dwRequestedSize)2873 MOS_STATUS Mos_Specific_VerifyPatchListSize(
2874 PMOS_INTERFACE osInterface,
2875 uint32_t dwRequestedSize)
2876 {
2877 MOS_OS_FUNCTION_ENTER;
2878
2879 MOS_OS_CHK_NULL_RETURN(osInterface);
2880
2881 // No APO MOS interface support for this func, implement in wrapper
2882 auto streamState = osInterface->osStreamState;
2883
2884 MOS_OS_CHK_NULL_RETURN(streamState);
2885 MOS_OS_CHK_NULL_RETURN(streamState->osDeviceContext);
2886
2887 auto osDeviceContext = streamState->osDeviceContext;
2888
2889 if (Mos_Solo_IsEnabled(nullptr))
2890 {
2891 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
2892 MOS_OS_GPU_CONTEXT &osGpuContext = osInterface->pOsContext->OsGpuContext[osInterface->CurrentGpuContextOrdinal];
2893 if (dwRequestedSize > osGpuContext.uiMaxPatchLocationsize)
2894 {
2895 return MOS_STATUS_UNKNOWN;
2896 }
2897 return MOS_STATUS_SUCCESS;
2898 }
2899
2900 auto gpuContextMgr = osDeviceContext->GetGpuContextMgr();
2901 MOS_OS_CHK_NULL_RETURN(gpuContextMgr);
2902
2903 auto gpuCtx = gpuContextMgr->GetGpuContext(streamState->currentGpuContextHandle);
2904
2905 auto gpuCtxSpecific = static_cast<GpuContextSpecificNext *>(gpuCtx);
2906 MOS_OS_CHK_NULL_RETURN(gpuCtxSpecific);
2907 return (gpuCtxSpecific->VerifyPatchListSize(dwRequestedSize));
2908 }
2909
2910 //!
2911 //! \brief reset command buffer space
2912 //! \details resets the command buffer space
2913 //! \param PMOS_INTERFACE osInterface
2914 //! [in] pointer to OS interface structure
2915 //! \param PMOS_COMMAND_BUFFER cmdBuffer
2916 //! [in] pointer to command buffer structure
2917 //! \return MOS_STATUS
2918 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2919 //!
Mos_Specific_ResetCommandBuffer(PMOS_INTERFACE osInterface,PMOS_COMMAND_BUFFER cmdBuffer)2920 MOS_STATUS Mos_Specific_ResetCommandBuffer(
2921 PMOS_INTERFACE osInterface,
2922 PMOS_COMMAND_BUFFER cmdBuffer)
2923 {
2924 MOS_OS_CHK_NULL_RETURN(osInterface);
2925 if (!Mos_Solo_IsEnabled(nullptr))
2926 {
2927 return MosInterface::ResetCommandBuffer(osInterface->osStreamState, cmdBuffer);
2928 }
2929
2930 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
2931 MOS_OS_GPU_CONTEXT &osGpuContext = osInterface->pOsContext->OsGpuContext[osInterface->CurrentGpuContextOrdinal];
2932
2933 osGpuContext.bCBFlushed = true;
2934
2935 return MOS_STATUS_SUCCESS;
2936 }
2937
2938 //!
2939 //! \brief Get the memory compression mode
2940 //! \details Gets the memory compression mode from GMM
2941 //! \param PMOS_INTERFACE osInterface
2942 //! [in] pointer to OS interface structure
2943 //! \param PMOS_RESOURCE osResource
2944 //! [in] pointer to input OS resource
2945 //! \param PMOS_MEMCOMP_STATE pResMmcMode
2946 //! [out] the memory compression mode gotten from OS resource
2947 //! \return MOS_STATUS
2948 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2949 //!
Mos_Specific_GetMemoryCompressionMode(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,PMOS_MEMCOMP_STATE pResMmcMode)2950 MOS_STATUS Mos_Specific_GetMemoryCompressionMode(
2951 PMOS_INTERFACE osInterface,
2952 PMOS_RESOURCE osResource,
2953 PMOS_MEMCOMP_STATE pResMmcMode)
2954 {
2955 MOS_OS_CHK_NULL_RETURN(pResMmcMode);
2956 MOS_OS_CHK_NULL_RETURN(osInterface);
2957
2958 return MosInterface::GetMemoryCompressionMode(osInterface->osStreamState, osResource, *pResMmcMode);
2959 }
2960
2961 //!
2962 //! \brief Set the memory compression mode in GMM
2963 //! \details Set the memory compression mode
2964 //! \param PMOS_INTERFACE osInterface
2965 //! [in] pointer to OS interface structure
2966 //! \param PMOS_RESOURCE osResource
2967 //! [in] pointer to input OS resource
2968 //! \param MOS_MEMCOMP_STATE ResMmcMode
2969 //! [in] the memory compression mode to be set into OS resource
2970 //! \return MOS_STATUS
2971 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2972 //!
Mos_Specific_SetMemoryCompressionMode(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,MOS_MEMCOMP_STATE resMmcMode)2973 MOS_STATUS Mos_Specific_SetMemoryCompressionMode(
2974 PMOS_INTERFACE osInterface,
2975 PMOS_RESOURCE osResource,
2976 MOS_MEMCOMP_STATE resMmcMode)
2977 {
2978 MOS_OS_CHK_NULL_RETURN(osInterface);
2979
2980 return MosInterface::SetMemoryCompressionMode(osInterface->osStreamState, osResource, resMmcMode);
2981 }
2982
2983 //!
2984 //! \brief Set the memory compression hint in GMM on Linux or Gralloc on Android
2985 //! \details Indicate if the surface is compressible
2986 //! \param PMOS_INTERFACE osInterface
2987 //! [in] pointer to OS interface structure
2988 //! \param PMOS_RESOURCE osResource
2989 //! [in] pointer to input OS resource
2990 //! \param int32_t bHintOn
2991 //! [in] the memory compression hint to be set
2992 //! \return MOS_STATUS
2993 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
2994 //!
Mos_Specific_SetMemoryCompressionHint(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,int32_t bHintOn)2995 MOS_STATUS Mos_Specific_SetMemoryCompressionHint(
2996 PMOS_INTERFACE osInterface,
2997 PMOS_RESOURCE osResource,
2998 int32_t bHintOn)
2999 {
3000 MOS_OS_CHK_NULL_RETURN(osInterface);
3001
3002 return MosInterface::SetMemoryCompressionHint(osInterface->osStreamState, osResource, bHintOn);
3003 }
3004
3005 //!
3006 //! \brief Get the memory compression format
3007 //! \details Gets the memory compression format from GMM
3008 //! \param PMOS_INTERFACE osInterface
3009 //! [in] pointer to OS interface structure
3010 //! \param PMOS_RESOURCE osResource
3011 //! [in] pointer to input OS resource
3012 //! \param uint32_t *pResMmcFormat
3013 //! [out] the memory compression format gotten from GMM resource
3014 //! \return MOS_STATUS
3015 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3016 //!
Mos_Specific_GetMemoryCompressionFormat(PMOS_INTERFACE osInterface,PMOS_RESOURCE osResource,uint32_t * pResMmcFormat)3017 MOS_STATUS Mos_Specific_GetMemoryCompressionFormat(
3018 PMOS_INTERFACE osInterface,
3019 PMOS_RESOURCE osResource,
3020 uint32_t *pResMmcFormat)
3021 {
3022 MOS_OS_CHK_NULL_RETURN(osInterface);
3023 return MosInterface::GetMemoryCompressionFormat(osInterface->osStreamState, osResource, pResMmcFormat);
3024 }
3025
3026 //!
3027 //! \brief Create GPU node association.
3028 //! \details In i915 it already implements coarse ping-pong based on fd.
3029 //! Set the I915_EXEC_BSD without I915_EXEC_BSD_RING0 and I915_EXEC_BSD_RING1, it will be dispatched to the corresponding node.
3030 //! \param PMOS_INTERFACE osInterface
3031 //! [in] OS Interface
3032 //! \param MOS_MEDIA_OPERATION MediaOperation
3033 //! [in] Media operation
3034 //! \param MOS_GPU_NODE *videoNodeOrdinal
3035 //! [out] VCS node ordinal
3036 //! \return MOS_STATUS
3037 //! MOS_STATUS_SUCCESS if success, otherwise error code
3038 //!
Mos_Specific_CreateVideoNodeAssociation(PMOS_INTERFACE osInterface,int32_t bSetVideoNode,MOS_GPU_NODE * videoNodeOrdinal)3039 MOS_STATUS Mos_Specific_CreateVideoNodeAssociation(
3040 PMOS_INTERFACE osInterface,
3041 int32_t bSetVideoNode,
3042 MOS_GPU_NODE *videoNodeOrdinal)
3043 {
3044 PMOS_OS_CONTEXT osContext = nullptr;
3045 MOS_OS_FUNCTION_ENTER;
3046
3047 MOS_OS_CHK_NULL_RETURN(osInterface);
3048 MOS_OS_CHK_NULL_RETURN(videoNodeOrdinal);
3049 MOS_OS_CHK_NULL_RETURN(osInterface->pOsContext);
3050
3051 osContext = osInterface->pOsContext;
3052 *videoNodeOrdinal = MOS_GPU_NODE_VIDEO;
3053
3054 if (false == osContext->bKMDHasVCS2)
3055 {
3056 return MOS_STATUS_SUCCESS;
3057 }
3058
3059 // If node selection is forced or we have only one VDBox, turn balancing off.
3060 // After that check debug flags.
3061 if (osInterface->bEnableVdboxBalancing)
3062 {
3063 osContext->bPerCmdBufferBalancing = osInterface->pfnGetVdboxNodeId;
3064 }
3065 else
3066 {
3067 osContext->bPerCmdBufferBalancing = 0;
3068 }
3069
3070 return MOS_STATUS_SUCCESS;
3071 }
3072
3073 //!
3074 //! \brief Destroy GPU node association.
3075 //! \details Destroy GPU node association.
3076 //! \param PMOS_INTERFACE osInterface
3077 //! [in] OS Interface
3078 //! \param MOS_GPU_NODE VideoNodeOrdinal
3079 //! [in] VCS node ordinal
3080 //! \return MOS_STATUS
3081 //! MOS_STATUS_SUCCESS if success, otherwise error code
3082 //!
Mos_Specific_DestroyVideoNodeAssociation(PMOS_INTERFACE osInterface,MOS_GPU_NODE VideoNodeOrdinal)3083 MOS_STATUS Mos_Specific_DestroyVideoNodeAssociation(
3084 PMOS_INTERFACE osInterface,
3085 MOS_GPU_NODE VideoNodeOrdinal)
3086 {
3087 return MOS_STATUS_SUCCESS;
3088 }
3089
Mos_Specific_GetVdboxNodeId(PMOS_INTERFACE osInterface,PMOS_COMMAND_BUFFER cmdBuffer)3090 MOS_VDBOX_NODE_IND Mos_Specific_GetVdboxNodeId(
3091 PMOS_INTERFACE osInterface,
3092 PMOS_COMMAND_BUFFER cmdBuffer)
3093 {
3094 MOS_VDBOX_NODE_IND idx = MOS_VDBOX_NODE_INVALID;
3095
3096 MOS_OS_CHK_NULL_RETURN_VALUE(cmdBuffer, MOS_VDBOX_NODE_INVALID);
3097 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, MOS_VDBOX_NODE_INVALID);
3098 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface->pOsContext, MOS_VDBOX_NODE_INVALID);
3099
3100 // If we have assigned vdbox index for the given cmdbuf, return it immediately
3101 return cmdBuffer->iVdboxNodeIndex;
3102 }
3103
3104 //!
3105 //! \brief Get the memory object
3106 //! \details Get the memory object for cache policy
3107 //! \param MOS_HW_RESOURCE_DEF mosUsage
3108 //! [in] HW resource
3109 //! [in] Gmm client context
3110 //! \return MEMORY_OBJECT_CONTROL_STATE
3111 //! Return the memory object
3112 //!
Mos_Specific_CachePolicyGetMemoryObject(MOS_HW_RESOURCE_DEF mosUsage,GMM_CLIENT_CONTEXT * gmmClientContext)3113 MEMORY_OBJECT_CONTROL_STATE Mos_Specific_CachePolicyGetMemoryObject(
3114 MOS_HW_RESOURCE_DEF mosUsage,
3115 GMM_CLIENT_CONTEXT *gmmClientContext)
3116 {
3117 // Force convert to stream handle for wrapper
3118 return MosInterface::GetCachePolicyMemoryObject(gmmClientContext, mosUsage);
3119 }
3120
3121 //!
3122 //! \brief Get the L1 config
3123 //! \details Get the L1 config for cache policy
3124 //! \param MOS_HW_RESOURCE_DEF MosUsage
3125 //! [in] HW resource
3126 //! [in] Gmm client context
3127 //! \return uint8_t
3128 //! L1_CACHE_CONTROL
3129 //!
Mos_Specific_CachePolicyGetL1Config(MOS_HW_RESOURCE_DEF mosUsage,GMM_CLIENT_CONTEXT * gmmClientContext)3130 uint8_t Mos_Specific_CachePolicyGetL1Config(
3131 MOS_HW_RESOURCE_DEF mosUsage,
3132 GMM_CLIENT_CONTEXT *gmmClientContext)
3133 {
3134 return 0;
3135 }
3136
3137
3138 //*-----------------------------------------------------------------------------
3139 //| Purpose : Loads library
3140 //| Returns : Instance to handle
3141 //*-----------------------------------------------------------------------------
3142 //!
3143 //! \brief
3144 //! \details
3145 //! \param const char *pFileName
3146 //! \return HINSTANCE
3147 //!
Mos_Specific_LoadLibrary(PMOS_INTERFACE osInterface,PCCHAR pFileName,void ** ppvModule)3148 MOS_STATUS Mos_Specific_LoadLibrary(
3149 PMOS_INTERFACE osInterface,
3150 PCCHAR pFileName,
3151 void **ppvModule)
3152 {
3153 MOS_UNUSED(osInterface);
3154
3155 return MosInterface::MosLoadLibrary(nullptr, pFileName, ppvModule);
3156 }
3157
3158 //*-----------------------------------------------------------------------------
3159 //| Purpose : Frees library
3160 //| Returns : Result of the operation
3161 //*-----------------------------------------------------------------------------
3162 //!
3163 //! \brief
3164 //! \details
3165 //! \param HINSTANCE hInstance
3166 //! \return MOS_STATUS
3167 //!
Mos_Specific_FreeLibrary(void * hInstance)3168 MOS_STATUS Mos_Specific_FreeLibrary(
3169 void *hInstance)
3170 {
3171 return MosInterface::MosFreeLibrary(hInstance);
3172 }
3173
3174 //!
3175 //! \brief Determines if the GPU Hung
3176 //! \param PMOS_INTERFACE osInterface
3177 //! [in] Pointer to OS Interface
3178 //! \return int32_t
3179 //! Return if the GPU Hung
3180 //!
Mos_Specific_IsGPUHung(PMOS_INTERFACE osInterface)3181 int32_t Mos_Specific_IsGPUHung(
3182 PMOS_INTERFACE osInterface)
3183 {
3184 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, false);
3185 return MosInterface::IsGPUHung(osInterface->osStreamState);
3186 }
3187
Mos_Specific_GetAuxTableBaseAddr(PMOS_INTERFACE osInterface)3188 uint64_t Mos_Specific_GetAuxTableBaseAddr(
3189 PMOS_INTERFACE osInterface)
3190 {
3191 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, 0);
3192 return MosInterface::GetAuxTableBaseAddr(osInterface->osStreamState);
3193 }
3194
3195 //!
3196 //! \brief Get gpu context priority from KMD
3197 //! \param [in] osInterface
3198 //! Pointer to OS interface
3199 //! \param [out] pPriority
3200 //! the priority of the current context.
3201 //!
Mos_Specific_GetGpuPriority(PMOS_INTERFACE osInterface,int32_t * pPriority)3202 void Mos_Specific_GetGpuPriority(
3203 PMOS_INTERFACE osInterface,
3204 int32_t* pPriority)
3205 {
3206 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
3207
3208 return MosInterface::GetGpuPriority(osInterface->osStreamState, pPriority);
3209 }
3210
3211 //!
3212 //! \brief Set gpu priority to KMD
3213 //! \param [in] osInterface
3214 //! Pointer to OS interface
3215 //! \param [in] priority
3216 //! the priority set to current context.
3217 //!
Mos_Specific_SetGpuPriority(PMOS_INTERFACE osInterface,int32_t priority)3218 void Mos_Specific_SetGpuPriority(
3219 PMOS_INTERFACE osInterface,
3220 int32_t priority)
3221 {
3222 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osInterface);
3223 return MosInterface::SetGpuPriority(osInterface->osStreamState, priority);
3224 }
3225
Mos_Specific_CheckVirtualEngineSupported(PMOS_INTERFACE osInterface)3226 MOS_STATUS Mos_Specific_CheckVirtualEngineSupported(
3227 PMOS_INTERFACE osInterface)
3228 {
3229 MOS_OS_CHK_NULL_RETURN(osInterface);
3230
3231 osInterface->bSupportVirtualEngine = true;
3232
3233 return MOS_STATUS_SUCCESS;
3234 }
3235
Mos_Specific_GetUserSettingInstance(PMOS_INTERFACE osInterface)3236 MediaUserSettingSharedPtr Mos_Specific_GetUserSettingInstance(
3237 PMOS_INTERFACE osInterface)
3238 {
3239 MOS_OS_FUNCTION_ENTER;
3240
3241 MOS_OS_CHK_NULL_RETURN_VALUE(osInterface, nullptr);
3242
3243 return MosInterface::MosGetUserSettingInstance(osInterface->osStreamState);
3244 }
3245
Mos_Specific_InitInterface_Ve(PMOS_INTERFACE osInterface)3246 static MOS_STATUS Mos_Specific_InitInterface_Ve(
3247 PMOS_INTERFACE osInterface)
3248 {
3249 MOS_STATUS eStatus;
3250 MOS_STATUS eStatusUserFeature;
3251 uint32_t regValue = 0;
3252 MediaUserSettingSharedPtr userSettingPtr = nullptr;
3253
3254 MOS_OS_FUNCTION_ENTER;
3255
3256 eStatus = MOS_STATUS_SUCCESS;
3257 eStatusUserFeature = MOS_STATUS_SUCCESS;
3258
3259 MOS_OS_CHK_NULL_RETURN(osInterface);
3260 userSettingPtr = osInterface->pfnGetUserSettingInstance(osInterface);
3261
3262 {
3263 //keep this as false until VE is enabled by all media components
3264 osInterface->bSupportVirtualEngine = false;
3265 osInterface->bUseHwSemaForResSyncInVE = false;
3266 osInterface->pVEInterf = nullptr;
3267 osInterface->VEEnable = false;
3268
3269 auto skuTable = osInterface->pfnGetSkuTable(osInterface);
3270 MOS_OS_CHK_NULL_RETURN(skuTable);
3271 if (MEDIA_IS_SKU(skuTable, FtrGucSubmission))
3272 {
3273 osInterface->bParallelSubmission = true;
3274 }
3275
3276 //Read Scalable/Legacy Decode mode on Gen11+
3277 //1:by default for scalable decode mode
3278 //0:for legacy decode mode
3279 regValue = 0;
3280 eStatusUserFeature = ReadUserSetting(
3281 userSettingPtr,
3282 regValue,
3283 __MEDIA_USER_FEATURE_VALUE_ENABLE_HCP_SCALABILITY_DECODE,
3284 MediaUserSetting::Group::Device);
3285
3286 osInterface->bHcpDecScalabilityMode = regValue ? MOS_SCALABILITY_ENABLE_MODE_DEFAULT : MOS_SCALABILITY_ENABLE_MODE_FALSE;
3287 if(osInterface->bHcpDecScalabilityMode
3288 && (eStatusUserFeature == MOS_STATUS_SUCCESS))
3289 {
3290 //user's value to enable scalability
3291 osInterface->bHcpDecScalabilityMode = MOS_SCALABILITY_ENABLE_MODE_USER_FORCE;
3292 }
3293
3294 #if (_DEBUG || _RELEASE_INTERNAL)
3295 osInterface->frameSplit = false;
3296 ReadUserSetting(
3297 userSettingPtr,
3298 osInterface->frameSplit,
3299 __MEDIA_USER_FEATURE_VALUE_ENABLE_LINUX_FRAME_SPLIT,
3300 MediaUserSetting::Group::Device);
3301
3302 regValue = 0;
3303 ReadUserSettingForDebug(
3304 userSettingPtr,
3305 regValue,
3306 __MEDIA_USER_FEATURE_VALUE_ENABLE_GUC_SUBMISSION,
3307 MediaUserSetting::Group::Device);
3308 osInterface->bParallelSubmission = osInterface->bParallelSubmission && regValue;
3309
3310 // read the "Force VEBOX" user feature key
3311 // 0: not force
3312 regValue = 0;
3313 ReadUserSettingForDebug(
3314 userSettingPtr,
3315 regValue,
3316 __MEDIA_USER_FEATURE_VALUE_FORCE_VEBOX,
3317 MediaUserSetting::Group::Device);
3318 osInterface->eForceVebox = (MOS_FORCE_VEBOX)regValue;
3319
3320 //KMD Virtual Engine DebugOverride
3321 // 0: not Override
3322 ReadUserSettingForDebug(
3323 userSettingPtr,
3324 osInterface->bEnableDbgOvrdInVE,
3325 __MEDIA_USER_FEATURE_VALUE_ENABLE_VE_DEBUG_OVERRIDE,
3326 MediaUserSetting::Group::Device);
3327 #endif
3328
3329 // UMD Vebox Virtual Engine Scalability Mode
3330 // 0: disable. can set to 1 only when KMD VE is enabled.
3331 regValue = 0;
3332 eStatusUserFeature = ReadUserSetting(
3333 userSettingPtr,
3334 regValue,
3335 __MEDIA_USER_FEATURE_VALUE_ENABLE_VEBOX_SCALABILITY_MODE,
3336 MediaUserSetting::Group::Device);
3337
3338 osInterface->bVeboxScalabilityMode = regValue ? MOS_SCALABILITY_ENABLE_MODE_DEFAULT : MOS_SCALABILITY_ENABLE_MODE_FALSE;
3339
3340 #if (_DEBUG || _RELEASE_INTERNAL)
3341 if(osInterface->bVeboxScalabilityMode
3342 && (eStatusUserFeature == MOS_STATUS_SUCCESS))
3343 {
3344 //user's value to enable scalability
3345 osInterface->bVeboxScalabilityMode = MOS_SCALABILITY_ENABLE_MODE_USER_FORCE;
3346
3347 if (osInterface->eForceVebox == MOS_FORCE_VEBOX_NONE)
3348 {
3349 osInterface->eForceVebox = MOS_FORCE_VEBOX_1_2;
3350 }
3351 }
3352 else if ((!osInterface->bVeboxScalabilityMode)
3353 && (eStatusUserFeature == MOS_STATUS_SUCCESS))
3354 {
3355 osInterface->eForceVebox = MOS_FORCE_VEBOX_NONE;
3356 }
3357
3358 // read the "Force VEBOX" user feature key
3359 // 0: not force
3360 regValue = 0;
3361 ReadUserSettingForDebug(
3362 userSettingPtr,
3363 regValue,
3364 __MEDIA_USER_FEATURE_VALUE_FORCE_VEBOX,
3365 MediaUserSetting::Group::Device);
3366 osInterface->eForceVebox = (MOS_FORCE_VEBOX)regValue;
3367 #endif
3368 }
3369
3370 return eStatus;
3371 }
3372
Mos_Specific_IsMismatchOrderProgrammingSupported()3373 bool Mos_Specific_IsMismatchOrderProgrammingSupported()
3374 {
3375 return MosInterface::IsMismatchOrderProgrammingSupported();
3376 }
3377
Mos_Specific_pfnIsMultipleCodecDevicesInUse(PMOS_INTERFACE osInterface)3378 bool Mos_Specific_pfnIsMultipleCodecDevicesInUse(
3379 PMOS_INTERFACE osInterface)
3380 {
3381 MOS_OS_FUNCTION_ENTER;
3382
3383 return false;
3384 }
3385
Mos_Specific_IsAsyncDevice(PMOS_INTERFACE osInterface)3386 bool Mos_Specific_IsAsyncDevice(PMOS_INTERFACE osInterface)
3387 {
3388 return false;
3389 }
3390
Mos_Specific_LoadFunction(PMOS_INTERFACE osInterface)3391 MOS_STATUS Mos_Specific_LoadFunction(
3392 PMOS_INTERFACE osInterface)
3393 {
3394 MOS_OS_CHK_NULL_RETURN(osInterface);
3395
3396 osInterface->pfnSetGpuContext = Mos_Specific_SetGpuContext;
3397 osInterface->pfnSetGpuContextFromHandle = Mos_Specific_SetGpuContextFromHandle;
3398 osInterface->pfnGetGpuContext = Mos_Specific_GetGpuContext;
3399 osInterface->pfnSetEncodePakContext = Mos_Specific_SetEncodePakContext;
3400 osInterface->pfnSetEncodeEncContext = Mos_Specific_SetEncodeEncContext;
3401 osInterface->pfnGetGmmClientContext = Mos_Specific_GetGmmClientContext;
3402
3403 osInterface->pfnGetPlatform = Mos_Specific_GetPlatform;
3404 osInterface->pfnDestroy = Mos_Specific_Destroy;
3405 osInterface->pfnGetSkuTable = Mos_Specific_GetSkuTable;
3406 osInterface->pfnGetWaTable = Mos_Specific_GetWaTable;
3407 osInterface->pfnGetGtSystemInfo = Mos_Specific_GetGtSystemInfo;
3408 osInterface->pfnGetMediaEngineInfo = Mos_Specific_GetMediaEngineInfo;
3409 osInterface->pfnResetOsStates = Mos_Specific_ResetOsStates;
3410 osInterface->pfnAllocateResource = Mos_Specific_AllocateResource;
3411 osInterface->pfnGetResourceInfo = Mos_Specific_GetResourceInfo;
3412 osInterface->pfnFreeResource = Mos_Specific_FreeResource;
3413 osInterface->pfnFreeResourceWithFlag = Mos_Specific_FreeResourceWithFlag;
3414 osInterface->pfnLockSyncRequest = Mos_Specific_LockSyncRequest;
3415 osInterface->pfnLockResource = Mos_Specific_LockResource;
3416 osInterface->pfnUnlockResource = Mos_Specific_UnlockResource;
3417 osInterface->pfnDecompResource = Mos_Specific_DecompResource;
3418 osInterface->pfnDoubleBufferCopyResource = Mos_Specific_DoubleBufferCopyResource;
3419 osInterface->pfnMediaCopyResource2D = Mos_Specific_MediaCopyResource2D;
3420 osInterface->pfnGetMosContext = Mos_Specific_GetMosContext;
3421 osInterface->pfnUpdateResourceUsageType = Mos_Specific_UpdateResourceUsageType;
3422 osInterface->pfnRegisterResource = Mos_Specific_RegisterResource;
3423 osInterface->pfnResetResourceAllocationIndex = Mos_Specific_ResetResourceAllocationIndex;
3424 osInterface->pfnGetResourceAllocationIndex = Mos_Specific_GetResourceAllocationIndex;
3425 osInterface->pfnGetResourceGfxAddress = Mos_Specific_GetResourceGfxAddress;
3426 osInterface->pfnGetResourceClearAddress = Mos_Specific_GetResourceClearAddress;
3427 osInterface->pfnGetCommandBuffer = Mos_Specific_GetCommandBuffer;
3428 osInterface->pfnResetCommandBuffer = Mos_Specific_ResetCommandBuffer;
3429 osInterface->pfnReturnCommandBuffer = Mos_Specific_ReturnCommandBuffer;
3430 osInterface->pfnSubmitCommandBuffer = Mos_Specific_SubmitCommandBuffer;
3431 osInterface->pfnVerifyCommandBufferSize = Mos_Specific_VerifyCommandBufferSize;
3432 osInterface->pfnResizeCommandBufferAndPatchList = Mos_Specific_ResizeCommandBufferAndPatchList;
3433 osInterface->pfnSetPerfTag = Mos_Specific_SetPerfTag;
3434 osInterface->pfnResetPerfBufferID = Mos_Specific_ResetPerfBufferID;
3435 osInterface->pfnIncPerfFrameID = Mos_Specific_IncPerfFrameID;
3436 osInterface->pfnIncPerfBufferID = Mos_Specific_IncPerfBufferID;
3437 osInterface->pfnGetPerfTag = Mos_Specific_GetPerfTag;
3438 osInterface->pfnIsPerfTagSet = Mos_Specific_IsPerfTagSet;
3439 osInterface->pfnSetIndirectStateSize = Mos_Specific_SetIndirectStateSize;
3440 osInterface->pfnGetIndirectState = Mos_Specific_GetIndirectState;
3441 osInterface->pfnGetIndirectStatePointer = Mos_Specific_GetIndirectStatePointer;
3442 osInterface->pfnSetPatchEntry = Mos_Specific_SetPatchEntry;
3443 osInterface->pfnGetInterfaceVersion = Mos_Specific_GetInterfaceVersion;
3444
3445 osInterface->pfnLoadLibrary = Mos_Specific_LoadLibrary;
3446 osInterface->pfnFreeLibrary = Mos_Specific_FreeLibrary;
3447 osInterface->pfnCheckVirtualEngineSupported = Mos_Specific_CheckVirtualEngineSupported;
3448
3449 //GPU context and synchronization functions
3450 osInterface->pfnCreateGpuContext = Mos_Specific_CreateGpuContext;
3451 osInterface->pfnCreateGpuComputeContext = Mos_Specific_CreateGpuComputeContext;
3452 osInterface->pfnDestroyGpuContext = Mos_Specific_DestroyGpuContext;
3453 osInterface->pfnDestroyGpuComputeContext = Mos_Specific_DestroyGpuComputeContext;
3454 osInterface->pfnIsGpuContextValid = Mos_Specific_IsGpuContextValid;
3455 osInterface->pfnSyncOnResource = Mos_Specific_SyncOnResource;
3456 osInterface->pfnGetGpuStatusBufferResource = Mos_Specific_GetGpuStatusBufferResource;
3457 osInterface->pfnGetGpuStatusTagOffset = Mos_Specific_GetGpuStatusTagOffset;
3458 osInterface->pfnGetGpuStatusTag = Mos_Specific_GetGpuStatusTag;
3459 osInterface->pfnIncrementGpuStatusTag = Mos_Specific_IncrementGpuStatusTag;
3460 osInterface->pfnGetGpuStatusSyncTag = Mos_Specific_GetGpuStatusSyncTag;
3461 osInterface->pfnSetResourceSyncTag = Mos_Specific_SetResourceSyncTag;
3462 osInterface->pfnPerformOverlaySync = Mos_Specific_PerformOverlaySync;
3463 osInterface->pfnWaitAllCmdCompletion = Mos_Specific_WaitAllCmdCompletion_Os;
3464 osInterface->pfnResourceWait = Mos_Specific_ResourceWait;
3465
3466 osInterface->pfnCachePolicyGetMemoryObject = Mos_Specific_CachePolicyGetMemoryObject;
3467 osInterface->pfnVerifyPatchListSize = Mos_Specific_VerifyPatchListSize;
3468 osInterface->pfnGetMemoryCompressionMode = Mos_Specific_GetMemoryCompressionMode;
3469 osInterface->pfnSetMemoryCompressionMode = Mos_Specific_SetMemoryCompressionMode;
3470 osInterface->pfnSetMemoryCompressionHint = Mos_Specific_SetMemoryCompressionHint;
3471 osInterface->pfnGetMemoryCompressionFormat = Mos_Specific_GetMemoryCompressionFormat;
3472 osInterface->pfnCreateVideoNodeAssociation = Mos_Specific_CreateVideoNodeAssociation;
3473 osInterface->pfnDestroyVideoNodeAssociation = Mos_Specific_DestroyVideoNodeAssociation;
3474 osInterface->pfnGetVdboxNodeId = Mos_Specific_GetVdboxNodeId;
3475
3476 osInterface->pfnGetNullHWRenderFlags = Mos_Specific_GetNullHWRenderFlags;
3477 osInterface->pfnSetCmdBufferDebugInfo = Mos_Specific_SetCmdBufferDebugInfo;
3478 osInterface->pfnGetCmdBufferDebugInfo = Mos_Specific_GetCmdBufferDebugInfo;
3479
3480 osInterface->pfnRegisterBBCompleteNotifyEvent = Mos_Specific_RegisterBBCompleteNotifyEvent;
3481 osInterface->pfnWaitForBBCompleteNotifyEvent = Mos_Specific_WaitForBBCompleteNotifyEvent;
3482 osInterface->pfnCachePolicyGetMemoryObject = Mos_Specific_CachePolicyGetMemoryObject;
3483 osInterface->pfnSkipResourceSync = Mos_Specific_SkipResourceSync;
3484 osInterface->pfnIsGPUHung = Mos_Specific_IsGPUHung;
3485 osInterface->pfnGetAuxTableBaseAddr = Mos_Specific_GetAuxTableBaseAddr;
3486 osInterface->pfnGetResourceIndex = Mos_Specific_GetResourceIndex;
3487 osInterface->pfnGetGpuPriority = Mos_Specific_GetGpuPriority;
3488 osInterface->pfnSetGpuPriority = Mos_Specific_SetGpuPriority;
3489 osInterface->pfnIsSetMarkerEnabled = Mos_Specific_IsSetMarkerEnabled;
3490 osInterface->pfnGetMarkerResource = Mos_Specific_GetMarkerResource;
3491 osInterface->pfnGetResType = GetResType;
3492 osInterface->pfnGetTsFrequency = Mos_Specific_GetTsFrequency;
3493 osInterface->pfnSetHintParams = Mos_Specific_SetHintParams;
3494 osInterface->pfnVirtualEngineInit = Mos_Specific_Virtual_Engine_Init;
3495 osInterface->pfnDestroyVeInterface = Mos_Specific_DestroyVeInterface;
3496 #if (_DEBUG || _RELEASE_INTERNAL)
3497 osInterface->pfnGetEngineLogicId = Mos_Specific_GetEngineLogicId;
3498 #endif
3499 osInterface->pfnSetGpuContextHandle = Mos_Specific_SetGpuContextHandle;
3500 osInterface->pfnGetGpuContextbyHandle = Mos_Specific_GetGpuContextbyHandle;
3501
3502 osInterface->pfnGetUserSettingInstance = Mos_Specific_GetUserSettingInstance;
3503
3504 osInterface->pfnIsMismatchOrderProgrammingSupported = Mos_Specific_IsMismatchOrderProgrammingSupported;
3505
3506 osInterface->pfnIsMultipleCodecDevicesInUse = Mos_Specific_pfnIsMultipleCodecDevicesInUse;
3507 osInterface->pfnIsAsynDevice = Mos_Specific_IsAsyncDevice;
3508
3509 return MOS_STATUS_SUCCESS;
3510 }
3511
3512 //! \brief Unified OS Initializes OS Linux Interface
3513 //! \details Linux OS Interface initilization
3514 //! \param PMOS_INTERFACE osInterface
3515 //! [in] Pointer to OS Interface
3516 //! \param PMOS_CONTEXT osDriverContext
3517 //! [in] Pointer to Driver context
3518 //! \return MOS_STATUS
3519 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
3520 //!
Mos_Specific_InitInterface(PMOS_INTERFACE osInterface,PMOS_CONTEXT osDriverContext)3521 MOS_STATUS Mos_Specific_InitInterface(
3522 PMOS_INTERFACE osInterface,
3523 PMOS_CONTEXT osDriverContext)
3524 {
3525 PMOS_OS_CONTEXT osContext = nullptr;
3526 PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface = nullptr;
3527 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
3528 uint32_t dwResetCount = 0;
3529 int32_t ret = 0;
3530 MediaUserSettingSharedPtr userSettingPtr = nullptr;
3531 bool bSimIsActive = false;
3532 uint32_t regValue = 0;
3533 char *pMediaWatchdog = nullptr;
3534 long int watchdog = 0;
3535
3536 MOS_OS_FUNCTION_ENTER;
3537
3538 MOS_OS_CHK_NULL_RETURN(osInterface);
3539 MOS_OS_CHK_NULL_RETURN(osDriverContext);
3540
3541 Mos_Specific_LoadFunction(osInterface);
3542
3543 userSettingPtr = osDriverContext->m_userSettingPtr;
3544
3545 // Initialize OS interface functions
3546 pOsUserFeatureInterface = (PMOS_USER_FEATURE_INTERFACE)&osInterface->UserFeatureInterface;
3547
3548 osInterface->modularizedGpuCtxEnabled = true;
3549 osInterface->veDefaultEnable = true;
3550 osInterface->phasedSubmission = true;
3551 osInterface->apoMosEnabled = true;
3552
3553 MOS_OS_CHK_NULL_RETURN(osDriverContext->m_osDeviceContext);
3554 osInterface->bNullHwIsEnabled = osDriverContext->m_osDeviceContext->GetNullHwIsEnabled();
3555
3556 osInterface->streamStateIniter = true;
3557 eStatus = MosInterface::CreateOsStreamState(
3558 &osInterface->osStreamState,
3559 (MOS_DEVICE_HANDLE)osDriverContext->m_osDeviceContext,
3560 (MOS_INTERFACE_HANDLE)osInterface,
3561 osInterface->Component,
3562 osDriverContext);
3563
3564 if(MOS_STATUS_SUCCESS != eStatus)
3565 {
3566 MOS_OS_ASSERTMESSAGE("MosInterface::CreateOsStreamState FAILED");
3567 Mos_DestroyInterface(osInterface);
3568 return eStatus;
3569 }
3570
3571 // Set interface functions for legacy HAL
3572 osContext = (PMOS_OS_CONTEXT)osInterface->osStreamState->perStreamParameters;
3573 MOS_OS_CHK_NULL_RETURN(osContext);
3574
3575 #if MOS_MEDIASOLO_SUPPORTED
3576 if (Mos_Solo_IsEnabled(osContext))
3577 {
3578 eStatus = Linux_InitContext(osContext, osDriverContext);
3579 if( MOS_STATUS_SUCCESS != eStatus )
3580 {
3581 MOS_OS_ASSERTMESSAGE("Unable to initialize context.");
3582 Mos_DestroyInterface(osInterface);
3583 return eStatus;
3584 }
3585
3586 osContext->bFreeContext = true;
3587
3588 //Added by Ben for video memory allocation
3589 osContext->bufmgr = osDriverContext->bufmgr;
3590 mos_bufmgr_enable_reuse(osDriverContext->bufmgr);
3591 }
3592 #endif
3593 osInterface->pOsContext = osContext;
3594
3595 osInterface->bUsesPatchList = true;
3596 osInterface->bUsesGfxAddress = false;
3597 osInterface->bNoParsingAssistanceInKmd = true;
3598 osInterface->bUsesCmdBufHeaderInResize = false;
3599 osInterface->bUsesCmdBufHeader = false;
3600 osInterface->dwNumNalUnitBytesIncluded = MOS_NAL_UNIT_LENGTH - MOS_NAL_UNIT_STARTCODE_LENGTH;
3601
3602 osInterface->bInlineCodecStatusUpdate = true;
3603 osInterface->bAllowExtraPatchToSameLoc = false;
3604
3605 pOsUserFeatureInterface->bIsNotificationSupported = false;
3606 pOsUserFeatureInterface->pOsInterface = osInterface;
3607
3608 pOsUserFeatureInterface->pfnEnableNotification = MosUtilities::MosUserFeatureEnableNotification;
3609 pOsUserFeatureInterface->pfnDisableNotification = MosUtilities::MosUserFeatureDisableNotification;
3610 pOsUserFeatureInterface->pfnParsePath = MosUtilities::MosUserFeatureParsePath;
3611
3612 // Init reset count for the context
3613 ret = mos_get_reset_stats(osInterface->pOsContext->intel_context, &dwResetCount, nullptr, nullptr);
3614 if (ret)
3615 {
3616 MOS_OS_NORMALMESSAGE("mos_get_reset_stats return error(%d)\n", ret);
3617 dwResetCount = 0;
3618 }
3619 osInterface->dwGPUResetCount = dwResetCount;
3620 osInterface->dwGPUActiveBatch = 0;
3621 osInterface->dwGPUPendingBatch = 0;
3622
3623 // enable it on Linux
3624 osInterface->bMediaReset = true;
3625 osInterface->trinityPath = TRINITY_DISABLED;
3626 osInterface->umdMediaResetEnable = true;
3627
3628 // disable Media Reset for non-xe platform who has no media reset support on Linux
3629 auto skuTable = osInterface->pfnGetSkuTable(osInterface);
3630 MOS_OS_CHK_NULL_RETURN(skuTable);
3631 if(!MEDIA_IS_SKU(skuTable, FtrSWMediaReset))
3632 {
3633 osInterface->bMediaReset = false;
3634 osInterface->umdMediaResetEnable = false;
3635 }
3636
3637 pMediaWatchdog = getenv("INTEL_MEDIA_RESET_WATCHDOG");
3638 if (pMediaWatchdog != nullptr)
3639 {
3640 watchdog = strtol(pMediaWatchdog, nullptr, 0);
3641 if (watchdog == 0)
3642 {
3643 osInterface->bMediaReset = false;
3644 osInterface->umdMediaResetEnable = false;
3645 }
3646 }
3647
3648 // initialize MOS_CP interface
3649 osInterface->osCpInterface = Create_MosCpInterface(osInterface);
3650 if (osInterface->osCpInterface == nullptr)
3651 {
3652 MOS_OS_ASSERTMESSAGE("fail to create osCpInterface.");
3653 Mos_DestroyInterface(osInterface);
3654 return MOS_STATUS_UNKNOWN;
3655 }
3656
3657 #if (_DEBUG || _RELEASE_INTERNAL)
3658 // read the "Force VDBOX" user feature key
3659 // 0: not force
3660 ReadUserSettingForDebug(
3661 userSettingPtr,
3662 osInterface->eForceVdbox,
3663 __MEDIA_USER_FEATURE_VALUE_FORCE_VDBOX,
3664 MediaUserSetting::Group::Device);
3665
3666 // Force TileYf/Ys
3667 // 0: Tile Y 1: Tile Yf 2 Tile Ys
3668 ReadUserSettingForDebug(
3669 userSettingPtr,
3670 osInterface->dwForceTileYfYs,
3671 __MEDIA_USER_FEATURE_VALUE_FORCE_YFYS,
3672 MediaUserSetting::Group::Device);
3673
3674 // Null HW Driver
3675 // 0: Disable
3676 ReadUserSettingForDebug(
3677 userSettingPtr,
3678 osInterface->NullHWAccelerationEnable.Value,
3679 __MEDIA_USER_FEATURE_VALUE_NULL_HW_ACCELERATION_ENABLE,
3680 MediaUserSetting::Group::Device);
3681 #endif // (_DEBUG || _RELEASE_INTERNAL)
3682
3683 #if MOS_MEDIASOLO_SUPPORTED
3684 Mos_Solo_Initialize(osInterface);
3685 #endif // MOS_MEDIASOLO_SUPPORTED
3686
3687 eStatus = Mos_Specific_InitInterface_Ve(osInterface);
3688 if(eStatus != MOS_STATUS_SUCCESS)
3689 {
3690 MOS_OS_ASSERTMESSAGE("Mos_Specific_InitInterface_Ve failed.");
3691 Mos_DestroyInterface(osInterface);
3692 return eStatus;
3693 }
3694
3695 return MOS_STATUS_SUCCESS;
3696 }
3697
3698 //!
3699 //! \brief Convert to MOS tile type
3700 //! \details Convert from Linux to MOS tile type
3701 //! \param uint32_t type
3702 //! [in] tile type
3703 //! \return MOS_TILE_TYPE
3704 //! Return MOS tile type
3705 //!
LinuxToMosTileType(uint32_t type)3706 MOS_TILE_TYPE LinuxToMosTileType(uint32_t type)
3707 {
3708 switch (type) {
3709 case TILING_NONE:
3710 return MOS_TILE_LINEAR;
3711 case TILING_X:
3712 return MOS_TILE_X;
3713 case TILING_Y:
3714 return MOS_TILE_Y;
3715 default:
3716 return MOS_TILE_INVALID;
3717 }
3718 };
3719
3720 //!
3721 //! \brief Get resource index
3722 //! \details Get resource index of MOS_RESOURCE
3723 //! \param PMOS_RESOURCE osResource
3724 //! [in] Pointer to OS resource
3725 //! \return uint32_t
3726 //! Resource index
3727 //!
Mos_Specific_GetResourceIndex(PMOS_RESOURCE osResource)3728 uint32_t Mos_Specific_GetResourceIndex(
3729 PMOS_RESOURCE osResource)
3730 {
3731 return 0;
3732 }
3733
Mos_Specific_GetResourcePitch(PMOS_RESOURCE osResource)3734 uint32_t Mos_Specific_GetResourcePitch(
3735 PMOS_RESOURCE osResource)
3736 {
3737 MOS_OS_FUNCTION_ENTER;
3738 MOS_OS_CHK_NULL_RETURN_VALUE(osResource, 0);
3739
3740 return osResource->iPitch;
3741 }
3742
Mos_Specific_SetResourceWidth(PMOS_RESOURCE osResource,uint32_t dwWidth)3743 void Mos_Specific_SetResourceWidth(
3744 PMOS_RESOURCE osResource,
3745 uint32_t dwWidth)
3746 {
3747 MOS_OS_FUNCTION_ENTER;
3748
3749 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osResource);
3750
3751 osResource->iWidth = dwWidth;
3752 }
3753
Mos_Specific_SetResourceFormat(PMOS_RESOURCE osResource,MOS_FORMAT mosFormat)3754 void Mos_Specific_SetResourceFormat(
3755 PMOS_RESOURCE osResource,
3756 MOS_FORMAT mosFormat)
3757 {
3758 MOS_OS_FUNCTION_ENTER;
3759
3760 MOS_OS_CHK_NULL_NO_STATUS_RETURN(osResource);
3761
3762 osResource->Format = mosFormat;
3763 }
3764
3765 //!
3766 //! \brief Get SetMarker enabled flag
3767 //! \details Get SetMarker enabled flag from OsInterface
3768 //! \param PMOS_INTERFACE osInterface
3769 //! [in] OS Interface
3770 //! \return bool
3771 //! SetMarker enabled flag
3772 //!
Mos_Specific_IsSetMarkerEnabled(PMOS_INTERFACE osInterface)3773 bool Mos_Specific_IsSetMarkerEnabled(
3774 PMOS_INTERFACE osInterface)
3775 {
3776 return false;
3777 }
3778
3779 //!
3780 //! \brief Get SetMarker resource address
3781 //! \details Get SetMarker resource address from OsInterface
3782 //! \param PMOS_INTERFACE osInterface
3783 //! [in] OS Interface
3784 //! \return PMOS_RESOURCE
3785 //! SetMarker resource address
3786 //!
Mos_Specific_GetMarkerResource(PMOS_INTERFACE osInterface)3787 PMOS_RESOURCE Mos_Specific_GetMarkerResource(
3788 PMOS_INTERFACE osInterface)
3789 {
3790 return 0;
3791 }
3792
3793 //!
3794 //! \brief Get TimeStamp frequency base
3795 //! \details Get TimeStamp frequency base from OsInterface
3796 //! \param PMOS_INTERFACE osInterface
3797 //! [in] OS Interface
3798 //! \return uint32_t
3799 //! time stamp frequency base
3800 //!
Mos_Specific_GetTsFrequency(PMOS_INTERFACE osInterface)3801 uint32_t Mos_Specific_GetTsFrequency(PMOS_INTERFACE osInterface)
3802 {
3803 uint32_t freq = 0;
3804 int ret = mos_get_ts_frequency(osInterface->pOsContext->bufmgr, &freq);
3805 if(ret == 0)
3806 {
3807 return freq;
3808 }
3809 else
3810 {
3811 // fail to query it from KMD
3812 return 0;
3813 }
3814 }
3815
Mos_GetDeviceUfPathInfo(PMOS_CONTEXT mosContext)3816 MOS_USER_FEATURE_KEY_PATH_INFO *Mos_GetDeviceUfPathInfo(
3817 PMOS_CONTEXT mosContext)
3818 {
3819 MOS_UNUSED(mosContext);
3820 //NOT IMPLEMENTED
3821 return nullptr;
3822 }
3823
Mos_Specific_Virtual_Engine_Init(PMOS_INTERFACE pOsInterface,PMOS_VIRTUALENGINE_HINT_PARAMS * veHitParams,MOS_VIRTUALENGINE_INIT_PARAMS & veInParams)3824 MOS_STATUS Mos_Specific_Virtual_Engine_Init(
3825 PMOS_INTERFACE pOsInterface,
3826 PMOS_VIRTUALENGINE_HINT_PARAMS* veHitParams,
3827 MOS_VIRTUALENGINE_INIT_PARAMS& veInParams)
3828 {
3829 MOS_OS_CHK_NULL_RETURN(pOsInterface);
3830 MOS_OS_CHK_NULL_RETURN(pOsInterface->osStreamState);
3831 MOS_VE_HANDLE veState = nullptr;
3832 MOS_OS_CHK_STATUS_RETURN(MosInterface::CreateVirtualEngineState(
3833 pOsInterface->osStreamState, &veInParams, veState));
3834
3835 MOS_OS_CHK_STATUS_RETURN(MosInterface::GetVeHintParams(pOsInterface->osStreamState, veInParams.bScalabilitySupported, veHitParams));
3836
3837 return MOS_STATUS_SUCCESS;
3838 }
3839
Mos_Specific_SetHintParams(PMOS_INTERFACE osInterface,PMOS_VIRTUALENGINE_SET_PARAMS veParams)3840 MOS_STATUS Mos_Specific_SetHintParams(
3841 PMOS_INTERFACE osInterface,
3842 PMOS_VIRTUALENGINE_SET_PARAMS veParams)
3843 {
3844 MOS_OS_FUNCTION_ENTER;
3845 MOS_OS_CHK_NULL_RETURN(osInterface);
3846 MOS_OS_CHK_NULL_RETURN(osInterface->osStreamState);
3847 MOS_OS_CHK_STATUS_RETURN(MosInterface::SetVeHintParams(osInterface->osStreamState, veParams));
3848
3849 return MOS_STATUS_SUCCESS;
3850 }
3851
Mos_Specific_DestroyVeInterface(PMOS_VIRTUALENGINE_INTERFACE * veInterface)3852 MOS_STATUS Mos_Specific_DestroyVeInterface(
3853 PMOS_VIRTUALENGINE_INTERFACE *veInterface)
3854 {
3855 MOS_OS_FUNCTION_ENTER;
3856
3857 return MOS_STATUS_SUCCESS;
3858 }
3859
3860 #if (_DEBUG || _RELEASE_INTERNAL)
Mos_Specific_GetEngineLogicId(PMOS_INTERFACE osInterface,uint8_t & id)3861 MOS_STATUS Mos_Specific_GetEngineLogicId(
3862 PMOS_INTERFACE osInterface,
3863 uint8_t& id)
3864 {
3865 if (MosInterface::GetVeEngineCount(osInterface->osStreamState) != 1)
3866 {
3867 MOS_OS_ASSERTMESSAGE("VeEngineCount is not equal to 1.");
3868 }
3869 id = MosInterface::GetEngineLogicId(osInterface->osStreamState, 0);
3870 return MOS_STATUS_SUCCESS;
3871 }
3872 #endif
3873