| 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 | struct xe_sa_manager *__xe_sa_bo_manager_init(struct xe_tile *tile, u32 size, u32 guard, u32 align); |
| 18 | struct drm_suballoc *__xe_sa_bo_new(struct xe_sa_manager *sa_manager, u32 size, gfp_t gfp); |
| 19 | |
| 20 | static inline struct xe_sa_manager *xe_sa_bo_manager_init(struct xe_tile *tile, u32 size, u32 align) |
| 21 | { |
| 22 | return __xe_sa_bo_manager_init(tile, size, SZ_4K, align); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * xe_sa_bo_new() - Make a suballocation. |
| 27 | * @sa_manager: the &xe_sa_manager |
| 28 | * @size: number of bytes we want to suballocate |
| 29 | * |
| 30 | * Try to make a suballocation of size @size. |
| 31 | * |
| 32 | * Return: a &drm_suballoc, or an ERR_PTR. |
| 33 | */ |
| 34 | static inline struct drm_suballoc *xe_sa_bo_new(struct xe_sa_manager *sa_manager, u32 size) |
| 35 | { |
| 36 | return __xe_sa_bo_new(sa_manager, size, GFP_KERNEL); |
| 37 | } |
| 38 | |
| 39 | void xe_sa_bo_flush_write(struct drm_suballoc *sa_bo); |
| 40 | void xe_sa_bo_sync_read(struct drm_suballoc *sa_bo); |
| 41 | void xe_sa_bo_free(struct drm_suballoc *sa_bo, struct dma_fence *fence); |
| 42 | |
| 43 | static inline struct xe_sa_manager * |
| 44 | to_xe_sa_manager(struct drm_suballoc_manager *mng) |
| 45 | { |
| 46 | return container_of(mng, struct xe_sa_manager, base); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * xe_sa_manager_gpu_addr - Retrieve GPU address of a back storage BO |
| 51 | * within suballocator. |
| 52 | * @sa_manager: the &xe_sa_manager struct instance |
| 53 | * Return: GGTT address of the back storage BO. |
| 54 | */ |
| 55 | static inline u64 xe_sa_manager_gpu_addr(struct xe_sa_manager *sa_manager) |
| 56 | { |
| 57 | return xe_bo_ggtt_addr(bo: sa_manager->bo); |
| 58 | } |
| 59 | |
| 60 | static inline u64 xe_sa_bo_gpu_addr(struct drm_suballoc *sa) |
| 61 | { |
| 62 | return xe_sa_manager_gpu_addr(sa_manager: to_xe_sa_manager(mng: sa->manager)) + |
| 63 | drm_suballoc_soffset(sa); |
| 64 | } |
| 65 | |
| 66 | static inline void *xe_sa_bo_cpu_addr(struct drm_suballoc *sa) |
| 67 | { |
| 68 | return to_xe_sa_manager(mng: sa->manager)->cpu_ptr + |
| 69 | drm_suballoc_soffset(sa); |
| 70 | } |
| 71 | |
| 72 | #endif |
| 73 | |