1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 #ifndef _XE_SA_H_ 6 #define _XE_SA_H_ 7 8 #include <linux/sizes.h> 9 #include <linux/types.h> 10 11 #include "xe_bo.h" 12 #include "xe_sa_types.h" 13 14 struct dma_fence; 15 struct xe_tile; 16 17 #define XE_SA_BO_MANAGER_FLAG_SHADOW BIT(0) 18 struct xe_sa_manager *__xe_sa_bo_manager_init(struct xe_tile *tile, u32 size, 19 u32 guard, u32 align, u32 flags); 20 struct drm_suballoc *__xe_sa_bo_new(struct xe_sa_manager *sa_manager, u32 size, gfp_t gfp); 21 22 static inline struct xe_sa_manager *xe_sa_bo_manager_init(struct xe_tile *tile, u32 size, u32 align) 23 { 24 return __xe_sa_bo_manager_init(tile, size, SZ_4K, align, 0); 25 } 26 27 /** 28 * xe_sa_bo_new() - Make a suballocation. 29 * @sa_manager: the &xe_sa_manager 30 * @size: number of bytes we want to suballocate 31 * 32 * Try to make a suballocation of size @size. 33 * 34 * Return: a &drm_suballoc, or an ERR_PTR. 35 */ 36 static inline struct drm_suballoc *xe_sa_bo_new(struct xe_sa_manager *sa_manager, u32 size) 37 { 38 return __xe_sa_bo_new(sa_manager, size, GFP_KERNEL); 39 } 40 41 void xe_sa_bo_flush_write(struct drm_suballoc *sa_bo); 42 void xe_sa_bo_sync_read(struct drm_suballoc *sa_bo); 43 void xe_sa_bo_free(struct drm_suballoc *sa_bo, struct dma_fence *fence); 44 45 static inline struct xe_sa_manager * 46 to_xe_sa_manager(struct drm_suballoc_manager *mng) 47 { 48 return container_of(mng, struct xe_sa_manager, base); 49 } 50 51 /** 52 * xe_sa_manager_gpu_addr - Retrieve GPU address of a back storage BO 53 * within suballocator. 54 * @sa_manager: the &xe_sa_manager struct instance 55 * Return: GGTT address of the back storage BO. 56 */ 57 static inline u64 xe_sa_manager_gpu_addr(struct xe_sa_manager *sa_manager) 58 { 59 return xe_bo_ggtt_addr(sa_manager->bo); 60 } 61 62 static inline u64 xe_sa_bo_gpu_addr(struct drm_suballoc *sa) 63 { 64 return xe_sa_manager_gpu_addr(to_xe_sa_manager(sa->manager)) + 65 drm_suballoc_soffset(sa); 66 } 67 68 static inline void *xe_sa_bo_cpu_addr(struct drm_suballoc *sa) 69 { 70 return to_xe_sa_manager(sa->manager)->cpu_ptr + 71 drm_suballoc_soffset(sa); 72 } 73 74 void xe_sa_bo_swap_shadow(struct xe_sa_manager *sa_manager); 75 void xe_sa_bo_sync_shadow(struct drm_suballoc *sa_bo); 76 77 /** 78 * xe_sa_bo_swap_guard() - Retrieve the SA BO swap guard within sub-allocator. 79 * @sa_manager: the &xe_sa_manager 80 * 81 * Return: Sub alloctor swap guard mutex. 82 */ 83 static inline struct mutex *xe_sa_bo_swap_guard(struct xe_sa_manager *sa_manager) 84 { 85 return &sa_manager->swap_guard; 86 } 87 88 #endif 89