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 "GmmCommonULT.h"
24 #ifndef _WIN32
25 #include <dlfcn.h>
26 #endif
27
28
29 ADAPTER_INFO * CommonULT::pGfxAdapterInfo = NULL;
30 PLATFORM CommonULT::GfxPlatform = {};
31 GMM_CLIENT_CONTEXT *CommonULT::pGmmULTClientContext = NULL;
32 PFNGMMINIT CommonULT::pfnGmmInit = {0};
33 PFNGMMDESTROY CommonULT::pfnGmmDestroy = {0};
34 #ifdef _WIN32
35 HINSTANCE CommonULT::hGmmLib = NULL;
36 #else
37 void *CommonULT::hGmmLib = NULL;
38 #endif
39
AllocateAdapterInfo()40 void CommonULT::AllocateAdapterInfo()
41 {
42 if(!pGfxAdapterInfo)
43 {
44 pGfxAdapterInfo = (ADAPTER_INFO *)malloc(sizeof(ADAPTER_INFO));
45 if(!pGfxAdapterInfo)
46 {
47 ASSERT_TRUE(false);
48 return;
49 }
50 memset(pGfxAdapterInfo, 0, sizeof(ADAPTER_INFO));
51
52 pGfxAdapterInfo->SkuTable.FtrTileY = 1;
53 pGfxAdapterInfo->WaTable.WaAuxTable64KGranular = 1; // 64K aux granularity
54 }
55 }
56
SetUpTestCase()57 void CommonULT::SetUpTestCase()
58 {
59 printf("%s\n", __FUNCTION__);
60
61 GMM_INIT_IN_ARGS InArgs;
62 GMM_INIT_OUT_ARGS OutArgs;
63
64
65 if(GfxPlatform.eProductFamily == IGFX_UNKNOWN ||
66 GfxPlatform.eRenderCoreFamily == IGFX_UNKNOWN_CORE)
67 {
68 GfxPlatform.eProductFamily = IGFX_BROADWELL;
69 GfxPlatform.eRenderCoreFamily = IGFX_GEN8_CORE;
70 }
71
72 AllocateAdapterInfo();
73
74 InArgs.ClientType = GMM_EXCITE_VISTA;
75 InArgs.pGtSysInfo = &pGfxAdapterInfo->SystemInfo;
76 InArgs.pSkuTable = &pGfxAdapterInfo->SkuTable;
77 InArgs.pWaTable = &pGfxAdapterInfo->WaTable;
78 InArgs.Platform = GfxPlatform;
79 #ifdef _WIN32
80 InArgs.stAdapterBDF = {0, 2, 0, 0};
81 #else
82 InArgs.FileDescriptor = 512; // Initializing BDF to {0,2,0,0} which corresponds to decimal 512 for AdapterBDF.Data
83 #endif
84
85 hGmmLib = dlopen(GMM_UMD_DLL, RTLD_LAZY);
86 ASSERT_TRUE(hGmmLib);
87
88 *(void **)(&pfnGmmInit) = dlsym(hGmmLib, "InitializeGmm");
89 *(void **)(&pfnGmmDestroy) = dlsym(hGmmLib, "GmmAdapterDestroy");
90
91 ASSERT_TRUE(pfnGmmInit);
92 ASSERT_TRUE(pfnGmmDestroy);
93
94 pfnGmmInit(&InArgs, &OutArgs);
95 pGmmULTClientContext = OutArgs.pGmmClientContext;
96
97 ASSERT_TRUE(pGmmULTClientContext);
98 }
99
TearDownTestCase()100 void CommonULT::TearDownTestCase()
101 {
102 printf("%s\n", __FUNCTION__);
103
104 GMM_INIT_OUT_ARGS OutArgs;
105 OutArgs.pGmmClientContext = static_cast<GMM_CLIENT_CONTEXT *>(pGmmULTClientContext);
106
107 pfnGmmDestroy(&OutArgs);
108
109 if(hGmmLib)
110 {
111 dlclose(hGmmLib);
112 }
113
114 hGmmLib = NULL;
115 pGmmULTClientContext = NULL;
116 free(pGfxAdapterInfo);
117 pGfxAdapterInfo = NULL;
118 GfxPlatform = {};
119 }
120