1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * IOMMU API for ARM architected SMMUv3 implementations.
5 * Copyright (C) 2015 ARM Limited
11 #include <linux/bitfield.h>
12 #include <linux/iommu.h>
13 #include <linux/kernel.h>
14 #include <linux/mmzone.h>
15 #include <linux/sizes.h>
18 #define ARM_SMMU_IDR0 0x0
19 #define IDR0_ST_LVL GENMASK(28, 27)
20 #define IDR0_ST_LVL_2LVL 1
21 #define IDR0_STALL_MODEL GENMASK(25, 24)
22 #define IDR0_STALL_MODEL_STALL 0
23 #define IDR0_STALL_MODEL_FORCE 2
24 #define IDR0_TTENDIAN GENMASK(22, 21)
25 #define IDR0_TTENDIAN_MIXED 0
26 #define IDR0_TTENDIAN_LE 2
27 #define IDR0_TTENDIAN_BE 3
28 #define IDR0_CD2L (1 << 19)
29 #define IDR0_VMID16 (1 << 18)
30 #define IDR0_PRI (1 << 16)
31 #define IDR0_SEV (1 << 14)
32 #define IDR0_MSI (1 << 13)
33 #define IDR0_ASID16 (1 << 12)
34 #define IDR0_ATS (1 << 10)
35 #define IDR0_HYP (1 << 9)
36 #define IDR0_COHACC (1 << 4)
37 #define IDR0_TTF GENMASK(3, 2)
38 #define IDR0_TTF_AARCH64 2
39 #define IDR0_TTF_AARCH32_64 3
40 #define IDR0_S1P (1 << 1)
41 #define IDR0_S2P (1 << 0)
43 #define ARM_SMMU_IDR1 0x4
44 #define IDR1_TABLES_PRESET (1 << 30)
45 #define IDR1_QUEUES_PRESET (1 << 29)
46 #define IDR1_REL (1 << 28)
47 #define IDR1_CMDQS GENMASK(25, 21)
48 #define IDR1_EVTQS GENMASK(20, 16)
49 #define IDR1_PRIQS GENMASK(15, 11)
50 #define IDR1_SSIDSIZE GENMASK(10, 6)
51 #define IDR1_SIDSIZE GENMASK(5, 0)
53 #define ARM_SMMU_IDR3 0xc
54 #define IDR3_RIL (1 << 10)
56 #define ARM_SMMU_IDR5 0x14
57 #define IDR5_STALL_MAX GENMASK(31, 16)
58 #define IDR5_GRAN64K (1 << 6)
59 #define IDR5_GRAN16K (1 << 5)
60 #define IDR5_GRAN4K (1 << 4)
61 #define IDR5_OAS GENMASK(2, 0)
62 #define IDR5_OAS_32_BIT 0
63 #define IDR5_OAS_36_BIT 1
64 #define IDR5_OAS_40_BIT 2
65 #define IDR5_OAS_42_BIT 3
66 #define IDR5_OAS_44_BIT 4
67 #define IDR5_OAS_48_BIT 5
68 #define IDR5_OAS_52_BIT 6
69 #define IDR5_VAX GENMASK(11, 10)
70 #define IDR5_VAX_52_BIT 1
72 #define ARM_SMMU_CR0 0x20
73 #define CR0_ATSCHK (1 << 4)
74 #define CR0_CMDQEN (1 << 3)
75 #define CR0_EVTQEN (1 << 2)
76 #define CR0_PRIQEN (1 << 1)
77 #define CR0_SMMUEN (1 << 0)
79 #define ARM_SMMU_CR0ACK 0x24
81 #define ARM_SMMU_CR1 0x28
82 #define CR1_TABLE_SH GENMASK(11, 10)
83 #define CR1_TABLE_OC GENMASK(9, 8)
84 #define CR1_TABLE_IC GENMASK(7, 6)
85 #define CR1_QUEUE_SH GENMASK(5, 4)
86 #define CR1_QUEUE_OC GENMASK(3, 2)
87 #define CR1_QUEUE_IC GENMASK(1, 0)
88 /* CR1 cacheability fields don't quite follow the usual TCR-style encoding */
89 #define CR1_CACHE_NC 0
90 #define CR1_CACHE_WB 1
91 #define CR1_CACHE_WT 2
93 #define ARM_SMMU_CR2 0x2c
94 #define CR2_PTM (1 << 2)
95 #define CR2_RECINVSID (1 << 1)
96 #define CR2_E2H (1 << 0)
98 #define ARM_SMMU_GBPA 0x44
99 #define GBPA_UPDATE (1 << 31)
100 #define GBPA_ABORT (1 << 20)
102 #define ARM_SMMU_IRQ_CTRL 0x50
103 #define IRQ_CTRL_EVTQ_IRQEN (1 << 2)
104 #define IRQ_CTRL_PRIQ_IRQEN (1 << 1)
105 #define IRQ_CTRL_GERROR_IRQEN (1 << 0)
107 #define ARM_SMMU_IRQ_CTRLACK 0x54
109 #define ARM_SMMU_GERROR 0x60
110 #define GERROR_SFM_ERR (1 << 8)
111 #define GERROR_MSI_GERROR_ABT_ERR (1 << 7)
112 #define GERROR_MSI_PRIQ_ABT_ERR (1 << 6)
113 #define GERROR_MSI_EVTQ_ABT_ERR (1 << 5)
114 #define GERROR_MSI_CMDQ_ABT_ERR (1 << 4)
115 #define GERROR_PRIQ_ABT_ERR (1 << 3)
116 #define GERROR_EVTQ_ABT_ERR (1 << 2)
117 #define GERROR_CMDQ_ERR (1 << 0)
118 #define GERROR_ERR_MASK 0xfd
120 #define ARM_SMMU_GERRORN 0x64
122 #define ARM_SMMU_GERROR_IRQ_CFG0 0x68
123 #define ARM_SMMU_GERROR_IRQ_CFG1 0x70
124 #define ARM_SMMU_GERROR_IRQ_CFG2 0x74
126 #define ARM_SMMU_STRTAB_BASE 0x80
127 #define STRTAB_BASE_RA (1UL << 62)
128 #define STRTAB_BASE_ADDR_MASK GENMASK_ULL(51, 6)
130 #define ARM_SMMU_STRTAB_BASE_CFG 0x88
131 #define STRTAB_BASE_CFG_FMT GENMASK(17, 16)
132 #define STRTAB_BASE_CFG_FMT_LINEAR 0
133 #define STRTAB_BASE_CFG_FMT_2LVL 1
134 #define STRTAB_BASE_CFG_SPLIT GENMASK(10, 6)
135 #define STRTAB_BASE_CFG_LOG2SIZE GENMASK(5, 0)
137 #define ARM_SMMU_CMDQ_BASE 0x90
138 #define ARM_SMMU_CMDQ_PROD 0x98
139 #define ARM_SMMU_CMDQ_CONS 0x9c
141 #define ARM_SMMU_EVTQ_BASE 0xa0
142 #define ARM_SMMU_EVTQ_PROD 0x100a8
143 #define ARM_SMMU_EVTQ_CONS 0x100ac
144 #define ARM_SMMU_EVTQ_IRQ_CFG0 0xb0
145 #define ARM_SMMU_EVTQ_IRQ_CFG1 0xb8
146 #define ARM_SMMU_EVTQ_IRQ_CFG2 0xbc
148 #define ARM_SMMU_PRIQ_BASE 0xc0
149 #define ARM_SMMU_PRIQ_PROD 0x100c8
150 #define ARM_SMMU_PRIQ_CONS 0x100cc
151 #define ARM_SMMU_PRIQ_IRQ_CFG0 0xd0
152 #define ARM_SMMU_PRIQ_IRQ_CFG1 0xd8
153 #define ARM_SMMU_PRIQ_IRQ_CFG2 0xdc
155 #define ARM_SMMU_REG_SZ 0xe00
157 /* Common MSI config fields */
158 #define MSI_CFG0_ADDR_MASK GENMASK_ULL(51, 2)
159 #define MSI_CFG2_SH GENMASK(5, 4)
160 #define MSI_CFG2_MEMATTR GENMASK(3, 0)
162 /* Common memory attribute values */
163 #define ARM_SMMU_SH_NSH 0
164 #define ARM_SMMU_SH_OSH 2
165 #define ARM_SMMU_SH_ISH 3
166 #define ARM_SMMU_MEMATTR_DEVICE_nGnRE 0x1
167 #define ARM_SMMU_MEMATTR_OIWB 0xf
169 #define Q_IDX(llq, p) ((p) & ((1 << (llq)->max_n_shift) - 1))
170 #define Q_WRP(llq, p) ((p) & (1 << (llq)->max_n_shift))
171 #define Q_OVERFLOW_FLAG (1U << 31)
172 #define Q_OVF(p) ((p) & Q_OVERFLOW_FLAG)
173 #define Q_ENT(q, p) ((q)->base + \
174 Q_IDX(&((q)->llq), p) * \
177 #define Q_BASE_RWA (1UL << 62)
178 #define Q_BASE_ADDR_MASK GENMASK_ULL(51, 5)
179 #define Q_BASE_LOG2SIZE GENMASK(4, 0)
181 /* Ensure DMA allocations are naturally aligned */
182 #ifdef CONFIG_CMA_ALIGNMENT
183 #define Q_MAX_SZ_SHIFT (PAGE_SHIFT + CONFIG_CMA_ALIGNMENT)
185 #define Q_MAX_SZ_SHIFT (PAGE_SHIFT + MAX_ORDER - 1)
191 * Linear: Enough to cover 1 << IDR1.SIDSIZE entries
192 * 2lvl: 128k L1 entries,
193 * 256 lazy entries per table (each table covers a PCI bus)
195 #define STRTAB_L1_SZ_SHIFT 20
196 #define STRTAB_SPLIT 8
198 #define STRTAB_L1_DESC_DWORDS 1
199 #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0)
200 #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6)
202 #define STRTAB_STE_DWORDS 8
203 #define STRTAB_STE_0_V (1UL << 0)
204 #define STRTAB_STE_0_CFG GENMASK_ULL(3, 1)
205 #define STRTAB_STE_0_CFG_ABORT 0
206 #define STRTAB_STE_0_CFG_BYPASS 4
207 #define STRTAB_STE_0_CFG_S1_TRANS 5
208 #define STRTAB_STE_0_CFG_S2_TRANS 6
210 #define STRTAB_STE_0_S1FMT GENMASK_ULL(5, 4)
211 #define STRTAB_STE_0_S1FMT_LINEAR 0
212 #define STRTAB_STE_0_S1FMT_64K_L2 2
213 #define STRTAB_STE_0_S1CTXPTR_MASK GENMASK_ULL(51, 6)
214 #define STRTAB_STE_0_S1CDMAX GENMASK_ULL(63, 59)
216 #define STRTAB_STE_1_S1DSS GENMASK_ULL(1, 0)
217 #define STRTAB_STE_1_S1DSS_TERMINATE 0x0
218 #define STRTAB_STE_1_S1DSS_BYPASS 0x1
219 #define STRTAB_STE_1_S1DSS_SSID0 0x2
221 #define STRTAB_STE_1_S1C_CACHE_NC 0UL
222 #define STRTAB_STE_1_S1C_CACHE_WBRA 1UL
223 #define STRTAB_STE_1_S1C_CACHE_WT 2UL
224 #define STRTAB_STE_1_S1C_CACHE_WB 3UL
225 #define STRTAB_STE_1_S1CIR GENMASK_ULL(3, 2)
226 #define STRTAB_STE_1_S1COR GENMASK_ULL(5, 4)
227 #define STRTAB_STE_1_S1CSH GENMASK_ULL(7, 6)
229 #define STRTAB_STE_1_S1STALLD (1UL << 27)
231 #define STRTAB_STE_1_EATS GENMASK_ULL(29, 28)
232 #define STRTAB_STE_1_EATS_ABT 0UL
233 #define STRTAB_STE_1_EATS_TRANS 1UL
234 #define STRTAB_STE_1_EATS_S1CHK 2UL
236 #define STRTAB_STE_1_STRW GENMASK_ULL(31, 30)
237 #define STRTAB_STE_1_STRW_NSEL1 0UL
238 #define STRTAB_STE_1_STRW_EL2 2UL
240 #define STRTAB_STE_1_SHCFG GENMASK_ULL(45, 44)
241 #define STRTAB_STE_1_SHCFG_INCOMING 1UL
243 #define STRTAB_STE_2_S2VMID GENMASK_ULL(15, 0)
244 #define STRTAB_STE_2_VTCR GENMASK_ULL(50, 32)
245 #define STRTAB_STE_2_VTCR_S2T0SZ GENMASK_ULL(5, 0)
246 #define STRTAB_STE_2_VTCR_S2SL0 GENMASK_ULL(7, 6)
247 #define STRTAB_STE_2_VTCR_S2IR0 GENMASK_ULL(9, 8)
248 #define STRTAB_STE_2_VTCR_S2OR0 GENMASK_ULL(11, 10)
249 #define STRTAB_STE_2_VTCR_S2SH0 GENMASK_ULL(13, 12)
250 #define STRTAB_STE_2_VTCR_S2TG GENMASK_ULL(15, 14)
251 #define STRTAB_STE_2_VTCR_S2PS GENMASK_ULL(18, 16)
252 #define STRTAB_STE_2_S2AA64 (1UL << 51)
253 #define STRTAB_STE_2_S2ENDI (1UL << 52)
254 #define STRTAB_STE_2_S2PTW (1UL << 54)
255 #define STRTAB_STE_2_S2R (1UL << 58)
257 #define STRTAB_STE_3_S2TTB_MASK GENMASK_ULL(51, 4)
260 * Context descriptors.
262 * Linear: when less than 1024 SSIDs are supported
263 * 2lvl: at most 1024 L1 entries,
264 * 1024 lazy entries per table.
266 #define CTXDESC_SPLIT 10
267 #define CTXDESC_L2_ENTRIES (1 << CTXDESC_SPLIT)
269 #define CTXDESC_L1_DESC_DWORDS 1
270 #define CTXDESC_L1_DESC_V (1UL << 0)
271 #define CTXDESC_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 12)
273 #define CTXDESC_CD_DWORDS 8
274 #define CTXDESC_CD_0_TCR_T0SZ GENMASK_ULL(5, 0)
275 #define CTXDESC_CD_0_TCR_TG0 GENMASK_ULL(7, 6)
276 #define CTXDESC_CD_0_TCR_IRGN0 GENMASK_ULL(9, 8)
277 #define CTXDESC_CD_0_TCR_ORGN0 GENMASK_ULL(11, 10)
278 #define CTXDESC_CD_0_TCR_SH0 GENMASK_ULL(13, 12)
279 #define CTXDESC_CD_0_TCR_EPD0 (1ULL << 14)
280 #define CTXDESC_CD_0_TCR_EPD1 (1ULL << 30)
282 #define CTXDESC_CD_0_ENDI (1UL << 15)
283 #define CTXDESC_CD_0_V (1UL << 31)
285 #define CTXDESC_CD_0_TCR_IPS GENMASK_ULL(34, 32)
286 #define CTXDESC_CD_0_TCR_TBI0 (1ULL << 38)
288 #define CTXDESC_CD_0_AA64 (1UL << 41)
289 #define CTXDESC_CD_0_S (1UL << 44)
290 #define CTXDESC_CD_0_R (1UL << 45)
291 #define CTXDESC_CD_0_A (1UL << 46)
292 #define CTXDESC_CD_0_ASET (1UL << 47)
293 #define CTXDESC_CD_0_ASID GENMASK_ULL(63, 48)
295 #define CTXDESC_CD_1_TTB0_MASK GENMASK_ULL(51, 4)
298 * When the SMMU only supports linear context descriptor tables, pick a
299 * reasonable size limit (64kB).
301 #define CTXDESC_LINEAR_CDMAX ilog2(SZ_64K / (CTXDESC_CD_DWORDS << 3))
304 #define CMDQ_ENT_SZ_SHIFT 4
305 #define CMDQ_ENT_DWORDS ((1 << CMDQ_ENT_SZ_SHIFT) >> 3)
306 #define CMDQ_MAX_SZ_SHIFT (Q_MAX_SZ_SHIFT - CMDQ_ENT_SZ_SHIFT)
308 #define CMDQ_CONS_ERR GENMASK(30, 24)
309 #define CMDQ_ERR_CERROR_NONE_IDX 0
310 #define CMDQ_ERR_CERROR_ILL_IDX 1
311 #define CMDQ_ERR_CERROR_ABT_IDX 2
312 #define CMDQ_ERR_CERROR_ATC_INV_IDX 3
314 #define CMDQ_PROD_OWNED_FLAG Q_OVERFLOW_FLAG
317 * This is used to size the command queue and therefore must be at least
318 * BITS_PER_LONG so that the valid_map works correctly (it relies on the
319 * total number of queue entries being a multiple of BITS_PER_LONG).
321 #define CMDQ_BATCH_ENTRIES BITS_PER_LONG
323 #define CMDQ_0_OP GENMASK_ULL(7, 0)
324 #define CMDQ_0_SSV (1UL << 11)
326 #define CMDQ_PREFETCH_0_SID GENMASK_ULL(63, 32)
327 #define CMDQ_PREFETCH_1_SIZE GENMASK_ULL(4, 0)
328 #define CMDQ_PREFETCH_1_ADDR_MASK GENMASK_ULL(63, 12)
330 #define CMDQ_CFGI_0_SSID GENMASK_ULL(31, 12)
331 #define CMDQ_CFGI_0_SID GENMASK_ULL(63, 32)
332 #define CMDQ_CFGI_1_LEAF (1UL << 0)
333 #define CMDQ_CFGI_1_RANGE GENMASK_ULL(4, 0)
335 #define CMDQ_TLBI_0_NUM GENMASK_ULL(16, 12)
336 #define CMDQ_TLBI_RANGE_NUM_MAX 31
337 #define CMDQ_TLBI_0_SCALE GENMASK_ULL(24, 20)
338 #define CMDQ_TLBI_0_VMID GENMASK_ULL(47, 32)
339 #define CMDQ_TLBI_0_ASID GENMASK_ULL(63, 48)
340 #define CMDQ_TLBI_1_LEAF (1UL << 0)
341 #define CMDQ_TLBI_1_TTL GENMASK_ULL(9, 8)
342 #define CMDQ_TLBI_1_TG GENMASK_ULL(11, 10)
343 #define CMDQ_TLBI_1_VA_MASK GENMASK_ULL(63, 12)
344 #define CMDQ_TLBI_1_IPA_MASK GENMASK_ULL(51, 12)
346 #define CMDQ_ATC_0_SSID GENMASK_ULL(31, 12)
347 #define CMDQ_ATC_0_SID GENMASK_ULL(63, 32)
348 #define CMDQ_ATC_0_GLOBAL (1UL << 9)
349 #define CMDQ_ATC_1_SIZE GENMASK_ULL(5, 0)
350 #define CMDQ_ATC_1_ADDR_MASK GENMASK_ULL(63, 12)
352 #define CMDQ_PRI_0_SSID GENMASK_ULL(31, 12)
353 #define CMDQ_PRI_0_SID GENMASK_ULL(63, 32)
354 #define CMDQ_PRI_1_GRPID GENMASK_ULL(8, 0)
355 #define CMDQ_PRI_1_RESP GENMASK_ULL(13, 12)
357 #define CMDQ_SYNC_0_CS GENMASK_ULL(13, 12)
358 #define CMDQ_SYNC_0_CS_NONE 0
359 #define CMDQ_SYNC_0_CS_IRQ 1
360 #define CMDQ_SYNC_0_CS_SEV 2
361 #define CMDQ_SYNC_0_MSH GENMASK_ULL(23, 22)
362 #define CMDQ_SYNC_0_MSIATTR GENMASK_ULL(27, 24)
363 #define CMDQ_SYNC_0_MSIDATA GENMASK_ULL(63, 32)
364 #define CMDQ_SYNC_1_MSIADDR_MASK GENMASK_ULL(51, 2)
367 #define EVTQ_ENT_SZ_SHIFT 5
368 #define EVTQ_ENT_DWORDS ((1 << EVTQ_ENT_SZ_SHIFT) >> 3)
369 #define EVTQ_MAX_SZ_SHIFT (Q_MAX_SZ_SHIFT - EVTQ_ENT_SZ_SHIFT)
371 #define EVTQ_0_ID GENMASK_ULL(7, 0)
374 #define PRIQ_ENT_SZ_SHIFT 4
375 #define PRIQ_ENT_DWORDS ((1 << PRIQ_ENT_SZ_SHIFT) >> 3)
376 #define PRIQ_MAX_SZ_SHIFT (Q_MAX_SZ_SHIFT - PRIQ_ENT_SZ_SHIFT)
378 #define PRIQ_0_SID GENMASK_ULL(31, 0)
379 #define PRIQ_0_SSID GENMASK_ULL(51, 32)
380 #define PRIQ_0_PERM_PRIV (1UL << 58)
381 #define PRIQ_0_PERM_EXEC (1UL << 59)
382 #define PRIQ_0_PERM_READ (1UL << 60)
383 #define PRIQ_0_PERM_WRITE (1UL << 61)
384 #define PRIQ_0_PRG_LAST (1UL << 62)
385 #define PRIQ_0_SSID_V (1UL << 63)
387 #define PRIQ_1_PRG_IDX GENMASK_ULL(8, 0)
388 #define PRIQ_1_ADDR_MASK GENMASK_ULL(63, 12)
390 /* High-level queue structures */
391 #define ARM_SMMU_POLL_TIMEOUT_US 1000000 /* 1s! */
392 #define ARM_SMMU_POLL_SPIN_COUNT 10
394 #define MSI_IOVA_BASE 0x8000000
395 #define MSI_IOVA_LENGTH 0x100000
403 struct arm_smmu_cmdq_ent
{
406 bool substream_valid
;
408 /* Command-specific fields */
410 #define CMDQ_OP_PREFETCH_CFG 0x1
417 #define CMDQ_OP_CFGI_STE 0x3
418 #define CMDQ_OP_CFGI_ALL 0x4
419 #define CMDQ_OP_CFGI_CD 0x5
420 #define CMDQ_OP_CFGI_CD_ALL 0x6
430 #define CMDQ_OP_TLBI_NH_ASID 0x11
431 #define CMDQ_OP_TLBI_NH_VA 0x12
432 #define CMDQ_OP_TLBI_EL2_ALL 0x20
433 #define CMDQ_OP_TLBI_S12_VMALL 0x28
434 #define CMDQ_OP_TLBI_S2_IPA 0x2a
435 #define CMDQ_OP_TLBI_NSNH_ALL 0x30
447 #define CMDQ_OP_ATC_INV 0x40
448 #define ATC_INV_SIZE_ALL 52
457 #define CMDQ_OP_PRI_RESP 0x41
465 #define CMDQ_OP_CMD_SYNC 0x46
472 struct arm_smmu_ll_queue
{
483 u8 __pad
[SMP_CACHE_BYTES
];
484 } ____cacheline_aligned_in_smp
;
488 struct arm_smmu_queue
{
489 struct arm_smmu_ll_queue llq
;
490 int irq
; /* Wired interrupt */
498 u32 __iomem
*prod_reg
;
499 u32 __iomem
*cons_reg
;
502 struct arm_smmu_queue_poll
{
505 unsigned int spin_cnt
;
509 struct arm_smmu_cmdq
{
510 struct arm_smmu_queue q
;
511 atomic_long_t
*valid_map
;
516 struct arm_smmu_cmdq_batch
{
517 u64 cmds
[CMDQ_BATCH_ENTRIES
* CMDQ_ENT_DWORDS
];
521 struct arm_smmu_evtq
{
522 struct arm_smmu_queue q
;
526 struct arm_smmu_priq
{
527 struct arm_smmu_queue q
;
530 /* High-level stream table and context descriptor structures */
531 struct arm_smmu_strtab_l1_desc
{
535 dma_addr_t l2ptr_dma
;
538 struct arm_smmu_ctx_desc
{
545 struct mm_struct
*mm
;
548 struct arm_smmu_l1_ctx_desc
{
550 dma_addr_t l2ptr_dma
;
553 struct arm_smmu_ctx_desc_cfg
{
555 dma_addr_t cdtab_dma
;
556 struct arm_smmu_l1_ctx_desc
*l1_desc
;
557 unsigned int num_l1_ents
;
560 struct arm_smmu_s1_cfg
{
561 struct arm_smmu_ctx_desc_cfg cdcfg
;
562 struct arm_smmu_ctx_desc cd
;
567 struct arm_smmu_s2_cfg
{
573 struct arm_smmu_strtab_cfg
{
575 dma_addr_t strtab_dma
;
576 struct arm_smmu_strtab_l1_desc
*l1_desc
;
577 unsigned int num_l1_ents
;
583 /* An SMMUv3 instance */
584 struct arm_smmu_device
{
589 #define ARM_SMMU_FEAT_2_LVL_STRTAB (1 << 0)
590 #define ARM_SMMU_FEAT_2_LVL_CDTAB (1 << 1)
591 #define ARM_SMMU_FEAT_TT_LE (1 << 2)
592 #define ARM_SMMU_FEAT_TT_BE (1 << 3)
593 #define ARM_SMMU_FEAT_PRI (1 << 4)
594 #define ARM_SMMU_FEAT_ATS (1 << 5)
595 #define ARM_SMMU_FEAT_SEV (1 << 6)
596 #define ARM_SMMU_FEAT_MSI (1 << 7)
597 #define ARM_SMMU_FEAT_COHERENCY (1 << 8)
598 #define ARM_SMMU_FEAT_TRANS_S1 (1 << 9)
599 #define ARM_SMMU_FEAT_TRANS_S2 (1 << 10)
600 #define ARM_SMMU_FEAT_STALLS (1 << 11)
601 #define ARM_SMMU_FEAT_HYP (1 << 12)
602 #define ARM_SMMU_FEAT_STALL_FORCE (1 << 13)
603 #define ARM_SMMU_FEAT_VAX (1 << 14)
604 #define ARM_SMMU_FEAT_RANGE_INV (1 << 15)
605 #define ARM_SMMU_FEAT_BTM (1 << 16)
606 #define ARM_SMMU_FEAT_SVA (1 << 17)
609 #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0)
610 #define ARM_SMMU_OPT_PAGE0_REGS_ONLY (1 << 1)
611 #define ARM_SMMU_OPT_MSIPOLL (1 << 2)
614 struct arm_smmu_cmdq cmdq
;
615 struct arm_smmu_evtq evtq
;
616 struct arm_smmu_priq priq
;
621 unsigned long ias
; /* IPA */
622 unsigned long oas
; /* PA */
623 unsigned long pgsize_bitmap
;
625 #define ARM_SMMU_MAX_ASIDS (1 << 16)
626 unsigned int asid_bits
;
628 #define ARM_SMMU_MAX_VMIDS (1 << 16)
629 unsigned int vmid_bits
;
630 DECLARE_BITMAP(vmid_map
, ARM_SMMU_MAX_VMIDS
);
632 unsigned int ssid_bits
;
633 unsigned int sid_bits
;
635 struct arm_smmu_strtab_cfg strtab_cfg
;
637 /* IOMMU core code handle */
638 struct iommu_device iommu
;
641 /* SMMU private data for each master */
642 struct arm_smmu_master
{
643 struct arm_smmu_device
*smmu
;
645 struct arm_smmu_domain
*domain
;
646 struct list_head domain_head
;
648 unsigned int num_sids
;
651 struct list_head bonds
;
652 unsigned int ssid_bits
;
655 /* SMMU private data for an IOMMU domain */
656 enum arm_smmu_domain_stage
{
657 ARM_SMMU_DOMAIN_S1
= 0,
659 ARM_SMMU_DOMAIN_NESTED
,
660 ARM_SMMU_DOMAIN_BYPASS
,
663 struct arm_smmu_domain
{
664 struct arm_smmu_device
*smmu
;
665 struct mutex init_mutex
; /* Protects smmu pointer */
667 struct io_pgtable_ops
*pgtbl_ops
;
669 atomic_t nr_ats_masters
;
671 enum arm_smmu_domain_stage stage
;
673 struct arm_smmu_s1_cfg s1_cfg
;
674 struct arm_smmu_s2_cfg s2_cfg
;
677 struct iommu_domain domain
;
679 struct list_head devices
;
680 spinlock_t devices_lock
;
682 struct list_head mmu_notifiers
;
685 static inline struct arm_smmu_domain
*to_smmu_domain(struct iommu_domain
*dom
)
687 return container_of(dom
, struct arm_smmu_domain
, domain
);
690 extern struct xarray arm_smmu_asid_xa
;
691 extern struct mutex arm_smmu_asid_lock
;
692 extern struct arm_smmu_ctx_desc quiet_cd
;
694 int arm_smmu_write_ctx_desc(struct arm_smmu_domain
*smmu_domain
, int ssid
,
695 struct arm_smmu_ctx_desc
*cd
);
696 void arm_smmu_tlb_inv_asid(struct arm_smmu_device
*smmu
, u16 asid
);
697 bool arm_smmu_free_asid(struct arm_smmu_ctx_desc
*cd
);
698 int arm_smmu_atc_inv_domain(struct arm_smmu_domain
*smmu_domain
, int ssid
,
699 unsigned long iova
, size_t size
);
701 #ifdef CONFIG_ARM_SMMU_V3_SVA
702 bool arm_smmu_sva_supported(struct arm_smmu_device
*smmu
);
703 bool arm_smmu_master_sva_supported(struct arm_smmu_master
*master
);
704 bool arm_smmu_master_sva_enabled(struct arm_smmu_master
*master
);
705 int arm_smmu_master_enable_sva(struct arm_smmu_master
*master
);
706 int arm_smmu_master_disable_sva(struct arm_smmu_master
*master
);
707 struct iommu_sva
*arm_smmu_sva_bind(struct device
*dev
, struct mm_struct
*mm
,
709 void arm_smmu_sva_unbind(struct iommu_sva
*handle
);
710 u32
arm_smmu_sva_get_pasid(struct iommu_sva
*handle
);
711 void arm_smmu_sva_notifier_synchronize(void);
712 #else /* CONFIG_ARM_SMMU_V3_SVA */
713 static inline bool arm_smmu_sva_supported(struct arm_smmu_device
*smmu
)
718 static inline bool arm_smmu_master_sva_supported(struct arm_smmu_master
*master
)
723 static inline bool arm_smmu_master_sva_enabled(struct arm_smmu_master
*master
)
728 static inline int arm_smmu_master_enable_sva(struct arm_smmu_master
*master
)
733 static inline int arm_smmu_master_disable_sva(struct arm_smmu_master
*master
)
738 static inline struct iommu_sva
*
739 arm_smmu_sva_bind(struct device
*dev
, struct mm_struct
*mm
, void *drvdata
)
741 return ERR_PTR(-ENODEV
);
744 static inline void arm_smmu_sva_unbind(struct iommu_sva
*handle
) {}
746 static inline u32
arm_smmu_sva_get_pasid(struct iommu_sva
*handle
)
748 return IOMMU_PASID_INVALID
;
751 static inline void arm_smmu_sva_notifier_synchronize(void) {}
752 #endif /* CONFIG_ARM_SMMU_V3_SVA */
753 #endif /* _ARM_SMMU_V3_H */