1 /*
2 * Copyright 2020 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 #include <errno.h>
8
9 #include "drv_helpers.h"
10 #include "drv_priv.h"
11 #include "util.h"
12
13 #define INIT_DUMB_DRIVER_WITH_NAME(driver, _name) \
14 const struct backend backend_##driver = { \
15 .name = _name, \
16 .init = dumb_driver_init, \
17 .bo_create = drv_dumb_bo_create, \
18 .bo_create_with_modifiers = dumb_bo_create_with_modifiers, \
19 .bo_destroy = drv_dumb_bo_destroy, \
20 .bo_import = drv_prime_bo_import, \
21 .bo_map = drv_dumb_bo_map, \
22 .bo_unmap = drv_bo_munmap, \
23 .resolve_format_and_use_flags = drv_resolve_format_and_use_flags_helper, \
24 };
25
26 #define INIT_DUMB_DRIVER(driver) INIT_DUMB_DRIVER_WITH_NAME(driver, #driver)
27
28 static const uint32_t scanout_render_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888,
29 DRM_FORMAT_ABGR8888, DRM_FORMAT_XBGR8888,
30 DRM_FORMAT_BGR888, DRM_FORMAT_RGB565 };
31
32 static const uint32_t texture_only_formats[] = { DRM_FORMAT_R8, DRM_FORMAT_NV12, DRM_FORMAT_NV21,
33 DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID };
34
dumb_driver_init(struct driver * drv)35 static int dumb_driver_init(struct driver *drv)
36 {
37 drv_add_combinations(drv, scanout_render_formats, ARRAY_SIZE(scanout_render_formats),
38 &LINEAR_METADATA, BO_USE_RENDER_MASK | BO_USE_SCANOUT);
39
40 drv_add_combinations(drv, texture_only_formats, ARRAY_SIZE(texture_only_formats),
41 &LINEAR_METADATA, BO_USE_TEXTURE_MASK);
42
43 drv_modify_combination(drv, DRM_FORMAT_R8, &LINEAR_METADATA,
44 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER |
45 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE |
46 BO_USE_GPU_DATA_BUFFER | BO_USE_SENSOR_DIRECT_DATA);
47 drv_modify_combination(drv, DRM_FORMAT_NV12, &LINEAR_METADATA,
48 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER |
49 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
50 drv_modify_combination(drv, DRM_FORMAT_NV21, &LINEAR_METADATA, BO_USE_HW_VIDEO_ENCODER);
51
52 return drv_modify_linear_combinations(drv);
53 }
54
dumb_bo_create_with_modifiers(struct bo * bo,uint32_t width,uint32_t height,uint32_t format,const uint64_t * modifiers,uint32_t count)55 static int dumb_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
56 uint32_t format, const uint64_t *modifiers, uint32_t count)
57 {
58 for (uint32_t i = 0; i < count; i++) {
59 if (modifiers[i] == DRM_FORMAT_MOD_LINEAR) {
60 return drv_dumb_bo_create(bo, width, height, format, 0);
61 }
62 }
63
64 return -EINVAL;
65 }
66
67 INIT_DUMB_DRIVER(evdi)
68 INIT_DUMB_DRIVER(komeda)
69 INIT_DUMB_DRIVER(marvell)
70 INIT_DUMB_DRIVER(meson)
71 INIT_DUMB_DRIVER(nouveau)
72 INIT_DUMB_DRIVER(radeon)
73 INIT_DUMB_DRIVER_WITH_NAME(sun4i_drm, "sun4i-drm")
74 INIT_DUMB_DRIVER(synaptics)
75 INIT_DUMB_DRIVER(udl)
76 INIT_DUMB_DRIVER(vkms)
77
78 #ifndef DRV_ROCKCHIP
79 INIT_DUMB_DRIVER(rockchip)
80 #endif
81 #ifndef DRV_MEDIATEK
82 INIT_DUMB_DRIVER(mediatek)
83 #endif
84