xref: /linux/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_stolen.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 #ifndef _I915_GEM_STOLEN_H_
2 #define _I915_GEM_STOLEN_H_
3 
4 #include "xe_ttm_stolen_mgr.h"
5 #include "xe_res_cursor.h"
6 
7 struct xe_bo;
8 
9 struct i915_stolen_fb {
10 	struct xe_bo *bo;
11 };
12 
13 static inline int i915_gem_stolen_insert_node_in_range(struct xe_device *xe,
14 						       struct i915_stolen_fb *fb,
15 						       u32 size, u32 align,
16 						       u32 start, u32 end)
17 {
18 	struct xe_bo *bo;
19 	int err;
20 	u32 flags = XE_BO_FLAG_PINNED | XE_BO_FLAG_STOLEN;
21 
22 	if (start < SZ_4K)
23 		start = SZ_4K;
24 
25 	if (align) {
26 		size = ALIGN(size, align);
27 		start = ALIGN(start, align);
28 	}
29 
30 	bo = xe_bo_create_locked_range(xe, xe_device_get_root_tile(xe),
31 				       NULL, size, start, end,
32 				       ttm_bo_type_kernel, flags, 0);
33 	if (IS_ERR(bo)) {
34 		err = PTR_ERR(bo);
35 		bo = NULL;
36 		return err;
37 	}
38 	err = xe_bo_pin(bo);
39 	xe_bo_unlock_vm_held(bo);
40 
41 	if (err) {
42 		xe_bo_put(fb->bo);
43 		bo = NULL;
44 	}
45 
46 	fb->bo = bo;
47 
48 	return err;
49 }
50 
51 static inline int i915_gem_stolen_insert_node(struct xe_device *xe,
52 					      struct i915_stolen_fb *fb,
53 					      u32 size, u32 align)
54 {
55 	/* Not used on xe */
56 	BUG_ON(1);
57 	return -ENODEV;
58 }
59 
60 static inline void i915_gem_stolen_remove_node(struct xe_device *xe,
61 					       struct i915_stolen_fb *fb)
62 {
63 	xe_bo_unpin_map_no_vm(fb->bo);
64 	fb->bo = NULL;
65 }
66 
67 #define i915_gem_stolen_initialized(xe) (!!ttm_manager_type(&(xe)->ttm, XE_PL_STOLEN))
68 #define i915_gem_stolen_node_allocated(fb) (!!((fb)->bo))
69 
70 static inline u32 i915_gem_stolen_node_offset(struct i915_stolen_fb *fb)
71 {
72 	struct xe_res_cursor res;
73 
74 	xe_res_first(fb->bo->ttm.resource, 0, 4096, &res);
75 	return res.start;
76 }
77 
78 /* Used for < gen4. These are not supported by Xe */
79 #define i915_gem_stolen_area_address(xe) (!WARN_ON(1))
80 /* Used for gen9 specific WA. Gen9 is not supported by Xe */
81 #define i915_gem_stolen_area_size(xe) (!WARN_ON(1))
82 
83 #define i915_gem_stolen_node_address(xe, fb) (xe_ttm_stolen_gpu_offset(xe) + \
84 					 i915_gem_stolen_node_offset(fb))
85 #define i915_gem_stolen_node_size(fb) ((u64)((fb)->bo->ttm.base.size))
86 
87 #endif
88