1 1.1 riastrad /* $NetBSD: fb_decoder.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice (including the next 14 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 15 1.1 riastrad * Software. 16 1.1 riastrad * 17 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 1.1 riastrad * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 1.1 riastrad * SOFTWARE. 24 1.1 riastrad * 25 1.1 riastrad * Authors: 26 1.1 riastrad * Kevin Tian <kevin.tian (at) intel.com> 27 1.1 riastrad * 28 1.1 riastrad * Contributors: 29 1.1 riastrad * Bing Niu <bing.niu (at) intel.com> 30 1.1 riastrad * Xu Han <xu.han (at) intel.com> 31 1.1 riastrad * Ping Gao <ping.a.gao (at) intel.com> 32 1.1 riastrad * Xiaoguang Chen <xiaoguang.chen (at) intel.com> 33 1.1 riastrad * Yang Liu <yang2.liu (at) intel.com> 34 1.1 riastrad * Tina Zhang <tina.zhang (at) intel.com> 35 1.1 riastrad * 36 1.1 riastrad */ 37 1.1 riastrad 38 1.1 riastrad #include <sys/cdefs.h> 39 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: fb_decoder.c,v 1.2 2021/12/18 23:45:31 riastradh Exp $"); 40 1.1 riastrad 41 1.1 riastrad #include <uapi/drm/drm_fourcc.h> 42 1.1 riastrad #include "i915_drv.h" 43 1.1 riastrad #include "gvt.h" 44 1.1 riastrad #include "i915_pvinfo.h" 45 1.1 riastrad 46 1.1 riastrad #define PRIMARY_FORMAT_NUM 16 47 1.1 riastrad struct pixel_format { 48 1.1 riastrad int drm_format; /* Pixel format in DRM definition */ 49 1.1 riastrad int bpp; /* Bits per pixel, 0 indicates invalid */ 50 1.1 riastrad char *desc; /* The description */ 51 1.1 riastrad }; 52 1.1 riastrad 53 1.1 riastrad static struct pixel_format bdw_pixel_formats[] = { 54 1.1 riastrad {DRM_FORMAT_C8, 8, "8-bit Indexed"}, 55 1.1 riastrad {DRM_FORMAT_RGB565, 16, "16-bit BGRX (5:6:5 MSB-R:G:B)"}, 56 1.1 riastrad {DRM_FORMAT_XRGB8888, 32, "32-bit BGRX (8:8:8:8 MSB-X:R:G:B)"}, 57 1.1 riastrad {DRM_FORMAT_XBGR2101010, 32, "32-bit RGBX (2:10:10:10 MSB-X:B:G:R)"}, 58 1.1 riastrad 59 1.1 riastrad {DRM_FORMAT_XRGB2101010, 32, "32-bit BGRX (2:10:10:10 MSB-X:R:G:B)"}, 60 1.1 riastrad {DRM_FORMAT_XBGR8888, 32, "32-bit RGBX (8:8:8:8 MSB-X:B:G:R)"}, 61 1.1 riastrad 62 1.1 riastrad /* non-supported format has bpp default to 0 */ 63 1.1 riastrad {0, 0, NULL}, 64 1.1 riastrad }; 65 1.1 riastrad 66 1.1 riastrad static struct pixel_format skl_pixel_formats[] = { 67 1.1 riastrad {DRM_FORMAT_YUYV, 16, "16-bit packed YUYV (8:8:8:8 MSB-V:Y2:U:Y1)"}, 68 1.1 riastrad {DRM_FORMAT_UYVY, 16, "16-bit packed UYVY (8:8:8:8 MSB-Y2:V:Y1:U)"}, 69 1.1 riastrad {DRM_FORMAT_YVYU, 16, "16-bit packed YVYU (8:8:8:8 MSB-U:Y2:V:Y1)"}, 70 1.1 riastrad {DRM_FORMAT_VYUY, 16, "16-bit packed VYUY (8:8:8:8 MSB-Y2:U:Y1:V)"}, 71 1.1 riastrad 72 1.1 riastrad {DRM_FORMAT_C8, 8, "8-bit Indexed"}, 73 1.1 riastrad {DRM_FORMAT_RGB565, 16, "16-bit BGRX (5:6:5 MSB-R:G:B)"}, 74 1.1 riastrad {DRM_FORMAT_ABGR8888, 32, "32-bit RGBA (8:8:8:8 MSB-A:B:G:R)"}, 75 1.1 riastrad {DRM_FORMAT_XBGR8888, 32, "32-bit RGBX (8:8:8:8 MSB-X:B:G:R)"}, 76 1.1 riastrad 77 1.1 riastrad {DRM_FORMAT_ARGB8888, 32, "32-bit BGRA (8:8:8:8 MSB-A:R:G:B)"}, 78 1.1 riastrad {DRM_FORMAT_XRGB8888, 32, "32-bit BGRX (8:8:8:8 MSB-X:R:G:B)"}, 79 1.1 riastrad {DRM_FORMAT_XBGR2101010, 32, "32-bit RGBX (2:10:10:10 MSB-X:B:G:R)"}, 80 1.1 riastrad {DRM_FORMAT_XRGB2101010, 32, "32-bit BGRX (2:10:10:10 MSB-X:R:G:B)"}, 81 1.1 riastrad 82 1.1 riastrad /* non-supported format has bpp default to 0 */ 83 1.1 riastrad {0, 0, NULL}, 84 1.1 riastrad }; 85 1.1 riastrad 86 1.1 riastrad static int bdw_format_to_drm(int format) 87 1.1 riastrad { 88 1.1 riastrad int bdw_pixel_formats_index = 6; 89 1.1 riastrad 90 1.1 riastrad switch (format) { 91 1.1 riastrad case DISPPLANE_8BPP: 92 1.1 riastrad bdw_pixel_formats_index = 0; 93 1.1 riastrad break; 94 1.1 riastrad case DISPPLANE_BGRX565: 95 1.1 riastrad bdw_pixel_formats_index = 1; 96 1.1 riastrad break; 97 1.1 riastrad case DISPPLANE_BGRX888: 98 1.1 riastrad bdw_pixel_formats_index = 2; 99 1.1 riastrad break; 100 1.1 riastrad case DISPPLANE_RGBX101010: 101 1.1 riastrad bdw_pixel_formats_index = 3; 102 1.1 riastrad break; 103 1.1 riastrad case DISPPLANE_BGRX101010: 104 1.1 riastrad bdw_pixel_formats_index = 4; 105 1.1 riastrad break; 106 1.1 riastrad case DISPPLANE_RGBX888: 107 1.1 riastrad bdw_pixel_formats_index = 5; 108 1.1 riastrad break; 109 1.1 riastrad 110 1.1 riastrad default: 111 1.1 riastrad break; 112 1.1 riastrad } 113 1.1 riastrad 114 1.1 riastrad return bdw_pixel_formats_index; 115 1.1 riastrad } 116 1.1 riastrad 117 1.1 riastrad static int skl_format_to_drm(int format, bool rgb_order, bool alpha, 118 1.1 riastrad int yuv_order) 119 1.1 riastrad { 120 1.1 riastrad int skl_pixel_formats_index = 12; 121 1.1 riastrad 122 1.1 riastrad switch (format) { 123 1.1 riastrad case PLANE_CTL_FORMAT_INDEXED: 124 1.1 riastrad skl_pixel_formats_index = 4; 125 1.1 riastrad break; 126 1.1 riastrad case PLANE_CTL_FORMAT_RGB_565: 127 1.1 riastrad skl_pixel_formats_index = 5; 128 1.1 riastrad break; 129 1.1 riastrad case PLANE_CTL_FORMAT_XRGB_8888: 130 1.1 riastrad if (rgb_order) 131 1.1 riastrad skl_pixel_formats_index = alpha ? 6 : 7; 132 1.1 riastrad else 133 1.1 riastrad skl_pixel_formats_index = alpha ? 8 : 9; 134 1.1 riastrad break; 135 1.1 riastrad case PLANE_CTL_FORMAT_XRGB_2101010: 136 1.1 riastrad skl_pixel_formats_index = rgb_order ? 10 : 11; 137 1.1 riastrad break; 138 1.1 riastrad case PLANE_CTL_FORMAT_YUV422: 139 1.1 riastrad skl_pixel_formats_index = yuv_order >> 16; 140 1.1 riastrad if (skl_pixel_formats_index > 3) 141 1.1 riastrad return -EINVAL; 142 1.1 riastrad break; 143 1.1 riastrad 144 1.1 riastrad default: 145 1.1 riastrad break; 146 1.1 riastrad } 147 1.1 riastrad 148 1.1 riastrad return skl_pixel_formats_index; 149 1.1 riastrad } 150 1.1 riastrad 151 1.1 riastrad static u32 intel_vgpu_get_stride(struct intel_vgpu *vgpu, int pipe, 152 1.1 riastrad u32 tiled, int stride_mask, int bpp) 153 1.1 riastrad { 154 1.1 riastrad struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; 155 1.1 riastrad 156 1.1 riastrad u32 stride_reg = vgpu_vreg_t(vgpu, DSPSTRIDE(pipe)) & stride_mask; 157 1.1 riastrad u32 stride = stride_reg; 158 1.1 riastrad 159 1.1 riastrad if (INTEL_GEN(dev_priv) >= 9) { 160 1.1 riastrad switch (tiled) { 161 1.1 riastrad case PLANE_CTL_TILED_LINEAR: 162 1.1 riastrad stride = stride_reg * 64; 163 1.1 riastrad break; 164 1.1 riastrad case PLANE_CTL_TILED_X: 165 1.1 riastrad stride = stride_reg * 512; 166 1.1 riastrad break; 167 1.1 riastrad case PLANE_CTL_TILED_Y: 168 1.1 riastrad stride = stride_reg * 128; 169 1.1 riastrad break; 170 1.1 riastrad case PLANE_CTL_TILED_YF: 171 1.1 riastrad if (bpp == 8) 172 1.1 riastrad stride = stride_reg * 64; 173 1.1 riastrad else if (bpp == 16 || bpp == 32 || bpp == 64) 174 1.1 riastrad stride = stride_reg * 128; 175 1.1 riastrad else 176 1.1 riastrad gvt_dbg_core("skl: unsupported bpp:%d\n", bpp); 177 1.1 riastrad break; 178 1.1 riastrad default: 179 1.1 riastrad gvt_dbg_core("skl: unsupported tile format:%x\n", 180 1.1 riastrad tiled); 181 1.1 riastrad } 182 1.1 riastrad } 183 1.1 riastrad 184 1.1 riastrad return stride; 185 1.1 riastrad } 186 1.1 riastrad 187 1.1 riastrad static int get_active_pipe(struct intel_vgpu *vgpu) 188 1.1 riastrad { 189 1.1 riastrad int i; 190 1.1 riastrad 191 1.1 riastrad for (i = 0; i < I915_MAX_PIPES; i++) 192 1.1 riastrad if (pipe_is_enabled(vgpu, i)) 193 1.1 riastrad break; 194 1.1 riastrad 195 1.1 riastrad return i; 196 1.1 riastrad } 197 1.1 riastrad 198 1.1 riastrad /** 199 1.1 riastrad * intel_vgpu_decode_primary_plane - Decode primary plane 200 1.1 riastrad * @vgpu: input vgpu 201 1.1 riastrad * @plane: primary plane to save decoded info 202 1.1 riastrad * This function is called for decoding plane 203 1.1 riastrad * 204 1.1 riastrad * Returns: 205 1.1 riastrad * 0 on success, non-zero if failed. 206 1.1 riastrad */ 207 1.1 riastrad int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu, 208 1.1 riastrad struct intel_vgpu_primary_plane_format *plane) 209 1.1 riastrad { 210 1.1 riastrad u32 val, fmt; 211 1.1 riastrad struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; 212 1.1 riastrad int pipe; 213 1.1 riastrad 214 1.1 riastrad pipe = get_active_pipe(vgpu); 215 1.1 riastrad if (pipe >= I915_MAX_PIPES) 216 1.1 riastrad return -ENODEV; 217 1.1 riastrad 218 1.1 riastrad val = vgpu_vreg_t(vgpu, DSPCNTR(pipe)); 219 1.1 riastrad plane->enabled = !!(val & DISPLAY_PLANE_ENABLE); 220 1.1 riastrad if (!plane->enabled) 221 1.1 riastrad return -ENODEV; 222 1.1 riastrad 223 1.1 riastrad if (INTEL_GEN(dev_priv) >= 9) { 224 1.1 riastrad plane->tiled = val & PLANE_CTL_TILED_MASK; 225 1.1 riastrad fmt = skl_format_to_drm( 226 1.1 riastrad val & PLANE_CTL_FORMAT_MASK, 227 1.1 riastrad val & PLANE_CTL_ORDER_RGBX, 228 1.1 riastrad val & PLANE_CTL_ALPHA_MASK, 229 1.1 riastrad val & PLANE_CTL_YUV422_ORDER_MASK); 230 1.1 riastrad 231 1.1 riastrad if (fmt >= ARRAY_SIZE(skl_pixel_formats)) { 232 1.1 riastrad gvt_vgpu_err("Out-of-bounds pixel format index\n"); 233 1.1 riastrad return -EINVAL; 234 1.1 riastrad } 235 1.1 riastrad 236 1.1 riastrad plane->bpp = skl_pixel_formats[fmt].bpp; 237 1.1 riastrad plane->drm_format = skl_pixel_formats[fmt].drm_format; 238 1.1 riastrad } else { 239 1.1 riastrad plane->tiled = val & DISPPLANE_TILED; 240 1.1 riastrad fmt = bdw_format_to_drm(val & DISPPLANE_PIXFORMAT_MASK); 241 1.1 riastrad plane->bpp = bdw_pixel_formats[fmt].bpp; 242 1.1 riastrad plane->drm_format = bdw_pixel_formats[fmt].drm_format; 243 1.1 riastrad } 244 1.1 riastrad 245 1.1 riastrad if (!plane->bpp) { 246 1.1 riastrad gvt_vgpu_err("Non-supported pixel format (0x%x)\n", fmt); 247 1.1 riastrad return -EINVAL; 248 1.1 riastrad } 249 1.1 riastrad 250 1.1 riastrad plane->hw_format = fmt; 251 1.1 riastrad 252 1.1 riastrad plane->base = vgpu_vreg_t(vgpu, DSPSURF(pipe)) & I915_GTT_PAGE_MASK; 253 1.1 riastrad if (!vgpu_gmadr_is_valid(vgpu, plane->base)) 254 1.1 riastrad return -EINVAL; 255 1.1 riastrad 256 1.1 riastrad plane->base_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm, plane->base); 257 1.1 riastrad if (plane->base_gpa == INTEL_GVT_INVALID_ADDR) { 258 1.1 riastrad gvt_vgpu_err("Translate primary plane gma 0x%x to gpa fail\n", 259 1.1 riastrad plane->base); 260 1.1 riastrad return -EINVAL; 261 1.1 riastrad } 262 1.1 riastrad 263 1.1 riastrad plane->stride = intel_vgpu_get_stride(vgpu, pipe, plane->tiled, 264 1.1 riastrad (INTEL_GEN(dev_priv) >= 9) ? 265 1.1 riastrad (_PRI_PLANE_STRIDE_MASK >> 6) : 266 1.1 riastrad _PRI_PLANE_STRIDE_MASK, plane->bpp); 267 1.1 riastrad 268 1.1 riastrad plane->width = (vgpu_vreg_t(vgpu, PIPESRC(pipe)) & _PIPE_H_SRCSZ_MASK) >> 269 1.1 riastrad _PIPE_H_SRCSZ_SHIFT; 270 1.1 riastrad plane->width += 1; 271 1.1 riastrad plane->height = (vgpu_vreg_t(vgpu, PIPESRC(pipe)) & 272 1.1 riastrad _PIPE_V_SRCSZ_MASK) >> _PIPE_V_SRCSZ_SHIFT; 273 1.1 riastrad plane->height += 1; /* raw height is one minus the real value */ 274 1.1 riastrad 275 1.1 riastrad val = vgpu_vreg_t(vgpu, DSPTILEOFF(pipe)); 276 1.1 riastrad plane->x_offset = (val & _PRI_PLANE_X_OFF_MASK) >> 277 1.1 riastrad _PRI_PLANE_X_OFF_SHIFT; 278 1.1 riastrad plane->y_offset = (val & _PRI_PLANE_Y_OFF_MASK) >> 279 1.1 riastrad _PRI_PLANE_Y_OFF_SHIFT; 280 1.1 riastrad 281 1.1 riastrad return 0; 282 1.1 riastrad } 283 1.1 riastrad 284 1.1 riastrad #define CURSOR_FORMAT_NUM (1 << 6) 285 1.1 riastrad struct cursor_mode_format { 286 1.1 riastrad int drm_format; /* Pixel format in DRM definition */ 287 1.1 riastrad u8 bpp; /* Bits per pixel; 0 indicates invalid */ 288 1.1 riastrad u32 width; /* In pixel */ 289 1.1 riastrad u32 height; /* In lines */ 290 1.1 riastrad char *desc; /* The description */ 291 1.1 riastrad }; 292 1.1 riastrad 293 1.1 riastrad static struct cursor_mode_format cursor_pixel_formats[] = { 294 1.1 riastrad {DRM_FORMAT_ARGB8888, 32, 128, 128, "128x128 32bpp ARGB"}, 295 1.1 riastrad {DRM_FORMAT_ARGB8888, 32, 256, 256, "256x256 32bpp ARGB"}, 296 1.1 riastrad {DRM_FORMAT_ARGB8888, 32, 64, 64, "64x64 32bpp ARGB"}, 297 1.1 riastrad {DRM_FORMAT_ARGB8888, 32, 64, 64, "64x64 32bpp ARGB"}, 298 1.1 riastrad 299 1.1 riastrad /* non-supported format has bpp default to 0 */ 300 1.1 riastrad {0, 0, 0, 0, NULL}, 301 1.1 riastrad }; 302 1.1 riastrad 303 1.1 riastrad static int cursor_mode_to_drm(int mode) 304 1.1 riastrad { 305 1.1 riastrad int cursor_pixel_formats_index = 4; 306 1.1 riastrad 307 1.1 riastrad switch (mode) { 308 1.1 riastrad case MCURSOR_MODE_128_ARGB_AX: 309 1.1 riastrad cursor_pixel_formats_index = 0; 310 1.1 riastrad break; 311 1.1 riastrad case MCURSOR_MODE_256_ARGB_AX: 312 1.1 riastrad cursor_pixel_formats_index = 1; 313 1.1 riastrad break; 314 1.1 riastrad case MCURSOR_MODE_64_ARGB_AX: 315 1.1 riastrad cursor_pixel_formats_index = 2; 316 1.1 riastrad break; 317 1.1 riastrad case MCURSOR_MODE_64_32B_AX: 318 1.1 riastrad cursor_pixel_formats_index = 3; 319 1.1 riastrad break; 320 1.1 riastrad 321 1.1 riastrad default: 322 1.1 riastrad break; 323 1.1 riastrad } 324 1.1 riastrad 325 1.1 riastrad return cursor_pixel_formats_index; 326 1.1 riastrad } 327 1.1 riastrad 328 1.1 riastrad /** 329 1.1 riastrad * intel_vgpu_decode_cursor_plane - Decode sprite plane 330 1.1 riastrad * @vgpu: input vgpu 331 1.1 riastrad * @plane: cursor plane to save decoded info 332 1.1 riastrad * This function is called for decoding plane 333 1.1 riastrad * 334 1.1 riastrad * Returns: 335 1.1 riastrad * 0 on success, non-zero if failed. 336 1.1 riastrad */ 337 1.1 riastrad int intel_vgpu_decode_cursor_plane(struct intel_vgpu *vgpu, 338 1.1 riastrad struct intel_vgpu_cursor_plane_format *plane) 339 1.1 riastrad { 340 1.1 riastrad u32 val, mode, index; 341 1.1 riastrad u32 alpha_plane, alpha_force; 342 1.1 riastrad struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; 343 1.1 riastrad int pipe; 344 1.1 riastrad 345 1.1 riastrad pipe = get_active_pipe(vgpu); 346 1.1 riastrad if (pipe >= I915_MAX_PIPES) 347 1.1 riastrad return -ENODEV; 348 1.1 riastrad 349 1.1 riastrad val = vgpu_vreg_t(vgpu, CURCNTR(pipe)); 350 1.1 riastrad mode = val & MCURSOR_MODE; 351 1.1 riastrad plane->enabled = (mode != MCURSOR_MODE_DISABLE); 352 1.1 riastrad if (!plane->enabled) 353 1.1 riastrad return -ENODEV; 354 1.1 riastrad 355 1.1 riastrad index = cursor_mode_to_drm(mode); 356 1.1 riastrad 357 1.1 riastrad if (!cursor_pixel_formats[index].bpp) { 358 1.1 riastrad gvt_vgpu_err("Non-supported cursor mode (0x%x)\n", mode); 359 1.1 riastrad return -EINVAL; 360 1.1 riastrad } 361 1.1 riastrad plane->mode = mode; 362 1.1 riastrad plane->bpp = cursor_pixel_formats[index].bpp; 363 1.1 riastrad plane->drm_format = cursor_pixel_formats[index].drm_format; 364 1.1 riastrad plane->width = cursor_pixel_formats[index].width; 365 1.1 riastrad plane->height = cursor_pixel_formats[index].height; 366 1.1 riastrad 367 1.1 riastrad alpha_plane = (val & _CURSOR_ALPHA_PLANE_MASK) >> 368 1.1 riastrad _CURSOR_ALPHA_PLANE_SHIFT; 369 1.1 riastrad alpha_force = (val & _CURSOR_ALPHA_FORCE_MASK) >> 370 1.1 riastrad _CURSOR_ALPHA_FORCE_SHIFT; 371 1.1 riastrad if (alpha_plane || alpha_force) 372 1.1 riastrad gvt_dbg_core("alpha_plane=0x%x, alpha_force=0x%x\n", 373 1.1 riastrad alpha_plane, alpha_force); 374 1.1 riastrad 375 1.1 riastrad plane->base = vgpu_vreg_t(vgpu, CURBASE(pipe)) & I915_GTT_PAGE_MASK; 376 1.1 riastrad if (!vgpu_gmadr_is_valid(vgpu, plane->base)) 377 1.1 riastrad return -EINVAL; 378 1.1 riastrad 379 1.1 riastrad plane->base_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm, plane->base); 380 1.1 riastrad if (plane->base_gpa == INTEL_GVT_INVALID_ADDR) { 381 1.1 riastrad gvt_vgpu_err("Translate cursor plane gma 0x%x to gpa fail\n", 382 1.1 riastrad plane->base); 383 1.1 riastrad return -EINVAL; 384 1.1 riastrad } 385 1.1 riastrad 386 1.1 riastrad val = vgpu_vreg_t(vgpu, CURPOS(pipe)); 387 1.1 riastrad plane->x_pos = (val & _CURSOR_POS_X_MASK) >> _CURSOR_POS_X_SHIFT; 388 1.1 riastrad plane->x_sign = (val & _CURSOR_SIGN_X_MASK) >> _CURSOR_SIGN_X_SHIFT; 389 1.1 riastrad plane->y_pos = (val & _CURSOR_POS_Y_MASK) >> _CURSOR_POS_Y_SHIFT; 390 1.1 riastrad plane->y_sign = (val & _CURSOR_SIGN_Y_MASK) >> _CURSOR_SIGN_Y_SHIFT; 391 1.1 riastrad 392 1.1 riastrad plane->x_hot = vgpu_vreg_t(vgpu, vgtif_reg(cursor_x_hot)); 393 1.1 riastrad plane->y_hot = vgpu_vreg_t(vgpu, vgtif_reg(cursor_y_hot)); 394 1.1 riastrad return 0; 395 1.1 riastrad } 396 1.1 riastrad 397 1.1 riastrad #define SPRITE_FORMAT_NUM (1 << 3) 398 1.1 riastrad 399 1.1 riastrad static struct pixel_format sprite_pixel_formats[SPRITE_FORMAT_NUM] = { 400 1.1 riastrad [0x0] = {DRM_FORMAT_YUV422, 16, "YUV 16-bit 4:2:2 packed"}, 401 1.1 riastrad [0x1] = {DRM_FORMAT_XRGB2101010, 32, "RGB 32-bit 2:10:10:10"}, 402 1.1 riastrad [0x2] = {DRM_FORMAT_XRGB8888, 32, "RGB 32-bit 8:8:8:8"}, 403 1.1 riastrad [0x4] = {DRM_FORMAT_AYUV, 32, 404 1.1 riastrad "YUV 32-bit 4:4:4 packed (8:8:8:8 MSB-X:Y:U:V)"}, 405 1.1 riastrad }; 406 1.1 riastrad 407 1.1 riastrad /** 408 1.1 riastrad * intel_vgpu_decode_sprite_plane - Decode sprite plane 409 1.1 riastrad * @vgpu: input vgpu 410 1.1 riastrad * @plane: sprite plane to save decoded info 411 1.1 riastrad * This function is called for decoding plane 412 1.1 riastrad * 413 1.1 riastrad * Returns: 414 1.1 riastrad * 0 on success, non-zero if failed. 415 1.1 riastrad */ 416 1.1 riastrad int intel_vgpu_decode_sprite_plane(struct intel_vgpu *vgpu, 417 1.1 riastrad struct intel_vgpu_sprite_plane_format *plane) 418 1.1 riastrad { 419 1.1 riastrad u32 val, fmt; 420 1.1 riastrad u32 color_order, yuv_order; 421 1.1 riastrad int drm_format; 422 1.1 riastrad int pipe; 423 1.1 riastrad 424 1.1 riastrad pipe = get_active_pipe(vgpu); 425 1.1 riastrad if (pipe >= I915_MAX_PIPES) 426 1.1 riastrad return -ENODEV; 427 1.1 riastrad 428 1.1 riastrad val = vgpu_vreg_t(vgpu, SPRCTL(pipe)); 429 1.1 riastrad plane->enabled = !!(val & SPRITE_ENABLE); 430 1.1 riastrad if (!plane->enabled) 431 1.1 riastrad return -ENODEV; 432 1.1 riastrad 433 1.1 riastrad plane->tiled = !!(val & SPRITE_TILED); 434 1.1 riastrad color_order = !!(val & SPRITE_RGB_ORDER_RGBX); 435 1.1 riastrad yuv_order = (val & SPRITE_YUV_BYTE_ORDER_MASK) >> 436 1.1 riastrad _SPRITE_YUV_ORDER_SHIFT; 437 1.1 riastrad 438 1.1 riastrad fmt = (val & SPRITE_PIXFORMAT_MASK) >> _SPRITE_FMT_SHIFT; 439 1.1 riastrad if (!sprite_pixel_formats[fmt].bpp) { 440 1.1 riastrad gvt_vgpu_err("Non-supported pixel format (0x%x)\n", fmt); 441 1.1 riastrad return -EINVAL; 442 1.1 riastrad } 443 1.1 riastrad plane->hw_format = fmt; 444 1.1 riastrad plane->bpp = sprite_pixel_formats[fmt].bpp; 445 1.1 riastrad drm_format = sprite_pixel_formats[fmt].drm_format; 446 1.1 riastrad 447 1.1 riastrad /* Order of RGB values in an RGBxxx buffer may be ordered RGB or 448 1.1 riastrad * BGR depending on the state of the color_order field 449 1.1 riastrad */ 450 1.1 riastrad if (!color_order) { 451 1.1 riastrad if (drm_format == DRM_FORMAT_XRGB2101010) 452 1.1 riastrad drm_format = DRM_FORMAT_XBGR2101010; 453 1.1 riastrad else if (drm_format == DRM_FORMAT_XRGB8888) 454 1.1 riastrad drm_format = DRM_FORMAT_XBGR8888; 455 1.1 riastrad } 456 1.1 riastrad 457 1.1 riastrad if (drm_format == DRM_FORMAT_YUV422) { 458 1.1 riastrad switch (yuv_order) { 459 1.1 riastrad case 0: 460 1.1 riastrad drm_format = DRM_FORMAT_YUYV; 461 1.1 riastrad break; 462 1.1 riastrad case 1: 463 1.1 riastrad drm_format = DRM_FORMAT_UYVY; 464 1.1 riastrad break; 465 1.1 riastrad case 2: 466 1.1 riastrad drm_format = DRM_FORMAT_YVYU; 467 1.1 riastrad break; 468 1.1 riastrad case 3: 469 1.1 riastrad drm_format = DRM_FORMAT_VYUY; 470 1.1 riastrad break; 471 1.1 riastrad default: 472 1.1 riastrad /* yuv_order has only 2 bits */ 473 1.1 riastrad break; 474 1.1 riastrad } 475 1.1 riastrad } 476 1.1 riastrad 477 1.1 riastrad plane->drm_format = drm_format; 478 1.1 riastrad 479 1.1 riastrad plane->base = vgpu_vreg_t(vgpu, SPRSURF(pipe)) & I915_GTT_PAGE_MASK; 480 1.1 riastrad if (!vgpu_gmadr_is_valid(vgpu, plane->base)) 481 1.1 riastrad return -EINVAL; 482 1.1 riastrad 483 1.1 riastrad plane->base_gpa = intel_vgpu_gma_to_gpa(vgpu->gtt.ggtt_mm, plane->base); 484 1.1 riastrad if (plane->base_gpa == INTEL_GVT_INVALID_ADDR) { 485 1.1 riastrad gvt_vgpu_err("Translate sprite plane gma 0x%x to gpa fail\n", 486 1.1 riastrad plane->base); 487 1.1 riastrad return -EINVAL; 488 1.1 riastrad } 489 1.1 riastrad 490 1.1 riastrad plane->stride = vgpu_vreg_t(vgpu, SPRSTRIDE(pipe)) & 491 1.1 riastrad _SPRITE_STRIDE_MASK; 492 1.1 riastrad 493 1.1 riastrad val = vgpu_vreg_t(vgpu, SPRSIZE(pipe)); 494 1.1 riastrad plane->height = (val & _SPRITE_SIZE_HEIGHT_MASK) >> 495 1.1 riastrad _SPRITE_SIZE_HEIGHT_SHIFT; 496 1.1 riastrad plane->width = (val & _SPRITE_SIZE_WIDTH_MASK) >> 497 1.1 riastrad _SPRITE_SIZE_WIDTH_SHIFT; 498 1.1 riastrad plane->height += 1; /* raw height is one minus the real value */ 499 1.1 riastrad plane->width += 1; /* raw width is one minus the real value */ 500 1.1 riastrad 501 1.1 riastrad val = vgpu_vreg_t(vgpu, SPRPOS(pipe)); 502 1.1 riastrad plane->x_pos = (val & _SPRITE_POS_X_MASK) >> _SPRITE_POS_X_SHIFT; 503 1.1 riastrad plane->y_pos = (val & _SPRITE_POS_Y_MASK) >> _SPRITE_POS_Y_SHIFT; 504 1.1 riastrad 505 1.1 riastrad val = vgpu_vreg_t(vgpu, SPROFFSET(pipe)); 506 1.1 riastrad plane->x_offset = (val & _SPRITE_OFFSET_START_X_MASK) >> 507 1.1 riastrad _SPRITE_OFFSET_START_X_SHIFT; 508 1.1 riastrad plane->y_offset = (val & _SPRITE_OFFSET_START_Y_MASK) >> 509 1.1 riastrad _SPRITE_OFFSET_START_Y_SHIFT; 510 1.1 riastrad 511 1.1 riastrad return 0; 512 1.1 riastrad } 513