Skip to content

Commit 4f4bdbd

Browse files
committed
drm/xe: Add sa/guc_buf_cache sync interface
In upcoming changes the cached buffers are going to be used to read data produced by the GuC. Add a counterpart to flush, which synchronizes the CPU-side of suballocation with the GPU data and propagate the interface to GuC Buffer Cache. Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com> Link: https://patch.msgid.link/20251112132220.516975-11-michal.winiarski@intel.com Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
1 parent 20cfef3 commit 4f4bdbd

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

drivers/gpu/drm/xe/xe_guc_buf.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ void xe_guc_buf_release(const struct xe_guc_buf buf)
115115
xe_sa_bo_free(buf.sa, NULL);
116116
}
117117

118+
/**
119+
* xe_guc_buf_sync_read() - Copy the data from the GPU memory to the sub-allocation.
120+
* @buf: the &xe_guc_buf to sync
121+
*
122+
* Return: a CPU pointer of the sub-allocation.
123+
*/
124+
void *xe_guc_buf_sync_read(const struct xe_guc_buf buf)
125+
{
126+
xe_sa_bo_sync_read(buf.sa);
127+
128+
return xe_sa_bo_cpu_addr(buf.sa);
129+
}
130+
118131
/**
119132
* xe_guc_buf_flush() - Copy the data from the sub-allocation to the GPU memory.
120133
* @buf: the &xe_guc_buf to flush

drivers/gpu/drm/xe/xe_guc_buf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static inline bool xe_guc_buf_is_valid(const struct xe_guc_buf buf)
3030
}
3131

3232
void *xe_guc_buf_cpu_ptr(const struct xe_guc_buf buf);
33+
void *xe_guc_buf_sync_read(const struct xe_guc_buf buf);
3334
u64 xe_guc_buf_flush(const struct xe_guc_buf buf);
3435
u64 xe_guc_buf_gpu_addr(const struct xe_guc_buf buf);
3536
u64 xe_guc_cache_gpu_addr_from_ptr(struct xe_guc_buf_cache *cache, const void *ptr, u32 size);

drivers/gpu/drm/xe/xe_sa.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ struct drm_suballoc *__xe_sa_bo_new(struct xe_sa_manager *sa_manager, u32 size,
110110
return drm_suballoc_new(&sa_manager->base, size, gfp, true, 0);
111111
}
112112

113+
/**
114+
* xe_sa_bo_flush_write() - Copy the data from the sub-allocation to the GPU memory.
115+
* @sa_bo: the &drm_suballoc to flush
116+
*/
113117
void xe_sa_bo_flush_write(struct drm_suballoc *sa_bo)
114118
{
115119
struct xe_sa_manager *sa_manager = to_xe_sa_manager(sa_bo->manager);
@@ -123,6 +127,23 @@ void xe_sa_bo_flush_write(struct drm_suballoc *sa_bo)
123127
drm_suballoc_size(sa_bo));
124128
}
125129

130+
/**
131+
* xe_sa_bo_sync_read() - Copy the data from GPU memory to the sub-allocation.
132+
* @sa_bo: the &drm_suballoc to sync
133+
*/
134+
void xe_sa_bo_sync_read(struct drm_suballoc *sa_bo)
135+
{
136+
struct xe_sa_manager *sa_manager = to_xe_sa_manager(sa_bo->manager);
137+
struct xe_device *xe = tile_to_xe(sa_manager->bo->tile);
138+
139+
if (!sa_manager->bo->vmap.is_iomem)
140+
return;
141+
142+
xe_map_memcpy_from(xe, xe_sa_bo_cpu_addr(sa_bo), &sa_manager->bo->vmap,
143+
drm_suballoc_soffset(sa_bo),
144+
drm_suballoc_size(sa_bo));
145+
}
146+
126147
void xe_sa_bo_free(struct drm_suballoc *sa_bo,
127148
struct dma_fence *fence)
128149
{

drivers/gpu/drm/xe/xe_sa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static inline struct drm_suballoc *xe_sa_bo_new(struct xe_sa_manager *sa_manager
3737
}
3838

3939
void xe_sa_bo_flush_write(struct drm_suballoc *sa_bo);
40+
void xe_sa_bo_sync_read(struct drm_suballoc *sa_bo);
4041
void xe_sa_bo_free(struct drm_suballoc *sa_bo, struct dma_fence *fence);
4142

4243
static inline struct xe_sa_manager *

0 commit comments

Comments
 (0)