[PATCH 2/8] iommu/amd: Making device attach / detach helpers non-static

Suravee Suthikulpanit posted 8 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 2/8] iommu/amd: Making device attach / detach helpers non-static
Posted by Suravee Suthikulpanit 1 month, 2 weeks ago
To allow reuse in subsequent patches.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 drivers/iommu/amd/amd_iommu.h |  2 ++
 drivers/iommu/amd/iommu.c     | 11 +++++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index 6ea549816a1f..5085aa353522 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -88,6 +88,8 @@ int amd_iommu_complete_ppr(struct device *dev, u32 pasid, int status, int tag);
  * This function flushes all internal caches of
  * the IOMMU used by this driver.
  */
+int __amd_iommu_attach_device(struct device *dev, struct protection_domain *domain);
+void amd_iommu_detach_device(struct device *dev);
 void amd_iommu_flush_all_caches(struct amd_iommu *iommu);
 void amd_iommu_update_and_flush_device_table(struct protection_domain *domain);
 void amd_iommu_domain_flush_pages(struct protection_domain *domain,
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a05b7f69ac74..207fef84a4c5 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2262,8 +2262,7 @@ static void pdom_detach_iommu(struct amd_iommu *iommu,
  * If a device is not yet associated with a domain, this function makes the
  * device visible in the domain
  */
-static int attach_device(struct device *dev,
-			 struct protection_domain *domain)
+int __amd_iommu_attach_device(struct device *dev, struct protection_domain *domain)
 {
 	struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
 	struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
@@ -2325,7 +2324,7 @@ static int attach_device(struct device *dev,
 /*
  * Removes a device from a protection domain (with devtable_lock held)
  */
-static void detach_device(struct device *dev)
+void amd_iommu_detach_device(struct device *dev)
 {
 	struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
 	struct amd_iommu *iommu = get_amd_iommu_from_dev_data(dev_data);
@@ -2639,7 +2638,7 @@ static int blocked_domain_attach_device(struct iommu_domain *domain,
 	struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
 
 	if (dev_data->domain)
-		detach_device(dev);
+		amd_iommu_detach_device(dev);
 
 	/* Clear DTE and flush the entry */
 	mutex_lock(&dev_data->mutex);
@@ -2717,9 +2716,9 @@ static int amd_iommu_attach_device(struct iommu_domain *dom,
 		return -EINVAL;
 
 	if (dev_data->domain)
-		detach_device(dev);
+		amd_iommu_detach_device(dev);
 
-	ret = attach_device(dev, domain);
+	ret = __amd_iommu_attach_device(dev, domain);
 
 #ifdef CONFIG_IRQ_REMAP
 	if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) {
-- 
2.34.1
Re: [PATCH 2/8] iommu/amd: Making device attach / detach helpers non-static
Posted by Jason Gunthorpe 1 month ago
On Wed, Aug 20, 2025 at 11:30:03AM +0000, Suravee Suthikulpanit wrote:
> To allow reuse in subsequent patches.
> 
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> ---
>  drivers/iommu/amd/amd_iommu.h |  2 ++
>  drivers/iommu/amd/iommu.c     | 11 +++++------
>  2 files changed, 7 insertions(+), 6 deletions(-)

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>

> -static int attach_device(struct device *dev,
> -			 struct protection_domain *domain)
> +int __amd_iommu_attach_device(struct device *dev, struct protection_domain *domain)

Though it would be nice to see a clearer name for this than __

Jason