mirror of
https://github.com/torvalds/linux.git
synced 2024-11-27 14:41:39 +00:00
iommu/amd: Update struct iommu_dev_data definition
struct iommu_dev_data contains member "pdev" to point to pci_dev. This is valid for only PCI devices and for other devices this will be NULL. This causes unnecessary "pdev != NULL" check at various places. Replace "struct pci_dev" member with "struct device" and use to_pci_dev() to get pci device reference as needed. Also adjust setup_aliases() and clone_aliases() function. No functional change intended. Co-developed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Link: https://lore.kernel.org/r/20220706113825.25582-2-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
83874d51eb
commit
d02674d71c
@ -689,7 +689,7 @@ struct iommu_dev_data {
|
||||
struct list_head list; /* For domain->dev_list */
|
||||
struct llist_node dev_data_list; /* For global dev_data_list */
|
||||
struct protection_domain *domain; /* Domain the device is bound to */
|
||||
struct pci_dev *pdev;
|
||||
struct device *dev;
|
||||
u16 devid; /* PCI Device ID */
|
||||
bool iommu_v2; /* Device can make use of IOMMUv2 */
|
||||
struct {
|
||||
|
@ -188,10 +188,13 @@ static int clone_alias(struct pci_dev *pdev, u16 alias, void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void clone_aliases(struct pci_dev *pdev)
|
||||
static void clone_aliases(struct device *dev)
|
||||
{
|
||||
if (!pdev)
|
||||
struct pci_dev *pdev;
|
||||
|
||||
if (!dev_is_pci(dev))
|
||||
return;
|
||||
pdev = to_pci_dev(dev);
|
||||
|
||||
/*
|
||||
* The IVRS alias stored in the alias table may not be
|
||||
@ -203,14 +206,14 @@ static void clone_aliases(struct pci_dev *pdev)
|
||||
pci_for_each_dma_alias(pdev, clone_alias, NULL);
|
||||
}
|
||||
|
||||
static struct pci_dev *setup_aliases(struct device *dev)
|
||||
static void setup_aliases(struct device *dev)
|
||||
{
|
||||
struct pci_dev *pdev = to_pci_dev(dev);
|
||||
u16 ivrs_alias;
|
||||
|
||||
/* For ACPI HID devices, there are no aliases */
|
||||
if (!dev_is_pci(dev))
|
||||
return NULL;
|
||||
return;
|
||||
|
||||
/*
|
||||
* Add the IVRS alias to the pci aliases if it is on the same
|
||||
@ -221,9 +224,7 @@ static struct pci_dev *setup_aliases(struct device *dev)
|
||||
PCI_BUS_NUM(ivrs_alias) == pdev->bus->number)
|
||||
pci_add_dma_alias(pdev, ivrs_alias & 0xff, 1);
|
||||
|
||||
clone_aliases(pdev);
|
||||
|
||||
return pdev;
|
||||
clone_aliases(dev);
|
||||
}
|
||||
|
||||
static struct iommu_dev_data *find_dev_data(u16 devid)
|
||||
@ -331,7 +332,8 @@ static int iommu_init_device(struct device *dev)
|
||||
if (!dev_data)
|
||||
return -ENOMEM;
|
||||
|
||||
dev_data->pdev = setup_aliases(dev);
|
||||
dev_data->dev = dev;
|
||||
setup_aliases(dev);
|
||||
|
||||
/*
|
||||
* By default we use passthrough mode for IOMMUv2 capable device.
|
||||
@ -1232,13 +1234,17 @@ static int device_flush_dte_alias(struct pci_dev *pdev, u16 alias, void *data)
|
||||
static int device_flush_dte(struct iommu_dev_data *dev_data)
|
||||
{
|
||||
struct amd_iommu *iommu;
|
||||
struct pci_dev *pdev = NULL;
|
||||
u16 alias;
|
||||
int ret;
|
||||
|
||||
iommu = amd_iommu_rlookup_table[dev_data->devid];
|
||||
|
||||
if (dev_data->pdev)
|
||||
ret = pci_for_each_dma_alias(dev_data->pdev,
|
||||
if (dev_is_pci(dev_data->dev))
|
||||
pdev = to_pci_dev(dev_data->dev);
|
||||
|
||||
if (pdev)
|
||||
ret = pci_for_each_dma_alias(pdev,
|
||||
device_flush_dte_alias, iommu);
|
||||
else
|
||||
ret = iommu_flush_dte(iommu, dev_data->devid);
|
||||
@ -1561,7 +1567,7 @@ static void do_attach(struct iommu_dev_data *dev_data,
|
||||
/* Update device table */
|
||||
set_dte_entry(dev_data->devid, domain,
|
||||
ats, dev_data->iommu_v2);
|
||||
clone_aliases(dev_data->pdev);
|
||||
clone_aliases(dev_data->dev);
|
||||
|
||||
device_flush_dte(dev_data);
|
||||
}
|
||||
@ -1577,7 +1583,7 @@ static void do_detach(struct iommu_dev_data *dev_data)
|
||||
dev_data->domain = NULL;
|
||||
list_del(&dev_data->list);
|
||||
clear_dte_entry(dev_data->devid);
|
||||
clone_aliases(dev_data->pdev);
|
||||
clone_aliases(dev_data->dev);
|
||||
|
||||
/* Flush the DTE entry */
|
||||
device_flush_dte(dev_data);
|
||||
@ -1818,7 +1824,7 @@ static void update_device_table(struct protection_domain *domain)
|
||||
list_for_each_entry(dev_data, &domain->dev_list, list) {
|
||||
set_dte_entry(dev_data->devid, domain,
|
||||
dev_data->ats.enabled, dev_data->iommu_v2);
|
||||
clone_aliases(dev_data->pdev);
|
||||
clone_aliases(dev_data->dev);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user