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

Merge tag 'iommu-updates-v4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull IOMMU updates from Joerg Roedel:
"The updates include:

- rate limiting for the VT-d fault handler

- remove statistics code from the AMD IOMMU driver. It is unused and
should be replaced by something more generic if needed

- per-domain pagesize-bitmaps in IOMMU core code to support systems
with different types of IOMMUs

- support for ACPI devices in the AMD IOMMU driver

- 4GB mode support for Mediatek IOMMU driver

- ARM-SMMU updates from Will Deacon:
- support for 64k pages with SMMUv1 implementations (e.g MMU-401)
- remove open-coded 64-bit MMIO accessors
- initial support for 16-bit VMIDs, as supported by some ThunderX
SMMU implementations
- a couple of errata workarounds for silicon in the field

- various fixes here and there"

* tag 'iommu-updates-v4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (44 commits)
iommu/arm-smmu: Use per-domain page sizes.
iommu/amd: Remove statistics code
iommu/dma: Finish optimising higher-order allocations
iommu: Allow selecting page sizes per domain
iommu: of: enforce const-ness of struct iommu_ops
iommu: remove unused priv field from struct iommu_ops
iommu/dma: Implement scatterlist segment merging
iommu/arm-smmu: Clear cache lock bit of ACR
iommu/arm-smmu: Support SMMUv1 64KB supplement
iommu/arm-smmu: Decouple context format from kernel config
iommu/arm-smmu: Tidy up 64-bit/atomic I/O accesses
io-64-nonatomic: Add relaxed accessor variants
iommu/arm-smmu: Work around MMU-500 prefetch errata
iommu/arm-smmu: Convert ThunderX workaround to new method
iommu/arm-smmu: Differentiate specific implementations
iommu/arm-smmu: Workaround for ThunderX erratum #27704
iommu/arm-smmu: Add support for 16 bit VMID
iommu/amd: Move get_device_id() and friends to beginning of file
iommu/amd: Don't use IS_ERR_VALUE to check integer values
iommu/amd: Signedness bug in acpihid_device_group()
...

+974 -416
+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.
+7
Documentation/kernel-parameters.txt
··· 1787 1787 PCI device 00:14.0 write the parameter as: 1788 1788 ivrs_hpet[0]=00:14.0 1789 1789 1790 + ivrs_acpihid [HW,X86_64] 1791 + Provide an override to the ACPI-HID:UID<->DEVICE-ID 1792 + mapping provided in the IVRS ACPI table. For 1793 + example, to map UART-HID:UID AMD0020:0 to 1794 + PCI device 00:14.5 write the parameter as: 1795 + ivrs_acpihid[00:14.5]=AMD0020:0 1796 + 1790 1797 js= [HW,JOY] Analog joystick 1791 1798 See Documentation/input/joystick.txt. 1792 1799
+1 -1
arch/arm/include/asm/dma-mapping.h
··· 118 118 119 119 #define arch_setup_dma_ops arch_setup_dma_ops 120 120 extern void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, 121 - struct iommu_ops *iommu, bool coherent); 121 + const struct iommu_ops *iommu, bool coherent); 122 122 123 123 #define arch_teardown_dma_ops arch_teardown_dma_ops 124 124 extern void arch_teardown_dma_ops(struct device *dev);
+3 -3
arch/arm/mm/dma-mapping.c
··· 2215 2215 } 2216 2216 2217 2217 static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size, 2218 - struct iommu_ops *iommu) 2218 + const struct iommu_ops *iommu) 2219 2219 { 2220 2220 struct dma_iommu_mapping *mapping; 2221 2221 ··· 2253 2253 #else 2254 2254 2255 2255 static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size, 2256 - struct iommu_ops *iommu) 2256 + const struct iommu_ops *iommu) 2257 2257 { 2258 2258 return false; 2259 2259 } ··· 2270 2270 } 2271 2271 2272 2272 void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, 2273 - struct iommu_ops *iommu, bool coherent) 2273 + const struct iommu_ops *iommu, bool coherent) 2274 2274 { 2275 2275 struct dma_map_ops *dma_ops; 2276 2276
+1 -1
arch/arm64/include/asm/dma-mapping.h
··· 48 48 } 49 49 50 50 void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, 51 - struct iommu_ops *iommu, bool coherent); 51 + const struct iommu_ops *iommu, bool coherent); 52 52 #define arch_setup_dma_ops arch_setup_dma_ops 53 53 54 54 #ifdef CONFIG_IOMMU_DMA
+4 -4
arch/arm64/mm/dma-mapping.c
··· 562 562 struct page **pages; 563 563 pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL, coherent); 564 564 565 - pages = iommu_dma_alloc(dev, iosize, gfp, ioprot, handle, 566 - flush_page); 565 + pages = iommu_dma_alloc(dev, iosize, gfp, attrs, ioprot, 566 + handle, flush_page); 567 567 if (!pages) 568 568 return NULL; 569 569 ··· 947 947 #else 948 948 949 949 static void __iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, 950 - struct iommu_ops *iommu) 950 + const struct iommu_ops *iommu) 951 951 { } 952 952 953 953 #endif /* CONFIG_IOMMU_DMA */ 954 954 955 955 void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, 956 - struct iommu_ops *iommu, bool coherent) 956 + const struct iommu_ops *iommu, bool coherent) 957 957 { 958 958 if (!dev->archdata.dma_ops) 959 959 dev->archdata.dma_ops = &swiotlb_dma_ops;
+1 -12
drivers/iommu/Kconfig
··· 76 76 77 77 config FSL_PAMU 78 78 bool "Freescale IOMMU support" 79 - depends on PPC32 80 - depends on PPC_E500MC || COMPILE_TEST 79 + depends on PPC_E500MC || (COMPILE_TEST && PPC) 81 80 select IOMMU_API 82 81 select GENERIC_ALLOCATOR 83 82 help ··· 122 123 You can find out if your system has an AMD IOMMU if you look into 123 124 your BIOS for an option to enable it or if you have an IVRS ACPI 124 125 table. 125 - 126 - config AMD_IOMMU_STATS 127 - bool "Export AMD IOMMU statistics to debugfs" 128 - depends on AMD_IOMMU 129 - select DEBUG_FS 130 - ---help--- 131 - This option enables code in the AMD IOMMU driver to collect various 132 - statistics about whats happening in the driver and exports that 133 - information to userspace via debugfs. 134 - If unsure, say N. 135 126 136 127 config AMD_IOMMU_V2 137 128 tristate "AMD IOMMU Version 2 driver"
+149 -118
drivers/iommu/amd_iommu.c
··· 19 19 20 20 #include <linux/ratelimit.h> 21 21 #include <linux/pci.h> 22 + #include <linux/acpi.h> 23 + #include <linux/amba/bus.h> 22 24 #include <linux/pci-ats.h> 23 25 #include <linux/bitmap.h> 24 26 #include <linux/slab.h> ··· 74 72 75 73 LIST_HEAD(ioapic_map); 76 74 LIST_HEAD(hpet_map); 75 + LIST_HEAD(acpihid_map); 77 76 78 77 /* 79 78 * Domain for untranslated devices - only allocated ··· 165 162 * 166 163 ****************************************************************************/ 167 164 168 - static struct protection_domain *to_pdomain(struct iommu_domain *dom) 165 + static inline int match_hid_uid(struct device *dev, 166 + struct acpihid_map_entry *entry) 169 167 { 170 - return container_of(dom, struct protection_domain, domain); 168 + const char *hid, *uid; 169 + 170 + hid = acpi_device_hid(ACPI_COMPANION(dev)); 171 + uid = acpi_device_uid(ACPI_COMPANION(dev)); 172 + 173 + if (!hid || !(*hid)) 174 + return -ENODEV; 175 + 176 + if (!uid || !(*uid)) 177 + return strcmp(hid, entry->hid); 178 + 179 + if (!(*entry->uid)) 180 + return strcmp(hid, entry->hid); 181 + 182 + return (strcmp(hid, entry->hid) || strcmp(uid, entry->uid)); 171 183 } 172 184 173 - static inline u16 get_device_id(struct device *dev) 185 + static inline u16 get_pci_device_id(struct device *dev) 174 186 { 175 187 struct pci_dev *pdev = to_pci_dev(dev); 176 188 177 189 return PCI_DEVID(pdev->bus->number, pdev->devfn); 190 + } 191 + 192 + static inline int get_acpihid_device_id(struct device *dev, 193 + struct acpihid_map_entry **entry) 194 + { 195 + struct acpihid_map_entry *p; 196 + 197 + list_for_each_entry(p, &acpihid_map, list) { 198 + if (!match_hid_uid(dev, p)) { 199 + if (entry) 200 + *entry = p; 201 + return p->devid; 202 + } 203 + } 204 + return -EINVAL; 205 + } 206 + 207 + static inline int get_device_id(struct device *dev) 208 + { 209 + int devid; 210 + 211 + if (dev_is_pci(dev)) 212 + devid = get_pci_device_id(dev); 213 + else 214 + devid = get_acpihid_device_id(dev, NULL); 215 + 216 + return devid; 217 + } 218 + 219 + static struct protection_domain *to_pdomain(struct iommu_domain *dom) 220 + { 221 + return container_of(dom, struct protection_domain, domain); 178 222 } 179 223 180 224 static struct iommu_dev_data *alloc_dev_data(u16 devid) ··· 272 222 struct pci_dev *pdev = to_pci_dev(dev); 273 223 u16 devid, ivrs_alias, pci_alias; 274 224 225 + /* The callers make sure that get_device_id() does not fail here */ 275 226 devid = get_device_id(dev); 276 227 ivrs_alias = amd_iommu_alias_table[devid]; 277 228 pci_for_each_dma_alias(pdev, __last_alias, &pci_alias); ··· 340 289 return dev->archdata.iommu; 341 290 } 342 291 292 + /* 293 + * Find or create an IOMMU group for a acpihid device. 294 + */ 295 + static struct iommu_group *acpihid_device_group(struct device *dev) 296 + { 297 + struct acpihid_map_entry *p, *entry = NULL; 298 + int devid; 299 + 300 + devid = get_acpihid_device_id(dev, &entry); 301 + if (devid < 0) 302 + return ERR_PTR(devid); 303 + 304 + list_for_each_entry(p, &acpihid_map, list) { 305 + if ((devid == p->devid) && p->group) 306 + entry->group = p->group; 307 + } 308 + 309 + if (!entry->group) 310 + entry->group = generic_device_group(dev); 311 + 312 + return entry->group; 313 + } 314 + 343 315 static bool pci_iommuv2_capable(struct pci_dev *pdev) 344 316 { 345 317 static const int caps[] = { ··· 414 340 struct dma_ops_domain *dma_dom) 415 341 { 416 342 struct unity_map_entry *e; 417 - u16 devid; 343 + int devid; 418 344 419 345 devid = get_device_id(dev); 346 + if (devid < 0) 347 + return; 420 348 421 349 list_for_each_entry(e, &amd_iommu_unity_map, list) { 422 350 if (!(devid >= e->devid_start && devid <= e->devid_end)) ··· 433 357 */ 434 358 static bool check_device(struct device *dev) 435 359 { 436 - u16 devid; 360 + int devid; 437 361 438 362 if (!dev || !dev->dma_mask) 439 363 return false; 440 364 441 - /* No PCI device */ 442 - if (!dev_is_pci(dev)) 443 - return false; 444 - 445 365 devid = get_device_id(dev); 366 + if (devid < 0) 367 + return false; 446 368 447 369 /* Out of our scope? */ 448 370 if (devid > amd_iommu_last_bdf) ··· 475 401 476 402 static int iommu_init_device(struct device *dev) 477 403 { 478 - struct pci_dev *pdev = to_pci_dev(dev); 479 404 struct iommu_dev_data *dev_data; 405 + int devid; 480 406 481 407 if (dev->archdata.iommu) 482 408 return 0; 483 409 484 - dev_data = find_dev_data(get_device_id(dev)); 410 + devid = get_device_id(dev); 411 + if (devid < 0) 412 + return devid; 413 + 414 + dev_data = find_dev_data(devid); 485 415 if (!dev_data) 486 416 return -ENOMEM; 487 417 488 418 dev_data->alias = get_alias(dev); 489 419 490 - if (pci_iommuv2_capable(pdev)) { 420 + if (dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) { 491 421 struct amd_iommu *iommu; 492 422 493 - iommu = amd_iommu_rlookup_table[dev_data->devid]; 423 + iommu = amd_iommu_rlookup_table[dev_data->devid]; 494 424 dev_data->iommu_v2 = iommu->is_iommu_v2; 495 425 } 496 426 ··· 508 430 509 431 static void iommu_ignore_device(struct device *dev) 510 432 { 511 - u16 devid, alias; 433 + u16 alias; 434 + int devid; 512 435 513 436 devid = get_device_id(dev); 437 + if (devid < 0) 438 + return; 439 + 514 440 alias = get_alias(dev); 515 441 516 442 memset(&amd_iommu_dev_table[devid], 0, sizeof(struct dev_table_entry)); ··· 526 444 527 445 static void iommu_uninit_device(struct device *dev) 528 446 { 529 - struct iommu_dev_data *dev_data = search_dev_data(get_device_id(dev)); 447 + int devid; 448 + struct iommu_dev_data *dev_data; 530 449 450 + devid = get_device_id(dev); 451 + if (devid < 0) 452 + return; 453 + 454 + dev_data = search_dev_data(devid); 531 455 if (!dev_data) 532 456 return; 533 457 ··· 553 465 * device is re-plugged - not doing so would introduce a ton of races. 554 466 */ 555 467 } 556 - 557 - #ifdef CONFIG_AMD_IOMMU_STATS 558 - 559 - /* 560 - * Initialization code for statistics collection 561 - */ 562 - 563 - DECLARE_STATS_COUNTER(compl_wait); 564 - DECLARE_STATS_COUNTER(cnt_map_single); 565 - DECLARE_STATS_COUNTER(cnt_unmap_single); 566 - DECLARE_STATS_COUNTER(cnt_map_sg); 567 - DECLARE_STATS_COUNTER(cnt_unmap_sg); 568 - DECLARE_STATS_COUNTER(cnt_alloc_coherent); 569 - DECLARE_STATS_COUNTER(cnt_free_coherent); 570 - DECLARE_STATS_COUNTER(cross_page); 571 - DECLARE_STATS_COUNTER(domain_flush_single); 572 - DECLARE_STATS_COUNTER(domain_flush_all); 573 - DECLARE_STATS_COUNTER(alloced_io_mem); 574 - DECLARE_STATS_COUNTER(total_map_requests); 575 - DECLARE_STATS_COUNTER(complete_ppr); 576 - DECLARE_STATS_COUNTER(invalidate_iotlb); 577 - DECLARE_STATS_COUNTER(invalidate_iotlb_all); 578 - DECLARE_STATS_COUNTER(pri_requests); 579 - 580 - static struct dentry *stats_dir; 581 - static struct dentry *de_fflush; 582 - 583 - static void amd_iommu_stats_add(struct __iommu_counter *cnt) 584 - { 585 - if (stats_dir == NULL) 586 - return; 587 - 588 - cnt->dent = debugfs_create_u64(cnt->name, 0444, stats_dir, 589 - &cnt->value); 590 - } 591 - 592 - static void amd_iommu_stats_init(void) 593 - { 594 - stats_dir = debugfs_create_dir("amd-iommu", NULL); 595 - if (stats_dir == NULL) 596 - return; 597 - 598 - de_fflush = debugfs_create_bool("fullflush", 0444, stats_dir, 599 - &amd_iommu_unmap_flush); 600 - 601 - amd_iommu_stats_add(&compl_wait); 602 - amd_iommu_stats_add(&cnt_map_single); 603 - amd_iommu_stats_add(&cnt_unmap_single); 604 - amd_iommu_stats_add(&cnt_map_sg); 605 - amd_iommu_stats_add(&cnt_unmap_sg); 606 - amd_iommu_stats_add(&cnt_alloc_coherent); 607 - amd_iommu_stats_add(&cnt_free_coherent); 608 - amd_iommu_stats_add(&cross_page); 609 - amd_iommu_stats_add(&domain_flush_single); 610 - amd_iommu_stats_add(&domain_flush_all); 611 - amd_iommu_stats_add(&alloced_io_mem); 612 - amd_iommu_stats_add(&total_map_requests); 613 - amd_iommu_stats_add(&complete_ppr); 614 - amd_iommu_stats_add(&invalidate_iotlb); 615 - amd_iommu_stats_add(&invalidate_iotlb_all); 616 - amd_iommu_stats_add(&pri_requests); 617 - } 618 - 619 - #endif 620 468 621 469 /**************************************************************************** 622 470 * ··· 675 651 static void iommu_handle_ppr_entry(struct amd_iommu *iommu, u64 *raw) 676 652 { 677 653 struct amd_iommu_fault fault; 678 - 679 - INC_STATS_COUNTER(pri_requests); 680 654 681 655 if (PPR_REQ_TYPE(raw[0]) != PPR_REQ_FAULT) { 682 656 pr_err_ratelimited("AMD-Vi: Unknown PPR request received\n"); ··· 2305 2283 static int attach_device(struct device *dev, 2306 2284 struct protection_domain *domain) 2307 2285 { 2308 - struct pci_dev *pdev = to_pci_dev(dev); 2286 + struct pci_dev *pdev; 2309 2287 struct iommu_dev_data *dev_data; 2310 2288 unsigned long flags; 2311 2289 int ret; 2312 2290 2313 2291 dev_data = get_dev_data(dev); 2314 2292 2293 + if (!dev_is_pci(dev)) 2294 + goto skip_ats_check; 2295 + 2296 + pdev = to_pci_dev(dev); 2315 2297 if (domain->flags & PD_IOMMUV2_MASK) { 2316 2298 if (!dev_data->passthrough) 2317 2299 return -EINVAL; ··· 2334 2308 dev_data->ats.qdep = pci_ats_queue_depth(pdev); 2335 2309 } 2336 2310 2311 + skip_ats_check: 2337 2312 write_lock_irqsave(&amd_iommu_devtable_lock, flags); 2338 2313 ret = __attach_device(dev_data, domain); 2339 2314 write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); ··· 2391 2364 __detach_device(dev_data); 2392 2365 write_unlock_irqrestore(&amd_iommu_devtable_lock, flags); 2393 2366 2367 + if (!dev_is_pci(dev)) 2368 + return; 2369 + 2394 2370 if (domain->flags & PD_IOMMUV2_MASK && dev_data->iommu_v2) 2395 2371 pdev_iommuv2_disable(to_pci_dev(dev)); 2396 2372 else if (dev_data->ats.enabled) ··· 2407 2377 struct iommu_dev_data *dev_data; 2408 2378 struct iommu_domain *domain; 2409 2379 struct amd_iommu *iommu; 2410 - u16 devid; 2411 - int ret; 2380 + int ret, devid; 2412 2381 2413 2382 if (!check_device(dev) || get_dev_data(dev)) 2414 2383 return 0; 2415 2384 2416 2385 devid = get_device_id(dev); 2386 + if (devid < 0) 2387 + return devid; 2388 + 2417 2389 iommu = amd_iommu_rlookup_table[devid]; 2418 2390 2419 2391 ret = iommu_init_device(dev); ··· 2453 2421 static void amd_iommu_remove_device(struct device *dev) 2454 2422 { 2455 2423 struct amd_iommu *iommu; 2456 - u16 devid; 2424 + int devid; 2457 2425 2458 2426 if (!check_device(dev)) 2459 2427 return; 2460 2428 2461 2429 devid = get_device_id(dev); 2430 + if (devid < 0) 2431 + return; 2432 + 2462 2433 iommu = amd_iommu_rlookup_table[devid]; 2463 2434 2464 2435 iommu_uninit_device(dev); 2465 2436 iommu_completion_wait(iommu); 2437 + } 2438 + 2439 + static struct iommu_group *amd_iommu_device_group(struct device *dev) 2440 + { 2441 + if (dev_is_pci(dev)) 2442 + return pci_device_group(dev); 2443 + 2444 + return acpihid_device_group(dev); 2466 2445 } 2467 2446 2468 2447 /***************************************************************************** ··· 2640 2597 pages = iommu_num_pages(paddr, size, PAGE_SIZE); 2641 2598 paddr &= PAGE_MASK; 2642 2599 2643 - INC_STATS_COUNTER(total_map_requests); 2644 - 2645 - if (pages > 1) 2646 - INC_STATS_COUNTER(cross_page); 2647 - 2648 2600 if (align) 2649 2601 align_mask = (1UL << get_order(size)) - 1; 2650 2602 ··· 2659 2621 start += PAGE_SIZE; 2660 2622 } 2661 2623 address += offset; 2662 - 2663 - ADD_STATS_COUNTER(alloced_io_mem, size); 2664 2624 2665 2625 if (unlikely(amd_iommu_np_cache)) { 2666 2626 domain_flush_pages(&dma_dom->domain, address, size); ··· 2707 2671 start += PAGE_SIZE; 2708 2672 } 2709 2673 2710 - SUB_STATS_COUNTER(alloced_io_mem, size); 2711 - 2712 2674 dma_ops_free_addresses(dma_dom, dma_addr, pages); 2713 2675 } 2714 2676 ··· 2721 2687 phys_addr_t paddr = page_to_phys(page) + offset; 2722 2688 struct protection_domain *domain; 2723 2689 u64 dma_mask; 2724 - 2725 - INC_STATS_COUNTER(cnt_map_single); 2726 2690 2727 2691 domain = get_domain(dev); 2728 2692 if (PTR_ERR(domain) == -EINVAL) ··· 2741 2709 enum dma_data_direction dir, struct dma_attrs *attrs) 2742 2710 { 2743 2711 struct protection_domain *domain; 2744 - 2745 - INC_STATS_COUNTER(cnt_unmap_single); 2746 2712 2747 2713 domain = get_domain(dev); 2748 2714 if (IS_ERR(domain)) ··· 2763 2733 phys_addr_t paddr; 2764 2734 int mapped_elems = 0; 2765 2735 u64 dma_mask; 2766 - 2767 - INC_STATS_COUNTER(cnt_map_sg); 2768 2736 2769 2737 domain = get_domain(dev); 2770 2738 if (IS_ERR(domain)) ··· 2809 2781 struct scatterlist *s; 2810 2782 int i; 2811 2783 2812 - INC_STATS_COUNTER(cnt_unmap_sg); 2813 - 2814 2784 domain = get_domain(dev); 2815 2785 if (IS_ERR(domain)) 2816 2786 return; ··· 2830 2804 u64 dma_mask = dev->coherent_dma_mask; 2831 2805 struct protection_domain *domain; 2832 2806 struct page *page; 2833 - 2834 - INC_STATS_COUNTER(cnt_alloc_coherent); 2835 2807 2836 2808 domain = get_domain(dev); 2837 2809 if (PTR_ERR(domain) == -EINVAL) { ··· 2883 2859 { 2884 2860 struct protection_domain *domain; 2885 2861 struct page *page; 2886 - 2887 - INC_STATS_COUNTER(cnt_free_coherent); 2888 2862 2889 2863 page = virt_to_page(virt_addr); 2890 2864 size = PAGE_ALIGN(size); ··· 2948 2926 2949 2927 int __init amd_iommu_init_api(void) 2950 2928 { 2951 - return bus_set_iommu(&pci_bus_type, &amd_iommu_ops); 2929 + int err = 0; 2930 + 2931 + err = bus_set_iommu(&pci_bus_type, &amd_iommu_ops); 2932 + if (err) 2933 + return err; 2934 + #ifdef CONFIG_ARM_AMBA 2935 + err = bus_set_iommu(&amba_bustype, &amd_iommu_ops); 2936 + if (err) 2937 + return err; 2938 + #endif 2939 + return 0; 2952 2940 } 2953 2941 2954 2942 int __init amd_iommu_init_dma_ops(void) ··· 2974 2942 */ 2975 2943 if (!swiotlb) 2976 2944 dma_ops = &nommu_dma_ops; 2977 - 2978 - amd_iommu_stats_init(); 2979 2945 2980 2946 if (amd_iommu_unmap_flush) 2981 2947 pr_info("AMD-Vi: IO/TLB flush on unmap enabled\n"); ··· 3128 3098 { 3129 3099 struct iommu_dev_data *dev_data = dev->archdata.iommu; 3130 3100 struct amd_iommu *iommu; 3131 - u16 devid; 3101 + int devid; 3132 3102 3133 3103 if (!check_device(dev)) 3134 3104 return; 3135 3105 3136 3106 devid = get_device_id(dev); 3107 + if (devid < 0) 3108 + return; 3137 3109 3138 3110 if (dev_data->domain != NULL) 3139 3111 detach_device(dev); ··· 3253 3221 struct list_head *head) 3254 3222 { 3255 3223 struct unity_map_entry *entry; 3256 - u16 devid; 3224 + int devid; 3257 3225 3258 3226 devid = get_device_id(dev); 3227 + if (devid < 0) 3228 + return; 3259 3229 3260 3230 list_for_each_entry(entry, &amd_iommu_unity_map, list) { 3261 3231 struct iommu_dm_region *region; ··· 3304 3270 .iova_to_phys = amd_iommu_iova_to_phys, 3305 3271 .add_device = amd_iommu_add_device, 3306 3272 .remove_device = amd_iommu_remove_device, 3307 - .device_group = pci_device_group, 3273 + .device_group = amd_iommu_device_group, 3308 3274 .get_dm_regions = amd_iommu_get_dm_regions, 3309 3275 .put_dm_regions = amd_iommu_put_dm_regions, 3310 3276 .pgsize_bitmap = AMD_IOMMU_PGSIZES, ··· 3465 3431 static int __amd_iommu_flush_page(struct protection_domain *domain, int pasid, 3466 3432 u64 address) 3467 3433 { 3468 - INC_STATS_COUNTER(invalidate_iotlb); 3469 - 3470 3434 return __flush_pasid(domain, pasid, address, false); 3471 3435 } 3472 3436 ··· 3485 3453 3486 3454 static int __amd_iommu_flush_tlb(struct protection_domain *domain, int pasid) 3487 3455 { 3488 - INC_STATS_COUNTER(invalidate_iotlb_all); 3489 - 3490 3456 return __flush_pasid(domain, pasid, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, 3491 3457 true); 3492 3458 } ··· 3603 3573 struct iommu_dev_data *dev_data; 3604 3574 struct amd_iommu *iommu; 3605 3575 struct iommu_cmd cmd; 3606 - 3607 - INC_STATS_COUNTER(complete_ppr); 3608 3576 3609 3577 dev_data = get_dev_data(&pdev->dev); 3610 3578 iommu = amd_iommu_rlookup_table[dev_data->devid]; ··· 3953 3925 case X86_IRQ_ALLOC_TYPE_MSI: 3954 3926 case X86_IRQ_ALLOC_TYPE_MSIX: 3955 3927 devid = get_device_id(&info->msi_dev->dev); 3928 + if (devid < 0) 3929 + return NULL; 3930 + 3956 3931 iommu = amd_iommu_rlookup_table[devid]; 3957 3932 if (iommu) 3958 3933 return iommu->msi_domain;
+290 -39
drivers/iommu/amd_iommu_init.c
··· 44 44 */ 45 45 #define IVRS_HEADER_LENGTH 48 46 46 47 - #define ACPI_IVHD_TYPE 0x10 47 + #define ACPI_IVHD_TYPE_MAX_SUPPORTED 0x40 48 48 #define ACPI_IVMD_TYPE_ALL 0x20 49 49 #define ACPI_IVMD_TYPE 0x21 50 50 #define ACPI_IVMD_TYPE_RANGE 0x22 ··· 58 58 #define IVHD_DEV_EXT_SELECT 0x46 59 59 #define IVHD_DEV_EXT_SELECT_RANGE 0x47 60 60 #define IVHD_DEV_SPECIAL 0x48 61 + #define IVHD_DEV_ACPI_HID 0xf0 62 + 63 + #define UID_NOT_PRESENT 0 64 + #define UID_IS_INTEGER 1 65 + #define UID_IS_CHARACTER 2 61 66 62 67 #define IVHD_SPECIAL_IOAPIC 1 63 68 #define IVHD_SPECIAL_HPET 2 ··· 104 99 u64 mmio_phys; 105 100 u16 pci_seg; 106 101 u16 info; 107 - u32 efr; 102 + u32 efr_attr; 103 + 104 + /* Following only valid on IVHD type 11h and 40h */ 105 + u64 efr_reg; /* Exact copy of MMIO_EXT_FEATURES */ 106 + u64 res; 108 107 } __attribute__((packed)); 109 108 110 109 /* ··· 120 111 u16 devid; 121 112 u8 flags; 122 113 u32 ext; 114 + u32 hidh; 115 + u64 cid; 116 + u8 uidf; 117 + u8 uidl; 118 + u8 uid; 123 119 } __attribute__((packed)); 124 120 125 121 /* ··· 147 133 148 134 static bool amd_iommu_detected; 149 135 static bool __initdata amd_iommu_disabled; 136 + static int amd_iommu_target_ivhd_type; 150 137 151 138 u16 amd_iommu_last_bdf; /* largest PCI device id we have 152 139 to handle */ ··· 233 218 #define EARLY_MAP_SIZE 4 234 219 static struct devid_map __initdata early_ioapic_map[EARLY_MAP_SIZE]; 235 220 static struct devid_map __initdata early_hpet_map[EARLY_MAP_SIZE]; 221 + static struct acpihid_map_entry __initdata early_acpihid_map[EARLY_MAP_SIZE]; 222 + 236 223 static int __initdata early_ioapic_map_size; 237 224 static int __initdata early_hpet_map_size; 225 + static int __initdata early_acpihid_map_size; 226 + 238 227 static bool __initdata cmdline_maps; 239 228 240 229 static enum iommu_init_state init_state = IOMMU_START_STATE; ··· 413 394 release_mem_region(iommu->mmio_phys, iommu->mmio_phys_end); 414 395 } 415 396 397 + static inline u32 get_ivhd_header_size(struct ivhd_header *h) 398 + { 399 + u32 size = 0; 400 + 401 + switch (h->type) { 402 + case 0x10: 403 + size = 24; 404 + break; 405 + case 0x11: 406 + case 0x40: 407 + size = 40; 408 + break; 409 + } 410 + return size; 411 + } 412 + 416 413 /**************************************************************************** 417 414 * 418 415 * The functions below belong to the first pass of AMD IOMMU ACPI table ··· 443 408 */ 444 409 static inline int ivhd_entry_length(u8 *ivhd) 445 410 { 446 - return 0x04 << (*ivhd >> 6); 411 + u32 type = ((struct ivhd_entry *)ivhd)->type; 412 + 413 + if (type < 0x80) { 414 + return 0x04 << (*ivhd >> 6); 415 + } else if (type == IVHD_DEV_ACPI_HID) { 416 + /* For ACPI_HID, offset 21 is uid len */ 417 + return *((u8 *)ivhd + 21) + 22; 418 + } 419 + return 0; 447 420 } 448 421 449 422 /* ··· 463 420 u8 *p = (void *)h, *end = (void *)h; 464 421 struct ivhd_entry *dev; 465 422 466 - p += sizeof(*h); 423 + u32 ivhd_size = get_ivhd_header_size(h); 424 + 425 + if (!ivhd_size) { 426 + pr_err("AMD-Vi: Unsupported IVHD type %#x\n", h->type); 427 + return -EINVAL; 428 + } 429 + 430 + p += ivhd_size; 467 431 end += h->length; 468 432 469 433 while (p < end) { ··· 498 448 return 0; 499 449 } 500 450 451 + static int __init check_ivrs_checksum(struct acpi_table_header *table) 452 + { 453 + int i; 454 + u8 checksum = 0, *p = (u8 *)table; 455 + 456 + for (i = 0; i < table->length; ++i) 457 + checksum += p[i]; 458 + if (checksum != 0) { 459 + /* ACPI table corrupt */ 460 + pr_err(FW_BUG "AMD-Vi: IVRS invalid checksum\n"); 461 + return -ENODEV; 462 + } 463 + 464 + return 0; 465 + } 466 + 501 467 /* 502 468 * Iterate over all IVHD entries in the ACPI table and find the highest device 503 469 * id which we need to handle. This is the first of three functions which parse ··· 521 455 */ 522 456 static int __init find_last_devid_acpi(struct acpi_table_header *table) 523 457 { 524 - int i; 525 - u8 checksum = 0, *p = (u8 *)table, *end = (u8 *)table; 458 + u8 *p = (u8 *)table, *end = (u8 *)table; 526 459 struct ivhd_header *h; 527 - 528 - /* 529 - * Validate checksum here so we don't need to do it when 530 - * we actually parse the table 531 - */ 532 - for (i = 0; i < table->length; ++i) 533 - checksum += p[i]; 534 - if (checksum != 0) 535 - /* ACPI table corrupt */ 536 - return -ENODEV; 537 460 538 461 p += IVRS_HEADER_LENGTH; 539 462 540 463 end += table->length; 541 464 while (p < end) { 542 465 h = (struct ivhd_header *)p; 543 - switch (h->type) { 544 - case ACPI_IVHD_TYPE: 545 - find_last_devid_from_ivhd(h); 546 - break; 547 - default: 548 - break; 466 + if (h->type == amd_iommu_target_ivhd_type) { 467 + int ret = find_last_devid_from_ivhd(h); 468 + 469 + if (ret) 470 + return ret; 549 471 } 550 472 p += h->length; 551 473 } ··· 778 724 return 0; 779 725 } 780 726 727 + static int __init add_acpi_hid_device(u8 *hid, u8 *uid, u16 *devid, 728 + bool cmd_line) 729 + { 730 + struct acpihid_map_entry *entry; 731 + struct list_head *list = &acpihid_map; 732 + 733 + list_for_each_entry(entry, list, list) { 734 + if (strcmp(entry->hid, hid) || 735 + (*uid && *entry->uid && strcmp(entry->uid, uid)) || 736 + !entry->cmd_line) 737 + continue; 738 + 739 + pr_info("AMD-Vi: Command-line override for hid:%s uid:%s\n", 740 + hid, uid); 741 + *devid = entry->devid; 742 + return 0; 743 + } 744 + 745 + entry = kzalloc(sizeof(*entry), GFP_KERNEL); 746 + if (!entry) 747 + return -ENOMEM; 748 + 749 + memcpy(entry->uid, uid, strlen(uid)); 750 + memcpy(entry->hid, hid, strlen(hid)); 751 + entry->devid = *devid; 752 + entry->cmd_line = cmd_line; 753 + entry->root_devid = (entry->devid & (~0x7)); 754 + 755 + pr_info("AMD-Vi:%s, add hid:%s, uid:%s, rdevid:%d\n", 756 + entry->cmd_line ? "cmd" : "ivrs", 757 + entry->hid, entry->uid, entry->root_devid); 758 + 759 + list_add_tail(&entry->list, list); 760 + return 0; 761 + } 762 + 781 763 static int __init add_early_maps(void) 782 764 { 783 765 int i, ret; ··· 832 742 early_hpet_map[i].id, 833 743 &early_hpet_map[i].devid, 834 744 early_hpet_map[i].cmd_line); 745 + if (ret) 746 + return ret; 747 + } 748 + 749 + for (i = 0; i < early_acpihid_map_size; ++i) { 750 + ret = add_acpi_hid_device(early_acpihid_map[i].hid, 751 + early_acpihid_map[i].uid, 752 + &early_acpihid_map[i].devid, 753 + early_acpihid_map[i].cmd_line); 835 754 if (ret) 836 755 return ret; 837 756 } ··· 884 785 u32 dev_i, ext_flags = 0; 885 786 bool alias = false; 886 787 struct ivhd_entry *e; 788 + u32 ivhd_size; 887 789 int ret; 888 790 889 791 ··· 900 800 /* 901 801 * Done. Now parse the device entries 902 802 */ 903 - p += sizeof(struct ivhd_header); 803 + ivhd_size = get_ivhd_header_size(h); 804 + if (!ivhd_size) { 805 + pr_err("AMD-Vi: Unsupported IVHD type %#x\n", h->type); 806 + return -EINVAL; 807 + } 808 + 809 + p += ivhd_size; 810 + 904 811 end += h->length; 905 812 906 813 ··· 1065 958 1066 959 break; 1067 960 } 961 + case IVHD_DEV_ACPI_HID: { 962 + u16 devid; 963 + u8 hid[ACPIHID_HID_LEN] = {0}; 964 + u8 uid[ACPIHID_UID_LEN] = {0}; 965 + int ret; 966 + 967 + if (h->type != 0x40) { 968 + pr_err(FW_BUG "Invalid IVHD device type %#x\n", 969 + e->type); 970 + break; 971 + } 972 + 973 + memcpy(hid, (u8 *)(&e->ext), ACPIHID_HID_LEN - 1); 974 + hid[ACPIHID_HID_LEN - 1] = '\0'; 975 + 976 + if (!(*hid)) { 977 + pr_err(FW_BUG "Invalid HID.\n"); 978 + break; 979 + } 980 + 981 + switch (e->uidf) { 982 + case UID_NOT_PRESENT: 983 + 984 + if (e->uidl != 0) 985 + pr_warn(FW_BUG "Invalid UID length.\n"); 986 + 987 + break; 988 + case UID_IS_INTEGER: 989 + 990 + sprintf(uid, "%d", e->uid); 991 + 992 + break; 993 + case UID_IS_CHARACTER: 994 + 995 + memcpy(uid, (u8 *)(&e->uid), ACPIHID_UID_LEN - 1); 996 + uid[ACPIHID_UID_LEN - 1] = '\0'; 997 + 998 + break; 999 + default: 1000 + break; 1001 + } 1002 + 1003 + DUMP_printk(" DEV_ACPI_HID(%s[%s])\t\tdevid: %02x:%02x.%x\n", 1004 + hid, uid, 1005 + PCI_BUS_NUM(devid), 1006 + PCI_SLOT(devid), 1007 + PCI_FUNC(devid)); 1008 + 1009 + devid = e->devid; 1010 + flags = e->flags; 1011 + 1012 + ret = add_acpi_hid_device(hid, uid, &devid, false); 1013 + if (ret) 1014 + return ret; 1015 + 1016 + /* 1017 + * add_special_device might update the devid in case a 1018 + * command-line override is present. So call 1019 + * set_dev_entry_from_acpi after add_special_device. 1020 + */ 1021 + set_dev_entry_from_acpi(iommu, devid, e->flags, 0); 1022 + 1023 + break; 1024 + } 1068 1025 default: 1069 1026 break; 1070 1027 } ··· 1249 1078 iommu->pci_seg = h->pci_seg; 1250 1079 iommu->mmio_phys = h->mmio_phys; 1251 1080 1252 - /* Check if IVHD EFR contains proper max banks/counters */ 1253 - if ((h->efr != 0) && 1254 - ((h->efr & (0xF << 13)) != 0) && 1255 - ((h->efr & (0x3F << 17)) != 0)) { 1256 - iommu->mmio_phys_end = MMIO_REG_END_OFFSET; 1257 - } else { 1258 - iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET; 1081 + switch (h->type) { 1082 + case 0x10: 1083 + /* Check if IVHD EFR contains proper max banks/counters */ 1084 + if ((h->efr_attr != 0) && 1085 + ((h->efr_attr & (0xF << 13)) != 0) && 1086 + ((h->efr_attr & (0x3F << 17)) != 0)) 1087 + iommu->mmio_phys_end = MMIO_REG_END_OFFSET; 1088 + else 1089 + iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET; 1090 + break; 1091 + case 0x11: 1092 + case 0x40: 1093 + if (h->efr_reg & (1 << 9)) 1094 + iommu->mmio_phys_end = MMIO_REG_END_OFFSET; 1095 + else 1096 + iommu->mmio_phys_end = MMIO_CNTR_CONF_OFFSET; 1097 + break; 1098 + default: 1099 + return -EINVAL; 1259 1100 } 1260 1101 1261 1102 iommu->mmio_base = iommu_map_mmio_space(iommu->mmio_phys, ··· 1300 1117 return 0; 1301 1118 } 1302 1119 1120 + /** 1121 + * get_highest_supported_ivhd_type - Look up the appropriate IVHD type 1122 + * @ivrs Pointer to the IVRS header 1123 + * 1124 + * This function search through all IVDB of the maximum supported IVHD 1125 + */ 1126 + static u8 get_highest_supported_ivhd_type(struct acpi_table_header *ivrs) 1127 + { 1128 + u8 *base = (u8 *)ivrs; 1129 + struct ivhd_header *ivhd = (struct ivhd_header *) 1130 + (base + IVRS_HEADER_LENGTH); 1131 + u8 last_type = ivhd->type; 1132 + u16 devid = ivhd->devid; 1133 + 1134 + while (((u8 *)ivhd - base < ivrs->length) && 1135 + (ivhd->type <= ACPI_IVHD_TYPE_MAX_SUPPORTED)) { 1136 + u8 *p = (u8 *) ivhd; 1137 + 1138 + if (ivhd->devid == devid) 1139 + last_type = ivhd->type; 1140 + ivhd = (struct ivhd_header *)(p + ivhd->length); 1141 + } 1142 + 1143 + return last_type; 1144 + } 1145 + 1303 1146 /* 1304 1147 * Iterates over all IOMMU entries in the ACPI table, allocates the 1305 1148 * IOMMU structure and initializes it with init_iommu_one() ··· 1342 1133 1343 1134 while (p < end) { 1344 1135 h = (struct ivhd_header *)p; 1345 - switch (*p) { 1346 - case ACPI_IVHD_TYPE: 1136 + if (*p == amd_iommu_target_ivhd_type) { 1347 1137 1348 1138 DUMP_printk("device: %02x:%02x.%01x cap: %04x " 1349 1139 "seg: %d flags: %01x info %04x\n", ··· 1359 1151 ret = init_iommu_one(iommu, h); 1360 1152 if (ret) 1361 1153 return ret; 1362 - break; 1363 - default: 1364 - break; 1365 1154 } 1366 1155 p += h->length; 1367 1156 ··· 2023 1818 * remapping setup code. 2024 1819 * 2025 1820 * This function basically parses the ACPI table for AMD IOMMU (IVRS) 2026 - * three times: 1821 + * four times: 2027 1822 * 2028 - * 1 pass) Find the highest PCI device id the driver has to handle. 1823 + * 1 pass) Discover the most comprehensive IVHD type to use. 1824 + * 1825 + * 2 pass) Find the highest PCI device id the driver has to handle. 2029 1826 * Upon this information the size of the data structures is 2030 1827 * determined that needs to be allocated. 2031 1828 * 2032 - * 2 pass) Initialize the data structures just allocated with the 1829 + * 3 pass) Initialize the data structures just allocated with the 2033 1830 * information in the ACPI table about available AMD IOMMUs 2034 1831 * in the system. It also maps the PCI devices in the 2035 1832 * system to specific IOMMUs 2036 1833 * 2037 - * 3 pass) After the basic data structures are allocated and 1834 + * 4 pass) After the basic data structures are allocated and 2038 1835 * initialized we update them with information about memory 2039 1836 * remapping requirements parsed out of the ACPI table in 2040 1837 * this last pass. ··· 2062 1855 pr_err("AMD-Vi: IVRS table error: %s\n", err); 2063 1856 return -EINVAL; 2064 1857 } 1858 + 1859 + /* 1860 + * Validate checksum here so we don't need to do it when 1861 + * we actually parse the table 1862 + */ 1863 + ret = check_ivrs_checksum(ivrs_base); 1864 + if (ret) 1865 + return ret; 1866 + 1867 + amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type(ivrs_base); 1868 + DUMP_printk("Using IVHD type %#x\n", amd_iommu_target_ivhd_type); 2065 1869 2066 1870 /* 2067 1871 * First parse ACPI tables to find the largest Bus/Dev/Func ··· 2477 2259 return 1; 2478 2260 } 2479 2261 2262 + static int __init parse_ivrs_acpihid(char *str) 2263 + { 2264 + u32 bus, dev, fn; 2265 + char *hid, *uid, *p; 2266 + char acpiid[ACPIHID_UID_LEN + ACPIHID_HID_LEN] = {0}; 2267 + int ret, i; 2268 + 2269 + ret = sscanf(str, "[%x:%x.%x]=%s", &bus, &dev, &fn, acpiid); 2270 + if (ret != 4) { 2271 + pr_err("AMD-Vi: Invalid command line: ivrs_acpihid(%s)\n", str); 2272 + return 1; 2273 + } 2274 + 2275 + p = acpiid; 2276 + hid = strsep(&p, ":"); 2277 + uid = p; 2278 + 2279 + if (!hid || !(*hid) || !uid) { 2280 + pr_err("AMD-Vi: Invalid command line: hid or uid\n"); 2281 + return 1; 2282 + } 2283 + 2284 + i = early_acpihid_map_size++; 2285 + memcpy(early_acpihid_map[i].hid, hid, strlen(hid)); 2286 + memcpy(early_acpihid_map[i].uid, uid, strlen(uid)); 2287 + early_acpihid_map[i].devid = 2288 + ((bus & 0xff) << 8) | ((dev & 0x1f) << 3) | (fn & 0x7); 2289 + early_acpihid_map[i].cmd_line = true; 2290 + 2291 + return 1; 2292 + } 2293 + 2480 2294 __setup("amd_iommu_dump", parse_amd_iommu_dump); 2481 2295 __setup("amd_iommu=", parse_amd_iommu_options); 2482 2296 __setup("ivrs_ioapic", parse_ivrs_ioapic); 2483 2297 __setup("ivrs_hpet", parse_ivrs_hpet); 2298 + __setup("ivrs_acpihid", parse_ivrs_acpihid); 2484 2299 2485 2300 IOMMU_INIT_FINISH(amd_iommu_detect, 2486 2301 gart_iommu_hole_init,
+14 -26
drivers/iommu/amd_iommu_types.h
··· 527 527 #endif 528 528 }; 529 529 530 + #define ACPIHID_UID_LEN 256 531 + #define ACPIHID_HID_LEN 9 532 + 533 + struct acpihid_map_entry { 534 + struct list_head list; 535 + u8 uid[ACPIHID_UID_LEN]; 536 + u8 hid[ACPIHID_HID_LEN]; 537 + u16 devid; 538 + u16 root_devid; 539 + bool cmd_line; 540 + struct iommu_group *group; 541 + }; 542 + 530 543 struct devid_map { 531 544 struct list_head list; 532 545 u8 id; ··· 550 537 /* Map HPET and IOAPIC ids to the devid used by the IOMMU */ 551 538 extern struct list_head ioapic_map; 552 539 extern struct list_head hpet_map; 540 + extern struct list_head acpihid_map; 553 541 554 542 /* 555 543 * List with all IOMMUs in the system. This list is not locked because it is ··· 681 667 682 668 return -EINVAL; 683 669 } 684 - 685 - #ifdef CONFIG_AMD_IOMMU_STATS 686 - 687 - struct __iommu_counter { 688 - char *name; 689 - struct dentry *dent; 690 - u64 value; 691 - }; 692 - 693 - #define DECLARE_STATS_COUNTER(nm) \ 694 - static struct __iommu_counter nm = { \ 695 - .name = #nm, \ 696 - } 697 - 698 - #define INC_STATS_COUNTER(name) name.value += 1 699 - #define ADD_STATS_COUNTER(name, x) name.value += (x) 700 - #define SUB_STATS_COUNTER(name, x) name.value -= (x) 701 - 702 - #else /* CONFIG_AMD_IOMMU_STATS */ 703 - 704 - #define DECLARE_STATS_COUNTER(name) 705 - #define INC_STATS_COUNTER(name) 706 - #define ADD_STATS_COUNTER(name, x) 707 - #define SUB_STATS_COUNTER(name, x) 708 - 709 - #endif /* CONFIG_AMD_IOMMU_STATS */ 710 670 711 671 #endif /* _ASM_X86_AMD_IOMMU_TYPES_H */
+10 -9
drivers/iommu/arm-smmu-v3.c
··· 590 590 591 591 unsigned long ias; /* IPA */ 592 592 unsigned long oas; /* PA */ 593 + unsigned long pgsize_bitmap; 593 594 594 595 #define ARM_SMMU_MAX_ASIDS (1 << 16) 595 596 unsigned int asid_bits; ··· 1517 1516 return 0; 1518 1517 } 1519 1518 1520 - static struct iommu_ops arm_smmu_ops; 1521 - 1522 1519 static int arm_smmu_domain_finalise(struct iommu_domain *domain) 1523 1520 { 1524 1521 int ret; ··· 1554 1555 } 1555 1556 1556 1557 pgtbl_cfg = (struct io_pgtable_cfg) { 1557 - .pgsize_bitmap = arm_smmu_ops.pgsize_bitmap, 1558 + .pgsize_bitmap = smmu->pgsize_bitmap, 1558 1559 .ias = ias, 1559 1560 .oas = oas, 1560 1561 .tlb = &arm_smmu_gather_ops, ··· 1565 1566 if (!pgtbl_ops) 1566 1567 return -ENOMEM; 1567 1568 1568 - arm_smmu_ops.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; 1569 + domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; 1569 1570 smmu_domain->pgtbl_ops = pgtbl_ops; 1570 1571 1571 1572 ret = finalise_stage_fn(smmu_domain, &pgtbl_cfg); ··· 2409 2410 { 2410 2411 u32 reg; 2411 2412 bool coherent; 2412 - unsigned long pgsize_bitmap = 0; 2413 2413 2414 2414 /* IDR0 */ 2415 2415 reg = readl_relaxed(smmu->base + ARM_SMMU_IDR0); ··· 2539 2541 2540 2542 /* Page sizes */ 2541 2543 if (reg & IDR5_GRAN64K) 2542 - pgsize_bitmap |= SZ_64K | SZ_512M; 2544 + smmu->pgsize_bitmap |= SZ_64K | SZ_512M; 2543 2545 if (reg & IDR5_GRAN16K) 2544 - pgsize_bitmap |= SZ_16K | SZ_32M; 2546 + smmu->pgsize_bitmap |= SZ_16K | SZ_32M; 2545 2547 if (reg & IDR5_GRAN4K) 2546 - pgsize_bitmap |= SZ_4K | SZ_2M | SZ_1G; 2548 + smmu->pgsize_bitmap |= SZ_4K | SZ_2M | SZ_1G; 2547 2549 2548 - arm_smmu_ops.pgsize_bitmap &= pgsize_bitmap; 2550 + if (arm_smmu_ops.pgsize_bitmap == -1UL) 2551 + arm_smmu_ops.pgsize_bitmap = smmu->pgsize_bitmap; 2552 + else 2553 + arm_smmu_ops.pgsize_bitmap |= smmu->pgsize_bitmap; 2549 2554 2550 2555 /* Output address size */ 2551 2556 switch (reg & IDR5_OAS_MASK << IDR5_OAS_SHIFT) {
+220 -88
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; ··· 351 322 unsigned long va_size; 352 323 unsigned long ipa_size; 353 324 unsigned long pa_size; 325 + unsigned long pgsize_bitmap; 354 326 355 327 u32 num_global_irqs; 356 328 u32 num_context_irqs; ··· 359 329 360 330 struct list_head list; 361 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, 362 341 }; 363 342 364 343 struct arm_smmu_cfg { 365 344 u8 cbndx; 366 345 u8 irptndx; 367 346 u32 cbar; 347 + enum arm_smmu_context_fmt fmt; 368 348 }; 369 349 #define INVALID_IRPTNDX 0xff 370 350 371 - #define ARM_SMMU_CB_ASID(cfg) ((cfg)->cbndx) 372 - #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) 373 353 374 354 enum arm_smmu_domain_stage { 375 355 ARM_SMMU_DOMAIN_S1 = 0, ··· 397 357 struct iommu_domain domain; 398 358 }; 399 359 400 - static struct iommu_ops arm_smmu_ops; 401 - 402 360 static DEFINE_SPINLOCK(arm_smmu_devices_lock); 403 361 static LIST_HEAD(arm_smmu_devices); 404 362 ··· 404 366 u32 opt; 405 367 const char *prop; 406 368 }; 369 + 370 + static atomic_t cavium_smmu_context_count = ATOMIC_INIT(0); 407 371 408 372 static struct arm_smmu_option_prop arm_smmu_options[] = { 409 373 { ARM_SMMU_OPT_SECURE_CFG_ACCESS, "calxeda,smmu-secure-config-access" }, ··· 618 578 619 579 if (stage1) { 620 580 base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 621 - writel_relaxed(ARM_SMMU_CB_ASID(cfg), 581 + writel_relaxed(ARM_SMMU_CB_ASID(smmu, cfg), 622 582 base + ARM_SMMU_CB_S1_TLBIASID); 623 583 } else { 624 584 base = ARM_SMMU_GR0(smmu); 625 - writel_relaxed(ARM_SMMU_CB_VMID(cfg), 585 + writel_relaxed(ARM_SMMU_CB_VMID(smmu, cfg), 626 586 base + ARM_SMMU_GR0_TLBIVMID); 627 587 } 628 588 ··· 642 602 reg = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 643 603 reg += leaf ? ARM_SMMU_CB_S1_TLBIVAL : ARM_SMMU_CB_S1_TLBIVA; 644 604 645 - if (!IS_ENABLED(CONFIG_64BIT) || smmu->version == ARM_SMMU_V1) { 605 + if (cfg->fmt != ARM_SMMU_CTX_FMT_AARCH64) { 646 606 iova &= ~12UL; 647 - iova |= ARM_SMMU_CB_ASID(cfg); 607 + iova |= ARM_SMMU_CB_ASID(smmu, cfg); 648 608 do { 649 609 writel_relaxed(iova, reg); 650 610 iova += granule; 651 611 } while (size -= granule); 652 - #ifdef CONFIG_64BIT 653 612 } else { 654 613 iova >>= 12; 655 - iova |= (u64)ARM_SMMU_CB_ASID(cfg) << 48; 614 + iova |= (u64)ARM_SMMU_CB_ASID(smmu, cfg) << 48; 656 615 do { 657 616 writeq_relaxed(iova, reg); 658 617 iova += granule >> 12; 659 618 } while (size -= granule); 660 - #endif 661 619 } 662 - #ifdef CONFIG_64BIT 663 620 } else if (smmu->version == ARM_SMMU_V2) { 664 621 reg = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 665 622 reg += leaf ? ARM_SMMU_CB_S2_TLBIIPAS2L : 666 623 ARM_SMMU_CB_S2_TLBIIPAS2; 667 624 iova >>= 12; 668 625 do { 669 - writeq_relaxed(iova, reg); 626 + smmu_write_atomic_lq(iova, reg); 670 627 iova += granule >> 12; 671 628 } while (size -= granule); 672 - #endif 673 629 } else { 674 630 reg = ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_TLBIVMID; 675 - writel_relaxed(ARM_SMMU_CB_VMID(cfg), reg); 631 + writel_relaxed(ARM_SMMU_CB_VMID(smmu, cfg), reg); 676 632 } 677 633 } 678 634 ··· 681 645 static irqreturn_t arm_smmu_context_fault(int irq, void *dev) 682 646 { 683 647 int flags, ret; 684 - u32 fsr, far, fsynr, resume; 648 + u32 fsr, fsynr, resume; 685 649 unsigned long iova; 686 650 struct iommu_domain *domain = dev; 687 651 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); ··· 703 667 fsynr = readl_relaxed(cb_base + ARM_SMMU_CB_FSYNR0); 704 668 flags = fsynr & FSYNR0_WNR ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ; 705 669 706 - far = readl_relaxed(cb_base + ARM_SMMU_CB_FAR_LO); 707 - iova = far; 708 - #ifdef CONFIG_64BIT 709 - far = readl_relaxed(cb_base + ARM_SMMU_CB_FAR_HI); 710 - iova |= ((unsigned long)far << 32); 711 - #endif 712 - 670 + iova = readq_relaxed(cb_base + ARM_SMMU_CB_FAR); 713 671 if (!report_iommu_fault(domain, smmu->dev, iova, flags)) { 714 672 ret = IRQ_HANDLED; 715 673 resume = RESUME_RETRY; ··· 764 734 cb_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); 765 735 766 736 if (smmu->version > ARM_SMMU_V1) { 767 - /* 768 - * CBA2R. 769 - * *Must* be initialised before CBAR thanks to VMID16 770 - * architectural oversight affected some implementations. 771 - */ 772 - #ifdef CONFIG_64BIT 773 - reg = CBA2R_RW64_64BIT; 774 - #else 775 - reg = CBA2R_RW64_32BIT; 776 - #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 + 777 745 writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBA2R(cfg->cbndx)); 778 746 } 779 747 780 748 /* CBAR */ 781 749 reg = cfg->cbar; 782 - if (smmu->version == ARM_SMMU_V1) 750 + if (smmu->version < ARM_SMMU_V2) 783 751 reg |= cfg->irptndx << CBAR_IRPTNDX_SHIFT; 784 752 785 753 /* ··· 787 759 if (stage1) { 788 760 reg |= (CBAR_S1_BPSHCFG_NSH << CBAR_S1_BPSHCFG_SHIFT) | 789 761 (CBAR_S1_MEMATTR_WB << CBAR_S1_MEMATTR_SHIFT); 790 - } else { 791 - 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; 792 765 } 793 766 writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBAR(cfg->cbndx)); 794 767 ··· 797 768 if (stage1) { 798 769 reg64 = pgtbl_cfg->arm_lpae_s1_cfg.ttbr[0]; 799 770 800 - reg64 |= ((u64)ARM_SMMU_CB_ASID(cfg)) << TTBRn_ASID_SHIFT; 801 - 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); 802 773 803 774 reg64 = pgtbl_cfg->arm_lpae_s1_cfg.ttbr[1]; 804 - reg64 |= ((u64)ARM_SMMU_CB_ASID(cfg)) << TTBRn_ASID_SHIFT; 805 - 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); 806 777 } else { 807 778 reg64 = pgtbl_cfg->arm_lpae_s2_cfg.vttbr; 808 - smmu_writeq(reg64, cb_base + ARM_SMMU_CB_TTBR0); 779 + writeq_relaxed(reg64, cb_base + ARM_SMMU_CB_TTBR0); 809 780 } 810 781 811 782 /* TTBCR */ ··· 884 855 if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S2)) 885 856 smmu_domain->stage = ARM_SMMU_DOMAIN_S1; 886 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 + 887 879 switch (smmu_domain->stage) { 888 880 case ARM_SMMU_DOMAIN_S1: 889 881 cfg->cbar = CBAR_TYPE_S1_TRANS_S2_BYPASS; 890 882 start = smmu->num_s2_context_banks; 891 883 ias = smmu->va_size; 892 884 oas = smmu->ipa_size; 893 - if (IS_ENABLED(CONFIG_64BIT)) 885 + if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64) { 894 886 fmt = ARM_64_LPAE_S1; 895 - else 887 + } else { 896 888 fmt = ARM_32_LPAE_S1; 889 + ias = min(ias, 32UL); 890 + oas = min(oas, 40UL); 891 + } 897 892 break; 898 893 case ARM_SMMU_DOMAIN_NESTED: 899 894 /* ··· 929 876 start = 0; 930 877 ias = smmu->ipa_size; 931 878 oas = smmu->pa_size; 932 - if (IS_ENABLED(CONFIG_64BIT)) 879 + if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64) { 933 880 fmt = ARM_64_LPAE_S2; 934 - else 881 + } else { 935 882 fmt = ARM_32_LPAE_S2; 883 + ias = min(ias, 40UL); 884 + oas = min(oas, 40UL); 885 + } 936 886 break; 937 887 default: 938 888 ret = -EINVAL; ··· 948 892 goto out_unlock; 949 893 950 894 cfg->cbndx = ret; 951 - if (smmu->version == ARM_SMMU_V1) { 895 + if (smmu->version < ARM_SMMU_V2) { 952 896 cfg->irptndx = atomic_inc_return(&smmu->irptndx); 953 897 cfg->irptndx %= smmu->num_context_irqs; 954 898 } else { ··· 956 900 } 957 901 958 902 pgtbl_cfg = (struct io_pgtable_cfg) { 959 - .pgsize_bitmap = arm_smmu_ops.pgsize_bitmap, 903 + .pgsize_bitmap = smmu->pgsize_bitmap, 960 904 .ias = ias, 961 905 .oas = oas, 962 906 .tlb = &arm_smmu_gather_ops, ··· 970 914 goto out_clear_smmu; 971 915 } 972 916 973 - /* Update our support page sizes to reflect the page table format */ 974 - arm_smmu_ops.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; 917 + /* Update the domain's page sizes to reflect the page table format */ 918 + domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap; 975 919 976 920 /* Initialise the context bank with our page table cfg */ 977 921 arm_smmu_init_context_bank(smmu_domain, &pgtbl_cfg); ··· 1308 1252 /* ATS1 registers can only be written atomically */ 1309 1253 va = iova & ~0xfffUL; 1310 1254 if (smmu->version == ARM_SMMU_V2) 1311 - smmu_writeq(va, cb_base + ARM_SMMU_CB_ATS1PR); 1312 - else 1255 + smmu_write_atomic_lq(va, cb_base + ARM_SMMU_CB_ATS1PR); 1256 + else /* Register is only 32-bit in v1 */ 1313 1257 writel_relaxed(va, cb_base + ARM_SMMU_CB_ATS1PR); 1314 1258 1315 1259 if (readl_poll_timeout_atomic(cb_base + ARM_SMMU_CB_ATSR, tmp, ··· 1320 1264 return ops->iova_to_phys(ops, iova); 1321 1265 } 1322 1266 1323 - phys = readl_relaxed(cb_base + ARM_SMMU_CB_PAR_LO); 1324 - phys |= ((u64)readl_relaxed(cb_base + ARM_SMMU_CB_PAR_HI)) << 32; 1325 - 1267 + phys = readq_relaxed(cb_base + ARM_SMMU_CB_PAR); 1326 1268 if (phys & CB_PAR_F) { 1327 1269 dev_err(dev, "translation fault!\n"); 1328 1270 dev_err(dev, "PAR = 0x%llx\n", phys); ··· 1546 1492 void __iomem *gr0_base = ARM_SMMU_GR0(smmu); 1547 1493 void __iomem *cb_base; 1548 1494 int i = 0; 1549 - u32 reg; 1495 + u32 reg, major; 1550 1496 1551 1497 /* clear global FSR */ 1552 1498 reg = readl_relaxed(ARM_SMMU_GR0_NS(smmu) + ARM_SMMU_GR0_sGFSR); ··· 1559 1505 writel_relaxed(reg, gr0_base + ARM_SMMU_GR0_S2CR(i)); 1560 1506 } 1561 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 + 1562 1521 /* Make sure all context banks are disabled and clear CB_FSR */ 1563 1522 for (i = 0; i < smmu->num_context_banks; ++i) { 1564 1523 cb_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, i); 1565 1524 writel_relaxed(0, cb_base + ARM_SMMU_CB_SCTLR); 1566 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 + } 1567 1535 } 1568 1536 1569 1537 /* Invalidate the TLB, just in case */ ··· 1612 1536 1613 1537 /* Don't upgrade barriers */ 1614 1538 reg &= ~(sCR0_BSU_MASK << sCR0_BSU_SHIFT); 1539 + 1540 + if (smmu->features & ARM_SMMU_FEAT_VMID16) 1541 + reg |= sCR0_VMID16EN; 1615 1542 1616 1543 /* Push the button */ 1617 1544 __arm_smmu_tlb_sync(smmu); ··· 1648 1569 bool cttw_dt, cttw_reg; 1649 1570 1650 1571 dev_notice(smmu->dev, "probing hardware configuration...\n"); 1651 - 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); 1652 1574 1653 1575 /* ID0 */ 1654 1576 id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID0); ··· 1681 1601 return -ENODEV; 1682 1602 } 1683 1603 1684 - if ((id & ID0_S1TS) && ((smmu->version == 1) || !(id & ID0_ATOSNS))) { 1604 + if ((id & ID0_S1TS) && 1605 + ((smmu->version < ARM_SMMU_V2) || !(id & ID0_ATOSNS))) { 1685 1606 smmu->features |= ARM_SMMU_FEAT_TRANS_OPS; 1686 1607 dev_notice(smmu->dev, "\taddress translation ops\n"); 1687 1608 } ··· 1738 1657 ID0_NUMSIDB_MASK; 1739 1658 } 1740 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 + 1741 1666 /* ID1 */ 1742 1667 id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID1); 1743 1668 smmu->pgshift = (id & ID1_PAGESIZE) ? 16 : 12; ··· 1764 1677 } 1765 1678 dev_notice(smmu->dev, "\t%u context banks (%u stage-2 only)\n", 1766 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 + } 1767 1691 1768 1692 /* ID2 */ 1769 1693 id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID2); ··· 1785 1687 size = arm_smmu_id_size_to_bits((id >> ID2_OAS_SHIFT) & ID2_OAS_MASK); 1786 1688 smmu->pa_size = size; 1787 1689 1690 + if (id & ID2_VMID16) 1691 + smmu->features |= ARM_SMMU_FEAT_VMID16; 1692 + 1788 1693 /* 1789 1694 * What the page table walker can address actually depends on which 1790 1695 * descriptor format is in use, but since a) we don't know that yet, ··· 1797 1696 dev_warn(smmu->dev, 1798 1697 "failed to set DMA mask for table walker\n"); 1799 1698 1800 - if (smmu->version == ARM_SMMU_V1) { 1699 + if (smmu->version < ARM_SMMU_V2) { 1801 1700 smmu->va_size = smmu->ipa_size; 1802 - size = SZ_4K | SZ_2M | SZ_1G; 1701 + if (smmu->version == ARM_SMMU_V1_64K) 1702 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_64K; 1803 1703 } else { 1804 1704 size = (id >> ID2_UBS_SHIFT) & ID2_UBS_MASK; 1805 1705 smmu->va_size = arm_smmu_id_size_to_bits(size); 1806 - #ifndef CONFIG_64BIT 1807 - smmu->va_size = min(32UL, smmu->va_size); 1808 - #endif 1809 - size = 0; 1810 1706 if (id & ID2_PTFS_4K) 1811 - size |= SZ_4K | SZ_2M | SZ_1G; 1707 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_4K; 1812 1708 if (id & ID2_PTFS_16K) 1813 - size |= SZ_16K | SZ_32M; 1709 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_16K; 1814 1710 if (id & ID2_PTFS_64K) 1815 - size |= SZ_64K | SZ_512M; 1711 + smmu->features |= ARM_SMMU_FEAT_FMT_AARCH64_64K; 1816 1712 } 1817 1713 1818 - arm_smmu_ops.pgsize_bitmap &= size; 1819 - dev_notice(smmu->dev, "\tSupported page sizes: 0x%08lx\n", size); 1714 + /* Now we've corralled the various formats, what'll it do? */ 1715 + if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH32_S) 1716 + smmu->pgsize_bitmap |= SZ_4K | SZ_64K | SZ_1M | SZ_16M; 1717 + if (smmu->features & 1718 + (ARM_SMMU_FEAT_FMT_AARCH32_L | ARM_SMMU_FEAT_FMT_AARCH64_4K)) 1719 + smmu->pgsize_bitmap |= SZ_4K | SZ_2M | SZ_1G; 1720 + if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH64_16K) 1721 + smmu->pgsize_bitmap |= SZ_16K | SZ_32M; 1722 + if (smmu->features & ARM_SMMU_FEAT_FMT_AARCH64_64K) 1723 + smmu->pgsize_bitmap |= SZ_64K | SZ_512M; 1724 + 1725 + if (arm_smmu_ops.pgsize_bitmap == -1UL) 1726 + arm_smmu_ops.pgsize_bitmap = smmu->pgsize_bitmap; 1727 + else 1728 + arm_smmu_ops.pgsize_bitmap |= smmu->pgsize_bitmap; 1729 + dev_notice(smmu->dev, "\tSupported page sizes: 0x%08lx\n", 1730 + smmu->pgsize_bitmap); 1731 + 1820 1732 1821 1733 if (smmu->features & ARM_SMMU_FEAT_TRANS_S1) 1822 1734 dev_notice(smmu->dev, "\tStage-1: %lu-bit VA -> %lu-bit IPA\n", ··· 1842 1728 return 0; 1843 1729 } 1844 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 + 1845 1745 static const struct of_device_id arm_smmu_of_match[] = { 1846 - { .compatible = "arm,smmu-v1", .data = (void *)ARM_SMMU_V1 }, 1847 - { .compatible = "arm,smmu-v2", .data = (void *)ARM_SMMU_V2 }, 1848 - { .compatible = "arm,mmu-400", .data = (void *)ARM_SMMU_V1 }, 1849 - { .compatible = "arm,mmu-401", .data = (void *)ARM_SMMU_V1 }, 1850 - { .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 }, 1851 1752 { }, 1852 1753 }; 1853 1754 MODULE_DEVICE_TABLE(of, arm_smmu_of_match); ··· 1870 1741 static int arm_smmu_device_dt_probe(struct platform_device *pdev) 1871 1742 { 1872 1743 const struct of_device_id *of_id; 1744 + const struct arm_smmu_match_data *data; 1873 1745 struct resource *res; 1874 1746 struct arm_smmu_device *smmu; 1875 1747 struct device *dev = &pdev->dev; ··· 1886 1756 smmu->dev = dev; 1887 1757 1888 1758 of_id = of_match_node(arm_smmu_of_match, dev->of_node); 1889 - 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; 1890 1762 1891 1763 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1892 1764 smmu->base = devm_ioremap_resource(dev, res); ··· 1954 1822 1955 1823 parse_driver_options(smmu); 1956 1824 1957 - if (smmu->version > ARM_SMMU_V1 && 1825 + if (smmu->version == ARM_SMMU_V2 && 1958 1826 smmu->num_context_banks != smmu->num_context_irqs) { 1959 1827 dev_err(dev, 1960 1828 "found only %d context interrupt(s) but %d required\n",
+101 -45
drivers/iommu/dma-iommu.c
··· 94 94 return -ENODEV; 95 95 96 96 /* Use the smallest supported page size for IOVA granularity */ 97 - order = __ffs(domain->ops->pgsize_bitmap); 97 + order = __ffs(domain->pgsize_bitmap); 98 98 base_pfn = max_t(unsigned long, 1, base >> order); 99 99 end_pfn = (base + size - 1) >> order; 100 100 ··· 190 190 kvfree(pages); 191 191 } 192 192 193 - static struct page **__iommu_dma_alloc_pages(unsigned int count, gfp_t gfp) 193 + static struct page **__iommu_dma_alloc_pages(unsigned int count, 194 + unsigned long order_mask, gfp_t gfp) 194 195 { 195 196 struct page **pages; 196 197 unsigned int i = 0, array_size = count * sizeof(*pages); 197 - unsigned int order = MAX_ORDER; 198 + 199 + order_mask &= (2U << MAX_ORDER) - 1; 200 + if (!order_mask) 201 + return NULL; 198 202 199 203 if (array_size <= PAGE_SIZE) 200 204 pages = kzalloc(array_size, GFP_KERNEL); ··· 212 208 213 209 while (count) { 214 210 struct page *page = NULL; 215 - int j; 211 + unsigned int order_size; 216 212 217 213 /* 218 214 * Higher-order allocations are a convenience rather 219 215 * than a necessity, hence using __GFP_NORETRY until 220 - * falling back to single-page allocations. 216 + * falling back to minimum-order allocations. 221 217 */ 222 - for (order = min_t(unsigned int, order, __fls(count)); 223 - order > 0; order--) { 224 - page = alloc_pages(gfp | __GFP_NORETRY, order); 218 + for (order_mask &= (2U << __fls(count)) - 1; 219 + order_mask; order_mask &= ~order_size) { 220 + unsigned int order = __fls(order_mask); 221 + 222 + order_size = 1U << order; 223 + page = alloc_pages((order_mask - order_size) ? 224 + gfp | __GFP_NORETRY : gfp, order); 225 225 if (!page) 226 226 continue; 227 - if (PageCompound(page)) { 228 - if (!split_huge_page(page)) 229 - break; 230 - __free_pages(page, order); 231 - } else { 227 + if (!order) 228 + break; 229 + if (!PageCompound(page)) { 232 230 split_page(page, order); 233 231 break; 232 + } else if (!split_huge_page(page)) { 233 + break; 234 234 } 235 + __free_pages(page, order); 235 236 } 236 - if (!page) 237 - page = alloc_page(gfp); 238 237 if (!page) { 239 238 __iommu_dma_free_pages(pages, i); 240 239 return NULL; 241 240 } 242 - j = 1 << order; 243 - count -= j; 244 - while (j--) 241 + count -= order_size; 242 + while (order_size--) 245 243 pages[i++] = page++; 246 244 } 247 245 return pages; ··· 273 267 * attached to an iommu_dma_domain 274 268 * @size: Size of buffer in bytes 275 269 * @gfp: Allocation flags 270 + * @attrs: DMA attributes for this allocation 276 271 * @prot: IOMMU mapping flags 277 272 * @handle: Out argument for allocated DMA handle 278 273 * @flush_page: Arch callback which must ensure PAGE_SIZE bytes from the ··· 285 278 * Return: Array of struct page pointers describing the buffer, 286 279 * or NULL on failure. 287 280 */ 288 - struct page **iommu_dma_alloc(struct device *dev, size_t size, 289 - gfp_t gfp, int prot, dma_addr_t *handle, 281 + struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, 282 + struct dma_attrs *attrs, int prot, dma_addr_t *handle, 290 283 void (*flush_page)(struct device *, const void *, phys_addr_t)) 291 284 { 292 285 struct iommu_domain *domain = iommu_get_domain_for_dev(dev); ··· 295 288 struct page **pages; 296 289 struct sg_table sgt; 297 290 dma_addr_t dma_addr; 298 - unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; 291 + unsigned int count, min_size, alloc_sizes = domain->pgsize_bitmap; 299 292 300 293 *handle = DMA_ERROR_CODE; 301 294 302 - pages = __iommu_dma_alloc_pages(count, gfp); 295 + min_size = alloc_sizes & -alloc_sizes; 296 + if (min_size < PAGE_SIZE) { 297 + min_size = PAGE_SIZE; 298 + alloc_sizes |= PAGE_SIZE; 299 + } else { 300 + size = ALIGN(size, min_size); 301 + } 302 + if (dma_get_attr(DMA_ATTR_ALLOC_SINGLE_PAGES, attrs)) 303 + alloc_sizes = min_size; 304 + 305 + count = PAGE_ALIGN(size) >> PAGE_SHIFT; 306 + pages = __iommu_dma_alloc_pages(count, alloc_sizes >> PAGE_SHIFT, gfp); 303 307 if (!pages) 304 308 return NULL; 305 309 ··· 407 389 408 390 /* 409 391 * Prepare a successfully-mapped scatterlist to give back to the caller. 410 - * Handling IOVA concatenation can come later, if needed 392 + * 393 + * At this point the segments are already laid out by iommu_dma_map_sg() to 394 + * avoid individually crossing any boundaries, so we merely need to check a 395 + * segment's start address to avoid concatenating across one. 411 396 */ 412 397 static int __finalise_sg(struct device *dev, struct scatterlist *sg, int nents, 413 398 dma_addr_t dma_addr) 414 399 { 415 - struct scatterlist *s; 416 - int i; 400 + struct scatterlist *s, *cur = sg; 401 + unsigned long seg_mask = dma_get_seg_boundary(dev); 402 + unsigned int cur_len = 0, max_len = dma_get_max_seg_size(dev); 403 + int i, count = 0; 417 404 418 405 for_each_sg(sg, s, nents, i) { 419 - /* Un-swizzling the fields here, hence the naming mismatch */ 420 - unsigned int s_offset = sg_dma_address(s); 406 + /* Restore this segment's original unaligned fields first */ 407 + unsigned int s_iova_off = sg_dma_address(s); 421 408 unsigned int s_length = sg_dma_len(s); 422 - unsigned int s_dma_len = s->length; 409 + unsigned int s_iova_len = s->length; 423 410 424 - s->offset += s_offset; 411 + s->offset += s_iova_off; 425 412 s->length = s_length; 426 - sg_dma_address(s) = dma_addr + s_offset; 427 - dma_addr += s_dma_len; 413 + sg_dma_address(s) = DMA_ERROR_CODE; 414 + sg_dma_len(s) = 0; 415 + 416 + /* 417 + * Now fill in the real DMA data. If... 418 + * - there is a valid output segment to append to 419 + * - and this segment starts on an IOVA page boundary 420 + * - but doesn't fall at a segment boundary 421 + * - and wouldn't make the resulting output segment too long 422 + */ 423 + if (cur_len && !s_iova_off && (dma_addr & seg_mask) && 424 + (cur_len + s_length <= max_len)) { 425 + /* ...then concatenate it with the previous one */ 426 + cur_len += s_length; 427 + } else { 428 + /* Otherwise start the next output segment */ 429 + if (i > 0) 430 + cur = sg_next(cur); 431 + cur_len = s_length; 432 + count++; 433 + 434 + sg_dma_address(cur) = dma_addr + s_iova_off; 435 + } 436 + 437 + sg_dma_len(cur) = cur_len; 438 + dma_addr += s_iova_len; 439 + 440 + if (s_length + s_iova_off < s_iova_len) 441 + cur_len = 0; 428 442 } 429 - return i; 443 + return count; 430 444 } 431 445 432 446 /* ··· 496 446 struct scatterlist *s, *prev = NULL; 497 447 dma_addr_t dma_addr; 498 448 size_t iova_len = 0; 449 + unsigned long mask = dma_get_seg_boundary(dev); 499 450 int i; 500 451 501 452 /* 502 453 * Work out how much IOVA space we need, and align the segments to 503 454 * IOVA granules for the IOMMU driver to handle. With some clever 504 455 * trickery we can modify the list in-place, but reversibly, by 505 - * hiding the original data in the as-yet-unused DMA fields. 456 + * stashing the unaligned parts in the as-yet-unused DMA fields. 506 457 */ 507 458 for_each_sg(sg, s, nents, i) { 508 - size_t s_offset = iova_offset(iovad, s->offset); 459 + size_t s_iova_off = iova_offset(iovad, s->offset); 509 460 size_t s_length = s->length; 461 + size_t pad_len = (mask - iova_len + 1) & mask; 510 462 511 - sg_dma_address(s) = s_offset; 463 + sg_dma_address(s) = s_iova_off; 512 464 sg_dma_len(s) = s_length; 513 - s->offset -= s_offset; 514 - s_length = iova_align(iovad, s_length + s_offset); 465 + s->offset -= s_iova_off; 466 + s_length = iova_align(iovad, s_length + s_iova_off); 515 467 s->length = s_length; 516 468 517 469 /* 518 - * The simple way to avoid the rare case of a segment 519 - * crossing the boundary mask is to pad the previous one 520 - * to end at a naturally-aligned IOVA for this one's size, 521 - * at the cost of potentially over-allocating a little. 470 + * Due to the alignment of our single IOVA allocation, we can 471 + * depend on these assumptions about the segment boundary mask: 472 + * - If mask size >= IOVA size, then the IOVA range cannot 473 + * possibly fall across a boundary, so we don't care. 474 + * - If mask size < IOVA size, then the IOVA range must start 475 + * exactly on a boundary, therefore we can lay things out 476 + * based purely on segment lengths without needing to know 477 + * the actual addresses beforehand. 478 + * - The mask must be a power of 2, so pad_len == 0 if 479 + * iova_len == 0, thus we cannot dereference prev the first 480 + * time through here (i.e. before it has a meaningful value). 522 481 */ 523 - if (prev) { 524 - size_t pad_len = roundup_pow_of_two(s_length); 525 - 526 - pad_len = (pad_len - iova_len) & (pad_len - 1); 482 + if (pad_len && pad_len < s_length - 1) { 527 483 prev->length += pad_len; 528 484 iova_len += pad_len; 529 485 }
+27 -20
drivers/iommu/dmar.c
··· 1579 1579 reason = dmar_get_fault_reason(fault_reason, &fault_type); 1580 1580 1581 1581 if (fault_type == INTR_REMAP) 1582 - pr_err("INTR-REMAP: Request device [[%02x:%02x.%d] " 1583 - "fault index %llx\n" 1584 - "INTR-REMAP:[fault reason %02d] %s\n", 1585 - (source_id >> 8), PCI_SLOT(source_id & 0xFF), 1582 + pr_err("[INTR-REMAP] Request device [%02x:%02x.%d] fault index %llx [fault reason %02d] %s\n", 1583 + source_id >> 8, PCI_SLOT(source_id & 0xFF), 1586 1584 PCI_FUNC(source_id & 0xFF), addr >> 48, 1587 1585 fault_reason, reason); 1588 1586 else 1589 - pr_err("DMAR:[%s] Request device [%02x:%02x.%d] " 1590 - "fault addr %llx \n" 1591 - "DMAR:[fault reason %02d] %s\n", 1592 - (type ? "DMA Read" : "DMA Write"), 1593 - (source_id >> 8), PCI_SLOT(source_id & 0xFF), 1587 + pr_err("[%s] Request device [%02x:%02x.%d] fault addr %llx [fault reason %02d] %s\n", 1588 + type ? "DMA Read" : "DMA Write", 1589 + source_id >> 8, PCI_SLOT(source_id & 0xFF), 1594 1590 PCI_FUNC(source_id & 0xFF), addr, fault_reason, reason); 1595 1591 return 0; 1596 1592 } ··· 1598 1602 int reg, fault_index; 1599 1603 u32 fault_status; 1600 1604 unsigned long flag; 1605 + bool ratelimited; 1606 + static DEFINE_RATELIMIT_STATE(rs, 1607 + DEFAULT_RATELIMIT_INTERVAL, 1608 + DEFAULT_RATELIMIT_BURST); 1609 + 1610 + /* Disable printing, simply clear the fault when ratelimited */ 1611 + ratelimited = !__ratelimit(&rs); 1601 1612 1602 1613 raw_spin_lock_irqsave(&iommu->register_lock, flag); 1603 1614 fault_status = readl(iommu->reg + DMAR_FSTS_REG); 1604 - if (fault_status) 1615 + if (fault_status && !ratelimited) 1605 1616 pr_err("DRHD: handling fault status reg %x\n", fault_status); 1606 1617 1607 1618 /* TBD: ignore advanced fault log currently */ ··· 1630 1627 if (!(data & DMA_FRCD_F)) 1631 1628 break; 1632 1629 1633 - fault_reason = dma_frcd_fault_reason(data); 1634 - type = dma_frcd_type(data); 1630 + if (!ratelimited) { 1631 + fault_reason = dma_frcd_fault_reason(data); 1632 + type = dma_frcd_type(data); 1635 1633 1636 - data = readl(iommu->reg + reg + 1637 - fault_index * PRIMARY_FAULT_REG_LEN + 8); 1638 - source_id = dma_frcd_source_id(data); 1634 + data = readl(iommu->reg + reg + 1635 + fault_index * PRIMARY_FAULT_REG_LEN + 8); 1636 + source_id = dma_frcd_source_id(data); 1639 1637 1640 - guest_addr = dmar_readq(iommu->reg + reg + 1641 - fault_index * PRIMARY_FAULT_REG_LEN); 1642 - guest_addr = dma_frcd_page_addr(guest_addr); 1638 + guest_addr = dmar_readq(iommu->reg + reg + 1639 + fault_index * PRIMARY_FAULT_REG_LEN); 1640 + guest_addr = dma_frcd_page_addr(guest_addr); 1641 + } 1642 + 1643 1643 /* clear the fault */ 1644 1644 writel(DMA_FRCD_F, iommu->reg + reg + 1645 1645 fault_index * PRIMARY_FAULT_REG_LEN + 12); 1646 1646 1647 1647 raw_spin_unlock_irqrestore(&iommu->register_lock, flag); 1648 1648 1649 - dmar_fault_do_one(iommu, type, fault_reason, 1650 - source_id, guest_addr); 1649 + if (!ratelimited) 1650 + dmar_fault_do_one(iommu, type, fault_reason, 1651 + source_id, guest_addr); 1651 1652 1652 1653 fault_index++; 1653 1654 if (fault_index >= cap_num_fault_regs(iommu->cap))
+1 -1
drivers/iommu/intel-iommu.c
··· 1143 1143 } while (!first_pte_in_page(++pte) && pfn <= last_pfn); 1144 1144 } 1145 1145 1146 - /* free page table pages. last level pte should already be cleared */ 1146 + /* clear last level (leaf) ptes and free page table pages. */ 1147 1147 static void dma_pte_free_pagetable(struct dmar_domain *domain, 1148 1148 unsigned long start_pfn, 1149 1149 unsigned long last_pfn)
+23 -6
drivers/iommu/io-pgtable-arm-v7s.c
··· 121 121 #define ARM_V7S_TEX_MASK 0x7 122 122 #define ARM_V7S_ATTR_TEX(val) (((val) & ARM_V7S_TEX_MASK) << ARM_V7S_TEX_SHIFT) 123 123 124 + #define ARM_V7S_ATTR_MTK_4GB BIT(9) /* MTK extend it for 4GB mode */ 125 + 124 126 /* *well, except for TEX on level 2 large pages, of course :( */ 125 127 #define ARM_V7S_CONT_PAGE_TEX_SHIFT 6 126 128 #define ARM_V7S_CONT_PAGE_TEX_MASK (ARM_V7S_TEX_MASK << ARM_V7S_CONT_PAGE_TEX_SHIFT) ··· 260 258 struct io_pgtable_cfg *cfg) 261 259 { 262 260 bool ap = !(cfg->quirks & IO_PGTABLE_QUIRK_NO_PERMS); 263 - arm_v7s_iopte pte = ARM_V7S_ATTR_NG | ARM_V7S_ATTR_S | 264 - ARM_V7S_ATTR_TEX(1); 261 + arm_v7s_iopte pte = ARM_V7S_ATTR_NG | ARM_V7S_ATTR_S; 265 262 263 + if (!(prot & IOMMU_MMIO)) 264 + pte |= ARM_V7S_ATTR_TEX(1); 266 265 if (ap) { 267 266 pte |= ARM_V7S_PTE_AF | ARM_V7S_PTE_AP_UNPRIV; 268 267 if (!(prot & IOMMU_WRITE)) ··· 273 270 274 271 if ((prot & IOMMU_NOEXEC) && ap) 275 272 pte |= ARM_V7S_ATTR_XN(lvl); 276 - if (prot & IOMMU_CACHE) 273 + if (prot & IOMMU_MMIO) 274 + pte |= ARM_V7S_ATTR_B; 275 + else if (prot & IOMMU_CACHE) 277 276 pte |= ARM_V7S_ATTR_B | ARM_V7S_ATTR_C; 278 277 279 278 return pte; ··· 284 279 static int arm_v7s_pte_to_prot(arm_v7s_iopte pte, int lvl) 285 280 { 286 281 int prot = IOMMU_READ; 282 + arm_v7s_iopte attr = pte >> ARM_V7S_ATTR_SHIFT(lvl); 287 283 288 - if (pte & (ARM_V7S_PTE_AP_RDONLY << ARM_V7S_ATTR_SHIFT(lvl))) 284 + if (attr & ARM_V7S_PTE_AP_RDONLY) 289 285 prot |= IOMMU_WRITE; 290 - if (pte & ARM_V7S_ATTR_C) 286 + if ((attr & (ARM_V7S_TEX_MASK << ARM_V7S_TEX_SHIFT)) == 0) 287 + prot |= IOMMU_MMIO; 288 + else if (pte & ARM_V7S_ATTR_C) 291 289 prot |= IOMMU_CACHE; 292 290 293 291 return prot; ··· 371 363 pte |= ARM_V7S_PTE_TYPE_PAGE; 372 364 if (lvl == 1 && (cfg->quirks & IO_PGTABLE_QUIRK_ARM_NS)) 373 365 pte |= ARM_V7S_ATTR_NS_SECTION; 366 + 367 + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_4GB) 368 + pte |= ARM_V7S_ATTR_MTK_4GB; 374 369 375 370 if (num_entries > 1) 376 371 pte = arm_v7s_pte_to_cont(pte, lvl); ··· 636 625 637 626 if (cfg->quirks & ~(IO_PGTABLE_QUIRK_ARM_NS | 638 627 IO_PGTABLE_QUIRK_NO_PERMS | 639 - IO_PGTABLE_QUIRK_TLBI_ON_MAP)) 628 + IO_PGTABLE_QUIRK_TLBI_ON_MAP | 629 + IO_PGTABLE_QUIRK_ARM_MTK_4GB)) 640 630 return NULL; 631 + 632 + /* If ARM_MTK_4GB is enabled, the NO_PERMS is also expected. */ 633 + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_MTK_4GB && 634 + !(cfg->quirks & IO_PGTABLE_QUIRK_NO_PERMS)) 635 + return NULL; 641 636 642 637 data = kmalloc(sizeof(*data), GFP_KERNEL); 643 638 if (!data)
+7 -2
drivers/iommu/io-pgtable-arm.c
··· 355 355 if (!(prot & IOMMU_WRITE) && (prot & IOMMU_READ)) 356 356 pte |= ARM_LPAE_PTE_AP_RDONLY; 357 357 358 - if (prot & IOMMU_CACHE) 358 + if (prot & IOMMU_MMIO) 359 + pte |= (ARM_LPAE_MAIR_ATTR_IDX_DEV 360 + << ARM_LPAE_PTE_ATTRINDX_SHIFT); 361 + else if (prot & IOMMU_CACHE) 359 362 pte |= (ARM_LPAE_MAIR_ATTR_IDX_CACHE 360 363 << ARM_LPAE_PTE_ATTRINDX_SHIFT); 361 364 } else { ··· 367 364 pte |= ARM_LPAE_PTE_HAP_READ; 368 365 if (prot & IOMMU_WRITE) 369 366 pte |= ARM_LPAE_PTE_HAP_WRITE; 370 - if (prot & IOMMU_CACHE) 367 + if (prot & IOMMU_MMIO) 368 + pte |= ARM_LPAE_PTE_MEMATTR_DEV; 369 + else if (prot & IOMMU_CACHE) 371 370 pte |= ARM_LPAE_PTE_MEMATTR_OIWB; 372 371 else 373 372 pte |= ARM_LPAE_PTE_MEMATTR_NC;
+1 -2
drivers/iommu/io-pgtable.c
··· 25 25 #include "io-pgtable.h" 26 26 27 27 static const struct io_pgtable_init_fns * 28 - io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = 29 - { 28 + io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] = { 30 29 #ifdef CONFIG_IOMMU_IO_PGTABLE_LPAE 31 30 [ARM_32_LPAE_S1] = &io_pgtable_arm_32_lpae_s1_init_fns, 32 31 [ARM_32_LPAE_S2] = &io_pgtable_arm_32_lpae_s2_init_fns,
+6
drivers/iommu/io-pgtable.h
··· 60 60 * IO_PGTABLE_QUIRK_TLBI_ON_MAP: If the format forbids caching invalid 61 61 * (unmapped) entries but the hardware might do so anyway, perform 62 62 * TLB maintenance when mapping as well as when unmapping. 63 + * 64 + * IO_PGTABLE_QUIRK_ARM_MTK_4GB: (ARM v7s format) Set bit 9 in all 65 + * PTEs, for Mediatek IOMMUs which treat it as a 33rd address bit 66 + * when the SoC is in "4GB mode" and they can only access the high 67 + * remap of DRAM (0x1_00000000 to 0x1_ffffffff). 63 68 */ 64 69 #define IO_PGTABLE_QUIRK_ARM_NS BIT(0) 65 70 #define IO_PGTABLE_QUIRK_NO_PERMS BIT(1) 66 71 #define IO_PGTABLE_QUIRK_TLBI_ON_MAP BIT(2) 72 + #define IO_PGTABLE_QUIRK_ARM_MTK_4GB BIT(3) 67 73 unsigned long quirks; 68 74 unsigned long pgsize_bitmap; 69 75 unsigned int ias;
+12 -10
drivers/iommu/iommu.c
··· 337 337 if (!domain || domain->type != IOMMU_DOMAIN_DMA) 338 338 return 0; 339 339 340 - BUG_ON(!domain->ops->pgsize_bitmap); 340 + BUG_ON(!domain->pgsize_bitmap); 341 341 342 - pg_size = 1UL << __ffs(domain->ops->pgsize_bitmap); 342 + pg_size = 1UL << __ffs(domain->pgsize_bitmap); 343 343 INIT_LIST_HEAD(&mappings); 344 344 345 345 iommu_get_dm_regions(dev, &mappings); ··· 1069 1069 1070 1070 domain->ops = bus->iommu_ops; 1071 1071 domain->type = type; 1072 + /* Assume all sizes by default; the driver may override this later */ 1073 + domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; 1072 1074 1073 1075 return domain; 1074 1076 } ··· 1295 1293 pgsize = (1UL << (pgsize_idx + 1)) - 1; 1296 1294 1297 1295 /* throw away page sizes not supported by the hardware */ 1298 - pgsize &= domain->ops->pgsize_bitmap; 1296 + pgsize &= domain->pgsize_bitmap; 1299 1297 1300 1298 /* make sure we're still sane */ 1301 1299 BUG_ON(!pgsize); ··· 1317 1315 int ret = 0; 1318 1316 1319 1317 if (unlikely(domain->ops->map == NULL || 1320 - domain->ops->pgsize_bitmap == 0UL)) 1318 + domain->pgsize_bitmap == 0UL)) 1321 1319 return -ENODEV; 1322 1320 1323 1321 if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING))) 1324 1322 return -EINVAL; 1325 1323 1326 1324 /* find out the minimum page size supported */ 1327 - min_pagesz = 1 << __ffs(domain->ops->pgsize_bitmap); 1325 + min_pagesz = 1 << __ffs(domain->pgsize_bitmap); 1328 1326 1329 1327 /* 1330 1328 * both the virtual address and the physical one, as well as ··· 1371 1369 unsigned long orig_iova = iova; 1372 1370 1373 1371 if (unlikely(domain->ops->unmap == NULL || 1374 - domain->ops->pgsize_bitmap == 0UL)) 1372 + domain->pgsize_bitmap == 0UL)) 1375 1373 return -ENODEV; 1376 1374 1377 1375 if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING))) 1378 1376 return -EINVAL; 1379 1377 1380 1378 /* find out the minimum page size supported */ 1381 - min_pagesz = 1 << __ffs(domain->ops->pgsize_bitmap); 1379 + min_pagesz = 1 << __ffs(domain->pgsize_bitmap); 1382 1380 1383 1381 /* 1384 1382 * The virtual address, as well as the size of the mapping, must be ··· 1424 1422 unsigned int i, min_pagesz; 1425 1423 int ret; 1426 1424 1427 - if (unlikely(domain->ops->pgsize_bitmap == 0UL)) 1425 + if (unlikely(domain->pgsize_bitmap == 0UL)) 1428 1426 return 0; 1429 1427 1430 - min_pagesz = 1 << __ffs(domain->ops->pgsize_bitmap); 1428 + min_pagesz = 1 << __ffs(domain->pgsize_bitmap); 1431 1429 1432 1430 for_each_sg(sg, s, nents, i) { 1433 1431 phys_addr_t phys = page_to_phys(sg_page(s)) + s->offset; ··· 1508 1506 break; 1509 1507 case DOMAIN_ATTR_PAGING: 1510 1508 paging = data; 1511 - *paging = (domain->ops->pgsize_bitmap != 0UL); 1509 + *paging = (domain->pgsize_bitmap != 0UL); 1512 1510 break; 1513 1511 case DOMAIN_ATTR_WINDOWS: 1514 1512 count = data;
+12 -4
drivers/iommu/mtk_iommu.c
··· 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 * GNU General Public License for more details. 13 13 */ 14 + #include <linux/bootmem.h> 14 15 #include <linux/bug.h> 15 16 #include <linux/clk.h> 16 17 #include <linux/component.h> ··· 57 56 #define F_MMU_TF_PROTECT_SEL(prot) (((prot) & 0x3) << 5) 58 57 59 58 #define REG_MMU_IVRP_PADDR 0x114 60 - #define F_MMU_IVRP_PA_SET(pa) ((pa) >> 1) 59 + #define F_MMU_IVRP_PA_SET(pa, ext) (((pa) >> 1) | ((!!(ext)) << 31)) 61 60 62 61 #define REG_MMU_INT_CONTROL0 0x120 63 62 #define F_L2_MULIT_HIT_EN BIT(0) ··· 126 125 struct mtk_iommu_domain *m4u_dom; 127 126 struct iommu_group *m4u_group; 128 127 struct mtk_smi_iommu smi_imu; /* SMI larb iommu info */ 128 + bool enable_4GB; 129 129 }; 130 130 131 131 static struct iommu_ops mtk_iommu_ops; ··· 259 257 .iommu_dev = data->dev, 260 258 }; 261 259 260 + if (data->enable_4GB) 261 + dom->cfg.quirks |= IO_PGTABLE_QUIRK_ARM_MTK_4GB; 262 + 262 263 dom->iop = alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data); 263 264 if (!dom->iop) { 264 265 dev_err(data->dev, "Failed to alloc io pgtable\n"); ··· 269 264 } 270 265 271 266 /* Update our support page sizes bitmap */ 272 - mtk_iommu_ops.pgsize_bitmap = dom->cfg.pgsize_bitmap; 267 + dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap; 273 268 274 269 writel(data->m4u_dom->cfg.arm_v7s_cfg.ttbr[0], 275 270 data->base + REG_MMU_PT_BASE_ADDR); ··· 535 530 F_INT_PRETETCH_TRANSATION_FIFO_FAULT; 536 531 writel_relaxed(regval, data->base + REG_MMU_INT_MAIN_CONTROL); 537 532 538 - writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base), 533 + writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base, data->enable_4GB), 539 534 data->base + REG_MMU_IVRP_PADDR); 540 535 541 536 writel_relaxed(0, data->base + REG_MMU_DCM_DIS); ··· 595 590 if (!protect) 596 591 return -ENOMEM; 597 592 data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN); 593 + 594 + /* Whether the current dram is over 4GB */ 595 + data->enable_4GB = !!(max_pfn > (0xffffffffUL >> PAGE_SHIFT)); 598 596 599 597 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 600 598 data->base = devm_ioremap_resource(dev, res); ··· 698 690 writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG); 699 691 writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0); 700 692 writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL); 701 - writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base), 693 + writel_relaxed(F_MMU_IVRP_PA_SET(data->protect_base, data->enable_4GB), 702 694 base + REG_MMU_IVRP_PADDR); 703 695 return 0; 704 696 }
+7 -7
drivers/iommu/of_iommu.c
··· 98 98 struct of_iommu_node { 99 99 struct list_head list; 100 100 struct device_node *np; 101 - struct iommu_ops *ops; 101 + const struct iommu_ops *ops; 102 102 }; 103 103 static LIST_HEAD(of_iommu_list); 104 104 static DEFINE_SPINLOCK(of_iommu_lock); 105 105 106 - void of_iommu_set_ops(struct device_node *np, struct iommu_ops *ops) 106 + void of_iommu_set_ops(struct device_node *np, const struct iommu_ops *ops) 107 107 { 108 108 struct of_iommu_node *iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); 109 109 ··· 119 119 spin_unlock(&of_iommu_lock); 120 120 } 121 121 122 - struct iommu_ops *of_iommu_get_ops(struct device_node *np) 122 + const struct iommu_ops *of_iommu_get_ops(struct device_node *np) 123 123 { 124 124 struct of_iommu_node *node; 125 - struct iommu_ops *ops = NULL; 125 + const struct iommu_ops *ops = NULL; 126 126 127 127 spin_lock(&of_iommu_lock); 128 128 list_for_each_entry(node, &of_iommu_list, list) ··· 134 134 return ops; 135 135 } 136 136 137 - struct iommu_ops *of_iommu_configure(struct device *dev, 138 - struct device_node *master_np) 137 + const struct iommu_ops *of_iommu_configure(struct device *dev, 138 + struct device_node *master_np) 139 139 { 140 140 struct of_phandle_args iommu_spec; 141 141 struct device_node *np; 142 - struct iommu_ops *ops = NULL; 142 + const struct iommu_ops *ops = NULL; 143 143 int idx = 0; 144 144 145 145 /*
+1 -1
drivers/iommu/omap-iommu-debug.c
··· 136 136 struct seq_file *s) 137 137 { 138 138 seq_printf(s, "%08x %08x %01x\n", cr->cam, cr->ram, 139 - (cr->cam & MMU_CAM_P) ? 1 : 0); 139 + (cr->cam & MMU_CAM_P) ? 1 : 0); 140 140 return 0; 141 141 } 142 142
+7 -3
drivers/iommu/omap-iommu.c
··· 628 628 break; 629 629 default: 630 630 fn = NULL; 631 - BUG(); 632 631 break; 633 632 } 633 + 634 + if (WARN_ON(!fn)) 635 + return -EINVAL; 634 636 635 637 prot = get_iopte_attr(e); 636 638 ··· 989 987 { 990 988 struct omap_iommu *obj = platform_get_drvdata(pdev); 991 989 992 - iopgtable_clear_entry_all(obj); 993 990 omap_iommu_debugfs_remove(obj); 994 991 995 992 pm_runtime_disable(obj->dev); ··· 1162 1161 * should never fail, but please keep this around to ensure 1163 1162 * we keep the hardware happy 1164 1163 */ 1165 - BUG_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE)); 1164 + if (WARN_ON(!IS_ALIGNED((long)omap_domain->pgtable, IOPGD_TABLE_SIZE))) 1165 + goto fail_align; 1166 1166 1167 1167 clean_dcache_area(omap_domain->pgtable, IOPGD_TABLE_SIZE); 1168 1168 spin_lock_init(&omap_domain->lock); ··· 1174 1172 1175 1173 return &omap_domain->domain; 1176 1174 1175 + fail_align: 1176 + kfree(omap_domain->pgtable); 1177 1177 fail_nomem: 1178 1178 kfree(omap_domain); 1179 1179 out:
+2
drivers/iommu/rockchip-iommu.c
··· 1049 1049 1050 1050 for (i = 0; i < pdev->num_resources; i++) { 1051 1051 res = platform_get_resource(pdev, IORESOURCE_MEM, i); 1052 + if (!res) 1053 + continue; 1052 1054 iommu->bases[i] = devm_ioremap_resource(&pdev->dev, res); 1053 1055 if (IS_ERR(iommu->bases[i])) 1054 1056 continue;
+1 -1
drivers/of/device.c
··· 88 88 int ret; 89 89 bool coherent; 90 90 unsigned long offset; 91 - struct iommu_ops *iommu; 91 + const struct iommu_ops *iommu; 92 92 93 93 /* 94 94 * Set default coherent_dma_mask to 32 bit. Drivers are expected to
+1 -1
drivers/vfio/vfio_iommu_type1.c
··· 407 407 408 408 mutex_lock(&iommu->lock); 409 409 list_for_each_entry(domain, &iommu->domain_list, next) 410 - bitmap &= domain->domain->ops->pgsize_bitmap; 410 + bitmap &= domain->domain->pgsize_bitmap; 411 411 mutex_unlock(&iommu->lock); 412 412 413 413 /*
+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
+2 -2
include/linux/dma-iommu.h
··· 38 38 * These implement the bulk of the relevant DMA mapping callbacks, but require 39 39 * the arch code to take care of attributes and cache maintenance 40 40 */ 41 - struct page **iommu_dma_alloc(struct device *dev, size_t size, 42 - gfp_t gfp, int prot, dma_addr_t *handle, 41 + struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, 42 + struct dma_attrs *attrs, int prot, dma_addr_t *handle, 43 43 void (*flush_page)(struct device *, const void *, phys_addr_t)); 44 44 void iommu_dma_free(struct device *dev, struct page **pages, size_t size, 45 45 dma_addr_t *handle);
+1 -1
include/linux/dma-mapping.h
··· 514 514 515 515 #ifndef arch_setup_dma_ops 516 516 static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, 517 - u64 size, struct iommu_ops *iommu, 517 + u64 size, const struct iommu_ops *iommu, 518 518 bool coherent) { } 519 519 #endif 520 520
+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_ */
+3 -3
include/linux/iommu.h
··· 30 30 #define IOMMU_WRITE (1 << 1) 31 31 #define IOMMU_CACHE (1 << 2) /* DMA cache coherency */ 32 32 #define IOMMU_NOEXEC (1 << 3) 33 + #define IOMMU_MMIO (1 << 4) /* e.g. things like MSI doorbells */ 33 34 34 35 struct iommu_ops; 35 36 struct iommu_group; ··· 79 78 struct iommu_domain { 80 79 unsigned type; 81 80 const struct iommu_ops *ops; 81 + unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */ 82 82 iommu_fault_handler_t handler; 83 83 void *handler_token; 84 84 struct iommu_domain_geometry geometry; ··· 157 155 * @domain_set_windows: Set the number of windows for a domain 158 156 * @domain_get_windows: Return the number of windows for a domain 159 157 * @of_xlate: add OF master IDs to iommu grouping 160 - * @pgsize_bitmap: bitmap of supported page sizes 161 - * @priv: per-instance data private to the iommu driver 158 + * @pgsize_bitmap: bitmap of all possible supported page sizes 162 159 */ 163 160 struct iommu_ops { 164 161 bool (*capable)(enum iommu_cap); ··· 199 198 int (*of_xlate)(struct device *dev, struct of_phandle_args *args); 200 199 201 200 unsigned long pgsize_bitmap; 202 - void *priv; 203 201 }; 204 202 205 203 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
+4 -4
include/linux/of_iommu.h
··· 12 12 size_t *size); 13 13 14 14 extern void of_iommu_init(void); 15 - extern struct iommu_ops *of_iommu_configure(struct device *dev, 15 + extern const struct iommu_ops *of_iommu_configure(struct device *dev, 16 16 struct device_node *master_np); 17 17 18 18 #else ··· 25 25 } 26 26 27 27 static inline void of_iommu_init(void) { } 28 - static inline struct iommu_ops *of_iommu_configure(struct device *dev, 28 + static inline const struct iommu_ops *of_iommu_configure(struct device *dev, 29 29 struct device_node *master_np) 30 30 { 31 31 return NULL; ··· 33 33 34 34 #endif /* CONFIG_OF_IOMMU */ 35 35 36 - void of_iommu_set_ops(struct device_node *np, struct iommu_ops *ops); 37 - struct iommu_ops *of_iommu_get_ops(struct device_node *np); 36 + void of_iommu_set_ops(struct device_node *np, const struct iommu_ops *ops); 37 + const struct iommu_ops *of_iommu_get_ops(struct device_node *np); 38 38 39 39 extern struct of_device_id __iommu_of_table; 40 40