Call ioctl to obtain file handle from prime bo

Related-To: NEO-3252

Change-Id: I8d976ae29875db83dd75802e0309cb4438d1332b
Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal
2019-06-06 16:26:47 +02:00
parent ee2a66cef8
commit 5244030e31
11 changed files with 65 additions and 8 deletions

View File

@@ -100,6 +100,7 @@ DECLARE_DEBUG_VARIABLE(bool, EnableExtendedVaFormats, false, "Enable more format
DECLARE_DEBUG_VARIABLE(bool, AddClGlSharing, false, "Add cl-gl extension")
DECLARE_DEBUG_VARIABLE(bool, EnablePassInlineData, false, "Enable passing of inline data")
DECLARE_DEBUG_VARIABLE(bool, EnableFormatQuery, false, "Enable sharing format querying")
DECLARE_DEBUG_VARIABLE(bool, AllowOpenFdOperations, false, "When enabled driver is allowed to call DRM_IOCTL_PRIME_HANDLE_TO_FD.")
DECLARE_DEBUG_VARIABLE(bool, EnableBlitterOperationsForReadWriteBuffers, false, "Use Blitter engine for Read/Write Buffers operations")
DECLARE_DEBUG_VARIABLE(int32_t, EnableCacheFlushAfterWalker, 0, "-1: platform behavior, 0: disabled, 1: enabled. Adds dedicated cache flush command after WALKER command when surfaces used by kernel require to flush the cache")
DECLARE_DEBUG_VARIABLE(int32_t, EnableLocalMemory, -1, "-1: default behavior, 0: disabled, 1: enabled, Allows allocating graphics memory in Local Memory")

View File

@@ -8,6 +8,7 @@
#include "runtime/os_interface/linux/drm_allocation.h"
#include "runtime/os_interface/linux/drm_buffer_object.h"
#include "runtime/os_interface/linux/drm_memory_manager.h"
#include <sstream>
@@ -20,5 +21,12 @@ std::string DrmAllocation::getAllocationInfoString() const {
return ss.str();
}
uint64_t DrmAllocation::peekInternalHandle() { return static_cast<uint64_t>(getBO()->peekHandle()); }
uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) {
auto drmMemoryManager = static_cast<DrmMemoryManager *>(memoryManager);
if (DebugManager.flags.AllowOpenFdOperations.get()) {
return static_cast<uint64_t>(drmMemoryManager->obtainFdFromHandle(getBO()->peekHandle()));
} else {
return 0llu;
}
}
} // namespace NEO

View File

@@ -35,7 +35,7 @@ class DrmAllocation : public GraphicsAllocation {
}
return this->bo;
}
uint64_t peekInternalHandle() override;
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
protected:
BufferObject *bo;

View File

@@ -768,4 +768,14 @@ void *DrmMemoryManager::reserveCpuAddressRange(size_t size) {
void DrmMemoryManager::releaseReservedCpuAddressRange(void *reserved, size_t size) {
munmapFunction(reserved, size);
}
int DrmMemoryManager::obtainFdFromHandle(int boHandle) {
drm_prime_handle openFd = {0, 0, 0};
openFd.flags = DRM_CLOEXEC | DRM_RDWR;
openFd.handle = boHandle;
drm->ioctl(DRM_IOCTL_PRIME_HANDLE_TO_FD, &openFd);
return openFd.fd;
}
} // namespace NEO

View File

@@ -57,6 +57,8 @@ class DrmMemoryManager : public MemoryManager {
void *reserveCpuAddressRange(size_t size) override;
void releaseReservedCpuAddressRange(void *reserved, size_t size) override;
int obtainFdFromHandle(int boHandle);
protected:
BufferObject *findAndReferenceSharedBufferObject(int boHandle);
BufferObject *createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness);