Commit ff5cbec0 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

sparc/iommu: create a common helper for map_sg

Share the code for the global and per-page flush map_sg loops using a
simple bool parameter to disable the per-page flush for the former
variant.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reported-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f25b23bc
...@@ -241,25 +241,9 @@ static dma_addr_t sbus_iommu_map_page_pflush(struct device *dev, ...@@ -241,25 +241,9 @@ static dma_addr_t sbus_iommu_map_page_pflush(struct device *dev,
return __sbus_iommu_map_page(dev, page, offset, len); return __sbus_iommu_map_page(dev, page, offset, len);
} }
static int sbus_iommu_map_sg_gflush(struct device *dev, struct scatterlist *sgl, static int __sbus_iommu_map_sg(struct device *dev, struct scatterlist *sgl,
int nents, enum dma_data_direction dir, unsigned long attrs) int nents, enum dma_data_direction dir, unsigned long attrs,
{ bool per_page_flush)
struct scatterlist *sg;
int i, n;
flush_page_for_dma(0);
for_each_sg(sgl, sg, nents, i) {
n = (sg->length + sg->offset + PAGE_SIZE-1) >> PAGE_SHIFT;
sg->dma_address = iommu_get_one(dev, sg_page(sg), n) + sg->offset;
sg->dma_length = sg->length;
}
return nents;
}
static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sgl,
int nents, enum dma_data_direction dir, unsigned long attrs)
{ {
unsigned long page, oldpage = 0; unsigned long page, oldpage = 0;
struct scatterlist *sg; struct scatterlist *sg;
...@@ -273,7 +257,7 @@ static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sgl, ...@@ -273,7 +257,7 @@ static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sgl,
* XXX Is this a good assumption? * XXX Is this a good assumption?
* XXX What if someone else unmaps it here and races us? * XXX What if someone else unmaps it here and races us?
*/ */
if (!PageHighMem(sg_page(sg))) { if (per_page_flush && !PageHighMem(sg_page(sg))) {
page = (unsigned long)page_address(sg_page(sg)); page = (unsigned long)page_address(sg_page(sg));
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (page != oldpage) { /* Already flushed? */ if (page != oldpage) { /* Already flushed? */
...@@ -291,6 +275,19 @@ static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sgl, ...@@ -291,6 +275,19 @@ static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sgl,
return nents; return nents;
} }
static int sbus_iommu_map_sg_gflush(struct device *dev, struct scatterlist *sgl,
int nents, enum dma_data_direction dir, unsigned long attrs)
{
flush_page_for_dma(0);
return __sbus_iommu_map_sg(dev, sgl, nents, dir, attrs, false);
}
static int sbus_iommu_map_sg_pflush(struct device *dev, struct scatterlist *sgl,
int nents, enum dma_data_direction dir, unsigned long attrs)
{
return __sbus_iommu_map_sg(dev, sgl, nents, dir, attrs, true);
}
static void sbus_iommu_unmap_page(struct device *dev, dma_addr_t dma_addr, static void sbus_iommu_unmap_page(struct device *dev, dma_addr_t dma_addr,
size_t len, enum dma_data_direction dir, unsigned long attrs) size_t len, enum dma_data_direction dir, unsigned long attrs)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment