Skip to content

Commit 854a77d

Browse files
Move code from drm_query to drm_neo
Move methods to drm_neo.cpp and hide kernel-specific implementations to IoctlHelper Related-To: NEO-6510 Signed-off-by: Szymon Morek <[email protected]>
1 parent d707a41 commit 854a77d

File tree

6 files changed

+95
-19
lines changed

6 files changed

+95
-19
lines changed

opencl/test/unit_test/os_interface/linux/ioctl_helper_tests_prelim.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,26 @@ TEST(IoctlHelperTestsPrelim, givenPrelimsAndInvalidIoctlReturnValWhenClosAllocWa
172172
EXPECT_EQ(0u, numWays);
173173
EXPECT_EQ(1u, drm->ioctlCallsCount);
174174
}
175+
176+
TEST(IoctlHelperTestsPrelim, givenPrelimsWhenWaitUserFenceThenCorrectValueReturned) {
177+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
178+
executionEnvironment->prepareRootDeviceEnvironments(1);
179+
auto drm = std::make_unique<DrmPrelimMock>(*executionEnvironment->rootDeviceEnvironments[0]);
180+
181+
uint64_t gpuAddress = 0x1020304000ull;
182+
uint64_t value = 0x98765ull;
183+
auto ioctlHelper = IoctlHelper::get(drm.get());
184+
for (uint32_t i = 0u; i < 4; i++) {
185+
auto ret = ioctlHelper->waitUserFence(drm.get(), 10u, gpuAddress, value, i, -1, 0u);
186+
EXPECT_EQ(0, ret);
187+
}
188+
}
189+
190+
TEST(IoctlHelperTestsPrelim, givenPrelimsWhenGetHwConfigIoctlValThenCorrectValueReturned) {
191+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
192+
executionEnvironment->prepareRootDeviceEnvironments(1);
193+
auto drm = std::make_unique<DrmPrelimMock>(*executionEnvironment->rootDeviceEnvironments[0]);
194+
195+
uint32_t ioctlVal = (1 << 16) | 6;
196+
EXPECT_EQ(ioctlVal, IoctlHelper::get(drm.get())->getHwConfigIoctlVal());
197+
}

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "shared/source/os_interface/linux/drm_gem_close_worker.h"
2020
#include "shared/source/os_interface/linux/drm_memory_manager.h"
2121
#include "shared/source/os_interface/linux/hw_device_id.h"
22+
#include "shared/source/os_interface/linux/ioctl_helper.h"
2223
#include "shared/source/os_interface/linux/os_context_linux.h"
2324
#include "shared/source/os_interface/linux/os_inc.h"
2425
#include "shared/source/os_interface/linux/pci_path.h"
@@ -909,4 +910,22 @@ void Drm::getPrelimVersion(std::string &prelimVersion) {
909910
ifs.close();
910911
}
911912

913+
int Drm::waitUserFence(uint32_t ctxId, uint64_t address, uint64_t value, ValueWidth dataWidth, int64_t timeout, uint16_t flags) {
914+
return IoctlHelper::get(this)->waitUserFence(this, ctxId, address, value, static_cast<uint32_t>(dataWidth), timeout, flags);
915+
}
916+
917+
bool Drm::querySystemInfo() {
918+
auto length = 0;
919+
auto request = IoctlHelper::get(this)->getHwConfigIoctlVal();
920+
auto deviceBlobQuery = this->query(request, DrmQueryItemFlags::empty, length);
921+
auto deviceBlob = reinterpret_cast<uint32_t *>(deviceBlobQuery.get());
922+
if (!deviceBlob) {
923+
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stdout, "%s", "INFO: System Info query failed!\n");
924+
return false;
925+
}
926+
this->systemInfo.reset(new SystemInfo(deviceBlob, length));
927+
928+
return true;
929+
}
930+
912931
} // namespace NEO

shared/source/os_interface/linux/drm_query.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,6 @@ bool Drm::isDebugAttachAvailable() {
107107
return false;
108108
}
109109

110-
bool Drm::querySystemInfo() {
111-
auto length = 0;
112-
113-
auto deviceBlobQuery = this->query(DRM_I915_QUERY_HWCONFIG_TABLE, DrmQueryItemFlags::empty, length);
114-
auto deviceBlob = reinterpret_cast<uint32_t *>(deviceBlobQuery.get());
115-
if (!deviceBlob) {
116-
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stdout, "%s", "INFO: System Info query failed!\n");
117-
return false;
118-
}
119-
this->systemInfo.reset(new SystemInfo(deviceBlob, length));
120-
121-
return true;
122-
}
123-
124110
void Drm::setupCacheInfo(const HardwareInfo &hwInfo) {
125111
this->cacheInfo.reset(new CacheInfoImpl());
126112
}
@@ -136,10 +122,6 @@ int Drm::unbindBufferObject(OsContext *osContext, uint32_t vmHandleId, BufferObj
136122
void Drm::waitForBind(uint32_t vmHandleId) {
137123
}
138124

139-
int Drm::waitUserFence(uint32_t ctx, uint64_t address, uint64_t value, ValueWidth dataWidth, int64_t timeout, uint16_t flags) {
140-
return 0;
141-
}
142-
143125
bool Drm::isVmBindAvailable() {
144126
return this->bindAvailable;
145127
}

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class IoctlHelper {
3030
virtual CacheRegion closAlloc(Drm *drm) = 0;
3131
virtual uint16_t closAllocWays(Drm *drm, CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) = 0;
3232
virtual CacheRegion closFree(Drm *drm, CacheRegion closIndex) = 0;
33+
virtual int waitUserFence(Drm *drm, uint32_t ctxId, uint64_t address,
34+
uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) = 0;
35+
virtual uint32_t getHwConfigIoctlVal() = 0;
3336
};
3437

3538
class IoctlHelperUpstream : public IoctlHelper {
@@ -39,6 +42,9 @@ class IoctlHelperUpstream : public IoctlHelper {
3942
CacheRegion closAlloc(Drm *drm) override;
4043
uint16_t closAllocWays(Drm *drm, CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) override;
4144
CacheRegion closFree(Drm *drm, CacheRegion closIndex) override;
45+
int waitUserFence(Drm *drm, uint32_t ctxId, uint64_t address,
46+
uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) override;
47+
uint32_t getHwConfigIoctlVal() override;
4248
};
4349

4450
template <PRODUCT_FAMILY gfxProduct>
@@ -59,6 +65,9 @@ class IoctlHelperPrelim20 : public IoctlHelper {
5965
CacheRegion closAlloc(Drm *drm) override;
6066
uint16_t closAllocWays(Drm *drm, CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) override;
6167
CacheRegion closFree(Drm *drm, CacheRegion closIndex) override;
68+
int waitUserFence(Drm *drm, uint32_t ctxId, uint64_t address,
69+
uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) override;
70+
uint32_t getHwConfigIoctlVal() override;
6271
};
6372

6473
} // namespace NEO

shared/source/os_interface/linux/ioctl_helper_prelim.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,38 @@ CacheRegion IoctlHelperPrelim20::closFree(Drm *drm, CacheRegion closIndex) {
101101
return closIndex;
102102
}
103103

104+
int IoctlHelperPrelim20::waitUserFence(Drm *drm, uint32_t ctxId, uint64_t address,
105+
uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) {
106+
prelim_drm_i915_gem_wait_user_fence wait = {};
107+
108+
wait.ctx_id = ctxId;
109+
wait.flags = flags;
110+
111+
switch (dataWidth) {
112+
case 3u:
113+
wait.mask = PRELIM_I915_UFENCE_WAIT_U64;
114+
break;
115+
case 2u:
116+
wait.mask = PRELIM_I915_UFENCE_WAIT_U32;
117+
break;
118+
case 1u:
119+
wait.mask = PRELIM_I915_UFENCE_WAIT_U16;
120+
break;
121+
default:
122+
wait.mask = PRELIM_I915_UFENCE_WAIT_U8;
123+
break;
124+
}
125+
126+
wait.op = PRELIM_I915_UFENCE_WAIT_GTE;
127+
wait.addr = address;
128+
wait.value = value;
129+
wait.timeout = timeout;
130+
131+
return IoctlHelper::ioctl(drm, PRELIM_DRM_IOCTL_I915_GEM_WAIT_USER_FENCE, &wait);
132+
}
133+
134+
uint32_t IoctlHelperPrelim20::getHwConfigIoctlVal() {
135+
return PRELIM_DRM_I915_QUERY_HWCONFIG_TABLE;
136+
}
137+
104138
} // namespace NEO

shared/source/os_interface/linux/ioctl_helper_upstream.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace NEO {
1515

1616
uint32_t IoctlHelperUpstream::createGemExt(Drm *drm, void *data, uint32_t dataSize, size_t allocSize, uint32_t &handle) {
17-
drm_i915_gem_create_ext_memory_regions memRegions;
17+
drm_i915_gem_create_ext_memory_regions memRegions{};
1818
memRegions.num_regions = dataSize;
1919
memRegions.regions = reinterpret_cast<uintptr_t>(data);
2020
memRegions.base.name = I915_GEM_CREATE_EXT_MEMORY_REGIONS;
@@ -58,4 +58,13 @@ CacheRegion IoctlHelperUpstream::closFree(Drm *drm, CacheRegion closIndex) {
5858
return CacheRegion::None;
5959
}
6060

61+
int IoctlHelperUpstream::waitUserFence(Drm *drm, uint32_t ctxId, uint64_t address,
62+
uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags) {
63+
return 0;
64+
}
65+
66+
uint32_t IoctlHelperUpstream::getHwConfigIoctlVal() {
67+
return DRM_I915_QUERY_HWCONFIG_TABLE;
68+
}
69+
6170
} // namespace NEO

0 commit comments

Comments
 (0)