xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/inc/External/Common/GmmClientContext.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 
23 #pragma once
24 #include "GmmCommonExt.h"
25 #include "GmmInfo.h"
26 
27 //////////////////////////////////////////////////////////////////
28 // Memory Allocators and DeAllocators for Gmm Create Objects
29 // This is needed for Clients who want to construct using their
30 // own memory allocators
31 //////////////////////////////////////////////////////////////////
32 typedef void* (GMM_STDCALL *PFN_ClientAllocationFunction)(
33     void*                                       pUserData,
34     uint32_t                                    size,
35     uint32_t                                    alignment);
36 
37 typedef void (GMM_STDCALL *PFN_ClientFreeFunction)(
38     void*                                       pUserData,
39     void*                                       pMemory);
40 
41 typedef struct _GmmClientAllocationCallbacks_
42 {
43     void*                                   pUserData;
44     uint32_t                                size;
45     uint32_t                                alignment;
46     PFN_ClientAllocationFunction            pfnAllocation;
47     PFN_ClientFreeFunction                  pfnFree;
48 } GmmClientAllocationCallbacks;
49 
50 //===========================================================================
51 // typedef:
52 //      GMM_DEVICE_OPERATION
53 //
54 // Description:
55 //     Decribes compoents required for device operations.
56 //---------------------------------------------- ------------------------------
57 typedef struct _GMM_DEVICE_INFO_REC
58 {
59     GMM_DEVICE_CALLBACKS_INT     *pDeviceCb;
60 }GMM_DEVICE_INFO;
61 
62 #ifdef __cplusplus
63 #include "GmmMemAllocator.hpp"
64 
65 /////////////////////////////////////////////////////////////////////////////////////
66 /// @file GmmClientContext.h
67 /// @brief This file contains the functions and members of GmmClientContext that is
68 ///       common for both Linux and Windows.
69 ///
70 /////////////////////////////////////////////////////////////////////////////////////
71 namespace GmmLib
72 {
73     /////////////////////////////////////////////////////////////////////////
74     /// Contains functions and members that are common between Linux and
75     /// Windows implementation.  This class members will hold data that
76     /// are specific to each client.
77     /////////////////////////////////////////////////////////////////////////
78     class Context;
79     class GMM_LIB_API NON_PAGED_SECTION GmmClientContext : public GmmMemAllocator
80     {
81     protected:
82         GMM_CLIENT                       ClientType;
83         ///< Placeholders for storing UMD context. Actual UMD context that needs to be stored here is
84         void                             *pUmdAdapter;
85         GMM_UMD_CONTEXT                  *pGmmUmdContext;
86         GMM_DEVICE_CALLBACKS_INT          DeviceCB;       //OS-specific defn: Will be used by Clients to send as input arguments.
87         // Flag to indicate Device_callbacks received.
88         uint8_t             IsDeviceCbReceived;
89         Context *pGmmLibContext;
90 
91     public:
92         /* Constructor */
93         GmmClientContext(GMM_CLIENT ClientType);
94         GmmClientContext(GMM_CLIENT ClientType, Context* pLibContext);
95 
96         /* Virtual destructor */
97         virtual ~GmmClientContext();
98 
99         /* Inline functions */
100         /////////////////////////////////////////////////////////////////////////////////////
101         /// Returns the GMM_CLIENT Type that has created this ClientContext.
102         /// @return     GMM_CLIENT
103         /////////////////////////////////////////////////////////////////////////////////////
GetClientType()104         GMM_INLINE_VIRTUAL GMM_INLINE_EXPORTED GMM_CLIENT GMM_STDCALL  GetClientType()
105         {
106             return (ClientType);
107         }
108 
GetLibContext()109 	GMM_INLINE_VIRTUAL GMM_LIB_CONTEXT *GetLibContext()
110         {
111             return pGmmLibContext;
112         }
113 
114         /* Function prototypes */
115         /* CachePolicy Related Exported Functions from GMM Lib */
116         GMM_VIRTUAL MEMORY_OBJECT_CONTROL_STATE         GMM_STDCALL CachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage);
117         GMM_VIRTUAL GMM_PTE_CACHE_CONTROL_BITS          GMM_STDCALL CachePolicyGetPteType(GMM_RESOURCE_USAGE_TYPE Usage);
118         GMM_VIRTUAL MEMORY_OBJECT_CONTROL_STATE         GMM_STDCALL CachePolicyGetOriginalMemoryObject(GMM_RESOURCE_INFO *pResInfo);
119         GMM_VIRTUAL uint8_t                             GMM_STDCALL CachePolicyIsUsagePTECached(GMM_RESOURCE_USAGE_TYPE Usage);
120         GMM_VIRTUAL uint8_t                             GMM_STDCALL GetSurfaceStateL1CachePolicy(GMM_RESOURCE_USAGE_TYPE Usage);
121 	GMM_VIRTUAL uint32_t                            GMM_STDCALL CachePolicyGetMaxMocsIndex();
122         GMM_VIRTUAL uint32_t                            GMM_STDCALL CachePolicyGetMaxL1HdcMocsIndex();
123         GMM_VIRTUAL uint32_t                            GMM_STDCALL CachePolicyGetMaxSpecialMocsIndex();
124         GMM_VIRTUAL GMM_CACHE_POLICY_ELEMENT*           GMM_STDCALL GetCachePolicyUsage();
125         GMM_VIRTUAL void                                GMM_STDCALL GetCacheSizes(GMM_CACHE_SIZES *pCacheSizes);
126         GMM_VIRTUAL GMM_CACHE_POLICY_ELEMENT            GMM_STDCALL GetCachePolicyElement(GMM_RESOURCE_USAGE_TYPE Usage);
127         GMM_VIRTUAL GMM_CACHE_POLICY_TBL_ELEMENT        GMM_STDCALL GetCachePolicyTlbElement(uint32_t  MocsIdx);
128         GMM_VIRTUAL GMM_PLATFORM_INFO&                  GMM_STDCALL GetPlatformInfo();
129         GMM_VIRTUAL const SKU_FEATURE_TABLE&            GMM_STDCALL GetSkuTable();
130         GMM_VIRTUAL void                                GMM_STDCALL GetExtendedTextureAlign(uint32_t Mode, ALIGNMENT &UnitAlign);
131 
132         GMM_VIRTUAL uint8_t                             GMM_STDCALL IsPlanar(GMM_RESOURCE_FORMAT Format);
133         GMM_VIRTUAL uint8_t                             GMM_STDCALL IsP0xx(GMM_RESOURCE_FORMAT Format);
134         GMM_VIRTUAL uint8_t                             GMM_STDCALL IsUVPacked(GMM_RESOURCE_FORMAT Format);
135         GMM_VIRTUAL uint8_t                             GMM_STDCALL IsCompressed(GMM_RESOURCE_FORMAT Format);
136         GMM_VIRTUAL uint8_t                             GMM_STDCALL IsYUVPacked(GMM_RESOURCE_FORMAT Format);
137         GMM_VIRTUAL GMM_SURFACESTATE_FORMAT             GMM_STDCALL GetSurfaceStateFormat(GMM_RESOURCE_FORMAT Format);
138         GMM_VIRTUAL uint8_t                             GMM_STDCALL GetSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT Format);
139         GMM_VIRTUAL uint8_t                             GMM_STDCALL GetMediaSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT Format);
140         GMM_VIRTUAL GMM_E2ECOMP_FORMAT                  GMM_STDCALL GetLosslessCompressionType(GMM_RESOURCE_FORMAT Format);
141         GMM_VIRTUAL uint64_t                            GMM_STDCALL GetInternalGpuVaRangeLimit();
142 
143         /* ResourceInfo Creation and Destroy API's */
144         GMM_VIRTUAL GMM_RESOURCE_INFO* GMM_STDCALL       CreateResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams);
145         GMM_VIRTUAL GMM_RESOURCE_INFO* GMM_STDCALL       CopyResInfoObject(GMM_RESOURCE_INFO *pSrcRes);
146         GMM_VIRTUAL void GMM_STDCALL                     ResMemcpy(void *pDst, void *pSrc);
147         GMM_VIRTUAL void  GMM_STDCALL                    DestroyResInfoObject(GMM_RESOURCE_INFO    *pResInfo);
148         /* PageTableMgr Creation and Destroy API's */
149         GMM_VIRTUAL GMM_PAGETABLE_MGR* GMM_STDCALL      CreatePageTblMgrObject(GMM_DEVICE_CALLBACKS_INT* pDevCb, uint32_t TTFlags);
150         GMM_VIRTUAL GMM_PAGETABLE_MGR* GMM_STDCALL      CreatePageTblMgrObject(uint32_t TTFlags);
151         /* PageTableMgr Creation and Destroy API's */
152         GMM_VIRTUAL void GMM_STDCALL                    DestroyPageTblMgrObject(GMM_PAGETABLE_MGR* pPageTableMgr);
153 
154 
155 #ifdef GMM_LIB_DLL
156         /* ResourceInfo and PageTableMgr Create and Destroy APIs with Client provided Memory Allocators */
157         GMM_VIRTUAL GMM_RESOURCE_INFO* GMM_STDCALL       CreateResInfoObject(GMM_RESCREATE_PARAMS *pCreateParams,
158                                                                              GmmClientAllocationCallbacks *pAllocCbs);
159         GMM_VIRTUAL void  GMM_STDCALL                    DestroyResInfoObject(GMM_RESOURCE_INFO    *pResInfo,
160                                                                               GmmClientAllocationCallbacks *pAllocCbs);
161 #endif
162 
163         GMM_VIRTUAL GMM_PAGETABLE_MGR* GMM_STDCALL      CreatePageTblMgrObject(
164                                                         GMM_DEVICE_CALLBACKS_INT* pDevCb,
165                                                         uint32_t TTFlags,
166                                                         GmmClientAllocationCallbacks* pAllocCbs);
167         GMM_VIRTUAL GMM_PAGETABLE_MGR* GMM_STDCALL      CreatePageTblMgrObject(
168                                                         uint32_t TTFlags,
169                                                         GmmClientAllocationCallbacks* pAllocCbs);
170         GMM_VIRTUAL void GMM_STDCALL                    DestroyPageTblMgrObject(GMM_PAGETABLE_MGR* pPageTableMgr,
171                                                         GmmClientAllocationCallbacks* pAllocCbs);
172         GMM_VIRTUAL GMM_STATUS GMM_STDCALL              GmmSetDeviceInfo(GMM_DEVICE_INFO* DeviceInfo);
173         GMM_VIRTUAL GMM_RESOURCE_INFO* GMM_STDCALL      CreateCustomResInfoObject(GMM_RESCREATE_CUSTOM_PARAMS* pCreateParams);
174 
175 #ifndef __GMM_KMD__
176         GMM_VIRTUAL GMM_RESOURCE_INFO *GMM_STDCALL      CreateCustomResInfoObject_2(GMM_RESCREATE_CUSTOM_PARAMS_2 *pCreateParams);
177 #endif
178 	GMM_VIRTUAL uint32_t GMM_STDCALL CachePolicyGetPATIndex(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE Usage, bool *pCompressionEnable, bool IsCpuCacheable);
179         GMM_VIRTUAL const SWIZZLE_DESCRIPTOR *GMM_STDCALL GetSwizzleDesc(EXTERNAL_SWIZZLE_NAME ExternalSwizzleName, EXTERNAL_RES_TYPE ResType, uint8_t bpe, bool isStdSwizzle = false);
180     };
181 }
182 
183 typedef GmmLib::GmmClientContext    GMM_CLIENT_CONTEXT;
184 
185 #else
186 struct GmmClientContext;
187 typedef struct GmmClientContext GMM_CLIENT_CONTEXT;
188 
189 #endif
190 
191 
192 
193 #ifdef __cplusplus
194 extern "C" {
195 #endif
196 
197     /* ClientContext will be unique to each client */
198     GMM_CLIENT_CONTEXT* GMM_STDCALL GmmCreateClientContextForAdapter(GMM_CLIENT ClientType, ADAPTER_BDF sBdf);
199     void GMM_STDCALL GmmDeleteClientContext(GMM_CLIENT_CONTEXT *pGmmClientContext);
200 
201 #if GMM_LIB_DLL
202 #ifdef _WIN32
203 
204     GMM_STATUS GMM_STDCALL GmmCreateLibContext(const PLATFORM           Platform,
205                                                const SKU_FEATURE_TABLE *pSkuTable,
206                                                const WA_TABLE *         pWaTable,
207                                                const GT_SYSTEM_INFO *   pGtSysInfo,
208                                                ADAPTER_BDF              sBdf);
209 #else
210 
211     GMM_STATUS GMM_STDCALL GmmCreateLibContext(const PLATFORM Platform,
212                                                const void *   pSkuTable,
213                                                const void *   pWaTable,
214                                                const void *   pGtSysInfo,
215                                                ADAPTER_BDF    sBdf,
216                                                const GMM_CLIENT ClientType);
217 #endif
218 
219     void GMM_STDCALL GmmLibContextFree(ADAPTER_BDF sBdf);
220     GMM_LIB_API_CONSTRUCTOR void GmmCreateMultiAdapterContext();
221     GMM_LIB_API_DESTRUCTOR void GmmDestroyMultiAdapterContext();
222 
223 #endif //GMM_LIB_DLL
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229