Skip to content

Commit 02aa9ef

Browse files
IcenowyRevySR
authored andcommitted
RISCV64: SG2042: HACK: ttm: disallow cached mapping
FIXME: this hack fixed the issue when booting PCIe radeon GPU card, it will report: [ 2.909876] [drm:r600_ring_test] *ERROR* radeon: ring 0 test failed (scratch(0x8504)=0xCAFEDEAD) Rootcasue Analysis: The radeon/amdgpu driver expects pcie to snoop cpu cache, which means the contents of cpu cache should also be seen by pcie. But sg2042 does not meet this requirement. When the GPU is being initialized, the GPU's ring_test tries to write a value to a certain memory address, and then read back to check whether it is written in (before that, the cpu writes another value in). Due to SG2042's issue, gpu cannot snoop cpu cache, check fails. The hack solution is to change the memory mapped by the ttm memory manager to uncached mode to workaround this SoC issue. Signed-off-by: Icenowy Zheng <[email protected]> Tested-by: Chen Wang <[email protected]> Signed-off-by: Han Gao <[email protected]>
1 parent 9c6bbd6 commit 02aa9ef

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

drivers/gpu/drm/drm_gem_vram_helper.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,11 @@ static struct ttm_tt *bo_driver_ttm_tt_create(struct ttm_buffer_object *bo,
797797
tt = kzalloc(sizeof(*tt), GFP_KERNEL);
798798
if (!tt)
799799
return NULL;
800-
800+
#if !defined(CONFIG_PCIE_SG2042_HACK)
801801
ret = ttm_tt_init(tt, bo, page_flags, ttm_cached, 0);
802+
#else
803+
ret = ttm_tt_init(tt, bo, page_flags, ttm_write_combined, 0);
804+
#endif
802805
if (ret < 0)
803806
goto err_ttm_tt_init;
804807

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
355355
if (ret)
356356
return ret;
357357

358+
#if !defined(CONFIG_PCIE_SG2042_HACK)
358359
if (num_pages == 1 && ttm->caching == ttm_cached &&
359360
!(man->use_tt && (ttm->page_flags & TTM_TT_FLAG_DECRYPTED))) {
360361
/*
@@ -366,6 +367,8 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
366367
map->page = ttm->pages[start_page];
367368
map->virtual = kmap(map->page);
368369
} else {
370+
#endif
371+
{
369372
/*
370373
* We need to use vmap to get the desired page protection
371374
* or to make the buffer object look contiguous.

drivers/gpu/drm/ttm/ttm_resource.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
335335
res->bus.addr = NULL;
336336
res->bus.offset = 0;
337337
res->bus.is_iomem = false;
338+
#if !defined(CONFIG_PCIE_SG2042_HACK)
338339
res->bus.caching = ttm_cached;
340+
#else
341+
res->bus.caching = ttm_write_combined;
342+
#endif
339343
res->bo = bo;
340344

341345
man = ttm_manager_type(bo->bdev, place->mem_type);
@@ -839,16 +843,22 @@ ttm_kmap_iter_linear_io_init(struct ttm_kmap_iter_linear_io *iter_io,
839843
} else {
840844
iter_io->needs_unmap = true;
841845
memset(&iter_io->dmap, 0, sizeof(iter_io->dmap));
846+
#if !defined(CONFIG_PCIE_SG2042_HACK)
842847
if (mem->bus.caching == ttm_write_combined)
848+
#else
849+
if (mem->bus.caching == ttm_write_combined || mem->bus.caching == ttm_cached)
850+
#endif
843851
iosys_map_set_vaddr_iomem(&iter_io->dmap,
844852
ioremap_wc(mem->bus.offset,
845853
mem->size));
854+
#if !defined(CONFIG_PCIE_SG2042_HACK)
846855
else if (mem->bus.caching == ttm_cached)
847856
iosys_map_set_vaddr(&iter_io->dmap,
848857
memremap(mem->bus.offset, mem->size,
849858
MEMREMAP_WB |
850859
MEMREMAP_WT |
851860
MEMREMAP_WC));
861+
#endif
852862

853863
/* If uncached requested or if mapping cached or wc failed */
854864
if (iosys_map_is_null(&iter_io->dmap))

drivers/gpu/drm/ttm/ttm_tt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
158158
ttm->dma_address = NULL;
159159
ttm->swap_storage = NULL;
160160
ttm->sg = bo->sg;
161+
#if !defined(CONFIG_PCIE_SG2042_HACK)
161162
ttm->caching = caching;
163+
#else
164+
ttm->caching = ttm_write_combined;
165+
#endif
162166
ttm->restore = NULL;
163167
ttm->backup = NULL;
164168
}

0 commit comments

Comments
 (0)