Skip to content

Commit 02b0795

Browse files
mariobalanica6by9
authored andcommitted
drm: Force write-combined mappings for DMA
PCIe GPU device drivers may use normal cached mappings for DMA memory. This requires the PCIe interface to be coherent with the CPU caches, which is not supported by many Arm platforms (e.g. RK35xx), leading to data corruption on inbound transactions. Add an option to force write-combined mappings instead (Normal non-cacheable on Arm). Note that this is just a band-aid to keep the patch small. The TTM allocator should frankly not be concerned with hardware limitations and always pass the requested caching type (a driver could still use cached memory and perform its own cache maintenance). A proper solution would be for GPU drivers to check whether the device supports coherency and request the appropriate caching type. The drm_arch_can_wc_memory() helper also needs to be reworked or possibly even dropped. Signed-off-by: Mario Bălănică <mariobalanica02@gmail.com>
1 parent eaadce9 commit 02b0795

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

drivers/gpu/drm/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ config DRM_LOAD_EDID_FIRMWARE
183183
default case is N. Details and instructions how to build your own
184184
EDID data are given in Documentation/admin-guide/edid.rst.
185185

186+
config DRM_FORCE_DMA_WRITE_COMBINED_MAPPINGS
187+
bool "Force write-combined mappings for DMA"
188+
default y
189+
help
190+
PCIe GPU device drivers may use normal cached mappings for DMA memory.
191+
192+
This requires the PCIe interface to be coherent with the CPU caches,
193+
which is not supported by many Arm platforms (e.g. RK35xx), leading to
194+
data corruption on inbound transactions.
195+
196+
Enable this option to force write-combined mappings instead (Normal
197+
non-cacheable on Arm).
198+
199+
Disable if the hardware supports coherency, as it might cause issues on
200+
certain platforms that ignore the PCIe NoSnoop TLP attribute.
201+
186202
source "drivers/gpu/drm/display/Kconfig"
187203

188204
config DRM_TTM

drivers/gpu/drm/ttm/ttm_tt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
154154
enum ttm_caching caching,
155155
unsigned long extra_pages)
156156
{
157+
#ifdef CONFIG_DRM_FORCE_DMA_WRITE_COMBINED_MAPPINGS
158+
if (caching == ttm_cached)
159+
caching = ttm_write_combined;
160+
#endif
157161
ttm->num_pages = (PAGE_ALIGN(bo->base.size) >> PAGE_SHIFT) + extra_pages;
158162
ttm->page_flags = page_flags;
159163
ttm->dma_address = NULL;

include/drm/drm_cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ bool drm_need_swiotlb(int dma_bits);
4545

4646
static inline bool drm_arch_can_wc_memory(void)
4747
{
48+
#ifdef CONFIG_DRM_FORCE_DMA_WRITE_COMBINED_MAPPINGS
49+
return true;
50+
#endif
4851
#if defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
4952
return false;
5053
#elif defined(CONFIG_MIPS) && defined(CONFIG_CPU_LOONGSON64)

0 commit comments

Comments
 (0)