aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2019-04-26 09:48:52 -0400
committerJoerg Roedel <jroedel@suse.de>2019-04-26 09:48:52 -0400
commit26ac2b6ee6c0902188316d16bc5ca9306d678f03 (patch)
tree9664a3178d423866a37759ae33920ceeb9c377fe
parent085b7755808aa11f78ab9377257e1dad2e6fa4bb (diff)
parentbc580b56cb7888d1f09fff8a50270228fb834ae8 (diff)
Merge branch 'for-joerg/arm-smmu/updates' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux into arm/smmu
-rw-r--r--drivers/acpi/arm64/iort.c11
-rw-r--r--drivers/iommu/Kconfig25
-rw-r--r--drivers/iommu/arm-smmu-regs.h2
-rw-r--r--drivers/iommu/arm-smmu-v3.c355
-rw-r--r--drivers/iommu/arm-smmu.c11
-rw-r--r--include/linux/iommu.h4
-rw-r--r--include/linux/pci.h31
7 files changed, 344 insertions, 95 deletions
diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
index e48894e002ba..4000902e57f0 100644
--- a/drivers/acpi/arm64/iort.c
+++ b/drivers/acpi/arm64/iort.c
@@ -1028,6 +1028,14 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
1028 dev_dbg(dev, "dma_pfn_offset(%#08llx)\n", offset); 1028 dev_dbg(dev, "dma_pfn_offset(%#08llx)\n", offset);
1029} 1029}
1030 1030
1031static bool iort_pci_rc_supports_ats(struct acpi_iort_node *node)
1032{
1033 struct acpi_iort_root_complex *pci_rc;
1034
1035 pci_rc = (struct acpi_iort_root_complex *)node->node_data;
1036 return pci_rc->ats_attribute & ACPI_IORT_ATS_SUPPORTED;
1037}
1038
1031/** 1039/**
1032 * iort_iommu_configure - Set-up IOMMU configuration for a device. 1040 * iort_iommu_configure - Set-up IOMMU configuration for a device.
1033 * 1041 *
@@ -1063,6 +1071,9 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev)
1063 info.node = node; 1071 info.node = node;
1064 err = pci_for_each_dma_alias(to_pci_dev(dev), 1072 err = pci_for_each_dma_alias(to_pci_dev(dev),
1065 iort_pci_iommu_init, &info); 1073 iort_pci_iommu_init, &info);
1074
1075 if (!err && iort_pci_rc_supports_ats(node))
1076 dev->iommu_fwspec->flags |= IOMMU_FWSPEC_PCI_RC_ATS;
1066 } else { 1077 } else {
1067 int i = 0; 1078 int i = 0;
1068 1079
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 6f07f3b21816..15b831113ded 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -359,6 +359,31 @@ config ARM_SMMU
359 Say Y here if your SoC includes an IOMMU device implementing 359 Say Y here if your SoC includes an IOMMU device implementing
360 the ARM SMMU architecture. 360 the ARM SMMU architecture.
361 361
362config ARM_SMMU_DISABLE_BYPASS_BY_DEFAULT
363 bool "Default to disabling bypass on ARM SMMU v1 and v2"
364 depends on ARM_SMMU
365 default y
366 help
367 Say Y here to (by default) disable bypass streams such that
368 incoming transactions from devices that are not attached to
369 an iommu domain will report an abort back to the device and
370 will not be allowed to pass through the SMMU.
371
372 Any old kernels that existed before this KConfig was
373 introduced would default to _allowing_ bypass (AKA the
374 equivalent of NO for this config). However the default for
375 this option is YES because the old behavior is insecure.
376
377 There are few reasons to allow unmatched stream bypass, and
378 even fewer good ones. If saying YES here breaks your board
379 you should work on fixing your board. This KConfig option
380 is expected to be removed in the future and we'll simply
381 hardcode the bypass disable in the code.
382
383 NOTE: the kernel command line parameter
384 'arm-smmu.disable_bypass' will continue to override this
385 config.
386
362config ARM_SMMU_V3 387config ARM_SMMU_V3
363 bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support" 388 bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
364 depends on ARM64 389 depends on ARM64
diff --git a/drivers/iommu/arm-smmu-regs.h b/drivers/iommu/arm-smmu-regs.h
index a1226e4ab5f8..e9132a926761 100644
--- a/drivers/iommu/arm-smmu-regs.h
+++ b/drivers/iommu/arm-smmu-regs.h
@@ -147,6 +147,8 @@ enum arm_smmu_s2cr_privcfg {
147#define CBAR_IRPTNDX_SHIFT 24 147#define CBAR_IRPTNDX_SHIFT 24
148#define CBAR_IRPTNDX_MASK 0xff 148#define CBAR_IRPTNDX_MASK 0xff
149 149
150#define ARM_SMMU_GR1_CBFRSYNRA(n) (0x400 + ((n) << 2))
151
150#define ARM_SMMU_GR1_CBA2R(n) (0x800 + ((n) << 2)) 152#define ARM_SMMU_GR1_CBA2R(n) (0x800 + ((n) << 2))
151#define CBA2R_RW64_32BIT (0 << 0) 153#define CBA2R_RW64_32BIT (0 << 0)
152#define CBA2R_RW64_64BIT (1 << 0) 154#define CBA2R_RW64_64BIT (1 << 0)
diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
index d3880010c6cf..4d5a694f02c2 100644
--- a/drivers/iommu/arm-smmu-v3.c
+++ b/drivers/iommu/arm-smmu-v3.c
@@ -29,6 +29,7 @@
29#include <linux/of_iommu.h> 29#include <linux/of_iommu.h>
30#include <linux/of_platform.h> 30#include <linux/of_platform.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/pci-ats.h>
32#include <linux/platform_device.h> 33#include <linux/platform_device.h>
33 34
34#include <linux/amba/bus.h> 35#include <linux/amba/bus.h>
@@ -86,6 +87,7 @@
86#define IDR5_VAX_52_BIT 1 87#define IDR5_VAX_52_BIT 1
87 88
88#define ARM_SMMU_CR0 0x20 89#define ARM_SMMU_CR0 0x20
90#define CR0_ATSCHK (1 << 4)
89#define CR0_CMDQEN (1 << 3) 91#define CR0_CMDQEN (1 << 3)
90#define CR0_EVTQEN (1 << 2) 92#define CR0_EVTQEN (1 << 2)
91#define CR0_PRIQEN (1 << 1) 93#define CR0_PRIQEN (1 << 1)
@@ -294,6 +296,7 @@
294#define CMDQ_ERR_CERROR_NONE_IDX 0 296#define CMDQ_ERR_CERROR_NONE_IDX 0
295#define CMDQ_ERR_CERROR_ILL_IDX 1 297#define CMDQ_ERR_CERROR_ILL_IDX 1
296#define CMDQ_ERR_CERROR_ABT_IDX 2 298#define CMDQ_ERR_CERROR_ABT_IDX 2
299#define CMDQ_ERR_CERROR_ATC_INV_IDX 3
297 300
298#define CMDQ_0_OP GENMASK_ULL(7, 0) 301#define CMDQ_0_OP GENMASK_ULL(7, 0)
299#define CMDQ_0_SSV (1UL << 11) 302#define CMDQ_0_SSV (1UL << 11)
@@ -312,6 +315,12 @@
312#define CMDQ_TLBI_1_VA_MASK GENMASK_ULL(63, 12) 315#define CMDQ_TLBI_1_VA_MASK GENMASK_ULL(63, 12)
313#define CMDQ_TLBI_1_IPA_MASK GENMASK_ULL(51, 12) 316#define CMDQ_TLBI_1_IPA_MASK GENMASK_ULL(51, 12)
314 317
318#define CMDQ_ATC_0_SSID GENMASK_ULL(31, 12)
319#define CMDQ_ATC_0_SID GENMASK_ULL(63, 32)
320#define CMDQ_ATC_0_GLOBAL (1UL << 9)
321#define CMDQ_ATC_1_SIZE GENMASK_ULL(5, 0)
322#define CMDQ_ATC_1_ADDR_MASK GENMASK_ULL(63, 12)
323
315#define CMDQ_PRI_0_SSID GENMASK_ULL(31, 12) 324#define CMDQ_PRI_0_SSID GENMASK_ULL(31, 12)
316#define CMDQ_PRI_0_SID GENMASK_ULL(63, 32) 325#define CMDQ_PRI_0_SID GENMASK_ULL(63, 32)
317#define CMDQ_PRI_1_GRPID GENMASK_ULL(8, 0) 326#define CMDQ_PRI_1_GRPID GENMASK_ULL(8, 0)
@@ -433,6 +442,16 @@ struct arm_smmu_cmdq_ent {
433 u64 addr; 442 u64 addr;
434 } tlbi; 443 } tlbi;
435 444
445 #define CMDQ_OP_ATC_INV 0x40
446 #define ATC_INV_SIZE_ALL 52
447 struct {
448 u32 sid;
449 u32 ssid;
450 u64 addr;
451 u8 size;
452 bool global;
453 } atc;
454
436 #define CMDQ_OP_PRI_RESP 0x41 455 #define CMDQ_OP_PRI_RESP 0x41
437 struct { 456 struct {
438 u32 sid; 457 u32 sid;
@@ -505,19 +524,6 @@ struct arm_smmu_s2_cfg {
505 u64 vtcr; 524 u64 vtcr;
506}; 525};
507 526
508struct arm_smmu_strtab_ent {
509 /*
510 * An STE is "assigned" if the master emitting the corresponding SID
511 * is attached to a domain. The behaviour of an unassigned STE is
512 * determined by the disable_bypass parameter, whereas an assigned
513 * STE behaves according to s1_cfg/s2_cfg, which themselves are
514 * configured according to the domain type.
515 */
516 bool assigned;
517 struct arm_smmu_s1_cfg *s1_cfg;
518 struct arm_smmu_s2_cfg *s2_cfg;
519};
520
521struct arm_smmu_strtab_cfg { 527struct arm_smmu_strtab_cfg {
522 __le64 *strtab; 528 __le64 *strtab;
523 dma_addr_t strtab_dma; 529 dma_addr_t strtab_dma;
@@ -591,9 +597,14 @@ struct arm_smmu_device {
591}; 597};
592 598
593/* SMMU private data for each master */ 599/* SMMU private data for each master */
594struct arm_smmu_master_data { 600struct arm_smmu_master {
595 struct arm_smmu_device *smmu; 601 struct arm_smmu_device *smmu;
596 struct arm_smmu_strtab_ent ste; 602 struct device *dev;
603 struct arm_smmu_domain *domain;
604 struct list_head domain_head;
605 u32 *sids;
606 unsigned int num_sids;
607 bool ats_enabled :1;
597}; 608};
598 609
599/* SMMU private data for an IOMMU domain */ 610/* SMMU private data for an IOMMU domain */
@@ -618,6 +629,9 @@ struct arm_smmu_domain {
618 }; 629 };
619 630
620 struct iommu_domain domain; 631 struct iommu_domain domain;
632
633 struct list_head devices;
634 spinlock_t devices_lock;
621}; 635};
622 636
623struct arm_smmu_option_prop { 637struct arm_smmu_option_prop {
@@ -820,6 +834,14 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent)
820 case CMDQ_OP_TLBI_S12_VMALL: 834 case CMDQ_OP_TLBI_S12_VMALL:
821 cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid); 835 cmd[0] |= FIELD_PREP(CMDQ_TLBI_0_VMID, ent->tlbi.vmid);
822 break; 836 break;
837 case CMDQ_OP_ATC_INV:
838 cmd[0] |= FIELD_PREP(CMDQ_0_SSV, ent->substream_valid);
839 cmd[0] |= FIELD_PREP(CMDQ_ATC_0_GLOBAL, ent->atc.global);
840 cmd[0] |= FIELD_PREP(CMDQ_ATC_0_SSID, ent->atc.ssid);
841 cmd[0] |= FIELD_PREP(CMDQ_ATC_0_SID, ent->atc.sid);
842 cmd[1] |= FIELD_PREP(CMDQ_ATC_1_SIZE, ent->atc.size);
843 cmd[1] |= ent->atc.addr & CMDQ_ATC_1_ADDR_MASK;
844 break;
823 case CMDQ_OP_PRI_RESP: 845 case CMDQ_OP_PRI_RESP:
824 cmd[0] |= FIELD_PREP(CMDQ_0_SSV, ent->substream_valid); 846 cmd[0] |= FIELD_PREP(CMDQ_0_SSV, ent->substream_valid);
825 cmd[0] |= FIELD_PREP(CMDQ_PRI_0_SSID, ent->pri.ssid); 847 cmd[0] |= FIELD_PREP(CMDQ_PRI_0_SSID, ent->pri.ssid);
@@ -864,6 +886,7 @@ static void arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu)
864 [CMDQ_ERR_CERROR_NONE_IDX] = "No error", 886 [CMDQ_ERR_CERROR_NONE_IDX] = "No error",
865 [CMDQ_ERR_CERROR_ILL_IDX] = "Illegal command", 887 [CMDQ_ERR_CERROR_ILL_IDX] = "Illegal command",
866 [CMDQ_ERR_CERROR_ABT_IDX] = "Abort on command fetch", 888 [CMDQ_ERR_CERROR_ABT_IDX] = "Abort on command fetch",
889 [CMDQ_ERR_CERROR_ATC_INV_IDX] = "ATC invalidate timeout",
867 }; 890 };
868 891
869 int i; 892 int i;
@@ -883,6 +906,14 @@ static void arm_smmu_cmdq_skip_err(struct arm_smmu_device *smmu)
883 dev_err(smmu->dev, "retrying command fetch\n"); 906 dev_err(smmu->dev, "retrying command fetch\n");
884 case CMDQ_ERR_CERROR_NONE_IDX: 907 case CMDQ_ERR_CERROR_NONE_IDX:
885 return; 908 return;
909 case CMDQ_ERR_CERROR_ATC_INV_IDX:
910 /*
911 * ATC Invalidation Completion timeout. CONS is still pointing
912 * at the CMD_SYNC. Attempt to complete other pending commands
913 * by repeating the CMD_SYNC, though we might well end up back
914 * here since the ATC invalidation may still be pending.
915 */
916 return;
886 case CMDQ_ERR_CERROR_ILL_IDX: 917 case CMDQ_ERR_CERROR_ILL_IDX:
887 /* Fallthrough */ 918 /* Fallthrough */
888 default: 919 default:
@@ -999,7 +1030,7 @@ static int __arm_smmu_cmdq_issue_sync(struct arm_smmu_device *smmu)
999 return ret; 1030 return ret;
1000} 1031}
1001 1032
1002static void arm_smmu_cmdq_issue_sync(struct arm_smmu_device *smmu) 1033static int arm_smmu_cmdq_issue_sync(struct arm_smmu_device *smmu)
1003{ 1034{
1004 int ret; 1035 int ret;
1005 bool msi = (smmu->features & ARM_SMMU_FEAT_MSI) && 1036 bool msi = (smmu->features & ARM_SMMU_FEAT_MSI) &&
@@ -1009,6 +1040,7 @@ static void arm_smmu_cmdq_issue_sync(struct arm_smmu_device *smmu)
1009 : __arm_smmu_cmdq_issue_sync(smmu); 1040 : __arm_smmu_cmdq_issue_sync(smmu);
1010 if (ret) 1041 if (ret)
1011 dev_err_ratelimited(smmu->dev, "CMD_SYNC timeout\n"); 1042 dev_err_ratelimited(smmu->dev, "CMD_SYNC timeout\n");
1043 return ret;
1012} 1044}
1013 1045
1014/* Context descriptor manipulation functions */ 1046/* Context descriptor manipulation functions */
@@ -1025,7 +1057,6 @@ static u64 arm_smmu_cpu_tcr_to_cd(u64 tcr)
1025 val |= ARM_SMMU_TCR2CD(tcr, EPD0); 1057 val |= ARM_SMMU_TCR2CD(tcr, EPD0);
1026 val |= ARM_SMMU_TCR2CD(tcr, EPD1); 1058 val |= ARM_SMMU_TCR2CD(tcr, EPD1);
1027 val |= ARM_SMMU_TCR2CD(tcr, IPS); 1059 val |= ARM_SMMU_TCR2CD(tcr, IPS);
1028 val |= ARM_SMMU_TCR2CD(tcr, TBI0);
1029 1060
1030 return val; 1061 return val;
1031} 1062}
@@ -1085,8 +1116,8 @@ static void arm_smmu_sync_ste_for_sid(struct arm_smmu_device *smmu, u32 sid)
1085 arm_smmu_cmdq_issue_sync(smmu); 1116 arm_smmu_cmdq_issue_sync(smmu);
1086} 1117}
1087 1118
1088static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid, 1119static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
1089 __le64 *dst, struct arm_smmu_strtab_ent *ste) 1120 __le64 *dst)
1090{ 1121{
1091 /* 1122 /*
1092 * This is hideously complicated, but we only really care about 1123 * This is hideously complicated, but we only really care about
@@ -1106,6 +1137,10 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
1106 */ 1137 */
1107 u64 val = le64_to_cpu(dst[0]); 1138 u64 val = le64_to_cpu(dst[0]);
1108 bool ste_live = false; 1139 bool ste_live = false;
1140 struct arm_smmu_device *smmu = NULL;
1141 struct arm_smmu_s1_cfg *s1_cfg = NULL;
1142 struct arm_smmu_s2_cfg *s2_cfg = NULL;
1143 struct arm_smmu_domain *smmu_domain = NULL;
1109 struct arm_smmu_cmdq_ent prefetch_cmd = { 1144 struct arm_smmu_cmdq_ent prefetch_cmd = {
1110 .opcode = CMDQ_OP_PREFETCH_CFG, 1145 .opcode = CMDQ_OP_PREFETCH_CFG,
1111 .prefetch = { 1146 .prefetch = {
@@ -1113,6 +1148,25 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
1113 }, 1148 },
1114 }; 1149 };
1115 1150
1151 if (master) {
1152 smmu_domain = master->domain;
1153 smmu = master->smmu;
1154 }
1155
1156 if (smmu_domain) {
1157 switch (smmu_domain->stage) {
1158 case ARM_SMMU_DOMAIN_S1:
1159 s1_cfg = &smmu_domain->s1_cfg;
1160 break;
1161 case ARM_SMMU_DOMAIN_S2:
1162 case ARM_SMMU_DOMAIN_NESTED:
1163 s2_cfg = &smmu_domain->s2_cfg;
1164 break;
1165 default:
1166 break;
1167 }
1168 }
1169
1116 if (val & STRTAB_STE_0_V) { 1170 if (val & STRTAB_STE_0_V) {
1117 switch (FIELD_GET(STRTAB_STE_0_CFG, val)) { 1171 switch (FIELD_GET(STRTAB_STE_0_CFG, val)) {
1118 case STRTAB_STE_0_CFG_BYPASS: 1172 case STRTAB_STE_0_CFG_BYPASS:
@@ -1133,8 +1187,8 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
1133 val = STRTAB_STE_0_V; 1187 val = STRTAB_STE_0_V;
1134 1188
1135 /* Bypass/fault */ 1189 /* Bypass/fault */
1136 if (!ste->assigned || !(ste->s1_cfg || ste->s2_cfg)) { 1190 if (!smmu_domain || !(s1_cfg || s2_cfg)) {
1137 if (!ste->assigned && disable_bypass) 1191 if (!smmu_domain && disable_bypass)
1138 val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT); 1192 val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT);
1139 else 1193 else
1140 val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS); 1194 val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_BYPASS);
@@ -1152,41 +1206,42 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
1152 return; 1206 return;
1153 } 1207 }
1154 1208
1155 if (ste->s1_cfg) { 1209 if (s1_cfg) {
1156 BUG_ON(ste_live); 1210 BUG_ON(ste_live);
1157 dst[1] = cpu_to_le64( 1211 dst[1] = cpu_to_le64(
1158 FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) | 1212 FIELD_PREP(STRTAB_STE_1_S1CIR, STRTAB_STE_1_S1C_CACHE_WBRA) |
1159 FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) | 1213 FIELD_PREP(STRTAB_STE_1_S1COR, STRTAB_STE_1_S1C_CACHE_WBRA) |
1160 FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) | 1214 FIELD_PREP(STRTAB_STE_1_S1CSH, ARM_SMMU_SH_ISH) |
1161#ifdef CONFIG_PCI_ATS
1162 FIELD_PREP(STRTAB_STE_1_EATS, STRTAB_STE_1_EATS_TRANS) |
1163#endif
1164 FIELD_PREP(STRTAB_STE_1_STRW, STRTAB_STE_1_STRW_NSEL1)); 1215 FIELD_PREP(STRTAB_STE_1_STRW, STRTAB_STE_1_STRW_NSEL1));
1165 1216
1166 if (smmu->features & ARM_SMMU_FEAT_STALLS && 1217 if (smmu->features & ARM_SMMU_FEAT_STALLS &&
1167 !(smmu->features & ARM_SMMU_FEAT_STALL_FORCE)) 1218 !(smmu->features & ARM_SMMU_FEAT_STALL_FORCE))
1168 dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD); 1219 dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD);
1169 1220
1170 val |= (ste->s1_cfg->cdptr_dma & STRTAB_STE_0_S1CTXPTR_MASK) | 1221 val |= (s1_cfg->cdptr_dma & STRTAB_STE_0_S1CTXPTR_MASK) |
1171 FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS); 1222 FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS);
1172 } 1223 }
1173 1224
1174 if (ste->s2_cfg) { 1225 if (s2_cfg) {
1175 BUG_ON(ste_live); 1226 BUG_ON(ste_live);
1176 dst[2] = cpu_to_le64( 1227 dst[2] = cpu_to_le64(
1177 FIELD_PREP(STRTAB_STE_2_S2VMID, ste->s2_cfg->vmid) | 1228 FIELD_PREP(STRTAB_STE_2_S2VMID, s2_cfg->vmid) |
1178 FIELD_PREP(STRTAB_STE_2_VTCR, ste->s2_cfg->vtcr) | 1229 FIELD_PREP(STRTAB_STE_2_VTCR, s2_cfg->vtcr) |
1179#ifdef __BIG_ENDIAN 1230#ifdef __BIG_ENDIAN
1180 STRTAB_STE_2_S2ENDI | 1231 STRTAB_STE_2_S2ENDI |
1181#endif 1232#endif
1182 STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2AA64 | 1233 STRTAB_STE_2_S2PTW | STRTAB_STE_2_S2AA64 |
1183 STRTAB_STE_2_S2R); 1234 STRTAB_STE_2_S2R);
1184 1235
1185 dst[3] = cpu_to_le64(ste->s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK); 1236 dst[3] = cpu_to_le64(s2_cfg->vttbr & STRTAB_STE_3_S2TTB_MASK);
1186 1237
1187 val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS); 1238 val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S2_TRANS);
1188 } 1239 }
1189 1240
1241 if (master->ats_enabled)
1242 dst[1] |= cpu_to_le64(FIELD_PREP(STRTAB_STE_1_EATS,
1243 STRTAB_STE_1_EATS_TRANS));
1244
1190 arm_smmu_sync_ste_for_sid(smmu, sid); 1245 arm_smmu_sync_ste_for_sid(smmu, sid);
1191 dst[0] = cpu_to_le64(val); 1246 dst[0] = cpu_to_le64(val);
1192 arm_smmu_sync_ste_for_sid(smmu, sid); 1247 arm_smmu_sync_ste_for_sid(smmu, sid);
@@ -1199,10 +1254,9 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_device *smmu, u32 sid,
1199static void arm_smmu_init_bypass_stes(u64 *strtab, unsigned int nent) 1254static void arm_smmu_init_bypass_stes(u64 *strtab, unsigned int nent)
1200{ 1255{
1201 unsigned int i; 1256 unsigned int i;
1202 struct arm_smmu_strtab_ent ste = { .assigned = false };
1203 1257
1204 for (i = 0; i < nent; ++i) { 1258 for (i = 0; i < nent; ++i) {
1205 arm_smmu_write_strtab_ent(NULL, -1, strtab, &ste); 1259 arm_smmu_write_strtab_ent(NULL, -1, strtab);
1206 strtab += STRTAB_STE_DWORDS; 1260 strtab += STRTAB_STE_DWORDS;
1207 } 1261 }
1208} 1262}
@@ -1390,6 +1444,96 @@ static irqreturn_t arm_smmu_combined_irq_handler(int irq, void *dev)
1390 return IRQ_WAKE_THREAD; 1444 return IRQ_WAKE_THREAD;
1391} 1445}
1392 1446
1447static void
1448arm_smmu_atc_inv_to_cmd(int ssid, unsigned long iova, size_t size,
1449 struct arm_smmu_cmdq_ent *cmd)
1450{
1451 size_t log2_span;
1452 size_t span_mask;
1453 /* ATC invalidates are always on 4096-bytes pages */
1454 size_t inval_grain_shift = 12;
1455 unsigned long page_start, page_end;
1456
1457 *cmd = (struct arm_smmu_cmdq_ent) {
1458 .opcode = CMDQ_OP_ATC_INV,
1459 .substream_valid = !!ssid,
1460 .atc.ssid = ssid,
1461 };
1462
1463 if (!size) {
1464 cmd->atc.size = ATC_INV_SIZE_ALL;
1465 return;
1466 }
1467
1468 page_start = iova >> inval_grain_shift;
1469 page_end = (iova + size - 1) >> inval_grain_shift;
1470
1471 /*
1472 * In an ATS Invalidate Request, the address must be aligned on the
1473 * range size, which must be a power of two number of page sizes. We
1474 * thus have to choose between grossly over-invalidating the region, or
1475 * splitting the invalidation into multiple commands. For simplicity
1476 * we'll go with the first solution, but should refine it in the future
1477 * if multiple commands are shown to be more efficient.
1478 *
1479 * Find the smallest power of two that covers the range. The most
1480 * significant differing bit between the start and end addresses,
1481 * fls(start ^ end), indicates the required span. For example:
1482 *
1483 * We want to invalidate pages [8; 11]. This is already the ideal range:
1484 * x = 0b1000 ^ 0b1011 = 0b11
1485 * span = 1 << fls(x) = 4
1486 *
1487 * To invalidate pages [7; 10], we need to invalidate [0; 15]:
1488 * x = 0b0111 ^ 0b1010 = 0b1101
1489 * span = 1 << fls(x) = 16
1490 */
1491 log2_span = fls_long(page_start ^ page_end);
1492 span_mask = (1ULL << log2_span) - 1;
1493
1494 page_start &= ~span_mask;
1495
1496 cmd->atc.addr = page_start << inval_grain_shift;
1497 cmd->atc.size = log2_span;
1498}
1499
1500static int arm_smmu_atc_inv_master(struct arm_smmu_master *master,
1501 struct arm_smmu_cmdq_ent *cmd)
1502{
1503 int i;
1504
1505 if (!master->ats_enabled)
1506 return 0;
1507
1508 for (i = 0; i < master->num_sids; i++) {
1509 cmd->atc.sid = master->sids[i];
1510 arm_smmu_cmdq_issue_cmd(master->smmu, cmd);
1511 }
1512
1513 return arm_smmu_cmdq_issue_sync(master->smmu);
1514}
1515
1516static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain,
1517 int ssid, unsigned long iova, size_t size)
1518{
1519 int ret = 0;
1520 unsigned long flags;
1521 struct arm_smmu_cmdq_ent cmd;
1522 struct arm_smmu_master *master;
1523
1524 if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_ATS))
1525 return 0;
1526
1527 arm_smmu_atc_inv_to_cmd(ssid, iova, size, &cmd);
1528
1529 spin_lock_irqsave(&smmu_domain->devices_lock, flags);
1530 list_for_each_entry(master, &smmu_domain->devices, domain_head)
1531 ret |= arm_smmu_atc_inv_master(master, &cmd);
1532 spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
1533
1534 return ret ? -ETIMEDOUT : 0;
1535}
1536
1393/* IO_PGTABLE API */ 1537/* IO_PGTABLE API */
1394static void arm_smmu_tlb_sync(void *cookie) 1538static void arm_smmu_tlb_sync(void *cookie)
1395{ 1539{
@@ -1493,6 +1637,9 @@ static struct iommu_domain *arm_smmu_domain_alloc(unsigned type)
1493 } 1637 }
1494 1638
1495 mutex_init(&smmu_domain->init_mutex); 1639 mutex_init(&smmu_domain->init_mutex);
1640 INIT_LIST_HEAD(&smmu_domain->devices);
1641 spin_lock_init(&smmu_domain->devices_lock);
1642
1496 return &smmu_domain->domain; 1643 return &smmu_domain->domain;
1497} 1644}
1498 1645
@@ -1688,55 +1835,97 @@ static __le64 *arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid)
1688 return step; 1835 return step;
1689} 1836}
1690 1837
1691static void arm_smmu_install_ste_for_dev(struct iommu_fwspec *fwspec) 1838static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master)
1692{ 1839{
1693 int i, j; 1840 int i, j;
1694 struct arm_smmu_master_data *master = fwspec->iommu_priv;
1695 struct arm_smmu_device *smmu = master->smmu; 1841 struct arm_smmu_device *smmu = master->smmu;
1696 1842
1697 for (i = 0; i < fwspec->num_ids; ++i) { 1843 for (i = 0; i < master->num_sids; ++i) {
1698 u32 sid = fwspec->ids[i]; 1844 u32 sid = master->sids[i];
1699 __le64 *step = arm_smmu_get_step_for_sid(smmu, sid); 1845 __le64 *step = arm_smmu_get_step_for_sid(smmu, sid);
1700 1846
1701 /* Bridged PCI devices may end up with duplicated IDs */ 1847 /* Bridged PCI devices may end up with duplicated IDs */
1702 for (j = 0; j < i; j++) 1848 for (j = 0; j < i; j++)
1703 if (fwspec->ids[j] == sid) 1849 if (master->sids[j] == sid)
1704 break; 1850 break;
1705 if (j < i) 1851 if (j < i)
1706 continue; 1852 continue;
1707 1853
1708 arm_smmu_write_strtab_ent(smmu, sid, step, &master->ste); 1854 arm_smmu_write_strtab_ent(master, sid, step);
1709 } 1855 }
1710} 1856}
1711 1857
1712static void arm_smmu_detach_dev(struct device *dev) 1858static int arm_smmu_enable_ats(struct arm_smmu_master *master)
1713{ 1859{
1714 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 1860 int ret;
1715 struct arm_smmu_master_data *master = fwspec->iommu_priv; 1861 size_t stu;
1862 struct pci_dev *pdev;
1863 struct arm_smmu_device *smmu = master->smmu;
1864 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(master->dev);
1716 1865
1717 master->ste.assigned = false; 1866 if (!(smmu->features & ARM_SMMU_FEAT_ATS) || !dev_is_pci(master->dev) ||
1718 arm_smmu_install_ste_for_dev(fwspec); 1867 !(fwspec->flags & IOMMU_FWSPEC_PCI_RC_ATS) || pci_ats_disabled())
1868 return -ENXIO;
1869
1870 pdev = to_pci_dev(master->dev);
1871 if (pdev->untrusted)
1872 return -EPERM;
1873
1874 /* Smallest Translation Unit: log2 of the smallest supported granule */
1875 stu = __ffs(smmu->pgsize_bitmap);
1876
1877 ret = pci_enable_ats(pdev, stu);
1878 if (ret)
1879 return ret;
1880
1881 master->ats_enabled = true;
1882 return 0;
1883}
1884
1885static void arm_smmu_disable_ats(struct arm_smmu_master *master)
1886{
1887 if (!master->ats_enabled || !dev_is_pci(master->dev))
1888 return;
1889
1890 pci_disable_ats(to_pci_dev(master->dev));
1891 master->ats_enabled = false;
1892}
1893
1894static void arm_smmu_detach_dev(struct arm_smmu_master *master)
1895{
1896 unsigned long flags;
1897 struct arm_smmu_domain *smmu_domain = master->domain;
1898
1899 if (!smmu_domain)
1900 return;
1901
1902 spin_lock_irqsave(&smmu_domain->devices_lock, flags);
1903 list_del(&master->domain_head);
1904 spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
1905
1906 master->domain = NULL;
1907 arm_smmu_install_ste_for_dev(master);
1908
1909 /* Disabling ATS invalidates all ATC entries */
1910 arm_smmu_disable_ats(master);
1719} 1911}
1720 1912
1721static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) 1913static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1722{ 1914{
1723 int ret = 0; 1915 int ret = 0;
1916 unsigned long flags;
1724 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 1917 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1725 struct arm_smmu_device *smmu; 1918 struct arm_smmu_device *smmu;
1726 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); 1919 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
1727 struct arm_smmu_master_data *master; 1920 struct arm_smmu_master *master;
1728 struct arm_smmu_strtab_ent *ste;
1729 1921
1730 if (!fwspec) 1922 if (!fwspec)
1731 return -ENOENT; 1923 return -ENOENT;
1732 1924
1733 master = fwspec->iommu_priv; 1925 master = fwspec->iommu_priv;
1734 smmu = master->smmu; 1926 smmu = master->smmu;
1735 ste = &master->ste;
1736 1927
1737 /* Already attached to a different domain? */ 1928 arm_smmu_detach_dev(master);
1738 if (ste->assigned)
1739 arm_smmu_detach_dev(dev);
1740 1929
1741 mutex_lock(&smmu_domain->init_mutex); 1930 mutex_lock(&smmu_domain->init_mutex);
1742 1931
@@ -1756,21 +1945,19 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1756 goto out_unlock; 1945 goto out_unlock;
1757 } 1946 }
1758 1947
1759 ste->assigned = true; 1948 master->domain = smmu_domain;
1760 1949
1761 if (smmu_domain->stage == ARM_SMMU_DOMAIN_BYPASS) { 1950 spin_lock_irqsave(&smmu_domain->devices_lock, flags);
1762 ste->s1_cfg = NULL; 1951 list_add(&master->domain_head, &smmu_domain->devices);
1763 ste->s2_cfg = NULL; 1952 spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
1764 } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
1765 ste->s1_cfg = &smmu_domain->s1_cfg;
1766 ste->s2_cfg = NULL;
1767 arm_smmu_write_ctx_desc(smmu, ste->s1_cfg);
1768 } else {
1769 ste->s1_cfg = NULL;
1770 ste->s2_cfg = &smmu_domain->s2_cfg;
1771 }
1772 1953
1773 arm_smmu_install_ste_for_dev(fwspec); 1954 if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS)
1955 arm_smmu_enable_ats(master);
1956
1957 if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1)
1958 arm_smmu_write_ctx_desc(smmu, &smmu_domain->s1_cfg);
1959
1960 arm_smmu_install_ste_for_dev(master);
1774out_unlock: 1961out_unlock:
1775 mutex_unlock(&smmu_domain->init_mutex); 1962 mutex_unlock(&smmu_domain->init_mutex);
1776 return ret; 1963 return ret;
@@ -1790,12 +1977,18 @@ static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova,
1790static size_t 1977static size_t
1791arm_smmu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) 1978arm_smmu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
1792{ 1979{
1793 struct io_pgtable_ops *ops = to_smmu_domain(domain)->pgtbl_ops; 1980 int ret;
1981 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
1982 struct io_pgtable_ops *ops = smmu_domain->pgtbl_ops;
1794 1983
1795 if (!ops) 1984 if (!ops)
1796 return 0; 1985 return 0;
1797 1986
1798 return ops->unmap(ops, iova, size); 1987 ret = ops->unmap(ops, iova, size);
1988 if (ret && arm_smmu_atc_inv_domain(smmu_domain, 0, iova, size))
1989 return 0;
1990
1991 return ret;
1799} 1992}
1800 1993
1801static void arm_smmu_flush_iotlb_all(struct iommu_domain *domain) 1994static void arm_smmu_flush_iotlb_all(struct iommu_domain *domain)
@@ -1860,7 +2053,7 @@ static int arm_smmu_add_device(struct device *dev)
1860{ 2053{
1861 int i, ret; 2054 int i, ret;
1862 struct arm_smmu_device *smmu; 2055 struct arm_smmu_device *smmu;
1863 struct arm_smmu_master_data *master; 2056 struct arm_smmu_master *master;
1864 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 2057 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1865 struct iommu_group *group; 2058 struct iommu_group *group;
1866 2059
@@ -1882,13 +2075,16 @@ static int arm_smmu_add_device(struct device *dev)
1882 if (!master) 2075 if (!master)
1883 return -ENOMEM; 2076 return -ENOMEM;
1884 2077
2078 master->dev = dev;
1885 master->smmu = smmu; 2079 master->smmu = smmu;
2080 master->sids = fwspec->ids;
2081 master->num_sids = fwspec->num_ids;
1886 fwspec->iommu_priv = master; 2082 fwspec->iommu_priv = master;
1887 } 2083 }
1888 2084
1889 /* Check the SIDs are in range of the SMMU and our stream table */ 2085 /* Check the SIDs are in range of the SMMU and our stream table */
1890 for (i = 0; i < fwspec->num_ids; i++) { 2086 for (i = 0; i < master->num_sids; i++) {
1891 u32 sid = fwspec->ids[i]; 2087 u32 sid = master->sids[i];
1892 2088
1893 if (!arm_smmu_sid_in_range(smmu, sid)) 2089 if (!arm_smmu_sid_in_range(smmu, sid))
1894 return -ERANGE; 2090 return -ERANGE;
@@ -1913,7 +2109,7 @@ static int arm_smmu_add_device(struct device *dev)
1913static void arm_smmu_remove_device(struct device *dev) 2109static void arm_smmu_remove_device(struct device *dev)
1914{ 2110{
1915 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 2111 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1916 struct arm_smmu_master_data *master; 2112 struct arm_smmu_master *master;
1917 struct arm_smmu_device *smmu; 2113 struct arm_smmu_device *smmu;
1918 2114
1919 if (!fwspec || fwspec->ops != &arm_smmu_ops) 2115 if (!fwspec || fwspec->ops != &arm_smmu_ops)
@@ -1921,8 +2117,7 @@ static void arm_smmu_remove_device(struct device *dev)
1921 2117
1922 master = fwspec->iommu_priv; 2118 master = fwspec->iommu_priv;
1923 smmu = master->smmu; 2119 smmu = master->smmu;
1924 if (master && master->ste.assigned) 2120 arm_smmu_detach_dev(master);
1925 arm_smmu_detach_dev(dev);
1926 iommu_group_remove_device(dev); 2121 iommu_group_remove_device(dev);
1927 iommu_device_unlink(&smmu->iommu, dev); 2122 iommu_device_unlink(&smmu->iommu, dev);
1928 kfree(master); 2123 kfree(master);
@@ -2454,13 +2649,9 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass)
2454 /* Clear CR0 and sync (disables SMMU and queue processing) */ 2649 /* Clear CR0 and sync (disables SMMU and queue processing) */
2455 reg = readl_relaxed(smmu->base + ARM_SMMU_CR0); 2650 reg = readl_relaxed(smmu->base + ARM_SMMU_CR0);
2456 if (reg & CR0_SMMUEN) { 2651 if (reg & CR0_SMMUEN) {
2457 if (is_kdump_kernel()) {
2458 arm_smmu_update_gbpa(smmu, GBPA_ABORT, 0);
2459 arm_smmu_device_disable(smmu);
2460 return -EBUSY;
2461 }
2462
2463 dev_warn(smmu->dev, "SMMU currently enabled! Resetting...\n"); 2652 dev_warn(smmu->dev, "SMMU currently enabled! Resetting...\n");
2653 WARN_ON(is_kdump_kernel() && !disable_bypass);
2654 arm_smmu_update_gbpa(smmu, GBPA_ABORT, 0);
2464 } 2655 }
2465 2656
2466 ret = arm_smmu_device_disable(smmu); 2657 ret = arm_smmu_device_disable(smmu);
@@ -2547,12 +2738,24 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass)
2547 } 2738 }
2548 } 2739 }
2549 2740
2741 if (smmu->features & ARM_SMMU_FEAT_ATS) {
2742 enables |= CR0_ATSCHK;
2743 ret = arm_smmu_write_reg_sync(smmu, enables, ARM_SMMU_CR0,
2744 ARM_SMMU_CR0ACK);
2745 if (ret) {
2746 dev_err(smmu->dev, "failed to enable ATS check\n");
2747 return ret;
2748 }
2749 }
2750
2550 ret = arm_smmu_setup_irqs(smmu); 2751 ret = arm_smmu_setup_irqs(smmu);
2551 if (ret) { 2752 if (ret) {
2552 dev_err(smmu->dev, "failed to setup irqs\n"); 2753 dev_err(smmu->dev, "failed to setup irqs\n");
2553 return ret; 2754 return ret;
2554 } 2755 }
2555 2756
2757 if (is_kdump_kernel())
2758 enables &= ~(CR0_EVTQEN | CR0_PRIQEN);
2556 2759
2557 /* Enable the SMMU interface, or ensure bypass */ 2760 /* Enable the SMMU interface, or ensure bypass */
2558 if (!bypass || disable_bypass) { 2761 if (!bypass || disable_bypass) {
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 045d93884164..5e54cc0a28b3 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -110,7 +110,8 @@ static int force_stage;
110module_param(force_stage, int, S_IRUGO); 110module_param(force_stage, int, S_IRUGO);
111MODULE_PARM_DESC(force_stage, 111MODULE_PARM_DESC(force_stage,
112 "Force SMMU mappings to be installed at a particular stage of translation. A value of '1' or '2' forces the corresponding stage. All other values are ignored (i.e. no stage is forced). Note that selecting a specific stage will disable support for nested translation."); 112 "Force SMMU mappings to be installed at a particular stage of translation. A value of '1' or '2' forces the corresponding stage. All other values are ignored (i.e. no stage is forced). Note that selecting a specific stage will disable support for nested translation.");
113static bool disable_bypass; 113static bool disable_bypass =
114 IS_ENABLED(CONFIG_ARM_SMMU_DISABLE_BYPASS_BY_DEFAULT);
114module_param(disable_bypass, bool, S_IRUGO); 115module_param(disable_bypass, bool, S_IRUGO);
115MODULE_PARM_DESC(disable_bypass, 116MODULE_PARM_DESC(disable_bypass,
116 "Disable bypass streams such that incoming transactions from devices that are not attached to an iommu domain will report an abort back to the device and will not be allowed to pass through the SMMU."); 117 "Disable bypass streams such that incoming transactions from devices that are not attached to an iommu domain will report an abort back to the device and will not be allowed to pass through the SMMU.");
@@ -569,12 +570,13 @@ static const struct iommu_gather_ops arm_smmu_s2_tlb_ops_v1 = {
569 570
570static irqreturn_t arm_smmu_context_fault(int irq, void *dev) 571static irqreturn_t arm_smmu_context_fault(int irq, void *dev)
571{ 572{
572 u32 fsr, fsynr; 573 u32 fsr, fsynr, cbfrsynra;
573 unsigned long iova; 574 unsigned long iova;
574 struct iommu_domain *domain = dev; 575 struct iommu_domain *domain = dev;
575 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); 576 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
576 struct arm_smmu_cfg *cfg = &smmu_domain->cfg; 577 struct arm_smmu_cfg *cfg = &smmu_domain->cfg;
577 struct arm_smmu_device *smmu = smmu_domain->smmu; 578 struct arm_smmu_device *smmu = smmu_domain->smmu;
579 void __iomem *gr1_base = ARM_SMMU_GR1(smmu);
578 void __iomem *cb_base; 580 void __iomem *cb_base;
579 581
580 cb_base = ARM_SMMU_CB(smmu, cfg->cbndx); 582 cb_base = ARM_SMMU_CB(smmu, cfg->cbndx);
@@ -585,10 +587,11 @@ static irqreturn_t arm_smmu_context_fault(int irq, void *dev)
585 587
586 fsynr = readl_relaxed(cb_base + ARM_SMMU_CB_FSYNR0); 588 fsynr = readl_relaxed(cb_base + ARM_SMMU_CB_FSYNR0);
587 iova = readq_relaxed(cb_base + ARM_SMMU_CB_FAR); 589 iova = readq_relaxed(cb_base + ARM_SMMU_CB_FAR);
590 cbfrsynra = readl_relaxed(gr1_base + ARM_SMMU_GR1_CBFRSYNRA(cfg->cbndx));
588 591
589 dev_err_ratelimited(smmu->dev, 592 dev_err_ratelimited(smmu->dev,
590 "Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cb=%d\n", 593 "Unhandled context fault: fsr=0x%x, iova=0x%08lx, fsynr=0x%x, cbfrsynra=0x%x, cb=%d\n",
591 fsr, iova, fsynr, cfg->cbndx); 594 fsr, iova, fsynr, cbfrsynra, cfg->cbndx);
592 595
593 writel(fsr, cb_base + ARM_SMMU_CB_FSR); 596 writel(fsr, cb_base + ARM_SMMU_CB_FSR);
594 return IRQ_HANDLED; 597 return IRQ_HANDLED;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ffbbc7e39cee..6c1b4c900191 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -392,10 +392,14 @@ struct iommu_fwspec {
392 const struct iommu_ops *ops; 392 const struct iommu_ops *ops;
393 struct fwnode_handle *iommu_fwnode; 393 struct fwnode_handle *iommu_fwnode;
394 void *iommu_priv; 394 void *iommu_priv;
395 u32 flags;
395 unsigned int num_ids; 396 unsigned int num_ids;
396 u32 ids[1]; 397 u32 ids[1];
397}; 398};
398 399
400/* ATS is supported */
401#define IOMMU_FWSPEC_PCI_RC_ATS (1 << 0)
402
399int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, 403int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
400 const struct iommu_ops *ops); 404 const struct iommu_ops *ops);
401void iommu_fwspec_free(struct device *dev); 405void iommu_fwspec_free(struct device *dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 77448215ef5b..61d7cd888bad 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1521,21 +1521,6 @@ static inline void pcie_ecrc_get_policy(char *str) { }
1521 1521
1522bool pci_ats_disabled(void); 1522bool pci_ats_disabled(void);
1523 1523
1524#ifdef CONFIG_PCI_ATS
1525/* Address Translation Service */
1526void pci_ats_init(struct pci_dev *dev);
1527int pci_enable_ats(struct pci_dev *dev, int ps);
1528void pci_disable_ats(struct pci_dev *dev);
1529int pci_ats_queue_depth(struct pci_dev *dev);
1530int pci_ats_page_aligned(struct pci_dev *dev);
1531#else
1532static inline void pci_ats_init(struct pci_dev *d) { }
1533static inline int pci_enable_ats(struct pci_dev *d, int ps) { return -ENODEV; }
1534static inline void pci_disable_ats(struct pci_dev *d) { }
1535static inline int pci_ats_queue_depth(struct pci_dev *d) { return -ENODEV; }
1536static inline int pci_ats_page_aligned(struct pci_dev *dev) { return 0; }
1537#endif
1538
1539#ifdef CONFIG_PCIE_PTM 1524#ifdef CONFIG_PCIE_PTM
1540int pci_enable_ptm(struct pci_dev *dev, u8 *granularity); 1525int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
1541#else 1526#else
@@ -1728,8 +1713,24 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,
1728static inline const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, 1713static inline const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
1729 struct pci_dev *dev) 1714 struct pci_dev *dev)
1730{ return NULL; } 1715{ return NULL; }
1716static inline bool pci_ats_disabled(void) { return true; }
1731#endif /* CONFIG_PCI */ 1717#endif /* CONFIG_PCI */
1732 1718
1719#ifdef CONFIG_PCI_ATS
1720/* Address Translation Service */
1721void pci_ats_init(struct pci_dev *dev);
1722int pci_enable_ats(struct pci_dev *dev, int ps);
1723void pci_disable_ats(struct pci_dev *dev);
1724int pci_ats_queue_depth(struct pci_dev *dev);
1725int pci_ats_page_aligned(struct pci_dev *dev);
1726#else
1727static inline void pci_ats_init(struct pci_dev *d) { }
1728static inline int pci_enable_ats(struct pci_dev *d, int ps) { return -ENODEV; }
1729static inline void pci_disable_ats(struct pci_dev *d) { }
1730static inline int pci_ats_queue_depth(struct pci_dev *d) { return -ENODEV; }
1731static inline int pci_ats_page_aligned(struct pci_dev *dev) { return 0; }
1732#endif
1733
1733/* Include architecture-dependent settings and functions */ 1734/* Include architecture-dependent settings and functions */
1734 1735
1735#include <asm/pci.h> 1736#include <asm/pci.h>