Skip to content

Commit 6009faa

Browse files
author
Christoph Hellwig
committed
powerpc: implement ->mapping_error
DMA_ERROR_CODE is going to go away, so don't rely on it. Instead define a ->mapping_error method for all IOMMU based dma operation instances. The direct ops don't ever return an error and don't need a ->mapping_error method. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent ceaf481 commit 6009faa

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

arch/powerpc/include/asm/dma-mapping.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
#include <asm/io.h>
1818
#include <asm/swiotlb.h>
1919

20-
#ifdef CONFIG_PPC64
21-
#define DMA_ERROR_CODE (~(dma_addr_t)0x0)
22-
#endif
23-
2420
/* Some dma direct funcs must be visible for use in other dma_ops */
2521
extern void *__dma_direct_alloc_coherent(struct device *dev, size_t size,
2622
dma_addr_t *dma_handle, gfp_t flag,

arch/powerpc/include/asm/iommu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ struct scatterlist;
139139

140140
#ifdef CONFIG_PPC64
141141

142+
#define IOMMU_MAPPING_ERROR (~(dma_addr_t)0x0)
143+
142144
static inline void set_iommu_table_base(struct device *dev,
143145
struct iommu_table *base)
144146
{
@@ -238,6 +240,8 @@ static inline int __init tce_iommu_bus_notifier_init(void)
238240
}
239241
#endif /* !CONFIG_IOMMU_API */
240242

243+
int dma_iommu_mapping_error(struct device *dev, dma_addr_t dma_addr);
244+
241245
#else
242246

243247
static inline void *get_iommu_table_base(struct device *dev)

arch/powerpc/kernel/dma-iommu.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ static u64 dma_iommu_get_required_mask(struct device *dev)
105105
return mask;
106106
}
107107

108+
int dma_iommu_mapping_error(struct device *dev, dma_addr_t dma_addr)
109+
{
110+
return dma_addr == IOMMU_MAPPING_ERROR;
111+
}
112+
108113
struct dma_map_ops dma_iommu_ops = {
109114
.alloc = dma_iommu_alloc_coherent,
110115
.free = dma_iommu_free_coherent,
@@ -115,5 +120,6 @@ struct dma_map_ops dma_iommu_ops = {
115120
.map_page = dma_iommu_map_page,
116121
.unmap_page = dma_iommu_unmap_page,
117122
.get_required_mask = dma_iommu_get_required_mask,
123+
.mapping_error = dma_iommu_mapping_error,
118124
};
119125
EXPORT_SYMBOL(dma_iommu_ops);

arch/powerpc/kernel/iommu.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ static unsigned long iommu_range_alloc(struct device *dev,
198198
if (unlikely(npages == 0)) {
199199
if (printk_ratelimit())
200200
WARN_ON(1);
201-
return DMA_ERROR_CODE;
201+
return IOMMU_MAPPING_ERROR;
202202
}
203203

204204
if (should_fail_iommu(dev))
205-
return DMA_ERROR_CODE;
205+
return IOMMU_MAPPING_ERROR;
206206

207207
/*
208208
* We don't need to disable preemption here because any CPU can
@@ -278,7 +278,7 @@ static unsigned long iommu_range_alloc(struct device *dev,
278278
} else {
279279
/* Give up */
280280
spin_unlock_irqrestore(&(pool->lock), flags);
281-
return DMA_ERROR_CODE;
281+
return IOMMU_MAPPING_ERROR;
282282
}
283283
}
284284

@@ -310,13 +310,13 @@ static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
310310
unsigned long attrs)
311311
{
312312
unsigned long entry;
313-
dma_addr_t ret = DMA_ERROR_CODE;
313+
dma_addr_t ret = IOMMU_MAPPING_ERROR;
314314
int build_fail;
315315

316316
entry = iommu_range_alloc(dev, tbl, npages, NULL, mask, align_order);
317317

318-
if (unlikely(entry == DMA_ERROR_CODE))
319-
return DMA_ERROR_CODE;
318+
if (unlikely(entry == IOMMU_MAPPING_ERROR))
319+
return IOMMU_MAPPING_ERROR;
320320

321321
entry += tbl->it_offset; /* Offset into real TCE table */
322322
ret = entry << tbl->it_page_shift; /* Set the return dma address */
@@ -328,12 +328,12 @@ static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
328328

329329
/* tbl->it_ops->set() only returns non-zero for transient errors.
330330
* Clean up the table bitmap in this case and return
331-
* DMA_ERROR_CODE. For all other errors the functionality is
331+
* IOMMU_MAPPING_ERROR. For all other errors the functionality is
332332
* not altered.
333333
*/
334334
if (unlikely(build_fail)) {
335335
__iommu_free(tbl, ret, npages);
336-
return DMA_ERROR_CODE;
336+
return IOMMU_MAPPING_ERROR;
337337
}
338338

339339
/* Flush/invalidate TLB caches if necessary */
@@ -478,7 +478,7 @@ int ppc_iommu_map_sg(struct device *dev, struct iommu_table *tbl,
478478
DBG(" - vaddr: %lx, size: %lx\n", vaddr, slen);
479479

480480
/* Handle failure */
481-
if (unlikely(entry == DMA_ERROR_CODE)) {
481+
if (unlikely(entry == IOMMU_MAPPING_ERROR)) {
482482
if (!(attrs & DMA_ATTR_NO_WARN) &&
483483
printk_ratelimit())
484484
dev_info(dev, "iommu_alloc failed, tbl %p "
@@ -545,7 +545,7 @@ int ppc_iommu_map_sg(struct device *dev, struct iommu_table *tbl,
545545
*/
546546
if (outcount < incount) {
547547
outs = sg_next(outs);
548-
outs->dma_address = DMA_ERROR_CODE;
548+
outs->dma_address = IOMMU_MAPPING_ERROR;
549549
outs->dma_length = 0;
550550
}
551551

@@ -563,7 +563,7 @@ int ppc_iommu_map_sg(struct device *dev, struct iommu_table *tbl,
563563
npages = iommu_num_pages(s->dma_address, s->dma_length,
564564
IOMMU_PAGE_SIZE(tbl));
565565
__iommu_free(tbl, vaddr, npages);
566-
s->dma_address = DMA_ERROR_CODE;
566+
s->dma_address = IOMMU_MAPPING_ERROR;
567567
s->dma_length = 0;
568568
}
569569
if (s == outs)
@@ -777,7 +777,7 @@ dma_addr_t iommu_map_page(struct device *dev, struct iommu_table *tbl,
777777
unsigned long mask, enum dma_data_direction direction,
778778
unsigned long attrs)
779779
{
780-
dma_addr_t dma_handle = DMA_ERROR_CODE;
780+
dma_addr_t dma_handle = IOMMU_MAPPING_ERROR;
781781
void *vaddr;
782782
unsigned long uaddr;
783783
unsigned int npages, align;
@@ -797,7 +797,7 @@ dma_addr_t iommu_map_page(struct device *dev, struct iommu_table *tbl,
797797
dma_handle = iommu_alloc(dev, tbl, vaddr, npages, direction,
798798
mask >> tbl->it_page_shift, align,
799799
attrs);
800-
if (dma_handle == DMA_ERROR_CODE) {
800+
if (dma_handle == IOMMU_MAPPING_ERROR) {
801801
if (!(attrs & DMA_ATTR_NO_WARN) &&
802802
printk_ratelimit()) {
803803
dev_info(dev, "iommu_alloc failed, tbl %p "
@@ -869,7 +869,7 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
869869
io_order = get_iommu_order(size, tbl);
870870
mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
871871
mask >> tbl->it_page_shift, io_order, 0);
872-
if (mapping == DMA_ERROR_CODE) {
872+
if (mapping == IOMMU_MAPPING_ERROR) {
873873
free_pages((unsigned long)ret, order);
874874
return NULL;
875875
}

arch/powerpc/platforms/cell/iommu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ static const struct dma_map_ops dma_iommu_fixed_ops = {
660660
.set_dma_mask = dma_set_mask_and_switch,
661661
.map_page = dma_fixed_map_page,
662662
.unmap_page = dma_fixed_unmap_page,
663+
.mapping_error = dma_iommu_mapping_error,
663664
};
664665

665666
static void cell_dma_dev_setup_fixed(struct device *dev);

arch/powerpc/platforms/pseries/vio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static dma_addr_t vio_dma_iommu_map_page(struct device *dev, struct page *page,
519519
{
520520
struct vio_dev *viodev = to_vio_dev(dev);
521521
struct iommu_table *tbl;
522-
dma_addr_t ret = DMA_ERROR_CODE;
522+
dma_addr_t ret = IOMMU_MAPPING_ERROR;
523523

524524
tbl = get_iommu_table_base(dev);
525525
if (vio_cmo_alloc(viodev, roundup(size, IOMMU_PAGE_SIZE(tbl)))) {
@@ -625,6 +625,7 @@ static const struct dma_map_ops vio_dma_mapping_ops = {
625625
.unmap_page = vio_dma_iommu_unmap_page,
626626
.dma_supported = vio_dma_iommu_dma_supported,
627627
.get_required_mask = vio_dma_get_required_mask,
628+
.mapping_error = dma_iommu_mapping_error,
628629
};
629630

630631
/**

0 commit comments

Comments
 (0)