From patchwork Thu Apr 18 16:55:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13635141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24BE7C04FF8 for ; Thu, 18 Apr 2024 16:55:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 784B0113E04; Thu, 18 Apr 2024 16:55:12 +0000 (UTC) Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id D6C2C112739; Thu, 18 Apr 2024 16:55:08 +0000 (UTC) From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Maarten Lankhorst Subject: [PATCH 1/5] drm/xe/display: Preparations for preallocating dpt bo Date: Thu, 18 Apr 2024 18:55:15 +0200 Message-ID: <20240418165520.88961-2-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> References: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The DPT bo should not be allocated when pinning, but in advance when creating the framebuffer. Split allocation from bo pinning and GGTT insertion. Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/xe/display/xe_fb_pin.c | 159 +++++++++++++++++++------ 1 file changed, 123 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c b/drivers/gpu/drm/xe/display/xe_fb_pin.c index 3a584bc3a0a3..d967d00bbf9d 100644 --- a/drivers/gpu/drm/xe/display/xe_fb_pin.c +++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c @@ -76,47 +76,130 @@ write_dpt_remapped(struct xe_bo *bo, struct iosys_map *map, u32 *dpt_ofs, *dpt_ofs = ALIGN(*dpt_ofs, 4096); } -static int __xe_pin_fb_vma_dpt(struct intel_framebuffer *fb, - const struct i915_gtt_view *view, - struct i915_vma *vma) +static struct xe_bo *xe_fb_dpt_alloc(struct intel_framebuffer *fb) { struct xe_device *xe = to_xe_device(fb->base.dev); struct xe_tile *tile0 = xe_device_get_root_tile(xe); - struct xe_ggtt *ggtt = tile0->mem.ggtt; struct xe_bo *bo = intel_fb_obj(&fb->base), *dpt; u32 dpt_size, size = bo->ttm.base.size; - if (view->type == I915_GTT_VIEW_NORMAL) + if (!intel_fb_needs_pot_stride_remap(fb)) dpt_size = ALIGN(size / XE_PAGE_SIZE * 8, XE_PAGE_SIZE); - else if (view->type == I915_GTT_VIEW_REMAPPED) - dpt_size = ALIGN(intel_remapped_info_size(&fb->remapped_view.gtt.remapped) * 8, - XE_PAGE_SIZE); else - /* display uses 4K tiles instead of bytes here, convert to entries.. */ - dpt_size = ALIGN(intel_rotation_info_size(&view->rotated) * 8, + dpt_size = ALIGN(intel_remapped_info_size(&fb->remapped_view.gtt.remapped) * 8, XE_PAGE_SIZE); if (IS_DGFX(xe)) - dpt = xe_bo_create_pin_map(xe, tile0, NULL, dpt_size, - ttm_bo_type_kernel, - XE_BO_FLAG_VRAM0 | - XE_BO_FLAG_GGTT | - XE_BO_FLAG_PAGETABLE); - else - dpt = xe_bo_create_pin_map(xe, tile0, NULL, dpt_size, - ttm_bo_type_kernel, - XE_BO_FLAG_STOLEN | - XE_BO_FLAG_GGTT | - XE_BO_FLAG_PAGETABLE); + return xe_bo_create(xe, tile0, NULL, dpt_size, + ttm_bo_type_kernel, + XE_BO_FLAG_NEEDS_CPU_ACCESS | + XE_BO_FLAG_VRAM0 | + XE_BO_FLAG_PAGETABLE); + + dpt = xe_bo_create(xe, tile0, NULL, dpt_size, + ttm_bo_type_kernel, + XE_BO_FLAG_NEEDS_CPU_ACCESS | + XE_BO_FLAG_STOLEN | + XE_BO_FLAG_PAGETABLE); if (IS_ERR(dpt)) - dpt = xe_bo_create_pin_map(xe, tile0, NULL, dpt_size, - ttm_bo_type_kernel, - XE_BO_FLAG_SYSTEM | - XE_BO_FLAG_GGTT | - XE_BO_FLAG_PAGETABLE); + dpt = xe_bo_create(xe, tile0, NULL, dpt_size, + ttm_bo_type_kernel, + XE_BO_FLAG_NEEDS_CPU_ACCESS | + XE_BO_FLAG_SYSTEM | + XE_BO_FLAG_PAGETABLE); + + return dpt; +} + +static void xe_fb_dpt_free(struct i915_vma *vma) +{ + xe_bo_put(vma->dpt); + vma->dpt = NULL; +} + +static int xe_fb_dpt_map_ggtt(struct xe_bo *dpt) +{ + struct xe_device *xe = xe_bo_device(dpt); + struct xe_tile *tile0 = xe_device_get_root_tile(xe); + struct xe_ggtt *ggtt = tile0->mem.ggtt; + u64 start = 0, end = U64_MAX; + u64 alignment = XE_PAGE_SIZE; + int err; + + if (dpt->flags & XE_BO_FLAG_INTERNAL_64K) + alignment = SZ_64K; + + if (XE_WARN_ON(dpt->ggtt_node.size)) + return -EINVAL; + + xe_device_mem_access_get(tile_to_xe(ggtt->tile)); + err = mutex_lock_interruptible(&ggtt->lock); + if (err) + goto out_put; + + err = drm_mm_insert_node_in_range(&ggtt->mm, &dpt->ggtt_node, dpt->size, + alignment, 0, start, end, 0); + if (!err) + xe_ggtt_map_bo(ggtt, dpt); + mutex_unlock(&ggtt->lock); + +out_put: + xe_device_mem_access_put(tile_to_xe(ggtt->tile)); + return err; +} + +static int +xe_fb_dpt_alloc_pinned(struct i915_vma *vma, struct intel_framebuffer *fb) +{ + struct xe_bo *dpt; + int err; + + dpt = xe_fb_dpt_alloc(fb); if (IS_ERR(dpt)) return PTR_ERR(dpt); + vma->dpt = dpt; + + err = ttm_bo_reserve(&dpt->ttm, true, false, NULL); + if (!err) { + err = xe_bo_validate(dpt, NULL, true); + if (!err) + err = xe_bo_vmap(dpt); + if (!err) + ttm_bo_pin(&dpt->ttm); + ttm_bo_unreserve(&dpt->ttm); + } + if (err) + xe_fb_dpt_free(vma); + return err; +} + +static void xe_fb_dpt_unpin_free(struct i915_vma *vma) +{ + ttm_bo_reserve(&vma->dpt->ttm, false, false, NULL); + ttm_bo_unpin(&vma->dpt->ttm); + ttm_bo_unreserve(&vma->dpt->ttm); + + xe_fb_dpt_free(vma); +} + +static int __xe_pin_fb_vma_dpt(struct intel_framebuffer *fb, + const struct i915_gtt_view *view, + struct i915_vma *vma) +{ + struct xe_device *xe = to_xe_device(fb->base.dev); + struct xe_tile *tile0 = xe_device_get_root_tile(xe); + struct xe_ggtt *ggtt = tile0->mem.ggtt; + struct xe_bo *bo = intel_fb_obj(&fb->base), *dpt; + u32 size = bo->ttm.base.size; + int ret; + + ret = xe_fb_dpt_alloc_pinned(vma, fb); + if (ret) + return ret; + dpt = vma->dpt; + + /* Create GGTT mapping.. */ if (view->type == I915_GTT_VIEW_NORMAL) { u32 x; @@ -151,9 +234,10 @@ static int __xe_pin_fb_vma_dpt(struct intel_framebuffer *fb, rot_info->plane[i].dst_stride); } - vma->dpt = dpt; - vma->node = dpt->ggtt_node; - return 0; + ret = xe_fb_dpt_map_ggtt(dpt); + if (ret) + xe_fb_dpt_unpin_free(vma); + return ret; } static void @@ -258,7 +342,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct intel_framebuffer *fb, int ret; if (!vma) - return ERR_PTR(-ENODEV); + return ERR_PTR(-ENOMEM); if (IS_DGFX(to_xe_device(bo->ttm.base.dev)) && intel_fb_rc_ccs_cc_plane(&fb->base) >= 0 && @@ -281,7 +365,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct intel_framebuffer *fb, * Pin the framebuffer, we can't use xe_bo_(un)pin functions as the * assumptions are incorrect for framebuffers */ - ret = ttm_bo_reserve(&bo->ttm, false, false, NULL); + ret = ttm_bo_reserve(&bo->ttm, true, false, NULL); if (ret) goto err; @@ -319,11 +403,14 @@ static void __xe_unpin_fb_vma(struct i915_vma *vma) struct xe_device *xe = to_xe_device(vma->bo->ttm.base.dev); struct xe_ggtt *ggtt = xe_device_get_root_tile(xe)->mem.ggtt; - if (vma->dpt) - xe_bo_unpin_map_no_vm(vma->dpt); - else if (!drm_mm_node_allocated(&vma->bo->ggtt_node) || - vma->bo->ggtt_node.start != vma->node.start) - xe_ggtt_remove_node(ggtt, &vma->node, false); + if (vma->dpt) { + xe_ggtt_remove_bo(ggtt, vma->dpt); + xe_fb_dpt_unpin_free(vma); + } else { + if (!drm_mm_node_allocated(&vma->bo->ggtt_node) || + vma->bo->ggtt_node.start != vma->node.start) + xe_ggtt_remove_node(ggtt, &vma->node, false); + } ttm_bo_reserve(&vma->bo->ttm, false, false, NULL); ttm_bo_unpin(&vma->bo->ttm); From patchwork Thu Apr 18 16:55:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13635138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5B23C04FF8 for ; Thu, 18 Apr 2024 16:55:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 23FDB10FA57; Thu, 18 Apr 2024 16:55:10 +0000 (UTC) Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id D653810FA57; Thu, 18 Apr 2024 16:55:08 +0000 (UTC) From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Maarten Lankhorst Subject: [PATCH 2/5] drm/xe: Use simple xchg to cache DPT Date: Thu, 18 Apr 2024 18:55:16 +0200 Message-ID: <20240418165520.88961-3-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> References: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/xe/display/xe_fb_pin.c | 33 +++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c b/drivers/gpu/drm/xe/display/xe_fb_pin.c index d967d00bbf9d..16a287cbebc5 100644 --- a/drivers/gpu/drm/xe/display/xe_fb_pin.c +++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c @@ -111,9 +111,11 @@ static struct xe_bo *xe_fb_dpt_alloc(struct intel_framebuffer *fb) return dpt; } -static void xe_fb_dpt_free(struct i915_vma *vma) +static void xe_fb_dpt_free(struct i915_vma *vma, struct intel_framebuffer *fb) { - xe_bo_put(vma->dpt); + if (!fb || cmpxchg((struct xe_bo **)&fb->dpt_vm, NULL, vma->dpt)) + xe_bo_put(vma->dpt); + vma->dpt = NULL; } @@ -151,10 +153,11 @@ static int xe_fb_dpt_map_ggtt(struct xe_bo *dpt) static int xe_fb_dpt_alloc_pinned(struct i915_vma *vma, struct intel_framebuffer *fb) { - struct xe_bo *dpt; + struct xe_bo *dpt = (struct xe_bo *)xchg(&fb->dpt_vm, NULL); int err; - dpt = xe_fb_dpt_alloc(fb); + if (!dpt) + dpt = xe_fb_dpt_alloc(fb); if (IS_ERR(dpt)) return PTR_ERR(dpt); @@ -170,17 +173,17 @@ xe_fb_dpt_alloc_pinned(struct i915_vma *vma, struct intel_framebuffer *fb) ttm_bo_unreserve(&dpt->ttm); } if (err) - xe_fb_dpt_free(vma); + xe_fb_dpt_free(vma, fb); return err; } -static void xe_fb_dpt_unpin_free(struct i915_vma *vma) +static void xe_fb_dpt_unpin_free(struct i915_vma *vma, struct intel_framebuffer *fb) { ttm_bo_reserve(&vma->dpt->ttm, false, false, NULL); ttm_bo_unpin(&vma->dpt->ttm); ttm_bo_unreserve(&vma->dpt->ttm); - xe_fb_dpt_free(vma); + xe_fb_dpt_free(vma, fb); } static int __xe_pin_fb_vma_dpt(struct intel_framebuffer *fb, @@ -236,7 +239,7 @@ static int __xe_pin_fb_vma_dpt(struct intel_framebuffer *fb, ret = xe_fb_dpt_map_ggtt(dpt); if (ret) - xe_fb_dpt_unpin_free(vma); + xe_fb_dpt_unpin_free(vma, fb); return ret; } @@ -398,14 +401,14 @@ static struct i915_vma *__xe_pin_fb_vma(struct intel_framebuffer *fb, return ERR_PTR(ret); } -static void __xe_unpin_fb_vma(struct i915_vma *vma) +static void __xe_unpin_fb_vma(struct i915_vma *vma, struct intel_framebuffer *fb) { struct xe_device *xe = to_xe_device(vma->bo->ttm.base.dev); struct xe_ggtt *ggtt = xe_device_get_root_tile(xe)->mem.ggtt; if (vma->dpt) { xe_ggtt_remove_bo(ggtt, vma->dpt); - xe_fb_dpt_unpin_free(vma); + xe_fb_dpt_unpin_free(vma, fb); } else { if (!drm_mm_node_allocated(&vma->bo->ggtt_node) || vma->bo->ggtt_node.start != vma->node.start) @@ -432,7 +435,7 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) { - __xe_unpin_fb_vma(vma); + __xe_unpin_fb_vma(vma, NULL); } int intel_plane_pin_fb(struct intel_plane_state *plane_state) @@ -454,7 +457,7 @@ int intel_plane_pin_fb(struct intel_plane_state *plane_state) void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) { - __xe_unpin_fb_vma(old_plane_state->ggtt_vma); + __xe_unpin_fb_vma(old_plane_state->ggtt_vma, to_intel_framebuffer(old_plane_state->hw.fb)); old_plane_state->ggtt_vma = NULL; } @@ -464,10 +467,12 @@ void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state) */ struct i915_address_space *intel_dpt_create(struct intel_framebuffer *fb) { - return NULL; + return (struct i915_address_space *)xe_fb_dpt_alloc(fb); } void intel_dpt_destroy(struct i915_address_space *vm) { - return; + struct xe_bo *bo = (struct xe_bo *)vm; + + xe_bo_put(bo); } From patchwork Thu Apr 18 16:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13635139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE833C071FD for ; Thu, 18 Apr 2024 16:55:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A935113491; Thu, 18 Apr 2024 16:55:12 +0000 (UTC) Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E12710FA57; Thu, 18 Apr 2024 16:55:09 +0000 (UTC) From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Maarten Lankhorst Subject: [PATCH 3/5] drm/xe: Remove safety check from __xe_ttm_stolen_io_mem_reserve_stolen Date: Thu, 18 Apr 2024 18:55:17 +0200 Message-ID: <20240418165520.88961-4-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> References: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" This is invalid with display code when reworking DPT. Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c b/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c index f77367329760..1613290b9eda 100644 --- a/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c +++ b/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c @@ -298,10 +298,6 @@ static int __xe_ttm_stolen_io_mem_reserve_stolen(struct xe_device *xe, XE_WARN_ON(IS_DGFX(xe)); - /* XXX: Require BO to be mapped to GGTT? */ - if (drm_WARN_ON(&xe->drm, !(bo->flags & XE_BO_FLAG_GGTT))) - return -EIO; - /* GGTT is always contiguously mapped */ mem->bus.offset = xe_bo_ggtt_addr(bo) + mgr->io_base; From patchwork Thu Apr 18 16:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13635142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10595C04FFE for ; Thu, 18 Apr 2024 16:55:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 66BEE113E05; Thu, 18 Apr 2024 16:55:13 +0000 (UTC) Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 17731113491; Thu, 18 Apr 2024 16:55:11 +0000 (UTC) From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Maarten Lankhorst Subject: [PATCH 4/5] drm/xe/display: Prevent overwriting original GGTT when taking over initial FB. Date: Thu, 18 Apr 2024 18:55:18 +0200 Message-ID: <20240418165520.88961-5-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> References: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Instead of overwriting the original GGTT mapping accidentally, allocate a new GGTT mapping above the original GGTT mapping. Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/xe/display/xe_fb_pin.c | 40 ++++++++++++------- drivers/gpu/drm/xe/display/xe_fb_pin.h | 20 ++++++++++ drivers/gpu/drm/xe/display/xe_plane_initial.c | 15 ++++--- drivers/gpu/drm/xe/xe_ggtt.c | 9 +++-- drivers/gpu/drm/xe/xe_ggtt.h | 3 +- 5 files changed, 63 insertions(+), 24 deletions(-) create mode 100644 drivers/gpu/drm/xe/display/xe_fb_pin.h diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c b/drivers/gpu/drm/xe/display/xe_fb_pin.c index 16a287cbebc5..dd7a1c4a9430 100644 --- a/drivers/gpu/drm/xe/display/xe_fb_pin.c +++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c @@ -8,6 +8,7 @@ #include "intel_dpt.h" #include "intel_fb.h" #include "intel_fb_pin.h" +#include "xe_fb_pin.h" #include "xe_ggtt.h" #include "xe_gt.h" @@ -119,12 +120,11 @@ static void xe_fb_dpt_free(struct i915_vma *vma, struct intel_framebuffer *fb) vma->dpt = NULL; } -static int xe_fb_dpt_map_ggtt(struct xe_bo *dpt) +static int xe_fb_dpt_map_ggtt(struct xe_bo *dpt, u64 ggtt_start) { struct xe_device *xe = xe_bo_device(dpt); struct xe_tile *tile0 = xe_device_get_root_tile(xe); struct xe_ggtt *ggtt = tile0->mem.ggtt; - u64 start = 0, end = U64_MAX; u64 alignment = XE_PAGE_SIZE; int err; @@ -139,8 +139,9 @@ static int xe_fb_dpt_map_ggtt(struct xe_bo *dpt) if (err) goto out_put; - err = drm_mm_insert_node_in_range(&ggtt->mm, &dpt->ggtt_node, dpt->size, - alignment, 0, start, end, 0); + err = xe_ggtt_insert_special_node_locked(ggtt, &dpt->ggtt_node, dpt->size, + alignment, ggtt_start, U64_MAX, + ggtt_start ? DRM_MM_INSERT_HIGH : 0); if (!err) xe_ggtt_map_bo(ggtt, dpt); mutex_unlock(&ggtt->lock); @@ -188,7 +189,7 @@ static void xe_fb_dpt_unpin_free(struct i915_vma *vma, struct intel_framebuffer static int __xe_pin_fb_vma_dpt(struct intel_framebuffer *fb, const struct i915_gtt_view *view, - struct i915_vma *vma) + struct i915_vma *vma, u64 ggtt_start) { struct xe_device *xe = to_xe_device(fb->base.dev); struct xe_tile *tile0 = xe_device_get_root_tile(xe); @@ -237,7 +238,7 @@ static int __xe_pin_fb_vma_dpt(struct intel_framebuffer *fb, rot_info->plane[i].dst_stride); } - ret = xe_fb_dpt_map_ggtt(dpt); + ret = xe_fb_dpt_map_ggtt(dpt, ggtt_start); if (ret) xe_fb_dpt_unpin_free(vma, fb); return ret; @@ -269,7 +270,7 @@ write_ggtt_rotated(struct xe_bo *bo, struct xe_ggtt *ggtt, u32 *ggtt_ofs, u32 bo static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer *fb, const struct i915_gtt_view *view, - struct i915_vma *vma) + struct i915_vma *vma, u64 ggtt_start) { struct xe_bo *bo = intel_fb_obj(&fb->base); struct xe_device *xe = to_xe_device(fb->base.dev); @@ -295,7 +296,8 @@ static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer *fb, u32 x, size = bo->ttm.base.size; ret = xe_ggtt_insert_special_node_locked(ggtt, &vma->node, size, - align, 0); + align, ggtt_start, U64_MAX, + ggtt_start ? DRM_MM_INSERT_HIGH : 0); if (ret) goto out_unlock; @@ -313,7 +315,7 @@ static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer *fb, u32 size = intel_rotation_info_size(rot_info) * XE_PAGE_SIZE; ret = xe_ggtt_insert_special_node_locked(ggtt, &vma->node, size, - align, 0); + align, ggtt_start, U64_MAX, 0); if (ret) goto out_unlock; @@ -336,7 +338,8 @@ static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer *fb, } static struct i915_vma *__xe_pin_fb_vma(struct intel_framebuffer *fb, - const struct i915_gtt_view *view) + const struct i915_gtt_view *view, + u64 ggtt_start) { struct drm_device *dev = fb->base.dev; struct xe_device *xe = to_xe_device(dev); @@ -384,9 +387,9 @@ static struct i915_vma *__xe_pin_fb_vma(struct intel_framebuffer *fb, vma->bo = bo; if (intel_fb_uses_dpt(&fb->base)) - ret = __xe_pin_fb_vma_dpt(fb, view, vma); + ret = __xe_pin_fb_vma_dpt(fb, view, vma, ggtt_start); else - ret = __xe_pin_fb_vma_ggtt(fb, view, vma); + ret = __xe_pin_fb_vma_ggtt(fb, view, vma, ggtt_start); if (ret) goto err_unpin; @@ -430,7 +433,16 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, { *out_flags = 0; - return __xe_pin_fb_vma(to_intel_framebuffer(fb), view); + return __xe_pin_fb_vma(to_intel_framebuffer(fb), view, 0); +} + + +struct i915_vma * +xe_pin_and_fence_fb_obj_initial(struct drm_framebuffer *fb, + const struct i915_gtt_view *view, + u64 ggtt_start) +{ + return __xe_pin_fb_vma(to_intel_framebuffer(fb), view, ggtt_start); } void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) @@ -447,7 +459,7 @@ int intel_plane_pin_fb(struct intel_plane_state *plane_state) /* We reject creating !SCANOUT fb's, so this is weird.. */ drm_WARN_ON(bo->ttm.base.dev, !(bo->flags & XE_BO_FLAG_SCANOUT)); - vma = __xe_pin_fb_vma(to_intel_framebuffer(fb), &plane_state->view.gtt); + vma = __xe_pin_fb_vma(to_intel_framebuffer(fb), &plane_state->view.gtt, 0); if (IS_ERR(vma)) return PTR_ERR(vma); diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.h b/drivers/gpu/drm/xe/display/xe_fb_pin.h new file mode 100644 index 000000000000..f22960138691 --- /dev/null +++ b/drivers/gpu/drm/xe/display/xe_fb_pin.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2024 Intel Corporation + */ + +#ifndef __XE_FB_PIN_H__ +#define __XE_FB_PIN_H__ + +#include + +struct i915_vma; +struct drm_framebuffer; +struct i915_gtt_view; + +struct i915_vma * +xe_pin_and_fence_fb_obj_initial(struct drm_framebuffer *fb, + const struct i915_gtt_view *view, + u64 ggtt_start); + +#endif diff --git a/drivers/gpu/drm/xe/display/xe_plane_initial.c b/drivers/gpu/drm/xe/display/xe_plane_initial.c index 9693c56d386b..fdb05043add1 100644 --- a/drivers/gpu/drm/xe/display/xe_plane_initial.c +++ b/drivers/gpu/drm/xe/display/xe_plane_initial.c @@ -18,6 +18,7 @@ #include "intel_fb_pin.h" #include "intel_frontbuffer.h" #include "intel_plane_initial.h" +#include "xe_fb_pin.h" static bool intel_reuse_initial_plane_obj(struct intel_crtc *this, @@ -63,7 +64,7 @@ initial_plane_bo(struct xe_device *xe, if (plane_config->size == 0) return NULL; - flags = XE_BO_FLAG_PINNED | XE_BO_FLAG_SCANOUT | XE_BO_FLAG_GGTT; + flags = XE_BO_FLAG_PINNED | XE_BO_FLAG_SCANOUT; base = round_down(plane_config->base, page_size); if (IS_DGFX(xe)) { @@ -193,6 +194,7 @@ intel_find_initial_plane_obj(struct intel_crtc *crtc, to_intel_crtc_state(crtc->base.state); struct drm_framebuffer *fb; struct i915_vma *vma; + u64 ggtt_start = 0; /* * TODO: @@ -202,17 +204,20 @@ intel_find_initial_plane_obj(struct intel_crtc *crtc, if (!plane_config->fb) return; - if (intel_alloc_initial_plane_obj(crtc, plane_config)) + if (intel_alloc_initial_plane_obj(crtc, plane_config)) { fb = &plane_config->fb->base; - else if (!intel_reuse_initial_plane_obj(crtc, plane_configs, &fb)) + + /* Ensure that new GGTT mapping is not overwriting the original mapping */ + ggtt_start = plane_config->base + intel_fb_obj(fb)->ttm.base.size; + } else if (!intel_reuse_initial_plane_obj(crtc, plane_configs, &fb)) { goto nofb; + } plane_state->uapi.rotation = plane_config->rotation; intel_fb_fill_view(to_intel_framebuffer(fb), plane_state->uapi.rotation, &plane_state->view); - vma = intel_pin_and_fence_fb_obj(fb, false, &plane_state->view.gtt, - false, &plane_state->flags); + vma = xe_pin_and_fence_fb_obj_initial(fb, &plane_state->view.gtt, ggtt_start); if (IS_ERR(vma)) goto nofb; diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c index 38f6c94c722d..281301f85aba 100644 --- a/drivers/gpu/drm/xe/xe_ggtt.c +++ b/drivers/gpu/drm/xe/xe_ggtt.c @@ -352,10 +352,10 @@ void xe_ggtt_deballoon(struct xe_ggtt *ggtt, struct drm_mm_node *node) } int xe_ggtt_insert_special_node_locked(struct xe_ggtt *ggtt, struct drm_mm_node *node, - u32 size, u32 align, u32 mm_flags) + u32 size, u32 align, u64 start, u64 end, u32 mm_flags) { - return drm_mm_insert_node_generic(&ggtt->mm, node, size, align, 0, - mm_flags); + return drm_mm_insert_node_in_range(&ggtt->mm, node, size, align, 0, + start, end, mm_flags); } int xe_ggtt_insert_special_node(struct xe_ggtt *ggtt, struct drm_mm_node *node, @@ -365,7 +365,8 @@ int xe_ggtt_insert_special_node(struct xe_ggtt *ggtt, struct drm_mm_node *node, mutex_lock(&ggtt->lock); ret = xe_ggtt_insert_special_node_locked(ggtt, node, size, - align, DRM_MM_INSERT_HIGH); + align, 0, U64_MAX, + DRM_MM_INSERT_HIGH); mutex_unlock(&ggtt->lock); return ret; diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h index 4a41a1762358..6fdd7c58f37f 100644 --- a/drivers/gpu/drm/xe/xe_ggtt.h +++ b/drivers/gpu/drm/xe/xe_ggtt.h @@ -22,7 +22,8 @@ int xe_ggtt_insert_special_node(struct xe_ggtt *ggtt, struct drm_mm_node *node, u32 size, u32 align); int xe_ggtt_insert_special_node_locked(struct xe_ggtt *ggtt, struct drm_mm_node *node, - u32 size, u32 align, u32 mm_flags); + u32 size, u32 align, + u64 start, u64 end, u32 mm_flags); void xe_ggtt_remove_node(struct xe_ggtt *ggtt, struct drm_mm_node *node, bool invalidate); void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_bo *bo); From patchwork Thu Apr 18 16:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 13635143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42AB7C4345F for ; Thu, 18 Apr 2024 16:55:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AAF6E113E06; Thu, 18 Apr 2024 16:55:15 +0000 (UTC) Received: from mblankhorst.nl (lankhorst.se [141.105.120.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id A7301113E07; Thu, 18 Apr 2024 16:55:14 +0000 (UTC) From: Maarten Lankhorst To: intel-xe@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, Maarten Lankhorst Subject: [PATCH 5/5] drm/xe/display: Re-use display vmas when possible Date: Thu, 18 Apr 2024 18:55:19 +0200 Message-ID: <20240418165520.88961-6-maarten.lankhorst@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> References: <20240418165520.88961-1-maarten.lankhorst@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" i915 has this really nice, infrastructure where everything becomes complicated, GGTT needs eviction, etc.. Lets not do that, and make the dumbest possible interface instead. Try to retrieve the VMA from old_plane_state, or intel_fbdev if kernel fb. Signed-off-by: Maarten Lankhorst --- .../gpu/drm/i915/display/intel_atomic_plane.c | 2 +- drivers/gpu/drm/i915/display/intel_cursor.c | 2 +- drivers/gpu/drm/i915/display/intel_fb_pin.c | 3 +- drivers/gpu/drm/i915/display/intel_fb_pin.h | 3 +- drivers/gpu/drm/i915/display/intel_fbdev.c | 5 ++ drivers/gpu/drm/i915/display/intel_fbdev.h | 9 ++++ .../gpu/drm/xe/compat-i915-headers/i915_vma.h | 3 ++ drivers/gpu/drm/xe/display/xe_fb_pin.c | 46 +++++++++++++++++-- 8 files changed, 65 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_atomic_plane.c b/drivers/gpu/drm/i915/display/intel_atomic_plane.c index 76d77d5a0409..24ba55531e8d 100644 --- a/drivers/gpu/drm/i915/display/intel_atomic_plane.c +++ b/drivers/gpu/drm/i915/display/intel_atomic_plane.c @@ -1106,7 +1106,7 @@ intel_prepare_plane_fb(struct drm_plane *_plane, if (!obj) return 0; - ret = intel_plane_pin_fb(new_plane_state); + ret = intel_plane_pin_fb(new_plane_state, old_plane_state); if (ret) return ret; diff --git a/drivers/gpu/drm/i915/display/intel_cursor.c b/drivers/gpu/drm/i915/display/intel_cursor.c index 23a122ee20c9..3d3b8e37c0f2 100644 --- a/drivers/gpu/drm/i915/display/intel_cursor.c +++ b/drivers/gpu/drm/i915/display/intel_cursor.c @@ -761,7 +761,7 @@ intel_legacy_cursor_update(struct drm_plane *_plane, if (ret) goto out_free; - ret = intel_plane_pin_fb(new_plane_state); + ret = intel_plane_pin_fb(new_plane_state, old_plane_state); if (ret) goto out_free; diff --git a/drivers/gpu/drm/i915/display/intel_fb_pin.c b/drivers/gpu/drm/i915/display/intel_fb_pin.c index b6df9baf481b..7b8a1825ccfc 100644 --- a/drivers/gpu/drm/i915/display/intel_fb_pin.c +++ b/drivers/gpu/drm/i915/display/intel_fb_pin.c @@ -236,7 +236,8 @@ void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) i915_vma_put(vma); } -int intel_plane_pin_fb(struct intel_plane_state *plane_state) +int intel_plane_pin_fb(struct intel_plane_state *plane_state, + const struct intel_plane_state *old_plane_state) { struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); struct drm_i915_private *dev_priv = to_i915(plane->base.dev); diff --git a/drivers/gpu/drm/i915/display/intel_fb_pin.h b/drivers/gpu/drm/i915/display/intel_fb_pin.h index de0efaa25905..48675e6233f0 100644 --- a/drivers/gpu/drm/i915/display/intel_fb_pin.h +++ b/drivers/gpu/drm/i915/display/intel_fb_pin.h @@ -22,7 +22,8 @@ intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags); -int intel_plane_pin_fb(struct intel_plane_state *plane_state); +int intel_plane_pin_fb(struct intel_plane_state *new_plane_state, + const struct intel_plane_state *old_plane_state); void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state); #endif diff --git a/drivers/gpu/drm/i915/display/intel_fbdev.c b/drivers/gpu/drm/i915/display/intel_fbdev.c index 43855c6c3509..a010b7a8a468 100644 --- a/drivers/gpu/drm/i915/display/intel_fbdev.c +++ b/drivers/gpu/drm/i915/display/intel_fbdev.c @@ -668,3 +668,8 @@ struct intel_framebuffer *intel_fbdev_framebuffer(struct intel_fbdev *fbdev) return to_intel_framebuffer(fbdev->helper.fb); } + +struct i915_vma *intel_fbdev_vma_pointer(struct intel_fbdev *fbdev) +{ + return fbdev ? fbdev->vma : NULL; +} diff --git a/drivers/gpu/drm/i915/display/intel_fbdev.h b/drivers/gpu/drm/i915/display/intel_fbdev.h index 04fd523a5023..fa6c0c1ae936 100644 --- a/drivers/gpu/drm/i915/display/intel_fbdev.h +++ b/drivers/gpu/drm/i915/display/intel_fbdev.h @@ -22,6 +22,8 @@ void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous void intel_fbdev_output_poll_changed(struct drm_device *dev); void intel_fbdev_restore_mode(struct drm_i915_private *dev_priv); struct intel_framebuffer *intel_fbdev_framebuffer(struct intel_fbdev *fbdev); +struct i915_vma *intel_fbdev_vma_pointer(struct intel_fbdev *fbdev); + #else static inline int intel_fbdev_init(struct drm_device *dev) { @@ -51,10 +53,17 @@ static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) static inline void intel_fbdev_restore_mode(struct drm_i915_private *i915) { } + static inline struct intel_framebuffer *intel_fbdev_framebuffer(struct intel_fbdev *fbdev) { return NULL; } + +static inline struct i915_vma *intel_fbdev_vma_pointer(struct intel_fbdev *fbdev) +{ + return NULL; +} + #endif #endif /* __INTEL_FBDEV_H__ */ diff --git a/drivers/gpu/drm/xe/compat-i915-headers/i915_vma.h b/drivers/gpu/drm/xe/compat-i915-headers/i915_vma.h index a20d2638ea7a..193382f97823 100644 --- a/drivers/gpu/drm/xe/compat-i915-headers/i915_vma.h +++ b/drivers/gpu/drm/xe/compat-i915-headers/i915_vma.h @@ -9,6 +9,8 @@ #include #include +#include + /* We don't want these from i915_drm.h in case of Xe */ #undef I915_TILING_X #undef I915_TILING_Y @@ -18,6 +20,7 @@ struct xe_bo; struct i915_vma { + refcount_t ref; struct xe_bo *bo, *dpt; struct drm_mm_node node; }; diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c b/drivers/gpu/drm/xe/display/xe_fb_pin.c index dd7a1c4a9430..10114c575e5a 100644 --- a/drivers/gpu/drm/xe/display/xe_fb_pin.c +++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c @@ -8,6 +8,7 @@ #include "intel_dpt.h" #include "intel_fb.h" #include "intel_fb_pin.h" +#include "intel_fbdev.h" #include "xe_fb_pin.h" #include "xe_ggtt.h" #include "xe_gt.h" @@ -350,6 +351,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct intel_framebuffer *fb, if (!vma) return ERR_PTR(-ENOMEM); + refcount_set(&vma->ref, 1); if (IS_DGFX(to_xe_device(bo->ttm.base.dev)) && intel_fb_rc_ccs_cc_plane(&fb->base) >= 0 && !(bo->flags & XE_BO_FLAG_NEEDS_CPU_ACCESS)) { @@ -409,6 +411,9 @@ static void __xe_unpin_fb_vma(struct i915_vma *vma, struct intel_framebuffer *fb struct xe_device *xe = to_xe_device(vma->bo->ttm.base.dev); struct xe_ggtt *ggtt = xe_device_get_root_tile(xe)->mem.ggtt; + if (!refcount_dec_and_test(&vma->ref)) + return; + if (vma->dpt) { xe_ggtt_remove_bo(ggtt, vma->dpt); xe_fb_dpt_unpin_free(vma, fb); @@ -450,20 +455,53 @@ void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags) __xe_unpin_fb_vma(vma, NULL); } -int intel_plane_pin_fb(struct intel_plane_state *plane_state) +static bool reuse_vma(struct intel_plane_state *new_plane_state, + const struct intel_plane_state *old_plane_state) { - struct drm_framebuffer *fb = plane_state->hw.fb; + struct intel_framebuffer *fb = to_intel_framebuffer(new_plane_state->hw.fb); + struct xe_device *xe = to_xe_device(fb->base.dev); + struct i915_vma *vma; + + if (old_plane_state->hw.fb == new_plane_state->hw.fb && + !memcmp(&old_plane_state->view.gtt, + &new_plane_state->view.gtt, + sizeof(new_plane_state->view.gtt))) { + vma = old_plane_state->ggtt_vma; + goto found; + } + + if (fb == intel_fbdev_framebuffer(xe->display.fbdev.fbdev)) { + vma = intel_fbdev_vma_pointer(xe->display.fbdev.fbdev); + if (vma) + goto found; + } + + return false; + +found: + refcount_inc(&vma->ref); + new_plane_state->ggtt_vma = vma; + return true; +} + +int intel_plane_pin_fb(struct intel_plane_state *new_plane_state, + const struct intel_plane_state *old_plane_state) +{ + struct drm_framebuffer *fb = new_plane_state->hw.fb; struct xe_bo *bo = intel_fb_obj(fb); struct i915_vma *vma; + if (reuse_vma(new_plane_state, old_plane_state)) + return 0; + /* We reject creating !SCANOUT fb's, so this is weird.. */ drm_WARN_ON(bo->ttm.base.dev, !(bo->flags & XE_BO_FLAG_SCANOUT)); - vma = __xe_pin_fb_vma(to_intel_framebuffer(fb), &plane_state->view.gtt, 0); + vma = __xe_pin_fb_vma(to_intel_framebuffer(fb), &new_plane_state->view.gtt, 0); if (IS_ERR(vma)) return PTR_ERR(vma); - plane_state->ggtt_vma = vma; + new_plane_state->ggtt_vma = vma; return 0; }