blob: 076f47841067aec24652cc82c1cc7e57bec3ce5c [file] [log] [blame]
JB Tsai0c16a0f2015-03-19 14:30:31 +08001/*
2 * Copyright 2015 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
Gurchetan Singh46faf6b2016-08-05 14:40:07 -07007#ifdef DRV_MEDIATEK
JB Tsai0c16a0f2015-03-19 14:30:31 +08008
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -08009// clang-format off
Stéphane Marchesin6ac299f2019-03-21 12:23:29 -070010#include <errno.h>
Luigi Santivetti500928f2018-08-28 10:09:20 +010011#include <fcntl.h>
Nicolas Boichatd7c83382019-08-29 21:46:29 +080012#include <inttypes.h>
Luigi Santivetti500928f2018-08-28 10:09:20 +010013#include <poll.h>
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -070014#include <stdio.h>
JB Tsai0c16a0f2015-03-19 14:30:31 +080015#include <string.h>
Gurchetan Singhef920532016-08-12 16:38:25 -070016#include <sys/mman.h>
Luigi Santivetti500928f2018-08-28 10:09:20 +010017#include <unistd.h>
JB Tsai0c16a0f2015-03-19 14:30:31 +080018#include <xf86drm.h>
19#include <mediatek_drm.h>
Gurchetan Singh1b1d56a2017-03-10 16:25:23 -080020// clang-format on
Gurchetan Singhef920532016-08-12 16:38:25 -070021
Yiwei Zhangb7a64442021-09-30 05:13:10 +000022#include "drv_helpers.h"
Gurchetan Singh46faf6b2016-08-05 14:40:07 -070023#include "drv_priv.h"
Gurchetan Singh179687e2016-10-28 10:07:35 -070024#include "util.h"
25
Miguel Casasdea0ccb2018-07-02 09:40:25 -040026#define TILE_TYPE_LINEAR 0
27
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +080028#if defined(MTK_MT8183) || defined(MTK_MT8186)
29#define SUPPORTS_YUV422_AND_HIGH_BIT_DEPTH_TEXTURING
30#endif
31
32// All platforms except MT8173 should USE_NV12_FOR_HW_VIDEO_DECODING.
33#if defined(MTK_MT8183) || defined(MTK_MT8186) || defined(MTK_MT8192) || defined(MTK_MT8195)
34#define USE_NV12_FOR_HW_VIDEO_DECODING
Miguel Casas35fd7d22022-02-18 10:52:28 -080035#else
36#define DONT_USE_64_ALIGNMENT_FOR_VIDEO_BUFFERS
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +080037#endif
38
Gurchetan Singh469a3aa2017-08-03 18:17:34 -070039struct mediatek_private_map_data {
40 void *cached_addr;
41 void *gem_addr;
Luigi Santivetti500928f2018-08-28 10:09:20 +010042 int prime_fd;
Gurchetan Singh469a3aa2017-08-03 18:17:34 -070043};
44
Gurchetan Singh767c5382018-05-05 00:42:12 +000045static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
Gurchetan Singh71bc6652018-09-17 17:42:05 -070046 DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888,
47 DRM_FORMAT_XRGB8888 };
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070048
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +080049// clang-format off
Yiwei Zhangf4c17252021-10-30 08:29:48 +000050static const uint32_t texture_source_formats[] = {
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +080051#ifdef SUPPORTS_YUV422_AND_HIGH_BIT_DEPTH_TEXTURING
52 DRM_FORMAT_NV21,
53 DRM_FORMAT_YUYV,
54 DRM_FORMAT_ABGR2101010,
55 DRM_FORMAT_ABGR16161616F,
Nick Fan01c40142018-10-08 11:53:26 +080056#endif
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +080057 DRM_FORMAT_NV12,
58 DRM_FORMAT_YVU420,
59 DRM_FORMAT_YVU420_ANDROID
60};
Miguel Casas35fd7d22022-02-18 10:52:28 -080061
62#ifdef DONT_USE_64_ALIGNMENT_FOR_VIDEO_BUFFERS
63static const uint32_t video_yuv_formats[] = {
64 DRM_FORMAT_NV21,
65 DRM_FORMAT_NV12,
66 DRM_FORMAT_YVU420,
67 DRM_FORMAT_YVU420_ANDROID
68};
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +080069// clang-format on
Gurchetan Singh179687e2016-10-28 10:07:35 -070070
Miguel Casas35fd7d22022-02-18 10:52:28 -080071static bool is_video_yuv_format(uint32_t format)
72{
73 size_t i;
74 for (i = 0; i < ARRAY_SIZE(video_yuv_formats); ++i) {
75 if (format == video_yuv_formats[i])
76 return true;
77 }
78 return false;
79}
80#endif
81
Gurchetan Singh179687e2016-10-28 10:07:35 -070082static int mediatek_init(struct driver *drv)
83{
Miguel Casasdea0ccb2018-07-02 09:40:25 -040084 struct format_metadata metadata;
85
Gurchetan Singhd3001452017-11-03 17:18:36 -070086 drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
Gurchetan Singh1914f982020-03-24 13:53:51 -070087 &LINEAR_METADATA, BO_USE_RENDER_MASK | BO_USE_SCANOUT);
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070088
Gurchetan Singhd3001452017-11-03 17:18:36 -070089 drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats),
90 &LINEAR_METADATA, BO_USE_TEXTURE_MASK);
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -070091
Gurchetan Singhbbba9dd2020-10-12 17:31:10 -070092 drv_add_combination(drv, DRM_FORMAT_R8, &LINEAR_METADATA, BO_USE_SW_MASK | BO_USE_LINEAR);
Hirokazu Hondafd8b8ab2020-06-16 15:28:56 +090093
Gurchetan Singh71bc6652018-09-17 17:42:05 -070094 /* Android CTS tests require this. */
95 drv_add_combination(drv, DRM_FORMAT_BGR888, &LINEAR_METADATA, BO_USE_SW_MASK);
96
Miguel Casasdea0ccb2018-07-02 09:40:25 -040097 /* Support BO_USE_HW_VIDEO_DECODER for protected content minigbm allocations. */
98 metadata.tiling = TILE_TYPE_LINEAR;
99 metadata.priority = 1;
100 metadata.modifier = DRM_FORMAT_MOD_LINEAR;
101 drv_modify_combination(drv, DRM_FORMAT_YVU420, &metadata, BO_USE_HW_VIDEO_DECODER);
102 drv_modify_combination(drv, DRM_FORMAT_YVU420_ANDROID, &metadata, BO_USE_HW_VIDEO_DECODER);
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +0800103#ifdef USE_NV12_FOR_HW_VIDEO_DECODING
Wei Lee2f02cfb2020-08-05 17:24:45 +0800104 // TODO(hiroh): Switch to use NV12 for video decoder on MT8173 as well.
Hirokazu Honda0f0ce6f2019-07-24 19:40:20 +0900105 drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata, BO_USE_HW_VIDEO_DECODER);
Wei Lee2f02cfb2020-08-05 17:24:45 +0800106#endif
Miguel Casasdea0ccb2018-07-02 09:40:25 -0400107
David Stevens49518142020-06-15 13:48:48 +0900108 /*
109 * R8 format is used for Android's HAL_PIXEL_FORMAT_BLOB for input/output from
110 * hardware decoder/encoder.
111 */
112 drv_modify_combination(drv, DRM_FORMAT_R8, &metadata,
Wei Leee03625b2020-07-21 11:27:14 +0800113 BO_USE_HW_VIDEO_DECODER | BO_USE_HW_VIDEO_ENCODER |
114 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
David Stevens49518142020-06-15 13:48:48 +0900115
Hirokazu Honda3bd681c2020-06-23 17:52:20 +0900116 /* NV12 format for encoding and display. */
117 drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata,
Wei Leee03625b2020-07-21 11:27:14 +0800118 BO_USE_SCANOUT | BO_USE_HW_VIDEO_ENCODER | BO_USE_CAMERA_READ |
119 BO_USE_CAMERA_WRITE);
Hirokazu Honda3bd681c2020-06-23 17:52:20 +0900120
Wei Leee03625b2020-07-21 11:27:14 +0800121#ifdef MTK_MT8183
Nick Fan01c40142018-10-08 11:53:26 +0800122 /* Only for MT8183 Camera subsystem */
Nick Fan01c40142018-10-08 11:53:26 +0800123 drv_modify_combination(drv, DRM_FORMAT_NV21, &metadata,
124 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
125 drv_modify_combination(drv, DRM_FORMAT_YUYV, &metadata,
126 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
127 drv_modify_combination(drv, DRM_FORMAT_YVU420, &metadata,
128 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
Jasmine Chenc7aa9742019-08-14 15:28:22 +0800129 /* Private formats for private reprocessing in camera */
130 drv_add_combination(drv, DRM_FORMAT_MTISP_SXYZW10, &metadata,
131 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_SW_MASK);
Nick Fan01c40142018-10-08 11:53:26 +0800132#endif
133
Gurchetan Singh8ac0c9a2017-05-15 09:34:22 -0700134 return drv_modify_linear_combinations(drv);
Gurchetan Singh179687e2016-10-28 10:07:35 -0700135}
JB Tsai0c16a0f2015-03-19 14:30:31 +0800136
Fritz Koenig1b9b5b92019-03-19 13:25:45 -0700137static int mediatek_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
138 uint32_t format, const uint64_t *modifiers,
139 uint32_t count)
JB Tsai0c16a0f2015-03-19 14:30:31 +0800140{
JB Tsai0c16a0f2015-03-19 14:30:31 +0800141 int ret;
Gurchetan Singh42cc6d62016-08-29 18:19:19 -0700142 size_t plane;
Gurchetan Singh6423ecb2017-03-29 08:23:40 -0700143 uint32_t stride;
Gurchetan Singh99644382020-10-07 15:28:11 -0700144 struct drm_mtk_gem_create gem_create = { 0 };
JB Tsai0c16a0f2015-03-19 14:30:31 +0800145
Fritz Koenig1b9b5b92019-03-19 13:25:45 -0700146 if (!drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_LINEAR)) {
147 errno = EINVAL;
148 drv_log("no usable modifier found\n");
149 return -EINVAL;
150 }
151
Gurchetan Singh6ea14ba2017-02-08 15:09:13 -0800152 /*
153 * Since the ARM L1 cache line size is 64 bytes, align to that as a
Miguel Casas35fd7d22022-02-18 10:52:28 -0800154 * performance optimization, except for video buffers on certain platforms,
155 * these should only be accessed from the GPU and VCODEC subsystems (maybe
156 * also MDP), so it's better to align to macroblocks.
Gurchetan Singh6ea14ba2017-02-08 15:09:13 -0800157 */
Gurchetan Singh6423ecb2017-03-29 08:23:40 -0700158 stride = drv_stride_from_format(format, width, 0);
Miguel Casas35fd7d22022-02-18 10:52:28 -0800159#ifdef DONT_USE_64_ALIGNMENT_FOR_VIDEO_BUFFERS
160 const uint32_t alignment = is_video_yuv_format(format) ? 16 : 64;
161 stride = ALIGN(stride, alignment);
162#else
Gurchetan Singh6423ecb2017-03-29 08:23:40 -0700163 stride = ALIGN(stride, 64);
Miguel Casas35fd7d22022-02-18 10:52:28 -0800164#endif
Hirokazu Honda2a2bfc22019-10-11 15:54:50 +0900165
Hsin-Yi Wangc37de982022-03-25 17:50:35 +0800166 if (bo->meta.use_flags & (BO_USE_HW_VIDEO_ENCODER | BO_USE_SCANOUT)) {
Hirokazu Honda2a2bfc22019-10-11 15:54:50 +0900167 uint32_t aligned_height = ALIGN(height, 32);
168 uint32_t padding[DRV_MAX_PLANES] = { 0 };
169
170 for (plane = 0; plane < bo->meta.num_planes; ++plane) {
171 uint32_t plane_stride = drv_stride_from_format(format, stride, plane);
172 padding[plane] = plane_stride *
173 (32 / drv_vertical_subsampling_from_format(format, plane));
174 }
175
176 drv_bo_from_format_and_padding(bo, stride, aligned_height, format, padding);
177 } else {
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +0800178#ifdef SUPPORTS_YUV422_AND_HIGH_BIT_DEPTH_TEXTURING
Moja Hsu059ac082019-10-02 14:47:10 +0800179 /*
180 * JPEG Encoder Accelerator requires 16x16 alignment. We want the buffer
181 * from camera can be put in JEA directly so align the height to 16
182 * bytes.
183 */
184 if (format == DRM_FORMAT_NV12)
185 height = ALIGN(height, 16);
186#endif
Hirokazu Honda2a2bfc22019-10-11 15:54:50 +0900187 drv_bo_from_format(bo, stride, height, format);
188 }
Yuly Novikov96c7a3b2015-12-08 22:48:29 -0500189
Gurchetan Singh298b7572019-09-19 09:55:18 -0700190 gem_create.size = bo->meta.total_size;
JB Tsai0c16a0f2015-03-19 14:30:31 +0800191
Gurchetan Singh46faf6b2016-08-05 14:40:07 -0700192 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create);
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -0700193 if (ret) {
Nicolas Boichatd7c83382019-08-29 21:46:29 +0800194 drv_log("DRM_IOCTL_MTK_GEM_CREATE failed (size=%" PRIu64 ")\n", gem_create.size);
Stéphane Marchesin6ac299f2019-03-21 12:23:29 -0700195 return -errno;
Ilja H. Friedelf9d2ab72015-04-09 14:08:36 -0700196 }
JB Tsai0c16a0f2015-03-19 14:30:31 +0800197
Gurchetan Singh298b7572019-09-19 09:55:18 -0700198 for (plane = 0; plane < bo->meta.num_planes; plane++)
Gurchetan Singh42cc6d62016-08-29 18:19:19 -0700199 bo->handles[plane].u32 = gem_create.handle;
JB Tsai0c16a0f2015-03-19 14:30:31 +0800200
201 return 0;
202}
203
Fritz Koenig1b9b5b92019-03-19 13:25:45 -0700204static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
205 uint64_t use_flags)
206{
207 uint64_t modifiers[] = { DRM_FORMAT_MOD_LINEAR };
208 return mediatek_bo_create_with_modifiers(bo, width, height, format, modifiers,
209 ARRAY_SIZE(modifiers));
210}
211
Gurchetan Singhee43c302017-11-14 18:20:27 -0800212static void *mediatek_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags)
Gurchetan Singhef920532016-08-12 16:38:25 -0700213{
Luigi Santivetti500928f2018-08-28 10:09:20 +0100214 int ret, prime_fd;
Gurchetan Singh99644382020-10-07 15:28:11 -0700215 struct drm_mtk_gem_map_off gem_map = { 0 };
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700216 struct mediatek_private_map_data *priv;
Yiwei Zhangafdf87d2021-09-28 04:06:06 +0000217 void *addr = NULL;
Gurchetan Singhef920532016-08-12 16:38:25 -0700218
Gurchetan Singhef920532016-08-12 16:38:25 -0700219 gem_map.handle = bo->handles[0].u32;
220
221 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_MAP_OFFSET, &gem_map);
222 if (ret) {
Alistair Strachan0cfaaa52018-03-19 14:03:23 -0700223 drv_log("DRM_IOCTL_MTK_GEM_MAP_OFFSET failed\n");
Gurchetan Singhef920532016-08-12 16:38:25 -0700224 return MAP_FAILED;
225 }
226
David Stevensddb56b52020-03-13 15:24:37 +0900227 prime_fd = drv_bo_get_plane_fd(bo, 0);
228 if (prime_fd < 0) {
Luigi Santivetti500928f2018-08-28 10:09:20 +0100229 drv_log("Failed to get a prime fd\n");
230 return MAP_FAILED;
231 }
232
Yiwei Zhangafdf87d2021-09-28 04:06:06 +0000233 addr = mmap(0, bo->meta.total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
234 gem_map.offset);
235 if (addr == MAP_FAILED)
236 goto out_close_prime_fd;
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700237
Gurchetan Singh298b7572019-09-19 09:55:18 -0700238 vma->length = bo->meta.total_size;
Gurchetan Singh1a31e602016-10-06 10:58:00 -0700239
Luigi Santivetti500928f2018-08-28 10:09:20 +0100240 priv = calloc(1, sizeof(*priv));
Yiwei Zhangafdf87d2021-09-28 04:06:06 +0000241 if (!priv)
242 goto out_unmap_addr;
Luigi Santivetti500928f2018-08-28 10:09:20 +0100243
Gurchetan Singh298b7572019-09-19 09:55:18 -0700244 if (bo->meta.use_flags & BO_USE_RENDERSCRIPT) {
245 priv->cached_addr = calloc(1, bo->meta.total_size);
Yiwei Zhangafdf87d2021-09-28 04:06:06 +0000246 if (!priv->cached_addr)
247 goto out_free_priv;
248
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700249 priv->gem_addr = addr;
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700250 addr = priv->cached_addr;
251 }
252
Yiwei Zhangafdf87d2021-09-28 04:06:06 +0000253 priv->prime_fd = prime_fd;
254 vma->priv = priv;
255
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700256 return addr;
Yiwei Zhangafdf87d2021-09-28 04:06:06 +0000257
258out_free_priv:
259 free(priv);
260out_unmap_addr:
261 munmap(addr, bo->meta.total_size);
262out_close_prime_fd:
263 close(prime_fd);
264 return MAP_FAILED;
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700265}
266
Gurchetan Singhee43c302017-11-14 18:20:27 -0800267static int mediatek_bo_unmap(struct bo *bo, struct vma *vma)
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700268{
Gurchetan Singhee43c302017-11-14 18:20:27 -0800269 if (vma->priv) {
270 struct mediatek_private_map_data *priv = vma->priv;
Luigi Santivettia72f4422018-09-12 16:28:21 +0100271
272 if (priv->cached_addr) {
273 vma->addr = priv->gem_addr;
274 free(priv->cached_addr);
275 }
276
Luigi Santivetti500928f2018-08-28 10:09:20 +0100277 close(priv->prime_fd);
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700278 free(priv);
Gurchetan Singhee43c302017-11-14 18:20:27 -0800279 vma->priv = NULL;
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700280 }
281
Gurchetan Singhee43c302017-11-14 18:20:27 -0800282 return munmap(vma->addr, vma->length);
Gurchetan Singhef920532016-08-12 16:38:25 -0700283}
284
Gurchetan Singhef262d82017-11-28 16:56:17 -0800285static int mediatek_bo_invalidate(struct bo *bo, struct mapping *mapping)
286{
Luigi Santivetti500928f2018-08-28 10:09:20 +0100287 struct mediatek_private_map_data *priv = mapping->vma->priv;
288
289 if (priv) {
290 struct pollfd fds = {
291 .fd = priv->prime_fd,
292 };
293
294 if (mapping->vma->map_flags & BO_MAP_WRITE)
295 fds.events |= POLLOUT;
296
297 if (mapping->vma->map_flags & BO_MAP_READ)
298 fds.events |= POLLIN;
299
300 poll(&fds, 1, -1);
301 if (fds.revents != fds.events)
302 drv_log("poll prime_fd failed\n");
303
304 if (priv->cached_addr)
Gurchetan Singh298b7572019-09-19 09:55:18 -0700305 memcpy(priv->cached_addr, priv->gem_addr, bo->meta.total_size);
Gurchetan Singhef262d82017-11-28 16:56:17 -0800306 }
307
308 return 0;
309}
310
Gurchetan Singh47e629b2017-11-02 14:07:18 -0700311static int mediatek_bo_flush(struct bo *bo, struct mapping *mapping)
Gurchetan Singh8e02e052017-09-14 14:18:43 -0700312{
Gurchetan Singh47e629b2017-11-02 14:07:18 -0700313 struct mediatek_private_map_data *priv = mapping->vma->priv;
Luigi Santivetti500928f2018-08-28 10:09:20 +0100314 if (priv && priv->cached_addr && (mapping->vma->map_flags & BO_MAP_WRITE))
Gurchetan Singh298b7572019-09-19 09:55:18 -0700315 memcpy(priv->gem_addr, priv->cached_addr, bo->meta.total_size);
Gurchetan Singh8e02e052017-09-14 14:18:43 -0700316
317 return 0;
318}
319
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000320static void mediatek_resolve_format_and_use_flags(struct driver *drv, uint32_t format,
321 uint64_t use_flags, uint32_t *out_format,
322 uint64_t *out_use_flags)
Gurchetan Singh42cc6d62016-08-29 18:19:19 -0700323{
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000324 *out_format = format;
325 *out_use_flags = use_flags;
Gurchetan Singh42cc6d62016-08-29 18:19:19 -0700326 switch (format) {
Gurchetan Singhf3b22da2016-11-21 10:46:38 -0800327 case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED:
Nick Fan01c40142018-10-08 11:53:26 +0800328#ifdef MTK_MT8183
Jasmine Chenc7aa9742019-08-14 15:28:22 +0800329 /* Only MT8183 Camera subsystem offers private reprocessing
330 * capability. CAMERA_READ indicates the buffer is intended for
331 * reprocessing and hence given the private format for MTK. */
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000332 if (use_flags & BO_USE_CAMERA_READ) {
333 *out_format = DRM_FORMAT_MTISP_SXYZW10;
334 break;
335 }
Nick Fan01c40142018-10-08 11:53:26 +0800336#endif
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000337 if (use_flags & BO_USE_CAMERA_WRITE) {
338 *out_format = DRM_FORMAT_NV12;
339 break;
340 }
Wei Leee03625b2020-07-21 11:27:14 +0800341
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000342 /* HACK: See b/28671744 */
343 *out_format = DRM_FORMAT_XBGR8888;
Yiwei Zhang3a171db2021-10-01 22:12:05 +0000344 *out_use_flags &= ~BO_USE_HW_VIDEO_ENCODER;
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000345 break;
Gurchetan Singhf3b22da2016-11-21 10:46:38 -0800346 case DRM_FORMAT_FLEX_YCbCr_420_888:
Hsin-Yi Wang8fe9f192022-01-18 17:51:02 +0800347#ifdef USE_NV12_FOR_HW_VIDEO_DECODING
Wei Lee2f02cfb2020-08-05 17:24:45 +0800348 // TODO(hiroh): Switch to use NV12 for video decoder on MT8173 as well.
349 if (use_flags & (BO_USE_HW_VIDEO_DECODER)) {
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000350 *out_format = DRM_FORMAT_NV12;
351 break;
Wei Lee2f02cfb2020-08-05 17:24:45 +0800352 }
353#endif
354 if (use_flags &
355 (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_HW_VIDEO_ENCODER)) {
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000356 *out_format = DRM_FORMAT_NV12;
357 break;
Hirokazu Honda2a2bfc22019-10-11 15:54:50 +0900358 }
Yiwei Zhangb3caf222021-10-01 21:55:58 +0000359
360 /* HACK: See b/139714614 */
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000361 *out_format = DRM_FORMAT_YVU420;
Yiwei Zhangb3caf222021-10-01 21:55:58 +0000362 *out_use_flags &= ~BO_USE_SCANOUT;
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000363 break;
364 case DRM_FORMAT_YVU420_ANDROID:
365 *out_use_flags &= ~BO_USE_SCANOUT;
366 break;
Gurchetan Singh42cc6d62016-08-29 18:19:19 -0700367 default:
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000368 break;
Gurchetan Singh42cc6d62016-08-29 18:19:19 -0700369 }
370}
371
Gurchetan Singh3e9d3832017-10-31 10:36:25 -0700372const struct backend backend_mediatek = {
JB Tsai0c16a0f2015-03-19 14:30:31 +0800373 .name = "mediatek",
Gurchetan Singh179687e2016-10-28 10:07:35 -0700374 .init = mediatek_init,
Gurchetan Singhd7c84fd2016-08-16 18:18:24 -0700375 .bo_create = mediatek_bo_create,
Fritz Koenig1b9b5b92019-03-19 13:25:45 -0700376 .bo_create_with_modifiers = mediatek_bo_create_with_modifiers,
Gurchetan Singh46faf6b2016-08-05 14:40:07 -0700377 .bo_destroy = drv_gem_bo_destroy,
Gurchetan Singh71611d62017-01-03 16:49:56 -0800378 .bo_import = drv_prime_bo_import,
Gurchetan Singhd7c84fd2016-08-16 18:18:24 -0700379 .bo_map = mediatek_bo_map,
Gurchetan Singh469a3aa2017-08-03 18:17:34 -0700380 .bo_unmap = mediatek_bo_unmap,
Gurchetan Singhef262d82017-11-28 16:56:17 -0800381 .bo_invalidate = mediatek_bo_invalidate,
Gurchetan Singh8e02e052017-09-14 14:18:43 -0700382 .bo_flush = mediatek_bo_flush,
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000383 .resolve_format_and_use_flags = mediatek_resolve_format_and_use_flags,
JB Tsai0c16a0f2015-03-19 14:30:31 +0800384};
385
386#endif