From patchwork Fri Mar 30 07:54:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipun Gupta X-Patchwork-Id: 10317341 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 7A8B760383 for ; Fri, 30 Mar 2018 07:56:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FB662A466 for ; Fri, 30 Mar 2018 07:56:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63D4C2A55F; Fri, 30 Mar 2018 07:56:23 +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 8291B2A466 for ; Fri, 30 Mar 2018 07:56:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751336AbeC3H4F (ORCPT ); Fri, 30 Mar 2018 03:56:05 -0400 Received: from mail-he1eur01on0046.outbound.protection.outlook.com ([104.47.0.46]:52096 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750744AbeC3HzY (ORCPT ); Fri, 30 Mar 2018 03:55:24 -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=fuKntED4Nu4ZghQuM1On7+Ho+M17cXHxMSqmAwLabHU=; b=dvmcBiAPLrnci8aNwxjiAya8aofpN7viYWPADfFfvZpMeqPyA0T2RJKXPhKSR9N4S0Ud3zdyso7DsoB/1lDfKJl9AxNB4recRzjrw/0bANqxSd42hF4fC86ZmfKSwFGEUBVFMFjqrlatXfMYchG/NastXefGOHpvaY3T3evpTrQ= 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 HE1PR0401MB2426.eurprd04.prod.outlook.com (2603:10a6:3:25::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Fri, 30 Mar 2018 07:55:12 +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 v3 1/2] dma-mapping: move dma configuration to bus infrastructure Date: Fri, 30 Mar 2018 13:24:44 +0530 Message-Id: <1522396485-10248-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: PN1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:c::27) To HE1PR0401MB2426.eurprd04.prod.outlook.com (2603:10a6:3:25::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0b5aded5-a920-4a83-5e3d-08d59613948e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:HE1PR0401MB2426; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0401MB2426; 3:8hlZt9c8/o2yow6/iOHtuAgdHB+BCHKXIQEzIBjSJjIRmzQUWOQ4QXJRrm4euv2Bq4bRrB/mPaebYXq0cc018TrnikZlYnFUoLTsQH1LuDgQMKn+MdK8IGyL3CKEpjPewvjuQWgwXkdYvdoR2+0qms4fz45eBSx11EGj7MOLmrlCM5ryc4BY3876OCxjEdkNY5yLMwYYTCf7UZzWWBsa0pb40m7h8f/4SkrRS6sSYDWNndj8ejG4Gh5Y/qG8pg/+; 25:CEQJItzidc8d8Xobx1C/QkVCCuGPzJD+pKqiWzDdJKBQ++17TEFy8okVvHBNV8+FKqqnfjcyMMhU84NvRplClr2U1+a43APUfiOv5d8UfNpOGBwEmSk7YA0rXN2UXIUKZomdbLEeyTE8mCI55nfUDuLDXDDj0iLq0NNHVdH4NeynXALwO51h8dHu113vjGDrVR7a9jn+VebkSiYHcTtkYX06Bm0mjrPG5KvHEFJFH1eUvYP9rLMglI+xLAK85oxVR9QVihSxLClE/LRNFzhhGyPdMo68Aa2laBzZ1rMsFtR/jHfIVfRAO9ScRIwM4Nrp4u6ugdXOc93K+/M4vOIIwA==; 31:1kGbJC6LsnbD1Ajiyoy1jj+qO1VHDovSuq8rstI63aiMR2iFBFWe0l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ib2yUN+CRBxGpN462AD99DM1obRhc5BntehVYqy4Pg5+a1etHGcvvQo+9e63VI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6055026)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:HE1PR0401MB2426; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0401MB2426; X-Forefront-PRVS: 06274D1C43 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(346002)(39380400002)(396003)(366004)(376002)(199004)(189003)(68736007)(50466002)(86362001)(7416002)(6116002)(2906002)(16586007)(66066001)(305945005)(6666003)(7736002)(316002)(3846002)(48376002)(5009440100003)(97736004)(186003)(16526019)(486005)(6486002)(8676002)(6512007)(8936002)(50226002)(6306002)(81166006)(81156014)(476003)(956004)(486005)(2616005)(11346002)(53936002)(446003)(47776003)(5660300001)(106356001)(478600001)(25786009)(39060400002)(5890100001)(105586002)(6506007)(966005)(59450400001)(55236004)(386003)(4326008)(36756003)(76176011)(51416003)(26005)(52116002)(110426004)(357404004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0401MB2426; H:b27504-OptiPlex-790.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0401MB2426; 23:NgLA5ePcHB1nsSd7hGs01HStct584ZRe0LroXZf?= =?us-ascii?Q?v/DdmHr/N6xsRNo9/0snU7bF6zdIl/hjML9pkZtDzdYu6r2nytZAa75lU7Ta?= =?us-ascii?Q?XIlcKVBW28w0uI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bonRRykcWZS1dTkBQrgQCkoNFVSl4iQoEPcG5FAD1g1pRFrJW9oOhJfXqlYCR1sMwOa8ubiVpBMVymE7WGC5UCjh6nF9VpgHExTQgpqES+1LmHHUWNeJnHFraDIG2fFZQVZBDg2Tm6RbFPz5jzyIkc38f+BGem2PWjNxxJ183Rah6vnjuqqQNN2hUU+l88bQ==; 5:UejdSh4Qv+eJs3mN2E28wzeyMH/CnQ9N9TSLhYV5AT8zV4zybxMRzyiRReOCmErsCpJ7I5Ilo0pHB3ez4XWddmMAU0FPPJdn96GtliDLX3oNyzWk5h/01//8J8t6o0jbsfiwTtGSo2vvtNgvLBlhME5VN/dYnur3SjkQpEvBNlE=; 24:E1+tZEhOWonCdWD/dxBhkjKc9l6prpiHckCUVeoLkH/364dqDHEcJqcyvOnbHu8TRUAGpzd2xwOSiF58jj4fwGnP0jHFqgkWC1pOMRs27zk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0401MB2426; 7:1GjM96SQWVX6/YZDZ3/AegKyCBjz8vufaWqZjLp4GwfLyNqtSSJevYeV9BL8sf3RKyMDCFfK/RN4RCCYVJy/AUfXcl4Gs+2mNqMPWE0pUSiN8YHhXq07wLTIjXrRGl9obV9ud+dtP/wYrTj0OOHjIgKrAMVWmiShOXaWIfPSZfIVyLYsLW/JzRLfMb7fzN5G4dsHEbsM13nYVn5v6C+8AsOtyb5yycQeNG1iBOVJSBaIaTKgDYMZODimZ3NwYWUK X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2018 07:55:12.2290 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b5aded5-a920-4a83-5e3d-08d59613948e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0401MB2426 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 is 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 Acked-by: Bjorn Helgaas # PCI parts --- - 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 Changes in v3 - Move dma_common_configure() within platform_dma_configure() and reuse platofrm_dma_configure() for AMBA bus too - Declare 'attr' in pci_dma_configure() inside the else statement where it is used. drivers/amba/bus.c | 4 ++++ drivers/base/dma-mapping.c | 31 ++++--------------------------- drivers/base/platform.c | 17 +++++++++++++++++ drivers/gpu/host1x/bus.c | 8 ++++++++ drivers/pci/pci-driver.c | 32 ++++++++++++++++++++++++++++++++ include/linux/device.h | 4 ++++ include/linux/platform_device.h | 2 ++ 7 files changed, 71 insertions(+), 27 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 594c228..867dc2b 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -188,12 +189,15 @@ static int amba_pm_runtime_resume(struct device *dev) /* * Primecells are part of the Advanced Microcontroller Bus Architecture, * so we call the bus "amba". + * DMA configuration for platform and AMBA bus is same. So here we reuse + * platform's DMA config routine. */ struct bus_type amba_bustype = { .name = "amba", .dev_groups = amba_dev_groups, .match = amba_match, .uevent = amba_uevent, + .dma_configure = platform_dma_configure, .pm = &amba_pm, .force_dma = true, }; diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 3b11835..fdc1502 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -331,36 +331,13 @@ 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 + * enables DMA API use for a device */ -#include - int dma_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 (attr != DEV_DMA_NOT_SUPPORTED) - ret = acpi_dma_configure(dev, attr); - } - - if (bridge) - pci_put_host_bridge_device(bridge); - - return ret; + if (dev->bus->dma_configure) + return dev->bus->dma_configure(dev); + return 0; } void dma_deconfigure(struct device *dev) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index f1bf7b3..72fdbf6 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1130,6 +1130,22 @@ int platform_pm_restore(struct device *dev) #endif /* CONFIG_HIBERNATE_CALLBACKS */ +int platform_dma_configure(struct device *dev) +{ + enum dev_dma_attr attr; + int ret = 0; + + 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); + } + + return ret; +} + static const struct dev_pm_ops platform_dev_pm_ops = { .runtime_suspend = pm_generic_runtime_suspend, .runtime_resume = pm_generic_runtime_resume, @@ -1141,6 +1157,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..a9ec99d 100644 --- a/drivers/gpu/host1x/bus.c +++ b/drivers/gpu/host1x/bus.c @@ -314,6 +314,13 @@ 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 +333,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..78e507f 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; + 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)) { + struct acpi_device *adev = to_acpi_device_node(bridge->fwnode); + enum dev_dma_attr attr = acpi_get_dma_attr(adev); + + 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/platform_device.h b/include/linux/platform_device.h index 49f634d..3097c94 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -356,6 +356,8 @@ static inline char *early_platform_driver_setup_func(void) \ #define platform_pm_restore NULL #endif +extern int platform_dma_configure(struct device *dev); + #ifdef CONFIG_PM_SLEEP #define USE_PLATFORM_PM_SLEEP_OPS \ .suspend = platform_pm_suspend, \