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

Merge branch 'for-joerg/arm-smmu/updates' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux into arm/smmu

+157 -117
+6
Documentation/devicetree/bindings/iommu/arm,smmu.txt
··· 43 43 44 44 ** System MMU optional properties: 45 45 46 + - dma-coherent : Present if page table walks made by the SMMU are 47 + cache coherent with the CPU. 48 + 49 + NOTE: this only applies to the SMMU itself, not 50 + masters connected upstream of the SMMU. 51 + 46 52 - calxeda,smmu-secure-config-access : Enable proper handling of buggy 47 53 implementations that always use secure access to 48 54 SMMU configuration registers. In this case non-secure
+2 -1
drivers/iommu/Kconfig
··· 23 23 config IOMMU_IO_PGTABLE_LPAE 24 24 bool "ARMv7/v8 Long Descriptor Format" 25 25 select IOMMU_IO_PGTABLE 26 - depends on ARM || ARM64 || COMPILE_TEST 26 + # SWIOTLB guarantees a dma_to_phys() implementation 27 + depends on ARM || ARM64 || (COMPILE_TEST && SWIOTLB) 27 28 help 28 29 Enable support for the ARM long descriptor pagetable format. 29 30 This allocator supports 4K/2M/1G, 16K/32M and 64K/512M page
+27 -39
drivers/iommu/arm-smmu-v3.c
··· 118 118 119 119 #define ARM_SMMU_IRQ_CTRL 0x50 120 120 #define IRQ_CTRL_EVTQ_IRQEN (1 << 2) 121 + #define IRQ_CTRL_PRIQ_IRQEN (1 << 1) 121 122 #define IRQ_CTRL_GERROR_IRQEN (1 << 0) 122 123 123 124 #define ARM_SMMU_IRQ_CTRLACK 0x54 ··· 174 173 #define ARM_SMMU_PRIQ_IRQ_CFG2 0xdc 175 174 176 175 /* Common MSI config fields */ 177 - #define MSI_CFG0_SH_SHIFT 60 178 - #define MSI_CFG0_SH_NSH (0UL << MSI_CFG0_SH_SHIFT) 179 - #define MSI_CFG0_SH_OSH (2UL << MSI_CFG0_SH_SHIFT) 180 - #define MSI_CFG0_SH_ISH (3UL << MSI_CFG0_SH_SHIFT) 181 - #define MSI_CFG0_MEMATTR_SHIFT 56 182 - #define MSI_CFG0_MEMATTR_DEVICE_nGnRE (0x1 << MSI_CFG0_MEMATTR_SHIFT) 183 176 #define MSI_CFG0_ADDR_SHIFT 2 184 177 #define MSI_CFG0_ADDR_MASK 0x3fffffffffffUL 178 + #define MSI_CFG2_SH_SHIFT 4 179 + #define MSI_CFG2_SH_NSH (0UL << MSI_CFG2_SH_SHIFT) 180 + #define MSI_CFG2_SH_OSH (2UL << MSI_CFG2_SH_SHIFT) 181 + #define MSI_CFG2_SH_ISH (3UL << MSI_CFG2_SH_SHIFT) 182 + #define MSI_CFG2_MEMATTR_SHIFT 0 183 + #define MSI_CFG2_MEMATTR_DEVICE_nGnRE (0x1 << MSI_CFG2_MEMATTR_SHIFT) 185 184 186 185 #define Q_IDX(q, p) ((p) & ((1 << (q)->max_n_shift) - 1)) 187 186 #define Q_WRP(q, p) ((p) & (1 << (q)->max_n_shift)) ··· 1331 1330 arm_smmu_cmdq_issue_cmd(smmu, &cmd); 1332 1331 } 1333 1332 1334 - static void arm_smmu_flush_pgtable(void *addr, size_t size, void *cookie) 1335 - { 1336 - struct arm_smmu_domain *smmu_domain = cookie; 1337 - struct arm_smmu_device *smmu = smmu_domain->smmu; 1338 - unsigned long offset = (unsigned long)addr & ~PAGE_MASK; 1339 - 1340 - if (smmu->features & ARM_SMMU_FEAT_COHERENCY) { 1341 - dsb(ishst); 1342 - } else { 1343 - dma_addr_t dma_addr; 1344 - struct device *dev = smmu->dev; 1345 - 1346 - dma_addr = dma_map_page(dev, virt_to_page(addr), offset, size, 1347 - DMA_TO_DEVICE); 1348 - 1349 - if (dma_mapping_error(dev, dma_addr)) 1350 - dev_err(dev, "failed to flush pgtable at %p\n", addr); 1351 - else 1352 - dma_unmap_page(dev, dma_addr, size, DMA_TO_DEVICE); 1353 - } 1354 - } 1355 - 1356 1333 static struct iommu_gather_ops arm_smmu_gather_ops = { 1357 1334 .tlb_flush_all = arm_smmu_tlb_inv_context, 1358 1335 .tlb_add_flush = arm_smmu_tlb_inv_range_nosync, 1359 1336 .tlb_sync = arm_smmu_tlb_sync, 1360 - .flush_pgtable = arm_smmu_flush_pgtable, 1361 1337 }; 1362 1338 1363 1339 /* IOMMU API */ ··· 1509 1531 .ias = ias, 1510 1532 .oas = oas, 1511 1533 .tlb = &arm_smmu_gather_ops, 1534 + .iommu_dev = smmu->dev, 1512 1535 }; 1513 1536 1514 1537 pgtbl_ops = alloc_io_pgtable_ops(fmt, &pgtbl_cfg, smmu_domain); ··· 2032 2053 int ret; 2033 2054 struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; 2034 2055 2035 - /* Calculate the L1 size, capped to the SIDSIZE */ 2036 - size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3); 2037 - size = min(size, smmu->sid_bits - STRTAB_SPLIT); 2056 + /* 2057 + * If we can resolve everything with a single L2 table, then we 2058 + * just need a single L1 descriptor. Otherwise, calculate the L1 2059 + * size, capped to the SIDSIZE. 2060 + */ 2061 + if (smmu->sid_bits < STRTAB_SPLIT) { 2062 + size = 0; 2063 + } else { 2064 + size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3); 2065 + size = min(size, smmu->sid_bits - STRTAB_SPLIT); 2066 + } 2038 2067 cfg->num_l1_ents = 1 << size; 2039 2068 2040 2069 size += STRTAB_SPLIT; ··· 2185 2198 static int arm_smmu_setup_irqs(struct arm_smmu_device *smmu) 2186 2199 { 2187 2200 int ret, irq; 2201 + u32 irqen_flags = IRQ_CTRL_EVTQ_IRQEN | IRQ_CTRL_GERROR_IRQEN; 2188 2202 2189 2203 /* Disable IRQs first */ 2190 2204 ret = arm_smmu_write_reg_sync(smmu, 0, ARM_SMMU_IRQ_CTRL, ··· 2240 2252 if (IS_ERR_VALUE(ret)) 2241 2253 dev_warn(smmu->dev, 2242 2254 "failed to enable priq irq\n"); 2255 + else 2256 + irqen_flags |= IRQ_CTRL_PRIQ_IRQEN; 2243 2257 } 2244 2258 } 2245 2259 2246 2260 /* Enable interrupt generation on the SMMU */ 2247 - ret = arm_smmu_write_reg_sync(smmu, 2248 - IRQ_CTRL_EVTQ_IRQEN | 2249 - IRQ_CTRL_GERROR_IRQEN, 2261 + ret = arm_smmu_write_reg_sync(smmu, irqen_flags, 2250 2262 ARM_SMMU_IRQ_CTRL, ARM_SMMU_IRQ_CTRLACK); 2251 2263 if (ret) 2252 2264 dev_warn(smmu->dev, "failed to enable irqs\n"); ··· 2528 2540 case IDR5_OAS_44_BIT: 2529 2541 smmu->oas = 44; 2530 2542 break; 2543 + default: 2544 + dev_info(smmu->dev, 2545 + "unknown output address size. Truncating to 48-bit\n"); 2546 + /* Fallthrough */ 2531 2547 case IDR5_OAS_48_BIT: 2532 2548 smmu->oas = 48; 2533 - break; 2534 - default: 2535 - dev_err(smmu->dev, "unknown output address size!\n"); 2536 - return -ENXIO; 2537 2549 } 2538 2550 2539 2551 /* Set the DMA mask for our table walker */
+18 -27
drivers/iommu/arm-smmu.c
··· 37 37 #include <linux/iopoll.h> 38 38 #include <linux/module.h> 39 39 #include <linux/of.h> 40 + #include <linux/of_address.h> 40 41 #include <linux/pci.h> 41 42 #include <linux/platform_device.h> 42 43 #include <linux/slab.h> ··· 608 607 } 609 608 } 610 609 611 - static void arm_smmu_flush_pgtable(void *addr, size_t size, void *cookie) 612 - { 613 - struct arm_smmu_domain *smmu_domain = cookie; 614 - struct arm_smmu_device *smmu = smmu_domain->smmu; 615 - unsigned long offset = (unsigned long)addr & ~PAGE_MASK; 616 - 617 - 618 - /* Ensure new page tables are visible to the hardware walker */ 619 - if (smmu->features & ARM_SMMU_FEAT_COHERENT_WALK) { 620 - dsb(ishst); 621 - } else { 622 - /* 623 - * If the SMMU can't walk tables in the CPU caches, treat them 624 - * like non-coherent DMA since we need to flush the new entries 625 - * all the way out to memory. There's no possibility of 626 - * recursion here as the SMMU table walker will not be wired 627 - * through another SMMU. 628 - */ 629 - dma_map_page(smmu->dev, virt_to_page(addr), offset, size, 630 - DMA_TO_DEVICE); 631 - } 632 - } 633 - 634 610 static struct iommu_gather_ops arm_smmu_gather_ops = { 635 611 .tlb_flush_all = arm_smmu_tlb_inv_context, 636 612 .tlb_add_flush = arm_smmu_tlb_inv_range_nosync, 637 613 .tlb_sync = arm_smmu_tlb_sync, 638 - .flush_pgtable = arm_smmu_flush_pgtable, 639 614 }; 640 615 641 616 static irqreturn_t arm_smmu_context_fault(int irq, void *dev) ··· 875 898 .ias = ias, 876 899 .oas = oas, 877 900 .tlb = &arm_smmu_gather_ops, 901 + .iommu_dev = smmu->dev, 878 902 }; 879 903 880 904 smmu_domain->smmu = smmu; ··· 1510 1532 unsigned long size; 1511 1533 void __iomem *gr0_base = ARM_SMMU_GR0(smmu); 1512 1534 u32 id; 1535 + bool cttw_dt, cttw_reg; 1513 1536 1514 1537 dev_notice(smmu->dev, "probing hardware configuration...\n"); 1515 1538 dev_notice(smmu->dev, "SMMUv%d with:\n", smmu->version); ··· 1550 1571 dev_notice(smmu->dev, "\taddress translation ops\n"); 1551 1572 } 1552 1573 1553 - if (id & ID0_CTTW) { 1574 + /* 1575 + * In order for DMA API calls to work properly, we must defer to what 1576 + * the DT says about coherency, regardless of what the hardware claims. 1577 + * Fortunately, this also opens up a workaround for systems where the 1578 + * ID register value has ended up configured incorrectly. 1579 + */ 1580 + cttw_dt = of_dma_is_coherent(smmu->dev->of_node); 1581 + cttw_reg = !!(id & ID0_CTTW); 1582 + if (cttw_dt) 1554 1583 smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK; 1555 - dev_notice(smmu->dev, "\tcoherent table walk\n"); 1556 - } 1584 + if (cttw_dt || cttw_reg) 1585 + dev_notice(smmu->dev, "\t%scoherent table walk\n", 1586 + cttw_dt ? "" : "non-"); 1587 + if (cttw_dt != cttw_reg) 1588 + dev_notice(smmu->dev, 1589 + "\t(IDR0.CTTW overridden by dma-coherent property)\n"); 1557 1590 1558 1591 if (id & ID0_SMS) { 1559 1592 u32 smr, sid, mask;
+93 -33
drivers/iommu/io-pgtable-arm.c
··· 26 26 #include <linux/slab.h> 27 27 #include <linux/types.h> 28 28 29 + #include <asm/barrier.h> 30 + 29 31 #include "io-pgtable.h" 30 32 31 33 #define ARM_LPAE_MAX_ADDR_BITS 48 ··· 202 200 203 201 static bool selftest_running = false; 204 202 203 + static dma_addr_t __arm_lpae_dma_addr(struct device *dev, void *pages) 204 + { 205 + return phys_to_dma(dev, virt_to_phys(pages)); 206 + } 207 + 208 + static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, 209 + struct io_pgtable_cfg *cfg) 210 + { 211 + struct device *dev = cfg->iommu_dev; 212 + dma_addr_t dma; 213 + void *pages = alloc_pages_exact(size, gfp | __GFP_ZERO); 214 + 215 + if (!pages) 216 + return NULL; 217 + 218 + if (!selftest_running) { 219 + dma = dma_map_single(dev, pages, size, DMA_TO_DEVICE); 220 + if (dma_mapping_error(dev, dma)) 221 + goto out_free; 222 + /* 223 + * We depend on the IOMMU being able to work with any physical 224 + * address directly, so if the DMA layer suggests it can't by 225 + * giving us back some translation, that bodes very badly... 226 + */ 227 + if (dma != __arm_lpae_dma_addr(dev, pages)) 228 + goto out_unmap; 229 + } 230 + 231 + return pages; 232 + 233 + out_unmap: 234 + dev_err(dev, "Cannot accommodate DMA translation for IOMMU page tables\n"); 235 + dma_unmap_single(dev, dma, size, DMA_TO_DEVICE); 236 + out_free: 237 + free_pages_exact(pages, size); 238 + return NULL; 239 + } 240 + 241 + static void __arm_lpae_free_pages(void *pages, size_t size, 242 + struct io_pgtable_cfg *cfg) 243 + { 244 + struct device *dev = cfg->iommu_dev; 245 + 246 + if (!selftest_running) 247 + dma_unmap_single(dev, __arm_lpae_dma_addr(dev, pages), 248 + size, DMA_TO_DEVICE); 249 + free_pages_exact(pages, size); 250 + } 251 + 252 + static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte, 253 + struct io_pgtable_cfg *cfg) 254 + { 255 + struct device *dev = cfg->iommu_dev; 256 + 257 + *ptep = pte; 258 + 259 + if (!selftest_running) 260 + dma_sync_single_for_device(dev, __arm_lpae_dma_addr(dev, ptep), 261 + sizeof(pte), DMA_TO_DEVICE); 262 + } 263 + 205 264 static int arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, 206 265 unsigned long iova, phys_addr_t paddr, 207 266 arm_lpae_iopte prot, int lvl, 208 267 arm_lpae_iopte *ptep) 209 268 { 210 269 arm_lpae_iopte pte = prot; 270 + struct io_pgtable_cfg *cfg = &data->iop.cfg; 211 271 212 272 /* We require an unmap first */ 213 273 if (iopte_leaf(*ptep, lvl)) { ··· 277 213 return -EEXIST; 278 214 } 279 215 280 - if (data->iop.cfg.quirks & IO_PGTABLE_QUIRK_ARM_NS) 216 + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_NS) 281 217 pte |= ARM_LPAE_PTE_NS; 282 218 283 219 if (lvl == ARM_LPAE_MAX_LEVELS - 1) ··· 288 224 pte |= ARM_LPAE_PTE_AF | ARM_LPAE_PTE_SH_IS; 289 225 pte |= pfn_to_iopte(paddr >> data->pg_shift, data); 290 226 291 - *ptep = pte; 292 - data->iop.cfg.tlb->flush_pgtable(ptep, sizeof(*ptep), data->iop.cookie); 227 + __arm_lpae_set_pte(ptep, pte, cfg); 293 228 return 0; 294 229 } 295 230 ··· 297 234 int lvl, arm_lpae_iopte *ptep) 298 235 { 299 236 arm_lpae_iopte *cptep, pte; 300 - void *cookie = data->iop.cookie; 301 237 size_t block_size = ARM_LPAE_BLOCK_SIZE(lvl, data); 238 + struct io_pgtable_cfg *cfg = &data->iop.cfg; 302 239 303 240 /* Find our entry at the current level */ 304 241 ptep += ARM_LPAE_LVL_IDX(iova, lvl, data); 305 242 306 243 /* If we can install a leaf entry at this level, then do so */ 307 - if (size == block_size && (size & data->iop.cfg.pgsize_bitmap)) 244 + if (size == block_size && (size & cfg->pgsize_bitmap)) 308 245 return arm_lpae_init_pte(data, iova, paddr, prot, lvl, ptep); 309 246 310 247 /* We can't allocate tables at the final level */ ··· 314 251 /* Grab a pointer to the next level */ 315 252 pte = *ptep; 316 253 if (!pte) { 317 - cptep = alloc_pages_exact(1UL << data->pg_shift, 318 - GFP_ATOMIC | __GFP_ZERO); 254 + cptep = __arm_lpae_alloc_pages(1UL << data->pg_shift, 255 + GFP_ATOMIC, cfg); 319 256 if (!cptep) 320 257 return -ENOMEM; 321 258 322 - data->iop.cfg.tlb->flush_pgtable(cptep, 1UL << data->pg_shift, 323 - cookie); 324 259 pte = __pa(cptep) | ARM_LPAE_PTE_TYPE_TABLE; 325 - if (data->iop.cfg.quirks & IO_PGTABLE_QUIRK_ARM_NS) 260 + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_NS) 326 261 pte |= ARM_LPAE_PTE_NSTABLE; 327 - *ptep = pte; 328 - data->iop.cfg.tlb->flush_pgtable(ptep, sizeof(*ptep), cookie); 262 + __arm_lpae_set_pte(ptep, pte, cfg); 329 263 } else { 330 264 cptep = iopte_deref(pte, data); 331 265 } ··· 369 309 { 370 310 struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops); 371 311 arm_lpae_iopte *ptep = data->pgd; 372 - int lvl = ARM_LPAE_START_LVL(data); 312 + int ret, lvl = ARM_LPAE_START_LVL(data); 373 313 arm_lpae_iopte prot; 374 314 375 315 /* If no access, then nothing to do */ ··· 377 317 return 0; 378 318 379 319 prot = arm_lpae_prot_to_pte(data, iommu_prot); 380 - return __arm_lpae_map(data, iova, paddr, size, prot, lvl, ptep); 320 + ret = __arm_lpae_map(data, iova, paddr, size, prot, lvl, ptep); 321 + /* 322 + * Synchronise all PTE updates for the new mapping before there's 323 + * a chance for anything to kick off a table walk for the new iova. 324 + */ 325 + wmb(); 326 + 327 + return ret; 381 328 } 382 329 383 330 static void __arm_lpae_free_pgtable(struct arm_lpae_io_pgtable *data, int lvl, ··· 414 347 __arm_lpae_free_pgtable(data, lvl + 1, iopte_deref(pte, data)); 415 348 } 416 349 417 - free_pages_exact(start, table_size); 350 + __arm_lpae_free_pages(start, table_size, &data->iop.cfg); 418 351 } 419 352 420 353 static void arm_lpae_free_pgtable(struct io_pgtable *iop) ··· 433 366 unsigned long blk_start, blk_end; 434 367 phys_addr_t blk_paddr; 435 368 arm_lpae_iopte table = 0; 436 - void *cookie = data->iop.cookie; 437 - const struct iommu_gather_ops *tlb = data->iop.cfg.tlb; 369 + struct io_pgtable_cfg *cfg = &data->iop.cfg; 438 370 439 371 blk_start = iova & ~(blk_size - 1); 440 372 blk_end = blk_start + blk_size; ··· 459 393 } 460 394 } 461 395 462 - *ptep = table; 463 - tlb->flush_pgtable(ptep, sizeof(*ptep), cookie); 396 + __arm_lpae_set_pte(ptep, table, cfg); 464 397 iova &= ~(blk_size - 1); 465 - tlb->tlb_add_flush(iova, blk_size, true, cookie); 398 + cfg->tlb->tlb_add_flush(iova, blk_size, true, data->iop.cookie); 466 399 return size; 467 400 } 468 401 ··· 483 418 484 419 /* If the size matches this level, we're in the right place */ 485 420 if (size == blk_size) { 486 - *ptep = 0; 487 - tlb->flush_pgtable(ptep, sizeof(*ptep), cookie); 421 + __arm_lpae_set_pte(ptep, 0, &data->iop.cfg); 488 422 489 423 if (!iopte_leaf(pte, lvl)) { 490 424 /* Also flush any partial walks */ 491 425 tlb->tlb_add_flush(iova, size, false, cookie); 492 - tlb->tlb_sync(data->iop.cookie); 426 + tlb->tlb_sync(cookie); 493 427 ptep = iopte_deref(pte, data); 494 428 __arm_lpae_free_pgtable(data, lvl + 1, ptep); 495 429 } else { ··· 704 640 cfg->arm_lpae_s1_cfg.mair[1] = 0; 705 641 706 642 /* Looking good; allocate a pgd */ 707 - data->pgd = alloc_pages_exact(data->pgd_size, GFP_KERNEL | __GFP_ZERO); 643 + data->pgd = __arm_lpae_alloc_pages(data->pgd_size, GFP_KERNEL, cfg); 708 644 if (!data->pgd) 709 645 goto out_free_data; 710 646 711 - cfg->tlb->flush_pgtable(data->pgd, data->pgd_size, cookie); 647 + /* Ensure the empty pgd is visible before any actual TTBR write */ 648 + wmb(); 712 649 713 650 /* TTBRs */ 714 651 cfg->arm_lpae_s1_cfg.ttbr[0] = virt_to_phys(data->pgd); ··· 793 728 cfg->arm_lpae_s2_cfg.vtcr = reg; 794 729 795 730 /* Allocate pgd pages */ 796 - data->pgd = alloc_pages_exact(data->pgd_size, GFP_KERNEL | __GFP_ZERO); 731 + data->pgd = __arm_lpae_alloc_pages(data->pgd_size, GFP_KERNEL, cfg); 797 732 if (!data->pgd) 798 733 goto out_free_data; 799 734 800 - cfg->tlb->flush_pgtable(data->pgd, data->pgd_size, cookie); 735 + /* Ensure the empty pgd is visible before any actual TTBR write */ 736 + wmb(); 801 737 802 738 /* VTTBR */ 803 739 cfg->arm_lpae_s2_cfg.vttbr = virt_to_phys(data->pgd); ··· 884 818 WARN_ON(cookie != cfg_cookie); 885 819 } 886 820 887 - static void dummy_flush_pgtable(void *ptr, size_t size, void *cookie) 888 - { 889 - WARN_ON(cookie != cfg_cookie); 890 - } 891 - 892 821 static struct iommu_gather_ops dummy_tlb_ops __initdata = { 893 822 .tlb_flush_all = dummy_tlb_flush_all, 894 823 .tlb_add_flush = dummy_tlb_add_flush, 895 824 .tlb_sync = dummy_tlb_sync, 896 - .flush_pgtable = dummy_flush_pgtable, 897 825 }; 898 826 899 827 static void __init arm_lpae_dump_ops(struct io_pgtable_ops *ops)
+6 -3
drivers/iommu/io-pgtable.h
··· 17 17 * 18 18 * @tlb_flush_all: Synchronously invalidate the entire TLB context. 19 19 * @tlb_add_flush: Queue up a TLB invalidation for a virtual address range. 20 - * @tlb_sync: Ensure any queue TLB invalidation has taken effect. 21 - * @flush_pgtable: Ensure page table updates are visible to the IOMMU. 20 + * @tlb_sync: Ensure any queued TLB invalidation has taken effect, and 21 + * any corresponding page table updates are visible to the 22 + * IOMMU. 22 23 * 23 24 * Note that these can all be called in atomic context and must therefore 24 25 * not block. ··· 29 28 void (*tlb_add_flush)(unsigned long iova, size_t size, bool leaf, 30 29 void *cookie); 31 30 void (*tlb_sync)(void *cookie); 32 - void (*flush_pgtable)(void *ptr, size_t size, void *cookie); 33 31 }; 34 32 35 33 /** ··· 41 41 * @ias: Input address (iova) size, in bits. 42 42 * @oas: Output address (paddr) size, in bits. 43 43 * @tlb: TLB management callbacks for this set of tables. 44 + * @iommu_dev: The device representing the DMA configuration for the 45 + * page table walker. 44 46 */ 45 47 struct io_pgtable_cfg { 46 48 #define IO_PGTABLE_QUIRK_ARM_NS (1 << 0) /* Set NS bit in PTEs */ ··· 51 49 unsigned int ias; 52 50 unsigned int oas; 53 51 const struct iommu_gather_ops *tlb; 52 + struct device *iommu_dev; 54 53 55 54 /* Low-level data specific to the table format */ 56 55 union {
+5 -14
drivers/iommu/ipmmu-vmsa.c
··· 283 283 /* The hardware doesn't support selective TLB flush. */ 284 284 } 285 285 286 - static void ipmmu_flush_pgtable(void *ptr, size_t size, void *cookie) 287 - { 288 - unsigned long offset = (unsigned long)ptr & ~PAGE_MASK; 289 - struct ipmmu_vmsa_domain *domain = cookie; 290 - 291 - /* 292 - * TODO: Add support for coherent walk through CCI with DVM and remove 293 - * cache handling. 294 - */ 295 - dma_map_page(domain->mmu->dev, virt_to_page(ptr), offset, size, 296 - DMA_TO_DEVICE); 297 - } 298 - 299 286 static struct iommu_gather_ops ipmmu_gather_ops = { 300 287 .tlb_flush_all = ipmmu_tlb_flush_all, 301 288 .tlb_add_flush = ipmmu_tlb_add_flush, 302 289 .tlb_sync = ipmmu_tlb_flush_all, 303 - .flush_pgtable = ipmmu_flush_pgtable, 304 290 }; 305 291 306 292 /* ----------------------------------------------------------------------------- ··· 313 327 domain->cfg.ias = 32; 314 328 domain->cfg.oas = 40; 315 329 domain->cfg.tlb = &ipmmu_gather_ops; 330 + /* 331 + * TODO: Add support for coherent walk through CCI with DVM and remove 332 + * cache handling. For now, delegate it to the io-pgtable code. 333 + */ 334 + domain->cfg.iommu_dev = domain->mmu->dev; 316 335 317 336 domain->iop = alloc_io_pgtable_ops(ARM_32_LPAE_S1, &domain->cfg, 318 337 domain);