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 #if defined (__linux__) && !defined(__i386__)
24
25 #include "GmmAuxTableULT.h"
26
27 using namespace std;
28 using namespace GmmLib;
29
30 static GMM_DEVICE_CALLBACKS_INT DeviceCBInt;
31
CTestAuxTable()32 CTestAuxTable::CTestAuxTable()
33 {
34 }
35
~CTestAuxTable()36 CTestAuxTable::~CTestAuxTable()
37 {
38 }
39
allocCB(void * bufMgr,size_t size,size_t alignment,void ** bo,void ** cpuAddr,uint64_t * gpuAddr)40 int CTestAuxTable::allocCB(void *bufMgr, size_t size, size_t alignment, void **bo, void **cpuAddr, uint64_t *gpuAddr)
41 {
42 if(bufMgr != (void *)0xdeadbeef)
43 return -1;
44
45 if(!bo || !cpuAddr || !gpuAddr)
46 return -2;
47
48 *cpuAddr = aligned_alloc(alignment, ALIGN(size, alignment));
49 if(!*cpuAddr)
50 return -3;
51
52 *bo = *cpuAddr;
53 *gpuAddr = (uint64_t)*cpuAddr;
54
55 return 0;
56 }
57
freeCB(void * bo)58 void CTestAuxTable::freeCB(void *bo)
59 {
60 ASSERT_TRUE(bo != NULL);
61
62 free(bo);
63 }
64
waitFromCpuCB(void * bo)65 void CTestAuxTable::waitFromCpuCB(void *bo)
66 {
67 }
68
SetUpTestCase()69 void CTestAuxTable::SetUpTestCase()
70 {
71 GfxPlatform.eProductFamily = IGFX_TIGERLAKE_LP;
72 GfxPlatform.eRenderCoreFamily = IGFX_GEN12_CORE;
73
74 DeviceCBInt.pBufMgr = (void *)0xdeadbeef;
75 DeviceCBInt.DevCbPtrs_.pfnAllocate = CTestAuxTable::allocCB;
76 DeviceCBInt.DevCbPtrs_.pfnDeallocate = CTestAuxTable::freeCB;
77 DeviceCBInt.DevCbPtrs_.pfnWaitFromCpu = CTestAuxTable::waitFromCpuCB;
78
79 if(GfxPlatform.eProductFamily == IGFX_UNKNOWN ||
80 GfxPlatform.eRenderCoreFamily == IGFX_UNKNOWN_CORE)
81 {
82 GfxPlatform.eProductFamily = IGFX_BROADWELL;
83 GfxPlatform.eRenderCoreFamily = IGFX_GEN8_CORE;
84 }
85
86 AllocateAdapterInfo();
87 if(pGfxAdapterInfo)
88 {
89 pGfxAdapterInfo->SkuTable.FtrE2ECompression = true;
90 pGfxAdapterInfo->SkuTable.FtrLinearCCS = true;
91 }
92
93 CommonULT::SetUpTestCase();
94 }
95
TearDownTestCase()96 void CTestAuxTable::TearDownTestCase()
97 {
98 CommonULT::TearDownTestCase();
99 }
100
TEST_F(CTestAuxTable,TestUpdateAuxTableCompressedSurface)101 TEST_F(CTestAuxTable, TestUpdateAuxTableCompressedSurface)
102 {
103 GmmPageTableMgr *mgr = pGmmULTClientContext->CreatePageTblMgrObject(&DeviceCBInt, TT_TYPE::AUXTT);
104
105 ASSERT_TRUE(mgr != NULL);
106
107 Surface *surf = new Surface(7680, 4320);
108
109 ASSERT_TRUE(surf != NULL && surf->init());
110
111 GMM_DDI_UPDATEAUXTABLE updateReq = {0};
112
113 updateReq.BaseResInfo = surf->getGMMResourceInfo();
114 updateReq.BaseGpuVA = surf->getGfxAddress(GMM_PLANE_Y);
115 updateReq.Map = 1;
116
117 GMM_STATUS res = mgr->UpdateAuxTable(&updateReq);
118 ASSERT_TRUE(res == GMM_SUCCESS);
119
120 delete surf;
121 pGmmULTClientContext->DestroyPageTblMgrObject(mgr);
122 }
123
TEST_F(CTestAuxTable,DISABLED_TestUpdateAuxTableNonCompressedSurface)124 TEST_F(CTestAuxTable, DISABLED_TestUpdateAuxTableNonCompressedSurface)
125 {
126 GmmPageTableMgr *mgr = pGmmULTClientContext->CreatePageTblMgrObject(&DeviceCBInt, TT_TYPE::AUXTT);
127
128 ASSERT_TRUE(mgr != NULL);
129
130 Surface *surf = new Surface(7680, 4320, false);
131
132 ASSERT_TRUE(surf != NULL && surf->init());
133
134 GMM_DDI_UPDATEAUXTABLE updateReq = {0};
135
136 memset(&updateReq, 0, sizeof(GMM_DDI_UPDATEAUXTABLE));
137
138 updateReq.BaseResInfo = surf->getGMMResourceInfo();
139 updateReq.BaseGpuVA = surf->getGfxAddress(GMM_PLANE_Y);
140 updateReq.Map = 1;
141
142 GMM_STATUS res = mgr->UpdateAuxTable(&updateReq);
143 ASSERT_TRUE(res != GMM_SUCCESS);
144
145 delete surf;
146 pGmmULTClientContext->DestroyPageTblMgrObject(mgr);
147 }
148
TEST_F(CTestAuxTable,TestInvalidateAuxTable)149 TEST_F(CTestAuxTable, TestInvalidateAuxTable)
150 {
151 GmmPageTableMgr *mgr = pGmmULTClientContext->CreatePageTblMgrObject(&DeviceCBInt, TT_TYPE::AUXTT);
152
153 ASSERT_TRUE(mgr != NULL);
154
155 Surface *surf = new Surface(7680, 4320);
156
157 ASSERT_TRUE(surf != NULL && surf->init());
158
159 GMM_DDI_UPDATEAUXTABLE updateReq = {0};
160
161 updateReq.BaseResInfo = surf->getGMMResourceInfo();
162 updateReq.BaseGpuVA = surf->getGfxAddress(GMM_PLANE_Y);
163 updateReq.Map = 1;
164
165 GMM_STATUS res = mgr->UpdateAuxTable(&updateReq);
166 ASSERT_TRUE(res == GMM_SUCCESS);
167
168 memset(&updateReq, 0, sizeof(updateReq));
169
170 updateReq.BaseResInfo = surf->getGMMResourceInfo();
171 updateReq.Map = 0;
172
173 res = mgr->UpdateAuxTable(&updateReq);
174 ASSERT_TRUE(res == GMM_SUCCESS);
175
176 delete surf;
177 pGmmULTClientContext->DestroyPageTblMgrObject(mgr);
178 }
179
TEST_F(CTestAuxTable,DISABLED_TestUpdateAuxTableStress)180 TEST_F(CTestAuxTable, DISABLED_TestUpdateAuxTableStress)
181 {
182 const int num_surf = 1000;
183 Surface * surfaces[num_surf];
184 Surface * surf;
185 int i;
186
187 GmmPageTableMgr *mgr = pGmmULTClientContext->CreatePageTblMgrObject(&DeviceCBInt, TT_TYPE::AUXTT);
188
189 ASSERT_TRUE(mgr != NULL);
190
191 for(i = 0; i < num_surf; i++)
192 {
193 surf = new Surface(7680, 4320);
194 surfaces[i] = surf;
195
196 ASSERT_TRUE(surf != NULL && surf->init());
197
198 GMM_DDI_UPDATEAUXTABLE updateReq = {0};
199
200 updateReq.BaseResInfo = surf->getGMMResourceInfo();
201 updateReq.BaseGpuVA = surf->getGfxAddress(GMM_PLANE_Y);
202 updateReq.Map = 1;
203
204 mgr->UpdateAuxTable(&updateReq);
205 }
206
207 for(i = 0; i < num_surf; i++)
208 {
209 surf = surfaces[i];
210 delete surf;
211 }
212
213 pGmmULTClientContext->DestroyPageTblMgrObject(mgr);
214 }
215
TEST_F(CTestAuxTable,TestAuxTableContent)216 TEST_F(CTestAuxTable, TestAuxTableContent)
217 {
218 GmmPageTableMgr *mgr = pGmmULTClientContext->CreatePageTblMgrObject(&DeviceCBInt, TT_TYPE::AUXTT);
219
220 ASSERT_TRUE(mgr != NULL);
221
222 Surface *surf = new Surface(720, 480);
223
224 ASSERT_TRUE(surf != NULL && surf->init());
225
226 GMM_DDI_UPDATEAUXTABLE updateReq = {0};
227
228 updateReq.BaseResInfo = surf->getGMMResourceInfo();
229 updateReq.BaseGpuVA = surf->getGfxAddress(GMM_PLANE_Y);
230 updateReq.Map = 1;
231
232 GMM_STATUS res = mgr->UpdateAuxTable(&updateReq);
233 ASSERT_TRUE(res == GMM_SUCCESS);
234
235 Walker *ywalker = new Walker(surf->getGfxAddress(GMM_PLANE_Y),
236 surf->getAuxGfxAddress(GMM_AUX_CCS),
237 mgr->GetAuxL3TableAddr());
238
239 for(size_t i = 0; i < surf->getSurfaceSize(GMM_PLANE_Y); i++)
240 {
241 GMM_GFX_ADDRESS addr = surf->getGfxAddress(GMM_PLANE_Y) + i;
242 GMM_GFX_ADDRESS val = ywalker->walk(addr);
243 GMM_GFX_ADDRESS expected = ywalker->expected(addr);
244 ASSERT_EQ(expected, val);
245 }
246
247 Walker *uvwalker = new Walker(surf->getGfxAddress(GMM_PLANE_U),
248 surf->getAuxGfxAddress(GMM_AUX_UV_CCS),
249 mgr->GetAuxL3TableAddr());
250
251 for(size_t i = 0; i < surf->getSurfaceSize(GMM_PLANE_U); i++)
252 {
253 GMM_GFX_ADDRESS addr = surf->getGfxAddress(GMM_PLANE_U) + i;
254 GMM_GFX_ADDRESS val = uvwalker->walk(addr);
255 GMM_GFX_ADDRESS expected = uvwalker->expected(addr);
256 ASSERT_EQ(expected, val);
257 }
258
259 delete uvwalker;
260 delete ywalker;
261 delete surf;
262 pGmmULTClientContext->DestroyPageTblMgrObject(mgr);
263 }
264
265 #endif /* __linux__ */
266