Blame view
drivers/iommu/amd_iommu_types.h
19.6 KB
8d283c35a x86, AMD IOMMU: a... |
1 |
/* |
5d0d71569 x86/amd-iommu: Up... |
2 |
* Copyright (C) 2007-2010 Advanced Micro Devices, Inc. |
8d283c35a x86, AMD IOMMU: a... |
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
* Author: Joerg Roedel <joerg.roedel@amd.com> * Leo Duran <leo.duran@amd.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
1965aae3c x86: Fix ASM_X86_... |
19 20 |
#ifndef _ASM_X86_AMD_IOMMU_TYPES_H #define _ASM_X86_AMD_IOMMU_TYPES_H |
8d283c35a x86, AMD IOMMU: a... |
21 22 |
#include <linux/types.h> |
5d214fe6e x86/amd-iommu: Pr... |
23 |
#include <linux/mutex.h> |
8d283c35a x86, AMD IOMMU: a... |
24 25 26 27 |
#include <linux/list.h> #include <linux/spinlock.h> /* |
bb52777ec x86/amd-iommu: Ad... |
28 29 30 31 32 |
* Maximum number of IOMMUs supported */ #define MAX_IOMMUS 32 /* |
8d283c35a x86, AMD IOMMU: a... |
33 34 |
* some size calculation constants */ |
83f5aac18 x86, AMD IOMMU: f... |
35 |
#define DEV_TABLE_ENTRY_SIZE 32 |
8d283c35a x86, AMD IOMMU: a... |
36 37 |
#define ALIAS_TABLE_ENTRY_SIZE 2 #define RLOOKUP_TABLE_ENTRY_SIZE (sizeof(void *)) |
8d283c35a x86, AMD IOMMU: a... |
38 39 40 41 42 43 |
/* Length of the MMIO region for the AMD IOMMU */ #define MMIO_REGION_LENGTH 0x4000 /* Capability offsets used by the driver */ #define MMIO_CAP_HDR_OFFSET 0x00 #define MMIO_RANGE_OFFSET 0x0c |
a80dc3e0e AMD IOMMU: add MS... |
44 |
#define MMIO_MISC_OFFSET 0x10 |
8d283c35a x86, AMD IOMMU: a... |
45 46 47 48 49 50 51 52 53 54 55 |
/* Masks, shifts and macros to parse the device range capability */ #define MMIO_RANGE_LD_MASK 0xff000000 #define MMIO_RANGE_FD_MASK 0x00ff0000 #define MMIO_RANGE_BUS_MASK 0x0000ff00 #define MMIO_RANGE_LD_SHIFT 24 #define MMIO_RANGE_FD_SHIFT 16 #define MMIO_RANGE_BUS_SHIFT 8 #define MMIO_GET_LD(x) (((x) & MMIO_RANGE_LD_MASK) >> MMIO_RANGE_LD_SHIFT) #define MMIO_GET_FD(x) (((x) & MMIO_RANGE_FD_MASK) >> MMIO_RANGE_FD_SHIFT) #define MMIO_GET_BUS(x) (((x) & MMIO_RANGE_BUS_MASK) >> MMIO_RANGE_BUS_SHIFT) |
a80dc3e0e AMD IOMMU: add MS... |
56 |
#define MMIO_MSI_NUM(x) ((x) & 0x1f) |
8d283c35a x86, AMD IOMMU: a... |
57 58 59 60 61 62 63 64 65 66 67 68 |
/* Flag masks for the AMD IOMMU exclusion range */ #define MMIO_EXCL_ENABLE_MASK 0x01ULL #define MMIO_EXCL_ALLOW_MASK 0x02ULL /* Used offsets into the MMIO space */ #define MMIO_DEV_TABLE_OFFSET 0x0000 #define MMIO_CMD_BUF_OFFSET 0x0008 #define MMIO_EVT_BUF_OFFSET 0x0010 #define MMIO_CONTROL_OFFSET 0x0018 #define MMIO_EXCL_BASE_OFFSET 0x0020 #define MMIO_EXCL_LIMIT_OFFSET 0x0028 |
d99ddec3e x86/amd-iommu: Ad... |
69 |
#define MMIO_EXT_FEATURES 0x0030 |
1a29ac014 iommu/amd: Setup ... |
70 |
#define MMIO_PPR_LOG_OFFSET 0x0038 |
8d283c35a x86, AMD IOMMU: a... |
71 72 73 74 75 |
#define MMIO_CMD_HEAD_OFFSET 0x2000 #define MMIO_CMD_TAIL_OFFSET 0x2008 #define MMIO_EVT_HEAD_OFFSET 0x2010 #define MMIO_EVT_TAIL_OFFSET 0x2018 #define MMIO_STATUS_OFFSET 0x2020 |
1a29ac014 iommu/amd: Setup ... |
76 77 |
#define MMIO_PPR_HEAD_OFFSET 0x2030 #define MMIO_PPR_TAIL_OFFSET 0x2038 |
8d283c35a x86, AMD IOMMU: a... |
78 |
|
d99ddec3e x86/amd-iommu: Ad... |
79 80 81 82 83 84 85 86 87 88 89 |
/* Extended Feature Bits */ #define FEATURE_PREFETCH (1ULL<<0) #define FEATURE_PPR (1ULL<<1) #define FEATURE_X2APIC (1ULL<<2) #define FEATURE_NX (1ULL<<3) #define FEATURE_GT (1ULL<<4) #define FEATURE_IA (1ULL<<6) #define FEATURE_GA (1ULL<<7) #define FEATURE_HE (1ULL<<8) #define FEATURE_PC (1ULL<<9) |
62f71abbc iommu/amd: Get th... |
90 91 |
#define FEATURE_PASID_SHIFT 32 #define FEATURE_PASID_MASK (0x1fULL << FEATURE_PASID_SHIFT) |
52815b756 iommu/amd: Add su... |
92 93 94 95 |
#define FEATURE_GLXVAL_SHIFT 14 #define FEATURE_GLXVAL_MASK (0x03ULL << FEATURE_GLXVAL_SHIFT) #define PASID_MASK 0x000fffff |
519c31bac x86, AMD IOMMU: u... |
96 |
/* MMIO status bits */ |
72e1dcc41 iommu/amd: Implem... |
97 98 |
#define MMIO_STATUS_COM_WAIT_INT_MASK (1 << 2) #define MMIO_STATUS_PPR_INT_MASK (1 << 6) |
519c31bac x86, AMD IOMMU: u... |
99 |
|
90008ee4b AMD IOMMU: add ev... |
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
/* event logging constants */ #define EVENT_ENTRY_SIZE 0x10 #define EVENT_TYPE_SHIFT 28 #define EVENT_TYPE_MASK 0xf #define EVENT_TYPE_ILL_DEV 0x1 #define EVENT_TYPE_IO_FAULT 0x2 #define EVENT_TYPE_DEV_TAB_ERR 0x3 #define EVENT_TYPE_PAGE_TAB_ERR 0x4 #define EVENT_TYPE_ILL_CMD 0x5 #define EVENT_TYPE_CMD_HARD_ERR 0x6 #define EVENT_TYPE_IOTLB_INV_TO 0x7 #define EVENT_TYPE_INV_DEV_REQ 0x8 #define EVENT_DEVID_MASK 0xffff #define EVENT_DEVID_SHIFT 0 #define EVENT_DOMID_MASK 0xffff #define EVENT_DOMID_SHIFT 0 #define EVENT_FLAGS_MASK 0xfff #define EVENT_FLAGS_SHIFT 0x10 |
8d283c35a x86, AMD IOMMU: a... |
118 119 120 121 122 123 |
/* feature control bits */ #define CONTROL_IOMMU_EN 0x00ULL #define CONTROL_HT_TUN_EN 0x01ULL #define CONTROL_EVT_LOG_EN 0x02ULL #define CONTROL_EVT_INT_EN 0x03ULL #define CONTROL_COMWAIT_EN 0x04ULL |
1456e9d2c iommu/amd: Set IO... |
124 |
#define CONTROL_INV_TIMEOUT 0x05ULL |
8d283c35a x86, AMD IOMMU: a... |
125 126 127 128 129 130 131 |
#define CONTROL_PASSPW_EN 0x08ULL #define CONTROL_RESPASSPW_EN 0x09ULL #define CONTROL_COHERENT_EN 0x0aULL #define CONTROL_ISOC_EN 0x0bULL #define CONTROL_CMDBUF_EN 0x0cULL #define CONTROL_PPFLOG_EN 0x0dULL #define CONTROL_PPFINT_EN 0x0eULL |
1a29ac014 iommu/amd: Setup ... |
132 |
#define CONTROL_PPR_EN 0x0fULL |
cbc33a908 iommu/amd: Enable... |
133 |
#define CONTROL_GT_EN 0x10ULL |
8d283c35a x86, AMD IOMMU: a... |
134 |
|
1456e9d2c iommu/amd: Set IO... |
135 136 137 138 139 140 141 142 |
#define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT) #define CTRL_INV_TO_NONE 0 #define CTRL_INV_TO_1MS 1 #define CTRL_INV_TO_10MS 2 #define CTRL_INV_TO_100MS 3 #define CTRL_INV_TO_1S 4 #define CTRL_INV_TO_10S 5 #define CTRL_INV_TO_100S 6 |
8d283c35a x86, AMD IOMMU: a... |
143 144 145 |
/* command specific defines */ #define CMD_COMPL_WAIT 0x01 #define CMD_INV_DEV_ENTRY 0x02 |
cb41ed85e x86/amd-iommu: Fl... |
146 147 |
#define CMD_INV_IOMMU_PAGES 0x03 #define CMD_INV_IOTLB_PAGES 0x04 |
c99afa25b iommu/amd: Implem... |
148 |
#define CMD_COMPLETE_PPR 0x07 |
58fc7f141 x86/amd-iommu: Ad... |
149 |
#define CMD_INV_ALL 0x08 |
8d283c35a x86, AMD IOMMU: a... |
150 151 |
#define CMD_COMPL_WAIT_STORE_MASK 0x01 |
519c31bac x86, AMD IOMMU: u... |
152 |
#define CMD_COMPL_WAIT_INT_MASK 0x02 |
8d283c35a x86, AMD IOMMU: a... |
153 154 |
#define CMD_INV_IOMMU_PAGES_SIZE_MASK 0x01 #define CMD_INV_IOMMU_PAGES_PDE_MASK 0x02 |
22e266c79 iommu/amd: Implem... |
155 |
#define CMD_INV_IOMMU_PAGES_GN_MASK 0x04 |
8d283c35a x86, AMD IOMMU: a... |
156 |
|
c99afa25b iommu/amd: Implem... |
157 158 |
#define PPR_STATUS_MASK 0xf #define PPR_STATUS_SHIFT 12 |
999ba417c x86, AMD IOMMU: f... |
159 |
#define CMD_INV_IOMMU_ALL_PAGES_ADDRESS 0x7fffffffffffffffULL |
8d283c35a x86, AMD IOMMU: a... |
160 161 162 163 164 |
/* macros and definitions for device table entries */ #define DEV_ENTRY_VALID 0x00 #define DEV_ENTRY_TRANSLATION 0x01 #define DEV_ENTRY_IR 0x3d #define DEV_ENTRY_IW 0x3e |
9f5f5fb35 x86, AMD IOMMU: i... |
165 |
#define DEV_ENTRY_NO_PAGE_FAULT 0x62 |
8d283c35a x86, AMD IOMMU: a... |
166 167 168 169 170 171 172 173 |
#define DEV_ENTRY_EX 0x67 #define DEV_ENTRY_SYSMGT1 0x68 #define DEV_ENTRY_SYSMGT2 0x69 #define DEV_ENTRY_INIT_PASS 0xb8 #define DEV_ENTRY_EINT_PASS 0xb9 #define DEV_ENTRY_NMI_PASS 0xba #define DEV_ENTRY_LINT0_PASS 0xbe #define DEV_ENTRY_LINT1_PASS 0xbf |
38ddf41b1 AMD IOMMU: some s... |
174 175 |
#define DEV_ENTRY_MODE_MASK 0x07 #define DEV_ENTRY_MODE_SHIFT 0x09 |
8d283c35a x86, AMD IOMMU: a... |
176 177 178 |
/* constants to configure the command buffer */ #define CMD_BUFFER_SIZE 8192 |
549c90dc9 x86/amd-iommu: wa... |
179 |
#define CMD_BUFFER_UNINITIALIZED 1 |
8d283c35a x86, AMD IOMMU: a... |
180 181 182 |
#define CMD_BUFFER_ENTRIES 512 #define MMIO_CMD_SIZE_SHIFT 56 #define MMIO_CMD_SIZE_512 (0x9ULL << MMIO_CMD_SIZE_SHIFT) |
335503e57 AMD IOMMU: add ev... |
183 184 185 |
/* constants for event buffer handling */ #define EVT_BUFFER_SIZE 8192 /* 512 entries */ #define EVT_LEN_MASK (0x9ULL << 56) |
1a29ac014 iommu/amd: Setup ... |
186 187 188 189 190 191 |
/* Constants for PPR Log handling */ #define PPR_LOG_ENTRIES 512 #define PPR_LOG_SIZE_SHIFT 56 #define PPR_LOG_SIZE_512 (0x9ULL << PPR_LOG_SIZE_SHIFT) #define PPR_ENTRY_SIZE 16 #define PPR_LOG_SIZE (PPR_ENTRY_SIZE * PPR_LOG_ENTRIES) |
72e1dcc41 iommu/amd: Implem... |
192 193 194 195 196 197 198 199 200 |
#define PPR_REQ_TYPE(x) (((x) >> 60) & 0xfULL) #define PPR_FLAGS(x) (((x) >> 48) & 0xfffULL) #define PPR_DEVID(x) ((x) & 0xffffULL) #define PPR_TAG(x) (((x) >> 32) & 0x3ffULL) #define PPR_PASID1(x) (((x) >> 16) & 0xffffULL) #define PPR_PASID2(x) (((x) >> 42) & 0xfULL) #define PPR_PASID(x) ((PPR_PASID2(x) << 16) | PPR_PASID1(x)) #define PPR_REQ_FAULT 0x01 |
0feae533d x86/amd-iommu: Ad... |
201 |
#define PAGE_MODE_NONE 0x00 |
8d283c35a x86, AMD IOMMU: a... |
202 203 204 |
#define PAGE_MODE_1_LEVEL 0x01 #define PAGE_MODE_2_LEVEL 0x02 #define PAGE_MODE_3_LEVEL 0x03 |
9355a0818 x86/amd-iommu: Ma... |
205 206 207 |
#define PAGE_MODE_4_LEVEL 0x04 #define PAGE_MODE_5_LEVEL 0x05 #define PAGE_MODE_6_LEVEL 0x06 |
8d283c35a x86, AMD IOMMU: a... |
208 |
|
9355a0818 x86/amd-iommu: Ma... |
209 210 211 212 213 |
#define PM_LEVEL_SHIFT(x) (12 + ((x) * 9)) #define PM_LEVEL_SIZE(x) (((x) < 6) ? \ ((1ULL << PM_LEVEL_SHIFT((x))) - 1): \ (0xffffffffffffffffULL)) #define PM_LEVEL_INDEX(x, a) (((a) >> PM_LEVEL_SHIFT((x))) & 0x1ffULL) |
50020fb63 x86/amd-iommu: In... |
214 215 216 |
#define PM_LEVEL_ENC(x) (((x) << 9) & 0xe00ULL) #define PM_LEVEL_PDE(x, a) ((a) | PM_LEVEL_ENC((x)) | \ IOMMU_PTE_P | IOMMU_PTE_IR | IOMMU_PTE_IW) |
a6b256b41 x86/amd-iommu: Su... |
217 |
#define PM_PTE_LEVEL(pte) (((pte) >> 9) & 0x7ULL) |
50020fb63 x86/amd-iommu: In... |
218 |
|
abdc5eb3d x86/amd-iommu: Ch... |
219 220 221 222 223 |
#define PM_MAP_4k 0 #define PM_ADDR_MASK 0x000ffffffffff000ULL #define PM_MAP_MASK(lvl) (PM_ADDR_MASK & \ (~((1ULL << (12 + ((lvl) * 9))) - 1))) #define PM_ALIGNED(lvl, addr) ((PM_MAP_MASK(lvl) & (addr)) == (addr)) |
8d283c35a x86, AMD IOMMU: a... |
224 |
|
cbb9d729f x86/amd-iommu: Ma... |
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
/* * Returns the page table level to use for a given page size * Pagesize is expected to be a power-of-two */ #define PAGE_SIZE_LEVEL(pagesize) \ ((__ffs(pagesize) - 12) / 9) /* * Returns the number of ptes to use for a given page size * Pagesize is expected to be a power-of-two */ #define PAGE_SIZE_PTE_COUNT(pagesize) \ (1ULL << ((__ffs(pagesize) - 12) % 9)) /* * Aligns a given io-virtual address to a given page size * Pagesize is expected to be a power-of-two */ #define PAGE_SIZE_ALIGN(address, pagesize) \ ((address) & ~((pagesize) - 1)) /* * Creates an IOMMU PTE for an address an a given pagesize * The PTE has no permission bits set * Pagesize is expected to be a power-of-two larger than 4096 */ #define PAGE_SIZE_PTE(address, pagesize) \ (((address) | ((pagesize) - 1)) & \ (~(pagesize >> 1)) & PM_ADDR_MASK) |
24cd77231 x86/amd-iommu: Ma... |
252 253 254 255 256 |
/* * Takes a PTE value with mode=0x07 and returns the page size it maps */ #define PTE_PAGE_SIZE(pte) \ (1ULL << (1 + ffz(((pte) | 0xfffULL)))) |
8d283c35a x86, AMD IOMMU: a... |
257 |
#define IOMMU_PTE_P (1ULL << 0) |
38ddf41b1 AMD IOMMU: some s... |
258 |
#define IOMMU_PTE_TV (1ULL << 1) |
8d283c35a x86, AMD IOMMU: a... |
259 260 261 262 |
#define IOMMU_PTE_U (1ULL << 59) #define IOMMU_PTE_FC (1ULL << 60) #define IOMMU_PTE_IR (1ULL << 61) #define IOMMU_PTE_IW (1ULL << 62) |
ee6c28684 iommu/amd: Conver... |
263 |
#define DTE_FLAG_IOTLB (0x01UL << 32) |
52815b756 iommu/amd: Add su... |
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
#define DTE_FLAG_GV (0x01ULL << 55) #define DTE_GLX_SHIFT (56) #define DTE_GLX_MASK (3) #define DTE_GCR3_VAL_A(x) (((x) >> 12) & 0x00007ULL) #define DTE_GCR3_VAL_B(x) (((x) >> 15) & 0x0ffffULL) #define DTE_GCR3_VAL_C(x) (((x) >> 31) & 0xfffffULL) #define DTE_GCR3_INDEX_A 0 #define DTE_GCR3_INDEX_B 1 #define DTE_GCR3_INDEX_C 1 #define DTE_GCR3_SHIFT_A 58 #define DTE_GCR3_SHIFT_B 16 #define DTE_GCR3_SHIFT_C 43 |
b16137b11 iommu/amd: Implem... |
279 |
#define GCR3_VALID 0x01ULL |
fd7b5535e x86/amd-iommu: Ad... |
280 |
|
8d283c35a x86, AMD IOMMU: a... |
281 282 283 284 285 286 287 288 289 290 291 292 |
#define IOMMU_PAGE_MASK (((1ULL << 52) - 1) & ~0xfffULL) #define IOMMU_PTE_PRESENT(pte) ((pte) & IOMMU_PTE_P) #define IOMMU_PTE_PAGE(pte) (phys_to_virt((pte) & IOMMU_PAGE_MASK)) #define IOMMU_PTE_MODE(pte) (((pte) >> 9) & 0x07) #define IOMMU_PROT_MASK 0x03 #define IOMMU_PROT_IR 0x01 #define IOMMU_PROT_IW 0x02 /* IOMMU capabilities */ #define IOMMU_CAP_IOTLB 24 #define IOMMU_CAP_NPCACHE 26 |
d99ddec3e x86/amd-iommu: Ad... |
293 |
#define IOMMU_CAP_EFR 27 |
8d283c35a x86, AMD IOMMU: a... |
294 295 |
#define MAX_DOMAIN_ID 65536 |
90008ee4b AMD IOMMU: add ev... |
296 297 |
/* FIXME: move this macro to <linux/pci.h> */ #define PCI_BUS(x) (((x) >> 8) & 0xff) |
9fdb19d64 AMD IOMMU: add pr... |
298 299 |
/* Protection domain flags */ #define PD_DMA_OPS_MASK (1UL << 0) /* domain used for dma_ops */ |
e2dc14a2a AMD IOMMU: add a ... |
300 301 |
#define PD_DEFAULT_MASK (1UL << 1) /* domain is a default dma_ops domain for an IOMMU */ |
0feae533d x86/amd-iommu: Ad... |
302 303 |
#define PD_PASSTHROUGH_MASK (1UL << 2) /* domain has no page translation */ |
52815b756 iommu/amd: Add su... |
304 |
#define PD_IOMMUV2_MASK (1UL << 3) /* domain has gcr3 table */ |
0feae533d x86/amd-iommu: Ad... |
305 |
|
fefda117d amd-iommu: add am... |
306 307 308 309 |
extern bool amd_iommu_dump; #define DUMP_printk(format, arg...) \ do { \ if (amd_iommu_dump) \ |
4c6f40d4e x86/amd-iommu: re... |
310 |
printk(KERN_INFO "AMD-Vi: " format, ## arg); \ |
fefda117d amd-iommu: add am... |
311 |
} while(0); |
9fdb19d64 AMD IOMMU: add pr... |
312 |
|
318afd41d x86/amd-iommu: Ma... |
313 314 |
/* global flag if IOMMUs cache non-present entries */ extern bool amd_iommu_np_cache; |
60f723b41 x86/amd-iommu: Ad... |
315 316 |
/* Only true if all IOMMUs support device IOTLBs */ extern bool amd_iommu_iotlb_sup; |
318afd41d x86/amd-iommu: Ma... |
317 |
|
5694703f1 x86, AMD IOMMU: a... |
318 |
/* |
3bd221724 amd-iommu: introd... |
319 320 321 322 323 324 |
* Make iterating over all IOMMUs easier */ #define for_each_iommu(iommu) \ list_for_each_entry((iommu), &amd_iommu_list, list) #define for_each_iommu_safe(iommu, next) \ list_for_each_entry_safe((iommu), (next), &amd_iommu_list, list) |
384de7291 amd-iommu: make a... |
325 326 327 328 329 330 |
#define APERTURE_RANGE_SHIFT 27 /* 128 MB */ #define APERTURE_RANGE_SIZE (1ULL << APERTURE_RANGE_SHIFT) #define APERTURE_RANGE_PAGES (APERTURE_RANGE_SIZE >> PAGE_SHIFT) #define APERTURE_MAX_RANGES 32 /* allows 4GB of DMA address space */ #define APERTURE_RANGE_INDEX(a) ((a) >> APERTURE_RANGE_SHIFT) #define APERTURE_PAGE_INDEX(a) (((a) >> 21) & 0x3fULL) |
9fdb19d64 AMD IOMMU: add pr... |
331 |
|
72e1dcc41 iommu/amd: Implem... |
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
/* * This struct is used to pass information about * incoming PPR faults around. */ struct amd_iommu_fault { u64 address; /* IO virtual address of the fault*/ u32 pasid; /* Address space identifier */ u16 device_id; /* Originating PCI device id */ u16 tag; /* PPR tag */ u16 flags; /* Fault flags */ }; #define PPR_FAULT_EXEC (1 << 1) #define PPR_FAULT_READ (1 << 2) #define PPR_FAULT_WRITE (1 << 5) #define PPR_FAULT_USER (1 << 6) #define PPR_FAULT_RSVD (1 << 7) #define PPR_FAULT_GN (1 << 8) |
f3572db82 iommu/amd: Add fu... |
352 |
struct iommu_domain; |
5694703f1 x86, AMD IOMMU: a... |
353 354 355 356 |
/* * This structure contains generic data for IOMMU protection domains * independent of their use. */ |
8d283c35a x86, AMD IOMMU: a... |
357 |
struct protection_domain { |
aeb26f553 x86/amd-iommu: Im... |
358 |
struct list_head list; /* for list of all protection domains */ |
7c392cbe9 x86/amd-iommu: Ke... |
359 |
struct list_head dev_list; /* List of all devices in this domain */ |
9fdb19d64 AMD IOMMU: add pr... |
360 |
spinlock_t lock; /* mostly used to lock the page table*/ |
5d214fe6e x86/amd-iommu: Pr... |
361 |
struct mutex api_lock; /* protect page tables in the iommu-api path */ |
9fdb19d64 AMD IOMMU: add pr... |
362 363 364 |
u16 id; /* the domain id written to the device table */ int mode; /* paging mode (0-6 levels) */ u64 *pt_root; /* page table root pointer */ |
52815b756 iommu/amd: Add su... |
365 366 |
int glx; /* Number of levels for GCR3 table */ u64 *gcr3_tbl; /* Guest CR3 table */ |
9fdb19d64 AMD IOMMU: add pr... |
367 |
unsigned long flags; /* flags to find out type of domain */ |
04bfdd840 x86/amd-iommu: Fl... |
368 |
bool updated; /* complete domain flush required */ |
863c74ebd AMD IOMMU: add de... |
369 |
unsigned dev_cnt; /* devices assigned to this domain */ |
c45961142 x86/amd-iommu: Ad... |
370 |
unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */ |
9fdb19d64 AMD IOMMU: add pr... |
371 |
void *priv; /* private data */ |
f3572db82 iommu/amd: Add fu... |
372 373 |
struct iommu_domain *iommu_domain; /* Pointer to generic domain structure */ |
c45961142 x86/amd-iommu: Ad... |
374 |
|
8d283c35a x86, AMD IOMMU: a... |
375 |
}; |
5694703f1 x86, AMD IOMMU: a... |
376 |
/* |
657cbb6b6 x86/amd-iommu: Us... |
377 378 379 |
* This struct contains device specific data for the IOMMU */ struct iommu_dev_data { |
7c392cbe9 x86/amd-iommu: Ke... |
380 |
struct list_head list; /* For domain->dev_list */ |
8fa5f802a x86/amd-iommu: In... |
381 |
struct list_head dev_data_list; /* For global dev_data_list */ |
71f775809 x86/amd-iommu: St... |
382 |
struct iommu_dev_data *alias_data;/* The alias dev_data */ |
657cbb6b6 x86/amd-iommu: Us... |
383 |
struct protection_domain *domain; /* Domain the device is bound to */ |
241000556 x86/amd-iommu: Ad... |
384 |
atomic_t bind; /* Domain attach reverent count */ |
f62dda66b x86/amd-iommu: St... |
385 |
u16 devid; /* PCI Device ID */ |
5abcdba4f iommu/amd: Put IO... |
386 387 |
bool iommu_v2; /* Device can make use of IOMMUv2 */ bool passthrough; /* Default for device is pt_domain */ |
ea61cddb9 x86/amd-iommu: St... |
388 389 390 391 |
struct { bool enabled; int qdep; } ats; /* ATS state */ |
c99afa25b iommu/amd: Implem... |
392 393 |
bool pri_tlp; /* PASID TLB required for PPR completions */ |
6a113ddc0 iommu/amd: Add de... |
394 |
u32 errata; /* Bitmap for errata to apply */ |
657cbb6b6 x86/amd-iommu: Us... |
395 396 397 |
}; /* |
c3239567a amd-iommu: introd... |
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
* For dynamic growth the aperture size is split into ranges of 128MB of * DMA address space each. This struct represents one such range. */ struct aperture_range { /* address allocation bitmap */ unsigned long *bitmap; /* * Array of PTE pages for the aperture. In this array we save all the * leaf pages of the domain page table used for the aperture. This way * we don't need to walk the page table to find a specific PTE. We can * just calculate its address in constant time. */ u64 *pte_pages[64]; |
384de7291 amd-iommu: make a... |
413 414 |
unsigned long offset; |
c3239567a amd-iommu: introd... |
415 416 417 |
}; /* |
5694703f1 x86, AMD IOMMU: a... |
418 419 |
* Data container for a dma_ops specific protection domain */ |
8d283c35a x86, AMD IOMMU: a... |
420 421 |
struct dma_ops_domain { struct list_head list; |
5694703f1 x86, AMD IOMMU: a... |
422 423 |
/* generic protection domain information */ |
8d283c35a x86, AMD IOMMU: a... |
424 |
struct protection_domain domain; |
5694703f1 x86, AMD IOMMU: a... |
425 426 |
/* size of the aperture for the mappings */ |
8d283c35a x86, AMD IOMMU: a... |
427 |
unsigned long aperture_size; |
5694703f1 x86, AMD IOMMU: a... |
428 429 |
/* address we start to search for free addresses */ |
803b8cb4d amd-iommu: change... |
430 |
unsigned long next_address; |
5694703f1 x86, AMD IOMMU: a... |
431 |
|
c3239567a amd-iommu: introd... |
432 |
/* address space relevant data */ |
384de7291 amd-iommu: make a... |
433 |
struct aperture_range *aperture[APERTURE_MAX_RANGES]; |
1c6557739 AMD IOMMU: implem... |
434 435 436 |
/* This will be set to true when TLB needs to be flushed */ bool need_flush; |
bd60b735c AMD IOMMU: don't ... |
437 438 439 440 441 442 |
/* * if this is a preallocated domain, keep the device for which it was * preallocated in this variable */ u16 target_dev; |
8d283c35a x86, AMD IOMMU: a... |
443 |
}; |
5694703f1 x86, AMD IOMMU: a... |
444 445 446 447 |
/* * Structure where we save information about one hardware AMD IOMMU in the * system. */ |
8d283c35a x86, AMD IOMMU: a... |
448 449 |
struct amd_iommu { struct list_head list; |
5694703f1 x86, AMD IOMMU: a... |
450 |
|
bb52777ec x86/amd-iommu: Ad... |
451 452 |
/* Index within the IOMMU array */ int index; |
5694703f1 x86, AMD IOMMU: a... |
453 |
/* locks the accesses to the hardware */ |
8d283c35a x86, AMD IOMMU: a... |
454 |
spinlock_t lock; |
3eaf28a1c AMD IOMMU: save p... |
455 456 |
/* Pointer to PCI device of this IOMMU */ struct pci_dev *dev; |
5694703f1 x86, AMD IOMMU: a... |
457 |
/* physical address of MMIO space */ |
8d283c35a x86, AMD IOMMU: a... |
458 |
u64 mmio_phys; |
5694703f1 x86, AMD IOMMU: a... |
459 |
/* virtual address of MMIO space */ |
8d283c35a x86, AMD IOMMU: a... |
460 |
u8 *mmio_base; |
5694703f1 x86, AMD IOMMU: a... |
461 462 |
/* capabilities of that IOMMU read from ACPI */ |
8d283c35a x86, AMD IOMMU: a... |
463 |
u32 cap; |
5694703f1 x86, AMD IOMMU: a... |
464 |
|
e9bf51971 x86/amd-iommu: Se... |
465 466 |
/* flags read from acpi table */ u8 acpi_flags; |
d99ddec3e x86/amd-iommu: Ad... |
467 468 |
/* Extended features */ u64 features; |
400a28a05 iommu/amd: Add io... |
469 470 |
/* IOMMUv2 */ bool is_iommu_v2; |
eac9fbc6a AMD IOMMU: struct... |
471 472 473 474 475 476 |
/* * Capability pointer. There could be more than one IOMMU per PCI * device function if there are more than one AMD IOMMU capability * pointers. */ u16 cap_ptr; |
ee893c24e AMD IOMMU: save p... |
477 478 |
/* pci domain of this IOMMU */ u16 pci_seg; |
5694703f1 x86, AMD IOMMU: a... |
479 |
/* first device this IOMMU handles. read from PCI */ |
8d283c35a x86, AMD IOMMU: a... |
480 |
u16 first_device; |
5694703f1 x86, AMD IOMMU: a... |
481 |
/* last device this IOMMU handles. read from PCI */ |
8d283c35a x86, AMD IOMMU: a... |
482 |
u16 last_device; |
5694703f1 x86, AMD IOMMU: a... |
483 484 |
/* start of exclusion range of that IOMMU */ |
8d283c35a x86, AMD IOMMU: a... |
485 |
u64 exclusion_start; |
5694703f1 x86, AMD IOMMU: a... |
486 |
/* length of exclusion range of that IOMMU */ |
8d283c35a x86, AMD IOMMU: a... |
487 |
u64 exclusion_length; |
5694703f1 x86, AMD IOMMU: a... |
488 |
/* command buffer virtual address */ |
8d283c35a x86, AMD IOMMU: a... |
489 |
u8 *cmd_buf; |
5694703f1 x86, AMD IOMMU: a... |
490 |
/* size of command buffer */ |
8d283c35a x86, AMD IOMMU: a... |
491 |
u32 cmd_buf_size; |
335503e57 AMD IOMMU: add ev... |
492 493 |
/* size of event buffer */ u32 evt_buf_size; |
eac9fbc6a AMD IOMMU: struct... |
494 495 |
/* event buffer virtual address */ u8 *evt_buf; |
a80dc3e0e AMD IOMMU: add MS... |
496 497 |
/* MSI number for event interrupt */ u16 evt_msi_num; |
335503e57 AMD IOMMU: add ev... |
498 |
|
1a29ac014 iommu/amd: Setup ... |
499 500 |
/* Base of the PPR log, if present */ u8 *ppr_log; |
a80dc3e0e AMD IOMMU: add MS... |
501 502 |
/* true if interrupts for this IOMMU are already enabled */ bool int_enabled; |
eac9fbc6a AMD IOMMU: struct... |
503 |
/* if one, we need to send a completion wait command */ |
0cfd7aa90 AMD IOMMU: conver... |
504 |
bool need_sync; |
eac9fbc6a AMD IOMMU: struct... |
505 |
|
5694703f1 x86, AMD IOMMU: a... |
506 |
/* default dma_ops domain for that IOMMU */ |
8d283c35a x86, AMD IOMMU: a... |
507 |
struct dma_ops_domain *default_dom; |
4c894f47b x86/amd-iommu: Wo... |
508 509 |
/* |
5bcd757f9 x86/amd-iommu: Re... |
510 511 |
* We can't rely on the BIOS to restore all values on reinit, so we * need to stash them |
4c894f47b x86/amd-iommu: Wo... |
512 |
*/ |
5bcd757f9 x86/amd-iommu: Re... |
513 514 515 516 517 518 519 520 521 522 523 524 525 |
/* The iommu BAR */ u32 stored_addr_lo; u32 stored_addr_hi; /* * Each iommu has 6 l1s, each of which is documented as having 0x12 * registers */ u32 stored_l1[6][0x12]; /* The l2 indirect registers */ u32 stored_l2[0x83]; |
8d283c35a x86, AMD IOMMU: a... |
526 |
}; |
5694703f1 x86, AMD IOMMU: a... |
527 528 529 530 |
/* * List with all IOMMUs in the system. This list is not locked because it is * only written and read at driver initialization or suspend time */ |
8d283c35a x86, AMD IOMMU: a... |
531 |
extern struct list_head amd_iommu_list; |
5694703f1 x86, AMD IOMMU: a... |
532 |
/* |
bb52777ec x86/amd-iommu: Ad... |
533 534 535 536 537 538 539 540 541 |
* Array with pointers to each IOMMU struct * The indices are referenced in the protection domains */ extern struct amd_iommu *amd_iommus[MAX_IOMMUS]; /* Number of IOMMUs present in the system */ extern int amd_iommus_present; /* |
aeb26f553 x86/amd-iommu: Im... |
542 543 544 545 546 547 |
* Declarations for the global list of all protection domains */ extern spinlock_t amd_iommu_pd_lock; extern struct list_head amd_iommu_pd_list; /* |
5694703f1 x86, AMD IOMMU: a... |
548 549 |
* Structure defining one entry in the device table */ |
8d283c35a x86, AMD IOMMU: a... |
550 |
struct dev_table_entry { |
ee6c28684 iommu/amd: Conver... |
551 |
u64 data[4]; |
8d283c35a x86, AMD IOMMU: a... |
552 |
}; |
5694703f1 x86, AMD IOMMU: a... |
553 554 555 |
/* * One entry for unity mappings parsed out of the ACPI table. */ |
8d283c35a x86, AMD IOMMU: a... |
556 557 |
struct unity_map_entry { struct list_head list; |
5694703f1 x86, AMD IOMMU: a... |
558 559 |
/* starting device id this entry is used for (including) */ |
8d283c35a x86, AMD IOMMU: a... |
560 |
u16 devid_start; |
5694703f1 x86, AMD IOMMU: a... |
561 |
/* end device id this entry is used for (including) */ |
8d283c35a x86, AMD IOMMU: a... |
562 |
u16 devid_end; |
5694703f1 x86, AMD IOMMU: a... |
563 564 |
/* start address to unity map (including) */ |
8d283c35a x86, AMD IOMMU: a... |
565 |
u64 address_start; |
5694703f1 x86, AMD IOMMU: a... |
566 |
/* end address to unity map (including) */ |
8d283c35a x86, AMD IOMMU: a... |
567 |
u64 address_end; |
5694703f1 x86, AMD IOMMU: a... |
568 569 |
/* required protection */ |
8d283c35a x86, AMD IOMMU: a... |
570 571 |
int prot; }; |
5694703f1 x86, AMD IOMMU: a... |
572 573 574 575 |
/* * List of all unity mappings. It is not locked because as runtime it is only * read. It is created at ACPI table parsing time. */ |
8d283c35a x86, AMD IOMMU: a... |
576 |
extern struct list_head amd_iommu_unity_map; |
5694703f1 x86, AMD IOMMU: a... |
577 578 579 580 581 582 583 584 |
/* * Data structures for device handling */ /* * Device table used by hardware. Read and write accesses by software are * locked with the amd_iommu_pd_table lock. */ |
8d283c35a x86, AMD IOMMU: a... |
585 |
extern struct dev_table_entry *amd_iommu_dev_table; |
5694703f1 x86, AMD IOMMU: a... |
586 587 588 589 590 |
/* * Alias table to find requestor ids to device ids. Not locked because only * read on runtime. */ |
8d283c35a x86, AMD IOMMU: a... |
591 |
extern u16 *amd_iommu_alias_table; |
5694703f1 x86, AMD IOMMU: a... |
592 593 594 595 |
/* * Reverse lookup table to find the IOMMU which translates a specific device. */ |
8d283c35a x86, AMD IOMMU: a... |
596 |
extern struct amd_iommu **amd_iommu_rlookup_table; |
5694703f1 x86, AMD IOMMU: a... |
597 |
/* size of the dma_ops aperture as power of 2 */ |
8d283c35a x86, AMD IOMMU: a... |
598 |
extern unsigned amd_iommu_aperture_order; |
5694703f1 x86, AMD IOMMU: a... |
599 |
/* largest PCI device id we expect translation requests for */ |
8d283c35a x86, AMD IOMMU: a... |
600 |
extern u16 amd_iommu_last_bdf; |
5694703f1 x86, AMD IOMMU: a... |
601 |
/* allocation bitmap for domain ids */ |
8d283c35a x86, AMD IOMMU: a... |
602 |
extern unsigned long *amd_iommu_pd_alloc_bitmap; |
afa9fdc2f iommu: remove ful... |
603 604 605 606 607 |
/* * If true, the addresses will be flushed on unmap time, not when * they are reused */ extern bool amd_iommu_unmap_flush; |
62f71abbc iommu/amd: Get th... |
608 609 |
/* Smallest number of PASIDs supported by any IOMMU in the system */ extern u32 amd_iommu_max_pasids; |
400a28a05 iommu/amd: Add io... |
610 |
extern bool amd_iommu_v2_present; |
5abcdba4f iommu/amd: Put IO... |
611 |
extern bool amd_iommu_force_isolation; |
52815b756 iommu/amd: Add su... |
612 613 |
/* Max levels of glxval supported */ extern int amd_iommu_max_glx_val; |
d591b0a3a x86, AMD IOMMU: r... |
614 615 616 617 618 619 |
/* takes bus and device/function and returns the device id * FIXME: should that be in generic PCI code? */ static inline u16 calc_devid(u8 bus, u8 devfn) { return (((u16)bus) << 8) | devfn; } |
a9dddbe04 AMD IOMMU: add ne... |
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
#ifdef CONFIG_AMD_IOMMU_STATS struct __iommu_counter { char *name; struct dentry *dent; u64 value; }; #define DECLARE_STATS_COUNTER(nm) \ static struct __iommu_counter nm = { \ .name = #nm, \ } #define INC_STATS_COUNTER(name) name.value += 1 #define ADD_STATS_COUNTER(name, x) name.value += (x) #define SUB_STATS_COUNTER(name, x) name.value -= (x) #else /* CONFIG_AMD_IOMMU_STATS */ #define DECLARE_STATS_COUNTER(name) #define INC_STATS_COUNTER(name) #define ADD_STATS_COUNTER(name, x) #define SUB_STATS_COUNTER(name, x) #endif /* CONFIG_AMD_IOMMU_STATS */ |
1965aae3c x86: Fix ASM_X86_... |
645 |
#endif /* _ASM_X86_AMD_IOMMU_TYPES_H */ |