xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/inc/External/Common/GmmInfo.h (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 #pragma once
23 
24 // GmmConst.h needed for GMM_MAX_NUMBER_MOCS_INDEXES
25 #include "GmmConst.h"
26 #include "../../../Platform/GmmPlatforms.h"
27 
28 #ifdef _WIN32
29 #define GMM_MUTEX_HANDLE    HANDLE
30 #else
31 #include <pthread.h>
32 #define GMM_MUTEX_HANDLE    pthread_mutex_t
33 #endif
34 
35 // Set packing alignment
36 #pragma pack(push, 8)
37 
38 //===========================================================================
39 // Forward Declaration: Defined in GmmResourceInfoExt.h
40 //---------------------------------------------------------------------------
41 struct GMM_CONTEXT_REC;
42 typedef struct GMM_CONTEXT_REC GMM_CONTEXT;
43 
44 //===========================================================================
45 // typedef:
46 //      GMM_UMD_CONTEXT
47 //
48 // Description:
49 //      Struct defines user mode GMM context.
50 //----------------------------------------------------------------------------
51 typedef struct GMM_UMD_CONTEXT_REC
52 {
53     uint32_t   TBD1;
54     uint32_t   TBD2;
55     uint32_t   TBD3;
56 } GMM_UMD_CONTEXT;
57 
58 
59 #if (!defined(__GMM_KMD__) && !defined(GMM_UNIFIED_LIB))
60 #include "GmmClientContext.h"
61 #endif
62 
63 //===========================================================================
64 // typedef:
65 //      GMM_GLOBAL_CONTEXT
66 //
67 // Description:
68 //     Struct contains contexts for user mode and kernel mode. It also contains
69 //     platform information. This struct is initialized in user mode with
70 //     GmmInitGlobalContext().
71 //
72 //----------------------------------------------------------------------------
73 
74 #ifdef __cplusplus
75 #include "GmmMemAllocator.hpp"
76 
77 namespace GmmLib
78 {
79     class NON_PAGED_SECTION Context : public GmmMemAllocator
80     {
81     private:
82 #if(!defined(__GMM_KMD__) && !GMM_LIB_DLL_MA)
83     	static int32_t                   RefCount;
84 #endif
85 #if GMM_LIB_DLL_MA
86         int32_t                          RefCount;
87 #endif //GMM_LIB_DLL_MA
88 	GMM_CLIENT                       ClientType;
89         GMM_PLATFORM_INFO_CLASS*         pPlatformInfo;
90 
91         GMM_TEXTURE_CALC*                pTextureCalc;
92         SKU_FEATURE_TABLE                SkuTable;
93         WA_TABLE                         WaTable;
94         GT_SYSTEM_INFO                   GtSysInfo;
95 
96     #if(defined(__GMM_KMD__))
97         GMM_GTT_CONTEXT              GttContext;
98     #endif
99 
100         GMM_CONTEXT                      *pGmmKmdContext;
101         GMM_UMD_CONTEXT                  *pGmmUmdContext;
102         void                             *pKmdHwDev;
103         void                             *pUmdAdapter;
104 
105         GMM_CACHE_POLICY_ELEMENT         CachePolicy[GMM_RESOURCE_USAGE_MAX];
106         GMM_CACHE_POLICY_TBL_ELEMENT     CachePolicyTbl[GMM_MAX_NUMBER_MOCS_INDEXES];
107         GMM_CACHE_POLICY                 *pGmmCachePolicy;
108 
109     #if(defined(__GMM_KMD__))
110         uint64_t           IA32ePATTable;
111 	GMM_PRIVATE_PAT     PrivatePATTable[GMM_NUM_PAT_ENTRIES];
112 	int32_t                PrivatePATTableMemoryType[GMM_NUM_GFX_PAT_TYPES];
113     #endif
114 
115         // Padding Percentage limit on 64KB paged resource
116         uint32_t               AllowedPaddingFor64KbPagesPercentage;
117         uint64_t               InternalGpuVaMax;
118         uint32_t               AllowedPaddingFor64KBTileSurf;
119 
120 #ifdef GMM_LIB_DLL
121         // Mutex Object used for synchronization of ProcessSingleton Context
122         static GMM_MUTEX_HANDLE           SingletonContextSyncMutex;
123 #endif
124         GMM_PRIVATE_PAT PrivatePATTable[GMM_NUM_PAT_ENTRIES];
125         GMM_MUTEX_HANDLE SyncMutex;         // SyncMutex to protect access of Gmm UMD Lib process Singleton Context
126     public :
127         //Constructors and destructors
128         Context();
129         ~Context();
130 
131         GMM_STATUS GMM_STDCALL          LockSingletonContextSyncMutex();
132         GMM_STATUS GMM_STDCALL          UnlockSingletonContextSyncMutex();
133 
134 #if GMM_LIB_DLL_MA
135         int32_t                         IncrementRefCount();
136         int32_t                         DecrementRefCount();
137 #endif //GMM_LIB_DLL_MA
138 
139 #if(!defined(__GMM_KMD__) && (!GMM_LIB_DLL_MA))
IncrementRefCount()140         static int32_t IncrementRefCount()  // Returns the current RefCount and then increment it
141         {
142 #if defined(_WIN32)
143             return(InterlockedIncrement((LONG *)&RefCount) - 1);  //InterLockedIncrement() returns incremented value
144 #elif defined(__linux__)
145             return(__sync_fetch_and_add(&RefCount, 1));
146 #endif
147         }
148 
DecrementRefCount()149         static int32_t DecrementRefCount()
150         {
151             int CurrentValue = 0;
152             int TargetValue = 0;
153             do
154             {
155                 CurrentValue = RefCount;
156                 if (CurrentValue > 0)
157                 {
158                     TargetValue = CurrentValue - 1;
159                 }
160                 else
161                 {
162                     break;
163                 }
164 #if defined(_WIN32)
165             } while (!(InterlockedCompareExchange((LONG *)&RefCount, TargetValue, CurrentValue) == CurrentValue));
166 #elif defined(__linux__)
167             } while (!__sync_bool_compare_and_swap(&RefCount, CurrentValue, TargetValue));
168 #endif
169 
170             return TargetValue;
171         }
172 #endif
173         GMM_STATUS GMM_STDCALL InitContext(
174                                     const PLATFORM& Platform,
175                                     const SKU_FEATURE_TABLE* pSkuTable,
176                                     const WA_TABLE* pWaTable,
177                                     const GT_SYSTEM_INFO* pGtSysInfo,
178                                     GMM_CLIENT ClientType);
179 
180         void GMM_STDCALL DestroyContext();
181 
182 #if (!defined(__GMM_KMD__) && !defined(GMM_UNIFIED_LIB))
183         GMM_CLIENT_CONTEXT *pGmmGlobalClientContext;
184 #endif
185 
186 
187         //Inline functions
188         /////////////////////////////////////////////////////////////////////////
189         /// Returns the client type e.g. DX, OCL, OGL etc.
190         /// @return   client type
191         /////////////////////////////////////////////////////////////////////////
GetClientType()192         GMM_INLINE GMM_CLIENT  GMM_STDCALL  GetClientType()
193         {
194             return (ClientType);
195         }
196 
197         /////////////////////////////////////////////////////////////////////////
198         /// Returns the PlatformInfo
199         /// @return   PlatformInfo
200         /////////////////////////////////////////////////////////////////////////
GetPlatformInfo()201         GMM_INLINE GMM_PLATFORM_INFO&  GMM_STDCALL  GetPlatformInfo()
202         {
203             return (const_cast<GMM_PLATFORM_INFO&>(pPlatformInfo->GetData()));
204         }
205 
206         /////////////////////////////////////////////////////////////////////////
207         /// Returns the cache policy element array ptr
208         /// @return   const cache policy elment ptr
209         /////////////////////////////////////////////////////////////////////////
GetCachePolicyUsage()210         GMM_INLINE GMM_CACHE_POLICY_ELEMENT*  GMM_STDCALL GetCachePolicyUsage()
211         {
212             return (&CachePolicy[0]);
213         }
214 
215         /////////////////////////////////////////////////////////////////////////
216         /// Returns the cache policy tlb element array ptr
217         /// @return   const cache policy elment ptr
218         /////////////////////////////////////////////////////////////////////////
GetCachePolicyTlbElement()219         GMM_INLINE GMM_CACHE_POLICY_TBL_ELEMENT*  GMM_STDCALL GetCachePolicyTlbElement()
220         {
221             return (&CachePolicyTbl[0]);
222         }
223 
224         /////////////////////////////////////////////////////////////////////////
225         /// Returns the texture calculation object ptr
226         /// @return   TextureCalc ptr
227         /////////////////////////////////////////////////////////////////////////
GetTextureCalc()228         GMM_INLINE GMM_TEXTURE_CALC* GMM_STDCALL GetTextureCalc()
229         {
230             return (pTextureCalc);
231         }
232 
233         /////////////////////////////////////////////////////////////////////////
234         /// Returns the platform info class object ptr
235         /// @return   PlatformInfo class object ptr
236         /////////////////////////////////////////////////////////////////////////
GetPlatformInfoObj()237         GMM_INLINE GMM_PLATFORM_INFO_CLASS* GMM_STDCALL GetPlatformInfoObj()
238         {
239             return (pPlatformInfo);
240         }
241 
242         /////////////////////////////////////////////////////////////////////////
243         /// Returns the cache policy object ptr
244         /// @return   TextureCalc ptr
245         /////////////////////////////////////////////////////////////////////////
GetCachePolicyObj()246         GMM_INLINE GMM_CACHE_POLICY* GMM_STDCALL GetCachePolicyObj()
247         {
248             return (pGmmCachePolicy);
249         }
250 
251         /////////////////////////////////////////////////////////////////////////
252         /// Returns the sku table ptr
253         /// @return   const SkuTable ptr
254         /////////////////////////////////////////////////////////////////////////
GetSkuTable()255         GMM_INLINE const SKU_FEATURE_TABLE& GMM_STDCALL GetSkuTable()
256         {
257             return (SkuTable);
258         }
259 
260         /////////////////////////////////////////////////////////////////////////
261         /// Returns the Wa table ptr
262         /// @return    WaTable ptr
263         /////////////////////////////////////////////////////////////////////////
GetWaTable()264         GMM_INLINE const WA_TABLE& GMM_STDCALL GetWaTable()
265         {
266             return (WaTable);
267         }
268 
269         /////////////////////////////////////////////////////////////////////////
270         /// Returns the GT system info ptr
271         /// @return   const GtSysInfo ptr
272         /////////////////////////////////////////////////////////////////////////
GetGtSysInfoPtr()273         GMM_INLINE const GT_SYSTEM_INFO* GMM_STDCALL GetGtSysInfoPtr()
274         {
275             return (&GtSysInfo);
276         }
277 
278         /////////////////////////////////////////////////////////////////////////
279         /// Returns the GT system info ptr
280         /// @return   GtSysInfo ptr
281         /////////////////////////////////////////////////////////////////////////
GetGtSysInfo()282         GMM_INLINE GT_SYSTEM_INFO* GMM_STDCALL GetGtSysInfo()
283         {
284             return (&GtSysInfo);
285         }
286 
287         /////////////////////////////////////////////////////////////////////////
288         /// Returns Cache policy element for a given usage type
289         /// @return   cache policy element
290         ////////////////////////////////////////////////////////////////////////
GetCachePolicyElement(GMM_RESOURCE_USAGE_TYPE Usage)291         GMM_INLINE GMM_CACHE_POLICY_ELEMENT GetCachePolicyElement(GMM_RESOURCE_USAGE_TYPE Usage)
292         {
293             return (CachePolicy[Usage]);
294         }
295 
296         /////////////////////////////////////////////////////////////////////////
297         /// Get padding percentage limit for 64kb pages
298         /////////////////////////////////////////////////////////////////////////
GetAllowedPaddingFor64KbPagesPercentage()299         uint32_t GetAllowedPaddingFor64KbPagesPercentage()
300         {
301             return (AllowedPaddingFor64KbPagesPercentage);
302         }
303 
GetInternalGpuVaRangeLimit()304         uint64_t& GetInternalGpuVaRangeLimit()
305         {
306             return InternalGpuVaMax;
307         }
308          /////////////////////////////////////////////////////////////////////////
309         /// Get padding  limit for 64k pages
310         /////////////////////////////////////////////////////////////////////////
GetAllowedPaddingFor64KBTileSurf()311         uint32_t GetAllowedPaddingFor64KBTileSurf()
312         {
313             return (AllowedPaddingFor64KBTileSurf);
314         }
315 
316         /////////////////////////////////////////////////////////////////////////
317         /// Set padding  limit for 64k pages
318         /////////////////////////////////////////////////////////////////////////
319 
SetAllowedPaddingFor64KBTileSurf(uint32_t Value)320         GMM_INLINE void SetAllowedPaddingFor64KBTileSurf(uint32_t Value)
321         {
322             AllowedPaddingFor64KBTileSurf = Value;
323         }
324 
325     #ifdef GMM_LIB_DLL
326         ADAPTER_BDF             sBdf;  // Adpater's Bus, Device and Function info for which Gmm UMD Lib process Singleton Context is created
327         #ifdef _WIN32
328             // ProcessHeapVA Singleton HeapObj
329             GMM_HEAP            *pHeapObj;
330             uint32_t            ProcessHeapCounter;
331             // ProcessVA Partition Address space
332             GMM_GFX_PARTITIONING ProcessVA;
333             uint32_t            ProcessVACounter;
334 
335             /////////////////////////////////////////////////////////////////////////
336             /// Get ProcessHeapVA Singleton HeapObj
337             /////////////////////////////////////////////////////////////////////////
338             GMM_HEAP* GetSharedHeapObject();
339 
340             /////////////////////////////////////////////////////////////////////////
341             /// Set ProcessHeapVA Singleton HeapObj
342             /////////////////////////////////////////////////////////////////////////
343             uint32_t SetSharedHeapObject(GMM_HEAP **pProcessHeapObj);
344 
345             /////////////////////////////////////////////////////////////////////////
346             /// Get or Sets ProcessGfxPartition VA
347             /////////////////////////////////////////////////////////////////////////
348             void GetProcessGfxPartition(GMM_GFX_PARTITIONING* pProcessVA);
349 
350             /////////////////////////////////////////////////////////////////////////
351             /// Get or Sets ProcessGfxPartition VA
352             /////////////////////////////////////////////////////////////////////////
353             void SetProcessGfxPartition(GMM_GFX_PARTITIONING* pProcessVA);
354 
355             /////////////////////////////////////////////////////////////////////////
356             /// Destroy Sync Mutex created for Singleton Context access
357             /////////////////////////////////////////////////////////////////////////
DestroySingletonContextSyncMutex()358             static void   DestroySingletonContextSyncMutex()
359             {
360                 if (SingletonContextSyncMutex)
361                 {
362                     ::CloseHandle(SingletonContextSyncMutex);
363                     SingletonContextSyncMutex = NULL;
364                 }
365             }
366             #if !GMM_LIB_DLL_MA
367             /////////////////////////////////////////////////////////////////////////
368             /// Acquire Sync Mutex for Singleton Context access
369             /////////////////////////////////////////////////////////////////////////
LockSingletonContextSyncMutex()370             static GMM_STATUS   LockSingletonContextSyncMutex()
371             {
372                 if (SingletonContextSyncMutex)
373                 {
374                     while (WAIT_OBJECT_0 != ::WaitForSingleObject(SingletonContextSyncMutex, INFINITE));
375                     return GMM_SUCCESS;
376                 }
377                 else
378                 {
379                     return GMM_ERROR;
380                 }
381             }
382 
383             /////////////////////////////////////////////////////////////////////////
384             /// Release Sync Mutex for Singleton Context access
385             /////////////////////////////////////////////////////////////////////////
UnlockSingletonContextSyncMutex()386             static GMM_STATUS   UnlockSingletonContextSyncMutex()
387             {
388                 if (SingletonContextSyncMutex)
389                 {
390                     ::ReleaseMutex(SingletonContextSyncMutex);
391                     return GMM_SUCCESS;
392                 }
393                 else
394                 {
395                     return GMM_ERROR;
396                 }
397             }
398             #endif //!GMM_LIB_DLL_MA
399 
400         #else // Non Win OS
401 
402             /////////////////////////////////////////////////////////////////////////
403             /// Destroy Sync Mutex created for Singleton Context access
404             /////////////////////////////////////////////////////////////////////////
DestroySingletonContextSyncMutex()405             static void   DestroySingletonContextSyncMutex()
406             {
407                 pthread_mutex_destroy(&SingletonContextSyncMutex);
408             }
409             #if !GMM_LIB_DLL_MA
410             /////////////////////////////////////////////////////////////////////////
411             /// Acquire Sync Mutex for Singleton Context access
412             /////////////////////////////////////////////////////////////////////////
LockSingletonContextSyncMutex()413             static GMM_STATUS   LockSingletonContextSyncMutex()
414             {
415                 pthread_mutex_lock(&SingletonContextSyncMutex);
416                 return GMM_SUCCESS;
417             }
418 
419             /////////////////////////////////////////////////////////////////////////
420             /// Release Sync Mutex for Singleton Context access
421             /////////////////////////////////////////////////////////////////////////
UnlockSingletonContextSyncMutex()422             static GMM_STATUS   UnlockSingletonContextSyncMutex()
423             {
424                 pthread_mutex_unlock(&SingletonContextSyncMutex);
425                 return GMM_SUCCESS;
426             }
427             #endif //!GMM_LIB_DLL_MA
428 
429         #endif // _WIN32
430 
431     #endif // GMM_LIB_DLL
432 
433         // KMD specific inline functions
434     #ifdef __GMM_KMD__
435 
436         /////////////////////////////////////////////////////////////////////////
437         /// Returns private PAT table memory type for a given PAT type
438         /// @return   PAT Memory type
439         /////////////////////////////////////////////////////////////////////////
GetPrivatePATTableMemoryType(GMM_GFX_PAT_TYPE PatType)440         GMM_INLINE int32_t  GMM_STDCALL GetPrivatePATTableMemoryType(GMM_GFX_PAT_TYPE PatType)
441         {
442             return (PrivatePATTableMemoryType[PatType]);
443         }
444 
445         /////////////////////////////////////////////////////////////////////////
446         /// Returns private PAT table memory type array ptr
447         /// @return   PAT Memory type array ptr
448         /////////////////////////////////////////////////////////////////////////
GetPrivatePATTableMemoryType()449         GMM_INLINE int32_t*  GMM_STDCALL GetPrivatePATTableMemoryType()
450         {
451             return (PrivatePATTableMemoryType);
452         }
453 
454 
455         /////////////////////////////////////////////////////////////////////////
456         /// Returns private PAT table array ptr
457         /// @return   PAT array ptr
458         /////////////////////////////////////////////////////////////////////////
GetPrivatePATTable()459         GMM_INLINE GMM_PRIVATE_PAT* GMM_STDCALL  GetPrivatePATTable()
460         {
461             return (PrivatePATTable);
462         }
463 
464         /////////////////////////////////////////////////////////////////////////
465         /// Returns private PAT table entry for a given PAT index
466         /// @return   PAT entry
467         /////////////////////////////////////////////////////////////////////////
GetPrivatePATEntry(uint32_t PatIndex)468         GMM_INLINE GMM_PRIVATE_PAT GMM_STDCALL  GetPrivatePATEntry(uint32_t  PatIndex)
469         {
470             return (PrivatePATTable[PatIndex]);
471         }
472 
473         /////////////////////////////////////////////////////////////////////////
474         /// Returns gmm kmd context ptr
475         /// @return   GmmKmdContext ptr
476         /////////////////////////////////////////////////////////////////////////
GetGmmKmdContext()477         GMM_INLINE GMM_CONTEXT* GetGmmKmdContext()
478         {
479             return (pGmmKmdContext);
480         }
481 
482         /////////////////////////////////////////////////////////////////////////
483         /// Sets gmm kmd context ptr
484         /// @return   GmmKmdContext ptr
485         /////////////////////////////////////////////////////////////////////////
SetGmmKmdContext(GMM_CONTEXT * pGmmKmdContext)486         GMM_INLINE void SetGmmKmdContext(GMM_CONTEXT *pGmmKmdContext)
487         {
488             this->pGmmKmdContext = pGmmKmdContext;
489         }
490 
491         /////////////////////////////////////////////////////////////////////////
492         /// Returns gtt context ptr
493         /// @return   GttContext ptr
494         /////////////////////////////////////////////////////////////////////////
GetGttContext()495         GMM_INLINE GMM_GTT_CONTEXT* GetGttContext()
496         {
497             return (&GttContext);
498         }
499 
500         /////////////////////////////////////////////////////////////////////////
501         /// Returns Cache policy tbl element for a given usage type
502         /// @return   cache policy tbl element
503         ////////////////////////////////////////////////////////////////////////
GetCachePolicyTblElement(GMM_RESOURCE_USAGE_TYPE Usage)504         GMM_INLINE GMM_CACHE_POLICY_TBL_ELEMENT GetCachePolicyTblElement(GMM_RESOURCE_USAGE_TYPE Usage)
505         {
506             return (CachePolicyTbl[Usage]);
507         }
508 
509         /////////////////////////////////////////////////////////////////////////
510         /// Resets  the sku Table after  GmmInitContext() could have changed them
511         /// since original latching
512         ////////////////////////////////////////////////////////////////////////
SetSkuTable(SKU_FEATURE_TABLE SkuTable)513         GMM_INLINE void SetSkuTable(SKU_FEATURE_TABLE SkuTable)
514         {
515             this->SkuTable = SkuTable;
516         }
517 
518         /////////////////////////////////////////////////////////////////////////
519         /// Resets  the Wa Table after  GmmInitContext() could have changed them
520         /// since original latching
521         ////////////////////////////////////////////////////////////////////////
SetWaTable(WA_TABLE WaTable)522         GMM_INLINE void SetWaTable(WA_TABLE WaTable)
523         {
524             this->WaTable = WaTable;
525         }
526 
527     #if(_DEBUG || _RELEASE_INTERNAL)
528 
529         /////////////////////////////////////////////////////////////////////////
530         /// Returns the override platform info class object ptr
531         /// @return   PlatformInfo class object ptr
532         /////////////////////////////////////////////////////////////////////////
GetOverridePlatformInfoObj()533         GMM_INLINE GMM_PLATFORM_INFO_CLASS* GMM_STDCALL GetOverridePlatformInfoObj()
534         {
535             return (Override.pPlatformInfo);
536         }
537 
538         /////////////////////////////////////////////////////////////////////////
539         /// Returns the override Platform info ptr to kmd
540         /// @return   override PlatformInfo ref
541         ////////////////////////////////////////////////////////////////////////
GetOverridePlatformInfo()542         GMM_INLINE GMM_PLATFORM_INFO& GMM_STDCALL GetOverridePlatformInfo()
543         {
544             return (const_cast<GMM_PLATFORM_INFO&>(Override.pPlatformInfo->GetData()));
545         }
546 
547         /////////////////////////////////////////////////////////////////////////
548         /// Set the override platform info calc ptr
549         ////////////////////////////////////////////////////////////////////////
SetOverridePlatformInfoObj(GMM_PLATFORM_INFO_CLASS * pPlatformInfoObj)550         GMM_INLINE void SetOverridePlatformInfoObj(GMM_PLATFORM_INFO_CLASS *pPlatformInfoObj)
551         {
552             Override.pPlatformInfo = pPlatformInfoObj;
553         }
554 
555         /////////////////////////////////////////////////////////////////////////
556         /// Returns the override Texture calc ptr to kmd
557         /// @return   override Texture calc ptr
558         ////////////////////////////////////////////////////////////////////////
GetOverrideTextureCalc()559         GMM_INLINE GMM_TEXTURE_CALC* GetOverrideTextureCalc()
560         {
561             return (Override.pTextureCalc);
562         }
563 
564         /////////////////////////////////////////////////////////////////////////
565         /// Set the override Texture calc ptr
566         ////////////////////////////////////////////////////////////////////////
SetOverrideTextureCalc(GMM_TEXTURE_CALC * pTextureCalc)567         GMM_INLINE void SetOverrideTextureCalc(GMM_TEXTURE_CALC *pTextureCalc)
568         {
569             Override.pTextureCalc = pTextureCalc;
570         }
571     #endif // (_DEBUG || _RELEASE_INTERNAL)
572 
573     #endif // __GMM_KMD__
574 
575     GMM_CACHE_POLICY* GMM_STDCALL CreateCachePolicyCommon();
576     GMM_TEXTURE_CALC* GMM_STDCALL CreateTextureCalc(PLATFORM Platform, bool Override);
577     GMM_PLATFORM_INFO_CLASS *GMM_STDCALL CreatePlatformInfo(PLATFORM Platform, bool Override);
578 
579     private:
580         void GMM_STDCALL OverrideSkuWa();
581 
582     public:
583     /////////////////////////////////////////////////////////////////////////
584     /// Returns private PAT table array ptr
585     /// @return   PAT array ptr
586     /////////////////////////////////////////////////////////////////////////
GetPrivatePATTable()587     GMM_INLINE GMM_PRIVATE_PAT *GMM_STDCALL GetPrivatePATTable()
588     {
589         return (&PrivatePATTable[0]);
590     }
591 
592     };
593 
594 // Max number of Multi-Adapters allowed in the system
595 #define MAX_NUM_ADAPTERS      9
596 //===========================================================================
597 // typedef:
598 //      _GMM_ADAPTER_INFO_
599 //
600 // Description:
601 //      Struct holds Adapter level information.
602 //----------------------------------------------------------------------------
603 typedef struct _GMM_ADAPTER_INFO_
604 {
605     Context             *pGmmLibContext;                    // Gmm UMD Lib Context which is process Singleton
606     _GMM_ADAPTER_INFO_  *pNext;                             // Linked List Next pointer to point to the Next Adapter node in the List
607 
608 }GMM_ADAPTER_INFO;
609 
610 ////////////////////////////////////////////////////////////////////////////////////
611 /// Multi Adpater Context to hold data related to Multiple Adapters in the system
612 /// Contains functions and members that are needed to support Multi-Adapter.
613 ///////////////////////////////////////////////////////////////////////////////////
614     class NON_PAGED_SECTION GmmMultiAdapterContext : public GmmMemAllocator
615     {
616     private:
617         GMM_ADAPTER_INFO                AdapterInfo[MAX_NUM_ADAPTERS];// For Static Initialization of adapter.
618         GMM_MUTEX_HANDLE                MAContextSyncMutex;         // SyncMutex to protect access of GmmMultiAdpaterContext
619         uint32_t                        NumAdapters;
620 	void*                           pCpuReserveBase;
621 	uint64_t                        CpuReserveSize;
622         GMM_ADAPTER_INFO                *pHeadNode;// For dynamic Initialization of adapter.
623                                                    // The Multi-Adapter Initialization is done dynamiclly using a Linked list Vector
624                                                    // pHeadNode points to the root node of the linked list and registers the first
625                                                    // adapter received from UMD.
626         // thread safe functions; these cannot be called within a LockMAContextSyncMutex block
627         GMM_ADAPTER_INFO *              GetAdapterNode(ADAPTER_BDF sBdf);   // Replacement for GetAdapterIndex, now get adapter node from the linked list
628 
629         // Mutexes which protect the below thread unsafe functions
630         GMM_STATUS GMM_STDCALL          LockMAContextSyncMutex();
631         GMM_STATUS GMM_STDCALL          UnLockMAContextSyncMutex();
632 
633         // thread unsafe functions; these must be protected with LockMAContextSyncMutex
634         GMM_ADAPTER_INFO *              GetAdapterNodeUnlocked(ADAPTER_BDF sBdf);
635         GMM_ADAPTER_INFO *              AddAdapterNode();
636         void                            RemoveAdapterNode(GMM_ADAPTER_INFO *pNode);
637 
638     public:
639         //Constructors and destructors
640         GmmMultiAdapterContext();
641         ~GmmMultiAdapterContext();
642         /* Function prototypes */
643         /* Functions that update MultiAdapterContext members*/
644         uint32_t GMM_STDCALL            GetAdapterIndex(ADAPTER_BDF sBdf);
645         uint32_t GMM_STDCALL            GetNumAdapters();
646         /* Functions that update AdapterInfo*/
647         // thread safe functions; these cannot be called within a LockMAContextSyncMutex block
648 #if LHDM
649         GMM_STATUS GMM_STDCALL          AddContext(const PLATFORM           Platform,
650                                                    const SKU_FEATURE_TABLE *pSkuTable,
651                                                    const WA_TABLE *         pWaTable,
652                                                    const GT_SYSTEM_INFO *   pGtSysInfo,
653                                                    ADAPTER_BDF              sBdf,
654                                                    const char *             DeviceRegistryPath);
655 #else
656         GMM_STATUS GMM_STDCALL          AddContext(const PLATFORM Platform,
657                                                    const void *   pSkuTable,
658                                                    const void *   pWaTable,
659                                                    const void *   pGtSysInfo,
660                                                    ADAPTER_BDF    sBdf,
661 						   const GMM_CLIENT ClientType);
662 #endif
663         GMM_STATUS GMM_STDCALL          RemoveContext(ADAPTER_BDF sBdf);
664         Context* GMM_STDCALL            GetAdapterLibContext(ADAPTER_BDF sBdf);
665     }; // GmmMultiAdapterContext
666 
667 } //namespace
668 
669 typedef GmmLib::Context GMM_GLOBAL_CONTEXT, GMM_LIB_CONTEXT;
670 typedef GmmLib::GmmMultiAdapterContext GMM_MA_LIB_CONTEXT;
671 
672 #else
673 struct GmmLibContext;
674 typedef struct GmmLibContext GMM_GLOBAL_CONTEXT, GMM_LIB_CONTEXT;
675 #endif
676 
677 
678 #ifdef __GMM_KMD__
679 void GMM_STDCALL GmmLinkKmdContextToGlobalInfo(GMM_GLOBAL_CONTEXT *pGmmLibContext, GMM_CONTEXT *pGmmKmdContext);
680 #endif /*__GMM_KMD__*/
681 
682 //Declare all  GMM global context C interfaces.
683 #ifdef __cplusplus
684 extern "C" {
685 #endif /*__cplusplus*/
686 
687     const GMM_PLATFORM_INFO* GMM_STDCALL GmmGetPlatformInfo(GMM_GLOBAL_CONTEXT *pGmmLibContext);
688     const GMM_CACHE_POLICY_ELEMENT* GmmGetCachePolicyUsage(GMM_GLOBAL_CONTEXT *pGmmLibContext);
689           GMM_TEXTURE_CALC*         GmmGetTextureCalc(GMM_GLOBAL_CONTEXT *pGmmLibContext);
690     const SKU_FEATURE_TABLE*        GmmGetSkuTable(GMM_GLOBAL_CONTEXT *pGmmLibContext);
691     const WA_TABLE*                 GmmGetWaTable(GMM_GLOBAL_CONTEXT *pGmmLibContext);
692     const GT_SYSTEM_INFO*           GmmGetGtSysInfo(GMM_GLOBAL_CONTEXT *pGmmLibContext);
693 
694 #ifdef __GMM_KMD__
695     int32_t             GmmGetPrivatePATTableMemoryType(GMM_GLOBAL_CONTEXT *pGmmLibContext, GMM_GFX_PAT_TYPE PatType);
696     GMM_CONTEXT*        GmmGetGmmKmdContext(GMM_GLOBAL_CONTEXT *pGmmLibContext);
697     GMM_GTT_CONTEXT*    GmmGetGttContext(GMM_GLOBAL_CONTEXT *pGmmLibContext);
698     GMM_CACHE_POLICY_TBL_ELEMENT GmmGetCachePolicyTblElement(GMM_GLOBAL_CONTEXT *pGmmLibContext, GMM_RESOURCE_USAGE_TYPE Usage);
699     GMM_CACHE_POLICY_ELEMENT GmmGetCachePolicyElement(GMM_GLOBAL_CONTEXT *pGmmLibContext, GMM_RESOURCE_USAGE_TYPE Usage);
700     void                GmmSetSkuTable(GMM_GLOBAL_CONTEXT *pGmmLibContext, SKU_FEATURE_TABLE SkuTable);
701     void                GmmSetWaTable(GMM_GLOBAL_CONTEXT *pGmmLibContext, WA_TABLE WaTable);
702     GMM_PLATFORM_INFO*  GmmKmdGetPlatformInfo(GMM_GLOBAL_CONTEXT *pGmmLibContext);
703 #if(_DEBUG || _RELEASE_INTERNAL)
704     const GMM_PLATFORM_INFO* GmmGetOverridePlatformInfo(GMM_GLOBAL_CONTEXT *pGmmLibContext);
705     GMM_TEXTURE_CALC*   GmmGetOverrideTextureCalc(GMM_GLOBAL_CONTEXT *pGmmLibContext);
706 #endif
707 
708 #endif
709     GMM_PRIVATE_PAT GmmGetPrivatePATEntry(GMM_LIB_CONTEXT *pGmmLibContext, uint32_t PatIndex);
710 
711 #ifdef __cplusplus
712 }
713 #endif /*__cplusplus*/
714 
715     #define GMM_OVERRIDE_PLATFORM_INFO(pTexInfo,pGmmLibContext)    (GmmGetPlatformInfo(pGmmLibContext))
716     #define GMM_OVERRIDE_TEXTURE_CALC(pTexInfo,pGmmLibContext)     (GmmGetTextureCalc(pGmmLibContext))
717 
718 #ifdef __GMM_KMD__
719     #define GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(pTexInfo)    GMM_OVERRIDE_PLATFORM_INFO(pTexInfo)
720     #define GMM_IS_PLANAR(Format)                            GmmIsPlanar(Format)
721 #else
722     #define GMM_OVERRIDE_EXPORTED_PLATFORM_INFO(pTexInfo,pGmmLibContext)    (&((GmmClientContext*)pClientContext)->GetPlatformInfo())
723     #define GMM_IS_PLANAR(Format)                            (pClientContext->IsPlanar(Format))
724 #endif
725 
726 #define GMM_IS_1MB_AUX_TILEALIGNEDPLANES(Platform, Surf) \
727     ((GFX_GET_CURRENT_PRODUCT(Platform) >= IGFX_METEORLAKE) && Surf.OffsetInfo.PlaneXe_LPG.Is1MBAuxTAlignedPlanes)
728 
729 // Reset packing alignment to project default
730 #pragma pack(pop)
731