Lines Matching full:group
66 ssize_t (*show)(struct iommu_group *group, char *buf);
67 ssize_t (*store)(struct iommu_group *group,
84 static int iommu_alloc_default_domain(struct iommu_group *group,
91 struct iommu_group *group);
92 static int __iommu_group_set_domain(struct iommu_group *group,
94 static int iommu_create_device_direct_mappings(struct iommu_group *group,
97 static ssize_t iommu_group_store_type(struct iommu_group *group,
285 struct iommu_group *group; in __iommu_probe_device() local
307 group = iommu_group_get_for_dev(dev); in __iommu_probe_device()
308 if (IS_ERR(group)) { in __iommu_probe_device()
309 ret = PTR_ERR(group); in __iommu_probe_device()
312 iommu_group_put(group); in __iommu_probe_device()
314 if (group_list && !group->default_domain && list_empty(&group->entry)) in __iommu_probe_device()
315 list_add_tail(&group->entry, group_list); in __iommu_probe_device()
337 struct iommu_group *group; in iommu_probe_device() local
344 group = iommu_group_get(dev); in iommu_probe_device()
345 if (!group) { in iommu_probe_device()
356 mutex_lock(&group->mutex); in iommu_probe_device()
357 iommu_alloc_default_domain(group, dev); in iommu_probe_device()
360 * If device joined an existing group which has been claimed, don't in iommu_probe_device()
363 if (group->default_domain && !group->owner) { in iommu_probe_device()
364 ret = __iommu_attach_device(group->default_domain, dev); in iommu_probe_device()
366 mutex_unlock(&group->mutex); in iommu_probe_device()
367 iommu_group_put(group); in iommu_probe_device()
372 iommu_create_device_direct_mappings(group, dev); in iommu_probe_device()
374 mutex_unlock(&group->mutex); in iommu_probe_device()
375 iommu_group_put(group); in iommu_probe_device()
448 struct iommu_group *group = to_iommu_group(kobj); in iommu_group_attr_show() local
452 ret = attr->show(group, buf); in iommu_group_attr_show()
461 struct iommu_group *group = to_iommu_group(kobj); in iommu_group_attr_store() local
465 ret = attr->store(group, buf, count); in iommu_group_attr_store()
474 static int iommu_group_create_file(struct iommu_group *group, in iommu_group_create_file() argument
477 return sysfs_create_file(&group->kobj, &attr->attr); in iommu_group_create_file()
480 static void iommu_group_remove_file(struct iommu_group *group, in iommu_group_remove_file() argument
483 sysfs_remove_file(&group->kobj, &attr->attr); in iommu_group_remove_file()
486 static ssize_t iommu_group_show_name(struct iommu_group *group, char *buf) in iommu_group_show_name() argument
488 return sprintf(buf, "%s\n", group->name); in iommu_group_show_name()
567 int iommu_get_group_resv_regions(struct iommu_group *group, in iommu_get_group_resv_regions() argument
573 mutex_lock(&group->mutex); in iommu_get_group_resv_regions()
574 list_for_each_entry(device, &group->devices, list) { in iommu_get_group_resv_regions()
591 mutex_unlock(&group->mutex); in iommu_get_group_resv_regions()
596 static ssize_t iommu_group_show_resv_regions(struct iommu_group *group, in iommu_group_show_resv_regions() argument
604 iommu_get_group_resv_regions(group, &group_resv_regions); in iommu_group_show_resv_regions()
618 static ssize_t iommu_group_show_type(struct iommu_group *group, in iommu_group_show_type() argument
623 mutex_lock(&group->mutex); in iommu_group_show_type()
624 if (group->default_domain) { in iommu_group_show_type()
625 switch (group->default_domain->type) { in iommu_group_show_type()
643 mutex_unlock(&group->mutex); in iommu_group_show_type()
659 struct iommu_group *group = to_iommu_group(kobj); in iommu_group_release() local
661 pr_debug("Releasing group %d\n", group->id); in iommu_group_release()
663 if (group->iommu_data_release) in iommu_group_release()
664 group->iommu_data_release(group->iommu_data); in iommu_group_release()
666 ida_free(&iommu_group_ida, group->id); in iommu_group_release()
668 if (group->default_domain) in iommu_group_release()
669 iommu_domain_free(group->default_domain); in iommu_group_release()
670 if (group->blocking_domain) in iommu_group_release()
671 iommu_domain_free(group->blocking_domain); in iommu_group_release()
673 kfree(group->name); in iommu_group_release()
674 kfree(group); in iommu_group_release()
683 * iommu_group_alloc - Allocate a new group
686 * group. The iommu group represents the minimum granularity of the iommu.
688 * group in order to hold the group until devices are added. Use
690 * group to be automatically reclaimed once it has no devices or external
695 struct iommu_group *group; in iommu_group_alloc() local
698 group = kzalloc(sizeof(*group), GFP_KERNEL); in iommu_group_alloc()
699 if (!group) in iommu_group_alloc()
702 group->kobj.kset = iommu_group_kset; in iommu_group_alloc()
703 mutex_init(&group->mutex); in iommu_group_alloc()
704 INIT_LIST_HEAD(&group->devices); in iommu_group_alloc()
705 INIT_LIST_HEAD(&group->entry); in iommu_group_alloc()
709 kfree(group); in iommu_group_alloc()
712 group->id = ret; in iommu_group_alloc()
714 ret = kobject_init_and_add(&group->kobj, &iommu_group_ktype, in iommu_group_alloc()
715 NULL, "%d", group->id); in iommu_group_alloc()
717 kobject_put(&group->kobj); in iommu_group_alloc()
721 group->devices_kobj = kobject_create_and_add("devices", &group->kobj); in iommu_group_alloc()
722 if (!group->devices_kobj) { in iommu_group_alloc()
723 kobject_put(&group->kobj); /* triggers .release & free */ in iommu_group_alloc()
728 * The devices_kobj holds a reference on the group kobject, so in iommu_group_alloc()
729 * as long as that exists so will the group. We can therefore in iommu_group_alloc()
732 kobject_put(&group->kobj); in iommu_group_alloc()
734 ret = iommu_group_create_file(group, in iommu_group_alloc()
739 ret = iommu_group_create_file(group, &iommu_group_attr_type); in iommu_group_alloc()
743 pr_debug("Allocated group %d\n", group->id); in iommu_group_alloc()
745 return group; in iommu_group_alloc()
752 struct iommu_group *group; in iommu_group_get_by_id() local
768 group = container_of(group_kobj, struct iommu_group, kobj); in iommu_group_get_by_id()
769 BUG_ON(group->id != id); in iommu_group_get_by_id()
771 kobject_get(group->devices_kobj); in iommu_group_get_by_id()
772 kobject_put(&group->kobj); in iommu_group_get_by_id()
774 return group; in iommu_group_get_by_id()
779 * iommu_group_get_iommudata - retrieve iommu_data registered for a group
780 * @group: the group
782 * iommu drivers can store data in the group for use when doing iommu
784 * should hold a group reference.
786 void *iommu_group_get_iommudata(struct iommu_group *group) in iommu_group_get_iommudata() argument
788 return group->iommu_data; in iommu_group_get_iommudata()
793 * iommu_group_set_iommudata - set iommu_data for a group
794 * @group: the group
798 * iommu drivers can store data in the group for use when doing iommu
800 * the group has been allocated. Caller should hold a group reference.
802 void iommu_group_set_iommudata(struct iommu_group *group, void *iommu_data, in iommu_group_set_iommudata() argument
805 group->iommu_data = iommu_data; in iommu_group_set_iommudata()
806 group->iommu_data_release = release; in iommu_group_set_iommudata()
811 * iommu_group_set_name - set name for a group
812 * @group: the group
815 * Allow iommu driver to set a name for a group. When set it will
816 * appear in a name attribute file under the group in sysfs.
818 int iommu_group_set_name(struct iommu_group *group, const char *name) in iommu_group_set_name() argument
822 if (group->name) { in iommu_group_set_name()
823 iommu_group_remove_file(group, &iommu_group_attr_name); in iommu_group_set_name()
824 kfree(group->name); in iommu_group_set_name()
825 group->name = NULL; in iommu_group_set_name()
830 group->name = kstrdup(name, GFP_KERNEL); in iommu_group_set_name()
831 if (!group->name) in iommu_group_set_name()
834 ret = iommu_group_create_file(group, &iommu_group_attr_name); in iommu_group_set_name()
836 kfree(group->name); in iommu_group_set_name()
837 group->name = NULL; in iommu_group_set_name()
845 static int iommu_create_device_direct_mappings(struct iommu_group *group, in iommu_create_device_direct_mappings() argument
848 struct iommu_domain *domain = group->default_domain; in iommu_create_device_direct_mappings()
920 * iommu_group_add_device - add a device to an iommu group
921 * @group: the group into which to add the device (reference should be held)
925 * group. Adding a device increments the group reference count.
927 int iommu_group_add_device(struct iommu_group *group, struct device *dev) in iommu_group_add_device() argument
938 ret = sysfs_create_link(&dev->kobj, &group->kobj, "iommu_group"); in iommu_group_add_device()
949 ret = sysfs_create_link_nowarn(group->devices_kobj, in iommu_group_add_device()
965 kobject_get(group->devices_kobj); in iommu_group_add_device()
967 dev->iommu_group = group; in iommu_group_add_device()
969 mutex_lock(&group->mutex); in iommu_group_add_device()
970 list_add_tail(&device->list, &group->devices); in iommu_group_add_device()
971 if (group->domain && !iommu_is_attach_deferred(dev)) in iommu_group_add_device()
972 ret = __iommu_attach_device(group->domain, dev); in iommu_group_add_device()
973 mutex_unlock(&group->mutex); in iommu_group_add_device()
977 trace_add_device_to_group(group->id, dev); in iommu_group_add_device()
979 dev_info(dev, "Adding to iommu group %d\n", group->id); in iommu_group_add_device()
984 mutex_lock(&group->mutex); in iommu_group_add_device()
986 mutex_unlock(&group->mutex); in iommu_group_add_device()
988 kobject_put(group->devices_kobj); in iommu_group_add_device()
989 sysfs_remove_link(group->devices_kobj, device->name); in iommu_group_add_device()
996 dev_err(dev, "Failed to add to iommu group %d: %d\n", group->id, ret); in iommu_group_add_device()
1002 * iommu_group_remove_device - remove a device from it's current group
1006 * it's current group. This decrements the iommu group reference count.
1010 struct iommu_group *group = dev->iommu_group; in iommu_group_remove_device() local
1013 if (!group) in iommu_group_remove_device()
1016 dev_info(dev, "Removing from iommu group %d\n", group->id); in iommu_group_remove_device()
1018 mutex_lock(&group->mutex); in iommu_group_remove_device()
1019 list_for_each_entry(tmp_device, &group->devices, list) { in iommu_group_remove_device()
1026 mutex_unlock(&group->mutex); in iommu_group_remove_device()
1031 sysfs_remove_link(group->devices_kobj, device->name); in iommu_group_remove_device()
1034 trace_remove_device_from_group(group->id, dev); in iommu_group_remove_device()
1039 kobject_put(group->devices_kobj); in iommu_group_remove_device()
1043 static int iommu_group_device_count(struct iommu_group *group) in iommu_group_device_count() argument
1048 list_for_each_entry(entry, &group->devices, list) in iommu_group_device_count()
1054 static int __iommu_group_for_each_dev(struct iommu_group *group, void *data, in __iommu_group_for_each_dev() argument
1060 list_for_each_entry(device, &group->devices, list) { in __iommu_group_for_each_dev()
1069 * iommu_group_for_each_dev - iterate over each device in the group
1070 * @group: the group
1074 * This function is called by group users to iterate over group devices.
1075 * Callers should hold a reference count to the group during callback.
1076 * The group->mutex is held across callbacks, which will block calls to
1079 int iommu_group_for_each_dev(struct iommu_group *group, void *data, in iommu_group_for_each_dev() argument
1084 mutex_lock(&group->mutex); in iommu_group_for_each_dev()
1085 ret = __iommu_group_for_each_dev(group, data, fn); in iommu_group_for_each_dev()
1086 mutex_unlock(&group->mutex); in iommu_group_for_each_dev()
1093 * iommu_group_get - Return the group for a device and increment reference
1094 * @dev: get the group that this device belongs to
1096 * This function is called by iommu drivers and users to get the group
1097 * for the specified device. If found, the group is returned and the group
1102 struct iommu_group *group = dev->iommu_group; in iommu_group_get() local
1104 if (group) in iommu_group_get()
1105 kobject_get(group->devices_kobj); in iommu_group_get()
1107 return group; in iommu_group_get()
1112 * iommu_group_ref_get - Increment reference on a group
1113 * @group: the group to use, must not be NULL
1116 * existing group. Returns the given group for convenience.
1118 struct iommu_group *iommu_group_ref_get(struct iommu_group *group) in iommu_group_ref_get() argument
1120 kobject_get(group->devices_kobj); in iommu_group_ref_get()
1121 return group; in iommu_group_ref_get()
1126 * iommu_group_put - Decrement group reference
1127 * @group: the group to use
1130 * iommu group. Once the reference count is zero, the group is released.
1132 void iommu_group_put(struct iommu_group *group) in iommu_group_put() argument
1134 if (group) in iommu_group_put()
1135 kobject_put(group->devices_kobj); in iommu_group_put()
1324 * matched using the group ID, the PASID valid bit and the PASID in iommu_page_response()
1325 * value. Otherwise only the group ID matches request and in iommu_page_response()
1351 * iommu_group_id - Return ID for a group
1352 * @group: the group to ID
1354 * Return the unique ID for the group matching the sysfs group number.
1356 int iommu_group_id(struct iommu_group *group) in iommu_group_id() argument
1358 return group->id; in iommu_group_id()
1379 * that may already have a group.
1385 struct iommu_group *group; in get_pci_function_alias_group() local
1396 group = get_pci_alias_group(tmp, devfns); in get_pci_function_alias_group()
1397 if (group) { in get_pci_function_alias_group()
1399 return group; in get_pci_function_alias_group()
1419 struct iommu_group *group; in get_pci_alias_group() local
1424 group = iommu_group_get(&pdev->dev); in get_pci_alias_group()
1425 if (group) in get_pci_alias_group()
1426 return group; in get_pci_alias_group()
1434 group = get_pci_alias_group(tmp, devfns); in get_pci_alias_group()
1435 if (group) { in get_pci_alias_group()
1437 return group; in get_pci_alias_group()
1440 group = get_pci_function_alias_group(tmp, devfns); in get_pci_alias_group()
1441 if (group) { in get_pci_alias_group()
1443 return group; in get_pci_alias_group()
1453 struct iommu_group *group; member
1458 * the IOMMU group if we find one along the way.
1465 data->group = iommu_group_get(&pdev->dev); in get_pci_alias_or_group()
1467 return data->group != NULL; in get_pci_alias_or_group()
1472 * iommu-group per device.
1482 * to find or create an IOMMU group for a device.
1489 struct iommu_group *group = NULL; in pci_device_group() local
1497 * be aliased due to topology in order to have its own IOMMU group. in pci_device_group()
1499 * group, use it. in pci_device_group()
1502 return data.group; in pci_device_group()
1510 * group, use it. in pci_device_group()
1521 group = iommu_group_get(&pdev->dev); in pci_device_group()
1522 if (group) in pci_device_group()
1523 return group; in pci_device_group()
1528 * device or another device aliases us, use the same group. in pci_device_group()
1530 group = get_pci_alias_group(pdev, (unsigned long *)devfns); in pci_device_group()
1531 if (group) in pci_device_group()
1532 return group; in pci_device_group()
1539 group = get_pci_function_alias_group(pdev, (unsigned long *)devfns); in pci_device_group()
1540 if (group) in pci_device_group()
1541 return group; in pci_device_group()
1543 /* No shared group found, allocate new */ in pci_device_group()
1548 /* Get the IOMMU group for device on fsl-mc bus */
1552 struct iommu_group *group; in fsl_mc_device_group() local
1554 group = iommu_group_get(cont_dev); in fsl_mc_device_group()
1555 if (!group) in fsl_mc_device_group()
1556 group = iommu_group_alloc(); in fsl_mc_device_group()
1557 return group; in fsl_mc_device_group()
1575 struct iommu_group *group, in iommu_group_alloc_default_domain() argument
1584 …pr_warn("Failed to allocate default IOMMU domain of type %u for group %s - Falling back to IOMMU_D… in iommu_group_alloc_default_domain()
1585 type, group->name); in iommu_group_alloc_default_domain()
1591 group->default_domain = dom; in iommu_group_alloc_default_domain()
1592 if (!group->domain) in iommu_group_alloc_default_domain()
1593 group->domain = dom; in iommu_group_alloc_default_domain()
1597 static int iommu_alloc_default_domain(struct iommu_group *group, in iommu_alloc_default_domain() argument
1602 if (group->default_domain) in iommu_alloc_default_domain()
1607 return iommu_group_alloc_default_domain(dev->bus, group, type); in iommu_alloc_default_domain()
1611 * iommu_group_get_for_dev - Find or create the IOMMU group for a device
1616 * IOMMU group for a device. On success, the caller will hold a reference
1617 * to the returned IOMMU group, which will already include the provided
1623 struct iommu_group *group; in iommu_group_get_for_dev() local
1626 group = iommu_group_get(dev); in iommu_group_get_for_dev()
1627 if (group) in iommu_group_get_for_dev()
1628 return group; in iommu_group_get_for_dev()
1630 group = ops->device_group(dev); in iommu_group_get_for_dev()
1631 if (WARN_ON_ONCE(group == NULL)) in iommu_group_get_for_dev()
1634 if (IS_ERR(group)) in iommu_group_get_for_dev()
1635 return group; in iommu_group_get_for_dev()
1637 ret = iommu_group_add_device(group, dev); in iommu_group_get_for_dev()
1641 return group; in iommu_group_get_for_dev()
1644 iommu_group_put(group); in iommu_group_get_for_dev()
1649 struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) in iommu_group_default_domain() argument
1651 return group->default_domain; in iommu_group_default_domain()
1657 struct iommu_group *group; in probe_iommu_group() local
1660 /* Device is probed already if in a group */ in probe_iommu_group()
1661 group = iommu_group_get(dev); in probe_iommu_group()
1662 if (group) { in probe_iommu_group()
1663 iommu_group_put(group); in probe_iommu_group()
1704 …dev_warn(dev, "Device needs domain type %s, but device %s in the same iommu group requires type %s… in probe_get_default_domain_type()
1721 struct iommu_group *group) in probe_alloc_default_domain() argument
1727 /* Ask for default domain requirements of all devices in the group */ in probe_alloc_default_domain()
1728 __iommu_group_for_each_dev(group, >ype, in probe_alloc_default_domain()
1734 iommu_group_alloc_default_domain(bus, group, gtype.type); in probe_alloc_default_domain()
1749 static int __iommu_group_dma_attach(struct iommu_group *group) in __iommu_group_dma_attach() argument
1751 return __iommu_group_for_each_dev(group, group->default_domain, in __iommu_group_dma_attach()
1765 static void __iommu_group_dma_finalize(struct iommu_group *group) in __iommu_group_dma_finalize() argument
1767 __iommu_group_for_each_dev(group, group->default_domain, in __iommu_group_dma_finalize()
1773 struct iommu_group *group = data; in iommu_do_create_direct_mappings() local
1775 iommu_create_device_direct_mappings(group, dev); in iommu_do_create_direct_mappings()
1780 static int iommu_group_create_direct_mappings(struct iommu_group *group) in iommu_group_create_direct_mappings() argument
1782 return __iommu_group_for_each_dev(group, group, in iommu_group_create_direct_mappings()
1788 struct iommu_group *group, *next; in bus_iommu_probe() local
1794 * creating the iommu group, so do it after the groups are in bus_iommu_probe()
1801 list_for_each_entry_safe(group, next, &group_list, entry) { in bus_iommu_probe()
1803 list_del_init(&group->entry); in bus_iommu_probe()
1805 mutex_lock(&group->mutex); in bus_iommu_probe()
1808 probe_alloc_default_domain(bus, group); in bus_iommu_probe()
1810 if (!group->default_domain) { in bus_iommu_probe()
1811 mutex_unlock(&group->mutex); in bus_iommu_probe()
1815 iommu_group_create_direct_mappings(group); in bus_iommu_probe()
1817 ret = __iommu_group_dma_attach(group); in bus_iommu_probe()
1819 mutex_unlock(&group->mutex); in bus_iommu_probe()
1824 __iommu_group_dma_finalize(group); in bus_iommu_probe()
1921 * Put the group's domain back to the appropriate core-owned domain - either the
1924 static void __iommu_group_set_core_domain(struct iommu_group *group) in __iommu_group_set_core_domain() argument
1929 if (group->owner) in __iommu_group_set_core_domain()
1930 new_domain = group->blocking_domain; in __iommu_group_set_core_domain()
1932 new_domain = group->default_domain; in __iommu_group_set_core_domain()
1934 ret = __iommu_group_set_domain(group, new_domain); in __iommu_group_set_core_domain()
1954 struct iommu_group *group; in iommu_attach_device() local
1957 group = iommu_group_get(dev); in iommu_attach_device()
1958 if (!group) in iommu_attach_device()
1962 * Lock the group to make sure the device-count doesn't in iommu_attach_device()
1965 mutex_lock(&group->mutex); in iommu_attach_device()
1967 if (iommu_group_device_count(group) != 1) in iommu_attach_device()
1970 ret = __iommu_attach_group(domain, group); in iommu_attach_device()
1973 mutex_unlock(&group->mutex); in iommu_attach_device()
1974 iommu_group_put(group); in iommu_attach_device()
2000 struct iommu_group *group; in iommu_detach_device() local
2002 group = iommu_group_get(dev); in iommu_detach_device()
2003 if (!group) in iommu_detach_device()
2006 mutex_lock(&group->mutex); in iommu_detach_device()
2007 if (WARN_ON(domain != group->domain) || in iommu_detach_device()
2008 WARN_ON(iommu_group_device_count(group) != 1)) in iommu_detach_device()
2010 __iommu_group_set_core_domain(group); in iommu_detach_device()
2013 mutex_unlock(&group->mutex); in iommu_detach_device()
2014 iommu_group_put(group); in iommu_detach_device()
2021 struct iommu_group *group; in iommu_get_domain_for_dev() local
2023 group = iommu_group_get(dev); in iommu_get_domain_for_dev()
2024 if (!group) in iommu_get_domain_for_dev()
2027 domain = group->domain; in iommu_get_domain_for_dev()
2029 iommu_group_put(group); in iommu_get_domain_for_dev()
2037 * guarantees that the group and its default domain are valid and correct.
2047 * iterating over the devices in a group. Ideally we'd have a single
2048 * device which represents the requestor ID of the group, but we also
2051 * wish to group them at a higher level (ex. untrusted multi-function
2062 struct iommu_group *group) in __iommu_attach_group() argument
2066 if (group->domain && group->domain != group->default_domain && in __iommu_attach_group()
2067 group->domain != group->blocking_domain) in __iommu_attach_group()
2070 ret = __iommu_group_for_each_dev(group, domain, in __iommu_attach_group()
2073 group->domain = domain; in __iommu_attach_group()
2078 int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group) in iommu_attach_group() argument
2082 mutex_lock(&group->mutex); in iommu_attach_group()
2083 ret = __iommu_attach_group(domain, group); in iommu_attach_group()
2084 mutex_unlock(&group->mutex); in iommu_attach_group()
2099 static int __iommu_group_set_domain(struct iommu_group *group, in __iommu_group_set_domain() argument
2104 if (group->domain == new_domain) in __iommu_group_set_domain()
2113 if (WARN_ON(!group->domain->ops->detach_dev)) in __iommu_group_set_domain()
2115 __iommu_group_for_each_dev(group, group->domain, in __iommu_group_set_domain()
2117 group->domain = NULL; in __iommu_group_set_domain()
2125 * either new_domain or group->domain, never something else. in __iommu_group_set_domain()
2130 ret = __iommu_group_for_each_dev(group, new_domain, in __iommu_group_set_domain()
2134 group->domain = new_domain; in __iommu_group_set_domain()
2138 void iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group) in iommu_detach_group() argument
2140 mutex_lock(&group->mutex); in iommu_detach_group()
2141 __iommu_group_set_core_domain(group); in iommu_detach_group()
2142 mutex_unlock(&group->mutex); in iommu_detach_group()
2748 struct iommu_group *group; in iommu_sva_bind_device() local
2755 group = iommu_group_get(dev); in iommu_sva_bind_device()
2756 if (!group) in iommu_sva_bind_device()
2760 mutex_lock(&group->mutex); in iommu_sva_bind_device()
2768 if (iommu_group_device_count(group) != 1) in iommu_sva_bind_device()
2774 mutex_unlock(&group->mutex); in iommu_sva_bind_device()
2775 iommu_group_put(group); in iommu_sva_bind_device()
2791 struct iommu_group *group; in iommu_sva_unbind_device() local
2798 group = iommu_group_get(dev); in iommu_sva_unbind_device()
2799 if (!group) in iommu_sva_unbind_device()
2802 mutex_lock(&group->mutex); in iommu_sva_unbind_device()
2804 mutex_unlock(&group->mutex); in iommu_sva_unbind_device()
2806 iommu_group_put(group); in iommu_sva_unbind_device()
2822 * Changes the default domain of an iommu group that has *only* one device
2824 * @group: The group for which the default domain should be changed
2825 * @prev_dev: The device in the group (this is used to make sure that the device
2827 * @type: The type of the new default domain that gets associated with the group
2833 * group's default domain type through /sys/kernel/iommu_groups/<grp_id>/type
2836 static int iommu_change_dev_def_domain(struct iommu_group *group, in iommu_change_dev_def_domain() argument
2844 mutex_lock(&group->mutex); in iommu_change_dev_def_domain()
2846 if (group->default_domain != group->domain) { in iommu_change_dev_def_domain()
2847 dev_err_ratelimited(prev_dev, "Group not assigned to default domain\n"); in iommu_change_dev_def_domain()
2853 * iommu group wasn't locked while acquiring device lock in in iommu_change_dev_def_domain()
2857 * Changing default domain of an iommu group with two or more devices in iommu_change_dev_def_domain()
2860 * the devices in the group and before it could acquire all of them, in iommu_change_dev_def_domain()
2865 if (iommu_group_device_count(group) != 1) { in iommu_change_dev_def_domain()
2866 dev_err_ratelimited(prev_dev, "Cannot change default domain: Group has more than one device\n"); in iommu_change_dev_def_domain()
2871 /* Since group has only one device */ in iommu_change_dev_def_domain()
2872 grp_dev = list_first_entry(&group->devices, struct group_device, list); in iommu_change_dev_def_domain()
2881 prev_dom = group->default_domain; in iommu_change_dev_def_domain()
2919 /* Sets group->default_domain to the newly allocated domain */ in iommu_change_dev_def_domain()
2920 ret = iommu_group_alloc_default_domain(dev->bus, group, type); in iommu_change_dev_def_domain()
2924 ret = iommu_create_device_direct_mappings(group, dev); in iommu_change_dev_def_domain()
2928 ret = __iommu_attach_device(group->default_domain, dev); in iommu_change_dev_def_domain()
2932 group->domain = group->default_domain; in iommu_change_dev_def_domain()
2938 * group->mutex, resulting in a deadlock. in iommu_change_dev_def_domain()
2940 mutex_unlock(&group->mutex); in iommu_change_dev_def_domain()
2943 iommu_group_do_probe_finalize(dev, group->default_domain); in iommu_change_dev_def_domain()
2948 iommu_domain_free(group->default_domain); in iommu_change_dev_def_domain()
2949 group->default_domain = prev_dom; in iommu_change_dev_def_domain()
2950 group->domain = prev_dom; in iommu_change_dev_def_domain()
2953 mutex_unlock(&group->mutex); in iommu_change_dev_def_domain()
2960 * drivers from the devices in the iommu group, except for a DMA -> DMA-FQ
2967 static ssize_t iommu_group_store_type(struct iommu_group *group, in iommu_group_store_type() argument
2977 if (WARN_ON(!group) || !group->default_domain) in iommu_group_store_type()
2992 * Lock/Unlock the group mutex here before device lock to in iommu_group_store_type()
2993 * 1. Make sure that the iommu group has only one device (this is a in iommu_group_store_type()
2997 mutex_lock(&group->mutex); in iommu_group_store_type()
2998 if (iommu_group_device_count(group) != 1) { in iommu_group_store_type()
2999 mutex_unlock(&group->mutex); in iommu_group_store_type()
3000 pr_err_ratelimited("Cannot change default domain: Group has more than one device\n"); in iommu_group_store_type()
3004 /* Since group has only one device */ in iommu_group_store_type()
3005 grp_dev = list_first_entry(&group->devices, struct group_device, list); in iommu_group_store_type()
3010 * Don't hold the group mutex because taking group mutex first and then in iommu_group_store_type()
3013 * iommu group and T2 is trying to hot unplug a device or release [1] VF in iommu_group_store_type()
3014 * of a PCIe device which is in the same iommu group. T1 takes group in iommu_group_store_type()
3016 * lock and is yet to take group mutex. Now, both the threads will be in iommu_group_store_type()
3020 * mutex_lock(&group->mutex); in iommu_group_store_type()
3022 * mutex_unlock(&group->mutex); in iommu_group_store_type()
3033 mutex_unlock(&group->mutex); in iommu_group_store_type()
3035 /* Check if the device in the group still has a driver bound to it */ in iommu_group_store_type()
3038 group->default_domain->type == IOMMU_DOMAIN_DMA)) { in iommu_group_store_type()
3044 ret = iommu_change_dev_def_domain(group, dev, req_type); in iommu_group_store_type()
3054 static bool iommu_is_default_domain(struct iommu_group *group) in iommu_is_default_domain() argument
3056 if (group->domain == group->default_domain) in iommu_is_default_domain()
3065 if (group->default_domain && in iommu_is_default_domain()
3066 group->default_domain->type == IOMMU_DOMAIN_IDENTITY && in iommu_is_default_domain()
3067 group->domain && group->domain->type == IOMMU_DOMAIN_IDENTITY) in iommu_is_default_domain()
3082 struct iommu_group *group = iommu_group_get(dev); in iommu_device_use_default_domain() local
3085 if (!group) in iommu_device_use_default_domain()
3088 mutex_lock(&group->mutex); in iommu_device_use_default_domain()
3089 if (group->owner_cnt) { in iommu_device_use_default_domain()
3090 if (group->owner || !iommu_is_default_domain(group)) { in iommu_device_use_default_domain()
3096 group->owner_cnt++; in iommu_device_use_default_domain()
3099 mutex_unlock(&group->mutex); in iommu_device_use_default_domain()
3100 iommu_group_put(group); in iommu_device_use_default_domain()
3115 struct iommu_group *group = iommu_group_get(dev); in iommu_device_unuse_default_domain() local
3117 if (!group) in iommu_device_unuse_default_domain()
3120 mutex_lock(&group->mutex); in iommu_device_unuse_default_domain()
3121 if (!WARN_ON(!group->owner_cnt)) in iommu_device_unuse_default_domain()
3122 group->owner_cnt--; in iommu_device_unuse_default_domain()
3124 mutex_unlock(&group->mutex); in iommu_device_unuse_default_domain()
3125 iommu_group_put(group); in iommu_device_unuse_default_domain()
3128 static int __iommu_group_alloc_blocking_domain(struct iommu_group *group) in __iommu_group_alloc_blocking_domain() argument
3131 list_first_entry(&group->devices, struct group_device, list); in __iommu_group_alloc_blocking_domain()
3133 if (group->blocking_domain) in __iommu_group_alloc_blocking_domain()
3136 group->blocking_domain = in __iommu_group_alloc_blocking_domain()
3138 if (!group->blocking_domain) { in __iommu_group_alloc_blocking_domain()
3143 group->blocking_domain = __iommu_domain_alloc( in __iommu_group_alloc_blocking_domain()
3145 if (!group->blocking_domain) in __iommu_group_alloc_blocking_domain()
3152 * iommu_group_claim_dma_owner() - Set DMA ownership of a group
3153 * @group: The group.
3160 int iommu_group_claim_dma_owner(struct iommu_group *group, void *owner) in iommu_group_claim_dma_owner() argument
3164 mutex_lock(&group->mutex); in iommu_group_claim_dma_owner()
3165 if (group->owner_cnt) { in iommu_group_claim_dma_owner()
3169 if (group->domain && group->domain != group->default_domain) { in iommu_group_claim_dma_owner()
3174 ret = __iommu_group_alloc_blocking_domain(group); in iommu_group_claim_dma_owner()
3178 ret = __iommu_group_set_domain(group, group->blocking_domain); in iommu_group_claim_dma_owner()
3181 group->owner = owner; in iommu_group_claim_dma_owner()
3184 group->owner_cnt++; in iommu_group_claim_dma_owner()
3186 mutex_unlock(&group->mutex); in iommu_group_claim_dma_owner()
3193 * iommu_group_release_dma_owner() - Release DMA ownership of a group
3194 * @group: The group.
3198 void iommu_group_release_dma_owner(struct iommu_group *group) in iommu_group_release_dma_owner() argument
3202 mutex_lock(&group->mutex); in iommu_group_release_dma_owner()
3203 if (WARN_ON(!group->owner_cnt || !group->owner)) in iommu_group_release_dma_owner()
3206 group->owner_cnt = 0; in iommu_group_release_dma_owner()
3207 group->owner = NULL; in iommu_group_release_dma_owner()
3208 ret = __iommu_group_set_domain(group, group->default_domain); in iommu_group_release_dma_owner()
3212 mutex_unlock(&group->mutex); in iommu_group_release_dma_owner()
3217 * iommu_group_dma_owner_claimed() - Query group dma ownership status
3218 * @group: The group.
3220 * This provides status query on a given group. It is racy and only for
3223 bool iommu_group_dma_owner_claimed(struct iommu_group *group) in iommu_group_dma_owner_claimed() argument
3227 mutex_lock(&group->mutex); in iommu_group_dma_owner_claimed()
3228 user = group->owner_cnt; in iommu_group_dma_owner_claimed()
3229 mutex_unlock(&group->mutex); in iommu_group_dma_owner_claimed()