Skip to content

Commit e5d1841

Browse files
committed
iommu/vt-d: Convert to probe/release_device() call-backs
Convert the Intel IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent dce8d69 commit e5d1841

File tree

1 file changed

+6
-61
lines changed

1 file changed

+6
-61
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5781,78 +5781,27 @@ static bool intel_iommu_capable(enum iommu_cap cap)
57815781
return false;
57825782
}
57835783

5784-
static int intel_iommu_add_device(struct device *dev)
5784+
static struct iommu_device *intel_iommu_probe_device(struct device *dev)
57855785
{
5786-
struct dmar_domain *dmar_domain;
5787-
struct iommu_domain *domain;
57885786
struct intel_iommu *iommu;
5789-
struct iommu_group *group;
57905787
u8 bus, devfn;
5791-
int ret;
57925788

57935789
iommu = device_to_iommu(dev, &bus, &devfn);
57945790
if (!iommu)
5795-
return -ENODEV;
5796-
5797-
iommu_device_link(&iommu->iommu, dev);
5791+
return ERR_PTR(-ENODEV);
57985792

57995793
if (translation_pre_enabled(iommu))
58005794
dev->archdata.iommu = DEFER_DEVICE_DOMAIN_INFO;
58015795

5802-
group = iommu_group_get_for_dev(dev);
5803-
5804-
if (IS_ERR(group)) {
5805-
ret = PTR_ERR(group);
5806-
goto unlink;
5807-
}
5808-
5809-
iommu_group_put(group);
5810-
5811-
domain = iommu_get_domain_for_dev(dev);
5812-
dmar_domain = to_dmar_domain(domain);
5813-
if (domain->type == IOMMU_DOMAIN_DMA) {
5814-
if (device_def_domain_type(dev) == IOMMU_DOMAIN_IDENTITY) {
5815-
ret = iommu_request_dm_for_dev(dev);
5816-
if (ret) {
5817-
dmar_remove_one_dev_info(dev);
5818-
dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN;
5819-
domain_add_dev_info(si_domain, dev);
5820-
dev_info(dev,
5821-
"Device uses a private identity domain.\n");
5822-
}
5823-
}
5824-
} else {
5825-
if (device_def_domain_type(dev) == IOMMU_DOMAIN_DMA) {
5826-
ret = iommu_request_dma_domain_for_dev(dev);
5827-
if (ret) {
5828-
dmar_remove_one_dev_info(dev);
5829-
dmar_domain->flags |= DOMAIN_FLAG_LOSE_CHILDREN;
5830-
if (!get_private_domain_for_dev(dev)) {
5831-
dev_warn(dev,
5832-
"Failed to get a private domain.\n");
5833-
ret = -ENOMEM;
5834-
goto unlink;
5835-
}
5836-
5837-
dev_info(dev,
5838-
"Device uses a private dma domain.\n");
5839-
}
5840-
}
5841-
}
5842-
58435796
if (device_needs_bounce(dev)) {
58445797
dev_info(dev, "Use Intel IOMMU bounce page dma_ops\n");
58455798
set_dma_ops(dev, &bounce_dma_ops);
58465799
}
58475800

5848-
return 0;
5849-
5850-
unlink:
5851-
iommu_device_unlink(&iommu->iommu, dev);
5852-
return ret;
5801+
return &iommu->iommu;
58535802
}
58545803

5855-
static void intel_iommu_remove_device(struct device *dev)
5804+
static void intel_iommu_release_device(struct device *dev)
58565805
{
58575806
struct intel_iommu *iommu;
58585807
u8 bus, devfn;
@@ -5863,10 +5812,6 @@ static void intel_iommu_remove_device(struct device *dev)
58635812

58645813
dmar_remove_one_dev_info(dev);
58655814

5866-
iommu_group_remove_device(dev);
5867-
5868-
iommu_device_unlink(&iommu->iommu, dev);
5869-
58705815
if (device_needs_bounce(dev))
58715816
set_dma_ops(dev, NULL);
58725817
}
@@ -6198,8 +6143,8 @@ const struct iommu_ops intel_iommu_ops = {
61986143
.map = intel_iommu_map,
61996144
.unmap = intel_iommu_unmap,
62006145
.iova_to_phys = intel_iommu_iova_to_phys,
6201-
.add_device = intel_iommu_add_device,
6202-
.remove_device = intel_iommu_remove_device,
6146+
.probe_device = intel_iommu_probe_device,
6147+
.release_device = intel_iommu_release_device,
62036148
.get_resv_regions = intel_iommu_get_resv_regions,
62046149
.put_resv_regions = generic_iommu_put_resv_regions,
62056150
.apply_resv_region = intel_iommu_apply_resv_region,

0 commit comments

Comments
 (0)