blob: 67aecff50af9fdcfc2af503ab4a5ec576dfdfbcf [file] [log] [blame]
Rajesh Yadav7f79cb52018-01-22 18:29:06 +05301/*
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 Shah067594b2018-11-26 10:05:18 -08009#include <assert.h>
Rob Clarke48e4d72020-08-07 08:08:30 -070010#include <dlfcn.h>
Tanmay Shah067594b2018-11-26 10:05:18 -080011#include <drm_fourcc.h>
Tanmay Shah617ee712018-07-11 16:41:05 -070012#include <errno.h>
Stephen Boyd5ff0cfd2019-04-09 11:03:00 -070013#include <inttypes.h>
Tanmay Shah617ee712018-07-11 16:41:05 -070014#include <msm_drm.h>
Tanmay Shah067594b2018-11-26 10:05:18 -080015#include <stdbool.h>
Tanmay Shah617ee712018-07-11 16:41:05 -070016#include <stdio.h>
17#include <string.h>
18#include <sys/mman.h>
19#include <xf86drm.h>
20
Yiwei Zhangb7a64442021-09-30 05:13:10 +000021#include "drv_helpers.h"
Rajesh Yadav7f79cb52018-01-22 18:29:06 +053022#include "drv_priv.h"
Rajesh Yadav7f79cb52018-01-22 18:29:06 +053023#include "util.h"
24
Tanmay Shah067594b2018-11-26 10:05:18 -080025/* Alignment values are based on SDM845 Gfx IP */
Tanmay Shah617ee712018-07-11 16:41:05 -070026#define DEFAULT_ALIGNMENT 64
Tanmay Shahc65bd8c2018-11-21 09:14:14 -080027#define BUFFER_SIZE_ALIGN 4096
28
29#define VENUS_STRIDE_ALIGN 128
30#define VENUS_SCANLINE_ALIGN 16
31#define NV12_LINEAR_PADDING (12 * 1024)
Tanmay Shah067594b2018-11-26 10:05:18 -080032#define NV12_UBWC_PADDING(y_stride) (MAX(16 * 1024, y_stride * 48))
33#define MACROTILE_WIDTH_ALIGN 64
34#define MACROTILE_HEIGHT_ALIGN 16
35#define PLANE_SIZE_ALIGN 4096
36
37#define MSM_UBWC_TILING 1
Stéphane Marchesin23e006a2018-02-28 16:37:46 -080038
Yiwei Zhang7648f062022-07-13 23:15:22 +000039static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
40 DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888,
41 DRM_FORMAT_XRGB8888, DRM_FORMAT_ABGR2101010,
Rob Clark06cf1f12022-01-24 16:10:59 -080042 DRM_FORMAT_ABGR16161616F };
Rajesh Yadav7f79cb52018-01-22 18:29:06 +053043
Tanmay Shah617ee712018-07-11 16:41:05 -070044static const uint32_t texture_source_formats[] = { DRM_FORMAT_NV12, DRM_FORMAT_R8,
Fritz Koenig2471aa22021-08-17 10:32:12 -070045 DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID,
46 DRM_FORMAT_P010 };
Alexandre Courbot1805a9b2018-05-21 19:05:10 +090047
Tanmay Shah067594b2018-11-26 10:05:18 -080048/*
49 * Each macrotile consists of m x n (mostly 4 x 4) tiles.
50 * Pixel data pitch/stride is aligned with macrotile width.
51 * Pixel data height is aligned with macrotile height.
52 * Entire pixel data buffer is aligned with 4k(bytes).
53 */
54static uint32_t get_ubwc_meta_size(uint32_t width, uint32_t height, uint32_t tile_width,
55 uint32_t tile_height)
56{
57 uint32_t macrotile_width, macrotile_height;
58
59 macrotile_width = DIV_ROUND_UP(width, tile_width);
60 macrotile_height = DIV_ROUND_UP(height, tile_height);
61
62 // Align meta buffer width to 64 blocks
63 macrotile_width = ALIGN(macrotile_width, MACROTILE_WIDTH_ALIGN);
64
65 // Align meta buffer height to 16 blocks
66 macrotile_height = ALIGN(macrotile_height, MACROTILE_HEIGHT_ALIGN);
67
68 return ALIGN(macrotile_width * macrotile_height, PLANE_SIZE_ALIGN);
69}
70
Rob Clark72787582020-12-01 12:13:13 -080071static unsigned get_pitch_alignment(struct bo *bo)
72{
73 switch (bo->meta.format) {
74 case DRM_FORMAT_NV12:
75 return VENUS_STRIDE_ALIGN;
76 case DRM_FORMAT_YVU420:
77 case DRM_FORMAT_YVU420_ANDROID:
78 /* TODO other YUV formats? */
79 /* Something (in the video stack?) assumes the U/V planes can use
80 * half the pitch as the Y plane.. to componsate, double the
81 * alignment:
82 */
83 return 2 * DEFAULT_ALIGNMENT;
84 default:
85 return DEFAULT_ALIGNMENT;
86 }
87}
88
Tanmay Shah067594b2018-11-26 10:05:18 -080089static void msm_calculate_layout(struct bo *bo)
Tanmay Shahc65bd8c2018-11-21 09:14:14 -080090{
91 uint32_t width, height;
92
Gurchetan Singh298b7572019-09-19 09:55:18 -070093 width = bo->meta.width;
94 height = bo->meta.height;
Tanmay Shahc65bd8c2018-11-21 09:14:14 -080095
96 /* NV12 format requires extra padding with platform
97 * specific alignments for venus driver
98 */
Fritz Koenig2471aa22021-08-17 10:32:12 -070099 if (bo->meta.format == DRM_FORMAT_NV12 || bo->meta.format == DRM_FORMAT_P010) {
Tanmay Shah067594b2018-11-26 10:05:18 -0800100 uint32_t y_stride, uv_stride, y_scanline, uv_scanline, y_plane, uv_plane, size,
101 extra_padding;
102
Fritz Koenig2471aa22021-08-17 10:32:12 -0700103 // P010 has the same layout as NV12. The difference is that each
104 // pixel in P010 takes 2 bytes, while in NV12 each pixel takes 1 byte.
105 if (bo->meta.format == DRM_FORMAT_P010)
106 width *= 2;
107
Tanmay Shahc65bd8c2018-11-21 09:14:14 -0800108 y_stride = ALIGN(width, VENUS_STRIDE_ALIGN);
109 uv_stride = ALIGN(width, VENUS_STRIDE_ALIGN);
110 y_scanline = ALIGN(height, VENUS_SCANLINE_ALIGN * 2);
Fritz Koenigb03e9c82020-09-09 15:22:46 -0700111 uv_scanline = ALIGN(DIV_ROUND_UP(height, 2),
Gurchetan Singh99644382020-10-07 15:28:11 -0700112 VENUS_SCANLINE_ALIGN * (bo->meta.tiling ? 2 : 1));
Tanmay Shahc65bd8c2018-11-21 09:14:14 -0800113 y_plane = y_stride * y_scanline;
114 uv_plane = uv_stride * uv_scanline;
115
Gurchetan Singh298b7572019-09-19 09:55:18 -0700116 if (bo->meta.tiling == MSM_UBWC_TILING) {
Fritz Koenigb03e9c82020-09-09 15:22:46 -0700117 y_plane = ALIGN(y_plane, PLANE_SIZE_ALIGN);
118 uv_plane = ALIGN(uv_plane, PLANE_SIZE_ALIGN);
Tanmay Shah067594b2018-11-26 10:05:18 -0800119 y_plane += get_ubwc_meta_size(width, height, 32, 8);
120 uv_plane += get_ubwc_meta_size(width >> 1, height >> 1, 16, 8);
121 extra_padding = NV12_UBWC_PADDING(y_stride);
122 } else {
123 extra_padding = NV12_LINEAR_PADDING;
124 }
125
Gurchetan Singh298b7572019-09-19 09:55:18 -0700126 bo->meta.strides[0] = y_stride;
127 bo->meta.sizes[0] = y_plane;
128 bo->meta.offsets[1] = y_plane;
129 bo->meta.strides[1] = uv_stride;
Tanmay Shah067594b2018-11-26 10:05:18 -0800130 size = y_plane + uv_plane + extra_padding;
Gurchetan Singh298b7572019-09-19 09:55:18 -0700131 bo->meta.total_size = ALIGN(size, BUFFER_SIZE_ALIGN);
132 bo->meta.sizes[1] = bo->meta.total_size - bo->meta.sizes[0];
Tanmay Shahc65bd8c2018-11-21 09:14:14 -0800133 } else {
134 uint32_t stride, alignw, alignh;
135
Rob Clark72787582020-12-01 12:13:13 -0800136 alignw = ALIGN(width, get_pitch_alignment(bo));
Jeffrey Kardatzkea6a9efc2020-02-21 15:35:01 -0800137 /* HAL_PIXEL_FORMAT_YV12 requires that the buffer's height not be aligned.
138 DRM_FORMAT_R8 of height one is used for JPEG camera output, so don't
139 height align that. */
140 if (bo->meta.format == DRM_FORMAT_YVU420_ANDROID ||
Rob Clark29daef02022-07-19 11:17:52 -0700141 bo->meta.format == DRM_FORMAT_YVU420 ||
Gurchetan Singh8d884742020-03-24 13:48:54 -0700142 (bo->meta.format == DRM_FORMAT_R8 && height == 1)) {
Rob Clark29daef02022-07-19 11:17:52 -0700143 assert(bo->meta.tiling != MSM_UBWC_TILING);
Tanmay Shahc65bd8c2018-11-21 09:14:14 -0800144 alignh = height;
145 } else {
146 alignh = ALIGN(height, DEFAULT_ALIGNMENT);
147 }
148
Gurchetan Singh298b7572019-09-19 09:55:18 -0700149 stride = drv_stride_from_format(bo->meta.format, alignw, 0);
Tanmay Shahc65bd8c2018-11-21 09:14:14 -0800150
151 /* Calculate size and assign stride, size, offset to each plane based on format */
Gurchetan Singh298b7572019-09-19 09:55:18 -0700152 drv_bo_from_format(bo, stride, alignh, bo->meta.format);
Tanmay Shah067594b2018-11-26 10:05:18 -0800153
154 /* For all RGB UBWC formats */
Gurchetan Singh298b7572019-09-19 09:55:18 -0700155 if (bo->meta.tiling == MSM_UBWC_TILING) {
156 bo->meta.sizes[0] += get_ubwc_meta_size(width, height, 16, 4);
157 bo->meta.total_size = bo->meta.sizes[0];
158 assert(IS_ALIGNED(bo->meta.total_size, BUFFER_SIZE_ALIGN));
Tanmay Shah067594b2018-11-26 10:05:18 -0800159 }
160 }
161}
162
163static bool is_ubwc_fmt(uint32_t format)
164{
165 switch (format) {
166 case DRM_FORMAT_XBGR8888:
167 case DRM_FORMAT_ABGR8888:
Fritz Koenige5c3fdf2019-12-10 16:30:34 -0800168 case DRM_FORMAT_XRGB8888:
169 case DRM_FORMAT_ARGB8888:
John Stultz0a4229e2021-11-06 03:12:43 +0000170#ifndef QCOM_DISABLE_COMPRESSED_NV12
Tanmay Shah067594b2018-11-26 10:05:18 -0800171 case DRM_FORMAT_NV12:
John Stultz0a4229e2021-11-06 03:12:43 +0000172#endif
Tanmay Shah067594b2018-11-26 10:05:18 -0800173 return 1;
174 default:
175 return 0;
176 }
177}
178
179static void msm_add_ubwc_combinations(struct driver *drv, const uint32_t *formats,
180 uint32_t num_formats, struct format_metadata *metadata,
181 uint64_t use_flags)
182{
183 for (uint32_t i = 0; i < num_formats; i++) {
184 if (is_ubwc_fmt(formats[i])) {
185 struct combination combo = { .format = formats[i],
186 .metadata = *metadata,
187 .use_flags = use_flags };
188 drv_array_append(drv->combos, &combo);
189 }
Tanmay Shahc65bd8c2018-11-21 09:14:14 -0800190 }
191}
192
Rob Clarke48e4d72020-08-07 08:08:30 -0700193/**
194 * Check for buggy apps that are known to not support modifiers, to avoid surprising them
195 * with a UBWC buffer.
196 */
197static bool should_avoid_ubwc(void)
198{
199#ifndef __ANDROID__
200 /* waffle is buggy and, requests a renderable buffer (which on qcom platforms, we
201 * want to use UBWC), and then passes it to the kernel discarding the modifier.
202 * So mesa ends up correctly rendering to as tiled+compressed, but kernel tries
203 * to display as linear. Other platforms do not see this issue, simply because
204 * they only use compressed (ex, AFBC) with the BO_USE_SCANOUT flag.
205 *
206 * See b/163137550
207 */
208 if (dlsym(RTLD_DEFAULT, "waffle_display_connect")) {
Yiwei Zhang04954732022-07-13 23:34:33 +0000209 drv_logi("WARNING: waffle detected, disabling UBWC\n");
Rob Clarke48e4d72020-08-07 08:08:30 -0700210 return true;
211 }
Yiwei Zhang7a1a7db2022-04-14 06:28:14 +0000212
213 /* Sommelier relies on implicit modifier, which does not pass host modifier to
214 * zwp_linux_buffer_params_v1_add. Graphics will be broken if UBWC is enabled.
215 * Sommelier shall be fixed to mirror what arc wayland_service does, and then
216 * we can re-enable UBWC here.
217 *
218 * Inherit the trick from crrev/c/2523246 previously used for gtest. The side
219 * effect is all VM guests on msm will revert back to use linear modifier.
220 *
221 * See b/229147702
222 */
223 if (!dlsym(RTLD_DEFAULT, "cupsFilePrintf")) {
Yiwei Zhang04954732022-07-13 23:34:33 +0000224 drv_logi("WARNING: virtualization detected, disabling UBWC\n");
Yiwei Zhang7a1a7db2022-04-14 06:28:14 +0000225 return true;
226 }
Rob Clarke48e4d72020-08-07 08:08:30 -0700227#endif
228 return false;
229}
230
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530231static int msm_init(struct driver *drv)
232{
Tanmay Shah067594b2018-11-26 10:05:18 -0800233 struct format_metadata metadata;
Jeffrey Kardatzkeafb2c562020-03-02 12:25:55 -0800234 uint64_t render_use_flags = BO_USE_RENDER_MASK | BO_USE_SCANOUT;
Tanmay Shah067594b2018-11-26 10:05:18 -0800235 uint64_t texture_use_flags = BO_USE_TEXTURE_MASK | BO_USE_HW_VIDEO_DECODER;
Rob Clark6f83a442020-10-05 12:10:51 -0700236 /*
237 * NOTE: we actually could use tiled in the BO_USE_FRONT_RENDERING case,
238 * if we had a modifier for tiled-but-not-compressed. But we *cannot* use
239 * compressed in this case because the UBWC flags/meta data can be out of
240 * sync with pixel data while the GPU is writing a frame out to memory.
241 */
Gurchetan Singh146ee022021-04-02 16:34:05 -0700242 uint64_t sw_flags =
243 (BO_USE_RENDERSCRIPT | BO_USE_SW_MASK | BO_USE_LINEAR | BO_USE_FRONT_RENDERING);
Tanmay Shah067594b2018-11-26 10:05:18 -0800244
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530245 drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
Tanmay Shah067594b2018-11-26 10:05:18 -0800246 &LINEAR_METADATA, render_use_flags);
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530247
Tanmay Shah617ee712018-07-11 16:41:05 -0700248 drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats),
Tanmay Shah067594b2018-11-26 10:05:18 -0800249 &LINEAR_METADATA, texture_use_flags);
Alexandre Courbot1805a9b2018-05-21 19:05:10 +0900250
Ricky Liangf11f1df2020-02-13 10:42:46 +0800251 /* The camera stack standardizes on NV12 for YUV buffers. */
Hirokazu Honda3bd681c2020-06-23 17:52:20 +0900252 /* YVU420 and NV12 formats for camera, display and encoding. */
Ricky Liangf11f1df2020-02-13 10:42:46 +0800253 drv_modify_combination(drv, DRM_FORMAT_NV12, &LINEAR_METADATA,
Hirokazu Honda3bd681c2020-06-23 17:52:20 +0900254 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_SCANOUT |
255 BO_USE_HW_VIDEO_ENCODER);
256
Ricky Liangf11f1df2020-02-13 10:42:46 +0800257 /*
258 * R8 format is used for Android's HAL_PIXEL_FORMAT_BLOB and is used for JPEG snapshots
David Stevens49518142020-06-15 13:48:48 +0900259 * from camera and input/output from hardware decoder/encoder.
Ricky Liangf11f1df2020-02-13 10:42:46 +0800260 */
Douglas Anderson0c03c9b2020-07-21 08:06:46 -0700261 drv_modify_combination(drv, DRM_FORMAT_R8, &LINEAR_METADATA,
David Stevens49518142020-06-15 13:48:48 +0900262 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE | BO_USE_HW_VIDEO_DECODER |
263 BO_USE_HW_VIDEO_ENCODER);
Ricky Liangf11f1df2020-02-13 10:42:46 +0800264
John Stultzd9381b62021-07-28 06:23:03 +0000265 /*
266 * Android also frequently requests YV12 formats for some camera implementations
Yiwei Zhang26e16cb2021-09-30 06:51:53 +0000267 * (including the external provider implmenetation).
John Stultzd9381b62021-07-28 06:23:03 +0000268 */
269 drv_modify_combination(drv, DRM_FORMAT_YVU420_ANDROID, &LINEAR_METADATA,
Yiwei Zhang26e16cb2021-09-30 06:51:53 +0000270 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
Rob Clark29daef02022-07-19 11:17:52 -0700271 drv_modify_combination(drv, DRM_FORMAT_YVU420, &LINEAR_METADATA,
272 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
John Stultzd9381b62021-07-28 06:23:03 +0000273
Gurchetan Singh71bc6652018-09-17 17:42:05 -0700274 /* Android CTS tests require this. */
275 drv_add_combination(drv, DRM_FORMAT_BGR888, &LINEAR_METADATA, BO_USE_SW_MASK);
276
Fritz Koenig2471aa22021-08-17 10:32:12 -0700277#ifdef SC_7280
278 drv_modify_combination(drv, DRM_FORMAT_P010, &LINEAR_METADATA,
279 BO_USE_SCANOUT | BO_USE_HW_VIDEO_ENCODER);
280#endif
281
Tanmay Shah067594b2018-11-26 10:05:18 -0800282 drv_modify_linear_combinations(drv);
283
Pilar Molina Lopez28cf2f12020-11-12 18:19:42 -0500284 if (should_avoid_ubwc() || !drv->compression)
Rob Clarke48e4d72020-08-07 08:08:30 -0700285 return 0;
286
Tanmay Shah067594b2018-11-26 10:05:18 -0800287 metadata.tiling = MSM_UBWC_TILING;
288 metadata.priority = 2;
289 metadata.modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
290
291 render_use_flags &= ~sw_flags;
292 texture_use_flags &= ~sw_flags;
293
Kristian H. Kristensen8f782d82020-08-26 00:26:24 +0000294 msm_add_ubwc_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
295 &metadata, render_use_flags);
Tanmay Shah067594b2018-11-26 10:05:18 -0800296
Kristian H. Kristensen8f782d82020-08-26 00:26:24 +0000297 msm_add_ubwc_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats),
298 &metadata, texture_use_flags);
Tanmay Shah067594b2018-11-26 10:05:18 -0800299
Fritz Koenigb8226cb2020-08-07 14:56:18 -0700300 drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata,
Gurchetan Singh45ca4492021-04-28 17:12:52 -0700301 BO_USE_SCANOUT | BO_USE_HW_VIDEO_ENCODER);
Fritz Koenigb8226cb2020-08-07 14:56:18 -0700302
Tanmay Shah067594b2018-11-26 10:05:18 -0800303 return 0;
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530304}
305
Tanmay Shah067594b2018-11-26 10:05:18 -0800306static int msm_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t height,
307 uint32_t format, const uint64_t modifier)
Stéphane Marchesin23e006a2018-02-28 16:37:46 -0800308{
Gurchetan Singh99644382020-10-07 15:28:11 -0700309 struct drm_msm_gem_new req = { 0 };
Tanmay Shah617ee712018-07-11 16:41:05 -0700310 int ret;
311 size_t i;
312
Gurchetan Singh298b7572019-09-19 09:55:18 -0700313 bo->meta.tiling = (modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED) ? MSM_UBWC_TILING : 0;
Tanmay Shah067594b2018-11-26 10:05:18 -0800314 msm_calculate_layout(bo);
Tanmay Shah617ee712018-07-11 16:41:05 -0700315
Tanmay Shah617ee712018-07-11 16:41:05 -0700316 req.flags = MSM_BO_WC | MSM_BO_SCANOUT;
Gurchetan Singh298b7572019-09-19 09:55:18 -0700317 req.size = bo->meta.total_size;
Tanmay Shah617ee712018-07-11 16:41:05 -0700318
319 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_NEW, &req);
320 if (ret) {
Yiwei Zhang04954732022-07-13 23:34:33 +0000321 drv_loge("DRM_IOCTL_MSM_GEM_NEW failed with %s\n", strerror(errno));
Stéphane Marchesin6ac299f2019-03-21 12:23:29 -0700322 return -errno;
Tanmay Shah617ee712018-07-11 16:41:05 -0700323 }
324
325 /*
326 * Though we use only one plane, we need to set handle for
327 * all planes to pass kernel checks
328 */
Gurchetan Singh52155b42021-01-27 17:55:17 -0800329 for (i = 0; i < bo->meta.num_planes; i++)
Tanmay Shah617ee712018-07-11 16:41:05 -0700330 bo->handles[i].u32 = req.handle;
Tanmay Shah617ee712018-07-11 16:41:05 -0700331
Gurchetan Singh52155b42021-01-27 17:55:17 -0800332 bo->meta.format_modifier = modifier;
Tanmay Shah617ee712018-07-11 16:41:05 -0700333 return 0;
334}
335
Tanmay Shah067594b2018-11-26 10:05:18 -0800336static int msm_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
337 uint32_t format, const uint64_t *modifiers, uint32_t count)
338{
339 static const uint64_t modifier_order[] = {
340 DRM_FORMAT_MOD_QCOM_COMPRESSED,
341 DRM_FORMAT_MOD_LINEAR,
342 };
343
344 uint64_t modifier =
345 drv_pick_modifier(modifiers, count, modifier_order, ARRAY_SIZE(modifier_order));
346
Pilar Molina Lopez28cf2f12020-11-12 18:19:42 -0500347 if (!bo->drv->compression && modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED)
348 modifier = DRM_FORMAT_MOD_LINEAR;
349
Tanmay Shah067594b2018-11-26 10:05:18 -0800350 return msm_bo_create_for_modifier(bo, width, height, format, modifier);
351}
352
353/* msm_bo_create will create linear buffers for now */
354static int msm_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
355 uint64_t flags)
356{
357 struct combination *combo = drv_get_combination(bo->drv, format, flags);
358
359 if (!combo) {
Yiwei Zhang04954732022-07-13 23:34:33 +0000360 drv_loge("invalid format = %d, flags = %" PRIx64 " combination\n", format, flags);
Tanmay Shah067594b2018-11-26 10:05:18 -0800361 return -EINVAL;
362 }
363
364 return msm_bo_create_for_modifier(bo, width, height, format, combo->metadata.modifier);
365}
366
Tanmay Shah617ee712018-07-11 16:41:05 -0700367static void *msm_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags)
368{
369 int ret;
Gurchetan Singh99644382020-10-07 15:28:11 -0700370 struct drm_msm_gem_info req = { 0 };
Tanmay Shah617ee712018-07-11 16:41:05 -0700371
Tanmay Shah617ee712018-07-11 16:41:05 -0700372 req.handle = bo->handles[0].u32;
Tanmay Shah617ee712018-07-11 16:41:05 -0700373 ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_INFO, &req);
374 if (ret) {
Yiwei Zhang04954732022-07-13 23:34:33 +0000375 drv_loge("DRM_IOCLT_MSM_GEM_INFO failed with %s\n", strerror(errno));
Tanmay Shah617ee712018-07-11 16:41:05 -0700376 return MAP_FAILED;
377 }
Gurchetan Singh298b7572019-09-19 09:55:18 -0700378 vma->length = bo->meta.total_size;
Tanmay Shah617ee712018-07-11 16:41:05 -0700379
Gurchetan Singh298b7572019-09-19 09:55:18 -0700380 return mmap(0, bo->meta.total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd,
Tanmay Shah617ee712018-07-11 16:41:05 -0700381 req.offset);
Stéphane Marchesin23e006a2018-02-28 16:37:46 -0800382}
383
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530384const struct backend backend_msm = {
385 .name = "msm",
386 .init = msm_init,
Stéphane Marchesin23e006a2018-02-28 16:37:46 -0800387 .bo_create = msm_bo_create,
Tanmay Shah067594b2018-11-26 10:05:18 -0800388 .bo_create_with_modifiers = msm_bo_create_with_modifiers,
Tanmay Shah617ee712018-07-11 16:41:05 -0700389 .bo_destroy = drv_gem_bo_destroy,
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530390 .bo_import = drv_prime_bo_import,
Tanmay Shah617ee712018-07-11 16:41:05 -0700391 .bo_map = msm_bo_map,
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530392 .bo_unmap = drv_bo_munmap,
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +0000393 .resolve_format_and_use_flags = drv_resolve_format_and_use_flags_helper,
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530394};
Rajesh Yadav7f79cb52018-01-22 18:29:06 +0530395#endif /* DRV_MSM */