Skip to content

Commit 6e4bf58

Browse files
Christoph HellwigIngo Molnar
authored andcommitted
x86/dma: Use generic swiotlb_ops
The generic swiotlb DMA ops were based on the x86 ones and provide equivalent functionality, so use them. Also fix the sta2x11 case. For that SOC the DMA map ops need an additional physical to DMA address translations. For swiotlb buffers that is done throught the phys_to_dma helper, but the sta2x11_dma_ops also added an additional translation on the return value from x86_swiotlb_alloc_coherent, which is only correct if that functions returns a direct allocation and not a swiotlb buffer. With the generic swiotlb and DMA-direct code phys_to_dma is not always used and the separate sta2x11_dma_ops can be replaced with a simple bit that marks if the additional physical to DMA address translation is needed. Tested-by: Tom Lendacky <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Jon Mason <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Muli Ben-Yehuda <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent fec777c commit 6e4bf58

File tree

4 files changed

+9
-95
lines changed

4 files changed

+9
-95
lines changed

arch/x86/include/asm/device.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ struct dev_archdata {
66
#if defined(CONFIG_INTEL_IOMMU) || defined(CONFIG_AMD_IOMMU)
77
void *iommu; /* hook for IOMMU specific extension */
88
#endif
9+
#ifdef CONFIG_STA2X11
10+
bool is_sta2x11;
11+
#endif
912
};
1013

1114
#if defined(CONFIG_X86_DEV_DMA_OPS) && defined(CONFIG_PCI_DOMAINS)

arch/x86/include/asm/swiotlb.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,4 @@ static inline void pci_swiotlb_late_init(void)
2727
{
2828
}
2929
#endif
30-
31-
extern void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
32-
dma_addr_t *dma_handle, gfp_t flags,
33-
unsigned long attrs);
34-
extern void x86_swiotlb_free_coherent(struct device *dev, size_t size,
35-
void *vaddr, dma_addr_t dma_addr,
36-
unsigned long attrs);
37-
3830
#endif /* _ASM_X86_SWIOTLB_H */

arch/x86/kernel/pci-swiotlb.c

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,6 @@
1717

1818
int swiotlb __read_mostly;
1919

20-
void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
21-
dma_addr_t *dma_handle, gfp_t flags,
22-
unsigned long attrs)
23-
{
24-
void *vaddr;
25-
26-
/*
27-
* Don't print a warning when the first allocation attempt fails.
28-
* swiotlb_alloc_coherent() will print a warning when the DMA
29-
* memory allocation ultimately failed.
30-
*/
31-
flags |= __GFP_NOWARN;
32-
33-
vaddr = dma_direct_alloc(hwdev, size, dma_handle, flags, attrs);
34-
if (vaddr)
35-
return vaddr;
36-
37-
return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
38-
}
39-
40-
void x86_swiotlb_free_coherent(struct device *dev, size_t size,
41-
void *vaddr, dma_addr_t dma_addr,
42-
unsigned long attrs)
43-
{
44-
if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
45-
swiotlb_free_coherent(dev, size, vaddr, dma_addr);
46-
else
47-
dma_direct_free(dev, size, vaddr, dma_addr, attrs);
48-
}
49-
50-
static const struct dma_map_ops x86_swiotlb_dma_ops = {
51-
.mapping_error = swiotlb_dma_mapping_error,
52-
.alloc = x86_swiotlb_alloc_coherent,
53-
.free = x86_swiotlb_free_coherent,
54-
.sync_single_for_cpu = swiotlb_sync_single_for_cpu,
55-
.sync_single_for_device = swiotlb_sync_single_for_device,
56-
.sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
57-
.sync_sg_for_device = swiotlb_sync_sg_for_device,
58-
.map_sg = swiotlb_map_sg_attrs,
59-
.unmap_sg = swiotlb_unmap_sg_attrs,
60-
.map_page = swiotlb_map_page,
61-
.unmap_page = swiotlb_unmap_page,
62-
.dma_supported = NULL,
63-
};
64-
6520
/*
6621
* pci_swiotlb_detect_override - set swiotlb to 1 if necessary
6722
*
@@ -111,7 +66,7 @@ void __init pci_swiotlb_init(void)
11166
{
11267
if (swiotlb) {
11368
swiotlb_init(0);
114-
dma_ops = &x86_swiotlb_dma_ops;
69+
dma_ops = &swiotlb_dma_ops;
11570
}
11671
}
11772

arch/x86/pci/sta2x11-fixup.c

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -159,43 +159,6 @@ static dma_addr_t a2p(dma_addr_t a, struct pci_dev *pdev)
159159
return p;
160160
}
161161

162-
/**
163-
* sta2x11_swiotlb_alloc_coherent - Allocate swiotlb bounce buffers
164-
* returns virtual address. This is the only "special" function here.
165-
* @dev: PCI device
166-
* @size: Size of the buffer
167-
* @dma_handle: DMA address
168-
* @flags: memory flags
169-
*/
170-
static void *sta2x11_swiotlb_alloc_coherent(struct device *dev,
171-
size_t size,
172-
dma_addr_t *dma_handle,
173-
gfp_t flags,
174-
unsigned long attrs)
175-
{
176-
void *vaddr;
177-
178-
vaddr = x86_swiotlb_alloc_coherent(dev, size, dma_handle, flags, attrs);
179-
*dma_handle = p2a(*dma_handle, to_pci_dev(dev));
180-
return vaddr;
181-
}
182-
183-
/* We have our own dma_ops: the same as swiotlb but from alloc (above) */
184-
static const struct dma_map_ops sta2x11_dma_ops = {
185-
.alloc = sta2x11_swiotlb_alloc_coherent,
186-
.free = x86_swiotlb_free_coherent,
187-
.map_page = swiotlb_map_page,
188-
.unmap_page = swiotlb_unmap_page,
189-
.map_sg = swiotlb_map_sg_attrs,
190-
.unmap_sg = swiotlb_unmap_sg_attrs,
191-
.sync_single_for_cpu = swiotlb_sync_single_for_cpu,
192-
.sync_single_for_device = swiotlb_sync_single_for_device,
193-
.sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
194-
.sync_sg_for_device = swiotlb_sync_sg_for_device,
195-
.mapping_error = swiotlb_dma_mapping_error,
196-
.dma_supported = dma_direct_supported,
197-
};
198-
199162
/* At setup time, we use our own ops if the device is a ConneXt one */
200163
static void sta2x11_setup_pdev(struct pci_dev *pdev)
201164
{
@@ -205,7 +168,8 @@ static void sta2x11_setup_pdev(struct pci_dev *pdev)
205168
return;
206169
pci_set_consistent_dma_mask(pdev, STA2X11_AMBA_SIZE - 1);
207170
pci_set_dma_mask(pdev, STA2X11_AMBA_SIZE - 1);
208-
pdev->dev.dma_ops = &sta2x11_dma_ops;
171+
pdev->dev.dma_ops = &swiotlb_dma_ops;
172+
pdev->dev.archdata.is_sta2x11 = true;
209173

210174
/* We must enable all devices as master, for audio DMA to work */
211175
pci_set_master(pdev);
@@ -225,7 +189,7 @@ bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
225189
{
226190
struct sta2x11_mapping *map;
227191

228-
if (dev->dma_ops != &sta2x11_dma_ops) {
192+
if (!dev->archdata.is_sta2x11) {
229193
if (!dev->dma_mask)
230194
return false;
231195
return addr + size - 1 <= *dev->dma_mask;
@@ -249,7 +213,7 @@ bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
249213
*/
250214
dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
251215
{
252-
if (dev->dma_ops != &sta2x11_dma_ops)
216+
if (!dev->archdata.is_sta2x11)
253217
return paddr;
254218
return p2a(paddr, to_pci_dev(dev));
255219
}
@@ -261,7 +225,7 @@ dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
261225
*/
262226
phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
263227
{
264-
if (dev->dma_ops != &sta2x11_dma_ops)
228+
if (!dev->archdata.is_sta2x11)
265229
return daddr;
266230
return a2p(daddr, to_pci_dev(dev));
267231
}

0 commit comments

Comments
 (0)