1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev * Copyright 2018 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev * All Rights Reserved.
4b843c749SSergey Zigachev *
5b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
6b843c749SSergey Zigachev * copy of this software and associated documentation files (the
7b843c749SSergey Zigachev * "Software"), to deal in the Software without restriction, including
8b843c749SSergey Zigachev * without limitation the rights to use, copy, modify, merge, publish,
9b843c749SSergey Zigachev * distribute, sub license, and/or sell copies of the Software, and to
10b843c749SSergey Zigachev * permit persons to whom the Software is furnished to do so, subject to
11b843c749SSergey Zigachev * the following conditions:
12b843c749SSergey Zigachev *
13b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16b843c749SSergey Zigachev * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17b843c749SSergey Zigachev * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18b843c749SSergey Zigachev * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19b843c749SSergey Zigachev * USE OR OTHER DEALINGS IN THE SOFTWARE.
20b843c749SSergey Zigachev *
21b843c749SSergey Zigachev * The above copyright notice and this permission notice (including the
22b843c749SSergey Zigachev * next paragraph) shall be included in all copies or substantial portions
23b843c749SSergey Zigachev * of the Software.
24b843c749SSergey Zigachev *
25b843c749SSergey Zigachev */
26b843c749SSergey Zigachev #ifndef __AMDGPU_GMC_H__
27b843c749SSergey Zigachev #define __AMDGPU_GMC_H__
28b843c749SSergey Zigachev
29b843c749SSergey Zigachev #include <linux/types.h>
30b843c749SSergey Zigachev
31b843c749SSergey Zigachev #include "amdgpu_irq.h"
32b843c749SSergey Zigachev
33b843c749SSergey Zigachev struct firmware;
34b843c749SSergey Zigachev
35b843c749SSergey Zigachev /*
36b843c749SSergey Zigachev * VMHUB structures, functions & helpers
37b843c749SSergey Zigachev */
38b843c749SSergey Zigachev struct amdgpu_vmhub {
39b843c749SSergey Zigachev uint32_t ctx0_ptb_addr_lo32;
40b843c749SSergey Zigachev uint32_t ctx0_ptb_addr_hi32;
41b843c749SSergey Zigachev uint32_t vm_inv_eng0_req;
42b843c749SSergey Zigachev uint32_t vm_inv_eng0_ack;
43b843c749SSergey Zigachev uint32_t vm_context0_cntl;
44b843c749SSergey Zigachev uint32_t vm_l2_pro_fault_status;
45b843c749SSergey Zigachev uint32_t vm_l2_pro_fault_cntl;
46b843c749SSergey Zigachev };
47b843c749SSergey Zigachev
48b843c749SSergey Zigachev /*
49b843c749SSergey Zigachev * GPU MC structures, functions & helpers
50b843c749SSergey Zigachev */
51b843c749SSergey Zigachev struct amdgpu_gmc_funcs {
52b843c749SSergey Zigachev /* flush the vm tlb via mmio */
53b843c749SSergey Zigachev void (*flush_gpu_tlb)(struct amdgpu_device *adev,
54b843c749SSergey Zigachev uint32_t vmid);
55b843c749SSergey Zigachev /* flush the vm tlb via ring */
56b843c749SSergey Zigachev uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
57b843c749SSergey Zigachev uint64_t pd_addr);
58b843c749SSergey Zigachev /* Change the VMID -> PASID mapping */
59b843c749SSergey Zigachev void (*emit_pasid_mapping)(struct amdgpu_ring *ring, unsigned vmid,
60b843c749SSergey Zigachev unsigned pasid);
61b843c749SSergey Zigachev /* write pte/pde updates using the cpu */
62b843c749SSergey Zigachev int (*set_pte_pde)(struct amdgpu_device *adev,
63b843c749SSergey Zigachev void *cpu_pt_addr, /* cpu addr of page table */
64b843c749SSergey Zigachev uint32_t gpu_page_idx, /* pte/pde to update */
65b843c749SSergey Zigachev uint64_t addr, /* addr to write into pte/pde */
66b843c749SSergey Zigachev uint64_t flags); /* access flags */
67b843c749SSergey Zigachev /* enable/disable PRT support */
68b843c749SSergey Zigachev void (*set_prt)(struct amdgpu_device *adev, bool enable);
69b843c749SSergey Zigachev /* set pte flags based per asic */
70b843c749SSergey Zigachev uint64_t (*get_vm_pte_flags)(struct amdgpu_device *adev,
71b843c749SSergey Zigachev uint32_t flags);
72b843c749SSergey Zigachev /* get the pde for a given mc addr */
73b843c749SSergey Zigachev void (*get_vm_pde)(struct amdgpu_device *adev, int level,
74*78973132SSergey Zigachev uint64_t *dst, uint64_t *flags);
75b843c749SSergey Zigachev };
76b843c749SSergey Zigachev
77b843c749SSergey Zigachev struct amdgpu_gmc {
78b843c749SSergey Zigachev resource_size_t aper_size;
79b843c749SSergey Zigachev resource_size_t aper_base;
80b843c749SSergey Zigachev /* for some chips with <= 32MB we need to lie
81b843c749SSergey Zigachev * about vram size near mc fb location */
82b843c749SSergey Zigachev u64 mc_vram_size;
83b843c749SSergey Zigachev u64 visible_vram_size;
84b843c749SSergey Zigachev u64 gart_size;
85b843c749SSergey Zigachev u64 gart_start;
86b843c749SSergey Zigachev u64 gart_end;
87b843c749SSergey Zigachev u64 vram_start;
88b843c749SSergey Zigachev u64 vram_end;
89b843c749SSergey Zigachev unsigned vram_width;
90b843c749SSergey Zigachev u64 real_vram_size;
91b843c749SSergey Zigachev int vram_mtrr;
92b843c749SSergey Zigachev u64 mc_mask;
93b843c749SSergey Zigachev const struct firmware *fw; /* MC firmware */
94b843c749SSergey Zigachev uint32_t fw_version;
95b843c749SSergey Zigachev struct amdgpu_irq_src vm_fault;
96b843c749SSergey Zigachev uint32_t vram_type;
97b843c749SSergey Zigachev uint32_t srbm_soft_reset;
98b843c749SSergey Zigachev bool prt_warning;
99b843c749SSergey Zigachev uint64_t stolen_size;
100b843c749SSergey Zigachev uint32_t sdpif_register;
101b843c749SSergey Zigachev /* apertures */
102b843c749SSergey Zigachev u64 shared_aperture_start;
103b843c749SSergey Zigachev u64 shared_aperture_end;
104b843c749SSergey Zigachev u64 private_aperture_start;
105b843c749SSergey Zigachev u64 private_aperture_end;
106b843c749SSergey Zigachev /* protects concurrent invalidation */
107*78973132SSergey Zigachev struct spinlock invalidate_lock;
108b843c749SSergey Zigachev bool translate_further;
109b843c749SSergey Zigachev struct kfd_vm_fault_info *vm_fault_info;
110b843c749SSergey Zigachev atomic_t vm_fault_info_updated;
111b843c749SSergey Zigachev
112b843c749SSergey Zigachev const struct amdgpu_gmc_funcs *gmc_funcs;
113b843c749SSergey Zigachev };
114b843c749SSergey Zigachev
115b843c749SSergey Zigachev /**
116b843c749SSergey Zigachev * amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR
117b843c749SSergey Zigachev *
118b843c749SSergey Zigachev * @adev: amdgpu_device pointer
119b843c749SSergey Zigachev *
120b843c749SSergey Zigachev * Returns:
121b843c749SSergey Zigachev * True if full VRAM is visible through the BAR
122b843c749SSergey Zigachev */
amdgpu_gmc_vram_full_visible(struct amdgpu_gmc * gmc)123b843c749SSergey Zigachev static inline bool amdgpu_gmc_vram_full_visible(struct amdgpu_gmc *gmc)
124b843c749SSergey Zigachev {
125b843c749SSergey Zigachev WARN_ON(gmc->real_vram_size < gmc->visible_vram_size);
126b843c749SSergey Zigachev
127b843c749SSergey Zigachev return (gmc->real_vram_size == gmc->visible_vram_size);
128b843c749SSergey Zigachev }
129b843c749SSergey Zigachev
130b843c749SSergey Zigachev #endif
131