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

Merge branches 'arm/mediatek', 'arm/smmu', 'x86/amd', 's390', 'core' and 'arm/exynos' into next

+2624 -455
+12
Documentation/ABI/testing/sysfs-devices-deferred_probe
··· 1 + What: /sys/devices/.../deferred_probe 2 + Date: August 2016 3 + Contact: Ben Hutchings <ben.hutchings@codethink.co.uk> 4 + Description: 5 + The /sys/devices/.../deferred_probe attribute is 6 + present for all devices. If a driver detects during 7 + probing a device that a related device is not yet 8 + ready, it may defer probing of the first device. The 9 + kernel will retry probing the first device after any 10 + other device is successfully probed. This attribute 11 + reads as 1 if probing of this device is currently 12 + deferred, or 0 otherwise.
+2
arch/arm64/mm/dma-mapping.c
··· 796 796 .sync_single_for_device = __iommu_sync_single_for_device, 797 797 .sync_sg_for_cpu = __iommu_sync_sg_for_cpu, 798 798 .sync_sg_for_device = __iommu_sync_sg_for_device, 799 + .map_resource = iommu_dma_map_resource, 800 + .unmap_resource = iommu_dma_unmap_resource, 799 801 .dma_supported = iommu_dma_supported, 800 802 .mapping_error = iommu_dma_mapping_error, 801 803 };
+2
arch/x86/kernel/cpu/intel_cacheinfo.c
··· 934 934 ci_leaf_init(this_leaf++, &id4_regs); 935 935 __cache_cpumap_setup(cpu, idx, &id4_regs); 936 936 } 937 + this_cpu_ci->cpu_map_populated = true; 938 + 937 939 return 0; 938 940 } 939 941
+600 -7
drivers/acpi/arm64/iort.c
··· 19 19 #define pr_fmt(fmt) "ACPI: IORT: " fmt 20 20 21 21 #include <linux/acpi_iort.h> 22 + #include <linux/iommu.h> 22 23 #include <linux/kernel.h> 24 + #include <linux/list.h> 23 25 #include <linux/pci.h> 26 + #include <linux/platform_device.h> 27 + #include <linux/slab.h> 28 + 29 + #define IORT_TYPE_MASK(type) (1 << (type)) 30 + #define IORT_MSI_TYPE (1 << ACPI_IORT_NODE_ITS_GROUP) 31 + #define IORT_IOMMU_TYPE ((1 << ACPI_IORT_NODE_SMMU) | \ 32 + (1 << ACPI_IORT_NODE_SMMU_V3)) 24 33 25 34 struct iort_its_msi_chip { 26 35 struct list_head list; 27 36 struct fwnode_handle *fw_node; 28 37 u32 translation_id; 29 38 }; 39 + 40 + struct iort_fwnode { 41 + struct list_head list; 42 + struct acpi_iort_node *iort_node; 43 + struct fwnode_handle *fwnode; 44 + }; 45 + static LIST_HEAD(iort_fwnode_list); 46 + static DEFINE_SPINLOCK(iort_fwnode_lock); 47 + 48 + /** 49 + * iort_set_fwnode() - Create iort_fwnode and use it to register 50 + * iommu data in the iort_fwnode_list 51 + * 52 + * @node: IORT table node associated with the IOMMU 53 + * @fwnode: fwnode associated with the IORT node 54 + * 55 + * Returns: 0 on success 56 + * <0 on failure 57 + */ 58 + static inline int iort_set_fwnode(struct acpi_iort_node *iort_node, 59 + struct fwnode_handle *fwnode) 60 + { 61 + struct iort_fwnode *np; 62 + 63 + np = kzalloc(sizeof(struct iort_fwnode), GFP_ATOMIC); 64 + 65 + if (WARN_ON(!np)) 66 + return -ENOMEM; 67 + 68 + INIT_LIST_HEAD(&np->list); 69 + np->iort_node = iort_node; 70 + np->fwnode = fwnode; 71 + 72 + spin_lock(&iort_fwnode_lock); 73 + list_add_tail(&np->list, &iort_fwnode_list); 74 + spin_unlock(&iort_fwnode_lock); 75 + 76 + return 0; 77 + } 78 + 79 + /** 80 + * iort_get_fwnode() - Retrieve fwnode associated with an IORT node 81 + * 82 + * @node: IORT table node to be looked-up 83 + * 84 + * Returns: fwnode_handle pointer on success, NULL on failure 85 + */ 86 + static inline 87 + struct fwnode_handle *iort_get_fwnode(struct acpi_iort_node *node) 88 + { 89 + struct iort_fwnode *curr; 90 + struct fwnode_handle *fwnode = NULL; 91 + 92 + spin_lock(&iort_fwnode_lock); 93 + list_for_each_entry(curr, &iort_fwnode_list, list) { 94 + if (curr->iort_node == node) { 95 + fwnode = curr->fwnode; 96 + break; 97 + } 98 + } 99 + spin_unlock(&iort_fwnode_lock); 100 + 101 + return fwnode; 102 + } 103 + 104 + /** 105 + * iort_delete_fwnode() - Delete fwnode associated with an IORT node 106 + * 107 + * @node: IORT table node associated with fwnode to delete 108 + */ 109 + static inline void iort_delete_fwnode(struct acpi_iort_node *node) 110 + { 111 + struct iort_fwnode *curr, *tmp; 112 + 113 + spin_lock(&iort_fwnode_lock); 114 + list_for_each_entry_safe(curr, tmp, &iort_fwnode_list, list) { 115 + if (curr->iort_node == node) { 116 + list_del(&curr->list); 117 + kfree(curr); 118 + break; 119 + } 120 + } 121 + spin_unlock(&iort_fwnode_lock); 122 + } 30 123 31 124 typedef acpi_status (*iort_find_node_callback) 32 125 (struct acpi_iort_node *node, void *context); ··· 234 141 return NULL; 235 142 } 236 143 144 + static acpi_status 145 + iort_match_type_callback(struct acpi_iort_node *node, void *context) 146 + { 147 + return AE_OK; 148 + } 149 + 150 + bool iort_node_match(u8 type) 151 + { 152 + struct acpi_iort_node *node; 153 + 154 + node = iort_scan_node(type, iort_match_type_callback, NULL); 155 + 156 + return node != NULL; 157 + } 158 + 237 159 static acpi_status iort_match_node_callback(struct acpi_iort_node *node, 238 160 void *context) 239 161 { ··· 320 212 return 0; 321 213 } 322 214 215 + static 216 + struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node, 217 + u32 *id_out, u8 type_mask, 218 + int index) 219 + { 220 + struct acpi_iort_node *parent; 221 + struct acpi_iort_id_mapping *map; 222 + 223 + if (!node->mapping_offset || !node->mapping_count || 224 + index >= node->mapping_count) 225 + return NULL; 226 + 227 + map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, 228 + node->mapping_offset); 229 + 230 + /* Firmware bug! */ 231 + if (!map->output_reference) { 232 + pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", 233 + node, node->type); 234 + return NULL; 235 + } 236 + 237 + parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, 238 + map->output_reference); 239 + 240 + if (!(IORT_TYPE_MASK(parent->type) & type_mask)) 241 + return NULL; 242 + 243 + if (map[index].flags & ACPI_IORT_ID_SINGLE_MAPPING) { 244 + if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || 245 + node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { 246 + *id_out = map[index].output_base; 247 + return parent; 248 + } 249 + } 250 + 251 + return NULL; 252 + } 253 + 323 254 static struct acpi_iort_node *iort_node_map_rid(struct acpi_iort_node *node, 324 255 u32 rid_in, u32 *rid_out, 325 - u8 type) 256 + u8 type_mask) 326 257 { 327 258 u32 rid = rid_in; 328 259 ··· 370 223 struct acpi_iort_id_mapping *map; 371 224 int i; 372 225 373 - if (node->type == type) { 226 + if (IORT_TYPE_MASK(node->type) & type_mask) { 374 227 if (rid_out) 375 228 *rid_out = rid; 376 229 return node; ··· 443 296 if (!node) 444 297 return req_id; 445 298 446 - iort_node_map_rid(node, req_id, &dev_id, ACPI_IORT_NODE_ITS_GROUP); 299 + iort_node_map_rid(node, req_id, &dev_id, IORT_MSI_TYPE); 447 300 return dev_id; 448 301 } 449 302 ··· 465 318 if (!node) 466 319 return -ENXIO; 467 320 468 - node = iort_node_map_rid(node, req_id, NULL, ACPI_IORT_NODE_ITS_GROUP); 321 + node = iort_node_map_rid(node, req_id, NULL, IORT_MSI_TYPE); 469 322 if (!node) 470 323 return -ENXIO; 471 324 ··· 503 356 return irq_find_matching_fwnode(handle, DOMAIN_BUS_PCI_MSI); 504 357 } 505 358 359 + static int __get_pci_rid(struct pci_dev *pdev, u16 alias, void *data) 360 + { 361 + u32 *rid = data; 362 + 363 + *rid = alias; 364 + return 0; 365 + } 366 + 367 + static int arm_smmu_iort_xlate(struct device *dev, u32 streamid, 368 + struct fwnode_handle *fwnode, 369 + const struct iommu_ops *ops) 370 + { 371 + int ret = iommu_fwspec_init(dev, fwnode, ops); 372 + 373 + if (!ret) 374 + ret = iommu_fwspec_add_ids(dev, &streamid, 1); 375 + 376 + return ret; 377 + } 378 + 379 + static const struct iommu_ops *iort_iommu_xlate(struct device *dev, 380 + struct acpi_iort_node *node, 381 + u32 streamid) 382 + { 383 + const struct iommu_ops *ops = NULL; 384 + int ret = -ENODEV; 385 + struct fwnode_handle *iort_fwnode; 386 + 387 + if (node) { 388 + iort_fwnode = iort_get_fwnode(node); 389 + if (!iort_fwnode) 390 + return NULL; 391 + 392 + ops = iommu_get_instance(iort_fwnode); 393 + if (!ops) 394 + return NULL; 395 + 396 + ret = arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops); 397 + } 398 + 399 + return ret ? NULL : ops; 400 + } 401 + 402 + /** 403 + * iort_set_dma_mask - Set-up dma mask for a device. 404 + * 405 + * @dev: device to configure 406 + */ 407 + void iort_set_dma_mask(struct device *dev) 408 + { 409 + /* 410 + * Set default coherent_dma_mask to 32 bit. Drivers are expected to 411 + * setup the correct supported mask. 412 + */ 413 + if (!dev->coherent_dma_mask) 414 + dev->coherent_dma_mask = DMA_BIT_MASK(32); 415 + 416 + /* 417 + * Set it to coherent_dma_mask by default if the architecture 418 + * code has not set it. 419 + */ 420 + if (!dev->dma_mask) 421 + dev->dma_mask = &dev->coherent_dma_mask; 422 + } 423 + 424 + /** 425 + * iort_iommu_configure - Set-up IOMMU configuration for a device. 426 + * 427 + * @dev: device to configure 428 + * 429 + * Returns: iommu_ops pointer on configuration success 430 + * NULL on configuration failure 431 + */ 432 + const struct iommu_ops *iort_iommu_configure(struct device *dev) 433 + { 434 + struct acpi_iort_node *node, *parent; 435 + const struct iommu_ops *ops = NULL; 436 + u32 streamid = 0; 437 + 438 + if (dev_is_pci(dev)) { 439 + struct pci_bus *bus = to_pci_dev(dev)->bus; 440 + u32 rid; 441 + 442 + pci_for_each_dma_alias(to_pci_dev(dev), __get_pci_rid, 443 + &rid); 444 + 445 + node = iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX, 446 + iort_match_node_callback, &bus->dev); 447 + if (!node) 448 + return NULL; 449 + 450 + parent = iort_node_map_rid(node, rid, &streamid, 451 + IORT_IOMMU_TYPE); 452 + 453 + ops = iort_iommu_xlate(dev, parent, streamid); 454 + 455 + } else { 456 + int i = 0; 457 + 458 + node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, 459 + iort_match_node_callback, dev); 460 + if (!node) 461 + return NULL; 462 + 463 + parent = iort_node_get_id(node, &streamid, 464 + IORT_IOMMU_TYPE, i++); 465 + 466 + while (parent) { 467 + ops = iort_iommu_xlate(dev, parent, streamid); 468 + 469 + parent = iort_node_get_id(node, &streamid, 470 + IORT_IOMMU_TYPE, i++); 471 + } 472 + } 473 + 474 + return ops; 475 + } 476 + 477 + static void __init acpi_iort_register_irq(int hwirq, const char *name, 478 + int trigger, 479 + struct resource *res) 480 + { 481 + int irq = acpi_register_gsi(NULL, hwirq, trigger, 482 + ACPI_ACTIVE_HIGH); 483 + 484 + if (irq <= 0) { 485 + pr_err("could not register gsi hwirq %d name [%s]\n", hwirq, 486 + name); 487 + return; 488 + } 489 + 490 + res->start = irq; 491 + res->end = irq; 492 + res->flags = IORESOURCE_IRQ; 493 + res->name = name; 494 + } 495 + 496 + static int __init arm_smmu_v3_count_resources(struct acpi_iort_node *node) 497 + { 498 + struct acpi_iort_smmu_v3 *smmu; 499 + /* Always present mem resource */ 500 + int num_res = 1; 501 + 502 + /* Retrieve SMMUv3 specific data */ 503 + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; 504 + 505 + if (smmu->event_gsiv) 506 + num_res++; 507 + 508 + if (smmu->pri_gsiv) 509 + num_res++; 510 + 511 + if (smmu->gerr_gsiv) 512 + num_res++; 513 + 514 + if (smmu->sync_gsiv) 515 + num_res++; 516 + 517 + return num_res; 518 + } 519 + 520 + static void __init arm_smmu_v3_init_resources(struct resource *res, 521 + struct acpi_iort_node *node) 522 + { 523 + struct acpi_iort_smmu_v3 *smmu; 524 + int num_res = 0; 525 + 526 + /* Retrieve SMMUv3 specific data */ 527 + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; 528 + 529 + res[num_res].start = smmu->base_address; 530 + res[num_res].end = smmu->base_address + SZ_128K - 1; 531 + res[num_res].flags = IORESOURCE_MEM; 532 + 533 + num_res++; 534 + 535 + if (smmu->event_gsiv) 536 + acpi_iort_register_irq(smmu->event_gsiv, "eventq", 537 + ACPI_EDGE_SENSITIVE, 538 + &res[num_res++]); 539 + 540 + if (smmu->pri_gsiv) 541 + acpi_iort_register_irq(smmu->pri_gsiv, "priq", 542 + ACPI_EDGE_SENSITIVE, 543 + &res[num_res++]); 544 + 545 + if (smmu->gerr_gsiv) 546 + acpi_iort_register_irq(smmu->gerr_gsiv, "gerror", 547 + ACPI_EDGE_SENSITIVE, 548 + &res[num_res++]); 549 + 550 + if (smmu->sync_gsiv) 551 + acpi_iort_register_irq(smmu->sync_gsiv, "cmdq-sync", 552 + ACPI_EDGE_SENSITIVE, 553 + &res[num_res++]); 554 + } 555 + 556 + static bool __init arm_smmu_v3_is_coherent(struct acpi_iort_node *node) 557 + { 558 + struct acpi_iort_smmu_v3 *smmu; 559 + 560 + /* Retrieve SMMUv3 specific data */ 561 + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; 562 + 563 + return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE; 564 + } 565 + 566 + static int __init arm_smmu_count_resources(struct acpi_iort_node *node) 567 + { 568 + struct acpi_iort_smmu *smmu; 569 + 570 + /* Retrieve SMMU specific data */ 571 + smmu = (struct acpi_iort_smmu *)node->node_data; 572 + 573 + /* 574 + * Only consider the global fault interrupt and ignore the 575 + * configuration access interrupt. 576 + * 577 + * MMIO address and global fault interrupt resources are always 578 + * present so add them to the context interrupt count as a static 579 + * value. 580 + */ 581 + return smmu->context_interrupt_count + 2; 582 + } 583 + 584 + static void __init arm_smmu_init_resources(struct resource *res, 585 + struct acpi_iort_node *node) 586 + { 587 + struct acpi_iort_smmu *smmu; 588 + int i, hw_irq, trigger, num_res = 0; 589 + u64 *ctx_irq, *glb_irq; 590 + 591 + /* Retrieve SMMU specific data */ 592 + smmu = (struct acpi_iort_smmu *)node->node_data; 593 + 594 + res[num_res].start = smmu->base_address; 595 + res[num_res].end = smmu->base_address + smmu->span - 1; 596 + res[num_res].flags = IORESOURCE_MEM; 597 + num_res++; 598 + 599 + glb_irq = ACPI_ADD_PTR(u64, node, smmu->global_interrupt_offset); 600 + /* Global IRQs */ 601 + hw_irq = IORT_IRQ_MASK(glb_irq[0]); 602 + trigger = IORT_IRQ_TRIGGER_MASK(glb_irq[0]); 603 + 604 + acpi_iort_register_irq(hw_irq, "arm-smmu-global", trigger, 605 + &res[num_res++]); 606 + 607 + /* Context IRQs */ 608 + ctx_irq = ACPI_ADD_PTR(u64, node, smmu->context_interrupt_offset); 609 + for (i = 0; i < smmu->context_interrupt_count; i++) { 610 + hw_irq = IORT_IRQ_MASK(ctx_irq[i]); 611 + trigger = IORT_IRQ_TRIGGER_MASK(ctx_irq[i]); 612 + 613 + acpi_iort_register_irq(hw_irq, "arm-smmu-context", trigger, 614 + &res[num_res++]); 615 + } 616 + } 617 + 618 + static bool __init arm_smmu_is_coherent(struct acpi_iort_node *node) 619 + { 620 + struct acpi_iort_smmu *smmu; 621 + 622 + /* Retrieve SMMU specific data */ 623 + smmu = (struct acpi_iort_smmu *)node->node_data; 624 + 625 + return smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK; 626 + } 627 + 628 + struct iort_iommu_config { 629 + const char *name; 630 + int (*iommu_init)(struct acpi_iort_node *node); 631 + bool (*iommu_is_coherent)(struct acpi_iort_node *node); 632 + int (*iommu_count_resources)(struct acpi_iort_node *node); 633 + void (*iommu_init_resources)(struct resource *res, 634 + struct acpi_iort_node *node); 635 + }; 636 + 637 + static const struct iort_iommu_config iort_arm_smmu_v3_cfg __initconst = { 638 + .name = "arm-smmu-v3", 639 + .iommu_is_coherent = arm_smmu_v3_is_coherent, 640 + .iommu_count_resources = arm_smmu_v3_count_resources, 641 + .iommu_init_resources = arm_smmu_v3_init_resources 642 + }; 643 + 644 + static const struct iort_iommu_config iort_arm_smmu_cfg __initconst = { 645 + .name = "arm-smmu", 646 + .iommu_is_coherent = arm_smmu_is_coherent, 647 + .iommu_count_resources = arm_smmu_count_resources, 648 + .iommu_init_resources = arm_smmu_init_resources 649 + }; 650 + 651 + static __init 652 + const struct iort_iommu_config *iort_get_iommu_cfg(struct acpi_iort_node *node) 653 + { 654 + switch (node->type) { 655 + case ACPI_IORT_NODE_SMMU_V3: 656 + return &iort_arm_smmu_v3_cfg; 657 + case ACPI_IORT_NODE_SMMU: 658 + return &iort_arm_smmu_cfg; 659 + default: 660 + return NULL; 661 + } 662 + } 663 + 664 + /** 665 + * iort_add_smmu_platform_device() - Allocate a platform device for SMMU 666 + * @node: Pointer to SMMU ACPI IORT node 667 + * 668 + * Returns: 0 on success, <0 failure 669 + */ 670 + static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node) 671 + { 672 + struct fwnode_handle *fwnode; 673 + struct platform_device *pdev; 674 + struct resource *r; 675 + enum dev_dma_attr attr; 676 + int ret, count; 677 + const struct iort_iommu_config *ops = iort_get_iommu_cfg(node); 678 + 679 + if (!ops) 680 + return -ENODEV; 681 + 682 + pdev = platform_device_alloc(ops->name, PLATFORM_DEVID_AUTO); 683 + if (!pdev) 684 + return PTR_ERR(pdev); 685 + 686 + count = ops->iommu_count_resources(node); 687 + 688 + r = kcalloc(count, sizeof(*r), GFP_KERNEL); 689 + if (!r) { 690 + ret = -ENOMEM; 691 + goto dev_put; 692 + } 693 + 694 + ops->iommu_init_resources(r, node); 695 + 696 + ret = platform_device_add_resources(pdev, r, count); 697 + /* 698 + * Resources are duplicated in platform_device_add_resources, 699 + * free their allocated memory 700 + */ 701 + kfree(r); 702 + 703 + if (ret) 704 + goto dev_put; 705 + 706 + /* 707 + * Add a copy of IORT node pointer to platform_data to 708 + * be used to retrieve IORT data information. 709 + */ 710 + ret = platform_device_add_data(pdev, &node, sizeof(node)); 711 + if (ret) 712 + goto dev_put; 713 + 714 + /* 715 + * We expect the dma masks to be equivalent for 716 + * all SMMUs set-ups 717 + */ 718 + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; 719 + 720 + fwnode = iort_get_fwnode(node); 721 + 722 + if (!fwnode) { 723 + ret = -ENODEV; 724 + goto dev_put; 725 + } 726 + 727 + pdev->dev.fwnode = fwnode; 728 + 729 + attr = ops->iommu_is_coherent(node) ? 730 + DEV_DMA_COHERENT : DEV_DMA_NON_COHERENT; 731 + 732 + /* Configure DMA for the page table walker */ 733 + acpi_dma_configure(&pdev->dev, attr); 734 + 735 + ret = platform_device_add(pdev); 736 + if (ret) 737 + goto dma_deconfigure; 738 + 739 + return 0; 740 + 741 + dma_deconfigure: 742 + acpi_dma_deconfigure(&pdev->dev); 743 + dev_put: 744 + platform_device_put(pdev); 745 + 746 + return ret; 747 + } 748 + 749 + static void __init iort_init_platform_devices(void) 750 + { 751 + struct acpi_iort_node *iort_node, *iort_end; 752 + struct acpi_table_iort *iort; 753 + struct fwnode_handle *fwnode; 754 + int i, ret; 755 + 756 + /* 757 + * iort_table and iort both point to the start of IORT table, but 758 + * have different struct types 759 + */ 760 + iort = (struct acpi_table_iort *)iort_table; 761 + 762 + /* Get the first IORT node */ 763 + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, 764 + iort->node_offset); 765 + iort_end = ACPI_ADD_PTR(struct acpi_iort_node, iort, 766 + iort_table->length); 767 + 768 + for (i = 0; i < iort->node_count; i++) { 769 + if (iort_node >= iort_end) { 770 + pr_err("iort node pointer overflows, bad table\n"); 771 + return; 772 + } 773 + 774 + if ((iort_node->type == ACPI_IORT_NODE_SMMU) || 775 + (iort_node->type == ACPI_IORT_NODE_SMMU_V3)) { 776 + 777 + fwnode = acpi_alloc_fwnode_static(); 778 + if (!fwnode) 779 + return; 780 + 781 + iort_set_fwnode(iort_node, fwnode); 782 + 783 + ret = iort_add_smmu_platform_device(iort_node); 784 + if (ret) { 785 + iort_delete_fwnode(iort_node); 786 + acpi_free_fwnode_static(fwnode); 787 + return; 788 + } 789 + } 790 + 791 + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, 792 + iort_node->length); 793 + } 794 + } 795 + 506 796 void __init acpi_iort_init(void) 507 797 { 508 798 acpi_status status; 509 799 510 800 status = acpi_get_table(ACPI_SIG_IORT, 0, &iort_table); 511 - if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 512 - const char *msg = acpi_format_exception(status); 513 - pr_err("Failed to get table, %s\n", msg); 801 + if (ACPI_FAILURE(status)) { 802 + if (status != AE_NOT_FOUND) { 803 + const char *msg = acpi_format_exception(status); 804 + 805 + pr_err("Failed to get table, %s\n", msg); 806 + } 807 + 808 + return; 514 809 } 810 + 811 + iort_init_platform_devices(); 812 + 813 + acpi_probe_device_table(iort); 515 814 }
+2 -2
drivers/acpi/glue.c
··· 227 227 228 228 attr = acpi_get_dma_attr(acpi_dev); 229 229 if (attr != DEV_DMA_NOT_SUPPORTED) 230 - arch_setup_dma_ops(dev, 0, 0, NULL, 231 - attr == DEV_DMA_COHERENT); 230 + acpi_dma_configure(dev, attr); 232 231 233 232 acpi_physnode_link_name(physical_node_name, node_id); 234 233 retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, ··· 250 251 return 0; 251 252 252 253 err: 254 + acpi_dma_deconfigure(dev); 253 255 ACPI_COMPANION_SET(dev, NULL); 254 256 put_device(dev); 255 257 put_device(&acpi_dev->dev);
+33
drivers/acpi/scan.c
··· 7 7 #include <linux/slab.h> 8 8 #include <linux/kernel.h> 9 9 #include <linux/acpi.h> 10 + #include <linux/acpi_iort.h> 10 11 #include <linux/signal.h> 11 12 #include <linux/kthread.h> 12 13 #include <linux/dmi.h> ··· 1370 1369 else 1371 1370 return DEV_DMA_NON_COHERENT; 1372 1371 } 1372 + 1373 + /** 1374 + * acpi_dma_configure - Set-up DMA configuration for the device. 1375 + * @dev: The pointer to the device 1376 + * @attr: device dma attributes 1377 + */ 1378 + void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) 1379 + { 1380 + const struct iommu_ops *iommu; 1381 + 1382 + iort_set_dma_mask(dev); 1383 + 1384 + iommu = iort_iommu_configure(dev); 1385 + 1386 + /* 1387 + * Assume dma valid range starts at 0 and covers the whole 1388 + * coherent_dma_mask. 1389 + */ 1390 + arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu, 1391 + attr == DEV_DMA_COHERENT); 1392 + } 1393 + EXPORT_SYMBOL_GPL(acpi_dma_configure); 1394 + 1395 + /** 1396 + * acpi_dma_deconfigure - Tear-down DMA configuration for the device. 1397 + * @dev: The pointer to the device 1398 + */ 1399 + void acpi_dma_deconfigure(struct device *dev) 1400 + { 1401 + arch_teardown_dma_ops(dev); 1402 + } 1403 + EXPORT_SYMBOL_GPL(acpi_dma_deconfigure); 1373 1404 1374 1405 static void acpi_init_coherency(struct acpi_device *adev) 1375 1406 {
+2
drivers/base/Kconfig
··· 224 224 unusable. You should say N here unless you are explicitly looking to 225 225 test this functionality. 226 226 227 + source "drivers/base/test/Kconfig" 228 + 227 229 config SYS_HYPERVISOR 228 230 bool 229 231 default n
+2
drivers/base/Makefile
··· 24 24 obj-$(CONFIG_DEV_COREDUMP) += devcoredump.o 25 25 obj-$(CONFIG_GENERIC_MSI_IRQ_DOMAIN) += platform-msi.o 26 26 27 + obj-y += test/ 28 + 27 29 ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG 28 30
+15
drivers/base/base.h
··· 107 107 108 108 extern int bus_add_driver(struct device_driver *drv); 109 109 extern void bus_remove_driver(struct device_driver *drv); 110 + extern void device_release_driver_internal(struct device *dev, 111 + struct device_driver *drv, 112 + struct device *parent); 110 113 111 114 extern void driver_detach(struct device_driver *drv); 112 115 extern int driver_probe_device(struct device_driver *drv, struct device *dev); ··· 141 138 extern struct kset *devices_kset; 142 139 extern void devices_kset_move_last(struct device *dev); 143 140 141 + extern struct device_attribute dev_attr_deferred_probe; 142 + 144 143 #if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS) 145 144 extern void module_add_driver(struct module *mod, struct device_driver *drv); 146 145 extern void module_remove_driver(struct device_driver *drv); ··· 157 152 #else 158 153 static inline int devtmpfs_init(void) { return 0; } 159 154 #endif 155 + 156 + /* Device links support */ 157 + extern int device_links_read_lock(void); 158 + extern void device_links_read_unlock(int idx); 159 + extern int device_links_check_suppliers(struct device *dev); 160 + extern void device_links_driver_bound(struct device *dev); 161 + extern void device_links_driver_cleanup(struct device *dev); 162 + extern void device_links_no_driver(struct device *dev); 163 + extern bool device_links_busy(struct device *dev); 164 + extern void device_links_unbind_consumers(struct device *dev);
+134 -4
drivers/base/cacheinfo.c
··· 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 18 */ 19 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20 + 21 + #include <linux/acpi.h> 19 22 #include <linux/bitops.h> 20 23 #include <linux/cacheinfo.h> 21 24 #include <linux/compiler.h> ··· 88 85 { 89 86 return sib_leaf->of_node == this_leaf->of_node; 90 87 } 88 + 89 + /* OF properties to query for a given cache type */ 90 + struct cache_type_info { 91 + const char *size_prop; 92 + const char *line_size_props[2]; 93 + const char *nr_sets_prop; 94 + }; 95 + 96 + static const struct cache_type_info cache_type_info[] = { 97 + { 98 + .size_prop = "cache-size", 99 + .line_size_props = { "cache-line-size", 100 + "cache-block-size", }, 101 + .nr_sets_prop = "cache-sets", 102 + }, { 103 + .size_prop = "i-cache-size", 104 + .line_size_props = { "i-cache-line-size", 105 + "i-cache-block-size", }, 106 + .nr_sets_prop = "i-cache-sets", 107 + }, { 108 + .size_prop = "d-cache-size", 109 + .line_size_props = { "d-cache-line-size", 110 + "d-cache-block-size", }, 111 + .nr_sets_prop = "d-cache-sets", 112 + }, 113 + }; 114 + 115 + static inline int get_cacheinfo_idx(enum cache_type type) 116 + { 117 + if (type == CACHE_TYPE_UNIFIED) 118 + return 0; 119 + return type; 120 + } 121 + 122 + static void cache_size(struct cacheinfo *this_leaf) 123 + { 124 + const char *propname; 125 + const __be32 *cache_size; 126 + int ct_idx; 127 + 128 + ct_idx = get_cacheinfo_idx(this_leaf->type); 129 + propname = cache_type_info[ct_idx].size_prop; 130 + 131 + cache_size = of_get_property(this_leaf->of_node, propname, NULL); 132 + if (cache_size) 133 + this_leaf->size = of_read_number(cache_size, 1); 134 + } 135 + 136 + /* not cache_line_size() because that's a macro in include/linux/cache.h */ 137 + static void cache_get_line_size(struct cacheinfo *this_leaf) 138 + { 139 + const __be32 *line_size; 140 + int i, lim, ct_idx; 141 + 142 + ct_idx = get_cacheinfo_idx(this_leaf->type); 143 + lim = ARRAY_SIZE(cache_type_info[ct_idx].line_size_props); 144 + 145 + for (i = 0; i < lim; i++) { 146 + const char *propname; 147 + 148 + propname = cache_type_info[ct_idx].line_size_props[i]; 149 + line_size = of_get_property(this_leaf->of_node, propname, NULL); 150 + if (line_size) 151 + break; 152 + } 153 + 154 + if (line_size) 155 + this_leaf->coherency_line_size = of_read_number(line_size, 1); 156 + } 157 + 158 + static void cache_nr_sets(struct cacheinfo *this_leaf) 159 + { 160 + const char *propname; 161 + const __be32 *nr_sets; 162 + int ct_idx; 163 + 164 + ct_idx = get_cacheinfo_idx(this_leaf->type); 165 + propname = cache_type_info[ct_idx].nr_sets_prop; 166 + 167 + nr_sets = of_get_property(this_leaf->of_node, propname, NULL); 168 + if (nr_sets) 169 + this_leaf->number_of_sets = of_read_number(nr_sets, 1); 170 + } 171 + 172 + static void cache_associativity(struct cacheinfo *this_leaf) 173 + { 174 + unsigned int line_size = this_leaf->coherency_line_size; 175 + unsigned int nr_sets = this_leaf->number_of_sets; 176 + unsigned int size = this_leaf->size; 177 + 178 + /* 179 + * If the cache is fully associative, there is no need to 180 + * check the other properties. 181 + */ 182 + if (!(nr_sets == 1) && (nr_sets > 0 && size > 0 && line_size > 0)) 183 + this_leaf->ways_of_associativity = (size / nr_sets) / line_size; 184 + } 185 + 186 + static void cache_of_override_properties(unsigned int cpu) 187 + { 188 + int index; 189 + struct cacheinfo *this_leaf; 190 + struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); 191 + 192 + for (index = 0; index < cache_leaves(cpu); index++) { 193 + this_leaf = this_cpu_ci->info_list + index; 194 + cache_size(this_leaf); 195 + cache_get_line_size(this_leaf); 196 + cache_nr_sets(this_leaf); 197 + cache_associativity(this_leaf); 198 + } 199 + } 91 200 #else 201 + static void cache_of_override_properties(unsigned int cpu) { } 92 202 static inline int cache_setup_of_node(unsigned int cpu) { return 0; } 93 203 static inline bool cache_leaves_are_shared(struct cacheinfo *this_leaf, 94 204 struct cacheinfo *sib_leaf) ··· 220 104 struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu); 221 105 struct cacheinfo *this_leaf, *sib_leaf; 222 106 unsigned int index; 223 - int ret; 107 + int ret = 0; 224 108 225 - ret = cache_setup_of_node(cpu); 109 + if (this_cpu_ci->cpu_map_populated) 110 + return 0; 111 + 112 + if (of_have_populated_dt()) 113 + ret = cache_setup_of_node(cpu); 114 + else if (!acpi_disabled) 115 + /* No cache property/hierarchy support yet in ACPI */ 116 + ret = -ENOTSUPP; 226 117 if (ret) 227 118 return ret; 228 119 ··· 284 161 } 285 162 } 286 163 164 + static void cache_override_properties(unsigned int cpu) 165 + { 166 + if (of_have_populated_dt()) 167 + return cache_of_override_properties(cpu); 168 + } 169 + 287 170 static void free_cache_attributes(unsigned int cpu) 288 171 { 289 172 if (!per_cpu_cacheinfo(cpu)) ··· 332 203 */ 333 204 ret = cache_shared_cpu_map_setup(cpu); 334 205 if (ret) { 335 - pr_warn("Unable to detect cache hierarchy from DT for CPU %d\n", 336 - cpu); 206 + pr_warn("Unable to detect cache hierarchy for CPU %d\n", cpu); 337 207 goto free_ci; 338 208 } 209 + 210 + cache_override_properties(cpu); 339 211 return 0; 340 212 341 213 free_ci:
+578
drivers/base/core.c
··· 44 44 early_param("sysfs.deprecated", sysfs_deprecated_setup); 45 45 #endif 46 46 47 + /* Device links support. */ 48 + 49 + #ifdef CONFIG_SRCU 50 + static DEFINE_MUTEX(device_links_lock); 51 + DEFINE_STATIC_SRCU(device_links_srcu); 52 + 53 + static inline void device_links_write_lock(void) 54 + { 55 + mutex_lock(&device_links_lock); 56 + } 57 + 58 + static inline void device_links_write_unlock(void) 59 + { 60 + mutex_unlock(&device_links_lock); 61 + } 62 + 63 + int device_links_read_lock(void) 64 + { 65 + return srcu_read_lock(&device_links_srcu); 66 + } 67 + 68 + void device_links_read_unlock(int idx) 69 + { 70 + srcu_read_unlock(&device_links_srcu, idx); 71 + } 72 + #else /* !CONFIG_SRCU */ 73 + static DECLARE_RWSEM(device_links_lock); 74 + 75 + static inline void device_links_write_lock(void) 76 + { 77 + down_write(&device_links_lock); 78 + } 79 + 80 + static inline void device_links_write_unlock(void) 81 + { 82 + up_write(&device_links_lock); 83 + } 84 + 85 + int device_links_read_lock(void) 86 + { 87 + down_read(&device_links_lock); 88 + return 0; 89 + } 90 + 91 + void device_links_read_unlock(int not_used) 92 + { 93 + up_read(&device_links_lock); 94 + } 95 + #endif /* !CONFIG_SRCU */ 96 + 97 + /** 98 + * device_is_dependent - Check if one device depends on another one 99 + * @dev: Device to check dependencies for. 100 + * @target: Device to check against. 101 + * 102 + * Check if @target depends on @dev or any device dependent on it (its child or 103 + * its consumer etc). Return 1 if that is the case or 0 otherwise. 104 + */ 105 + static int device_is_dependent(struct device *dev, void *target) 106 + { 107 + struct device_link *link; 108 + int ret; 109 + 110 + if (WARN_ON(dev == target)) 111 + return 1; 112 + 113 + ret = device_for_each_child(dev, target, device_is_dependent); 114 + if (ret) 115 + return ret; 116 + 117 + list_for_each_entry(link, &dev->links.consumers, s_node) { 118 + if (WARN_ON(link->consumer == target)) 119 + return 1; 120 + 121 + ret = device_is_dependent(link->consumer, target); 122 + if (ret) 123 + break; 124 + } 125 + return ret; 126 + } 127 + 128 + static int device_reorder_to_tail(struct device *dev, void *not_used) 129 + { 130 + struct device_link *link; 131 + 132 + /* 133 + * Devices that have not been registered yet will be put to the ends 134 + * of the lists during the registration, so skip them here. 135 + */ 136 + if (device_is_registered(dev)) 137 + devices_kset_move_last(dev); 138 + 139 + if (device_pm_initialized(dev)) 140 + device_pm_move_last(dev); 141 + 142 + device_for_each_child(dev, NULL, device_reorder_to_tail); 143 + list_for_each_entry(link, &dev->links.consumers, s_node) 144 + device_reorder_to_tail(link->consumer, NULL); 145 + 146 + return 0; 147 + } 148 + 149 + /** 150 + * device_link_add - Create a link between two devices. 151 + * @consumer: Consumer end of the link. 152 + * @supplier: Supplier end of the link. 153 + * @flags: Link flags. 154 + * 155 + * The caller is responsible for the proper synchronization of the link creation 156 + * with runtime PM. First, setting the DL_FLAG_PM_RUNTIME flag will cause the 157 + * runtime PM framework to take the link into account. Second, if the 158 + * DL_FLAG_RPM_ACTIVE flag is set in addition to it, the supplier devices will 159 + * be forced into the active metastate and reference-counted upon the creation 160 + * of the link. If DL_FLAG_PM_RUNTIME is not set, DL_FLAG_RPM_ACTIVE will be 161 + * ignored. 162 + * 163 + * If the DL_FLAG_AUTOREMOVE is set, the link will be removed automatically 164 + * when the consumer device driver unbinds from it. The combination of both 165 + * DL_FLAG_AUTOREMOVE and DL_FLAG_STATELESS set is invalid and will cause NULL 166 + * to be returned. 167 + * 168 + * A side effect of the link creation is re-ordering of dpm_list and the 169 + * devices_kset list by moving the consumer device and all devices depending 170 + * on it to the ends of these lists (that does not happen to devices that have 171 + * not been registered when this function is called). 172 + * 173 + * The supplier device is required to be registered when this function is called 174 + * and NULL will be returned if that is not the case. The consumer device need 175 + * not be registerd, however. 176 + */ 177 + struct device_link *device_link_add(struct device *consumer, 178 + struct device *supplier, u32 flags) 179 + { 180 + struct device_link *link; 181 + 182 + if (!consumer || !supplier || 183 + ((flags & DL_FLAG_STATELESS) && (flags & DL_FLAG_AUTOREMOVE))) 184 + return NULL; 185 + 186 + device_links_write_lock(); 187 + device_pm_lock(); 188 + 189 + /* 190 + * If the supplier has not been fully registered yet or there is a 191 + * reverse dependency between the consumer and the supplier already in 192 + * the graph, return NULL. 193 + */ 194 + if (!device_pm_initialized(supplier) 195 + || device_is_dependent(consumer, supplier)) { 196 + link = NULL; 197 + goto out; 198 + } 199 + 200 + list_for_each_entry(link, &supplier->links.consumers, s_node) 201 + if (link->consumer == consumer) 202 + goto out; 203 + 204 + link = kzalloc(sizeof(*link), GFP_KERNEL); 205 + if (!link) 206 + goto out; 207 + 208 + if (flags & DL_FLAG_PM_RUNTIME) { 209 + if (flags & DL_FLAG_RPM_ACTIVE) { 210 + if (pm_runtime_get_sync(supplier) < 0) { 211 + pm_runtime_put_noidle(supplier); 212 + kfree(link); 213 + link = NULL; 214 + goto out; 215 + } 216 + link->rpm_active = true; 217 + } 218 + pm_runtime_new_link(consumer); 219 + } 220 + get_device(supplier); 221 + link->supplier = supplier; 222 + INIT_LIST_HEAD(&link->s_node); 223 + get_device(consumer); 224 + link->consumer = consumer; 225 + INIT_LIST_HEAD(&link->c_node); 226 + link->flags = flags; 227 + 228 + /* Deterine the initial link state. */ 229 + if (flags & DL_FLAG_STATELESS) { 230 + link->status = DL_STATE_NONE; 231 + } else { 232 + switch (supplier->links.status) { 233 + case DL_DEV_DRIVER_BOUND: 234 + switch (consumer->links.status) { 235 + case DL_DEV_PROBING: 236 + /* 237 + * Balance the decrementation of the supplier's 238 + * runtime PM usage counter after consumer probe 239 + * in driver_probe_device(). 240 + */ 241 + if (flags & DL_FLAG_PM_RUNTIME) 242 + pm_runtime_get_sync(supplier); 243 + 244 + link->status = DL_STATE_CONSUMER_PROBE; 245 + break; 246 + case DL_DEV_DRIVER_BOUND: 247 + link->status = DL_STATE_ACTIVE; 248 + break; 249 + default: 250 + link->status = DL_STATE_AVAILABLE; 251 + break; 252 + } 253 + break; 254 + case DL_DEV_UNBINDING: 255 + link->status = DL_STATE_SUPPLIER_UNBIND; 256 + break; 257 + default: 258 + link->status = DL_STATE_DORMANT; 259 + break; 260 + } 261 + } 262 + 263 + /* 264 + * Move the consumer and all of the devices depending on it to the end 265 + * of dpm_list and the devices_kset list. 266 + * 267 + * It is necessary to hold dpm_list locked throughout all that or else 268 + * we may end up suspending with a wrong ordering of it. 269 + */ 270 + device_reorder_to_tail(consumer, NULL); 271 + 272 + list_add_tail_rcu(&link->s_node, &supplier->links.consumers); 273 + list_add_tail_rcu(&link->c_node, &consumer->links.suppliers); 274 + 275 + dev_info(consumer, "Linked as a consumer to %s\n", dev_name(supplier)); 276 + 277 + out: 278 + device_pm_unlock(); 279 + device_links_write_unlock(); 280 + return link; 281 + } 282 + EXPORT_SYMBOL_GPL(device_link_add); 283 + 284 + static void device_link_free(struct device_link *link) 285 + { 286 + put_device(link->consumer); 287 + put_device(link->supplier); 288 + kfree(link); 289 + } 290 + 291 + #ifdef CONFIG_SRCU 292 + static void __device_link_free_srcu(struct rcu_head *rhead) 293 + { 294 + device_link_free(container_of(rhead, struct device_link, rcu_head)); 295 + } 296 + 297 + static void __device_link_del(struct device_link *link) 298 + { 299 + dev_info(link->consumer, "Dropping the link to %s\n", 300 + dev_name(link->supplier)); 301 + 302 + if (link->flags & DL_FLAG_PM_RUNTIME) 303 + pm_runtime_drop_link(link->consumer); 304 + 305 + list_del_rcu(&link->s_node); 306 + list_del_rcu(&link->c_node); 307 + call_srcu(&device_links_srcu, &link->rcu_head, __device_link_free_srcu); 308 + } 309 + #else /* !CONFIG_SRCU */ 310 + static void __device_link_del(struct device_link *link) 311 + { 312 + dev_info(link->consumer, "Dropping the link to %s\n", 313 + dev_name(link->supplier)); 314 + 315 + list_del(&link->s_node); 316 + list_del(&link->c_node); 317 + device_link_free(link); 318 + } 319 + #endif /* !CONFIG_SRCU */ 320 + 321 + /** 322 + * device_link_del - Delete a link between two devices. 323 + * @link: Device link to delete. 324 + * 325 + * The caller must ensure proper synchronization of this function with runtime 326 + * PM. 327 + */ 328 + void device_link_del(struct device_link *link) 329 + { 330 + device_links_write_lock(); 331 + device_pm_lock(); 332 + __device_link_del(link); 333 + device_pm_unlock(); 334 + device_links_write_unlock(); 335 + } 336 + EXPORT_SYMBOL_GPL(device_link_del); 337 + 338 + static void device_links_missing_supplier(struct device *dev) 339 + { 340 + struct device_link *link; 341 + 342 + list_for_each_entry(link, &dev->links.suppliers, c_node) 343 + if (link->status == DL_STATE_CONSUMER_PROBE) 344 + WRITE_ONCE(link->status, DL_STATE_AVAILABLE); 345 + } 346 + 347 + /** 348 + * device_links_check_suppliers - Check presence of supplier drivers. 349 + * @dev: Consumer device. 350 + * 351 + * Check links from this device to any suppliers. Walk the list of the device's 352 + * links to suppliers and see if all of them are available. If not, simply 353 + * return -EPROBE_DEFER. 354 + * 355 + * We need to guarantee that the supplier will not go away after the check has 356 + * been positive here. It only can go away in __device_release_driver() and 357 + * that function checks the device's links to consumers. This means we need to 358 + * mark the link as "consumer probe in progress" to make the supplier removal 359 + * wait for us to complete (or bad things may happen). 360 + * 361 + * Links with the DL_FLAG_STATELESS flag set are ignored. 362 + */ 363 + int device_links_check_suppliers(struct device *dev) 364 + { 365 + struct device_link *link; 366 + int ret = 0; 367 + 368 + device_links_write_lock(); 369 + 370 + list_for_each_entry(link, &dev->links.suppliers, c_node) { 371 + if (link->flags & DL_FLAG_STATELESS) 372 + continue; 373 + 374 + if (link->status != DL_STATE_AVAILABLE) { 375 + device_links_missing_supplier(dev); 376 + ret = -EPROBE_DEFER; 377 + break; 378 + } 379 + WRITE_ONCE(link->status, DL_STATE_CONSUMER_PROBE); 380 + } 381 + dev->links.status = DL_DEV_PROBING; 382 + 383 + device_links_write_unlock(); 384 + return ret; 385 + } 386 + 387 + /** 388 + * device_links_driver_bound - Update device links after probing its driver. 389 + * @dev: Device to update the links for. 390 + * 391 + * The probe has been successful, so update links from this device to any 392 + * consumers by changing their status to "available". 393 + * 394 + * Also change the status of @dev's links to suppliers to "active". 395 + * 396 + * Links with the DL_FLAG_STATELESS flag set are ignored. 397 + */ 398 + void device_links_driver_bound(struct device *dev) 399 + { 400 + struct device_link *link; 401 + 402 + device_links_write_lock(); 403 + 404 + list_for_each_entry(link, &dev->links.consumers, s_node) { 405 + if (link->flags & DL_FLAG_STATELESS) 406 + continue; 407 + 408 + WARN_ON(link->status != DL_STATE_DORMANT); 409 + WRITE_ONCE(link->status, DL_STATE_AVAILABLE); 410 + } 411 + 412 + list_for_each_entry(link, &dev->links.suppliers, c_node) { 413 + if (link->flags & DL_FLAG_STATELESS) 414 + continue; 415 + 416 + WARN_ON(link->status != DL_STATE_CONSUMER_PROBE); 417 + WRITE_ONCE(link->status, DL_STATE_ACTIVE); 418 + } 419 + 420 + dev->links.status = DL_DEV_DRIVER_BOUND; 421 + 422 + device_links_write_unlock(); 423 + } 424 + 425 + /** 426 + * __device_links_no_driver - Update links of a device without a driver. 427 + * @dev: Device without a drvier. 428 + * 429 + * Delete all non-persistent links from this device to any suppliers. 430 + * 431 + * Persistent links stay around, but their status is changed to "available", 432 + * unless they already are in the "supplier unbind in progress" state in which 433 + * case they need not be updated. 434 + * 435 + * Links with the DL_FLAG_STATELESS flag set are ignored. 436 + */ 437 + static void __device_links_no_driver(struct device *dev) 438 + { 439 + struct device_link *link, *ln; 440 + 441 + list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) { 442 + if (link->flags & DL_FLAG_STATELESS) 443 + continue; 444 + 445 + if (link->flags & DL_FLAG_AUTOREMOVE) 446 + __device_link_del(link); 447 + else if (link->status != DL_STATE_SUPPLIER_UNBIND) 448 + WRITE_ONCE(link->status, DL_STATE_AVAILABLE); 449 + } 450 + 451 + dev->links.status = DL_DEV_NO_DRIVER; 452 + } 453 + 454 + void device_links_no_driver(struct device *dev) 455 + { 456 + device_links_write_lock(); 457 + __device_links_no_driver(dev); 458 + device_links_write_unlock(); 459 + } 460 + 461 + /** 462 + * device_links_driver_cleanup - Update links after driver removal. 463 + * @dev: Device whose driver has just gone away. 464 + * 465 + * Update links to consumers for @dev by changing their status to "dormant" and 466 + * invoke %__device_links_no_driver() to update links to suppliers for it as 467 + * appropriate. 468 + * 469 + * Links with the DL_FLAG_STATELESS flag set are ignored. 470 + */ 471 + void device_links_driver_cleanup(struct device *dev) 472 + { 473 + struct device_link *link; 474 + 475 + device_links_write_lock(); 476 + 477 + list_for_each_entry(link, &dev->links.consumers, s_node) { 478 + if (link->flags & DL_FLAG_STATELESS) 479 + continue; 480 + 481 + WARN_ON(link->flags & DL_FLAG_AUTOREMOVE); 482 + WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND); 483 + WRITE_ONCE(link->status, DL_STATE_DORMANT); 484 + } 485 + 486 + __device_links_no_driver(dev); 487 + 488 + device_links_write_unlock(); 489 + } 490 + 491 + /** 492 + * device_links_busy - Check if there are any busy links to consumers. 493 + * @dev: Device to check. 494 + * 495 + * Check each consumer of the device and return 'true' if its link's status 496 + * is one of "consumer probe" or "active" (meaning that the given consumer is 497 + * probing right now or its driver is present). Otherwise, change the link 498 + * state to "supplier unbind" to prevent the consumer from being probed 499 + * successfully going forward. 500 + * 501 + * Return 'false' if there are no probing or active consumers. 502 + * 503 + * Links with the DL_FLAG_STATELESS flag set are ignored. 504 + */ 505 + bool device_links_busy(struct device *dev) 506 + { 507 + struct device_link *link; 508 + bool ret = false; 509 + 510 + device_links_write_lock(); 511 + 512 + list_for_each_entry(link, &dev->links.consumers, s_node) { 513 + if (link->flags & DL_FLAG_STATELESS) 514 + continue; 515 + 516 + if (link->status == DL_STATE_CONSUMER_PROBE 517 + || link->status == DL_STATE_ACTIVE) { 518 + ret = true; 519 + break; 520 + } 521 + WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND); 522 + } 523 + 524 + dev->links.status = DL_DEV_UNBINDING; 525 + 526 + device_links_write_unlock(); 527 + return ret; 528 + } 529 + 530 + /** 531 + * device_links_unbind_consumers - Force unbind consumers of the given device. 532 + * @dev: Device to unbind the consumers of. 533 + * 534 + * Walk the list of links to consumers for @dev and if any of them is in the 535 + * "consumer probe" state, wait for all device probes in progress to complete 536 + * and start over. 537 + * 538 + * If that's not the case, change the status of the link to "supplier unbind" 539 + * and check if the link was in the "active" state. If so, force the consumer 540 + * driver to unbind and start over (the consumer will not re-probe as we have 541 + * changed the state of the link already). 542 + * 543 + * Links with the DL_FLAG_STATELESS flag set are ignored. 544 + */ 545 + void device_links_unbind_consumers(struct device *dev) 546 + { 547 + struct device_link *link; 548 + 549 + start: 550 + device_links_write_lock(); 551 + 552 + list_for_each_entry(link, &dev->links.consumers, s_node) { 553 + enum device_link_state status; 554 + 555 + if (link->flags & DL_FLAG_STATELESS) 556 + continue; 557 + 558 + status = link->status; 559 + if (status == DL_STATE_CONSUMER_PROBE) { 560 + device_links_write_unlock(); 561 + 562 + wait_for_device_probe(); 563 + goto start; 564 + } 565 + WRITE_ONCE(link->status, DL_STATE_SUPPLIER_UNBIND); 566 + if (status == DL_STATE_ACTIVE) { 567 + struct device *consumer = link->consumer; 568 + 569 + get_device(consumer); 570 + 571 + device_links_write_unlock(); 572 + 573 + device_release_driver_internal(consumer, NULL, 574 + consumer->parent); 575 + put_device(consumer); 576 + goto start; 577 + } 578 + } 579 + 580 + device_links_write_unlock(); 581 + } 582 + 583 + /** 584 + * device_links_purge - Delete existing links to other devices. 585 + * @dev: Target device. 586 + */ 587 + static void device_links_purge(struct device *dev) 588 + { 589 + struct device_link *link, *ln; 590 + 591 + /* 592 + * Delete all of the remaining links from this device to any other 593 + * devices (either consumers or suppliers). 594 + */ 595 + device_links_write_lock(); 596 + 597 + list_for_each_entry_safe_reverse(link, ln, &dev->links.suppliers, c_node) { 598 + WARN_ON(link->status == DL_STATE_ACTIVE); 599 + __device_link_del(link); 600 + } 601 + 602 + list_for_each_entry_safe_reverse(link, ln, &dev->links.consumers, s_node) { 603 + WARN_ON(link->status != DL_STATE_DORMANT && 604 + link->status != DL_STATE_NONE); 605 + __device_link_del(link); 606 + } 607 + 608 + device_links_write_unlock(); 609 + } 610 + 611 + /* Device links support end. */ 612 + 47 613 int (*platform_notify)(struct device *dev) = NULL; 48 614 int (*platform_notify_remove)(struct device *dev) = NULL; 49 615 static struct kobject *dev_kobj; ··· 1060 494 goto err_remove_dev_groups; 1061 495 } 1062 496 497 + error = device_create_file(dev, &dev_attr_deferred_probe); 498 + if (error) 499 + goto err_remove_online; 500 + 1063 501 return 0; 1064 502 503 + err_remove_online: 504 + device_remove_file(dev, &dev_attr_online); 1065 505 err_remove_dev_groups: 1066 506 device_remove_groups(dev, dev->groups); 1067 507 err_remove_type_groups: ··· 1085 513 struct class *class = dev->class; 1086 514 const struct device_type *type = dev->type; 1087 515 516 + device_remove_file(dev, &dev_attr_deferred_probe); 1088 517 device_remove_file(dev, &dev_attr_online); 1089 518 device_remove_groups(dev, dev->groups); 1090 519 ··· 1284 711 #ifdef CONFIG_GENERIC_MSI_IRQ 1285 712 INIT_LIST_HEAD(&dev->msi_list); 1286 713 #endif 714 + INIT_LIST_HEAD(&dev->links.consumers); 715 + INIT_LIST_HEAD(&dev->links.suppliers); 716 + dev->links.status = DL_DEV_NO_DRIVER; 1287 717 } 1288 718 EXPORT_SYMBOL_GPL(device_initialize); 1289 719 ··· 1834 1258 if (dev->bus) 1835 1259 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 1836 1260 BUS_NOTIFY_DEL_DEVICE, dev); 1261 + 1262 + device_links_purge(dev); 1837 1263 dpm_sysfs_remove(dev); 1838 1264 if (parent) 1839 1265 klist_del(&dev->p->knode_parent);
+66 -13
drivers/base/dd.c
··· 53 53 static LIST_HEAD(deferred_probe_active_list); 54 54 static atomic_t deferred_trigger_count = ATOMIC_INIT(0); 55 55 56 + static ssize_t deferred_probe_show(struct device *dev, 57 + struct device_attribute *attr, char *buf) 58 + { 59 + bool value; 60 + 61 + mutex_lock(&deferred_probe_mutex); 62 + value = !list_empty(&dev->p->deferred_probe); 63 + mutex_unlock(&deferred_probe_mutex); 64 + 65 + return sprintf(buf, "%d\n", value); 66 + } 67 + DEVICE_ATTR_RO(deferred_probe); 68 + 56 69 /* 57 70 * In some cases, like suspend to RAM or hibernation, It might be reasonable 58 71 * to prohibit probing of devices as it could be unsafe. ··· 257 244 __func__, dev_name(dev)); 258 245 259 246 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices); 247 + device_links_driver_bound(dev); 260 248 261 249 device_pm_check_callbacks(dev); 262 250 ··· 352 338 return ret; 353 339 } 354 340 341 + ret = device_links_check_suppliers(dev); 342 + if (ret) 343 + return ret; 344 + 355 345 atomic_inc(&probe_count); 356 346 pr_debug("bus: '%s': %s: probing driver %s with device %s\n", 357 347 drv->bus->name, __func__, drv->name, dev_name(dev)); ··· 434 416 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 435 417 BUS_NOTIFY_DRIVER_NOT_BOUND, dev); 436 418 pinctrl_bind_failed: 419 + device_links_no_driver(dev); 437 420 devres_release_all(dev); 438 421 driver_sysfs_remove(dev); 439 422 dev->driver = NULL; ··· 527 508 pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 528 509 drv->bus->name, __func__, dev_name(dev), drv->name); 529 510 511 + pm_runtime_get_suppliers(dev); 530 512 if (dev->parent) 531 513 pm_runtime_get_sync(dev->parent); 532 514 ··· 538 518 if (dev->parent) 539 519 pm_runtime_put(dev->parent); 540 520 521 + pm_runtime_put_suppliers(dev); 541 522 return ret; 542 523 } 543 524 ··· 793 772 * __device_release_driver() must be called with @dev lock held. 794 773 * When called for a USB interface, @dev->parent lock must be held as well. 795 774 */ 796 - static void __device_release_driver(struct device *dev) 775 + static void __device_release_driver(struct device *dev, struct device *parent) 797 776 { 798 777 struct device_driver *drv; 799 778 ··· 802 781 if (driver_allows_async_probing(drv)) 803 782 async_synchronize_full(); 804 783 784 + while (device_links_busy(dev)) { 785 + device_unlock(dev); 786 + if (parent) 787 + device_unlock(parent); 788 + 789 + device_links_unbind_consumers(dev); 790 + if (parent) 791 + device_lock(parent); 792 + 793 + device_lock(dev); 794 + /* 795 + * A concurrent invocation of the same function might 796 + * have released the driver successfully while this one 797 + * was waiting, so check for that. 798 + */ 799 + if (dev->driver != drv) 800 + return; 801 + } 802 + 805 803 pm_runtime_get_sync(dev); 804 + pm_runtime_clean_up_links(dev); 806 805 807 806 driver_sysfs_remove(dev); 808 807 ··· 837 796 dev->bus->remove(dev); 838 797 else if (drv->remove) 839 798 drv->remove(dev); 799 + 800 + device_links_driver_cleanup(dev); 840 801 devres_release_all(dev); 841 802 dev->driver = NULL; 842 803 dev_set_drvdata(dev, NULL); ··· 855 812 } 856 813 } 857 814 815 + void device_release_driver_internal(struct device *dev, 816 + struct device_driver *drv, 817 + struct device *parent) 818 + { 819 + if (parent) 820 + device_lock(parent); 821 + 822 + device_lock(dev); 823 + if (!drv || drv == dev->driver) 824 + __device_release_driver(dev, parent); 825 + 826 + device_unlock(dev); 827 + if (parent) 828 + device_unlock(parent); 829 + } 830 + 858 831 /** 859 832 * device_release_driver - manually detach device from driver. 860 833 * @dev: device. 861 834 * 862 835 * Manually detach device from driver. 863 836 * When called for a USB interface, @dev->parent lock must be held. 837 + * 838 + * If this function is to be called with @dev->parent lock held, ensure that 839 + * the device's consumers are unbound in advance or that their locks can be 840 + * acquired under the @dev->parent lock. 864 841 */ 865 842 void device_release_driver(struct device *dev) 866 843 { ··· 889 826 * within their ->remove callback for the same device, they 890 827 * will deadlock right here. 891 828 */ 892 - device_lock(dev); 893 - __device_release_driver(dev); 894 - device_unlock(dev); 829 + device_release_driver_internal(dev, NULL, NULL); 895 830 } 896 831 EXPORT_SYMBOL_GPL(device_release_driver); 897 832 ··· 914 853 dev = dev_prv->device; 915 854 get_device(dev); 916 855 spin_unlock(&drv->p->klist_devices.k_lock); 917 - 918 - if (dev->parent) /* Needed for USB */ 919 - device_lock(dev->parent); 920 - device_lock(dev); 921 - if (dev->driver == drv) 922 - __device_release_driver(dev); 923 - device_unlock(dev); 924 - if (dev->parent) 925 - device_unlock(dev->parent); 856 + device_release_driver_internal(dev, drv, dev->parent); 926 857 put_device(dev); 927 858 } 928 859 }
+83 -4
drivers/base/power/main.c
··· 131 131 dev_warn(dev, "parent %s should not be sleeping\n", 132 132 dev_name(dev->parent)); 133 133 list_add_tail(&dev->power.entry, &dpm_list); 134 + dev->power.in_dpm_list = true; 134 135 mutex_unlock(&dpm_list_mtx); 135 136 } 136 137 ··· 146 145 complete_all(&dev->power.completion); 147 146 mutex_lock(&dpm_list_mtx); 148 147 list_del_init(&dev->power.entry); 148 + dev->power.in_dpm_list = false; 149 149 mutex_unlock(&dpm_list_mtx); 150 150 device_wakeup_disable(dev); 151 151 pm_runtime_remove(dev); ··· 244 242 static void dpm_wait_for_children(struct device *dev, bool async) 245 243 { 246 244 device_for_each_child(dev, &async, dpm_wait_fn); 245 + } 246 + 247 + static void dpm_wait_for_suppliers(struct device *dev, bool async) 248 + { 249 + struct device_link *link; 250 + int idx; 251 + 252 + idx = device_links_read_lock(); 253 + 254 + /* 255 + * If the supplier goes away right after we've checked the link to it, 256 + * we'll wait for its completion to change the state, but that's fine, 257 + * because the only things that will block as a result are the SRCU 258 + * callbacks freeing the link objects for the links in the list we're 259 + * walking. 260 + */ 261 + list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) 262 + if (READ_ONCE(link->status) != DL_STATE_DORMANT) 263 + dpm_wait(link->supplier, async); 264 + 265 + device_links_read_unlock(idx); 266 + } 267 + 268 + static void dpm_wait_for_superior(struct device *dev, bool async) 269 + { 270 + dpm_wait(dev->parent, async); 271 + dpm_wait_for_suppliers(dev, async); 272 + } 273 + 274 + static void dpm_wait_for_consumers(struct device *dev, bool async) 275 + { 276 + struct device_link *link; 277 + int idx; 278 + 279 + idx = device_links_read_lock(); 280 + 281 + /* 282 + * The status of a device link can only be changed from "dormant" by a 283 + * probe, but that cannot happen during system suspend/resume. In 284 + * theory it can change to "dormant" at that time, but then it is 285 + * reasonable to wait for the target device anyway (eg. if it goes 286 + * away, it's better to wait for it to go away completely and then 287 + * continue instead of trying to continue in parallel with its 288 + * unregistration). 289 + */ 290 + list_for_each_entry_rcu(link, &dev->links.consumers, s_node) 291 + if (READ_ONCE(link->status) != DL_STATE_DORMANT) 292 + dpm_wait(link->consumer, async); 293 + 294 + device_links_read_unlock(idx); 295 + } 296 + 297 + static void dpm_wait_for_subordinate(struct device *dev, bool async) 298 + { 299 + dpm_wait_for_children(dev, async); 300 + dpm_wait_for_consumers(dev, async); 247 301 } 248 302 249 303 /** ··· 546 488 if (!dev->power.is_noirq_suspended) 547 489 goto Out; 548 490 549 - dpm_wait(dev->parent, async); 491 + dpm_wait_for_superior(dev, async); 550 492 551 493 if (dev->pm_domain) { 552 494 info = "noirq power domain "; ··· 676 618 if (!dev->power.is_late_suspended) 677 619 goto Out; 678 620 679 - dpm_wait(dev->parent, async); 621 + dpm_wait_for_superior(dev, async); 680 622 681 623 if (dev->pm_domain) { 682 624 info = "early power domain "; ··· 808 750 goto Complete; 809 751 } 810 752 811 - dpm_wait(dev->parent, async); 753 + dpm_wait_for_superior(dev, async); 812 754 dpm_watchdog_set(&wd, dev); 813 755 device_lock(dev); 814 756 ··· 1098 1040 if (dev->power.syscore || dev->power.direct_complete) 1099 1041 goto Complete; 1100 1042 1043 + dpm_wait_for_subordinate(dev, async); 1044 + 1101 1045 if (dev->pm_domain) { 1102 1046 info = "noirq power domain "; 1103 1047 callback = pm_noirq_op(&dev->pm_domain->ops, state); ··· 1246 1186 1247 1187 if (dev->power.syscore || dev->power.direct_complete) 1248 1188 goto Complete; 1189 + 1190 + dpm_wait_for_subordinate(dev, async); 1249 1191 1250 1192 if (dev->pm_domain) { 1251 1193 info = "late power domain "; ··· 1404 1342 return error; 1405 1343 } 1406 1344 1345 + static void dpm_clear_suppliers_direct_complete(struct device *dev) 1346 + { 1347 + struct device_link *link; 1348 + int idx; 1349 + 1350 + idx = device_links_read_lock(); 1351 + 1352 + list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) { 1353 + spin_lock_irq(&link->supplier->power.lock); 1354 + link->supplier->power.direct_complete = false; 1355 + spin_unlock_irq(&link->supplier->power.lock); 1356 + } 1357 + 1358 + device_links_read_unlock(idx); 1359 + } 1360 + 1407 1361 /** 1408 1362 * device_suspend - Execute "suspend" callbacks for given device. 1409 1363 * @dev: Device to handle. ··· 1436 1358 TRACE_DEVICE(dev); 1437 1359 TRACE_SUSPEND(0); 1438 1360 1439 - dpm_wait_for_children(dev, async); 1361 + dpm_wait_for_subordinate(dev, async); 1440 1362 1441 1363 if (async_error) 1442 1364 goto Complete; ··· 1532 1454 1533 1455 spin_unlock_irq(&parent->power.lock); 1534 1456 } 1457 + dpm_clear_suppliers_direct_complete(dev); 1535 1458 } 1536 1459 1537 1460 device_unlock(dev);
+10
drivers/base/power/power.h
··· 127 127 extern void device_pm_move_last(struct device *); 128 128 extern void device_pm_check_callbacks(struct device *dev); 129 129 130 + static inline bool device_pm_initialized(struct device *dev) 131 + { 132 + return dev->power.in_dpm_list; 133 + } 134 + 130 135 #else /* !CONFIG_PM_SLEEP */ 131 136 132 137 static inline void device_pm_sleep_init(struct device *dev) {} ··· 150 145 static inline void device_pm_move_last(struct device *dev) {} 151 146 152 147 static inline void device_pm_check_callbacks(struct device *dev) {} 148 + 149 + static inline bool device_pm_initialized(struct device *dev) 150 + { 151 + return device_is_registered(dev); 152 + } 153 153 154 154 #endif /* !CONFIG_PM_SLEEP */ 155 155
+169 -5
drivers/base/power/runtime.c
··· 12 12 #include <linux/pm_runtime.h> 13 13 #include <linux/pm_wakeirq.h> 14 14 #include <trace/events/rpm.h> 15 + 16 + #include "../base.h" 15 17 #include "power.h" 16 18 17 19 typedef int (*pm_callback_t)(struct device *); ··· 260 258 return retval; 261 259 } 262 260 261 + static int rpm_get_suppliers(struct device *dev) 262 + { 263 + struct device_link *link; 264 + 265 + list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) { 266 + int retval; 267 + 268 + if (!(link->flags & DL_FLAG_PM_RUNTIME)) 269 + continue; 270 + 271 + if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND || 272 + link->rpm_active) 273 + continue; 274 + 275 + retval = pm_runtime_get_sync(link->supplier); 276 + if (retval < 0) { 277 + pm_runtime_put_noidle(link->supplier); 278 + return retval; 279 + } 280 + link->rpm_active = true; 281 + } 282 + return 0; 283 + } 284 + 285 + static void rpm_put_suppliers(struct device *dev) 286 + { 287 + struct device_link *link; 288 + 289 + list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) 290 + if (link->rpm_active && 291 + READ_ONCE(link->status) != DL_STATE_SUPPLIER_UNBIND) { 292 + pm_runtime_put(link->supplier); 293 + link->rpm_active = false; 294 + } 295 + } 296 + 263 297 /** 264 298 * __rpm_callback - Run a given runtime PM callback for a given device. 265 299 * @cb: Runtime PM callback to run. ··· 304 266 static int __rpm_callback(int (*cb)(struct device *), struct device *dev) 305 267 __releases(&dev->power.lock) __acquires(&dev->power.lock) 306 268 { 307 - int retval; 269 + int retval, idx; 270 + bool use_links = dev->power.links_count > 0; 308 271 309 - if (dev->power.irq_safe) 272 + if (dev->power.irq_safe) { 310 273 spin_unlock(&dev->power.lock); 311 - else 274 + } else { 312 275 spin_unlock_irq(&dev->power.lock); 276 + 277 + /* 278 + * Resume suppliers if necessary. 279 + * 280 + * The device's runtime PM status cannot change until this 281 + * routine returns, so it is safe to read the status outside of 282 + * the lock. 283 + */ 284 + if (use_links && dev->power.runtime_status == RPM_RESUMING) { 285 + idx = device_links_read_lock(); 286 + 287 + retval = rpm_get_suppliers(dev); 288 + if (retval) 289 + goto fail; 290 + 291 + device_links_read_unlock(idx); 292 + } 293 + } 313 294 314 295 retval = cb(dev); 315 296 316 - if (dev->power.irq_safe) 297 + if (dev->power.irq_safe) { 317 298 spin_lock(&dev->power.lock); 318 - else 299 + } else { 300 + /* 301 + * If the device is suspending and the callback has returned 302 + * success, drop the usage counters of the suppliers that have 303 + * been reference counted on its resume. 304 + * 305 + * Do that if resume fails too. 306 + */ 307 + if (use_links 308 + && ((dev->power.runtime_status == RPM_SUSPENDING && !retval) 309 + || (dev->power.runtime_status == RPM_RESUMING && retval))) { 310 + idx = device_links_read_lock(); 311 + 312 + fail: 313 + rpm_put_suppliers(dev); 314 + 315 + device_links_read_unlock(idx); 316 + } 317 + 319 318 spin_lock_irq(&dev->power.lock); 319 + } 320 320 321 321 return retval; 322 322 } ··· 1520 1444 { 1521 1445 __pm_runtime_disable(dev, false); 1522 1446 pm_runtime_reinit(dev); 1447 + } 1448 + 1449 + /** 1450 + * pm_runtime_clean_up_links - Prepare links to consumers for driver removal. 1451 + * @dev: Device whose driver is going to be removed. 1452 + * 1453 + * Check links from this device to any consumers and if any of them have active 1454 + * runtime PM references to the device, drop the usage counter of the device 1455 + * (once per link). 1456 + * 1457 + * Links with the DL_FLAG_STATELESS flag set are ignored. 1458 + * 1459 + * Since the device is guaranteed to be runtime-active at the point this is 1460 + * called, nothing else needs to be done here. 1461 + * 1462 + * Moreover, this is called after device_links_busy() has returned 'false', so 1463 + * the status of each link is guaranteed to be DL_STATE_SUPPLIER_UNBIND and 1464 + * therefore rpm_active can't be manipulated concurrently. 1465 + */ 1466 + void pm_runtime_clean_up_links(struct device *dev) 1467 + { 1468 + struct device_link *link; 1469 + int idx; 1470 + 1471 + idx = device_links_read_lock(); 1472 + 1473 + list_for_each_entry_rcu(link, &dev->links.consumers, s_node) { 1474 + if (link->flags & DL_FLAG_STATELESS) 1475 + continue; 1476 + 1477 + if (link->rpm_active) { 1478 + pm_runtime_put_noidle(dev); 1479 + link->rpm_active = false; 1480 + } 1481 + } 1482 + 1483 + device_links_read_unlock(idx); 1484 + } 1485 + 1486 + /** 1487 + * pm_runtime_get_suppliers - Resume and reference-count supplier devices. 1488 + * @dev: Consumer device. 1489 + */ 1490 + void pm_runtime_get_suppliers(struct device *dev) 1491 + { 1492 + struct device_link *link; 1493 + int idx; 1494 + 1495 + idx = device_links_read_lock(); 1496 + 1497 + list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) 1498 + if (link->flags & DL_FLAG_PM_RUNTIME) 1499 + pm_runtime_get_sync(link->supplier); 1500 + 1501 + device_links_read_unlock(idx); 1502 + } 1503 + 1504 + /** 1505 + * pm_runtime_put_suppliers - Drop references to supplier devices. 1506 + * @dev: Consumer device. 1507 + */ 1508 + void pm_runtime_put_suppliers(struct device *dev) 1509 + { 1510 + struct device_link *link; 1511 + int idx; 1512 + 1513 + idx = device_links_read_lock(); 1514 + 1515 + list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) 1516 + if (link->flags & DL_FLAG_PM_RUNTIME) 1517 + pm_runtime_put(link->supplier); 1518 + 1519 + device_links_read_unlock(idx); 1520 + } 1521 + 1522 + void pm_runtime_new_link(struct device *dev) 1523 + { 1524 + spin_lock_irq(&dev->power.lock); 1525 + dev->power.links_count++; 1526 + spin_unlock_irq(&dev->power.lock); 1527 + } 1528 + 1529 + void pm_runtime_drop_link(struct device *dev) 1530 + { 1531 + spin_lock_irq(&dev->power.lock); 1532 + WARN_ON(dev->power.links_count == 0); 1533 + dev->power.links_count--; 1534 + spin_unlock_irq(&dev->power.lock); 1523 1535 } 1524 1536 1525 1537 /**
+9
drivers/base/test/Kconfig
··· 1 + config TEST_ASYNC_DRIVER_PROBE 2 + tristate "Build kernel module to test asynchronous driver probing" 3 + depends on m 4 + help 5 + Enabling this option produces a kernel module that allows 6 + testing asynchronous driver probing by the device core. 7 + The module name will be test_async_driver_probe.ko 8 + 9 + If unsure say N.
+1
drivers/base/test/Makefile
··· 1 + obj-$(CONFIG_TEST_ASYNC_DRIVER_PROBE) += test_async_driver_probe.o
+171
drivers/base/test/test_async_driver_probe.c
··· 1 + /* 2 + * Copyright (C) 2014 Google, Inc. 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15 + 16 + #include <linux/delay.h> 17 + #include <linux/init.h> 18 + #include <linux/hrtimer.h> 19 + #include <linux/module.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/time.h> 22 + 23 + #define TEST_PROBE_DELAY (5 * 1000) /* 5 sec */ 24 + #define TEST_PROBE_THRESHOLD (TEST_PROBE_DELAY / 2) 25 + 26 + static int test_probe(struct platform_device *pdev) 27 + { 28 + dev_info(&pdev->dev, "sleeping for %d msecs in probe\n", 29 + TEST_PROBE_DELAY); 30 + msleep(TEST_PROBE_DELAY); 31 + dev_info(&pdev->dev, "done sleeping\n"); 32 + 33 + return 0; 34 + } 35 + 36 + static struct platform_driver async_driver = { 37 + .driver = { 38 + .name = "test_async_driver", 39 + .owner = THIS_MODULE, 40 + .probe_type = PROBE_PREFER_ASYNCHRONOUS, 41 + }, 42 + .probe = test_probe, 43 + }; 44 + 45 + static struct platform_driver sync_driver = { 46 + .driver = { 47 + .name = "test_sync_driver", 48 + .owner = THIS_MODULE, 49 + .probe_type = PROBE_FORCE_SYNCHRONOUS, 50 + }, 51 + .probe = test_probe, 52 + }; 53 + 54 + static struct platform_device *async_dev_1, *async_dev_2; 55 + static struct platform_device *sync_dev_1; 56 + 57 + static int __init test_async_probe_init(void) 58 + { 59 + ktime_t calltime, delta; 60 + unsigned long long duration; 61 + int error; 62 + 63 + pr_info("registering first asynchronous device...\n"); 64 + 65 + async_dev_1 = platform_device_register_simple("test_async_driver", 1, 66 + NULL, 0); 67 + if (IS_ERR(async_dev_1)) { 68 + error = PTR_ERR(async_dev_1); 69 + pr_err("failed to create async_dev_1: %d", error); 70 + return error; 71 + } 72 + 73 + pr_info("registering asynchronous driver...\n"); 74 + calltime = ktime_get(); 75 + error = platform_driver_register(&async_driver); 76 + if (error) { 77 + pr_err("Failed to register async_driver: %d\n", error); 78 + goto err_unregister_async_dev_1; 79 + } 80 + 81 + delta = ktime_sub(ktime_get(), calltime); 82 + duration = (unsigned long long) ktime_to_ms(delta); 83 + pr_info("registration took %lld msecs\n", duration); 84 + if (duration > TEST_PROBE_THRESHOLD) { 85 + pr_err("test failed: probe took too long\n"); 86 + error = -ETIMEDOUT; 87 + goto err_unregister_async_driver; 88 + } 89 + 90 + pr_info("registering second asynchronous device...\n"); 91 + calltime = ktime_get(); 92 + async_dev_2 = platform_device_register_simple("test_async_driver", 2, 93 + NULL, 0); 94 + if (IS_ERR(async_dev_2)) { 95 + error = PTR_ERR(async_dev_2); 96 + pr_err("failed to create async_dev_2: %d", error); 97 + goto err_unregister_async_driver; 98 + } 99 + 100 + delta = ktime_sub(ktime_get(), calltime); 101 + duration = (unsigned long long) ktime_to_ms(delta); 102 + pr_info("registration took %lld msecs\n", duration); 103 + if (duration > TEST_PROBE_THRESHOLD) { 104 + pr_err("test failed: probe took too long\n"); 105 + error = -ETIMEDOUT; 106 + goto err_unregister_async_dev_2; 107 + } 108 + 109 + pr_info("registering synchronous driver...\n"); 110 + 111 + error = platform_driver_register(&sync_driver); 112 + if (error) { 113 + pr_err("Failed to register async_driver: %d\n", error); 114 + goto err_unregister_async_dev_2; 115 + } 116 + 117 + pr_info("registering synchronous device...\n"); 118 + calltime = ktime_get(); 119 + sync_dev_1 = platform_device_register_simple("test_sync_driver", 1, 120 + NULL, 0); 121 + if (IS_ERR(async_dev_1)) { 122 + error = PTR_ERR(sync_dev_1); 123 + pr_err("failed to create sync_dev_1: %d", error); 124 + goto err_unregister_sync_driver; 125 + } 126 + 127 + delta = ktime_sub(ktime_get(), calltime); 128 + duration = (unsigned long long) ktime_to_ms(delta); 129 + pr_info("registration took %lld msecs\n", duration); 130 + if (duration < TEST_PROBE_THRESHOLD) { 131 + pr_err("test failed: probe was too quick\n"); 132 + error = -ETIMEDOUT; 133 + goto err_unregister_sync_dev_1; 134 + } 135 + 136 + pr_info("completed successfully"); 137 + 138 + return 0; 139 + 140 + err_unregister_sync_dev_1: 141 + platform_device_unregister(sync_dev_1); 142 + 143 + err_unregister_sync_driver: 144 + platform_driver_unregister(&sync_driver); 145 + 146 + err_unregister_async_dev_2: 147 + platform_device_unregister(async_dev_2); 148 + 149 + err_unregister_async_driver: 150 + platform_driver_unregister(&async_driver); 151 + 152 + err_unregister_async_dev_1: 153 + platform_device_unregister(async_dev_1); 154 + 155 + return error; 156 + } 157 + module_init(test_async_probe_init); 158 + 159 + static void __exit test_async_probe_exit(void) 160 + { 161 + platform_driver_unregister(&async_driver); 162 + platform_driver_unregister(&sync_driver); 163 + platform_device_unregister(async_dev_1); 164 + platform_device_unregister(async_dev_2); 165 + platform_device_unregister(sync_dev_1); 166 + } 167 + module_exit(test_async_probe_exit); 168 + 169 + MODULE_DESCRIPTION("Test module for asynchronous driver probing"); 170 + MODULE_AUTHOR("Dmitry Torokhov <dtor@chromium.org>"); 171 + MODULE_LICENSE("GPL");
+2
drivers/iommu/amd_iommu.c
··· 373 373 374 374 if (!entry->group) 375 375 entry->group = generic_device_group(dev); 376 + else 377 + iommu_group_ref_get(entry->group); 376 378 377 379 return entry->group; 378 380 }
+4
drivers/iommu/amd_iommu_init.c
··· 28 28 #include <linux/amd-iommu.h> 29 29 #include <linux/export.h> 30 30 #include <linux/iommu.h> 31 + #include <linux/kmemleak.h> 31 32 #include <asm/pci-direct.h> 32 33 #include <asm/iommu.h> 33 34 #include <asm/gart.h> ··· 2091 2090 2092 2091 static void __init free_on_init_error(void) 2093 2092 { 2093 + kmemleak_free(irq_lookup_table); 2094 2094 free_pages((unsigned long)irq_lookup_table, 2095 2095 get_order(rlookup_table_size)); 2096 2096 ··· 2323 2321 irq_lookup_table = (void *)__get_free_pages( 2324 2322 GFP_KERNEL | __GFP_ZERO, 2325 2323 get_order(rlookup_table_size)); 2324 + kmemleak_alloc(irq_lookup_table, rlookup_table_size, 2325 + 1, GFP_KERNEL); 2326 2326 if (!irq_lookup_table) 2327 2327 goto out; 2328 2328 }
+3 -1
drivers/iommu/amd_iommu_v2.c
··· 805 805 goto out_free_domain; 806 806 807 807 group = iommu_group_get(&pdev->dev); 808 - if (!group) 808 + if (!group) { 809 + ret = -EINVAL; 809 810 goto out_free_domain; 811 + } 810 812 811 813 ret = iommu_attach_group(dev_state->domain, group); 812 814 if (ret != 0)
+82 -22
drivers/iommu/arm-smmu-v3.c
··· 20 20 * This driver is powered by bad coffee and bombay mix. 21 21 */ 22 22 23 + #include <linux/acpi.h> 24 + #include <linux/acpi_iort.h> 23 25 #include <linux/delay.h> 24 26 #include <linux/dma-iommu.h> 25 27 #include <linux/err.h> ··· 1360 1358 } while (size -= granule); 1361 1359 } 1362 1360 1363 - static struct iommu_gather_ops arm_smmu_gather_ops = { 1361 + static const struct iommu_gather_ops arm_smmu_gather_ops = { 1364 1362 .tlb_flush_all = arm_smmu_tlb_inv_context, 1365 1363 .tlb_add_flush = arm_smmu_tlb_inv_range_nosync, 1366 1364 .tlb_sync = arm_smmu_tlb_sync, ··· 1725 1723 1726 1724 static int arm_smmu_match_node(struct device *dev, void *data) 1727 1725 { 1728 - return dev->of_node == data; 1726 + return dev->fwnode == data; 1729 1727 } 1730 1728 1731 - static struct arm_smmu_device *arm_smmu_get_by_node(struct device_node *np) 1729 + static 1730 + struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) 1732 1731 { 1733 1732 struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, 1734 - np, arm_smmu_match_node); 1733 + fwnode, arm_smmu_match_node); 1735 1734 put_device(dev); 1736 1735 return dev ? dev_get_drvdata(dev) : NULL; 1737 1736 } ··· 1768 1765 master = fwspec->iommu_priv; 1769 1766 smmu = master->smmu; 1770 1767 } else { 1771 - smmu = arm_smmu_get_by_node(to_of_node(fwspec->iommu_fwnode)); 1768 + smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode); 1772 1769 if (!smmu) 1773 1770 return -ENODEV; 1774 1771 master = kzalloc(sizeof(*master), GFP_KERNEL); ··· 2383 2380 return 0; 2384 2381 } 2385 2382 2386 - static int arm_smmu_device_probe(struct arm_smmu_device *smmu) 2383 + static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) 2387 2384 { 2388 2385 u32 reg; 2389 - bool coherent; 2386 + bool coherent = smmu->features & ARM_SMMU_FEAT_COHERENCY; 2390 2387 2391 2388 /* IDR0 */ 2392 2389 reg = readl_relaxed(smmu->base + ARM_SMMU_IDR0); ··· 2438 2435 smmu->features |= ARM_SMMU_FEAT_HYP; 2439 2436 2440 2437 /* 2441 - * The dma-coherent property is used in preference to the ID 2438 + * The coherency feature as set by FW is used in preference to the ID 2442 2439 * register, but warn on mismatch. 2443 2440 */ 2444 - coherent = of_dma_is_coherent(smmu->dev->of_node); 2445 - if (coherent) 2446 - smmu->features |= ARM_SMMU_FEAT_COHERENCY; 2447 - 2448 2441 if (!!(reg & IDR0_COHACC) != coherent) 2449 2442 dev_warn(smmu->dev, "IDR0.COHACC overridden by dma-coherent property (%s)\n", 2450 2443 coherent ? "true" : "false"); ··· 2561 2562 return 0; 2562 2563 } 2563 2564 2564 - static int arm_smmu_device_dt_probe(struct platform_device *pdev) 2565 + #ifdef CONFIG_ACPI 2566 + static int arm_smmu_device_acpi_probe(struct platform_device *pdev, 2567 + struct arm_smmu_device *smmu) 2565 2568 { 2566 - int irq, ret; 2567 - struct resource *res; 2568 - struct arm_smmu_device *smmu; 2569 + struct acpi_iort_smmu_v3 *iort_smmu; 2570 + struct device *dev = smmu->dev; 2571 + struct acpi_iort_node *node; 2572 + 2573 + node = *(struct acpi_iort_node **)dev_get_platdata(dev); 2574 + 2575 + /* Retrieve SMMUv3 specific data */ 2576 + iort_smmu = (struct acpi_iort_smmu_v3 *)node->node_data; 2577 + 2578 + if (iort_smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE) 2579 + smmu->features |= ARM_SMMU_FEAT_COHERENCY; 2580 + 2581 + return 0; 2582 + } 2583 + #else 2584 + static inline int arm_smmu_device_acpi_probe(struct platform_device *pdev, 2585 + struct arm_smmu_device *smmu) 2586 + { 2587 + return -ENODEV; 2588 + } 2589 + #endif 2590 + 2591 + static int arm_smmu_device_dt_probe(struct platform_device *pdev, 2592 + struct arm_smmu_device *smmu) 2593 + { 2569 2594 struct device *dev = &pdev->dev; 2570 - bool bypass = true; 2571 2595 u32 cells; 2596 + int ret = -EINVAL; 2572 2597 2573 2598 if (of_property_read_u32(dev->of_node, "#iommu-cells", &cells)) 2574 2599 dev_err(dev, "missing #iommu-cells property\n"); 2575 2600 else if (cells != 1) 2576 2601 dev_err(dev, "invalid #iommu-cells value (%d)\n", cells); 2577 2602 else 2578 - bypass = false; 2603 + ret = 0; 2604 + 2605 + parse_driver_options(smmu); 2606 + 2607 + if (of_dma_is_coherent(dev->of_node)) 2608 + smmu->features |= ARM_SMMU_FEAT_COHERENCY; 2609 + 2610 + return ret; 2611 + } 2612 + 2613 + static int arm_smmu_device_probe(struct platform_device *pdev) 2614 + { 2615 + int irq, ret; 2616 + struct resource *res; 2617 + struct arm_smmu_device *smmu; 2618 + struct device *dev = &pdev->dev; 2619 + bool bypass; 2579 2620 2580 2621 smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); 2581 2622 if (!smmu) { ··· 2652 2613 if (irq > 0) 2653 2614 smmu->gerr_irq = irq; 2654 2615 2655 - parse_driver_options(smmu); 2616 + if (dev->of_node) { 2617 + ret = arm_smmu_device_dt_probe(pdev, smmu); 2618 + } else { 2619 + ret = arm_smmu_device_acpi_probe(pdev, smmu); 2620 + if (ret == -ENODEV) 2621 + return ret; 2622 + } 2623 + 2624 + /* Set bypass mode according to firmware probing result */ 2625 + bypass = !!ret; 2656 2626 2657 2627 /* Probe the h/w */ 2658 - ret = arm_smmu_device_probe(smmu); 2628 + ret = arm_smmu_device_hw_probe(smmu); 2659 2629 if (ret) 2660 2630 return ret; 2661 2631 ··· 2682 2634 return ret; 2683 2635 2684 2636 /* And we're up. Go go go! */ 2685 - of_iommu_set_ops(dev->of_node, &arm_smmu_ops); 2637 + iommu_register_instance(dev->fwnode, &arm_smmu_ops); 2638 + 2686 2639 #ifdef CONFIG_PCI 2687 2640 if (pci_bus_type.iommu_ops != &arm_smmu_ops) { 2688 2641 pci_request_acs(); ··· 2726 2677 .name = "arm-smmu-v3", 2727 2678 .of_match_table = of_match_ptr(arm_smmu_of_match), 2728 2679 }, 2729 - .probe = arm_smmu_device_dt_probe, 2680 + .probe = arm_smmu_device_probe, 2730 2681 .remove = arm_smmu_device_remove, 2731 2682 }; 2732 2683 ··· 2763 2714 return 0; 2764 2715 } 2765 2716 IOMMU_OF_DECLARE(arm_smmuv3, "arm,smmu-v3", arm_smmu_of_init); 2717 + 2718 + #ifdef CONFIG_ACPI 2719 + static int __init acpi_smmu_v3_init(struct acpi_table_header *table) 2720 + { 2721 + if (iort_node_match(ACPI_IORT_NODE_SMMU_V3)) 2722 + return arm_smmu_init(); 2723 + 2724 + return 0; 2725 + } 2726 + IORT_ACPI_DECLARE(arm_smmu_v3, ACPI_SIG_IORT, acpi_smmu_v3_init); 2727 + #endif 2766 2728 2767 2729 MODULE_DESCRIPTION("IOMMU API for ARM architected SMMUv3 implementations"); 2768 2730 MODULE_AUTHOR("Will Deacon <will.deacon@arm.com>");
+136 -41
drivers/iommu/arm-smmu.c
··· 28 28 29 29 #define pr_fmt(fmt) "arm-smmu: " fmt 30 30 31 + #include <linux/acpi.h> 32 + #include <linux/acpi_iort.h> 31 33 #include <linux/atomic.h> 32 34 #include <linux/delay.h> 33 35 #include <linux/dma-iommu.h> ··· 249 247 #define ARM_MMU500_ACTLR_CPRE (1 << 1) 250 248 251 249 #define ARM_MMU500_ACR_CACHE_LOCK (1 << 26) 250 + #define ARM_MMU500_ACR_SMTNMB_TLBEN (1 << 8) 252 251 253 252 #define CB_PAR_F (1 << 0) 254 253 ··· 645 642 } 646 643 } 647 644 648 - static struct iommu_gather_ops arm_smmu_gather_ops = { 645 + static const struct iommu_gather_ops arm_smmu_gather_ops = { 649 646 .tlb_flush_all = arm_smmu_tlb_inv_context, 650 647 .tlb_add_flush = arm_smmu_tlb_inv_range_nosync, 651 648 .tlb_sync = arm_smmu_tlb_sync, ··· 1382 1379 1383 1380 static int arm_smmu_match_node(struct device *dev, void *data) 1384 1381 { 1385 - return dev->of_node == data; 1382 + return dev->fwnode == data; 1386 1383 } 1387 1384 1388 - static struct arm_smmu_device *arm_smmu_get_by_node(struct device_node *np) 1385 + static 1386 + struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode) 1389 1387 { 1390 1388 struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL, 1391 - np, arm_smmu_match_node); 1389 + fwnode, arm_smmu_match_node); 1392 1390 put_device(dev); 1393 1391 return dev ? dev_get_drvdata(dev) : NULL; 1394 1392 } ··· 1407 1403 if (ret) 1408 1404 goto out_free; 1409 1405 } else if (fwspec && fwspec->ops == &arm_smmu_ops) { 1410 - smmu = arm_smmu_get_by_node(to_of_node(fwspec->iommu_fwnode)); 1406 + smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode); 1411 1407 } else { 1412 1408 return -ENODEV; 1413 1409 } ··· 1482 1478 } 1483 1479 1484 1480 if (group) 1485 - return group; 1481 + return iommu_group_ref_get(group); 1486 1482 1487 1483 if (dev_is_pci(dev)) 1488 1484 group = pci_device_group(dev); ··· 1585 1581 for (i = 0; i < smmu->num_mapping_groups; ++i) 1586 1582 arm_smmu_write_sme(smmu, i); 1587 1583 1588 - /* 1589 - * Before clearing ARM_MMU500_ACTLR_CPRE, need to 1590 - * clear CACHE_LOCK bit of ACR first. And, CACHE_LOCK 1591 - * bit is only present in MMU-500r2 onwards. 1592 - */ 1593 - reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID7); 1594 - major = (reg >> ID7_MAJOR_SHIFT) & ID7_MAJOR_MASK; 1595 - if ((smmu->model == ARM_MMU500) && (major >= 2)) { 1584 + if (smmu->model == ARM_MMU500) { 1585 + /* 1586 + * Before clearing ARM_MMU500_ACTLR_CPRE, need to 1587 + * clear CACHE_LOCK bit of ACR first. And, CACHE_LOCK 1588 + * bit is only present in MMU-500r2 onwards. 1589 + */ 1590 + reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID7); 1591 + major = (reg >> ID7_MAJOR_SHIFT) & ID7_MAJOR_MASK; 1596 1592 reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_sACR); 1597 - reg &= ~ARM_MMU500_ACR_CACHE_LOCK; 1593 + if (major >= 2) 1594 + reg &= ~ARM_MMU500_ACR_CACHE_LOCK; 1595 + /* 1596 + * Allow unmatched Stream IDs to allocate bypass 1597 + * TLB entries for reduced latency. 1598 + */ 1599 + reg |= ARM_MMU500_ACR_SMTNMB_TLBEN; 1598 1600 writel_relaxed(reg, gr0_base + ARM_SMMU_GR0_sACR); 1599 1601 } 1600 1602 ··· 1677 1667 unsigned long size; 1678 1668 void __iomem *gr0_base = ARM_SMMU_GR0(smmu); 1679 1669 u32 id; 1680 - bool cttw_dt, cttw_reg; 1670 + bool cttw_reg, cttw_fw = smmu->features & ARM_SMMU_FEAT_COHERENT_WALK; 1681 1671 int i; 1682 1672 1683 1673 dev_notice(smmu->dev, "probing hardware configuration...\n"); ··· 1722 1712 1723 1713 /* 1724 1714 * In order for DMA API calls to work properly, we must defer to what 1725 - * the DT says about coherency, regardless of what the hardware claims. 1715 + * the FW says about coherency, regardless of what the hardware claims. 1726 1716 * Fortunately, this also opens up a workaround for systems where the 1727 1717 * ID register value has ended up configured incorrectly. 1728 1718 */ 1729 - cttw_dt = of_dma_is_coherent(smmu->dev->of_node); 1730 1719 cttw_reg = !!(id & ID0_CTTW); 1731 - if (cttw_dt) 1732 - smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK; 1733 - if (cttw_dt || cttw_reg) 1720 + if (cttw_fw || cttw_reg) 1734 1721 dev_notice(smmu->dev, "\t%scoherent table walk\n", 1735 - cttw_dt ? "" : "non-"); 1736 - if (cttw_dt != cttw_reg) 1722 + cttw_fw ? "" : "non-"); 1723 + if (cttw_fw != cttw_reg) 1737 1724 dev_notice(smmu->dev, 1738 - "\t(IDR0.CTTW overridden by dma-coherent property)\n"); 1725 + "\t(IDR0.CTTW overridden by FW configuration)\n"); 1739 1726 1740 1727 /* Max. number of entries we have for stream matching/indexing */ 1741 1728 size = 1 << ((id >> ID0_NUMSIDB_SHIFT) & ID0_NUMSIDB_MASK); ··· 1913 1906 }; 1914 1907 MODULE_DEVICE_TABLE(of, arm_smmu_of_match); 1915 1908 1916 - static int arm_smmu_device_dt_probe(struct platform_device *pdev) 1909 + #ifdef CONFIG_ACPI 1910 + static int acpi_smmu_get_data(u32 model, struct arm_smmu_device *smmu) 1911 + { 1912 + int ret = 0; 1913 + 1914 + switch (model) { 1915 + case ACPI_IORT_SMMU_V1: 1916 + case ACPI_IORT_SMMU_CORELINK_MMU400: 1917 + smmu->version = ARM_SMMU_V1; 1918 + smmu->model = GENERIC_SMMU; 1919 + break; 1920 + case ACPI_IORT_SMMU_V2: 1921 + smmu->version = ARM_SMMU_V2; 1922 + smmu->model = GENERIC_SMMU; 1923 + break; 1924 + case ACPI_IORT_SMMU_CORELINK_MMU500: 1925 + smmu->version = ARM_SMMU_V2; 1926 + smmu->model = ARM_MMU500; 1927 + break; 1928 + default: 1929 + ret = -ENODEV; 1930 + } 1931 + 1932 + return ret; 1933 + } 1934 + 1935 + static int arm_smmu_device_acpi_probe(struct platform_device *pdev, 1936 + struct arm_smmu_device *smmu) 1937 + { 1938 + struct device *dev = smmu->dev; 1939 + struct acpi_iort_node *node = 1940 + *(struct acpi_iort_node **)dev_get_platdata(dev); 1941 + struct acpi_iort_smmu *iort_smmu; 1942 + int ret; 1943 + 1944 + /* Retrieve SMMU1/2 specific data */ 1945 + iort_smmu = (struct acpi_iort_smmu *)node->node_data; 1946 + 1947 + ret = acpi_smmu_get_data(iort_smmu->model, smmu); 1948 + if (ret < 0) 1949 + return ret; 1950 + 1951 + /* Ignore the configuration access interrupt */ 1952 + smmu->num_global_irqs = 1; 1953 + 1954 + if (iort_smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK) 1955 + smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK; 1956 + 1957 + return 0; 1958 + } 1959 + #else 1960 + static inline int arm_smmu_device_acpi_probe(struct platform_device *pdev, 1961 + struct arm_smmu_device *smmu) 1962 + { 1963 + return -ENODEV; 1964 + } 1965 + #endif 1966 + 1967 + static int arm_smmu_device_dt_probe(struct platform_device *pdev, 1968 + struct arm_smmu_device *smmu) 1917 1969 { 1918 1970 const struct arm_smmu_match_data *data; 1919 - struct resource *res; 1920 - struct arm_smmu_device *smmu; 1921 1971 struct device *dev = &pdev->dev; 1922 - int num_irqs, i, err; 1923 1972 bool legacy_binding; 1973 + 1974 + if (of_property_read_u32(dev->of_node, "#global-interrupts", 1975 + &smmu->num_global_irqs)) { 1976 + dev_err(dev, "missing #global-interrupts property\n"); 1977 + return -ENODEV; 1978 + } 1979 + 1980 + data = of_device_get_match_data(dev); 1981 + smmu->version = data->version; 1982 + smmu->model = data->model; 1983 + 1984 + parse_driver_options(smmu); 1924 1985 1925 1986 legacy_binding = of_find_property(dev->of_node, "mmu-masters", NULL); 1926 1987 if (legacy_binding && !using_generic_binding) { ··· 2002 1927 return -ENODEV; 2003 1928 } 2004 1929 1930 + if (of_dma_is_coherent(dev->of_node)) 1931 + smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK; 1932 + 1933 + return 0; 1934 + } 1935 + 1936 + static int arm_smmu_device_probe(struct platform_device *pdev) 1937 + { 1938 + struct resource *res; 1939 + struct arm_smmu_device *smmu; 1940 + struct device *dev = &pdev->dev; 1941 + int num_irqs, i, err; 1942 + 2005 1943 smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); 2006 1944 if (!smmu) { 2007 1945 dev_err(dev, "failed to allocate arm_smmu_device\n"); ··· 2022 1934 } 2023 1935 smmu->dev = dev; 2024 1936 2025 - data = of_device_get_match_data(dev); 2026 - smmu->version = data->version; 2027 - smmu->model = data->model; 1937 + if (dev->of_node) 1938 + err = arm_smmu_device_dt_probe(pdev, smmu); 1939 + else 1940 + err = arm_smmu_device_acpi_probe(pdev, smmu); 1941 + 1942 + if (err) 1943 + return err; 2028 1944 2029 1945 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2030 1946 smmu->base = devm_ioremap_resource(dev, res); 2031 1947 if (IS_ERR(smmu->base)) 2032 1948 return PTR_ERR(smmu->base); 2033 1949 smmu->size = resource_size(res); 2034 - 2035 - if (of_property_read_u32(dev->of_node, "#global-interrupts", 2036 - &smmu->num_global_irqs)) { 2037 - dev_err(dev, "missing #global-interrupts property\n"); 2038 - return -ENODEV; 2039 - } 2040 1950 2041 1951 num_irqs = 0; 2042 1952 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, num_irqs))) { ··· 2070 1984 if (err) 2071 1985 return err; 2072 1986 2073 - parse_driver_options(smmu); 2074 - 2075 1987 if (smmu->version == ARM_SMMU_V2 && 2076 1988 smmu->num_context_banks != smmu->num_context_irqs) { 2077 1989 dev_err(dev, ··· 2091 2007 } 2092 2008 } 2093 2009 2094 - of_iommu_set_ops(dev->of_node, &arm_smmu_ops); 2010 + iommu_register_instance(dev->fwnode, &arm_smmu_ops); 2095 2011 platform_set_drvdata(pdev, smmu); 2096 2012 arm_smmu_device_reset(smmu); 2097 2013 ··· 2131 2047 .name = "arm-smmu", 2132 2048 .of_match_table = of_match_ptr(arm_smmu_of_match), 2133 2049 }, 2134 - .probe = arm_smmu_device_dt_probe, 2050 + .probe = arm_smmu_device_probe, 2135 2051 .remove = arm_smmu_device_remove, 2136 2052 }; 2137 2053 ··· 2173 2089 IOMMU_OF_DECLARE(arm_mmu401, "arm,mmu-401", arm_smmu_of_init); 2174 2090 IOMMU_OF_DECLARE(arm_mmu500, "arm,mmu-500", arm_smmu_of_init); 2175 2091 IOMMU_OF_DECLARE(cavium_smmuv2, "cavium,smmu-v2", arm_smmu_of_init); 2092 + 2093 + #ifdef CONFIG_ACPI 2094 + static int __init arm_smmu_acpi_init(struct acpi_table_header *table) 2095 + { 2096 + if (iort_node_match(ACPI_IORT_NODE_SMMU)) 2097 + return arm_smmu_init(); 2098 + 2099 + return 0; 2100 + } 2101 + IORT_ACPI_DECLARE(arm_smmu, ACPI_SIG_IORT, arm_smmu_acpi_init); 2102 + #endif 2176 2103 2177 2104 MODULE_DESCRIPTION("IOMMU API for ARM architected SMMU implementations"); 2178 2105 MODULE_AUTHOR("Will Deacon <will.deacon@arm.com>");
+21 -3
drivers/iommu/dma-iommu.c
··· 432 432 return ret; 433 433 } 434 434 435 - dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, 436 - unsigned long offset, size_t size, int prot) 435 + static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, 436 + size_t size, int prot) 437 437 { 438 438 dma_addr_t dma_addr; 439 439 struct iommu_domain *domain = iommu_get_domain_for_dev(dev); 440 440 struct iova_domain *iovad = cookie_iovad(domain); 441 - phys_addr_t phys = page_to_phys(page) + offset; 442 441 size_t iova_off = iova_offset(iovad, phys); 443 442 size_t len = iova_align(iovad, size + iova_off); 444 443 struct iova *iova = __alloc_iova(domain, len, dma_get_mask(dev)); ··· 451 452 return DMA_ERROR_CODE; 452 453 } 453 454 return dma_addr + iova_off; 455 + } 456 + 457 + dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, 458 + unsigned long offset, size_t size, int prot) 459 + { 460 + return __iommu_dma_map(dev, page_to_phys(page) + offset, size, prot); 454 461 } 455 462 456 463 void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size, ··· 627 622 * contiguous IOVA allocation, so this is incredibly easy. 628 623 */ 629 624 __iommu_dma_unmap(iommu_get_domain_for_dev(dev), sg_dma_address(sg)); 625 + } 626 + 627 + dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys, 628 + size_t size, enum dma_data_direction dir, unsigned long attrs) 629 + { 630 + return __iommu_dma_map(dev, phys, size, 631 + dma_direction_to_prot(dir, false) | IOMMU_MMIO); 632 + } 633 + 634 + void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, 635 + size_t size, enum dma_data_direction dir, unsigned long attrs) 636 + { 637 + __iommu_dma_unmap(iommu_get_domain_for_dev(dev), handle); 630 638 } 631 639 632 640 int iommu_dma_supported(struct device *dev, u64 mask)
+149 -150
drivers/iommu/exynos-iommu.c
··· 70 70 #define SYSMMU_PG_ENT_SHIFT 0 71 71 #define SYSMMU_V5_PG_ENT_SHIFT 4 72 72 73 + static const sysmmu_pte_t *LV1_PROT; 74 + static const sysmmu_pte_t SYSMMU_LV1_PROT[] = { 75 + ((0 << 15) | (0 << 10)), /* no access */ 76 + ((1 << 15) | (1 << 10)), /* IOMMU_READ only */ 77 + ((0 << 15) | (1 << 10)), /* IOMMU_WRITE not supported, use read/write */ 78 + ((0 << 15) | (1 << 10)), /* IOMMU_READ | IOMMU_WRITE */ 79 + }; 80 + static const sysmmu_pte_t SYSMMU_V5_LV1_PROT[] = { 81 + (0 << 4), /* no access */ 82 + (1 << 4), /* IOMMU_READ only */ 83 + (2 << 4), /* IOMMU_WRITE only */ 84 + (3 << 4), /* IOMMU_READ | IOMMU_WRITE */ 85 + }; 86 + 87 + static const sysmmu_pte_t *LV2_PROT; 88 + static const sysmmu_pte_t SYSMMU_LV2_PROT[] = { 89 + ((0 << 9) | (0 << 4)), /* no access */ 90 + ((1 << 9) | (1 << 4)), /* IOMMU_READ only */ 91 + ((0 << 9) | (1 << 4)), /* IOMMU_WRITE not supported, use read/write */ 92 + ((0 << 9) | (1 << 4)), /* IOMMU_READ | IOMMU_WRITE */ 93 + }; 94 + static const sysmmu_pte_t SYSMMU_V5_LV2_PROT[] = { 95 + (0 << 2), /* no access */ 96 + (1 << 2), /* IOMMU_READ only */ 97 + (2 << 2), /* IOMMU_WRITE only */ 98 + (3 << 2), /* IOMMU_READ | IOMMU_WRITE */ 99 + }; 100 + 101 + #define SYSMMU_SUPPORTED_PROT_BITS (IOMMU_READ | IOMMU_WRITE) 102 + 73 103 #define sect_to_phys(ent) (((phys_addr_t) ent) << PG_ENT_SHIFT) 74 104 #define section_phys(sent) (sect_to_phys(*(sent)) & SECT_MASK) 75 105 #define section_offs(iova) (iova & (SECT_SIZE - 1)) ··· 127 97 #define SPAGES_PER_LPAGE (LPAGE_SIZE / SPAGE_SIZE) 128 98 #define lv2table_base(sent) (sect_to_phys(*(sent) & 0xFFFFFFC0)) 129 99 130 - #define mk_lv1ent_sect(pa) ((pa >> PG_ENT_SHIFT) | 2) 100 + #define mk_lv1ent_sect(pa, prot) ((pa >> PG_ENT_SHIFT) | LV1_PROT[prot] | 2) 131 101 #define mk_lv1ent_page(pa) ((pa >> PG_ENT_SHIFT) | 1) 132 - #define mk_lv2ent_lpage(pa) ((pa >> PG_ENT_SHIFT) | 1) 133 - #define mk_lv2ent_spage(pa) ((pa >> PG_ENT_SHIFT) | 2) 102 + #define mk_lv2ent_lpage(pa, prot) ((pa >> PG_ENT_SHIFT) | LV2_PROT[prot] | 1) 103 + #define mk_lv2ent_spage(pa, prot) ((pa >> PG_ENT_SHIFT) | LV2_PROT[prot] | 2) 134 104 135 105 #define CTRL_ENABLE 0x5 136 106 #define CTRL_BLOCK 0x7 137 107 #define CTRL_DISABLE 0x0 138 108 139 109 #define CFG_LRU 0x1 110 + #define CFG_EAP (1 << 2) 140 111 #define CFG_QOS(n) ((n & 0xF) << 7) 141 112 #define CFG_ACGEN (1 << 24) /* System MMU 3.3 only */ 142 113 #define CFG_SYSSEL (1 << 22) /* System MMU 3.2 only */ ··· 237 206 struct exynos_iommu_owner { 238 207 struct list_head controllers; /* list of sysmmu_drvdata.owner_node */ 239 208 struct iommu_domain *domain; /* domain this device is attached */ 209 + struct mutex rpm_lock; /* for runtime pm of all sysmmus */ 240 210 }; 241 211 242 212 /* ··· 269 237 struct clk *aclk; /* SYSMMU's aclk clock */ 270 238 struct clk *pclk; /* SYSMMU's pclk clock */ 271 239 struct clk *clk_master; /* master's device clock */ 272 - int activations; /* number of calls to sysmmu_enable */ 273 240 spinlock_t lock; /* lock for modyfying state */ 241 + bool active; /* current status */ 274 242 struct exynos_iommu_domain *domain; /* domain we belong to */ 275 243 struct list_head domain_node; /* node for domain clients list */ 276 244 struct list_head owner_node; /* node for owner controllers list */ ··· 281 249 static struct exynos_iommu_domain *to_exynos_domain(struct iommu_domain *dom) 282 250 { 283 251 return container_of(dom, struct exynos_iommu_domain, domain); 284 - } 285 - 286 - static bool set_sysmmu_active(struct sysmmu_drvdata *data) 287 - { 288 - /* return true if the System MMU was not active previously 289 - and it needs to be initialized */ 290 - return ++data->activations == 1; 291 - } 292 - 293 - static bool set_sysmmu_inactive(struct sysmmu_drvdata *data) 294 - { 295 - /* return true if the System MMU is needed to be disabled */ 296 - BUG_ON(data->activations < 1); 297 - return --data->activations == 0; 298 - } 299 - 300 - static bool is_sysmmu_active(struct sysmmu_drvdata *data) 301 - { 302 - return data->activations > 0; 303 252 } 304 253 305 254 static void sysmmu_unblock(struct sysmmu_drvdata *data) ··· 401 388 unsigned short reg_status, reg_clear; 402 389 int ret = -ENOSYS; 403 390 404 - WARN_ON(!is_sysmmu_active(data)); 391 + WARN_ON(!data->active); 405 392 406 393 if (MMU_MAJ_VER(data->version) < 5) { 407 394 reg_status = REG_INT_STATUS; ··· 447 434 return IRQ_HANDLED; 448 435 } 449 436 450 - static void __sysmmu_disable_nocount(struct sysmmu_drvdata *data) 437 + static void __sysmmu_disable(struct sysmmu_drvdata *data) 451 438 { 452 - clk_enable(data->clk_master); 453 - 454 - writel(CTRL_DISABLE, data->sfrbase + REG_MMU_CTRL); 455 - writel(0, data->sfrbase + REG_MMU_CFG); 456 - 457 - __sysmmu_disable_clocks(data); 458 - } 459 - 460 - static bool __sysmmu_disable(struct sysmmu_drvdata *data) 461 - { 462 - bool disabled; 463 439 unsigned long flags; 464 440 441 + clk_enable(data->clk_master); 442 + 465 443 spin_lock_irqsave(&data->lock, flags); 466 - 467 - disabled = set_sysmmu_inactive(data); 468 - 469 - if (disabled) { 470 - data->pgtable = 0; 471 - data->domain = NULL; 472 - 473 - __sysmmu_disable_nocount(data); 474 - 475 - dev_dbg(data->sysmmu, "Disabled\n"); 476 - } else { 477 - dev_dbg(data->sysmmu, "%d times left to disable\n", 478 - data->activations); 479 - } 480 - 444 + writel(CTRL_DISABLE, data->sfrbase + REG_MMU_CTRL); 445 + writel(0, data->sfrbase + REG_MMU_CFG); 446 + data->active = false; 481 447 spin_unlock_irqrestore(&data->lock, flags); 482 448 483 - return disabled; 449 + __sysmmu_disable_clocks(data); 484 450 } 485 451 486 452 static void __sysmmu_init_config(struct sysmmu_drvdata *data) ··· 473 481 else 474 482 cfg = CFG_QOS(15) | CFG_FLPDCACHE | CFG_ACGEN; 475 483 484 + cfg |= CFG_EAP; /* enable access protection bits check */ 485 + 476 486 writel(cfg, data->sfrbase + REG_MMU_CFG); 477 487 } 478 488 479 - static void __sysmmu_enable_nocount(struct sysmmu_drvdata *data) 489 + static void __sysmmu_enable(struct sysmmu_drvdata *data) 480 490 { 491 + unsigned long flags; 492 + 481 493 __sysmmu_enable_clocks(data); 482 494 495 + spin_lock_irqsave(&data->lock, flags); 483 496 writel(CTRL_BLOCK, data->sfrbase + REG_MMU_CTRL); 484 - 485 497 __sysmmu_init_config(data); 486 - 487 498 __sysmmu_set_ptbase(data, data->pgtable); 488 - 489 499 writel(CTRL_ENABLE, data->sfrbase + REG_MMU_CTRL); 500 + data->active = true; 501 + spin_unlock_irqrestore(&data->lock, flags); 490 502 491 503 /* 492 504 * SYSMMU driver keeps master's clock enabled only for the short ··· 501 505 clk_disable(data->clk_master); 502 506 } 503 507 504 - static int __sysmmu_enable(struct sysmmu_drvdata *data, phys_addr_t pgtable, 505 - struct exynos_iommu_domain *domain) 506 - { 507 - int ret = 0; 508 - unsigned long flags; 509 - 510 - spin_lock_irqsave(&data->lock, flags); 511 - if (set_sysmmu_active(data)) { 512 - data->pgtable = pgtable; 513 - data->domain = domain; 514 - 515 - __sysmmu_enable_nocount(data); 516 - 517 - dev_dbg(data->sysmmu, "Enabled\n"); 518 - } else { 519 - ret = (pgtable == data->pgtable) ? 1 : -EBUSY; 520 - 521 - dev_dbg(data->sysmmu, "already enabled\n"); 522 - } 523 - 524 - if (WARN_ON(ret < 0)) 525 - set_sysmmu_inactive(data); /* decrement count */ 526 - 527 - spin_unlock_irqrestore(&data->lock, flags); 528 - 529 - return ret; 530 - } 531 - 532 508 static void sysmmu_tlb_invalidate_flpdcache(struct sysmmu_drvdata *data, 533 509 sysmmu_iova_t iova) 534 510 { 535 511 unsigned long flags; 536 512 537 - 538 513 spin_lock_irqsave(&data->lock, flags); 539 - if (is_sysmmu_active(data) && data->version >= MAKE_MMU_VER(3, 3)) { 514 + if (data->active && data->version >= MAKE_MMU_VER(3, 3)) { 540 515 clk_enable(data->clk_master); 541 516 __sysmmu_tlb_invalidate_entry(data, iova, 1); 542 517 clk_disable(data->clk_master); 543 518 } 544 519 spin_unlock_irqrestore(&data->lock, flags); 545 - 546 520 } 547 521 548 522 static void sysmmu_tlb_invalidate_entry(struct sysmmu_drvdata *data, ··· 521 555 unsigned long flags; 522 556 523 557 spin_lock_irqsave(&data->lock, flags); 524 - if (is_sysmmu_active(data)) { 558 + if (data->active) { 525 559 unsigned int num_inv = 1; 526 560 527 561 clk_enable(data->clk_master); ··· 544 578 sysmmu_unblock(data); 545 579 } 546 580 clk_disable(data->clk_master); 547 - } else { 548 - dev_dbg(data->master, 549 - "disabled. Skipping TLB invalidation @ %#x\n", iova); 550 581 } 551 582 spin_unlock_irqrestore(&data->lock, flags); 552 583 } ··· 615 652 616 653 __sysmmu_get_version(data); 617 654 if (PG_ENT_SHIFT < 0) { 618 - if (MMU_MAJ_VER(data->version) < 5) 655 + if (MMU_MAJ_VER(data->version) < 5) { 619 656 PG_ENT_SHIFT = SYSMMU_PG_ENT_SHIFT; 620 - else 657 + LV1_PROT = SYSMMU_LV1_PROT; 658 + LV2_PROT = SYSMMU_LV2_PROT; 659 + } else { 621 660 PG_ENT_SHIFT = SYSMMU_V5_PG_ENT_SHIFT; 661 + LV1_PROT = SYSMMU_V5_LV1_PROT; 662 + LV2_PROT = SYSMMU_V5_LV2_PROT; 663 + } 622 664 } 623 665 624 666 pm_runtime_enable(dev); ··· 633 665 return 0; 634 666 } 635 667 636 - #ifdef CONFIG_PM_SLEEP 637 - static int exynos_sysmmu_suspend(struct device *dev) 668 + static int __maybe_unused exynos_sysmmu_suspend(struct device *dev) 638 669 { 639 670 struct sysmmu_drvdata *data = dev_get_drvdata(dev); 671 + struct device *master = data->master; 640 672 641 - dev_dbg(dev, "suspend\n"); 642 - if (is_sysmmu_active(data)) { 643 - __sysmmu_disable_nocount(data); 644 - pm_runtime_put(dev); 673 + if (master) { 674 + struct exynos_iommu_owner *owner = master->archdata.iommu; 675 + 676 + mutex_lock(&owner->rpm_lock); 677 + if (data->domain) { 678 + dev_dbg(data->sysmmu, "saving state\n"); 679 + __sysmmu_disable(data); 680 + } 681 + mutex_unlock(&owner->rpm_lock); 645 682 } 646 683 return 0; 647 684 } 648 685 649 - static int exynos_sysmmu_resume(struct device *dev) 686 + static int __maybe_unused exynos_sysmmu_resume(struct device *dev) 650 687 { 651 688 struct sysmmu_drvdata *data = dev_get_drvdata(dev); 689 + struct device *master = data->master; 652 690 653 - dev_dbg(dev, "resume\n"); 654 - if (is_sysmmu_active(data)) { 655 - pm_runtime_get_sync(dev); 656 - __sysmmu_enable_nocount(data); 691 + if (master) { 692 + struct exynos_iommu_owner *owner = master->archdata.iommu; 693 + 694 + mutex_lock(&owner->rpm_lock); 695 + if (data->domain) { 696 + dev_dbg(data->sysmmu, "restoring state\n"); 697 + __sysmmu_enable(data); 698 + } 699 + mutex_unlock(&owner->rpm_lock); 657 700 } 658 701 return 0; 659 702 } 660 - #endif 661 703 662 704 static const struct dev_pm_ops sysmmu_pm_ops = { 663 - SET_LATE_SYSTEM_SLEEP_PM_OPS(exynos_sysmmu_suspend, exynos_sysmmu_resume) 705 + SET_RUNTIME_PM_OPS(exynos_sysmmu_suspend, exynos_sysmmu_resume, NULL) 706 + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 707 + pm_runtime_force_resume) 664 708 }; 665 709 666 710 static const struct of_device_id sysmmu_of_match[] __initconst = { ··· 776 796 spin_lock_irqsave(&domain->lock, flags); 777 797 778 798 list_for_each_entry_safe(data, next, &domain->clients, domain_node) { 779 - if (__sysmmu_disable(data)) 780 - data->master = NULL; 799 + spin_lock(&data->lock); 800 + __sysmmu_disable(data); 801 + data->pgtable = 0; 802 + data->domain = NULL; 781 803 list_del_init(&data->domain_node); 804 + spin_unlock(&data->lock); 782 805 } 783 806 784 807 spin_unlock_irqrestore(&domain->lock, flags); ··· 815 832 phys_addr_t pagetable = virt_to_phys(domain->pgtable); 816 833 struct sysmmu_drvdata *data, *next; 817 834 unsigned long flags; 818 - bool found = false; 819 835 820 836 if (!has_sysmmu(dev) || owner->domain != iommu_domain) 821 837 return; 822 838 839 + mutex_lock(&owner->rpm_lock); 840 + 841 + list_for_each_entry(data, &owner->controllers, owner_node) { 842 + pm_runtime_get_noresume(data->sysmmu); 843 + if (pm_runtime_active(data->sysmmu)) 844 + __sysmmu_disable(data); 845 + pm_runtime_put(data->sysmmu); 846 + } 847 + 823 848 spin_lock_irqsave(&domain->lock, flags); 824 849 list_for_each_entry_safe(data, next, &domain->clients, domain_node) { 825 - if (data->master == dev) { 826 - if (__sysmmu_disable(data)) { 827 - data->master = NULL; 828 - list_del_init(&data->domain_node); 829 - } 830 - pm_runtime_put(data->sysmmu); 831 - found = true; 832 - } 850 + spin_lock(&data->lock); 851 + data->pgtable = 0; 852 + data->domain = NULL; 853 + list_del_init(&data->domain_node); 854 + spin_unlock(&data->lock); 833 855 } 856 + owner->domain = NULL; 834 857 spin_unlock_irqrestore(&domain->lock, flags); 835 858 836 - owner->domain = NULL; 859 + mutex_unlock(&owner->rpm_lock); 837 860 838 - if (found) 839 - dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", 840 - __func__, &pagetable); 841 - else 842 - dev_err(dev, "%s: No IOMMU is attached\n", __func__); 861 + dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", __func__, 862 + &pagetable); 843 863 } 844 864 845 865 static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, ··· 853 867 struct sysmmu_drvdata *data; 854 868 phys_addr_t pagetable = virt_to_phys(domain->pgtable); 855 869 unsigned long flags; 856 - int ret = -ENODEV; 857 870 858 871 if (!has_sysmmu(dev)) 859 872 return -ENODEV; ··· 860 875 if (owner->domain) 861 876 exynos_iommu_detach_device(owner->domain, dev); 862 877 878 + mutex_lock(&owner->rpm_lock); 879 + 880 + spin_lock_irqsave(&domain->lock, flags); 863 881 list_for_each_entry(data, &owner->controllers, owner_node) { 864 - pm_runtime_get_sync(data->sysmmu); 865 - ret = __sysmmu_enable(data, pagetable, domain); 866 - if (ret >= 0) { 867 - data->master = dev; 868 - 869 - spin_lock_irqsave(&domain->lock, flags); 870 - list_add_tail(&data->domain_node, &domain->clients); 871 - spin_unlock_irqrestore(&domain->lock, flags); 872 - } 882 + spin_lock(&data->lock); 883 + data->pgtable = pagetable; 884 + data->domain = domain; 885 + list_add_tail(&data->domain_node, &domain->clients); 886 + spin_unlock(&data->lock); 873 887 } 874 - 875 - if (ret < 0) { 876 - dev_err(dev, "%s: Failed to attach IOMMU with pgtable %pa\n", 877 - __func__, &pagetable); 878 - return ret; 879 - } 880 - 881 888 owner->domain = iommu_domain; 882 - dev_dbg(dev, "%s: Attached IOMMU with pgtable %pa %s\n", 883 - __func__, &pagetable, (ret == 0) ? "" : ", again"); 889 + spin_unlock_irqrestore(&domain->lock, flags); 884 890 885 - return ret; 891 + list_for_each_entry(data, &owner->controllers, owner_node) { 892 + pm_runtime_get_noresume(data->sysmmu); 893 + if (pm_runtime_active(data->sysmmu)) 894 + __sysmmu_enable(data); 895 + pm_runtime_put(data->sysmmu); 896 + } 897 + 898 + mutex_unlock(&owner->rpm_lock); 899 + 900 + dev_dbg(dev, "%s: Attached IOMMU with pgtable %pa\n", __func__, 901 + &pagetable); 902 + 903 + return 0; 886 904 } 887 905 888 906 static sysmmu_pte_t *alloc_lv2entry(struct exynos_iommu_domain *domain, ··· 942 954 943 955 static int lv1set_section(struct exynos_iommu_domain *domain, 944 956 sysmmu_pte_t *sent, sysmmu_iova_t iova, 945 - phys_addr_t paddr, short *pgcnt) 957 + phys_addr_t paddr, int prot, short *pgcnt) 946 958 { 947 959 if (lv1ent_section(sent)) { 948 960 WARN(1, "Trying mapping on 1MiB@%#08x that is mapped", ··· 961 973 *pgcnt = 0; 962 974 } 963 975 964 - update_pte(sent, mk_lv1ent_sect(paddr)); 976 + update_pte(sent, mk_lv1ent_sect(paddr, prot)); 965 977 966 978 spin_lock(&domain->lock); 967 979 if (lv1ent_page_zero(sent)) { ··· 979 991 } 980 992 981 993 static int lv2set_page(sysmmu_pte_t *pent, phys_addr_t paddr, size_t size, 982 - short *pgcnt) 994 + int prot, short *pgcnt) 983 995 { 984 996 if (size == SPAGE_SIZE) { 985 997 if (WARN_ON(!lv2ent_fault(pent))) 986 998 return -EADDRINUSE; 987 999 988 - update_pte(pent, mk_lv2ent_spage(paddr)); 1000 + update_pte(pent, mk_lv2ent_spage(paddr, prot)); 989 1001 *pgcnt -= 1; 990 1002 } else { /* size == LPAGE_SIZE */ 991 1003 int i; ··· 1001 1013 return -EADDRINUSE; 1002 1014 } 1003 1015 1004 - *pent = mk_lv2ent_lpage(paddr); 1016 + *pent = mk_lv2ent_lpage(paddr, prot); 1005 1017 } 1006 1018 dma_sync_single_for_device(dma_dev, pent_base, 1007 1019 sizeof(*pent) * SPAGES_PER_LPAGE, ··· 1049 1061 int ret = -ENOMEM; 1050 1062 1051 1063 BUG_ON(domain->pgtable == NULL); 1064 + prot &= SYSMMU_SUPPORTED_PROT_BITS; 1052 1065 1053 1066 spin_lock_irqsave(&domain->pgtablelock, flags); 1054 1067 1055 1068 entry = section_entry(domain->pgtable, iova); 1056 1069 1057 1070 if (size == SECT_SIZE) { 1058 - ret = lv1set_section(domain, entry, iova, paddr, 1071 + ret = lv1set_section(domain, entry, iova, paddr, prot, 1059 1072 &domain->lv2entcnt[lv1ent_offset(iova)]); 1060 1073 } else { 1061 1074 sysmmu_pte_t *pent; ··· 1067 1078 if (IS_ERR(pent)) 1068 1079 ret = PTR_ERR(pent); 1069 1080 else 1070 - ret = lv2set_page(pent, paddr, size, 1081 + ret = lv2set_page(pent, paddr, size, prot, 1071 1082 &domain->lv2entcnt[lv1ent_offset(iova)]); 1072 1083 } 1073 1084 ··· 1257 1268 return -ENOMEM; 1258 1269 1259 1270 INIT_LIST_HEAD(&owner->controllers); 1271 + mutex_init(&owner->rpm_lock); 1260 1272 dev->archdata.iommu = owner; 1261 1273 } 1262 1274 1263 1275 list_add_tail(&data->owner_node, &owner->controllers); 1276 + data->master = dev; 1277 + 1278 + /* 1279 + * SYSMMU will be runtime activated via device link (dependency) to its 1280 + * master device, so there are no direct calls to pm_runtime_get/put 1281 + * in this driver. 1282 + */ 1283 + device_link_add(dev, data->sysmmu, DL_FLAG_PM_RUNTIME); 1284 + 1264 1285 return 0; 1265 1286 } 1266 1287
+1 -4
drivers/iommu/io-pgtable-arm-v7s.c
··· 793 793 * Distinct mappings of different granule sizes. 794 794 */ 795 795 iova = 0; 796 - i = find_first_bit(&cfg.pgsize_bitmap, BITS_PER_LONG); 797 - while (i != BITS_PER_LONG) { 796 + for_each_set_bit(i, &cfg.pgsize_bitmap, BITS_PER_LONG) { 798 797 size = 1UL << i; 799 798 if (ops->map(ops, iova, iova, size, IOMMU_READ | 800 799 IOMMU_WRITE | ··· 810 811 return __FAIL(ops); 811 812 812 813 iova += SZ_16M; 813 - i++; 814 - i = find_next_bit(&cfg.pgsize_bitmap, BITS_PER_LONG, i); 815 814 loopnr++; 816 815 } 817 816
+2 -5
drivers/iommu/io-pgtable-arm.c
··· 916 916 WARN_ON(cookie != cfg_cookie); 917 917 } 918 918 919 - static struct iommu_gather_ops dummy_tlb_ops __initdata = { 919 + static const struct iommu_gather_ops dummy_tlb_ops __initconst = { 920 920 .tlb_flush_all = dummy_tlb_flush_all, 921 921 .tlb_add_flush = dummy_tlb_add_flush, 922 922 .tlb_sync = dummy_tlb_sync, ··· 980 980 * Distinct mappings of different granule sizes. 981 981 */ 982 982 iova = 0; 983 - j = find_first_bit(&cfg->pgsize_bitmap, BITS_PER_LONG); 984 - while (j != BITS_PER_LONG) { 983 + for_each_set_bit(j, &cfg->pgsize_bitmap, BITS_PER_LONG) { 985 984 size = 1UL << j; 986 985 987 986 if (ops->map(ops, iova, iova, size, IOMMU_READ | ··· 998 999 return __FAIL(ops, i); 999 1000 1000 1001 iova += SZ_1G; 1001 - j++; 1002 - j = find_next_bit(&cfg->pgsize_bitmap, BITS_PER_LONG, j); 1003 1002 } 1004 1003 1005 1004 /* Partial unmap */
+53
drivers/iommu/iommu.c
··· 552 552 EXPORT_SYMBOL_GPL(iommu_group_get); 553 553 554 554 /** 555 + * iommu_group_ref_get - Increment reference on a group 556 + * @group: the group to use, must not be NULL 557 + * 558 + * This function is called by iommu drivers to take additional references on an 559 + * existing group. Returns the given group for convenience. 560 + */ 561 + struct iommu_group *iommu_group_ref_get(struct iommu_group *group) 562 + { 563 + kobject_get(group->devices_kobj); 564 + return group; 565 + } 566 + 567 + /** 555 568 * iommu_group_put - Decrement group reference 556 569 * @group: the group to use 557 570 * ··· 1626 1613 iommu_group_put(group); 1627 1614 1628 1615 return ret; 1616 + } 1617 + 1618 + struct iommu_instance { 1619 + struct list_head list; 1620 + struct fwnode_handle *fwnode; 1621 + const struct iommu_ops *ops; 1622 + }; 1623 + static LIST_HEAD(iommu_instance_list); 1624 + static DEFINE_SPINLOCK(iommu_instance_lock); 1625 + 1626 + void iommu_register_instance(struct fwnode_handle *fwnode, 1627 + const struct iommu_ops *ops) 1628 + { 1629 + struct iommu_instance *iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); 1630 + 1631 + if (WARN_ON(!iommu)) 1632 + return; 1633 + 1634 + of_node_get(to_of_node(fwnode)); 1635 + INIT_LIST_HEAD(&iommu->list); 1636 + iommu->fwnode = fwnode; 1637 + iommu->ops = ops; 1638 + spin_lock(&iommu_instance_lock); 1639 + list_add_tail(&iommu->list, &iommu_instance_list); 1640 + spin_unlock(&iommu_instance_lock); 1641 + } 1642 + 1643 + const struct iommu_ops *iommu_get_instance(struct fwnode_handle *fwnode) 1644 + { 1645 + struct iommu_instance *instance; 1646 + const struct iommu_ops *ops = NULL; 1647 + 1648 + spin_lock(&iommu_instance_lock); 1649 + list_for_each_entry(instance, &iommu_instance_list, list) 1650 + if (instance->fwnode == fwnode) { 1651 + ops = instance->ops; 1652 + break; 1653 + } 1654 + spin_unlock(&iommu_instance_lock); 1655 + return ops; 1629 1656 } 1630 1657 1631 1658 int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
+1 -1
drivers/iommu/iova.c
··· 56 56 static struct rb_node * 57 57 __get_cached_rbnode(struct iova_domain *iovad, unsigned long *limit_pfn) 58 58 { 59 - if ((*limit_pfn != iovad->dma_32bit_pfn) || 59 + if ((*limit_pfn > iovad->dma_32bit_pfn) || 60 60 (iovad->cached32_node == NULL)) 61 61 return rb_last(&iovad->rbroot); 62 62 else {
+25 -60
drivers/iommu/mtk_iommu.c
··· 195 195 static void mtk_iommu_config(struct mtk_iommu_data *data, 196 196 struct device *dev, bool enable) 197 197 { 198 - struct mtk_iommu_client_priv *head, *cur, *next; 199 198 struct mtk_smi_larb_iommu *larb_mmu; 200 199 unsigned int larbid, portid; 200 + struct iommu_fwspec *fwspec = dev->iommu_fwspec; 201 + int i; 201 202 202 - head = dev->archdata.iommu; 203 - list_for_each_entry_safe(cur, next, &head->client, client) { 204 - larbid = MTK_M4U_TO_LARB(cur->mtk_m4u_id); 205 - portid = MTK_M4U_TO_PORT(cur->mtk_m4u_id); 203 + for (i = 0; i < fwspec->num_ids; ++i) { 204 + larbid = MTK_M4U_TO_LARB(fwspec->ids[i]); 205 + portid = MTK_M4U_TO_PORT(fwspec->ids[i]); 206 206 larb_mmu = &data->smi_imu.larb_imu[larbid]; 207 207 208 208 dev_dbg(dev, "%s iommu port: %d\n", ··· 282 282 struct device *dev) 283 283 { 284 284 struct mtk_iommu_domain *dom = to_mtk_domain(domain); 285 - struct mtk_iommu_client_priv *priv = dev->archdata.iommu; 286 - struct mtk_iommu_data *data; 285 + struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; 287 286 int ret; 288 287 289 - if (!priv) 288 + if (!data) 290 289 return -ENODEV; 291 290 292 - data = dev_get_drvdata(priv->m4udev); 293 291 if (!data->m4u_dom) { 294 292 data->m4u_dom = dom; 295 293 ret = mtk_iommu_domain_finalise(data); ··· 308 310 static void mtk_iommu_detach_device(struct iommu_domain *domain, 309 311 struct device *dev) 310 312 { 311 - struct mtk_iommu_client_priv *priv = dev->archdata.iommu; 312 - struct mtk_iommu_data *data; 313 + struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; 313 314 314 - if (!priv) 315 + if (!data) 315 316 return; 316 317 317 - data = dev_get_drvdata(priv->m4udev); 318 318 mtk_iommu_config(data, dev, false); 319 319 } 320 320 ··· 362 366 { 363 367 struct iommu_group *group; 364 368 365 - if (!dev->archdata.iommu) /* Not a iommu client device */ 366 - return -ENODEV; 369 + if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) 370 + return -ENODEV; /* Not a iommu client device */ 367 371 368 372 group = iommu_group_get_for_dev(dev); 369 373 if (IS_ERR(group)) ··· 375 379 376 380 static void mtk_iommu_remove_device(struct device *dev) 377 381 { 378 - struct mtk_iommu_client_priv *head, *cur, *next; 379 - 380 - head = dev->archdata.iommu; 381 - if (!head) 382 + if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) 382 383 return; 383 384 384 - list_for_each_entry_safe(cur, next, &head->client, client) { 385 - list_del(&cur->client); 386 - kfree(cur); 387 - } 388 - kfree(head); 389 - dev->archdata.iommu = NULL; 390 - 391 385 iommu_group_remove_device(dev); 386 + iommu_fwspec_free(dev); 392 387 } 393 388 394 389 static struct iommu_group *mtk_iommu_device_group(struct device *dev) 395 390 { 396 - struct mtk_iommu_data *data; 397 - struct mtk_iommu_client_priv *priv; 391 + struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; 398 392 399 - priv = dev->archdata.iommu; 400 - if (!priv) 393 + if (!data) 401 394 return ERR_PTR(-ENODEV); 402 395 403 396 /* All the client devices are in the same m4u iommu-group */ 404 - data = dev_get_drvdata(priv->m4udev); 405 397 if (!data->m4u_group) { 406 398 data->m4u_group = iommu_group_alloc(); 407 399 if (IS_ERR(data->m4u_group)) 408 400 dev_err(dev, "Failed to allocate M4U IOMMU group\n"); 401 + } else { 402 + iommu_group_ref_get(data->m4u_group); 409 403 } 410 404 return data->m4u_group; 411 405 } 412 406 413 407 static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) 414 408 { 415 - struct mtk_iommu_client_priv *head, *priv, *next; 416 409 struct platform_device *m4updev; 417 410 418 411 if (args->args_count != 1) { ··· 410 425 return -EINVAL; 411 426 } 412 427 413 - if (!dev->archdata.iommu) { 428 + if (!dev->iommu_fwspec->iommu_priv) { 414 429 /* Get the m4u device */ 415 430 m4updev = of_find_device_by_node(args->np); 416 431 if (WARN_ON(!m4updev)) 417 432 return -EINVAL; 418 433 419 - head = kzalloc(sizeof(*head), GFP_KERNEL); 420 - if (!head) 421 - return -ENOMEM; 422 - 423 - dev->archdata.iommu = head; 424 - INIT_LIST_HEAD(&head->client); 425 - head->m4udev = &m4updev->dev; 426 - } else { 427 - head = dev->archdata.iommu; 434 + dev->iommu_fwspec->iommu_priv = platform_get_drvdata(m4updev); 428 435 } 429 436 430 - priv = kzalloc(sizeof(*priv), GFP_KERNEL); 431 - if (!priv) 432 - goto err_free_mem; 433 - 434 - priv->mtk_m4u_id = args->args[0]; 435 - list_add_tail(&priv->client, &head->client); 436 - 437 - return 0; 438 - 439 - err_free_mem: 440 - list_for_each_entry_safe(priv, next, &head->client, client) 441 - kfree(priv); 442 - kfree(head); 443 - dev->archdata.iommu = NULL; 444 - return -ENOMEM; 437 + return iommu_fwspec_add_ids(dev, args->args, 1); 445 438 } 446 439 447 440 static struct iommu_ops mtk_iommu_ops = { ··· 546 583 continue; 547 584 548 585 plarbdev = of_find_device_by_node(larbnode); 549 - of_node_put(larbnode); 550 586 if (!plarbdev) { 551 587 plarbdev = of_platform_device_create( 552 588 larbnode, NULL, 553 589 platform_bus_type.dev_root); 554 - if (!plarbdev) 590 + if (!plarbdev) { 591 + of_node_put(larbnode); 555 592 return -EPROBE_DEFER; 593 + } 556 594 } 557 595 data->smi_imu.larb_imu[i].dev = &plarbdev->dev; 558 596 559 - component_match_add(dev, &match, compare_of, larbnode); 597 + component_match_add_release(dev, &match, release_of, 598 + compare_of, larbnode); 560 599 } 561 600 562 601 platform_set_drvdata(pdev, data);
+5 -6
drivers/iommu/mtk_iommu.h
··· 34 34 u32 int_main_control; 35 35 }; 36 36 37 - struct mtk_iommu_client_priv { 38 - struct list_head client; 39 - unsigned int mtk_m4u_id; 40 - struct device *m4udev; 41 - }; 42 - 43 37 struct mtk_iommu_domain; 44 38 45 39 struct mtk_iommu_data { ··· 52 58 static inline int compare_of(struct device *dev, void *data) 53 59 { 54 60 return dev->of_node == data; 61 + } 62 + 63 + static inline void release_of(struct device *dev, void *data) 64 + { 65 + of_node_put(data); 55 66 } 56 67 57 68 static inline int mtk_iommu_bind(struct device *dev)
+43 -62
drivers/iommu/mtk_iommu_v1.c
··· 204 204 static void mtk_iommu_config(struct mtk_iommu_data *data, 205 205 struct device *dev, bool enable) 206 206 { 207 - struct mtk_iommu_client_priv *head, *cur, *next; 208 207 struct mtk_smi_larb_iommu *larb_mmu; 209 208 unsigned int larbid, portid; 209 + struct iommu_fwspec *fwspec = dev->iommu_fwspec; 210 + int i; 210 211 211 - head = dev->archdata.iommu; 212 - list_for_each_entry_safe(cur, next, &head->client, client) { 213 - larbid = mt2701_m4u_to_larb(cur->mtk_m4u_id); 214 - portid = mt2701_m4u_to_port(cur->mtk_m4u_id); 212 + for (i = 0; i < fwspec->num_ids; ++i) { 213 + larbid = mt2701_m4u_to_larb(fwspec->ids[i]); 214 + portid = mt2701_m4u_to_port(fwspec->ids[i]); 215 215 larb_mmu = &data->smi_imu.larb_imu[larbid]; 216 216 217 217 dev_dbg(dev, "%s iommu port: %d\n", ··· 271 271 struct device *dev) 272 272 { 273 273 struct mtk_iommu_domain *dom = to_mtk_domain(domain); 274 - struct mtk_iommu_client_priv *priv = dev->archdata.iommu; 275 - struct mtk_iommu_data *data; 274 + struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; 276 275 int ret; 277 276 278 - if (!priv) 277 + if (!data) 279 278 return -ENODEV; 280 279 281 - data = dev_get_drvdata(priv->m4udev); 282 280 if (!data->m4u_dom) { 283 281 data->m4u_dom = dom; 284 282 ret = mtk_iommu_domain_finalise(data); ··· 293 295 static void mtk_iommu_detach_device(struct iommu_domain *domain, 294 296 struct device *dev) 295 297 { 296 - struct mtk_iommu_client_priv *priv = dev->archdata.iommu; 297 - struct mtk_iommu_data *data; 298 + struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; 298 299 299 - if (!priv) 300 + if (!data) 300 301 return; 301 302 302 - data = dev_get_drvdata(priv->m4udev); 303 303 mtk_iommu_config(data, dev, false); 304 304 } 305 305 ··· 362 366 return pa; 363 367 } 364 368 369 + static struct iommu_ops mtk_iommu_ops; 370 + 365 371 /* 366 372 * MTK generation one iommu HW only support one iommu domain, and all the client 367 373 * sharing the same iova address space. ··· 371 373 static int mtk_iommu_create_mapping(struct device *dev, 372 374 struct of_phandle_args *args) 373 375 { 374 - struct mtk_iommu_client_priv *head, *priv, *next; 376 + struct mtk_iommu_data *data; 375 377 struct platform_device *m4updev; 376 378 struct dma_iommu_mapping *mtk_mapping; 377 379 struct device *m4udev; ··· 383 385 return -EINVAL; 384 386 } 385 387 386 - if (!dev->archdata.iommu) { 388 + if (!dev->iommu_fwspec) { 389 + ret = iommu_fwspec_init(dev, &args->np->fwnode, &mtk_iommu_ops); 390 + if (ret) 391 + return ret; 392 + } else if (dev->iommu_fwspec->ops != &mtk_iommu_ops) { 393 + return -EINVAL; 394 + } 395 + 396 + if (!dev->iommu_fwspec->iommu_priv) { 387 397 /* Get the m4u device */ 388 398 m4updev = of_find_device_by_node(args->np); 389 399 if (WARN_ON(!m4updev)) 390 400 return -EINVAL; 391 401 392 - head = kzalloc(sizeof(*head), GFP_KERNEL); 393 - if (!head) 394 - return -ENOMEM; 395 - 396 - dev->archdata.iommu = head; 397 - INIT_LIST_HEAD(&head->client); 398 - head->m4udev = &m4updev->dev; 399 - } else { 400 - head = dev->archdata.iommu; 402 + dev->iommu_fwspec->iommu_priv = platform_get_drvdata(m4updev); 401 403 } 402 404 403 - priv = kzalloc(sizeof(*priv), GFP_KERNEL); 404 - if (!priv) { 405 - ret = -ENOMEM; 406 - goto err_free_mem; 407 - } 408 - priv->mtk_m4u_id = args->args[0]; 409 - list_add_tail(&priv->client, &head->client); 405 + ret = iommu_fwspec_add_ids(dev, args->args, 1); 406 + if (ret) 407 + return ret; 410 408 411 - m4udev = head->m4udev; 409 + data = dev->iommu_fwspec->iommu_priv; 410 + m4udev = data->dev; 412 411 mtk_mapping = m4udev->archdata.iommu; 413 412 if (!mtk_mapping) { 414 413 /* MTK iommu support 4GB iova address space. */ 415 414 mtk_mapping = arm_iommu_create_mapping(&platform_bus_type, 416 415 0, 1ULL << 32); 417 - if (IS_ERR(mtk_mapping)) { 418 - ret = PTR_ERR(mtk_mapping); 419 - goto err_free_mem; 420 - } 416 + if (IS_ERR(mtk_mapping)) 417 + return PTR_ERR(mtk_mapping); 418 + 421 419 m4udev->archdata.iommu = mtk_mapping; 422 420 } 423 421 ··· 426 432 err_release_mapping: 427 433 arm_iommu_release_mapping(mtk_mapping); 428 434 m4udev->archdata.iommu = NULL; 429 - err_free_mem: 430 - list_for_each_entry_safe(priv, next, &head->client, client) 431 - kfree(priv); 432 - kfree(head); 433 - dev->archdata.iommu = NULL; 434 435 return ret; 435 436 } 436 437 ··· 447 458 of_node_put(iommu_spec.np); 448 459 } 449 460 450 - if (!dev->archdata.iommu) /* Not a iommu client device */ 451 - return -ENODEV; 461 + if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) 462 + return -ENODEV; /* Not a iommu client device */ 452 463 453 464 group = iommu_group_get_for_dev(dev); 454 465 if (IS_ERR(group)) ··· 460 471 461 472 static void mtk_iommu_remove_device(struct device *dev) 462 473 { 463 - struct mtk_iommu_client_priv *head, *cur, *next; 464 - 465 - head = dev->archdata.iommu; 466 - if (!head) 474 + if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops) 467 475 return; 468 476 469 - list_for_each_entry_safe(cur, next, &head->client, client) { 470 - list_del(&cur->client); 471 - kfree(cur); 472 - } 473 - kfree(head); 474 - dev->archdata.iommu = NULL; 475 - 476 477 iommu_group_remove_device(dev); 478 + iommu_fwspec_free(dev); 477 479 } 478 480 479 481 static struct iommu_group *mtk_iommu_device_group(struct device *dev) 480 482 { 481 - struct mtk_iommu_data *data; 482 - struct mtk_iommu_client_priv *priv; 483 + struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv; 483 484 484 - priv = dev->archdata.iommu; 485 - if (!priv) 485 + if (!data) 486 486 return ERR_PTR(-ENODEV); 487 487 488 488 /* All the client devices are in the same m4u iommu-group */ 489 - data = dev_get_drvdata(priv->m4udev); 490 489 if (!data->m4u_group) { 491 490 data->m4u_group = iommu_group_alloc(); 492 491 if (IS_ERR(data->m4u_group)) 493 492 dev_err(dev, "Failed to allocate M4U IOMMU group\n"); 493 + } else { 494 + iommu_group_ref_get(data->m4u_group); 494 495 } 495 496 return data->m4u_group; 496 497 } ··· 603 624 continue; 604 625 605 626 plarbdev = of_find_device_by_node(larb_spec.np); 606 - of_node_put(larb_spec.np); 607 627 if (!plarbdev) { 608 628 plarbdev = of_platform_device_create( 609 629 larb_spec.np, NULL, 610 630 platform_bus_type.dev_root); 611 - if (!plarbdev) 631 + if (!plarbdev) { 632 + of_node_put(larb_spec.np); 612 633 return -EPROBE_DEFER; 634 + } 613 635 } 614 636 615 637 data->smi_imu.larb_imu[larb_nr].dev = &plarbdev->dev; 616 - component_match_add(dev, &match, compare_of, larb_spec.np); 638 + component_match_add_release(dev, &match, release_of, 639 + compare_of, larb_spec.np); 617 640 larb_nr++; 618 641 } 619 642
-39
drivers/iommu/of_iommu.c
··· 96 96 } 97 97 EXPORT_SYMBOL_GPL(of_get_dma_window); 98 98 99 - struct of_iommu_node { 100 - struct list_head list; 101 - struct device_node *np; 102 - const struct iommu_ops *ops; 103 - }; 104 - static LIST_HEAD(of_iommu_list); 105 - static DEFINE_SPINLOCK(of_iommu_lock); 106 - 107 - void of_iommu_set_ops(struct device_node *np, const struct iommu_ops *ops) 108 - { 109 - struct of_iommu_node *iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); 110 - 111 - if (WARN_ON(!iommu)) 112 - return; 113 - 114 - of_node_get(np); 115 - INIT_LIST_HEAD(&iommu->list); 116 - iommu->np = np; 117 - iommu->ops = ops; 118 - spin_lock(&of_iommu_lock); 119 - list_add_tail(&iommu->list, &of_iommu_list); 120 - spin_unlock(&of_iommu_lock); 121 - } 122 - 123 - const struct iommu_ops *of_iommu_get_ops(struct device_node *np) 124 - { 125 - struct of_iommu_node *node; 126 - const struct iommu_ops *ops = NULL; 127 - 128 - spin_lock(&of_iommu_lock); 129 - list_for_each_entry(node, &of_iommu_list, list) 130 - if (node->np == np) { 131 - ops = node->ops; 132 - break; 133 - } 134 - spin_unlock(&of_iommu_lock); 135 - return ops; 136 - } 137 - 138 99 static int __get_pci_rid(struct pci_dev *pdev, u16 alias, void *data) 139 100 { 140 101 struct of_phandle_args *iommu_spec = data;
-1
drivers/iommu/s390-iommu.c
··· 8 8 #include <linux/pci.h> 9 9 #include <linux/iommu.h> 10 10 #include <linux/iommu-helper.h> 11 - #include <linux/pci.h> 12 11 #include <linux/sizes.h> 13 12 #include <asm/pci_dma.h> 14 13
+1 -2
drivers/pci/probe.c
··· 1764 1764 if (attr == DEV_DMA_NOT_SUPPORTED) 1765 1765 dev_warn(&dev->dev, "DMA not supported.\n"); 1766 1766 else 1767 - arch_setup_dma_ops(&dev->dev, 0, 0, NULL, 1768 - attr == DEV_DMA_COHERENT); 1767 + acpi_dma_configure(&dev->dev, attr); 1769 1768 } 1770 1769 1771 1770 pci_put_host_bridge_device(bridge);
+2
include/acpi/acpi_bus.h
··· 573 573 574 574 bool acpi_dma_supported(struct acpi_device *adev); 575 575 enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); 576 + void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr); 577 + void acpi_dma_deconfigure(struct device *dev); 576 578 577 579 struct acpi_device *acpi_find_child_device(struct acpi_device *parent, 578 580 u64 address, bool check_children);
+1
include/asm-generic/vmlinux.lds.h
··· 566 566 IRQCHIP_OF_MATCH_TABLE() \ 567 567 ACPI_PROBE_TABLE(irqchip) \ 568 568 ACPI_PROBE_TABLE(clksrc) \ 569 + ACPI_PROBE_TABLE(iort) \ 569 570 EARLYCON_TABLE() 570 571 571 572 #define INIT_TEXT \
+26
include/linux/acpi.h
··· 56 56 acpi_fwnode_handle(adev) : NULL) 57 57 #define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev)) 58 58 59 + static inline struct fwnode_handle *acpi_alloc_fwnode_static(void) 60 + { 61 + struct fwnode_handle *fwnode; 62 + 63 + fwnode = kzalloc(sizeof(struct fwnode_handle), GFP_KERNEL); 64 + if (!fwnode) 65 + return NULL; 66 + 67 + fwnode->type = FWNODE_ACPI_STATIC; 68 + 69 + return fwnode; 70 + } 71 + 72 + static inline void acpi_free_fwnode_static(struct fwnode_handle *fwnode) 73 + { 74 + if (WARN_ON(!fwnode || fwnode->type != FWNODE_ACPI_STATIC)) 75 + return; 76 + 77 + kfree(fwnode); 78 + } 79 + 59 80 /** 60 81 * ACPI_DEVICE_CLASS - macro used to describe an ACPI device with 61 82 * the PCI-defined class-code information ··· 764 743 { 765 744 return DEV_DMA_NOT_SUPPORTED; 766 745 } 746 + 747 + static inline void acpi_dma_configure(struct device *dev, 748 + enum dev_dma_attr attr) { } 749 + 750 + static inline void acpi_dma_deconfigure(struct device *dev) { } 767 751 768 752 #define ACPI_PTR(_ptr) (NULL) 769 753
+16
include/linux/acpi_iort.h
··· 23 23 #include <linux/fwnode.h> 24 24 #include <linux/irqdomain.h> 25 25 26 + #define IORT_IRQ_MASK(irq) (irq & 0xffffffffULL) 27 + #define IORT_IRQ_TRIGGER_MASK(irq) ((irq >> 32) & 0xffffffffULL) 28 + 26 29 int iort_register_domain_token(int trans_id, struct fwnode_handle *fw_node); 27 30 void iort_deregister_domain_token(int trans_id); 28 31 struct fwnode_handle *iort_find_domain_token(int trans_id); 29 32 #ifdef CONFIG_ACPI_IORT 30 33 void acpi_iort_init(void); 34 + bool iort_node_match(u8 type); 31 35 u32 iort_msi_map_rid(struct device *dev, u32 req_id); 32 36 struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id); 37 + /* IOMMU interface */ 38 + void iort_set_dma_mask(struct device *dev); 39 + const struct iommu_ops *iort_iommu_configure(struct device *dev); 33 40 #else 34 41 static inline void acpi_iort_init(void) { } 42 + static inline bool iort_node_match(u8 type) { return false; } 35 43 static inline u32 iort_msi_map_rid(struct device *dev, u32 req_id) 36 44 { return req_id; } 37 45 static inline struct irq_domain *iort_get_device_domain(struct device *dev, 38 46 u32 req_id) 39 47 { return NULL; } 48 + /* IOMMU interface */ 49 + static inline void iort_set_dma_mask(struct device *dev) { } 50 + static inline 51 + const struct iommu_ops *iort_iommu_configure(struct device *dev) 52 + { return NULL; } 40 53 #endif 54 + 55 + #define IORT_ACPI_DECLARE(name, table_id, fn) \ 56 + ACPI_DECLARE_PROBE_ENTRY(iort, name, table_id, 0, NULL, 0, fn) 41 57 42 58 #endif /* __ACPI_IORT_H__ */
+1
include/linux/cacheinfo.h
··· 71 71 struct cacheinfo *info_list; 72 72 unsigned int num_levels; 73 73 unsigned int num_leaves; 74 + bool cpu_map_populated; 74 75 }; 75 76 76 77 /*
+27 -17
include/linux/debugfs.h
··· 62 62 return filp->f_path.dentry->d_fsdata; 63 63 } 64 64 65 + #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ 66 + static int __fops ## _open(struct inode *inode, struct file *file) \ 67 + { \ 68 + __simple_attr_check_format(__fmt, 0ull); \ 69 + return simple_attr_open(inode, file, __get, __set, __fmt); \ 70 + } \ 71 + static const struct file_operations __fops = { \ 72 + .owner = THIS_MODULE, \ 73 + .open = __fops ## _open, \ 74 + .release = simple_attr_release, \ 75 + .read = debugfs_attr_read, \ 76 + .write = debugfs_attr_write, \ 77 + .llseek = generic_file_llseek, \ 78 + } 79 + 65 80 #if defined(CONFIG_DEBUG_FS) 66 81 67 82 struct dentry *debugfs_create_file(const char *name, umode_t mode, ··· 113 98 size_t len, loff_t *ppos); 114 99 ssize_t debugfs_attr_write(struct file *file, const char __user *buf, 115 100 size_t len, loff_t *ppos); 116 - 117 - #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ 118 - static int __fops ## _open(struct inode *inode, struct file *file) \ 119 - { \ 120 - __simple_attr_check_format(__fmt, 0ull); \ 121 - return simple_attr_open(inode, file, __get, __set, __fmt); \ 122 - } \ 123 - static const struct file_operations __fops = { \ 124 - .owner = THIS_MODULE, \ 125 - .open = __fops ## _open, \ 126 - .release = simple_attr_release, \ 127 - .read = debugfs_attr_read, \ 128 - .write = debugfs_attr_write, \ 129 - .llseek = generic_file_llseek, \ 130 - } 131 101 132 102 struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, 133 103 struct dentry *new_dir, const char *new_name); ··· 233 233 __releases(&debugfs_srcu) 234 234 { } 235 235 236 - #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ 237 - static const struct file_operations __fops = { 0 } 236 + static inline ssize_t debugfs_attr_read(struct file *file, char __user *buf, 237 + size_t len, loff_t *ppos) 238 + { 239 + return -ENODEV; 240 + } 241 + 242 + static inline ssize_t debugfs_attr_write(struct file *file, 243 + const char __user *buf, 244 + size_t len, loff_t *ppos) 245 + { 246 + return -ENODEV; 247 + } 238 248 239 249 static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, 240 250 struct dentry *new_dir, char *new_name)
+86
include/linux/device.h
··· 708 708 }; 709 709 710 710 /** 711 + * enum device_link_state - Device link states. 712 + * @DL_STATE_NONE: The presence of the drivers is not being tracked. 713 + * @DL_STATE_DORMANT: None of the supplier/consumer drivers is present. 714 + * @DL_STATE_AVAILABLE: The supplier driver is present, but the consumer is not. 715 + * @DL_STATE_CONSUMER_PROBE: The consumer is probing (supplier driver present). 716 + * @DL_STATE_ACTIVE: Both the supplier and consumer drivers are present. 717 + * @DL_STATE_SUPPLIER_UNBIND: The supplier driver is unbinding. 718 + */ 719 + enum device_link_state { 720 + DL_STATE_NONE = -1, 721 + DL_STATE_DORMANT = 0, 722 + DL_STATE_AVAILABLE, 723 + DL_STATE_CONSUMER_PROBE, 724 + DL_STATE_ACTIVE, 725 + DL_STATE_SUPPLIER_UNBIND, 726 + }; 727 + 728 + /* 729 + * Device link flags. 730 + * 731 + * STATELESS: The core won't track the presence of supplier/consumer drivers. 732 + * AUTOREMOVE: Remove this link automatically on consumer driver unbind. 733 + * PM_RUNTIME: If set, the runtime PM framework will use this link. 734 + * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation. 735 + */ 736 + #define DL_FLAG_STATELESS BIT(0) 737 + #define DL_FLAG_AUTOREMOVE BIT(1) 738 + #define DL_FLAG_PM_RUNTIME BIT(2) 739 + #define DL_FLAG_RPM_ACTIVE BIT(3) 740 + 741 + /** 742 + * struct device_link - Device link representation. 743 + * @supplier: The device on the supplier end of the link. 744 + * @s_node: Hook to the supplier device's list of links to consumers. 745 + * @consumer: The device on the consumer end of the link. 746 + * @c_node: Hook to the consumer device's list of links to suppliers. 747 + * @status: The state of the link (with respect to the presence of drivers). 748 + * @flags: Link flags. 749 + * @rpm_active: Whether or not the consumer device is runtime-PM-active. 750 + * @rcu_head: An RCU head to use for deferred execution of SRCU callbacks. 751 + */ 752 + struct device_link { 753 + struct device *supplier; 754 + struct list_head s_node; 755 + struct device *consumer; 756 + struct list_head c_node; 757 + enum device_link_state status; 758 + u32 flags; 759 + bool rpm_active; 760 + #ifdef CONFIG_SRCU 761 + struct rcu_head rcu_head; 762 + #endif 763 + }; 764 + 765 + /** 766 + * enum dl_dev_state - Device driver presence tracking information. 767 + * @DL_DEV_NO_DRIVER: There is no driver attached to the device. 768 + * @DL_DEV_PROBING: A driver is probing. 769 + * @DL_DEV_DRIVER_BOUND: The driver has been bound to the device. 770 + * @DL_DEV_UNBINDING: The driver is unbinding from the device. 771 + */ 772 + enum dl_dev_state { 773 + DL_DEV_NO_DRIVER = 0, 774 + DL_DEV_PROBING, 775 + DL_DEV_DRIVER_BOUND, 776 + DL_DEV_UNBINDING, 777 + }; 778 + 779 + /** 780 + * struct dev_links_info - Device data related to device links. 781 + * @suppliers: List of links to supplier devices. 782 + * @consumers: List of links to consumer devices. 783 + * @status: Driver status information. 784 + */ 785 + struct dev_links_info { 786 + struct list_head suppliers; 787 + struct list_head consumers; 788 + enum dl_dev_state status; 789 + }; 790 + 791 + /** 711 792 * struct device - The basic device structure 712 793 * @parent: The device's "parent" device, the device to which it is attached. 713 794 * In most cases, a parent device is some sort of bus or host ··· 880 799 core doesn't touch it */ 881 800 void *driver_data; /* Driver data, set and get with 882 801 dev_set/get_drvdata */ 802 + struct dev_links_info links; 883 803 struct dev_pm_info power; 884 804 struct dev_pm_domain *pm_domain; 885 805 ··· 1198 1116 /* debugging and troubleshooting/diagnostic helpers. */ 1199 1117 extern const char *dev_driver_string(const struct device *dev); 1200 1118 1119 + /* Device links interface. */ 1120 + struct device_link *device_link_add(struct device *consumer, 1121 + struct device *supplier, u32 flags); 1122 + void device_link_del(struct device_link *link); 1201 1123 1202 1124 #ifdef CONFIG_PRINTK 1203 1125
+4
include/linux/dma-iommu.h
··· 61 61 enum dma_data_direction dir, unsigned long attrs); 62 62 void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, 63 63 enum dma_data_direction dir, unsigned long attrs); 64 + dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys, 65 + size_t size, enum dma_data_direction dir, unsigned long attrs); 66 + void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, 67 + size_t size, enum dma_data_direction dir, unsigned long attrs); 64 68 int iommu_dma_supported(struct device *dev, u64 mask); 65 69 int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr); 66 70
+2 -1
include/linux/fwnode.h
··· 17 17 FWNODE_OF, 18 18 FWNODE_ACPI, 19 19 FWNODE_ACPI_DATA, 20 + FWNODE_ACPI_STATIC, 20 21 FWNODE_PDATA, 21 - FWNODE_IRQCHIP, 22 + FWNODE_IRQCHIP 22 23 }; 23 24 24 25 struct fwnode_handle {
+15
include/linux/iommu.h
··· 253 253 extern int iommu_group_for_each_dev(struct iommu_group *group, void *data, 254 254 int (*fn)(struct device *, void *)); 255 255 extern struct iommu_group *iommu_group_get(struct device *dev); 256 + extern struct iommu_group *iommu_group_ref_get(struct iommu_group *group); 256 257 extern void iommu_group_put(struct iommu_group *group); 257 258 extern int iommu_group_register_notifier(struct iommu_group *group, 258 259 struct notifier_block *nb); ··· 352 351 const struct iommu_ops *ops); 353 352 void iommu_fwspec_free(struct device *dev); 354 353 int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); 354 + void iommu_register_instance(struct fwnode_handle *fwnode, 355 + const struct iommu_ops *ops); 356 + const struct iommu_ops *iommu_get_instance(struct fwnode_handle *fwnode); 355 357 356 358 #else /* CONFIG_IOMMU_API */ 357 359 ··· 582 578 int num_ids) 583 579 { 584 580 return -ENODEV; 581 + } 582 + 583 + static inline void iommu_register_instance(struct fwnode_handle *fwnode, 584 + const struct iommu_ops *ops) 585 + { 586 + } 587 + 588 + static inline 589 + const struct iommu_ops *iommu_get_instance(struct fwnode_handle *fwnode) 590 + { 591 + return NULL; 585 592 } 586 593 587 594 #endif /* CONFIG_IOMMU_API */
+10 -2
include/linux/of_iommu.h
··· 31 31 32 32 #endif /* CONFIG_OF_IOMMU */ 33 33 34 - void of_iommu_set_ops(struct device_node *np, const struct iommu_ops *ops); 35 - const struct iommu_ops *of_iommu_get_ops(struct device_node *np); 34 + static inline void of_iommu_set_ops(struct device_node *np, 35 + const struct iommu_ops *ops) 36 + { 37 + iommu_register_instance(&np->fwnode, ops); 38 + } 39 + 40 + static inline const struct iommu_ops *of_iommu_get_ops(struct device_node *np) 41 + { 42 + return iommu_get_instance(&np->fwnode); 43 + } 36 44 37 45 extern struct of_device_id __iommu_of_table; 38 46
+2
include/linux/pm.h
··· 559 559 pm_message_t power_state; 560 560 unsigned int can_wakeup:1; 561 561 unsigned int async_suspend:1; 562 + bool in_dpm_list:1; /* Owned by the PM core */ 562 563 bool is_prepared:1; /* Owned by the PM core */ 563 564 bool is_suspended:1; /* Ditto */ 564 565 bool is_noirq_suspended:1; ··· 597 596 unsigned int use_autosuspend:1; 598 597 unsigned int timer_autosuspends:1; 599 598 unsigned int memalloc_noio:1; 599 + unsigned int links_count; 600 600 enum rpm_request request; 601 601 enum rpm_status runtime_status; 602 602 int runtime_error;
+10
include/linux/pm_runtime.h
··· 55 55 extern void pm_runtime_update_max_time_suspended(struct device *dev, 56 56 s64 delta_ns); 57 57 extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable); 58 + extern void pm_runtime_clean_up_links(struct device *dev); 59 + extern void pm_runtime_get_suppliers(struct device *dev); 60 + extern void pm_runtime_put_suppliers(struct device *dev); 61 + extern void pm_runtime_new_link(struct device *dev); 62 + extern void pm_runtime_drop_link(struct device *dev); 58 63 59 64 static inline void pm_suspend_ignore_children(struct device *dev, bool enable) 60 65 { ··· 191 186 struct device *dev) { return 0; } 192 187 static inline void pm_runtime_set_memalloc_noio(struct device *dev, 193 188 bool enable){} 189 + static inline void pm_runtime_clean_up_links(struct device *dev) {} 190 + static inline void pm_runtime_get_suppliers(struct device *dev) {} 191 + static inline void pm_runtime_put_suppliers(struct device *dev) {} 192 + static inline void pm_runtime_new_link(struct device *dev) {} 193 + static inline void pm_runtime_drop_link(struct device *dev) {} 194 194 195 195 #endif /* !CONFIG_PM */ 196 196
+3 -3
lib/kobject_uevent.c
··· 56 56 * kobject_action_type - translate action string to numeric type 57 57 * 58 58 * @buf: buffer containing the action string, newline is ignored 59 - * @len: length of buffer 59 + * @count: length of buffer 60 60 * @type: pointer to the location to store the action type 61 61 * 62 62 * Returns 0 if the action string was recognized. ··· 154 154 /** 155 155 * kobject_uevent_env - send an uevent with environmental data 156 156 * 157 - * @action: action that is happening 158 157 * @kobj: struct kobject that the action is happening to 158 + * @action: action that is happening 159 159 * @envp_ext: pointer to environmental data 160 160 * 161 161 * Returns 0 if kobject_uevent_env() is completed with success or the ··· 363 363 /** 364 364 * kobject_uevent - notify userspace by sending an uevent 365 365 * 366 - * @action: action that is happening 367 366 * @kobj: struct kobject that the action is happening to 367 + * @action: action that is happening 368 368 * 369 369 * Returns 0 if kobject_uevent() is completed with success or the 370 370 * corresponding error when it fails.