|
17 | 17 | #include "shared/source/os_interface/linux/memory_info_impl.h" |
18 | 18 |
|
19 | 19 | 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 | + |
20 | 38 | GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const AllocationData &allocationData) { |
21 | 39 | return nullptr; |
22 | 40 | } |
@@ -63,17 +81,13 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData & |
63 | 81 | return nullptr; |
64 | 82 | } |
65 | 83 |
|
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); |
73 | 87 | return nullptr; |
74 | 88 | } |
75 | 89 |
|
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)); |
77 | 91 | DEBUG_BREAK_IF(retPtr != cpuPointer); |
78 | 92 |
|
79 | 93 | obtainGpuAddress(allocationData, bo.get(), gpuAddress); |
@@ -127,16 +141,14 @@ void *DrmMemoryManager::lockResourceInLocalMemoryImpl(BufferObject *bo) { |
127 | 141 | if (bo == nullptr) |
128 | 142 | return nullptr; |
129 | 143 |
|
130 | | - drm_i915_gem_mmap_offset mmapOffset = {}; |
131 | | - mmapOffset.handle = bo->peekHandle(); |
132 | | - mmapOffset.flags = I915_MMAP_OFFSET_WC; |
133 | 144 | auto rootDeviceIndex = this->getRootDeviceIndex(bo->drm); |
134 | 145 |
|
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)) { |
136 | 148 | return nullptr; |
137 | 149 | } |
138 | 150 |
|
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)); |
140 | 152 | DEBUG_BREAK_IF(addr == MAP_FAILED); |
141 | 153 |
|
142 | 154 | bo->setLockedAddress(addr); |
|
0 commit comments