]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/xe/svm: Add xe_svm_find_vma_start() helper
authorHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Tue, 13 May 2025 04:02:26 +0000 (09:32 +0530)
committerHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Wed, 14 May 2025 13:55:54 +0000 (19:25 +0530)
Add helper xe_svm_find_vma_start() function to determine start of cpu
vma in input range.

Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Acked-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Link: https://lore.kernel.org/r/20250513040228.470682-14-himal.prasad.ghimiray@intel.com
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
drivers/gpu/drm/xe/xe_svm.c
drivers/gpu/drm/xe/xe_svm.h

index 248f615a343e63ce346abe0c3adb7f6f28011d93..4432685936ed4e5b880714d7b34e63d59a48de59 100644 (file)
@@ -692,6 +692,28 @@ bool xe_svm_range_validate(struct xe_vm *vm,
        return ret;
 }
 
+/**
+ * xe_svm_find_vma_start - Find start of CPU VMA
+ * @vm: xe_vm pointer
+ * @start: start address
+ * @end: end address
+ * @vma: Pointer to struct xe_vma
+ *
+ *
+ * This function searches for a cpu vma, within the specified
+ * range [start, end] in the given VM. It adjusts the range based on the
+ * xe_vma start and end addresses. If no cpu VMA is found, it returns ULONG_MAX.
+ *
+ * Return: The starting address of the VMA within the range,
+ * or ULONG_MAX if no VMA is found
+ */
+u64 xe_svm_find_vma_start(struct xe_vm *vm, u64 start, u64 end, struct xe_vma *vma)
+{
+       return drm_gpusvm_find_vma_start(&vm->svm.gpusvm,
+                                        max(start, xe_vma_start(vma)),
+                                        min(end, xe_vma_end(vma)));
+}
+
 #if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
 static struct xe_vram_region *tile_to_vr(struct xe_tile *tile)
 {
index 42be9e5d044450c750a5dcf97721227418def685..19ce4f2754a7825e4559201347572c665cde0955 100644 (file)
@@ -89,6 +89,8 @@ bool xe_svm_range_validate(struct xe_vm *vm,
                           struct xe_svm_range *range,
                           u8 tile_mask, bool devmem_preferred);
 
+u64 xe_svm_find_vma_start(struct xe_vm *vm, u64 addr, u64 end,  struct xe_vma *vma);
+
 /**
  * xe_svm_range_has_dma_mapping() - SVM range has DMA mapping
  * @range: SVM range
@@ -297,6 +299,12 @@ bool xe_svm_range_validate(struct xe_vm *vm,
        return false;
 }
 
+static inline
+u64 xe_svm_find_vma_start(struct xe_vm *vm, u64 addr, u64 end, struct xe_vma *vma)
+{
+       return ULONG_MAX;
+}
+
 #define xe_svm_assert_in_notifier(...) do {} while (0)
 #define xe_svm_range_has_dma_mapping(...) false