xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/GlobalInfo/GmmClientContext.cpp (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2017 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 #include "Internal/Common/GmmLibInc.h"
24 #include "External/Common/GmmClientContext.h"
25 
26 #if !__GMM_KMD__ && LHDM
27 #include "..\..\inc\common\gfxEscape.h"
28 #include "..\..\..\miniport\LHDM\inc\gmmEscape.h"
29 #include "Internal\Windows\GmmResourceInfoWinInt.h"
30 #include "../TranslationTable/GmmUmdTranslationTable.h"
31 #endif
32 
33 extern GMM_MA_LIB_CONTEXT *pGmmMALibContext;
34 
35 /////////////////////////////////////////////////////////////////////////////////////
36 /// Overloaded Constructor to zero initialize the GmmLib::GmmClientContext object
37 /// This Construtor takes pointer to GmmLibCOntext as input argumnet and initiaizes
38 /// ClientContext's GmmLibContext with this value
39 /////////////////////////////////////////////////////////////////////////////////////
GmmClientContext(GMM_CLIENT ClientType,Context * pLibContext)40 GmmLib::GmmClientContext::GmmClientContext(GMM_CLIENT ClientType, Context *pLibContext)
41     : ClientType(),
42       pUmdAdapter(),
43       pGmmUmdContext(),
44       DeviceCB(),
45       IsDeviceCbReceived(0)
46 {
47     this->ClientType     = ClientType;
48     this->pGmmLibContext = pLibContext;
49 }
50 /////////////////////////////////////////////////////////////////////////////////////
51 /// Destructor to free  GmmLib::GmmClientContext object memory
52 /////////////////////////////////////////////////////////////////////////////////////
~GmmClientContext()53 GmmLib::GmmClientContext::~GmmClientContext()
54 {
55     pGmmLibContext = NULL;
56 }
57 
58 /////////////////////////////////////////////////////////////////////////////////////
59 /// Member function of ClientContext class for returning
60 /// MEMORY_OBJECT_CONTROL_STATE for a given Resource Usage Type
61 ///
62 /// @param[in]  GMM_RESOURCE_INFO       : Pointer to ResInfo object
63 /// @param[in]  GMM_RESOURCE_USAGE_TYPE : Resource Usage Type
64 /// @return     MEMORY_OBJECT_CONTROL_STATE for the resource of "Usage" type.
65 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetMemoryObject(GMM_RESOURCE_INFO * pResInfo,GMM_RESOURCE_USAGE_TYPE Usage)66 MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmLib::GmmClientContext::CachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage)
67 {
68     return pGmmLibContext->GetCachePolicyObj()->CachePolicyGetMemoryObject(pResInfo, Usage);
69 }
70 /////////////////////////////////////////////////////////////////////////////////////
71 /// Member function of ClientContext class for returning
72 /// GMM_PTE_CACHE_CONTROL_BITS for a given Resource Usage Type
73 ///
74 /// @param[in]  GMM_RESOURCE_USAGE_TYPE : Resource Usage Type
75 /// @return     GMM_PTE_CACHE_CONTROL_BITS for the resource of "Usage" type.
76 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetPteType(GMM_RESOURCE_USAGE_TYPE Usage)77 GMM_PTE_CACHE_CONTROL_BITS GMM_STDCALL GmmLib::GmmClientContext::CachePolicyGetPteType(GMM_RESOURCE_USAGE_TYPE Usage)
78 {
79     return pGmmLibContext->GetCachePolicyObj()->CachePolicyGetPteType(Usage);
80 }
81 
82 /////////////////////////////////////////////////////////////////////////////////////
83 /// Member function of ClientContext class for returning
84 /// MEMORY_OBJECT_CONTROL_STATE for a given ResInfo Object
85 ///
86 /// @param[in]  GMM_RESOURCE_INFO       : Pointer to ResInfo object
87 /// @return     MEMORY_OBJECT_CONTROL_STATE for the ResInfo object
88 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetOriginalMemoryObject(GMM_RESOURCE_INFO * pResInfo)89 MEMORY_OBJECT_CONTROL_STATE GMM_STDCALL GmmLib::GmmClientContext::CachePolicyGetOriginalMemoryObject(GMM_RESOURCE_INFO *pResInfo)
90 {
91     return pGmmLibContext->GetCachePolicyObj()->CachePolicyGetOriginalMemoryObject(pResInfo);
92 }
93 
94 /////////////////////////////////////////////////////////////////////////////////////
95 /// Member function of ClientContext class for returning
96 /// PAT Index for a given Resource Usage Type
97 ///
98 /// @param[in]  GMM_RESOURCE_INFO       : Pointer to ResInfo object
99 /// @param[in]  GMM_RESOURCE_USAGE_TYPE : Resource Usage Type
100 /// @return     PAT index for the resource of "Usage" type.
101 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetPATIndex(GMM_RESOURCE_INFO * pResInfo,GMM_RESOURCE_USAGE_TYPE Usage,bool * pCompressionEnable,bool IsCpuCacheable)102 uint32_t GMM_STDCALL GmmLib::GmmClientContext::CachePolicyGetPATIndex(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage, bool *pCompressionEnable, bool IsCpuCacheable)
103 {
104     return pGmmLibContext->GetCachePolicyObj()->CachePolicyGetPATIndex(pResInfo, Usage, pCompressionEnable, IsCpuCacheable);
105 }
106 
107 /////////////////////////////////////////////////////////////////////////////////////
108 /// Member function of ClientContext class for checking if PTE is cached  for a
109 /// given resource usage type
110 ///
111 /// @param[in]  GMM_RESOURCE_USAGE_TYPE : Resource Usage Type
112 /// @return     True if PTE cached, else false
113 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyIsUsagePTECached(GMM_RESOURCE_USAGE_TYPE Usage)114 uint8_t GMM_STDCALL GmmLib::GmmClientContext::CachePolicyIsUsagePTECached(GMM_RESOURCE_USAGE_TYPE Usage)
115 {
116     return pGmmLibContext->GetCachePolicyObj()->CachePolicyIsUsagePTECached(Usage);
117 }
118 
119 /////////////////////////////////////////////////////////////////////////////////////
120 /// Member function of ClientContext class to return L1 Cache Control on DG2 for a
121 /// given resource usage type
122 ///
123 /// @param[in]  GMM_RESOURCE_USAGE_TYPE : Resource Usage Type
124 /// @return     Value of L1 Cache control
125 /////////////////////////////////////////////////////////////////////////////////////
GetSurfaceStateL1CachePolicy(GMM_RESOURCE_USAGE_TYPE Usage)126 uint8_t GMM_STDCALL GmmLib::GmmClientContext::GetSurfaceStateL1CachePolicy(GMM_RESOURCE_USAGE_TYPE Usage)
127 {
128     return pGmmLibContext->GetCachePolicyObj()->GetSurfaceStateL1CachePolicy(Usage);
129 }
130 
131 /////////////////////////////////////////////////////////////////////////////////////
132 /// Member function of ClientContext class to return Swizzle Descriptor
133 /// given Swizzle name , ResType and bpe
134 ///
135 /// @param[in] EXTERNAL_SWIZZLE_NAME
136 /// @param[in] EXTERNAL_RES_TYPE
137 /// @param[in] bpe
138 /// @return  SWIZZLE_DESCRIPTOR*
139 /////////////////////////////////////////////////////////////////////////////////////
GetSwizzleDesc(EXTERNAL_SWIZZLE_NAME ExternalSwizzleName,EXTERNAL_RES_TYPE ResType,uint8_t bpe,bool isStdSwizzle)140 const SWIZZLE_DESCRIPTOR *GMM_STDCALL GmmLib::GmmClientContext::GetSwizzleDesc(EXTERNAL_SWIZZLE_NAME ExternalSwizzleName, EXTERNAL_RES_TYPE ResType, uint8_t bpe, bool isStdSwizzle)
141 {
142     const SWIZZLE_DESCRIPTOR *pSwizzleDesc;
143     pSwizzleDesc = NULL;
144     /*#define SWITCH_SWIZZLE(Layout, res, bpe) \
145         pSwizzleDesc = &Layout##_##res##bpe;*/
146 
147 #define CASE_BPP(Layout, Tile, msaa, xD, bpe)       \
148     case bpe:                                       \
149         pSwizzleDesc = &Layout##_##Tile##msaa##bpe; \
150         break;
151 
152 #define SWITCH_SWIZZLE(Layout, Tile, msaa, bpe) \
153     switch (bpe)                                \
154     {                                           \
155         CASE_BPP(Layout, Tile, msaa, xD, 8);    \
156         CASE_BPP(Layout, Tile, msaa, xD, 16);   \
157         CASE_BPP(Layout, Tile, msaa, xD, 32);   \
158         CASE_BPP(Layout, Tile, msaa, xD, 64);   \
159         CASE_BPP(Layout, Tile, msaa, xD, 128);  \
160     }
161 #define SWIZZLE_DESC(pGmmLibContext, ExternalSwizzleName, ResType, bpe, pSwizzleDesc) \
162     switch (ExternalSwizzleName)                                                      \
163     {                                                                                 \
164     case TILEX:                                                                       \
165         pSwizzleDesc = &INTEL_TILE_X;                                                 \
166         break;                                                                        \
167     case TILEY:                                                                       \
168         if (GmmGetSkuTable(pGmmLibContext)->FtrTileY)                                 \
169             pSwizzleDesc = &INTEL_TILE_Y;                                             \
170         else                                                                          \
171             pSwizzleDesc = &INTEL_TILE_4;                                             \
172         break;                                                                        \
173     case TILEYS:                                                                      \
174         if (GmmGetSkuTable(pGmmLibContext)->FtrTileY || isStdSwizzle)                 \
175         {                                                                             \
176             switch (ResType)                                                          \
177             {                                                                         \
178             case 0:                                                                   \
179                 SWITCH_SWIZZLE(INTEL_TILE_YS, , , bpe);                               \
180                 break;                                                                \
181             case 1:                                                                   \
182                 SWITCH_SWIZZLE(INTEL_TILE_YS, 3D_, , bpe);                            \
183                 break;                                                                \
184             case 2:                                                                   \
185                 SWITCH_SWIZZLE(INTEL_TILE_YS, , MSAA2_, bpe);                         \
186                 break;                                                                \
187             case 3:                                                                   \
188                 SWITCH_SWIZZLE(INTEL_TILE_YS, , MSAA4_, bpe);                         \
189                 break;                                                                \
190             case 4:                                                                   \
191                 SWITCH_SWIZZLE(INTEL_TILE_YS, , MSAA8_, bpe);                         \
192                 break;                                                                \
193             case 5:                                                                   \
194                 SWITCH_SWIZZLE(INTEL_TILE_YS, , MSAA16_, bpe);                        \
195                 break;                                                                \
196             }                                                                         \
197         }                                                                             \
198         else if (GmmGetSkuTable(pGmmLibContext)->FtrXe2PlusTiling)                    \
199         {                                                                             \
200             switch (ResType)                                                          \
201             {                                                                         \
202             case 0:                                                                   \
203                 SWITCH_SWIZZLE(INTEL_TILE_64, , , bpe);                               \
204                 break;                                                                \
205             case 1:                                                                   \
206                 SWITCH_SWIZZLE(INTEL_TILE_64_V2, 3D_, , bpe);                         \
207                 break;                                                                \
208             case 2:                                                                   \
209                 SWITCH_SWIZZLE(INTEL_TILE_64_V2, , MSAA2_, bpe);                      \
210                 break;                                                                \
211             case 3:                                                                   \
212                 SWITCH_SWIZZLE(INTEL_TILE_64_V2, , MSAA4_, bpe);                      \
213                 break;                                                                \
214             case 4:                                                                   \
215                 SWITCH_SWIZZLE(INTEL_TILE_64_V2, , MSAA8_, bpe);                      \
216                 break;                                                                \
217             case 5:                                                                   \
218                 SWITCH_SWIZZLE(INTEL_TILE_64_V2, , MSAA16_, bpe);                     \
219                 break;                                                                \
220             }                                                                         \
221         }                                                                             \
222         else                                                                          \
223         {                                                                             \
224             switch (ResType)                                                          \
225             {                                                                         \
226             case 0:                                                                   \
227                 SWITCH_SWIZZLE(INTEL_TILE_64, , , bpe);                               \
228                 break;                                                                \
229             case 1:                                                                   \
230                 SWITCH_SWIZZLE(INTEL_TILE_64, 3D_, , bpe);                            \
231                 break;                                                                \
232             case 2:                                                                   \
233                 SWITCH_SWIZZLE(INTEL_TILE_64, , MSAA2_, bpe);                         \
234                 break;                                                                \
235             case 3:                                                                   \
236             case 4:                                                                   \
237             case 5:                                                                   \
238                 SWITCH_SWIZZLE(INTEL_TILE_64, , MSAA_, bpe);                          \
239                 break;                                                                \
240             }                                                                         \
241         }                                                                             \
242     case TILEW:                                                                       \
243     case TILEYF:                                                                      \
244     default: break;                                                                   \
245     }                                                                                 \
246 
247     SWIZZLE_DESC(pGmmLibContext, ExternalSwizzleName, ResType, bpe, pSwizzleDesc);
248     return pSwizzleDesc;
249 }
250 
251 /////////////////////////////////////////////////////////////////////////////////////
252 /// Member function of ClientContext class for returning Max MOCS index used
253 /// on a platform
254 ///
255 /// @return     Max MOCS Index
256 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetMaxMocsIndex()257 uint32_t GMM_STDCALL GmmLib::GmmClientContext::CachePolicyGetMaxMocsIndex()
258 {
259     GMM_CACHE_POLICY *          pCachePolicy = pGmmLibContext->GetCachePolicyObj();
260     GmmLib::GmmGen9CachePolicy *ptr          = static_cast<GmmLib::GmmGen9CachePolicy *>(pCachePolicy);
261     return ptr->CurrentMaxMocsIndex;
262 }
263 
264 /////////////////////////////////////////////////////////////////////////////////////
265 /// Member function of ClientContext class for returning Max L1 HDC MOCS index used
266 /// on a platform
267 ///
268 /// @return     Max L1 HDC MOCS Index
269 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetMaxL1HdcMocsIndex()270 uint32_t GMM_STDCALL GmmLib::GmmClientContext::CachePolicyGetMaxL1HdcMocsIndex()
271 {
272     GMM_CACHE_POLICY *          pCachePolicy = pGmmLibContext->GetCachePolicyObj();
273     GmmLib::GmmGen9CachePolicy *ptr          = static_cast<GmmLib::GmmGen9CachePolicy *>(pCachePolicy);
274     return ptr->CurrentMaxL1HdcMocsIndex;
275 }
276 
277 /////////////////////////////////////////////////////////////////////////////////////
278 /// Returns count of current Special MOCS values for MOCS Table programming at GMM boot
279 ///
280 /// @param[in]  none:
281 /// @return     uint32_t  max special mocs index needed to program
282 /////////////////////////////////////////////////////////////////////////////////////
CachePolicyGetMaxSpecialMocsIndex(void)283 uint32_t GMM_STDCALL GmmLib::GmmClientContext::CachePolicyGetMaxSpecialMocsIndex(void)
284 {
285     GMM_CACHE_POLICY *pCachePolicy = pGmmLibContext->GetCachePolicyObj();
286     return pCachePolicy->GetMaxSpecialMocsIndex();
287 }
288 /////////////////////////////////////////////////////////////////////////////////////
289 /// Member function of ClientContext class for returning GMM_CACHE_POLICY_ELEMENT
290 /// Table defiend for a platform
291 ///
292 /// @return     Const GMM_CACHE_POLICY_ELEMENT Table
293 /////////////////////////////////////////////////////////////////////////////////////
GetCachePolicyUsage()294 GMM_CACHE_POLICY_ELEMENT *GMM_STDCALL GmmLib::GmmClientContext::GetCachePolicyUsage()
295 {
296     return (pGmmLibContext->GetCachePolicyUsage());
297 }
298 
299 /////////////////////////////////////////////////////////////////////////////////////
300 /// Member function of ClientContext class for populating GMM_CACHE_SIZES
301 /// available on a platform
302 ///
303 /// @return     In/Out GMM_CACHE_SIZES Populated Caches sizes
304 /////////////////////////////////////////////////////////////////////////////////////
GetCacheSizes(GMM_CACHE_SIZES * pCacheSizes)305 void GMM_STDCALL GmmLib::GmmClientContext::GetCacheSizes(GMM_CACHE_SIZES *pCacheSizes)
306 {
307     return GmmGetCacheSizes(pGmmLibContext, pCacheSizes);
308 }
309 
310 /////////////////////////////////////////////////////////////////////////////////////
311 /// Member function of ClientContext class for returning GMM_CACHE_POLICY_ELEMENT
312 /// for a given Resource Usage Type
313 ///
314 /// @return     GMM_CACHE_POLICY_ELEMENT
315 /////////////////////////////////////////////////////////////////////////////////////
GetCachePolicyElement(GMM_RESOURCE_USAGE_TYPE Usage)316 GMM_CACHE_POLICY_ELEMENT GMM_STDCALL GmmLib::GmmClientContext::GetCachePolicyElement(GMM_RESOURCE_USAGE_TYPE Usage)
317 {
318     return pGmmLibContext->GetCachePolicyElement(Usage);
319 }
320 
321 /////////////////////////////////////////////////////////////////////////////////////
322 /// Member function of ClientContext class for returning GMM_CACHE_POLICY_TBL_ELEMENT
323 /// for a given Mocs Index
324 ///
325 /// @return     GMM_CACHE_POLICY_TBL_ELEMENT
326 /////////////////////////////////////////////////////////////////////////////////////
GetCachePolicyTlbElement(uint32_t MocsIdx)327 GMM_CACHE_POLICY_TBL_ELEMENT GMM_STDCALL GmmLib::GmmClientContext::GetCachePolicyTlbElement(uint32_t MocsIdx)
328 {
329     return pGmmLibContext->GetCachePolicyTlbElement()[MocsIdx];
330 }
331 
332 /////////////////////////////////////////////////////////////////////////////////////
333 /// Member function of ClientContext class for returning GMM_PLATFORM_INFO data
334 ///
335 /// @return     GMM_PLATFORM_INFO&
336 /////////////////////////////////////////////////////////////////////////////////////
GetPlatformInfo()337 GMM_PLATFORM_INFO &GMM_STDCALL GmmLib::GmmClientContext::GetPlatformInfo()
338 {
339     return pGmmLibContext->GetPlatformInfo();
340 }
341 
342 /////////////////////////////////////////////////////////////////////////////////////
343 /// Member function of ClientContext class for getting Alignment info
344 ///
345 /// @return     void
346 //////////////////////////////////////////////////////////////////////////////////
GetExtendedTextureAlign(uint32_t Mode,ALIGNMENT & UnitAlign)347 void GMM_STDCALL GmmLib::GmmClientContext::GetExtendedTextureAlign(uint32_t Mode, ALIGNMENT &UnitAlign)
348 {
349     ALIGNMENT AlignInfo;
350     pGmmLibContext->GetPlatformInfoObj()->ApplyExtendedTexAlign(Mode, AlignInfo);
351     UnitAlign = AlignInfo;
352 }
353 
354 /////////////////////////////////////////////////////////////////////////////////////
355 /// Member function of ClientContext class for returning SKU_FEATURE_TABLE data
356 ///
357 /// @return     SKU_FEATURE_TABLE&
358 /////////////////////////////////////////////////////////////////////////////////////
GetSkuTable()359 const SKU_FEATURE_TABLE &GMM_STDCALL GmmLib::GmmClientContext::GetSkuTable()
360 {
361     return pGmmLibContext->GetSkuTable();
362 }
363 
364 /////////////////////////////////////////////////////////////////////////////////////
365 /// Member function of ClientContext class for returning whether the given Resource
366 /// format is Planar
367 ///
368 /// @return     True if the Given format is planar
369 /////////////////////////////////////////////////////////////////////////////////////
IsPlanar(GMM_RESOURCE_FORMAT Format)370 uint8_t GMM_STDCALL GmmLib::GmmClientContext::IsPlanar(GMM_RESOURCE_FORMAT Format)
371 {
372     return GmmIsPlanar(Format);
373 }
374 
375 /////////////////////////////////////////////////////////////////////////////////////
376 /// Member function of ClientContext class for returning whether the given Resource
377 /// format is P0xx
378 ///
379 /// @return     True if the Given format is P0xx
380 /////////////////////////////////////////////////////////////////////////////////////
IsP0xx(GMM_RESOURCE_FORMAT Format)381 uint8_t GMM_STDCALL GmmLib::GmmClientContext::IsP0xx(GMM_RESOURCE_FORMAT Format)
382 {
383     return GmmIsP0xx(Format);
384 }
385 
386 /////////////////////////////////////////////////////////////////////////////////////
387 /// Member function of ClientContext class for returning whether the given Resource
388 /// format is UV Packed plane
389 ///
390 /// @return     True if the Given format is UV packed
391 /////////////////////////////////////////////////////////////////////////////////////
IsUVPacked(GMM_RESOURCE_FORMAT Format)392 uint8_t GMM_STDCALL GmmLib::GmmClientContext::IsUVPacked(GMM_RESOURCE_FORMAT Format)
393 {
394     return GmmIsUVPacked(Format);
395 }
396 
397 /////////////////////////////////////////////////////////////////////////////////////
398 /// Member function of ClientContext class for returning whether the given Resource
399 /// format is Compressed
400 ///
401 /// @return     True if the Given format is Compressed
402 /////////////////////////////////////////////////////////////////////////////////////
IsCompressed(GMM_RESOURCE_FORMAT Format)403 uint8_t GMM_STDCALL GmmLib::GmmClientContext::IsCompressed(GMM_RESOURCE_FORMAT Format)
404 {
405     return (Format > GMM_FORMAT_INVALID) &&
406            (Format < GMM_RESOURCE_FORMATS) &&
407            pGmmLibContext->GetPlatformInfo().FormatTable[Format].Compressed;
408 }
409 
410 /////////////////////////////////////////////////////////////////////////////////////
411 /// Member function of ClientContext class for returning whether the given Resource
412 /// format is YUV Packed plane
413 ///
414 /// @return     True if the Given format is YUV packed
415 /////////////////////////////////////////////////////////////////////////////////////
IsYUVPacked(GMM_RESOURCE_FORMAT Format)416 uint8_t GMM_STDCALL GmmLib::GmmClientContext::IsYUVPacked(GMM_RESOURCE_FORMAT Format)
417 {
418     return GmmIsYUVPacked(Format);
419 }
420 
421 /////////////////////////////////////////////////////////////////////////////////////
422 /// Member function of ClientContext class for returning its GMM_SURFACESTATE_FORMAT
423 /// for the given equivalent GMM_RESOURCE_FORMAT type
424 ///
425 /// @return     GMM_SURFACESTATE_FORMAT for the given format type
426 /////////////////////////////////////////////////////////////////////////////////////
GetSurfaceStateFormat(GMM_RESOURCE_FORMAT Format)427 GMM_SURFACESTATE_FORMAT GMM_STDCALL GmmLib::GmmClientContext::GetSurfaceStateFormat(GMM_RESOURCE_FORMAT Format)
428 {
429     // ToDo: Remove the definition of GmmGetSurfaceStateFormat(Format)
430     return ((Format > GMM_FORMAT_INVALID) &&
431             (Format < GMM_RESOURCE_FORMATS)) ?
432            pGmmLibContext->GetPlatformInfo().FormatTable[Format].SurfaceStateFormat :
433            GMM_SURFACESTATE_FORMAT_INVALID;
434 }
435 
436 /////////////////////////////////////////////////////////////////////////////////////
437 /// Member function of ClientContext class for returning
438 /// RENDER_SURFACE_STATE::CompressionFormat
439 ///
440 /// @return     uint8_t
441 /////////////////////////////////////////////////////////////////////////////////////
GetSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT Format)442 uint8_t GMM_STDCALL GmmLib::GmmClientContext::GetSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT Format)
443 {
444     __GMM_ASSERT((Format > GMM_FORMAT_INVALID) && (Format < GMM_RESOURCE_FORMATS));
445     return pGmmLibContext->GetPlatformInfo().FormatTable[Format].CompressionFormat.AuxL1eFormat;
446 
447 }
448 
449 /////////////////////////////////////////////////////////////////////////////////////
450 /// Member function of ClientContext class for returning
451 /// MEDIA_SURFACE_STATE::CompressionFormat
452 ///
453 /// @return     uint8_t
454 /////////////////////////////////////////////////////////////////////////////////////
GetMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT Format)455 uint8_t GMM_STDCALL GmmLib::GmmClientContext::GetMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT Format)
456 {
457     __GMM_ASSERT((Format > GMM_FORMAT_INVALID) && (Format < GMM_RESOURCE_FORMATS));
458 
459     return pGmmLibContext->GetPlatformInfoObj()->OverrideCompressionFormat(Format, (uint8_t)0x1);
460 }
461 
462 /////////////////////////////////////////////////////////////////////////////////////
463 /// Member function of ClientContext class for returning E2E compression format
464 ///
465 /// @return     GMM_E2ECOMP_FORMAT
466 /////////////////////////////////////////////////////////////////////////////////////
GetLosslessCompressionType(GMM_RESOURCE_FORMAT Format)467 GMM_E2ECOMP_FORMAT GMM_STDCALL GmmLib::GmmClientContext::GetLosslessCompressionType(GMM_RESOURCE_FORMAT Format)
468 {
469     // ToDo: Remove the definition of GmmGetLosslessCompressionType(Format)
470     __GMM_ASSERT((Format > GMM_FORMAT_INVALID) && (Format < GMM_RESOURCE_FORMATS));
471 
472     return pGmmLibContext->GetPlatformInfo().FormatTable[Format].CompressionFormat.AuxL1eFormat;
473 }
474 
475 /////////////////////////////////////////////////////////////////////////////////////
476 /// Member function of ClientContext class to return InternalGpuVaMax value
477 /// stored in pGmmLibContext
478 ///
479 /// @return    GMM_SUCCESS
480 /////////////////////////////////////////////////////////////////////////////////////
GetInternalGpuVaRangeLimit()481 uint64_t GMM_STDCALL GmmLib::GmmClientContext::GetInternalGpuVaRangeLimit()
482 {
483     return pGmmLibContext->GetInternalGpuVaRangeLimit();
484 }
485 
486 /////////////////////////////////////////////////////////////////////////////////////
487 /// Member function of ClientContext class for creation of Custiom ResourceInfo Object .
488 /// @see        GmmLib::GmmResourceInfoCommon::Create()
489 ///
490 /// @param[in] pCreateParams: Flags which specify what sort of resource to create
491 /// @return     Pointer to GmmResourceInfo class.
492 /////////////////////////////////////////////////////////////////////////////////////
CreateCustomResInfoObject(GMM_RESCREATE_CUSTOM_PARAMS * pCreateParams)493 GMM_RESOURCE_INFO *GMM_STDCALL GmmLib::GmmClientContext::CreateCustomResInfoObject(GMM_RESCREATE_CUSTOM_PARAMS *pCreateParams)
494 {
495     GMM_RESOURCE_INFO *pRes             = NULL;
496     GmmClientContext * pClientContextIn = NULL;
497 
498     pClientContextIn = this;
499 
500     if((pRes = new GMM_RESOURCE_INFO(pClientContextIn)) == NULL)
501     {
502         GMM_ASSERTDPF(0, "Allocation failed!");
503         goto ERROR_CASE;
504     }
505 
506     if(pRes->CreateCustomRes(*pGmmLibContext, *pCreateParams) != GMM_SUCCESS)
507     {
508         goto ERROR_CASE;
509     }
510 
511     return (pRes);
512 
513 ERROR_CASE:
514     if(pRes)
515     {
516         DestroyResInfoObject(pRes);
517     }
518 
519     return (NULL);
520 }
521 
522 #ifndef __GMM_KMD__
523 /////////////////////////////////////////////////////////////////////////////////////
524 /// Member function of ClientContext class for creation of Custiom ResourceInfo Object .
525 /// @see        GmmLib::GmmResourceInfoCommon::CreateCustomResInfoObject_2()
526 ///
527 /// @param[in] pCreateParams: Flags which specify what sort of resource to create
528 /// @return     Pointer to GmmResourceInfo class.
529 /////////////////////////////////////////////////////////////////////////////////////
CreateCustomResInfoObject_2(GMM_RESCREATE_CUSTOM_PARAMS_2 * pCreateParams)530 GMM_RESOURCE_INFO *GMM_STDCALL GmmLib::GmmClientContext::CreateCustomResInfoObject_2(GMM_RESCREATE_CUSTOM_PARAMS_2 *pCreateParams)
531 {
532     GMM_RESOURCE_INFO *pRes             = NULL;
533     GmmClientContext * pClientContextIn = NULL;
534 
535     pClientContextIn = this;
536 
537     if((pRes = new GMM_RESOURCE_INFO(pClientContextIn)) == NULL)
538     {
539         GMM_ASSERTDPF(0, "Allocation failed!");
540         goto ERROR_CASE;
541     }
542 
543     if(pRes->CreateCustomRes_2(*pGmmLibContext, *pCreateParams) != GMM_SUCCESS)
544     {
545         goto ERROR_CASE;
546     }
547 
548     return (pRes);
549 
550 ERROR_CASE:
551     if(pRes)
552     {
553         DestroyResInfoObject(pRes);
554     }
555 
556     return (NULL);
557 }
558 #endif
559 
560 /////////////////////////////////////////////////////////////////////////////////////
561 /// Member function of ClientContext class for creation of ResourceInfo Object .
562 /// @see        GmmLib::GmmResourceInfoCommon::Create()
563 ///
564 /// @param[in] pCreateParams: Flags which specify what sort of resource to create
565 /// @return     Pointer to GmmResourceInfo class.
566 /////////////////////////////////////////////////////////////////////////////////////
CreateResInfoObject(GMM_RESCREATE_PARAMS * pCreateParams)567 GMM_RESOURCE_INFO *GMM_STDCALL GmmLib::GmmClientContext::CreateResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams)
568 {
569     GMM_RESOURCE_INFO *pRes             = NULL;
570     GmmClientContext * pClientContextIn = NULL;
571 
572 #if(!defined(GMM_UNIFIED_LIB))
573     pClientContextIn = pGmmLibContext->pGmmGlobalClientContext;
574 #else
575     pClientContextIn = this;
576 #endif
577 
578     GMM_DPF_ENTER;
579 
580     // GMM_RESOURCE_INFO...
581     if(pCreateParams->pPreallocatedResInfo)
582     {
583         pRes = new(pCreateParams->pPreallocatedResInfo) GmmLib::GmmResourceInfo(pClientContextIn); // Use preallocated memory as a class
584         pCreateParams->Flags.Info.__PreallocatedResInfo =
585         pRes->GetResFlags().Info.__PreallocatedResInfo = 1; // Set both in case we can die before copying over the flags.
586     }
587     else
588     {
589         if((pRes = new GMM_RESOURCE_INFO(pClientContextIn)) == NULL)
590         {
591             GMM_ASSERTDPF(0, "Allocation failed!");
592             goto ERROR_CASE;
593         }
594     }
595 
596     if(pRes->Create(*pGmmLibContext, *pCreateParams) != GMM_SUCCESS)
597     {
598         goto ERROR_CASE;
599     }
600 
601     GMM_DPF_EXIT;
602 
603     return (pRes);
604 
605 ERROR_CASE:
606     if(pRes)
607     {
608         DestroyResInfoObject(pRes);
609     }
610 
611     return (NULL);
612 }
613 
614 /////////////////////////////////////////////////////////////////////////////////////
615 /// Member function of ClientContext class for creation of ResourceInfo Object from
616 /// already created Src ResInfo object
617 /// @see        GmmLib::GmmResourceInfoCommon::Create()
618 ///
619 /// @param[in] pSrcRes: Existing ResInfoObj
620 /// @return     Pointer to GmmResourceInfo class.
621 /////////////////////////////////////////////////////////////////////////////////////
CopyResInfoObject(GMM_RESOURCE_INFO * pSrcRes)622 GMM_RESOURCE_INFO *GMM_STDCALL GmmLib::GmmClientContext::CopyResInfoObject(GMM_RESOURCE_INFO *pSrcRes)
623 {
624     GMM_RESOURCE_INFO *pResCopy         = NULL;
625     GmmClientContext * pClientContextIn = NULL;
626 
627 #if(!defined(GMM_UNIFIED_LIB))
628     pClientContextIn = pGmmLibContext->pGmmGlobalClientContext;
629 #else
630     pClientContextIn = this;
631 #endif
632 
633     __GMM_ASSERTPTR(pSrcRes, NULL);
634 
635     pResCopy = new GMM_RESOURCE_INFO(pClientContextIn);
636     if(!pResCopy)
637     {
638         GMM_ASSERTDPF(0, "Allocation failed.");
639         return NULL;
640     }
641 
642     // Set the GmmLibContext for newly created DestResInfo object
643     pResCopy->SetGmmLibContext(pGmmLibContext);
644 
645     *pResCopy = *pSrcRes;
646 
647     // Set the client type to the client for which this resinfo is created
648     pResCopy->SetClientType(GetClientType());
649 
650     // We are allocating new class, flag must be false to avoid leak at DestroyResource
651     pResCopy->GetResFlags().Info.__PreallocatedResInfo = 0;
652 
653     return (pResCopy);
654 }
655 
656 /////////////////////////////////////////////////////////////////////////////////////
657 /// Member function of ClientContext class for copy of ResourceInfo Object from
658 /// already created Src ResInfo object
659 /// @see        GmmLib::GmmResourceInfoCommon::Create()
660 ///
661 /// @param[in] pDst: Pointer to memory when pSrc will be copied
662 /// @param[in] pSrc: Pointer to GmmResourceInfo class that needs to be copied
663 /////////////////////////////////////////////////////////////////////////////////////
ResMemcpy(void * pDst,void * pSrc)664 void GMM_STDCALL GmmLib::GmmClientContext::ResMemcpy(void *pDst, void *pSrc)
665 {
666     GmmClientContext *pClientContextIn = NULL;
667 
668 #if(!defined(GMM_UNIFIED_LIB))
669     pClientContextIn = pGmmLibContext->pGmmGlobalClientContext;
670 #else
671     pClientContextIn = this;
672 #endif
673 
674     GMM_RESOURCE_INFO *pResSrc = reinterpret_cast<GMM_RESOURCE_INFO *>(pSrc);
675     // Init memory correctly, in case the pointer is a raw memory pointer
676     GMM_RESOURCE_INFO *pResDst = new(pDst) GMM_RESOURCE_INFO(pClientContextIn);
677 
678     // Set the GmmLibContext for newly created DestResInfo object
679     pResDst->SetGmmLibContext(pGmmLibContext);
680 
681     *pResDst = *pResSrc;
682 
683     // Set the client type to the client for which this resinfo is created
684     pResDst->SetClientType(GetClientType());
685 }
686 
687 /////////////////////////////////////////////////////////////////////////////////////
688 /// Member function of ClientContext class for Destroying ResInfoObject
689 ///
690 /// @param[in] pResInfo: Pointer to ResInfoObject
691 /// @return     void.
692 /////////////////////////////////////////////////////////////////////////////////////
DestroyResInfoObject(GMM_RESOURCE_INFO * pResInfo)693 void GMM_STDCALL GmmLib::GmmClientContext::DestroyResInfoObject(GMM_RESOURCE_INFO *pResInfo)
694 {
695     __GMM_ASSERTPTR(pResInfo, VOIDRETURN);
696 
697     if(pResInfo->GetResFlags().Info.__PreallocatedResInfo)
698     {
699         *pResInfo = GmmLib::GmmResourceInfo();
700     }
701     else
702     {
703         delete pResInfo;
704         pResInfo = NULL;
705     }
706 }
707 
708 /////////////////////////////////////////////////////////////////////////////////////
709 /// Member function of ClientContext class for creation of PAgeTableMgr Object .
710 /// @see        GmmLib::GMM_PAGETABLE_MGR::GMM_PAGETABLE_MGR
711 ///
712 /// @param[in] TTFags
713 /// @return     Pointer to GMM_PAGETABLE_MGR class.
714 /////////////////////////////////////////////////////////////////////////////////////
CreatePageTblMgrObject(uint32_t TTFlags)715 GMM_PAGETABLE_MGR* GMM_STDCALL GmmLib::GmmClientContext::CreatePageTblMgrObject(uint32_t TTFlags)
716 {
717     if (!IsDeviceCbReceived)
718     {
719         GMM_ASSERTDPF(0, "Device_callbacks not set");
720         return NULL;
721     }
722 
723     return CreatePageTblMgrObject(&DeviceCB, TTFlags);
724 }
725 
726 /////////////////////////////////////////////////////////////////////////////////////
727 /// Member function of ClientContext class for creation of PAgeTableMgr Object .
728 /// @see        GmmLib::GMM_PAGETABLE_MGR::GMM_PAGETABLE_MGR
729 ///
730 /// @param[in] pDevCb: Pointer to GMM_DEVICE_CALLBACKS_INT
731 /// @param[in] TTFags
732 /// @return     Pointer to GMM_PAGETABLE_MGR class.
733 //  move the code to new overloaded the API and remove this API once all clients are moved to new API.
734 /////////////////////////////////////////////////////////////////////////////////////
CreatePageTblMgrObject(GMM_DEVICE_CALLBACKS_INT * pDevCb,uint32_t TTFlags)735 GMM_PAGETABLE_MGR* GMM_STDCALL GmmLib::GmmClientContext::CreatePageTblMgrObject(GMM_DEVICE_CALLBACKS_INT* pDevCb,
736                                                                                 uint32_t TTFlags)
737 {
738     GMM_PAGETABLE_MGR* pPageTableMgr = NULL;
739 
740     pPageTableMgr = new GMM_PAGETABLE_MGR(pDevCb, TTFlags, this);
741 
742     return pPageTableMgr;
743 }
744 
745 /////////////////////////////////////////////////////////////////////////////////////
746 /// Member function of ClientContext class for destroy of PageTableMgr Object .
747 ///
748 /// @param[in] pPageTableMgr: Pointer to GMM_PAGETABLE_MGR
749 /// @return     void.
750 /////////////////////////////////////////////////////////////////////////////////////
DestroyPageTblMgrObject(GMM_PAGETABLE_MGR * pPageTableMgr)751 void GMM_STDCALL GmmLib::GmmClientContext::DestroyPageTblMgrObject(GMM_PAGETABLE_MGR* pPageTableMgr)
752 {
753     if (pPageTableMgr)
754     {
755         delete pPageTableMgr;
756     }
757 }
758 
759 #ifdef GMM_LIB_DLL
760 /////////////////////////////////////////////////////////////////////////////////////
761 /// Member function of ClientContext class for creation of ResourceInfo Object .
762 /// @see        GmmLib::GmmResourceInfoCommon::Create()
763 ///
764 /// @param[in] pCreateParams: Flags which specify what sort of resource to create
765 /// @return     Pointer to GmmResourceInfo class.
766 /////////////////////////////////////////////////////////////////////////////////////
CreateResInfoObject(GMM_RESCREATE_PARAMS * pCreateParams,GmmClientAllocationCallbacks * pAllocCbs)767 GMM_RESOURCE_INFO *GMM_STDCALL GmmLib::GmmClientContext::CreateResInfoObject(GMM_RESCREATE_PARAMS *        pCreateParams,
768                                                                              GmmClientAllocationCallbacks *pAllocCbs)
769 {
770     if(!pAllocCbs || !pAllocCbs->pfnAllocation)
771     {
772         return CreateResInfoObject(pCreateParams);
773     }
774     else
775     {
776         GMM_RESOURCE_INFO *pRes   = NULL;
777         void *             pConst = NULL;
778 
779         // GMM_RESOURCE_INFO...
780         if(pCreateParams->pPreallocatedResInfo)
781         {
782             pRes = new(pCreateParams->pPreallocatedResInfo) GmmLib::GmmResourceInfo(this); // Use preallocated memory as a class
783             pCreateParams->Flags.Info.__PreallocatedResInfo =
784             pRes->GetResFlags().Info.__PreallocatedResInfo = 1; // Set both in case we can die before copying over the flags.
785         }
786         else
787         {
788             pConst = pAllocCbs->pfnAllocation(pAllocCbs->pUserData,
789                                               sizeof(GMM_RESOURCE_INFO),
790                                               alignof(GMM_RESOURCE_INFO));
791             if(pConst == NULL)
792             {
793                 GMM_ASSERTDPF(0, "Allocation failed!");
794                 goto ERROR_CASE;
795             }
796             else
797             {
798                 pRes = new(pConst) GMM_RESOURCE_INFO(this);
799             }
800         }
801 
802         if(pRes->Create(*pGmmLibContext, *pCreateParams) != GMM_SUCCESS)
803         {
804             goto ERROR_CASE;
805         }
806 
807         return (pRes);
808 
809     ERROR_CASE:
810         if(pRes)
811         {
812             if(pAllocCbs->pfnFree)
813             {
814 #ifdef _WIN32
815                 pRes->~GmmResourceInfoWin();
816 #else
817                 pRes->~GmmResourceInfoLin();
818 #endif
819 
820                 pAllocCbs->pfnFree(pAllocCbs->pUserData, (void *)pRes);
821             }
822         }
823 
824         return (NULL);
825     }
826 }
827 
828 /////////////////////////////////////////////////////////////////////////////////////
829 /// Member function of ClientContext class for Destroying ResInfoObject
830 ///
831 /// @param[in] pResInfo: Pointer to ResInfoObject
832 /// @return     void.
833 /////////////////////////////////////////////////////////////////////////////////////
DestroyResInfoObject(GMM_RESOURCE_INFO * pResInfo,GmmClientAllocationCallbacks * pAllocCbs)834 void GMM_STDCALL GmmLib::GmmClientContext::DestroyResInfoObject(GMM_RESOURCE_INFO *           pResInfo,
835                                                                 GmmClientAllocationCallbacks *pAllocCbs)
836 {
837     __GMM_ASSERTPTR(pResInfo, VOIDRETURN);
838 
839     if(!pAllocCbs || !pAllocCbs->pfnFree)
840     {
841         return DestroyResInfoObject(pResInfo);
842     }
843     else
844     {
845         if(pResInfo->GetResFlags().Info.__PreallocatedResInfo)
846         {
847             *pResInfo = GmmLib::GmmResourceInfo();
848         }
849         else
850         {
851 #ifdef _WIN32
852             pResInfo->~GmmResourceInfoWin();
853 #else
854             pResInfo->~GmmResourceInfoLin();
855 #endif
856             pAllocCbs->pfnFree(pAllocCbs->pUserData, (void *)pResInfo);
857             pResInfo = NULL;
858         }
859     }
860 }
861 #endif
862 
863 /////////////////////////////////////////////////////////////////////////////////////
864 /// Member function of ClientContext class for creation of PAgeTableMgr Object .
865 /// @see        GmmLib::GMM_PAGETABLE_MGR::GMM_PAGETABLE_MGR
866 ///
867 /// @param[in] TTFags
868 /// @return     Pointer to GMM_PAGETABLE_MGR class.
869 /////////////////////////////////////////////////////////////////////////////////////
CreatePageTblMgrObject(uint32_t TTFlags,GmmClientAllocationCallbacks * pAllocCbs)870 GMM_PAGETABLE_MGR* GMM_STDCALL GmmLib::GmmClientContext::CreatePageTblMgrObject(uint32_t TTFlags,
871                                                          GmmClientAllocationCallbacks* pAllocCbs)
872 {
873     if (!IsDeviceCbReceived)
874     {
875         GMM_ASSERTDPF(0, "Device_callbacks not set");
876         return NULL;
877     }
878     return CreatePageTblMgrObject(
879         &DeviceCB,
880         TTFlags,
881         pAllocCbs);
882 }
883 
884 /////////////////////////////////////////////////////////////////////////////////////
885 /// Member function of ClientContext class for creation of PAgeTableMgr Object .
886 /// @see        GmmLib::GMM_PAGETABLE_MGR::GMM_PAGETABLE_MGR
887 ///
888 /// @param[in] pDevCb: Pointer to GMM_DEVICE_CALLBACKS_INT
889 /// @param[in] TTFags
890 /// @return     Pointer to GMM_PAGETABLE_MGR class.
891 /// move the code to new overloaded the API and remove this API once all clients are moved to new API.
892 /////////////////////////////////////////////////////////////////////////////////////
CreatePageTblMgrObject(GMM_DEVICE_CALLBACKS_INT * pDevCb,uint32_t TTFlags,GmmClientAllocationCallbacks * pAllocCbs)893 GMM_PAGETABLE_MGR* GMM_STDCALL GmmLib::GmmClientContext::CreatePageTblMgrObject(
894                                                          GMM_DEVICE_CALLBACKS_INT* pDevCb,
895                                                          uint32_t                      TTFlags,
896                                                          GmmClientAllocationCallbacks* pAllocCbs)
897 {
898     if (!pAllocCbs || !pAllocCbs->pfnAllocation)
899     {
900         return CreatePageTblMgrObject(
901             pDevCb,
902             TTFlags);
903     }
904     else
905     {
906         GMM_PAGETABLE_MGR* pPageTableMgr = NULL;
907         return pPageTableMgr;
908     }
909 }
910 
911 /////////////////////////////////////////////////////////////////////////////////////
912 /// Member function of ClientContext class for destroy of PageTableMgr Object .
913 ///
914 /// @param[in] pPageTableMgr: Pointer to GMM_PAGETABLE_MGR
915 /// @return     void.
916 /////////////////////////////////////////////////////////////////////////////////////
DestroyPageTblMgrObject(GMM_PAGETABLE_MGR * pPageTableMgr,GmmClientAllocationCallbacks * pAllocCbs)917 void GMM_STDCALL GmmLib::GmmClientContext::DestroyPageTblMgrObject(GMM_PAGETABLE_MGR* pPageTableMgr,
918     GmmClientAllocationCallbacks* pAllocCbs)
919 {
920     if (!pAllocCbs || !pAllocCbs->pfnFree)
921     {
922         return DestroyPageTblMgrObject(pPageTableMgr);
923     }
924 }
925 
926 ////////////////////////////////////////////////////////////////////////////////////
927 /// Member function of ClientContext class for doing device specific operations.
928 /// Clients must call it before any Gfx resource (incl. svm)
929 /// is mapped, must happen before any use of GfxPartition, or PageTableMgr init.
930 /// @param[in]  DeviceInfo : Pointer to info related to Device Operations.
931 /// @return     GMM_STATUS.
932 //////////////////////////////////////////////////////////////////////////////////////////
GmmSetDeviceInfo(GMM_DEVICE_INFO * DeviceInfo)933 GMM_STATUS GMM_STDCALL GmmLib::GmmClientContext::GmmSetDeviceInfo(GMM_DEVICE_INFO* DeviceInfo)
934 {
935     GMM_STATUS Status = GMM_SUCCESS;
936 
937     if (DeviceInfo == NULL || DeviceInfo->pDeviceCb == NULL)
938     {
939         return GMM_INVALIDPARAM;
940     }
941 
942     DeviceCB = *(DeviceInfo->pDeviceCb);
943     IsDeviceCbReceived = 1;
944     return Status;
945 }
946 
947 /////////////////////////////////////////////////////////////////////////////////////
948 /// Gmm lib DLL C wrapper for creating GmmLib::GmmClientContext object
949 /// This C wrapper is used for Multi-Adapter scenarios to take in Adapter's BDF as
950 /// additional input argument to derive its correspodning GmmLibContext
951 ///
952 /// @see        Class GmmLib::GmmClientContext
953 ///
954 /// @param[in]  ClientType : describles the UMD clients such as OCL, DX, OGL, Vulkan etc
955 /// @param[in]  sBDF: Adapter's BDF info
956 ///
957 /// @return     Pointer to GmmClientContext, if Context is created
958 /////////////////////////////////////////////////////////////////////////////////////
GmmCreateClientContextForAdapter(GMM_CLIENT ClientType,ADAPTER_BDF sBdf)959 extern "C" GMM_CLIENT_CONTEXT *GMM_STDCALL GmmCreateClientContextForAdapter(GMM_CLIENT  ClientType,
960                                                                             ADAPTER_BDF sBdf)
961 {
962     GMM_CLIENT_CONTEXT *pGmmClientContext = nullptr;
963     GMM_LIB_CONTEXT *   pLibContext       = pGmmMALibContext->GetAdapterLibContext(sBdf);
964 
965     if (pLibContext)
966     {
967         pGmmClientContext = new GMM_CLIENT_CONTEXT(ClientType, pLibContext);
968 
969     }
970     return pGmmClientContext;
971 }
972 /////////////////////////////////////////////////////////////////////////////////////
973 /// Gmm lib DLL exported C wrapper for deleting GmmLib::GmmClientContext object
974 /// @see        Class GmmLib::GmmClientContext
975 ///
976 /// @param[in]  GMM_CLIENT_CONTEXT * : Pointer to ClientContext object
977 /// @return     Void
978 /////////////////////////////////////////////////////////////////////////////////////
GmmDeleteClientContext(GMM_CLIENT_CONTEXT * pGmmClientContext)979 extern "C" void GMM_STDCALL GmmDeleteClientContext(GMM_CLIENT_CONTEXT *pGmmClientContext)
980 {
981     if(pGmmClientContext)
982     {
983         delete pGmmClientContext;
984         pGmmClientContext = NULL;
985     }
986 }
987