1c632d799SFlora Cui /* 2c632d799SFlora Cui * Copyright 2016 Advanced Micro Devices, Inc. 3c632d799SFlora Cui * 4c632d799SFlora Cui * Permission is hereby granted, free of charge, to any person obtaining a 5c632d799SFlora Cui * copy of this software and associated documentation files (the "Software"), 6c632d799SFlora Cui * to deal in the Software without restriction, including without limitation 7c632d799SFlora Cui * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8c632d799SFlora Cui * and/or sell copies of the Software, and to permit persons to whom the 9c632d799SFlora Cui * Software is furnished to do so, subject to the following conditions: 10c632d799SFlora Cui * 11c632d799SFlora Cui * The above copyright notice and this permission notice shall be included in 12c632d799SFlora Cui * all copies or substantial portions of the Software. 13c632d799SFlora Cui * 14c632d799SFlora Cui * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15c632d799SFlora Cui * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16c632d799SFlora Cui * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17c632d799SFlora Cui * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18c632d799SFlora Cui * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19c632d799SFlora Cui * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20c632d799SFlora Cui * OTHER DEALINGS IN THE SOFTWARE. 21c632d799SFlora Cui * 22c632d799SFlora Cui */ 23c632d799SFlora Cui 24c632d799SFlora Cui #ifndef __AMDGPU_TTM_H__ 25c632d799SFlora Cui #define __AMDGPU_TTM_H__ 26c632d799SFlora Cui 27a40cfa0bSTom St Denis #include "amdgpu.h" 281b1f42d8SLucas Stach #include <drm/gpu_scheduler.h> 29c632d799SFlora Cui 30283cde69SChristian König #define AMDGPU_PL_GDS (TTM_PL_PRIV + 0) 31283cde69SChristian König #define AMDGPU_PL_GWS (TTM_PL_PRIV + 1) 32283cde69SChristian König #define AMDGPU_PL_OA (TTM_PL_PRIV + 2) 33c632d799SFlora Cui 34283cde69SChristian König #define AMDGPU_PL_FLAG_GDS (TTM_PL_FLAG_PRIV << 0) 35283cde69SChristian König #define AMDGPU_PL_FLAG_GWS (TTM_PL_FLAG_PRIV << 1) 36283cde69SChristian König #define AMDGPU_PL_FLAG_OA (TTM_PL_FLAG_PRIV << 2) 37c632d799SFlora Cui 38cc25188aSChristian König #define AMDGPU_GTT_MAX_TRANSFER_SIZE 512 39cc25188aSChristian König #define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 2 40cc25188aSChristian König 41ab2f7a5cSFelix Kuehling #define AMDGPU_POISON 0xd0bed0be 42ab2f7a5cSFelix Kuehling 43c632d799SFlora Cui struct amdgpu_mman { 44c632d799SFlora Cui struct ttm_bo_device bdev; 45c632d799SFlora Cui bool mem_global_referenced; 46c632d799SFlora Cui bool initialized; 47f8f4b9a6SAmber Lin void __iomem *aper_base_kaddr; 48c632d799SFlora Cui 49c632d799SFlora Cui #if defined(CONFIG_DEBUG_FS) 50a40cfa0bSTom St Denis struct dentry *debugfs_entries[8]; 51c632d799SFlora Cui #endif 52c632d799SFlora Cui 53c632d799SFlora Cui /* buffer handling */ 54c632d799SFlora Cui const struct amdgpu_buffer_funcs *buffer_funcs; 55c632d799SFlora Cui struct amdgpu_ring *buffer_funcs_ring; 5681988f9cSChristian König bool buffer_funcs_enabled; 57abca90f1SChristian König 58abca90f1SChristian König struct mutex gtt_window_lock; 59c632d799SFlora Cui /* Scheduler entity for buffer moves */ 601b1f42d8SLucas Stach struct drm_sched_entity entity; 61c632d799SFlora Cui }; 62c632d799SFlora Cui 631eca5a53SHarish Kasiviswanathan struct amdgpu_copy_mem { 641eca5a53SHarish Kasiviswanathan struct ttm_buffer_object *bo; 651eca5a53SHarish Kasiviswanathan struct ttm_mem_reg *mem; 661eca5a53SHarish Kasiviswanathan unsigned long offset; 671eca5a53SHarish Kasiviswanathan }; 681eca5a53SHarish Kasiviswanathan 69bb990bb0SChristian König extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func; 706a7f76e7SChristian König extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func; 71bb990bb0SChristian König 723da917b6SChristian König bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem); 739255d77dSChristian König uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man); 74c1c7ce8fSChristian König int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man); 75bb990bb0SChristian König 76ddc21af4SMichel Dänzer u64 amdgpu_vram_mgr_bo_visible_size(struct amdgpu_bo *bo); 773c848bb3SChristian König uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man); 783c848bb3SChristian König uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man); 793c848bb3SChristian König 80c396ef9bSChristian König int amdgpu_ttm_init(struct amdgpu_device *adev); 816f752ec2SAndrey Grodzovsky void amdgpu_ttm_late_init(struct amdgpu_device *adev); 82c396ef9bSChristian König void amdgpu_ttm_fini(struct amdgpu_device *adev); 8357adc4ceSChristian König void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, 8457adc4ceSChristian König bool enable); 85c396ef9bSChristian König 86fc9c8f54SChristian König int amdgpu_copy_buffer(struct amdgpu_ring *ring, uint64_t src_offset, 87fc9c8f54SChristian König uint64_t dst_offset, uint32_t byte_count, 8852791eeeSChristian König struct dma_resv *resv, 89fc9c8f54SChristian König struct dma_fence **fence, bool direct_submit, 90c9dc9cfeSAaron Liu bool vm_needs_flush, bool tmz); 911eca5a53SHarish Kasiviswanathan int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, 921eca5a53SHarish Kasiviswanathan struct amdgpu_copy_mem *src, 931eca5a53SHarish Kasiviswanathan struct amdgpu_copy_mem *dst, 94*effb97ccSChristian König uint64_t size, bool tmz, 9552791eeeSChristian König struct dma_resv *resv, 961eca5a53SHarish Kasiviswanathan struct dma_fence **f); 97c632d799SFlora Cui int amdgpu_fill_buffer(struct amdgpu_bo *bo, 9844e1baebSChristian König uint32_t src_data, 9952791eeeSChristian König struct dma_resv *resv, 100f54d1867SChris Wilson struct dma_fence **fence); 101c632d799SFlora Cui 102c632d799SFlora Cui int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma); 103c5835bbbSChristian König int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo); 104c1c7ce8fSChristian König int amdgpu_ttm_recover_gart(struct ttm_buffer_object *tbo); 105c855e250SChristian König 106ad595b86SPhilip Yang #if IS_ENABLED(CONFIG_DRM_AMDGPU_USERPTR) 107e5eaa7ccSPhilip Yang int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages); 108899fbde1SPhilip Yang bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm); 109ad595b86SPhilip Yang #else 110e5eaa7ccSPhilip Yang static inline int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, 111e5eaa7ccSPhilip Yang struct page **pages) 112ad595b86SPhilip Yang { 113ad595b86SPhilip Yang return -EPERM; 114ad595b86SPhilip Yang } 115ad595b86SPhilip Yang static inline bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm) 116ad595b86SPhilip Yang { 117ad595b86SPhilip Yang return false; 118ad595b86SPhilip Yang } 119ad595b86SPhilip Yang #endif 120ad595b86SPhilip Yang 121711becf0SChristian König void amdgpu_ttm_tt_set_user_pages(struct ttm_tt *ttm, struct page **pages); 122711becf0SChristian König int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, 123711becf0SChristian König uint32_t flags); 124711becf0SChristian König bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm); 125711becf0SChristian König struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm); 126711becf0SChristian König bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start, 127711becf0SChristian König unsigned long end); 128711becf0SChristian König bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm, 129711becf0SChristian König int *last_invalidated); 130899fbde1SPhilip Yang bool amdgpu_ttm_tt_is_userptr(struct ttm_tt *ttm); 131711becf0SChristian König bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm); 13224a8d289SChristian König uint64_t amdgpu_ttm_tt_pde_flags(struct ttm_tt *ttm, struct ttm_mem_reg *mem); 133711becf0SChristian König uint64_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm, 134711becf0SChristian König struct ttm_mem_reg *mem); 135711becf0SChristian König 136c5820361SAlex Deucher int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev); 137c5820361SAlex Deucher 138c632d799SFlora Cui #endif 139