0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _ASM_X86_AMD_IOMMU_H
0009 #define _ASM_X86_AMD_IOMMU_H
0010
0011 #include <linux/types.h>
0012
0013 struct amd_iommu;
0014
0015
0016
0017
0018
0019
0020 struct amd_iommu_pi_data {
0021 u32 ga_tag;
0022 u32 prev_ga_tag;
0023 u64 base;
0024 bool is_guest_mode;
0025 struct vcpu_data *vcpu_data;
0026 void *ir_data;
0027 };
0028
0029 #ifdef CONFIG_AMD_IOMMU
0030
0031 struct task_struct;
0032 struct pci_dev;
0033
0034 extern int amd_iommu_detect(void);
0035 extern int amd_iommu_init_hardware(void);
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 extern int amd_iommu_init_device(struct pci_dev *pdev, int pasids);
0047
0048
0049
0050
0051
0052
0053 extern void amd_iommu_free_device(struct pci_dev *pdev);
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 extern int amd_iommu_bind_pasid(struct pci_dev *pdev, u32 pasid,
0064 struct task_struct *task);
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 extern void amd_iommu_unbind_pasid(struct pci_dev *pdev, u32 pasid);
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 #define AMD_IOMMU_INV_PRI_RSP_SUCCESS 0
0097 #define AMD_IOMMU_INV_PRI_RSP_INVALID 1
0098 #define AMD_IOMMU_INV_PRI_RSP_FAIL 2
0099
0100 typedef int (*amd_iommu_invalid_ppr_cb)(struct pci_dev *pdev,
0101 u32 pasid,
0102 unsigned long address,
0103 u16);
0104
0105 extern int amd_iommu_set_invalid_ppr_cb(struct pci_dev *pdev,
0106 amd_iommu_invalid_ppr_cb cb);
0107
0108 #define PPR_FAULT_EXEC (1 << 1)
0109 #define PPR_FAULT_READ (1 << 2)
0110 #define PPR_FAULT_WRITE (1 << 5)
0111 #define PPR_FAULT_USER (1 << 6)
0112 #define PPR_FAULT_RSVD (1 << 7)
0113 #define PPR_FAULT_GN (1 << 8)
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 #define AMD_IOMMU_DEVICE_FLAG_ATS_SUP 0x1
0126 #define AMD_IOMMU_DEVICE_FLAG_PRI_SUP 0x2
0127 #define AMD_IOMMU_DEVICE_FLAG_PASID_SUP 0x4
0128 #define AMD_IOMMU_DEVICE_FLAG_EXEC_SUP 0x8
0129
0130 #define AMD_IOMMU_DEVICE_FLAG_PRIV_SUP 0x10
0131
0132
0133 struct amd_iommu_device_info {
0134 int max_pasids;
0135 u32 flags;
0136 };
0137
0138 extern int amd_iommu_device_info(struct pci_dev *pdev,
0139 struct amd_iommu_device_info *info);
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 typedef void (*amd_iommu_invalidate_ctx)(struct pci_dev *pdev, u32 pasid);
0154
0155 extern int amd_iommu_set_invalidate_ctx_cb(struct pci_dev *pdev,
0156 amd_iommu_invalidate_ctx cb);
0157 #else
0158
0159 static inline int amd_iommu_detect(void) { return -ENODEV; }
0160
0161 #endif
0162
0163 #if defined(CONFIG_AMD_IOMMU) && defined(CONFIG_IRQ_REMAP)
0164
0165
0166 extern int amd_iommu_register_ga_log_notifier(int (*notifier)(u32));
0167
0168 extern int
0169 amd_iommu_update_ga(int cpu, bool is_run, void *data);
0170
0171 extern int amd_iommu_activate_guest_mode(void *data);
0172 extern int amd_iommu_deactivate_guest_mode(void *data);
0173
0174 #else
0175
0176 static inline int
0177 amd_iommu_register_ga_log_notifier(int (*notifier)(u32))
0178 {
0179 return 0;
0180 }
0181
0182 static inline int
0183 amd_iommu_update_ga(int cpu, bool is_run, void *data)
0184 {
0185 return 0;
0186 }
0187
0188 static inline int amd_iommu_activate_guest_mode(void *data)
0189 {
0190 return 0;
0191 }
0192
0193 static inline int amd_iommu_deactivate_guest_mode(void *data)
0194 {
0195 return 0;
0196 }
0197 #endif
0198
0199 int amd_iommu_get_num_iommus(void);
0200 bool amd_iommu_pc_supported(void);
0201 u8 amd_iommu_pc_get_max_banks(unsigned int idx);
0202 u8 amd_iommu_pc_get_max_counters(unsigned int idx);
0203 int amd_iommu_pc_set_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn,
0204 u64 *value);
0205 int amd_iommu_pc_get_reg(struct amd_iommu *iommu, u8 bank, u8 cntr, u8 fxn,
0206 u64 *value);
0207 struct amd_iommu *get_amd_iommu(unsigned int idx);
0208
0209 #ifdef CONFIG_AMD_MEM_ENCRYPT
0210 int amd_iommu_snp_enable(void);
0211 #endif
0212
0213 #endif