xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/Resource/Linux/GmmResourceInfoLinCWrapper.cpp (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2019 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 
25 #if defined(__linux__) && !LHDM
26 #include "Internal/Linux/GmmResourceInfoLinInt.h"
27 
28 /////////////////////////////////////////////////////////////////////////////////////
29 /// This is an overloaded function to call DeviceCb Function for CreateAllocation
30 ///
31 /// @param[in]  ClientType
32 /// @param[in]  pDeviceCb: Pointer to GMM_DEVICE_CALLBACKS_INT Struct
33 /// @param[in]  pAllocate: Pointer to GMM_DDI_ALLOCATE Union
34 /// @return     Status of CreateAllocation call.
35 /////////////////////////////////////////////////////////////////////////////////////
GmmDeviceCallback(GMM_CLIENT ClientType,GMM_DEVICE_CALLBACKS_INT * pDeviceCb,GMM_DDI_ALLOCATE * pAllocate)36 int GmmDeviceCallback(GMM_CLIENT ClientType, GMM_DEVICE_CALLBACKS_INT *pDeviceCb, GMM_DDI_ALLOCATE *pAllocate)
37 {
38     int      Status   = 0;
39     void *   pBo      = NULL;
40     void *   pCpuAddr = NULL;
41     uint64_t gpuAddr  = 0ULL;
42 
43     Status = pDeviceCb->DevCbPtrs_.pfnAllocate(pDeviceCb->pBufMgr,
44                                                pAllocate->size,
45                                                pAllocate->alignment,
46                                                &pBo,
47                                                &pCpuAddr,
48                                                &gpuAddr);
49     pAllocate->bo      = pBo;
50     pAllocate->cpuAddr = pCpuAddr;
51     pAllocate->gfxAddr = gpuAddr;
52 
53     return Status;
54 }
55 
56 /////////////////////////////////////////////////////////////////////////////////////
57 /// This is an overloaded function to call DeviceCb Function for DestroyAllocation
58 ///
59 /// @param[in]  ClientType
60 /// @param[in]  pDeviceCb: Pointer to GMM_DEVICE_CALLBACKS_INT Struct
61 /// @param[in]  pAllocate: Pointer to GMM_DDI_DEALLOCATE Union
62 /// @return     Status of DestroyAllocation call.
63 /////////////////////////////////////////////////////////////////////////////////////
GmmDeviceCallback(GMM_CLIENT ClientType,GMM_DEVICE_CALLBACKS_INT * pDeviceCb,GMM_DDI_DEALLOCATE * pDeallocate)64 int GmmDeviceCallback(GMM_CLIENT ClientType, GMM_DEVICE_CALLBACKS_INT *pDeviceCb, GMM_DDI_DEALLOCATE *pDeallocate)
65 {
66     int Status = 0;
67 
68     pDeviceCb->DevCbPtrs_.pfnDeallocate(pDeallocate->bo);
69 
70     return Status;
71 }
72 
73 /////////////////////////////////////////////////////////////////////////////////////
74 /// This is an overloaded function to call DeviceCb Function for WaitForSyncObjFromCpu
75 ///
76 /// @param[in]  ClientType
77 /// @param[in]  pDeviceCb: Pointer to GMM_DEVICE_CALLBACKS_INT Struct
78 /// @param[in]  pAllocate: Pointer to GMM_DDI_WAITFORSYNCHRONIZATIONOBJECTFROMCPU Union
79 /// @return     Status of WaitForSyncObjFromCpu call.
80 /////////////////////////////////////////////////////////////////////////////////////
GmmDeviceCallback(GMM_CLIENT ClientType,GMM_DEVICE_CALLBACKS_INT * pDeviceCb,GMM_DDI_WAITFORSYNCHRONIZATIONOBJECTFROMCPU * pWait)81 int GmmDeviceCallback(GMM_CLIENT ClientType, GMM_DEVICE_CALLBACKS_INT *pDeviceCb, GMM_DDI_WAITFORSYNCHRONIZATIONOBJECTFROMCPU *pWait)
82 {
83     int Status = 0;
84 
85     pDeviceCb->DevCbPtrs_.pfnWaitFromCpu(pWait->bo);
86 
87     return Status;
88 }
89 
90 /////////////////////////////////////////////////////////////////////////////////////
91 /// This function checks for Null DeviceCb Function pointer
92 ///
93 /// @param[in]  ClientType
94 /// @param[in]  pDeviceCb: Pointer to GMM_DEVICE_CALLBACKS_INT Struct
95 /// @param[in]  CallBackType Enum @GMM_DEVICE_CALLBACKS_TYPE
96 /// @return     True if not Null.
97 /////////////////////////////////////////////////////////////////////////////////////
GmmCheckForNullDevCbPfn(GMM_CLIENT ClientType,GMM_DEVICE_CALLBACKS_INT * pDeviceCb,GMM_DEVICE_CALLBACKS_TYPE CallBackType)98 int GmmCheckForNullDevCbPfn(GMM_CLIENT ClientType, GMM_DEVICE_CALLBACKS_INT *pDeviceCb, GMM_DEVICE_CALLBACKS_TYPE CallBackType)
99 {
100     int Status = 0;
101 
102     switch(CallBackType)
103     {
104         case GMM_DEV_CB_ALLOC:
105             Status = (pDeviceCb->DevCbPtrs_.pfnAllocate != 0);
106             break;
107         case GMM_DEV_CB_DEALLOC:
108             Status = (pDeviceCb->DevCbPtrs_.pfnDeallocate != 0);
109             break;
110         case GMM_DEV_CB_WAIT_FROM_CPU:
111             Status = (pDeviceCb->DevCbPtrs_.pfnWaitFromCpu != 0);
112             break;
113         default:
114             Status = 0;
115             break;
116     }
117 
118     return Status;
119 }
120 
121 // Dummy Translation Table Callback for reusing ..
DummyPrologTranslationTable(void * pDeviceHandle)122 static inline int DummyPrologTranslationTable(void *pDeviceHandle)
123 {
124     return 0;
125 }
126 
DummyWriteL1Entries(void * pDeviceHandle,const uint32_t NumEntries,GMM_GFX_ADDRESS GfxAddress,uint32_t * Data)127 static inline int DummyWriteL1Entries(void *          pDeviceHandle,
128                                       const uint32_t  NumEntries,
129                                       GMM_GFX_ADDRESS GfxAddress,
130                                       uint32_t *      Data)
131 {
132     return 0;
133 }
134 
DummyWriteL2L3Entry(void * pDeviceHandle,GMM_GFX_ADDRESS GfxAddress,uint64_t Data)135 static inline int DummyWriteL2L3Entry(void *          pDeviceHandle,
136                                       GMM_GFX_ADDRESS GfxAddress,
137                                       uint64_t        Data)
138 {
139     return 0;
140 }
141 
DummyWriteFenceID(void * pDeviceHandle,GMM_GFX_ADDRESS GfxAddress,uint64_t Data)142 static inline int DummyWriteFenceID(void *          pDeviceHandle,
143                                     GMM_GFX_ADDRESS GfxAddress,
144                                     uint64_t        Data)
145 {
146     return 0;
147 }
148 
DummyEpilogTranslationTable(void * pDeviceHandle,uint8_t ForceFlush)149 static inline int DummyEpilogTranslationTable(void *  pDeviceHandle,
150                                               uint8_t ForceFlush)
151 {
152     return 0;
153 }
154 
DummyCopyL1Entry(void * pDeviceHandle,GMM_GFX_ADDRESS DstGfxAddress,GMM_GFX_ADDRESS SrcGfxAddress)155 static inline int DummyCopyL1Entry(void *          pDeviceHandle,
156                                    GMM_GFX_ADDRESS DstGfxAddress,
157                                    GMM_GFX_ADDRESS SrcGfxAddress)
158 {
159     return 0;
160 }
161 
DummyWriteL3Adr(void * pDeviceHandle,GMM_GFX_ADDRESS L3GfxAddress,uint64_t RegOffset)162 static inline int DummyWriteL3Adr(void *          pDeviceHandle,
163                                   GMM_GFX_ADDRESS L3GfxAddress,
164                                   uint64_t        RegOffset)
165 {
166     return 0;
167 }
168 
169 GMM_TRANSLATIONTABLE_CALLBACKS DummyTTCB = {
170 .pfPrologTranslationTable = DummyPrologTranslationTable,
171 .pfWriteL1Entries         = DummyWriteL1Entries,
172 .pfWriteL2L3Entry         = DummyWriteL2L3Entry,
173 .pfWriteFenceID           = DummyWriteFenceID,
174 .pfEpilogTranslationTable = DummyEpilogTranslationTable,
175 .pfCopyL1Entry            = DummyCopyL1Entry,
176 .pfWriteL3Adr             = DummyWriteL3Adr,
177 };
178 
179 #endif /*__linux__*/
180