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_CREATE_PINNED_BIT | XE_BO_CREATE_STOLEN_BIT;
21 
22 	if (align)
23 		size = ALIGN(size, align);
24 
25 	bo = xe_bo_create_locked_range(xe, xe_device_get_root_tile(xe),
26 				       NULL, size, start, end,
27 				       ttm_bo_type_kernel, flags);
28 	if (IS_ERR(bo)) {
29 		err = PTR_ERR(bo);
30 		bo = NULL;
31 		return err;
32 	}
33 	err = xe_bo_pin(bo);
34 	xe_bo_unlock_vm_held(bo);
35 
36 	if (err) {
37 		xe_bo_put(fb->bo);
38 		bo = NULL;
39 	}
40 
41 	fb->bo = bo;
42 
43 	return err;
44 }
45 
46 static inline int i915_gem_stolen_insert_node(struct xe_device *xe,
47 					      struct i915_stolen_fb *fb,
48 					      u32 size, u32 align)
49 {
50 	/* Not used on xe */
51 	BUG_ON(1);
52 	return -ENODEV;
53 }
54 
55 static inline void i915_gem_stolen_remove_node(struct xe_device *xe,
56 					       struct i915_stolen_fb *fb)
57 {
58 	xe_bo_unpin_map_no_vm(fb->bo);
59 	fb->bo = NULL;
60 }
61 
62 #define i915_gem_stolen_initialized(xe) (!!ttm_manager_type(&(xe)->ttm, XE_PL_STOLEN))
63 #define i915_gem_stolen_node_allocated(fb) (!!((fb)->bo))
64 
65 static inline u32 i915_gem_stolen_node_offset(struct i915_stolen_fb *fb)
66 {
67 	struct xe_res_cursor res;
68 
69 	xe_res_first(fb->bo->ttm.resource, 0, 4096, &res);
70 	return res.start;
71 }
72 
73 /* Used for < gen4. These are not supported by Xe */
74 #define i915_gem_stolen_area_address(xe) (!WARN_ON(1))
75 /* Used for gen9 specific WA. Gen9 is not supported by Xe */
76 #define i915_gem_stolen_area_size(xe) (!WARN_ON(1))
77 
78 #define i915_gem_stolen_node_address(xe, fb) (xe_ttm_stolen_gpu_offset(xe) + \
79 					 i915_gem_stolen_node_offset(fb))
80 #define i915_gem_stolen_node_size(fb) ((u64)((fb)->bo->ttm.base.size))
81 
82 #endif
83