JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 1 | /* |
| 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 Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 7 | #ifdef DRV_MEDIATEK |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 8 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 9 | // clang-format off |
Stéphane Marchesin | 6ac299f | 2019-03-21 12:23:29 -0700 | [diff] [blame] | 10 | #include <errno.h> |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 11 | #include <fcntl.h> |
Nicolas Boichat | d7c8338 | 2019-08-29 21:46:29 +0800 | [diff] [blame] | 12 | #include <inttypes.h> |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 13 | #include <poll.h> |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 14 | #include <stdio.h> |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 15 | #include <string.h> |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 16 | #include <sys/mman.h> |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 17 | #include <unistd.h> |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 18 | #include <xf86drm.h> |
| 19 | #include <mediatek_drm.h> |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 20 | // clang-format on |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 21 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 22 | #include "drv_priv.h" |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 23 | #include "helpers.h" |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 24 | #include "util.h" |
| 25 | |
Miguel Casas | dea0ccb | 2018-07-02 09:40:25 -0400 | [diff] [blame] | 26 | #define TILE_TYPE_LINEAR 0 |
| 27 | |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 28 | struct mediatek_private_map_data { |
| 29 | void *cached_addr; |
| 30 | void *gem_addr; |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 31 | int prime_fd; |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
Gurchetan Singh | 767c538 | 2018-05-05 00:42:12 +0000 | [diff] [blame] | 34 | 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] | 35 | DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, |
| 36 | DRM_FORMAT_XRGB8888 }; |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 37 | |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 38 | #ifdef MTK_MT8183 |
Gurchetan Singh | dc9b120 | 2019-06-04 16:53:54 -0700 | [diff] [blame] | 39 | static const uint32_t texture_source_formats[] = { DRM_FORMAT_NV21, DRM_FORMAT_NV12, |
| 40 | DRM_FORMAT_YUYV, DRM_FORMAT_YVU420, |
| 41 | DRM_FORMAT_YVU420_ANDROID }; |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 42 | #else |
Gurchetan Singh | dc9b120 | 2019-06-04 16:53:54 -0700 | [diff] [blame] | 43 | static const uint32_t texture_source_formats[] = { DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID, |
| 44 | DRM_FORMAT_NV12 }; |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 45 | #endif |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 46 | |
| 47 | static int mediatek_init(struct driver *drv) |
| 48 | { |
Miguel Casas | dea0ccb | 2018-07-02 09:40:25 -0400 | [diff] [blame] | 49 | struct format_metadata metadata; |
| 50 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 51 | drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), |
Gurchetan Singh | 1914f98 | 2020-03-24 13:53:51 -0700 | [diff] [blame] | 52 | &LINEAR_METADATA, BO_USE_RENDER_MASK | BO_USE_SCANOUT); |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 53 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 54 | drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats), |
| 55 | &LINEAR_METADATA, BO_USE_TEXTURE_MASK); |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 56 | |
Gurchetan Singh | 8312ec2 | 2019-09-24 10:37:59 -0700 | [diff] [blame] | 57 | drv_add_combination(drv, DRM_FORMAT_R8, &LINEAR_METADATA, |
| 58 | BO_USE_SW_MASK | BO_USE_LINEAR | BO_USE_PROTECTED); |
Hirokazu Honda | fd8b8ab | 2020-06-16 15:28:56 +0900 | [diff] [blame] | 59 | |
Gurchetan Singh | 71bc665 | 2018-09-17 17:42:05 -0700 | [diff] [blame] | 60 | /* Android CTS tests require this. */ |
| 61 | drv_add_combination(drv, DRM_FORMAT_BGR888, &LINEAR_METADATA, BO_USE_SW_MASK); |
| 62 | |
Miguel Casas | dea0ccb | 2018-07-02 09:40:25 -0400 | [diff] [blame] | 63 | /* Support BO_USE_HW_VIDEO_DECODER for protected content minigbm allocations. */ |
| 64 | metadata.tiling = TILE_TYPE_LINEAR; |
| 65 | metadata.priority = 1; |
| 66 | metadata.modifier = DRM_FORMAT_MOD_LINEAR; |
| 67 | drv_modify_combination(drv, DRM_FORMAT_YVU420, &metadata, BO_USE_HW_VIDEO_DECODER); |
| 68 | drv_modify_combination(drv, DRM_FORMAT_YVU420_ANDROID, &metadata, BO_USE_HW_VIDEO_DECODER); |
Hirokazu Honda | 0f0ce6f | 2019-07-24 19:40:20 +0900 | [diff] [blame] | 69 | drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata, BO_USE_HW_VIDEO_DECODER); |
Miguel Casas | dea0ccb | 2018-07-02 09:40:25 -0400 | [diff] [blame] | 70 | |
David Stevens | 4951814 | 2020-06-15 13:48:48 +0900 | [diff] [blame] | 71 | /* |
| 72 | * R8 format is used for Android's HAL_PIXEL_FORMAT_BLOB for input/output from |
| 73 | * hardware decoder/encoder. |
| 74 | */ |
| 75 | drv_modify_combination(drv, DRM_FORMAT_R8, &metadata, |
| 76 | BO_USE_HW_VIDEO_DECODER | BO_USE_HW_VIDEO_ENCODER); |
| 77 | |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 78 | #ifdef MTK_MT8183 |
Hirokazu Honda | 3bd681c | 2020-06-23 17:52:20 +0900 | [diff] [blame] | 79 | /* NV12 format for encoding and display. */ |
| 80 | drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata, |
| 81 | BO_USE_SCANOUT | BO_USE_HW_VIDEO_ENCODER); |
| 82 | |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 83 | /* Only for MT8183 Camera subsystem */ |
| 84 | drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata, |
| 85 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
| 86 | drv_modify_combination(drv, DRM_FORMAT_NV21, &metadata, |
| 87 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
| 88 | drv_modify_combination(drv, DRM_FORMAT_YUYV, &metadata, |
| 89 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
| 90 | drv_modify_combination(drv, DRM_FORMAT_YVU420, &metadata, |
| 91 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
| 92 | drv_modify_combination(drv, DRM_FORMAT_R8, &metadata, |
Gurchetan Singh | 39490e9 | 2019-05-28 17:49:09 -0700 | [diff] [blame] | 93 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
Jasmine Chen | c7aa974 | 2019-08-14 15:28:22 +0800 | [diff] [blame] | 94 | /* Private formats for private reprocessing in camera */ |
| 95 | drv_add_combination(drv, DRM_FORMAT_MTISP_SXYZW10, &metadata, |
| 96 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_SW_MASK); |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 97 | #endif |
| 98 | |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 99 | return drv_modify_linear_combinations(drv); |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 100 | } |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 101 | |
Fritz Koenig | 1b9b5b9 | 2019-03-19 13:25:45 -0700 | [diff] [blame] | 102 | static int mediatek_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height, |
| 103 | uint32_t format, const uint64_t *modifiers, |
| 104 | uint32_t count) |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 105 | { |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 106 | int ret; |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 107 | size_t plane; |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 108 | uint32_t stride; |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 109 | struct drm_mtk_gem_create gem_create; |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 110 | |
Fritz Koenig | 1b9b5b9 | 2019-03-19 13:25:45 -0700 | [diff] [blame] | 111 | if (!drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_LINEAR)) { |
| 112 | errno = EINVAL; |
| 113 | drv_log("no usable modifier found\n"); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
Gurchetan Singh | 6ea14ba | 2017-02-08 15:09:13 -0800 | [diff] [blame] | 117 | /* |
| 118 | * Since the ARM L1 cache line size is 64 bytes, align to that as a |
| 119 | * performance optimization. |
| 120 | */ |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 121 | stride = drv_stride_from_format(format, width, 0); |
| 122 | stride = ALIGN(stride, 64); |
Hirokazu Honda | 2a2bfc2 | 2019-10-11 15:54:50 +0900 | [diff] [blame] | 123 | |
| 124 | if (bo->meta.use_flags & BO_USE_HW_VIDEO_ENCODER) { |
| 125 | uint32_t aligned_height = ALIGN(height, 32); |
| 126 | uint32_t padding[DRV_MAX_PLANES] = { 0 }; |
| 127 | |
| 128 | for (plane = 0; plane < bo->meta.num_planes; ++plane) { |
| 129 | uint32_t plane_stride = drv_stride_from_format(format, stride, plane); |
| 130 | padding[plane] = plane_stride * |
| 131 | (32 / drv_vertical_subsampling_from_format(format, plane)); |
| 132 | } |
| 133 | |
| 134 | drv_bo_from_format_and_padding(bo, stride, aligned_height, format, padding); |
| 135 | } else { |
Moja Hsu | 059ac08 | 2019-10-02 14:47:10 +0800 | [diff] [blame] | 136 | #ifdef MTK_MT8183 |
| 137 | /* |
| 138 | * JPEG Encoder Accelerator requires 16x16 alignment. We want the buffer |
| 139 | * from camera can be put in JEA directly so align the height to 16 |
| 140 | * bytes. |
| 141 | */ |
| 142 | if (format == DRM_FORMAT_NV12) |
| 143 | height = ALIGN(height, 16); |
| 144 | #endif |
Hirokazu Honda | 2a2bfc2 | 2019-10-11 15:54:50 +0900 | [diff] [blame] | 145 | drv_bo_from_format(bo, stride, height, format); |
| 146 | } |
Yuly Novikov | 96c7a3b | 2015-12-08 22:48:29 -0500 | [diff] [blame] | 147 | |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 148 | memset(&gem_create, 0, sizeof(gem_create)); |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 149 | gem_create.size = bo->meta.total_size; |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 150 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 151 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_CREATE, &gem_create); |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 152 | if (ret) { |
Nicolas Boichat | d7c8338 | 2019-08-29 21:46:29 +0800 | [diff] [blame] | 153 | drv_log("DRM_IOCTL_MTK_GEM_CREATE failed (size=%" PRIu64 ")\n", gem_create.size); |
Stéphane Marchesin | 6ac299f | 2019-03-21 12:23:29 -0700 | [diff] [blame] | 154 | return -errno; |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 155 | } |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 156 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 157 | for (plane = 0; plane < bo->meta.num_planes; plane++) |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 158 | bo->handles[plane].u32 = gem_create.handle; |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
Fritz Koenig | 1b9b5b9 | 2019-03-19 13:25:45 -0700 | [diff] [blame] | 163 | static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, |
| 164 | uint64_t use_flags) |
| 165 | { |
| 166 | uint64_t modifiers[] = { DRM_FORMAT_MOD_LINEAR }; |
| 167 | return mediatek_bo_create_with_modifiers(bo, width, height, format, modifiers, |
| 168 | ARRAY_SIZE(modifiers)); |
| 169 | } |
| 170 | |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 171 | static void *mediatek_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags) |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 172 | { |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 173 | int ret, prime_fd; |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 174 | struct drm_mtk_gem_map_off gem_map; |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 175 | struct mediatek_private_map_data *priv; |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 176 | |
| 177 | memset(&gem_map, 0, sizeof(gem_map)); |
| 178 | gem_map.handle = bo->handles[0].u32; |
| 179 | |
| 180 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MTK_GEM_MAP_OFFSET, &gem_map); |
| 181 | if (ret) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 182 | drv_log("DRM_IOCTL_MTK_GEM_MAP_OFFSET failed\n"); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 183 | return MAP_FAILED; |
| 184 | } |
| 185 | |
David Stevens | ddb56b5 | 2020-03-13 15:24:37 +0900 | [diff] [blame] | 186 | prime_fd = drv_bo_get_plane_fd(bo, 0); |
| 187 | if (prime_fd < 0) { |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 188 | drv_log("Failed to get a prime fd\n"); |
| 189 | return MAP_FAILED; |
| 190 | } |
| 191 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 192 | void *addr = mmap(0, bo->meta.total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd, |
Gurchetan Singh | cfb8876 | 2017-09-28 17:14:50 -0700 | [diff] [blame] | 193 | gem_map.offset); |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 194 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 195 | vma->length = bo->meta.total_size; |
Gurchetan Singh | 1a31e60 | 2016-10-06 10:58:00 -0700 | [diff] [blame] | 196 | |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 197 | priv = calloc(1, sizeof(*priv)); |
| 198 | priv->prime_fd = prime_fd; |
| 199 | vma->priv = priv; |
| 200 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 201 | if (bo->meta.use_flags & BO_USE_RENDERSCRIPT) { |
| 202 | priv->cached_addr = calloc(1, bo->meta.total_size); |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 203 | priv->gem_addr = addr; |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 204 | addr = priv->cached_addr; |
| 205 | } |
| 206 | |
| 207 | return addr; |
| 208 | } |
| 209 | |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 210 | static int mediatek_bo_unmap(struct bo *bo, struct vma *vma) |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 211 | { |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 212 | if (vma->priv) { |
| 213 | struct mediatek_private_map_data *priv = vma->priv; |
Luigi Santivetti | a72f442 | 2018-09-12 16:28:21 +0100 | [diff] [blame] | 214 | |
| 215 | if (priv->cached_addr) { |
| 216 | vma->addr = priv->gem_addr; |
| 217 | free(priv->cached_addr); |
| 218 | } |
| 219 | |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 220 | close(priv->prime_fd); |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 221 | free(priv); |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 222 | vma->priv = NULL; |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 225 | return munmap(vma->addr, vma->length); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Gurchetan Singh | ef262d8 | 2017-11-28 16:56:17 -0800 | [diff] [blame] | 228 | static int mediatek_bo_invalidate(struct bo *bo, struct mapping *mapping) |
| 229 | { |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 230 | struct mediatek_private_map_data *priv = mapping->vma->priv; |
| 231 | |
| 232 | if (priv) { |
| 233 | struct pollfd fds = { |
| 234 | .fd = priv->prime_fd, |
| 235 | }; |
| 236 | |
| 237 | if (mapping->vma->map_flags & BO_MAP_WRITE) |
| 238 | fds.events |= POLLOUT; |
| 239 | |
| 240 | if (mapping->vma->map_flags & BO_MAP_READ) |
| 241 | fds.events |= POLLIN; |
| 242 | |
| 243 | poll(&fds, 1, -1); |
| 244 | if (fds.revents != fds.events) |
| 245 | drv_log("poll prime_fd failed\n"); |
| 246 | |
| 247 | if (priv->cached_addr) |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 248 | memcpy(priv->cached_addr, priv->gem_addr, bo->meta.total_size); |
Gurchetan Singh | ef262d8 | 2017-11-28 16:56:17 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 254 | static int mediatek_bo_flush(struct bo *bo, struct mapping *mapping) |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 255 | { |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 256 | struct mediatek_private_map_data *priv = mapping->vma->priv; |
Luigi Santivetti | 500928f | 2018-08-28 10:09:20 +0100 | [diff] [blame] | 257 | if (priv && priv->cached_addr && (mapping->vma->map_flags & BO_MAP_WRITE)) |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 258 | memcpy(priv->gem_addr, priv->cached_addr, bo->meta.total_size); |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
Gurchetan Singh | 0d44d48 | 2019-06-04 19:39:51 -0700 | [diff] [blame] | 263 | static uint32_t mediatek_resolve_format(struct driver *drv, uint32_t format, uint64_t use_flags) |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 264 | { |
| 265 | switch (format) { |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 266 | case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 267 | #ifdef MTK_MT8183 |
Jasmine Chen | c7aa974 | 2019-08-14 15:28:22 +0800 | [diff] [blame] | 268 | /* Only MT8183 Camera subsystem offers private reprocessing |
| 269 | * capability. CAMERA_READ indicates the buffer is intended for |
| 270 | * reprocessing and hence given the private format for MTK. */ |
| 271 | if (use_flags & BO_USE_CAMERA_READ) |
| 272 | return DRM_FORMAT_MTISP_SXYZW10; |
| 273 | /* For non-reprocessing uses, only MT8183 Camera subsystem |
| 274 | * requires NV12. */ |
| 275 | else if (use_flags & BO_USE_CAMERA_WRITE) |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 276 | return DRM_FORMAT_NV12; |
| 277 | #endif |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 278 | /*HACK: See b/28671744 */ |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 279 | return DRM_FORMAT_XBGR8888; |
| 280 | case DRM_FORMAT_FLEX_YCbCr_420_888: |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 281 | #ifdef MTK_MT8183 |
Alexandre Courbot | 6ad6382 | 2019-10-01 16:07:31 +0900 | [diff] [blame] | 282 | /* MT8183 camera and decoder subsystems require NV12. */ |
Hirokazu Honda | 2a2bfc2 | 2019-10-11 15:54:50 +0900 | [diff] [blame] | 283 | if (use_flags & (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | |
| 284 | BO_USE_HW_VIDEO_DECODER | BO_USE_HW_VIDEO_ENCODER)) { |
Gurchetan Singh | 39490e9 | 2019-05-28 17:49:09 -0700 | [diff] [blame] | 285 | return DRM_FORMAT_NV12; |
Hirokazu Honda | 2a2bfc2 | 2019-10-11 15:54:50 +0900 | [diff] [blame] | 286 | } |
Nick Fan | 01c4014 | 2018-10-08 11:53:26 +0800 | [diff] [blame] | 287 | #endif |
Hirokazu Honda | 3d85602 | 2019-08-23 14:31:31 +0900 | [diff] [blame] | 288 | return DRM_FORMAT_YVU420; |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 289 | default: |
| 290 | return format; |
| 291 | } |
| 292 | } |
| 293 | |
Gurchetan Singh | 3e9d383 | 2017-10-31 10:36:25 -0700 | [diff] [blame] | 294 | const struct backend backend_mediatek = { |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 295 | .name = "mediatek", |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 296 | .init = mediatek_init, |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 297 | .bo_create = mediatek_bo_create, |
Fritz Koenig | 1b9b5b9 | 2019-03-19 13:25:45 -0700 | [diff] [blame] | 298 | .bo_create_with_modifiers = mediatek_bo_create_with_modifiers, |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 299 | .bo_destroy = drv_gem_bo_destroy, |
Gurchetan Singh | 71611d6 | 2017-01-03 16:49:56 -0800 | [diff] [blame] | 300 | .bo_import = drv_prime_bo_import, |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 301 | .bo_map = mediatek_bo_map, |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 302 | .bo_unmap = mediatek_bo_unmap, |
Gurchetan Singh | ef262d8 | 2017-11-28 16:56:17 -0800 | [diff] [blame] | 303 | .bo_invalidate = mediatek_bo_invalidate, |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 304 | .bo_flush = mediatek_bo_flush, |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 305 | .resolve_format = mediatek_resolve_format, |
JB Tsai | 0c16a0f | 2015-03-19 14:30:31 +0800 | [diff] [blame] | 306 | }; |
| 307 | |
| 308 | #endif |