Not using it yet, that will be done in the next patch.
Xe only supports submission using VM.
For i915 the backend functions are just a noop.
Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21698>
const VkDeviceCreateInfo *pCreateInfo,
const uint32_t num_queues)
{
- switch (anv_kmd_type_get(device)) {
+ switch (device->info->kmd_type) {
case INTEL_KMD_TYPE_I915:
return anv_i915_device_setup_context(device, pCreateInfo, num_queues);
case INTEL_KMD_TYPE_XE:
static bool
anv_device_destroy_context_or_vm(struct anv_device *device)
{
- switch (anv_kmd_type_get(device)) {
+ switch (device->info->kmd_type) {
case INTEL_KMD_TYPE_I915:
return intel_gem_destroy_context(device->fd, device->context_id);
case INTEL_KMD_TYPE_XE:
unreachable("Unused");
}
+static int
+stub_gem_vm_bind(struct anv_device *device, struct anv_bo *bo)
+{
+ return 0;
+}
+
+static int
+stub_gem_vm_unbind(struct anv_device *device, struct anv_bo *bo)
+{
+ return 0;
+}
+
const struct anv_kmd_backend *anv_stub_kmd_backend_get(void)
{
static const struct anv_kmd_backend stub_backend = {
.gem_create = stub_gem_create,
.gem_close = stub_gem_close,
.gem_mmap = stub_gem_mmap,
+ .gem_vm_bind = stub_gem_vm_bind,
+ .gem_vm_unbind = stub_gem_vm_unbind,
.execute_simple_batch = stub_execute_simple_batch,
.queue_exec_locked = stub_queue_exec_locked,
};
return NULL;
}
}
-
-inline enum intel_kmd_type
-anv_kmd_type_get(struct anv_device *device)
-{
- return device->info->kmd_type;
-}
void *(*gem_mmap)(struct anv_device *device, struct anv_bo *bo,
uint64_t offset, uint64_t size,
VkMemoryPropertyFlags property_flags);
+ int (*gem_vm_bind)(struct anv_device *device, struct anv_bo *bo);
+ int (*gem_vm_unbind)(struct anv_device *device, struct anv_bo *bo);
VkResult (*execute_simple_batch)(struct anv_queue *queue,
struct anv_bo *batch_bo,
uint32_t batch_bo_size);
const struct anv_kmd_backend *anv_kmd_backend_get(enum intel_kmd_type type);
-enum intel_kmd_type
-anv_kmd_type_get(struct anv_device *device);
-
/* Internal functions, should only be called by anv_kmd_backend_get() */
const struct anv_kmd_backend *anv_i915_kmd_backend_get(void);
const struct anv_kmd_backend *anv_xe_kmd_backend_get(void);
return i915_gem_mmap_legacy(device, bo, offset, size, flags);
}
+static int
+i915_gem_vm_bind(struct anv_device *device, struct anv_bo *bo)
+{
+ return 0;
+}
+
+static int
+i915_gem_vm_unbind(struct anv_device *device, struct anv_bo *bo)
+{
+ return 0;
+}
+
const struct anv_kmd_backend *
anv_i915_kmd_backend_get(void)
{
.gem_create = i915_gem_create,
.gem_close = i915_gem_close,
.gem_mmap = i915_gem_mmap,
+ .gem_vm_bind = i915_gem_vm_bind,
+ .gem_vm_unbind = i915_gem_vm_unbind,
.execute_simple_batch = i915_execute_simple_batch,
.queue_exec_locked = i915_queue_exec_locked
};
*/
#include <sys/mman.h>
+#include <xf86drm.h>
#include "anv_private.h"
device->fd, args.offset);
}
+static inline int
+xe_gem_vm_bind_op(struct anv_device *device, struct anv_bo *bo, uint32_t op)
+{
+ uint32_t syncobj_handle;
+ int ret = drmSyncobjCreate(device->fd, 0, &syncobj_handle);
+
+ if (ret)
+ return ret;
+
+ struct drm_xe_sync sync = {
+ .flags = DRM_XE_SYNC_SYNCOBJ | DRM_XE_SYNC_SIGNAL,
+ .handle = syncobj_handle,
+ };
+ struct drm_xe_vm_bind args = {
+ .vm_id = device->vm_id,
+ .num_binds = 1,
+ .bind.obj = op == XE_VM_BIND_OP_UNMAP ? 0 : bo->gem_handle,
+ .bind.obj_offset = 0,
+ .bind.range = bo->size + bo->_ccs_size,
+ .bind.addr = intel_48b_address(bo->offset),
+ .bind.op = op,
+ .num_syncs = 1,
+ .syncs = (uintptr_t)&sync,
+ };
+ ret = intel_ioctl(device->fd, DRM_IOCTL_XE_VM_BIND, &args);
+ if (ret)
+ goto bind_error;
+
+ struct drm_syncobj_wait wait = {
+ .handles = (uintptr_t)&syncobj_handle,
+ .timeout_nsec = INT64_MAX,
+ .count_handles = 1,
+ .flags = 0,
+ .first_signaled = 0,
+ .pad = 0,
+ };
+ intel_ioctl(device->fd, DRM_IOCTL_SYNCOBJ_WAIT, &wait);
+
+bind_error:
+ drmSyncobjDestroy(device->fd, syncobj_handle);
+ return ret;
+}
+
+static int xe_gem_vm_bind(struct anv_device *device, struct anv_bo *bo)
+{
+ return xe_gem_vm_bind_op(device, bo, XE_VM_BIND_OP_MAP);
+}
+
+static int xe_gem_vm_unbind(struct anv_device *device, struct anv_bo *bo)
+{
+ return xe_gem_vm_bind_op(device, bo, XE_VM_BIND_OP_UNMAP);
+}
+
const struct anv_kmd_backend *
anv_xe_kmd_backend_get(void)
{
.gem_create = xe_gem_create,
.gem_close = xe_gem_close,
.gem_mmap = xe_gem_mmap,
+ .gem_vm_bind = xe_gem_vm_bind,
+ .gem_vm_unbind = xe_gem_vm_unbind,
};
return &xe_backend;
}