Skip to content

Commit cea9d03

Browse files
author
Christoph Hellwig
committed
dma-mapping: add an arch_dma_supported hook
To implement the x86 forbid_dac and iommu_sac_force we want an arch hook so that it can apply the global options across all dma_map_ops implementations. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
1 parent 57bf5a8 commit cea9d03

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

‎arch/x86/include/asm/dma-mapping.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
3030
return dma_ops;
3131
}
3232

33+
int arch_dma_supported(struct device *dev, u64 mask);
34+
#define arch_dma_supported arch_dma_supported
35+
3336
bool arch_dma_alloc_attrs(struct device **dev, gfp_t *gfp);
3437
#define arch_dma_alloc_attrs arch_dma_alloc_attrs
3538

‎arch/x86/kernel/pci-dma.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static __init int iommu_setup(char *p)
215215
}
216216
early_param("iommu", iommu_setup);
217217

218-
int x86_dma_supported(struct device *dev, u64 mask)
218+
int arch_dma_supported(struct device *dev, u64 mask)
219219
{
220220
#ifdef CONFIG_PCI
221221
if (mask > 0xffffffff && forbid_dac > 0) {
@@ -224,12 +224,6 @@ int x86_dma_supported(struct device *dev, u64 mask)
224224
}
225225
#endif
226226

227-
/* Copied from i386. Doesn't make much sense, because it will
228-
only work for pci_alloc_coherent.
229-
The caller just has to use GFP_DMA in this case. */
230-
if (mask < DMA_BIT_MASK(24))
231-
return 0;
232-
233227
/* Tell the device to use SAC when IOMMU force is on. This
234228
allows the driver to use cheaper accesses in some cases.
235229
@@ -249,6 +243,17 @@ int x86_dma_supported(struct device *dev, u64 mask)
249243

250244
return 1;
251245
}
246+
EXPORT_SYMBOL(arch_dma_supported);
247+
248+
int x86_dma_supported(struct device *dev, u64 mask)
249+
{
250+
/* Copied from i386. Doesn't make much sense, because it will
251+
only work for pci_alloc_coherent.
252+
The caller just has to use GFP_DMA in this case. */
253+
if (mask < DMA_BIT_MASK(24))
254+
return 0;
255+
return 1;
256+
}
252257

253258
static int __init pci_iommu_init(void)
254259
{

‎include/linux/dma-mapping.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,14 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
576576
return 0;
577577
}
578578

579+
/*
580+
* This is a hack for the legacy x86 forbid_dac and iommu_sac_force. Please
581+
* don't use this is new code.
582+
*/
583+
#ifndef arch_dma_supported
584+
#define arch_dma_supported(dev, mask) (1)
585+
#endif
586+
579587
static inline void dma_check_mask(struct device *dev, u64 mask)
580588
{
581589
if (sme_active() && (mask < (((u64)sme_get_me_mask() << 1) - 1)))
@@ -588,6 +596,9 @@ static inline int dma_supported(struct device *dev, u64 mask)
588596

589597
if (!ops)
590598
return 0;
599+
if (!arch_dma_supported(dev, mask))
600+
return 0;
601+
591602
if (!ops->dma_supported)
592603
return 1;
593604
return ops->dma_supported(dev, mask);

0 commit comments

Comments
 (0)