Skip to content

Commit 3abc667

Browse files
committed
drm: Implement drm_need_swiotlb() in drm_cache.c
The function is declared in drm_cache.h. I also removed the curly braces from the for loop to adhere to kernel coding style. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Christian König <christian.koenig@amd.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20210112081035.6882-3-tzimmermann@suse.de
1 parent ff28a9f commit 3abc667

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

drivers/gpu/drm/drm_cache.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <linux/export.h>
3232
#include <linux/highmem.h>
33+
#include <xen/xen.h>
3334

3435
#include <drm/drm_cache.h>
3536

@@ -176,3 +177,34 @@ drm_clflush_virt_range(void *addr, unsigned long length)
176177
#endif
177178
}
178179
EXPORT_SYMBOL(drm_clflush_virt_range);
180+
181+
bool drm_need_swiotlb(int dma_bits)
182+
{
183+
struct resource *tmp;
184+
resource_size_t max_iomem = 0;
185+
186+
/*
187+
* Xen paravirtual hosts require swiotlb regardless of requested dma
188+
* transfer size.
189+
*
190+
* NOTE: Really, what it requires is use of the dma_alloc_coherent
191+
* allocator used in ttm_dma_populate() instead of
192+
* ttm_populate_and_map_pages(), which bounce buffers so much in
193+
* Xen it leads to swiotlb buffer exhaustion.
194+
*/
195+
if (xen_pv_domain())
196+
return true;
197+
198+
/*
199+
* Enforce dma_alloc_coherent when memory encryption is active as well
200+
* for the same reasons as for Xen paravirtual hosts.
201+
*/
202+
if (mem_encrypt_active())
203+
return true;
204+
205+
for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling)
206+
max_iomem = max(max_iomem, tmp->end);
207+
208+
return max_iomem > ((u64)1 << dma_bits);
209+
}
210+
EXPORT_SYMBOL(drm_need_swiotlb);

drivers/gpu/drm/drm_memory.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <linux/highmem.h>
3838
#include <linux/pci.h>
3939
#include <linux/vmalloc.h>
40-
#include <xen/xen.h>
4140

4241
#include <drm/drm_agpsupport.h>
4342
#include <drm/drm_cache.h>
@@ -138,35 +137,3 @@ void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
138137
iounmap(map->handle);
139138
}
140139
EXPORT_SYMBOL(drm_legacy_ioremapfree);
141-
142-
bool drm_need_swiotlb(int dma_bits)
143-
{
144-
struct resource *tmp;
145-
resource_size_t max_iomem = 0;
146-
147-
/*
148-
* Xen paravirtual hosts require swiotlb regardless of requested dma
149-
* transfer size.
150-
*
151-
* NOTE: Really, what it requires is use of the dma_alloc_coherent
152-
* allocator used in ttm_dma_populate() instead of
153-
* ttm_populate_and_map_pages(), which bounce buffers so much in
154-
* Xen it leads to swiotlb buffer exhaustion.
155-
*/
156-
if (xen_pv_domain())
157-
return true;
158-
159-
/*
160-
* Enforce dma_alloc_coherent when memory encryption is active as well
161-
* for the same reasons as for Xen paravirtual hosts.
162-
*/
163-
if (mem_encrypt_active())
164-
return true;
165-
166-
for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) {
167-
max_iomem = max(max_iomem, tmp->end);
168-
}
169-
170-
return max_iomem > ((u64)1 << dma_bits);
171-
}
172-
EXPORT_SYMBOL(drm_need_swiotlb);

0 commit comments

Comments
 (0)