History

dma-mapping: remove the default map_resource implementation

Instead provide a proper implementation in the direct mapping code, and also wire it up for arm and powerpc, leaving an error return for all the IOMMU or virtual mapping instances for which we'd have to wire up an actual implementation

Christoph Hellwig committed 7 years ago

Commit cfced781 parent f17b5f05 files · +25 −5Browse files

Unified · Split

5 files
  1. arch/arm/mm/dma-mapping.c +2 −0
  2. arch/powerpc/kernel/dma-swiotlb.c +1 −0
  3. arch/powerpc/kernel/dma.c +1 −0
  4. include/linux/dma-mapping.h +7 −5
  5. kernel/dma/direct.c +14 −0
arch/arm/mm/dma-mapping.c+2−0
@@ -188,6 +188,7 @@ const struct dma_map_ops arm_dma_ops = { · 187 unmodified lines
188188 .unmap_page = arm_dma_unmap_page,
189189 .map_sg = arm_dma_map_sg,
190190 .unmap_sg = arm_dma_unmap_sg,
191+ .map_resource = dma_direct_map_resource,
191192 .sync_single_for_cpu = arm_dma_sync_single_for_cpu,
192193 .sync_single_for_device = arm_dma_sync_single_for_device,
193194 .sync_sg_for_cpu = arm_dma_sync_sg_for_cpu,
@@ -211,6 +212,7 @@ const struct dma_map_ops arm_coherent_dma_ops = { · 17 unmodified lines
211212 .get_sgtable = arm_dma_get_sgtable,
212213 .map_page = arm_coherent_dma_map_page,
213214 .map_sg = arm_dma_map_sg,
215+ .map_resource = dma_direct_map_resource,
214216 .dma_supported = arm_dma_supported,
215217 };
216218 EXPORT_SYMBOL(arm_coherent_dma_ops);
arch/powerpc/kernel/dma-swiotlb.c+1−0
@@ -55,6 +55,7 @@ const struct dma_map_ops powerpc_swiotlb_dma_ops = { · 54 unmodified lines
5555 .dma_supported = swiotlb_dma_supported,
5656 .map_page = dma_direct_map_page,
5757 .unmap_page = dma_direct_unmap_page,
58+ .map_resource = dma_direct_map_resource,
5859 .sync_single_for_cpu = dma_direct_sync_single_for_cpu,
5960 .sync_single_for_device = dma_direct_sync_single_for_device,
6061 .sync_sg_for_cpu = dma_direct_sync_sg_for_cpu,
arch/powerpc/kernel/dma.c+1−0
@@ -273,6 +273,7 @@ const struct dma_map_ops dma_nommu_ops = { · 272 unmodified lines
273273 .dma_supported = dma_nommu_dma_supported,
274274 .map_page = dma_nommu_map_page,
275275 .unmap_page = dma_nommu_unmap_page,
276+ .map_resource = dma_direct_map_resource,
276277 .get_required_mask = dma_nommu_get_required_mask,
277278 #ifdef CONFIG_NOT_COHERENT_CACHE
278279 .sync_single_for_cpu = dma_nommu_sync_single,
include/linux/dma-mapping.h+7−5
@@ -208,6 +208,8 @@ dma_addr_t dma_direct_map_page(struct device *dev, struct page *page, · 207 unmodified lines
208208 unsigned long attrs);
209209 int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
210210 enum dma_data_direction dir, unsigned long attrs);
211+dma_addr_t dma_direct_map_resource(struct device *dev, phys_addr_t paddr,
212+ size_t size, enum dma_data_direction dir, unsigned long attrs);
211213
212214 #if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
213215 defined(CONFIG_SWIOTLB)
@@ -346,19 +348,19 @@ static inline dma_addr_t dma_map_resource(struct device *dev, · 132 unmodified lines
346348 unsigned long attrs)
347349 {
348350 const struct dma_map_ops *ops = get_dma_ops(dev);
349− dma_addr_t addr;
351+ dma_addr_t addr = DMA_MAPPING_ERROR;
350352
351353 BUG_ON(!valid_dma_direction(dir));
352354
353355 /* Don't allow RAM to be mapped */
354356 BUG_ON(pfn_valid(PHYS_PFN(phys_addr)));
355357
356− addr = phys_addr;
357− if (ops && ops->map_resource)
358+ if (dma_is_direct(ops))
359+ addr = dma_direct_map_resource(dev, phys_addr, size, dir, attrs);
360+ else if (ops->map_resource)
358361 addr = ops->map_resource(dev, phys_addr, size, dir, attrs);
359362
360363 debug_dma_map_resource(dev, phys_addr, size, dir, addr);
361−
362364 return addr;
363365 }
364366
@@ -369,7 +371,7 @@ static inline void dma_unmap_resource(struct device *dev, dma_addr_t addr, · 4 unmodified lines
369371 const struct dma_map_ops *ops = get_dma_ops(dev);
370372
371373 BUG_ON(!valid_dma_direction(dir));
372− if (ops && ops->unmap_resource)
374+ if (!dma_is_direct(ops) && ops->unmap_resource)
373375 ops->unmap_resource(dev, addr, size, dir, attrs);
374376 debug_dma_unmap_resource(dev, addr, size, dir);
375377 }
kernel/dma/direct.c+14−0
@@ -356,6 +356,20 @@ out_unmap: · 355 unmodified lines
356356 }
357357 EXPORT_SYMBOL(dma_direct_map_sg);
358358
359+dma_addr_t dma_direct_map_resource(struct device *dev, phys_addr_t paddr,
360+ size_t size, enum dma_data_direction dir, unsigned long attrs)
361+{
362+ dma_addr_t dma_addr = paddr;
363+
364+ if (unlikely(!dma_direct_possible(dev, dma_addr, size))) {
365+ report_addr(dev, dma_addr, size);
366+ return DMA_MAPPING_ERROR;
367+ }
368+
369+ return dma_addr;
370+}
371+EXPORT_SYMBOL(dma_direct_map_resource);
372+
359373 /*
360374 * Because 32-bit DMA masks are so common we expect every architecture to be
361375 * able to satisfy them - either by not supporting more physical memory, or by

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t