From patchwork Sat Oct 12 20:32:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Varun Sethi X-Patchwork-Id: 283016 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 19C6A2C049D for ; Sun, 13 Oct 2013 07:47:08 +1100 (EST) Received: from tx2outboundpool.messaging.microsoft.com (tx2ehsobe005.messaging.microsoft.com [65.55.88.15]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client CN "mail.global.frontbridge.com", Issuer "MSIT Machine Auth CA 2" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E71722C03AB for ; Sun, 13 Oct 2013 07:45:53 +1100 (EST) Received: from mail36-tx2-R.bigfish.com (10.9.14.242) by TX2EHSOBE011.bigfish.com (10.9.40.31) with Microsoft SMTP Server id 14.1.225.22; Sat, 12 Oct 2013 20:45:50 +0000 Received: from mail36-tx2 (localhost [127.0.0.1]) by mail36-tx2-R.bigfish.com (Postfix) with ESMTP id CFA4034018A; Sat, 12 Oct 2013 20:45:49 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 1 X-BigFish: VS1(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzd2iz1de098h1de097h8275bhz2dh2a8h839he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1dfeh1dffh1e23h1fe8h1ff5h1155h) Received: from mail36-tx2 (localhost.localdomain [127.0.0.1]) by mail36-tx2 (MessageSwitch) id 1381610746964435_10287; Sat, 12 Oct 2013 20:45:46 +0000 (UTC) Received: from TX2EHSMHS043.bigfish.com (unknown [10.9.14.243]) by mail36-tx2.bigfish.com (Postfix) with ESMTP id DBE1E240041; Sat, 12 Oct 2013 20:45:46 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS043.bigfish.com (10.9.99.143) with Microsoft SMTP Server (TLS) id 14.16.227.3; Sat, 12 Oct 2013 20:45:46 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.3.158.2; Sat, 12 Oct 2013 20:45:46 +0000 Received: from nmglablinux27.ap.freescale.net ([10.232.15.69]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r9CKjTeQ019958; Sat, 12 Oct 2013 13:45:43 -0700 From: Varun Sethi To: , , , , , , , Subject: [PATCH 1/3] iommu/fsl: Factor out PCI specific code. Date: Sun, 13 Oct 2013 02:02:32 +0530 Message-ID: <1381609954-15283-2-git-send-email-Varun.Sethi@freescale.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1381609954-15283-1-git-send-email-Varun.Sethi@freescale.com> References: <1381609954-15283-1-git-send-email-Varun.Sethi@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Cc: Varun Sethi X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16rc2 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Factor out PCI specific code in the PAMU driver. Signed-off-by: Varun Sethi --- drivers/iommu/fsl_pamu_domain.c | 81 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c index c857c30..e02e1de 100644 --- a/drivers/iommu/fsl_pamu_domain.c +++ b/drivers/iommu/fsl_pamu_domain.c @@ -677,13 +677,9 @@ static int handle_attach_device(struct fsl_dma_domain *dma_domain, return ret; } -static int fsl_pamu_attach_device(struct iommu_domain *domain, - struct device *dev) +static void check_for_pci_dma_device(struct device **dev) { - struct fsl_dma_domain *dma_domain = domain->priv; - const u32 *liodn; - u32 liodn_cnt; - int len, ret = 0; +#ifdef CONFIG_PCI struct pci_dev *pdev = NULL; struct pci_controller *pci_ctl; @@ -691,25 +687,38 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain, * Use LIODN of the PCI controller while attaching a * PCI device. */ - if (dev->bus == &pci_bus_type) { - pdev = to_pci_dev(dev); + if ((*dev)->bus == &pci_bus_type) { + pdev = to_pci_dev(*dev); pci_ctl = pci_bus_to_host(pdev->bus); /* * make dev point to pci controller device * so we can get the LIODN programmed by * u-boot. */ - dev = pci_ctl->parent; + *dev = pci_ctl->parent; } +#endif +} - liodn = of_get_property(dev->of_node, "fsl,liodn", &len); +static int fsl_pamu_attach_device(struct iommu_domain *domain, + struct device *dev) +{ + struct fsl_dma_domain *dma_domain = domain->priv; + struct device *dma_dev = dev; + const u32 *liodn; + u32 liodn_cnt; + int len, ret = 0; + + check_for_pci_dma_device(&dma_dev); + + liodn = of_get_property(dma_dev->of_node, "fsl,liodn", &len); if (liodn) { liodn_cnt = len / sizeof(u32); ret = handle_attach_device(dma_domain, dev, liodn, liodn_cnt); } else { pr_debug("missing fsl,liodn property at %s\n", - dev->of_node->full_name); + dma_dev->of_node->full_name); ret = -EINVAL; } @@ -720,32 +729,18 @@ static void fsl_pamu_detach_device(struct iommu_domain *domain, struct device *dev) { struct fsl_dma_domain *dma_domain = domain->priv; + struct device *dma_dev = dev; const u32 *prop; int len; - struct pci_dev *pdev = NULL; - struct pci_controller *pci_ctl; - /* - * Use LIODN of the PCI controller while detaching a - * PCI device. - */ - if (dev->bus == &pci_bus_type) { - pdev = to_pci_dev(dev); - pci_ctl = pci_bus_to_host(pdev->bus); - /* - * make dev point to pci controller device - * so we can get the LIODN programmed by - * u-boot. - */ - dev = pci_ctl->parent; - } + check_for_pci_dma_device(&dma_dev); - prop = of_get_property(dev->of_node, "fsl,liodn", &len); + prop = of_get_property(dma_dev->of_node, "fsl,liodn", &len); if (prop) detach_device(dev, dma_domain); else pr_debug("missing fsl,liodn property at %s\n", - dev->of_node->full_name); + dma_dev->of_node->full_name); } static int configure_domain_geometry(struct iommu_domain *domain, void *data) @@ -905,6 +900,7 @@ static struct iommu_group *get_device_iommu_group(struct device *dev) return group; } +#ifdef CONFIG_PCI static bool check_pci_ctl_endpt_part(struct pci_controller *pci_ctl) { u32 version; @@ -945,13 +941,18 @@ static struct iommu_group *get_shared_pci_device_group(struct pci_dev *pdev) return NULL; } -static struct iommu_group *get_pci_device_group(struct pci_dev *pdev) +static struct iommu_group *get_pci_device_group(struct device *dev) { struct pci_controller *pci_ctl; bool pci_endpt_partioning; struct iommu_group *group = NULL; - struct pci_dev *bridge, *dma_pdev = NULL; + struct pci_dev *bridge, *pdev; + struct pci_dev *dma_pdev = NULL; + pdev = to_pci_dev(dev); + /* Don't create device groups for virtual PCI bridges */ + if (pdev->subordinate) + return NULL; pci_ctl = pci_bus_to_host(pdev->bus); pci_endpt_partioning = check_pci_ctl_endpt_part(pci_ctl); /* We can partition PCIe devices so assign device group to the device */ @@ -1044,11 +1045,11 @@ root_bus: return group; } +#endif static int fsl_pamu_add_device(struct device *dev) { struct iommu_group *group = NULL; - struct pci_dev *pdev; const u32 *prop; int ret, len; @@ -1056,19 +1057,15 @@ static int fsl_pamu_add_device(struct device *dev) * For platform devices we allocate a separate group for * each of the devices. */ - if (dev->bus == &pci_bus_type) { - pdev = to_pci_dev(dev); - /* Don't create device groups for virtual PCI bridges */ - if (pdev->subordinate) - return 0; - - group = get_pci_device_group(pdev); - - } else { + if (dev->bus == &platform_bus_type) { prop = of_get_property(dev->of_node, "fsl,liodn", &len); if (prop) group = get_device_iommu_group(dev); } +#ifdef CONFIG_PCI + else + group = get_pci_device_group(dev); +#endif if (!group || IS_ERR(group)) return PTR_ERR(group); @@ -1166,7 +1163,9 @@ int pamu_domain_init() return ret; bus_set_iommu(&platform_bus_type, &fsl_pamu_ops); +#ifdef CONFIG_PCI bus_set_iommu(&pci_bus_type, &fsl_pamu_ops); +#endif return ret; }