Skip to content

Commit 8d8bb39

Browse files
fujitatorvalds
authored andcommitted
dma-mapping: add the device argument to dma_mapping_error()
Add per-device dma_mapping_ops support for CONFIG_X86_64 as POWER architecture does: This enables us to cleanly fix the Calgary IOMMU issue that some devices are not behind the IOMMU (http://lkml.org/lkml/2008/5/8/423). I think that per-device dma_mapping_ops support would be also helpful for KVM people to support PCI passthrough but Andi thinks that this makes it difficult to support the PCI passthrough (see the above thread). So I CC'ed this to KVM camp. Comments are appreciated. A pointer to dma_mapping_ops to struct dev_archdata is added. If the pointer is non NULL, DMA operations in asm/dma-mapping.h use it. If it's NULL, the system-wide dma_ops pointer is used as before. If it's useful for KVM people, I plan to implement a mechanism to register a hook called when a new pci (or dma capable) device is created (it works with hot plugging). It enables IOMMUs to set up an appropriate dma_mapping_ops per device. The major obstacle is that dma_mapping_error doesn't take a pointer to the device unlike other DMA operations. So x86 can't have dma_mapping_ops per device. Note all the POWER IOMMUs use the same dma_mapping_error function so this is not a problem for POWER but x86 IOMMUs use different dma_mapping_error functions. The first patch adds the device argument to dma_mapping_error. The patch is trivial but large since it touches lots of drivers and dma-mapping.h in all the architecture. This patch: dma_mapping_error() doesn't take a pointer to the device unlike other DMA operations. So we can't have dma_mapping_ops per device. Note that POWER already has dma_mapping_ops per device but all the POWER IOMMUs use the same dma_mapping_error function. x86 IOMMUs use device argument. [akpm@linux-foundation.org: fix sge] [akpm@linux-foundation.org: fix svc_rdma] [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: fix bnx2x] [akpm@linux-foundation.org: fix s2io] [akpm@linux-foundation.org: fix pasemi_mac] [akpm@linux-foundation.org: fix sdhci] [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: fix sparc] [akpm@linux-foundation.org: fix ibmvscsi] Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Muli Ben-Yehuda <muli@il.ibm.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@elte.hu> Cc: Avi Kivity <avi@qumranet.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c485b46 commit 8d8bb39

76 files changed

Lines changed: 256 additions & 210 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/DMA-API.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ recommended that you never use these unless you really know what the
298298
cache width is.
299299

300300
int
301-
dma_mapping_error(dma_addr_t dma_addr)
301+
dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
302302

303303
int
304-
pci_dma_mapping_error(dma_addr_t dma_addr)
304+
pci_dma_mapping_error(struct pci_dev *hwdev, dma_addr_t dma_addr)
305305

306306
In some circumstances dma_map_single and dma_map_page will fail to create
307307
a mapping. A driver can check for these errors by testing the returned

‎arch/arm/common/dmabounce.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
280280
/*
281281
* Trying to unmap an invalid mapping
282282
*/
283-
if (dma_mapping_error(dma_addr)) {
283+
if (dma_mapping_error(dev, dma_addr)) {
284284
dev_err(dev, "Trying to unmap invalid mapping\n");
285285
return;
286286
}

‎arch/ia64/hp/common/hwsw_iommu.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ hwsw_dma_supported (struct device *dev, u64 mask)
186186
}
187187

188188
int
189-
hwsw_dma_mapping_error (dma_addr_t dma_addr)
189+
hwsw_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
190190
{
191-
return hwiommu_dma_mapping_error (dma_addr) || swiotlb_dma_mapping_error(dma_addr);
191+
return hwiommu_dma_mapping_error(dev, dma_addr) ||
192+
swiotlb_dma_mapping_error(dev, dma_addr);
192193
}
193194

194195
EXPORT_SYMBOL(hwsw_dma_mapping_error);

‎arch/ia64/hp/common/sba_iommu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ sba_dma_supported (struct device *dev, u64 mask)
21472147
}
21482148

21492149
int
2150-
sba_dma_mapping_error (dma_addr_t dma_addr)
2150+
sba_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
21512151
{
21522152
return 0;
21532153
}

‎arch/ia64/sn/pci/pci_dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ void sn_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
350350
}
351351
EXPORT_SYMBOL(sn_dma_sync_sg_for_device);
352352

353-
int sn_dma_mapping_error(dma_addr_t dma_addr)
353+
int sn_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
354354
{
355355
return 0;
356356
}

‎arch/mips/mm/dma-default.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nele
348348

349349
EXPORT_SYMBOL(dma_sync_sg_for_device);
350350

351-
int dma_mapping_error(dma_addr_t dma_addr)
351+
int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
352352
{
353353
return 0;
354354
}

‎arch/powerpc/platforms/cell/celleb_scc_pciex.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static int __init scc_pciex_iowa_init(struct iowa_bus *bus, void *data)
281281

282282
dummy_page_da = dma_map_single(bus->phb->parent, dummy_page_va,
283283
PAGE_SIZE, DMA_FROM_DEVICE);
284-
if (dma_mapping_error(dummy_page_da)) {
284+
if (dma_mapping_error(bus->phb->parent, dummy_page_da)) {
285285
pr_err("PCIEX:Map dummy page failed.\n");
286286
kfree(dummy_page_va);
287287
return -1;

‎arch/powerpc/platforms/cell/spider-pci.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int __init spiderpci_pci_setup_chip(struct pci_controller *phb,
111111

112112
dummy_page_da = dma_map_single(phb->parent, dummy_page_va,
113113
PAGE_SIZE, DMA_FROM_DEVICE);
114-
if (dma_mapping_error(dummy_page_da)) {
114+
if (dma_mapping_error(phb->parent, dummy_page_da)) {
115115
pr_err("SPIDER-IOWA:Map dummy page filed.\n");
116116
kfree(dummy_page_va);
117117
return -1;

‎arch/powerpc/platforms/iseries/mf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static int proc_mf_dump_cmdline(char *page, char **start, off_t off,
871871
count = 256 - off;
872872

873873
dma_addr = iseries_hv_map(page, off + count, DMA_FROM_DEVICE);
874-
if (dma_mapping_error(dma_addr))
874+
if (dma_mapping_error(NULL, dma_addr))
875875
return -ENOMEM;
876876
memset(page, 0, off + count);
877877
memset(&vsp_cmd, 0, sizeof(vsp_cmd));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size,
544544
return ret;
545545
}
546546

547-
static const struct dma_mapping_ops calgary_dma_ops = {
547+
static struct dma_mapping_ops calgary_dma_ops = {
548548
.alloc_coherent = calgary_alloc_coherent,
549549
.map_single = calgary_map_single,
550550
.unmap_single = calgary_unmap_single,

0 commit comments

Comments
 (0)