1 // SPDX-License-Identifier: MIT
3 * Copyright © 2021 Intel Corporation
6 #include <drm/drm_blend.h>
7 #include <drm/drm_framebuffer.h>
8 #include <drm/drm_modeset_helper.h>
11 #include "intel_display.h"
12 #include "intel_display_types.h"
13 #include "intel_dpt.h"
16 #define check_array_bounds(i915, a, i) drm_WARN_ON(&(i915)->drm, (i) >= ARRAY_SIZE(a))
19 * From the Sky Lake PRM:
20 * "The Color Control Surface (CCS) contains the compression status of
21 * the cache-line pairs. The compression state of the cache-line pair
22 * is specified by 2 bits in the CCS. Each CCS cache-line represents
23 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
24 * cache-line-pairs. CCS is always Y tiled."
26 * Since cache line pairs refers to horizontally adjacent cache lines,
27 * each cache line in the CCS corresponds to an area of 32x16 cache
28 * lines on the main surface. Since each pixel is 4 bytes, this gives
29 * us a ratio of one byte in the CCS for each 8x16 pixels in the
32 static const struct drm_format_info skl_ccs_formats[] = {
33 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
34 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
35 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
36 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
37 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
38 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
39 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
40 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
44 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
45 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
46 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
47 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
50 static const struct drm_format_info gen12_ccs_formats[] = {
51 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
52 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
53 .hsub = 1, .vsub = 1, },
54 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
55 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
56 .hsub = 1, .vsub = 1, },
57 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
58 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
59 .hsub = 1, .vsub = 1, .has_alpha = true },
60 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
61 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
62 .hsub = 1, .vsub = 1, .has_alpha = true },
63 { .format = DRM_FORMAT_YUYV, .num_planes = 2,
64 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
65 .hsub = 2, .vsub = 1, .is_yuv = true },
66 { .format = DRM_FORMAT_YVYU, .num_planes = 2,
67 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
68 .hsub = 2, .vsub = 1, .is_yuv = true },
69 { .format = DRM_FORMAT_UYVY, .num_planes = 2,
70 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
71 .hsub = 2, .vsub = 1, .is_yuv = true },
72 { .format = DRM_FORMAT_VYUY, .num_planes = 2,
73 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
74 .hsub = 2, .vsub = 1, .is_yuv = true },
75 { .format = DRM_FORMAT_XYUV8888, .num_planes = 2,
76 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
77 .hsub = 1, .vsub = 1, .is_yuv = true },
78 { .format = DRM_FORMAT_NV12, .num_planes = 4,
79 .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
80 .hsub = 2, .vsub = 2, .is_yuv = true },
81 { .format = DRM_FORMAT_P010, .num_planes = 4,
82 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
83 .hsub = 2, .vsub = 2, .is_yuv = true },
84 { .format = DRM_FORMAT_P012, .num_planes = 4,
85 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
86 .hsub = 2, .vsub = 2, .is_yuv = true },
87 { .format = DRM_FORMAT_P016, .num_planes = 4,
88 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
89 .hsub = 2, .vsub = 2, .is_yuv = true },
93 * Same as gen12_ccs_formats[] above, but with additional surface used
94 * to pass Clear Color information in plane 2 with 64 bits of data.
96 static const struct drm_format_info gen12_ccs_cc_formats[] = {
97 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 3,
98 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
99 .hsub = 1, .vsub = 1, },
100 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 3,
101 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
102 .hsub = 1, .vsub = 1, },
103 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 3,
104 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
105 .hsub = 1, .vsub = 1, .has_alpha = true },
106 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 3,
107 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
108 .hsub = 1, .vsub = 1, .has_alpha = true },
111 static const struct drm_format_info gen12_flat_ccs_cc_formats[] = {
112 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
113 .char_per_block = { 4, 0 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
114 .hsub = 1, .vsub = 1, },
115 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
116 .char_per_block = { 4, 0 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
117 .hsub = 1, .vsub = 1, },
118 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
119 .char_per_block = { 4, 0 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
120 .hsub = 1, .vsub = 1, .has_alpha = true },
121 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
122 .char_per_block = { 4, 0 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
123 .hsub = 1, .vsub = 1, .has_alpha = true },
126 struct intel_modifier_desc {
132 #define DISPLAY_VER_ALL { 0, -1 }
134 const struct drm_format_info *formats;
136 #define FORMAT_OVERRIDE(format_list) \
137 .formats = format_list, \
138 .format_count = ARRAY_SIZE(format_list)
144 u8 packed_aux_planes:4;
145 u8 planar_aux_planes:4;
149 #define INTEL_PLANE_CAP_CCS_MASK (INTEL_PLANE_CAP_CCS_RC | \
150 INTEL_PLANE_CAP_CCS_RC_CC | \
151 INTEL_PLANE_CAP_CCS_MC)
152 #define INTEL_PLANE_CAP_TILING_MASK (INTEL_PLANE_CAP_TILING_X | \
153 INTEL_PLANE_CAP_TILING_Y | \
154 INTEL_PLANE_CAP_TILING_Yf | \
155 INTEL_PLANE_CAP_TILING_4)
156 #define INTEL_PLANE_CAP_TILING_NONE 0
158 static const struct intel_modifier_desc intel_modifiers[] = {
160 .modifier = I915_FORMAT_MOD_4_TILED_MTL_MC_CCS,
161 .display_ver = { 14, 14 },
162 .plane_caps = INTEL_PLANE_CAP_TILING_4 | INTEL_PLANE_CAP_CCS_MC,
164 .ccs.packed_aux_planes = BIT(1),
165 .ccs.planar_aux_planes = BIT(2) | BIT(3),
167 FORMAT_OVERRIDE(gen12_ccs_formats),
169 .modifier = I915_FORMAT_MOD_4_TILED_MTL_RC_CCS,
170 .display_ver = { 14, 14 },
171 .plane_caps = INTEL_PLANE_CAP_TILING_4 | INTEL_PLANE_CAP_CCS_RC,
173 .ccs.packed_aux_planes = BIT(1),
175 FORMAT_OVERRIDE(gen12_ccs_formats),
177 .modifier = I915_FORMAT_MOD_4_TILED_MTL_RC_CCS_CC,
178 .display_ver = { 14, 14 },
179 .plane_caps = INTEL_PLANE_CAP_TILING_4 | INTEL_PLANE_CAP_CCS_RC_CC,
181 .ccs.cc_planes = BIT(2),
182 .ccs.packed_aux_planes = BIT(1),
184 FORMAT_OVERRIDE(gen12_ccs_cc_formats),
186 .modifier = I915_FORMAT_MOD_4_TILED_DG2_MC_CCS,
187 .display_ver = { 13, 13 },
188 .plane_caps = INTEL_PLANE_CAP_TILING_4 | INTEL_PLANE_CAP_CCS_MC,
190 .modifier = I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC,
191 .display_ver = { 13, 13 },
192 .plane_caps = INTEL_PLANE_CAP_TILING_4 | INTEL_PLANE_CAP_CCS_RC_CC,
194 .ccs.cc_planes = BIT(1),
196 FORMAT_OVERRIDE(gen12_flat_ccs_cc_formats),
198 .modifier = I915_FORMAT_MOD_4_TILED_DG2_RC_CCS,
199 .display_ver = { 13, 13 },
200 .plane_caps = INTEL_PLANE_CAP_TILING_4 | INTEL_PLANE_CAP_CCS_RC,
202 .modifier = I915_FORMAT_MOD_4_TILED,
203 .display_ver = { 13, -1 },
204 .plane_caps = INTEL_PLANE_CAP_TILING_4,
206 .modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS,
207 .display_ver = { 12, 13 },
208 .plane_caps = INTEL_PLANE_CAP_TILING_Y | INTEL_PLANE_CAP_CCS_MC,
210 .ccs.packed_aux_planes = BIT(1),
211 .ccs.planar_aux_planes = BIT(2) | BIT(3),
213 FORMAT_OVERRIDE(gen12_ccs_formats),
215 .modifier = I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS,
216 .display_ver = { 12, 13 },
217 .plane_caps = INTEL_PLANE_CAP_TILING_Y | INTEL_PLANE_CAP_CCS_RC,
219 .ccs.packed_aux_planes = BIT(1),
221 FORMAT_OVERRIDE(gen12_ccs_formats),
223 .modifier = I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC,
224 .display_ver = { 12, 13 },
225 .plane_caps = INTEL_PLANE_CAP_TILING_Y | INTEL_PLANE_CAP_CCS_RC_CC,
227 .ccs.cc_planes = BIT(2),
228 .ccs.packed_aux_planes = BIT(1),
230 FORMAT_OVERRIDE(gen12_ccs_cc_formats),
232 .modifier = I915_FORMAT_MOD_Yf_TILED_CCS,
233 .display_ver = { 9, 11 },
234 .plane_caps = INTEL_PLANE_CAP_TILING_Yf | INTEL_PLANE_CAP_CCS_RC,
236 .ccs.packed_aux_planes = BIT(1),
238 FORMAT_OVERRIDE(skl_ccs_formats),
240 .modifier = I915_FORMAT_MOD_Y_TILED_CCS,
241 .display_ver = { 9, 11 },
242 .plane_caps = INTEL_PLANE_CAP_TILING_Y | INTEL_PLANE_CAP_CCS_RC,
244 .ccs.packed_aux_planes = BIT(1),
246 FORMAT_OVERRIDE(skl_ccs_formats),
248 .modifier = I915_FORMAT_MOD_Yf_TILED,
249 .display_ver = { 9, 11 },
250 .plane_caps = INTEL_PLANE_CAP_TILING_Yf,
252 .modifier = I915_FORMAT_MOD_Y_TILED,
253 .display_ver = { 9, 13 },
254 .plane_caps = INTEL_PLANE_CAP_TILING_Y,
256 .modifier = I915_FORMAT_MOD_X_TILED,
257 .display_ver = DISPLAY_VER_ALL,
258 .plane_caps = INTEL_PLANE_CAP_TILING_X,
260 .modifier = DRM_FORMAT_MOD_LINEAR,
261 .display_ver = DISPLAY_VER_ALL,
265 static const struct intel_modifier_desc *lookup_modifier_or_null(u64 modifier)
269 for (i = 0; i < ARRAY_SIZE(intel_modifiers); i++)
270 if (intel_modifiers[i].modifier == modifier)
271 return &intel_modifiers[i];
276 static const struct intel_modifier_desc *lookup_modifier(u64 modifier)
278 const struct intel_modifier_desc *md = lookup_modifier_or_null(modifier);
281 return &intel_modifiers[0];
286 static const struct drm_format_info *
287 lookup_format_info(const struct drm_format_info formats[],
288 int num_formats, u32 format)
292 for (i = 0; i < num_formats; i++) {
293 if (formats[i].format == format)
301 * intel_fb_get_format_info: Get a modifier specific format information
302 * @cmd: FB add command structure
305 * Returns the format information for @cmd->pixel_format specific to @cmd->modifier[0],
306 * or %NULL if the modifier doesn't override the format.
308 const struct drm_format_info *
309 intel_fb_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
311 const struct intel_modifier_desc *md = lookup_modifier_or_null(cmd->modifier[0]);
313 if (!md || !md->formats)
316 return lookup_format_info(md->formats, md->format_count, cmd->pixel_format);
319 static bool plane_caps_contain_any(u8 caps, u8 mask)
324 static bool plane_caps_contain_all(u8 caps, u8 mask)
326 return (caps & mask) == mask;
330 * intel_fb_is_tiled_modifier: Check if a modifier is a tiled modifier type
331 * @modifier: Modifier to check
334 * Returns %true if @modifier is a tiled modifier.
336 bool intel_fb_is_tiled_modifier(u64 modifier)
338 return plane_caps_contain_any(lookup_modifier(modifier)->plane_caps,
339 INTEL_PLANE_CAP_TILING_MASK);
343 * intel_fb_is_ccs_modifier: Check if a modifier is a CCS modifier type
344 * @modifier: Modifier to check
347 * Returns %true if @modifier is a render, render with color clear or
348 * media compression modifier.
350 bool intel_fb_is_ccs_modifier(u64 modifier)
352 return plane_caps_contain_any(lookup_modifier(modifier)->plane_caps,
353 INTEL_PLANE_CAP_CCS_MASK);
357 * intel_fb_is_rc_ccs_cc_modifier: Check if a modifier is an RC CCS CC modifier type
358 * @modifier: Modifier to check
361 * Returns %true if @modifier is a render with color clear modifier.
363 bool intel_fb_is_rc_ccs_cc_modifier(u64 modifier)
365 return plane_caps_contain_any(lookup_modifier(modifier)->plane_caps,
366 INTEL_PLANE_CAP_CCS_RC_CC);
370 * intel_fb_is_mc_ccs_modifier: Check if a modifier is an MC CCS modifier type
371 * @modifier: Modifier to check
374 * Returns %true if @modifier is a media compression modifier.
376 bool intel_fb_is_mc_ccs_modifier(u64 modifier)
378 return plane_caps_contain_any(lookup_modifier(modifier)->plane_caps,
379 INTEL_PLANE_CAP_CCS_MC);
382 static bool check_modifier_display_ver_range(const struct intel_modifier_desc *md,
383 u8 display_ver_from, u8 display_ver_until)
385 return md->display_ver.from <= display_ver_until &&
386 display_ver_from <= md->display_ver.until;
389 static bool plane_has_modifier(struct drm_i915_private *i915,
391 const struct intel_modifier_desc *md)
393 if (!IS_DISPLAY_VER(i915, md->display_ver.from, md->display_ver.until))
396 if (!plane_caps_contain_all(plane_caps, md->plane_caps))
400 * Separate AuxCCS and Flat CCS modifiers to be run only on platforms
403 if (intel_fb_is_ccs_modifier(md->modifier) &&
404 HAS_FLAT_CCS(i915) != !md->ccs.packed_aux_planes)
411 * intel_fb_plane_get_modifiers: Get the modifiers for the given platform and plane capabilities
412 * @i915: i915 device instance
413 * @plane_caps: capabilities for the plane the modifiers are queried for
416 * Returns the list of modifiers allowed by the @i915 platform and @plane_caps.
417 * The caller must free the returned buffer.
419 u64 *intel_fb_plane_get_modifiers(struct drm_i915_private *i915,
423 int count = 1; /* +1 for invalid modifier terminator */
426 for (i = 0; i < ARRAY_SIZE(intel_modifiers); i++) {
427 if (plane_has_modifier(i915, plane_caps, &intel_modifiers[i]))
431 list = kmalloc_array(count, sizeof(*list), GFP_KERNEL);
432 if (drm_WARN_ON(&i915->drm, !list))
436 for (i = 0; i < ARRAY_SIZE(intel_modifiers); i++) {
437 if (plane_has_modifier(i915, plane_caps, &intel_modifiers[i]))
438 *p++ = intel_modifiers[i].modifier;
440 *p++ = DRM_FORMAT_MOD_INVALID;
446 * intel_fb_plane_supports_modifier: Determine if a modifier is supported by the given plane
447 * @plane: Plane to check the modifier support for
448 * @modifier: The modifier to check the support for
451 * %true if the @modifier is supported on @plane.
453 bool intel_fb_plane_supports_modifier(struct intel_plane *plane, u64 modifier)
457 for (i = 0; i < plane->base.modifier_count; i++)
458 if (plane->base.modifiers[i] == modifier)
464 static bool format_is_yuv_semiplanar(const struct intel_modifier_desc *md,
465 const struct drm_format_info *info)
470 if (hweight8(md->ccs.planar_aux_planes) == 2)
471 return info->num_planes == 4;
473 return info->num_planes == 2;
477 * intel_format_info_is_yuv_semiplanar: Check if the given format is YUV semiplanar
478 * @info: format to check
479 * @modifier: modifier used with the format
482 * %true if @info / @modifier is YUV semiplanar.
484 bool intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
487 return format_is_yuv_semiplanar(lookup_modifier(modifier), info);
490 static u8 ccs_aux_plane_mask(const struct intel_modifier_desc *md,
491 const struct drm_format_info *format)
493 if (format_is_yuv_semiplanar(md, format))
494 return md->ccs.planar_aux_planes;
496 return md->ccs.packed_aux_planes;
500 * intel_fb_is_ccs_aux_plane: Check if a framebuffer color plane is a CCS AUX plane
502 * @color_plane: color plane index to check
505 * Returns %true if @fb's color plane at index @color_plane is a CCS AUX plane.
507 bool intel_fb_is_ccs_aux_plane(const struct drm_framebuffer *fb, int color_plane)
509 const struct intel_modifier_desc *md = lookup_modifier(fb->modifier);
511 return ccs_aux_plane_mask(md, fb->format) & BIT(color_plane);
515 * intel_fb_is_gen12_ccs_aux_plane: Check if a framebuffer color plane is a GEN12 CCS AUX plane
517 * @color_plane: color plane index to check
520 * Returns %true if @fb's color plane at index @color_plane is a GEN12 CCS AUX plane.
522 static bool intel_fb_is_gen12_ccs_aux_plane(const struct drm_framebuffer *fb, int color_plane)
524 const struct intel_modifier_desc *md = lookup_modifier(fb->modifier);
526 return check_modifier_display_ver_range(md, 12, 14) &&
527 ccs_aux_plane_mask(md, fb->format) & BIT(color_plane);
531 * intel_fb_rc_ccs_cc_plane: Get the CCS CC color plane index for a framebuffer
535 * Returns the index of the color clear plane for @fb, or -1 if @fb is not a
536 * framebuffer using a render compression/color clear modifier.
538 int intel_fb_rc_ccs_cc_plane(const struct drm_framebuffer *fb)
540 const struct intel_modifier_desc *md = lookup_modifier(fb->modifier);
542 if (!md->ccs.cc_planes)
545 drm_WARN_ON_ONCE(fb->dev, hweight8(md->ccs.cc_planes) > 1);
547 return ilog2((int)md->ccs.cc_planes);
550 static bool is_gen12_ccs_cc_plane(const struct drm_framebuffer *fb, int color_plane)
552 return intel_fb_rc_ccs_cc_plane(fb) == color_plane;
555 static bool is_semiplanar_uv_plane(const struct drm_framebuffer *fb, int color_plane)
557 return intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
561 bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
563 return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
564 intel_fb_is_gen12_ccs_aux_plane(fb, color_plane) ||
565 is_gen12_ccs_cc_plane(fb, color_plane);
568 int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
570 drm_WARN_ON(fb->dev, !intel_fb_is_ccs_modifier(fb->modifier) ||
571 (main_plane && main_plane >= fb->format->num_planes / 2));
573 return fb->format->num_planes / 2 + main_plane;
576 int skl_ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
578 drm_WARN_ON(fb->dev, !intel_fb_is_ccs_modifier(fb->modifier) ||
579 ccs_plane < fb->format->num_planes / 2);
581 if (is_gen12_ccs_cc_plane(fb, ccs_plane))
584 return ccs_plane - fb->format->num_planes / 2;
587 static unsigned int gen12_ccs_aux_stride(struct intel_framebuffer *fb, int ccs_plane)
589 int main_plane = skl_ccs_to_main_plane(&fb->base, ccs_plane);
590 unsigned int main_stride = fb->base.pitches[main_plane];
591 unsigned int main_tile_width = intel_tile_width_bytes(&fb->base, main_plane);
593 return DIV_ROUND_UP(main_stride, 4 * main_tile_width) * 64;
596 int skl_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
598 const struct intel_modifier_desc *md = lookup_modifier(fb->modifier);
599 struct drm_i915_private *i915 = to_i915(fb->dev);
601 if (md->ccs.packed_aux_planes | md->ccs.planar_aux_planes)
602 return main_to_ccs_plane(fb, main_plane);
603 else if (DISPLAY_VER(i915) < 11 &&
604 format_is_yuv_semiplanar(md, fb->format))
610 unsigned int intel_tile_size(const struct drm_i915_private *i915)
612 return DISPLAY_VER(i915) == 2 ? 2048 : 4096;
616 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
618 struct drm_i915_private *dev_priv = to_i915(fb->dev);
619 unsigned int cpp = fb->format->cpp[color_plane];
621 switch (fb->modifier) {
622 case DRM_FORMAT_MOD_LINEAR:
623 return intel_tile_size(dev_priv);
624 case I915_FORMAT_MOD_X_TILED:
625 if (DISPLAY_VER(dev_priv) == 2)
629 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS:
630 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC:
631 case I915_FORMAT_MOD_4_TILED_DG2_MC_CCS:
632 case I915_FORMAT_MOD_4_TILED:
634 * Each 4K tile consists of 64B(8*8) subtiles, with
635 * same shape as Y Tile(i.e 4*16B OWords)
638 case I915_FORMAT_MOD_Y_TILED_CCS:
639 if (intel_fb_is_ccs_aux_plane(fb, color_plane))
642 case I915_FORMAT_MOD_4_TILED_MTL_RC_CCS:
643 case I915_FORMAT_MOD_4_TILED_MTL_RC_CCS_CC:
644 case I915_FORMAT_MOD_4_TILED_MTL_MC_CCS:
645 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
646 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
647 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
648 if (intel_fb_is_ccs_aux_plane(fb, color_plane) ||
649 is_gen12_ccs_cc_plane(fb, color_plane))
652 case I915_FORMAT_MOD_Y_TILED:
653 if (DISPLAY_VER(dev_priv) == 2 || HAS_128_BYTE_Y_TILING(dev_priv))
657 case I915_FORMAT_MOD_Yf_TILED_CCS:
658 if (intel_fb_is_ccs_aux_plane(fb, color_plane))
661 case I915_FORMAT_MOD_Yf_TILED:
677 MISSING_CASE(fb->modifier);
682 unsigned int intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
684 return intel_tile_size(to_i915(fb->dev)) /
685 intel_tile_width_bytes(fb, color_plane);
689 * Return the tile dimensions in pixel units, based on the (2 or 4 kbyte) GTT
692 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
693 unsigned int *tile_width,
694 unsigned int *tile_height)
696 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
697 unsigned int cpp = fb->format->cpp[color_plane];
699 *tile_width = tile_width_bytes / cpp;
700 *tile_height = intel_tile_height(fb, color_plane);
704 * Return the tile dimensions in pixel units, based on the tile block size.
705 * The block covers the full GTT page sized tile on all tiled surfaces and
706 * it's a 64 byte portion of the tile on TGL+ CCS surfaces.
708 static void intel_tile_block_dims(const struct drm_framebuffer *fb, int color_plane,
709 unsigned int *tile_width,
710 unsigned int *tile_height)
712 intel_tile_dims(fb, color_plane, tile_width, tile_height);
714 if (intel_fb_is_gen12_ccs_aux_plane(fb, color_plane))
718 unsigned int intel_tile_row_size(const struct drm_framebuffer *fb, int color_plane)
720 unsigned int tile_width, tile_height;
722 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
724 return fb->pitches[color_plane] * tile_height;
728 intel_fb_align_height(const struct drm_framebuffer *fb,
729 int color_plane, unsigned int height)
731 unsigned int tile_height = intel_tile_height(fb, color_plane);
733 return ALIGN(height, tile_height);
736 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
738 u8 tiling_caps = lookup_modifier(fb_modifier)->plane_caps &
739 INTEL_PLANE_CAP_TILING_MASK;
741 switch (tiling_caps) {
742 case INTEL_PLANE_CAP_TILING_Y:
743 return I915_TILING_Y;
744 case INTEL_PLANE_CAP_TILING_X:
745 return I915_TILING_X;
746 case INTEL_PLANE_CAP_TILING_4:
747 case INTEL_PLANE_CAP_TILING_Yf:
748 case INTEL_PLANE_CAP_TILING_NONE:
749 return I915_TILING_NONE;
751 MISSING_CASE(tiling_caps);
752 return I915_TILING_NONE;
756 bool intel_fb_modifier_uses_dpt(struct drm_i915_private *i915, u64 modifier)
758 return HAS_DPT(i915) && modifier != DRM_FORMAT_MOD_LINEAR;
761 bool intel_fb_uses_dpt(const struct drm_framebuffer *fb)
763 return fb && to_i915(fb->dev)->params.enable_dpt &&
764 intel_fb_modifier_uses_dpt(to_i915(fb->dev), fb->modifier);
767 unsigned int intel_cursor_alignment(const struct drm_i915_private *i915)
771 else if (IS_I85X(i915))
773 else if (IS_I845G(i915) || IS_I865G(i915))
779 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
781 if (DISPLAY_VER(dev_priv) >= 9)
783 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
784 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
786 else if (DISPLAY_VER(dev_priv) >= 4)
792 unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
795 struct drm_i915_private *dev_priv = to_i915(fb->dev);
797 if (intel_fb_uses_dpt(fb))
800 /* AUX_DIST needs only 4K alignment */
801 if (intel_fb_is_ccs_aux_plane(fb, color_plane))
804 if (is_semiplanar_uv_plane(fb, color_plane)) {
806 * TODO: cross-check wrt. the bspec stride in bytes * 64 bytes
807 * alignment for linear UV planes on all platforms.
809 if (DISPLAY_VER(dev_priv) >= 12) {
810 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
811 return intel_linear_alignment(dev_priv);
813 return intel_tile_row_size(fb, color_plane);
819 drm_WARN_ON(&dev_priv->drm, color_plane != 0);
821 switch (fb->modifier) {
822 case DRM_FORMAT_MOD_LINEAR:
823 return intel_linear_alignment(dev_priv);
824 case I915_FORMAT_MOD_X_TILED:
825 if (HAS_ASYNC_FLIPS(dev_priv))
828 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
829 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
830 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
831 case I915_FORMAT_MOD_4_TILED_MTL_MC_CCS:
832 case I915_FORMAT_MOD_4_TILED_MTL_RC_CCS:
833 case I915_FORMAT_MOD_4_TILED_MTL_RC_CCS_CC:
835 case I915_FORMAT_MOD_Y_TILED_CCS:
836 case I915_FORMAT_MOD_Yf_TILED_CCS:
837 case I915_FORMAT_MOD_Y_TILED:
838 case I915_FORMAT_MOD_4_TILED:
839 case I915_FORMAT_MOD_Yf_TILED:
840 return 1 * 1024 * 1024;
841 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS:
842 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC:
843 case I915_FORMAT_MOD_4_TILED_DG2_MC_CCS:
846 MISSING_CASE(fb->modifier);
851 void intel_fb_plane_get_subsampling(int *hsub, int *vsub,
852 const struct drm_framebuffer *fb,
857 if (color_plane == 0) {
865 * TODO: Deduct the subsampling from the char block for all CCS
866 * formats and planes.
868 if (!intel_fb_is_gen12_ccs_aux_plane(fb, color_plane)) {
869 *hsub = fb->format->hsub;
870 *vsub = fb->format->vsub;
875 main_plane = skl_ccs_to_main_plane(fb, color_plane);
876 *hsub = drm_format_info_block_width(fb->format, color_plane) /
877 drm_format_info_block_width(fb->format, main_plane);
880 * The min stride check in the core framebuffer_check() function
881 * assumes that format->hsub applies to every plane except for the
882 * first plane. That's incorrect for the CCS AUX plane of the first
883 * plane, but for the above check to pass we must define the block
884 * width with that subsampling applied to it. Adjust the width here
885 * accordingly, so we can calculate the actual subsampling factor.
888 *hsub *= fb->format->hsub;
893 static void intel_fb_plane_dims(const struct intel_framebuffer *fb, int color_plane, int *w, int *h)
895 int main_plane = intel_fb_is_ccs_aux_plane(&fb->base, color_plane) ?
896 skl_ccs_to_main_plane(&fb->base, color_plane) : 0;
897 unsigned int main_width = fb->base.width;
898 unsigned int main_height = fb->base.height;
899 int main_hsub, main_vsub;
902 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, &fb->base, main_plane);
903 intel_fb_plane_get_subsampling(&hsub, &vsub, &fb->base, color_plane);
905 *w = DIV_ROUND_UP(main_width, main_hsub * hsub);
906 *h = DIV_ROUND_UP(main_height, main_vsub * vsub);
909 static u32 intel_adjust_tile_offset(int *x, int *y,
910 unsigned int tile_width,
911 unsigned int tile_height,
912 unsigned int tile_size,
913 unsigned int pitch_tiles,
917 unsigned int pitch_pixels = pitch_tiles * tile_width;
920 WARN_ON(old_offset & (tile_size - 1));
921 WARN_ON(new_offset & (tile_size - 1));
922 WARN_ON(new_offset > old_offset);
924 tiles = (old_offset - new_offset) / tile_size;
926 *y += tiles / pitch_tiles * tile_height;
927 *x += tiles % pitch_tiles * tile_width;
929 /* minimize x in case it got needlessly big */
930 *y += *x / pitch_pixels * tile_height;
936 static u32 intel_adjust_linear_offset(int *x, int *y,
942 old_offset += *y * pitch + *x * cpp;
944 *y = (old_offset - new_offset) / pitch;
945 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
950 static u32 intel_adjust_aligned_offset(int *x, int *y,
951 const struct drm_framebuffer *fb,
953 unsigned int rotation,
955 u32 old_offset, u32 new_offset)
957 struct drm_i915_private *i915 = to_i915(fb->dev);
958 unsigned int cpp = fb->format->cpp[color_plane];
960 drm_WARN_ON(&i915->drm, new_offset > old_offset);
962 if (!is_surface_linear(fb, color_plane)) {
963 unsigned int tile_size, tile_width, tile_height;
964 unsigned int pitch_tiles;
966 tile_size = intel_tile_size(i915);
967 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
969 if (drm_rotation_90_or_270(rotation)) {
970 pitch_tiles = pitch / tile_height;
971 swap(tile_width, tile_height);
973 pitch_tiles = pitch / (tile_width * cpp);
976 intel_adjust_tile_offset(x, y, tile_width, tile_height,
977 tile_size, pitch_tiles,
978 old_offset, new_offset);
980 intel_adjust_linear_offset(x, y, cpp, pitch,
981 old_offset, new_offset);
988 * Adjust the tile offset by moving the difference into
991 u32 intel_plane_adjust_aligned_offset(int *x, int *y,
992 const struct intel_plane_state *state,
994 u32 old_offset, u32 new_offset)
996 return intel_adjust_aligned_offset(x, y, state->hw.fb, color_plane,
998 state->view.color_plane[color_plane].mapping_stride,
999 old_offset, new_offset);
1003 * Computes the aligned offset to the base tile and adjusts
1004 * x, y. bytes per pixel is assumed to be a power-of-two.
1006 * In the 90/270 rotated case, x and y are assumed
1007 * to be already rotated to match the rotated GTT view, and
1008 * pitch is the tile_height aligned framebuffer height.
1010 * This function is used when computing the derived information
1011 * under intel_framebuffer, so using any of that information
1012 * here is not allowed. Anything under drm_framebuffer can be
1013 * used. This is why the user has to pass in the pitch since it
1014 * is specified in the rotated orientation.
1016 static u32 intel_compute_aligned_offset(struct drm_i915_private *i915,
1018 const struct drm_framebuffer *fb,
1021 unsigned int rotation,
1024 unsigned int cpp = fb->format->cpp[color_plane];
1025 u32 offset, offset_aligned;
1027 if (!is_surface_linear(fb, color_plane)) {
1028 unsigned int tile_size, tile_width, tile_height;
1029 unsigned int tile_rows, tiles, pitch_tiles;
1031 tile_size = intel_tile_size(i915);
1032 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
1034 if (drm_rotation_90_or_270(rotation)) {
1035 pitch_tiles = pitch / tile_height;
1036 swap(tile_width, tile_height);
1038 pitch_tiles = pitch / (tile_width * cpp);
1041 tile_rows = *y / tile_height;
1044 tiles = *x / tile_width;
1047 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
1049 offset_aligned = offset;
1051 offset_aligned = rounddown(offset_aligned, alignment);
1053 intel_adjust_tile_offset(x, y, tile_width, tile_height,
1054 tile_size, pitch_tiles,
1055 offset, offset_aligned);
1057 offset = *y * pitch + *x * cpp;
1058 offset_aligned = offset;
1060 offset_aligned = rounddown(offset_aligned, alignment);
1061 *y = (offset % alignment) / pitch;
1062 *x = ((offset % alignment) - *y * pitch) / cpp;
1068 return offset_aligned;
1071 u32 intel_plane_compute_aligned_offset(int *x, int *y,
1072 const struct intel_plane_state *state,
1075 struct intel_plane *intel_plane = to_intel_plane(state->uapi.plane);
1076 struct drm_i915_private *i915 = to_i915(intel_plane->base.dev);
1077 const struct drm_framebuffer *fb = state->hw.fb;
1078 unsigned int rotation = state->hw.rotation;
1079 int pitch = state->view.color_plane[color_plane].mapping_stride;
1082 if (intel_plane->id == PLANE_CURSOR)
1083 alignment = intel_cursor_alignment(i915);
1085 alignment = intel_surf_alignment(fb, color_plane);
1087 return intel_compute_aligned_offset(i915, x, y, fb, color_plane,
1088 pitch, rotation, alignment);
1091 /* Convert the fb->offset[] into x/y offsets */
1092 static int intel_fb_offset_to_xy(int *x, int *y,
1093 const struct drm_framebuffer *fb,
1096 struct drm_i915_private *i915 = to_i915(fb->dev);
1097 unsigned int height;
1100 if (DISPLAY_VER(i915) >= 12 &&
1101 !intel_fb_needs_pot_stride_remap(to_intel_framebuffer(fb)) &&
1102 is_semiplanar_uv_plane(fb, color_plane))
1103 alignment = intel_tile_row_size(fb, color_plane);
1104 else if (fb->modifier != DRM_FORMAT_MOD_LINEAR)
1105 alignment = intel_tile_size(i915);
1109 if (alignment != 0 && fb->offsets[color_plane] % alignment) {
1110 drm_dbg_kms(&i915->drm,
1111 "Misaligned offset 0x%08x for color plane %d\n",
1112 fb->offsets[color_plane], color_plane);
1116 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
1117 height = ALIGN(height, intel_tile_height(fb, color_plane));
1119 /* Catch potential overflows early */
1120 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
1121 fb->offsets[color_plane])) {
1122 drm_dbg_kms(&i915->drm,
1123 "Bad offset 0x%08x or pitch %d for color plane %d\n",
1124 fb->offsets[color_plane], fb->pitches[color_plane],
1132 intel_adjust_aligned_offset(x, y,
1133 fb, color_plane, DRM_MODE_ROTATE_0,
1134 fb->pitches[color_plane],
1135 fb->offsets[color_plane], 0);
1140 static int intel_fb_check_ccs_xy(const struct drm_framebuffer *fb, int ccs_plane, int x, int y)
1142 struct drm_i915_private *i915 = to_i915(fb->dev);
1143 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
1146 int tile_width, tile_height;
1150 if (!intel_fb_is_ccs_aux_plane(fb, ccs_plane))
1154 * While all the tile dimensions are based on a 2k or 4k GTT page size
1155 * here the main and CCS coordinates must match only within a (64 byte
1156 * on TGL+) block inside the tile.
1158 intel_tile_block_dims(fb, ccs_plane, &tile_width, &tile_height);
1159 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
1162 tile_height *= vsub;
1164 ccs_x = (x * hsub) % tile_width;
1165 ccs_y = (y * vsub) % tile_height;
1167 main_plane = skl_ccs_to_main_plane(fb, ccs_plane);
1168 main_x = intel_fb->normal_view.color_plane[main_plane].x % tile_width;
1169 main_y = intel_fb->normal_view.color_plane[main_plane].y % tile_height;
1172 * CCS doesn't have its own x/y offset register, so the intra CCS tile
1173 * x/y offsets must match between CCS and the main surface.
1175 if (main_x != ccs_x || main_y != ccs_y) {
1176 drm_dbg_kms(&i915->drm,
1177 "Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
1180 intel_fb->normal_view.color_plane[main_plane].x,
1181 intel_fb->normal_view.color_plane[main_plane].y,
1189 static bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
1191 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1192 struct drm_i915_private *i915 = to_i915(plane->base.dev);
1193 const struct drm_framebuffer *fb = plane_state->hw.fb;
1196 /* We don't want to deal with remapping with cursors */
1197 if (plane->id == PLANE_CURSOR)
1201 * The display engine limits already match/exceed the
1202 * render engine limits, so not much point in remapping.
1203 * Would also need to deal with the fence POT alignment
1204 * and gen2 2KiB GTT tile size.
1206 if (DISPLAY_VER(i915) < 4)
1210 * The new CCS hash mode isn't compatible with remapping as
1211 * the virtual address of the pages affects the compressed data.
1213 if (intel_fb_is_ccs_modifier(fb->modifier))
1216 /* Linear needs a page aligned stride for remapping */
1217 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
1218 unsigned int alignment = intel_tile_size(i915) - 1;
1220 for (i = 0; i < fb->format->num_planes; i++) {
1221 if (fb->pitches[i] & alignment)
1229 bool intel_fb_needs_pot_stride_remap(const struct intel_framebuffer *fb)
1231 struct drm_i915_private *i915 = to_i915(fb->base.dev);
1233 return (IS_ALDERLAKE_P(i915) || DISPLAY_VER(i915) >= 14) &&
1234 intel_fb_uses_dpt(&fb->base);
1237 static int intel_fb_pitch(const struct intel_framebuffer *fb, int color_plane, unsigned int rotation)
1239 if (drm_rotation_90_or_270(rotation))
1240 return fb->rotated_view.color_plane[color_plane].mapping_stride;
1241 else if (intel_fb_needs_pot_stride_remap(fb))
1242 return fb->remapped_view.color_plane[color_plane].mapping_stride;
1244 return fb->normal_view.color_plane[color_plane].mapping_stride;
1247 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
1249 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1250 const struct intel_framebuffer *fb = to_intel_framebuffer(plane_state->hw.fb);
1251 unsigned int rotation = plane_state->hw.rotation;
1252 u32 stride, max_stride;
1255 * No remapping for invisible planes since we don't have
1256 * an actual source viewport to remap.
1258 if (!plane_state->uapi.visible)
1261 if (!intel_plane_can_remap(plane_state))
1265 * FIXME: aux plane limits on gen9+ are
1266 * unclear in Bspec, for now no checking.
1268 stride = intel_fb_pitch(fb, 0, rotation);
1269 max_stride = plane->max_stride(plane, fb->base.format->format,
1270 fb->base.modifier, rotation);
1272 return stride > max_stride;
1275 static int convert_plane_offset_to_xy(const struct intel_framebuffer *fb, int color_plane,
1276 int plane_width, int *x, int *y)
1278 struct drm_i915_gem_object *obj = intel_fb_obj(&fb->base);
1281 ret = intel_fb_offset_to_xy(x, y, &fb->base, color_plane);
1283 drm_dbg_kms(fb->base.dev,
1284 "bad fb plane %d offset: 0x%x\n",
1285 color_plane, fb->base.offsets[color_plane]);
1289 ret = intel_fb_check_ccs_xy(&fb->base, color_plane, *x, *y);
1294 * The fence (if used) is aligned to the start of the object
1295 * so having the framebuffer wrap around across the edge of the
1296 * fenced region doesn't really work. We have no API to configure
1297 * the fence start offset within the object (nor could we probably
1298 * on gen2/3). So it's just easier if we just require that the
1299 * fb layout agrees with the fence layout. We already check that the
1300 * fb stride matches the fence stride elsewhere.
1302 if (color_plane == 0 && i915_gem_object_is_tiled(obj) &&
1303 (*x + plane_width) * fb->base.format->cpp[color_plane] > fb->base.pitches[color_plane]) {
1304 drm_dbg_kms(fb->base.dev,
1305 "bad fb plane %d offset: 0x%x\n",
1306 color_plane, fb->base.offsets[color_plane]);
1313 static u32 calc_plane_aligned_offset(const struct intel_framebuffer *fb, int color_plane, int *x, int *y)
1315 struct drm_i915_private *i915 = to_i915(fb->base.dev);
1316 unsigned int tile_size = intel_tile_size(i915);
1319 offset = intel_compute_aligned_offset(i915, x, y, &fb->base, color_plane,
1320 fb->base.pitches[color_plane],
1324 return offset / tile_size;
1327 struct fb_plane_view_dims {
1328 unsigned int width, height;
1329 unsigned int tile_width, tile_height;
1332 static void init_plane_view_dims(const struct intel_framebuffer *fb, int color_plane,
1333 unsigned int width, unsigned int height,
1334 struct fb_plane_view_dims *dims)
1336 dims->width = width;
1337 dims->height = height;
1339 intel_tile_dims(&fb->base, color_plane, &dims->tile_width, &dims->tile_height);
1343 plane_view_src_stride_tiles(const struct intel_framebuffer *fb, int color_plane,
1344 const struct fb_plane_view_dims *dims)
1346 return DIV_ROUND_UP(fb->base.pitches[color_plane],
1347 dims->tile_width * fb->base.format->cpp[color_plane]);
1351 plane_view_dst_stride_tiles(const struct intel_framebuffer *fb, int color_plane,
1352 unsigned int pitch_tiles)
1354 if (intel_fb_needs_pot_stride_remap(fb)) {
1356 * ADL_P, the only platform needing a POT stride has a minimum
1357 * of 8 main surface tiles.
1359 return roundup_pow_of_two(max(pitch_tiles, 8u));
1366 plane_view_scanout_stride(const struct intel_framebuffer *fb, int color_plane,
1367 unsigned int tile_width,
1368 unsigned int src_stride_tiles, unsigned int dst_stride_tiles)
1370 struct drm_i915_private *i915 = to_i915(fb->base.dev);
1371 unsigned int stride_tiles;
1373 if (IS_ALDERLAKE_P(i915) || DISPLAY_VER(i915) >= 14)
1374 stride_tiles = src_stride_tiles;
1376 stride_tiles = dst_stride_tiles;
1378 return stride_tiles * tile_width * fb->base.format->cpp[color_plane];
1382 plane_view_width_tiles(const struct intel_framebuffer *fb, int color_plane,
1383 const struct fb_plane_view_dims *dims,
1386 return DIV_ROUND_UP(x + dims->width, dims->tile_width);
1390 plane_view_height_tiles(const struct intel_framebuffer *fb, int color_plane,
1391 const struct fb_plane_view_dims *dims,
1394 return DIV_ROUND_UP(y + dims->height, dims->tile_height);
1398 plane_view_linear_tiles(const struct intel_framebuffer *fb, int color_plane,
1399 const struct fb_plane_view_dims *dims,
1402 struct drm_i915_private *i915 = to_i915(fb->base.dev);
1405 size = (y + dims->height) * fb->base.pitches[color_plane] +
1406 x * fb->base.format->cpp[color_plane];
1408 return DIV_ROUND_UP(size, intel_tile_size(i915));
1411 #define assign_chk_ovf(i915, var, val) ({ \
1412 drm_WARN_ON(&(i915)->drm, overflows_type(val, var)); \
1416 #define assign_bfld_chk_ovf(i915, var, val) ({ \
1418 drm_WARN_ON(&(i915)->drm, (var) != (val)); \
1422 static u32 calc_plane_remap_info(const struct intel_framebuffer *fb, int color_plane,
1423 const struct fb_plane_view_dims *dims,
1424 u32 obj_offset, u32 gtt_offset, int x, int y,
1425 struct intel_fb_view *view)
1427 struct drm_i915_private *i915 = to_i915(fb->base.dev);
1428 struct intel_remapped_plane_info *remap_info = &view->gtt.remapped.plane[color_plane];
1429 struct i915_color_plane_view *color_plane_info = &view->color_plane[color_plane];
1430 unsigned int tile_width = dims->tile_width;
1431 unsigned int tile_height = dims->tile_height;
1432 unsigned int tile_size = intel_tile_size(i915);
1436 assign_bfld_chk_ovf(i915, remap_info->offset, obj_offset);
1438 if (intel_fb_is_gen12_ccs_aux_plane(&fb->base, color_plane)) {
1439 remap_info->linear = 1;
1441 assign_chk_ovf(i915, remap_info->size,
1442 plane_view_linear_tiles(fb, color_plane, dims, x, y));
1444 remap_info->linear = 0;
1446 assign_chk_ovf(i915, remap_info->src_stride,
1447 plane_view_src_stride_tiles(fb, color_plane, dims));
1448 assign_chk_ovf(i915, remap_info->width,
1449 plane_view_width_tiles(fb, color_plane, dims, x));
1450 assign_chk_ovf(i915, remap_info->height,
1451 plane_view_height_tiles(fb, color_plane, dims, y));
1454 if (view->gtt.type == I915_GTT_VIEW_ROTATED) {
1455 drm_WARN_ON(&i915->drm, remap_info->linear);
1456 check_array_bounds(i915, view->gtt.rotated.plane, color_plane);
1458 assign_chk_ovf(i915, remap_info->dst_stride,
1459 plane_view_dst_stride_tiles(fb, color_plane, remap_info->height));
1461 /* rotate the x/y offsets to match the GTT view */
1462 drm_rect_init(&r, x, y, dims->width, dims->height);
1464 remap_info->width * tile_width,
1465 remap_info->height * tile_height,
1466 DRM_MODE_ROTATE_270);
1468 color_plane_info->x = r.x1;
1469 color_plane_info->y = r.y1;
1471 color_plane_info->mapping_stride = remap_info->dst_stride * tile_height;
1472 color_plane_info->scanout_stride = color_plane_info->mapping_stride;
1474 size += remap_info->dst_stride * remap_info->width;
1476 /* rotate the tile dimensions to match the GTT view */
1477 swap(tile_width, tile_height);
1479 drm_WARN_ON(&i915->drm, view->gtt.type != I915_GTT_VIEW_REMAPPED);
1481 check_array_bounds(i915, view->gtt.remapped.plane, color_plane);
1483 if (view->gtt.remapped.plane_alignment) {
1484 unsigned int aligned_offset = ALIGN(gtt_offset,
1485 view->gtt.remapped.plane_alignment);
1487 size += aligned_offset - gtt_offset;
1488 gtt_offset = aligned_offset;
1491 color_plane_info->x = x;
1492 color_plane_info->y = y;
1494 if (remap_info->linear) {
1495 color_plane_info->mapping_stride = fb->base.pitches[color_plane];
1496 color_plane_info->scanout_stride = color_plane_info->mapping_stride;
1498 size += remap_info->size;
1500 unsigned int dst_stride = plane_view_dst_stride_tiles(fb, color_plane,
1503 assign_chk_ovf(i915, remap_info->dst_stride, dst_stride);
1504 color_plane_info->mapping_stride = dst_stride *
1506 fb->base.format->cpp[color_plane];
1507 color_plane_info->scanout_stride =
1508 plane_view_scanout_stride(fb, color_plane, tile_width,
1509 remap_info->src_stride,
1512 size += dst_stride * remap_info->height;
1517 * We only keep the x/y offsets, so push all of the gtt offset into
1518 * the x/y offsets. x,y will hold the first pixel of the framebuffer
1519 * plane from the start of the remapped/rotated gtt mapping.
1521 if (remap_info->linear)
1522 intel_adjust_linear_offset(&color_plane_info->x, &color_plane_info->y,
1523 fb->base.format->cpp[color_plane],
1524 color_plane_info->mapping_stride,
1525 gtt_offset * tile_size, 0);
1527 intel_adjust_tile_offset(&color_plane_info->x, &color_plane_info->y,
1528 tile_width, tile_height,
1529 tile_size, remap_info->dst_stride,
1530 gtt_offset * tile_size, 0);
1535 #undef assign_chk_ovf
1537 /* Return number of tiles @color_plane needs. */
1539 calc_plane_normal_size(const struct intel_framebuffer *fb, int color_plane,
1540 const struct fb_plane_view_dims *dims,
1545 if (is_surface_linear(&fb->base, color_plane)) {
1546 tiles = plane_view_linear_tiles(fb, color_plane, dims, x, y);
1548 tiles = plane_view_src_stride_tiles(fb, color_plane, dims) *
1549 plane_view_height_tiles(fb, color_plane, dims, y);
1551 * If the plane isn't horizontally tile aligned,
1552 * we need one more tile.
1561 static void intel_fb_view_init(struct drm_i915_private *i915, struct intel_fb_view *view,
1562 enum i915_gtt_view_type view_type)
1564 memset(view, 0, sizeof(*view));
1565 view->gtt.type = view_type;
1567 if (view_type == I915_GTT_VIEW_REMAPPED &&
1568 (IS_ALDERLAKE_P(i915) || DISPLAY_VER(i915) >= 14))
1569 view->gtt.remapped.plane_alignment = SZ_2M / PAGE_SIZE;
1572 bool intel_fb_supports_90_270_rotation(const struct intel_framebuffer *fb)
1574 if (DISPLAY_VER(to_i915(fb->base.dev)) >= 13)
1577 return fb->base.modifier == I915_FORMAT_MOD_Y_TILED ||
1578 fb->base.modifier == I915_FORMAT_MOD_Yf_TILED;
1581 int intel_fill_fb_info(struct drm_i915_private *i915, struct intel_framebuffer *fb)
1583 struct drm_i915_gem_object *obj = intel_fb_obj(&fb->base);
1584 u32 gtt_offset_rotated = 0;
1585 u32 gtt_offset_remapped = 0;
1586 unsigned int max_size = 0;
1587 int i, num_planes = fb->base.format->num_planes;
1588 unsigned int tile_size = intel_tile_size(i915);
1590 intel_fb_view_init(i915, &fb->normal_view, I915_GTT_VIEW_NORMAL);
1592 drm_WARN_ON(&i915->drm,
1593 intel_fb_supports_90_270_rotation(fb) &&
1594 intel_fb_needs_pot_stride_remap(fb));
1596 if (intel_fb_supports_90_270_rotation(fb))
1597 intel_fb_view_init(i915, &fb->rotated_view, I915_GTT_VIEW_ROTATED);
1598 if (intel_fb_needs_pot_stride_remap(fb))
1599 intel_fb_view_init(i915, &fb->remapped_view, I915_GTT_VIEW_REMAPPED);
1601 for (i = 0; i < num_planes; i++) {
1602 struct fb_plane_view_dims view_dims;
1603 unsigned int width, height;
1604 unsigned int cpp, size;
1610 * Plane 2 of Render Compression with Clear Color fb modifier
1611 * is consumed by the driver and not passed to DE. Skip the
1612 * arithmetic related to alignment and offset calculation.
1614 if (is_gen12_ccs_cc_plane(&fb->base, i)) {
1615 if (IS_ALIGNED(fb->base.offsets[i], PAGE_SIZE))
1621 cpp = fb->base.format->cpp[i];
1622 intel_fb_plane_dims(fb, i, &width, &height);
1624 ret = convert_plane_offset_to_xy(fb, i, width, &x, &y);
1628 init_plane_view_dims(fb, i, width, height, &view_dims);
1631 * First pixel of the framebuffer from
1632 * the start of the normal gtt mapping.
1634 fb->normal_view.color_plane[i].x = x;
1635 fb->normal_view.color_plane[i].y = y;
1636 fb->normal_view.color_plane[i].mapping_stride = fb->base.pitches[i];
1637 fb->normal_view.color_plane[i].scanout_stride =
1638 fb->normal_view.color_plane[i].mapping_stride;
1640 offset = calc_plane_aligned_offset(fb, i, &x, &y);
1642 if (intel_fb_supports_90_270_rotation(fb))
1643 gtt_offset_rotated += calc_plane_remap_info(fb, i, &view_dims,
1644 offset, gtt_offset_rotated, x, y,
1647 if (intel_fb_needs_pot_stride_remap(fb))
1648 gtt_offset_remapped += calc_plane_remap_info(fb, i, &view_dims,
1649 offset, gtt_offset_remapped, x, y,
1650 &fb->remapped_view);
1652 size = calc_plane_normal_size(fb, i, &view_dims, x, y);
1653 /* how many tiles in total needed in the bo */
1654 max_size = max(max_size, offset + size);
1657 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
1658 drm_dbg_kms(&i915->drm,
1659 "fb too big for bo (need %llu bytes, have %zu bytes)\n",
1660 mul_u32_u32(max_size, tile_size), obj->base.size);
1667 static void intel_plane_remap_gtt(struct intel_plane_state *plane_state)
1669 struct drm_i915_private *i915 =
1670 to_i915(plane_state->uapi.plane->dev);
1671 struct drm_framebuffer *fb = plane_state->hw.fb;
1672 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
1673 unsigned int rotation = plane_state->hw.rotation;
1674 int i, num_planes = fb->format->num_planes;
1675 unsigned int src_x, src_y;
1676 unsigned int src_w, src_h;
1679 intel_fb_view_init(i915, &plane_state->view,
1680 drm_rotation_90_or_270(rotation) ? I915_GTT_VIEW_ROTATED :
1681 I915_GTT_VIEW_REMAPPED);
1683 src_x = plane_state->uapi.src.x1 >> 16;
1684 src_y = plane_state->uapi.src.y1 >> 16;
1685 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1686 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1688 drm_WARN_ON(&i915->drm, intel_fb_is_ccs_modifier(fb->modifier));
1690 /* Make src coordinates relative to the viewport */
1691 drm_rect_translate(&plane_state->uapi.src,
1692 -(src_x << 16), -(src_y << 16));
1694 /* Rotate src coordinates to match rotated GTT view */
1695 if (drm_rotation_90_or_270(rotation))
1696 drm_rect_rotate(&plane_state->uapi.src,
1697 src_w << 16, src_h << 16,
1698 DRM_MODE_ROTATE_270);
1700 for (i = 0; i < num_planes; i++) {
1701 unsigned int hsub = i ? fb->format->hsub : 1;
1702 unsigned int vsub = i ? fb->format->vsub : 1;
1703 struct fb_plane_view_dims view_dims;
1704 unsigned int width, height;
1710 width = src_w / hsub;
1711 height = src_h / vsub;
1713 init_plane_view_dims(intel_fb, i, width, height, &view_dims);
1716 * First pixel of the src viewport from the
1717 * start of the normal gtt mapping.
1719 x += intel_fb->normal_view.color_plane[i].x;
1720 y += intel_fb->normal_view.color_plane[i].y;
1722 offset = calc_plane_aligned_offset(intel_fb, i, &x, &y);
1724 gtt_offset += calc_plane_remap_info(intel_fb, i, &view_dims,
1725 offset, gtt_offset, x, y,
1726 &plane_state->view);
1730 void intel_fb_fill_view(const struct intel_framebuffer *fb, unsigned int rotation,
1731 struct intel_fb_view *view)
1733 if (drm_rotation_90_or_270(rotation))
1734 *view = fb->rotated_view;
1735 else if (intel_fb_needs_pot_stride_remap(fb))
1736 *view = fb->remapped_view;
1738 *view = fb->normal_view;
1742 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
1743 u32 pixel_format, u64 modifier)
1746 * Arbitrary limit for gen4+ chosen to match the
1747 * render engine max stride.
1749 * The new CCS hash mode makes remapping impossible
1751 if (DISPLAY_VER(dev_priv) < 4 || intel_fb_is_ccs_modifier(modifier) ||
1752 intel_fb_modifier_uses_dpt(dev_priv, modifier))
1753 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
1754 else if (DISPLAY_VER(dev_priv) >= 7)
1761 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
1763 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1766 if (is_surface_linear(fb, color_plane)) {
1767 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
1772 * To make remapping with linear generally feasible
1773 * we need the stride to be page aligned.
1775 if (fb->pitches[color_plane] > max_stride &&
1776 !intel_fb_is_ccs_modifier(fb->modifier))
1777 return intel_tile_size(dev_priv);
1782 tile_width = intel_tile_width_bytes(fb, color_plane);
1783 if (intel_fb_is_ccs_modifier(fb->modifier)) {
1785 * On TGL the surface stride must be 4 tile aligned, mapped by
1786 * one 64 byte cacheline on the CCS AUX surface.
1788 if (DISPLAY_VER(dev_priv) >= 12)
1791 * Display WA #0531: skl,bxt,kbl,glk
1793 * Render decompression and plane width > 3840
1794 * combined with horizontal panning requires the
1795 * plane stride to be a multiple of 4. We'll just
1796 * require the entire fb to accommodate that to avoid
1797 * potential runtime errors at plane configuration time.
1799 else if ((DISPLAY_VER(dev_priv) == 9 || IS_GEMINILAKE(dev_priv)) &&
1800 color_plane == 0 && fb->width > 3840)
1806 static int intel_plane_check_stride(const struct intel_plane_state *plane_state)
1808 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1809 const struct drm_framebuffer *fb = plane_state->hw.fb;
1810 unsigned int rotation = plane_state->hw.rotation;
1811 u32 stride, max_stride;
1814 * We ignore stride for all invisible planes that
1815 * can be remapped. Otherwise we could end up
1816 * with a false positive when the remapping didn't
1817 * kick in due the plane being invisible.
1819 if (intel_plane_can_remap(plane_state) &&
1820 !plane_state->uapi.visible)
1823 /* FIXME other color planes? */
1824 stride = plane_state->view.color_plane[0].mapping_stride;
1825 max_stride = plane->max_stride(plane, fb->format->format,
1826 fb->modifier, rotation);
1828 if (stride > max_stride) {
1829 DRM_DEBUG_KMS("[FB:%d] stride (%d) exceeds [PLANE:%d:%s] max stride (%d)\n",
1830 fb->base.id, stride,
1831 plane->base.base.id, plane->base.name, max_stride);
1838 int intel_plane_compute_gtt(struct intel_plane_state *plane_state)
1840 const struct intel_framebuffer *fb =
1841 to_intel_framebuffer(plane_state->hw.fb);
1842 unsigned int rotation = plane_state->hw.rotation;
1847 if (intel_plane_needs_remap(plane_state)) {
1848 intel_plane_remap_gtt(plane_state);
1851 * Sometimes even remapping can't overcome
1852 * the stride limitations :( Can happen with
1853 * big plane sizes and suitably misaligned
1856 return intel_plane_check_stride(plane_state);
1859 intel_fb_fill_view(fb, rotation, &plane_state->view);
1861 /* Rotate src coordinates to match rotated GTT view */
1862 if (drm_rotation_90_or_270(rotation))
1863 drm_rect_rotate(&plane_state->uapi.src,
1864 fb->base.width << 16, fb->base.height << 16,
1865 DRM_MODE_ROTATE_270);
1867 return intel_plane_check_stride(plane_state);
1870 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
1872 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
1874 drm_framebuffer_cleanup(fb);
1876 if (intel_fb_uses_dpt(fb))
1877 intel_dpt_destroy(intel_fb->dpt_vm);
1879 intel_frontbuffer_put(intel_fb->frontbuffer);
1884 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
1885 struct drm_file *file,
1886 unsigned int *handle)
1888 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1889 struct drm_i915_private *i915 = to_i915(obj->base.dev);
1891 if (i915_gem_object_is_userptr(obj)) {
1893 "attempting to use a userptr for a framebuffer, denied\n");
1897 return drm_gem_handle_create(file, &obj->base, handle);
1900 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
1901 struct drm_file *file,
1902 unsigned int flags, unsigned int color,
1903 struct drm_clip_rect *clips,
1904 unsigned int num_clips)
1906 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1908 i915_gem_object_flush_if_display(obj);
1909 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
1914 static const struct drm_framebuffer_funcs intel_fb_funcs = {
1915 .destroy = intel_user_framebuffer_destroy,
1916 .create_handle = intel_user_framebuffer_create_handle,
1917 .dirty = intel_user_framebuffer_dirty,
1920 int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
1921 struct drm_i915_gem_object *obj,
1922 struct drm_mode_fb_cmd2 *mode_cmd)
1924 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
1925 struct drm_framebuffer *fb = &intel_fb->base;
1927 unsigned int tiling, stride;
1931 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
1932 if (!intel_fb->frontbuffer)
1935 i915_gem_object_lock(obj, NULL);
1936 tiling = i915_gem_object_get_tiling(obj);
1937 stride = i915_gem_object_get_stride(obj);
1938 i915_gem_object_unlock(obj);
1940 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
1942 * If there's a fence, enforce that
1943 * the fb modifier and tiling mode match.
1945 if (tiling != I915_TILING_NONE &&
1946 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
1947 drm_dbg_kms(&dev_priv->drm,
1948 "tiling_mode doesn't match fb modifier\n");
1952 if (tiling == I915_TILING_X) {
1953 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
1954 } else if (tiling == I915_TILING_Y) {
1955 drm_dbg_kms(&dev_priv->drm,
1956 "No Y tiling for legacy addfb\n");
1961 if (!drm_any_plane_has_format(&dev_priv->drm,
1962 mode_cmd->pixel_format,
1963 mode_cmd->modifier[0])) {
1964 drm_dbg_kms(&dev_priv->drm,
1965 "unsupported pixel format %p4cc / modifier 0x%llx\n",
1966 &mode_cmd->pixel_format, mode_cmd->modifier[0]);
1971 * gen2/3 display engine uses the fence if present,
1972 * so the tiling mode must match the fb modifier exactly.
1974 if (DISPLAY_VER(dev_priv) < 4 &&
1975 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
1976 drm_dbg_kms(&dev_priv->drm,
1977 "tiling_mode must match fb modifier exactly on gen2/3\n");
1981 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
1982 mode_cmd->modifier[0]);
1983 if (mode_cmd->pitches[0] > max_stride) {
1984 drm_dbg_kms(&dev_priv->drm,
1985 "%s pitch (%u) must be at most %d\n",
1986 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
1988 mode_cmd->pitches[0], max_stride);
1993 * If there's a fence, enforce that
1994 * the fb pitch and fence stride match.
1996 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
1997 drm_dbg_kms(&dev_priv->drm,
1998 "pitch (%d) must match tiling stride (%d)\n",
1999 mode_cmd->pitches[0], stride);
2003 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
2004 if (mode_cmd->offsets[0] != 0) {
2005 drm_dbg_kms(&dev_priv->drm,
2006 "plane 0 offset (0x%08x) must be 0\n",
2007 mode_cmd->offsets[0]);
2011 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
2013 for (i = 0; i < fb->format->num_planes; i++) {
2014 u32 stride_alignment;
2016 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
2017 drm_dbg_kms(&dev_priv->drm, "bad plane %d handle\n",
2022 stride_alignment = intel_fb_stride_alignment(fb, i);
2023 if (fb->pitches[i] & (stride_alignment - 1)) {
2024 drm_dbg_kms(&dev_priv->drm,
2025 "plane %d pitch (%d) must be at least %u byte aligned\n",
2026 i, fb->pitches[i], stride_alignment);
2030 if (intel_fb_is_gen12_ccs_aux_plane(fb, i)) {
2031 int ccs_aux_stride = gen12_ccs_aux_stride(intel_fb, i);
2033 if (fb->pitches[i] != ccs_aux_stride) {
2034 drm_dbg_kms(&dev_priv->drm,
2035 "ccs aux plane %d pitch (%d) must be %d\n",
2037 fb->pitches[i], ccs_aux_stride);
2042 fb->obj[i] = &obj->base;
2045 ret = intel_fill_fb_info(dev_priv, intel_fb);
2049 if (intel_fb_uses_dpt(fb)) {
2050 struct i915_address_space *vm;
2052 vm = intel_dpt_create(intel_fb);
2054 drm_dbg_kms(&dev_priv->drm, "failed to create DPT\n");
2059 intel_fb->dpt_vm = vm;
2062 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
2064 drm_err(&dev_priv->drm, "framebuffer init failed %d\n", ret);
2071 if (intel_fb_uses_dpt(fb))
2072 intel_dpt_destroy(intel_fb->dpt_vm);
2074 intel_frontbuffer_put(intel_fb->frontbuffer);
2078 struct drm_framebuffer *
2079 intel_user_framebuffer_create(struct drm_device *dev,
2080 struct drm_file *filp,
2081 const struct drm_mode_fb_cmd2 *user_mode_cmd)
2083 struct drm_framebuffer *fb;
2084 struct drm_i915_gem_object *obj;
2085 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
2086 struct drm_i915_private *i915;
2088 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
2090 return ERR_PTR(-ENOENT);
2092 /* object is backed with LMEM for discrete */
2093 i915 = to_i915(obj->base.dev);
2094 if (HAS_LMEM(i915) && !i915_gem_object_can_migrate(obj, INTEL_REGION_LMEM_0)) {
2095 /* object is "remote", not in local memory */
2096 i915_gem_object_put(obj);
2097 drm_dbg_kms(&i915->drm, "framebuffer must reside in local memory\n");
2098 return ERR_PTR(-EREMOTE);
2101 fb = intel_framebuffer_create(obj, &mode_cmd);
2102 i915_gem_object_put(obj);
2107 struct drm_framebuffer *
2108 intel_framebuffer_create(struct drm_i915_gem_object *obj,
2109 struct drm_mode_fb_cmd2 *mode_cmd)
2111 struct intel_framebuffer *intel_fb;
2114 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
2116 return ERR_PTR(-ENOMEM);
2118 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
2122 return &intel_fb->base;
2126 return ERR_PTR(ret);