2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Kevin Tian <kevin.tian@intel.com>
27 * Bing Niu <bing.niu@intel.com>
28 * Xu Han <xu.han@intel.com>
29 * Ping Gao <ping.a.gao@intel.com>
30 * Xiaoguang Chen <xiaoguang.chen@intel.com>
31 * Yang Liu <yang2.liu@intel.com>
32 * Tina Zhang <tina.zhang@intel.com>
36 #include <uapi/drm/drm_fourcc.h>
39 #include "i915_pvinfo.h"
41 #define PRIMARY_FORMAT_NUM 16
43 int drm_format
; /* Pixel format in DRM definition */
44 int bpp
; /* Bits per pixel, 0 indicates invalid */
45 char *desc
; /* The description */
48 static struct pixel_format bdw_pixel_formats
[] = {
49 {DRM_FORMAT_C8
, 8, "8-bit Indexed"},
50 {DRM_FORMAT_RGB565
, 16, "16-bit BGRX (5:6:5 MSB-R:G:B)"},
51 {DRM_FORMAT_XRGB8888
, 32, "32-bit BGRX (8:8:8:8 MSB-X:R:G:B)"},
52 {DRM_FORMAT_XBGR2101010
, 32, "32-bit RGBX (2:10:10:10 MSB-X:B:G:R)"},
54 {DRM_FORMAT_XRGB2101010
, 32, "32-bit BGRX (2:10:10:10 MSB-X:R:G:B)"},
55 {DRM_FORMAT_XBGR8888
, 32, "32-bit RGBX (8:8:8:8 MSB-X:B:G:R)"},
57 /* non-supported format has bpp default to 0 */
61 static struct pixel_format skl_pixel_formats
[] = {
62 {DRM_FORMAT_YUYV
, 16, "16-bit packed YUYV (8:8:8:8 MSB-V:Y2:U:Y1)"},
63 {DRM_FORMAT_UYVY
, 16, "16-bit packed UYVY (8:8:8:8 MSB-Y2:V:Y1:U)"},
64 {DRM_FORMAT_YVYU
, 16, "16-bit packed YVYU (8:8:8:8 MSB-U:Y2:V:Y1)"},
65 {DRM_FORMAT_VYUY
, 16, "16-bit packed VYUY (8:8:8:8 MSB-Y2:U:Y1:V)"},
67 {DRM_FORMAT_C8
, 8, "8-bit Indexed"},
68 {DRM_FORMAT_RGB565
, 16, "16-bit BGRX (5:6:5 MSB-R:G:B)"},
69 {DRM_FORMAT_ABGR8888
, 32, "32-bit RGBA (8:8:8:8 MSB-A:B:G:R)"},
70 {DRM_FORMAT_XBGR8888
, 32, "32-bit RGBX (8:8:8:8 MSB-X:B:G:R)"},
72 {DRM_FORMAT_ARGB8888
, 32, "32-bit BGRA (8:8:8:8 MSB-A:R:G:B)"},
73 {DRM_FORMAT_XRGB8888
, 32, "32-bit BGRX (8:8:8:8 MSB-X:R:G:B)"},
74 {DRM_FORMAT_XBGR2101010
, 32, "32-bit RGBX (2:10:10:10 MSB-X:B:G:R)"},
75 {DRM_FORMAT_XRGB2101010
, 32, "32-bit BGRX (2:10:10:10 MSB-X:R:G:B)"},
77 /* non-supported format has bpp default to 0 */
81 static int bdw_format_to_drm(int format
)
83 int bdw_pixel_formats_index
= 6;
87 bdw_pixel_formats_index
= 0;
89 case DISPPLANE_BGRX565
:
90 bdw_pixel_formats_index
= 1;
92 case DISPPLANE_BGRX888
:
93 bdw_pixel_formats_index
= 2;
95 case DISPPLANE_RGBX101010
:
96 bdw_pixel_formats_index
= 3;
98 case DISPPLANE_BGRX101010
:
99 bdw_pixel_formats_index
= 4;
101 case DISPPLANE_RGBX888
:
102 bdw_pixel_formats_index
= 5;
109 return bdw_pixel_formats_index
;
112 static int skl_format_to_drm(int format
, bool rgb_order
, bool alpha
,
115 int skl_pixel_formats_index
= 12;
118 case PLANE_CTL_FORMAT_INDEXED
:
119 skl_pixel_formats_index
= 4;
121 case PLANE_CTL_FORMAT_RGB_565
:
122 skl_pixel_formats_index
= 5;
124 case PLANE_CTL_FORMAT_XRGB_8888
:
126 skl_pixel_formats_index
= alpha
? 6 : 7;
128 skl_pixel_formats_index
= alpha
? 8 : 9;
130 case PLANE_CTL_FORMAT_XRGB_2101010
:
131 skl_pixel_formats_index
= rgb_order
? 10 : 11;
133 case PLANE_CTL_FORMAT_YUV422
:
134 skl_pixel_formats_index
= yuv_order
>> 16;
135 if (skl_pixel_formats_index
> 3)
143 return skl_pixel_formats_index
;
146 static u32
intel_vgpu_get_stride(struct intel_vgpu
*vgpu
, int pipe
,
147 u32 tiled
, int stride_mask
, int bpp
)
149 struct drm_i915_private
*dev_priv
= vgpu
->gvt
->dev_priv
;
151 u32 stride_reg
= vgpu_vreg_t(vgpu
, DSPSTRIDE(pipe
)) & stride_mask
;
152 u32 stride
= stride_reg
;
154 if (IS_SKYLAKE(dev_priv
)
155 || IS_KABYLAKE(dev_priv
)
156 || IS_BROXTON(dev_priv
)) {
158 case PLANE_CTL_TILED_LINEAR
:
159 stride
= stride_reg
* 64;
161 case PLANE_CTL_TILED_X
:
162 stride
= stride_reg
* 512;
164 case PLANE_CTL_TILED_Y
:
165 stride
= stride_reg
* 128;
167 case PLANE_CTL_TILED_YF
:
169 stride
= stride_reg
* 64;
170 else if (bpp
== 16 || bpp
== 32 || bpp
== 64)
171 stride
= stride_reg
* 128;
173 gvt_dbg_core("skl: unsupported bpp:%d\n", bpp
);
176 gvt_dbg_core("skl: unsupported tile format:%x\n",
184 static int get_active_pipe(struct intel_vgpu
*vgpu
)
188 for (i
= 0; i
< I915_MAX_PIPES
; i
++)
189 if (pipe_is_enabled(vgpu
, i
))
196 * intel_vgpu_decode_primary_plane - Decode primary plane
198 * @plane: primary plane to save decoded info
199 * This function is called for decoding plane
202 * 0 on success, non-zero if failed.
204 int intel_vgpu_decode_primary_plane(struct intel_vgpu
*vgpu
,
205 struct intel_vgpu_primary_plane_format
*plane
)
208 struct drm_i915_private
*dev_priv
= vgpu
->gvt
->dev_priv
;
211 pipe
= get_active_pipe(vgpu
);
212 if (pipe
>= I915_MAX_PIPES
)
215 val
= vgpu_vreg_t(vgpu
, DSPCNTR(pipe
));
216 plane
->enabled
= !!(val
& DISPLAY_PLANE_ENABLE
);
220 if (IS_SKYLAKE(dev_priv
)
221 || IS_KABYLAKE(dev_priv
)
222 || IS_BROXTON(dev_priv
)) {
223 plane
->tiled
= val
& PLANE_CTL_TILED_MASK
;
224 fmt
= skl_format_to_drm(
225 val
& PLANE_CTL_FORMAT_MASK
,
226 val
& PLANE_CTL_ORDER_RGBX
,
227 val
& PLANE_CTL_ALPHA_MASK
,
228 val
& PLANE_CTL_YUV422_ORDER_MASK
);
230 if (fmt
>= ARRAY_SIZE(skl_pixel_formats
)) {
231 gvt_vgpu_err("Out-of-bounds pixel format index\n");
235 plane
->bpp
= skl_pixel_formats
[fmt
].bpp
;
236 plane
->drm_format
= skl_pixel_formats
[fmt
].drm_format
;
238 plane
->tiled
= val
& DISPPLANE_TILED
;
239 fmt
= bdw_format_to_drm(val
& DISPPLANE_PIXFORMAT_MASK
);
240 plane
->bpp
= bdw_pixel_formats
[fmt
].bpp
;
241 plane
->drm_format
= bdw_pixel_formats
[fmt
].drm_format
;
245 gvt_vgpu_err("Non-supported pixel format (0x%x)\n", fmt
);
249 plane
->hw_format
= fmt
;
251 plane
->base
= vgpu_vreg_t(vgpu
, DSPSURF(pipe
)) & I915_GTT_PAGE_MASK
;
252 if (!intel_gvt_ggtt_validate_range(vgpu
, plane
->base
, 0))
255 plane
->base_gpa
= intel_vgpu_gma_to_gpa(vgpu
->gtt
.ggtt_mm
, plane
->base
);
256 if (plane
->base_gpa
== INTEL_GVT_INVALID_ADDR
) {
257 gvt_vgpu_err("Translate primary plane gma 0x%x to gpa fail\n",
262 plane
->stride
= intel_vgpu_get_stride(vgpu
, pipe
, plane
->tiled
,
263 (IS_SKYLAKE(dev_priv
)
264 || IS_KABYLAKE(dev_priv
)
265 || IS_BROXTON(dev_priv
)) ?
266 (_PRI_PLANE_STRIDE_MASK
>> 6) :
267 _PRI_PLANE_STRIDE_MASK
, plane
->bpp
);
269 plane
->width
= (vgpu_vreg_t(vgpu
, PIPESRC(pipe
)) & _PIPE_H_SRCSZ_MASK
) >>
272 plane
->height
= (vgpu_vreg_t(vgpu
, PIPESRC(pipe
)) &
273 _PIPE_V_SRCSZ_MASK
) >> _PIPE_V_SRCSZ_SHIFT
;
274 plane
->height
+= 1; /* raw height is one minus the real value */
276 val
= vgpu_vreg_t(vgpu
, DSPTILEOFF(pipe
));
277 plane
->x_offset
= (val
& _PRI_PLANE_X_OFF_MASK
) >>
278 _PRI_PLANE_X_OFF_SHIFT
;
279 plane
->y_offset
= (val
& _PRI_PLANE_Y_OFF_MASK
) >>
280 _PRI_PLANE_Y_OFF_SHIFT
;
285 #define CURSOR_FORMAT_NUM (1 << 6)
286 struct cursor_mode_format
{
287 int drm_format
; /* Pixel format in DRM definition */
288 u8 bpp
; /* Bits per pixel; 0 indicates invalid */
289 u32 width
; /* In pixel */
290 u32 height
; /* In lines */
291 char *desc
; /* The description */
294 static struct cursor_mode_format cursor_pixel_formats
[] = {
295 {DRM_FORMAT_ARGB8888
, 32, 128, 128, "128x128 32bpp ARGB"},
296 {DRM_FORMAT_ARGB8888
, 32, 256, 256, "256x256 32bpp ARGB"},
297 {DRM_FORMAT_ARGB8888
, 32, 64, 64, "64x64 32bpp ARGB"},
298 {DRM_FORMAT_ARGB8888
, 32, 64, 64, "64x64 32bpp ARGB"},
300 /* non-supported format has bpp default to 0 */
304 static int cursor_mode_to_drm(int mode
)
306 int cursor_pixel_formats_index
= 4;
309 case MCURSOR_MODE_128_ARGB_AX
:
310 cursor_pixel_formats_index
= 0;
312 case MCURSOR_MODE_256_ARGB_AX
:
313 cursor_pixel_formats_index
= 1;
315 case MCURSOR_MODE_64_ARGB_AX
:
316 cursor_pixel_formats_index
= 2;
318 case MCURSOR_MODE_64_32B_AX
:
319 cursor_pixel_formats_index
= 3;
326 return cursor_pixel_formats_index
;
330 * intel_vgpu_decode_cursor_plane - Decode sprite plane
332 * @plane: cursor plane to save decoded info
333 * This function is called for decoding plane
336 * 0 on success, non-zero if failed.
338 int intel_vgpu_decode_cursor_plane(struct intel_vgpu
*vgpu
,
339 struct intel_vgpu_cursor_plane_format
*plane
)
341 u32 val
, mode
, index
;
342 u32 alpha_plane
, alpha_force
;
343 struct drm_i915_private
*dev_priv
= vgpu
->gvt
->dev_priv
;
346 pipe
= get_active_pipe(vgpu
);
347 if (pipe
>= I915_MAX_PIPES
)
350 val
= vgpu_vreg_t(vgpu
, CURCNTR(pipe
));
351 mode
= val
& MCURSOR_MODE
;
352 plane
->enabled
= (mode
!= MCURSOR_MODE_DISABLE
);
356 index
= cursor_mode_to_drm(mode
);
358 if (!cursor_pixel_formats
[index
].bpp
) {
359 gvt_vgpu_err("Non-supported cursor mode (0x%x)\n", mode
);
363 plane
->bpp
= cursor_pixel_formats
[index
].bpp
;
364 plane
->drm_format
= cursor_pixel_formats
[index
].drm_format
;
365 plane
->width
= cursor_pixel_formats
[index
].width
;
366 plane
->height
= cursor_pixel_formats
[index
].height
;
368 alpha_plane
= (val
& _CURSOR_ALPHA_PLANE_MASK
) >>
369 _CURSOR_ALPHA_PLANE_SHIFT
;
370 alpha_force
= (val
& _CURSOR_ALPHA_FORCE_MASK
) >>
371 _CURSOR_ALPHA_FORCE_SHIFT
;
372 if (alpha_plane
|| alpha_force
)
373 gvt_dbg_core("alpha_plane=0x%x, alpha_force=0x%x\n",
374 alpha_plane
, alpha_force
);
376 plane
->base
= vgpu_vreg_t(vgpu
, CURBASE(pipe
)) & I915_GTT_PAGE_MASK
;
377 if (!intel_gvt_ggtt_validate_range(vgpu
, plane
->base
, 0))
380 plane
->base_gpa
= intel_vgpu_gma_to_gpa(vgpu
->gtt
.ggtt_mm
, plane
->base
);
381 if (plane
->base_gpa
== INTEL_GVT_INVALID_ADDR
) {
382 gvt_vgpu_err("Translate cursor plane gma 0x%x to gpa fail\n",
387 val
= vgpu_vreg_t(vgpu
, CURPOS(pipe
));
388 plane
->x_pos
= (val
& _CURSOR_POS_X_MASK
) >> _CURSOR_POS_X_SHIFT
;
389 plane
->x_sign
= (val
& _CURSOR_SIGN_X_MASK
) >> _CURSOR_SIGN_X_SHIFT
;
390 plane
->y_pos
= (val
& _CURSOR_POS_Y_MASK
) >> _CURSOR_POS_Y_SHIFT
;
391 plane
->y_sign
= (val
& _CURSOR_SIGN_Y_MASK
) >> _CURSOR_SIGN_Y_SHIFT
;
393 plane
->x_hot
= vgpu_vreg_t(vgpu
, vgtif_reg(cursor_x_hot
));
394 plane
->y_hot
= vgpu_vreg_t(vgpu
, vgtif_reg(cursor_y_hot
));
398 #define SPRITE_FORMAT_NUM (1 << 3)
400 static struct pixel_format sprite_pixel_formats
[SPRITE_FORMAT_NUM
] = {
401 [0x0] = {DRM_FORMAT_YUV422
, 16, "YUV 16-bit 4:2:2 packed"},
402 [0x1] = {DRM_FORMAT_XRGB2101010
, 32, "RGB 32-bit 2:10:10:10"},
403 [0x2] = {DRM_FORMAT_XRGB8888
, 32, "RGB 32-bit 8:8:8:8"},
404 [0x4] = {DRM_FORMAT_AYUV
, 32,
405 "YUV 32-bit 4:4:4 packed (8:8:8:8 MSB-X:Y:U:V)"},
409 * intel_vgpu_decode_sprite_plane - Decode sprite plane
411 * @plane: sprite plane to save decoded info
412 * This function is called for decoding plane
415 * 0 on success, non-zero if failed.
417 int intel_vgpu_decode_sprite_plane(struct intel_vgpu
*vgpu
,
418 struct intel_vgpu_sprite_plane_format
*plane
)
421 u32 color_order
, yuv_order
;
425 pipe
= get_active_pipe(vgpu
);
426 if (pipe
>= I915_MAX_PIPES
)
429 val
= vgpu_vreg_t(vgpu
, SPRCTL(pipe
));
430 plane
->enabled
= !!(val
& SPRITE_ENABLE
);
434 plane
->tiled
= !!(val
& SPRITE_TILED
);
435 color_order
= !!(val
& SPRITE_RGB_ORDER_RGBX
);
436 yuv_order
= (val
& SPRITE_YUV_BYTE_ORDER_MASK
) >>
437 _SPRITE_YUV_ORDER_SHIFT
;
439 fmt
= (val
& SPRITE_PIXFORMAT_MASK
) >> _SPRITE_FMT_SHIFT
;
440 if (!sprite_pixel_formats
[fmt
].bpp
) {
441 gvt_vgpu_err("Non-supported pixel format (0x%x)\n", fmt
);
444 plane
->hw_format
= fmt
;
445 plane
->bpp
= sprite_pixel_formats
[fmt
].bpp
;
446 drm_format
= sprite_pixel_formats
[fmt
].drm_format
;
448 /* Order of RGB values in an RGBxxx buffer may be ordered RGB or
449 * BGR depending on the state of the color_order field
452 if (drm_format
== DRM_FORMAT_XRGB2101010
)
453 drm_format
= DRM_FORMAT_XBGR2101010
;
454 else if (drm_format
== DRM_FORMAT_XRGB8888
)
455 drm_format
= DRM_FORMAT_XBGR8888
;
458 if (drm_format
== DRM_FORMAT_YUV422
) {
461 drm_format
= DRM_FORMAT_YUYV
;
464 drm_format
= DRM_FORMAT_UYVY
;
467 drm_format
= DRM_FORMAT_YVYU
;
470 drm_format
= DRM_FORMAT_VYUY
;
473 /* yuv_order has only 2 bits */
478 plane
->drm_format
= drm_format
;
480 plane
->base
= vgpu_vreg_t(vgpu
, SPRSURF(pipe
)) & I915_GTT_PAGE_MASK
;
481 if (!intel_gvt_ggtt_validate_range(vgpu
, plane
->base
, 0))
484 plane
->base_gpa
= intel_vgpu_gma_to_gpa(vgpu
->gtt
.ggtt_mm
, plane
->base
);
485 if (plane
->base_gpa
== INTEL_GVT_INVALID_ADDR
) {
486 gvt_vgpu_err("Translate sprite plane gma 0x%x to gpa fail\n",
491 plane
->stride
= vgpu_vreg_t(vgpu
, SPRSTRIDE(pipe
)) &
494 val
= vgpu_vreg_t(vgpu
, SPRSIZE(pipe
));
495 plane
->height
= (val
& _SPRITE_SIZE_HEIGHT_MASK
) >>
496 _SPRITE_SIZE_HEIGHT_SHIFT
;
497 plane
->width
= (val
& _SPRITE_SIZE_WIDTH_MASK
) >>
498 _SPRITE_SIZE_WIDTH_SHIFT
;
499 plane
->height
+= 1; /* raw height is one minus the real value */
500 plane
->width
+= 1; /* raw width is one minus the real value */
502 val
= vgpu_vreg_t(vgpu
, SPRPOS(pipe
));
503 plane
->x_pos
= (val
& _SPRITE_POS_X_MASK
) >> _SPRITE_POS_X_SHIFT
;
504 plane
->y_pos
= (val
& _SPRITE_POS_Y_MASK
) >> _SPRITE_POS_Y_SHIFT
;
506 val
= vgpu_vreg_t(vgpu
, SPROFFSET(pipe
));
507 plane
->x_offset
= (val
& _SPRITE_OFFSET_START_X_MASK
) >>
508 _SPRITE_OFFSET_START_X_SHIFT
;
509 plane
->y_offset
= (val
& _SPRITE_OFFSET_START_Y_MASK
) >>
510 _SPRITE_OFFSET_START_Y_SHIFT
;