Skip to content

Commit 8b16874

Browse files
Add function for retrieving offset to mmap buffer object
Related-To: NEO-6276 Signed-off-by: Milczarek, Slawomir <[email protected]>
1 parent e097511 commit 8b16874

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

shared/source/os_interface/linux/drm_memory_manager_local_memory_dg1.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@
1717
#include "shared/source/os_interface/linux/memory_info_impl.h"
1818

1919
namespace NEO {
20+
21+
bool retrieveMmapOffsetForBufferObject(Drm &drm, BufferObject &bo, uint64_t flags, uint64_t &offset) {
22+
drm_i915_gem_mmap_offset mmapOffset = {};
23+
mmapOffset.handle = bo.peekHandle();
24+
mmapOffset.flags = flags;
25+
26+
auto ret = drm.ioctl(DRM_IOCTL_I915_GEM_MMAP_OFFSET, &mmapOffset);
27+
if (ret != 0) {
28+
int err = drm.getErrno();
29+
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(DRM_IOCTL_I915_GEM_MMAP_OFFSET) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
30+
DEBUG_BREAK_IF(ret != 0);
31+
return false;
32+
}
33+
34+
offset = mmapOffset.offset;
35+
return true;
36+
}
37+
2038
GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const AllocationData &allocationData) {
2139
return nullptr;
2240
}
@@ -63,17 +81,13 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData &
6381
return nullptr;
6482
}
6583

66-
drm_i915_gem_mmap_offset gemMmap{};
67-
gemMmap.handle = bo->peekHandle();
68-
gemMmap.flags = I915_MMAP_OFFSET_WB;
69-
70-
auto ret = this->getDrm(allocationData.rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_MMAP_OFFSET, &gemMmap);
71-
if (ret != 0) {
72-
this->munmapFunction(cpuBasePointer, totalSizeToAlloc);
84+
uint64_t offset = 0;
85+
if (!retrieveMmapOffsetForBufferObject(this->getDrm(allocationData.rootDeviceIndex), *bo, I915_MMAP_OFFSET_WB, offset)) {
86+
this->munmapFunction(cpuPointer, size);
7387
return nullptr;
7488
}
7589

76-
[[maybe_unused]] auto retPtr = this->mmapFunction(cpuPointer, alignedSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, getDrm(allocationData.rootDeviceIndex).getFileDescriptor(), static_cast<off_t>(gemMmap.offset));
90+
[[maybe_unused]] auto retPtr = this->mmapFunction(cpuPointer, alignedSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, getDrm(allocationData.rootDeviceIndex).getFileDescriptor(), static_cast<off_t>(offset));
7791
DEBUG_BREAK_IF(retPtr != cpuPointer);
7892

7993
obtainGpuAddress(allocationData, bo.get(), gpuAddress);
@@ -127,16 +141,14 @@ void *DrmMemoryManager::lockResourceInLocalMemoryImpl(BufferObject *bo) {
127141
if (bo == nullptr)
128142
return nullptr;
129143

130-
drm_i915_gem_mmap_offset mmapOffset = {};
131-
mmapOffset.handle = bo->peekHandle();
132-
mmapOffset.flags = I915_MMAP_OFFSET_WC;
133144
auto rootDeviceIndex = this->getRootDeviceIndex(bo->drm);
134145

135-
if (getDrm(rootDeviceIndex).ioctl(DRM_IOCTL_I915_GEM_MMAP_OFFSET, &mmapOffset) != 0) {
146+
uint64_t offset = 0;
147+
if (!retrieveMmapOffsetForBufferObject(this->getDrm(rootDeviceIndex), *bo, I915_MMAP_OFFSET_WC, offset)) {
136148
return nullptr;
137149
}
138150

139-
auto addr = mmapFunction(nullptr, bo->peekSize(), PROT_WRITE | PROT_READ, MAP_SHARED, getDrm(rootDeviceIndex).getFileDescriptor(), static_cast<off_t>(mmapOffset.offset));
151+
auto addr = mmapFunction(nullptr, bo->peekSize(), PROT_WRITE | PROT_READ, MAP_SHARED, getDrm(rootDeviceIndex).getFileDescriptor(), static_cast<off_t>(offset));
140152
DEBUG_BREAK_IF(addr == MAP_FAILED);
141153

142154
bo->setLockedAddress(addr);

0 commit comments

Comments
 (0)