xref: /openbmc/linux/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1770d13b1SChristian König /*
2770d13b1SChristian König  * Copyright 2018 Advanced Micro Devices, Inc.
3770d13b1SChristian König  * All Rights Reserved.
4770d13b1SChristian König  *
5770d13b1SChristian König  * Permission is hereby granted, free of charge, to any person obtaining a
6770d13b1SChristian König  * copy of this software and associated documentation files (the
7770d13b1SChristian König  * "Software"), to deal in the Software without restriction, including
8770d13b1SChristian König  * without limitation the rights to use, copy, modify, merge, publish,
9770d13b1SChristian König  * distribute, sub license, and/or sell copies of the Software, and to
10770d13b1SChristian König  * permit persons to whom the Software is furnished to do so, subject to
11770d13b1SChristian König  * the following conditions:
12770d13b1SChristian König  *
13770d13b1SChristian König  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14770d13b1SChristian König  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15770d13b1SChristian König  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16770d13b1SChristian König  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17770d13b1SChristian König  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18770d13b1SChristian König  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19770d13b1SChristian König  * USE OR OTHER DEALINGS IN THE SOFTWARE.
20770d13b1SChristian König  *
21770d13b1SChristian König  * The above copyright notice and this permission notice (including the
22770d13b1SChristian König  * next paragraph) shall be included in all copies or substantial portions
23770d13b1SChristian König  * of the Software.
24770d13b1SChristian König  *
25770d13b1SChristian König  */
26770d13b1SChristian König #ifndef __AMDGPU_GMC_H__
27770d13b1SChristian König #define __AMDGPU_GMC_H__
28770d13b1SChristian König 
29770d13b1SChristian König #include <linux/types.h>
30770d13b1SChristian König 
31770d13b1SChristian König #include "amdgpu_irq.h"
326c245386Syipechai #include "amdgpu_ras.h"
33770d13b1SChristian König 
34ad9a5b78SChristian König /* VA hole for 48bit addresses on Vega10 */
35ad9a5b78SChristian König #define AMDGPU_GMC_HOLE_START	0x0000800000000000ULL
36ad9a5b78SChristian König #define AMDGPU_GMC_HOLE_END	0xffff800000000000ULL
37ad9a5b78SChristian König 
38ad9a5b78SChristian König /*
39ad9a5b78SChristian König  * Hardware is programmed as if the hole doesn't exists with start and end
40ad9a5b78SChristian König  * address values.
41ad9a5b78SChristian König  *
42ad9a5b78SChristian König  * This mask is used to remove the upper 16bits of the VA and so come up with
43ad9a5b78SChristian König  * the linear addr value.
44ad9a5b78SChristian König  */
45ad9a5b78SChristian König #define AMDGPU_GMC_HOLE_MASK	0x0000ffffffffffffULL
46ad9a5b78SChristian König 
47c1a8abd9SChristian König /*
48c1a8abd9SChristian König  * Ring size as power of two for the log of recent faults.
49c1a8abd9SChristian König  */
50c1a8abd9SChristian König #define AMDGPU_GMC_FAULT_RING_ORDER	8
51c1a8abd9SChristian König #define AMDGPU_GMC_FAULT_RING_SIZE	(1 << AMDGPU_GMC_FAULT_RING_ORDER)
52c1a8abd9SChristian König 
53c1a8abd9SChristian König /*
54c1a8abd9SChristian König  * Hash size as power of two for the log of recent faults
55c1a8abd9SChristian König  */
56c1a8abd9SChristian König #define AMDGPU_GMC_FAULT_HASH_ORDER	8
57c1a8abd9SChristian König #define AMDGPU_GMC_FAULT_HASH_SIZE	(1 << AMDGPU_GMC_FAULT_HASH_ORDER)
58c1a8abd9SChristian König 
59c1a8abd9SChristian König /*
60c1a8abd9SChristian König  * Number of IH timestamp ticks until a fault is considered handled
61c1a8abd9SChristian König  */
62c1a8abd9SChristian König #define AMDGPU_GMC_FAULT_TIMEOUT	5000ULL
63c1a8abd9SChristian König 
64770d13b1SChristian König struct firmware;
65770d13b1SChristian König 
66b6f90baaSLijo Lazar enum amdgpu_memory_partition {
67b6f90baaSLijo Lazar 	UNKNOWN_MEMORY_PARTITION_MODE = 0,
68b6f90baaSLijo Lazar 	AMDGPU_NPS1_PARTITION_MODE = 1,
69b6f90baaSLijo Lazar 	AMDGPU_NPS2_PARTITION_MODE = 2,
70b6f90baaSLijo Lazar 	AMDGPU_NPS3_PARTITION_MODE = 3,
71b6f90baaSLijo Lazar 	AMDGPU_NPS4_PARTITION_MODE = 4,
72b6f90baaSLijo Lazar 	AMDGPU_NPS6_PARTITION_MODE = 6,
73b6f90baaSLijo Lazar 	AMDGPU_NPS8_PARTITION_MODE = 8,
74b6f90baaSLijo Lazar };
75b6f90baaSLijo Lazar 
76770d13b1SChristian König /*
77c1a8abd9SChristian König  * GMC page fault information
78c1a8abd9SChristian König  */
79c1a8abd9SChristian König struct amdgpu_gmc_fault {
8036255b5fSPhilip Yang 	uint64_t	timestamp:48;
81c1a8abd9SChristian König 	uint64_t	next:AMDGPU_GMC_FAULT_RING_ORDER;
8236255b5fSPhilip Yang 	atomic64_t	key;
83dd299441SMukul Joshi 	uint64_t	timestamp_expiry:48;
84c1a8abd9SChristian König };
85c1a8abd9SChristian König 
86c1a8abd9SChristian König /*
87770d13b1SChristian König  * VMHUB structures, functions & helpers
88770d13b1SChristian König  */
892577db91SHuang Rui struct amdgpu_vmhub_funcs {
902577db91SHuang Rui 	void (*print_l2_protection_fault_status)(struct amdgpu_device *adev,
912577db91SHuang Rui 						 uint32_t status);
92caa9f483SHuang Rui 	uint32_t (*get_invalidate_req)(unsigned int vmid, uint32_t flush_type);
932577db91SHuang Rui };
942577db91SHuang Rui 
95770d13b1SChristian König struct amdgpu_vmhub {
96770d13b1SChristian König 	uint32_t	ctx0_ptb_addr_lo32;
97770d13b1SChristian König 	uint32_t	ctx0_ptb_addr_hi32;
986c2c8972Schangzhu 	uint32_t	vm_inv_eng0_sem;
99770d13b1SChristian König 	uint32_t	vm_inv_eng0_req;
100770d13b1SChristian König 	uint32_t	vm_inv_eng0_ack;
101770d13b1SChristian König 	uint32_t	vm_context0_cntl;
102770d13b1SChristian König 	uint32_t	vm_l2_pro_fault_status;
103770d13b1SChristian König 	uint32_t	vm_l2_pro_fault_cntl;
1041f9d56c3SHuang Rui 
1051f9d56c3SHuang Rui 	/*
1061f9d56c3SHuang Rui 	 * store the register distances between two continuous context domain
1071f9d56c3SHuang Rui 	 * and invalidation engine.
1081f9d56c3SHuang Rui 	 */
1091f9d56c3SHuang Rui 	uint32_t	ctx_distance;
1101f9d56c3SHuang Rui 	uint32_t	ctx_addr_distance; /* include LO32/HI32 */
1111f9d56c3SHuang Rui 	uint32_t	eng_distance;
1121f9d56c3SHuang Rui 	uint32_t	eng_addr_distance; /* include LO32/HI32 */
1135befb6fcSHuang Rui 
114d7dab4fcSJack Xiao 	uint32_t        vm_cntx_cntl;
1155befb6fcSHuang Rui 	uint32_t	vm_cntx_cntl_vm_fault;
11698a0f868STianci.Yin 	uint32_t	vm_l2_bank_select_reserved_cid2;
1172577db91SHuang Rui 
118057e335cSYifan Zha 	uint32_t	vm_contexts_disable;
119057e335cSYifan Zha 
1202577db91SHuang Rui 	const struct amdgpu_vmhub_funcs *vmhub_funcs;
121770d13b1SChristian König };
122770d13b1SChristian König 
123770d13b1SChristian König /*
124770d13b1SChristian König  * GPU MC structures, functions & helpers
125770d13b1SChristian König  */
126132f34e4SChristian König struct amdgpu_gmc_funcs {
127132f34e4SChristian König 	/* flush the vm tlb via mmio */
1283ff98548SOak Zeng 	void (*flush_gpu_tlb)(struct amdgpu_device *adev, uint32_t vmid,
1293ff98548SOak Zeng 				uint32_t vmhub, uint32_t flush_type);
130ea930000SAlex Sierra 	/* flush the vm tlb via pasid */
131ea930000SAlex Sierra 	int (*flush_gpu_tlb_pasid)(struct amdgpu_device *adev, uint16_t pasid,
132f87f6864SMukul Joshi 					uint32_t flush_type, bool all_hub,
133f87f6864SMukul Joshi 					uint32_t inst);
1347ef11047SChristian König 	/* flush the vm tlb via ring */
1357ef11047SChristian König 	uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
136c633c00bSChristian König 				       uint64_t pd_addr);
137c633c00bSChristian König 	/* Change the VMID -> PASID mapping */
138c633c00bSChristian König 	void (*emit_pasid_mapping)(struct amdgpu_ring *ring, unsigned vmid,
139c633c00bSChristian König 				   unsigned pasid);
140132f34e4SChristian König 	/* enable/disable PRT support */
141132f34e4SChristian König 	void (*set_prt)(struct amdgpu_device *adev, bool enable);
14271776b6dSChristian König 	/* map mtype to hardware flags */
14371776b6dSChristian König 	uint64_t (*map_mtype)(struct amdgpu_device *adev, uint32_t flags);
144132f34e4SChristian König 	/* get the pde for a given mc addr */
145132f34e4SChristian König 	void (*get_vm_pde)(struct amdgpu_device *adev, int level,
146132f34e4SChristian König 			   u64 *dst, u64 *flags);
147cbfae36cSChristian König 	/* get the pte flags to use for a BO VA mapping */
148cbfae36cSChristian König 	void (*get_vm_pte)(struct amdgpu_device *adev,
149cbfae36cSChristian König 			   struct amdgpu_bo_va_mapping *mapping,
150cbfae36cSChristian König 			   uint64_t *flags);
151352b919cSFelix Kuehling 	/* override per-page pte flags */
152352b919cSFelix Kuehling 	void (*override_vm_pte_flags)(struct amdgpu_device *dev,
153352b919cSFelix Kuehling 				      struct amdgpu_vm *vm,
154352b919cSFelix Kuehling 				      uint64_t addr, uint64_t *flags);
155dd285c5dSAlex Deucher 	/* get the amount of memory used by the vbios for pre-OS console */
156dd285c5dSAlex Deucher 	unsigned int (*get_vbios_fb_size)(struct amdgpu_device *adev);
157b6f90baaSLijo Lazar 
158b6f90baaSLijo Lazar 	enum amdgpu_memory_partition (*query_mem_partition_mode)(
159b6f90baaSLijo Lazar 		struct amdgpu_device *adev);
160132f34e4SChristian König };
161132f34e4SChristian König 
1626c245386Syipechai struct amdgpu_xgmi_ras {
1636c245386Syipechai 	struct amdgpu_ras_block_object ras_block;
16452137ca8SHawking Zhang };
16552137ca8SHawking Zhang 
16676a5b367SAlex Deucher struct amdgpu_xgmi {
16776a5b367SAlex Deucher 	/* from psp */
168dd3c45d3SHawking Zhang 	u64 node_id;
16976a5b367SAlex Deucher 	u64 hive_id;
17076a5b367SAlex Deucher 	/* fixed per family */
17176a5b367SAlex Deucher 	u64 node_segment_size;
17276a5b367SAlex Deucher 	/* physical node (0-3) */
17376a5b367SAlex Deucher 	unsigned physical_node_id;
17476a5b367SAlex Deucher 	/* number of nodes (0-4) */
17576a5b367SAlex Deucher 	unsigned num_physical_nodes;
176fb30fc59SShaoyun Liu 	/* gpu list in the same hive */
177fb30fc59SShaoyun Liu 	struct list_head head;
17847622ba0SAlex Deucher 	bool supported;
179029fbd43SHawking Zhang 	struct ras_common_if *ras_if;
18031691b8dSRajneesh Bhardwaj 	bool connected_to_cpu;
181e3c1b071Sshaoyunl 	bool pending_reset;
1826c245386Syipechai 	struct amdgpu_xgmi_ras *ras;
18376a5b367SAlex Deucher };
18476a5b367SAlex Deucher 
18514493cb9SLijo Lazar struct amdgpu_mem_partition_info {
18614493cb9SLijo Lazar 	union {
18714493cb9SLijo Lazar 		struct {
18814493cb9SLijo Lazar 			uint32_t fpfn;
18914493cb9SLijo Lazar 			uint32_t lpfn;
19014493cb9SLijo Lazar 		} range;
19114493cb9SLijo Lazar 		struct {
19214493cb9SLijo Lazar 			int node;
19314493cb9SLijo Lazar 		} numa;
19414493cb9SLijo Lazar 	};
19514493cb9SLijo Lazar 	uint64_t size;
19614493cb9SLijo Lazar };
19714493cb9SLijo Lazar 
19814493cb9SLijo Lazar #define INVALID_PFN    -1
19914493cb9SLijo Lazar 
200770d13b1SChristian König struct amdgpu_gmc {
201f6baa074SOak Zeng 	/* FB's physical address in MMIO space (for CPU to
202f6baa074SOak Zeng 	 * map FB). This is different compared to the agp/
203f6baa074SOak Zeng 	 * gart/vram_start/end field as the later is from
204f6baa074SOak Zeng 	 * GPU's view and aper_base is from CPU's view.
205f6baa074SOak Zeng 	 */
206770d13b1SChristian König 	resource_size_t		aper_size;
207770d13b1SChristian König 	resource_size_t		aper_base;
208770d13b1SChristian König 	/* for some chips with <= 32MB we need to lie
209770d13b1SChristian König 	 * about vram size near mc fb location */
210770d13b1SChristian König 	u64			mc_vram_size;
211770d13b1SChristian König 	u64			visible_vram_size;
212f6baa074SOak Zeng 	/* AGP aperture start and end in MC address space
213f6baa074SOak Zeng 	 * Driver find a hole in the MC address space
214f6baa074SOak Zeng 	 * to place AGP by setting MC_VM_AGP_BOT/TOP registers
215f6baa074SOak Zeng 	 * Under VMID0, logical address == MC address. AGP
216f6baa074SOak Zeng 	 * aperture maps to physical bus or IOVA addressed.
217f6baa074SOak Zeng 	 * AGP aperture is used to simulate FB in ZFB case.
218f6baa074SOak Zeng 	 * AGP aperture is also used for page table in system
219f6baa074SOak Zeng 	 * memory (mainly for APU).
220f6baa074SOak Zeng 	 *
221f6baa074SOak Zeng 	 */
222d76364fcSChristian König 	u64			agp_size;
223d76364fcSChristian König 	u64			agp_start;
224d76364fcSChristian König 	u64			agp_end;
225f6baa074SOak Zeng 	/* GART aperture start and end in MC address space
226f6baa074SOak Zeng 	 * Driver find a hole in the MC address space
227f6baa074SOak Zeng 	 * to place GART by setting VM_CONTEXT0_PAGE_TABLE_START/END_ADDR
228f6baa074SOak Zeng 	 * registers
229f6baa074SOak Zeng 	 * Under VMID0, logical address inside GART aperture will
230f6baa074SOak Zeng 	 * be translated through gpuvm gart page table to access
231f6baa074SOak Zeng 	 * paged system memory
232f6baa074SOak Zeng 	 */
233770d13b1SChristian König 	u64			gart_size;
234770d13b1SChristian König 	u64			gart_start;
235770d13b1SChristian König 	u64			gart_end;
236f6baa074SOak Zeng 	/* Frame buffer aperture of this GPU device. Different from
237f6baa074SOak Zeng 	 * fb_start (see below), this only covers the local GPU device.
238be0478e7SOak Zeng 	 * If driver uses FB aperture to access FB, driver get fb_start from
2396e93ef8bSOak Zeng 	 * MC_VM_FB_LOCATION_BASE (set by vbios) and calculate vram_start
2406e93ef8bSOak Zeng 	 * of this local device by adding an offset inside the XGMI hive.
241be0478e7SOak Zeng 	 * If driver uses GART table for VMID0 FB access, driver finds a hole in
2426e93ef8bSOak Zeng 	 * VMID0's virtual address space to place the SYSVM aperture inside
2436e93ef8bSOak Zeng 	 * which the first part is vram and the second part is gart (covering
244be0478e7SOak Zeng 	 * system ram).
245f6baa074SOak Zeng 	 */
246770d13b1SChristian König 	u64			vram_start;
247770d13b1SChristian König 	u64			vram_end;
2486fdd68b1SAlex Deucher 	/* FB region , it's same as local vram region in single GPU, in XGMI
2496fdd68b1SAlex Deucher 	 * configuration, this region covers all GPUs in the same hive ,
2506fdd68b1SAlex Deucher 	 * each GPU in the hive has the same view of this FB region .
2516fdd68b1SAlex Deucher 	 * GPU0's vram starts at offset (0 * segment size) ,
2526fdd68b1SAlex Deucher 	 * GPU1 starts at offset (1 * segment size), etc.
2536fdd68b1SAlex Deucher 	 */
2546fdd68b1SAlex Deucher 	u64			fb_start;
2556fdd68b1SAlex Deucher 	u64			fb_end;
256770d13b1SChristian König 	unsigned		vram_width;
257770d13b1SChristian König 	u64			real_vram_size;
258770d13b1SChristian König 	int			vram_mtrr;
259770d13b1SChristian König 	u64                     mc_mask;
260770d13b1SChristian König 	const struct firmware   *fw;	/* MC firmware */
261770d13b1SChristian König 	uint32_t                fw_version;
262770d13b1SChristian König 	struct amdgpu_irq_src	vm_fault;
263770d13b1SChristian König 	uint32_t		vram_type;
264ad02e08eSOri Messinger 	uint8_t			vram_vendor;
265770d13b1SChristian König 	uint32_t                srbm_soft_reset;
266770d13b1SChristian König 	bool			prt_warning;
267c2ecd79bSShirish S 	uint32_t		sdpif_register;
268770d13b1SChristian König 	/* apertures */
269770d13b1SChristian König 	u64			shared_aperture_start;
270770d13b1SChristian König 	u64			shared_aperture_end;
271770d13b1SChristian König 	u64			private_aperture_start;
272770d13b1SChristian König 	u64			private_aperture_end;
273770d13b1SChristian König 	/* protects concurrent invalidation */
274770d13b1SChristian König 	spinlock_t		invalidate_lock;
275770d13b1SChristian König 	bool			translate_further;
276b97dfa27Sshaoyunl 	struct kfd_vm_fault_info *vm_fault_info;
277b97dfa27Sshaoyunl 	atomic_t		vm_fault_info_updated;
278132f34e4SChristian König 
279c1a8abd9SChristian König 	struct amdgpu_gmc_fault	fault_ring[AMDGPU_GMC_FAULT_RING_SIZE];
280c1a8abd9SChristian König 	struct {
281c1a8abd9SChristian König 		uint64_t	idx:AMDGPU_GMC_FAULT_RING_ORDER;
282c1a8abd9SChristian König 	} fault_hash[AMDGPU_GMC_FAULT_HASH_SIZE];
283c1a8abd9SChristian König 	uint64_t		last_fault:AMDGPU_GMC_FAULT_RING_ORDER;
284c1a8abd9SChristian König 
285c6252390SLuben Tuikov 	bool tmz_enabled;
286497db7eaSRajneesh Bhardwaj 	bool is_app_apu;
287c6252390SLuben Tuikov 
28814493cb9SLijo Lazar 	struct amdgpu_mem_partition_info *mem_partitions;
28914493cb9SLijo Lazar 	uint8_t num_mem_partitions;
290132f34e4SChristian König 	const struct amdgpu_gmc_funcs	*gmc_funcs;
29176a5b367SAlex Deucher 
29276a5b367SAlex Deucher 	struct amdgpu_xgmi xgmi;
293791c4769Sxinhui pan 	struct amdgpu_irq_src	ecc_irq;
2949b498efaSAlex Deucher 	int noretry;
2957b454b3aSOak Zeng 
2967b454b3aSOak Zeng 	uint32_t	vmid0_page_table_block_size;
2977b454b3aSOak Zeng 	uint32_t	vmid0_page_table_depth;
298a2902c09SOak Zeng 	struct amdgpu_bo		*pdb0_bo;
299a2902c09SOak Zeng 	/* CPU kmapped address of pdb0*/
300a2902c09SOak Zeng 	void				*ptr_pdb0;
301053d35deSAlex Deucher 
302053d35deSAlex Deucher 	/* MALL size */
303053d35deSAlex Deucher 	u64 mall_size;
304bcd9a5f8SCandice Li 	uint32_t m_half_use;
305bcd9a5f8SCandice Li 
306a2efebf1SAlex Deucher 	/* number of UMC instances */
307a2efebf1SAlex Deucher 	int num_umc;
308bfaced6eSVictor Zhao 	/* mode2 save restore */
309bfaced6eSVictor Zhao 	u64 VM_L2_CNTL;
310bfaced6eSVictor Zhao 	u64 VM_L2_CNTL2;
311bfaced6eSVictor Zhao 	u64 VM_DUMMY_PAGE_FAULT_CNTL;
312bfaced6eSVictor Zhao 	u64 VM_DUMMY_PAGE_FAULT_ADDR_LO32;
313bfaced6eSVictor Zhao 	u64 VM_DUMMY_PAGE_FAULT_ADDR_HI32;
314bfaced6eSVictor Zhao 	u64 VM_L2_PROTECTION_FAULT_CNTL;
315bfaced6eSVictor Zhao 	u64 VM_L2_PROTECTION_FAULT_CNTL2;
316bfaced6eSVictor Zhao 	u64 VM_L2_PROTECTION_FAULT_MM_CNTL3;
317bfaced6eSVictor Zhao 	u64 VM_L2_PROTECTION_FAULT_MM_CNTL4;
318bfaced6eSVictor Zhao 	u64 VM_L2_PROTECTION_FAULT_ADDR_LO32;
319bfaced6eSVictor Zhao 	u64 VM_L2_PROTECTION_FAULT_ADDR_HI32;
320bfaced6eSVictor Zhao 	u64 VM_DEBUG;
321bfaced6eSVictor Zhao 	u64 VM_L2_MM_GROUP_RT_CLASSES;
322bfaced6eSVictor Zhao 	u64 VM_L2_BANK_SELECT_RESERVED_CID;
323bfaced6eSVictor Zhao 	u64 VM_L2_BANK_SELECT_RESERVED_CID2;
324bfaced6eSVictor Zhao 	u64 VM_L2_CACHE_PARITY_CNTL;
325bfaced6eSVictor Zhao 	u64 VM_L2_IH_LOG_CNTL;
326bfaced6eSVictor Zhao 	u64 VM_CONTEXT_CNTL[16];
327bfaced6eSVictor Zhao 	u64 VM_CONTEXT_PAGE_TABLE_BASE_ADDR_LO32[16];
328bfaced6eSVictor Zhao 	u64 VM_CONTEXT_PAGE_TABLE_BASE_ADDR_HI32[16];
329bfaced6eSVictor Zhao 	u64 VM_CONTEXT_PAGE_TABLE_START_ADDR_LO32[16];
330bfaced6eSVictor Zhao 	u64 VM_CONTEXT_PAGE_TABLE_START_ADDR_HI32[16];
331bfaced6eSVictor Zhao 	u64 VM_CONTEXT_PAGE_TABLE_END_ADDR_LO32[16];
332bfaced6eSVictor Zhao 	u64 VM_CONTEXT_PAGE_TABLE_END_ADDR_HI32[16];
333bfaced6eSVictor Zhao 	u64 MC_VM_MX_L1_TLB_CNTL;
334*e77673d1SMukul Joshi 
335*e77673d1SMukul Joshi 	u64 noretry_flags;
336770d13b1SChristian König };
337770d13b1SChristian König 
3383ff98548SOak Zeng #define amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, type) ((adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (vmhub), (type)))
339f87f6864SMukul Joshi #define amdgpu_gmc_flush_gpu_tlb_pasid(adev, pasid, type, allhub, inst) \
340ea930000SAlex Sierra 	((adev)->gmc.gmc_funcs->flush_gpu_tlb_pasid \
341f87f6864SMukul Joshi 	((adev), (pasid), (type), (allhub), (inst)))
342c082b998SHuang Rui #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
343c082b998SHuang Rui #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
34471776b6dSChristian König #define amdgpu_gmc_map_mtype(adev, flags) (adev)->gmc.gmc_funcs->map_mtype((adev),(flags))
345c082b998SHuang Rui #define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) (adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags))
346cbfae36cSChristian König #define amdgpu_gmc_get_vm_pte(adev, mapping, flags) (adev)->gmc.gmc_funcs->get_vm_pte((adev), (mapping), (flags))
347352b919cSFelix Kuehling #define amdgpu_gmc_override_vm_pte_flags(adev, vm, addr, pte_flags)	\
348352b919cSFelix Kuehling 	(adev)->gmc.gmc_funcs->override_vm_pte_flags			\
349352b919cSFelix Kuehling 		((adev), (vm), (addr), (pte_flags))
350dd285c5dSAlex Deucher #define amdgpu_gmc_get_vbios_fb_size(adev) (adev)->gmc.gmc_funcs->get_vbios_fb_size((adev))
351c082b998SHuang Rui 
352c8c5e569SAndrey Grodzovsky /**
353c8c5e569SAndrey Grodzovsky  * amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR
354c8c5e569SAndrey Grodzovsky  *
355c8c5e569SAndrey Grodzovsky  * @adev: amdgpu_device pointer
356c8c5e569SAndrey Grodzovsky  *
357c8c5e569SAndrey Grodzovsky  * Returns:
358c8c5e569SAndrey Grodzovsky  * True if full VRAM is visible through the BAR
359c8c5e569SAndrey Grodzovsky  */
amdgpu_gmc_vram_full_visible(struct amdgpu_gmc * gmc)360c8c5e569SAndrey Grodzovsky static inline bool amdgpu_gmc_vram_full_visible(struct amdgpu_gmc *gmc)
361c8c5e569SAndrey Grodzovsky {
362c8c5e569SAndrey Grodzovsky 	WARN_ON(gmc->real_vram_size < gmc->visible_vram_size);
363c8c5e569SAndrey Grodzovsky 
364c8c5e569SAndrey Grodzovsky 	return (gmc->real_vram_size == gmc->visible_vram_size);
365c8c5e569SAndrey Grodzovsky }
366c8c5e569SAndrey Grodzovsky 
367ad9a5b78SChristian König /**
368ad9a5b78SChristian König  * amdgpu_gmc_sign_extend - sign extend the given gmc address
369ad9a5b78SChristian König  *
370ad9a5b78SChristian König  * @addr: address to extend
371ad9a5b78SChristian König  */
amdgpu_gmc_sign_extend(uint64_t addr)372ad9a5b78SChristian König static inline uint64_t amdgpu_gmc_sign_extend(uint64_t addr)
373ad9a5b78SChristian König {
374ad9a5b78SChristian König 	if (addr >= AMDGPU_GMC_HOLE_START)
375ad9a5b78SChristian König 		addr |= AMDGPU_GMC_HOLE_END;
376ad9a5b78SChristian König 
377ad9a5b78SChristian König 	return addr;
378ad9a5b78SChristian König }
379ad9a5b78SChristian König 
380a2902c09SOak Zeng int amdgpu_gmc_pdb0_alloc(struct amdgpu_device *adev);
38124a8d289SChristian König void amdgpu_gmc_get_pde_for_bo(struct amdgpu_bo *bo, int level,
38224a8d289SChristian König 			       uint64_t *addr, uint64_t *flags);
3836490bd76SYong Zhao int amdgpu_gmc_set_pte_pde(struct amdgpu_device *adev, void *cpu_pt_addr,
3846490bd76SYong Zhao 				uint32_t gpu_page_idx, uint64_t addr,
3856490bd76SYong Zhao 				uint64_t flags);
38611c3a249SChristian König uint64_t amdgpu_gmc_pd_addr(struct amdgpu_bo *bo);
387485fc361SChristian König uint64_t amdgpu_gmc_agp_addr(struct ttm_buffer_object *bo);
388f527f310SOak Zeng void amdgpu_gmc_sysvm_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc);
389961c75cfSChristian König void amdgpu_gmc_vram_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc,
390961c75cfSChristian König 			      u64 base);
391961c75cfSChristian König void amdgpu_gmc_gart_location(struct amdgpu_device *adev,
392961c75cfSChristian König 			      struct amdgpu_gmc *mc);
393d76364fcSChristian König void amdgpu_gmc_agp_location(struct amdgpu_device *adev,
394d76364fcSChristian König 			     struct amdgpu_gmc *mc);
3953c2d6ea2SPhilip Yang bool amdgpu_gmc_filter_faults(struct amdgpu_device *adev,
3963c2d6ea2SPhilip Yang 			      struct amdgpu_ih_ring *ih, uint64_t addr,
397c1a8abd9SChristian König 			      uint16_t pasid, uint64_t timestamp);
39836255b5fSPhilip Yang void amdgpu_gmc_filter_faults_remove(struct amdgpu_device *adev, uint64_t addr,
39936255b5fSPhilip Yang 				     uint16_t pasid);
400a6dcf9a7SHawking Zhang int amdgpu_gmc_ras_sw_init(struct amdgpu_device *adev);
401ba083492STao Zhou int amdgpu_gmc_ras_late_init(struct amdgpu_device *adev);
4022adf1344STao Zhou void amdgpu_gmc_ras_fini(struct amdgpu_device *adev);
403bdbe90f0SAlex Deucher int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev);
40411c3a249SChristian König 
405c6252390SLuben Tuikov extern void amdgpu_gmc_tmz_set(struct amdgpu_device *adev);
4069b498efaSAlex Deucher extern void amdgpu_gmc_noretry_set(struct amdgpu_device *adev);
407c6252390SLuben Tuikov 
408f2c1b5c1SHuang Rui extern void
409f2c1b5c1SHuang Rui amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, int hub_type,
410f2c1b5c1SHuang Rui 			      bool enable);
411f2c1b5c1SHuang Rui 
412dd285c5dSAlex Deucher void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev);
413dd285c5dSAlex Deucher 
414a2902c09SOak Zeng void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev);
415dead5e42SOak Zeng uint64_t amdgpu_gmc_vram_mc2pa(struct amdgpu_device *adev, uint64_t mc_addr);
416dead5e42SOak Zeng uint64_t amdgpu_gmc_vram_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo);
417dead5e42SOak Zeng uint64_t amdgpu_gmc_vram_cpu_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo);
418479e3b02SXiaojian Du int amdgpu_gmc_vram_checking(struct amdgpu_device *adev);
419b6f90baaSLijo Lazar int amdgpu_gmc_sysfs_init(struct amdgpu_device *adev);
420b6f90baaSLijo Lazar void amdgpu_gmc_sysfs_fini(struct amdgpu_device *adev);
421b6f90baaSLijo Lazar 
422770d13b1SChristian König #endif
423