1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright 2026 Advanced Micro Devices, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 */ 24 25 #ifndef AMDGPU_SA_H_ 26 #define AMDGPU_SA_H_ 27 28 #include <drm/drm_suballoc.h> 29 30 struct amdgpu_device; 31 struct amdgpu_bo; 32 33 struct amdgpu_sa_manager { 34 struct drm_suballoc_manager base; 35 struct amdgpu_bo *bo; 36 uint64_t gpu_addr; 37 void *cpu_ptr; 38 }; 39 40 static inline struct amdgpu_sa_manager * 41 to_amdgpu_sa_manager(struct drm_suballoc_manager *manager) 42 { 43 return container_of(manager, struct amdgpu_sa_manager, base); 44 } 45 46 static inline uint64_t amdgpu_sa_bo_gpu_addr(struct drm_suballoc *sa_bo) 47 { 48 return to_amdgpu_sa_manager(sa_bo->manager)->gpu_addr + 49 drm_suballoc_soffset(sa_bo); 50 } 51 52 static inline void *amdgpu_sa_bo_cpu_addr(struct drm_suballoc *sa_bo) 53 { 54 return to_amdgpu_sa_manager(sa_bo->manager)->cpu_ptr + 55 drm_suballoc_soffset(sa_bo); 56 } 57 58 int amdgpu_sa_bo_manager_init(struct amdgpu_device *adev, 59 struct amdgpu_sa_manager *sa_manager, 60 unsigned size, u32 align, u32 domain); 61 void amdgpu_sa_bo_manager_fini(struct amdgpu_device *adev, 62 struct amdgpu_sa_manager *sa_manager); 63 int amdgpu_sa_bo_manager_start(struct amdgpu_device *adev, 64 struct amdgpu_sa_manager *sa_manager); 65 int amdgpu_sa_bo_new(struct amdgpu_sa_manager *sa_manager, 66 struct drm_suballoc **sa_bo, 67 unsigned int size); 68 void amdgpu_sa_bo_free(struct drm_suballoc **sa_bo, 69 struct dma_fence *fence); 70 #if defined(CONFIG_DEBUG_FS) 71 void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager, 72 struct seq_file *m); 73 u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m); 74 #endif 75 void amdgpu_debugfs_sa_init(struct amdgpu_device *adev); 76 77 #endif 78