summaryrefslogtreecommitdiff
path: root/drivers/parisc/iommu-helpers.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-17 02:20:36 +0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-17 02:20:36 +0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/parisc/iommu-helpers.h
downloadlinux-1da177e4c3f41524e886b7f1b8a0c1fc7321cac2.tar.xz
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/parisc/iommu-helpers.h')
-rw-r--r--drivers/parisc/iommu-helpers.h171
1 files changed, 171 insertions, 0 deletions
diff --git a/drivers/parisc/iommu-helpers.h b/drivers/parisc/iommu-helpers.h
new file mode 100644
index 000000000000..38d9e1aba1d0
--- /dev/null
+++ b/drivers/parisc/iommu-helpers.h
@@ -0,0 +1,171 @@
+/**
+ * iommu_fill_pdir - Insert coalesced scatter/gather chunks into the I/O Pdir.
+ * @ioc: The I/O Controller.
+ * @startsg: The scatter/gather list of coalesced chunks.
+ * @nents: The number of entries in the scatter/gather list.
+ * @hint: The DMA Hint.
+ *
+ * This function inserts the coalesced scatter/gather list chunks into the
+ * I/O Controller's I/O Pdir.
+ */
+static inline unsigned int
+iommu_fill_pdir(struct ioc *ioc, struct scatterlist *startsg, int nents,
+ unsigned long hint,
+ void (*iommu_io_pdir_entry)(u64 *, space_t, unsigned long,
+ unsigned long))
+{
+ struct scatterlist *dma_sg = startsg; /* pointer to current DMA */
+ unsigned int n_mappings = 0;
+ unsigned long dma_offset = 0, dma_len = 0;
+ u64 *pdirp = NULL;
+
+ /* Horrible hack. For efficiency's sake, dma_sg starts one
+ * entry below the true start (it is immediately incremented
+ * in the loop) */
+ dma_sg--;
+
+ while (nents-- > 0) {
+ unsigned long vaddr;
+ long size;
+
+ DBG_RUN_SG(" %d : %08lx/%05x %08lx/%05x\n", nents,
+ (unsigned long)sg_dma_address(startsg), cnt,
+ sg_virt_addr(startsg), startsg->length
+ );
+
+
+ /*
+ ** Look for the start of a new DMA stream
+ */
+
+ if (sg_dma_address(startsg) & PIDE_FLAG) {
+ u32 pide = sg_dma_address(startsg) & ~PIDE_FLAG;
+
+ BUG_ON(pdirp && (dma_len != sg_dma_len(dma_sg)));
+
+ dma_sg++;
+
+ dma_len = sg_dma_len(startsg);
+ sg_dma_len(startsg) = 0;
+ dma_offset = (unsigned long) pide & ~IOVP_MASK;
+ n_mappings++;
+#if defined(ZX1_SUPPORT)
+ /* Pluto IOMMU IO Virt Address is not zero based */
+ sg_dma_address(dma_sg) = pide | ioc->ibase;
+#else
+ /* SBA, ccio, and dino are zero based.
+ * Trying to save a few CPU cycles for most users.
+ */
+ sg_dma_address(dma_sg) = pide;
+#endif
+ pdirp = &(ioc->pdir_base[pide >> IOVP_SHIFT]);
+ prefetchw(pdirp);
+ }
+
+ BUG_ON(pdirp == NULL);
+
+ vaddr = sg_virt_addr(startsg);
+ sg_dma_len(dma_sg) += startsg->length;
+ size = startsg->length + dma_offset;
+ dma_offset = 0;
+#ifdef IOMMU_MAP_STATS
+ ioc->msg_pages += startsg->length >> IOVP_SHIFT;
+#endif
+ do {
+ iommu_io_pdir_entry(pdirp, KERNEL_SPACE,
+ vaddr, hint);
+ vaddr += IOVP_SIZE;
+ size -= IOVP_SIZE;
+ pdirp++;
+ } while(unlikely(size > 0));
+ startsg++;
+ }
+ return(n_mappings);
+}
+
+
+/*
+** First pass is to walk the SG list and determine where the breaks are
+** in the DMA stream. Allocates PDIR entries but does not fill them.
+** Returns the number of DMA chunks.
+**
+** Doing the fill separate from the coalescing/allocation keeps the
+** code simpler. Future enhancement could make one pass through
+** the sglist do both.
+*/
+
+static inline unsigned int
+iommu_coalesce_chunks(struct ioc *ioc, struct scatterlist *startsg, int nents,
+ int (*iommu_alloc_range)(struct ioc *, size_t))
+{
+ struct scatterlist *contig_sg; /* contig chunk head */
+ unsigned long dma_offset, dma_len; /* start/len of DMA stream */
+ unsigned int n_mappings = 0;
+
+ while (nents > 0) {
+
+ /*
+ ** Prepare for first/next DMA stream
+ */
+ contig_sg = startsg;
+ dma_len = startsg->length;
+ dma_offset = sg_virt_addr(startsg) & ~IOVP_MASK;
+
+ /* PARANOID: clear entries */
+ sg_dma_address(startsg) = 0;
+ sg_dma_len(startsg) = 0;
+
+ /*
+ ** This loop terminates one iteration "early" since
+ ** it's always looking one "ahead".
+ */
+ while(--nents > 0) {
+ unsigned long prevstartsg_end, startsg_end;
+
+ prevstartsg_end = sg_virt_addr(startsg) +
+ startsg->length;
+
+ startsg++;
+ startsg_end = sg_virt_addr(startsg) +
+ startsg->length;
+
+ /* PARANOID: clear entries */
+ sg_dma_address(startsg) = 0;
+ sg_dma_len(startsg) = 0;
+
+ /*
+ ** First make sure current dma stream won't
+ ** exceed DMA_CHUNK_SIZE if we coalesce the
+ ** next entry.
+ */
+ if(unlikely(ROUNDUP(dma_len + dma_offset + startsg->length,
+ IOVP_SIZE) > DMA_CHUNK_SIZE))
+ break;
+
+ /*
+ ** Next see if we can append the next chunk (i.e.
+ ** it must end on one page and begin on another
+ */
+ if (unlikely(((prevstartsg_end | sg_virt_addr(startsg)) & ~PAGE_MASK) != 0))
+ break;
+
+ dma_len += startsg->length;
+ }
+
+ /*
+ ** End of DMA Stream
+ ** Terminate last VCONTIG block.
+ ** Allocate space for DMA stream.
+ */
+ sg_dma_len(contig_sg) = dma_len;
+ dma_len = ROUNDUP(dma_len + dma_offset, IOVP_SIZE);
+ sg_dma_address(contig_sg) =
+ PIDE_FLAG
+ | (iommu_alloc_range(ioc, dma_len) << IOVP_SHIFT)
+ | dma_offset;
+ n_mappings++;
+ }
+
+ return n_mappings;
+}
+