if (err)
goto err_lrc;
+ /*
+ * Normally the user vm holds an rpm ref to keep the device
+ * awake, and the context holds a ref for the vm, however for
+ * some engines we use the kernels migrate vm underneath which
+ * offers no such rpm ref. Make sure we keep a ref here, so we
+ * can perform GuC CT actions when needed. Caller is expected to
+ * have already grabbed the rpm ref outside any sensitive locks.
+ */
+ if (e->flags & ENGINE_FLAG_VM)
+ drm_WARN_ON(&xe->drm, !xe_device_mem_access_get_if_ongoing(xe));
+
return e;
err_lrc:
xe_lrc_finish(e->lrc + i);
if (e->vm)
xe_vm_put(e->vm);
+ if (e->flags & ENGINE_FLAG_VM)
+ xe_device_mem_access_put(gt_to_xe(e->gt));
kfree(e);
}
if (XE_IOCTL_DBG(xe, !hwe))
return -EINVAL;
+ /* The migration vm doesn't hold rpm ref */
+ xe_device_mem_access_get(xe);
+
migrate_vm = xe_migrate_get_vm(gt_to_tile(gt)->migrate);
new = xe_engine_create(xe, migrate_vm, logical_mask,
args->width, hwe,
(id ?
ENGINE_FLAG_BIND_ENGINE_CHILD :
0));
+
+ xe_device_mem_access_put(xe); /* now held by engine */
+
xe_vm_put(migrate_vm);
if (IS_ERR(new)) {
err = PTR_ERR(new);
#define ENGINE_FLAG_KERNEL BIT(1)
#define ENGINE_FLAG_PERSISTENT BIT(2)
#define ENGINE_FLAG_COMPUTE_MODE BIT(3)
+/* Caller needs to hold rpm ref when creating engine with ENGINE_FLAG_VM */
#define ENGINE_FLAG_VM BIT(4)
#define ENGINE_FLAG_BIND_ENGINE_CHILD BIT(5)
#define ENGINE_FLAG_WA BIT(6)