Skip to content

Commit 887712a

Browse files
author
Christoph Hellwig
committed
x86/calgary: remove the mapping_error dma_map_ops method
Return DMA_MAPPING_ERROR instead of the magic bad_dma_addr on a dma mapping failure and let the core dma-mapping code handle the rest. Remove the magic EMERGENCY_PAGES that the bad_dma_addr gets redirected to. Signed-off-by: Christoph Hellwig <[email protected]> Acked-by: Linus Torvalds <[email protected]>
1 parent 9e8aa6b commit 887712a

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

arch/x86/kernel/pci-calgary_64.c

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

54-
#define CALGARY_MAPPING_ERROR 0
55-
5654
#ifdef CONFIG_CALGARY_IOMMU_ENABLED_BY_DEFAULT
5755
int use_calgary __read_mostly = 1;
5856
#else
@@ -157,8 +155,6 @@ static const unsigned long phb_debug_offsets[] = {
157155

158156
#define PHB_DEBUG_STUFF_OFFSET 0x0020
159157

160-
#define EMERGENCY_PAGES 32 /* = 128KB */
161-
162158
unsigned int specified_table_size = TCE_TABLE_SIZE_UNSPECIFIED;
163159
static int translate_empty_slots __read_mostly = 0;
164160
static int calgary_detected __read_mostly = 0;
@@ -255,7 +251,7 @@ static unsigned long iommu_range_alloc(struct device *dev,
255251
if (panic_on_overflow)
256252
panic("Calgary: fix the allocator.\n");
257253
else
258-
return CALGARY_MAPPING_ERROR;
254+
return DMA_MAPPING_ERROR;
259255
}
260256
}
261257

@@ -274,11 +270,10 @@ static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
274270
dma_addr_t ret;
275271

276272
entry = iommu_range_alloc(dev, tbl, npages);
277-
278-
if (unlikely(entry == CALGARY_MAPPING_ERROR)) {
273+
if (unlikely(entry == DMA_MAPPING_ERROR)) {
279274
pr_warn("failed to allocate %u pages in iommu %p\n",
280275
npages, tbl);
281-
return CALGARY_MAPPING_ERROR;
276+
return DMA_MAPPING_ERROR;
282277
}
283278

284279
/* set the return dma address */
@@ -294,12 +289,10 @@ static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
294289
unsigned int npages)
295290
{
296291
unsigned long entry;
297-
unsigned long badend;
298292
unsigned long flags;
299293

300294
/* were we called with bad_dma_address? */
301-
badend = CALGARY_MAPPING_ERROR + (EMERGENCY_PAGES * PAGE_SIZE);
302-
if (unlikely(dma_addr < badend)) {
295+
if (unlikely(dma_addr == DMA_MAPPING_ERROR)) {
303296
WARN(1, KERN_ERR "Calgary: driver tried unmapping bad DMA "
304297
"address 0x%Lx\n", dma_addr);
305298
return;
@@ -383,7 +376,7 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
383376
npages = iommu_num_pages(vaddr, s->length, PAGE_SIZE);
384377

385378
entry = iommu_range_alloc(dev, tbl, npages);
386-
if (entry == CALGARY_MAPPING_ERROR) {
379+
if (entry == DMA_MAPPING_ERROR) {
387380
/* makes sure unmap knows to stop */
388381
s->dma_length = 0;
389382
goto error;
@@ -401,7 +394,7 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
401394
error:
402395
calgary_unmap_sg(dev, sg, nelems, dir, 0);
403396
for_each_sg(sg, s, nelems, i) {
404-
sg->dma_address = CALGARY_MAPPING_ERROR;
397+
sg->dma_address = DMA_MAPPING_ERROR;
405398
sg->dma_length = 0;
406399
}
407400
return 0;
@@ -454,7 +447,7 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size,
454447

455448
/* set up tces to cover the allocated range */
456449
mapping = iommu_alloc(dev, tbl, ret, npages, DMA_BIDIRECTIONAL);
457-
if (mapping == CALGARY_MAPPING_ERROR)
450+
if (mapping == DMA_MAPPING_ERROR)
458451
goto free;
459452
*dma_handle = mapping;
460453
return ret;
@@ -479,19 +472,13 @@ static void calgary_free_coherent(struct device *dev, size_t size,
479472
free_pages((unsigned long)vaddr, get_order(size));
480473
}
481474

482-
static int calgary_mapping_error(struct device *dev, dma_addr_t dma_addr)
483-
{
484-
return dma_addr == CALGARY_MAPPING_ERROR;
485-
}
486-
487475
static const struct dma_map_ops calgary_dma_ops = {
488476
.alloc = calgary_alloc_coherent,
489477
.free = calgary_free_coherent,
490478
.map_sg = calgary_map_sg,
491479
.unmap_sg = calgary_unmap_sg,
492480
.map_page = calgary_map_page,
493481
.unmap_page = calgary_unmap_page,
494-
.mapping_error = calgary_mapping_error,
495482
.dma_supported = dma_direct_supported,
496483
};
497484

@@ -739,9 +726,6 @@ static void __init calgary_reserve_regions(struct pci_dev *dev)
739726
u64 start;
740727
struct iommu_table *tbl = pci_iommu(dev->bus);
741728

742-
/* reserve EMERGENCY_PAGES from bad_dma_address and up */
743-
iommu_range_reserve(tbl, CALGARY_MAPPING_ERROR, EMERGENCY_PAGES);
744-
745729
/* avoid the BIOS/VGA first 640KB-1MB region */
746730
/* for CalIOC2 - avoid the entire first MB */
747731
if (is_calgary(dev->device)) {

0 commit comments

Comments
 (0)