1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2021 Intel Corporation
6 #include <drm/drm_framebuffer.h>
8 #include "gem/i915_gem_object.h"
12 #include "intel_fb_bo.h"
14 void intel_fb_bo_framebuffer_fini(struct drm_i915_gem_object *obj)
16 /* Nothing to do for i915 */
19 int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb,
20 struct drm_i915_gem_object *obj,
21 struct drm_mode_fb_cmd2 *mode_cmd)
23 struct drm_i915_private *i915 = to_i915(obj->base.dev);
24 unsigned int tiling, stride;
26 i915_gem_object_lock(obj, NULL);
27 tiling = i915_gem_object_get_tiling(obj);
28 stride = i915_gem_object_get_stride(obj);
29 i915_gem_object_unlock(obj);
31 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
33 * If there's a fence, enforce that
34 * the fb modifier and tiling mode match.
36 if (tiling != I915_TILING_NONE &&
37 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
38 drm_dbg_kms(&i915->drm,
39 "tiling_mode doesn't match fb modifier\n");
43 if (tiling == I915_TILING_X) {
44 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
45 } else if (tiling == I915_TILING_Y) {
46 drm_dbg_kms(&i915->drm,
47 "No Y tiling for legacy addfb\n");
53 * gen2/3 display engine uses the fence if present,
54 * so the tiling mode must match the fb modifier exactly.
56 if (DISPLAY_VER(i915) < 4 &&
57 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
58 drm_dbg_kms(&i915->drm,
59 "tiling_mode must match fb modifier exactly on gen2/3\n");
64 * If there's a fence, enforce that
65 * the fb pitch and fence stride match.
67 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
68 drm_dbg_kms(&i915->drm,
69 "pitch (%d) must match tiling stride (%d)\n",
70 mode_cmd->pitches[0], stride);
77 struct drm_i915_gem_object *
78 intel_fb_bo_lookup_valid_bo(struct drm_i915_private *i915,
79 struct drm_file *filp,
80 const struct drm_mode_fb_cmd2 *mode_cmd)
82 struct drm_i915_gem_object *obj;
84 obj = i915_gem_object_lookup(filp, mode_cmd->handles[0]);
86 return ERR_PTR(-ENOENT);
88 /* object is backed with LMEM for discrete */
89 if (HAS_LMEM(i915) && !i915_gem_object_can_migrate(obj, INTEL_REGION_LMEM_0)) {
90 /* object is "remote", not in local memory */
91 i915_gem_object_put(obj);
92 drm_dbg_kms(&i915->drm, "framebuffer must reside in local memory\n");
93 return ERR_PTR(-EREMOTE);