From patchwork Wed Mar 21 06:55:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipun Gupta X-Patchwork-Id: 10298687 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 56E14600CC for ; Wed, 21 Mar 2018 06:56:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4913A29711 for ; Wed, 21 Mar 2018 06:56:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D68D29783; Wed, 21 Mar 2018 06:56:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87F1E29763 for ; Wed, 21 Mar 2018 06:56:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751712AbeCUG4O (ORCPT ); Wed, 21 Mar 2018 02:56:14 -0400 Received: from mail-ve1eur01on0047.outbound.protection.outlook.com ([104.47.1.47]:3180 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751661AbeCUG4K (ORCPT ); Wed, 21 Mar 2018 02:56:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=pTU/o7/+sYzd7Ei++D/McuII5JcM/Vo5HlDTK3Oy7GQ=; b=UPyFy4KxKKghvQmfrFm2/3g2zqnPDNYua4TyJYMZa5pqG/5BO4fkBtovdEYYuDdR3fsNjjj57wRPSQvF6J9FZ/SZ0A2RpHr8Bsv66x30jzesAffamvaezfN6llk3hil1al6F0j9zaUHp1gLMOgt20cyZcqopF70ysf+591FVq48= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=nipun.gupta@nxp.com; Received: from b27504-OptiPlex-790.ap.freescale.net (14.142.187.166) by VI1PR0401MB2431.eurprd04.prod.outlook.com (2603:10a6:800:2a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.588.14; Wed, 21 Mar 2018 06:55:58 +0000 From: Nipun Gupta To: robin.murphy@arm.com, hch@lst.de, linux@armlinux.org.uk, gregkh@linuxfoundation.org, m.szyprowski@samsung.com Cc: bhelgaas@google.com, zajec5@gmail.com, andy.gross@linaro.org, david.brown@linaro.org, dan.j.williams@intel.com, vinod.koul@intel.com, thierry.reding@gmail.com, robh+dt@kernel.org, frowand.list@gmail.com, jarkko.sakkinen@linux.intel.com, rafael.j.wysocki@intel.com, dmitry.torokhov@gmail.com, johan@kernel.org, msuchanek@suse.de, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-wireless@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, dmaengine@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, bharat.bhushan@nxp.com, leoyang.li@nxp.com, Nipun Gupta Subject: [PATCH v2 1/2] dma-mapping: move dma configuration to bus infrastructure Date: Wed, 21 Mar 2018 12:25:22 +0530 Message-Id: <1521615323-4752-1-git-send-email-nipun.gupta@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1520868292-2479-1-git-send-email-nipun.gupta@nxp.com> References: <1520868292-2479-1-git-send-email-nipun.gupta@nxp.com> MIME-Version: 1.0 X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: BM1PR01CA0090.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1::30) To VI1PR0401MB2431.eurprd04.prod.outlook.com (2603:10a6:800:2a::24) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1c035eef-e2f5-45c4-84cc-08d58ef8d059 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0401MB2431; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0401MB2431; 3:5Vn0cNTwmbYoXPXVq2J4O5diJq/ZbkIcKJw8Orj4OWt9VSVJB1YJrnDq31yEPN97w+sVLN1s61Z/mInqaLne+RA3VRd6AXd95pjZh2K5r7j2L640TNbJOgPPJGLkmnnKoIVGQtjJ9c1nbd5cHjoTJEF5WcnGZte6Zx67nZ8df4gj+Mo9ReIYBVMpk5/AIPwxHD2QtX+1mTnbiJmpUgjDOcdb3CYk4vUBUn92pnSPYRyVPa1z3UMCQU6XFpFhdjy3; 25:qUz1z1YVT/jSAdb2tcv4bXoUtpqrZBeqd6UwvsgFNPyRJ8hgS+hE/tevP6/DrLXRqFe2OVCfYqgA/z5MQY9bCfRj1P1dlhOIrVObEABnozy8Qk37+IABc3MLxT4jcQj6OzKNemjf+5bF/WZgHPLbZHi9gyLE2vytejhUQvg6+PKpsPmifeA+peYxtILQL4+Q2D/J9d3vE4D8W+Hs8EpsxL17IbUVTlI5bpzM8bguiSU81u+2E5OqvtYA+S5R95EC+BrjXa99iAY2nRDeXuuneASYJ3AQLfcmu3/UjjhSxhtwPxuYACq/z8NHIy9Vuymib2sr9UVNzSj9gb8fSwBHmA==; 31:mCG7BwaZ9PVhZ3VADlmne7eR9Fd66qIhPYtKEfvf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qiF5lvOQUiWG71J0J/a X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231221)(944501244)(52105095)(3002001)(6055026)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:VI1PR0401MB2431; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0401MB2431; X-Forefront-PRVS: 0618E4E7E1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(366004)(346002)(376002)(39380400002)(39860400002)(189003)(199004)(50226002)(2950100002)(7736002)(966005)(4326008)(86362001)(36756003)(8676002)(81166006)(478600001)(6486002)(316002)(81156014)(66066001)(305945005)(47776003)(6666003)(2906002)(8936002)(5009440100003)(6116002)(97736004)(16586007)(3846002)(186003)(52116002)(51416003)(76176011)(5890100001)(105586002)(39060400002)(53936002)(106356001)(48376002)(59450400001)(6512007)(5660300001)(16526019)(25786009)(68736007)(386003)(55236004)(6506007)(26005)(6306002)(7416002)(50466002)(110426004)(357404004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0401MB2431; H:b27504-OptiPlex-790.ap.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0401MB2431; 23:l7aYbUVgCn7K/eSx4mDbqPcBjv4i1YOyvhKnrRB?= =?us-ascii?Q?SMRoDP0yKWiTle3jt0dZDl10v/XQmc01BFTN7NCmgGLf+hmGENkIb2XsYU6e?= =?us-ascii?Q?LkSeAeONueUxk+mrZ3pJRlqX1PlfT5DVqX/1sRuQQymwlym7ZKrTOWAzM7Ve?= =?us-ascii?Q?dgW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/61HRU2v9H3q2DPyPep8yx10IVpAMyhIKksFlYi/0YcticUrbZUCWzEDmHye+FgTD9Rh1g/ffSzX2g=; 24:m+CTGBRYMInPMZ5/+xP3XPd1D+GKpYnPp2XAN/2qkp/Dco7ZavoEPOHnLodbVDHmyPRXQQifpD8viPQyds983Huu63BHj7TG2BYhB61GPzs=; 7:peFTycMMn+lATLXzm7AySuTJw3AZw1UvFZHxpNKdFmWWMZAAdChDC2I5CMtkQ6sZ48APCyfokwkkSdIUPHeCIGg61pCE5c83WcRb/bQVixr0nnV0cRe5K30zaUIFRcGHP9oA+FeGD+NCBmif+6SrWUWpCTVbj1AXvLAp+cldxGd33d54IyeqGIyHH+2aMkPoSDcgEhC6W7TYb2Gx9K+8mah3++2o41q8l26WmlmJ6X2zgn4osH5wxYINgsXqMN4C SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Mar 2018 06:55:58.0728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c035eef-e2f5-45c4-84cc-08d58ef8d059 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2431 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It's bus specific aspect to map a given device on the bus and relevant firmware description of its DMA configuration. So, this change introduces '/dma_configure/' as bus callback giving flexibility to busses for implementing its own dma configuration function. The change eases the addition of new busses w.r.t. adding the dma configuration functionality. This patch also updates the PCI, Platform, ACPI and host1x bus to use new introduced callbacks. Suggested-by: Christoph Hellwig Signed-off-by: Nipun Gupta Reviewed-by: Greg Kroah-Hartman --- - The patches are based on the comments on: https://patchwork.kernel.org/patch/10259087/ Changes in v2: - Do not have dma_deconfigure callback - Have '/dma_common_configure/' API to provide a common DMA configuration which can be used by busses if it suits them. - Platform and ACPI bus to use '/dma_common_configure/' in '/dma_configure/' callback. - Updated commit message - Updated pci_dma_configure API with changes suggested by Robin drivers/amba/bus.c | 7 +++++++ drivers/base/dma-mapping.c | 35 +++++++++++++++-------------------- drivers/base/platform.c | 6 ++++++ drivers/gpu/host1x/bus.c | 9 +++++++++ drivers/pci/pci-driver.c | 32 ++++++++++++++++++++++++++++++++ include/linux/device.h | 4 ++++ include/linux/dma-mapping.h | 1 + 7 files changed, 74 insertions(+), 20 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 594c228..2fa1e8b 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -171,6 +172,11 @@ static int amba_pm_runtime_resume(struct device *dev) } #endif /* CONFIG_PM */ +static int amba_dma_configure(struct device *dev) +{ + return dma_common_configure(dev); +} + static const struct dev_pm_ops amba_pm = { .suspend = pm_generic_suspend, .resume = pm_generic_resume, @@ -194,6 +200,7 @@ struct bus_type amba_bustype = { .dev_groups = amba_dev_groups, .match = amba_match, .uevent = amba_uevent, + .dma_configure = amba_dma_configure, .pm = &amba_pm, .force_dma = true, }; diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 3b11835..48f9af0 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -331,38 +331,33 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags) #endif /* - * Common configuration to enable DMA API use for a device + * Common configuration to enable DMA API use for a device. + * A bus can use this function in its 'dma_configure' callback, if + * suitable for the bus. */ -#include - -int dma_configure(struct device *dev) +int dma_common_configure(struct device *dev) { - struct device *bridge = NULL, *dma_dev = dev; enum dev_dma_attr attr; int ret = 0; - if (dev_is_pci(dev)) { - bridge = pci_get_host_bridge_device(to_pci_dev(dev)); - dma_dev = bridge; - if (IS_ENABLED(CONFIG_OF) && dma_dev->parent && - dma_dev->parent->of_node) - dma_dev = dma_dev->parent; - } - - if (dma_dev->of_node) { - ret = of_dma_configure(dev, dma_dev->of_node); - } else if (has_acpi_companion(dma_dev)) { - attr = acpi_get_dma_attr(to_acpi_device_node(dma_dev->fwnode)); + if (dev->of_node) { + ret = of_dma_configure(dev, dev->of_node); + } else if (has_acpi_companion(dev)) { + attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode)); if (attr != DEV_DMA_NOT_SUPPORTED) ret = acpi_dma_configure(dev, attr); } - if (bridge) - pci_put_host_bridge_device(bridge); - return ret; } +int dma_configure(struct device *dev) +{ + if (dev->bus->dma_configure) + return dev->bus->dma_configure(dev); + + return 0; +} void dma_deconfigure(struct device *dev) { of_dma_deconfigure(dev); diff --git a/drivers/base/platform.c b/drivers/base/platform.c index f1bf7b3..d2d5891 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1130,6 +1130,11 @@ int platform_pm_restore(struct device *dev) #endif /* CONFIG_HIBERNATE_CALLBACKS */ +static int platform_dma_configure(struct device *dev) +{ + return dma_common_configure(dev); +} + static const struct dev_pm_ops platform_dev_pm_ops = { .runtime_suspend = pm_generic_runtime_suspend, .runtime_resume = pm_generic_runtime_resume, @@ -1141,6 +1146,7 @@ struct bus_type platform_bus_type = { .dev_groups = platform_dev_groups, .match = platform_match, .uevent = platform_uevent, + .dma_configure = platform_dma_configure, .pm = &platform_dev_pm_ops, .force_dma = true, }; diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c index 88a3558..fa9896d 100644 --- a/drivers/gpu/host1x/bus.c +++ b/drivers/gpu/host1x/bus.c @@ -314,6 +314,14 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv) return strcmp(dev_name(dev), drv->name) == 0; } +static int host1x_dma_configure(struct device *dev) +{ + if (dev->of_node) + return of_dma_configure(dev, dev->of_node); + + return 0; +} + static const struct dev_pm_ops host1x_device_pm_ops = { .suspend = pm_generic_suspend, .resume = pm_generic_resume, @@ -326,6 +334,7 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv) struct bus_type host1x_bus_type = { .name = "host1x", .match = host1x_device_match, + .dma_configure = host1x_dma_configure, .pm = &host1x_device_pm_ops, .force_dma = true, }; diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 3bed6be..b473a4c 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "pci.h" struct pci_dynid { @@ -1522,6 +1524,35 @@ static int pci_bus_num_vf(struct device *dev) return pci_num_vf(to_pci_dev(dev)); } +/** + * pci_dma_configure - Setup DMA configuration + * @dev: ptr to dev structure + * + * Function to update PCI devices's DMA configuration using the same + * info from the OF node or ACPI node of host bridge's parent (if any). + */ +static int pci_dma_configure(struct device *dev) +{ + struct device *bridge; + enum dev_dma_attr attr; + int ret = 0; + + bridge = pci_get_host_bridge_device(to_pci_dev(dev)); + + if (IS_ENABLED(CONFIG_OF) && bridge->parent && + bridge->parent->of_node) { + ret = of_dma_configure(dev, bridge->parent->of_node); + } else if (has_acpi_companion(bridge)) { + attr = acpi_get_dma_attr(to_acpi_device_node(bridge->fwnode)); + if (attr != DEV_DMA_NOT_SUPPORTED) + ret = acpi_dma_configure(dev, attr); + } + + pci_put_host_bridge_device(bridge); + + return ret; +} + struct bus_type pci_bus_type = { .name = "pci", .match = pci_bus_match, @@ -1534,6 +1565,7 @@ struct bus_type pci_bus_type = { .drv_groups = pci_drv_groups, .pm = PCI_PM_OPS_PTR, .num_vf = pci_bus_num_vf, + .dma_configure = pci_dma_configure, .force_dma = true, }; EXPORT_SYMBOL(pci_bus_type); diff --git a/include/linux/device.h b/include/linux/device.h index b093405..1832d90 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -88,6 +88,8 @@ extern int __must_check bus_create_file(struct bus_type *, * @resume: Called to bring a device on this bus out of sleep mode. * @num_vf: Called to find out how many virtual functions a device on this * bus supports. + * @dma_configure: Called to setup DMA configuration on a device on + this bus. * @pm: Power management operations of this bus, callback the specific * device driver's pm-ops. * @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU @@ -130,6 +132,8 @@ struct bus_type { int (*num_vf)(struct device *dev); + int (*dma_configure)(struct device *dev); + const struct dev_pm_ops *pm; const struct iommu_ops *iommu_ops; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index eb9eab4..c15986b 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -761,6 +761,7 @@ void *dma_mark_declared_memory_occupied(struct device *dev, } #endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ +int dma_common_configure(struct device *dev); #ifdef CONFIG_HAS_DMA int dma_configure(struct device *dev); void dma_deconfigure(struct device *dev);