Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #ifdef DRV_MSM |
| 8 | |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 9 | #include <assert.h> |
| 10 | #include <drm_fourcc.h> |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 11 | #include <errno.h> |
Stephen Boyd | 5ff0cfd | 2019-04-09 11:03:00 -0700 | [diff] [blame] | 12 | #include <inttypes.h> |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 13 | #include <msm_drm.h> |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 14 | #include <stdbool.h> |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 15 | #include <stdio.h> |
| 16 | #include <string.h> |
| 17 | #include <sys/mman.h> |
| 18 | #include <xf86drm.h> |
| 19 | |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 20 | #include "drv_priv.h" |
| 21 | #include "helpers.h" |
| 22 | #include "util.h" |
| 23 | |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 24 | /* Alignment values are based on SDM845 Gfx IP */ |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 25 | #define DEFAULT_ALIGNMENT 64 |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 26 | #define BUFFER_SIZE_ALIGN 4096 |
| 27 | |
| 28 | #define VENUS_STRIDE_ALIGN 128 |
| 29 | #define VENUS_SCANLINE_ALIGN 16 |
| 30 | #define NV12_LINEAR_PADDING (12 * 1024) |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 31 | #define NV12_UBWC_PADDING(y_stride) (MAX(16 * 1024, y_stride * 48)) |
| 32 | #define MACROTILE_WIDTH_ALIGN 64 |
| 33 | #define MACROTILE_HEIGHT_ALIGN 16 |
| 34 | #define PLANE_SIZE_ALIGN 4096 |
| 35 | |
| 36 | #define MSM_UBWC_TILING 1 |
Stéphane Marchesin | 23e006a | 2018-02-28 16:37:46 -0800 | [diff] [blame] | 37 | |
Gurchetan Singh | b131c9d | 2018-08-28 14:17:05 -0700 | [diff] [blame] | 38 | static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, |
Gurchetan Singh | 71bc665 | 2018-09-17 17:42:05 -0700 | [diff] [blame] | 39 | DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, |
| 40 | DRM_FORMAT_XRGB8888 }; |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 41 | |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 42 | static const uint32_t texture_source_formats[] = { DRM_FORMAT_NV12, DRM_FORMAT_R8, |
| 43 | DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID }; |
Alexandre Courbot | 1805a9b | 2018-05-21 19:05:10 +0900 | [diff] [blame] | 44 | |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 45 | /* |
| 46 | * Each macrotile consists of m x n (mostly 4 x 4) tiles. |
| 47 | * Pixel data pitch/stride is aligned with macrotile width. |
| 48 | * Pixel data height is aligned with macrotile height. |
| 49 | * Entire pixel data buffer is aligned with 4k(bytes). |
| 50 | */ |
| 51 | static uint32_t get_ubwc_meta_size(uint32_t width, uint32_t height, uint32_t tile_width, |
| 52 | uint32_t tile_height) |
| 53 | { |
| 54 | uint32_t macrotile_width, macrotile_height; |
| 55 | |
| 56 | macrotile_width = DIV_ROUND_UP(width, tile_width); |
| 57 | macrotile_height = DIV_ROUND_UP(height, tile_height); |
| 58 | |
| 59 | // Align meta buffer width to 64 blocks |
| 60 | macrotile_width = ALIGN(macrotile_width, MACROTILE_WIDTH_ALIGN); |
| 61 | |
| 62 | // Align meta buffer height to 16 blocks |
| 63 | macrotile_height = ALIGN(macrotile_height, MACROTILE_HEIGHT_ALIGN); |
| 64 | |
| 65 | return ALIGN(macrotile_width * macrotile_height, PLANE_SIZE_ALIGN); |
| 66 | } |
| 67 | |
| 68 | static void msm_calculate_layout(struct bo *bo) |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 69 | { |
| 70 | uint32_t width, height; |
| 71 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 72 | width = bo->meta.width; |
| 73 | height = bo->meta.height; |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 74 | |
| 75 | /* NV12 format requires extra padding with platform |
| 76 | * specific alignments for venus driver |
| 77 | */ |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 78 | if (bo->meta.format == DRM_FORMAT_NV12) { |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 79 | uint32_t y_stride, uv_stride, y_scanline, uv_scanline, y_plane, uv_plane, size, |
| 80 | extra_padding; |
| 81 | |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 82 | y_stride = ALIGN(width, VENUS_STRIDE_ALIGN); |
| 83 | uv_stride = ALIGN(width, VENUS_STRIDE_ALIGN); |
| 84 | y_scanline = ALIGN(height, VENUS_SCANLINE_ALIGN * 2); |
| 85 | uv_scanline = ALIGN(DIV_ROUND_UP(height, 2), VENUS_SCANLINE_ALIGN); |
| 86 | y_plane = y_stride * y_scanline; |
| 87 | uv_plane = uv_stride * uv_scanline; |
| 88 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 89 | if (bo->meta.tiling == MSM_UBWC_TILING) { |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 90 | y_plane += get_ubwc_meta_size(width, height, 32, 8); |
| 91 | uv_plane += get_ubwc_meta_size(width >> 1, height >> 1, 16, 8); |
| 92 | extra_padding = NV12_UBWC_PADDING(y_stride); |
| 93 | } else { |
| 94 | extra_padding = NV12_LINEAR_PADDING; |
| 95 | } |
| 96 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 97 | bo->meta.strides[0] = y_stride; |
| 98 | bo->meta.sizes[0] = y_plane; |
| 99 | bo->meta.offsets[1] = y_plane; |
| 100 | bo->meta.strides[1] = uv_stride; |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 101 | size = y_plane + uv_plane + extra_padding; |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 102 | bo->meta.total_size = ALIGN(size, BUFFER_SIZE_ALIGN); |
| 103 | bo->meta.sizes[1] = bo->meta.total_size - bo->meta.sizes[0]; |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 104 | } else { |
| 105 | uint32_t stride, alignw, alignh; |
| 106 | |
| 107 | alignw = ALIGN(width, DEFAULT_ALIGNMENT); |
Jeffrey Kardatzke | a6a9efc | 2020-02-21 15:35:01 -0800 | [diff] [blame] | 108 | /* HAL_PIXEL_FORMAT_YV12 requires that the buffer's height not be aligned. |
| 109 | DRM_FORMAT_R8 of height one is used for JPEG camera output, so don't |
| 110 | height align that. */ |
| 111 | if (bo->meta.format == DRM_FORMAT_YVU420_ANDROID || |
Gurchetan Singh | 8d88474 | 2020-03-24 13:48:54 -0700 | [diff] [blame] | 112 | (bo->meta.format == DRM_FORMAT_R8 && height == 1)) { |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 113 | alignh = height; |
| 114 | } else { |
| 115 | alignh = ALIGN(height, DEFAULT_ALIGNMENT); |
| 116 | } |
| 117 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 118 | stride = drv_stride_from_format(bo->meta.format, alignw, 0); |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 119 | |
| 120 | /* Calculate size and assign stride, size, offset to each plane based on format */ |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 121 | drv_bo_from_format(bo, stride, alignh, bo->meta.format); |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 122 | |
| 123 | /* For all RGB UBWC formats */ |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 124 | if (bo->meta.tiling == MSM_UBWC_TILING) { |
| 125 | bo->meta.sizes[0] += get_ubwc_meta_size(width, height, 16, 4); |
| 126 | bo->meta.total_size = bo->meta.sizes[0]; |
| 127 | assert(IS_ALIGNED(bo->meta.total_size, BUFFER_SIZE_ALIGN)); |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | static bool is_ubwc_fmt(uint32_t format) |
| 133 | { |
| 134 | switch (format) { |
| 135 | case DRM_FORMAT_XBGR8888: |
| 136 | case DRM_FORMAT_ABGR8888: |
Fritz Koenig | e5c3fdf | 2019-12-10 16:30:34 -0800 | [diff] [blame] | 137 | case DRM_FORMAT_XRGB8888: |
| 138 | case DRM_FORMAT_ARGB8888: |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 139 | case DRM_FORMAT_NV12: |
| 140 | return 1; |
| 141 | default: |
| 142 | return 0; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | static void msm_add_ubwc_combinations(struct driver *drv, const uint32_t *formats, |
| 147 | uint32_t num_formats, struct format_metadata *metadata, |
| 148 | uint64_t use_flags) |
| 149 | { |
| 150 | for (uint32_t i = 0; i < num_formats; i++) { |
| 151 | if (is_ubwc_fmt(formats[i])) { |
| 152 | struct combination combo = { .format = formats[i], |
| 153 | .metadata = *metadata, |
| 154 | .use_flags = use_flags }; |
| 155 | drv_array_append(drv->combos, &combo); |
| 156 | } |
Tanmay Shah | c65bd8c | 2018-11-21 09:14:14 -0800 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 160 | static int msm_init(struct driver *drv) |
| 161 | { |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 162 | struct format_metadata metadata; |
Jeffrey Kardatzke | afb2c56 | 2020-03-02 12:25:55 -0800 | [diff] [blame] | 163 | uint64_t render_use_flags = BO_USE_RENDER_MASK | BO_USE_SCANOUT; |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 164 | uint64_t texture_use_flags = BO_USE_TEXTURE_MASK | BO_USE_HW_VIDEO_DECODER; |
| 165 | uint64_t sw_flags = (BO_USE_RENDERSCRIPT | BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_OFTEN | |
| 166 | BO_USE_LINEAR | BO_USE_PROTECTED); |
| 167 | |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 168 | drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 169 | &LINEAR_METADATA, render_use_flags); |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 170 | |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 171 | drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats), |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 172 | &LINEAR_METADATA, texture_use_flags); |
Alexandre Courbot | 1805a9b | 2018-05-21 19:05:10 +0900 | [diff] [blame] | 173 | |
Hirokazu Honda | 3b8d4d0 | 2019-07-31 16:35:52 +0900 | [diff] [blame] | 174 | /* |
| 175 | * Chrome uses DMA-buf mmap to write to YV12 buffers, which are then accessed by the |
| 176 | * Video Encoder Accelerator (VEA). It could also support NV12 potentially in the future. |
| 177 | */ |
| 178 | drv_modify_combination(drv, DRM_FORMAT_YVU420, &LINEAR_METADATA, BO_USE_HW_VIDEO_ENCODER); |
| 179 | drv_modify_combination(drv, DRM_FORMAT_NV12, &LINEAR_METADATA, BO_USE_HW_VIDEO_ENCODER); |
| 180 | |
Ricky Liang | f11f1df | 2020-02-13 10:42:46 +0800 | [diff] [blame] | 181 | /* The camera stack standardizes on NV12 for YUV buffers. */ |
| 182 | drv_modify_combination(drv, DRM_FORMAT_NV12, &LINEAR_METADATA, |
Jeffrey Kardatzke | afb2c56 | 2020-03-02 12:25:55 -0800 | [diff] [blame] | 183 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_SCANOUT); |
Ricky Liang | f11f1df | 2020-02-13 10:42:46 +0800 | [diff] [blame] | 184 | /* |
| 185 | * R8 format is used for Android's HAL_PIXEL_FORMAT_BLOB and is used for JPEG snapshots |
| 186 | * from camera. |
| 187 | */ |
| 188 | drv_modify_combination(drv, DRM_FORMAT_R8, &LINEAR_METADATA, |
| 189 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
| 190 | |
Gurchetan Singh | 71bc665 | 2018-09-17 17:42:05 -0700 | [diff] [blame] | 191 | /* Android CTS tests require this. */ |
| 192 | drv_add_combination(drv, DRM_FORMAT_BGR888, &LINEAR_METADATA, BO_USE_SW_MASK); |
| 193 | |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 194 | drv_modify_linear_combinations(drv); |
| 195 | |
| 196 | metadata.tiling = MSM_UBWC_TILING; |
| 197 | metadata.priority = 2; |
| 198 | metadata.modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED; |
| 199 | |
| 200 | render_use_flags &= ~sw_flags; |
| 201 | texture_use_flags &= ~sw_flags; |
| 202 | |
| 203 | msm_add_ubwc_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), |
Jeffrey Kardatzke | afb2c56 | 2020-03-02 12:25:55 -0800 | [diff] [blame] | 204 | &metadata, render_use_flags); |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 205 | |
| 206 | msm_add_ubwc_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats), |
Jeffrey Kardatzke | 6f26690 | 2020-02-13 16:19:03 -0800 | [diff] [blame] | 207 | &metadata, texture_use_flags); |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 208 | |
| 209 | return 0; |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 210 | } |
| 211 | |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 212 | static int msm_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t height, |
| 213 | uint32_t format, const uint64_t modifier) |
Stéphane Marchesin | 23e006a | 2018-02-28 16:37:46 -0800 | [diff] [blame] | 214 | { |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 215 | struct drm_msm_gem_new req; |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 216 | int ret; |
| 217 | size_t i; |
| 218 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 219 | bo->meta.tiling = (modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED) ? MSM_UBWC_TILING : 0; |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 220 | |
| 221 | msm_calculate_layout(bo); |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 222 | |
| 223 | memset(&req, 0, sizeof(req)); |
| 224 | req.flags = MSM_BO_WC | MSM_BO_SCANOUT; |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 225 | req.size = bo->meta.total_size; |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 226 | |
| 227 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_NEW, &req); |
| 228 | if (ret) { |
| 229 | drv_log("DRM_IOCTL_MSM_GEM_NEW failed with %s\n", strerror(errno)); |
Stéphane Marchesin | 6ac299f | 2019-03-21 12:23:29 -0700 | [diff] [blame] | 230 | return -errno; |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Though we use only one plane, we need to set handle for |
| 235 | * all planes to pass kernel checks |
| 236 | */ |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 237 | for (i = 0; i < bo->meta.num_planes; i++) { |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 238 | bo->handles[i].u32 = req.handle; |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 239 | bo->meta.format_modifiers[i] = modifier; |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 245 | static int msm_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height, |
| 246 | uint32_t format, const uint64_t *modifiers, uint32_t count) |
| 247 | { |
| 248 | static const uint64_t modifier_order[] = { |
| 249 | DRM_FORMAT_MOD_QCOM_COMPRESSED, |
| 250 | DRM_FORMAT_MOD_LINEAR, |
| 251 | }; |
| 252 | |
| 253 | uint64_t modifier = |
| 254 | drv_pick_modifier(modifiers, count, modifier_order, ARRAY_SIZE(modifier_order)); |
| 255 | |
| 256 | return msm_bo_create_for_modifier(bo, width, height, format, modifier); |
| 257 | } |
| 258 | |
| 259 | /* msm_bo_create will create linear buffers for now */ |
| 260 | static int msm_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, |
| 261 | uint64_t flags) |
| 262 | { |
| 263 | struct combination *combo = drv_get_combination(bo->drv, format, flags); |
| 264 | |
| 265 | if (!combo) { |
Stephen Boyd | 5ff0cfd | 2019-04-09 11:03:00 -0700 | [diff] [blame] | 266 | drv_log("invalid format = %d, flags = %" PRIx64 " combination\n", format, flags); |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 267 | return -EINVAL; |
| 268 | } |
| 269 | |
| 270 | return msm_bo_create_for_modifier(bo, width, height, format, combo->metadata.modifier); |
| 271 | } |
| 272 | |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 273 | static void *msm_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags) |
| 274 | { |
| 275 | int ret; |
| 276 | struct drm_msm_gem_info req; |
| 277 | |
| 278 | memset(&req, 0, sizeof(req)); |
| 279 | req.handle = bo->handles[0].u32; |
| 280 | |
| 281 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_INFO, &req); |
| 282 | if (ret) { |
| 283 | drv_log("DRM_IOCLT_MSM_GEM_INFO failed with %s\n", strerror(errno)); |
| 284 | return MAP_FAILED; |
| 285 | } |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 286 | vma->length = bo->meta.total_size; |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 287 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 288 | return mmap(0, bo->meta.total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd, |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 289 | req.offset); |
Stéphane Marchesin | 23e006a | 2018-02-28 16:37:46 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Jeffrey Kardatzke | e3cd0d3 | 2020-02-25 10:33:37 -0800 | [diff] [blame] | 292 | static uint32_t msm_resolve_format(struct driver *drv, uint32_t format, uint64_t use_flags) |
| 293 | { |
| 294 | switch (format) { |
Douglas Anderson | 64b80ce | 2020-05-19 10:12:14 -0700 | [diff] [blame^] | 295 | case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: |
| 296 | /* Camera subsystem requires NV12. */ |
| 297 | if (use_flags & (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE)) |
| 298 | return DRM_FORMAT_NV12; |
| 299 | /*HACK: See b/28671744 */ |
| 300 | return DRM_FORMAT_XBGR8888; |
Jeffrey Kardatzke | e3cd0d3 | 2020-02-25 10:33:37 -0800 | [diff] [blame] | 301 | case DRM_FORMAT_FLEX_YCbCr_420_888: |
| 302 | return DRM_FORMAT_NV12; |
| 303 | default: |
| 304 | return format; |
| 305 | } |
| 306 | } |
| 307 | |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 308 | const struct backend backend_msm = { |
| 309 | .name = "msm", |
| 310 | .init = msm_init, |
Stéphane Marchesin | 23e006a | 2018-02-28 16:37:46 -0800 | [diff] [blame] | 311 | .bo_create = msm_bo_create, |
Tanmay Shah | 067594b | 2018-11-26 10:05:18 -0800 | [diff] [blame] | 312 | .bo_create_with_modifiers = msm_bo_create_with_modifiers, |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 313 | .bo_destroy = drv_gem_bo_destroy, |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 314 | .bo_import = drv_prime_bo_import, |
Tanmay Shah | 617ee71 | 2018-07-11 16:41:05 -0700 | [diff] [blame] | 315 | .bo_map = msm_bo_map, |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 316 | .bo_unmap = drv_bo_munmap, |
Jeffrey Kardatzke | e3cd0d3 | 2020-02-25 10:33:37 -0800 | [diff] [blame] | 317 | .resolve_format = msm_resolve_format, |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 318 | }; |
Rajesh Yadav | 7f79cb5 | 2018-01-22 18:29:06 +0530 | [diff] [blame] | 319 | #endif /* DRV_MSM */ |