1 // SPDX-License-Identifier: MIT 2 /* Copyright © 2025 Intel Corporation */ 3 4 #include "gem/i915_gem_stolen.h" 5 #include "xe_res_cursor.h" 6 #include "xe_ttm_stolen_mgr.h" 7 #include "xe_validation.h" 8 9 struct intel_stolen_node { 10 struct xe_device *xe; 11 struct xe_bo *bo; 12 }; 13 14 int i915_gem_stolen_insert_node_in_range(struct intel_stolen_node *node, u64 size, 15 unsigned int align, u64 start, u64 end) 16 { 17 struct xe_device *xe = node->xe; 18 19 struct xe_bo *bo; 20 int err = 0; 21 u32 flags = XE_BO_FLAG_PINNED | XE_BO_FLAG_STOLEN; 22 23 if (start < SZ_4K) 24 start = SZ_4K; 25 26 if (align) { 27 size = ALIGN(size, align); 28 start = ALIGN(start, align); 29 } 30 31 bo = xe_bo_create_pin_range_novm(xe, xe_device_get_root_tile(xe), 32 size, start, end, ttm_bo_type_kernel, flags); 33 if (IS_ERR(bo)) { 34 err = PTR_ERR(bo); 35 bo = NULL; 36 return err; 37 } 38 39 node->bo = bo; 40 41 return err; 42 } 43 44 int i915_gem_stolen_insert_node(struct intel_stolen_node *node, u64 size, unsigned int align) 45 { 46 /* Not used on xe */ 47 WARN_ON(1); 48 49 return -ENODEV; 50 } 51 52 void i915_gem_stolen_remove_node(struct intel_stolen_node *node) 53 { 54 xe_bo_unpin_map_no_vm(node->bo); 55 node->bo = NULL; 56 } 57 58 bool i915_gem_stolen_initialized(struct drm_device *drm) 59 { 60 struct xe_device *xe = to_xe_device(drm); 61 62 return ttm_manager_type(&xe->ttm, XE_PL_STOLEN); 63 } 64 65 bool i915_gem_stolen_node_allocated(const struct intel_stolen_node *node) 66 { 67 return node->bo; 68 } 69 70 u32 i915_gem_stolen_node_offset(struct intel_stolen_node *node) 71 { 72 struct xe_res_cursor res; 73 74 xe_res_first(node->bo->ttm.resource, 0, 4096, &res); 75 return res.start; 76 } 77 78 /* Used for < gen4. These are not supported by Xe */ 79 u64 i915_gem_stolen_area_address(struct drm_device *drm) 80 { 81 WARN_ON(1); 82 83 return 0; 84 } 85 86 /* Used for gen9 specific WA. Gen9 is not supported by Xe */ 87 u64 i915_gem_stolen_area_size(struct drm_device *drm) 88 { 89 WARN_ON(1); 90 91 return 0; 92 } 93 94 u64 i915_gem_stolen_node_address(struct intel_stolen_node *node) 95 { 96 struct xe_device *xe = node->xe; 97 98 return xe_ttm_stolen_gpu_offset(xe) + i915_gem_stolen_node_offset(node); 99 } 100 101 u64 i915_gem_stolen_node_size(const struct intel_stolen_node *node) 102 { 103 return node->bo->ttm.base.size; 104 } 105 106 struct intel_stolen_node *i915_gem_stolen_node_alloc(struct drm_device *drm) 107 { 108 struct xe_device *xe = to_xe_device(drm); 109 struct intel_stolen_node *node; 110 111 node = kzalloc(sizeof(*node), GFP_KERNEL); 112 if (!node) 113 return NULL; 114 115 node->xe = xe; 116 117 return node; 118 } 119 120 void i915_gem_stolen_node_free(const struct intel_stolen_node *node) 121 { 122 kfree(node); 123 } 124