xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h (revision 994aeacbb3c039b4f3e02e76e6d39407920e76c6)
1d38ceaf9SAlex Deucher /*
2d38ceaf9SAlex Deucher  * Copyright 2008 Advanced Micro Devices, Inc.
3d38ceaf9SAlex Deucher  * Copyright 2008 Red Hat Inc.
4d38ceaf9SAlex Deucher  * Copyright 2009 Jerome Glisse.
5d38ceaf9SAlex Deucher  *
6d38ceaf9SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
7d38ceaf9SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
8d38ceaf9SAlex Deucher  * to deal in the Software without restriction, including without limitation
9d38ceaf9SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10d38ceaf9SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
11d38ceaf9SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
12d38ceaf9SAlex Deucher  *
13d38ceaf9SAlex Deucher  * The above copyright notice and this permission notice shall be included in
14d38ceaf9SAlex Deucher  * all copies or substantial portions of the Software.
15d38ceaf9SAlex Deucher  *
16d38ceaf9SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17d38ceaf9SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18d38ceaf9SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19d38ceaf9SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20d38ceaf9SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21d38ceaf9SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22d38ceaf9SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
23d38ceaf9SAlex Deucher  *
24d38ceaf9SAlex Deucher  * Authors: Dave Airlie
25d38ceaf9SAlex Deucher  *          Alex Deucher
26d38ceaf9SAlex Deucher  *          Jerome Glisse
27d38ceaf9SAlex Deucher  */
28d38ceaf9SAlex Deucher #ifndef __AMDGPU_OBJECT_H__
29d38ceaf9SAlex Deucher #define __AMDGPU_OBJECT_H__
30d38ceaf9SAlex Deucher 
31d38ceaf9SAlex Deucher #include <drm/amdgpu_drm.h>
32d38ceaf9SAlex Deucher #include "amdgpu.h"
332b77ade8SChristian König #include "amdgpu_res_cursor.h"
342b77ade8SChristian König 
3562914a99SJason Gunthorpe #ifdef CONFIG_MMU_NOTIFIER
3662914a99SJason Gunthorpe #include <linux/mmu_notifier.h>
3762914a99SJason Gunthorpe #endif
38d38ceaf9SAlex Deucher 
399702d40dSChristian König #define AMDGPU_BO_INVALID_OFFSET	LONG_MAX
40bf314ca3SChristian König #define AMDGPU_BO_MAX_PLACEMENTS	3
419702d40dSChristian König 
42f04c79cfSAlex Sierra /* BO flag to indicate a KFD userptr BO */
43f04c79cfSAlex Sierra #define AMDGPU_AMDKFD_CREATE_USERPTR_BO	(1ULL << 63)
44f04c79cfSAlex Sierra 
459ad0d033SNirmoy Das #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)
466fdd6f4aSNirmoy Das #define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo)
479ad0d033SNirmoy Das 
48a906dbb1SChunming Zhou struct amdgpu_bo_param {
49a906dbb1SChunming Zhou 	unsigned long			size;
50a906dbb1SChunming Zhou 	int				byte_align;
519fd5543eSNirmoy Das 	u32				bo_ptr_size;
52a906dbb1SChunming Zhou 	u32				domain;
53aa2b2e28SChunming Zhou 	u32				preferred_domain;
54a906dbb1SChunming Zhou 	u64				flags;
55a906dbb1SChunming Zhou 	enum ttm_bo_type		type;
56061468c4SChristian König 	bool				no_wait_gpu;
5752791eeeSChristian König 	struct dma_resv			*resv;
5823e24fbbSNirmoy Das 	void				(*destroy)(struct ttm_buffer_object *bo);
593ebfd221SPhilip Yang 	/* xcp partition number plus 1, 0 means any partition */
603ebfd221SPhilip Yang 	int8_t				xcp_id_plus1;
61a906dbb1SChunming Zhou };
62a906dbb1SChunming Zhou 
63ec681545SChristian König /* bo virtual addresses in a vm */
649124a398SChristian König struct amdgpu_bo_va_mapping {
65aebc5e6fSChristian König 	struct amdgpu_bo_va		*bo_va;
669124a398SChristian König 	struct list_head		list;
679124a398SChristian König 	struct rb_node			rb;
689124a398SChristian König 	uint64_t			start;
699124a398SChristian König 	uint64_t			last;
709124a398SChristian König 	uint64_t			__subtree_last;
719124a398SChristian König 	uint64_t			offset;
729124a398SChristian König 	uint64_t			flags;
739124a398SChristian König };
749124a398SChristian König 
75ec681545SChristian König /* User space allocated BO in a VM */
769124a398SChristian König struct amdgpu_bo_va {
77ec681545SChristian König 	struct amdgpu_vm_bo_base	base;
78ec681545SChristian König 
799124a398SChristian König 	/* protected by bo being reserved */
809124a398SChristian König 	unsigned			ref_count;
819124a398SChristian König 
8200b5cc83SChristian König 	/* all other members protected by the VM PD being reserved */
8300b5cc83SChristian König 	struct dma_fence	        *last_pt_update;
8400b5cc83SChristian König 
859124a398SChristian König 	/* mappings for this bo_va */
869124a398SChristian König 	struct list_head		invalids;
879124a398SChristian König 	struct list_head		valids;
88cb7b6ec2SChristian König 
89cb7b6ec2SChristian König 	/* If the mappings are cleared or filled */
90cb7b6ec2SChristian König 	bool				cleared;
91df399b06Sshaoyunl 
92df399b06Sshaoyunl 	bool				is_xgmi;
93*834368eaSPhilip Yang 
94*834368eaSPhilip Yang 	/*
95*834368eaSPhilip Yang 	 * protected by vm reservation lock
96*834368eaSPhilip Yang 	 * if non-zero, cannot unmap from GPU because user queues may still access it
97*834368eaSPhilip Yang 	 */
98*834368eaSPhilip Yang 	unsigned int			queue_refcount;
999124a398SChristian König };
1009124a398SChristian König 
1019124a398SChristian König struct amdgpu_bo {
1029124a398SChristian König 	/* Protected by tbo.reserved */
1036d7d9c5aSKent Russell 	u32				preferred_domains;
1049124a398SChristian König 	u32				allowed_domains;
105bf314ca3SChristian König 	struct ttm_place		placements[AMDGPU_BO_MAX_PLACEMENTS];
1069124a398SChristian König 	struct ttm_placement		placement;
1079124a398SChristian König 	struct ttm_buffer_object	tbo;
1089124a398SChristian König 	struct ttm_bo_kmap_obj		kmap;
1099124a398SChristian König 	u64				flags;
110646b9025SChristian König 	/* per VM structure for page tables and with virtual addresses */
111646b9025SChristian König 	struct amdgpu_vm_bo_base	*vm_bo;
1129124a398SChristian König 	/* Constant after initialization */
1139124a398SChristian König 	struct amdgpu_bo		*parent;
11462914a99SJason Gunthorpe 
11562914a99SJason Gunthorpe #ifdef CONFIG_MMU_NOTIFIER
11662914a99SJason Gunthorpe 	struct mmu_interval_notifier	notifier;
11762914a99SJason Gunthorpe #endif
118a46a2cd1SFelix Kuehling 	struct kgd_mem                  *kfd_bo;
119f24e924bSPhilip Yang 
1203ebfd221SPhilip Yang 	/*
1213ebfd221SPhilip Yang 	 * For GPUs with spatial partitioning, xcp partition number, -1 means
1223ebfd221SPhilip Yang 	 * any partition. For other ASICs without spatial partition, always 0
1233ebfd221SPhilip Yang 	 * for memory accounting.
1243ebfd221SPhilip Yang 	 */
1253ebfd221SPhilip Yang 	int8_t				xcp_id;
126ed5b89c6SChristian König };
1279124a398SChristian König 
1289ad0d033SNirmoy Das struct amdgpu_bo_user {
1299ad0d033SNirmoy Das 	struct amdgpu_bo		bo;
1309ad0d033SNirmoy Das 	u64				tiling_flags;
1319ad0d033SNirmoy Das 	u64				metadata_flags;
1329ad0d033SNirmoy Das 	void				*metadata;
1339ad0d033SNirmoy Das 	u32				metadata_size;
1349ad0d033SNirmoy Das 
1359ad0d033SNirmoy Das };
1369ad0d033SNirmoy Das 
1376fdd6f4aSNirmoy Das struct amdgpu_bo_vm {
1386fdd6f4aSNirmoy Das 	struct amdgpu_bo		bo;
139391629bdSNirmoy Das 	struct amdgpu_vm_bo_base        entries[];
1406fdd6f4aSNirmoy Das };
1416fdd6f4aSNirmoy Das 
142d6530c33SMarek Olšák struct amdgpu_mem_stats {
143d6530c33SMarek Olšák 	/* current VRAM usage, includes visible VRAM */
144d6530c33SMarek Olšák 	uint64_t vram;
145ba1a58d5SAlex Deucher 	/* current shared VRAM usage, includes visible VRAM */
146ba1a58d5SAlex Deucher 	uint64_t vram_shared;
147d6530c33SMarek Olšák 	/* current visible VRAM usage */
148d6530c33SMarek Olšák 	uint64_t visible_vram;
149d6530c33SMarek Olšák 	/* current GTT usage */
150d6530c33SMarek Olšák 	uint64_t gtt;
151ba1a58d5SAlex Deucher 	/* current shared GTT usage */
152ba1a58d5SAlex Deucher 	uint64_t gtt_shared;
153d6530c33SMarek Olšák 	/* current system memory usage */
154d6530c33SMarek Olšák 	uint64_t cpu;
155ba1a58d5SAlex Deucher 	/* current shared system memory usage */
156ba1a58d5SAlex Deucher 	uint64_t cpu_shared;
157d6530c33SMarek Olšák 	/* sum of evicted buffers, includes visible VRAM */
158d6530c33SMarek Olšák 	uint64_t evicted_vram;
159d6530c33SMarek Olšák 	/* sum of evicted buffers due to CPU access */
160d6530c33SMarek Olšák 	uint64_t evicted_visible_vram;
161d6530c33SMarek Olšák 	/* how much userspace asked for, includes vis.VRAM */
162d6530c33SMarek Olšák 	uint64_t requested_vram;
163d6530c33SMarek Olšák 	/* how much userspace asked for */
164d6530c33SMarek Olšák 	uint64_t requested_visible_vram;
165d6530c33SMarek Olšák 	/* how much userspace asked for */
166d6530c33SMarek Olšák 	uint64_t requested_gtt;
167d6530c33SMarek Olšák };
168d6530c33SMarek Olšák 
ttm_to_amdgpu_bo(struct ttm_buffer_object * tbo)169b82485fdSAndres Rodriguez static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
170b82485fdSAndres Rodriguez {
171b82485fdSAndres Rodriguez 	return container_of(tbo, struct amdgpu_bo, tbo);
172b82485fdSAndres Rodriguez }
173b82485fdSAndres Rodriguez 
174d38ceaf9SAlex Deucher /**
175d38ceaf9SAlex Deucher  * amdgpu_mem_type_to_domain - return domain corresponding to mem_type
176d38ceaf9SAlex Deucher  * @mem_type:	ttm memory type
177d38ceaf9SAlex Deucher  *
178d38ceaf9SAlex Deucher  * Returns corresponding domain of the ttm mem_type
179d38ceaf9SAlex Deucher  */
amdgpu_mem_type_to_domain(u32 mem_type)180d38ceaf9SAlex Deucher static inline unsigned amdgpu_mem_type_to_domain(u32 mem_type)
181d38ceaf9SAlex Deucher {
182d38ceaf9SAlex Deucher 	switch (mem_type) {
183d38ceaf9SAlex Deucher 	case TTM_PL_VRAM:
184d38ceaf9SAlex Deucher 		return AMDGPU_GEM_DOMAIN_VRAM;
185d38ceaf9SAlex Deucher 	case TTM_PL_TT:
186d38ceaf9SAlex Deucher 		return AMDGPU_GEM_DOMAIN_GTT;
187d38ceaf9SAlex Deucher 	case TTM_PL_SYSTEM:
188d38ceaf9SAlex Deucher 		return AMDGPU_GEM_DOMAIN_CPU;
189d38ceaf9SAlex Deucher 	case AMDGPU_PL_GDS:
190d38ceaf9SAlex Deucher 		return AMDGPU_GEM_DOMAIN_GDS;
191d38ceaf9SAlex Deucher 	case AMDGPU_PL_GWS:
192d38ceaf9SAlex Deucher 		return AMDGPU_GEM_DOMAIN_GWS;
193d38ceaf9SAlex Deucher 	case AMDGPU_PL_OA:
194d38ceaf9SAlex Deucher 		return AMDGPU_GEM_DOMAIN_OA;
195dc3499c7SAlex Deucher 	case AMDGPU_PL_DOORBELL:
196dc3499c7SAlex Deucher 		return AMDGPU_GEM_DOMAIN_DOORBELL;
197d38ceaf9SAlex Deucher 	default:
198d38ceaf9SAlex Deucher 		break;
199d38ceaf9SAlex Deucher 	}
200d38ceaf9SAlex Deucher 	return 0;
201d38ceaf9SAlex Deucher }
202d38ceaf9SAlex Deucher 
203d38ceaf9SAlex Deucher /**
204d38ceaf9SAlex Deucher  * amdgpu_bo_reserve - reserve bo
205d38ceaf9SAlex Deucher  * @bo:		bo structure
206d38ceaf9SAlex Deucher  * @no_intr:	don't return -ERESTARTSYS on pending signal
207d38ceaf9SAlex Deucher  *
208d38ceaf9SAlex Deucher  * Returns:
209d38ceaf9SAlex Deucher  * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
210d38ceaf9SAlex Deucher  * a signal. Release all buffer reservations and return to user-space.
211d38ceaf9SAlex Deucher  */
amdgpu_bo_reserve(struct amdgpu_bo * bo,bool no_intr)212d38ceaf9SAlex Deucher static inline int amdgpu_bo_reserve(struct amdgpu_bo *bo, bool no_intr)
213d38ceaf9SAlex Deucher {
214a7d64de6SChristian König 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
215d38ceaf9SAlex Deucher 	int r;
216d38ceaf9SAlex Deucher 
21746bca88bSDave Airlie 	r = ttm_bo_reserve(&bo->tbo, !no_intr, false, NULL);
218d38ceaf9SAlex Deucher 	if (unlikely(r != 0)) {
219d38ceaf9SAlex Deucher 		if (r != -ERESTARTSYS)
220a7d64de6SChristian König 			dev_err(adev->dev, "%p reserve failed\n", bo);
221d38ceaf9SAlex Deucher 		return r;
222d38ceaf9SAlex Deucher 	}
223d38ceaf9SAlex Deucher 	return 0;
224d38ceaf9SAlex Deucher }
225d38ceaf9SAlex Deucher 
amdgpu_bo_unreserve(struct amdgpu_bo * bo)226d38ceaf9SAlex Deucher static inline void amdgpu_bo_unreserve(struct amdgpu_bo *bo)
227d38ceaf9SAlex Deucher {
228d38ceaf9SAlex Deucher 	ttm_bo_unreserve(&bo->tbo);
229d38ceaf9SAlex Deucher }
230d38ceaf9SAlex Deucher 
amdgpu_bo_size(struct amdgpu_bo * bo)231d38ceaf9SAlex Deucher static inline unsigned long amdgpu_bo_size(struct amdgpu_bo *bo)
232d38ceaf9SAlex Deucher {
233e11bfb99SChristian König 	return bo->tbo.base.size;
234d38ceaf9SAlex Deucher }
235d38ceaf9SAlex Deucher 
amdgpu_bo_ngpu_pages(struct amdgpu_bo * bo)236d38ceaf9SAlex Deucher static inline unsigned amdgpu_bo_ngpu_pages(struct amdgpu_bo *bo)
237d38ceaf9SAlex Deucher {
238e11bfb99SChristian König 	return bo->tbo.base.size / AMDGPU_GPU_PAGE_SIZE;
239d38ceaf9SAlex Deucher }
240d38ceaf9SAlex Deucher 
amdgpu_bo_gpu_page_alignment(struct amdgpu_bo * bo)241d38ceaf9SAlex Deucher static inline unsigned amdgpu_bo_gpu_page_alignment(struct amdgpu_bo *bo)
242d38ceaf9SAlex Deucher {
243c777dc9eSChristian König 	return (bo->tbo.page_alignment << PAGE_SHIFT) / AMDGPU_GPU_PAGE_SIZE;
244d38ceaf9SAlex Deucher }
245d38ceaf9SAlex Deucher 
246d38ceaf9SAlex Deucher /**
247d38ceaf9SAlex Deucher  * amdgpu_bo_mmap_offset - return mmap offset of bo
248d38ceaf9SAlex Deucher  * @bo:	amdgpu object for which we query the offset
249d38ceaf9SAlex Deucher  *
250d38ceaf9SAlex Deucher  * Returns mmap offset of the object.
251d38ceaf9SAlex Deucher  */
amdgpu_bo_mmap_offset(struct amdgpu_bo * bo)252d38ceaf9SAlex Deucher static inline u64 amdgpu_bo_mmap_offset(struct amdgpu_bo *bo)
253d38ceaf9SAlex Deucher {
254b96f3e7cSGerd Hoffmann 	return drm_vma_node_offset_addr(&bo->tbo.base.vma_node);
255d38ceaf9SAlex Deucher }
256d38ceaf9SAlex Deucher 
257b99f3103SNicolai Hähnle /**
258177ae09bSAndres Rodriguez  * amdgpu_bo_explicit_sync - return whether the bo is explicitly synced
259177ae09bSAndres Rodriguez  */
amdgpu_bo_explicit_sync(struct amdgpu_bo * bo)260177ae09bSAndres Rodriguez static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)
261177ae09bSAndres Rodriguez {
262177ae09bSAndres Rodriguez 	return bo->flags & AMDGPU_GEM_CREATE_EXPLICIT_SYNC;
263177ae09bSAndres Rodriguez }
264177ae09bSAndres Rodriguez 
2654cd24494SAlex Deucher /**
2664cd24494SAlex Deucher  * amdgpu_bo_encrypted - test if the BO is encrypted
2674cd24494SAlex Deucher  * @bo: pointer to a buffer object
2684cd24494SAlex Deucher  *
2694cd24494SAlex Deucher  * Return true if the buffer object is encrypted, false otherwise.
2704cd24494SAlex Deucher  */
amdgpu_bo_encrypted(struct amdgpu_bo * bo)2714cd24494SAlex Deucher static inline bool amdgpu_bo_encrypted(struct amdgpu_bo *bo)
2724cd24494SAlex Deucher {
2734cd24494SAlex Deucher 	return bo->flags & AMDGPU_GEM_CREATE_ENCRYPTED;
2744cd24494SAlex Deucher }
2754cd24494SAlex Deucher 
276c704ab18SChristian König bool amdgpu_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
277c704ab18SChristian König void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain);
278c704ab18SChristian König 
2793216c6b7SChunming Zhou int amdgpu_bo_create(struct amdgpu_device *adev,
2803216c6b7SChunming Zhou 		     struct amdgpu_bo_param *bp,
281d38ceaf9SAlex Deucher 		     struct amdgpu_bo **bo_ptr);
2829d903cbdSChristian König int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
2839d903cbdSChristian König 			      unsigned long size, int align,
2849d903cbdSChristian König 			      u32 domain, struct amdgpu_bo **bo_ptr,
2859d903cbdSChristian König 			      u64 *gpu_addr, void **cpu_addr);
2867c204889SChristian König int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
2877c204889SChristian König 			    unsigned long size, int align,
2887c204889SChristian König 			    u32 domain, struct amdgpu_bo **bo_ptr,
2897c204889SChristian König 			    u64 *gpu_addr, void **cpu_addr);
290de7b45baSChristian König int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
2913273f116SLuben Tuikov 			       uint64_t offset, uint64_t size,
292de7b45baSChristian König 			       struct amdgpu_bo **bo_ptr, void **cpu_addr);
2939ad0d033SNirmoy Das int amdgpu_bo_create_user(struct amdgpu_device *adev,
2949ad0d033SNirmoy Das 			  struct amdgpu_bo_param *bp,
2959ad0d033SNirmoy Das 			  struct amdgpu_bo_user **ubo_ptr);
2966fdd6f4aSNirmoy Das int amdgpu_bo_create_vm(struct amdgpu_device *adev,
2976fdd6f4aSNirmoy Das 			struct amdgpu_bo_param *bp,
2986fdd6f4aSNirmoy Das 			struct amdgpu_bo_vm **ubo_ptr);
299aa1d562eSJunwei Zhang void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
300aa1d562eSJunwei Zhang 			   void **cpu_addr);
301d38ceaf9SAlex Deucher int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
302f5e1c740SChristian König void *amdgpu_bo_kptr(struct amdgpu_bo *bo);
303d38ceaf9SAlex Deucher void amdgpu_bo_kunmap(struct amdgpu_bo *bo);
304d38ceaf9SAlex Deucher struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo);
305d38ceaf9SAlex Deucher void amdgpu_bo_unref(struct amdgpu_bo **bo);
3067b7c6c81SJunwei Zhang int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain);
3074671078eSChristian König void amdgpu_bo_unpin(struct amdgpu_bo *bo);
308d38ceaf9SAlex Deucher int amdgpu_bo_init(struct amdgpu_device *adev);
309d38ceaf9SAlex Deucher void amdgpu_bo_fini(struct amdgpu_device *adev);
310d38ceaf9SAlex Deucher int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags);
311d38ceaf9SAlex Deucher void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags);
312d38ceaf9SAlex Deucher int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
313d38ceaf9SAlex Deucher 			    uint32_t metadata_size, uint64_t flags);
314d38ceaf9SAlex Deucher int amdgpu_bo_get_metadata(struct amdgpu_bo *bo, void *buffer,
315d38ceaf9SAlex Deucher 			   size_t buffer_size, uint32_t *metadata_size,
316d38ceaf9SAlex Deucher 			   uint64_t *flags);
317d3a9331aSChristian König void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
318d3a9331aSChristian König 			   bool evict,
319d3a9331aSChristian König 			   struct ttm_resource *new_mem);
320ab2f7a5cSFelix Kuehling void amdgpu_bo_release_notify(struct ttm_buffer_object *bo);
321d3ef581aSChristian König vm_fault_t amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
322f54d1867SChris Wilson void amdgpu_bo_fence(struct amdgpu_bo *bo, struct dma_fence *fence,
323d38ceaf9SAlex Deucher 		     bool shared);
3249f3cc18dSChristian König int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv,
3259f3cc18dSChristian König 			     enum amdgpu_sync_mode sync_mode, void *owner,
3269f3cc18dSChristian König 			     bool intr);
327e8e32426SFelix Kuehling int amdgpu_bo_sync_wait(struct amdgpu_bo *bo, void *owner, bool intr);
328cdb7e8f2SChristian König u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo);
329b1a8ef95SNirmoy Das u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo);
330d6530c33SMarek Olšák void amdgpu_bo_get_memory(struct amdgpu_bo *bo,
331d6530c33SMarek Olšák 			  struct amdgpu_mem_stats *stats);
332d035f84dSYifan Zhang uint32_t amdgpu_bo_get_preferred_domain(struct amdgpu_device *adev,
33384b74608SDeepak Sharma 					    uint32_t domain);
334d38ceaf9SAlex Deucher 
335d38ceaf9SAlex Deucher /*
336d38ceaf9SAlex Deucher  * sub allocation
337d38ceaf9SAlex Deucher  */
338c103a23fSMaarten Lankhorst static inline struct amdgpu_sa_manager *
to_amdgpu_sa_manager(struct drm_suballoc_manager * manager)339c103a23fSMaarten Lankhorst to_amdgpu_sa_manager(struct drm_suballoc_manager *manager)
340d38ceaf9SAlex Deucher {
341c103a23fSMaarten Lankhorst 	return container_of(manager, struct amdgpu_sa_manager, base);
342d38ceaf9SAlex Deucher }
343d38ceaf9SAlex Deucher 
amdgpu_sa_bo_gpu_addr(struct drm_suballoc * sa_bo)344c103a23fSMaarten Lankhorst static inline uint64_t amdgpu_sa_bo_gpu_addr(struct drm_suballoc *sa_bo)
345d38ceaf9SAlex Deucher {
346c103a23fSMaarten Lankhorst 	return to_amdgpu_sa_manager(sa_bo->manager)->gpu_addr +
347c103a23fSMaarten Lankhorst 		drm_suballoc_soffset(sa_bo);
348c103a23fSMaarten Lankhorst }
349c103a23fSMaarten Lankhorst 
amdgpu_sa_bo_cpu_addr(struct drm_suballoc * sa_bo)350c103a23fSMaarten Lankhorst static inline void *amdgpu_sa_bo_cpu_addr(struct drm_suballoc *sa_bo)
351c103a23fSMaarten Lankhorst {
352c103a23fSMaarten Lankhorst 	return to_amdgpu_sa_manager(sa_bo->manager)->cpu_ptr +
353c103a23fSMaarten Lankhorst 		drm_suballoc_soffset(sa_bo);
354d38ceaf9SAlex Deucher }
355d38ceaf9SAlex Deucher 
356d38ceaf9SAlex Deucher int amdgpu_sa_bo_manager_init(struct amdgpu_device *adev,
357d38ceaf9SAlex Deucher 				     struct amdgpu_sa_manager *sa_manager,
358d38ceaf9SAlex Deucher 				     unsigned size, u32 align, u32 domain);
359d38ceaf9SAlex Deucher void amdgpu_sa_bo_manager_fini(struct amdgpu_device *adev,
360d38ceaf9SAlex Deucher 				      struct amdgpu_sa_manager *sa_manager);
361d38ceaf9SAlex Deucher int amdgpu_sa_bo_manager_start(struct amdgpu_device *adev,
362d38ceaf9SAlex Deucher 				      struct amdgpu_sa_manager *sa_manager);
363bbf0b345SJunwei Zhang int amdgpu_sa_bo_new(struct amdgpu_sa_manager *sa_manager,
364c103a23fSMaarten Lankhorst 		     struct drm_suballoc **sa_bo,
365c103a23fSMaarten Lankhorst 		     unsigned int size);
366d38ceaf9SAlex Deucher void amdgpu_sa_bo_free(struct amdgpu_device *adev,
367c103a23fSMaarten Lankhorst 		       struct drm_suballoc **sa_bo,
368f54d1867SChris Wilson 		       struct dma_fence *fence);
369d38ceaf9SAlex Deucher #if defined(CONFIG_DEBUG_FS)
370d38ceaf9SAlex Deucher void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager,
371d38ceaf9SAlex Deucher 					 struct seq_file *m);
372ff72bc40SMihir Bhogilal Patel u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m);
373d38ceaf9SAlex Deucher #endif
37498d28ac2SNirmoy Das void amdgpu_debugfs_sa_init(struct amdgpu_device *adev);
375d38ceaf9SAlex Deucher 
3763d1b8ec7SAndrey Grodzovsky bool amdgpu_bo_support_uswc(u64 bo_flags);
3773d1b8ec7SAndrey Grodzovsky 
378d38ceaf9SAlex Deucher 
379d38ceaf9SAlex Deucher #endif
380