aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <joro@8bytes.org>2014-03-04 08:54:27 -0500
committerJoerg Roedel <joro@8bytes.org>2014-03-04 08:54:27 -0500
commitdc03753b98e21d73699c38b208ad39d9839519ee (patch)
tree0b7bbfba26ea0c75098c0276897653f6a87fb6fa
parent0414855fdc4a40da05221fc6062cccbc0c30f169 (diff)
parent34fb4b37b7b6da7dc34797d1abf234dd30b091d8 (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--Documentation/devicetree/bindings/iommu/arm,smmu.txt6
-rw-r--r--drivers/iommu/arm-smmu.c105
2 files changed, 77 insertions, 34 deletions
diff --git a/Documentation/devicetree/bindings/iommu/arm,smmu.txt b/Documentation/devicetree/bindings/iommu/arm,smmu.txt
index e34c6cdd8ba8..f284b99402bc 100644
--- a/Documentation/devicetree/bindings/iommu/arm,smmu.txt
+++ b/Documentation/devicetree/bindings/iommu/arm,smmu.txt
@@ -48,6 +48,12 @@ conditions.
48 from the mmu-masters towards memory) node for this 48 from the mmu-masters towards memory) node for this
49 SMMU. 49 SMMU.
50 50
51- calxeda,smmu-secure-config-access : Enable proper handling of buggy
52 implementations that always use secure access to
53 SMMU configuration registers. In this case non-secure
54 aliases of secure registers have to be used during
55 SMMU configuration.
56
51Example: 57Example:
52 58
53 smmu { 59 smmu {
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 1d9ab39af29f..8b89e33a89fe 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -48,7 +48,7 @@
48#include <asm/pgalloc.h> 48#include <asm/pgalloc.h>
49 49
50/* Maximum number of stream IDs assigned to a single device */ 50/* Maximum number of stream IDs assigned to a single device */
51#define MAX_MASTER_STREAMIDS 8 51#define MAX_MASTER_STREAMIDS MAX_PHANDLE_ARGS
52 52
53/* Maximum number of context banks per SMMU */ 53/* Maximum number of context banks per SMMU */
54#define ARM_SMMU_MAX_CBS 128 54#define ARM_SMMU_MAX_CBS 128
@@ -60,6 +60,16 @@
60#define ARM_SMMU_GR0(smmu) ((smmu)->base) 60#define ARM_SMMU_GR0(smmu) ((smmu)->base)
61#define ARM_SMMU_GR1(smmu) ((smmu)->base + (smmu)->pagesize) 61#define ARM_SMMU_GR1(smmu) ((smmu)->base + (smmu)->pagesize)
62 62
63/*
64 * SMMU global address space with conditional offset to access secure
65 * aliases of non-secure registers (e.g. nsCR0: 0x400, nsGFSR: 0x448,
66 * nsGFSYNR0: 0x450)
67 */
68#define ARM_SMMU_GR0_NS(smmu) \
69 ((smmu)->base + \
70 ((smmu->options & ARM_SMMU_OPT_SECURE_CFG_ACCESS) \
71 ? 0x400 : 0))
72
63/* Page table bits */ 73/* Page table bits */
64#define ARM_SMMU_PTE_XN (((pteval_t)3) << 53) 74#define ARM_SMMU_PTE_XN (((pteval_t)3) << 53)
65#define ARM_SMMU_PTE_CONT (((pteval_t)1) << 52) 75#define ARM_SMMU_PTE_CONT (((pteval_t)1) << 52)
@@ -351,6 +361,9 @@ struct arm_smmu_device {
351#define ARM_SMMU_FEAT_TRANS_S2 (1 << 3) 361#define ARM_SMMU_FEAT_TRANS_S2 (1 << 3)
352#define ARM_SMMU_FEAT_TRANS_NESTED (1 << 4) 362#define ARM_SMMU_FEAT_TRANS_NESTED (1 << 4)
353 u32 features; 363 u32 features;
364
365#define ARM_SMMU_OPT_SECURE_CFG_ACCESS (1 << 0)
366 u32 options;
354 int version; 367 int version;
355 368
356 u32 num_context_banks; 369 u32 num_context_banks;
@@ -401,6 +414,29 @@ struct arm_smmu_domain {
401static DEFINE_SPINLOCK(arm_smmu_devices_lock); 414static DEFINE_SPINLOCK(arm_smmu_devices_lock);
402static LIST_HEAD(arm_smmu_devices); 415static LIST_HEAD(arm_smmu_devices);
403 416
417struct arm_smmu_option_prop {
418 u32 opt;
419 const char *prop;
420};
421
422static struct arm_smmu_option_prop arm_smmu_options [] = {
423 { ARM_SMMU_OPT_SECURE_CFG_ACCESS, "calxeda,smmu-secure-config-access" },
424 { 0, NULL},
425};
426
427static void parse_driver_options(struct arm_smmu_device *smmu)
428{
429 int i = 0;
430 do {
431 if (of_property_read_bool(smmu->dev->of_node,
432 arm_smmu_options[i].prop)) {
433 smmu->options |= arm_smmu_options[i].opt;
434 dev_notice(smmu->dev, "option %s\n",
435 arm_smmu_options[i].prop);
436 }
437 } while (arm_smmu_options[++i].opt);
438}
439
404static struct arm_smmu_master *find_smmu_master(struct arm_smmu_device *smmu, 440static struct arm_smmu_master *find_smmu_master(struct arm_smmu_device *smmu,
405 struct device_node *dev_node) 441 struct device_node *dev_node)
406{ 442{
@@ -614,16 +650,16 @@ static irqreturn_t arm_smmu_global_fault(int irq, void *dev)
614{ 650{
615 u32 gfsr, gfsynr0, gfsynr1, gfsynr2; 651 u32 gfsr, gfsynr0, gfsynr1, gfsynr2;
616 struct arm_smmu_device *smmu = dev; 652 struct arm_smmu_device *smmu = dev;
617 void __iomem *gr0_base = ARM_SMMU_GR0(smmu); 653 void __iomem *gr0_base = ARM_SMMU_GR0_NS(smmu);
618 654
619 gfsr = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSR); 655 gfsr = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSR);
620 if (!gfsr)
621 return IRQ_NONE;
622
623 gfsynr0 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR0); 656 gfsynr0 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR0);
624 gfsynr1 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR1); 657 gfsynr1 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR1);
625 gfsynr2 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR2); 658 gfsynr2 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sGFSYNR2);
626 659
660 if (!gfsr)
661 return IRQ_NONE;
662
627 dev_err_ratelimited(smmu->dev, 663 dev_err_ratelimited(smmu->dev,
628 "Unexpected global fault, this could be serious\n"); 664 "Unexpected global fault, this could be serious\n");
629 dev_err_ratelimited(smmu->dev, 665 dev_err_ratelimited(smmu->dev,
@@ -642,7 +678,7 @@ static void arm_smmu_flush_pgtable(struct arm_smmu_device *smmu, void *addr,
642 678
643 /* Ensure new page tables are visible to the hardware walker */ 679 /* Ensure new page tables are visible to the hardware walker */
644 if (smmu->features & ARM_SMMU_FEAT_COHERENT_WALK) { 680 if (smmu->features & ARM_SMMU_FEAT_COHERENT_WALK) {
645 dsb(); 681 dsb(ishst);
646 } else { 682 } else {
647 /* 683 /*
648 * If the SMMU can't walk tables in the CPU caches, treat them 684 * If the SMMU can't walk tables in the CPU caches, treat them
@@ -990,9 +1026,8 @@ static void arm_smmu_free_pgtables(struct arm_smmu_domain *smmu_domain)
990 1026
991 /* 1027 /*
992 * Recursively free the page tables for this domain. We don't 1028 * Recursively free the page tables for this domain. We don't
993 * care about speculative TLB filling, because the TLB will be 1029 * care about speculative TLB filling because the tables should
994 * nuked next time this context bank is re-allocated and no devices 1030 * not be active in any context bank at this point (SCTLR.M is 0).
995 * currently map to these tables.
996 */ 1031 */
997 pgd = pgd_base; 1032 pgd = pgd_base;
998 for (i = 0; i < PTRS_PER_PGD; ++i) { 1033 for (i = 0; i < PTRS_PER_PGD; ++i) {
@@ -1218,7 +1253,7 @@ static bool arm_smmu_pte_is_contiguous_range(unsigned long addr,
1218 1253
1219static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd, 1254static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
1220 unsigned long addr, unsigned long end, 1255 unsigned long addr, unsigned long end,
1221 unsigned long pfn, int flags, int stage) 1256 unsigned long pfn, int prot, int stage)
1222{ 1257{
1223 pte_t *pte, *start; 1258 pte_t *pte, *start;
1224 pteval_t pteval = ARM_SMMU_PTE_PAGE | ARM_SMMU_PTE_AF | ARM_SMMU_PTE_XN; 1259 pteval_t pteval = ARM_SMMU_PTE_PAGE | ARM_SMMU_PTE_AF | ARM_SMMU_PTE_XN;
@@ -1240,28 +1275,28 @@ static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
1240 1275
1241 if (stage == 1) { 1276 if (stage == 1) {
1242 pteval |= ARM_SMMU_PTE_AP_UNPRIV | ARM_SMMU_PTE_nG; 1277 pteval |= ARM_SMMU_PTE_AP_UNPRIV | ARM_SMMU_PTE_nG;
1243 if (!(flags & IOMMU_WRITE) && (flags & IOMMU_READ)) 1278 if (!(prot & IOMMU_WRITE) && (prot & IOMMU_READ))
1244 pteval |= ARM_SMMU_PTE_AP_RDONLY; 1279 pteval |= ARM_SMMU_PTE_AP_RDONLY;
1245 1280
1246 if (flags & IOMMU_CACHE) 1281 if (prot & IOMMU_CACHE)
1247 pteval |= (MAIR_ATTR_IDX_CACHE << 1282 pteval |= (MAIR_ATTR_IDX_CACHE <<
1248 ARM_SMMU_PTE_ATTRINDX_SHIFT); 1283 ARM_SMMU_PTE_ATTRINDX_SHIFT);
1249 } else { 1284 } else {
1250 pteval |= ARM_SMMU_PTE_HAP_FAULT; 1285 pteval |= ARM_SMMU_PTE_HAP_FAULT;
1251 if (flags & IOMMU_READ) 1286 if (prot & IOMMU_READ)
1252 pteval |= ARM_SMMU_PTE_HAP_READ; 1287 pteval |= ARM_SMMU_PTE_HAP_READ;
1253 if (flags & IOMMU_WRITE) 1288 if (prot & IOMMU_WRITE)
1254 pteval |= ARM_SMMU_PTE_HAP_WRITE; 1289 pteval |= ARM_SMMU_PTE_HAP_WRITE;
1255 if (flags & IOMMU_CACHE) 1290 if (prot & IOMMU_CACHE)
1256 pteval |= ARM_SMMU_PTE_MEMATTR_OIWB; 1291 pteval |= ARM_SMMU_PTE_MEMATTR_OIWB;
1257 else