From: Julien Grall Subject: [PATCH v4 3/8] xen/iommu: Consolidate device assignment ops into a single set Date: Wed, 25 Feb 2015 18:52:56 +0000 Message-ID: <1424890381-4225-4-git-send-email-julien.grall@linaro.org> References: <1424890381-4225-1-git-send-email-julien.grall@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YQh5W-0005q7-GV for xen-devel@lists.xenproject.org; Wed, 25 Feb 2015 18:53:38 +0000 Received: by wggz12 with SMTP id z12so5619822wgg.2 for ; Wed, 25 Feb 2015 10:53:36 -0800 (PST) In-Reply-To: <1424890381-4225-1-git-send-email-julien.grall@linaro.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: ian.campbell@citrix.com, Stefano Stabellini , manish.jaggi@caviumnetworks.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Jan Beulich List-Id: xen-devel@lists.xenproject.org On ARM, the way to assign device tree node is exactly the same as PCI. Futhermore, all devices can be represented by a 'device_t'. Therefore there is no need to add separate ops. The x86 iommu drivers has not been modified to replace 'struct pci_dev' by "device_t" because the latter is an alias of the former. Signed-off-by: Julien Grall Acked-by: Jan Beulich Acked-by: Stefano Stabellini \ Acked-by: Ian Campbell --- Changes in v4: - Add Ian's ack Changes in v3: - Add Stefano and Jan's ack Changes in v2: - Use the newly type device_t - It's not neccessary to modify the x86 iommu drivers --- xen/drivers/passthrough/device_tree.c | 5 +++-- xen/drivers/passthrough/pci.c | 20 +++++++++++--------- xen/include/xen/iommu.h | 17 ++++++----------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 3e47df5..377d41d 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -41,7 +41,7 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) if ( !list_empty(&dev->domain_list) ) goto fail; - rc = hd->platform_ops->assign_dt_device(d, dev); + rc = hd->platform_ops->assign_device(d, 0, dt_to_dev(dev)); if ( rc ) goto fail; @@ -68,7 +68,8 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev) spin_lock(&dtdevs_lock); - rc = hd->platform_ops->reassign_dt_device(d, hardware_domain, dev); + rc = hd->platform_ops->reassign_device(d, hardware_domain, + 0, dt_to_dev(dev)); if ( rc ) goto fail; diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index b93e7d8..4b83583 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1254,7 +1254,7 @@ int iommu_add_device(struct pci_dev *pdev) if ( !iommu_enabled || !hd->platform_ops ) return 0; - rc = hd->platform_ops->add_device(pdev->devfn, pdev); + rc = hd->platform_ops->add_device(pdev->devfn, pci_to_dev(pdev)); if ( rc || !pdev->phantom_stride ) return rc; @@ -1263,7 +1263,7 @@ int iommu_add_device(struct pci_dev *pdev) devfn += pdev->phantom_stride; if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) return 0; - rc = hd->platform_ops->add_device(devfn, pdev); + rc = hd->platform_ops->add_device(devfn, pci_to_dev(pdev)); if ( rc ) printk(XENLOG_WARNING "IOMMU: add %04x:%02x:%02x.%u failed (%d)\n", pdev->seg, pdev->bus, PCI_SLOT(devfn), PCI_FUNC(devfn), rc); @@ -1284,7 +1284,7 @@ int iommu_enable_device(struct pci_dev *pdev) !hd->platform_ops->enable_device ) return 0; - return hd->platform_ops->enable_device(pdev); + return hd->platform_ops->enable_device(pci_to_dev(pdev)); } int iommu_remove_device(struct pci_dev *pdev) @@ -1306,7 +1306,7 @@ int iommu_remove_device(struct pci_dev *pdev) devfn += pdev->phantom_stride; if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) break; - rc = hd->platform_ops->remove_device(devfn, pdev); + rc = hd->platform_ops->remove_device(devfn, pci_to_dev(pdev)); if ( !rc ) continue; @@ -1315,7 +1315,7 @@ int iommu_remove_device(struct pci_dev *pdev) return rc; } - return hd->platform_ops->remove_device(pdev->devfn, pdev); + return hd->platform_ops->remove_device(pdev->devfn, pci_to_dev(pdev)); } /* @@ -1383,7 +1383,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) pdev->fault.count = 0; - if ( (rc = hd->platform_ops->assign_device(d, devfn, pdev)) ) + if ( (rc = hd->platform_ops->assign_device(d, devfn, pci_to_dev(pdev))) ) goto done; for ( ; pdev->phantom_stride; rc = 0 ) @@ -1391,7 +1391,7 @@ static int assign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) devfn += pdev->phantom_stride; if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) break; - rc = hd->platform_ops->assign_device(d, devfn, pdev); + rc = hd->platform_ops->assign_device(d, devfn, pci_to_dev(pdev)); if ( rc ) printk(XENLOG_G_WARNING "d%d: assign %04x:%02x:%02x.%u failed (%d)\n", d->domain_id, seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn), @@ -1426,7 +1426,8 @@ int deassign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) devfn += pdev->phantom_stride; if ( PCI_SLOT(devfn) != PCI_SLOT(pdev->devfn) ) break; - ret = hd->platform_ops->reassign_device(d, hardware_domain, devfn, pdev); + ret = hd->platform_ops->reassign_device(d, hardware_domain, devfn, + pci_to_dev(pdev)); if ( !ret ) continue; @@ -1436,7 +1437,8 @@ int deassign_device(struct domain *d, u16 seg, u8 bus, u8 devfn) } devfn = pdev->devfn; - ret = hd->platform_ops->reassign_device(d, hardware_domain, devfn, pdev); + ret = hd->platform_ops->reassign_device(d, hardware_domain, devfn, + pci_to_dev(pdev)); if ( ret ) { dprintk(XENLOG_G_ERR, diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index ecb2627..bf4aff0 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -124,22 +124,17 @@ struct page_info; struct iommu_ops { int (*init)(struct domain *d); void (*hwdom_init)(struct domain *d); -#ifdef HAS_PCI - int (*add_device)(u8 devfn, struct pci_dev *); - int (*enable_device)(struct pci_dev *pdev); - int (*remove_device)(u8 devfn, struct pci_dev *); - int (*assign_device)(struct domain *, u8 devfn, struct pci_dev *); + int (*add_device)(u8 devfn, device_t *dev); + int (*enable_device)(device_t *dev); + int (*remove_device)(u8 devfn, device_t *dev); + int (*assign_device)(struct domain *, u8 devfn, device_t *dev); int (*reassign_device)(struct domain *s, struct domain *t, - u8 devfn, struct pci_dev *); + u8 devfn, device_t *dev); +#ifdef HAS_PCI int (*get_device_group_id)(u16 seg, u8 bus, u8 devfn); int (*update_ire_from_msi)(struct msi_desc *msi_desc, struct msi_msg *msg); void (*read_msi_from_ire)(struct msi_desc *msi_desc, struct msi_msg *msg); #endif /* HAS_PCI */ -#ifdef HAS_DEVICE_TREE - int (*assign_dt_device)(struct domain *d, const struct dt_device_node *dev); - int (*reassign_dt_device)(struct domain *s, struct domain *t, - const struct dt_device_node *dev); -#endif void (*teardown)(struct domain *d); int (*map_page)(struct domain *d, unsigned long gfn, unsigned long mfn, -- 2.1.4