Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Replace drm_gem_vram_push_to_system() with kunmap + unpin

The push-to-system function forces a buffer out of video RAM. This decision
should rather be made by the memory manager. By replacing the function with
calls to the kunmap and unpin functions, the buffer's memory becomes available,
but the buffer remains in VRAM until it's evicted by a pin operation.

This patch replaces the remaining instances of drm_gem_vram_push_to_system()
in ast and mgag200, and removes the function from DRM.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20190521110831.20200-2-tzimmermann@suse.de
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

authored by

Thomas Zimmermann and committed by
Gerd Hoffmann
81da87f6 982c0500

+20 -62
+10 -4
drivers/gpu/drm/ast/ast_mode.c
··· 521 521 } 522 522 } 523 523 524 - /* ast is different - we will force move buffers out of VRAM */ 525 524 static int ast_crtc_do_set_base(struct drm_crtc *crtc, 526 525 struct drm_framebuffer *fb, 527 526 int x, int y, int atomic) ··· 533 534 s64 gpu_addr; 534 535 void *base; 535 536 536 - /* push the previous fb to system ram */ 537 537 if (!atomic && fb) { 538 538 ast_fb = to_ast_framebuffer(fb); 539 539 obj = ast_fb->obj; 540 540 gbo = drm_gem_vram_of_gem(obj); 541 - drm_gem_vram_push_to_system(gbo); 541 + 542 + /* unmap if console */ 543 + if (&ast->fbdev->afb == ast_fb) 544 + drm_gem_vram_kunmap(gbo); 545 + drm_gem_vram_unpin(gbo); 542 546 } 543 547 544 548 ast_fb = to_ast_framebuffer(crtc->primary->fb); ··· 624 622 DRM_DEBUG_KMS("\n"); 625 623 ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 626 624 if (crtc->primary->fb) { 625 + struct ast_private *ast = crtc->dev->dev_private; 627 626 struct ast_framebuffer *ast_fb = to_ast_framebuffer(crtc->primary->fb); 628 627 struct drm_gem_object *obj = ast_fb->obj; 629 628 struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(obj); 630 629 631 - drm_gem_vram_push_to_system(gbo); 630 + /* unmap if console */ 631 + if (&ast->fbdev->afb == ast_fb) 632 + drm_gem_vram_kunmap(gbo); 633 + drm_gem_vram_unpin(gbo); 632 634 } 633 635 crtc->primary->fb = NULL; 634 636 }
-50
drivers/gpu/drm/drm_gem_vram_helper.c
··· 380 380 EXPORT_SYMBOL(drm_gem_vram_unpin_reserved); 381 381 382 382 /** 383 - * drm_gem_vram_push_to_system() - \ 384 - Unpins a GEM VRAM object and moves it to system memory 385 - * @gbo: the GEM VRAM object 386 - * 387 - * This operation only works if the caller holds the final pin on the 388 - * buffer object. 389 - * 390 - * Returns: 391 - * 0 on success, or 392 - * a negative error code otherwise. 393 - */ 394 - int drm_gem_vram_push_to_system(struct drm_gem_vram_object *gbo) 395 - { 396 - int i, ret; 397 - struct ttm_operation_ctx ctx = { false, false }; 398 - 399 - ret = ttm_bo_reserve(&gbo->bo, true, false, NULL); 400 - if (ret < 0) 401 - return ret; 402 - 403 - if (WARN_ON_ONCE(!gbo->pin_count)) 404 - goto out; 405 - 406 - --gbo->pin_count; 407 - if (gbo->pin_count) 408 - goto out; 409 - 410 - if (gbo->kmap.virtual) 411 - ttm_bo_kunmap(&gbo->kmap); 412 - 413 - drm_gem_vram_placement(gbo, TTM_PL_FLAG_SYSTEM); 414 - for (i = 0; i < gbo->placement.num_placement ; ++i) 415 - gbo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT; 416 - 417 - ret = ttm_bo_validate(&gbo->bo, &gbo->placement, &ctx); 418 - if (ret) 419 - goto err_ttm_bo_unreserve; 420 - 421 - out: 422 - ttm_bo_unreserve(&gbo->bo); 423 - 424 - return 0; 425 - 426 - err_ttm_bo_unreserve: 427 - ttm_bo_unreserve(&gbo->bo); 428 - return ret; 429 - } 430 - EXPORT_SYMBOL(drm_gem_vram_push_to_system); 431 - 432 - /** 433 383 * drm_gem_vram_kmap_at() - Maps a GEM VRAM object into kernel address space 434 384 * @gbo: the GEM VRAM object 435 385 * @map: establish a mapping if necessary
-2
drivers/gpu/drm/drm_vram_helper_common.c
··· 79 79 * RAM. Call drm_gem_vram_pin() with &DRM_GEM_VRAM_PL_FLAG_VRAM or 80 80 * &DRM_GEM_VRAM_PL_FLAG_SYSTEM to pin a buffer object in video RAM or system 81 81 * memory. Call drm_gem_vram_unpin() to release the pinned object afterwards. 82 - * If you have to evict a buffer object from video RAM (e.g., for freeing up 83 - * memory), unpin the buffer and call drm_gem_vram_push_to_system(). 84 82 * 85 83 * A buffer object that is pinned in video RAM has a fixed address within that 86 84 * memory region. Call drm_gem_vram_offset() to retrieve this value. Typically
+10 -5
drivers/gpu/drm/mgag200/mgag200_mode.c
··· 858 858 WREG_ECRT(0x0, ((u8)(addr >> 16) & 0xf) | crtcext0); 859 859 } 860 860 861 - 862 - /* ast is different - we will force move buffers out of VRAM */ 863 861 static int mga_crtc_do_set_base(struct drm_crtc *crtc, 864 862 struct drm_framebuffer *fb, 865 863 int x, int y, int atomic) ··· 870 872 s64 gpu_addr; 871 873 void *base; 872 874 873 - /* push the previous fb to system ram */ 874 875 if (!atomic && fb) { 875 876 mga_fb = to_mga_framebuffer(fb); 876 877 obj = mga_fb->obj; 877 878 gbo = drm_gem_vram_of_gem(obj); 878 - drm_gem_vram_push_to_system(gbo); 879 + 880 + /* unmap if console */ 881 + if (&mdev->mfbdev->mfb == mga_fb) 882 + drm_gem_vram_kunmap(gbo); 883 + drm_gem_vram_unpin(gbo); 879 884 } 880 885 881 886 mga_fb = to_mga_framebuffer(crtc->primary->fb); ··· 1426 1425 DRM_DEBUG_KMS("\n"); 1427 1426 mga_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); 1428 1427 if (crtc->primary->fb) { 1428 + struct mga_device *mdev = crtc->dev->dev_private; 1429 1429 struct mga_framebuffer *mga_fb = to_mga_framebuffer(crtc->primary->fb); 1430 1430 struct drm_gem_object *obj = mga_fb->obj; 1431 1431 struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(obj); 1432 1432 1433 - drm_gem_vram_push_to_system(gbo); 1433 + /* unmap if console */ 1434 + if (&mdev->mfbdev->mfb == mga_fb) 1435 + drm_gem_vram_kunmap(gbo); 1436 + drm_gem_vram_unpin(gbo); 1434 1437 } 1435 1438 crtc->primary->fb = NULL; 1436 1439 }
-1
include/drm/drm_gem_vram_helper.h
··· 86 86 unsigned long pl_flag); 87 87 int drm_gem_vram_unpin(struct drm_gem_vram_object *gbo); 88 88 int drm_gem_vram_unpin_reserved(struct drm_gem_vram_object *gbo); 89 - int drm_gem_vram_push_to_system(struct drm_gem_vram_object *gbo); 90 89 void *drm_gem_vram_kmap_at(struct drm_gem_vram_object *gbo, bool map, 91 90 bool *is_iomem, struct ttm_bo_kmap_obj *kmap); 92 91 void *drm_gem_vram_kmap(struct drm_gem_vram_object *gbo, bool map,