Skip to content

Commit 8bd17c6

Browse files
author
Christoph Hellwig
committed
x86/calgary: implement ->mapping_error
DMA_ERROR_CODE is going to go away, so don't rely on it. Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 14a9aad commit 8bd17c6

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

arch/x86/kernel/pci-calgary_64.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#include <asm/x86_init.h>
5151
#include <asm/iommu_table.h>
5252

53+
#define CALGARY_MAPPING_ERROR 0
54+
5355
#ifdef CONFIG_CALGARY_IOMMU_ENABLED_BY_DEFAULT
5456
int use_calgary __read_mostly = 1;
5557
#else
@@ -252,7 +254,7 @@ static unsigned long iommu_range_alloc(struct device *dev,
252254
if (panic_on_overflow)
253255
panic("Calgary: fix the allocator.\n");
254256
else
255-
return DMA_ERROR_CODE;
257+
return CALGARY_MAPPING_ERROR;
256258
}
257259
}
258260

@@ -272,10 +274,10 @@ static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
272274

273275
entry = iommu_range_alloc(dev, tbl, npages);
274276

275-
if (unlikely(entry == DMA_ERROR_CODE)) {
277+
if (unlikely(entry == CALGARY_MAPPING_ERROR)) {
276278
pr_warn("failed to allocate %u pages in iommu %p\n",
277279
npages, tbl);
278-
return DMA_ERROR_CODE;
280+
return CALGARY_MAPPING_ERROR;
279281
}
280282

281283
/* set the return dma address */
@@ -295,7 +297,7 @@ static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
295297
unsigned long flags;
296298

297299
/* were we called with bad_dma_address? */
298-
badend = DMA_ERROR_CODE + (EMERGENCY_PAGES * PAGE_SIZE);
300+
badend = CALGARY_MAPPING_ERROR + (EMERGENCY_PAGES * PAGE_SIZE);
299301
if (unlikely(dma_addr < badend)) {
300302
WARN(1, KERN_ERR "Calgary: driver tried unmapping bad DMA "
301303
"address 0x%Lx\n", dma_addr);
@@ -380,7 +382,7 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
380382
npages = iommu_num_pages(vaddr, s->length, PAGE_SIZE);
381383

382384
entry = iommu_range_alloc(dev, tbl, npages);
383-
if (entry == DMA_ERROR_CODE) {
385+
if (entry == CALGARY_MAPPING_ERROR) {
384386
/* makes sure unmap knows to stop */
385387
s->dma_length = 0;
386388
goto error;
@@ -398,7 +400,7 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
398400
error:
399401
calgary_unmap_sg(dev, sg, nelems, dir, 0);
400402
for_each_sg(sg, s, nelems, i) {
401-
sg->dma_address = DMA_ERROR_CODE;
403+
sg->dma_address = CALGARY_MAPPING_ERROR;
402404
sg->dma_length = 0;
403405
}
404406
return 0;
@@ -453,7 +455,7 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size,
453455

454456
/* set up tces to cover the allocated range */
455457
mapping = iommu_alloc(dev, tbl, ret, npages, DMA_BIDIRECTIONAL);
456-
if (mapping == DMA_ERROR_CODE)
458+
if (mapping == CALGARY_MAPPING_ERROR)
457459
goto free;
458460
*dma_handle = mapping;
459461
return ret;
@@ -478,13 +480,19 @@ static void calgary_free_coherent(struct device *dev, size_t size,
478480
free_pages((unsigned long)vaddr, get_order(size));
479481
}
480482

483+
static int calgary_mapping_error(struct device *dev, dma_addr_t dma_addr)
484+
{
485+
return dma_addr == CALGARY_MAPPING_ERROR;
486+
}
487+
481488
static const struct dma_map_ops calgary_dma_ops = {
482489
.alloc = calgary_alloc_coherent,
483490
.free = calgary_free_coherent,
484491
.map_sg = calgary_map_sg,
485492
.unmap_sg = calgary_unmap_sg,
486493
.map_page = calgary_map_page,
487494
.unmap_page = calgary_unmap_page,
495+
.mapping_error = calgary_mapping_error,
488496
};
489497

490498
static inline void __iomem * busno_to_bbar(unsigned char num)
@@ -732,7 +740,7 @@ static void __init calgary_reserve_regions(struct pci_dev *dev)
732740
struct iommu_table *tbl = pci_iommu(dev->bus);
733741

734742
/* reserve EMERGENCY_PAGES from bad_dma_address and up */
735-
iommu_range_reserve(tbl, DMA_ERROR_CODE, EMERGENCY_PAGES);
743+
iommu_range_reserve(tbl, CALGARY_MAPPING_ERROR, EMERGENCY_PAGES);
736744

737745
/* avoid the BIOS/VGA first 640KB-1MB region */
738746
/* for CalIOC2 - avoid the entire first MB */

0 commit comments

Comments
 (0)