From: John Feeney <jfeeney@redhat.com> Date: Tue, 21 Apr 2009 19:02:36 -0400 Subject: [misc] I/O AT: new dmaengine_v3.c Message-id: 49EE508C.4020307@redhat.com O-Subject: [RHEL5.4 PATCH 6/8] Update I/O AT: new dmaengine_v3.c Bugzilla: 436048 RH-Acked-by: Prarit Bhargava <prarit@redhat.com> RH-Acked-by: John W. Linville <linville@redhat.com> bz436048 Update I/O AT code to upstream This patch adds Kconfig, Makefile and dmaengine_v3.c in drivers/dma_v3. Kconfig | 34 +++ Makefile | 4 dmaengine_v3.c | 634 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 672 insertions(+) The commits to each file and any modifications are listed below. Note: upstream commits come from drivers/dma but patch adds files to the new directory, drivers/dma_v3. drivers/dma_v3/Kconfig Same as these commits with exception of adding "_V3" or "version 3" to comments in order to differentiate with dma/Kconfig: c13c8260da3155f2cefb63b0d1b7dcdcb405c644 Leech 5/24/06 0bbd5f4e97ff9c057b385a1886b4aed1fb0300f1 Leech 5/24/06 db21733488f84a596faaad0d05430b3f51804692 Leech 6/18/06 drivers/dma_v3/Makefile Same as commits below but files that are already in drivers/dma have "_v3" suffix added to help differentiate and "_V3" added to CONFIG_* names. c13c8260da3155f2cefb63b0d1b7dcdcb405c644 Leech 5/24/06 0bbd5f4e97ff9c057b385a1886b4aed1fb0300f1 Leech 6/18/06 de5506e155276d385712c2aa1c2d9a27cd4ed947 Leech 6/18/06 1fda5f4e96225c3ed0baded942704c0ae399da23 Nelson 10/16/07 8ab89567da0cea9bae2c1b5dad47b51c424479e4 Nelson 10/16/07 2ed6dc34f9ed39bb8e4c81ea1056f0ba56315841 Nelson 10/16/07 drivers/dma_v3/dmaengine_3.c In order to differentiate from existing, the new dmaengine is named "dmaengine_v3.c". The commits found below make up this file with the following exceptions: All EXPORT function names have the "_v3" suffix (dma_sync_wait_v3(), dma_chan_cleanup_v3(), dma_async_client_register_v3(), dma_async_client_unregister_v3(), dma_async_client_chan_request_v3(), dma_async_device_register_v3(), dma_async_device_unregister_v3(), dma_async_memcpy_buf_to_buf_v3(), dma_async_memcpy_buf_to_pg_v3(), dma_async_memcpy_pg_to_pg_v3(), and dma_async_tx_descriptor_init_v3(). #ifndef __GENKSYMS__ added around linux/mm.h and linux/jiffies.h to prevent kabi errors in Brew .name in dma_devclass has "_v3" suffix All references to dma_device changed to dma_device_v3 All references to chan->device changed to chan->device_v3 All references to client->event_callback changed to client->event_callback_v3 Use DMA_STATE_RESOURCE_AVAILABLE and DMA_STATE_RESOURCE_REMOVED instead of DMA_RESOURCE_AVAILABLE and DMA_RESOURCE_REMOVED c13c8260da3155f2cefb63b0d1b7dcdcb405c644 Leech 5/24/06 17f3ae08b6e7fd778371f2cafbd1c988a67ee343 Morton 5/25/06 6508871eddbbd3e62799f3b6182a6a4fd3ef31d5 Dunlop 7/4/06 765e3d8a71bbc1f3400667d5cfcfd7b03382d587 Brownell 3/16/07 ff487fb773749124550a5ad2b7fbfe0376af6f0d Garzik 7/11/07 7405f74badf46b5d023c5d2b670b4471525f6c91 Williams 07/13/07 d379b01e9087a582d58f4b678208a4f8d8376fe7 Williams 7/13/07 348badf1e825323c419dd118f65783db0f7d2ec8 Skinnemoen 11/15/07 0036731c88fdb5bf4f04a796a30b5e445fc57f54 Williams 2/6/08 9b941c6660bae673e27c207f1d20d98ef8ecd450 Zhang 3/13/08 19242d7233df7d658405d4b7ee1758d21414cfaa Wiliams 4/17/08 ce4d65a5db77e1568c82d5151a746f627c4f6ed5 Williams 4/17/08 636bdeaa1243327501edfd2a597ed7443eb4239a Williams 4/17/08 8a5703f846e2363fc466aff3f53608340a1ae33f Siewior 4/21/08 7cc5bf9a3a84e5a02e23e5739fb894790b37c101 Williams 7/8/08 848c536a37b8db4e461f14ca15fe29850151c822 Williams 7/8/08 dc0ee6435cb92ccc81b14ff28d163fecc5a7f120 Skinnemoen 7/8/08 Note: The entire of the RHEL-5 source tree was checked to make sure the "_v3" EXPORTed functions replaced the existing functions, outside of the drivers/dma directory. diff --git a/drivers/dma_v3/Kconfig b/drivers/dma_v3/Kconfig new file mode 100644 index 0000000..bfd2c11 --- /dev/null +++ b/drivers/dma_v3/Kconfig @@ -0,0 +1,34 @@ +# +# DMA engine configuration +# + +menu "DMA Engine support version 3" + +config DMA_ENGINE_V3 + bool "Support for DMA engines version 3" + ---help--- + DMA engines offload copy operations from the CPU to dedicated + hardware, allowing the copies to happen asynchronously. + +comment "DMA Clients V3" + +config NET_DMA + bool "Network: TCP receive copy offload" + depends on DMA_ENGINE_V3 && NET + default y + ---help--- + This enables the use of DMA engines in the network stack to + offload receive copy-to-user operations, freeing CPU cycles. + Since this is the main user of the DMA engine, it should be enabled; + say Y here. + +comment "DMA Devices" + +config INTEL_IOATDMA_V3 + tristate "Intel I/OAT DMA support version 3" + depends on DMA_ENGINE_V3 && PCI + default m + ---help--- + Enable version 3 support for the Intel(R) I/OAT DMA engine. + +endmenu diff --git a/drivers/dma_v3/Makefile b/drivers/dma_v3/Makefile new file mode 100644 index 0000000..ada56b1 --- /dev/null +++ b/drivers/dma_v3/Makefile @@ -0,0 +1,4 @@ +obj-$(CONFIG_DMA_ENGINE_V3) += dmaengine_v3.o +obj-$(CONFIG_NET_DMA) += iovlock_v3.o +obj-$(CONFIG_INTEL_IOATDMA_V3) += ioatdma_v3.o +ioatdma_v3-objs := ioat.o ioat_dma.o ioat_dca.o diff --git a/drivers/dma_v3/dmaengine_v3.c b/drivers/dma_v3/dmaengine_v3.c new file mode 100644 index 0000000..04db9a2 --- /dev/null +++ b/drivers/dma_v3/dmaengine_v3.c @@ -0,0 +1,634 @@ +/* + * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The full GNU General Public License is included in this distribution in the + * file called COPYING. + */ + +/* + * This code implements the DMA subsystem. It provides a HW-neutral interface + * for other kernel code to use asynchronous memory copy capabilities, + * if present, and allows different HW DMA drivers to register as providing + * this capability. + * + * Due to the fact we are accelerating what is already a relatively fast + * operation, the code goes to great lengths to avoid additional overhead, + * such as locking. + * + * LOCKING: + * + * The subsystem keeps two global lists, dma_device_list and dma_client_list. + * Both of these are protected by a mutex, dma_list_mutex. + * + * Each device has a channels list, which runs unlocked but is never modified + * once the device is registered, it's just setup by the driver. + * + * Each client is responsible for keeping track of the channels it uses. See + * the definition of dma_event_callback in dmaengine.h. + * + * Each device has a kref, which is initialized to 1 when the device is + * registered. A kref_get is done for each class_device registered. When the + * class_device is released, the corresponding kref_put is done in the release + * method. Every time one of the device's channels is allocated to a client, + * a kref_get occurs. When the channel is freed, the corresponding kref_put + * happens. The device's release function does a completion, so + * unregister_device does a remove event, class_device_unregister, a kref_put + * for the first reference, then waits on the completion for all other + * references to finish. + * + * Each channel has an open-coded implementation of Rusty Russell's "bigref," + * with a kref and a per_cpu local_t. A dma_chan_get is called when a client + * signals that it wants to use a channel, and dma_chan_put is called when + * a channel is removed or a client using it is unregistered. A client can + * take extra references per outstanding transaction, as is the case with + * the NET DMA client. The release function does a kref_put on the device. + * -ChrisL, DanW + */ + +#include <linux/init.h> +#include <linux/module.h> +#ifndef __GENKSYMS__ +#include <linux/mm.h> +#endif +#include <linux/device.h> +#include <linux/dmaengine.h> +#include <linux/hardirq.h> +#include <linux/spinlock.h> +#include <linux/percpu.h> +#include <linux/rcupdate.h> +#include <linux/mutex.h> +#ifndef __GENKSYMS__ +#include <linux/jiffies.h> +#endif + +static DEFINE_MUTEX(dma_list_mutex); +static LIST_HEAD(dma_device_list); +static LIST_HEAD(dma_client_list); + +/* --- sysfs implementation --- */ + +static ssize_t show_memcpy_count(struct class_device *cd, char *buf) +{ + struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); + unsigned long count = 0; + int i; + + for_each_possible_cpu(i) + count += per_cpu_ptr(chan->local, i)->memcpy_count; + + return sprintf(buf, "%lu\n", count); +} + +static ssize_t show_bytes_transferred(struct class_device *cd, char *buf) +{ + struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); + unsigned long count = 0; + int i; + + for_each_possible_cpu(i) + count += per_cpu_ptr(chan->local, i)->bytes_transferred; + + return sprintf(buf, "%lu\n", count); +} + +static ssize_t show_in_use(struct class_device *cd, char *buf) +{ + struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); + int in_use = 0; + + if (unlikely(chan->slow_ref) && + atomic_read(&chan->refcount.refcount) > 1) + in_use = 1; + else { + if (local_read(&(per_cpu_ptr(chan->local, + get_cpu())->refcount)) > 0) + in_use = 1; + put_cpu(); + } + + return sprintf(buf, "%d\n", in_use); +} + +static struct class_device_attribute dma_class_attrs[] = { + __ATTR(memcpy_count, S_IRUGO, show_memcpy_count, NULL), + __ATTR(bytes_transferred, S_IRUGO, show_bytes_transferred, NULL), + __ATTR(in_use, S_IRUGO, show_in_use, NULL), + __ATTR_NULL +}; + +static void dma_async_device_cleanup(struct kref *kref); + +static void dma_class_dev_release(struct class_device *cd) +{ + struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev); + kref_put(&chan->device_v3->refcount, dma_async_device_cleanup); +} + +static struct class dma_devclass = { + .name = "dma_v3", + .class_dev_attrs = dma_class_attrs, + .release = dma_class_dev_release, +}; + +/* --- client and device registration --- */ + +#define dma_chan_satisfies_mask(chan, mask) \ + __dma_chan_satisfies_mask((chan), &(mask)) +static int +__dma_chan_satisfies_mask(struct dma_chan *chan, dma_cap_mask_t *want) +{ + dma_cap_mask_t has; + + bitmap_and(has.bits, want->bits, chan->device_v3->cap_mask.bits, + DMA_TX_TYPE_END); + return bitmap_equal(want->bits, has.bits, DMA_TX_TYPE_END); +} + +/** + * dma_client_chan_alloc - try to allocate channels to a client + * @client: &dma_client + * + * Called with dma_list_mutex held. + */ +static void dma_client_chan_alloc(struct dma_client *client) +{ + struct dma_device_v3 *device; + struct dma_chan *chan; + int desc; /* allocated descriptor count */ + enum dma_state_client ack; + + /* Find a channel */ + list_for_each_entry(device, &dma_device_list, global_node) { + /* Does the client require a specific DMA controller? */ + if (client->slave && client->slave->dma_dev + && client->slave->dma_dev != device->dev) + continue; + + list_for_each_entry(chan, &device->channels, device_node) { + if (!dma_chan_satisfies_mask(chan, client->cap_mask)) + continue; + + desc = chan->device_v3->device_alloc_chan_resources( + chan, client); + if (desc >= 0) { + ack = client->event_callback_v3(client, + chan, + DMA_STATE_RESOURCE_AVAILABLE); + + /* we are done once this client rejects + * an available resource + */ + if (ack == DMA_ACK) { + dma_chan_get(chan); + chan->client_count++; + } else if (ack == DMA_NAK) + return; + } + } + } +} + +enum dma_status dma_sync_wait_v3(struct dma_chan *chan, dma_cookie_t cookie) +{ + enum dma_status status; + unsigned long dma_sync_wait_timeout = jiffies + msecs_to_jiffies(5000); + + dma_async_issue_pending(chan); + do { + status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); + if (time_after_eq(jiffies, dma_sync_wait_timeout)) { + printk(KERN_ERR "dma_sync_wait_timeout!\n"); + return DMA_ERROR; + } + } while (status == DMA_IN_PROGRESS); + + return status; +} +EXPORT_SYMBOL(dma_sync_wait_v3); + +/** + * dma_chan_cleanup_v3 - release a DMA channel's resources + * @kref: kernel reference structure that contains the DMA channel device + */ +void dma_chan_cleanup_v3(struct kref *kref) +{ + struct dma_chan *chan = container_of(kref, struct dma_chan, refcount); + chan->device_v3->device_free_chan_resources(chan); + kref_put(&chan->device_v3->refcount, dma_async_device_cleanup); +} +EXPORT_SYMBOL(dma_chan_cleanup_v3); + +static void dma_chan_free_rcu(struct rcu_head *rcu) +{ + struct dma_chan *chan = container_of(rcu, struct dma_chan, rcu); + int bias = 0x7FFFFFFF; + int i; + for_each_possible_cpu(i) + bias -= local_read(&per_cpu_ptr(chan->local, i)->refcount); + atomic_sub(bias, &chan->refcount.refcount); + kref_put(&chan->refcount, dma_chan_cleanup_v3); +} + +static void dma_chan_release(struct dma_chan *chan) +{ + atomic_add(0x7FFFFFFF, &chan->refcount.refcount); + chan->slow_ref = 1; + call_rcu(&chan->rcu, dma_chan_free_rcu); +} + +/** + * dma_chans_notify_available - broadcast available channels to the clients + */ +static void dma_clients_notify_available(void) +{ + struct dma_client *client; + + mutex_lock(&dma_list_mutex); + + list_for_each_entry(client, &dma_client_list, global_node) + dma_client_chan_alloc(client); + + mutex_unlock(&dma_list_mutex); +} + +/** + * dma_chans_notify_available - tell the clients that a channel is going away + * @chan: channel on its way out + */ +static void dma_clients_notify_removed(struct dma_chan *chan) +{ + struct dma_client *client; + enum dma_state_client ack; + + mutex_lock(&dma_list_mutex); + + list_for_each_entry(client, &dma_client_list, global_node) { + ack = client->event_callback_v3(client, chan, + DMA_STATE_RESOURCE_REMOVED); + + /* client was holding resources for this channel so + * free it + */ + if (ack == DMA_ACK) { + dma_chan_put(chan); + chan->client_count--; + } + } + + mutex_unlock(&dma_list_mutex); +} + +/** + * dma_async_client_register_v3 - register a &dma_client + * @client: ptr to a client structure with valid 'event_callback' and 'cap_mask' + */ +void dma_async_client_register_v3(struct dma_client *client) +{ + /* validate client data */ + BUG_ON(dma_has_cap(DMA_SLAVE, client->cap_mask) && + !client->slave); + + mutex_lock(&dma_list_mutex); + list_add_tail(&client->global_node, &dma_client_list); + mutex_unlock(&dma_list_mutex); +} +EXPORT_SYMBOL(dma_async_client_register_v3); + +/** + * dma_async_client_unregister_v3 - unregister a client and free the &dma_client + * @client: &dma_client to free + * + * Force frees any allocated DMA channels, frees the &dma_client memory + */ +void dma_async_client_unregister_v3(struct dma_client *client) +{ + struct dma_device_v3 *device; + struct dma_chan *chan; + enum dma_state_client ack; + + if (!client) + return; + + mutex_lock(&dma_list_mutex); + /* free all channels the client is holding */ + list_for_each_entry(device, &dma_device_list, global_node) + list_for_each_entry(chan, &device->channels, device_node) { + ack = client->event_callback_v3(client, chan, + DMA_STATE_RESOURCE_REMOVED); + + if (ack == DMA_ACK) { + dma_chan_put(chan); + chan->client_count--; + } + } + + list_del(&client->global_node); + mutex_unlock(&dma_list_mutex); +} +EXPORT_SYMBOL(dma_async_client_unregister_v3); + +/** + * dma_async_client_chan_request_v3 - send all available channels to the + * client that satisfy the capability mask + * @client - requester + */ +void dma_async_client_chan_request_v3(struct dma_client *client) +{ + mutex_lock(&dma_list_mutex); + dma_client_chan_alloc(client); + mutex_unlock(&dma_list_mutex); +} +EXPORT_SYMBOL(dma_async_client_chan_request_v3); + +/** + * dma_async_device_register_v3 - registers DMA devices found + * @device: &dma_device_v3 + */ +int dma_async_device_register_v3(struct dma_device_v3 *device) +{ + static int id; + int chancnt = 0, rc; + struct dma_chan* chan; + + if (!device) + return -ENODEV; + + /* validate device routines */ + BUG_ON(dma_has_cap(DMA_MEMCPY, device->cap_mask) && + !device->device_prep_dma_memcpy); + BUG_ON(dma_has_cap(DMA_XOR, device->cap_mask) && + !device->device_prep_dma_xor); + BUG_ON(dma_has_cap(DMA_ZERO_SUM, device->cap_mask) && + !device->device_prep_dma_zero_sum); + BUG_ON(dma_has_cap(DMA_MEMSET, device->cap_mask) && + !device->device_prep_dma_memset); + BUG_ON(dma_has_cap(DMA_INTERRUPT, device->cap_mask) && + !device->device_prep_dma_interrupt); + BUG_ON(dma_has_cap(DMA_SLAVE, device->cap_mask) && + !device->device_prep_slave_sg); + BUG_ON(dma_has_cap(DMA_SLAVE, device->cap_mask) && + !device->device_terminate_all); + + BUG_ON(!device->device_alloc_chan_resources); + BUG_ON(!device->device_free_chan_resources); + BUG_ON(!device->device_is_tx_complete); + BUG_ON(!device->device_issue_pending); + BUG_ON(!device->dev); + + init_completion(&device->done); + kref_init(&device->refcount); + device->dev_id = id++; + + /* represent channels in sysfs. Probably want devs too */ + list_for_each_entry(chan, &device->channels, device_node) { + chan->local = alloc_percpu(typeof(*chan->local)); + if (chan->local == NULL) + continue; + + chan->chan_id = chancnt++; + chan->class_dev.class = &dma_devclass; + chan->class_dev.dev = NULL; + snprintf(chan->class_dev.class_id, BUS_ID_SIZE, "dma%dchan%d", + device->dev_id, chan->chan_id); + + rc = class_device_register(&chan->class_dev); + if (rc) { + chancnt--; + free_percpu(chan->local); + chan->local = NULL; + goto err_out; + } + + /* One for the channel, one of the class device */ + kref_get(&device->refcount); + kref_get(&device->refcount); + kref_init(&chan->refcount); + chan->client_count = 0; + chan->slow_ref = 0; + INIT_RCU_HEAD(&chan->rcu); + } + + mutex_lock(&dma_list_mutex); + list_add_tail(&device->global_node, &dma_device_list); + mutex_unlock(&dma_list_mutex); + + dma_clients_notify_available(); + + return 0; + +err_out: + list_for_each_entry(chan, &device->channels, device_node) { + if (chan->local == NULL) + continue; + kref_put(&device->refcount, dma_async_device_cleanup); + class_device_unregister(&chan->class_dev); + chancnt--; + free_percpu(chan->local); + } + return rc; +} +EXPORT_SYMBOL(dma_async_device_register_v3); + +/** + * dma_async_device_cleanup - function called when all references are released + * @kref: kernel reference object + */ +static void dma_async_device_cleanup(struct kref *kref) +{ + struct dma_device_v3 *device; + + device = container_of(kref, struct dma_device_v3, refcount); + complete(&device->done); +} + +/** + * dma_async_device_unregister_v3 - unregisters DMA devices + * @device: &dma_device + */ +void dma_async_device_unregister_v3(struct dma_device_v3 *device) +{ + struct dma_chan *chan; + + mutex_lock(&dma_list_mutex); + list_del(&device->global_node); + mutex_unlock(&dma_list_mutex); + + list_for_each_entry(chan, &device->channels, device_node) { + dma_clients_notify_removed(chan); + class_device_unregister(&chan->class_dev); + dma_chan_release(chan); + } + + kref_put(&device->refcount, dma_async_device_cleanup); + wait_for_completion(&device->done); +} +EXPORT_SYMBOL(dma_async_device_unregister_v3); + +/** + * dma_async_memcpy_buf_to_buf_v3 - offloaded copy between virtual addresses + * @chan: DMA channel to offload copy to + * @dest: destination address (virtual) + * @src: source address (virtual) + * @len: length + * + * Both @dest and @src must be mappable to a bus address according to the + * DMA mapping API rules for streaming mappings. + * Both @dest and @src must stay memory resident (kernel memory or locked + * user space pages). + */ +dma_cookie_t +dma_async_memcpy_buf_to_buf_v3(struct dma_chan *chan, void *dest, + void *src, size_t len) +{ + struct dma_device_v3 *dev = chan->device_v3; + struct dma_async_tx_descriptor *tx; + dma_addr_t dma_dest, dma_src; + dma_cookie_t cookie; + int cpu; + + dma_src = dma_map_single(dev->dev, src, len, DMA_TO_DEVICE); + dma_dest = dma_map_single(dev->dev, dest, len, DMA_FROM_DEVICE); + tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, + DMA_CTRL_ACK); + + if (!tx) { + dma_unmap_single(dev->dev, dma_src, len, DMA_TO_DEVICE); + dma_unmap_single(dev->dev, dma_dest, len, DMA_FROM_DEVICE); + return -ENOMEM; + } + + tx->callback = NULL; + cookie = tx->tx_submit(tx); + + cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return cookie; +} +EXPORT_SYMBOL(dma_async_memcpy_buf_to_buf_v3); + +/** + * dma_async_memcpy_buf_to_pg_v3 - offloaded copy from address to page + * @chan: DMA channel to offload copy to + * @page: destination page + * @offset: offset in page to copy to + * @kdata: source address (virtual) + * @len: length + * + * Both @page/@offset and @kdata must be mappable to a bus address according + * to the DMA mapping API rules for streaming mappings. + * Both @page/@offset and @kdata must stay memory resident (kernel memory or + * locked user space pages) + */ +dma_cookie_t +dma_async_memcpy_buf_to_pg_v3(struct dma_chan *chan, struct page *page, + unsigned int offset, void *kdata, size_t len) +{ + struct dma_device_v3 *dev = chan->device_v3; + struct dma_async_tx_descriptor *tx; + dma_addr_t dma_dest, dma_src; + dma_cookie_t cookie; + int cpu; + + dma_src = dma_map_single(dev->dev, kdata, len, DMA_TO_DEVICE); + dma_dest = dma_map_page(dev->dev, page, offset, len, DMA_FROM_DEVICE); + tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, + DMA_CTRL_ACK); + + if (!tx) { + dma_unmap_single(dev->dev, dma_src, len, DMA_TO_DEVICE); + dma_unmap_page(dev->dev, dma_dest, len, DMA_FROM_DEVICE); + return -ENOMEM; + } + + tx->callback = NULL; + cookie = tx->tx_submit(tx); + + cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return cookie; +} +EXPORT_SYMBOL(dma_async_memcpy_buf_to_pg_v3); + +/** + * dma_async_memcpy_pg_to_pg_v3 - offloaded copy from page to page + * @chan: DMA channel to offload copy to + * @dest_pg: destination page + * @dest_off: offset in page to copy to + * @src_pg: source page + * @src_off: offset in page to copy from + * @len: length + * + * Both @dest_page/@dest_off and @src_page/@src_off must be mappable to a bus + * address according to the DMA mapping API rules for streaming mappings. + * Both @dest_page/@dest_off and @src_page/@src_off must stay memory resident + * (kernel memory or locked user space pages). + */ +dma_cookie_t +dma_async_memcpy_pg_to_pg_v3(struct dma_chan *chan, struct page *dest_pg, + unsigned int dest_off, struct page *src_pg, unsigned int src_off, + size_t len) +{ + struct dma_device_v3 *dev = chan->device_v3; + struct dma_async_tx_descriptor *tx; + dma_addr_t dma_dest, dma_src; + dma_cookie_t cookie; + int cpu; + + dma_src = dma_map_page(dev->dev, src_pg, src_off, len, DMA_TO_DEVICE); + dma_dest = dma_map_page(dev->dev, dest_pg, dest_off, len, + DMA_FROM_DEVICE); + tx = dev->device_prep_dma_memcpy(chan, dma_dest, dma_src, len, + DMA_CTRL_ACK); + + if (!tx) { + dma_unmap_page(dev->dev, dma_src, len, DMA_TO_DEVICE); + dma_unmap_page(dev->dev, dma_dest, len, DMA_FROM_DEVICE); + return -ENOMEM; + } + + tx->callback = NULL; + cookie = tx->tx_submit(tx); + + cpu = get_cpu(); + per_cpu_ptr(chan->local, cpu)->bytes_transferred += len; + per_cpu_ptr(chan->local, cpu)->memcpy_count++; + put_cpu(); + + return cookie; +} +EXPORT_SYMBOL(dma_async_memcpy_pg_to_pg_v3); + +void dma_async_tx_descriptor_init_v3(struct dma_async_tx_descriptor *tx, + struct dma_chan *chan) +{ + tx->chan = chan; + spin_lock_init(&tx->lock); +} +EXPORT_SYMBOL(dma_async_tx_descriptor_init_v3); + +static int __init dma_bus_init(void) +{ + mutex_init(&dma_list_mutex); + return class_register(&dma_devclass); +} +subsys_initcall(dma_bus_init);