Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 1 | /* |
Daniele Castagna | 7a755de | 2016-12-16 17:32:30 -0500 | [diff] [blame] | 2 | * Copyright 2014 The Chromium OS Authors. All rights reserved. |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 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_ROCKCHIP |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 8 | |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 9 | #include <errno.h> |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 10 | #include <rockchip_drm.h> |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 11 | #include <stdbool.h> |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 12 | #include <stdio.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 13 | #include <string.h> |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 14 | #include <sys/mman.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 15 | #include <xf86drm.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 16 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 17 | #include "drv_priv.h" |
Dominik Behr | e13ac28 | 2015-01-13 00:59:21 -0800 | [diff] [blame] | 18 | #include "helpers.h" |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 19 | #include "util.h" |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 20 | |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 21 | struct rockchip_private_map_data { |
| 22 | void *cached_addr; |
| 23 | void *gem_addr; |
| 24 | }; |
| 25 | |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 26 | static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, |
| 27 | DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, |
| 28 | DRM_FORMAT_XRGB8888 }; |
| 29 | |
| 30 | static const uint32_t texture_source_formats[] = { DRM_FORMAT_R8, DRM_FORMAT_NV12, |
| 31 | DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID }; |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 32 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 33 | static int afbc_bo_from_format(struct bo *bo, uint32_t width, uint32_t height, uint32_t format) |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 34 | { |
| 35 | /* We've restricted ourselves to four bytes per pixel. */ |
| 36 | const uint32_t pixel_size = 4; |
| 37 | |
| 38 | const uint32_t clump_width = 4; |
| 39 | const uint32_t clump_height = 4; |
| 40 | |
| 41 | #define AFBC_NARROW 1 |
| 42 | #if AFBC_NARROW == 1 |
| 43 | const uint32_t block_width = 4 * clump_width; |
| 44 | const uint32_t block_height = 4 * clump_height; |
| 45 | #else |
| 46 | const uint32_t block_width = 8 * clump_width; |
| 47 | const uint32_t block_height = 2 * clump_height; |
| 48 | #endif |
| 49 | |
| 50 | const uint32_t header_block_size = 16; |
| 51 | const uint32_t body_block_size = block_width * block_height * pixel_size; |
| 52 | const uint32_t width_in_blocks = DIV_ROUND_UP(width, block_width); |
| 53 | const uint32_t height_in_blocks = DIV_ROUND_UP(height, block_height); |
| 54 | const uint32_t total_blocks = width_in_blocks * height_in_blocks; |
| 55 | |
| 56 | const uint32_t header_plane_size = total_blocks * header_block_size; |
| 57 | const uint32_t body_plane_size = total_blocks * body_block_size; |
| 58 | |
| 59 | /* GPU requires 64 bytes, but EGL import code expects 1024 byte |
| 60 | * alignement for the body plane. */ |
| 61 | const uint32_t body_plane_alignment = 1024; |
| 62 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 63 | const uint32_t body_plane_offset = ALIGN(header_plane_size, body_plane_alignment); |
| 64 | const uint32_t total_size = body_plane_offset + body_plane_size; |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 65 | |
| 66 | bo->strides[0] = width_in_blocks * block_width * pixel_size; |
| 67 | bo->sizes[0] = total_size; |
| 68 | bo->offsets[0] = 0; |
| 69 | |
| 70 | bo->total_size = total_size; |
| 71 | |
| 72 | bo->format_modifiers[0] = DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 77 | static int rockchip_add_kms_item(struct driver *drv, const struct kms_item *item) |
| 78 | { |
| 79 | int ret; |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 80 | uint32_t i, j; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 81 | uint64_t flags; |
| 82 | struct combination *combo; |
| 83 | struct format_metadata metadata; |
| 84 | |
Ege Mihmanli | 96b7d46 | 2017-09-19 20:13:26 -0700 | [diff] [blame] | 85 | for (i = 0; i < drv->combos.size; i++) { |
| 86 | combo = &drv->combos.data[i]; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 87 | if (combo->format == item->format) { |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 88 | if (item->modifier == DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) { |
| 89 | flags = BO_USE_RENDERING | BO_USE_SCANOUT | BO_USE_TEXTURE; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 90 | metadata.modifier = item->modifier; |
| 91 | metadata.tiling = 0; |
| 92 | metadata.priority = 2; |
| 93 | |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 94 | for (j = 0; j < ARRAY_SIZE(texture_source_formats); j++) { |
| 95 | if (item->format == texture_source_formats[j]) |
| 96 | flags &= ~BO_USE_RENDERING; |
| 97 | } |
| 98 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 99 | ret = drv_add_combination(drv, item[i].format, &metadata, flags); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 100 | if (ret) |
| 101 | return ret; |
| 102 | } else { |
| 103 | combo->usage |= item->usage; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 111 | static int rockchip_init(struct driver *drv) |
| 112 | { |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 113 | int ret; |
| 114 | uint32_t i, num_items; |
| 115 | struct kms_item *items; |
| 116 | struct format_metadata metadata; |
| 117 | |
| 118 | metadata.tiling = 0; |
| 119 | metadata.priority = 1; |
| 120 | metadata.modifier = DRM_FORMAT_MOD_NONE; |
| 121 | |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 122 | ret = drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), |
| 123 | &metadata, BO_USE_RENDER_MASK); |
| 124 | if (ret) |
| 125 | return ret; |
| 126 | |
| 127 | ret = drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats), |
| 128 | &metadata, BO_USE_TEXTURE_MASK); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 129 | if (ret) |
| 130 | return ret; |
| 131 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 132 | drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT); |
| 133 | drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 134 | |
Jeffy Chen | 55525f5 | 2017-09-19 17:15:30 +0800 | [diff] [blame] | 135 | /* Camera ISP supports only NV12 output. */ |
| 136 | drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata, |
| 137 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
| 138 | /* |
| 139 | * R8 format is used for Android's HAL_PIXEL_FORMAT_BLOB and is used for JPEG snapshots |
| 140 | * from camera. |
| 141 | */ |
| 142 | drv_modify_combination(drv, DRM_FORMAT_R8, &metadata, |
| 143 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
| 144 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 145 | items = drv_query_kms(drv, &num_items); |
| 146 | if (!items || !num_items) |
| 147 | return 0; |
| 148 | |
| 149 | for (i = 0; i < num_items; i++) { |
| 150 | ret = rockchip_add_kms_item(drv, &items[i]); |
| 151 | if (ret) { |
| 152 | free(items); |
| 153 | return ret; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | free(items); |
| 158 | return 0; |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 161 | static bool has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier) |
| 162 | { |
| 163 | uint32_t i; |
| 164 | |
| 165 | for (i = 0; i < count; i++) |
| 166 | if (list[i] == modifier) |
| 167 | return true; |
| 168 | |
| 169 | return false; |
| 170 | } |
| 171 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 172 | static int rockchip_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height, |
| 173 | uint32_t format, const uint64_t *modifiers, |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 174 | uint32_t count) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 175 | { |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 176 | int ret; |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 177 | size_t plane; |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 178 | struct drm_rockchip_gem_create gem_create; |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 179 | |
Pin-chih Lin | 1964341 | 2017-07-25 08:06:26 +0000 | [diff] [blame] | 180 | if (format == DRM_FORMAT_NV12) { |
| 181 | uint32_t w_mbs = DIV_ROUND_UP(ALIGN(width, 16), 16); |
| 182 | uint32_t h_mbs = DIV_ROUND_UP(ALIGN(height, 16), 16); |
| 183 | |
| 184 | uint32_t aligned_width = w_mbs * 16; |
| 185 | uint32_t aligned_height = DIV_ROUND_UP(h_mbs * 16 * 3, 2); |
| 186 | |
| 187 | drv_bo_from_format(bo, aligned_width, height, format); |
| 188 | bo->total_size = bo->strides[0] * aligned_height + w_mbs * h_mbs * 128; |
| 189 | } else if (width <= 2560 && |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 190 | has_modifier(modifiers, count, DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) { |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 191 | /* If the caller has decided they can use AFBC, always |
| 192 | * pick that */ |
| 193 | afbc_bo_from_format(bo, width, height, format); |
Gurchetan Singh | 10a1180 | 2016-09-23 15:27:07 -0700 | [diff] [blame] | 194 | } else { |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 195 | if (!has_modifier(modifiers, count, DRM_FORMAT_MOD_NONE)) { |
| 196 | errno = EINVAL; |
| 197 | fprintf(stderr, "no usable modifier found\n"); |
| 198 | return -1; |
| 199 | } |
Gurchetan Singh | 6ea14ba | 2017-02-08 15:09:13 -0800 | [diff] [blame] | 200 | |
Pin-chih Lin | 1964341 | 2017-07-25 08:06:26 +0000 | [diff] [blame] | 201 | uint32_t stride; |
Gurchetan Singh | 6ea14ba | 2017-02-08 15:09:13 -0800 | [diff] [blame] | 202 | /* |
Pin-chih Lin | 1964341 | 2017-07-25 08:06:26 +0000 | [diff] [blame] | 203 | * Since the ARM L1 cache line size is 64 bytes, align to that |
| 204 | * as a performance optimization. For YV12, the Mali cmem allocator |
| 205 | * requires that chroma planes are aligned to 64-bytes, so align the |
| 206 | * luma plane to 128 bytes. |
Gurchetan Singh | 6ea14ba | 2017-02-08 15:09:13 -0800 | [diff] [blame] | 207 | */ |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 208 | stride = drv_stride_from_format(format, width, 0); |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 209 | if (format == DRM_FORMAT_YVU420 || format == DRM_FORMAT_YVU420_ANDROID) |
Gurchetan Singh | 4c3aa42 | 2017-03-23 18:47:06 -0700 | [diff] [blame] | 210 | stride = ALIGN(stride, 128); |
| 211 | else |
| 212 | stride = ALIGN(stride, 64); |
| 213 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 214 | drv_bo_from_format(bo, stride, height, format); |
Gurchetan Singh | 10a1180 | 2016-09-23 15:27:07 -0700 | [diff] [blame] | 215 | } |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 216 | |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 217 | memset(&gem_create, 0, sizeof(gem_create)); |
Gurchetan Singh | a40ca9e | 2016-08-29 19:51:45 -0700 | [diff] [blame] | 218 | gem_create.size = bo->total_size; |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 219 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 220 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_CREATE, &gem_create); |
Gurchetan Singh | f64487b | 2016-07-14 19:54:44 -0700 | [diff] [blame] | 221 | |
| 222 | if (ret) { |
Gurchetan Singh | cb1471b | 2017-05-15 14:33:16 -0700 | [diff] [blame] | 223 | fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_CREATE failed (size=%llu)\n", |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 224 | gem_create.size); |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 225 | return ret; |
Zach Reizner | 58080df | 2016-04-27 11:14:41 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Gurchetan Singh | 42cc6d6 | 2016-08-29 18:19:19 -0700 | [diff] [blame] | 228 | for (plane = 0; plane < bo->num_planes; plane++) |
| 229 | bo->handles[plane].u32 = gem_create.handle; |
| 230 | |
| 231 | return 0; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 234 | static int rockchip_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, |
| 235 | uint32_t flags) |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 236 | { |
| 237 | uint64_t modifiers[] = { DRM_FORMAT_MOD_NONE }; |
| 238 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 239 | return rockchip_bo_create_with_modifiers(bo, width, height, format, modifiers, |
| 240 | ARRAY_SIZE(modifiers)); |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Joe Kniss | 6570585 | 2017-06-29 15:02:46 -0700 | [diff] [blame] | 243 | static void *rockchip_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot) |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 244 | { |
| 245 | int ret; |
| 246 | struct drm_rockchip_gem_map_off gem_map; |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 247 | struct rockchip_private_map_data *priv; |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 248 | |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 249 | /* We can only map buffers created with SW access flags, which should |
| 250 | * have no modifiers (ie, not AFBC). */ |
| 251 | if (bo->format_modifiers[0] == DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC) |
| 252 | return MAP_FAILED; |
| 253 | |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 254 | memset(&gem_map, 0, sizeof(gem_map)); |
| 255 | gem_map.handle = bo->handles[0].u32; |
| 256 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 257 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET, &gem_map); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 258 | if (ret) { |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 259 | fprintf(stderr, "drv: DRM_IOCTL_ROCKCHIP_GEM_MAP_OFFSET failed\n"); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 260 | return MAP_FAILED; |
| 261 | } |
| 262 | |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 263 | void *addr = mmap(0, bo->total_size, prot, MAP_SHARED, bo->drv->fd, gem_map.offset); |
| 264 | |
Gurchetan Singh | 1a31e60 | 2016-10-06 10:58:00 -0700 | [diff] [blame] | 265 | data->length = bo->total_size; |
| 266 | |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 267 | if (bo->flags & BO_USE_RENDERSCRIPT) { |
| 268 | priv = calloc(1, sizeof(*priv)); |
| 269 | priv->cached_addr = calloc(1, bo->total_size); |
| 270 | priv->gem_addr = addr; |
| 271 | memcpy(priv->cached_addr, priv->gem_addr, bo->total_size); |
| 272 | data->priv = priv; |
| 273 | addr = priv->cached_addr; |
| 274 | } |
| 275 | |
| 276 | return addr; |
| 277 | } |
| 278 | |
| 279 | static int rockchip_bo_unmap(struct bo *bo, struct map_info *data) |
| 280 | { |
| 281 | if (data->priv) { |
| 282 | struct rockchip_private_map_data *priv = data->priv; |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 283 | data->addr = priv->gem_addr; |
| 284 | free(priv->cached_addr); |
| 285 | free(priv); |
| 286 | data->priv = NULL; |
| 287 | } |
| 288 | |
| 289 | return munmap(data->addr, data->length); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 292 | static int rockchip_bo_flush(struct bo *bo, struct map_info *data) |
| 293 | { |
| 294 | struct rockchip_private_map_data *priv = data->priv; |
| 295 | |
| 296 | if (priv) |
| 297 | memcpy(priv->gem_addr, priv->cached_addr, bo->total_size); |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
Tomasz Figa | ce1ae02 | 2017-07-05 18:15:06 +0900 | [diff] [blame] | 302 | static uint32_t rockchip_resolve_format(uint32_t format, uint64_t usage) |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 303 | { |
| 304 | switch (format) { |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 305 | case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: |
Jeffy Chen | 55525f5 | 2017-09-19 17:15:30 +0800 | [diff] [blame] | 306 | /* Camera subsystem requires NV12. */ |
| 307 | if (usage & (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE)) |
| 308 | return DRM_FORMAT_NV12; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 309 | /*HACK: See b/28671744 */ |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 310 | return DRM_FORMAT_XBGR8888; |
| 311 | case DRM_FORMAT_FLEX_YCbCr_420_888: |
| 312 | return DRM_FORMAT_NV12; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 313 | default: |
| 314 | return format; |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 318 | struct backend backend_rockchip = { |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 319 | .name = "rockchip", |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 320 | .init = rockchip_init, |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 321 | .bo_create = rockchip_bo_create, |
Kristian H. Kristensen | b1efbd8 | 2016-09-06 11:43:26 -0700 | [diff] [blame] | 322 | .bo_create_with_modifiers = rockchip_bo_create_with_modifiers, |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 323 | .bo_destroy = drv_gem_bo_destroy, |
Gurchetan Singh | 71611d6 | 2017-01-03 16:49:56 -0800 | [diff] [blame] | 324 | .bo_import = drv_prime_bo_import, |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 325 | .bo_map = rockchip_bo_map, |
Gurchetan Singh | 469a3aa | 2017-08-03 18:17:34 -0700 | [diff] [blame] | 326 | .bo_unmap = rockchip_bo_unmap, |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 327 | .bo_flush = rockchip_bo_flush, |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 328 | .resolve_format = rockchip_resolve_format, |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | #endif |