Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'arm/smmu' into core

+265 -83
+2
Documentation/arm64/silicon-errata.txt
··· 53 53 | ARM | Cortex-A57 | #832075 | ARM64_ERRATUM_832075 | 54 54 | ARM | Cortex-A57 | #852523 | N/A | 55 55 | ARM | Cortex-A57 | #834220 | ARM64_ERRATUM_834220 | 56 + | ARM | MMU-500 | #841119,#826419 | N/A | 56 57 | | | | | 57 58 | Cavium | ThunderX ITS | #22375, #24313 | CAVIUM_ERRATUM_22375 | 58 59 | Cavium | ThunderX GICv3 | #23154 | CAVIUM_ERRATUM_23154 | 59 60 | Cavium | ThunderX Core | #27456 | CAVIUM_ERRATUM_27456 | 61 + | Cavium | ThunderX SMMUv2 | #27704 | N/A |
+1
Documentation/devicetree/bindings/iommu/arm,smmu.txt
··· 16 16 "arm,mmu-400" 17 17 "arm,mmu-401" 18 18 "arm,mmu-500" 19 + "cavium,smmu-v2" 19 20 20 21 depending on the particular implementation and/or the 21 22 version of the architecture implemented.
+210 -81
drivers/iommu/arm-smmu.c
··· 34 34 #include <linux/err.h> 35 35 #include <linux/interrupt.h> 36 36 #include <linux/io.h> 37 + #include <linux/io-64-nonatomic-hi-lo.h> 37 38 #include <linux/iommu.h> 38 39 #include <linux/iopoll.h> 39 40 #include <linux/module.h> ··· 72 71 ((smmu->options & ARM_SMMU_OPT_SECURE_CFG_ACCESS) \ 73 72 ? 0x400 : 0)) 74 73 74 + /* 75 + * Some 64-bit registers only make sense to write atomically, but in such 76 + * cases all the data relevant to AArch32 formats lies within the lower word, 77 + * therefore this actually makes more sense than it might first appear. 78 + */ 75 79 #ifdef CONFIG_64BIT 76 - #define smmu_writeq writeq_relaxed 80 + #define smmu_write_atomic_lq writeq_relaxed 77 81 #else 78 - #define smmu_writeq(reg64, addr) \ 79 - do { \ 80 - u64 __val = (reg64); \ 81 - void __iomem *__addr = (addr); \ 82 - writel_relaxed(__val >> 32, __addr + 4); \ 83 - writel_relaxed(__val, __addr); \ 84 - } while (0) 82 + #define smmu_write_atomic_lq writel_relaxed 85 83 #endif 86 84 87 85 /* Configuration registers */ ··· 94 94 #define sCR0_VMIDPNE (1 << 11) 95 95 #define sCR0_PTM (1 << 12) 96 96 #define sCR0_FB (1 << 13) 97 + #define sCR0_VMID16EN (1 << 31) 97 98 #define sCR0_BSU_SHIFT 14 98 99 #define sCR0_BSU_MASK 0x3 100 + 101 + /* Auxiliary Configuration register */ 102 + #define ARM_SMMU_GR0_sACR 0x10 99 103 100 104 /* Identification registers */ 101 105 #define ARM_SMMU_GR0_ID0 0x20 ··· 120 116 #define ID0_NTS (1 << 28) 121 117 #define ID0_SMS (1 << 27) 122 118 #define ID0_ATOSNS (1 << 26) 119 + #define ID0_PTFS_NO_AARCH32 (1 << 25) 120 + #define ID0_PTFS_NO_AARCH32S (1 << 24) 123 121 #define ID0_CTTW (1 << 14) 124 122 #define ID0_NUMIRPT_SHIFT 16 125 123 #define ID0_NUMIRPT_MASK 0xff ··· 147 141 #define ID2_PTFS_4K (1 << 12) 148 142 #define ID2_PTFS_16K (1 << 13) 149 143 #define ID2_PTFS_64K (1 << 14) 144 + #define ID2_VMID16 (1 << 15) 145 + 146 + #define ID7_MAJOR_SHIFT 4 147 + #define ID7_MAJOR_MASK 0xf 150 148 151 149 /* Global TLB invalidation */ 152 150 #define ARM_SMMU_GR0_TLBIVMID 0x64 ··· 203 193 #define ARM_SMMU_GR1_CBA2R(n) (0x800 + ((n) << 2)) 204 194 #define CBA2R_RW64_32BIT (0 << 0) 205 195 #define CBA2R_RW64_64BIT (1 << 0) 196 + #define CBA2R_VMID_SHIFT 16 197 + #define CBA2R_VMID_MASK 0xffff 206 198 207 199 /* Translation context bank */ 208 200 #define ARM_SMMU_CB_BASE(smmu) ((smmu)->base + ((smmu)->size >> 1)) 209 201 #define ARM_SMMU_CB(smmu, n) ((n) * (1 << (smmu)->pgshift)) 210 202 211 203 #define ARM_SMMU_CB_SCTLR 0x0 204 + #define ARM_SMMU_CB_ACTLR 0x4 212 205 #define ARM_SMMU_CB_RESUME 0x8 213 206 #define ARM_SMMU_CB_TTBCR2 0x10 214 207 #define ARM_SMMU_CB_TTBR0 0x20 ··· 219 206 #define ARM_SMMU_CB_TTBCR 0x30 220 207 #define ARM_SMMU_CB_S1_MAIR0 0x38 221 208 #define ARM_SMMU_CB_S1_MAIR1 0x3c 222 - #define ARM_SMMU_CB_PAR_LO 0x50 223 - #define ARM_SMMU_CB_PAR_HI 0x54 209 + #define ARM_SMMU_CB_PAR 0x50 224 210 #define ARM_SMMU_CB_FSR 0x58 225 - #define ARM_SMMU_CB_FAR_LO 0x60 226 - #define ARM_SMMU_CB_FAR_HI 0x64 211 + #define ARM_SMMU_CB_FAR 0x60 227 212 #define ARM_SMMU_CB_FSYNR0 0x68 228 213 #define ARM_SMMU_CB_S1_TLBIVA 0x600 229 214 #define ARM_SMMU_CB_S1_TLBIASID 0x610 ··· 240 229 #define SCTLR_TRE (1 << 1) 241 230 #define SCTLR_M (1 << 0) 242 231 #define SCTLR_EAE_SBOP (SCTLR_AFE | SCTLR_TRE) 232 + 233 + #define ARM_MMU500_ACTLR_CPRE (1 << 1) 234 + 235 + #define ARM_MMU500_ACR_CACHE_LOCK (1 << 26) 243 236 244 237 #define CB_PAR_F (1 << 0) 245 238 ··· 285 270 "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."); 286 271 287 272 enum arm_smmu_arch_version { 288 - ARM_SMMU_V1 = 1, 273 + ARM_SMMU_V1, 274 + ARM_SMMU_V1_64K, 289 275 ARM_SMMU_V2, 276 + }; 277 + 278 + enum arm_smmu_implementation { 279 + GENERIC_SMMU, 280 + ARM_MMU500, 281 + CAVIUM_SMMUV2, 290 282 }; 291 283 292 284 struct arm_smmu_smr { ··· 327 305 #define ARM_SMMU_FEAT_TRANS_S2 (1 << 3) 328 306 #define ARM_SMMU_FEAT_TRANS_NESTED (1 << 4) 329 307 #define ARM_SMMU_FEAT_TRANS_OPS (1 << 5) 308 + #define ARM_SMMU_FEAT_VMID16 (1 << 6) 309 + #define ARM_SMMU_FEAT_FMT_AARCH64_4K (1 << 7) 310 + #define ARM_SMMU_FEAT_FMT_AARCH64_16K (1 << 8) 311 + #define ARM_SMMU_FEAT_FMT_AARCH64_64K (1 << 9) 312 + #define ARM_SMMU_FEAT_FMT_AARCH32_L (1 << 10) 313 + #define ARM_SMMU_FEAT_FMT_AARCH32_S (1 << 11) 330 314 u32 features; 331 315 332 316 #define ARM_SMMU_OPT_SECURE_CFG_ACCESS (1 << 0) 333 317 u32 options; 334 318 enum arm_smmu_arch_version version; 319 + enum arm_smmu_implementation model; 335 320 336 321 u32 num_context_banks; 337 322 u32 num_s2_context_banks; ··· 358 329 359 330 struct list_head list; 360 331 struct rb_root masters; 332 + 333 + u32 cavium_id_base; /* Specific to Cavium */ 334 + }; 335 + 336 + enum arm_smmu_context_fmt { 337 + ARM_SMMU_CTX_FMT_NONE, 338 + ARM_SMMU_CTX_FMT_AARCH64, 339 + ARM_SMMU_CTX_FMT_AARCH32_L, 340 + ARM_SMMU_CTX_FMT_AARCH32_S, 361 341 }; 362 342 363 343 struct arm_smmu_cfg { 364 344 u8 cbndx; 365 345 u8 irptndx; 366 346 u32 cbar; 347 + enum arm_smmu_context_fmt fmt; 367 348 }; 368 349 #define INVALID_IRPTNDX 0xff 369 350 370 - #define ARM_SMMU_CB_ASID(cfg) ((cfg)->cbndx) 371 - #define ARM_SMMU_CB_VMID(cfg) ((cfg)->cbndx + 1) 351 + #define ARM_SMMU_CB_ASID(smmu, cfg) ((u16)(smmu)->cavium_id_base + (cfg)->cbndx) 352 + #define ARM_SMMU_CB_VMID(smmu, cfg) ((u16)(smmu)->cavium_id_base + (cfg)->cbndx + 1) 372 353 373 354 enum arm_smmu_domain_stage { 374 355 ARM_SMMU_DOMAIN_S1 = 0, ··· 405 366 u32 opt; 406 367 const char *prop; 407 368 }; 369 + 370 + static atomic_t cavium_smmu_context_count = ATOMIC_INIT(0); 408 371 409 372 static struct arm_smmu_option_prop arm_smmu_options[] = { 410 373 { ARM_SMMU_OPT_SECURE_CFG_ACCESS, "calxeda,smmu-secure-config-access" }, ··· 619 578 620 579 if (stage1) { 621 580 base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 622 - writel_relaxed(ARM_SMMU_CB_ASID(cfg), 581 + writel_relaxed(ARM_SMMU_CB_ASID(smmu, cfg), 623 582 base + ARM_SMMU_CB_S1_TLBIASID); 624 583 } else { 625 584 base = ARM_SMMU_GR0(smmu); 626 - writel_relaxed(ARM_SMMU_CB_VMID(cfg), 585 + writel_relaxed(ARM_SMMU_CB_VMID(smmu, cfg), 627 586 base + ARM_SMMU_GR0_TLBIVMID); 628 587 } 629 588 ··· 643 602 reg = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 644 603 reg += leaf ? ARM_SMMU_CB_S1_TLBIVAL : ARM_SMMU_CB_S1_TLBIVA; 645 604 646 - if (!IS_ENABLED(CONFIG_64BIT) || smmu->version == ARM_SMMU_V1) { 605 + if (cfg->fmt != ARM_SMMU_CTX_FMT_AARCH64) { 647 606 iova &= ~12UL; 648 - iova |= ARM_SMMU_CB_ASID(cfg); 607 + iova |= ARM_SMMU_CB_ASID(smmu, cfg); 649 608 do { 650 609 writel_relaxed(iova, reg); 651 610 iova += granule; 652 611 } while (size -= granule); 653 - #ifdef CONFIG_64BIT 654 612 } else { 655 613 iova >>= 12; 656 - iova |= (u64)ARM_SMMU_CB_ASID(cfg) << 48; 614 + iova |= (u64)ARM_SMMU_CB_ASID(smmu, cfg) << 48; 657 615 do { 658 616 writeq_relaxed(iova, reg); 659 617 iova += granule >> 12; 660 618 } while (size -= granule); 661 - #endif 662 619 } 663 - #ifdef CONFIG_64BIT 664 620 } else if (smmu->version == ARM_SMMU_V2) { 665 621 reg = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 666 622 reg += leaf ? ARM_SMMU_CB_S2_TLBIIPAS2L : 667 623 ARM_SMMU_CB_S2_TLBIIPAS2; 668 624 iova >>= 12; 669 625 do { 670 - writeq_relaxed(iova, reg); 626 + smmu_write_atomic_lq(iova, reg); 671 627 iova += granule >> 12; 672 628 } while (size -= granule); 673 - #endif 674 629 } else { 675 630 reg = ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_TLBIVMID; 676 - writel_relaxed(ARM_SMMU_CB_VMID(cfg), reg); 631 + writel_relaxed(ARM_SMMU_CB_VMID(smmu, cfg), reg); 677 632 } 678 633 } 679 634 ··· 682 645 static irqreturn_t arm_smmu_context_fault(int irq, void *dev) 683 646 { 684 647 int flags, ret; 685 - u32 fsr, far, fsynr, resume; 648 + u32 fsr, fsynr, resume; 686 649 unsigned long iova; 687 650 struct iommu_domain *domain = dev; 688 651 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); ··· 704 667 fsynr = readl_relaxed(cb_base + ARM_SMMU_CB_FSYNR0); 705 668 flags = fsynr & FSYNR0_WNR ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ; 706 669 707 - far = readl_relaxed(cb_base + ARM_SMMU_CB_FAR_LO); 708 - iova = far; 709 - #ifdef CONFIG_64BIT 710 - far = readl_relaxed(cb_base + ARM_SMMU_CB_FAR_HI); 711 - iova |= ((unsigned long)far << 32); 712 - #endif 713 - 670 + iova = readq_relaxed(cb_base + ARM_SMMU_CB_FAR); 714 671 if (!report_iommu_fault(domain, smmu->dev, iova, flags)) { 715 672 ret = IRQ_HANDLED; 716 673 resume = RESUME_RETRY; ··· 765 734 cb_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 766 735 767 736 if (smmu->version > ARM_SMMU_V1) { 768 - /* 769 - * CBA2R. 770 - * *Must* be initialised before CBAR thanks to VMID16 771 - * architectural oversight affected some implementations. 772 - */ 773 - #ifdef CONFIG_64BIT 774 - reg = CBA2R_RW64_64BIT; 775 - #else 776 - reg = CBA2R_RW64_32BIT; 777 - #endif 737 + if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64) 738 + reg = CBA2R_RW64_64BIT; 739 + else 740 + reg = CBA2R_RW64_32BIT; 741 + /* 16-bit VMIDs live in CBA2R */ 742 + if (smmu->features & ARM_SMMU_FEAT_VMID16) 743 + reg |= ARM_SMMU_CB_VMID(smmu, cfg) << CBA2R_VMID_SHIFT; 744 + 778 745 writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBA2R(cfg->cbndx)); 779 746 } 780 747 781 748 /* CBAR */ 782 749 reg = cfg->cbar; 783 - if (smmu->version == ARM_SMMU_V1) 750 + if (smmu->version < ARM_SMMU_V2) 784 751 reg |= cfg->irptndx << CBAR_IRPTNDX_SHIFT; 785 752 786 753 /* ··· 788 759 if (stage1) { 789 760 reg |= (CBAR_S1_BPSHCFG_NSH << CBAR_S1_BPSHCFG_SHIFT) | 790 761 (CBAR_S1_MEMATTR_WB << CBAR_S1_MEMATTR_SHIFT); 791 - } else { 792 - reg |= ARM_SMMU_CB_VMID(cfg) << CBAR_VMID_SHIFT; 762 + } else if (!(smmu->features & ARM_SMMU_FEAT_VMID16)) { 763 + /* 8-bit VMIDs live in CBAR */ 764 + reg |= ARM_SMMU_CB_VMID(smmu, cfg) << CBAR_VMID_SHIFT; 793 765 } 794 766 writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBAR(cfg->cbndx)); 795 767 ··· 798 768 if (stage1) { 799 769 reg64 = pgtbl_cfg->arm_lpae_s1_cfg.ttbr[0]; 800 770 801 - reg64 |= ((u64)ARM_SMMU_CB_ASID(cfg)) << TTBRn_ASID_SHIFT; 802 - smmu_writeq(reg64, cb_base + ARM_SMMU_CB_TTBR0); 771 + reg64 |= ((u64)ARM_SMMU_CB_ASID(smmu, cfg)) << TTBRn_ASID_SHIFT; 772 + writeq_relaxed(reg64, cb_base + ARM_SMMU_CB_TTBR0); 803 773 804 774 reg64 = pgtbl_cfg->arm_lpae_s1_cfg.ttbr[1]; 805 - reg64 |= ((u64)ARM_SMMU_CB_ASID(cfg)) << TTBRn_ASID_SHIFT; 806 - smmu_writeq(reg64, cb_base + ARM_SMMU_CB_TTBR1); 775 + reg64 |= ((u64)ARM_SMMU_CB_ASID(smmu, cfg)) << TTBRn_ASID_SHIFT; 776 + writeq_relaxed(reg64, cb_base + ARM_SMMU_CB_TTBR1); 807 777 } else { 808 778 reg64 = pgtbl_cfg->arm_lpae_s2_cfg.vttbr; 809 - smmu_writeq(reg64, cb_base + ARM_SMMU_CB_TTBR0); 779 + writeq_relaxed(reg64, cb_base + ARM_SMMU_CB_TTBR0); 810 780 } 811 781 812 782 /* TTBCR */ ··· 885 855 if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) 886 856 smmu_domain->stage = ARM_SMMU_DOMAIN_S1; 887 857 858 + /* 859 + * Choosing a suitable context format is even more fiddly. Until we 860 + * grow some way for the caller to express a preference, and/or move 861 + * the decision into the io-pgtable code where it arguably belongs, 862 + * just aim for the closest thing to the rest of the system, and hope 863 + * that the hardware isn't esoteric enough that we can't assume AArch64 864 + * support to be a superset of AArch32 support... 865 + */ 866 + if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH32_L) 867 + cfg->fmt = ARM_SMMU_CTX_FMT_AARCH32_L; 868 + if ((IS_ENABLED(CONFIG_64BIT) || cfg->fmt == ARM_SMMU_CTX_FMT_NONE) && 869 + (smmu->features & (ARM_SMMU_FEAT_FMT_AARCH64_64K | 870 + ARM_SMMU_FEAT_FMT_AARCH64_16K | 871 + ARM_SMMU_FEAT_FMT_AARCH64_4K))) 872 + cfg->fmt = ARM_SMMU_CTX_FMT_AARCH64; 873 + 874 + if (cfg->fmt == ARM_SMMU_CTX_FMT_NONE) { 875 + ret = -EINVAL; 876 + goto out_unlock; 877 + } 878 + 888 879 switch (smmu_domain->stage) { 889 880 case ARM_SMMU_DOMAIN_S1: 890 881 cfg->cbar = CBAR_TYPE_S1_TRANS_S2_BYPASS; 891 882 start = smmu->num_s2_context_banks; 892 883 ias = smmu->va_size; 893 884 oas = smmu->ipa_size; 894 - if (IS_ENABLED(CONFIG_64BIT)) 885 + if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64) { 895 886 fmt = ARM_64_LPAE_S1; 896 - else 887 + } else { 897 888 fmt = ARM_32_LPAE_S1; 889 + ias = min(ias, 32UL); 890 + oas = min(oas, 40UL); 891 + } 898 892 break; 899 893 case ARM_SMMU_DOMAIN_NESTED: 900 894 /* ··· 930 876 start = 0; 931 877 ias = smmu->ipa_size; 932 878 oas = smmu->pa_size; 933 - if (IS_ENABLED(CONFIG_64BIT)) 879 + if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64) { 934 880 fmt = ARM_64_LPAE_S2; 935 - else 881 + } else { 936 882 fmt = ARM_32_LPAE_S2; 883 + ias = min(ias, 40UL); 884 + oas = min(oas, 40UL); 885 + } 937 886 break; 938 887 default: 939 888 ret = -EINVAL; ··· 949 892 goto out_unlock; 950 893 951 894 cfg->cbndx = ret; 952 - if (smmu->version == ARM_SMMU_V1) { 895 + if (smmu->version < ARM_SMMU_V2) { 953 896 cfg->irptndx = atomic_inc_return(&smmu->irptndx); 954 897 cfg->irptndx %= smmu->num_context_irqs; 955 898 } else { ··· 1309 1252 /* ATS1 registers can only be written atomically */ 1310 1253 va = iova & ~0xfffUL; 1311 1254 if (smmu->version == ARM_SMMU_V2) 1312 - smmu_writeq(va, cb_base + ARM_SMMU_CB_ATS1PR); 1313 - else 1255 + smmu_write_atomic_lq(va, cb_base + ARM_SMMU_CB_ATS1PR); 1256 + else /* Register is only 32-bit in v1 */ 1314 1257 writel_relaxed(va, cb_base + ARM_SMMU_CB_ATS1PR); 1315 1258 1316 1259 if (readl_poll_timeout_atomic(cb_base + ARM_SMMU_CB_ATSR, tmp, ··· 1321 1264 return ops->iova_to_phys(ops, iova); 1322 1265 } 1323 1266 1324 - phys = readl_relaxed(cb_base + ARM_SMMU_CB_PAR_LO); 1325 - phys |= ((u64)readl_relaxed(cb_base + ARM_SMMU_CB_PAR_HI)) << 32; 1326 - 1267 + phys = readq_relaxed(cb_base + ARM_SMMU_CB_PAR); 1327 1268 if (phys & CB_PAR_F) { 1328 1269 dev_err(dev, "translation fault!\n"); 1329 1270 dev_err(dev, "PAR = 0x%llx\n", phys); ··· 1547 1492 void __iomem *gr0_base = ARM_SMMU_GR0(smmu); 1548 1493 void __iomem *cb_base; 1549 1494 int i = 0; 1550 - u32 reg; 1495 + u32 reg, major; 1551 1496 1552 1497 /* clear global FSR */ 1553 1498 reg = readl_relaxed(ARM_SMMU_GR0_NS(smmu) + ARM_SMMU_GR0_sGFSR); ··· 1560 1505 writel_relaxed(reg, gr0_base + ARM_SMMU_GR0_S2CR(i)); 1561 1506 } 1562 1507 1508 + /* 1509 + * Before clearing ARM_MMU500_ACTLR_CPRE, need to 1510 + * clear CACHE_LOCK bit of ACR first. And, CACHE_LOCK 1511 + * bit is only present in MMU-500r2 onwards. 1512 + */ 1513 + reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID7); 1514 + major = (reg >> ID7_MAJOR_SHIFT) & ID7_MAJOR_MASK; 1515 + if ((smmu->model == ARM_MMU500) && (major >= 2)) { 1516 + reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_sACR); 1517 + reg &= ~ARM_MMU500_ACR_CACHE_LOCK; 1518 + writel_relaxed(reg, gr0_base + ARM_SMMU_GR0_sACR); 1519 + } 1520 + 1563 1521 /* Make sure all context banks are disabled and clear CB_FSR */ 1564 1522 for (i = 0; i < smmu->num_context_banks; ++i) { 1565 1523 cb_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, i); 1566 1524 writel_relaxed(0, cb_base + ARM_SMMU_CB_SCTLR); 1567 1525 writel_relaxed(FSR_FAULT, cb_base + ARM_SMMU_CB_FSR); 1526 + /* 1527 + * Disable MMU-500's not-particularly-beneficial next-page 1528 + * prefetcher for the sake of errata #841119 and #826419. 1529 + */ 1530 + if (smmu->model == ARM_MMU500) { 1531 + reg = readl_relaxed(cb_base + ARM_SMMU_CB_ACTLR); 1532 + reg &= ~ARM_MMU500_ACTLR_CPRE; 1533 + writel_relaxed(reg, cb_base + ARM_SMMU_CB_ACTLR); 1534 + } 1568 1535 } 1569 1536 1570 1537 /* Invalidate the TLB, just in case */ ··· 1613 1536 1614 1537 /* Don't upgrade barriers */ 1615 1538 reg &= ~(sCR0_BSU_MASK << sCR0_BSU_SHIFT); 1539 + 1540 + if (smmu->features & ARM_SMMU_FEAT_VMID16) 1541 + reg |= sCR0_VMID16EN; 1616 1542 1617 1543 /* Push the button */ 1618 1544 __arm_smmu_tlb_sync(smmu); ··· 1649 1569 bool cttw_dt, cttw_reg; 1650 1570 1651 1571 dev_notice(smmu->dev, "probing hardware configuration...\n"); 1652 - dev_notice(smmu->dev, "SMMUv%d with:\n", smmu->version); 1572 + dev_notice(smmu->dev, "SMMUv%d with:\n", 1573 + smmu->version == ARM_SMMU_V2 ? 2 : 1); 1653 1574 1654 1575 /* ID0 */ 1655 1576 id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID0); ··· 1682 1601 return -ENODEV; 1683 1602 } 1684 1603 1685 - if ((id & ID0_S1TS) && ((smmu->version == 1) || !(id & ID0_ATOSNS))) { 1604 + if ((id & ID0_S1TS) && 1605 + ((smmu->version < ARM_SMMU_V2) || !(id & ID0_ATOSNS))) { 1686 1606 smmu->features |= ARM_SMMU_FEAT_TRANS_OPS; 1687 1607 dev_notice(smmu->dev, "\taddress translation ops\n"); 1688 1608 } ··· 1739 1657 ID0_NUMSIDB_MASK; 1740 1658 } 1741 1659 1660 + if (smmu->version < ARM_SMMU_V2 || !(id & ID0_PTFS_NO_AARCH32)) { 1661 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH32_L; 1662 + if (!(id & ID0_PTFS_NO_AARCH32S)) 1663 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH32_S; 1664 + } 1665 + 1742 1666 /* ID1 */ 1743 1667 id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID1); 1744 1668 smmu->pgshift = (id & ID1_PAGESIZE) ? 16 : 12; ··· 1765 1677 } 1766 1678 dev_notice(smmu->dev, "\t%u context banks (%u stage-2 only)\n", 1767 1679 smmu->num_context_banks, smmu->num_s2_context_banks); 1680 + /* 1681 + * Cavium CN88xx erratum #27704. 1682 + * Ensure ASID and VMID allocation is unique across all SMMUs in 1683 + * the system. 1684 + */ 1685 + if (smmu->model == CAVIUM_SMMUV2) { 1686 + smmu->cavium_id_base = 1687 + atomic_add_return(smmu->num_context_banks, 1688 + &cavium_smmu_context_count); 1689 + smmu->cavium_id_base -= smmu->num_context_banks; 1690 + } 1768 1691 1769 1692 /* ID2 */ 1770 1693 id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID2); ··· 1786 1687 size = arm_smmu_id_size_to_bits((id >> ID2_OAS_SHIFT) & ID2_OAS_MASK); 1787 1688 smmu->pa_size = size; 1788 1689 1690 + if (id & ID2_VMID16) 1691 + smmu->features |= ARM_SMMU_FEAT_VMID16; 1692 + 1789 1693 /* 1790 1694 * What the page table walker can address actually depends on which 1791 1695 * descriptor format is in use, but since a) we don't know that yet, ··· 1798 1696 dev_warn(smmu->dev, 1799 1697 "failed to set DMA mask for table walker\n"); 1800 1698 1801 - if (smmu->version == ARM_SMMU_V1) { 1699 + if (smmu->version < ARM_SMMU_V2) { 1802 1700 smmu->va_size = smmu->ipa_size; 1803 - size = SZ_4K | SZ_2M | SZ_1G; 1701 + if (smmu->version == ARM_SMMU_V1_64K) 1702 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_64K; 1804 1703 } else { 1805 1704 size = (id >> ID2_UBS_SHIFT) & ID2_UBS_MASK; 1806 1705 smmu->va_size = arm_smmu_id_size_to_bits(size); 1807 - #ifndef CONFIG_64BIT 1808 - smmu->va_size = min(32UL, smmu->va_size); 1809 - #endif 1810 - size = 0; 1811 1706 if (id & ID2_PTFS_4K) 1812 - size |= SZ_4K | SZ_2M | SZ_1G; 1707 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_4K; 1813 1708 if (id & ID2_PTFS_16K) 1814 - size |= SZ_16K | SZ_32M; 1709 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_16K; 1815 1710 if (id & ID2_PTFS_64K) 1816 - size |= SZ_64K | SZ_512M; 1711 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_64K; 1817 1712 } 1713 + 1714 + /* Now we've corralled the various formats, what'll it do? */ 1715 + size = 0; 1716 + if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH32_S) 1717 + size |= SZ_4K | SZ_64K | SZ_1M | SZ_16M; 1718 + if (smmu->features & 1719 + (ARM_SMMU_FEAT_FMT_AARCH32_L | ARM_SMMU_FEAT_FMT_AARCH64_4K)) 1720 + size |= SZ_4K | SZ_2M | SZ_1G; 1721 + if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH64_16K) 1722 + size |= SZ_16K | SZ_32M; 1723 + if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH64_64K) 1724 + size |= SZ_64K | SZ_512M; 1818 1725 1819 1726 arm_smmu_ops.pgsize_bitmap &= size; 1820 1727 dev_notice(smmu->dev, "\tSupported page sizes: 0x%08lx\n", size); ··· 1839 1728 return 0; 1840 1729 } 1841 1730 1731 + struct arm_smmu_match_data { 1732 + enum arm_smmu_arch_version version; 1733 + enum arm_smmu_implementation model; 1734 + }; 1735 + 1736 + #define ARM_SMMU_MATCH_DATA(name, ver, imp) \ 1737 + static struct arm_smmu_match_data name = { .version = ver, .model = imp } 1738 + 1739 + ARM_SMMU_MATCH_DATA(smmu_generic_v1, ARM_SMMU_V1, GENERIC_SMMU); 1740 + ARM_SMMU_MATCH_DATA(smmu_generic_v2, ARM_SMMU_V2, GENERIC_SMMU); 1741 + ARM_SMMU_MATCH_DATA(arm_mmu401, ARM_SMMU_V1_64K, GENERIC_SMMU); 1742 + ARM_SMMU_MATCH_DATA(arm_mmu500, ARM_SMMU_V2, ARM_MMU500); 1743 + ARM_SMMU_MATCH_DATA(cavium_smmuv2, ARM_SMMU_V2, CAVIUM_SMMUV2); 1744 + 1842 1745 static const struct of_device_id arm_smmu_of_match[] = { 1843 - { .compatible = "arm,smmu-v1", .data = (void *)ARM_SMMU_V1 }, 1844 - { .compatible = "arm,smmu-v2", .data = (void *)ARM_SMMU_V2 }, 1845 - { .compatible = "arm,mmu-400", .data = (void *)ARM_SMMU_V1 }, 1846 - { .compatible = "arm,mmu-401", .data = (void *)ARM_SMMU_V1 }, 1847 - { .compatible = "arm,mmu-500", .data = (void *)ARM_SMMU_V2 }, 1746 + { .compatible = "arm,smmu-v1", .data = &smmu_generic_v1 }, 1747 + { .compatible = "arm,smmu-v2", .data = &smmu_generic_v2 }, 1748 + { .compatible = "arm,mmu-400", .data = &smmu_generic_v1 }, 1749 + { .compatible = "arm,mmu-401", .data = &arm_mmu401 }, 1750 + { .compatible = "arm,mmu-500", .data = &arm_mmu500 }, 1751 + { .compatible = "cavium,smmu-v2", .data = &cavium_smmuv2 }, 1848 1752 { }, 1849 1753 }; 1850 1754 MODULE_DEVICE_TABLE(of, arm_smmu_of_match); ··· 1867 1741 static int arm_smmu_device_dt_probe(struct platform_device *pdev) 1868 1742 { 1869 1743 const struct of_device_id *of_id; 1744 + const struct arm_smmu_match_data *data; 1870 1745 struct resource *res; 1871 1746 struct arm_smmu_device *smmu; 1872 1747 struct device *dev = &pdev->dev; ··· 1883 1756 smmu->dev = dev; 1884 1757 1885 1758 of_id = of_match_node(arm_smmu_of_match, dev->of_node); 1886 - smmu->version = (enum arm_smmu_arch_version)of_id->data; 1759 + data = of_id->data; 1760 + smmu->version = data->version; 1761 + smmu->model = data->model; 1887 1762 1888 1763 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1889 1764 smmu->base = devm_ioremap_resource(dev, res); ··· 1951 1822 1952 1823 parse_driver_options(smmu); 1953 1824 1954 - if (smmu->version > ARM_SMMU_V1 && 1825 + if (smmu->version == ARM_SMMU_V2 && 1955 1826 smmu->num_context_banks != smmu->num_context_irqs) { 1956 1827 dev_err(dev, 1957 1828 "found only %d context interrupt(s) but %d required\n",
+2 -2
include/asm-generic/io.h
··· 191 191 #define readl_relaxed readl 192 192 #endif 193 193 194 - #ifndef readq_relaxed 194 + #if defined(readq) && !defined(readq_relaxed) 195 195 #define readq_relaxed readq 196 196 #endif 197 197 ··· 207 207 #define writel_relaxed writel 208 208 #endif 209 209 210 - #ifndef writeq_relaxed 210 + #if defined(writeq) && !defined(writeq_relaxed) 211 211 #define writeq_relaxed writeq 212 212 #endif 213 213
+25
include/linux/io-64-nonatomic-hi-lo.h
··· 21 21 writel(val, addr); 22 22 } 23 23 24 + static inline __u64 hi_lo_readq_relaxed(const volatile void __iomem *addr) 25 + { 26 + const volatile u32 __iomem *p = addr; 27 + u32 low, high; 28 + 29 + high = readl_relaxed(p + 1); 30 + low = readl_relaxed(p); 31 + 32 + return low + ((u64)high << 32); 33 + } 34 + 35 + static inline void hi_lo_writeq_relaxed(__u64 val, volatile void __iomem *addr) 36 + { 37 + writel_relaxed(val >> 32, addr + 4); 38 + writel_relaxed(val, addr); 39 + } 40 + 24 41 #ifndef readq 25 42 #define readq hi_lo_readq 26 43 #endif 27 44 28 45 #ifndef writeq 29 46 #define writeq hi_lo_writeq 47 + #endif 48 + 49 + #ifndef readq_relaxed 50 + #define readq_relaxed hi_lo_readq_relaxed 51 + #endif 52 + 53 + #ifndef writeq_relaxed 54 + #define writeq_relaxed hi_lo_writeq_relaxed 30 55 #endif 31 56 32 57 #endif /* _LINUX_IO_64_NONATOMIC_HI_LO_H_ */
+25
include/linux/io-64-nonatomic-lo-hi.h
··· 21 21 writel(val >> 32, addr + 4); 22 22 } 23 23 24 + static inline __u64 lo_hi_readq_relaxed(const volatile void __iomem *addr) 25 + { 26 + const volatile u32 __iomem *p = addr; 27 + u32 low, high; 28 + 29 + low = readl_relaxed(p); 30 + high = readl_relaxed(p + 1); 31 + 32 + return low + ((u64)high << 32); 33 + } 34 + 35 + static inline void lo_hi_writeq_relaxed(__u64 val, volatile void __iomem *addr) 36 + { 37 + writel_relaxed(val, addr); 38 + writel_relaxed(val >> 32, addr + 4); 39 + } 40 + 24 41 #ifndef readq 25 42 #define readq lo_hi_readq 26 43 #endif 27 44 28 45 #ifndef writeq 29 46 #define writeq lo_hi_writeq 47 + #endif 48 + 49 + #ifndef readq_relaxed 50 + #define readq_relaxed lo_hi_readq_relaxed 51 + #endif 52 + 53 + #ifndef writeq_relaxed 54 + #define writeq_relaxed lo_hi_writeq_relaxed 30 55 #endif 31 56 32 57 #endif /* _LINUX_IO_64_NONATOMIC_LO_HI_H_ */