blob: f337e8bee8a370dd88f0b8588db8f4d49108c60f [file] [log] [blame]
Anders Delliene5bef532020-06-10 10:30:44 +01001/*
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
Matt Turner7790b232021-11-17 18:36:46 +00007#include <errno.h>
8
Yiwei Zhangb7a64442021-09-30 05:13:10 +00009#include "drv_helpers.h"
Anders Delliene5bef532020-06-10 10:30:44 +010010#include "drv_priv.h"
Anders Delliene5bef532020-06-10 10:30:44 +010011#include "util.h"
12
13#define INIT_DUMB_DRIVER(driver) \
14 const struct backend backend_##driver = { \
15 .name = #driver, \
16 .init = dumb_driver_init, \
17 .bo_create = drv_dumb_bo_create, \
Matt Turner7790b232021-11-17 18:36:46 +000018 .bo_create_with_modifiers = dumb_bo_create_with_modifiers, \
Anders Delliene5bef532020-06-10 10:30:44 +010019 .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, \
Yiwei Zhangb8ad7b82021-10-01 17:55:14 +000023 .resolve_format_and_use_flags = drv_resolve_format_and_use_flags_helper, \
Anders Delliene5bef532020-06-10 10:30:44 +010024 };
25
26static const uint32_t scanout_render_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888,
27 DRM_FORMAT_ABGR8888, DRM_FORMAT_XBGR8888,
Yiwei Zhang65d4bf32021-11-18 20:06:00 +000028 DRM_FORMAT_BGR888, DRM_FORMAT_RGB565 };
Anders Delliene5bef532020-06-10 10:30:44 +010029
Nicholas Bishop17d3eb82022-04-08 17:37:52 -040030static const uint32_t texture_only_formats[] = { DRM_FORMAT_R8, DRM_FORMAT_NV12, DRM_FORMAT_NV21,
Anders Delliene5bef532020-06-10 10:30:44 +010031 DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID };
32
33static int dumb_driver_init(struct driver *drv)
34{
35 drv_add_combinations(drv, scanout_render_formats, ARRAY_SIZE(scanout_render_formats),
36 &LINEAR_METADATA, BO_USE_RENDER_MASK | BO_USE_SCANOUT);
37
38 drv_add_combinations(drv, texture_only_formats, ARRAY_SIZE(texture_only_formats),
39 &LINEAR_METADATA, BO_USE_TEXTURE_MASK);
40
Nicholas Bishop17d3eb82022-04-08 17:37:52 -040041 drv_modify_combination(drv, DRM_FORMAT_R8, &LINEAR_METADATA,
42 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER |
Yiwei Zhangbbe1fd32022-07-20 20:44:22 +000043 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE |
Jason Macnak80f664c2022-07-19 16:44:22 -070044 BO_USE_GPU_DATA_BUFFER | BO_USE_SENSOR_DIRECT_DATA);
Anders Delliene5bef532020-06-10 10:30:44 +010045 drv_modify_combination(drv, DRM_FORMAT_NV12, &LINEAR_METADATA,
46 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER |
47 BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE);
48 drv_modify_combination(drv, DRM_FORMAT_NV21, &LINEAR_METADATA, BO_USE_HW_VIDEO_ENCODER);
49
50 return drv_modify_linear_combinations(drv);
51}
52
Matt Turner7790b232021-11-17 18:36:46 +000053static int dumb_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
54 uint32_t format, const uint64_t *modifiers, uint32_t count)
55{
56 for (uint32_t i = 0; i < count; i++) {
57 if (modifiers[i] == DRM_FORMAT_MOD_LINEAR) {
58 return drv_dumb_bo_create(bo, width, height, format, 0);
59 }
60 }
61
62 return -EINVAL;
63}
64
Gurchetan Singh238001f2020-10-28 15:00:10 -070065INIT_DUMB_DRIVER(evdi)
Anders Delliene5bef532020-06-10 10:30:44 +010066INIT_DUMB_DRIVER(komeda)
67INIT_DUMB_DRIVER(marvell)
68INIT_DUMB_DRIVER(meson)
69INIT_DUMB_DRIVER(nouveau)
70INIT_DUMB_DRIVER(radeon)
71INIT_DUMB_DRIVER(synaptics)
Gurchetan Singh238001f2020-10-28 15:00:10 -070072INIT_DUMB_DRIVER(udl)
François-Denis Gonthiercea0b842020-05-22 18:02:24 -040073INIT_DUMB_DRIVER(vkms)