1
2
3
4
5
6
7
8#ifndef _ASM_X86_AMD_IOMMU_H
9#define _ASM_X86_AMD_IOMMU_H
10
11#include <linux/types.h>
12
13struct amd_iommu;
14
15
16
17
18
19
20struct amd_iommu_pi_data {
21 u32 ga_tag;
22 u32 prev_ga_tag;
23 u64 base;
24 bool is_guest_mode;
25 struct vcpu_data *vcpu_data;
26 void *ir_data;
27};
28
29#ifdef CONFIG_AMD_IOMMU
30
31struct task_struct;
32struct pci_dev;
33
34extern int amd_iommu_detect(void);
35extern int amd_iommu_init_hardware(void);
36
37
38
39
40
41
42
43
44
45
46extern int amd_iommu_init_device(struct pci_dev *pdev, int pasids);
47
48
49
50
51
52
53extern void amd_iommu_free_device(struct pci_dev *pdev);
54
55
56
57
58
59
60
61
62
63extern int amd_iommu_bind_pasid(struct pci_dev *pdev, u32 pasid,
64 struct task_struct *task);
65
66
67
68
69
70
71
72
73
74
75extern void amd_iommu_unbind_pasid(struct pci_dev *pdev, u32 pasid);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96#define AMD_IOMMU_INV_PRI_RSP_SUCCESS 0
97#define AMD_IOMMU_INV_PRI_RSP_INVALID 1
98#define AMD_IOMMU_INV_PRI_RSP_FAIL 2
99
100typedef int (*amd_iommu_invalid_ppr_cb)(struct pci_dev *pdev,
101 u32 pasid,
102 unsigned long address,
103 u16);
104
105extern int amd_iommu_set_invalid_ppr_cb(struct pci_dev *pdev,
106 amd_iommu_invalid_ppr_cb cb);
107
108#define PPR_FAULT_EXEC (1 << 1)
109#define PPR_FAULT_READ (1 << 2)
110#define PPR_FAULT_WRITE (1 << 5)
111#define PPR_FAULT_USER (1 << 6)
112#define PPR_FAULT_RSVD (1 << 7)
113#define PPR_FAULT_GN (1 << 8)
114
115
116
117
118
119
120
121
122
123
124
125#define AMD_IOMMU_DEVICE_FLAG_ATS_SUP 0x1
126#define AMD_IOMMU_DEVICE_FLAG_PRI_SUP 0x2
127#define AMD_IOMMU_DEVICE_FLAG_PASID_SUP 0x4
128#define AMD_IOMMU_DEVICE_FLAG_EXEC_SUP 0x8
129
130#define AMD_IOMMU_DEVICE_FLAG_PRIV_SUP 0x10
131
132
133struct amd_iommu_device_info {
134 int max_pasids;
135 u32 flags;
136};
137
138extern int amd_iommu_device_info(struct pci_dev *pdev,
139 struct amd_iommu_device_info *info);
140
141
142
143
144
145
146
147
148
149
150
151
152
153typedef void (*amd_iommu_invalidate_ctx)(struct pci_dev *pdev, u32 pasid);
154
155extern int amd_iommu_set_invalidate_ctx_cb(struct pci_dev *pdev,
156 amd_iommu_invalidate_ctx cb);
157#else
158
159static inline int amd_iommu_detect(void) { return -ENODEV; }
160
161#endif
162
163#if defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP)
164
165
166extern int amd_iommu_register_ga_log_notifier(int (*notifier)(u32));
167
168extern int
169amd_iommu_update_ga(int cpu, bool is_run, void *data);
170
171extern int amd_iommu_activate_guest_mode(void *data);
172extern int amd_iommu_deactivate_guest_mode(void *data);
173
174#else
175
176static inline int
177amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
178{
179 return 0;
180}
181
182static inline int
183amd_iommu_update_ga(int cpu, bool is_run, void *data)
184{
185 return 0;
186}
187
188static inline int amd_iommu_activate_guest_mode(void *data)
189{
190 return 0;
191}
192
193static inline int amd_iommu_deactivate_guest_mode(void *data)
194{
195 return 0;
196}
197#endif
198
199int amd_iommu_get_num_iommus(void);
200bool amd_iommu_pc_supported(void);
201u8 amd_iommu_pc_get_max_banks(unsigned int idx);
202u8 amd_iommu_pc_get_max_counters(unsigned int idx);
203int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn,
204 u64 *value);
205int amd_iommu_pc_get_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn,
206 u64 *value);
207struct amd_iommu *get_amd_iommu(unsigned int idx);
208
209#endif
210