1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2021 Intel Corporation
6 #include <drm/drm_modeset_helper.h>
7 #include <drm/ttm/ttm_bo.h>
9 #include "intel_display_types.h"
11 #include "intel_fb_bo.h"
14 void intel_fb_bo_framebuffer_fini(struct drm_gem_object *obj)
16 struct xe_bo *bo = gem_to_xe_bo(obj);
18 if (bo->flags & XE_BO_FLAG_PINNED) {
19 /* Unpin our kernel fb first */
20 xe_bo_lock(bo, false);
27 int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb,
28 struct drm_gem_object *obj,
29 struct drm_mode_fb_cmd2 *mode_cmd)
31 struct xe_bo *bo = gem_to_xe_bo(obj);
32 struct xe_device *xe = to_xe_device(bo->ttm.base.dev);
36 * Some modifiers require physical alignment of 64KiB VRAM pages;
37 * require that the BO in those cases is created correctly.
39 if (XE_IOCTL_DBG(xe, intel_fb_needs_64k_phys(mode_cmd->modifier[0]) &&
40 !(bo->flags & XE_BO_FLAG_NEEDS_64K)))
45 ret = ttm_bo_reserve(&bo->ttm, true, false, NULL);
49 if (!(bo->flags & XE_BO_FLAG_SCANOUT)) {
51 * XE_BO_FLAG_SCANOUT should ideally be set at creation, or is
52 * automatically set when creating FB. We cannot change caching
53 * mode when the boect is VM_BINDed, so we can only set
54 * coherency with display when unbound.
56 if (XE_IOCTL_DBG(xe, !list_empty(&bo->ttm.base.gpuva.list))) {
57 ttm_bo_unreserve(&bo->ttm);
61 bo->flags |= XE_BO_FLAG_SCANOUT;
63 ttm_bo_unreserve(&bo->ttm);
71 struct drm_gem_object *intel_fb_bo_lookup_valid_bo(struct drm_i915_private *i915,
72 struct drm_file *filp,
73 const struct drm_mode_fb_cmd2 *mode_cmd)
76 struct drm_gem_object *gem = drm_gem_object_lookup(filp, mode_cmd->handles[0]);
79 return ERR_PTR(-ENOENT);
81 bo = gem_to_xe_bo(gem);
82 /* Require vram placement or dma-buf import */
84 !xe_bo_can_migrate(bo, XE_PL_VRAM0) &&
85 bo->ttm.type != ttm_bo_type_sg) {
86 drm_gem_object_put(gem);
87 return ERR_PTR(-EREMOTE);