xref: /linux/drivers/gpu/drm/xe/xe_migrate.h (revision 45fbb51050e72723c2bdcedc1ce32305256c70ed)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 
6 #ifndef _XE_MIGRATE_
7 #define _XE_MIGRATE_
8 
9 #include <linux/types.h>
10 
11 struct dma_fence;
12 struct iosys_map;
13 struct ttm_resource;
14 
15 struct xe_bo;
16 struct xe_gt;
17 struct xe_gt_tlb_inval_job;
18 struct xe_exec_queue;
19 struct xe_migrate;
20 struct xe_migrate_pt_update;
21 struct xe_sync_entry;
22 struct xe_pt;
23 struct xe_tile;
24 struct xe_vm;
25 struct xe_vm_pgtable_update;
26 struct xe_vma;
27 
28 enum xe_sriov_vf_ccs_rw_ctxs;
29 
30 /**
31  * struct xe_migrate_pt_update_ops - Callbacks for the
32  * xe_migrate_update_pgtables() function.
33  */
34 struct xe_migrate_pt_update_ops {
35 	/**
36 	 * @populate: Populate a command buffer or page-table with ptes.
37 	 * @pt_update: Embeddable callback argument.
38 	 * @tile: The tile for the current operation.
39 	 * @map: struct iosys_map into the memory to be populated.
40 	 * @pos: If @map is NULL, map into the memory to be populated.
41 	 * @ofs: qword offset into @map, unused if @map is NULL.
42 	 * @num_qwords: Number of qwords to write.
43 	 * @update: Information about the PTEs to be inserted.
44 	 *
45 	 * This interface is intended to be used as a callback into the
46 	 * page-table system to populate command buffers or shared
47 	 * page-tables with PTEs.
48 	 */
49 	void (*populate)(struct xe_migrate_pt_update *pt_update,
50 			 struct xe_tile *tile, struct iosys_map *map,
51 			 void *pos, u32 ofs, u32 num_qwords,
52 			 const struct xe_vm_pgtable_update *update);
53 	/**
54 	 * @clear: Clear a command buffer or page-table with ptes.
55 	 * @pt_update: Embeddable callback argument.
56 	 * @tile: The tile for the current operation.
57 	 * @map: struct iosys_map into the memory to be populated.
58 	 * @pos: If @map is NULL, map into the memory to be populated.
59 	 * @ofs: qword offset into @map, unused if @map is NULL.
60 	 * @num_qwords: Number of qwords to write.
61 	 * @update: Information about the PTEs to be inserted.
62 	 *
63 	 * This interface is intended to be used as a callback into the
64 	 * page-table system to populate command buffers or shared
65 	 * page-tables with PTEs.
66 	 */
67 	void (*clear)(struct xe_migrate_pt_update *pt_update,
68 		      struct xe_tile *tile, struct iosys_map *map,
69 		      void *pos, u32 ofs, u32 num_qwords,
70 		      const struct xe_vm_pgtable_update *update);
71 
72 	/**
73 	 * @pre_commit: Callback to be called just before arming the
74 	 * sched_job.
75 	 * @pt_update: Pointer to embeddable callback argument.
76 	 *
77 	 * Return: 0 on success, negative error code on error.
78 	 */
79 	int (*pre_commit)(struct xe_migrate_pt_update *pt_update);
80 };
81 
82 /**
83  * struct xe_migrate_pt_update - Argument to the
84  * struct xe_migrate_pt_update_ops callbacks.
85  *
86  * Intended to be subclassed to support additional arguments if necessary.
87  */
88 struct xe_migrate_pt_update {
89 	/** @ops: Pointer to the struct xe_migrate_pt_update_ops callbacks */
90 	const struct xe_migrate_pt_update_ops *ops;
91 	/** @vops: VMA operations */
92 	struct xe_vma_ops *vops;
93 	/** @job: The job if a GPU page-table update. NULL otherwise */
94 	struct xe_sched_job *job;
95 	/**
96 	 * @ijob: The GT TLB invalidation job for primary tile. NULL otherwise
97 	 */
98 	struct xe_gt_tlb_inval_job *ijob;
99 	/**
100 	 * @mjob: The GT TLB invalidation job for media tile. NULL otherwise
101 	 */
102 	struct xe_gt_tlb_inval_job *mjob;
103 	/** @tile_id: Tile ID of the update */
104 	u8 tile_id;
105 };
106 
107 struct xe_migrate *xe_migrate_alloc(struct xe_tile *tile);
108 struct xe_migrate *xe_migrate_init(struct xe_tile *tile);
109 
110 struct dma_fence *xe_migrate_to_vram(struct xe_migrate *m,
111 				     unsigned long npages,
112 				     dma_addr_t *src_addr,
113 				     u64 dst_addr);
114 
115 struct dma_fence *xe_migrate_from_vram(struct xe_migrate *m,
116 				       unsigned long npages,
117 				       u64 src_addr,
118 				       dma_addr_t *dst_addr);
119 
120 struct dma_fence *xe_migrate_copy(struct xe_migrate *m,
121 				  struct xe_bo *src_bo,
122 				  struct xe_bo *dst_bo,
123 				  struct ttm_resource *src,
124 				  struct ttm_resource *dst,
125 				  bool copy_only_ccs);
126 
127 int xe_migrate_ccs_rw_copy(struct xe_migrate *m,
128 			   struct xe_bo *src_bo,
129 			   enum xe_sriov_vf_ccs_rw_ctxs read_write);
130 
131 struct xe_lrc *xe_migrate_lrc(struct xe_migrate *migrate);
132 struct xe_exec_queue *xe_migrate_exec_queue(struct xe_migrate *migrate);
133 int xe_migrate_access_memory(struct xe_migrate *m, struct xe_bo *bo,
134 			     unsigned long offset, void *buf, int len,
135 			     int write);
136 
137 #define XE_MIGRATE_CLEAR_FLAG_BO_DATA		BIT(0)
138 #define XE_MIGRATE_CLEAR_FLAG_CCS_DATA		BIT(1)
139 #define XE_MIGRATE_CLEAR_FLAG_FULL	(XE_MIGRATE_CLEAR_FLAG_BO_DATA | \
140 					XE_MIGRATE_CLEAR_FLAG_CCS_DATA)
141 struct dma_fence *xe_migrate_clear(struct xe_migrate *m,
142 				   struct xe_bo *bo,
143 				   struct ttm_resource *dst,
144 				   u32 clear_flags);
145 
146 struct xe_vm *xe_migrate_get_vm(struct xe_migrate *m);
147 
148 struct dma_fence *
149 xe_migrate_update_pgtables(struct xe_migrate *m,
150 			   struct xe_migrate_pt_update *pt_update);
151 
152 void xe_migrate_wait(struct xe_migrate *m);
153 
154 void xe_migrate_job_lock(struct xe_migrate *m, struct xe_exec_queue *q);
155 void xe_migrate_job_unlock(struct xe_migrate *m, struct xe_exec_queue *q);
156 
157 #endif
158