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