From patchwork Mon Mar 12 15:24:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nipun Gupta X-Patchwork-Id: 10276597 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 CCA426038F for ; Mon, 12 Mar 2018 15:25:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCCF623F88 for ; Mon, 12 Mar 2018 15:25:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0CCB286B5; Mon, 12 Mar 2018 15:25:21 +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=ham 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 A8EB927F17 for ; Mon, 12 Mar 2018 15:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751483AbeCLPZT (ORCPT ); Mon, 12 Mar 2018 11:25:19 -0400 Received: from mail-he1eur01on0062.outbound.protection.outlook.com ([104.47.0.62]:63680 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751248AbeCLPZR (ORCPT ); Mon, 12 Mar 2018 11:25:17 -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=lcoZnY2sUtS/7tlN9o+x9F4UY5IhIAo8YJphpCYvyWs=; b=RTMWS2Us+ivz+A/4OfNZY32fOm0/8H94dJeAiOAcedjCQMBaDWDvGIAcEQB7yAWNd7VPp77LvvAqDrgS2yTojIBNFcrAWy59HQ0E1SzXloRFYh8EBpieFsWleuCiI5Hav72rtzm40++qJ3tgJHi4XSGuzEiK5Mdyt8dqjRia5Js= 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 HE1PR0401MB2428.eurprd04.prod.outlook.com (2603:10a6:3:25::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.548.13; Mon, 12 Mar 2018 15:25:10 +0000 From: Nipun Gupta To: hch@lst.de, robin.murphy@arm.com, linux@armlinux.org.uk, gregkh@linuxfoundation.org, m.szyprowski@samsung.com, bhelgaas@google.com Cc: dmitry.torokhov@gmail.com, rafael.j.wysocki@intel.com, jarkko.sakkinen@linux.intel.com, linus.walleij@linaro.org, johan@kernel.org, msuchanek@suse.de, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, Nipun Gupta Subject: [PATCH] dma-mapping: move dma configuration to bus infrastructure Date: Mon, 12 Mar 2018 20:54:52 +0530 Message-Id: <1520868292-2479-1-git-send-email-nipun.gupta@nxp.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: BMXPR01CA0034.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:c::20) To HE1PR0401MB2428.eurprd04.prod.outlook.com (2603:10a6:3:25::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31707004-1d6c-427a-cab6-08d5882d7389 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:HE1PR0401MB2428; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0401MB2428; 3:sZxwBqaR+fo3EN83ufy0hE0MIXdMXJ20gCIMgu0SdVHRLmFFg/xK6prc1pYZyjfQs5fkhg9QyA4Xg33epJHcDh1yldOWU+uvgazZVnOnQ6rVt2LqxY3Yp3G+u19uCk/PPUBg2RoowcROav51Yhg7u3hvY/ZxP4jB5Ei8j6mXJdAe57Pysxs/OFNuP4THeBtTH4zOlb8HYhjd3hNTStF9Znt9ERO2ttcEqDR22xMmBtoWWbj6wU5U5H10KLW8fAu8; 25:LB4PABMhTiGkxaf8izhp5x/xCiPp1ByoNU59CnDsebary9BgiVPdVHYzJldpIJHn23F4gDd74ALVzjFv7fRH2K/sEX6bPWqVBXcfldg4TMZOMatut/X/UtT2DcBf9Y7fRTeIQXrq3ps9DgzNxNeFCUt2qGHqNwh6RXViumpVyJ+e9x0tVsB3GkNBdmFkEJylbUGv4NmyybHVxNAOkp9xFufC+8KhOMngkKVEKYVo+ITwkjeTJzEyKEuNpo0R66MkhPSFGXe6nUR3M63yYycYw7K/apN4uLCCx9aCay4UjqlLBMVhHWV5t7mSglSadDgCfKc4UqZa5thQRE21Cl6esw==; 31:WFY/2I/LlYcF4/6dow6gD+HyOJ3Z5WKpVQHuIWukIIeZknloXexX4JmWJRnmGesoVtsoP2sGiV1y58TDe6qhygEO2aYcZoWxMQhHic21e7fDBrHIPmwC+jnUHiScVk8j0QHJzWRVW4PaTZ9JzYnlRDFSQEXf6pGQ1kOrL8luOVc7lebD2eOJxOOswZRqEkn2wD0SSDS+wJ7aeghNLX63lcG7KMAEDArcEL0d+E7Uma0= X-MS-TrafficTypeDiagnostic: HE1PR0401MB2428: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0401MB2428; 20:at5xJuRX4NtqG1bgMame2xz1OFxvd4WfAKYg3woFGxy+DMeR/sQO8s6aORH+qYXalnC6rtECFGxr3xCbo2y1c66lYRGGsmr79sR4tdTGQ5Jy2wNlY+SlAwjoBze2NpXXz4teGEskhrmXsdAlYd9RDRvnYsOQmsbepgjeFpuQ0r+jv0lqANAU/7aODF/WqxmHA8CBaZL8XfcY8B7vH03UaV4TiR54dhial+oe+oVbKLMIRAK1PRMiEWSFJhsbYxHvY0/XH9joFPQSd7pgVmjrhEmxu7HeO3ulq/DSP8P3io5tFBK58vPJacGOHZvlVrKxNYwluMN9BXkmp2+9PDKslgJPgr7do+mLxp4kzwhfcQzcuaBwONK9oLHqvmsFJW35ht/SBtBIRix4jQigr4+9abBB36au6CZyuGvLZuLqVqZ5tQaWEDtyvmpapHcT1idb/HZ1EaNpdS6OWo1a0PuvoJa9UFYlk8UG6EKEbvht6Lkkwoby7+rzR1QswnorXpcD; 4:XI+9a4NSvxsMD98Dh24+8ClJNco5PB+S+OHDino6E5kJtAxHTsWusbuucihNu7GO0b7kTStxo2LeISPaGLYbSf8k95lzNmvjMP/Owo8W3EJdLASlkAS6uCUatf2UIxLL8z7iY5wIlWP7CqeIxiNvsC7lMIcHRjLyrh8lpz3z62jLhvWXwikUC2gZlgHI62Id81CzY57nAeqI+nYvJ13JSuQi5CVpNxQcOCTFb3akEAQvIkBLEETj9p1e/c+naQN9rjODshbJDrlkwwf3tfuiRAV1gK4y/YoK6PyQ9JHyWsjEVYLybclGcbn022uG03oo 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)(3002001)(3231220)(944501244)(52105095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:HE1PR0401MB2428; BCL:0; PCL:0; RULEID:; SRVR:HE1PR0401MB2428; X-Forefront-PRVS: 06098A2863 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(39380400002)(366004)(396003)(376002)(199004)(189003)(86362001)(386003)(6666003)(4326008)(55236004)(26005)(2906002)(16526019)(186003)(25786009)(97736004)(106356001)(316002)(39060400002)(5009440100003)(16586007)(6506007)(52116002)(1857600001)(51416003)(53936002)(36756003)(47776003)(66066001)(68736007)(105586002)(50226002)(50466002)(8936002)(81166006)(48376002)(6306002)(6512007)(81156014)(3846002)(7736002)(6486002)(7416002)(8676002)(966005)(5660300001)(5890100001)(6116002)(305945005)(59450400001)(478600001)(110426004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0401MB2428; H:b27504-OptiPlex-790.ap.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; HE1PR0401MB2428; 23:VvMUnDa5n+wvjl9mScL8MXh91v7Uze25KiISO1t?= =?us-ascii?Q?Dh7PUIXWQXDTISnpV/XJXfAPEf5HrPN8GwD+fQluc635b4zpg/Z/t5JOY6UQ?= =?us-ascii?Q?MeZJ72waTmBUkOaxlkMdViPtNjYS4j0EyA7ktLF3V3gzIEtuhgT5eZB23MYf?= =?us-ascii?Q?9kXxxh5ndTMXDaOXE2NK7FSStR3QSKvTFySDsj7tt5b3X4VdNHIu0+j7lci0?= =?us-ascii?Q?J0jepxB27Vfn01Vrv+SczJhzp36bv5mC32VP34AemIEupWDpl3nkUsNBeZye?= =?us-ascii?Q?HWd7KPZ4xhSxOVRdRAUsq0/OokvTHnRVzZLeC4hZi2TMrh3wUzVliB6oxSeE?= =?us-ascii?Q?ifw0Eaq1JZSKHjo3a14d/A2uGdF/ojauCfVAMBkt6e9L3pdbM+aVxVuykF0W?= =?us-ascii?Q?Un2Wdsuy41kNTw9HRO/2rixDgQf9xNWJxeeJFHhp+jpN9tZ0KRUg4ectGOmL?= =?us-ascii?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Uuoy2TbU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2018 15:25:10.4702 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31707004-1d6c-427a-cab6-08d5882d7389 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0401MB2428 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 The change introduces 'dma_configure' & 'dma_deconfigure'as bus callback functions so each bus can choose to implement its own dma configuration function. This eases the addition of new busses w.r.t. adding the dma configuration functionality. The change also updates the PCI, Platform and ACPI bus to use new introduced callbacks. Signed-off-by: Nipun Gupta --- - This patch is based on the comments on: https://patchwork.kernel.org/patch/10259087/ - I have validated for PCI and platform, but not for AMBA as I do not have infrastructure to validate it. Can anyone please validate them on AMBA? drivers/amba/bus.c | 38 ++++++++++++++++++++++++----- drivers/base/dd.c | 14 +++++++---- drivers/base/dma-mapping.c | 41 ------------------------------- drivers/base/platform.c | 36 ++++++++++++++++++++++----- drivers/pci/pci-driver.c | 59 ++++++++++++++++++++++++++++++++++++--------- include/linux/device.h | 6 +++++ include/linux/dma-mapping.h | 12 --------- 7 files changed, 124 insertions(+), 82 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 594c228..58241d2 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include @@ -171,6 +173,28 @@ static int amba_pm_runtime_resume(struct device *dev) } #endif /* CONFIG_PM */ +int amba_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; +} + +void amba_dma_deconfigure(struct device *dev) +{ + of_dma_deconfigure(dev); + acpi_dma_deconfigure(dev); +} + static const struct dev_pm_ops amba_pm = { .suspend = pm_generic_suspend, .resume = pm_generic_resume, @@ -190,12 +214,14 @@ static int amba_pm_runtime_resume(struct device *dev) * so we call the bus "amba". */ struct bus_type amba_bustype = { - .name = "amba", - .dev_groups = amba_dev_groups, - .match = amba_match, - .uevent = amba_uevent, - .pm = &amba_pm, - .force_dma = true, + .name = "amba", + .dev_groups = amba_dev_groups, + .match = amba_match, + .uevent = amba_uevent, + .pm = &amba_pm, + .dma_configure = amba_dma_configure, + .dma_deconfigure = amba_dma_deconfigure, + .force_dma = true, }; static int __init amba_init(void) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index de6fd09..f124f3f 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -421,9 +421,11 @@ static int really_probe(struct device *dev, struct device_driver *drv) if (ret) goto pinctrl_bind_failed; - ret = dma_configure(dev); - if (ret) - goto dma_failed; + if (dev->bus->dma_configure) { + ret = dev->bus->dma_configure(dev); + if (ret) + goto dma_failed; + } if (driver_sysfs_add(dev)) { printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", @@ -486,7 +488,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) goto done; probe_failed: - dma_deconfigure(dev); + if (dev->bus->dma_deconfigure) + dev->bus->dma_deconfigure(dev); dma_failed: if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, @@ -895,7 +898,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) drv->remove(dev); device_links_driver_cleanup(dev); - dma_deconfigure(dev); + if (dev->bus->dma_deconfigure) + dev->bus->dma_deconfigure(dev); devres_release_all(dev); dev->driver = NULL; diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 3b11835..f16bd49 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -6,11 +6,9 @@ * Copyright (c) 2006 Tejun Heo */ -#include #include #include #include -#include #include #include @@ -329,42 +327,3 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags) vunmap(cpu_addr); } #endif - -/* - * Common configuration to enable 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; -} - -void dma_deconfigure(struct device *dev) -{ - of_dma_deconfigure(dev); - acpi_dma_deconfigure(dev); -} diff --git a/drivers/base/platform.c b/drivers/base/platform.c index f1bf7b3..adf94eb 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1130,6 +1130,28 @@ 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; +} + +void platform_dma_deconfigure(struct device *dev) +{ + of_dma_deconfigure(dev); + acpi_dma_deconfigure(dev); +} + static const struct dev_pm_ops platform_dev_pm_ops = { .runtime_suspend = pm_generic_runtime_suspend, .runtime_resume = pm_generic_runtime_resume, @@ -1137,12 +1159,14 @@ int platform_pm_restore(struct device *dev) }; struct bus_type platform_bus_type = { - .name = "platform", - .dev_groups = platform_dev_groups, - .match = platform_match, - .uevent = platform_uevent, - .pm = &platform_dev_pm_ops, - .force_dma = true, + .name = "platform", + .dev_groups = platform_dev_groups, + .match = platform_match, + .uevent = platform_uevent, + .pm = &platform_dev_pm_ops, + .dma_configure = platform_dma_configure, + .dma_deconfigure = platform_dma_deconfigure, + .force_dma = true, }; EXPORT_SYMBOL_GPL(platform_bus_type); diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 3bed6be..4a77814 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,19 +1524,52 @@ static int pci_bus_num_vf(struct device *dev) return pci_num_vf(to_pci_dev(dev)); } +int pci_dma_configure(struct device *dev) +{ + struct device *bridge, *dma_dev; + enum dev_dma_attr attr; + int ret = 0; + + 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); + } + + pci_put_host_bridge_device(bridge); + + return ret; +} + +void pci_dma_deconfigure(struct device *dev) +{ + of_dma_deconfigure(dev); + acpi_dma_deconfigure(dev); +} + struct bus_type pci_bus_type = { - .name = "pci", - .match = pci_bus_match, - .uevent = pci_uevent, - .probe = pci_device_probe, - .remove = pci_device_remove, - .shutdown = pci_device_shutdown, - .dev_groups = pci_dev_groups, - .bus_groups = pci_bus_groups, - .drv_groups = pci_drv_groups, - .pm = PCI_PM_OPS_PTR, - .num_vf = pci_bus_num_vf, - .force_dma = true, + .name = "pci", + .match = pci_bus_match, + .uevent = pci_uevent, + .probe = pci_device_probe, + .remove = pci_device_remove, + .shutdown = pci_device_shutdown, + .dev_groups = pci_dev_groups, + .bus_groups = pci_bus_groups, + .drv_groups = pci_drv_groups, + .pm = PCI_PM_OPS_PTR, + .num_vf = pci_bus_num_vf, + .dma_configure = pci_dma_configure, + .dma_deconfigure = pci_dma_deconfigure, + .force_dma = true, }; EXPORT_SYMBOL(pci_bus_type); diff --git a/include/linux/device.h b/include/linux/device.h index b093405..9b2dcf6 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -88,6 +88,9 @@ 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. + * @dma_deconfigure: Called to tear down the DMA configuration. * @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 +133,9 @@ struct bus_type { int (*num_vf)(struct device *dev); + int (*dma_configure)(struct device *dev); + void (*dma_deconfigure)(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..039224b 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -761,18 +761,6 @@ void *dma_mark_declared_memory_occupied(struct device *dev, } #endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */ -#ifdef CONFIG_HAS_DMA -int dma_configure(struct device *dev); -void dma_deconfigure(struct device *dev); -#else -static inline int dma_configure(struct device *dev) -{ - return 0; -} - -static inline void dma_deconfigure(struct device *dev) {} -#endif - /* * Managed DMA API */