Skip to content

Commit aac7d39

Browse files
committed
Merge branch 'for-joerg/arm-smmu/updates' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux into arm/smmu
2 parents 566cf87 + 3677a64 commit aac7d39

File tree

7 files changed

+68
-56
lines changed

7 files changed

+68
-56
lines changed

drivers/iommu/arm-smmu-v3.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,8 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
10421042
}
10431043
}
10441044

1045-
/* Nuke the existing Config, as we're going to rewrite it */
1046-
val &= ~(STRTAB_STE_0_CFG_MASK << STRTAB_STE_0_CFG_SHIFT);
1047-
1048-
if (ste->valid)
1049-
val |= STRTAB_STE_0_V;
1050-
else
1051-
val &= ~STRTAB_STE_0_V;
1045+
/* Nuke the existing STE_0 value, as we're going to rewrite it */
1046+
val = ste->valid ? STRTAB_STE_0_V : 0;
10521047

10531048
if (ste->bypass) {
10541049
val |= disable_bypass ? STRTAB_STE_0_CFG_ABORT
@@ -1083,7 +1078,6 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
10831078
val |= (ste->s1_cfg->cdptr_dma & STRTAB_STE_0_S1CTXPTR_MASK
10841079
<< STRTAB_STE_0_S1CTXPTR_SHIFT) |
10851080
STRTAB_STE_0_CFG_S1_TRANS;
1086-
10871081
}
10881082

10891083
if (ste->s2_cfg) {
@@ -1983,17 +1977,9 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu)
19831977
u32 size, l1size;
19841978
struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
19851979

1986-
/*
1987-
* If we can resolve everything with a single L2 table, then we
1988-
* just need a single L1 descriptor. Otherwise, calculate the L1
1989-
* size, capped to the SIDSIZE.
1990-
*/
1991-
if (smmu->sid_bits < STRTAB_SPLIT) {
1992-
size = 0;
1993-
} else {
1994-
size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3);
1995-
size = min(size, smmu->sid_bits - STRTAB_SPLIT);
1996-
}
1980+
/* Calculate the L1 size, capped to the SIDSIZE. */
1981+
size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3);
1982+
size = min(size, smmu->sid_bits - STRTAB_SPLIT);
19971983
cfg->num_l1_ents = 1 << size;
19981984

19991985
size += STRTAB_SPLIT;
@@ -2504,6 +2490,13 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu)
25042490
smmu->ssid_bits = reg >> IDR1_SSID_SHIFT & IDR1_SSID_MASK;
25052491
smmu->sid_bits = reg >> IDR1_SID_SHIFT & IDR1_SID_MASK;
25062492

2493+
/*
2494+
* If the SMMU supports fewer bits than would fill a single L2 stream
2495+
* table, use a linear table instead.
2496+
*/
2497+
if (smmu->sid_bits <= STRTAB_SPLIT)
2498+
smmu->features &= ~ARM_SMMU_FEAT_2_LVL_STRTAB;
2499+
25072500
/* IDR5 */
25082501
reg = readl_relaxed(smmu->base + ARM_SMMU_IDR5);
25092502

drivers/iommu/arm-smmu.c

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* - v7/v8 long-descriptor format
2525
* - Non-secure access to the SMMU
2626
* - Context fault reporting
27+
* - Extended Stream ID (16 bit)
2728
*/
2829

2930
#define pr_fmt(fmt) "arm-smmu: " fmt
@@ -87,6 +88,7 @@
8788
#define sCR0_CLIENTPD (1 << 0)
8889
#define sCR0_GFRE (1 << 1)
8990
#define sCR0_GFIE (1 << 2)
91+
#define sCR0_EXIDENABLE (1 << 3)
9092
#define sCR0_GCFGFRE (1 << 4)
9193
#define sCR0_GCFGFIE (1 << 5)
9294
#define sCR0_USFCFG (1 << 10)
@@ -126,6 +128,7 @@
126128
#define ID0_NUMIRPT_MASK 0xff
127129
#define ID0_NUMSIDB_SHIFT 9
128130
#define ID0_NUMSIDB_MASK 0xf
131+
#define ID0_EXIDS (1 << 8)
129132
#define ID0_NUMSMRG_SHIFT 0
130133
#define ID0_NUMSMRG_MASK 0xff
131134

@@ -169,6 +172,7 @@
169172
#define ARM_SMMU_GR0_S2CR(n) (0xc00 + ((n) << 2))
170173
#define S2CR_CBNDX_SHIFT 0
171174
#define S2CR_CBNDX_MASK 0xff
175+
#define S2CR_EXIDVALID (1 << 10)
172176
#define S2CR_TYPE_SHIFT 16
173177
#define S2CR_TYPE_MASK 0x3
174178
enum arm_smmu_s2cr_type {
@@ -260,6 +264,7 @@ enum arm_smmu_s2cr_privcfg {
260264

261265
#define TTBCR2_SEP_SHIFT 15
262266
#define TTBCR2_SEP_UPSTREAM (0x7 << TTBCR2_SEP_SHIFT)
267+
#define TTBCR2_AS (1 << 4)
263268

264269
#define TTBRn_ASID_SHIFT 48
265270

@@ -351,6 +356,7 @@ struct arm_smmu_device {
351356
#define ARM_SMMU_FEAT_FMT_AARCH64_64K (1 << 9)
352357
#define ARM_SMMU_FEAT_FMT_AARCH32_L (1 << 10)
353358
#define ARM_SMMU_FEAT_FMT_AARCH32_S (1 << 11)
359+
#define ARM_SMMU_FEAT_EXIDS (1 << 12)
354360
u32 features;
355361

356362
#define ARM_SMMU_OPT_SECURE_CFG_ACCESS (1 << 0)
@@ -778,6 +784,8 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
778784
reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
779785
reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
780786
reg2 |= TTBCR2_SEP_UPSTREAM;
787+
if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
788+
reg2 |= TTBCR2_AS;
781789
}
782790
if (smmu->version > ARM_SMMU_V1)
783791
writel_relaxed(reg2, cb_base + ARM_SMMU_CB_TTBCR2);
@@ -1048,7 +1056,7 @@ static void arm_smmu_write_smr(struct arm_smmu_device *smmu, int idx)
10481056
struct arm_smmu_smr *smr = smmu->smrs + idx;
10491057
u32 reg = smr->id << SMR_ID_SHIFT | smr->mask << SMR_MASK_SHIFT;
10501058

1051-
if (smr->valid)
1059+
if (!(smmu->features & ARM_SMMU_FEAT_EXIDS) && smr->valid)
10521060
reg |= SMR_VALID;
10531061
writel_relaxed(reg, ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_SMR(idx));
10541062
}
@@ -1060,6 +1068,9 @@ static void arm_smmu_write_s2cr(struct arm_smmu_device *smmu, int idx)
10601068
(s2cr->cbndx & S2CR_CBNDX_MASK) << S2CR_CBNDX_SHIFT |
10611069
(s2cr->privcfg & S2CR_PRIVCFG_MASK) << S2CR_PRIVCFG_SHIFT;
10621070

1071+
if (smmu->features & ARM_SMMU_FEAT_EXIDS && smmu->smrs &&
1072+
smmu->smrs[idx].valid)
1073+
reg |= S2CR_EXIDVALID;
10631074
writel_relaxed(reg, ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_S2CR(idx));
10641075
}
10651076

@@ -1070,6 +1081,34 @@ static void arm_smmu_write_sme(struct arm_smmu_device *smmu, int idx)
10701081
arm_smmu_write_smr(smmu, idx);
10711082
}
10721083

1084+
/*
1085+
* The width of SMR's mask field depends on sCR0_EXIDENABLE, so this function
1086+
* should be called after sCR0 is written.
1087+
*/
1088+
static void arm_smmu_test_smr_masks(struct arm_smmu_device *smmu)
1089+
{
1090+
void __iomem *gr0_base = ARM_SMMU_GR0(smmu);
1091+
u32 smr;
1092+
1093+
if (!smmu->smrs)
1094+
return;
1095+
1096+
/*
1097+
* SMR.ID bits may not be preserved if the corresponding MASK
1098+
* bits are set, so check each one separately. We can reject
1099+
* masters later if they try to claim IDs outside these masks.
1100+
*/
1101+
smr = smmu->streamid_mask << SMR_ID_SHIFT;
1102+
writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
1103+
smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
1104+
smmu->streamid_mask = smr >> SMR_ID_SHIFT;
1105+
1106+
smr = smmu->streamid_mask << SMR_MASK_SHIFT;
1107+
writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
1108+
smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
1109+
smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
1110+
}
1111+
10731112
static int arm_smmu_find_sme(struct arm_smmu_device *smmu, u16 id, u16 mask)
10741113
{
10751114
struct arm_smmu_smr *smrs = smmu->smrs;
@@ -1648,6 +1687,9 @@ static void arm_smmu_device_reset(struct arm_smmu_device *smmu)
16481687
if (smmu->features & ARM_SMMU_FEAT_VMID16)
16491688
reg |= sCR0_VMID16EN;
16501689

1690+
if (smmu->features & ARM_SMMU_FEAT_EXIDS)
1691+
reg |= sCR0_EXIDENABLE;
1692+
16511693
/* Push the button */
16521694
__arm_smmu_tlb_sync(smmu);
16531695
writel(reg, ARM_SMMU_GR0_NS(smmu) + ARM_SMMU_GR0_sCR0);
@@ -1735,11 +1777,14 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
17351777
"\t(IDR0.CTTW overridden by FW configuration)\n");
17361778

17371779
/* Max. number of entries we have for stream matching/indexing */
1738-
size = 1 << ((id >> ID0_NUMSIDB_SHIFT) & ID0_NUMSIDB_MASK);
1780+
if (smmu->version == ARM_SMMU_V2 && id & ID0_EXIDS) {
1781+
smmu->features |= ARM_SMMU_FEAT_EXIDS;
1782+
size = 1 << 16;
1783+
} else {
1784+
size = 1 << ((id >> ID0_NUMSIDB_SHIFT) & ID0_NUMSIDB_MASK);
1785+
}
17391786
smmu->streamid_mask = size - 1;
17401787
if (id & ID0_SMS) {
1741-
u32 smr;
1742-
17431788
smmu->features |= ARM_SMMU_FEAT_STREAM_MATCH;
17441789
size = (id >> ID0_NUMSMRG_SHIFT) & ID0_NUMSMRG_MASK;
17451790
if (size == 0) {
@@ -1748,30 +1793,14 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
17481793
return -ENODEV;
17491794
}
17501795

1751-
/*
1752-
* SMR.ID bits may not be preserved if the corresponding MASK
1753-
* bits are set, so check each one separately. We can reject
1754-
* masters later if they try to claim IDs outside these masks.
1755-
*/
1756-
smr = smmu->streamid_mask << SMR_ID_SHIFT;
1757-
writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
1758-
smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
1759-
smmu->streamid_mask = smr >> SMR_ID_SHIFT;
1760-
1761-
smr = smmu->streamid_mask << SMR_MASK_SHIFT;
1762-
writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
1763-
smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
1764-
smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
1765-
17661796
/* Zero-initialised to mark as invalid */
17671797
smmu->smrs = devm_kcalloc(smmu->dev, size, sizeof(*smmu->smrs),
17681798
GFP_KERNEL);
17691799
if (!smmu->smrs)
17701800
return -ENOMEM;
17711801

17721802
dev_notice(smmu->dev,
1773-
"\tstream matching with %lu register groups, mask 0x%x",
1774-
size, smmu->smr_mask_mask);
1803+
"\tstream matching with %lu register groups", size);
17751804
}
17761805
/* s2cr->type == 0 means translation, so initialise explicitly */
17771806
smmu->s2crs = devm_kmalloc_array(smmu->dev, size, sizeof(*smmu->s2crs),
@@ -2094,6 +2123,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
20942123
iommu_register_instance(dev->fwnode, &arm_smmu_ops);
20952124
platform_set_drvdata(pdev, smmu);
20962125
arm_smmu_device_reset(smmu);
2126+
arm_smmu_test_smr_masks(smmu);
20972127

20982128
/* Oh, for a proper bus abstraction */
20992129
if (!iommu_present(&platform_bus_type))

drivers/iommu/exynos-iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ static int __init exynos_sysmmu_probe(struct platform_device *pdev)
628628

629629
pm_runtime_enable(dev);
630630

631-
of_iommu_set_ops(dev->of_node, &exynos_iommu_ops);
631+
iommu_register_instance(dev->fwnode, &exynos_iommu_ops);
632632

633633
return 0;
634634
}

drivers/iommu/msm_iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static int msm_iommu_probe(struct platform_device *pdev)
737737
}
738738

739739
list_add(&iommu->dev_node, &qcom_iommu_devices);
740-
of_iommu_set_ops(pdev->dev.of_node, &msm_iommu_ops);
740+
iommu_register_instance(pdev->dev.fwnode, &msm_iommu_ops);
741741

742742
pr_info("device mapped at %p, irq %d with %d ctx banks\n",
743743
iommu->base, iommu->irq, iommu->ncb);

drivers/iommu/mtk_iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static int mtk_iommu_init_fn(struct device_node *np)
655655
return ret;
656656
}
657657

658-
of_iommu_set_ops(np, &mtk_iommu_ops);
658+
iommu_register_instance(&np->fwnode, &mtk_iommu_ops);
659659
return 0;
660660
}
661661

drivers/iommu/of_iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static const struct iommu_ops
127127
"iommu-map-mask", &iommu_spec.np, iommu_spec.args))
128128
return NULL;
129129

130-
ops = of_iommu_get_ops(iommu_spec.np);
130+
ops = iommu_get_instance(&iommu_spec.np->fwnode);
131131
if (!ops || !ops->of_xlate ||
132132
iommu_fwspec_init(&pdev->dev, &iommu_spec.np->fwnode, ops) ||
133133
ops->of_xlate(&pdev->dev, &iommu_spec))
@@ -157,7 +157,7 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
157157
"#iommu-cells", idx,
158158
&iommu_spec)) {
159159
np = iommu_spec.np;
160-
ops = of_iommu_get_ops(np);
160+
ops = iommu_get_instance(&np->fwnode);
161161

162162
if (!ops || !ops->of_xlate ||
163163
iommu_fwspec_init(dev, &np->fwnode, ops) ||

include/linux/of_iommu.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ static inline const struct iommu_ops *of_iommu_configure(struct device *dev,
3131

3232
#endif /* CONFIG_OF_IOMMU */
3333

34-
static inline void of_iommu_set_ops(struct device_node *np,
35-
const struct iommu_ops *ops)
36-
{
37-
iommu_register_instance(&np->fwnode, ops);
38-
}
39-
40-
static inline const struct iommu_ops *of_iommu_get_ops(struct device_node *np)
41-
{
42-
return iommu_get_instance(&np->fwnode);
43-
}
44-
4534
extern struct of_device_id __iommu_of_table;
4635

4736
typedef int (*of_iommu_init_fn)(struct device_node *);

0 commit comments

Comments
 (0)