]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe: Add xe_device_asid_to_vm helper
authorMatthew Brost <matthew.brost@intel.com>
Fri, 16 Jan 2026 22:17:24 +0000 (14:17 -0800)
committerMatthew Brost <matthew.brost@intel.com>
Sat, 17 Jan 2026 02:24:48 +0000 (18:24 -0800)
Introduce the xe_device_asid_to_vm helper, which can be used throughout
the driver to resolve the VM from a given ASID.

v4:
 - Move forward declare after includes (Stuart)

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matt Atwood <matthew.s.atwood@intel.com>
Reviewed-by: Stuart Summers <stuart.summers@intel.com>
Tested-by: Stuart Summers <stuart.summers@intel.com>
Link: https://patch.msgid.link/20260116221731.868657-5-matthew.brost@intel.com
drivers/gpu/drm/xe/xe_device.c
drivers/gpu/drm/xe/xe_device.h

index 495310a624b57b00433f568b8f493b494ea6d803..aad4aa53a51f924addc4a418683570da35bdda1a 100644 (file)
@@ -1375,3 +1375,28 @@ const char *xe_wedged_mode_to_string(enum xe_wedged_mode mode)
                return "<invalid>";
        }
 }
+
+/**
+ * xe_device_asid_to_vm() - Find VM from ASID
+ * @xe: the &xe_device
+ * @asid: Address space ID
+ *
+ * Find a VM from ASID and take a reference to VM which caller must drop.
+ * Reclaim safe.
+ *
+ * Return: VM on success, ERR_PTR on failure
+ */
+struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid)
+{
+       struct xe_vm *vm;
+
+       down_read(&xe->usm.lock);
+       vm = xa_load(&xe->usm.asid_to_vm, asid);
+       if (vm)
+               xe_vm_get(vm);
+       else
+               vm = ERR_PTR(-EINVAL);
+       up_read(&xe->usm.lock);
+
+       return vm;
+}
index 3740143790db2fce4f88a6a7ca3cfdb552748b9a..d25421e5181c52889a170781a73cda4bc0c143d6 100644 (file)
@@ -12,6 +12,8 @@
 #include "xe_gt_types.h"
 #include "xe_sriov.h"
 
+struct xe_vm;
+
 static inline struct xe_device *to_xe_device(const struct drm_device *dev)
 {
        return container_of(dev, struct xe_device, drm);
@@ -204,6 +206,8 @@ int xe_is_injection_active(void);
 
 bool xe_is_xe_file(const struct file *file);
 
+struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid);
+
 /*
  * Occasionally it is seen that the G2H worker starts running after a delay of more than
  * a second even after being queued and activated by the Linux workqueue subsystem. This