blob: 6fea0b0b7e519dec922557563353e01df8a65e2d [file] [log] [blame]
Thomas Gleixner45051532019-05-29 16:57:47 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Rob Clark2b037742017-08-09 10:43:03 -04002/*
3 * IOMMU API for ARM architected SMMU implementations.
4 *
Rob Clark2b037742017-08-09 10:43:03 -04005 * Copyright (C) 2013 ARM Limited
6 *
7 * Author: Will Deacon <will.deacon@arm.com>
8 */
9
Robin Murphyc5fc6482019-08-15 19:37:32 +010010#ifndef _ARM_SMMU_H
11#define _ARM_SMMU_H
Rob Clark2b037742017-08-09 10:43:03 -040012
Robin Murphyfc058d32019-08-15 19:37:33 +010013#include <linux/atomic.h>
Robin Murphy0caf5f42019-08-15 19:37:23 +010014#include <linux/bits.h>
Robin Murphyfc058d32019-08-15 19:37:33 +010015#include <linux/clk.h>
16#include <linux/device.h>
17#include <linux/iommu.h>
18#include <linux/mutex.h>
19#include <linux/spinlock.h>
20#include <linux/types.h>
Robin Murphy0caf5f42019-08-15 19:37:23 +010021
Rob Clark2b037742017-08-09 10:43:03 -040022/* Configuration registers */
23#define ARM_SMMU_GR0_sCR0 0x0
Robin Murphy0caf5f42019-08-15 19:37:23 +010024#define sCR0_VMID16EN BIT(31)
25#define sCR0_BSU GENMASK(15, 14)
26#define sCR0_FB BIT(13)
27#define sCR0_PTM BIT(12)
28#define sCR0_VMIDPNE BIT(11)
29#define sCR0_USFCFG BIT(10)
30#define sCR0_GCFGFIE BIT(5)
31#define sCR0_GCFGFRE BIT(4)
32#define sCR0_EXIDENABLE BIT(3)
33#define sCR0_GFIE BIT(2)
34#define sCR0_GFRE BIT(1)
35#define sCR0_CLIENTPD BIT(0)
Rob Clark2b037742017-08-09 10:43:03 -040036
37/* Auxiliary Configuration register */
38#define ARM_SMMU_GR0_sACR 0x10
39
40/* Identification registers */
41#define ARM_SMMU_GR0_ID0 0x20
Robin Murphy0caf5f42019-08-15 19:37:23 +010042#define ID0_S1TS BIT(30)
43#define ID0_S2TS BIT(29)
44#define ID0_NTS BIT(28)
45#define ID0_SMS BIT(27)
46#define ID0_ATOSNS BIT(26)
47#define ID0_PTFS_NO_AARCH32 BIT(25)
48#define ID0_PTFS_NO_AARCH32S BIT(24)
49#define ID0_NUMIRPT GENMASK(23, 16)
50#define ID0_CTTW BIT(14)
51#define ID0_NUMSIDB GENMASK(12, 9)
52#define ID0_EXIDS BIT(8)
53#define ID0_NUMSMRG GENMASK(7, 0)
54
Rob Clark2b037742017-08-09 10:43:03 -040055#define ARM_SMMU_GR0_ID1 0x24
Robin Murphy0caf5f42019-08-15 19:37:23 +010056#define ID1_PAGESIZE BIT(31)
57#define ID1_NUMPAGENDXB GENMASK(30, 28)
58#define ID1_NUMS2CB GENMASK(23, 16)
59#define ID1_NUMCB GENMASK(7, 0)
60
Rob Clark2b037742017-08-09 10:43:03 -040061#define ARM_SMMU_GR0_ID2 0x28
Robin Murphy0caf5f42019-08-15 19:37:23 +010062#define ID2_VMID16 BIT(15)
63#define ID2_PTFS_64K BIT(14)
64#define ID2_PTFS_16K BIT(13)
65#define ID2_PTFS_4K BIT(12)
66#define ID2_UBS GENMASK(11, 8)
67#define ID2_OAS GENMASK(7, 4)
68#define ID2_IAS GENMASK(3, 0)
69
Rob Clark2b037742017-08-09 10:43:03 -040070#define ARM_SMMU_GR0_ID3 0x2c
71#define ARM_SMMU_GR0_ID4 0x30
72#define ARM_SMMU_GR0_ID5 0x34
73#define ARM_SMMU_GR0_ID6 0x38
Robin Murphy0caf5f42019-08-15 19:37:23 +010074
Rob Clark2b037742017-08-09 10:43:03 -040075#define ARM_SMMU_GR0_ID7 0x3c
Robin Murphy0caf5f42019-08-15 19:37:23 +010076#define ID7_MAJOR GENMASK(7, 4)
77#define ID7_MINOR GENMASK(3, 0)
78
Rob Clark2b037742017-08-09 10:43:03 -040079#define ARM_SMMU_GR0_sGFSR 0x48
80#define ARM_SMMU_GR0_sGFSYNR0 0x50
81#define ARM_SMMU_GR0_sGFSYNR1 0x54
82#define ARM_SMMU_GR0_sGFSYNR2 0x58
83
Rob Clark2b037742017-08-09 10:43:03 -040084/* Global TLB invalidation */
85#define ARM_SMMU_GR0_TLBIVMID 0x64
86#define ARM_SMMU_GR0_TLBIALLNSNH 0x68
87#define ARM_SMMU_GR0_TLBIALLH 0x6c
88#define ARM_SMMU_GR0_sTLBGSYNC 0x70
Robin Murphy0caf5f42019-08-15 19:37:23 +010089
Rob Clark2b037742017-08-09 10:43:03 -040090#define ARM_SMMU_GR0_sTLBGSTATUS 0x74
Robin Murphy0caf5f42019-08-15 19:37:23 +010091#define sTLBGSTATUS_GSACTIVE BIT(0)
Rob Clark2b037742017-08-09 10:43:03 -040092
93/* Stream mapping registers */
94#define ARM_SMMU_GR0_SMR(n) (0x800 + ((n) << 2))
Robin Murphy0caf5f42019-08-15 19:37:23 +010095#define SMR_VALID BIT(31)
96#define SMR_MASK GENMASK(31, 16)
97#define SMR_ID GENMASK(15, 0)
Rob Clark2b037742017-08-09 10:43:03 -040098
99#define ARM_SMMU_GR0_S2CR(n) (0xc00 + ((n) << 2))
Robin Murphy0caf5f42019-08-15 19:37:23 +0100100#define S2CR_PRIVCFG GENMASK(25, 24)
Rob Clark2b037742017-08-09 10:43:03 -0400101enum arm_smmu_s2cr_privcfg {
102 S2CR_PRIVCFG_DEFAULT,
103 S2CR_PRIVCFG_DIPAN,
104 S2CR_PRIVCFG_UNPRIV,
105 S2CR_PRIVCFG_PRIV,
106};
Robin Murphy0caf5f42019-08-15 19:37:23 +0100107#define S2CR_TYPE GENMASK(17, 16)
108enum arm_smmu_s2cr_type {
109 S2CR_TYPE_TRANS,
110 S2CR_TYPE_BYPASS,
111 S2CR_TYPE_FAULT,
112};
113#define S2CR_EXIDVALID BIT(10)
114#define S2CR_CBNDX GENMASK(7, 0)
Rob Clark2b037742017-08-09 10:43:03 -0400115
116/* Context bank attribute registers */
117#define ARM_SMMU_GR1_CBAR(n) (0x0 + ((n) << 2))
Robin Murphy5114e962019-08-15 19:37:24 +0100118#define CBAR_IRPTNDX GENMASK(31, 24)
119#define CBAR_TYPE GENMASK(17, 16)
120enum arm_smmu_cbar_type {
121 CBAR_TYPE_S2_TRANS,
122 CBAR_TYPE_S1_TRANS_S2_BYPASS,
123 CBAR_TYPE_S1_TRANS_S2_FAULT,
124 CBAR_TYPE_S1_TRANS_S2_TRANS,
125};
126#define CBAR_S1_MEMATTR GENMASK(15, 12)
Rob Clark2b037742017-08-09 10:43:03 -0400127#define CBAR_S1_MEMATTR_WB 0xf
Robin Murphy5114e962019-08-15 19:37:24 +0100128#define CBAR_S1_BPSHCFG GENMASK(9, 8)
129#define CBAR_S1_BPSHCFG_NSH 3
130#define CBAR_VMID GENMASK(7, 0)
Rob Clark2b037742017-08-09 10:43:03 -0400131
Vivek Gautambc580b52019-04-22 12:40:36 +0530132#define ARM_SMMU_GR1_CBFRSYNRA(n) (0x400 + ((n) << 2))
133
Rob Clark2b037742017-08-09 10:43:03 -0400134#define ARM_SMMU_GR1_CBA2R(n) (0x800 + ((n) << 2))
Robin Murphy5114e962019-08-15 19:37:24 +0100135#define CBA2R_VMID16 GENMASK(31, 16)
136#define CBA2R_VA64 BIT(0)
Rob Clark2b037742017-08-09 10:43:03 -0400137
138#define ARM_SMMU_CB_SCTLR 0x0
Robin Murphy620565a2019-08-15 19:37:25 +0100139#define SCTLR_S1_ASIDPNE BIT(12)
140#define SCTLR_CFCFG BIT(7)
141#define SCTLR_CFIE BIT(6)
142#define SCTLR_CFRE BIT(5)
143#define SCTLR_E BIT(4)
144#define SCTLR_AFE BIT(2)
145#define SCTLR_TRE BIT(1)
146#define SCTLR_M BIT(0)
147
Rob Clark2b037742017-08-09 10:43:03 -0400148#define ARM_SMMU_CB_ACTLR 0x4
Robin Murphy620565a2019-08-15 19:37:25 +0100149
Rob Clark2b037742017-08-09 10:43:03 -0400150#define ARM_SMMU_CB_RESUME 0x8
Robin Murphy620565a2019-08-15 19:37:25 +0100151#define RESUME_TERMINATE BIT(0)
152
153#define ARM_SMMU_CB_TCR2 0x10
154#define TCR2_SEP GENMASK(17, 15)
155#define TCR2_SEP_UPSTREAM 0x7
156#define TCR2_AS BIT(4)
157
Rob Clark2b037742017-08-09 10:43:03 -0400158#define ARM_SMMU_CB_TTBR0 0x20
159#define ARM_SMMU_CB_TTBR1 0x28
Robin Murphy620565a2019-08-15 19:37:25 +0100160#define TTBRn_ASID GENMASK_ULL(63, 48)
161
162#define ARM_SMMU_CB_TCR 0x30
Rob Clark2b037742017-08-09 10:43:03 -0400163#define ARM_SMMU_CB_CONTEXTIDR 0x34
164#define ARM_SMMU_CB_S1_MAIR0 0x38
165#define ARM_SMMU_CB_S1_MAIR1 0x3c
Robin Murphy620565a2019-08-15 19:37:25 +0100166
Rob Clark2b037742017-08-09 10:43:03 -0400167#define ARM_SMMU_CB_PAR 0x50
Robin Murphy620565a2019-08-15 19:37:25 +0100168#define CB_PAR_F BIT(0)
169
Rob Clark2b037742017-08-09 10:43:03 -0400170#define ARM_SMMU_CB_FSR 0x58
Robin Murphy620565a2019-08-15 19:37:25 +0100171#define FSR_MULTI BIT(31)
172#define FSR_SS BIT(30)
173#define FSR_UUT BIT(8)
174#define FSR_ASF BIT(7)
175#define FSR_TLBLKF BIT(6)
176#define FSR_TLBMCF BIT(5)
177#define FSR_EF BIT(4)
178#define FSR_PF BIT(3)
179#define FSR_AFF BIT(2)
180#define FSR_TF BIT(1)
181
182#define FSR_IGN (FSR_AFF | FSR_ASF | \
183 FSR_TLBMCF | FSR_TLBLKF)
184#define FSR_FAULT (FSR_MULTI | FSR_SS | FSR_UUT | \
185 FSR_EF | FSR_PF | FSR_TF | FSR_IGN)
186
Rob Clark2b037742017-08-09 10:43:03 -0400187#define ARM_SMMU_CB_FAR 0x60
Robin Murphy620565a2019-08-15 19:37:25 +0100188
Rob Clark2b037742017-08-09 10:43:03 -0400189#define ARM_SMMU_CB_FSYNR0 0x68
Robin Murphy620565a2019-08-15 19:37:25 +0100190#define FSYNR0_WNR BIT(4)
191
Rob Clark2b037742017-08-09 10:43:03 -0400192#define ARM_SMMU_CB_S1_TLBIVA 0x600
193#define ARM_SMMU_CB_S1_TLBIASID 0x610
194#define ARM_SMMU_CB_S1_TLBIVAL 0x620
195#define ARM_SMMU_CB_S2_TLBIIPAS2 0x630
196#define ARM_SMMU_CB_S2_TLBIIPAS2L 0x638
197#define ARM_SMMU_CB_TLBSYNC 0x7f0
198#define ARM_SMMU_CB_TLBSTATUS 0x7f4
199#define ARM_SMMU_CB_ATS1PR 0x800
Robin Murphy620565a2019-08-15 19:37:25 +0100200
Rob Clark2b037742017-08-09 10:43:03 -0400201#define ARM_SMMU_CB_ATSR 0x8f0
Robin Murphy620565a2019-08-15 19:37:25 +0100202#define ATSR_ACTIVE BIT(0)
Rob Clark2b037742017-08-09 10:43:03 -0400203
Robin Murphyfc058d32019-08-15 19:37:33 +0100204
205/* Maximum number of context banks per SMMU */
206#define ARM_SMMU_MAX_CBS 128
207
208
209/* Shared driver definitions */
210enum arm_smmu_arch_version {
211 ARM_SMMU_V1,
212 ARM_SMMU_V1_64K,
213 ARM_SMMU_V2,
214};
215
216enum arm_smmu_implementation {
217 GENERIC_SMMU,
218 ARM_MMU500,
219 CAVIUM_SMMUV2,
220 QCOM_SMMUV2,
221};
222
223struct arm_smmu_device {
224 struct device *dev;
225
226 void __iomem *base;
227 unsigned int numpage;
228 unsigned int pgshift;
229
230#define ARM_SMMU_FEAT_COHERENT_WALK (1 << 0)
231#define ARM_SMMU_FEAT_STREAM_MATCH (1 << 1)
232#define ARM_SMMU_FEAT_TRANS_S1 (1 << 2)
233#define ARM_SMMU_FEAT_TRANS_S2 (1 << 3)
234#define ARM_SMMU_FEAT_TRANS_NESTED (1 << 4)
235#define ARM_SMMU_FEAT_TRANS_OPS (1 << 5)
236#define ARM_SMMU_FEAT_VMID16 (1 << 6)
237#define ARM_SMMU_FEAT_FMT_AARCH64_4K (1 << 7)
238#define ARM_SMMU_FEAT_FMT_AARCH64_16K (1 << 8)
239#define ARM_SMMU_FEAT_FMT_AARCH64_64K (1 << 9)
240#define ARM_SMMU_FEAT_FMT_AARCH32_L (1 << 10)
241#define ARM_SMMU_FEAT_FMT_AARCH32_S (1 << 11)
242#define ARM_SMMU_FEAT_EXIDS (1 << 12)
243 u32 features;
244
245#define ARM_SMMU_OPT_SECURE_CFG_ACCESS (1 << 0)
246 u32 options;
247 enum arm_smmu_arch_version version;
248 enum arm_smmu_implementation model;
249
250 u32 num_context_banks;
251 u32 num_s2_context_banks;
252 DECLARE_BITMAP(context_map, ARM_SMMU_MAX_CBS);
253 struct arm_smmu_cb *cbs;
254 atomic_t irptndx;
255
256 u32 num_mapping_groups;
257 u16 streamid_mask;
258 u16 smr_mask_mask;
259 struct arm_smmu_smr *smrs;
260 struct arm_smmu_s2cr *s2crs;
261 struct mutex stream_map_mutex;
262
263 unsigned long va_size;
264 unsigned long ipa_size;
265 unsigned long pa_size;
266 unsigned long pgsize_bitmap;
267
268 u32 num_global_irqs;
269 u32 num_context_irqs;
270 unsigned int *irqs;
271 struct clk_bulk_data *clks;
272 int num_clks;
273
274 u32 cavium_id_base; /* Specific to Cavium */
275
276 spinlock_t global_sync_lock;
277
278 /* IOMMU core code handle */
279 struct iommu_device iommu;
280};
281
282
283/* Implementation details, yay! */
284struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu);
285
Robin Murphyc5fc6482019-08-15 19:37:32 +0100286#endif /* _ARM_SMMU_H */