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