Add xe_svm and xe_svm_range data structure. Each xe_svm represents a svm address space and it maps 1:1 to the process's mm_struct. It also maps 1:1 to the gpu xe_vm struct. Each xe_svm_range represent a virtual address range inside a svm address space. It is similar to CPU's vm_area_struct, or to the GPU xe_vma struct. It contains data to synchronize this address range to CPU's virtual address range, using mmu notifier mechanism. It can also hold this range's memory attributes set by user, such as preferred memory location etc - this is TBD. Each svm address space is made of many svm virtual address range. All address ranges are maintained in xe_svm's interval tree. Also add a xe_svm pointer to xe_vm data structure. So we have a 1:1 mapping b/t xe_svm and xe_vm. Signed-off-by: Oak Zeng <oak.zeng@xxxxxxxxx> Cc: Niranjana Vishwanathapura <niranjana.vishwanathapura@xxxxxxxxx> Cc: Matthew Brost <matthew.brost@xxxxxxxxx> Cc: Thomas Hellström <thomas.hellstrom@xxxxxxxxx> Cc: Brian Welty <brian.welty@xxxxxxxxx> --- drivers/gpu/drm/xe/xe_svm.h | 59 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_vm_types.h | 2 ++ 2 files changed, 61 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_svm.h diff --git a/drivers/gpu/drm/xe/xe_svm.h b/drivers/gpu/drm/xe/xe_svm.h new file mode 100644 index 000000000000..ba301a331f59 --- /dev/null +++ b/drivers/gpu/drm/xe/xe_svm.h @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2023 Intel Corporation + */ + +#ifndef __XE_SVM_H +#define __XE_SVM_H +#include <linux/list.h> +#include <linux/mutex.h> +#include <linux/mmu_notifier.h> +#include <linux/workqueue.h> +#include <linux/rbtree_types.h> +#include <linux/interval_tree.h> + +struct xe_vm; +struct mm_struct; + +/** + * struct xe_svm - data structure to represent a shared + * virtual address space from device side. xe_svm, xe_vm + * and mm_struct has a 1:1:1 relationship. + */ +struct xe_svm { + /** @vm: The xe_vm address space corresponding to this xe_svm */ + struct xe_vm *vm; + /** @mm: The mm_struct corresponding to this xe_svm */ + struct mm_struct *mm; + /** + * @mutex: A lock used by svm subsystem. It protects: + * 1. below range_tree + * 2. GPU page table update. Serialize all SVM GPU page table updates + */ + struct mutex mutex; + /** + * @range_tree: Interval tree of all svm ranges in this svm + */ + struct rb_root_cached range_tree; +}; + +/** + * struct xe_svm_range - Represents a shared virtual address range. + */ +struct xe_svm_range { + /** @notifier: The mmu interval notifer used to keep track of CPU + * side address range change. Driver will get a callback with this + * notifier if anything changed from CPU side, such as range is + * unmapped from CPU + */ + struct mmu_interval_notifier notifier; + /** @start: start address of this range, inclusive */ + u64 start; + /** @end: end address of this range, exclusive */ + u64 end; + /** @unregister_notifier_work: A worker used to unregister this notifier */ + struct work_struct unregister_notifier_work; + /** @inode: used to link this range to svm's range_tree */ + struct interval_tree_node inode; +}; +#endif diff --git a/drivers/gpu/drm/xe/xe_vm_types.h b/drivers/gpu/drm/xe/xe_vm_types.h index 63e8a50b88e9..037fb7168c63 100644 --- a/drivers/gpu/drm/xe/xe_vm_types.h +++ b/drivers/gpu/drm/xe/xe_vm_types.h @@ -17,6 +17,7 @@ #include "xe_pt_types.h" #include "xe_range_fence.h" +struct xe_svm; struct xe_bo; struct xe_sync_entry; struct xe_vm; @@ -279,6 +280,7 @@ struct xe_vm { bool batch_invalidate_tlb; /** @xef: XE file handle for tracking this VM's drm client */ struct xe_file *xef; + struct xe_svm *svm; }; /** struct xe_vma_op_map - VMA map operation */ -- 2.26.3