From: Jason Gunthorpe <jgg@nvidia.com>
Sent: Wednesday, July 19, 2023 3:06 AM
This implements the common pattern seen in drivers of a single
iommu_group for the entire iommu driver. Implement this in core code
so the drivers that want this can select it from their ops.
strictly speaking it's per-iommu-instance group. 😊
+/*
+ * Generic device_group call-back function. It just allocates one
+ * iommu-group per iommu driver.
+ */
+struct iommu_group *generic_single_device_group(struct device *dev)
+{
+ struct iommu_device *iommu = dev->iommu->iommu_dev;
+
+ lockdep_assert_held(&dev_iommu_group_lock);
+
+ if (!iommu->singleton_group) {
+ struct iommu_group *group;
+
+ group = iommu_group_alloc();
+ if (IS_ERR(group))
+ return group;
+ iommu->singleton_group = group;
+ }
+ return iommu_group_ref_get(iommu->singleton_group);
'singleton' is a bit confusing whether it means a single
group per instance or a group having only a single device.
I don't know a better name, but probably just using
iommu->group is not worse than the 'singleton_' prefix...
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel