xref: /linux/drivers/gpu/drm/xe/xe_sa.h (revision b615879dbfea6cf1236acbc3f2fb25ae84e07071)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 #ifndef _XE_SA_H_
6 #define _XE_SA_H_
7 
8 #include <linux/sizes.h>
9 #include <linux/types.h>
10 
11 #include "xe_bo.h"
12 #include "xe_sa_types.h"
13 
14 struct dma_fence;
15 struct xe_tile;
16 
17 struct xe_sa_manager *__xe_sa_bo_manager_init(struct xe_tile *tile, u32 size, u32 guard, u32 align);
18 struct drm_suballoc *__xe_sa_bo_new(struct xe_sa_manager *sa_manager, u32 size, gfp_t gfp);
19 
20 static inline struct xe_sa_manager *xe_sa_bo_manager_init(struct xe_tile *tile, u32 size, u32 align)
21 {
22 	return __xe_sa_bo_manager_init(tile, size, SZ_4K, align);
23 }
24 
25 /**
26  * xe_sa_bo_new() - Make a suballocation.
27  * @sa_manager: the &xe_sa_manager
28  * @size: number of bytes we want to suballocate
29  *
30  * Try to make a suballocation of size @size.
31  *
32  * Return: a &drm_suballoc, or an ERR_PTR.
33  */
34 static inline struct drm_suballoc *xe_sa_bo_new(struct xe_sa_manager *sa_manager, u32 size)
35 {
36 	return __xe_sa_bo_new(sa_manager, size, GFP_KERNEL);
37 }
38 
39 void xe_sa_bo_flush_write(struct drm_suballoc *sa_bo);
40 void xe_sa_bo_free(struct drm_suballoc *sa_bo, struct dma_fence *fence);
41 
42 static inline struct xe_sa_manager *
43 to_xe_sa_manager(struct drm_suballoc_manager *mng)
44 {
45 	return container_of(mng, struct xe_sa_manager, base);
46 }
47 
48 /**
49  * xe_sa_manager_gpu_addr - Retrieve GPU address of a back storage BO
50  * within suballocator.
51  * @sa_manager: the &xe_sa_manager struct instance
52  * Return: GGTT address of the back storage BO.
53  */
54 static inline u64 xe_sa_manager_gpu_addr(struct xe_sa_manager *sa_manager)
55 {
56 	return xe_bo_ggtt_addr(sa_manager->bo);
57 }
58 
59 static inline u64 xe_sa_bo_gpu_addr(struct drm_suballoc *sa)
60 {
61 	return xe_sa_manager_gpu_addr(to_xe_sa_manager(sa->manager)) +
62 		drm_suballoc_soffset(sa);
63 }
64 
65 static inline void *xe_sa_bo_cpu_addr(struct drm_suballoc *sa)
66 {
67 	return to_xe_sa_manager(sa->manager)->cpu_ptr +
68 		drm_suballoc_soffset(sa);
69 }
70 
71 #endif
72