Create wrappers for drm_i915_gem_create and drm_i915_gem_userptr

Related-To: NEO-6852
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-05-16 13:05:56 +00:00
committed by Compute-Runtime-Automation
parent 4266f861ac
commit 06517f429f
6 changed files with 34 additions and 12 deletions

View File

@@ -241,9 +241,9 @@ bool DrmMemoryManager::setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_
}
NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex) {
drm_i915_gem_userptr userptr = {};
userptr.user_ptr = address;
userptr.user_size = size;
GemUserPtr userptr = {};
userptr.userPtr = address;
userptr.userSize = size;
userptr.flags = static_cast<uint32_t>(flags);
auto &drm = this->getDrm(rootDeviceIndex);
@@ -514,7 +514,7 @@ GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &
size_t bufferSize = allocationData.size;
uint64_t gpuRange = acquireGpuRange(bufferSize, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD64KB);
drm_i915_gem_create create = {0, 0, 0};
GemCreate create{};
create.size = bufferSize;
auto &drm = getDrm(allocationData.rootDeviceIndex);
@@ -547,7 +547,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
uint64_t gpuRange = acquireGpuRange(allocationData.imgInfo->size, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD);
drm_i915_gem_create create = {0, 0, 0};
GemCreate create{};
create.size = allocationData.imgInfo->size;
auto &drm = this->getDrm(allocationData.rootDeviceIndex);

View File

@@ -18,6 +18,16 @@ uint32_t IoctlHelper::ioctl(Drm *drm, unsigned long request, void *arg) {
return drm->ioctl(request, arg);
}
static_assert(sizeof(GemCreate) == sizeof(drm_i915_gem_create));
static_assert(offsetof(GemCreate, size) == offsetof(drm_i915_gem_create, size));
static_assert(offsetof(GemCreate, handle) == offsetof(drm_i915_gem_create, handle));
static_assert(sizeof(GemUserPtr) == sizeof(drm_i915_gem_userptr));
static_assert(offsetof(GemUserPtr, userPtr) == offsetof(drm_i915_gem_userptr, user_ptr));
static_assert(offsetof(GemUserPtr, userSize) == offsetof(drm_i915_gem_userptr, user_size));
static_assert(offsetof(GemUserPtr, flags) == offsetof(drm_i915_gem_userptr, flags));
static_assert(offsetof(GemUserPtr, handle) == offsetof(drm_i915_gem_userptr, handle));
static_assert(sizeof(RegisterRead) == sizeof(drm_i915_reg_read));
static_assert(offsetof(RegisterRead, offset) == offsetof(drm_i915_reg_read, offset));
static_assert(offsetof(RegisterRead, value) == offsetof(drm_i915_reg_read, val));

View File

@@ -87,6 +87,18 @@ struct ExecBuffer {
uint8_t data[64];
};
struct GemCreate {
uint64_t size;
uint32_t handle;
};
struct GemUserPtr {
uint64_t userPtr;
uint64_t userSize;
uint32_t flags;
uint32_t handle;
};
class IoctlHelper {
public:
virtual ~IoctlHelper() {}

View File

@@ -166,14 +166,14 @@ int DrmMock::ioctl(unsigned long request, void *arg) {
}
if (request == DRM_IOCTL_I915_GEM_USERPTR) {
ioctlCount.gemUserptr++;
auto userPtrParams = static_cast<drm_i915_gem_userptr *>(arg);
auto userPtrParams = static_cast<NEO::GemUserPtr *>(arg);
userPtrParams->handle = returnHandle;
returnHandle++;
return 0;
}
if (request == DRM_IOCTL_I915_GEM_CREATE) {
ioctlCount.gemCreate++;
auto createParams = static_cast<drm_i915_gem_create *>(arg);
auto createParams = static_cast<NEO::GemCreate *>(arg);
this->createParamsSize = createParams->size;
this->createParamsHandle = createParams->handle = 1u;
if (0 == this->createParamsSize) {

View File

@@ -78,14 +78,14 @@ int DrmMockCustom::ioctl(unsigned long request, void *arg) {
} break;
case DRM_IOCTL_I915_GEM_USERPTR: {
auto *userPtrParams = (drm_i915_gem_userptr *)arg;
auto *userPtrParams = static_cast<NEO::GemUserPtr *>(arg);
userPtrParams->handle = returnHandle;
returnHandle++;
ioctl_cnt.gemUserptr++;
} break;
case DRM_IOCTL_I915_GEM_CREATE: {
auto *createParams = (drm_i915_gem_create *)arg;
auto *createParams = static_cast<NEO::GemCreate *>(arg);
this->createParamsSize = createParams->size;
this->createParamsHandle = createParams->handle = 1u;
ioctl_cnt.gemCreate++;

View File

@@ -56,9 +56,9 @@ class DrmTipMock : public DrmMock {
}
return 0;
} else if (request == DRM_IOCTL_I915_GEM_MMAP_OFFSET) {
auto mmap_arg = static_cast<drm_i915_gem_mmap_offset *>(arg);
mmapOffsetFlagsReceived = mmap_arg->flags;
mmap_arg->offset = offset;
auto mmapArg = static_cast<drm_i915_gem_mmap_offset *>(arg);
mmapOffsetFlagsReceived = mmapArg->flags;
mmapArg->offset = offset;
return mmapOffsetRetVal;
}
return handleKernelSpecificRequests(request, arg);