Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f295c8c

Browse files
committed
drm/nouveau: fix dma syncing warning with debugging on.
Since I wrote the below patch if you run a debug kernel you can a dma debug warning like: nouveau 0000:1f:00.0: DMA-API: device driver tries to sync DMA memory it has not allocated [device address=0x000000016e012000] [size=4096 bytes] The old nouveau code wasn't consolidate the pages like the ttm code, but the dma-debug expects the sync code to give it the same base/range pairs as the allocator. Fix the nouveau sync code to consolidate pages before calling the sync code. Fixes: bd549d3 ("nouveau: use ttm populate mapping functions. (v2)") Reported-by: Lyude Paul <[email protected]> Reviewed-by: Ben Skeggs <[email protected]> Signed-off-by: Dave Airlie <[email protected]> Link: https://patchwork.freedesktop.org/patch/417588/
1 parent 1048ba8 commit f295c8c

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

drivers/gpu/drm/nouveau/nouveau_bo.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ nouveau_bo_sync_for_device(struct nouveau_bo *nvbo)
547547
{
548548
struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
549549
struct ttm_tt *ttm_dma = (struct ttm_tt *)nvbo->bo.ttm;
550-
int i;
550+
int i, j;
551551

552552
if (!ttm_dma)
553553
return;
@@ -556,18 +556,29 @@ nouveau_bo_sync_for_device(struct nouveau_bo *nvbo)
556556
if (nvbo->force_coherent)
557557
return;
558558

559-
for (i = 0; i < ttm_dma->num_pages; i++)
559+
for (i = 0; i < ttm_dma->num_pages; ++i) {
560+
struct page *p = ttm_dma->pages[i];
561+
size_t num_pages = 1;
562+
563+
for (j = i + 1; j < ttm_dma->num_pages; ++j) {
564+
if (++p != ttm_dma->pages[j])
565+
break;
566+
567+
++num_pages;
568+
}
560569
dma_sync_single_for_device(drm->dev->dev,
561570
ttm_dma->dma_address[i],
562-
PAGE_SIZE, DMA_TO_DEVICE);
571+
num_pages * PAGE_SIZE, DMA_TO_DEVICE);
572+
i += num_pages;
573+
}
563574
}
564575

565576
void
566577
nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo)
567578
{
568579
struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
569580
struct ttm_tt *ttm_dma = (struct ttm_tt *)nvbo->bo.ttm;
570-
int i;
581+
int i, j;
571582

572583
if (!ttm_dma)
573584
return;
@@ -576,9 +587,21 @@ nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo)
576587
if (nvbo->force_coherent)
577588
return;
578589

579-
for (i = 0; i < ttm_dma->num_pages; i++)
590+
for (i = 0; i < ttm_dma->num_pages; ++i) {
591+
struct page *p = ttm_dma->pages[i];
592+
size_t num_pages = 1;
593+
594+
for (j = i + 1; j < ttm_dma->num_pages; ++j) {
595+
if (++p != ttm_dma->pages[j])
596+
break;
597+
598+
++num_pages;
599+
}
600+
580601
dma_sync_single_for_cpu(drm->dev->dev, ttm_dma->dma_address[i],
581-
PAGE_SIZE, DMA_FROM_DEVICE);
602+
num_pages * PAGE_SIZE, DMA_FROM_DEVICE);
603+
i += num_pages;
604+
}
582605
}
583606

584607
void nouveau_bo_add_io_reserve_lru(struct ttm_buffer_object *bo)

0 commit comments

Comments
 (0)