]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/ieee1394/dma.c
ide: add ide_pio_cycle_time() helper (take 2)
[karo-tx-linux.git] / drivers / ieee1394 / dma.c
index 9fb2769d9abca9b25f3e136a79a48609ff5ee0dc..45d6055819227367fb318e472b1ee2de990b458f 100644 (file)
@@ -7,10 +7,13 @@
  * directory of the kernel sources for details.
  */
 
+#include <linux/mm.h>
 #include <linux/module.h>
-#include <linux/vmalloc.h>
+#include <linux/pci.h>
 #include <linux/slab.h>
-#include <linux/mm.h>
+#include <linux/vmalloc.h>
+#include <asm/scatterlist.h>
+
 #include "dma.h"
 
 /* dma_prog_region */
@@ -59,6 +62,9 @@ void dma_prog_region_free(struct dma_prog_region *prog)
 
 /* dma_region */
 
+/**
+ * dma_region_init - clear out all fields but do not allocate anything
+ */
 void dma_region_init(struct dma_region *dma)
 {
        dma->kvirt = NULL;
@@ -68,6 +74,9 @@ void dma_region_init(struct dma_region *dma)
        dma->sglist = NULL;
 }
 
+/**
+ * dma_region_alloc - allocate the buffer and map it to the IOMMU
+ */
 int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
                     struct pci_dev *dev, int direction)
 {
@@ -125,6 +134,9 @@ int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
        return -ENOMEM;
 }
 
+/**
+ * dma_region_free - unmap and free the buffer
+ */
 void dma_region_free(struct dma_region *dma)
 {
        if (dma->n_dma_pages) {
@@ -145,12 +157,12 @@ void dma_region_free(struct dma_region *dma)
 /* find the scatterlist index and remaining offset corresponding to a
    given offset from the beginning of the buffer */
 static inline int dma_region_find(struct dma_region *dma, unsigned long offset,
-                                 unsigned long *rem)
+                                 unsigned int start, unsigned long *rem)
 {
        int i;
        unsigned long off = offset;
 
-       for (i = 0; i < dma->n_dma_pages; i++) {
+       for (i = start; i < dma->n_dma_pages; i++) {
                if (off < sg_dma_len(&dma->sglist[i])) {
                        *rem = off;
                        break;
@@ -164,43 +176,55 @@ static inline int dma_region_find(struct dma_region *dma, unsigned long offset,
        return i;
 }
 
+/**
+ * dma_region_offset_to_bus - get bus address of an offset within a DMA region
+ *
+ * Returns the DMA bus address of the byte with the given @offset relative to
+ * the beginning of the @dma.
+ */
 dma_addr_t dma_region_offset_to_bus(struct dma_region * dma,
                                    unsigned long offset)
 {
        unsigned long rem = 0;
 
        struct scatterlist *sg =
-           &dma->sglist[dma_region_find(dma, offset, &rem)];
+           &dma->sglist[dma_region_find(dma, offset, 0, &rem)];
        return sg_dma_address(sg) + rem;
 }
 
+/**
+ * dma_region_sync_for_cpu - sync the CPU's view of the buffer
+ */
 void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset,
                             unsigned long len)
 {
        int first, last;
-       unsigned long rem;
+       unsigned long rem = 0;
 
        if (!len)
                len = 1;
 
-       first = dma_region_find(dma, offset, &rem);
-       last = dma_region_find(dma, offset + len - 1, &rem);
+       first = dma_region_find(dma, offset, 0, &rem);
+       last = dma_region_find(dma, rem + len - 1, first, &rem);
 
        pci_dma_sync_sg_for_cpu(dma->dev, &dma->sglist[first], last - first + 1,
                                dma->direction);
 }
 
+/**
+ * dma_region_sync_for_device - sync the IO bus' view of the buffer
+ */
 void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset,
                                unsigned long len)
 {
        int first, last;
-       unsigned long rem;
+       unsigned long rem = 0;
 
        if (!len)
                len = 1;
 
-       first = dma_region_find(dma, offset, &rem);
-       last = dma_region_find(dma, offset + len - 1, &rem);
+       first = dma_region_find(dma, offset, 0, &rem);
+       last = dma_region_find(dma, rem + len - 1, first, &rem);
 
        pci_dma_sync_sg_for_device(dma->dev, &dma->sglist[first],
                                   last - first + 1, dma->direction);
@@ -241,6 +265,9 @@ static struct vm_operations_struct dma_region_vm_ops = {
        .nopage = dma_region_pagefault,
 };
 
+/**
+ * dma_region_mmap - map the buffer into a user space process
+ */
 int dma_region_mmap(struct dma_region *dma, struct file *file,
                    struct vm_area_struct *vma)
 {